aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTony Luck <tony.luck@intel.com>2005-07-13 15:15:43 -0400
committerTony Luck <tony.luck@intel.com>2005-07-13 15:15:43 -0400
commit99ad25a313bda566a346b46a6015afa65bc0a02b (patch)
treeb9443fed1ab74f320c4ee0791864ee96d7c069df
parentf62c4a96f74d6c6dd56d1742697e94a5c2085e87 (diff)
parent9a556e89081b0c1c2f83cee915363b15a68a6f2d (diff)
Auto merge with /home/aegl/GIT/linus
-rw-r--r--Documentation/acpi-hotkey.txt35
-rw-r--r--Documentation/filesystems/inotify.txt138
-rw-r--r--Documentation/hwmon/adm1021 (renamed from Documentation/i2c/chips/adm1021)0
-rw-r--r--Documentation/hwmon/adm1025 (renamed from Documentation/i2c/chips/adm1025)0
-rw-r--r--Documentation/hwmon/adm1026 (renamed from Documentation/i2c/chips/adm1026)0
-rw-r--r--Documentation/hwmon/adm1031 (renamed from Documentation/i2c/chips/adm1031)0
-rw-r--r--Documentation/hwmon/adm9240 (renamed from Documentation/i2c/chips/adm9240)0
-rw-r--r--Documentation/hwmon/asb100 (renamed from Documentation/i2c/chips/asb100)0
-rw-r--r--Documentation/hwmon/ds1621 (renamed from Documentation/i2c/chips/ds1621)0
-rw-r--r--Documentation/hwmon/fscher (renamed from Documentation/i2c/chips/fscher)0
-rw-r--r--Documentation/hwmon/gl518sm (renamed from Documentation/i2c/chips/gl518sm)0
-rw-r--r--Documentation/hwmon/it87 (renamed from Documentation/i2c/chips/it87)0
-rw-r--r--Documentation/hwmon/lm63 (renamed from Documentation/i2c/chips/lm63)0
-rw-r--r--Documentation/hwmon/lm75 (renamed from Documentation/i2c/chips/lm75)0
-rw-r--r--Documentation/hwmon/lm77 (renamed from Documentation/i2c/chips/lm77)0
-rw-r--r--Documentation/hwmon/lm78 (renamed from Documentation/i2c/chips/lm78)0
-rw-r--r--Documentation/hwmon/lm80 (renamed from Documentation/i2c/chips/lm80)0
-rw-r--r--Documentation/hwmon/lm83 (renamed from Documentation/i2c/chips/lm83)0
-rw-r--r--Documentation/hwmon/lm85 (renamed from Documentation/i2c/chips/lm85)0
-rw-r--r--Documentation/hwmon/lm87 (renamed from Documentation/i2c/chips/lm87)0
-rw-r--r--Documentation/hwmon/lm90 (renamed from Documentation/i2c/chips/lm90)0
-rw-r--r--Documentation/hwmon/lm92 (renamed from Documentation/i2c/chips/lm92)0
-rw-r--r--Documentation/hwmon/max1619 (renamed from Documentation/i2c/chips/max1619)0
-rw-r--r--Documentation/hwmon/pc87360 (renamed from Documentation/i2c/chips/pc87360)0
-rw-r--r--Documentation/hwmon/sis5595 (renamed from Documentation/i2c/chips/sis5595)0
-rw-r--r--Documentation/hwmon/smsc47b397 (renamed from Documentation/i2c/chips/smsc47b397)0
-rw-r--r--Documentation/hwmon/smsc47m1 (renamed from Documentation/i2c/chips/smsc47m1)0
-rw-r--r--Documentation/hwmon/sysfs-interface (renamed from Documentation/i2c/sysfs-interface)0
-rw-r--r--Documentation/hwmon/userspace-tools (renamed from Documentation/i2c/userspace-tools)0
-rw-r--r--Documentation/hwmon/via686a (renamed from Documentation/i2c/chips/via686a)0
-rw-r--r--Documentation/hwmon/w83627hf (renamed from Documentation/i2c/chips/w83627hf)0
-rw-r--r--Documentation/hwmon/w83781d (renamed from Documentation/i2c/chips/w83781d)0
-rw-r--r--Documentation/hwmon/w83l785ts (renamed from Documentation/i2c/chips/w83l785ts)0
-rw-r--r--Documentation/i2c/chips/max687522
-rw-r--r--Documentation/i2c/dev-interface15
-rw-r--r--Documentation/i2c/writing-clients7
-rw-r--r--Documentation/kernel-parameters.txt2
-rw-r--r--Documentation/pcmcia/driver-changes.txt9
-rw-r--r--Documentation/usb/sn9c102.txt4
-rw-r--r--Documentation/usb/usbmon.txt29
-rw-r--r--Documentation/video4linux/CARDLIST.bttv2
-rw-r--r--Documentation/video4linux/CARDLIST.cx882
-rw-r--r--Documentation/video4linux/CARDLIST.saa713414
-rw-r--r--Documentation/video4linux/CARDLIST.tuner4
-rw-r--r--Documentation/video4linux/bttv/Cards74
-rw-r--r--Documentation/video4linux/not-in-cx2388x-datasheet.txt4
-rw-r--r--MAINTAINERS2
-rw-r--r--Makefile2
-rw-r--r--arch/alpha/Kconfig2
-rw-r--r--arch/arm/Kconfig6
-rw-r--r--arch/arm/kernel/smp.c7
-rw-r--r--arch/arm/mach-integrator/platsmp.c8
-rw-r--r--arch/arm/mach-omap1/leds-h2p2-debug.c1
-rw-r--r--arch/arm/nwfpe/fpmodule.c1
-rw-r--r--arch/arm/plat-omap/ocpi.c1
-rw-r--r--arch/arm26/Kconfig4
-rw-r--r--arch/cris/Kconfig4
-rw-r--r--arch/frv/Kconfig2
-rw-r--r--arch/frv/mb93090-mb00/pci-irq.c2
-rw-r--r--arch/h8300/Kconfig6
-rw-r--r--arch/i386/Kconfig2
-rw-r--r--arch/i386/kernel/acpi/Makefile4
-rw-r--r--arch/i386/kernel/acpi/cstate.c103
-rw-r--r--arch/i386/kernel/acpi/wakeup.S5
-rw-r--r--arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c2
-rw-r--r--arch/i386/kernel/syscall_table.S3
-rw-r--r--arch/i386/mach-voyager/voyager_basic.c1
-rw-r--r--arch/i386/mach-voyager/voyager_smp.c6
-rw-r--r--arch/i386/pci/irq.c16
-rw-r--r--arch/i386/pci/visws.c2
-rw-r--r--arch/ia64/Kconfig2
-rw-r--r--arch/ia64/kernel/acpi.c54
-rw-r--r--arch/ia64/kernel/mca.c2
-rw-r--r--arch/ia64/kernel/process.c1
-rw-r--r--arch/ia64/kernel/setup.c3
-rw-r--r--arch/ia64/kernel/topology.c7
-rw-r--r--arch/m32r/Kconfig2
-rw-r--r--arch/m68k/Kconfig2
-rw-r--r--arch/m68knommu/Kconfig2
-rw-r--r--arch/mips/Kconfig2
-rw-r--r--arch/parisc/Kconfig2
-rw-r--r--arch/ppc/Kconfig2
-rw-r--r--arch/ppc/kernel/machine_kexec.c6
-rw-r--r--arch/ppc64/Kconfig2
-rw-r--r--arch/s390/Kconfig4
-rw-r--r--arch/sh/Kconfig2
-rw-r--r--arch/sh64/Kconfig2
-rw-r--r--arch/sparc/Kconfig2
-rw-r--r--arch/sparc64/Kconfig6
-rw-r--r--arch/sparc64/kernel/smp.c4
-rw-r--r--arch/um/Kconfig4
-rw-r--r--arch/um/Makefile3
-rw-r--r--arch/v850/Kconfig4
-rw-r--r--arch/x86_64/Kconfig2
-rw-r--r--arch/x86_64/kernel/vmlinux.lds.S4
-rw-r--r--arch/xtensa/Kconfig2
-rw-r--r--arch/xtensa/kernel/asm-offsets.c1
-rw-r--r--arch/xtensa/kernel/syscalls.c4
-rw-r--r--arch/xtensa/kernel/syscalls.h6
-rw-r--r--arch/xtensa/kernel/traps.c4
-rw-r--r--arch/xtensa/kernel/vmlinux.lds.S6
-rw-r--r--drivers/Kconfig4
-rw-r--r--drivers/Makefile1
-rw-r--r--drivers/acpi/Kconfig38
-rw-r--r--drivers/acpi/Makefile5
-rw-r--r--drivers/acpi/asus_acpi.c4
-rw-r--r--drivers/acpi/bus.c8
-rw-r--r--drivers/acpi/button.c245
-rw-r--r--drivers/acpi/dispatcher/dsfield.c58
-rw-r--r--drivers/acpi/dispatcher/dsinit.c28
-rw-r--r--drivers/acpi/dispatcher/dsmethod.c11
-rw-r--r--drivers/acpi/dispatcher/dsmthdat.c195
-rw-r--r--drivers/acpi/dispatcher/dsobject.c79
-rw-r--r--drivers/acpi/dispatcher/dsopcode.c105
-rw-r--r--drivers/acpi/dispatcher/dsutils.c41
-rw-r--r--drivers/acpi/dispatcher/dswexec.c57
-rw-r--r--drivers/acpi/dispatcher/dswload.c118
-rw-r--r--drivers/acpi/dispatcher/dswscope.c31
-rw-r--r--drivers/acpi/dispatcher/dswstate.c458
-rw-r--r--drivers/acpi/ec.c420
-rw-r--r--drivers/acpi/events/evevent.c33
-rw-r--r--drivers/acpi/events/evgpe.c39
-rw-r--r--drivers/acpi/events/evgpeblk.c63
-rw-r--r--drivers/acpi/events/evmisc.c97
-rw-r--r--drivers/acpi/events/evregion.c35
-rw-r--r--drivers/acpi/events/evrgnini.c14
-rw-r--r--drivers/acpi/events/evsci.c12
-rw-r--r--drivers/acpi/events/evxface.c19
-rw-r--r--drivers/acpi/events/evxfevnt.c25
-rw-r--r--drivers/acpi/executer/exconfig.c31
-rw-r--r--drivers/acpi/executer/exconvrt.c44
-rw-r--r--drivers/acpi/executer/excreate.c50
-rw-r--r--drivers/acpi/executer/exdump.c105
-rw-r--r--drivers/acpi/executer/exfield.c25
-rw-r--r--drivers/acpi/executer/exfldio.c133
-rw-r--r--drivers/acpi/executer/exmisc.c7
-rw-r--r--drivers/acpi/executer/exmutex.c45
-rw-r--r--drivers/acpi/executer/exnames.c70
-rw-r--r--drivers/acpi/executer/exoparg1.c94
-rw-r--r--drivers/acpi/executer/exoparg2.c69
-rw-r--r--drivers/acpi/executer/exoparg3.c25
-rw-r--r--drivers/acpi/executer/exoparg6.c26
-rw-r--r--drivers/acpi/executer/exprep.c104
-rw-r--r--drivers/acpi/executer/exregion.c34
-rw-r--r--drivers/acpi/executer/exresnte.c24
-rw-r--r--drivers/acpi/executer/exresolv.c63
-rw-r--r--drivers/acpi/executer/exresop.c80
-rw-r--r--drivers/acpi/executer/exstore.c260
-rw-r--r--drivers/acpi/executer/exstoren.c20
-rw-r--r--drivers/acpi/executer/exstorob.c9
-rw-r--r--drivers/acpi/executer/exsystem.c48
-rw-r--r--drivers/acpi/executer/exutils.c37
-rw-r--r--drivers/acpi/glue.c360
-rw-r--r--drivers/acpi/hardware/hwacpi.c19
-rw-r--r--drivers/acpi/hardware/hwgpe.c31
-rw-r--r--drivers/acpi/hardware/hwregs.c114
-rw-r--r--drivers/acpi/hardware/hwsleep.c101
-rw-r--r--drivers/acpi/hardware/hwtimer.c4
-rw-r--r--drivers/acpi/hotkey.c1019
-rw-r--r--drivers/acpi/ibm_acpi.c8
-rw-r--r--drivers/acpi/namespace/nsaccess.c5
-rw-r--r--drivers/acpi/namespace/nsalloc.c121
-rw-r--r--drivers/acpi/namespace/nsdump.c109
-rw-r--r--drivers/acpi/namespace/nsdumpdv.c18
-rw-r--r--drivers/acpi/namespace/nseval.c70
-rw-r--r--drivers/acpi/namespace/nsinit.c28
-rw-r--r--drivers/acpi/namespace/nsload.c28
-rw-r--r--drivers/acpi/namespace/nsnames.c12
-rw-r--r--drivers/acpi/namespace/nsobject.c14
-rw-r--r--drivers/acpi/namespace/nssearch.c29
-rw-r--r--drivers/acpi/namespace/nsutils.c167
-rw-r--r--drivers/acpi/namespace/nswalk.c2
-rw-r--r--drivers/acpi/namespace/nsxfeval.c16
-rw-r--r--drivers/acpi/namespace/nsxfname.c8
-rw-r--r--drivers/acpi/namespace/nsxfobj.c4
-rw-r--r--drivers/acpi/osl.c12
-rw-r--r--drivers/acpi/parser/psargs.c55
-rw-r--r--drivers/acpi/parser/psopcode.c298
-rw-r--r--drivers/acpi/parser/psparse.c144
-rw-r--r--drivers/acpi/parser/psscope.c45
-rw-r--r--drivers/acpi/parser/pstree.c159
-rw-r--r--drivers/acpi/parser/psutils.c15
-rw-r--r--drivers/acpi/parser/pswalk.c11
-rw-r--r--drivers/acpi/parser/psxface.c21
-rw-r--r--drivers/acpi/pci_link.c43
-rw-r--r--drivers/acpi/processor_core.c37
-rw-r--r--drivers/acpi/processor_idle.c138
-rw-r--r--drivers/acpi/processor_perflib.c33
-rw-r--r--drivers/acpi/resources/rsaddr.c480
-rw-r--r--drivers/acpi/resources/rscalc.c144
-rw-r--r--drivers/acpi/resources/rscreate.c45
-rw-r--r--drivers/acpi/resources/rsdump.c402
-rw-r--r--drivers/acpi/resources/rsio.c197
-rw-r--r--drivers/acpi/resources/rsirq.c167
-rw-r--r--drivers/acpi/resources/rslist.c68
-rw-r--r--drivers/acpi/resources/rsmemory.c236
-rw-r--r--drivers/acpi/resources/rsmisc.c160
-rw-r--r--drivers/acpi/resources/rsutils.c53
-rw-r--r--drivers/acpi/resources/rsxface.c43
-rw-r--r--drivers/acpi/scan.c12
-rw-r--r--drivers/acpi/sleep/main.c74
-rw-r--r--drivers/acpi/sleep/poweroff.c81
-rw-r--r--drivers/acpi/sleep/proc.c9
-rw-r--r--drivers/acpi/tables/tbconvrt.c105
-rw-r--r--drivers/acpi/tables/tbget.c63
-rw-r--r--drivers/acpi/tables/tbgetall.c45
-rw-r--r--drivers/acpi/tables/tbinstal.c31
-rw-r--r--drivers/acpi/tables/tbrsdt.c19
-rw-r--r--drivers/acpi/tables/tbutils.c97
-rw-r--r--drivers/acpi/tables/tbxface.c39
-rw-r--r--drivers/acpi/tables/tbxfroot.c123
-rw-r--r--drivers/acpi/toshiba_acpi.c8
-rw-r--r--drivers/acpi/utilities/utalloc.c84
-rw-r--r--drivers/acpi/utilities/utcopy.c126
-rw-r--r--drivers/acpi/utilities/utdebug.c106
-rw-r--r--drivers/acpi/utilities/utdelete.c63
-rw-r--r--drivers/acpi/utilities/uteval.c36
-rw-r--r--drivers/acpi/utilities/utglobal.c133
-rw-r--r--drivers/acpi/utilities/utinit.c36
-rw-r--r--drivers/acpi/utilities/utmath.c2
-rw-r--r--drivers/acpi/utilities/utmisc.c187
-rw-r--r--drivers/acpi/utilities/utobject.c68
-rw-r--r--drivers/acpi/utilities/utxface.c61
-rw-r--r--drivers/acpi/video.c15
-rw-r--r--drivers/base/sys.c1
-rw-r--r--drivers/char/tb0219.c19
-rw-r--r--drivers/hwmon/Kconfig420
-rw-r--r--drivers/hwmon/Makefile44
-rw-r--r--drivers/hwmon/adm1021.c (renamed from drivers/i2c/chips/adm1021.c)0
-rw-r--r--drivers/hwmon/adm1025.c (renamed from drivers/i2c/chips/adm1025.c)0
-rw-r--r--drivers/hwmon/adm1026.c (renamed from drivers/i2c/chips/adm1026.c)0
-rw-r--r--drivers/hwmon/adm1031.c (renamed from drivers/i2c/chips/adm1031.c)0
-rw-r--r--drivers/hwmon/adm9240.c (renamed from drivers/i2c/chips/adm9240.c)0
-rw-r--r--drivers/hwmon/asb100.c (renamed from drivers/i2c/chips/asb100.c)0
-rw-r--r--drivers/hwmon/atxp1.c (renamed from drivers/i2c/chips/atxp1.c)0
-rw-r--r--drivers/hwmon/ds1621.c (renamed from drivers/i2c/chips/ds1621.c)0
-rw-r--r--drivers/hwmon/fscher.c (renamed from drivers/i2c/chips/fscher.c)0
-rw-r--r--drivers/hwmon/fscpos.c (renamed from drivers/i2c/chips/fscpos.c)0
-rw-r--r--drivers/hwmon/gl518sm.c (renamed from drivers/i2c/chips/gl518sm.c)0
-rw-r--r--drivers/hwmon/gl520sm.c (renamed from drivers/i2c/chips/gl520sm.c)0
-rw-r--r--drivers/hwmon/it87.c (renamed from drivers/i2c/chips/it87.c)0
-rw-r--r--drivers/hwmon/lm63.c (renamed from drivers/i2c/chips/lm63.c)0
-rw-r--r--drivers/hwmon/lm75.c (renamed from drivers/i2c/chips/lm75.c)0
-rw-r--r--drivers/hwmon/lm75.h (renamed from drivers/i2c/chips/lm75.h)0
-rw-r--r--drivers/hwmon/lm77.c (renamed from drivers/i2c/chips/lm77.c)0
-rw-r--r--drivers/hwmon/lm78.c (renamed from drivers/i2c/chips/lm78.c)0
-rw-r--r--drivers/hwmon/lm80.c (renamed from drivers/i2c/chips/lm80.c)0
-rw-r--r--drivers/hwmon/lm83.c (renamed from drivers/i2c/chips/lm83.c)0
-rw-r--r--drivers/hwmon/lm85.c (renamed from drivers/i2c/chips/lm85.c)0
-rw-r--r--drivers/hwmon/lm87.c (renamed from drivers/i2c/chips/lm87.c)0
-rw-r--r--drivers/hwmon/lm90.c (renamed from drivers/i2c/chips/lm90.c)0
-rw-r--r--drivers/hwmon/lm92.c (renamed from drivers/i2c/chips/lm92.c)0
-rw-r--r--drivers/hwmon/max1619.c (renamed from drivers/i2c/chips/max1619.c)0
-rw-r--r--drivers/hwmon/pc87360.c (renamed from drivers/i2c/chips/pc87360.c)0
-rw-r--r--drivers/hwmon/sis5595.c (renamed from drivers/i2c/chips/sis5595.c)0
-rw-r--r--drivers/hwmon/smsc47b397.c (renamed from drivers/i2c/chips/smsc47b397.c)0
-rw-r--r--drivers/hwmon/smsc47m1.c (renamed from drivers/i2c/chips/smsc47m1.c)0
-rw-r--r--drivers/hwmon/via686a.c (renamed from drivers/i2c/chips/via686a.c)12
-rw-r--r--drivers/hwmon/w83627ehf.c (renamed from drivers/i2c/chips/w83627ehf.c)0
-rw-r--r--drivers/hwmon/w83627hf.c (renamed from drivers/i2c/chips/w83627hf.c)0
-rw-r--r--drivers/hwmon/w83781d.c (renamed from drivers/i2c/chips/w83781d.c)0
-rw-r--r--drivers/hwmon/w83l785ts.c (renamed from drivers/i2c/chips/w83l785ts.c)0
-rw-r--r--drivers/i2c/algos/i2c-algo-ite.c8
-rw-r--r--drivers/i2c/busses/i2c-i801.c4
-rw-r--r--drivers/i2c/busses/i2c-piix4.c2
-rw-r--r--drivers/i2c/busses/i2c-sis5595.c2
-rw-r--r--drivers/i2c/chips/Kconfig413
-rw-r--r--drivers/i2c/chips/Makefile38
-rw-r--r--drivers/i2c/chips/eeprom.c3
-rw-r--r--drivers/i2c/chips/m41t00.c2
-rw-r--r--drivers/i2c/chips/max6875.c6
-rw-r--r--drivers/i2c/chips/tps65010.c59
-rw-r--r--drivers/i2c/i2c-core.c17
-rw-r--r--drivers/ide/ide-cd.c4
-rw-r--r--drivers/md/dm-mpath.c68
-rw-r--r--drivers/md/dm-snap.c6
-rw-r--r--drivers/md/dm-table.c1
-rw-r--r--drivers/md/dm.c27
-rw-r--r--drivers/media/common/ir-common.c255
-rw-r--r--drivers/media/dvb/bt8xx/dst.c2
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-dvb.c2
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-init.c6
-rw-r--r--drivers/media/dvb/dvb-usb/vp7045.c4
-rw-r--r--drivers/media/dvb/frontends/lgdt3302.c64
-rw-r--r--drivers/media/dvb/ttpci/budget-av.c2
-rw-r--r--drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c2
-rw-r--r--drivers/media/video/Kconfig13
-rw-r--r--drivers/media/video/bt832.c12
-rw-r--r--drivers/media/video/bttv-cards.c110
-rw-r--r--drivers/media/video/bttv-driver.c19
-rw-r--r--drivers/media/video/bttv-i2c.c26
-rw-r--r--drivers/media/video/bttv-risc.c9
-rw-r--r--drivers/media/video/cx88/cx88-blackbird.c5
-rw-r--r--drivers/media/video/cx88/cx88-core.c48
-rw-r--r--drivers/media/video/cx88/cx88-dvb.c39
-rw-r--r--drivers/media/video/cx88/cx88-i2c.c31
-rw-r--r--drivers/media/video/cx88/cx88-input.c448
-rw-r--r--drivers/media/video/cx88/cx88-mpeg.c26
-rw-r--r--drivers/media/video/cx88/cx88-reg.h11
-rw-r--r--drivers/media/video/cx88/cx88-tvaudio.c76
-rw-r--r--drivers/media/video/cx88/cx88-video.c303
-rw-r--r--drivers/media/video/cx88/cx88.h12
-rw-r--r--drivers/media/video/ir-kbd-i2c.c51
-rw-r--r--drivers/media/video/msp3400.c25
-rw-r--r--drivers/media/video/mt20xx.c16
-rw-r--r--drivers/media/video/mxb.c7
-rw-r--r--drivers/media/video/saa7134/saa6752hs.c4
-rw-r--r--drivers/media/video/saa7134/saa7134-cards.c2096
-rw-r--r--drivers/media/video/saa7134/saa7134-core.c74
-rw-r--r--drivers/media/video/saa7134/saa7134-dvb.c423
-rw-r--r--drivers/media/video/saa7134/saa7134-i2c.c45
-rw-r--r--drivers/media/video/saa7134/saa7134-input.c48
-rw-r--r--drivers/media/video/saa7134/saa7134-oss.c19
-rw-r--r--drivers/media/video/saa7134/saa7134-ts.c6
-rw-r--r--drivers/media/video/saa7134/saa7134-tvaudio.c121
-rw-r--r--drivers/media/video/saa7134/saa7134-vbi.c12
-rw-r--r--drivers/media/video/saa7134/saa7134-video.c54
-rw-r--r--drivers/media/video/saa7134/saa7134.h21
-rw-r--r--drivers/media/video/tda7432.c13
-rw-r--r--drivers/media/video/tda8290.c13
-rw-r--r--drivers/media/video/tda9875.c13
-rw-r--r--drivers/media/video/tda9887.c9
-rw-r--r--drivers/media/video/tea5767.c158
-rw-r--r--drivers/media/video/tuner-3036.c2
-rw-r--r--drivers/media/video/tuner-core.c707
-rw-r--r--drivers/media/video/tuner-simple.c85
-rw-r--r--drivers/media/video/tvaudio.c5
-rw-r--r--drivers/media/video/tveeprom.c9
-rw-r--r--drivers/misc/Kconfig5
-rw-r--r--drivers/net/Kconfig3
-rw-r--r--drivers/net/appletalk/Kconfig27
-rw-r--r--drivers/net/b44.c3
-rw-r--r--drivers/net/myri_sbus.c2
-rw-r--r--drivers/net/ne2k-pci.c3
-rw-r--r--drivers/net/plip.c2
-rw-r--r--drivers/net/wan/farsync.c3
-rw-r--r--drivers/net/wan/hdlc_cisco.c3
-rw-r--r--drivers/net/wan/hdlc_ppp.c3
-rw-r--r--drivers/net/wan/hdlc_raw.c3
-rw-r--r--drivers/pci/pci-acpi.c110
-rw-r--r--drivers/pci/pci.c22
-rw-r--r--drivers/pci/pci.h4
-rw-r--r--drivers/pcmcia/yenta_socket.c163
-rw-r--r--drivers/pnp/pnpacpi/rsparser.c15
-rw-r--r--drivers/pnp/pnpbios/rsparser.c2
-rw-r--r--drivers/pnp/resource.c2
-rw-r--r--drivers/s390/net/qeth_main.c2
-rw-r--r--drivers/scsi/aacraid/commctrl.c2
-rw-r--r--drivers/usb/Makefile2
-rw-r--r--drivers/usb/atm/cxacru.c2
-rw-r--r--drivers/usb/atm/speedtch.c63
-rw-r--r--drivers/usb/class/cdc-acm.c31
-rw-r--r--drivers/usb/core/buffer.c2
-rw-r--r--drivers/usb/core/hcd-pci.c1
-rw-r--r--drivers/usb/core/hcd.c2
-rw-r--r--drivers/usb/core/hcd.h8
-rw-r--r--drivers/usb/core/hub.c40
-rw-r--r--drivers/usb/core/message.c2
-rw-r--r--drivers/usb/core/sysfs.c2
-rw-r--r--drivers/usb/core/urb.c4
-rw-r--r--drivers/usb/core/usb.c5
-rw-r--r--drivers/usb/gadget/dummy_hcd.c9
-rw-r--r--drivers/usb/gadget/ether.c22
-rw-r--r--drivers/usb/gadget/goku_udc.c6
-rw-r--r--drivers/usb/gadget/lh7a40x_udc.c6
-rw-r--r--drivers/usb/gadget/net2280.c8
-rw-r--r--drivers/usb/gadget/omap_udc.c9
-rw-r--r--drivers/usb/gadget/pxa2xx_udc.c6
-rw-r--r--drivers/usb/gadget/zero.c8
-rw-r--r--drivers/usb/host/ehci-hcd.c2
-rw-r--r--drivers/usb/host/ehci-q.c2
-rw-r--r--drivers/usb/host/ehci-sched.c19
-rw-r--r--drivers/usb/host/hc_crisv10.c10
-rw-r--r--drivers/usb/host/isp116x-hcd.c20
-rw-r--r--drivers/usb/host/ohci-hcd.c6
-rw-r--r--drivers/usb/host/ohci-hub.c3
-rw-r--r--drivers/usb/host/ohci-mem.c4
-rw-r--r--drivers/usb/host/ohci-omap.c53
-rw-r--r--drivers/usb/host/sl811-hcd.c2
-rw-r--r--drivers/usb/host/uhci-q.c2
-rw-r--r--drivers/usb/input/Kconfig13
-rw-r--r--drivers/usb/input/Makefile1
-rw-r--r--drivers/usb/input/hid-core.c24
-rw-r--r--drivers/usb/input/keyspan_remote.c633
-rw-r--r--drivers/usb/media/Makefile2
-rw-r--r--drivers/usb/media/sn9c102.h2
-rw-r--r--drivers/usb/media/sn9c102_core.c2
-rw-r--r--drivers/usb/media/sn9c102_ov7630.c394
-rw-r--r--drivers/usb/media/sn9c102_sensor.h16
-rw-r--r--drivers/usb/media/sn9c102_tas5110c1b.c21
-rw-r--r--drivers/usb/media/sn9c102_tas5130d1b.c27
-rw-r--r--drivers/usb/misc/Kconfig10
-rw-r--r--drivers/usb/misc/Makefile1
-rw-r--r--drivers/usb/misc/ldusb.c794
-rw-r--r--drivers/usb/mon/mon_text.c48
-rw-r--r--drivers/usb/net/kaweth.c4
-rw-r--r--drivers/usb/serial/ftdi_sio.c756
-rw-r--r--drivers/usb/storage/unusual_devs.h2
-rw-r--r--drivers/w1/w1.c5
-rw-r--r--fs/Kconfig13
-rw-r--r--fs/Makefile1
-rw-r--r--fs/attr.c33
-rw-r--r--fs/char_dev.c3
-rw-r--r--fs/compat.c12
-rw-r--r--fs/exec.c12
-rw-r--r--fs/ext2/ext2.h9
-rw-r--r--fs/ext2/super.c24
-rw-r--r--fs/ext3/super.c70
-rw-r--r--fs/file_table.c3
-rw-r--r--fs/inode.c43
-rw-r--r--fs/inotify.c1037
-rw-r--r--fs/jfs/jfs_dmap.c298
-rw-r--r--fs/jfs/jfs_dtree.c199
-rw-r--r--fs/jfs/jfs_dtree.h7
-rw-r--r--fs/jfs/jfs_imap.c105
-rw-r--r--fs/jfs/jfs_unicode.c7
-rw-r--r--fs/jfs/jfs_xtree.c340
-rw-r--r--fs/jfs/jfs_xtree.h6
-rw-r--r--fs/jfs/xattr.c6
-rw-r--r--fs/namei.c30
-rw-r--r--fs/nfsd/vfs.c6
-rw-r--r--fs/open.c3
-rw-r--r--fs/read_write.c15
-rw-r--r--fs/reiserfs/bitmap.c1842
-rw-r--r--fs/reiserfs/dir.c488
-rw-r--r--fs/reiserfs/do_balan.c3236
-rw-r--r--fs/reiserfs/file.c2564
-rw-r--r--fs/reiserfs/fix_node.c4051
-rw-r--r--fs/reiserfs/hashes.c193
-rw-r--r--fs/reiserfs/ibalance.c1844
-rw-r--r--fs/reiserfs/inode.c4915
-rw-r--r--fs/reiserfs/ioctl.c197
-rw-r--r--fs/reiserfs/item_ops.c979
-rw-r--r--fs/reiserfs/journal.c6855
-rw-r--r--fs/reiserfs/lbalance.c2218
-rw-r--r--fs/reiserfs/namei.c2574
-rw-r--r--fs/reiserfs/objectid.c303
-rw-r--r--fs/reiserfs/prints.c1003
-rw-r--r--fs/reiserfs/procfs.c695
-rw-r--r--fs/reiserfs/resize.c207
-rw-r--r--fs/reiserfs/stree.c3369
-rw-r--r--fs/reiserfs/super.c3623
-rw-r--r--fs/reiserfs/tail_conversion.c463
-rw-r--r--fs/reiserfs/xattr.c2173
-rw-r--r--fs/reiserfs/xattr_acl.c641
-rw-r--r--fs/reiserfs/xattr_security.c54
-rw-r--r--fs/reiserfs/xattr_trusted.c70
-rw-r--r--fs/reiserfs/xattr_user.c89
-rw-r--r--fs/sysfs/file.c7
-rw-r--r--fs/xattr.c5
-rw-r--r--include/acpi/acconfig.h7
-rw-r--r--include/acpi/acdebug.h146
-rw-r--r--include/acpi/acdisasm.h114
-rw-r--r--include/acpi/acdispat.h171
-rw-r--r--include/acpi/acevents.h85
-rw-r--r--include/acpi/acexcep.h5
-rw-r--r--include/acpi/acglobal.h12
-rw-r--r--include/acpi/achware.h52
-rw-r--r--include/acpi/acinterp.h243
-rw-r--r--include/acpi/aclocal.h10
-rw-r--r--include/acpi/acmacros.h10
-rw-r--r--include/acpi/acnames.h84
-rw-r--r--include/acpi/acnamesp.h163
-rw-r--r--include/acpi/acobject.h2
-rw-r--r--include/acpi/acopcode.h325
-rw-r--r--include/acpi/acparser.h134
-rw-r--r--include/acpi/acpi.h1
-rw-r--r--include/acpi/acpi_bus.h21
-rw-r--r--include/acpi/acpi_drivers.h5
-rw-r--r--include/acpi/acpiosxf.h18
-rw-r--r--include/acpi/acpixf.h13
-rw-r--r--include/acpi/acresrc.h67
-rw-r--r--include/acpi/acstruct.h1
-rw-r--r--include/acpi/actables.h70
-rw-r--r--include/acpi/actbl.h2
-rw-r--r--include/acpi/actypes.h2
-rw-r--r--include/acpi/acutils.h274
-rw-r--r--include/acpi/amlcode.h12
-rw-r--r--include/acpi/pdc_intel.h29
-rw-r--r--include/acpi/platform/acenv.h20
-rw-r--r--include/acpi/processor.h34
-rw-r--r--include/asm-alpha/pci.h2
-rw-r--r--include/asm-alpha/pgtable.h4
-rw-r--r--include/asm-arm/pci.h2
-rw-r--r--include/asm-arm/smp.h3
-rw-r--r--include/asm-h8300/pci.h2
-rw-r--r--include/asm-i386/acpi.h10
-rw-r--r--include/asm-i386/apicdef.h6
-rw-r--r--include/asm-i386/pci.h2
-rw-r--r--include/asm-i386/unistd.h5
-rw-r--r--include/asm-ia64/acpi.h9
-rw-r--r--include/asm-ia64/pci.h2
-rw-r--r--include/asm-m68k/pci.h2
-rw-r--r--include/asm-mips/pci.h2
-rw-r--r--include/asm-ppc/kexec.h2
-rw-r--r--include/asm-ppc/pci.h2
-rw-r--r--include/asm-ppc64/pci.h2
-rw-r--r--include/asm-sh/pci.h2
-rw-r--r--include/asm-sh64/pci.h2
-rw-r--r--include/asm-sparc/pci.h2
-rw-r--r--include/asm-sparc64/pci.h2
-rw-r--r--include/asm-sparc64/seccomp.h21
-rw-r--r--include/asm-um/mmu_context.h4
-rw-r--r--include/asm-x86_64/acpi.h8
-rw-r--r--include/asm-x86_64/pci.h2
-rw-r--r--include/linux/acpi.h7
-rw-r--r--include/linux/device.h6
-rw-r--r--include/linux/etherdevice.h2
-rw-r--r--include/linux/ext3_fs.h14
-rw-r--r--include/linux/fddidevice.h2
-rw-r--r--include/linux/fs.h6
-rw-r--r--include/linux/fsnotify.h248
-rw-r--r--include/linux/hardirq.h1
-rw-r--r--include/linux/hdlc.h4
-rw-r--r--include/linux/inotify.h108
-rw-r--r--include/linux/mount.h2
-rw-r--r--include/linux/netlink.h1
-rw-r--r--include/linux/pm.h2
-rw-r--r--include/linux/reiserfs_acl.h52
-rw-r--r--include/linux/reiserfs_fs.h1595
-rw-r--r--include/linux/reiserfs_fs_i.h59
-rw-r--r--include/linux/reiserfs_fs_sb.h616
-rw-r--r--include/linux/reiserfs_xattr.h126
-rw-r--r--include/linux/sched.h4
-rw-r--r--include/linux/swap.h2
-rw-r--r--include/linux/sysctl.h9
-rw-r--r--include/linux/usb.h8
-rw-r--r--include/linux/usb_cdc.h13
-rw-r--r--include/linux/usb_gadget.h12
-rw-r--r--include/linux/wanrouter.h3
-rw-r--r--include/media/audiochip.h3
-rw-r--r--include/media/saa6752hs.h49
-rw-r--r--include/media/tuner.h51
-rw-r--r--include/net/sctp/sctp.h3
-rw-r--r--include/net/sctp/sm.h11
-rw-r--r--include/net/sctp/structs.h30
-rw-r--r--include/net/sctp/ulpevent.h16
-rw-r--r--include/net/sctp/ulpqueue.h11
-rw-r--r--include/net/x25device.h3
-rw-r--r--include/pcmcia/ds.h5
-rw-r--r--init/do_mounts.c1
-rw-r--r--init/do_mounts.h1
-rw-r--r--ipc/util.h2
-rw-r--r--kernel/fork.c4
-rw-r--r--kernel/power/disk.c2
-rw-r--r--kernel/power/main.c16
-rw-r--r--kernel/power/swsusp.c3
-rw-r--r--kernel/sys_ni.c3
-rw-r--r--kernel/sysctl.c14
-rw-r--r--kernel/user.c4
-rw-r--r--mm/filemap_xip.c2
-rw-r--r--net/802/fddi.c4
-rw-r--r--net/8021q/Kconfig19
-rw-r--r--net/8021q/vlan.c8
-rw-r--r--net/Kconfig456
-rw-r--r--net/atm/Kconfig74
-rw-r--r--net/atm/br2684.c3
-rw-r--r--net/bridge/Kconfig31
-rw-r--r--net/decnet/Kconfig23
-rw-r--r--net/econet/Kconfig36
-rw-r--r--net/ethernet/eth.c2
-rw-r--r--net/ipv4/Kconfig25
-rw-r--r--net/ipv4/ip_output.c9
-rw-r--r--net/ipv4/ipvs/Kconfig4
-rw-r--r--net/ipv4/ipvs/ip_vs_conn.c6
-rw-r--r--net/ipv4/ipvs/ip_vs_ctl.c9
-rw-r--r--net/ipv4/netfilter/ip_conntrack_standalone.c7
-rw-r--r--net/ipv4/route.c2
-rw-r--r--net/ipv6/Kconfig22
-rw-r--r--net/ipx/Kconfig33
-rw-r--r--net/lapb/Kconfig22
-rw-r--r--net/packet/Kconfig26
-rw-r--r--net/packet/af_packet.c6
-rw-r--r--net/sched/Kconfig37
-rw-r--r--net/sctp/associola.c13
-rw-r--r--net/sctp/bind_addr.c16
-rw-r--r--net/sctp/chunk.c2
-rw-r--r--net/sctp/endpointola.c6
-rw-r--r--net/sctp/protocol.c2
-rw-r--r--net/sctp/sm_make_chunk.c15
-rw-r--r--net/sctp/sm_sideeffect.c13
-rw-r--r--net/sctp/ssnmap.c3
-rw-r--r--net/sctp/transport.c5
-rw-r--r--net/sctp/ulpevent.c19
-rw-r--r--net/sctp/ulpqueue.c9
-rw-r--r--net/unix/Kconfig21
-rw-r--r--net/wanrouter/Kconfig29
-rw-r--r--net/wanrouter/wanmain.c6
-rw-r--r--net/x25/Kconfig36
-rw-r--r--net/xfrm/Kconfig15
-rwxr-xr-xscripts/Lindent2
591 files changed, 40788 insertions, 34072 deletions
diff --git a/Documentation/acpi-hotkey.txt b/Documentation/acpi-hotkey.txt
new file mode 100644
index 000000000000..4c115a7bb826
--- /dev/null
+++ b/Documentation/acpi-hotkey.txt
@@ -0,0 +1,35 @@
1driver/acpi/hotkey.c implement:
21. /proc/acpi/hotkey/event_config
3(event based hotkey or event config interface):
4a. add a event based hotkey(event) :
5echo "0:bus::action:method:num:num" > event_config
6
7b. delete a event based hotkey(event):
8echo "1:::::num:num" > event_config
9
10c. modify a event based hotkey(event):
11echo "2:bus::action:method:num:num" > event_config
12
132. /proc/acpi/hotkey/poll_config
14(polling based hotkey or event config interface):
15a.add a polling based hotkey(event) :
16echo "0:bus:method:action:method:num" > poll_config
17this adding command will create a proc file
18/proc/acpi/hotkey/method, which is used to get
19result of polling.
20
21b.delete a polling based hotkey(event):
22echo "1:::::num" > event_config
23
24c.modify a polling based hotkey(event):
25echo "2:bus:method:action:method:num" > poll_config
26
273./proc/acpi/hotkey/action
28(interface to call aml method associated with a
29specific hotkey(event))
30echo "event_num:event_type:event_argument" >
31 /proc/acpi/hotkey/action.
32The result of the execution of this aml method is
33attached to /proc/acpi/hotkey/poll_method, which is dnyamically
34created. Please use command "cat /proc/acpi/hotkey/polling_method"
35to retrieve it.
diff --git a/Documentation/filesystems/inotify.txt b/Documentation/filesystems/inotify.txt
new file mode 100644
index 000000000000..2c716041f578
--- /dev/null
+++ b/Documentation/filesystems/inotify.txt
@@ -0,0 +1,138 @@
1 inotify
2 a powerful yet simple file change notification system
3
4
5
6Document started 15 Mar 2005 by Robert Love <rml@novell.com>
7
8(i) User Interface
9
10Inotify is controlled by a set of three sys calls
11
12First step in using inotify is to initialise an inotify instance
13
14 int fd = inotify_init ();
15
16Change events are managed by "watches". A watch is an (object,mask) pair where
17the object is a file or directory and the mask is a bit mask of one or more
18inotify events that the application wishes to receive. See <linux/inotify.h>
19for valid events. A watch is referenced by a watch descriptor, or wd.
20
21Watches are added via a path to the file.
22
23Watches on a directory will return events on any files inside of the directory.
24
25Adding a watch is simple,
26
27 int wd = inotify_add_watch (fd, path, mask);
28
29You can add a large number of files via something like
30
31 for each file to watch {
32 int wd = inotify_add_watch (fd, file, mask);
33 }
34
35You can update an existing watch in the same manner, by passing in a new mask.
36
37An existing watch is removed via the INOTIFY_IGNORE ioctl, for example
38
39 inotify_rm_watch (fd, wd);
40
41Events are provided in the form of an inotify_event structure that is read(2)
42from a inotify instance fd. The filename is of dynamic length and follows the
43struct. It is of size len. The filename is padded with null bytes to ensure
44proper alignment. This padding is reflected in len.
45
46You can slurp multiple events by passing a large buffer, for example
47
48 size_t len = read (fd, buf, BUF_LEN);
49
50Will return as many events as are available and fit in BUF_LEN.
51
52each inotify instance fd is also select()- and poll()-able.
53
54You can find the size of the current event queue via the FIONREAD ioctl.
55
56All watches are destroyed and cleaned up on close.
57
58
59(ii) Internal Kernel Implementation
60
61Each open inotify instance is associated with an inotify_device structure.
62
63Each watch is associated with an inotify_watch structure. Watches are chained
64off of each associated device and each associated inode.
65
66See fs/inotify.c for the locking and lifetime rules.
67
68
69(iii) Rationale
70
71Q: What is the design decision behind not tying the watch to the open fd of
72 the watched object?
73
74A: Watches are associated with an open inotify device, not an open file.
75 This solves the primary problem with dnotify: keeping the file open pins
76 the file and thus, worse, pins the mount. Dnotify is therefore infeasible
77 for use on a desktop system with removable media as the media cannot be
78 unmounted.
79
80Q: What is the design decision behind using an-fd-per-device as opposed to
81 an fd-per-watch?
82
83A: An fd-per-watch quickly consumes more file descriptors than are allowed,
84 more fd's than are feasible to manage, and more fd's than are optimally
85 select()-able. Yes, root can bump the per-process fd limit and yes, users
86 can use epoll, but requiring both is a silly and extraneous requirement.
87 A watch consumes less memory than an open file, separating the number
88 spaces is thus sensible. The current design is what user-space developers
89 want: Users initialize inotify, once, and add n watches, requiring but one fd
90 and no twiddling with fd limits. Initializing an inotify instance two
91 thousand times is silly. If we can implement user-space's preferences
92 cleanly--and we can, the idr layer makes stuff like this trivial--then we
93 should.
94
95 There are other good arguments. With a single fd, there is a single
96 item to block on, which is mapped to a single queue of events. The single
97 fd returns all watch events and also any potential out-of-band data. If
98 every fd was a separate watch,
99
100 - There would be no way to get event ordering. Events on file foo and
101 file bar would pop poll() on both fd's, but there would be no way to tell
102 which happened first. A single queue trivially gives you ordering. Such
103 ordering is crucial to existing applications such as Beagle. Imagine
104 "mv a b ; mv b a" events without ordering.
105
106 - We'd have to maintain n fd's and n internal queues with state,
107 versus just one. It is a lot messier in the kernel. A single, linear
108 queue is the data structure that makes sense.
109
110 - User-space developers prefer the current API. The Beagle guys, for
111 example, love it. Trust me, I asked. It is not a surprise: Who'd want
112 to manage and block on 1000 fd's via select?
113
114 - You'd have to manage the fd's, as an example: Call close() when you
115 received a delete event.
116
117 - No way to get out of band data.
118
119 - 1024 is still too low. ;-)
120
121 When you talk about designing a file change notification system that
122 scales to 1000s of directories, juggling 1000s of fd's just does not seem
123 the right interface. It is too heavy.
124
125Q: Why the system call approach?
126
127A: The poor user-space interface is the second biggest problem with dnotify.
128 Signals are a terrible, terrible interface for file notification. Or for
129 anything, for that matter. The ideal solution, from all perspectives, is a
130 file descriptor-based one that allows basic file I/O and poll/select.
131 Obtaining the fd and managing the watches could have been done either via a
132 device file or a family of new system calls. We decided to implement a
133 family of system calls because that is the preffered approach for new kernel
134 features and it means our user interface requirements.
135
136 Additionally, it _is_ possible to more than one instance and
137 juggle more than one queue and thus more than one associated fd.
138
diff --git a/Documentation/i2c/chips/adm1021 b/Documentation/hwmon/adm1021
index 03d02bfb3df1..03d02bfb3df1 100644
--- a/Documentation/i2c/chips/adm1021
+++ b/Documentation/hwmon/adm1021
diff --git a/Documentation/i2c/chips/adm1025 b/Documentation/hwmon/adm1025
index 39d2b781b5d6..39d2b781b5d6 100644
--- a/Documentation/i2c/chips/adm1025
+++ b/Documentation/hwmon/adm1025
diff --git a/Documentation/i2c/chips/adm1026 b/Documentation/hwmon/adm1026
index 473c689d7924..473c689d7924 100644
--- a/Documentation/i2c/chips/adm1026
+++ b/Documentation/hwmon/adm1026
diff --git a/Documentation/i2c/chips/adm1031 b/Documentation/hwmon/adm1031
index 130a38382b98..130a38382b98 100644
--- a/Documentation/i2c/chips/adm1031
+++ b/Documentation/hwmon/adm1031
diff --git a/Documentation/i2c/chips/adm9240 b/Documentation/hwmon/adm9240
index 35f618f32896..35f618f32896 100644
--- a/Documentation/i2c/chips/adm9240
+++ b/Documentation/hwmon/adm9240
diff --git a/Documentation/i2c/chips/asb100 b/Documentation/hwmon/asb100
index ab7365e139be..ab7365e139be 100644
--- a/Documentation/i2c/chips/asb100
+++ b/Documentation/hwmon/asb100
diff --git a/Documentation/i2c/chips/ds1621 b/Documentation/hwmon/ds1621
index 1fee6f1e6bc5..1fee6f1e6bc5 100644
--- a/Documentation/i2c/chips/ds1621
+++ b/Documentation/hwmon/ds1621
diff --git a/Documentation/i2c/chips/fscher b/Documentation/hwmon/fscher
index 64031659aff3..64031659aff3 100644
--- a/Documentation/i2c/chips/fscher
+++ b/Documentation/hwmon/fscher
diff --git a/Documentation/i2c/chips/gl518sm b/Documentation/hwmon/gl518sm
index ce0881883bca..ce0881883bca 100644
--- a/Documentation/i2c/chips/gl518sm
+++ b/Documentation/hwmon/gl518sm
diff --git a/Documentation/i2c/chips/it87 b/Documentation/hwmon/it87
index 0d0195040d88..0d0195040d88 100644
--- a/Documentation/i2c/chips/it87
+++ b/Documentation/hwmon/it87
diff --git a/Documentation/i2c/chips/lm63 b/Documentation/hwmon/lm63
index 31660bf97979..31660bf97979 100644
--- a/Documentation/i2c/chips/lm63
+++ b/Documentation/hwmon/lm63
diff --git a/Documentation/i2c/chips/lm75 b/Documentation/hwmon/lm75
index 8e6356fe05d7..8e6356fe05d7 100644
--- a/Documentation/i2c/chips/lm75
+++ b/Documentation/hwmon/lm75
diff --git a/Documentation/i2c/chips/lm77 b/Documentation/hwmon/lm77
index 57c3a46d6370..57c3a46d6370 100644
--- a/Documentation/i2c/chips/lm77
+++ b/Documentation/hwmon/lm77
diff --git a/Documentation/i2c/chips/lm78 b/Documentation/hwmon/lm78
index 357086ed7f64..357086ed7f64 100644
--- a/Documentation/i2c/chips/lm78
+++ b/Documentation/hwmon/lm78
diff --git a/Documentation/i2c/chips/lm80 b/Documentation/hwmon/lm80
index cb5b407ba3e6..cb5b407ba3e6 100644
--- a/Documentation/i2c/chips/lm80
+++ b/Documentation/hwmon/lm80
diff --git a/Documentation/i2c/chips/lm83 b/Documentation/hwmon/lm83
index 061d9ed8ff43..061d9ed8ff43 100644
--- a/Documentation/i2c/chips/lm83
+++ b/Documentation/hwmon/lm83
diff --git a/Documentation/i2c/chips/lm85 b/Documentation/hwmon/lm85
index 9549237530cf..9549237530cf 100644
--- a/Documentation/i2c/chips/lm85
+++ b/Documentation/hwmon/lm85
diff --git a/Documentation/i2c/chips/lm87 b/Documentation/hwmon/lm87
index c952c57f0e11..c952c57f0e11 100644
--- a/Documentation/i2c/chips/lm87
+++ b/Documentation/hwmon/lm87
diff --git a/Documentation/i2c/chips/lm90 b/Documentation/hwmon/lm90
index 2c4cf39471f4..2c4cf39471f4 100644
--- a/Documentation/i2c/chips/lm90
+++ b/Documentation/hwmon/lm90
diff --git a/Documentation/i2c/chips/lm92 b/Documentation/hwmon/lm92
index 7705bfaa0708..7705bfaa0708 100644
--- a/Documentation/i2c/chips/lm92
+++ b/Documentation/hwmon/lm92
diff --git a/Documentation/i2c/chips/max1619 b/Documentation/hwmon/max1619
index d6f8d9cd7d7f..d6f8d9cd7d7f 100644
--- a/Documentation/i2c/chips/max1619
+++ b/Documentation/hwmon/max1619
diff --git a/Documentation/i2c/chips/pc87360 b/Documentation/hwmon/pc87360
index 89a8fcfa78df..89a8fcfa78df 100644
--- a/Documentation/i2c/chips/pc87360
+++ b/Documentation/hwmon/pc87360
diff --git a/Documentation/i2c/chips/sis5595 b/Documentation/hwmon/sis5595
index b7ae36b8cdf5..b7ae36b8cdf5 100644
--- a/Documentation/i2c/chips/sis5595
+++ b/Documentation/hwmon/sis5595
diff --git a/Documentation/i2c/chips/smsc47b397 b/Documentation/hwmon/smsc47b397
index da9d80c96432..da9d80c96432 100644
--- a/Documentation/i2c/chips/smsc47b397
+++ b/Documentation/hwmon/smsc47b397
diff --git a/Documentation/i2c/chips/smsc47m1 b/Documentation/hwmon/smsc47m1
index 34e6478c1425..34e6478c1425 100644
--- a/Documentation/i2c/chips/smsc47m1
+++ b/Documentation/hwmon/smsc47m1
diff --git a/Documentation/i2c/sysfs-interface b/Documentation/hwmon/sysfs-interface
index 346400519d0d..346400519d0d 100644
--- a/Documentation/i2c/sysfs-interface
+++ b/Documentation/hwmon/sysfs-interface
diff --git a/Documentation/i2c/userspace-tools b/Documentation/hwmon/userspace-tools
index 2622aac65422..2622aac65422 100644
--- a/Documentation/i2c/userspace-tools
+++ b/Documentation/hwmon/userspace-tools
diff --git a/Documentation/i2c/chips/via686a b/Documentation/hwmon/via686a
index b82014cb7c53..b82014cb7c53 100644
--- a/Documentation/i2c/chips/via686a
+++ b/Documentation/hwmon/via686a
diff --git a/Documentation/i2c/chips/w83627hf b/Documentation/hwmon/w83627hf
index 78f37c2d602e..78f37c2d602e 100644
--- a/Documentation/i2c/chips/w83627hf
+++ b/Documentation/hwmon/w83627hf
diff --git a/Documentation/i2c/chips/w83781d b/Documentation/hwmon/w83781d
index e5459333ba68..e5459333ba68 100644
--- a/Documentation/i2c/chips/w83781d
+++ b/Documentation/hwmon/w83781d
diff --git a/Documentation/i2c/chips/w83l785ts b/Documentation/hwmon/w83l785ts
index 1841cedc25b2..1841cedc25b2 100644
--- a/Documentation/i2c/chips/w83l785ts
+++ b/Documentation/hwmon/w83l785ts
diff --git a/Documentation/i2c/chips/max6875 b/Documentation/i2c/chips/max6875
index b4fb49b41813..b02002898a09 100644
--- a/Documentation/i2c/chips/max6875
+++ b/Documentation/i2c/chips/max6875
@@ -2,10 +2,10 @@ Kernel driver max6875
2===================== 2=====================
3 3
4Supported chips: 4Supported chips:
5 * Maxim max6874, max6875 5 * Maxim MAX6874, MAX6875
6 Prefixes: 'max6875' 6 Prefix: 'max6875'
7 Addresses scanned: 0x50, 0x52 7 Addresses scanned: 0x50, 0x52
8 Datasheets: 8 Datasheet:
9 http://pdfserv.maxim-ic.com/en/ds/MAX6874-MAX6875.pdf 9 http://pdfserv.maxim-ic.com/en/ds/MAX6874-MAX6875.pdf
10 10
11Author: Ben Gardner <bgardner@wabtec.com> 11Author: Ben Gardner <bgardner@wabtec.com>
@@ -23,14 +23,26 @@ Module Parameters
23Description 23Description
24----------- 24-----------
25 25
26The MAXIM max6875 is a EEPROM-programmable power-supply sequencer/supervisor. 26The Maxim MAX6875 is an EEPROM-programmable power-supply sequencer/supervisor.
27It provides timed outputs that can be used as a watchdog, if properly wired. 27It provides timed outputs that can be used as a watchdog, if properly wired.
28It also provides 512 bytes of user EEPROM. 28It also provides 512 bytes of user EEPROM.
29 29
30At reset, the max6875 reads the configuration eeprom into its configuration 30At reset, the MAX6875 reads the configuration EEPROM into its configuration
31registers. The chip then begins to operate according to the values in the 31registers. The chip then begins to operate according to the values in the
32registers. 32registers.
33 33
34The Maxim MAX6874 is a similar, mostly compatible device, with more intputs
35and outputs:
36
37 vin gpi vout
38MAX6874 6 4 8
39MAX6875 4 3 5
40
41MAX6874 chips can have four different addresses (as opposed to only two for
42the MAX6875). The additional addresses (0x54 and 0x56) are not probed by
43this driver by default, but the probe module parameter can be used if
44needed.
45
34See the datasheet for details on how to program the EEPROM. 46See the datasheet for details on how to program the EEPROM.
35 47
36 48
diff --git a/Documentation/i2c/dev-interface b/Documentation/i2c/dev-interface
index 09d6cda2a1fb..b849ad636583 100644
--- a/Documentation/i2c/dev-interface
+++ b/Documentation/i2c/dev-interface
@@ -14,9 +14,12 @@ C example
14========= 14=========
15 15
16So let's say you want to access an i2c adapter from a C program. The 16So let's say you want to access an i2c adapter from a C program. The
17first thing to do is `#include <linux/i2c.h>" and "#include <linux/i2c-dev.h>. 17first thing to do is "#include <linux/i2c-dev.h>". Please note that
18Yes, I know, you should never include kernel header files, but until glibc 18there are two files named "i2c-dev.h" out there, one is distributed
19knows about i2c, there is not much choice. 19with the Linux kernel and is meant to be included from kernel
20driver code, the other one is distributed with lm_sensors and is
21meant to be included from user-space programs. You obviously want
22the second one here.
20 23
21Now, you have to decide which adapter you want to access. You should 24Now, you have to decide which adapter you want to access. You should
22inspect /sys/class/i2c-dev/ to decide this. Adapter numbers are assigned 25inspect /sys/class/i2c-dev/ to decide this. Adapter numbers are assigned
@@ -78,7 +81,7 @@ Full interface description
78========================== 81==========================
79 82
80The following IOCTLs are defined and fully supported 83The following IOCTLs are defined and fully supported
81(see also i2c-dev.h and i2c.h): 84(see also i2c-dev.h):
82 85
83ioctl(file,I2C_SLAVE,long addr) 86ioctl(file,I2C_SLAVE,long addr)
84 Change slave address. The address is passed in the 7 lower bits of the 87 Change slave address. The address is passed in the 7 lower bits of the
@@ -97,10 +100,10 @@ ioctl(file,I2C_PEC,long select)
97ioctl(file,I2C_FUNCS,unsigned long *funcs) 100ioctl(file,I2C_FUNCS,unsigned long *funcs)
98 Gets the adapter functionality and puts it in *funcs. 101 Gets the adapter functionality and puts it in *funcs.
99 102
100ioctl(file,I2C_RDWR,struct i2c_ioctl_rdwr_data *msgset) 103ioctl(file,I2C_RDWR,struct i2c_rdwr_ioctl_data *msgset)
101 104
102 Do combined read/write transaction without stop in between. 105 Do combined read/write transaction without stop in between.
103 The argument is a pointer to a struct i2c_ioctl_rdwr_data { 106 The argument is a pointer to a struct i2c_rdwr_ioctl_data {
104 107
105 struct i2c_msg *msgs; /* ptr to array of simple messages */ 108 struct i2c_msg *msgs; /* ptr to array of simple messages */
106 int nmsgs; /* number of messages to exchange */ 109 int nmsgs; /* number of messages to exchange */
diff --git a/Documentation/i2c/writing-clients b/Documentation/i2c/writing-clients
index f482dae81de3..91664be91ffc 100644
--- a/Documentation/i2c/writing-clients
+++ b/Documentation/i2c/writing-clients
@@ -27,7 +27,6 @@ address.
27static struct i2c_driver foo_driver = { 27static struct i2c_driver foo_driver = {
28 .owner = THIS_MODULE, 28 .owner = THIS_MODULE,
29 .name = "Foo version 2.3 driver", 29 .name = "Foo version 2.3 driver",
30 .id = I2C_DRIVERID_FOO, /* from i2c-id.h, optional */
31 .flags = I2C_DF_NOTIFY, 30 .flags = I2C_DF_NOTIFY,
32 .attach_adapter = &foo_attach_adapter, 31 .attach_adapter = &foo_attach_adapter,
33 .detach_client = &foo_detach_client, 32 .detach_client = &foo_detach_client,
@@ -37,12 +36,6 @@ static struct i2c_driver foo_driver = {
37The name can be chosen freely, and may be upto 40 characters long. Please 36The name can be chosen freely, and may be upto 40 characters long. Please
38use something descriptive here. 37use something descriptive here.
39 38
40If used, the id should be a unique ID. The range 0xf000 to 0xffff is
41reserved for local use, and you can use one of those until you start
42distributing the driver, at which time you should contact the i2c authors
43to get your own ID(s). Note that most of the time you don't need an ID
44at all so you can just omit it.
45
46Don't worry about the flags field; just put I2C_DF_NOTIFY into it. This 39Don't worry about the flags field; just put I2C_DF_NOTIFY into it. This
47means that your driver will be notified when new adapters are found. 40means that your driver will be notified when new adapters are found.
48This is almost always what you want. 41This is almost always what you want.
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index 753db6d8b745..a998a8c2f95b 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -37,7 +37,7 @@ restrictions referred to are that the relevant option is valid if:
37 IA-32 IA-32 aka i386 architecture is enabled. 37 IA-32 IA-32 aka i386 architecture is enabled.
38 IA-64 IA-64 architecture is enabled. 38 IA-64 IA-64 architecture is enabled.
39 IOSCHED More than one I/O scheduler is enabled. 39 IOSCHED More than one I/O scheduler is enabled.
40 IP_PNP IP DCHP, BOOTP, or RARP is enabled. 40 IP_PNP IP DHCP, BOOTP, or RARP is enabled.
41 ISAPNP ISA PnP code is enabled. 41 ISAPNP ISA PnP code is enabled.
42 ISDN Appropriate ISDN support is enabled. 42 ISDN Appropriate ISDN support is enabled.
43 JOY Appropriate joystick support is enabled. 43 JOY Appropriate joystick support is enabled.
diff --git a/Documentation/pcmcia/driver-changes.txt b/Documentation/pcmcia/driver-changes.txt
index 9c315ab48a02..59ccc63838c1 100644
--- a/Documentation/pcmcia/driver-changes.txt
+++ b/Documentation/pcmcia/driver-changes.txt
@@ -1,6 +1,13 @@
1This file details changes in 2.6 which affect PCMCIA card driver authors: 1This file details changes in 2.6 which affect PCMCIA card driver authors:
2 2
3* in-kernel device<->driver matching 3* event handler initialization in struct pcmcia_driver (as of 2.6.13)
4 The event handler is notified of all events, and must be initialized
5 as the event() callback in the driver's struct pcmcia_driver.
6
7* pcmcia/version.h should not be used (as of 2.6.13)
8 This file will be removed eventually.
9
10* in-kernel device<->driver matching (as of 2.6.13)
4 PCMCIA devices and their correct drivers can now be matched in 11 PCMCIA devices and their correct drivers can now be matched in
5 kernelspace. See 'devicetable.txt' for details. 12 kernelspace. See 'devicetable.txt' for details.
6 13
diff --git a/Documentation/usb/sn9c102.txt b/Documentation/usb/sn9c102.txt
index cf9a1187edce..3f8a119db31b 100644
--- a/Documentation/usb/sn9c102.txt
+++ b/Documentation/usb/sn9c102.txt
@@ -297,6 +297,7 @@ Vendor ID Product ID
2970x0c45 0x602a 2970x0c45 0x602a
2980x0c45 0x602b 2980x0c45 0x602b
2990x0c45 0x602c 2990x0c45 0x602c
3000x0c45 0x602d
3000x0c45 0x6030 3010x0c45 0x6030
3010x0c45 0x6080 3020x0c45 0x6080
3020x0c45 0x6082 3030x0c45 0x6082
@@ -333,6 +334,7 @@ Model Manufacturer
333----- ------------ 334----- ------------
334HV7131D Hynix Semiconductor, Inc. 335HV7131D Hynix Semiconductor, Inc.
335MI-0343 Micron Technology, Inc. 336MI-0343 Micron Technology, Inc.
337OV7630 OmniVision Technologies, Inc.
336PAS106B PixArt Imaging, Inc. 338PAS106B PixArt Imaging, Inc.
337PAS202BCB PixArt Imaging, Inc. 339PAS202BCB PixArt Imaging, Inc.
338TAS5110C1B Taiwan Advanced Sensor Corporation 340TAS5110C1B Taiwan Advanced Sensor Corporation
@@ -470,9 +472,11 @@ order):
470- Luca Capello for the donation of a webcam; 472- Luca Capello for the donation of a webcam;
471- Joao Rodrigo Fuzaro, Joao Limirio, Claudio Filho and Caio Begotti for the 473- Joao Rodrigo Fuzaro, Joao Limirio, Claudio Filho and Caio Begotti for the
472 donation of a webcam; 474 donation of a webcam;
475- Jon Hollstrom for the donation of a webcam;
473- Carlos Eduardo Medaglia Dyonisio, who added the support for the PAS202BCB 476- Carlos Eduardo Medaglia Dyonisio, who added the support for the PAS202BCB
474 image sensor; 477 image sensor;
475- Stefano Mozzi, who donated 45 EU; 478- Stefano Mozzi, who donated 45 EU;
479- Andrew Pearce for the donation of a webcam;
476- Bertrik Sikken, who reverse-engineered and documented the Huffman compression 480- Bertrik Sikken, who reverse-engineered and documented the Huffman compression
477 algorithm used in the SN9C10x controllers and implemented the first decoder; 481 algorithm used in the SN9C10x controllers and implemented the first decoder;
478- Mizuno Takafumi for the donation of a webcam; 482- Mizuno Takafumi for the donation of a webcam;
diff --git a/Documentation/usb/usbmon.txt b/Documentation/usb/usbmon.txt
index 2f8431f92b77..f1896ee3bb2a 100644
--- a/Documentation/usb/usbmon.txt
+++ b/Documentation/usb/usbmon.txt
@@ -101,6 +101,13 @@ Here is the list of words, from left to right:
101 or 3 and 2 positions, correspondingly. 101 or 3 and 2 positions, correspondingly.
102- URB Status. This field makes no sense for submissions, but is present 102- URB Status. This field makes no sense for submissions, but is present
103 to help scripts with parsing. In error case, it contains the error code. 103 to help scripts with parsing. In error case, it contains the error code.
104 In case of a setup packet, it contains a Setup Tag. If scripts read a number
105 in this field, the proceed to read Data Length. Otherwise, they read
106 the setup packet before reading the Data Length.
107- Setup packet, if present, consists of 5 words: one of each for bmRequestType,
108 bRequest, wValue, wIndex, wLength, as specified by the USB Specification 2.0.
109 These words are safe to decode if Setup Tag was 's'. Otherwise, the setup
110 packet was present, but not captured, and the fields contain filler.
104- Data Length. This is the actual length in the URB. 111- Data Length. This is the actual length in the URB.
105- Data tag. The usbmon may not always capture data, even if length is nonzero. 112- Data tag. The usbmon may not always capture data, even if length is nonzero.
106 Only if tag is '=', the data words are present. 113 Only if tag is '=', the data words are present.
@@ -125,25 +132,31 @@ class ParsedLine {
125 String data_str = st.nextToken(); 132 String data_str = st.nextToken();
126 int len = data_str.length() / 2; 133 int len = data_str.length() / 2;
127 int i; 134 int i;
135 int b; // byte is signed, apparently?! XXX
128 for (i = 0; i < len; i++) { 136 for (i = 0; i < len; i++) {
129 data[data_len] = Byte.parseByte( 137 // data[data_len] = Byte.parseByte(
130 data_str.substring(i*2, i*2 + 2), 138 // data_str.substring(i*2, i*2 + 2),
131 16); 139 // 16);
140 b = Integer.parseInt(
141 data_str.substring(i*2, i*2 + 2),
142 16);
143 if (b >= 128)
144 b *= -1;
145 data[data_len] = (byte) b;
132 data_len++; 146 data_len++;
133 } 147 }
134 } 148 }
135 } 149 }
136} 150}
137 151
138This format is obviously deficient. For example, the setup packet for control 152This format may be changed in the future.
139transfers is not delivered. This will change in the future.
140 153
141Examples: 154Examples:
142 155
143An input control transfer to get a port status: 156An input control transfer to get a port status.
144 157
145d74ff9a0 2640288196 S Ci:001:00 -115 4 < 158d5ea89a0 3575914555 S Ci:001:00 s a3 00 0000 0003 0004 4 <
146d74ff9a0 2640288202 C Ci:001:00 0 4 = 01010100 159d5ea89a0 3575914560 C Ci:001:00 0 4 = 01050000
147 160
148An output bulk transfer to send a SCSI command 0x5E in a 31-byte Bulk wrapper 161An output bulk transfer to send a SCSI command 0x5E in a 31-byte Bulk wrapper
149to a storage device at address 5: 162to a storage device at address 5:
diff --git a/Documentation/video4linux/CARDLIST.bttv b/Documentation/video4linux/CARDLIST.bttv
index aeeafec0594c..62a12a08e2ac 100644
--- a/Documentation/video4linux/CARDLIST.bttv
+++ b/Documentation/video4linux/CARDLIST.bttv
@@ -1,4 +1,4 @@
1card=0 - *** UNKNOWN/GENERIC *** 1card=0 - *** UNKNOWN/GENERIC ***
2card=1 - MIRO PCTV 2card=1 - MIRO PCTV
3card=2 - Hauppauge (bt848) 3card=2 - Hauppauge (bt848)
4card=3 - STB, Gateway P/N 6000699 (bt848) 4card=3 - STB, Gateway P/N 6000699 (bt848)
diff --git a/Documentation/video4linux/CARDLIST.cx88 b/Documentation/video4linux/CARDLIST.cx88
index 4377aa11f567..6d44958289de 100644
--- a/Documentation/video4linux/CARDLIST.cx88
+++ b/Documentation/video4linux/CARDLIST.cx88
@@ -27,3 +27,5 @@ card=25 - Digital-Logic MICROSPACE Entertainment Center (MEC)
27card=26 - IODATA GV/BCTV7E 27card=26 - IODATA GV/BCTV7E
28card=27 - PixelView PlayTV Ultra Pro (Stereo) 28card=27 - PixelView PlayTV Ultra Pro (Stereo)
29card=28 - DViCO FusionHDTV 3 Gold-T 29card=28 - DViCO FusionHDTV 3 Gold-T
30card=29 - ADS Tech Instant TV DVB-T PCI
31card=30 - TerraTec Cinergy 1400 DVB-T
diff --git a/Documentation/video4linux/CARDLIST.saa7134 b/Documentation/video4linux/CARDLIST.saa7134
index 735e8ba02d9f..1b5a3a9ffbe2 100644
--- a/Documentation/video4linux/CARDLIST.saa7134
+++ b/Documentation/video4linux/CARDLIST.saa7134
@@ -1,10 +1,10 @@
1 0 -> UNKNOWN/GENERIC 1 0 -> UNKNOWN/GENERIC
2 1 -> Proteus Pro [philips reference design] [1131:2001,1131:2001] 2 1 -> Proteus Pro [philips reference design] [1131:2001,1131:2001]
3 2 -> LifeView FlyVIDEO3000 [5168:0138,4e42:0138] 3 2 -> LifeView FlyVIDEO3000 [5168:0138,4e42:0138]
4 3 -> LifeView FlyVIDEO2000 [5168:0138] 4 3 -> LifeView FlyVIDEO2000 [5168:0138]
5 4 -> EMPRESS [1131:6752] 5 4 -> EMPRESS [1131:6752]
6 5 -> SKNet Monster TV [1131:4e85] 6 5 -> SKNet Monster TV [1131:4e85]
7 6 -> Tevion MD 9717 7 6 -> Tevion MD 9717
8 7 -> KNC One TV-Station RDS / Typhoon TV Tuner RDS [1131:fe01,1894:fe01] 8 7 -> KNC One TV-Station RDS / Typhoon TV Tuner RDS [1131:fe01,1894:fe01]
9 8 -> Terratec Cinergy 400 TV [153B:1142] 9 8 -> Terratec Cinergy 400 TV [153B:1142]
10 9 -> Medion 5044 10 9 -> Medion 5044
@@ -34,6 +34,7 @@
34 33 -> AVerMedia DVD EZMaker [1461:10ff] 34 33 -> AVerMedia DVD EZMaker [1461:10ff]
35 34 -> Noval Prime TV 7133 35 34 -> Noval Prime TV 7133
36 35 -> AverMedia AverTV Studio 305 [1461:2115] 36 35 -> AverMedia AverTV Studio 305 [1461:2115]
37 36 -> UPMOST PURPLE TV [12ab:0800]
37 37 -> Items MuchTV Plus / IT-005 38 37 -> Items MuchTV Plus / IT-005
38 38 -> Terratec Cinergy 200 TV [153B:1152] 39 38 -> Terratec Cinergy 200 TV [153B:1152]
39 39 -> LifeView FlyTV Platinum Mini [5168:0212] 40 39 -> LifeView FlyTV Platinum Mini [5168:0212]
@@ -43,20 +44,21 @@
43 43 -> :Zolid Xpert TV7134 44 43 -> :Zolid Xpert TV7134
44 44 -> Empire PCI TV-Radio LE 45 44 -> Empire PCI TV-Radio LE
45 45 -> Avermedia AVerTV Studio 307 [1461:9715] 46 45 -> Avermedia AVerTV Studio 307 [1461:9715]
46 46 -> AVerMedia Cardbus TV/Radio [1461:d6ee] 47 46 -> AVerMedia Cardbus TV/Radio (E500) [1461:d6ee]
47 47 -> Terratec Cinergy 400 mobile [153b:1162] 48 47 -> Terratec Cinergy 400 mobile [153b:1162]
48 48 -> Terratec Cinergy 600 TV MK3 [153B:1158] 49 48 -> Terratec Cinergy 600 TV MK3 [153B:1158]
49 49 -> Compro VideoMate Gold+ Pal [185b:c200] 50 49 -> Compro VideoMate Gold+ Pal [185b:c200]
50 50 -> Pinnacle PCTV 300i DVB-T + PAL [11bd:002d] 51 50 -> Pinnacle PCTV 300i DVB-T + PAL [11bd:002d]
51 51 -> ProVideo PV952 [1540:9524] 52 51 -> ProVideo PV952 [1540:9524]
52 52 -> AverMedia AverTV/305 [1461:2108] 53 52 -> AverMedia AverTV/305 [1461:2108]
54 53 -> ASUS TV-FM 7135 [1043:4845]
53 54 -> LifeView FlyTV Platinum FM [5168:0214,1489:0214] 55 54 -> LifeView FlyTV Platinum FM [5168:0214,1489:0214]
54 55 -> LifeView FlyDVB-T DUO [5168:0306] 56 55 -> LifeView FlyDVB-T DUO [5168:0502,5168:0306]
55 56 -> Avermedia AVerTV 307 [1461:a70a] 57 56 -> Avermedia AVerTV 307 [1461:a70a]
56 57 -> Avermedia AVerTV GO 007 FM [1461:f31f] 58 57 -> Avermedia AVerTV GO 007 FM [1461:f31f]
57 58 -> ADS Tech Instant TV (saa7135) [1421:0350,1421:0370] 59 58 -> ADS Tech Instant TV (saa7135) [1421:0350,1421:0370]
58 59 -> Kworld/Tevion V-Stream Xpert TV PVR7134 60 59 -> Kworld/Tevion V-Stream Xpert TV PVR7134
59 60 -> Typhoon DVB-T Duo Digital/Analog Cardbus 61 60 -> Typhoon DVB-T Duo Digital/Analog Cardbus [4e42:0502]
60 61 -> Philips TOUGH DVB-T reference design 62 61 -> Philips TOUGH DVB-T reference design [1131:2004]
61 62 -> Compro VideoMate TV Gold+II 63 62 -> Compro VideoMate TV Gold+II
62 63 -> Kworld Xpert TV PVR7134 64 63 -> Kworld Xpert TV PVR7134
diff --git a/Documentation/video4linux/CARDLIST.tuner b/Documentation/video4linux/CARDLIST.tuner
index e78020f68b2e..d1b9d21ffd89 100644
--- a/Documentation/video4linux/CARDLIST.tuner
+++ b/Documentation/video4linux/CARDLIST.tuner
@@ -56,9 +56,9 @@ tuner=54 - tda8290+75
56tuner=55 - LG PAL (TAPE series) 56tuner=55 - LG PAL (TAPE series)
57tuner=56 - Philips PAL/SECAM multi (FQ1216AME MK4) 57tuner=56 - Philips PAL/SECAM multi (FQ1216AME MK4)
58tuner=57 - Philips FQ1236A MK4 58tuner=57 - Philips FQ1236A MK4
59tuner=58 - Ymec TVision TVF-8531MF 59tuner=58 - Ymec TVision TVF-8531MF/8831MF/8731MF
60tuner=59 - Ymec TVision TVF-5533MF 60tuner=59 - Ymec TVision TVF-5533MF
61tuner=60 - Thomson DDT 7611 (ATSC/NTSC) 61tuner=60 - Thomson DDT 7611 (ATSC/NTSC)
62tuner=61 - Tena TNF9533-D/IF 62tuner=61 - Tena TNF9533-D/IF/TNF9533-B/DF
63tuner=62 - Philips TEA5767HN FM Radio 63tuner=62 - Philips TEA5767HN FM Radio
64tuner=63 - Philips FMD1216ME MK3 Hybrid Tuner 64tuner=63 - Philips FMD1216ME MK3 Hybrid Tuner
diff --git a/Documentation/video4linux/bttv/Cards b/Documentation/video4linux/bttv/Cards
index 7f8c7eb70ab2..8f1941ede4da 100644
--- a/Documentation/video4linux/bttv/Cards
+++ b/Documentation/video4linux/bttv/Cards
@@ -20,7 +20,7 @@ All other cards only differ by additional components as tuners, sound
20decoders, EEPROMs, teletext decoders ... 20decoders, EEPROMs, teletext decoders ...
21 21
22 22
23Unsupported Cards: 23Unsupported Cards:
24------------------ 24------------------
25 25
26Cards with Zoran (ZR) or Philips (SAA) or ISA are not supported by 26Cards with Zoran (ZR) or Philips (SAA) or ISA are not supported by
@@ -50,11 +50,11 @@ Bt848a/Bt849 single crytal operation support possible!!!
50Miro/Pinnacle PCTV 50Miro/Pinnacle PCTV
51------------------ 51------------------
52 52
53- Bt848 53- Bt848
54 some (all??) come with 2 crystals for PAL/SECAM and NTSC 54 some (all??) come with 2 crystals for PAL/SECAM and NTSC
55- PAL, SECAM or NTSC TV tuner (Philips or TEMIC) 55- PAL, SECAM or NTSC TV tuner (Philips or TEMIC)
56- MSP34xx sound decoder on add on board 56- MSP34xx sound decoder on add on board
57 decoder is supported but AFAIK does not yet work 57 decoder is supported but AFAIK does not yet work
58 (other sound MUX setting in GPIO port needed??? somebody who fixed this???) 58 (other sound MUX setting in GPIO port needed??? somebody who fixed this???)
59- 1 tuner, 1 composite and 1 S-VHS input 59- 1 tuner, 1 composite and 1 S-VHS input
60- tuner type is autodetected 60- tuner type is autodetected
@@ -70,7 +70,7 @@ in 1997!
70Hauppauge Win/TV pci 70Hauppauge Win/TV pci
71-------------------- 71--------------------
72 72
73There are many different versions of the Hauppauge cards with different 73There are many different versions of the Hauppauge cards with different
74tuners (TV+Radio ...), teletext decoders. 74tuners (TV+Radio ...), teletext decoders.
75Note that even cards with same model numbers have (depending on the revision) 75Note that even cards with same model numbers have (depending on the revision)
76different chips on it. 76different chips on it.
@@ -80,22 +80,22 @@ different chips on it.
80- PAL, SECAM, NTSC or tuner with or without Radio support 80- PAL, SECAM, NTSC or tuner with or without Radio support
81 81
82e.g.: 82e.g.:
83 PAL: 83 PAL:
84 TDA5737: VHF, hyperband and UHF mixer/oscillator for TV and VCR 3-band tuners 84 TDA5737: VHF, hyperband and UHF mixer/oscillator for TV and VCR 3-band tuners
85 TSA5522: 1.4 GHz I2C-bus controlled synthesizer, I2C 0xc2-0xc3 85 TSA5522: 1.4 GHz I2C-bus controlled synthesizer, I2C 0xc2-0xc3
86 86
87 NTSC: 87 NTSC:
88 TDA5731: VHF, hyperband and UHF mixer/oscillator for TV and VCR 3-band tuners 88 TDA5731: VHF, hyperband and UHF mixer/oscillator for TV and VCR 3-band tuners
89 TSA5518: no datasheet available on Philips site 89 TSA5518: no datasheet available on Philips site
90- Philips SAA5246 or SAA5284 ( or no) Teletext decoder chip 90- Philips SAA5246 or SAA5284 ( or no) Teletext decoder chip
91 with buffer RAM (e.g. Winbond W24257AS-35: 32Kx8 CMOS static RAM) 91 with buffer RAM (e.g. Winbond W24257AS-35: 32Kx8 CMOS static RAM)
92 SAA5246 (I2C 0x22) is supported 92 SAA5246 (I2C 0x22) is supported
93- 256 bytes EEPROM: Microchip 24LC02B or Philips 8582E2Y 93- 256 bytes EEPROM: Microchip 24LC02B or Philips 8582E2Y
94 with configuration information 94 with configuration information
95 I2C address 0xa0 (24LC02B also responds to 0xa2-0xaf) 95 I2C address 0xa0 (24LC02B also responds to 0xa2-0xaf)
96- 1 tuner, 1 composite and (depending on model) 1 S-VHS input 96- 1 tuner, 1 composite and (depending on model) 1 S-VHS input
97- 14052B: mux for selection of sound source 97- 14052B: mux for selection of sound source
98- sound decoder: TDA9800, MSP34xx (stereo cards) 98- sound decoder: TDA9800, MSP34xx (stereo cards)
99 99
100 100
101Askey CPH-Series 101Askey CPH-Series
@@ -108,17 +108,17 @@ Developed by TelSignal(?), OEMed by many vendors (Typhoon, Anubis, Dynalink)
108 CPH05x: BT878 with FM 108 CPH05x: BT878 with FM
109 CPH06x: BT878 (w/o FM) 109 CPH06x: BT878 (w/o FM)
110 CPH07x: BT878 capture only 110 CPH07x: BT878 capture only
111 111
112 TV standards: 112 TV standards:
113 CPH0x0: NTSC-M/M 113 CPH0x0: NTSC-M/M
114 CPH0x1: PAL-B/G 114 CPH0x1: PAL-B/G
115 CPH0x2: PAL-I/I 115 CPH0x2: PAL-I/I
116 CPH0x3: PAL-D/K 116 CPH0x3: PAL-D/K
117 CPH0x4: SECAM-L/L 117 CPH0x4: SECAM-L/L
118 CPH0x5: SECAM-B/G 118 CPH0x5: SECAM-B/G
119 CPH0x6: SECAM-D/K 119 CPH0x6: SECAM-D/K
120 CPH0x7: PAL-N/N 120 CPH0x7: PAL-N/N
121 CPH0x8: PAL-B/H 121 CPH0x8: PAL-B/H
122 CPH0x9: PAL-M/M 122 CPH0x9: PAL-M/M
123 123
124 CPH03x was often sold as "TV capturer". 124 CPH03x was often sold as "TV capturer".
@@ -174,7 +174,7 @@ Lifeview Flyvideo Series:
174 "The FlyVideo2000 and FlyVideo2000s product name have renamed to FlyVideo98." 174 "The FlyVideo2000 and FlyVideo2000s product name have renamed to FlyVideo98."
175 Their Bt8x8 cards are listed as discontinued. 175 Their Bt8x8 cards are listed as discontinued.
176 Flyvideo 2000S was probably sold as Flyvideo 3000 in some contries(Europe?). 176 Flyvideo 2000S was probably sold as Flyvideo 3000 in some contries(Europe?).
177 The new Flyvideo 2000/3000 are SAA7130/SAA7134 based. 177 The new Flyvideo 2000/3000 are SAA7130/SAA7134 based.
178 178
179 "Flyvideo II" had been the name for the 848 cards, nowadays (in Germany) 179 "Flyvideo II" had been the name for the 848 cards, nowadays (in Germany)
180 this name is re-used for LR50 Rev.W. 180 this name is re-used for LR50 Rev.W.
@@ -235,12 +235,12 @@ Prolink
235 Multimedia TV packages (card + software pack): 235 Multimedia TV packages (card + software pack):
236 PixelView Play TV Theater - (Model: PV-M4200) = PixelView Play TV pro + Software 236 PixelView Play TV Theater - (Model: PV-M4200) = PixelView Play TV pro + Software
237 PixelView Play TV PAK - (Model: PV-BT878P+ REV 4E) 237 PixelView Play TV PAK - (Model: PV-BT878P+ REV 4E)
238 PixelView Play TV/VCR - (Model: PV-M3200 REV 4C / 8D / 10A ) 238 PixelView Play TV/VCR - (Model: PV-M3200 REV 4C / 8D / 10A )
239 PixelView Studio PAK - (Model: M2200 REV 4C / 8D / 10A ) 239 PixelView Studio PAK - (Model: M2200 REV 4C / 8D / 10A )
240 PixelView PowerStudio PAK - (Model: PV-M3600 REV 4E) 240 PixelView PowerStudio PAK - (Model: PV-M3600 REV 4E)
241 PixelView DigitalVCR PAK - (Model: PV-M2400 REV 4C / 8D / 10A ) 241 PixelView DigitalVCR PAK - (Model: PV-M2400 REV 4C / 8D / 10A )
242 242
243 PixelView PlayTV PAK II (TV/FM card + usb camera) PV-M3800 243 PixelView PlayTV PAK II (TV/FM card + usb camera) PV-M3800
244 PixelView PlayTV XP PV-M4700,PV-M4700(w/FM) 244 PixelView PlayTV XP PV-M4700,PV-M4700(w/FM)
245 PixelView PlayTV DVR PV-M4600 package contents:PixelView PlayTV pro, windvr & videoMail s/w 245 PixelView PlayTV DVR PV-M4600 package contents:PixelView PlayTV pro, windvr & videoMail s/w
246 246
@@ -254,7 +254,7 @@ Prolink
254 254
255 DTV3000 PV-DTV3000P+ DVB-S CI = Twinhan VP-1030 255 DTV3000 PV-DTV3000P+ DVB-S CI = Twinhan VP-1030
256 DTV2000 DVB-S = Twinhan VP-1020 256 DTV2000 DVB-S = Twinhan VP-1020
257 257
258 Video Conferencing: 258 Video Conferencing:
259 PixelView Meeting PAK - (Model: PV-BT878P) 259 PixelView Meeting PAK - (Model: PV-BT878P)
260 PixelView Meeting PAK Lite - (Model: PV-BT878P) 260 PixelView Meeting PAK Lite - (Model: PV-BT878P)
@@ -308,7 +308,7 @@ KNC One
308 308
309 newer Cards have saa7134, but model name stayed the same? 309 newer Cards have saa7134, but model name stayed the same?
310 310
311Provideo 311Provideo
312-------- 312--------
313 PV951 or PV-951 (also are sold as: 313 PV951 or PV-951 (also are sold as:
314 Boeder TV-FM Video Capture Card 314 Boeder TV-FM Video Capture Card
@@ -353,7 +353,7 @@ AVerMedia
353 AVerTV 353 AVerTV
354 AVerTV Stereo 354 AVerTV Stereo
355 AVerTV Studio (w/FM) 355 AVerTV Studio (w/FM)
356 AVerMedia TV98 with Remote 356 AVerMedia TV98 with Remote
357 AVerMedia TV/FM98 Stereo 357 AVerMedia TV/FM98 Stereo
358 AVerMedia TVCAM98 358 AVerMedia TVCAM98
359 TVCapture (Bt848) 359 TVCapture (Bt848)
@@ -373,7 +373,7 @@ AVerMedia
373 (1) Daughterboard MB68-A with TDA9820T and TDA9840T 373 (1) Daughterboard MB68-A with TDA9820T and TDA9840T
374 (2) Sony NE41S soldered (stereo sound?) 374 (2) Sony NE41S soldered (stereo sound?)
375 (3) Daughterboard M118-A w/ pic 16c54 and 4 MHz quartz 375 (3) Daughterboard M118-A w/ pic 16c54 and 4 MHz quartz
376 376
377 US site has different drivers for (as of 09/2002): 377 US site has different drivers for (as of 09/2002):
378 EZ Capture/InterCam PCI (BT-848 chip) 378 EZ Capture/InterCam PCI (BT-848 chip)
379 EZ Capture/InterCam PCI (BT-878 chip) 379 EZ Capture/InterCam PCI (BT-878 chip)
@@ -437,7 +437,7 @@ Terratec
437 Terra TValueRadio, "LR102 Rev.C" printed on the PCB 437 Terra TValueRadio, "LR102 Rev.C" printed on the PCB
438 Terra TV/Radio+ Version 1.0, "80-CP2830100-0" TTTV3 printed on the PCB, 438 Terra TV/Radio+ Version 1.0, "80-CP2830100-0" TTTV3 printed on the PCB,
439 "CPH010-E83" on the back, SAA6588T, TDA9873H 439 "CPH010-E83" on the back, SAA6588T, TDA9873H
440 Terra TValue Version BT878, "80-CP2830110-0 TTTV4" printed on the PCB, 440 Terra TValue Version BT878, "80-CP2830110-0 TTTV4" printed on the PCB,
441 "CPH011-D83" on back 441 "CPH011-D83" on back
442 Terra TValue Version 1.0 "ceb105.PCB" (really identical to Terra TV+ Version 1.0) 442 Terra TValue Version 1.0 "ceb105.PCB" (really identical to Terra TV+ Version 1.0)
443 Terra TValue New Revision "LR102 Rec.C" 443 Terra TValue New Revision "LR102 Rec.C"
@@ -528,7 +528,7 @@ Koutech
528 KW-606RSF 528 KW-606RSF
529 KW-607A (capture only) 529 KW-607A (capture only)
530 KW-608 (Zoran capture only) 530 KW-608 (Zoran capture only)
531 531
532IODATA (jp) 532IODATA (jp)
533------ 533------
534 GV-BCTV/PCI 534 GV-BCTV/PCI
@@ -542,15 +542,15 @@ Canopus (jp)
542------- 542-------
543 WinDVR = Kworld "KW-TVL878RF" 543 WinDVR = Kworld "KW-TVL878RF"
544 544
545www.sigmacom.co.kr 545www.sigmacom.co.kr
546------------------ 546------------------
547 Sigma Cyber TV II 547 Sigma Cyber TV II
548 548
549www.sasem.co.kr 549www.sasem.co.kr
550--------------- 550---------------
551 Litte OnAir TV 551 Litte OnAir TV
552 552
553hama 553hama
554---- 554----
555 TV/Radio-Tuner Card, PCI (Model 44677) = CPH051 555 TV/Radio-Tuner Card, PCI (Model 44677) = CPH051
556 556
@@ -638,7 +638,7 @@ Media-Surfer (esc-kathrein.de)
638 638
639Jetway (www.jetway.com.tw) 639Jetway (www.jetway.com.tw)
640-------------------------- 640--------------------------
641 JW-TV 878M 641 JW-TV 878M
642 JW-TV 878 = KWorld KW-TV878RF 642 JW-TV 878 = KWorld KW-TV878RF
643 643
644Galaxis 644Galaxis
@@ -715,7 +715,7 @@ Hauppauge
715 809 MyVideo 715 809 MyVideo
716 872 MyTV2Go FM 716 872 MyTV2Go FM
717 717
718 718
719 546 WinTV Nova-S CI 719 546 WinTV Nova-S CI
720 543 WinTV Nova 720 543 WinTV Nova
721 907 Nova-S USB 721 907 Nova-S USB
@@ -739,7 +739,7 @@ Hauppauge
739 832 MyTV2Go 739 832 MyTV2Go
740 869 MyTV2Go-FM 740 869 MyTV2Go-FM
741 805 MyVideo (USB) 741 805 MyVideo (USB)
742 742
743 743
744Matrix-Vision 744Matrix-Vision
745------------- 745-------------
@@ -764,7 +764,7 @@ Gallant (www.gallantcom.com) www.minton.com.tw
764 Intervision IV-550 (bt8x8) 764 Intervision IV-550 (bt8x8)
765 Intervision IV-100 (zoran) 765 Intervision IV-100 (zoran)
766 Intervision IV-1000 (bt8x8) 766 Intervision IV-1000 (bt8x8)
767 767
768Asonic (www.asonic.com.cn) (website down) 768Asonic (www.asonic.com.cn) (website down)
769----------------------------------------- 769-----------------------------------------
770 SkyEye tv 878 770 SkyEye tv 878
@@ -804,11 +804,11 @@ Kworld (www.kworld.com.tw)
804 804
805JTT/ Justy Corp.http://www.justy.co.jp/ (www.jtt.com.jp website down) 805JTT/ Justy Corp.http://www.justy.co.jp/ (www.jtt.com.jp website down)
806--------------------------------------------------------------------- 806---------------------------------------------------------------------
807 JTT-02 (JTT TV) "TV watchmate pro" (bt848) 807 JTT-02 (JTT TV) "TV watchmate pro" (bt848)
808 808
809ADS www.adstech.com 809ADS www.adstech.com
810------------------- 810-------------------
811 Channel Surfer TV ( CHX-950 ) 811 Channel Surfer TV ( CHX-950 )
812 Channel Surfer TV+FM ( CHX-960FM ) 812 Channel Surfer TV+FM ( CHX-960FM )
813 813
814AVEC www.prochips.com 814AVEC www.prochips.com
@@ -874,7 +874,7 @@ www.ids-imaging.de
874------------------ 874------------------
875 Falcon Series (capture only) 875 Falcon Series (capture only)
876 In USA: http://www.theimagingsource.com/ 876 In USA: http://www.theimagingsource.com/
877 DFG/LC1 877 DFG/LC1
878 878
879www.sknet-web.co.jp 879www.sknet-web.co.jp
880------------------- 880-------------------
@@ -890,7 +890,7 @@ Cybertainment
890 CyberMail Xtreme 890 CyberMail Xtreme
891 These are Flyvideo 891 These are Flyvideo
892 892
893VCR (http://www.vcrinc.com/) 893VCR (http://www.vcrinc.com/)
894--- 894---
895 Video Catcher 16 895 Video Catcher 16
896 896
@@ -920,7 +920,7 @@ Sdisilk www.sdisilk.com/
920 SDI Silk 200 SDI Input Card 920 SDI Silk 200 SDI Input Card
921 921
922www.euresys.com 922www.euresys.com
923 PICOLO series 923 PICOLO series
924 924
925PMC/Pace 925PMC/Pace
926www.pacecom.co.uk website closed 926www.pacecom.co.uk website closed
diff --git a/Documentation/video4linux/not-in-cx2388x-datasheet.txt b/Documentation/video4linux/not-in-cx2388x-datasheet.txt
index 96b638b5ba1d..edbfe744d21d 100644
--- a/Documentation/video4linux/not-in-cx2388x-datasheet.txt
+++ b/Documentation/video4linux/not-in-cx2388x-datasheet.txt
@@ -34,4 +34,8 @@ MO_OUTPUT_FORMAT (0x310164)
34 2: HACTEXT 34 2: HACTEXT
35 1: HSFMT 35 1: HSFMT
36 36
370x47 is the sync byte for MPEG-2 transport stream packets.
38Datasheet incorrectly states to use 47 decimal. 188 is the length.
39All DVB compliant frontends output packets with this start code.
40
37================================================================================= 41=================================================================================
diff --git a/MAINTAINERS b/MAINTAINERS
index 37fb1e2ec687..5d014725901c 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1240,7 +1240,7 @@ S: Maintained
1240 1240
1241IRDA SUBSYSTEM 1241IRDA SUBSYSTEM
1242P: Jean Tourrilhes 1242P: Jean Tourrilhes
1243L: irda-users@lists.sourceforge.net 1243L: irda-users@lists.sourceforge.net (subscribers-only)
1244W: http://irda.sourceforge.net/ 1244W: http://irda.sourceforge.net/
1245S: Maintained 1245S: Maintained
1246 1246
diff --git a/Makefile b/Makefile
index 9cf07e7b9f88..cf34a6b5c6eb 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
1VERSION = 2 1VERSION = 2
2PATCHLEVEL = 6 2PATCHLEVEL = 6
3SUBLEVEL = 13 3SUBLEVEL = 13
4EXTRAVERSION =-rc2 4EXTRAVERSION =-rc3
5NAME=Woozy Numbat 5NAME=Woozy Numbat
6 6
7# *DOCUMENTATION* 7# *DOCUMENTATION*
diff --git a/arch/alpha/Kconfig b/arch/alpha/Kconfig
index c5739d6309df..083c5df42d35 100644
--- a/arch/alpha/Kconfig
+++ b/arch/alpha/Kconfig
@@ -596,6 +596,8 @@ source "fs/Kconfig.binfmt"
596 596
597endmenu 597endmenu
598 598
599source "net/Kconfig"
600
599source "drivers/Kconfig" 601source "drivers/Kconfig"
600 602
601source "fs/Kconfig" 603source "fs/Kconfig"
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 8752751f9985..7bc4a583f4e1 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -700,6 +700,8 @@ config APM
700 700
701endmenu 701endmenu
702 702
703source "net/Kconfig"
704
703menu "Device Drivers" 705menu "Device Drivers"
704 706
705source "drivers/base/Kconfig" 707source "drivers/base/Kconfig"
@@ -732,7 +734,7 @@ source "drivers/ieee1394/Kconfig"
732 734
733source "drivers/message/i2o/Kconfig" 735source "drivers/message/i2o/Kconfig"
734 736
735source "net/Kconfig" 737source "drivers/net/Kconfig"
736 738
737source "drivers/isdn/Kconfig" 739source "drivers/isdn/Kconfig"
738 740
@@ -744,6 +746,8 @@ source "drivers/char/Kconfig"
744 746
745source "drivers/i2c/Kconfig" 747source "drivers/i2c/Kconfig"
746 748
749source "drivers/hwmon/Kconfig"
750
747#source "drivers/l3/Kconfig" 751#source "drivers/l3/Kconfig"
748 752
749source "drivers/misc/Kconfig" 753source "drivers/misc/Kconfig"
diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
index a931409c8fe4..7ae45c3fc834 100644
--- a/arch/arm/kernel/smp.c
+++ b/arch/arm/kernel/smp.c
@@ -36,7 +36,7 @@
36 * The present bitmask indicates that the CPU is physically present. 36 * The present bitmask indicates that the CPU is physically present.
37 * The online bitmask indicates that the CPU is up and running. 37 * The online bitmask indicates that the CPU is up and running.
38 */ 38 */
39cpumask_t cpu_present_mask; 39cpumask_t cpu_possible_map;
40cpumask_t cpu_online_map; 40cpumask_t cpu_online_map;
41 41
42/* 42/*
@@ -235,7 +235,8 @@ void __init smp_prepare_boot_cpu(void)
235{ 235{
236 unsigned int cpu = smp_processor_id(); 236 unsigned int cpu = smp_processor_id();
237 237
238 cpu_set(cpu, cpu_present_mask); 238 cpu_set(cpu, cpu_possible_map);
239 cpu_set(cpu, cpu_present_map);
239 cpu_set(cpu, cpu_online_map); 240 cpu_set(cpu, cpu_online_map);
240} 241}
241 242
@@ -355,7 +356,7 @@ void show_ipi_list(struct seq_file *p)
355 356
356 seq_puts(p, "IPI:"); 357 seq_puts(p, "IPI:");
357 358
358 for_each_online_cpu(cpu) 359 for_each_present_cpu(cpu)
359 seq_printf(p, " %10lu", per_cpu(ipi_data, cpu).ipi_count); 360 seq_printf(p, " %10lu", per_cpu(ipi_data, cpu).ipi_count);
360 361
361 seq_putc(p, '\n'); 362 seq_putc(p, '\n');
diff --git a/arch/arm/mach-integrator/platsmp.c b/arch/arm/mach-integrator/platsmp.c
index ead15dfcb53d..2ba025777098 100644
--- a/arch/arm/mach-integrator/platsmp.c
+++ b/arch/arm/mach-integrator/platsmp.c
@@ -174,11 +174,13 @@ void __init smp_prepare_cpus(unsigned int max_cpus)
174 max_cpus = ncores; 174 max_cpus = ncores;
175 175
176 /* 176 /*
177 * Initialise the present mask - this tells us which CPUs should 177 * Initialise the possible/present maps.
178 * be present. 178 * cpu_possible_map describes the set of CPUs which may be present
179 * cpu_present_map describes the set of CPUs populated
179 */ 180 */
180 for (i = 0; i < max_cpus; i++) { 181 for (i = 0; i < max_cpus; i++) {
181 cpu_set(i, cpu_present_mask); 182 cpu_set(i, cpu_possible_map);
183 cpu_set(i, cpu_present_map);
182 } 184 }
183 185
184 /* 186 /*
diff --git a/arch/arm/mach-omap1/leds-h2p2-debug.c b/arch/arm/mach-omap1/leds-h2p2-debug.c
index 6e98290cca5c..ec0d8285f243 100644
--- a/arch/arm/mach-omap1/leds-h2p2-debug.c
+++ b/arch/arm/mach-omap1/leds-h2p2-debug.c
@@ -13,7 +13,6 @@
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/kernel_stat.h> 14#include <linux/kernel_stat.h>
15#include <linux/sched.h> 15#include <linux/sched.h>
16#include <linux/version.h>
17 16
18#include <asm/io.h> 17#include <asm/io.h>
19#include <asm/hardware.h> 18#include <asm/hardware.h>
diff --git a/arch/arm/nwfpe/fpmodule.c b/arch/arm/nwfpe/fpmodule.c
index a806fea5c3ed..a8efcf34888e 100644
--- a/arch/arm/nwfpe/fpmodule.c
+++ b/arch/arm/nwfpe/fpmodule.c
@@ -24,7 +24,6 @@
24#include "fpa11.h" 24#include "fpa11.h"
25 25
26#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/version.h>
28#include <linux/config.h> 27#include <linux/config.h>
29 28
30/* XXX */ 29/* XXX */
diff --git a/arch/arm/plat-omap/ocpi.c b/arch/arm/plat-omap/ocpi.c
index 1fb16f9edfd5..2ede2ee8cae4 100644
--- a/arch/arm/plat-omap/ocpi.c
+++ b/arch/arm/plat-omap/ocpi.c
@@ -25,7 +25,6 @@
25 25
26#include <linux/config.h> 26#include <linux/config.h>
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/version.h>
29#include <linux/types.h> 28#include <linux/types.h>
30#include <linux/errno.h> 29#include <linux/errno.h>
31#include <linux/kernel.h> 30#include <linux/kernel.h>
diff --git a/arch/arm26/Kconfig b/arch/arm26/Kconfig
index dc0c1936969b..1f0373267306 100644
--- a/arch/arm26/Kconfig
+++ b/arch/arm26/Kconfig
@@ -183,6 +183,8 @@ source "mm/Kconfig"
183 183
184endmenu 184endmenu
185 185
186source "net/Kconfig"
187
186source "drivers/base/Kconfig" 188source "drivers/base/Kconfig"
187 189
188source "drivers/parport/Kconfig" 190source "drivers/parport/Kconfig"
@@ -193,7 +195,7 @@ source "drivers/block/Kconfig"
193 195
194source "drivers/md/Kconfig" 196source "drivers/md/Kconfig"
195 197
196source "net/Kconfig" 198source "drivers/net/Kconfig"
197 199
198source "drivers/ide/Kconfig" 200source "drivers/ide/Kconfig"
199 201
diff --git a/arch/cris/Kconfig b/arch/cris/Kconfig
index f848e3761491..e5979d68e352 100644
--- a/arch/cris/Kconfig
+++ b/arch/cris/Kconfig
@@ -122,6 +122,8 @@ source arch/cris/arch-v10/Kconfig
122 122
123endmenu 123endmenu
124 124
125source "net/Kconfig"
126
125# bring in ETRAX built-in drivers 127# bring in ETRAX built-in drivers
126menu "Drivers for built-in interfaces" 128menu "Drivers for built-in interfaces"
127source arch/cris/arch-v10/drivers/Kconfig 129source arch/cris/arch-v10/drivers/Kconfig
@@ -149,7 +151,7 @@ source "drivers/ieee1394/Kconfig"
149 151
150source "drivers/message/i2o/Kconfig" 152source "drivers/message/i2o/Kconfig"
151 153
152source "net/Kconfig" 154source "drivers/net/Kconfig"
153 155
154source "drivers/isdn/Kconfig" 156source "drivers/isdn/Kconfig"
155 157
diff --git a/arch/frv/Kconfig b/arch/frv/Kconfig
index c93f95146cc2..ec85c0d6c6da 100644
--- a/arch/frv/Kconfig
+++ b/arch/frv/Kconfig
@@ -346,6 +346,8 @@ source "fs/Kconfig.binfmt"
346 346
347endmenu 347endmenu
348 348
349source "net/Kconfig"
350
349source "drivers/Kconfig" 351source "drivers/Kconfig"
350 352
351source "fs/Kconfig" 353source "fs/Kconfig"
diff --git a/arch/frv/mb93090-mb00/pci-irq.c b/arch/frv/mb93090-mb00/pci-irq.c
index 24622d89b1ca..af981bda015c 100644
--- a/arch/frv/mb93090-mb00/pci-irq.c
+++ b/arch/frv/mb93090-mb00/pci-irq.c
@@ -60,7 +60,7 @@ void __init pcibios_fixup_irqs(void)
60 } 60 }
61} 61}
62 62
63void __init pcibios_penalize_isa_irq(int irq) 63void __init pcibios_penalize_isa_irq(int irq, int active)
64{ 64{
65} 65}
66 66
diff --git a/arch/h8300/Kconfig b/arch/h8300/Kconfig
index 62a89e812e3e..26698a49f153 100644
--- a/arch/h8300/Kconfig
+++ b/arch/h8300/Kconfig
@@ -55,6 +55,8 @@ source "fs/Kconfig.binfmt"
55 55
56endmenu 56endmenu
57 57
58source "net/Kconfig"
59
58source "drivers/base/Kconfig" 60source "drivers/base/Kconfig"
59 61
60source "drivers/mtd/Kconfig" 62source "drivers/mtd/Kconfig"
@@ -65,7 +67,7 @@ source "drivers/ide/Kconfig"
65 67
66source "arch/h8300/Kconfig.ide" 68source "arch/h8300/Kconfig.ide"
67 69
68source "net/Kconfig" 70source "drivers/net/Kconfig"
69 71
70# 72#
71# input - input/joystick depends on it. As does USB. 73# input - input/joystick depends on it. As does USB.
@@ -179,6 +181,8 @@ source "drivers/serial/Kconfig"
179 181
180source "drivers/i2c/Kconfig" 182source "drivers/i2c/Kconfig"
181 183
184source "drivers/hwmon/Kconfig"
185
182source "drivers/usb/Kconfig" 186source "drivers/usb/Kconfig"
183 187
184endmenu 188endmenu
diff --git a/arch/i386/Kconfig b/arch/i386/Kconfig
index 6c02336fe2e4..a801d9d48606 100644
--- a/arch/i386/Kconfig
+++ b/arch/i386/Kconfig
@@ -1285,6 +1285,8 @@ source "fs/Kconfig.binfmt"
1285 1285
1286endmenu 1286endmenu
1287 1287
1288source "net/Kconfig"
1289
1288source "drivers/Kconfig" 1290source "drivers/Kconfig"
1289 1291
1290source "fs/Kconfig" 1292source "fs/Kconfig"
diff --git a/arch/i386/kernel/acpi/Makefile b/arch/i386/kernel/acpi/Makefile
index ee75cb286cfe..5e291a20c03d 100644
--- a/arch/i386/kernel/acpi/Makefile
+++ b/arch/i386/kernel/acpi/Makefile
@@ -2,3 +2,7 @@ obj-$(CONFIG_ACPI_BOOT) := boot.o
2obj-$(CONFIG_X86_IO_APIC) += earlyquirk.o 2obj-$(CONFIG_X86_IO_APIC) += earlyquirk.o
3obj-$(CONFIG_ACPI_SLEEP) += sleep.o wakeup.o 3obj-$(CONFIG_ACPI_SLEEP) += sleep.o wakeup.o
4 4
5ifneq ($(CONFIG_ACPI_PROCESSOR),)
6obj-y += cstate.o
7endif
8
diff --git a/arch/i386/kernel/acpi/cstate.c b/arch/i386/kernel/acpi/cstate.c
new file mode 100644
index 000000000000..4c3036ba65df
--- /dev/null
+++ b/arch/i386/kernel/acpi/cstate.c
@@ -0,0 +1,103 @@
1/*
2 * arch/i386/kernel/acpi/cstate.c
3 *
4 * Copyright (C) 2005 Intel Corporation
5 * Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
6 * - Added _PDC for SMP C-states on Intel CPUs
7 */
8
9#include <linux/kernel.h>
10#include <linux/module.h>
11#include <linux/init.h>
12#include <linux/acpi.h>
13
14#include <acpi/processor.h>
15#include <asm/acpi.h>
16
17static void acpi_processor_power_init_intel_pdc(struct acpi_processor_power
18 *pow)
19{
20 struct acpi_object_list *obj_list;
21 union acpi_object *obj;
22 u32 *buf;
23
24 /* allocate and initialize pdc. It will be used later. */
25 obj_list = kmalloc(sizeof(struct acpi_object_list), GFP_KERNEL);
26 if (!obj_list) {
27 printk(KERN_ERR "Memory allocation error\n");
28 return;
29 }
30
31 obj = kmalloc(sizeof(union acpi_object), GFP_KERNEL);
32 if (!obj) {
33 printk(KERN_ERR "Memory allocation error\n");
34 kfree(obj_list);
35 return;
36 }
37
38 buf = kmalloc(12, GFP_KERNEL);
39 if (!buf) {
40 printk(KERN_ERR "Memory allocation error\n");
41 kfree(obj);
42 kfree(obj_list);
43 return;
44 }
45
46 buf[0] = ACPI_PDC_REVISION_ID;
47 buf[1] = 1;
48 buf[2] = ACPI_PDC_C_CAPABILITY_SMP;
49
50 obj->type = ACPI_TYPE_BUFFER;
51 obj->buffer.length = 12;
52 obj->buffer.pointer = (u8 *) buf;
53 obj_list->count = 1;
54 obj_list->pointer = obj;
55 pow->pdc = obj_list;
56
57 return;
58}
59
60/* Initialize _PDC data based on the CPU vendor */
61void acpi_processor_power_init_pdc(struct acpi_processor_power *pow,
62 unsigned int cpu)
63{
64 struct cpuinfo_x86 *c = cpu_data + cpu;
65
66 pow->pdc = NULL;
67 if (c->x86_vendor == X86_VENDOR_INTEL)
68 acpi_processor_power_init_intel_pdc(pow);
69
70 return;
71}
72
73EXPORT_SYMBOL(acpi_processor_power_init_pdc);
74
75/*
76 * Initialize bm_flags based on the CPU cache properties
77 * On SMP it depends on cache configuration
78 * - When cache is not shared among all CPUs, we flush cache
79 * before entering C3.
80 * - When cache is shared among all CPUs, we use bm_check
81 * mechanism as in UP case
82 *
83 * This routine is called only after all the CPUs are online
84 */
85void acpi_processor_power_init_bm_check(struct acpi_processor_flags *flags,
86 unsigned int cpu)
87{
88 struct cpuinfo_x86 *c = cpu_data + cpu;
89
90 flags->bm_check = 0;
91 if (num_online_cpus() == 1)
92 flags->bm_check = 1;
93 else if (c->x86_vendor == X86_VENDOR_INTEL) {
94 /*
95 * Today all CPUs that support C3 share cache.
96 * TBD: This needs to look at cache shared map, once
97 * multi-core detection patch makes to the base.
98 */
99 flags->bm_check = 1;
100 }
101}
102
103EXPORT_SYMBOL(acpi_processor_power_init_bm_check);
diff --git a/arch/i386/kernel/acpi/wakeup.S b/arch/i386/kernel/acpi/wakeup.S
index 39d32484f6f5..44d886c745ec 100644
--- a/arch/i386/kernel/acpi/wakeup.S
+++ b/arch/i386/kernel/acpi/wakeup.S
@@ -74,8 +74,9 @@ wakeup_code:
74 movw %ax,%fs 74 movw %ax,%fs
75 movw $0x0e00 + 'i', %fs:(0x12) 75 movw $0x0e00 + 'i', %fs:(0x12)
76 76
77 # need a gdt 77 # need a gdt -- use lgdtl to force 32-bit operands, in case
78 lgdt real_save_gdt - wakeup_code 78 # the GDT is located past 16 megabytes.
79 lgdtl real_save_gdt - wakeup_code
79 80
80 movl real_save_cr0 - wakeup_code, %eax 81 movl real_save_cr0 - wakeup_code, %eax
81 movl %eax, %cr0 82 movl %eax, %cr0
diff --git a/arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c b/arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c
index 7dcbf70fc16f..327a55d4d1c6 100644
--- a/arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c
+++ b/arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c
@@ -375,7 +375,7 @@ static int centrino_cpu_init_acpi(struct cpufreq_policy *policy)
375 arg0.buffer.pointer = (u8 *) arg0_buf; 375 arg0.buffer.pointer = (u8 *) arg0_buf;
376 arg0_buf[0] = ACPI_PDC_REVISION_ID; 376 arg0_buf[0] = ACPI_PDC_REVISION_ID;
377 arg0_buf[1] = 1; 377 arg0_buf[1] = 1;
378 arg0_buf[2] = ACPI_PDC_EST_CAPABILITY_SMP | ACPI_PDC_EST_CAPABILITY_MSR; 378 arg0_buf[2] = ACPI_PDC_EST_CAPABILITY_SMP_MSR;
379 379
380 p.pdc = &arg_list; 380 p.pdc = &arg_list;
381 381
diff --git a/arch/i386/kernel/syscall_table.S b/arch/i386/kernel/syscall_table.S
index 3db9a04aec6e..468500a7e894 100644
--- a/arch/i386/kernel/syscall_table.S
+++ b/arch/i386/kernel/syscall_table.S
@@ -291,3 +291,6 @@ ENTRY(sys_call_table)
291 .long sys_keyctl 291 .long sys_keyctl
292 .long sys_ioprio_set 292 .long sys_ioprio_set
293 .long sys_ioprio_get /* 290 */ 293 .long sys_ioprio_get /* 290 */
294 .long sys_inotify_init
295 .long sys_inotify_add_watch
296 .long sys_inotify_rm_watch
diff --git a/arch/i386/mach-voyager/voyager_basic.c b/arch/i386/mach-voyager/voyager_basic.c
index 3e439ce5e1b2..8680080a6a89 100644
--- a/arch/i386/mach-voyager/voyager_basic.c
+++ b/arch/i386/mach-voyager/voyager_basic.c
@@ -36,6 +36,7 @@
36 * Power off function, if any 36 * Power off function, if any
37 */ 37 */
38void (*pm_power_off)(void); 38void (*pm_power_off)(void);
39EXPORT_SYMBOL(pm_power_off);
39 40
40int voyager_level = 0; 41int voyager_level = 0;
41 42
diff --git a/arch/i386/mach-voyager/voyager_smp.c b/arch/i386/mach-voyager/voyager_smp.c
index 8c8527593da0..0e1f4208b07c 100644
--- a/arch/i386/mach-voyager/voyager_smp.c
+++ b/arch/i386/mach-voyager/voyager_smp.c
@@ -10,6 +10,7 @@
10 * the voyager hal to provide the functionality 10 * the voyager hal to provide the functionality
11 */ 11 */
12#include <linux/config.h> 12#include <linux/config.h>
13#include <linux/module.h>
13#include <linux/mm.h> 14#include <linux/mm.h>
14#include <linux/kernel_stat.h> 15#include <linux/kernel_stat.h>
15#include <linux/delay.h> 16#include <linux/delay.h>
@@ -40,6 +41,7 @@ static unsigned long cpu_irq_affinity[NR_CPUS] __cacheline_aligned = { [0 ... NR
40/* per CPU data structure (for /proc/cpuinfo et al), visible externally 41/* per CPU data structure (for /proc/cpuinfo et al), visible externally
41 * indexed physically */ 42 * indexed physically */
42struct cpuinfo_x86 cpu_data[NR_CPUS] __cacheline_aligned; 43struct cpuinfo_x86 cpu_data[NR_CPUS] __cacheline_aligned;
44EXPORT_SYMBOL(cpu_data);
43 45
44/* physical ID of the CPU used to boot the system */ 46/* physical ID of the CPU used to boot the system */
45unsigned char boot_cpu_id; 47unsigned char boot_cpu_id;
@@ -72,6 +74,7 @@ static volatile unsigned long smp_invalidate_needed;
72/* Bitmask of currently online CPUs - used by setup.c for 74/* Bitmask of currently online CPUs - used by setup.c for
73 /proc/cpuinfo, visible externally but still physical */ 75 /proc/cpuinfo, visible externally but still physical */
74cpumask_t cpu_online_map = CPU_MASK_NONE; 76cpumask_t cpu_online_map = CPU_MASK_NONE;
77EXPORT_SYMBOL(cpu_online_map);
75 78
76/* Bitmask of CPUs present in the system - exported by i386_syms.c, used 79/* Bitmask of CPUs present in the system - exported by i386_syms.c, used
77 * by scheduler but indexed physically */ 80 * by scheduler but indexed physically */
@@ -238,6 +241,7 @@ static cpumask_t smp_commenced_mask = CPU_MASK_NONE;
238/* This is for the new dynamic CPU boot code */ 241/* This is for the new dynamic CPU boot code */
239cpumask_t cpu_callin_map = CPU_MASK_NONE; 242cpumask_t cpu_callin_map = CPU_MASK_NONE;
240cpumask_t cpu_callout_map = CPU_MASK_NONE; 243cpumask_t cpu_callout_map = CPU_MASK_NONE;
244EXPORT_SYMBOL(cpu_callout_map);
241 245
242/* The per processor IRQ masks (these are usually kept in sync) */ 246/* The per processor IRQ masks (these are usually kept in sync) */
243static __u16 vic_irq_mask[NR_CPUS] __cacheline_aligned; 247static __u16 vic_irq_mask[NR_CPUS] __cacheline_aligned;
@@ -978,6 +982,7 @@ void flush_tlb_page(struct vm_area_struct * vma, unsigned long va)
978 982
979 preempt_enable(); 983 preempt_enable();
980} 984}
985EXPORT_SYMBOL(flush_tlb_page);
981 986
982/* enable the requested IRQs */ 987/* enable the requested IRQs */
983static void 988static void
@@ -1109,6 +1114,7 @@ smp_call_function (void (*func) (void *info), void *info, int retry,
1109 1114
1110 return 0; 1115 return 0;
1111} 1116}
1117EXPORT_SYMBOL(smp_call_function);
1112 1118
1113/* Sorry about the name. In an APIC based system, the APICs 1119/* Sorry about the name. In an APIC based system, the APICs
1114 * themselves are programmed to send a timer interrupt. This is used 1120 * themselves are programmed to send a timer interrupt. This is used
diff --git a/arch/i386/pci/irq.c b/arch/i386/pci/irq.c
index 78ca1ecbb907..766b104ac1a1 100644
--- a/arch/i386/pci/irq.c
+++ b/arch/i386/pci/irq.c
@@ -1051,24 +1051,28 @@ static int __init pcibios_irq_init(void)
1051subsys_initcall(pcibios_irq_init); 1051subsys_initcall(pcibios_irq_init);
1052 1052
1053 1053
1054static void pirq_penalize_isa_irq(int irq) 1054static void pirq_penalize_isa_irq(int irq, int active)
1055{ 1055{
1056 /* 1056 /*
1057 * If any ISAPnP device reports an IRQ in its list of possible 1057 * If any ISAPnP device reports an IRQ in its list of possible
1058 * IRQ's, we try to avoid assigning it to PCI devices. 1058 * IRQ's, we try to avoid assigning it to PCI devices.
1059 */ 1059 */
1060 if (irq < 16) 1060 if (irq < 16) {
1061 pirq_penalty[irq] += 100; 1061 if (active)
1062 pirq_penalty[irq] += 1000;
1063 else
1064 pirq_penalty[irq] += 100;
1065 }
1062} 1066}
1063 1067
1064void pcibios_penalize_isa_irq(int irq) 1068void pcibios_penalize_isa_irq(int irq, int active)
1065{ 1069{
1066#ifdef CONFIG_ACPI_PCI 1070#ifdef CONFIG_ACPI_PCI
1067 if (!acpi_noirq) 1071 if (!acpi_noirq)
1068 acpi_penalize_isa_irq(irq); 1072 acpi_penalize_isa_irq(irq, active);
1069 else 1073 else
1070#endif 1074#endif
1071 pirq_penalize_isa_irq(irq); 1075 pirq_penalize_isa_irq(irq, active);
1072} 1076}
1073 1077
1074static int pirq_enable_irq(struct pci_dev *dev) 1078static int pirq_enable_irq(struct pci_dev *dev)
diff --git a/arch/i386/pci/visws.c b/arch/i386/pci/visws.c
index 6a9248784439..314c933b6b8e 100644
--- a/arch/i386/pci/visws.c
+++ b/arch/i386/pci/visws.c
@@ -21,7 +21,7 @@ static int pci_visws_enable_irq(struct pci_dev *dev) { return 0; }
21 21
22int (*pcibios_enable_irq)(struct pci_dev *dev) = &pci_visws_enable_irq; 22int (*pcibios_enable_irq)(struct pci_dev *dev) = &pci_visws_enable_irq;
23 23
24void __init pcibios_penalize_isa_irq(int irq) {} 24void __init pcibios_penalize_isa_irq(int irq, int active) {}
25 25
26 26
27unsigned int pci_bus0, pci_bus1; 27unsigned int pci_bus0, pci_bus1;
diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
index bfdd062dd827..cbb3e0cef93a 100644
--- a/arch/ia64/Kconfig
+++ b/arch/ia64/Kconfig
@@ -416,6 +416,8 @@ endmenu
416 416
417endif 417endif
418 418
419source "net/Kconfig"
420
419source "drivers/Kconfig" 421source "drivers/Kconfig"
420 422
421source "fs/Kconfig" 423source "fs/Kconfig"
diff --git a/arch/ia64/kernel/acpi.c b/arch/ia64/kernel/acpi.c
index 542256e98e60..9609f243e5d0 100644
--- a/arch/ia64/kernel/acpi.c
+++ b/arch/ia64/kernel/acpi.c
@@ -11,6 +11,7 @@
11 * Copyright (C) 2001 Jenna Hall <jenna.s.hall@intel.com> 11 * Copyright (C) 2001 Jenna Hall <jenna.s.hall@intel.com>
12 * Copyright (C) 2001 Takayoshi Kochi <t-kochi@bq.jp.nec.com> 12 * Copyright (C) 2001 Takayoshi Kochi <t-kochi@bq.jp.nec.com>
13 * Copyright (C) 2002 Erich Focht <efocht@ess.nec.de> 13 * Copyright (C) 2002 Erich Focht <efocht@ess.nec.de>
14 * Copyright (C) 2004 Ashok Raj <ashok.raj@intel.com>
14 * 15 *
15 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 16 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
16 * 17 *
@@ -67,6 +68,11 @@ EXPORT_SYMBOL(pm_power_off);
67unsigned char acpi_kbd_controller_present = 1; 68unsigned char acpi_kbd_controller_present = 1;
68unsigned char acpi_legacy_devices; 69unsigned char acpi_legacy_devices;
69 70
71static unsigned int __initdata acpi_madt_rev;
72
73unsigned int acpi_cpei_override;
74unsigned int acpi_cpei_phys_cpuid;
75
70#define MAX_SAPICS 256 76#define MAX_SAPICS 256
71u16 ia64_acpiid_to_sapicid[MAX_SAPICS] = 77u16 ia64_acpiid_to_sapicid[MAX_SAPICS] =
72 { [0 ... MAX_SAPICS - 1] = -1 }; 78 { [0 ... MAX_SAPICS - 1] = -1 };
@@ -265,10 +271,56 @@ acpi_parse_plat_int_src (
265 (plintsrc->flags.trigger == 1) ? IOSAPIC_EDGE : IOSAPIC_LEVEL); 271 (plintsrc->flags.trigger == 1) ? IOSAPIC_EDGE : IOSAPIC_LEVEL);
266 272
267 platform_intr_list[plintsrc->type] = vector; 273 platform_intr_list[plintsrc->type] = vector;
274 if (acpi_madt_rev > 1) {
275 acpi_cpei_override = plintsrc->plint_flags.cpei_override_flag;
276 }
277
278 /*
279 * Save the physical id, so we can check when its being removed
280 */
281 acpi_cpei_phys_cpuid = ((plintsrc->id << 8) | (plintsrc->eid)) & 0xffff;
282
268 return 0; 283 return 0;
269} 284}
270 285
271 286
287unsigned int can_cpei_retarget(void)
288{
289 extern int cpe_vector;
290
291 /*
292 * Only if CPEI is supported and the override flag
293 * is present, otherwise return that its re-targettable
294 * if we are in polling mode.
295 */
296 if (cpe_vector > 0 && !acpi_cpei_override)
297 return 0;
298 else
299 return 1;
300}
301
302unsigned int is_cpu_cpei_target(unsigned int cpu)
303{
304 unsigned int logical_id;
305
306 logical_id = cpu_logical_id(acpi_cpei_phys_cpuid);
307
308 if (logical_id == cpu)
309 return 1;
310 else
311 return 0;
312}
313
314void set_cpei_target_cpu(unsigned int cpu)
315{
316 acpi_cpei_phys_cpuid = cpu_physical_id(cpu);
317}
318
319unsigned int get_cpei_target_cpu(void)
320{
321 return acpi_cpei_phys_cpuid;
322}
323
272static int __init 324static int __init
273acpi_parse_int_src_ovr ( 325acpi_parse_int_src_ovr (
274 acpi_table_entry_header *header, const unsigned long end) 326 acpi_table_entry_header *header, const unsigned long end)
@@ -326,6 +378,8 @@ acpi_parse_madt (unsigned long phys_addr, unsigned long size)
326 378
327 acpi_madt = (struct acpi_table_madt *) __va(phys_addr); 379 acpi_madt = (struct acpi_table_madt *) __va(phys_addr);
328 380
381 acpi_madt_rev = acpi_madt->header.revision;
382
329 /* remember the value for reference after free_initmem() */ 383 /* remember the value for reference after free_initmem() */
330#ifdef CONFIG_ITANIUM 384#ifdef CONFIG_ITANIUM
331 has_8259 = 1; /* Firmware on old Itanium systems is broken */ 385 has_8259 = 1; /* Firmware on old Itanium systems is broken */
diff --git a/arch/ia64/kernel/mca.c b/arch/ia64/kernel/mca.c
index 736e328b5e61..4ebbf3974381 100644
--- a/arch/ia64/kernel/mca.c
+++ b/arch/ia64/kernel/mca.c
@@ -271,7 +271,7 @@ ia64_mca_log_sal_error_record(int sal_info_type)
271 271
272#ifdef CONFIG_ACPI 272#ifdef CONFIG_ACPI
273 273
274static int cpe_vector = -1; 274int cpe_vector = -1;
275 275
276static irqreturn_t 276static irqreturn_t
277ia64_mca_cpe_int_handler (int cpe_irq, void *arg, struct pt_regs *ptregs) 277ia64_mca_cpe_int_handler (int cpe_irq, void *arg, struct pt_regs *ptregs)
diff --git a/arch/ia64/kernel/process.c b/arch/ia64/kernel/process.c
index 6e35bff05d59..e484910246ad 100644
--- a/arch/ia64/kernel/process.c
+++ b/arch/ia64/kernel/process.c
@@ -196,6 +196,7 @@ update_pal_halt_status(int status)
196void 196void
197default_idle (void) 197default_idle (void)
198{ 198{
199 local_irq_enable();
199 while (!need_resched()) 200 while (!need_resched())
200 if (can_do_pal_halt) 201 if (can_do_pal_halt)
201 safe_halt(); 202 safe_halt();
diff --git a/arch/ia64/kernel/setup.c b/arch/ia64/kernel/setup.c
index 7fc891aca446..84f89da7c640 100644
--- a/arch/ia64/kernel/setup.c
+++ b/arch/ia64/kernel/setup.c
@@ -41,6 +41,8 @@
41#include <linux/serial_core.h> 41#include <linux/serial_core.h>
42#include <linux/efi.h> 42#include <linux/efi.h>
43#include <linux/initrd.h> 43#include <linux/initrd.h>
44#include <linux/platform.h>
45#include <linux/pm.h>
44 46
45#include <asm/ia32.h> 47#include <asm/ia32.h>
46#include <asm/machvec.h> 48#include <asm/machvec.h>
@@ -816,6 +818,7 @@ cpu_init (void)
816 /* size of physical stacked register partition plus 8 bytes: */ 818 /* size of physical stacked register partition plus 8 bytes: */
817 __get_cpu_var(ia64_phys_stacked_size_p8) = num_phys_stacked*8 + 8; 819 __get_cpu_var(ia64_phys_stacked_size_p8) = num_phys_stacked*8 + 8;
818 platform_cpu_init(); 820 platform_cpu_init();
821 pm_idle = default_idle;
819} 822}
820 823
821void 824void
diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
index f1aafd4c05f9..d8030f3bd865 100644
--- a/arch/ia64/kernel/topology.c
+++ b/arch/ia64/kernel/topology.c
@@ -36,6 +36,13 @@ int arch_register_cpu(int num)
36 parent = &sysfs_nodes[cpu_to_node(num)]; 36 parent = &sysfs_nodes[cpu_to_node(num)];
37#endif /* CONFIG_NUMA */ 37#endif /* CONFIG_NUMA */
38 38
39 /*
40 * If CPEI cannot be re-targetted, and this is
41 * CPEI target, then dont create the control file
42 */
43 if (!can_cpei_retarget() && is_cpu_cpei_target(num))
44 sysfs_cpus[num].cpu.no_control = 1;
45
39 return register_cpu(&sysfs_cpus[num].cpu, num, parent); 46 return register_cpu(&sysfs_cpus[num].cpu, num, parent);
40} 47}
41 48
diff --git a/arch/m32r/Kconfig b/arch/m32r/Kconfig
index 42ca8a39798d..7772951df313 100644
--- a/arch/m32r/Kconfig
+++ b/arch/m32r/Kconfig
@@ -359,6 +359,8 @@ source "fs/Kconfig.binfmt"
359 359
360endmenu 360endmenu
361 361
362source "net/Kconfig"
363
362source "drivers/Kconfig" 364source "drivers/Kconfig"
363 365
364source "fs/Kconfig" 366source "fs/Kconfig"
diff --git a/arch/m68k/Kconfig b/arch/m68k/Kconfig
index 691a2469ff36..178c4a3fbb72 100644
--- a/arch/m68k/Kconfig
+++ b/arch/m68k/Kconfig
@@ -450,6 +450,8 @@ source "drivers/zorro/Kconfig"
450 450
451endmenu 451endmenu
452 452
453source "net/Kconfig"
454
453source "drivers/Kconfig" 455source "drivers/Kconfig"
454 456
455menu "Character devices" 457menu "Character devices"
diff --git a/arch/m68knommu/Kconfig b/arch/m68knommu/Kconfig
index dbfcdc8e6087..117f183f0b43 100644
--- a/arch/m68knommu/Kconfig
+++ b/arch/m68knommu/Kconfig
@@ -575,6 +575,8 @@ config PM
575 575
576endmenu 576endmenu
577 577
578source "net/Kconfig"
579
578source "drivers/Kconfig" 580source "drivers/Kconfig"
579 581
580source "fs/Kconfig" 582source "fs/Kconfig"
diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index bd9de7b00c0a..b578239146b5 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -1640,6 +1640,8 @@ config PM
1640 1640
1641endmenu 1641endmenu
1642 1642
1643source "net/Kconfig"
1644
1643source "drivers/Kconfig" 1645source "drivers/Kconfig"
1644 1646
1645source "fs/Kconfig" 1647source "fs/Kconfig"
diff --git a/arch/parisc/Kconfig b/arch/parisc/Kconfig
index ce327c799b44..1c2d87435233 100644
--- a/arch/parisc/Kconfig
+++ b/arch/parisc/Kconfig
@@ -190,6 +190,8 @@ source "fs/Kconfig.binfmt"
190 190
191endmenu 191endmenu
192 192
193source "net/Kconfig"
194
193source "drivers/Kconfig" 195source "drivers/Kconfig"
194 196
195source "fs/Kconfig" 197source "fs/Kconfig"
diff --git a/arch/ppc/Kconfig b/arch/ppc/Kconfig
index 23b0d2f662c5..b833cbcd77f0 100644
--- a/arch/ppc/Kconfig
+++ b/arch/ppc/Kconfig
@@ -1355,6 +1355,8 @@ config PIN_TLB
1355 depends on ADVANCED_OPTIONS && 8xx 1355 depends on ADVANCED_OPTIONS && 8xx
1356endmenu 1356endmenu
1357 1357
1358source "net/Kconfig"
1359
1358source "drivers/Kconfig" 1360source "drivers/Kconfig"
1359 1361
1360source "fs/Kconfig" 1362source "fs/Kconfig"
diff --git a/arch/ppc/kernel/machine_kexec.c b/arch/ppc/kernel/machine_kexec.c
index 84d65a87191e..a72787747df7 100644
--- a/arch/ppc/kernel/machine_kexec.c
+++ b/arch/ppc/kernel/machine_kexec.c
@@ -28,6 +28,12 @@ typedef NORET_TYPE void (*relocate_new_kernel_t)(
28const extern unsigned char relocate_new_kernel[]; 28const extern unsigned char relocate_new_kernel[];
29const extern unsigned int relocate_new_kernel_size; 29const extern unsigned int relocate_new_kernel_size;
30 30
31/*
32 * Provide a dummy crash_notes definition while crash dump arrives to ppc.
33 * This prevents breakage of crash_notes attribute in kernel/ksysfs.c.
34 */
35void *crash_notes = NULL;
36
31void machine_shutdown(void) 37void machine_shutdown(void)
32{ 38{
33 if (ppc_md.machine_shutdown) 39 if (ppc_md.machine_shutdown)
diff --git a/arch/ppc64/Kconfig b/arch/ppc64/Kconfig
index f804f25232ac..fdd8afba7152 100644
--- a/arch/ppc64/Kconfig
+++ b/arch/ppc64/Kconfig
@@ -429,6 +429,8 @@ config CMDLINE
429 429
430endmenu 430endmenu
431 431
432source "net/Kconfig"
433
432source "drivers/Kconfig" 434source "drivers/Kconfig"
433 435
434source "fs/Kconfig" 436source "fs/Kconfig"
diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
index 6600ee87f896..477ac2758bd5 100644
--- a/arch/s390/Kconfig
+++ b/arch/s390/Kconfig
@@ -465,6 +465,8 @@ config KEXEC
465 465
466endmenu 466endmenu
467 467
468source "net/Kconfig"
469
468config PCMCIA 470config PCMCIA
469 bool 471 bool
470 default n 472 default n
@@ -475,7 +477,7 @@ source "drivers/scsi/Kconfig"
475 477
476source "drivers/s390/Kconfig" 478source "drivers/s390/Kconfig"
477 479
478source "net/Kconfig" 480source "drivers/net/Kconfig"
479 481
480source "fs/Kconfig" 482source "fs/Kconfig"
481 483
diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig
index a7c8bfc11604..adc8109f8b77 100644
--- a/arch/sh/Kconfig
+++ b/arch/sh/Kconfig
@@ -784,6 +784,8 @@ config EMBEDDED_RAMDISK_IMAGE
784 784
785endmenu 785endmenu
786 786
787source "net/Kconfig"
788
787source "drivers/Kconfig" 789source "drivers/Kconfig"
788 790
789source "fs/Kconfig" 791source "fs/Kconfig"
diff --git a/arch/sh64/Kconfig b/arch/sh64/Kconfig
index 708e59736a4d..4c3e5334adb3 100644
--- a/arch/sh64/Kconfig
+++ b/arch/sh64/Kconfig
@@ -268,6 +268,8 @@ source "fs/Kconfig.binfmt"
268 268
269endmenu 269endmenu
270 270
271source "net/Kconfig"
272
271source "drivers/Kconfig" 273source "drivers/Kconfig"
272 274
273source "fs/Kconfig" 275source "fs/Kconfig"
diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig
index 7a117ef473c5..aca028aa29bf 100644
--- a/arch/sparc/Kconfig
+++ b/arch/sparc/Kconfig
@@ -268,6 +268,8 @@ source "mm/Kconfig"
268 268
269endmenu 269endmenu
270 270
271source "net/Kconfig"
272
271source "drivers/Kconfig" 273source "drivers/Kconfig"
272 274
273if !SUN4 275if !SUN4
diff --git a/arch/sparc64/Kconfig b/arch/sparc64/Kconfig
index 6a4733683f0f..9afd28e2c4d5 100644
--- a/arch/sparc64/Kconfig
+++ b/arch/sparc64/Kconfig
@@ -525,6 +525,8 @@ source "mm/Kconfig"
525 525
526endmenu 526endmenu
527 527
528source "net/Kconfig"
529
528source "drivers/base/Kconfig" 530source "drivers/base/Kconfig"
529 531
530source "drivers/video/Kconfig" 532source "drivers/video/Kconfig"
@@ -551,7 +553,7 @@ endif
551 553
552source "drivers/ieee1394/Kconfig" 554source "drivers/ieee1394/Kconfig"
553 555
554source "net/Kconfig" 556source "drivers/net/Kconfig"
555 557
556source "drivers/isdn/Kconfig" 558source "drivers/isdn/Kconfig"
557 559
@@ -647,6 +649,8 @@ source "drivers/input/Kconfig"
647 649
648source "drivers/i2c/Kconfig" 650source "drivers/i2c/Kconfig"
649 651
652source "drivers/hwmon/Kconfig"
653
650source "fs/Kconfig" 654source "fs/Kconfig"
651 655
652source "drivers/media/Kconfig" 656source "drivers/media/Kconfig"
diff --git a/arch/sparc64/kernel/smp.c b/arch/sparc64/kernel/smp.c
index 441fc2e52ce6..7e8e2919e186 100644
--- a/arch/sparc64/kernel/smp.c
+++ b/arch/sparc64/kernel/smp.c
@@ -45,8 +45,8 @@ extern void calibrate_delay(void);
45/* Please don't make this stuff initdata!!! --DaveM */ 45/* Please don't make this stuff initdata!!! --DaveM */
46static unsigned char boot_cpu_id; 46static unsigned char boot_cpu_id;
47 47
48cpumask_t cpu_online_map = CPU_MASK_NONE __read_mostly; 48cpumask_t cpu_online_map __read_mostly = CPU_MASK_NONE;
49cpumask_t phys_cpu_present_map = CPU_MASK_NONE __read_mostly; 49cpumask_t phys_cpu_present_map __read_mostly = CPU_MASK_NONE;
50static cpumask_t smp_commenced_mask; 50static cpumask_t smp_commenced_mask;
51static cpumask_t cpu_callout_map; 51static cpumask_t cpu_callout_map;
52 52
diff --git a/arch/um/Kconfig b/arch/um/Kconfig
index 6682c7883647..f945444df49c 100644
--- a/arch/um/Kconfig
+++ b/arch/um/Kconfig
@@ -275,6 +275,8 @@ endmenu
275 275
276source "init/Kconfig" 276source "init/Kconfig"
277 277
278source "net/Kconfig"
279
278source "drivers/base/Kconfig" 280source "drivers/base/Kconfig"
279 281
280source "arch/um/Kconfig_char" 282source "arch/um/Kconfig_char"
@@ -287,7 +289,7 @@ config NETDEVICES
287 289
288source "arch/um/Kconfig_net" 290source "arch/um/Kconfig_net"
289 291
290source "net/Kconfig" 292source "drivers/net/Kconfig"
291 293
292source "fs/Kconfig" 294source "fs/Kconfig"
293 295
diff --git a/arch/um/Makefile b/arch/um/Makefile
index 3f073902351f..4a375bbac109 100644
--- a/arch/um/Makefile
+++ b/arch/um/Makefile
@@ -140,7 +140,8 @@ endef
140#When cleaning we don't include .config, so we don't include 140#When cleaning we don't include .config, so we don't include
141#TT or skas makefiles and don't clean skas_ptregs.h. 141#TT or skas makefiles and don't clean skas_ptregs.h.
142CLEAN_FILES += linux x.i gmon.out $(ARCH_DIR)/include/uml-config.h \ 142CLEAN_FILES += linux x.i gmon.out $(ARCH_DIR)/include/uml-config.h \
143 $(GEN_HEADERS) $(ARCH_DIR)/include/skas_ptregs.h 143 $(GEN_HEADERS) $(ARCH_DIR)/include/skas_ptregs.h \
144 $(ARCH_DIR)/include/user_constants.h
144 145
145MRPROPER_FILES += $(SYMLINK_HEADERS) $(ARCH_SYMLINKS) \ 146MRPROPER_FILES += $(SYMLINK_HEADERS) $(ARCH_SYMLINKS) \
146 $(addprefix $(ARCH_DIR)/kernel/,$(KERN_SYMLINKS)) $(ARCH_DIR)/os \ 147 $(addprefix $(ARCH_DIR)/kernel/,$(KERN_SYMLINKS)) $(ARCH_DIR)/os \
diff --git a/arch/v850/Kconfig b/arch/v850/Kconfig
index 27febd6ffa80..89c053b6c2c4 100644
--- a/arch/v850/Kconfig
+++ b/arch/v850/Kconfig
@@ -250,6 +250,8 @@ source "fs/Kconfig.binfmt"
250 250
251endmenu 251endmenu
252 252
253source "net/Kconfig"
254
253############################################################################# 255#############################################################################
254 256
255source "drivers/base/Kconfig" 257source "drivers/base/Kconfig"
@@ -283,7 +285,7 @@ source "drivers/ieee1394/Kconfig"
283 285
284source "drivers/message/i2o/Kconfig" 286source "drivers/message/i2o/Kconfig"
285 287
286source "net/Kconfig" 288source "drivers/net/Kconfig"
287 289
288source "drivers/isdn/Kconfig" 290source "drivers/isdn/Kconfig"
289 291
diff --git a/arch/x86_64/Kconfig b/arch/x86_64/Kconfig
index d09437b5c48f..4b8326177c52 100644
--- a/arch/x86_64/Kconfig
+++ b/arch/x86_64/Kconfig
@@ -515,6 +515,8 @@ config UID16
515 515
516endmenu 516endmenu
517 517
518source "net/Kconfig"
519
518source drivers/Kconfig 520source drivers/Kconfig
519 521
520source "drivers/firmware/Kconfig" 522source "drivers/firmware/Kconfig"
diff --git a/arch/x86_64/kernel/vmlinux.lds.S b/arch/x86_64/kernel/vmlinux.lds.S
index 61c12758ca70..2a94f9b60b2d 100644
--- a/arch/x86_64/kernel/vmlinux.lds.S
+++ b/arch/x86_64/kernel/vmlinux.lds.S
@@ -62,8 +62,8 @@ SECTIONS
62 } 62 }
63 63
64#define VSYSCALL_ADDR (-10*1024*1024) 64#define VSYSCALL_ADDR (-10*1024*1024)
65#define VSYSCALL_PHYS_ADDR ((LOADADDR(.data.cacheline_aligned) + SIZEOF(.data.cacheline_aligned) + 4095) & ~(4095)) 65#define VSYSCALL_PHYS_ADDR ((LOADADDR(.data.read_mostly) + SIZEOF(.data.read_mostly) + 4095) & ~(4095))
66#define VSYSCALL_VIRT_ADDR ((ADDR(.data.cacheline_aligned) + SIZEOF(.data.cacheline_aligned) + 4095) & ~(4095)) 66#define VSYSCALL_VIRT_ADDR ((ADDR(.data.read_mostly) + SIZEOF(.data.read_mostly) + 4095) & ~(4095))
67 67
68#define VLOAD_OFFSET (VSYSCALL_ADDR - VSYSCALL_PHYS_ADDR) 68#define VLOAD_OFFSET (VSYSCALL_ADDR - VSYSCALL_PHYS_ADDR)
69#define VLOAD(x) (ADDR(x) - VLOAD_OFFSET) 69#define VLOAD(x) (ADDR(x) - VLOAD_OFFSET)
diff --git a/arch/xtensa/Kconfig b/arch/xtensa/Kconfig
index c9b5d298e3c4..2b6257bec4c3 100644
--- a/arch/xtensa/Kconfig
+++ b/arch/xtensa/Kconfig
@@ -228,6 +228,8 @@ source "fs/Kconfig.binfmt"
228 228
229endmenu 229endmenu
230 230
231source "net/Kconfig"
232
231source "drivers/Kconfig" 233source "drivers/Kconfig"
232 234
233source "fs/Kconfig" 235source "fs/Kconfig"
diff --git a/arch/xtensa/kernel/asm-offsets.c b/arch/xtensa/kernel/asm-offsets.c
index 840cd9a1d3d2..7cd1d7f8f608 100644
--- a/arch/xtensa/kernel/asm-offsets.c
+++ b/arch/xtensa/kernel/asm-offsets.c
@@ -15,7 +15,6 @@
15#include <asm/processor.h> 15#include <asm/processor.h>
16 16
17#include <linux/types.h> 17#include <linux/types.h>
18#include <linux/sched.h>
19#include <linux/stddef.h> 18#include <linux/stddef.h>
20#include <linux/thread_info.h> 19#include <linux/thread_info.h>
21#include <linux/ptrace.h> 20#include <linux/ptrace.h>
diff --git a/arch/xtensa/kernel/syscalls.c b/arch/xtensa/kernel/syscalls.c
index 7270509c44de..f20c6494c518 100644
--- a/arch/xtensa/kernel/syscalls.c
+++ b/arch/xtensa/kernel/syscalls.c
@@ -69,8 +69,8 @@ int sys_pipe(int __user *userfds)
69/* 69/*
70 * Common code for old and new mmaps. 70 * Common code for old and new mmaps.
71 */ 71 */
72long sys_mmap2(unsigned long addr, unsigned long len, unsigned long prot, 72long sys_mmap(unsigned long addr, unsigned long len, unsigned long prot,
73 unsigned long flags, unsigned long fd, unsigned long pgoff) 73 unsigned long flags, unsigned long fd, unsigned long pgoff)
74{ 74{
75 int error = -EBADF; 75 int error = -EBADF;
76 struct file * file = NULL; 76 struct file * file = NULL;
diff --git a/arch/xtensa/kernel/syscalls.h b/arch/xtensa/kernel/syscalls.h
index 07580696b602..216c10a31501 100644
--- a/arch/xtensa/kernel/syscalls.h
+++ b/arch/xtensa/kernel/syscalls.h
@@ -42,7 +42,7 @@ SYSCALL(sys_mknod, 3)
42SYSCALL(sys_chmod, 2) /* 15 */ 42SYSCALL(sys_chmod, 2) /* 15 */
43SYSCALL(sys_lchown, 3) 43SYSCALL(sys_lchown, 3)
44SYSCALL(sys_ni_syscall, 0) 44SYSCALL(sys_ni_syscall, 0)
45SYSCALL(sys_stat, 2) 45SYSCALL(sys_newstat, 2)
46SYSCALL(sys_lseek, 3) 46SYSCALL(sys_lseek, 3)
47SYSCALL(sys_getpid, 0) /* 20 */ 47SYSCALL(sys_getpid, 0) /* 20 */
48SYSCALL(sys_mount, 5) 48SYSCALL(sys_mount, 5)
@@ -52,7 +52,7 @@ SYSCALL(sys_getuid, 0)
52SYSCALL(sys_ni_syscall, 1) /* 25 */ 52SYSCALL(sys_ni_syscall, 1) /* 25 */
53SYSCALL(sys_ptrace, 4) 53SYSCALL(sys_ptrace, 4)
54SYSCALL(sys_ni_syscall, 1) 54SYSCALL(sys_ni_syscall, 1)
55SYSCALL(sys_fstat, 2) 55SYSCALL(sys_newfstat, 2)
56SYSCALL(sys_ni_syscall, 0) 56SYSCALL(sys_ni_syscall, 0)
57SYSCALL(sys_utime, 2) /* 30 */ 57SYSCALL(sys_utime, 2) /* 30 */
58SYSCALL(sys_ni_syscall, 0) 58SYSCALL(sys_ni_syscall, 0)
@@ -108,7 +108,7 @@ SYSCALL(sys_getgroups, 2) /* 80 */
108SYSCALL(sys_setgroups, 2) 108SYSCALL(sys_setgroups, 2)
109SYSCALL(sys_ni_syscall, 0) 109SYSCALL(sys_ni_syscall, 0)
110SYSCALL(sys_symlink, 2) 110SYSCALL(sys_symlink, 2)
111SYSCALL(sys_lstat, 2) 111SYSCALL(sys_newlstat, 2)
112SYSCALL(sys_readlink, 3) /* 85 */ 112SYSCALL(sys_readlink, 3) /* 85 */
113SYSCALL(sys_uselib, 1) 113SYSCALL(sys_uselib, 1)
114SYSCALL(sys_swapon, 2) 114SYSCALL(sys_swapon, 2)
diff --git a/arch/xtensa/kernel/traps.c b/arch/xtensa/kernel/traps.c
index 804246e743b1..225d64d73f04 100644
--- a/arch/xtensa/kernel/traps.c
+++ b/arch/xtensa/kernel/traps.c
@@ -29,6 +29,7 @@
29#include <linux/module.h> 29#include <linux/module.h>
30#include <linux/stringify.h> 30#include <linux/stringify.h>
31#include <linux/kallsyms.h> 31#include <linux/kallsyms.h>
32#include <linux/delay.h>
32 33
33#include <asm/ptrace.h> 34#include <asm/ptrace.h>
34#include <asm/timex.h> 35#include <asm/timex.h>
@@ -488,8 +489,7 @@ void die(const char * str, struct pt_regs * regs, long err)
488 489
489 if (panic_on_oops) { 490 if (panic_on_oops) {
490 printk(KERN_EMERG "Fatal exception: panic in 5 seconds\n"); 491 printk(KERN_EMERG "Fatal exception: panic in 5 seconds\n");
491 set_current_state(TASK_UNINTERRUPTIBLE); 492 ssleep(5);
492 schedule_timeout(5 * HZ);
493 panic("Fatal exception"); 493 panic("Fatal exception");
494 } 494 }
495 do_exit(err); 495 do_exit(err);
diff --git a/arch/xtensa/kernel/vmlinux.lds.S b/arch/xtensa/kernel/vmlinux.lds.S
index 476b2b53cd01..5ed71dfc8110 100644
--- a/arch/xtensa/kernel/vmlinux.lds.S
+++ b/arch/xtensa/kernel/vmlinux.lds.S
@@ -90,10 +90,10 @@ SECTIONS
90 *(.literal .text) 90 *(.literal .text)
91 *(.srom.text) 91 *(.srom.text)
92 VMLINUX_SYMBOL(__sched_text_start) = .; 92 VMLINUX_SYMBOL(__sched_text_start) = .;
93 *(.sched.text.literal .sched.text) 93 *(.sched.literal .sched.text)
94 VMLINUX_SYMBOL(__sched_text_end) = .; 94 VMLINUX_SYMBOL(__sched_text_end) = .;
95 VMLINUX_SYMBOL(__lock_text_start) = .; 95 VMLINUX_SYMBOL(__lock_text_start) = .;
96 *(.spinlock.text.literal .spinlock.text) 96 *(.spinlock.literal .spinlock.text)
97 VMLINUX_SYMBOL(__lock_text_end) = .; 97 VMLINUX_SYMBOL(__lock_text_end) = .;
98 98
99 } 99 }
@@ -164,7 +164,7 @@ SECTIONS
164 __init_begin = .; 164 __init_begin = .;
165 .init.text : { 165 .init.text : {
166 _sinittext = .; 166 _sinittext = .;
167 *(.init.text.literal) *(.init.text) 167 *(.init.literal) *(.init.text)
168 _einittext = .; 168 _einittext = .;
169 } 169 }
170 170
diff --git a/drivers/Kconfig b/drivers/Kconfig
index aed4a9b97c14..cecab0acc3fe 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -28,7 +28,7 @@ source "drivers/message/i2o/Kconfig"
28 28
29source "drivers/macintosh/Kconfig" 29source "drivers/macintosh/Kconfig"
30 30
31source "net/Kconfig" 31source "drivers/net/Kconfig"
32 32
33source "drivers/isdn/Kconfig" 33source "drivers/isdn/Kconfig"
34 34
@@ -44,6 +44,8 @@ source "drivers/i2c/Kconfig"
44 44
45source "drivers/w1/Kconfig" 45source "drivers/w1/Kconfig"
46 46
47source "drivers/hwmon/Kconfig"
48
47source "drivers/misc/Kconfig" 49source "drivers/misc/Kconfig"
48 50
49source "drivers/media/Kconfig" 51source "drivers/media/Kconfig"
diff --git a/drivers/Makefile b/drivers/Makefile
index 3167be54fedd..126a851d5653 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -52,6 +52,7 @@ obj-$(CONFIG_INPUT) += input/
52obj-$(CONFIG_I2O) += message/ 52obj-$(CONFIG_I2O) += message/
53obj-$(CONFIG_I2C) += i2c/ 53obj-$(CONFIG_I2C) += i2c/
54obj-$(CONFIG_W1) += w1/ 54obj-$(CONFIG_W1) += w1/
55obj-$(CONFIG_HWMON) += hwmon/
55obj-$(CONFIG_PHONE) += telephony/ 56obj-$(CONFIG_PHONE) += telephony/
56obj-$(CONFIG_MD) += md/ 57obj-$(CONFIG_MD) += md/
57obj-$(CONFIG_BT) += bluetooth/ 58obj-$(CONFIG_BT) += bluetooth/
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig
index 86c52520ed34..986410e7b483 100644
--- a/drivers/acpi/Kconfig
+++ b/drivers/acpi/Kconfig
@@ -3,6 +3,7 @@
3# 3#
4 4
5menu "ACPI (Advanced Configuration and Power Interface) Support" 5menu "ACPI (Advanced Configuration and Power Interface) Support"
6 depends on PM
6 depends on !X86_VISWS 7 depends on !X86_VISWS
7 depends on !IA64_HP_SIM 8 depends on !IA64_HP_SIM
8 depends on IA64 || X86 9 depends on IA64 || X86
@@ -48,7 +49,6 @@ config ACPI_BOOT
48 49
49config ACPI_INTERPRETER 50config ACPI_INTERPRETER
50 bool 51 bool
51 depends on !IA64_SGI_SN
52 default y 52 default y
53 53
54if ACPI_INTERPRETER 54if ACPI_INTERPRETER
@@ -79,6 +79,14 @@ config ACPI_SLEEP_PROC_FS
79 depends on ACPI_SLEEP && PROC_FS 79 depends on ACPI_SLEEP && PROC_FS
80 default y 80 default y
81 81
82config ACPI_SLEEP_PROC_SLEEP
83 bool "/proc/acpi/sleep (deprecated)"
84 depends on ACPI_SLEEP_PROC_FS
85 default n
86 ---help---
87 Create /proc/acpi/sleep
88 Deprecated by /sys/power/state
89
82config ACPI_AC 90config ACPI_AC
83 tristate "AC Adapter" 91 tristate "AC Adapter"
84 depends on X86 92 depends on X86
@@ -99,7 +107,6 @@ config ACPI_BATTERY
99 107
100config ACPI_BUTTON 108config ACPI_BUTTON
101 tristate "Button" 109 tristate "Button"
102 depends on !IA64_SGI_SN
103 default m 110 default m
104 help 111 help
105 This driver registers for events based on buttons, such as the 112 This driver registers for events based on buttons, such as the
@@ -111,7 +118,6 @@ config ACPI_BUTTON
111config ACPI_VIDEO 118config ACPI_VIDEO
112 tristate "Video" 119 tristate "Video"
113 depends on EXPERIMENTAL 120 depends on EXPERIMENTAL
114 depends on !IA64_SGI_SN
115 default m 121 default m
116 help 122 help
117 This driver implement the ACPI Extensions For Display Adapters 123 This driver implement the ACPI Extensions For Display Adapters
@@ -122,9 +128,17 @@ config ACPI_VIDEO
122 Note that this is an ref. implementation only. It may or may not work 128 Note that this is an ref. implementation only. It may or may not work
123 for your integrated video device. 129 for your integrated video device.
124 130
131config ACPI_HOTKEY
132 tristate "Generic Hotkey"
133 depends on ACPI_INTERPRETER
134 depends on EXPERIMENTAL
135 depends on !IA64_SGI_SN
136 default m
137 help
138 ACPI generic hotkey
139
125config ACPI_FAN 140config ACPI_FAN
126 tristate "Fan" 141 tristate "Fan"
127 depends on !IA64_SGI_SN
128 default m 142 default m
129 help 143 help
130 This driver adds support for ACPI fan devices, allowing user-mode 144 This driver adds support for ACPI fan devices, allowing user-mode
@@ -132,7 +146,6 @@ config ACPI_FAN
132 146
133config ACPI_PROCESSOR 147config ACPI_PROCESSOR
134 tristate "Processor" 148 tristate "Processor"
135 depends on !IA64_SGI_SN
136 default m 149 default m
137 help 150 help
138 This driver installs ACPI as the idle handler for Linux, and uses 151 This driver installs ACPI as the idle handler for Linux, and uses
@@ -142,7 +155,6 @@ config ACPI_PROCESSOR
142config ACPI_HOTPLUG_CPU 155config ACPI_HOTPLUG_CPU
143 bool "Processor Hotplug (EXPERIMENTAL)" 156 bool "Processor Hotplug (EXPERIMENTAL)"
144 depends on ACPI_PROCESSOR && HOTPLUG_CPU && EXPERIMENTAL 157 depends on ACPI_PROCESSOR && HOTPLUG_CPU && EXPERIMENTAL
145 depends on !IA64_SGI_SN
146 select ACPI_CONTAINER 158 select ACPI_CONTAINER
147 default n 159 default n
148 ---help--- 160 ---help---
@@ -262,7 +274,6 @@ config ACPI_BLACKLIST_YEAR
262 274
263config ACPI_DEBUG 275config ACPI_DEBUG
264 bool "Debug Statements" 276 bool "Debug Statements"
265 depends on !IA64_SGI_SN
266 default n 277 default n
267 help 278 help
268 The ACPI driver can optionally report errors with a great deal 279 The ACPI driver can optionally report errors with a great deal
@@ -271,7 +282,6 @@ config ACPI_DEBUG
271 282
272config ACPI_BUS 283config ACPI_BUS
273 bool 284 bool
274 depends on !IA64_SGI_SN
275 default y 285 default y
276 286
277config ACPI_EC 287config ACPI_EC
@@ -285,17 +295,14 @@ config ACPI_EC
285 295
286config ACPI_POWER 296config ACPI_POWER
287 bool 297 bool
288 depends on !IA64_SGI_SN
289 default y 298 default y
290 299
291config ACPI_PCI 300config ACPI_PCI
292 bool 301 bool
293 depends on !IA64_SGI_SN
294 default PCI 302 default PCI
295 303
296config ACPI_SYSTEM 304config ACPI_SYSTEM
297 bool 305 bool
298 depends on !IA64_SGI_SN
299 default y 306 default y
300 help 307 help
301 This driver will enable your system to shut down using ACPI, and 308 This driver will enable your system to shut down using ACPI, and
@@ -327,8 +334,13 @@ config ACPI_CONTAINER
327 depends on EXPERIMENTAL 334 depends on EXPERIMENTAL
328 default (ACPI_HOTPLUG_MEMORY || ACPI_HOTPLUG_CPU || ACPI_HOTPLUG_IO) 335 default (ACPI_HOTPLUG_MEMORY || ACPI_HOTPLUG_CPU || ACPI_HOTPLUG_IO)
329 ---help--- 336 ---help---
330 This is the ACPI generic container driver which supports 337 This allows _physical_ insertion and removal of CPUs and memory.
331 ACPI0004, PNP0A05 and PNP0A06 devices 338 This can be useful, for example, on NUMA machines that support
339 ACPI based physical hotplug of nodes, or non-NUMA machines that
340 support physical cpu/memory hot-plug.
341
342 If one selects "m", this driver can be loaded with
343 "modprobe acpi_container".
332 344
333config ACPI_HOTPLUG_MEMORY 345config ACPI_HOTPLUG_MEMORY
334 tristate "Memory Hotplug" 346 tristate "Memory Hotplug"
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index 65c92e20566d..ad67e8f61e6c 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -36,13 +36,14 @@ processor-objs += processor_perflib.o
36endif 36endif
37 37
38obj-$(CONFIG_ACPI_BUS) += sleep/ 38obj-$(CONFIG_ACPI_BUS) += sleep/
39obj-$(CONFIG_ACPI_BUS) += bus.o 39obj-$(CONFIG_ACPI_BUS) += bus.o glue.o
40obj-$(CONFIG_ACPI_AC) += ac.o 40obj-$(CONFIG_ACPI_AC) += ac.o
41obj-$(CONFIG_ACPI_BATTERY) += battery.o 41obj-$(CONFIG_ACPI_BATTERY) += battery.o
42obj-$(CONFIG_ACPI_BUTTON) += button.o 42obj-$(CONFIG_ACPI_BUTTON) += button.o
43obj-$(CONFIG_ACPI_EC) += ec.o 43obj-$(CONFIG_ACPI_EC) += ec.o
44obj-$(CONFIG_ACPI_FAN) += fan.o 44obj-$(CONFIG_ACPI_FAN) += fan.o
45obj-$(CONFIG_ACPI_VIDEO) += video.o 45obj-$(CONFIG_ACPI_VIDEO) += video.o
46obj-$(CONFIG_ACPI_HOTKEY) += hotkey.o
46obj-$(CONFIG_ACPI_PCI) += pci_root.o pci_link.o pci_irq.o pci_bind.o 47obj-$(CONFIG_ACPI_PCI) += pci_root.o pci_link.o pci_irq.o pci_bind.o
47obj-$(CONFIG_ACPI_POWER) += power.o 48obj-$(CONFIG_ACPI_POWER) += power.o
48obj-$(CONFIG_ACPI_PROCESSOR) += processor.o 49obj-$(CONFIG_ACPI_PROCESSOR) += processor.o
diff --git a/drivers/acpi/asus_acpi.c b/drivers/acpi/asus_acpi.c
index a75cb565caeb..a560b1e2da77 100644
--- a/drivers/acpi/asus_acpi.c
+++ b/drivers/acpi/asus_acpi.c
@@ -1204,6 +1204,10 @@ static int __init asus_acpi_init(void)
1204 if (acpi_disabled) 1204 if (acpi_disabled)
1205 return -ENODEV; 1205 return -ENODEV;
1206 1206
1207 if (!acpi_specific_hotkey_enabled){
1208 printk(KERN_ERR "Using generic hotkey driver\n");
1209 return -ENODEV;
1210 }
1207 asus_proc_dir = proc_mkdir(PROC_ASUS, acpi_root_dir); 1211 asus_proc_dir = proc_mkdir(PROC_ASUS, acpi_root_dir);
1208 if (!asus_proc_dir) { 1212 if (!asus_proc_dir) {
1209 printk(KERN_ERR "Asus ACPI: Unable to create /proc entry\n"); 1213 printk(KERN_ERR "Asus ACPI: Unable to create /proc entry\n");
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index 4edff1738579..d77c2307883c 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -212,6 +212,12 @@ acpi_bus_set_power (
212 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Device is not power manageable\n")); 212 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Device is not power manageable\n"));
213 return_VALUE(-ENODEV); 213 return_VALUE(-ENODEV);
214 } 214 }
215 /*
216 * Get device's current power state if it's unknown
217 * This means device power state isn't initialized or previous setting failed
218 */
219 if (device->power.state == ACPI_STATE_UNKNOWN)
220 acpi_bus_get_power(device->handle, &device->power.state);
215 if (state == device->power.state) { 221 if (state == device->power.state) {
216 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n", state)); 222 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n", state));
217 return_VALUE(0); 223 return_VALUE(0);
@@ -231,7 +237,7 @@ acpi_bus_set_power (
231 * On transitions to a high-powered state we first apply power (via 237 * On transitions to a high-powered state we first apply power (via
232 * power resources) then evalute _PSx. Conversly for transitions to 238 * power resources) then evalute _PSx. Conversly for transitions to
233 * a lower-powered state. 239 * a lower-powered state.
234 */ 240 */
235 if (state < device->power.state) { 241 if (state < device->power.state) {
236 if (device->power.flags.power_resources) { 242 if (device->power.flags.power_resources) {
237 result = acpi_power_transition(device, state); 243 result = acpi_power_transition(device, state);
diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c
index ec4430e3053f..0f45d45f05a0 100644
--- a/drivers/acpi/button.c
+++ b/drivers/acpi/button.c
@@ -26,9 +26,6 @@
26#include <linux/kernel.h> 26#include <linux/kernel.h>
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/init.h> 28#include <linux/init.h>
29#include <linux/types.h>
30#include <linux/proc_fs.h>
31#include <linux/seq_file.h>
32#include <acpi/acpi_bus.h> 29#include <acpi/acpi_bus.h>
33#include <acpi/acpi_drivers.h> 30#include <acpi/acpi_drivers.h>
34 31
@@ -36,9 +33,6 @@
36#define ACPI_BUTTON_COMPONENT 0x00080000 33#define ACPI_BUTTON_COMPONENT 0x00080000
37#define ACPI_BUTTON_DRIVER_NAME "ACPI Button Driver" 34#define ACPI_BUTTON_DRIVER_NAME "ACPI Button Driver"
38#define ACPI_BUTTON_CLASS "button" 35#define ACPI_BUTTON_CLASS "button"
39#define ACPI_BUTTON_FILE_INFO "info"
40#define ACPI_BUTTON_FILE_STATE "state"
41#define ACPI_BUTTON_TYPE_UNKNOWN 0x00
42#define ACPI_BUTTON_NOTIFY_STATUS 0x80 36#define ACPI_BUTTON_NOTIFY_STATUS 0x80
43 37
44#define ACPI_BUTTON_SUBCLASS_POWER "power" 38#define ACPI_BUTTON_SUBCLASS_POWER "power"
@@ -70,8 +64,6 @@ MODULE_LICENSE("GPL");
70 64
71static int acpi_button_add (struct acpi_device *device); 65static int acpi_button_add (struct acpi_device *device);
72static int acpi_button_remove (struct acpi_device *device, int type); 66static int acpi_button_remove (struct acpi_device *device, int type);
73static int acpi_button_info_open_fs(struct inode *inode, struct file *file);
74static int acpi_button_state_open_fs(struct inode *inode, struct file *file);
75 67
76static struct acpi_driver acpi_button_driver = { 68static struct acpi_driver acpi_button_driver = {
77 .name = ACPI_BUTTON_DRIVER_NAME, 69 .name = ACPI_BUTTON_DRIVER_NAME,
@@ -90,187 +82,6 @@ struct acpi_button {
90 unsigned long pushed; 82 unsigned long pushed;
91}; 83};
92 84
93static struct file_operations acpi_button_info_fops = {
94 .open = acpi_button_info_open_fs,
95 .read = seq_read,
96 .llseek = seq_lseek,
97 .release = single_release,
98};
99
100static struct file_operations acpi_button_state_fops = {
101 .open = acpi_button_state_open_fs,
102 .read = seq_read,
103 .llseek = seq_lseek,
104 .release = single_release,
105};
106/* --------------------------------------------------------------------------
107 FS Interface (/proc)
108 -------------------------------------------------------------------------- */
109
110static struct proc_dir_entry *acpi_button_dir;
111
112static int acpi_button_info_seq_show(struct seq_file *seq, void *offset)
113{
114 struct acpi_button *button = (struct acpi_button *) seq->private;
115
116 ACPI_FUNCTION_TRACE("acpi_button_info_seq_show");
117
118 if (!button || !button->device)
119 return_VALUE(0);
120
121 seq_printf(seq, "type: %s\n",
122 acpi_device_name(button->device));
123
124 return_VALUE(0);
125}
126
127static int acpi_button_info_open_fs(struct inode *inode, struct file *file)
128{
129 return single_open(file, acpi_button_info_seq_show, PDE(inode)->data);
130}
131
132static int acpi_button_state_seq_show(struct seq_file *seq, void *offset)
133{
134 struct acpi_button *button = (struct acpi_button *) seq->private;
135 acpi_status status;
136 unsigned long state;
137
138 ACPI_FUNCTION_TRACE("acpi_button_state_seq_show");
139
140 if (!button || !button->device)
141 return_VALUE(0);
142
143 status = acpi_evaluate_integer(button->handle,"_LID",NULL,&state);
144 if (ACPI_FAILURE(status)) {
145 seq_printf(seq, "state: unsupported\n");
146 }
147 else{
148 seq_printf(seq, "state: %s\n", (state ? "open" : "closed"));
149 }
150
151 return_VALUE(0);
152}
153
154static int acpi_button_state_open_fs(struct inode *inode, struct file *file)
155{
156 return single_open(file, acpi_button_state_seq_show, PDE(inode)->data);
157}
158
159static int
160acpi_button_add_fs (
161 struct acpi_device *device)
162{
163 struct proc_dir_entry *entry = NULL;
164 struct acpi_button *button = NULL;
165
166 ACPI_FUNCTION_TRACE("acpi_button_add_fs");
167
168 if (!device || !acpi_driver_data(device))
169 return_VALUE(-EINVAL);
170
171 button = acpi_driver_data(device);
172
173 switch (button->type) {
174 case ACPI_BUTTON_TYPE_POWER:
175 case ACPI_BUTTON_TYPE_POWERF:
176 entry = proc_mkdir(ACPI_BUTTON_SUBCLASS_POWER,
177 acpi_button_dir);
178 break;
179 case ACPI_BUTTON_TYPE_SLEEP:
180 case ACPI_BUTTON_TYPE_SLEEPF:
181 entry = proc_mkdir(ACPI_BUTTON_SUBCLASS_SLEEP,
182 acpi_button_dir);
183 break;
184 case ACPI_BUTTON_TYPE_LID:
185 entry = proc_mkdir(ACPI_BUTTON_SUBCLASS_LID,
186 acpi_button_dir);
187 break;
188 }
189
190 if (!entry)
191 return_VALUE(-ENODEV);
192 entry->owner = THIS_MODULE;
193
194 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), entry);
195 if (!acpi_device_dir(device))
196 return_VALUE(-ENODEV);
197 acpi_device_dir(device)->owner = THIS_MODULE;
198
199 /* 'info' [R] */
200 entry = create_proc_entry(ACPI_BUTTON_FILE_INFO,
201 S_IRUGO, acpi_device_dir(device));
202 if (!entry)
203 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
204 "Unable to create '%s' fs entry\n",
205 ACPI_BUTTON_FILE_INFO));
206 else {
207 entry->proc_fops = &acpi_button_info_fops;
208 entry->data = acpi_driver_data(device);
209 entry->owner = THIS_MODULE;
210 }
211
212 /* show lid state [R] */
213 if (button->type == ACPI_BUTTON_TYPE_LID) {
214 entry = create_proc_entry(ACPI_BUTTON_FILE_STATE,
215 S_IRUGO, acpi_device_dir(device));
216 if (!entry)
217 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
218 "Unable to create '%s' fs entry\n",
219 ACPI_BUTTON_FILE_INFO));
220 else {
221 entry->proc_fops = &acpi_button_state_fops;
222 entry->data = acpi_driver_data(device);
223 entry->owner = THIS_MODULE;
224 }
225 }
226
227 return_VALUE(0);
228}
229
230
231static int
232acpi_button_remove_fs (
233 struct acpi_device *device)
234{
235 struct acpi_button *button = NULL;
236
237 ACPI_FUNCTION_TRACE("acpi_button_remove_fs");
238
239 button = acpi_driver_data(device);
240 if (acpi_device_dir(device)) {
241 if (button->type == ACPI_BUTTON_TYPE_LID)
242 remove_proc_entry(ACPI_BUTTON_FILE_STATE,
243 acpi_device_dir(device));
244 remove_proc_entry(ACPI_BUTTON_FILE_INFO,
245 acpi_device_dir(device));
246
247 remove_proc_entry(acpi_device_bid(device),
248 acpi_device_dir(device)->parent);
249
250
251 switch (button->type) {
252 case ACPI_BUTTON_TYPE_POWER:
253 case ACPI_BUTTON_TYPE_POWERF:
254 remove_proc_entry(ACPI_BUTTON_SUBCLASS_POWER,
255 acpi_button_dir);
256 break;
257 case ACPI_BUTTON_TYPE_SLEEP:
258 case ACPI_BUTTON_TYPE_SLEEPF:
259 remove_proc_entry(ACPI_BUTTON_SUBCLASS_SLEEP,
260 acpi_button_dir);
261 break;
262 case ACPI_BUTTON_TYPE_LID:
263 remove_proc_entry(ACPI_BUTTON_SUBCLASS_LID,
264 acpi_button_dir);
265 break;
266 }
267 acpi_device_dir(device) = NULL;
268 }
269
270 return_VALUE(0);
271}
272
273
274/* -------------------------------------------------------------------------- 85/* --------------------------------------------------------------------------
275 Driver Interface 86 Driver Interface
276 -------------------------------------------------------------------------- */ 87 -------------------------------------------------------------------------- */
@@ -310,8 +121,7 @@ acpi_button_notify_fixed (
310 121
311 ACPI_FUNCTION_TRACE("acpi_button_notify_fixed"); 122 ACPI_FUNCTION_TRACE("acpi_button_notify_fixed");
312 123
313 if (!button) 124 BUG_ON(!button);
314 return_ACPI_STATUS(AE_BAD_PARAMETER);
315 125
316 acpi_button_notify(button->handle, ACPI_BUTTON_NOTIFY_STATUS, button); 126 acpi_button_notify(button->handle, ACPI_BUTTON_NOTIFY_STATUS, button);
317 127
@@ -327,10 +137,6 @@ acpi_button_add (
327 acpi_status status = AE_OK; 137 acpi_status status = AE_OK;
328 struct acpi_button *button = NULL; 138 struct acpi_button *button = NULL;
329 139
330 static struct acpi_device *power_button;
331 static struct acpi_device *sleep_button;
332 static struct acpi_device *lid_button;
333
334 ACPI_FUNCTION_TRACE("acpi_button_add"); 140 ACPI_FUNCTION_TRACE("acpi_button_add");
335 141
336 if (!device) 142 if (!device)
@@ -391,42 +197,6 @@ acpi_button_add (
391 goto end; 197 goto end;
392 } 198 }
393 199
394 /*
395 * Ensure only one button of each type is used.
396 */
397 switch (button->type) {
398 case ACPI_BUTTON_TYPE_POWER:
399 case ACPI_BUTTON_TYPE_POWERF:
400 if (!power_button)
401 power_button = device;
402 else {
403 kfree(button);
404 return_VALUE(-ENODEV);
405 }
406 break;
407 case ACPI_BUTTON_TYPE_SLEEP:
408 case ACPI_BUTTON_TYPE_SLEEPF:
409 if (!sleep_button)
410 sleep_button = device;
411 else {
412 kfree(button);
413 return_VALUE(-ENODEV);
414 }
415 break;
416 case ACPI_BUTTON_TYPE_LID:
417 if (!lid_button)
418 lid_button = device;
419 else {
420 kfree(button);
421 return_VALUE(-ENODEV);
422 }
423 break;
424 }
425
426 result = acpi_button_add_fs(device);
427 if (result)
428 goto end;
429
430 switch (button->type) { 200 switch (button->type) {
431 case ACPI_BUTTON_TYPE_POWERF: 201 case ACPI_BUTTON_TYPE_POWERF:
432 status = acpi_install_fixed_event_handler ( 202 status = acpi_install_fixed_event_handler (
@@ -470,7 +240,6 @@ acpi_button_add (
470 240
471end: 241end:
472 if (result) { 242 if (result) {
473 acpi_button_remove_fs(device);
474 kfree(button); 243 kfree(button);
475 } 244 }
476 245
@@ -511,8 +280,6 @@ acpi_button_remove (struct acpi_device *device, int type)
511 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 280 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
512 "Error removing notify handler\n")); 281 "Error removing notify handler\n"));
513 282
514 acpi_button_remove_fs(device);
515
516 kfree(button); 283 kfree(button);
517 284
518 return_VALUE(0); 285 return_VALUE(0);
@@ -526,21 +293,14 @@ acpi_button_init (void)
526 293
527 ACPI_FUNCTION_TRACE("acpi_button_init"); 294 ACPI_FUNCTION_TRACE("acpi_button_init");
528 295
529 acpi_button_dir = proc_mkdir(ACPI_BUTTON_CLASS, acpi_root_dir);
530 if (!acpi_button_dir)
531 return_VALUE(-ENODEV);
532 acpi_button_dir->owner = THIS_MODULE;
533
534 result = acpi_bus_register_driver(&acpi_button_driver); 296 result = acpi_bus_register_driver(&acpi_button_driver);
535 if (result < 0) { 297 if (result < 0) {
536 remove_proc_entry(ACPI_BUTTON_CLASS, acpi_root_dir);
537 return_VALUE(-ENODEV); 298 return_VALUE(-ENODEV);
538 } 299 }
539 300
540 return_VALUE(0); 301 return_VALUE(0);
541} 302}
542 303
543
544static void __exit 304static void __exit
545acpi_button_exit (void) 305acpi_button_exit (void)
546{ 306{
@@ -548,11 +308,8 @@ acpi_button_exit (void)
548 308
549 acpi_bus_unregister_driver(&acpi_button_driver); 309 acpi_bus_unregister_driver(&acpi_button_driver);
550 310
551 remove_proc_entry(ACPI_BUTTON_CLASS, acpi_root_dir);
552
553 return_VOID; 311 return_VOID;
554} 312}
555 313
556
557module_init(acpi_button_init); 314module_init(acpi_button_init);
558module_exit(acpi_button_exit); 315module_exit(acpi_button_exit);
diff --git a/drivers/acpi/dispatcher/dsfield.c b/drivers/acpi/dispatcher/dsfield.c
index 2779211be756..84193983d6ba 100644
--- a/drivers/acpi/dispatcher/dsfield.c
+++ b/drivers/acpi/dispatcher/dsfield.c
@@ -53,13 +53,20 @@
53#define _COMPONENT ACPI_DISPATCHER 53#define _COMPONENT ACPI_DISPATCHER
54 ACPI_MODULE_NAME ("dsfield") 54 ACPI_MODULE_NAME ("dsfield")
55 55
56/* Local prototypes */
57
58static acpi_status
59acpi_ds_get_field_names (
60 struct acpi_create_field_info *info,
61 struct acpi_walk_state *walk_state,
62 union acpi_parse_object *arg);
63
56 64
57/******************************************************************************* 65/*******************************************************************************
58 * 66 *
59 * FUNCTION: acpi_ds_create_buffer_field 67 * FUNCTION: acpi_ds_create_buffer_field
60 * 68 *
61 * PARAMETERS: Opcode - The opcode to be executed 69 * PARAMETERS: Op - Current parse op (create_xXField)
62 * Operands - List of operands for the opcode
63 * walk_state - Current state 70 * walk_state - Current state
64 * 71 *
65 * RETURN: Status 72 * RETURN: Status
@@ -70,7 +77,7 @@
70 * create_word_field_op, 77 * create_word_field_op,
71 * create_dword_field_op, 78 * create_dword_field_op,
72 * create_qword_field_op, 79 * create_qword_field_op,
73 * create_field_op (all of which define fields in buffers) 80 * create_field_op (all of which define a field in a buffer)
74 * 81 *
75 ******************************************************************************/ 82 ******************************************************************************/
76 83
@@ -119,7 +126,8 @@ acpi_ds_create_buffer_field (
119 flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE; 126 flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE;
120 } 127 }
121 else { 128 else {
122 flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE | ACPI_NS_ERROR_IF_FOUND; 129 flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
130 ACPI_NS_ERROR_IF_FOUND;
123 } 131 }
124 132
125 /* 133 /*
@@ -134,16 +142,16 @@ acpi_ds_create_buffer_field (
134 } 142 }
135 } 143 }
136 144
137 /* We could put the returned object (Node) on the object stack for later, but 145 /* We could put the returned object (Node) on the object stack for later,
138 * for now, we will put it in the "op" object that the parser uses, so we 146 * but for now, we will put it in the "op" object that the parser uses,
139 * can get it again at the end of this scope 147 * so we can get it again at the end of this scope
140 */ 148 */
141 op->common.node = node; 149 op->common.node = node;
142 150
143 /* 151 /*
144 * If there is no object attached to the node, this node was just created and 152 * If there is no object attached to the node, this node was just created
145 * we need to create the field object. Otherwise, this was a lookup of an 153 * and we need to create the field object. Otherwise, this was a lookup
146 * existing node and we don't want to create the field object again. 154 * of an existing node and we don't want to create the field object again.
147 */ 155 */
148 obj_desc = acpi_ns_get_attached_object (node); 156 obj_desc = acpi_ns_get_attached_object (node);
149 if (obj_desc) { 157 if (obj_desc) {
@@ -205,7 +213,7 @@ cleanup:
205 * 213 *
206 ******************************************************************************/ 214 ******************************************************************************/
207 215
208acpi_status 216static acpi_status
209acpi_ds_get_field_names ( 217acpi_ds_get_field_names (
210 struct acpi_create_field_info *info, 218 struct acpi_create_field_info *info,
211 struct acpi_walk_state *walk_state, 219 struct acpi_walk_state *walk_state,
@@ -238,7 +246,8 @@ acpi_ds_get_field_names (
238 + (acpi_integer) arg->common.value.size; 246 + (acpi_integer) arg->common.value.size;
239 247
240 if (position > ACPI_UINT32_MAX) { 248 if (position > ACPI_UINT32_MAX) {
241 ACPI_REPORT_ERROR (("Bit offset within field too large (> 0xFFFFFFFF)\n")); 249 ACPI_REPORT_ERROR ((
250 "Bit offset within field too large (> 0xFFFFFFFF)\n"));
242 return_ACPI_STATUS (AE_SUPPORT); 251 return_ACPI_STATUS (AE_SUPPORT);
243 } 252 }
244 253
@@ -250,12 +259,15 @@ acpi_ds_get_field_names (
250 259
251 /* 260 /*
252 * Get a new access_type and access_attribute -- to be used for all 261 * Get a new access_type and access_attribute -- to be used for all
253 * field units that follow, until field end or another access_as keyword. 262 * field units that follow, until field end or another access_as
263 * keyword.
254 * 264 *
255 * In field_flags, preserve the flag bits other than the ACCESS_TYPE bits 265 * In field_flags, preserve the flag bits other than the
266 * ACCESS_TYPE bits
256 */ 267 */
257 info->field_flags = (u8) ((info->field_flags & ~(AML_FIELD_ACCESS_TYPE_MASK)) | 268 info->field_flags = (u8)
258 ((u8) ((u32) arg->common.value.integer >> 8))); 269 ((info->field_flags & ~(AML_FIELD_ACCESS_TYPE_MASK)) |
270 ((u8) ((u32) arg->common.value.integer >> 8)));
259 271
260 info->attribute = (u8) (arg->common.value.integer); 272 info->attribute = (u8) (arg->common.value.integer);
261 break; 273 break;
@@ -267,7 +279,8 @@ acpi_ds_get_field_names (
267 279
268 status = acpi_ns_lookup (walk_state->scope_info, 280 status = acpi_ns_lookup (walk_state->scope_info,
269 (char *) &arg->named.name, 281 (char *) &arg->named.name,
270 info->field_type, ACPI_IMODE_EXECUTE, ACPI_NS_DONT_OPEN_SCOPE, 282 info->field_type, ACPI_IMODE_EXECUTE,
283 ACPI_NS_DONT_OPEN_SCOPE,
271 walk_state, &info->field_node); 284 walk_state, &info->field_node);
272 if (ACPI_FAILURE (status)) { 285 if (ACPI_FAILURE (status)) {
273 ACPI_REPORT_NSERROR ((char *) &arg->named.name, status); 286 ACPI_REPORT_NSERROR ((char *) &arg->named.name, status);
@@ -295,8 +308,9 @@ acpi_ds_get_field_names (
295 + (acpi_integer) arg->common.value.size; 308 + (acpi_integer) arg->common.value.size;
296 309
297 if (position > ACPI_UINT32_MAX) { 310 if (position > ACPI_UINT32_MAX) {
298 ACPI_REPORT_ERROR (("Field [%4.4s] bit offset too large (> 0xFFFFFFFF)\n", 311 ACPI_REPORT_ERROR ((
299 (char *) &info->field_node->name)); 312 "Field [%4.4s] bit offset too large (> 0xFFFFFFFF)\n",
313 (char *) &info->field_node->name));
300 return_ACPI_STATUS (AE_SUPPORT); 314 return_ACPI_STATUS (AE_SUPPORT);
301 } 315 }
302 316
@@ -306,7 +320,8 @@ acpi_ds_get_field_names (
306 320
307 default: 321 default:
308 322
309 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Invalid opcode in field list: %X\n", 323 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
324 "Invalid opcode in field list: %X\n",
310 arg->common.aml_opcode)); 325 arg->common.aml_opcode));
311 return_ACPI_STATUS (AE_AML_BAD_OPCODE); 326 return_ACPI_STATUS (AE_AML_BAD_OPCODE);
312 } 327 }
@@ -435,7 +450,8 @@ acpi_ds_init_field_objects (
435 status = acpi_ns_lookup (walk_state->scope_info, 450 status = acpi_ns_lookup (walk_state->scope_info,
436 (char *) &arg->named.name, 451 (char *) &arg->named.name,
437 type, ACPI_IMODE_LOAD_PASS1, 452 type, ACPI_IMODE_LOAD_PASS1,
438 ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE | ACPI_NS_ERROR_IF_FOUND, 453 ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
454 ACPI_NS_ERROR_IF_FOUND,
439 walk_state, &node); 455 walk_state, &node);
440 if (ACPI_FAILURE (status)) { 456 if (ACPI_FAILURE (status)) {
441 ACPI_REPORT_NSERROR ((char *) &arg->named.name, status); 457 ACPI_REPORT_NSERROR ((char *) &arg->named.name, status);
diff --git a/drivers/acpi/dispatcher/dsinit.c b/drivers/acpi/dispatcher/dsinit.c
index b4d264dbbf67..d7790db50178 100644
--- a/drivers/acpi/dispatcher/dsinit.c
+++ b/drivers/acpi/dispatcher/dsinit.c
@@ -49,12 +49,21 @@
49#define _COMPONENT ACPI_DISPATCHER 49#define _COMPONENT ACPI_DISPATCHER
50 ACPI_MODULE_NAME ("dsinit") 50 ACPI_MODULE_NAME ("dsinit")
51 51
52/* Local prototypes */
53
54static acpi_status
55acpi_ds_init_one_object (
56 acpi_handle obj_handle,
57 u32 level,
58 void *context,
59 void **return_value);
60
52 61
53/******************************************************************************* 62/*******************************************************************************
54 * 63 *
55 * FUNCTION: acpi_ds_init_one_object 64 * FUNCTION: acpi_ds_init_one_object
56 * 65 *
57 * PARAMETERS: obj_handle - Node 66 * PARAMETERS: obj_handle - Node for the object
58 * Level - Current nesting level 67 * Level - Current nesting level
59 * Context - Points to a init info struct 68 * Context - Points to a init info struct
60 * return_value - Not used 69 * return_value - Not used
@@ -70,7 +79,7 @@
70 * 79 *
71 ******************************************************************************/ 80 ******************************************************************************/
72 81
73acpi_status 82static acpi_status
74acpi_ds_init_one_object ( 83acpi_ds_init_one_object (
75 acpi_handle obj_handle, 84 acpi_handle obj_handle,
76 u32 level, 85 u32 level,
@@ -105,7 +114,8 @@ acpi_ds_init_one_object (
105 114
106 status = acpi_ds_initialize_region (obj_handle); 115 status = acpi_ds_initialize_region (obj_handle);
107 if (ACPI_FAILURE (status)) { 116 if (ACPI_FAILURE (status)) {
108 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Region %p [%4.4s] - Init failure, %s\n", 117 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
118 "Region %p [%4.4s] - Init failure, %s\n",
109 obj_handle, acpi_ut_get_node_name (obj_handle), 119 obj_handle, acpi_ut_get_node_name (obj_handle),
110 acpi_format_exception (status))); 120 acpi_format_exception (status)));
111 } 121 }
@@ -118,8 +128,10 @@ acpi_ds_init_one_object (
118 128
119 info->method_count++; 129 info->method_count++;
120 130
121 /* Print a dot for each method unless we are going to print the entire pathname */ 131 /*
122 132 * Print a dot for each method unless we are going to print
133 * the entire pathname
134 */
123 if (!(acpi_dbg_level & ACPI_LV_INIT_NAMES)) { 135 if (!(acpi_dbg_level & ACPI_LV_INIT_NAMES)) {
124 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT, ".")); 136 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT, "."));
125 } 137 }
@@ -140,7 +152,8 @@ acpi_ds_init_one_object (
140 */ 152 */
141 status = acpi_ds_parse_method (obj_handle); 153 status = acpi_ds_parse_method (obj_handle);
142 if (ACPI_FAILURE (status)) { 154 if (ACPI_FAILURE (status)) {
143 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Method %p [%4.4s] - parse failure, %s\n", 155 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
156 "Method %p [%4.4s] - parse failure, %s\n",
144 obj_handle, acpi_ut_get_node_name (obj_handle), 157 obj_handle, acpi_ut_get_node_name (obj_handle),
145 acpi_format_exception (status))); 158 acpi_format_exception (status)));
146 159
@@ -154,7 +167,8 @@ acpi_ds_init_one_object (
154 * for every execution since there isn't much overhead 167 * for every execution since there isn't much overhead
155 */ 168 */
156 acpi_ns_delete_namespace_subtree (obj_handle); 169 acpi_ns_delete_namespace_subtree (obj_handle);
157 acpi_ns_delete_namespace_by_owner (((struct acpi_namespace_node *) obj_handle)->object->method.owning_id); 170 acpi_ns_delete_namespace_by_owner (
171 ((struct acpi_namespace_node *) obj_handle)->object->method.owning_id);
158 break; 172 break;
159 173
160 174
diff --git a/drivers/acpi/dispatcher/dsmethod.c b/drivers/acpi/dispatcher/dsmethod.c
index 9f0456cb9bb5..9fc3f4c033eb 100644
--- a/drivers/acpi/dispatcher/dsmethod.c
+++ b/drivers/acpi/dispatcher/dsmethod.c
@@ -153,12 +153,11 @@ acpi_ds_parse_method (
153 /* 153 /*
154 * Parse the method, first pass 154 * Parse the method, first pass
155 * 155 *
156 * The first pass load is where newly declared named objects are 156 * The first pass load is where newly declared named objects are added into
157 * added into the namespace. Actual evaluation of 157 * the namespace. Actual evaluation of the named objects (what would be
158 * the named objects (what would be called a "second 158 * called a "second pass") happens during the actual execution of the
159 * pass") happens during the actual execution of the 159 * method so that operands to the named objects can take on dynamic
160 * method so that operands to the named objects can 160 * run-time values.
161 * take on dynamic run-time values.
162 */ 161 */
163 status = acpi_ps_parse_aml (walk_state); 162 status = acpi_ps_parse_aml (walk_state);
164 if (ACPI_FAILURE (status)) { 163 if (ACPI_FAILURE (status)) {
diff --git a/drivers/acpi/dispatcher/dsmthdat.c b/drivers/acpi/dispatcher/dsmthdat.c
index f31d095f9833..f7998306f756 100644
--- a/drivers/acpi/dispatcher/dsmthdat.c
+++ b/drivers/acpi/dispatcher/dsmthdat.c
@@ -52,6 +52,29 @@
52#define _COMPONENT ACPI_DISPATCHER 52#define _COMPONENT ACPI_DISPATCHER
53 ACPI_MODULE_NAME ("dsmthdat") 53 ACPI_MODULE_NAME ("dsmthdat")
54 54
55/* Local prototypes */
56
57static void
58acpi_ds_method_data_delete_value (
59 u16 opcode,
60 u32 index,
61 struct acpi_walk_state *walk_state);
62
63static acpi_status
64acpi_ds_method_data_set_value (
65 u16 opcode,
66 u32 index,
67 union acpi_operand_object *object,
68 struct acpi_walk_state *walk_state);
69
70#ifdef ACPI_OBSOLETE_FUNCTIONS
71acpi_object_type
72acpi_ds_method_data_get_type (
73 u16 opcode,
74 u32 index,
75 struct acpi_walk_state *walk_state);
76#endif
77
55 78
56/******************************************************************************* 79/*******************************************************************************
57 * 80 *
@@ -62,8 +85,8 @@
62 * RETURN: Status 85 * RETURN: Status
63 * 86 *
64 * DESCRIPTION: Initialize the data structures that hold the method's arguments 87 * DESCRIPTION: Initialize the data structures that hold the method's arguments
65 * and locals. The data struct is an array of NTEs for each. 88 * and locals. The data struct is an array of namespace nodes for
66 * This allows ref_of and de_ref_of to work properly for these 89 * each - this allows ref_of and de_ref_of to work properly for these
67 * special data types. 90 * special data types.
68 * 91 *
69 * NOTES: walk_state fields are initialized to zero by the 92 * NOTES: walk_state fields are initialized to zero by the
@@ -92,7 +115,8 @@ acpi_ds_method_data_init (
92 walk_state->arguments[i].name.integer |= (i << 24); 115 walk_state->arguments[i].name.integer |= (i << 24);
93 walk_state->arguments[i].descriptor = ACPI_DESC_TYPE_NAMED; 116 walk_state->arguments[i].descriptor = ACPI_DESC_TYPE_NAMED;
94 walk_state->arguments[i].type = ACPI_TYPE_ANY; 117 walk_state->arguments[i].type = ACPI_TYPE_ANY;
95 walk_state->arguments[i].flags = ANOBJ_END_OF_PEER_LIST | ANOBJ_METHOD_ARG; 118 walk_state->arguments[i].flags = ANOBJ_END_OF_PEER_LIST |
119 ANOBJ_METHOD_ARG;
96 } 120 }
97 121
98 /* Init the method locals */ 122 /* Init the method locals */
@@ -104,7 +128,8 @@ acpi_ds_method_data_init (
104 walk_state->local_variables[i].name.integer |= (i << 24); 128 walk_state->local_variables[i].name.integer |= (i << 24);
105 walk_state->local_variables[i].descriptor = ACPI_DESC_TYPE_NAMED; 129 walk_state->local_variables[i].descriptor = ACPI_DESC_TYPE_NAMED;
106 walk_state->local_variables[i].type = ACPI_TYPE_ANY; 130 walk_state->local_variables[i].type = ACPI_TYPE_ANY;
107 walk_state->local_variables[i].flags = ANOBJ_END_OF_PEER_LIST | ANOBJ_METHOD_LOCAL; 131 walk_state->local_variables[i].flags = ANOBJ_END_OF_PEER_LIST |
132 ANOBJ_METHOD_LOCAL;
108 } 133 }
109 134
110 return_VOID; 135 return_VOID;
@@ -198,15 +223,18 @@ acpi_ds_method_data_init_args (
198 return_ACPI_STATUS (AE_OK); 223 return_ACPI_STATUS (AE_OK);
199 } 224 }
200 225
201 /* Copy passed parameters into the new method stack frame */ 226 /* Copy passed parameters into the new method stack frame */
202 227
203 while ((index < ACPI_METHOD_NUM_ARGS) && (index < max_param_count) && params[index]) { 228 while ((index < ACPI_METHOD_NUM_ARGS) &&
229 (index < max_param_count) &&
230 params[index]) {
204 /* 231 /*
205 * A valid parameter. 232 * A valid parameter.
206 * Store the argument in the method/walk descriptor. 233 * Store the argument in the method/walk descriptor.
207 * Do not copy the arg in order to implement call by reference 234 * Do not copy the arg in order to implement call by reference
208 */ 235 */
209 status = acpi_ds_method_data_set_value (AML_ARG_OP, index, params[index], walk_state); 236 status = acpi_ds_method_data_set_value (AML_ARG_OP, index,
237 params[index], walk_state);
210 if (ACPI_FAILURE (status)) { 238 if (ACPI_FAILURE (status)) {
211 return_ACPI_STATUS (status); 239 return_ACPI_STATUS (status);
212 } 240 }
@@ -224,11 +252,13 @@ acpi_ds_method_data_init_args (
224 * FUNCTION: acpi_ds_method_data_get_node 252 * FUNCTION: acpi_ds_method_data_get_node
225 * 253 *
226 * PARAMETERS: Opcode - Either AML_LOCAL_OP or AML_ARG_OP 254 * PARAMETERS: Opcode - Either AML_LOCAL_OP or AML_ARG_OP
227 * Index - which local_var or argument whose type 255 * Index - Which Local or Arg whose type to get
228 * to get
229 * walk_state - Current walk state object 256 * walk_state - Current walk state object
257 * Node - Where the node is returned.
230 * 258 *
231 * RETURN: Get the Node associated with a local or arg. 259 * RETURN: Status and node
260 *
261 * DESCRIPTION: Get the Node associated with a local or arg.
232 * 262 *
233 ******************************************************************************/ 263 ******************************************************************************/
234 264
@@ -249,7 +279,8 @@ acpi_ds_method_data_get_node (
249 case AML_LOCAL_OP: 279 case AML_LOCAL_OP:
250 280
251 if (index > ACPI_METHOD_MAX_LOCAL) { 281 if (index > ACPI_METHOD_MAX_LOCAL) {
252 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Local index %d is invalid (max %d)\n", 282 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
283 "Local index %d is invalid (max %d)\n",
253 index, ACPI_METHOD_MAX_LOCAL)); 284 index, ACPI_METHOD_MAX_LOCAL));
254 return_ACPI_STATUS (AE_AML_INVALID_INDEX); 285 return_ACPI_STATUS (AE_AML_INVALID_INDEX);
255 } 286 }
@@ -262,7 +293,8 @@ acpi_ds_method_data_get_node (
262 case AML_ARG_OP: 293 case AML_ARG_OP:
263 294
264 if (index > ACPI_METHOD_MAX_ARG) { 295 if (index > ACPI_METHOD_MAX_ARG) {
265 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Arg index %d is invalid (max %d)\n", 296 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
297 "Arg index %d is invalid (max %d)\n",
266 index, ACPI_METHOD_MAX_ARG)); 298 index, ACPI_METHOD_MAX_ARG));
267 return_ACPI_STATUS (AE_AML_INVALID_INDEX); 299 return_ACPI_STATUS (AE_AML_INVALID_INDEX);
268 } 300 }
@@ -286,7 +318,7 @@ acpi_ds_method_data_get_node (
286 * FUNCTION: acpi_ds_method_data_set_value 318 * FUNCTION: acpi_ds_method_data_set_value
287 * 319 *
288 * PARAMETERS: Opcode - Either AML_LOCAL_OP or AML_ARG_OP 320 * PARAMETERS: Opcode - Either AML_LOCAL_OP or AML_ARG_OP
289 * Index - which local_var or argument to get 321 * Index - Which Local or Arg to get
290 * Object - Object to be inserted into the stack entry 322 * Object - Object to be inserted into the stack entry
291 * walk_state - Current walk state object 323 * walk_state - Current walk state object
292 * 324 *
@@ -297,7 +329,7 @@ acpi_ds_method_data_get_node (
297 * 329 *
298 ******************************************************************************/ 330 ******************************************************************************/
299 331
300acpi_status 332static acpi_status
301acpi_ds_method_data_set_value ( 333acpi_ds_method_data_set_value (
302 u16 opcode, 334 u16 opcode,
303 u32 index, 335 u32 index,
@@ -340,68 +372,16 @@ acpi_ds_method_data_set_value (
340 372
341/******************************************************************************* 373/*******************************************************************************
342 * 374 *
343 * FUNCTION: acpi_ds_method_data_get_type
344 *
345 * PARAMETERS: Opcode - Either AML_LOCAL_OP or AML_ARG_OP
346 * Index - which local_var or argument whose type
347 * to get
348 * walk_state - Current walk state object
349 *
350 * RETURN: Data type of current value of the selected Arg or Local
351 *
352 ******************************************************************************/
353#ifdef ACPI_FUTURE_USAGE
354acpi_object_type
355acpi_ds_method_data_get_type (
356 u16 opcode,
357 u32 index,
358 struct acpi_walk_state *walk_state)
359{
360 acpi_status status;
361 struct acpi_namespace_node *node;
362 union acpi_operand_object *object;
363
364
365 ACPI_FUNCTION_TRACE ("ds_method_data_get_type");
366
367
368 /* Get the namespace node for the arg/local */
369
370 status = acpi_ds_method_data_get_node (opcode, index, walk_state, &node);
371 if (ACPI_FAILURE (status)) {
372 return_VALUE ((ACPI_TYPE_NOT_FOUND));
373 }
374
375 /* Get the object */
376
377 object = acpi_ns_get_attached_object (node);
378 if (!object) {
379 /* Uninitialized local/arg, return TYPE_ANY */
380
381 return_VALUE (ACPI_TYPE_ANY);
382 }
383
384 /* Get the object type */
385
386 return_VALUE (ACPI_GET_OBJECT_TYPE (object));
387}
388#endif /* ACPI_FUTURE_USAGE */
389
390
391/*******************************************************************************
392 *
393 * FUNCTION: acpi_ds_method_data_get_value 375 * FUNCTION: acpi_ds_method_data_get_value
394 * 376 *
395 * PARAMETERS: Opcode - Either AML_LOCAL_OP or AML_ARG_OP 377 * PARAMETERS: Opcode - Either AML_LOCAL_OP or AML_ARG_OP
396 * Index - which local_var or argument to get 378 * Index - which local_var or argument to get
397 * walk_state - Current walk state object 379 * walk_state - Current walk state object
398 * *dest_desc - Ptr to Descriptor into which selected Arg 380 * dest_desc - Where Arg or Local value is returned
399 * or Local value should be copied
400 * 381 *
401 * RETURN: Status 382 * RETURN: Status
402 * 383 *
403 * DESCRIPTION: Retrieve value of selected Arg or Local from the method frame 384 * DESCRIPTION: Retrieve value of selected Arg or Local for this method
404 * at the current top of the method stack.
405 * Used only in acpi_ex_resolve_to_value(). 385 * Used only in acpi_ex_resolve_to_value().
406 * 386 *
407 ******************************************************************************/ 387 ******************************************************************************/
@@ -467,14 +447,16 @@ acpi_ds_method_data_get_value (
467 else switch (opcode) { 447 else switch (opcode) {
468 case AML_ARG_OP: 448 case AML_ARG_OP:
469 449
470 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Uninitialized Arg[%d] at node %p\n", 450 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
451 "Uninitialized Arg[%d] at node %p\n",
471 index, node)); 452 index, node));
472 453
473 return_ACPI_STATUS (AE_AML_UNINITIALIZED_ARG); 454 return_ACPI_STATUS (AE_AML_UNINITIALIZED_ARG);
474 455
475 case AML_LOCAL_OP: 456 case AML_LOCAL_OP:
476 457
477 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Uninitialized Local[%d] at node %p\n", 458 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
459 "Uninitialized Local[%d] at node %p\n",
478 index, node)); 460 index, node));
479 461
480 return_ACPI_STATUS (AE_AML_UNINITIALIZED_LOCAL); 462 return_ACPI_STATUS (AE_AML_UNINITIALIZED_LOCAL);
@@ -506,12 +488,12 @@ acpi_ds_method_data_get_value (
506 * 488 *
507 * RETURN: None 489 * RETURN: None
508 * 490 *
509 * DESCRIPTION: Delete the entry at Opcode:Index on the method stack. Inserts 491 * DESCRIPTION: Delete the entry at Opcode:Index. Inserts
510 * a null into the stack slot after the object is deleted. 492 * a null into the stack slot after the object is deleted.
511 * 493 *
512 ******************************************************************************/ 494 ******************************************************************************/
513 495
514void 496static void
515acpi_ds_method_data_delete_value ( 497acpi_ds_method_data_delete_value (
516 u16 opcode, 498 u16 opcode,
517 u32 index, 499 u32 index,
@@ -562,7 +544,7 @@ acpi_ds_method_data_delete_value (
562 * FUNCTION: acpi_ds_store_object_to_local 544 * FUNCTION: acpi_ds_store_object_to_local
563 * 545 *
564 * PARAMETERS: Opcode - Either AML_LOCAL_OP or AML_ARG_OP 546 * PARAMETERS: Opcode - Either AML_LOCAL_OP or AML_ARG_OP
565 * Index - which local_var or argument to set 547 * Index - Which Local or Arg to set
566 * obj_desc - Value to be stored 548 * obj_desc - Value to be stored
567 * walk_state - Current walk state 549 * walk_state - Current walk state
568 * 550 *
@@ -651,19 +633,20 @@ acpi_ds_store_object_to_local (
651 */ 633 */
652 if (opcode == AML_ARG_OP) { 634 if (opcode == AML_ARG_OP) {
653 /* 635 /*
654 * Make sure that the object is the correct type. This may be overkill, but 636 * Make sure that the object is the correct type. This may be
655 * it is here because references were NS nodes in the past. Now they are 637 * overkill, butit is here because references were NS nodes in
656 * operand objects of type Reference. 638 * the past. Now they are operand objects of type Reference.
657 */ 639 */
658 if (ACPI_GET_DESCRIPTOR_TYPE (current_obj_desc) != ACPI_DESC_TYPE_OPERAND) { 640 if (ACPI_GET_DESCRIPTOR_TYPE (current_obj_desc) != ACPI_DESC_TYPE_OPERAND) {
659 ACPI_REPORT_ERROR (("Invalid descriptor type while storing to method arg: [%s]\n", 641 ACPI_REPORT_ERROR ((
660 acpi_ut_get_descriptor_name (current_obj_desc))); 642 "Invalid descriptor type while storing to method arg: [%s]\n",
643 acpi_ut_get_descriptor_name (current_obj_desc)));
661 return_ACPI_STATUS (AE_AML_INTERNAL); 644 return_ACPI_STATUS (AE_AML_INTERNAL);
662 } 645 }
663 646
664 /* 647 /*
665 * If we have a valid reference object that came from ref_of(), do the 648 * If we have a valid reference object that came from ref_of(),
666 * indirect store 649 * do the indirect store
667 */ 650 */
668 if ((current_obj_desc->common.type == ACPI_TYPE_LOCAL_REFERENCE) && 651 if ((current_obj_desc->common.type == ACPI_TYPE_LOCAL_REFERENCE) &&
669 (current_obj_desc->reference.opcode == AML_REF_OF_OP)) { 652 (current_obj_desc->reference.opcode == AML_REF_OF_OP)) {
@@ -713,3 +696,55 @@ acpi_ds_store_object_to_local (
713} 696}
714 697
715 698
699#ifdef ACPI_OBSOLETE_FUNCTIONS
700/*******************************************************************************
701 *
702 * FUNCTION: acpi_ds_method_data_get_type
703 *
704 * PARAMETERS: Opcode - Either AML_LOCAL_OP or AML_ARG_OP
705 * Index - Which Local or Arg whose type to get
706 * walk_state - Current walk state object
707 *
708 * RETURN: Data type of current value of the selected Arg or Local
709 *
710 * DESCRIPTION: Get the type of the object stored in the Local or Arg
711 *
712 ******************************************************************************/
713
714acpi_object_type
715acpi_ds_method_data_get_type (
716 u16 opcode,
717 u32 index,
718 struct acpi_walk_state *walk_state)
719{
720 acpi_status status;
721 struct acpi_namespace_node *node;
722 union acpi_operand_object *object;
723
724
725 ACPI_FUNCTION_TRACE ("ds_method_data_get_type");
726
727
728 /* Get the namespace node for the arg/local */
729
730 status = acpi_ds_method_data_get_node (opcode, index, walk_state, &node);
731 if (ACPI_FAILURE (status)) {
732 return_VALUE ((ACPI_TYPE_NOT_FOUND));
733 }
734
735 /* Get the object */
736
737 object = acpi_ns_get_attached_object (node);
738 if (!object) {
739 /* Uninitialized local/arg, return TYPE_ANY */
740
741 return_VALUE (ACPI_TYPE_ANY);
742 }
743
744 /* Get the object type */
745
746 return_VALUE (ACPI_GET_OBJECT_TYPE (object));
747}
748#endif
749
750
diff --git a/drivers/acpi/dispatcher/dsobject.c b/drivers/acpi/dispatcher/dsobject.c
index eb8af4785bcb..bfbae4e4c667 100644
--- a/drivers/acpi/dispatcher/dsobject.c
+++ b/drivers/acpi/dispatcher/dsobject.c
@@ -52,9 +52,15 @@
52#define _COMPONENT ACPI_DISPATCHER 52#define _COMPONENT ACPI_DISPATCHER
53 ACPI_MODULE_NAME ("dsobject") 53 ACPI_MODULE_NAME ("dsobject")
54 54
55static acpi_status
56acpi_ds_build_internal_object (
57 struct acpi_walk_state *walk_state,
58 union acpi_parse_object *op,
59 union acpi_operand_object **obj_desc_ptr);
60
55 61
56#ifndef ACPI_NO_METHOD_EXECUTION 62#ifndef ACPI_NO_METHOD_EXECUTION
57/***************************************************************************** 63/*******************************************************************************
58 * 64 *
59 * FUNCTION: acpi_ds_build_internal_object 65 * FUNCTION: acpi_ds_build_internal_object
60 * 66 *
@@ -67,9 +73,9 @@
67 * DESCRIPTION: Translate a parser Op object to the equivalent namespace object 73 * DESCRIPTION: Translate a parser Op object to the equivalent namespace object
68 * Simple objects are any objects other than a package object! 74 * Simple objects are any objects other than a package object!
69 * 75 *
70 ****************************************************************************/ 76 ******************************************************************************/
71 77
72acpi_status 78static acpi_status
73acpi_ds_build_internal_object ( 79acpi_ds_build_internal_object (
74 struct acpi_walk_state *walk_state, 80 struct acpi_walk_state *walk_state,
75 union acpi_parse_object *op, 81 union acpi_parse_object *op,
@@ -90,9 +96,11 @@ acpi_ds_build_internal_object (
90 * Otherwise, go ahead and look it up now 96 * Otherwise, go ahead and look it up now
91 */ 97 */
92 if (!op->common.node) { 98 if (!op->common.node) {
93 status = acpi_ns_lookup (walk_state->scope_info, op->common.value.string, 99 status = acpi_ns_lookup (walk_state->scope_info,
100 op->common.value.string,
94 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE, 101 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
95 ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, NULL, 102 ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
103 NULL,
96 (struct acpi_namespace_node **) &(op->common.node)); 104 (struct acpi_namespace_node **) &(op->common.node));
97 105
98 if (ACPI_FAILURE (status)) { 106 if (ACPI_FAILURE (status)) {
@@ -104,12 +112,14 @@ acpi_ds_build_internal_object (
104 112
105 /* Create and init the internal ACPI object */ 113 /* Create and init the internal ACPI object */
106 114
107 obj_desc = acpi_ut_create_internal_object ((acpi_ps_get_opcode_info (op->common.aml_opcode))->object_type); 115 obj_desc = acpi_ut_create_internal_object (
116 (acpi_ps_get_opcode_info (op->common.aml_opcode))->object_type);
108 if (!obj_desc) { 117 if (!obj_desc) {
109 return_ACPI_STATUS (AE_NO_MEMORY); 118 return_ACPI_STATUS (AE_NO_MEMORY);
110 } 119 }
111 120
112 status = acpi_ds_init_object_from_op (walk_state, op, op->common.aml_opcode, &obj_desc); 121 status = acpi_ds_init_object_from_op (walk_state, op, op->common.aml_opcode,
122 &obj_desc);
113 if (ACPI_FAILURE (status)) { 123 if (ACPI_FAILURE (status)) {
114 acpi_ut_remove_reference (obj_desc); 124 acpi_ut_remove_reference (obj_desc);
115 return_ACPI_STATUS (status); 125 return_ACPI_STATUS (status);
@@ -120,7 +130,7 @@ acpi_ds_build_internal_object (
120} 130}
121 131
122 132
123/***************************************************************************** 133/*******************************************************************************
124 * 134 *
125 * FUNCTION: acpi_ds_build_internal_buffer_obj 135 * FUNCTION: acpi_ds_build_internal_buffer_obj
126 * 136 *
@@ -134,7 +144,7 @@ acpi_ds_build_internal_object (
134 * DESCRIPTION: Translate a parser Op package object to the equivalent 144 * DESCRIPTION: Translate a parser Op package object to the equivalent
135 * namespace object 145 * namespace object
136 * 146 *
137 ****************************************************************************/ 147 ******************************************************************************/
138 148
139acpi_status 149acpi_status
140acpi_ds_build_internal_buffer_obj ( 150acpi_ds_build_internal_buffer_obj (
@@ -229,7 +239,7 @@ acpi_ds_build_internal_buffer_obj (
229} 239}
230 240
231 241
232/***************************************************************************** 242/*******************************************************************************
233 * 243 *
234 * FUNCTION: acpi_ds_build_internal_package_obj 244 * FUNCTION: acpi_ds_build_internal_package_obj
235 * 245 *
@@ -243,7 +253,7 @@ acpi_ds_build_internal_buffer_obj (
243 * DESCRIPTION: Translate a parser Op package object to the equivalent 253 * DESCRIPTION: Translate a parser Op package object to the equivalent
244 * namespace object 254 * namespace object
245 * 255 *
246 ****************************************************************************/ 256 ******************************************************************************/
247 257
248acpi_status 258acpi_status
249acpi_ds_build_internal_package_obj ( 259acpi_ds_build_internal_package_obj (
@@ -331,11 +341,12 @@ acpi_ds_build_internal_package_obj (
331 if (arg->common.aml_opcode == AML_INT_RETURN_VALUE_OP) { 341 if (arg->common.aml_opcode == AML_INT_RETURN_VALUE_OP) {
332 /* Object (package or buffer) is already built */ 342 /* Object (package or buffer) is already built */
333 343
334 obj_desc->package.elements[i] = ACPI_CAST_PTR (union acpi_operand_object, arg->common.node); 344 obj_desc->package.elements[i] =
345 ACPI_CAST_PTR (union acpi_operand_object, arg->common.node);
335 } 346 }
336 else { 347 else {
337 status = acpi_ds_build_internal_object (walk_state, arg, 348 status = acpi_ds_build_internal_object (walk_state, arg,
338 &obj_desc->package.elements[i]); 349 &obj_desc->package.elements[i]);
339 } 350 }
340 351
341 i++; 352 i++;
@@ -348,7 +359,7 @@ acpi_ds_build_internal_package_obj (
348} 359}
349 360
350 361
351/***************************************************************************** 362/*******************************************************************************
352 * 363 *
353 * FUNCTION: acpi_ds_create_node 364 * FUNCTION: acpi_ds_create_node
354 * 365 *
@@ -360,7 +371,7 @@ acpi_ds_build_internal_package_obj (
360 * 371 *
361 * DESCRIPTION: Create the object to be associated with a namespace node 372 * DESCRIPTION: Create the object to be associated with a namespace node
362 * 373 *
363 ****************************************************************************/ 374 ******************************************************************************/
364 375
365acpi_status 376acpi_status
366acpi_ds_create_node ( 377acpi_ds_create_node (
@@ -392,7 +403,8 @@ acpi_ds_create_node (
392 403
393 /* Build an internal object for the argument(s) */ 404 /* Build an internal object for the argument(s) */
394 405
395 status = acpi_ds_build_internal_object (walk_state, op->common.value.arg, &obj_desc); 406 status = acpi_ds_build_internal_object (walk_state, op->common.value.arg,
407 &obj_desc);
396 if (ACPI_FAILURE (status)) { 408 if (ACPI_FAILURE (status)) {
397 return_ACPI_STATUS (status); 409 return_ACPI_STATUS (status);
398 } 410 }
@@ -414,7 +426,7 @@ acpi_ds_create_node (
414#endif /* ACPI_NO_METHOD_EXECUTION */ 426#endif /* ACPI_NO_METHOD_EXECUTION */
415 427
416 428
417/***************************************************************************** 429/*******************************************************************************
418 * 430 *
419 * FUNCTION: acpi_ds_init_object_from_op 431 * FUNCTION: acpi_ds_init_object_from_op
420 * 432 *
@@ -429,7 +441,7 @@ acpi_ds_create_node (
429 * associated arguments. The namespace object is a more compact 441 * associated arguments. The namespace object is a more compact
430 * representation of the Op and its arguments. 442 * representation of the Op and its arguments.
431 * 443 *
432 ****************************************************************************/ 444 ******************************************************************************/
433 445
434acpi_status 446acpi_status
435acpi_ds_init_object_from_op ( 447acpi_ds_init_object_from_op (
@@ -462,7 +474,8 @@ acpi_ds_init_object_from_op (
462 /* 474 /*
463 * Defer evaluation of Buffer term_arg operand 475 * Defer evaluation of Buffer term_arg operand
464 */ 476 */
465 obj_desc->buffer.node = (struct acpi_namespace_node *) walk_state->operands[0]; 477 obj_desc->buffer.node = (struct acpi_namespace_node *)
478 walk_state->operands[0];
466 obj_desc->buffer.aml_start = op->named.data; 479 obj_desc->buffer.aml_start = op->named.data;
467 obj_desc->buffer.aml_length = op->named.length; 480 obj_desc->buffer.aml_length = op->named.length;
468 break; 481 break;
@@ -473,7 +486,8 @@ acpi_ds_init_object_from_op (
473 /* 486 /*
474 * Defer evaluation of Package term_arg operand 487 * Defer evaluation of Package term_arg operand
475 */ 488 */
476 obj_desc->package.node = (struct acpi_namespace_node *) walk_state->operands[0]; 489 obj_desc->package.node = (struct acpi_namespace_node *)
490 walk_state->operands[0];
477 obj_desc->package.aml_start = op->named.data; 491 obj_desc->package.aml_start = op->named.data;
478 obj_desc->package.aml_length = op->named.length; 492 obj_desc->package.aml_length = op->named.length;
479 break; 493 break;
@@ -486,9 +500,10 @@ acpi_ds_init_object_from_op (
486 /* 500 /*
487 * Resolve AML Constants here - AND ONLY HERE! 501 * Resolve AML Constants here - AND ONLY HERE!
488 * All constants are integers. 502 * All constants are integers.
489 * We mark the integer with a flag that indicates that it started life 503 * We mark the integer with a flag that indicates that it started
490 * as a constant -- so that stores to constants will perform as expected (noop). 504 * life as a constant -- so that stores to constants will perform
491 * (zero_op is used as a placeholder for optional target operands.) 505 * as expected (noop). zero_op is used as a placeholder for optional
506 * target operands.
492 */ 507 */
493 obj_desc->common.flags = AOPOBJ_AML_CONSTANT; 508 obj_desc->common.flags = AOPOBJ_AML_CONSTANT;
494 509
@@ -521,7 +536,8 @@ acpi_ds_init_object_from_op (
521 536
522 default: 537 default:
523 538
524 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown constant opcode %X\n", opcode)); 539 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
540 "Unknown constant opcode %X\n", opcode));
525 status = AE_AML_OPERAND_TYPE; 541 status = AE_AML_OPERAND_TYPE;
526 break; 542 break;
527 } 543 }
@@ -535,7 +551,8 @@ acpi_ds_init_object_from_op (
535 551
536 552
537 default: 553 default:
538 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown Integer type %X\n", op_info->type)); 554 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown Integer type %X\n",
555 op_info->type));
539 status = AE_AML_OPERAND_TYPE; 556 status = AE_AML_OPERAND_TYPE;
540 break; 557 break;
541 } 558 }
@@ -570,8 +587,10 @@ acpi_ds_init_object_from_op (
570 obj_desc->reference.offset = opcode - AML_LOCAL_OP; 587 obj_desc->reference.offset = opcode - AML_LOCAL_OP;
571 588
572#ifndef ACPI_NO_METHOD_EXECUTION 589#ifndef ACPI_NO_METHOD_EXECUTION
573 status = acpi_ds_method_data_get_node (AML_LOCAL_OP, obj_desc->reference.offset, 590 status = acpi_ds_method_data_get_node (AML_LOCAL_OP,
574 walk_state, (struct acpi_namespace_node **) &obj_desc->reference.object); 591 obj_desc->reference.offset,
592 walk_state,
593 (struct acpi_namespace_node **) &obj_desc->reference.object);
575#endif 594#endif
576 break; 595 break;
577 596
@@ -584,8 +603,10 @@ acpi_ds_init_object_from_op (
584 obj_desc->reference.offset = opcode - AML_ARG_OP; 603 obj_desc->reference.offset = opcode - AML_ARG_OP;
585 604
586#ifndef ACPI_NO_METHOD_EXECUTION 605#ifndef ACPI_NO_METHOD_EXECUTION
587 status = acpi_ds_method_data_get_node (AML_ARG_OP, obj_desc->reference.offset, 606 status = acpi_ds_method_data_get_node (AML_ARG_OP,
588 walk_state, (struct acpi_namespace_node **) &obj_desc->reference.object); 607 obj_desc->reference.offset,
608 walk_state,
609 (struct acpi_namespace_node **) &obj_desc->reference.object);
589#endif 610#endif
590 break; 611 break;
591 612
diff --git a/drivers/acpi/dispatcher/dsopcode.c b/drivers/acpi/dispatcher/dsopcode.c
index 5c987a0e7b75..ba13bca28bee 100644
--- a/drivers/acpi/dispatcher/dsopcode.c
+++ b/drivers/acpi/dispatcher/dsopcode.c
@@ -54,12 +54,31 @@
54#define _COMPONENT ACPI_DISPATCHER 54#define _COMPONENT ACPI_DISPATCHER
55 ACPI_MODULE_NAME ("dsopcode") 55 ACPI_MODULE_NAME ("dsopcode")
56 56
57/* Local prototypes */
57 58
58/***************************************************************************** 59static acpi_status
60acpi_ds_execute_arguments (
61 struct acpi_namespace_node *node,
62 struct acpi_namespace_node *scope_node,
63 u32 aml_length,
64 u8 *aml_start);
65
66static acpi_status
67acpi_ds_init_buffer_field (
68 u16 aml_opcode,
69 union acpi_operand_object *obj_desc,
70 union acpi_operand_object *buffer_desc,
71 union acpi_operand_object *offset_desc,
72 union acpi_operand_object *length_desc,
73 union acpi_operand_object *result_desc);
74
75
76/*******************************************************************************
59 * 77 *
60 * FUNCTION: acpi_ds_execute_arguments 78 * FUNCTION: acpi_ds_execute_arguments
61 * 79 *
62 * PARAMETERS: Node - Parent NS node 80 * PARAMETERS: Node - Object NS node
81 * scope_node - Parent NS node
63 * aml_length - Length of executable AML 82 * aml_length - Length of executable AML
64 * aml_start - Pointer to the AML 83 * aml_start - Pointer to the AML
65 * 84 *
@@ -67,9 +86,9 @@
67 * 86 *
68 * DESCRIPTION: Late (deferred) execution of region or field arguments 87 * DESCRIPTION: Late (deferred) execution of region or field arguments
69 * 88 *
70 ****************************************************************************/ 89 ******************************************************************************/
71 90
72acpi_status 91static acpi_status
73acpi_ds_execute_arguments ( 92acpi_ds_execute_arguments (
74 struct acpi_namespace_node *node, 93 struct acpi_namespace_node *node,
75 struct acpi_namespace_node *scope_node, 94 struct acpi_namespace_node *scope_node,
@@ -162,7 +181,7 @@ acpi_ds_execute_arguments (
162} 181}
163 182
164 183
165/***************************************************************************** 184/*******************************************************************************
166 * 185 *
167 * FUNCTION: acpi_ds_get_buffer_field_arguments 186 * FUNCTION: acpi_ds_get_buffer_field_arguments
168 * 187 *
@@ -173,7 +192,7 @@ acpi_ds_execute_arguments (
173 * DESCRIPTION: Get buffer_field Buffer and Index. This implements the late 192 * DESCRIPTION: Get buffer_field Buffer and Index. This implements the late
174 * evaluation of these field attributes. 193 * evaluation of these field attributes.
175 * 194 *
176 ****************************************************************************/ 195 ******************************************************************************/
177 196
178acpi_status 197acpi_status
179acpi_ds_get_buffer_field_arguments ( 198acpi_ds_get_buffer_field_arguments (
@@ -208,7 +227,7 @@ acpi_ds_get_buffer_field_arguments (
208} 227}
209 228
210 229
211/***************************************************************************** 230/*******************************************************************************
212 * 231 *
213 * FUNCTION: acpi_ds_get_buffer_arguments 232 * FUNCTION: acpi_ds_get_buffer_arguments
214 * 233 *
@@ -219,7 +238,7 @@ acpi_ds_get_buffer_field_arguments (
219 * DESCRIPTION: Get Buffer length and initializer byte list. This implements 238 * DESCRIPTION: Get Buffer length and initializer byte list. This implements
220 * the late evaluation of these attributes. 239 * the late evaluation of these attributes.
221 * 240 *
222 ****************************************************************************/ 241 ******************************************************************************/
223 242
224acpi_status 243acpi_status
225acpi_ds_get_buffer_arguments ( 244acpi_ds_get_buffer_arguments (
@@ -255,7 +274,7 @@ acpi_ds_get_buffer_arguments (
255} 274}
256 275
257 276
258/***************************************************************************** 277/*******************************************************************************
259 * 278 *
260 * FUNCTION: acpi_ds_get_package_arguments 279 * FUNCTION: acpi_ds_get_package_arguments
261 * 280 *
@@ -266,7 +285,7 @@ acpi_ds_get_buffer_arguments (
266 * DESCRIPTION: Get Package length and initializer byte list. This implements 285 * DESCRIPTION: Get Package length and initializer byte list. This implements
267 * the late evaluation of these attributes. 286 * the late evaluation of these attributes.
268 * 287 *
269 ****************************************************************************/ 288 ******************************************************************************/
270 289
271acpi_status 290acpi_status
272acpi_ds_get_package_arguments ( 291acpi_ds_get_package_arguments (
@@ -353,17 +372,17 @@ acpi_ds_get_region_arguments (
353} 372}
354 373
355 374
356/***************************************************************************** 375/*******************************************************************************
357 * 376 *
358 * FUNCTION: acpi_ds_initialize_region 377 * FUNCTION: acpi_ds_initialize_region
359 * 378 *
360 * PARAMETERS: Op - A valid region Op object 379 * PARAMETERS: obj_handle - Region namespace node
361 * 380 *
362 * RETURN: Status 381 * RETURN: Status
363 * 382 *
364 * DESCRIPTION: Front end to ev_initialize_region 383 * DESCRIPTION: Front end to ev_initialize_region
365 * 384 *
366 ****************************************************************************/ 385 ******************************************************************************/
367 386
368acpi_status 387acpi_status
369acpi_ds_initialize_region ( 388acpi_ds_initialize_region (
@@ -382,7 +401,7 @@ acpi_ds_initialize_region (
382} 401}
383 402
384 403
385/***************************************************************************** 404/*******************************************************************************
386 * 405 *
387 * FUNCTION: acpi_ds_init_buffer_field 406 * FUNCTION: acpi_ds_init_buffer_field
388 * 407 *
@@ -390,16 +409,16 @@ acpi_ds_initialize_region (
390 * obj_desc - buffer_field object 409 * obj_desc - buffer_field object
391 * buffer_desc - Host Buffer 410 * buffer_desc - Host Buffer
392 * offset_desc - Offset into buffer 411 * offset_desc - Offset into buffer
393 * Length - Length of field (CREATE_FIELD_OP only) 412 * length_desc - Length of field (CREATE_FIELD_OP only)
394 * Result - Where to store the result 413 * result_desc - Where to store the result
395 * 414 *
396 * RETURN: Status 415 * RETURN: Status
397 * 416 *
398 * DESCRIPTION: Perform actual initialization of a buffer field 417 * DESCRIPTION: Perform actual initialization of a buffer field
399 * 418 *
400 ****************************************************************************/ 419 ******************************************************************************/
401 420
402acpi_status 421static acpi_status
403acpi_ds_init_buffer_field ( 422acpi_ds_init_buffer_field (
404 u16 aml_opcode, 423 u16 aml_opcode,
405 union acpi_operand_object *obj_desc, 424 union acpi_operand_object *obj_desc,
@@ -435,8 +454,10 @@ acpi_ds_init_buffer_field (
435 * after resolution in acpi_ex_resolve_operands(). 454 * after resolution in acpi_ex_resolve_operands().
436 */ 455 */
437 if (ACPI_GET_DESCRIPTOR_TYPE (result_desc) != ACPI_DESC_TYPE_NAMED) { 456 if (ACPI_GET_DESCRIPTOR_TYPE (result_desc) != ACPI_DESC_TYPE_NAMED) {
438 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "(%s) destination not a NS Node [%s]\n", 457 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
439 acpi_ps_get_opcode_name (aml_opcode), acpi_ut_get_descriptor_name (result_desc))); 458 "(%s) destination not a NS Node [%s]\n",
459 acpi_ps_get_opcode_name (aml_opcode),
460 acpi_ut_get_descriptor_name (result_desc)));
440 461
441 status = AE_AML_OPERAND_TYPE; 462 status = AE_AML_OPERAND_TYPE;
442 goto cleanup; 463 goto cleanup;
@@ -452,9 +473,18 @@ acpi_ds_init_buffer_field (
452 473
453 /* Offset is in bits, count is in bits */ 474 /* Offset is in bits, count is in bits */
454 475
476 field_flags = AML_FIELD_ACCESS_BYTE;
455 bit_offset = offset; 477 bit_offset = offset;
456 bit_count = (u32) length_desc->integer.value; 478 bit_count = (u32) length_desc->integer.value;
457 field_flags = AML_FIELD_ACCESS_BYTE; 479
480 /* Must have a valid (>0) bit count */
481
482 if (bit_count == 0) {
483 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
484 "Attempt to create_field of length 0\n"));
485 status = AE_AML_OPERAND_VALUE;
486 goto cleanup;
487 }
458 break; 488 break;
459 489
460 case AML_CREATE_BIT_FIELD_OP: 490 case AML_CREATE_BIT_FIELD_OP:
@@ -527,7 +557,8 @@ acpi_ds_init_buffer_field (
527 557
528 /* 558 /*
529 * Initialize areas of the field object that are common to all fields 559 * Initialize areas of the field object that are common to all fields
530 * For field_flags, use LOCK_RULE = 0 (NO_LOCK), UPDATE_RULE = 0 (UPDATE_PRESERVE) 560 * For field_flags, use LOCK_RULE = 0 (NO_LOCK),
561 * UPDATE_RULE = 0 (UPDATE_PRESERVE)
531 */ 562 */
532 status = acpi_ex_prep_common_field_object (obj_desc, field_flags, 0, 563 status = acpi_ex_prep_common_field_object (obj_desc, field_flags, 0,
533 bit_offset, bit_count); 564 bit_offset, bit_count);
@@ -539,8 +570,8 @@ acpi_ds_init_buffer_field (
539 570
540 /* Reference count for buffer_desc inherits obj_desc count */ 571 /* Reference count for buffer_desc inherits obj_desc count */
541 572
542 buffer_desc->common.reference_count = (u16) (buffer_desc->common.reference_count + 573 buffer_desc->common.reference_count = (u16)
543 obj_desc->common.reference_count); 574 (buffer_desc->common.reference_count + obj_desc->common.reference_count);
544 575
545 576
546cleanup: 577cleanup:
@@ -569,7 +600,7 @@ cleanup:
569} 600}
570 601
571 602
572/***************************************************************************** 603/*******************************************************************************
573 * 604 *
574 * FUNCTION: acpi_ds_eval_buffer_field_operands 605 * FUNCTION: acpi_ds_eval_buffer_field_operands
575 * 606 *
@@ -581,7 +612,7 @@ cleanup:
581 * DESCRIPTION: Get buffer_field Buffer and Index 612 * DESCRIPTION: Get buffer_field Buffer and Index
582 * Called from acpi_ds_exec_end_op during buffer_field parse tree walk 613 * Called from acpi_ds_exec_end_op during buffer_field parse tree walk
583 * 614 *
584 ****************************************************************************/ 615 ******************************************************************************/
585 616
586acpi_status 617acpi_status
587acpi_ds_eval_buffer_field_operands ( 618acpi_ds_eval_buffer_field_operands (
@@ -656,7 +687,7 @@ acpi_ds_eval_buffer_field_operands (
656} 687}
657 688
658 689
659/***************************************************************************** 690/*******************************************************************************
660 * 691 *
661 * FUNCTION: acpi_ds_eval_region_operands 692 * FUNCTION: acpi_ds_eval_region_operands
662 * 693 *
@@ -668,7 +699,7 @@ acpi_ds_eval_buffer_field_operands (
668 * DESCRIPTION: Get region address and length 699 * DESCRIPTION: Get region address and length
669 * Called from acpi_ds_exec_end_op during op_region parse tree walk 700 * Called from acpi_ds_exec_end_op during op_region parse tree walk
670 * 701 *
671 ****************************************************************************/ 702 ******************************************************************************/
672 703
673acpi_status 704acpi_status
674acpi_ds_eval_region_operands ( 705acpi_ds_eval_region_operands (
@@ -686,7 +717,8 @@ acpi_ds_eval_region_operands (
686 717
687 718
688 /* 719 /*
689 * This is where we evaluate the address and length fields of the op_region declaration 720 * This is where we evaluate the address and length fields of the
721 * op_region declaration
690 */ 722 */
691 node = op->common.node; 723 node = op->common.node;
692 724
@@ -707,7 +739,8 @@ acpi_ds_eval_region_operands (
707 739
708 /* Resolve the length and address operands to numbers */ 740 /* Resolve the length and address operands to numbers */
709 741
710 status = acpi_ex_resolve_operands (op->common.aml_opcode, ACPI_WALK_OPERANDS, walk_state); 742 status = acpi_ex_resolve_operands (op->common.aml_opcode,
743 ACPI_WALK_OPERANDS, walk_state);
711 if (ACPI_FAILURE (status)) { 744 if (ACPI_FAILURE (status)) {
712 return_ACPI_STATUS (status); 745 return_ACPI_STATUS (status);
713 } 746 }
@@ -736,7 +769,8 @@ acpi_ds_eval_region_operands (
736 */ 769 */
737 operand_desc = walk_state->operands[walk_state->num_operands - 2]; 770 operand_desc = walk_state->operands[walk_state->num_operands - 2];
738 771
739 obj_desc->region.address = (acpi_physical_address) operand_desc->integer.value; 772 obj_desc->region.address = (acpi_physical_address)
773 operand_desc->integer.value;
740 acpi_ut_remove_reference (operand_desc); 774 acpi_ut_remove_reference (operand_desc);
741 775
742 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "rgn_obj %p Addr %8.8X%8.8X Len %X\n", 776 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "rgn_obj %p Addr %8.8X%8.8X Len %X\n",
@@ -752,7 +786,7 @@ acpi_ds_eval_region_operands (
752} 786}
753 787
754 788
755/***************************************************************************** 789/*******************************************************************************
756 * 790 *
757 * FUNCTION: acpi_ds_eval_data_object_operands 791 * FUNCTION: acpi_ds_eval_data_object_operands
758 * 792 *
@@ -765,7 +799,7 @@ acpi_ds_eval_region_operands (
765 * DESCRIPTION: Get the operands and complete the following data object types: 799 * DESCRIPTION: Get the operands and complete the following data object types:
766 * Buffer, Package. 800 * Buffer, Package.
767 * 801 *
768 ****************************************************************************/ 802 ******************************************************************************/
769 803
770acpi_status 804acpi_status
771acpi_ds_eval_data_object_operands ( 805acpi_ds_eval_data_object_operands (
@@ -830,7 +864,7 @@ acpi_ds_eval_data_object_operands (
830 864
831 if (ACPI_SUCCESS (status)) { 865 if (ACPI_SUCCESS (status)) {
832 /* 866 /*
833 * Return the object in the walk_state, unless the parent is a package -- 867 * Return the object in the walk_state, unless the parent is a package -
834 * in this case, the return object will be stored in the parse tree 868 * in this case, the return object will be stored in the parse tree
835 * for the package. 869 * for the package.
836 */ 870 */
@@ -988,7 +1022,8 @@ acpi_ds_exec_end_control_op (
988 status = AE_CTRL_PENDING; 1022 status = AE_CTRL_PENDING;
989 } 1023 }
990 1024
991 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[WHILE_OP] termination! Op=%p\n", op)); 1025 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1026 "[WHILE_OP] termination! Op=%p\n",op));
992 1027
993 /* Pop this control state and free it */ 1028 /* Pop this control state and free it */
994 1029
diff --git a/drivers/acpi/dispatcher/dsutils.c b/drivers/acpi/dispatcher/dsutils.c
index 462c5d83e747..9613349ac31d 100644
--- a/drivers/acpi/dispatcher/dsutils.c
+++ b/drivers/acpi/dispatcher/dsutils.c
@@ -100,7 +100,6 @@ acpi_ds_clear_implicit_return (
100 100
101 101
102#ifndef ACPI_NO_METHOD_EXECUTION 102#ifndef ACPI_NO_METHOD_EXECUTION
103
104/******************************************************************************* 103/*******************************************************************************
105 * 104 *
106 * FUNCTION: acpi_ds_do_implicit_return 105 * FUNCTION: acpi_ds_do_implicit_return
@@ -205,7 +204,7 @@ acpi_ds_is_result_used (
205 * NOTE: this is optional because the ASL language does not actually 204 * NOTE: this is optional because the ASL language does not actually
206 * support this behavior. 205 * support this behavior.
207 */ 206 */
208 acpi_ds_do_implicit_return (walk_state->result_obj, walk_state, TRUE); 207 (void) acpi_ds_do_implicit_return (walk_state->result_obj, walk_state, TRUE);
209 208
210 /* 209 /*
211 * Now determine if the parent will use the result 210 * Now determine if the parent will use the result
@@ -219,8 +218,9 @@ acpi_ds_is_result_used (
219 (op->common.parent->common.aml_opcode == AML_SCOPE_OP)) { 218 (op->common.parent->common.aml_opcode == AML_SCOPE_OP)) {
220 /* No parent, the return value cannot possibly be used */ 219 /* No parent, the return value cannot possibly be used */
221 220
222 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "At Method level, result of [%s] not used\n", 221 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
223 acpi_ps_get_opcode_name (op->common.aml_opcode))); 222 "At Method level, result of [%s] not used\n",
223 acpi_ps_get_opcode_name (op->common.aml_opcode)));
224 return_VALUE (FALSE); 224 return_VALUE (FALSE);
225 } 225 }
226 226
@@ -228,7 +228,8 @@ acpi_ds_is_result_used (
228 228
229 parent_info = acpi_ps_get_opcode_info (op->common.parent->common.aml_opcode); 229 parent_info = acpi_ps_get_opcode_info (op->common.parent->common.aml_opcode);
230 if (parent_info->class == AML_CLASS_UNKNOWN) { 230 if (parent_info->class == AML_CLASS_UNKNOWN) {
231 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown parent opcode. Op=%p\n", op)); 231 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
232 "Unknown parent opcode. Op=%p\n", op));
232 return_VALUE (FALSE); 233 return_VALUE (FALSE);
233 } 234 }
234 235
@@ -309,17 +310,19 @@ acpi_ds_is_result_used (
309 310
310 311
311result_used: 312result_used:
312 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Result of [%s] used by Parent [%s] Op=%p\n", 313 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
313 acpi_ps_get_opcode_name (op->common.aml_opcode), 314 "Result of [%s] used by Parent [%s] Op=%p\n",
314 acpi_ps_get_opcode_name (op->common.parent->common.aml_opcode), op)); 315 acpi_ps_get_opcode_name (op->common.aml_opcode),
316 acpi_ps_get_opcode_name (op->common.parent->common.aml_opcode), op));
315 317
316 return_VALUE (TRUE); 318 return_VALUE (TRUE);
317 319
318 320
319result_not_used: 321result_not_used:
320 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Result of [%s] not used by Parent [%s] Op=%p\n", 322 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
321 acpi_ps_get_opcode_name (op->common.aml_opcode), 323 "Result of [%s] not used by Parent [%s] Op=%p\n",
322 acpi_ps_get_opcode_name (op->common.parent->common.aml_opcode), op)); 324 acpi_ps_get_opcode_name (op->common.aml_opcode),
325 acpi_ps_get_opcode_name (op->common.parent->common.aml_opcode), op));
323 326
324 return_VALUE (FALSE); 327 return_VALUE (FALSE);
325} 328}
@@ -522,7 +525,8 @@ acpi_ds_create_operand (
522 if ((walk_state->deferred_node) && 525 if ((walk_state->deferred_node) &&
523 (walk_state->deferred_node->type == ACPI_TYPE_BUFFER_FIELD) && 526 (walk_state->deferred_node->type == ACPI_TYPE_BUFFER_FIELD) &&
524 (arg_index != 0)) { 527 (arg_index != 0)) {
525 obj_desc = ACPI_CAST_PTR (union acpi_operand_object, walk_state->deferred_node); 528 obj_desc = ACPI_CAST_PTR (
529 union acpi_operand_object, walk_state->deferred_node);
526 status = AE_OK; 530 status = AE_OK;
527 } 531 }
528 else /* All other opcodes */ { 532 else /* All other opcodes */ {
@@ -565,7 +569,8 @@ acpi_ds_create_operand (
565 * indicate this to the interpreter, set the 569 * indicate this to the interpreter, set the
566 * object to the root 570 * object to the root
567 */ 571 */
568 obj_desc = ACPI_CAST_PTR (union acpi_operand_object, acpi_gbl_root_node); 572 obj_desc = ACPI_CAST_PTR (
573 union acpi_operand_object, acpi_gbl_root_node);
569 status = AE_OK; 574 status = AE_OK;
570 } 575 }
571 else { 576 else {
@@ -612,7 +617,8 @@ acpi_ds_create_operand (
612 */ 617 */
613 opcode = AML_ZERO_OP; /* Has no arguments! */ 618 opcode = AML_ZERO_OP; /* Has no arguments! */
614 619
615 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Null namepath: Arg=%p\n", arg)); 620 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
621 "Null namepath: Arg=%p\n", arg));
616 } 622 }
617 else { 623 else {
618 opcode = arg->common.aml_opcode; 624 opcode = arg->common.aml_opcode;
@@ -642,7 +648,8 @@ acpi_ds_create_operand (
642 * Only error is underflow, and this indicates 648 * Only error is underflow, and this indicates
643 * a missing or null operand! 649 * a missing or null operand!
644 */ 650 */
645 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Missing or null operand, %s\n", 651 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
652 "Missing or null operand, %s\n",
646 acpi_format_exception (status))); 653 acpi_format_exception (status)));
647 return_ACPI_STATUS (status); 654 return_ACPI_STATUS (status);
648 } 655 }
@@ -657,8 +664,8 @@ acpi_ds_create_operand (
657 664
658 /* Initialize the new object */ 665 /* Initialize the new object */
659 666
660 status = acpi_ds_init_object_from_op (walk_state, arg, 667 status = acpi_ds_init_object_from_op (
661 opcode, &obj_desc); 668 walk_state, arg, opcode, &obj_desc);
662 if (ACPI_FAILURE (status)) { 669 if (ACPI_FAILURE (status)) {
663 acpi_ut_delete_object_desc (obj_desc); 670 acpi_ut_delete_object_desc (obj_desc);
664 return_ACPI_STATUS (status); 671 return_ACPI_STATUS (status);
diff --git a/drivers/acpi/dispatcher/dswexec.c b/drivers/acpi/dispatcher/dswexec.c
index 2071a0d2bbbb..10f71318e23b 100644
--- a/drivers/acpi/dispatcher/dswexec.c
+++ b/drivers/acpi/dispatcher/dswexec.c
@@ -73,11 +73,13 @@ static ACPI_EXECUTE_OP acpi_gbl_op_type_dispatch [] = {
73 acpi_ex_opcode_3A_1T_1R, 73 acpi_ex_opcode_3A_1T_1R,
74 acpi_ex_opcode_6A_0T_1R}; 74 acpi_ex_opcode_6A_0T_1R};
75 75
76
76/***************************************************************************** 77/*****************************************************************************
77 * 78 *
78 * FUNCTION: acpi_ds_get_predicate_value 79 * FUNCTION: acpi_ds_get_predicate_value
79 * 80 *
80 * PARAMETERS: walk_state - Current state of the parse tree walk 81 * PARAMETERS: walk_state - Current state of the parse tree walk
82 * result_obj - if non-zero, pop result from result stack
81 * 83 *
82 * RETURN: Status 84 * RETURN: Status
83 * 85 *
@@ -124,7 +126,8 @@ acpi_ds_get_predicate_value (
124 } 126 }
125 127
126 if (!obj_desc) { 128 if (!obj_desc) {
127 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No predicate obj_desc=%p State=%p\n", 129 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
130 "No predicate obj_desc=%p State=%p\n",
128 obj_desc, walk_state)); 131 obj_desc, walk_state));
129 132
130 return_ACPI_STATUS (AE_AML_NO_OPERAND); 133 return_ACPI_STATUS (AE_AML_NO_OPERAND);
@@ -197,7 +200,7 @@ cleanup:
197 * FUNCTION: acpi_ds_exec_begin_op 200 * FUNCTION: acpi_ds_exec_begin_op
198 * 201 *
199 * PARAMETERS: walk_state - Current state of the parse tree walk 202 * PARAMETERS: walk_state - Current state of the parse tree walk
200 * out_op - Return op if a new one is created 203 * out_op - Where to return op if a new one is created
201 * 204 *
202 * RETURN: Status 205 * RETURN: Status
203 * 206 *
@@ -233,7 +236,8 @@ acpi_ds_exec_begin_op (
233 walk_state->op_info = acpi_ps_get_opcode_info (op->common.aml_opcode); 236 walk_state->op_info = acpi_ps_get_opcode_info (op->common.aml_opcode);
234 237
235 if (acpi_ns_opens_scope (walk_state->op_info->object_type)) { 238 if (acpi_ns_opens_scope (walk_state->op_info->object_type)) {
236 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s) Popping scope for Op %p\n", 239 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
240 "(%s) Popping scope for Op %p\n",
237 acpi_ut_get_type_name (walk_state->op_info->object_type), op)); 241 acpi_ut_get_type_name (walk_state->op_info->object_type), op));
238 242
239 status = acpi_ds_scope_stack_pop (walk_state); 243 status = acpi_ds_scope_stack_pop (walk_state);
@@ -297,11 +301,10 @@ acpi_ds_exec_begin_op (
297 301
298 if (walk_state->walk_type == ACPI_WALK_METHOD) { 302 if (walk_state->walk_type == ACPI_WALK_METHOD) {
299 /* 303 /*
300 * Found a named object declaration during method 304 * Found a named object declaration during method execution;
301 * execution; we must enter this object into the 305 * we must enter this object into the namespace. The created
302 * namespace. The created object is temporary and 306 * object is temporary and will be deleted upon completion of
303 * will be deleted upon completion of the execution 307 * the execution of this method.
304 * of this method.
305 */ 308 */
306 status = acpi_ds_load2_begin_op (walk_state, NULL); 309 status = acpi_ds_load2_begin_op (walk_state, NULL);
307 } 310 }
@@ -338,8 +341,6 @@ acpi_ds_exec_begin_op (
338 * FUNCTION: acpi_ds_exec_end_op 341 * FUNCTION: acpi_ds_exec_end_op
339 * 342 *
340 * PARAMETERS: walk_state - Current state of the parse tree walk 343 * PARAMETERS: walk_state - Current state of the parse tree walk
341 * Op - Op that has been just been completed in the
342 * walk; Arguments have now been evaluated.
343 * 344 *
344 * RETURN: Status 345 * RETURN: Status
345 * 346 *
@@ -389,7 +390,7 @@ acpi_ds_exec_end_op (
389 /* Decode the Opcode Class */ 390 /* Decode the Opcode Class */
390 391
391 switch (op_class) { 392 switch (op_class) {
392 case AML_CLASS_ARGUMENT: /* constants, literals, etc. -- do nothing */ 393 case AML_CLASS_ARGUMENT: /* constants, literals, etc. - do nothing */
393 break; 394 break;
394 395
395 396
@@ -417,12 +418,12 @@ acpi_ds_exec_end_op (
417 /* Resolve all operands */ 418 /* Resolve all operands */
418 419
419 status = acpi_ex_resolve_operands (walk_state->opcode, 420 status = acpi_ex_resolve_operands (walk_state->opcode,
420 &(walk_state->operands [walk_state->num_operands -1]), 421 &(walk_state->operands [walk_state->num_operands -1]),
421 walk_state); 422 walk_state);
422 if (ACPI_SUCCESS (status)) { 423 if (ACPI_SUCCESS (status)) {
423 ACPI_DUMP_OPERANDS (ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE, 424 ACPI_DUMP_OPERANDS (ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE,
424 acpi_ps_get_opcode_name (walk_state->opcode), 425 acpi_ps_get_opcode_name (walk_state->opcode),
425 walk_state->num_operands, "after ex_resolve_operands"); 426 walk_state->num_operands, "after ex_resolve_operands");
426 } 427 }
427 } 428 }
428 429
@@ -506,7 +507,8 @@ acpi_ds_exec_end_op (
506 if ((op->asl.parent) && 507 if ((op->asl.parent) &&
507 ((op->asl.parent->asl.aml_opcode == AML_PACKAGE_OP) || 508 ((op->asl.parent->asl.aml_opcode == AML_PACKAGE_OP) ||
508 (op->asl.parent->asl.aml_opcode == AML_VAR_PACKAGE_OP))) { 509 (op->asl.parent->asl.aml_opcode == AML_VAR_PACKAGE_OP))) {
509 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Method Reference in a Package, Op=%p\n", op)); 510 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
511 "Method Reference in a Package, Op=%p\n", op));
510 op->common.node = (struct acpi_namespace_node *) op->asl.value.arg->asl.node->object; 512 op->common.node = (struct acpi_namespace_node *) op->asl.value.arg->asl.node->object;
511 acpi_ut_add_reference (op->asl.value.arg->asl.node->object); 513 acpi_ut_add_reference (op->asl.value.arg->asl.node->object);
512 return_ACPI_STATUS (AE_OK); 514 return_ACPI_STATUS (AE_OK);
@@ -583,13 +585,15 @@ acpi_ds_exec_end_op (
583 case AML_NAME_OP: 585 case AML_NAME_OP:
584 586
585 /* 587 /*
586 * Put the Node on the object stack (Contains the ACPI Name of 588 * Put the Node on the object stack (Contains the ACPI Name
587 * this object) 589 * of this object)
588 */ 590 */
589 walk_state->operands[0] = (void *) op->common.parent->common.node; 591 walk_state->operands[0] = (void *) op->common.parent->common.node;
590 walk_state->num_operands = 1; 592 walk_state->num_operands = 1;
591 593
592 status = acpi_ds_create_node (walk_state, op->common.parent->common.node, op->common.parent); 594 status = acpi_ds_create_node (walk_state,
595 op->common.parent->common.node,
596 op->common.parent);
593 if (ACPI_FAILURE (status)) { 597 if (ACPI_FAILURE (status)) {
594 break; 598 break;
595 } 599 }
@@ -600,7 +604,7 @@ acpi_ds_exec_end_op (
600 case AML_INT_EVAL_SUBTREE_OP: 604 case AML_INT_EVAL_SUBTREE_OP:
601 605
602 status = acpi_ds_eval_data_object_operands (walk_state, op, 606 status = acpi_ds_eval_data_object_operands (walk_state, op,
603 acpi_ns_get_attached_object (op->common.parent->common.node)); 607 acpi_ns_get_attached_object (op->common.parent->common.node));
604 break; 608 break;
605 609
606 default: 610 default:
@@ -609,7 +613,7 @@ acpi_ds_exec_end_op (
609 break; 613 break;
610 } 614 }
611 615
612 /* Done with this result state (Now that operand stack is built) */ 616 /* Done with result state (Now that operand stack is built) */
613 617
614 status = acpi_ds_result_stack_pop (walk_state); 618 status = acpi_ds_result_stack_pop (walk_state);
615 if (ACPI_FAILURE (status)) { 619 if (ACPI_FAILURE (status)) {
@@ -620,8 +624,7 @@ acpi_ds_exec_end_op (
620 * If a result object was returned from above, push it on the 624 * If a result object was returned from above, push it on the
621 * current result stack 625 * current result stack
622 */ 626 */
623 if (ACPI_SUCCESS (status) && 627 if (walk_state->result_obj) {
624 walk_state->result_obj) {
625 status = acpi_ds_result_push (walk_state->result_obj, walk_state); 628 status = acpi_ds_result_push (walk_state->result_obj, walk_state);
626 } 629 }
627 break; 630 break;
@@ -654,7 +657,8 @@ acpi_ds_exec_end_op (
654 657
655 case AML_TYPE_UNDEFINED: 658 case AML_TYPE_UNDEFINED:
656 659
657 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Undefined opcode type Op=%p\n", op)); 660 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
661 "Undefined opcode type Op=%p\n", op));
658 return_ACPI_STATUS (AE_NOT_IMPLEMENTED); 662 return_ACPI_STATUS (AE_NOT_IMPLEMENTED);
659 663
660 664
@@ -709,13 +713,14 @@ cleanup:
709 status = acpi_gbl_exception_handler (status, 713 status = acpi_gbl_exception_handler (status,
710 walk_state->method_node->name.integer, walk_state->opcode, 714 walk_state->method_node->name.integer, walk_state->opcode,
711 walk_state->aml_offset, NULL); 715 walk_state->aml_offset, NULL);
712 acpi_ex_enter_interpreter (); 716 (void) acpi_ex_enter_interpreter ();
713 } 717 }
714 718
715 if (walk_state->result_obj) { 719 if (walk_state->result_obj) {
716 /* Break to debugger to display result */ 720 /* Break to debugger to display result */
717 721
718 ACPI_DEBUGGER_EXEC (acpi_db_display_result_object (walk_state->result_obj, walk_state)); 722 ACPI_DEBUGGER_EXEC (acpi_db_display_result_object (walk_state->result_obj,
723 walk_state));
719 724
720 /* 725 /*
721 * Delete the result op if and only if: 726 * Delete the result op if and only if:
diff --git a/drivers/acpi/dispatcher/dswload.c b/drivers/acpi/dispatcher/dswload.c
index 06d758679588..1ac197ccfc80 100644
--- a/drivers/acpi/dispatcher/dswload.c
+++ b/drivers/acpi/dispatcher/dswload.c
@@ -79,20 +79,23 @@ acpi_ds_init_callbacks (
79 79
80 switch (pass_number) { 80 switch (pass_number) {
81 case 1: 81 case 1:
82 walk_state->parse_flags = ACPI_PARSE_LOAD_PASS1 | ACPI_PARSE_DELETE_TREE; 82 walk_state->parse_flags = ACPI_PARSE_LOAD_PASS1 |
83 ACPI_PARSE_DELETE_TREE;
83 walk_state->descending_callback = acpi_ds_load1_begin_op; 84 walk_state->descending_callback = acpi_ds_load1_begin_op;
84 walk_state->ascending_callback = acpi_ds_load1_end_op; 85 walk_state->ascending_callback = acpi_ds_load1_end_op;
85 break; 86 break;
86 87
87 case 2: 88 case 2:
88 walk_state->parse_flags = ACPI_PARSE_LOAD_PASS1 | ACPI_PARSE_DELETE_TREE; 89 walk_state->parse_flags = ACPI_PARSE_LOAD_PASS1 |
90 ACPI_PARSE_DELETE_TREE;
89 walk_state->descending_callback = acpi_ds_load2_begin_op; 91 walk_state->descending_callback = acpi_ds_load2_begin_op;
90 walk_state->ascending_callback = acpi_ds_load2_end_op; 92 walk_state->ascending_callback = acpi_ds_load2_end_op;
91 break; 93 break;
92 94
93 case 3: 95 case 3:
94#ifndef ACPI_NO_METHOD_EXECUTION 96#ifndef ACPI_NO_METHOD_EXECUTION
95 walk_state->parse_flags |= ACPI_PARSE_EXECUTE | ACPI_PARSE_DELETE_TREE; 97 walk_state->parse_flags |= ACPI_PARSE_EXECUTE |
98 ACPI_PARSE_DELETE_TREE;
96 walk_state->descending_callback = acpi_ds_exec_begin_op; 99 walk_state->descending_callback = acpi_ds_exec_begin_op;
97 walk_state->ascending_callback = acpi_ds_exec_end_op; 100 walk_state->ascending_callback = acpi_ds_exec_end_op;
98#endif 101#endif
@@ -111,8 +114,7 @@ acpi_ds_init_callbacks (
111 * FUNCTION: acpi_ds_load1_begin_op 114 * FUNCTION: acpi_ds_load1_begin_op
112 * 115 *
113 * PARAMETERS: walk_state - Current state of the parse tree walk 116 * PARAMETERS: walk_state - Current state of the parse tree walk
114 * Op - Op that has been just been reached in the 117 * out_op - Where to return op if a new one is created
115 * walk; Arguments have not been evaluated yet.
116 * 118 *
117 * RETURN: Status 119 * RETURN: Status
118 * 120 *
@@ -146,7 +148,8 @@ acpi_ds_load1_begin_op (
146#if 0 148#if 0
147 if ((walk_state->op_info->class == AML_CLASS_EXECUTE) || 149 if ((walk_state->op_info->class == AML_CLASS_EXECUTE) ||
148 (walk_state->op_info->class == AML_CLASS_CONTROL)) { 150 (walk_state->op_info->class == AML_CLASS_CONTROL)) {
149 acpi_os_printf ("\n\n***EXECUTABLE OPCODE %s***\n\n", walk_state->op_info->name); 151 acpi_os_printf ("\n\n***EXECUTABLE OPCODE %s***\n\n",
152 walk_state->op_info->name);
150 *out_op = op; 153 *out_op = op;
151 return (AE_CTRL_SKIP); 154 return (AE_CTRL_SKIP);
152 } 155 }
@@ -191,7 +194,8 @@ acpi_ds_load1_begin_op (
191 */ 194 */
192 acpi_dm_add_to_external_list (path); 195 acpi_dm_add_to_external_list (path);
193 status = acpi_ns_lookup (walk_state->scope_info, path, object_type, 196 status = acpi_ns_lookup (walk_state->scope_info, path, object_type,
194 ACPI_IMODE_LOAD_PASS1, ACPI_NS_SEARCH_PARENT, walk_state, &(node)); 197 ACPI_IMODE_LOAD_PASS1, ACPI_NS_SEARCH_PARENT,
198 walk_state, &(node));
195 } 199 }
196#endif 200#endif
197 if (ACPI_FAILURE (status)) { 201 if (ACPI_FAILURE (status)) {
@@ -224,10 +228,12 @@ acpi_ds_load1_begin_op (
224 * Name (DEB, 0) 228 * Name (DEB, 0)
225 * Scope (DEB) { ... } 229 * Scope (DEB) { ... }
226 * 230 *
227 * Note: silently change the type here. On the second pass, we will report a warning 231 * Note: silently change the type here. On the second pass, we will report
232 * a warning
228 */ 233 */
229 234
230 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Type override - [%4.4s] had invalid type (%s) for Scope operator, changed to (Scope)\n", 235 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
236 "Type override - [%4.4s] had invalid type (%s) for Scope operator, changed to (Scope)\n",
231 path, acpi_ut_get_type_name (node->type))); 237 path, acpi_ut_get_type_name (node->type)));
232 238
233 node->type = ACPI_TYPE_ANY; 239 node->type = ACPI_TYPE_ANY;
@@ -238,7 +244,8 @@ acpi_ds_load1_begin_op (
238 244
239 /* All other types are an error */ 245 /* All other types are an error */
240 246
241 ACPI_REPORT_ERROR (("Invalid type (%s) for target of Scope operator [%4.4s] (Cannot override)\n", 247 ACPI_REPORT_ERROR ((
248 "Invalid type (%s) for target of Scope operator [%4.4s] (Cannot override)\n",
242 acpi_ut_get_type_name (node->type), path)); 249 acpi_ut_get_type_name (node->type), path));
243 250
244 return (AE_AML_OPERAND_TYPE); 251 return (AE_AML_OPERAND_TYPE);
@@ -249,7 +256,8 @@ acpi_ds_load1_begin_op (
249 default: 256 default:
250 257
251 /* 258 /*
252 * For all other named opcodes, we will enter the name into the namespace. 259 * For all other named opcodes, we will enter the name into
260 * the namespace.
253 * 261 *
254 * Setup the search flags. 262 * Setup the search flags.
255 * Since we are entering a name into the namespace, we do not want to 263 * Since we are entering a name into the namespace, we do not want to
@@ -279,14 +287,16 @@ acpi_ds_load1_begin_op (
279 acpi_ut_get_type_name (object_type))); 287 acpi_ut_get_type_name (object_type)));
280 } 288 }
281 else { 289 else {
282 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[%s] Both Find or Create allowed\n", 290 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
291 "[%s] Both Find or Create allowed\n",
283 acpi_ut_get_type_name (object_type))); 292 acpi_ut_get_type_name (object_type)));
284 } 293 }
285 294
286 /* 295 /*
287 * Enter the named type into the internal namespace. We enter the name 296 * Enter the named type into the internal namespace. We enter the name
288 * as we go downward in the parse tree. Any necessary subobjects that involve 297 * as we go downward in the parse tree. Any necessary subobjects that
289 * arguments to the opcode must be created as we go back up the parse tree later. 298 * involve arguments to the opcode must be created as we go back up the
299 * parse tree later.
290 */ 300 */
291 status = acpi_ns_lookup (walk_state->scope_info, path, object_type, 301 status = acpi_ns_lookup (walk_state->scope_info, path, object_type,
292 ACPI_IMODE_LOAD_PASS1, flags, walk_state, &(node)); 302 ACPI_IMODE_LOAD_PASS1, flags, walk_state, &(node));
@@ -335,8 +345,6 @@ acpi_ds_load1_begin_op (
335 * FUNCTION: acpi_ds_load1_end_op 345 * FUNCTION: acpi_ds_load1_end_op
336 * 346 *
337 * PARAMETERS: walk_state - Current state of the parse tree walk 347 * PARAMETERS: walk_state - Current state of the parse tree walk
338 * Op - Op that has been just been completed in the
339 * walk; Arguments have now been evaluated.
340 * 348 *
341 * RETURN: Status 349 * RETURN: Status
342 * 350 *
@@ -383,7 +391,9 @@ acpi_ds_load1_end_op (
383 391
384 if (op->common.aml_opcode == AML_REGION_OP) { 392 if (op->common.aml_opcode == AML_REGION_OP) {
385 status = acpi_ex_create_region (op->named.data, op->named.length, 393 status = acpi_ex_create_region (op->named.data, op->named.length,
386 (acpi_adr_space_type) ((op->common.value.arg)->common.value.integer), walk_state); 394 (acpi_adr_space_type)
395 ((op->common.value.arg)->common.value.integer),
396 walk_state);
387 if (ACPI_FAILURE (status)) { 397 if (ACPI_FAILURE (status)) {
388 return (status); 398 return (status);
389 } 399 }
@@ -394,7 +404,8 @@ acpi_ds_load1_end_op (
394 /* For Name opcode, get the object type from the argument */ 404 /* For Name opcode, get the object type from the argument */
395 405
396 if (op->common.value.arg) { 406 if (op->common.value.arg) {
397 object_type = (acpi_ps_get_opcode_info ((op->common.value.arg)->common.aml_opcode))->object_type; 407 object_type = (acpi_ps_get_opcode_info (
408 (op->common.value.arg)->common.aml_opcode))->object_type;
398 op->common.node->type = (u8) object_type; 409 op->common.node->type = (u8) object_type;
399 } 410 }
400 } 411 }
@@ -448,8 +459,7 @@ acpi_ds_load1_end_op (
448 * FUNCTION: acpi_ds_load2_begin_op 459 * FUNCTION: acpi_ds_load2_begin_op
449 * 460 *
450 * PARAMETERS: walk_state - Current state of the parse tree walk 461 * PARAMETERS: walk_state - Current state of the parse tree walk
451 * Op - Op that has been just been reached in the 462 * out_op - Wher to return op if a new one is created
452 * walk; Arguments have not been evaluated yet.
453 * 463 *
454 * RETURN: Status 464 * RETURN: Status
455 * 465 *
@@ -478,14 +488,20 @@ acpi_ds_load2_begin_op (
478 if (op) { 488 if (op) {
479 /* We only care about Namespace opcodes here */ 489 /* We only care about Namespace opcodes here */
480 490
481 if ((!(walk_state->op_info->flags & AML_NSOPCODE) && (walk_state->opcode != AML_INT_NAMEPATH_OP)) || 491 if ((!(walk_state->op_info->flags & AML_NSOPCODE) &&
492 (walk_state->opcode != AML_INT_NAMEPATH_OP)) ||
482 (!(walk_state->op_info->flags & AML_NAMED))) { 493 (!(walk_state->op_info->flags & AML_NAMED))) {
494 if ((walk_state->op_info->class == AML_CLASS_EXECUTE) ||
495 (walk_state->op_info->class == AML_CLASS_CONTROL)) {
496 ACPI_REPORT_WARNING ((
497 "Encountered executable code at module level, [%s]\n",
498 acpi_ps_get_opcode_name (walk_state->opcode)));
499 }
483 return_ACPI_STATUS (AE_OK); 500 return_ACPI_STATUS (AE_OK);
484 } 501 }
485 502
486 /* 503 /* Get the name we are going to enter or lookup in the namespace */
487 * Get the name we are going to enter or lookup in the namespace 504
488 */
489 if (walk_state->opcode == AML_INT_NAMEPATH_OP) { 505 if (walk_state->opcode == AML_INT_NAMEPATH_OP) {
490 /* For Namepath op, get the path string */ 506 /* For Namepath op, get the path string */
491 507
@@ -528,21 +544,25 @@ acpi_ds_load2_begin_op (
528 case AML_INT_NAMEPATH_OP: 544 case AML_INT_NAMEPATH_OP:
529 545
530 /* 546 /*
531 * The name_path is an object reference to an existing object. Don't enter the 547 * The name_path is an object reference to an existing object.
532 * name into the namespace, but look it up for use later 548 * Don't enter the name into the namespace, but look it up
549 * for use later.
533 */ 550 */
534 status = acpi_ns_lookup (walk_state->scope_info, buffer_ptr, object_type, 551 status = acpi_ns_lookup (walk_state->scope_info, buffer_ptr, object_type,
535 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, walk_state, &(node)); 552 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
553 walk_state, &(node));
536 break; 554 break;
537 555
538 case AML_SCOPE_OP: 556 case AML_SCOPE_OP:
539 557
540 /* 558 /*
541 * The Path is an object reference to an existing object. Don't enter the 559 * The Path is an object reference to an existing object.
542 * name into the namespace, but look it up for use later 560 * Don't enter the name into the namespace, but look it up
561 * for use later.
543 */ 562 */
544 status = acpi_ns_lookup (walk_state->scope_info, buffer_ptr, object_type, 563 status = acpi_ns_lookup (walk_state->scope_info, buffer_ptr, object_type,
545 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, walk_state, &(node)); 564 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
565 walk_state, &(node));
546 if (ACPI_FAILURE (status)) { 566 if (ACPI_FAILURE (status)) {
547#ifdef _ACPI_ASL_COMPILER 567#ifdef _ACPI_ASL_COMPILER
548 if (status == AE_NOT_FOUND) { 568 if (status == AE_NOT_FOUND) {
@@ -582,7 +602,8 @@ acpi_ds_load2_begin_op (
582 * Scope (DEB) { ... } 602 * Scope (DEB) { ... }
583 */ 603 */
584 604
585 ACPI_REPORT_WARNING (("Type override - [%4.4s] had invalid type (%s) for Scope operator, changed to (Scope)\n", 605 ACPI_REPORT_WARNING ((
606 "Type override - [%4.4s] had invalid type (%s) for Scope operator, changed to (Scope)\n",
586 buffer_ptr, acpi_ut_get_type_name (node->type))); 607 buffer_ptr, acpi_ut_get_type_name (node->type)));
587 608
588 node->type = ACPI_TYPE_ANY; 609 node->type = ACPI_TYPE_ANY;
@@ -593,7 +614,8 @@ acpi_ds_load2_begin_op (
593 614
594 /* All other types are an error */ 615 /* All other types are an error */
595 616
596 ACPI_REPORT_ERROR (("Invalid type (%s) for target of Scope operator [%4.4s]\n", 617 ACPI_REPORT_ERROR ((
618 "Invalid type (%s) for target of Scope operator [%4.4s]\n",
597 acpi_ut_get_type_name (node->type), buffer_ptr)); 619 acpi_ut_get_type_name (node->type), buffer_ptr));
598 620
599 return (AE_AML_OPERAND_TYPE); 621 return (AE_AML_OPERAND_TYPE);
@@ -621,8 +643,9 @@ acpi_ds_load2_begin_op (
621 643
622 /* 644 /*
623 * Enter the named type into the internal namespace. We enter the name 645 * Enter the named type into the internal namespace. We enter the name
624 * as we go downward in the parse tree. Any necessary subobjects that involve 646 * as we go downward in the parse tree. Any necessary subobjects that
625 * arguments to the opcode must be created as we go back up the parse tree later. 647 * involve arguments to the opcode must be created as we go back up the
648 * parse tree later.
626 * 649 *
627 * Note: Name may already exist if we are executing a deferred opcode. 650 * Note: Name may already exist if we are executing a deferred opcode.
628 */ 651 */
@@ -635,7 +658,8 @@ acpi_ds_load2_begin_op (
635 } 658 }
636 659
637 status = acpi_ns_lookup (walk_state->scope_info, buffer_ptr, object_type, 660 status = acpi_ns_lookup (walk_state->scope_info, buffer_ptr, object_type,
638 ACPI_IMODE_EXECUTE, ACPI_NS_NO_UPSEARCH, walk_state, &(node)); 661 ACPI_IMODE_EXECUTE, ACPI_NS_NO_UPSEARCH,
662 walk_state, &(node));
639 break; 663 break;
640 } 664 }
641 665
@@ -678,8 +702,6 @@ acpi_ds_load2_begin_op (
678 * FUNCTION: acpi_ds_load2_end_op 702 * FUNCTION: acpi_ds_load2_end_op
679 * 703 *
680 * PARAMETERS: walk_state - Current state of the parse tree walk 704 * PARAMETERS: walk_state - Current state of the parse tree walk
681 * Op - Op that has been just been completed in the
682 * walk; Arguments have now been evaluated.
683 * 705 *
684 * RETURN: Status 706 * RETURN: Status
685 * 707 *
@@ -738,7 +760,8 @@ acpi_ds_load2_end_op (
738 760
739 /* Pop the scope stack */ 761 /* Pop the scope stack */
740 762
741 if (acpi_ns_opens_scope (object_type) && (op->common.aml_opcode != AML_INT_METHODCALL_OP)) { 763 if (acpi_ns_opens_scope (object_type) &&
764 (op->common.aml_opcode != AML_INT_METHODCALL_OP)) {
742 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s) Popping scope for Op %p\n", 765 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s) Popping scope for Op %p\n",
743 acpi_ut_get_type_name (object_type), op)); 766 acpi_ut_get_type_name (object_type), op));
744 767
@@ -803,7 +826,7 @@ acpi_ds_load2_end_op (
803 case AML_INDEX_FIELD_OP: 826 case AML_INDEX_FIELD_OP:
804 827
805 status = acpi_ds_create_index_field (op, (acpi_handle) arg->common.node, 828 status = acpi_ds_create_index_field (op, (acpi_handle) arg->common.node,
806 walk_state); 829 walk_state);
807 break; 830 break;
808 831
809 case AML_BANK_FIELD_OP: 832 case AML_BANK_FIELD_OP:
@@ -884,14 +907,16 @@ acpi_ds_load2_end_op (
884#ifndef ACPI_NO_METHOD_EXECUTION 907#ifndef ACPI_NO_METHOD_EXECUTION
885 case AML_REGION_OP: 908 case AML_REGION_OP:
886 /* 909 /*
887 * The op_region is not fully parsed at this time. Only valid argument is the space_id. 910 * The op_region is not fully parsed at this time. Only valid
888 * (We must save the address of the AML of the address and length operands) 911 * argument is the space_id. (We must save the address of the
912 * AML of the address and length operands)
889 */ 913 */
890 /* 914 /*
891 * If we have a valid region, initialize it 915 * If we have a valid region, initialize it
892 * Namespace is NOT locked at this point. 916 * Namespace is NOT locked at this point.
893 */ 917 */
894 status = acpi_ev_initialize_region (acpi_ns_get_attached_object (node), FALSE); 918 status = acpi_ev_initialize_region (acpi_ns_get_attached_object (node),
919 FALSE);
895 if (ACPI_FAILURE (status)) { 920 if (ACPI_FAILURE (status)) {
896 /* 921 /*
897 * If AE_NOT_EXIST is returned, it is not fatal 922 * If AE_NOT_EXIST is returned, it is not fatal
@@ -942,15 +967,16 @@ acpi_ds_load2_end_op (
942 if (ACPI_SUCCESS (status)) { 967 if (ACPI_SUCCESS (status)) {
943 /* 968 /*
944 * Make sure that what we found is indeed a method 969 * Make sure that what we found is indeed a method
945 * We didn't search for a method on purpose, to see if the name would resolve 970 * We didn't search for a method on purpose, to see if the name
971 * would resolve
946 */ 972 */
947 if (new_node->type != ACPI_TYPE_METHOD) { 973 if (new_node->type != ACPI_TYPE_METHOD) {
948 status = AE_AML_OPERAND_TYPE; 974 status = AE_AML_OPERAND_TYPE;
949 } 975 }
950 976
951 /* We could put the returned object (Node) on the object stack for later, but 977 /* We could put the returned object (Node) on the object stack for
952 * for now, we will put it in the "op" object that the parser uses, so we 978 * later, but for now, we will put it in the "op" object that the
953 * can get it again at the end of this scope 979 * parser uses, so we can get it again at the end of this scope
954 */ 980 */
955 op->common.node = new_node; 981 op->common.node = new_node;
956 } 982 }
diff --git a/drivers/acpi/dispatcher/dswscope.c b/drivers/acpi/dispatcher/dswscope.c
index 65f456151e25..21f4548ff323 100644
--- a/drivers/acpi/dispatcher/dswscope.c
+++ b/drivers/acpi/dispatcher/dswscope.c
@@ -50,14 +50,13 @@
50 ACPI_MODULE_NAME ("dswscope") 50 ACPI_MODULE_NAME ("dswscope")
51 51
52 52
53#define STACK_POP(head) head
54
55
56/**************************************************************************** 53/****************************************************************************
57 * 54 *
58 * FUNCTION: acpi_ds_scope_stack_clear 55 * FUNCTION: acpi_ds_scope_stack_clear
59 * 56 *
60 * PARAMETERS: None 57 * PARAMETERS: walk_state - Current state
58 *
59 * RETURN: None
61 * 60 *
62 * DESCRIPTION: Pop (and free) everything on the scope stack except the 61 * DESCRIPTION: Pop (and free) everything on the scope stack except the
63 * root scope object (which remains at the stack top.) 62 * root scope object (which remains at the stack top.)
@@ -80,7 +79,8 @@ acpi_ds_scope_stack_clear (
80 walk_state->scope_info = scope_info->scope.next; 79 walk_state->scope_info = scope_info->scope.next;
81 80
82 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 81 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
83 "Popped object type (%s)\n", acpi_ut_get_type_name (scope_info->common.value))); 82 "Popped object type (%s)\n",
83 acpi_ut_get_type_name (scope_info->common.value)));
84 acpi_ut_delete_generic_state (scope_info); 84 acpi_ut_delete_generic_state (scope_info);
85 } 85 }
86} 86}
@@ -90,8 +90,11 @@ acpi_ds_scope_stack_clear (
90 * 90 *
91 * FUNCTION: acpi_ds_scope_stack_push 91 * FUNCTION: acpi_ds_scope_stack_push
92 * 92 *
93 * PARAMETERS: *Node, - Name to be made current 93 * PARAMETERS: Node - Name to be made current
94 * Type, - Type of frame being pushed 94 * Type - Type of frame being pushed
95 * walk_state - Current state
96 *
97 * RETURN: Status
95 * 98 *
96 * DESCRIPTION: Push the current scope on the scope stack, and make the 99 * DESCRIPTION: Push the current scope on the scope stack, and make the
97 * passed Node current. 100 * passed Node current.
@@ -121,7 +124,8 @@ acpi_ds_scope_stack_push (
121 /* Make sure object type is valid */ 124 /* Make sure object type is valid */
122 125
123 if (!acpi_ut_valid_object_type (type)) { 126 if (!acpi_ut_valid_object_type (type)) {
124 ACPI_REPORT_WARNING (("ds_scope_stack_push: Invalid object type: 0x%X\n", type)); 127 ACPI_REPORT_WARNING ((
128 "ds_scope_stack_push: Invalid object type: 0x%X\n", type));
125 } 129 }
126 130
127 /* Allocate a new scope object */ 131 /* Allocate a new scope object */
@@ -170,16 +174,11 @@ acpi_ds_scope_stack_push (
170 * 174 *
171 * FUNCTION: acpi_ds_scope_stack_pop 175 * FUNCTION: acpi_ds_scope_stack_pop
172 * 176 *
173 * PARAMETERS: Type - The type of frame to be found 177 * PARAMETERS: walk_state - Current state
174 * 178 *
175 * DESCRIPTION: Pop the scope stack until a frame of the requested type 179 * RETURN: Status
176 * is found.
177 * 180 *
178 * RETURN: Count of frames popped. If no frame of the requested type 181 * DESCRIPTION: Pop the scope stack once.
179 * was found, the count is returned as a negative number and
180 * the scope stack is emptied (which sets the current scope
181 * to the root). If the scope stack was empty at entry, the
182 * function is a no-op and returns 0.
183 * 182 *
184 ***************************************************************************/ 183 ***************************************************************************/
185 184
diff --git a/drivers/acpi/dispatcher/dswstate.c b/drivers/acpi/dispatcher/dswstate.c
index e555b3fbd5e5..9cd3db652b31 100644
--- a/drivers/acpi/dispatcher/dswstate.c
+++ b/drivers/acpi/dispatcher/dswstate.c
@@ -50,67 +50,31 @@
50#define _COMPONENT ACPI_DISPATCHER 50#define _COMPONENT ACPI_DISPATCHER
51 ACPI_MODULE_NAME ("dswstate") 51 ACPI_MODULE_NAME ("dswstate")
52 52
53/* Local prototypes */
53 54
54#ifdef ACPI_FUTURE_USAGE 55#ifdef ACPI_OBSOLETE_FUNCTIONS
55
56/*******************************************************************************
57 *
58 * FUNCTION: acpi_ds_result_insert
59 *
60 * PARAMETERS: Object - Object to push
61 * Index - Where to insert the object
62 * walk_state - Current Walk state
63 *
64 * RETURN: Status
65 *
66 * DESCRIPTION: Insert an object onto this walk's result stack
67 *
68 ******************************************************************************/
69
70acpi_status 56acpi_status
71acpi_ds_result_insert ( 57acpi_ds_result_insert (
72 void *object, 58 void *object,
73 u32 index, 59 u32 index,
74 struct acpi_walk_state *walk_state) 60 struct acpi_walk_state *walk_state);
75{
76 union acpi_generic_state *state;
77
78 61
79 ACPI_FUNCTION_NAME ("ds_result_insert"); 62acpi_status
80 63acpi_ds_obj_stack_delete_all (
81 64 struct acpi_walk_state *walk_state);
82 state = walk_state->results;
83 if (!state) {
84 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No result object pushed! State=%p\n",
85 walk_state));
86 return (AE_NOT_EXIST);
87 }
88
89 if (index >= ACPI_OBJ_NUM_OPERANDS) {
90 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
91 "Index out of range: %X Obj=%p State=%p Num=%X\n",
92 index, object, walk_state, state->results.num_results));
93 return (AE_BAD_PARAMETER);
94 }
95
96 if (!object) {
97 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
98 "Null Object! Index=%X Obj=%p State=%p Num=%X\n",
99 index, object, walk_state, state->results.num_results));
100 return (AE_BAD_PARAMETER);
101 }
102
103 state->results.obj_desc [index] = object;
104 state->results.num_results++;
105 65
106 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 66acpi_status
107 "Obj=%p [%s] State=%p Num=%X Cur=%X\n", 67acpi_ds_obj_stack_pop_object (
108 object, object ? acpi_ut_get_object_type_name ((union acpi_operand_object *) object) : "NULL", 68 union acpi_operand_object **object,
109 walk_state, state->results.num_results, walk_state->current_result)); 69 struct acpi_walk_state *walk_state);
110 70
111 return (AE_OK); 71void *
112} 72acpi_ds_obj_stack_get_value (
73 u32 index,
74 struct acpi_walk_state *walk_state);
75#endif
113 76
77#ifdef ACPI_FUTURE_USAGE
114 78
115/******************************************************************************* 79/*******************************************************************************
116 * 80 *
@@ -178,7 +142,6 @@ acpi_ds_result_remove (
178 142
179#endif /* ACPI_FUTURE_USAGE */ 143#endif /* ACPI_FUTURE_USAGE */
180 144
181
182/******************************************************************************* 145/*******************************************************************************
183 * 146 *
184 * FUNCTION: acpi_ds_result_pop 147 * FUNCTION: acpi_ds_result_pop
@@ -227,15 +190,18 @@ acpi_ds_result_pop (
227 *object = state->results.obj_desc [index -1]; 190 *object = state->results.obj_desc [index -1];
228 state->results.obj_desc [index -1] = NULL; 191 state->results.obj_desc [index -1] = NULL;
229 192
230 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p [%s] Index=%X State=%p Num=%X\n", 193 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
231 *object, (*object) ? acpi_ut_get_object_type_name (*object) : "NULL", 194 "Obj=%p [%s] Index=%X State=%p Num=%X\n",
195 *object,
196 (*object) ? acpi_ut_get_object_type_name (*object) : "NULL",
232 (u32) index -1, walk_state, state->results.num_results)); 197 (u32) index -1, walk_state, state->results.num_results));
233 198
234 return (AE_OK); 199 return (AE_OK);
235 } 200 }
236 } 201 }
237 202
238 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No result objects! State=%p\n", walk_state)); 203 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
204 "No result objects! State=%p\n", walk_state));
239 return (AE_AML_NO_RETURN_VALUE); 205 return (AE_AML_NO_RETURN_VALUE);
240} 206}
241 207
@@ -274,7 +240,8 @@ acpi_ds_result_pop_from_bottom (
274 } 240 }
275 241
276 if (!state->results.num_results) { 242 if (!state->results.num_results) {
277 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No result objects! State=%p\n", walk_state)); 243 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No result objects! State=%p\n",
244 walk_state));
278 return (AE_AML_NO_RETURN_VALUE); 245 return (AE_AML_NO_RETURN_VALUE);
279 } 246 }
280 247
@@ -293,7 +260,8 @@ acpi_ds_result_pop_from_bottom (
293 /* Check for a valid result object */ 260 /* Check for a valid result object */
294 261
295 if (!*object) { 262 if (!*object) {
296 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Null operand! State=%p #Ops=%X, Index=%X\n", 263 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
264 "Null operand! State=%p #Ops=%X, Index=%X\n",
297 walk_state, state->results.num_results, (u32) index)); 265 walk_state, state->results.num_results, (u32) index));
298 return (AE_AML_NO_RETURN_VALUE); 266 return (AE_AML_NO_RETURN_VALUE);
299 } 267 }
@@ -344,7 +312,8 @@ acpi_ds_result_push (
344 } 312 }
345 313
346 if (!object) { 314 if (!object) {
347 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Null Object! Obj=%p State=%p Num=%X\n", 315 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
316 "Null Object! Obj=%p State=%p Num=%X\n",
348 object, walk_state, state->results.num_results)); 317 object, walk_state, state->results.num_results));
349 return (AE_BAD_PARAMETER); 318 return (AE_BAD_PARAMETER);
350 } 319 }
@@ -439,43 +408,6 @@ acpi_ds_result_stack_pop (
439 408
440/******************************************************************************* 409/*******************************************************************************
441 * 410 *
442 * FUNCTION: acpi_ds_obj_stack_delete_all
443 *
444 * PARAMETERS: walk_state - Current Walk state
445 *
446 * RETURN: Status
447 *
448 * DESCRIPTION: Clear the object stack by deleting all objects that are on it.
449 * Should be used with great care, if at all!
450 *
451 ******************************************************************************/
452#ifdef ACPI_FUTURE_USAGE
453acpi_status
454acpi_ds_obj_stack_delete_all (
455 struct acpi_walk_state *walk_state)
456{
457 u32 i;
458
459
460 ACPI_FUNCTION_TRACE_PTR ("ds_obj_stack_delete_all", walk_state);
461
462
463 /* The stack size is configurable, but fixed */
464
465 for (i = 0; i < ACPI_OBJ_NUM_OPERANDS; i++) {
466 if (walk_state->operands[i]) {
467 acpi_ut_remove_reference (walk_state->operands[i]);
468 walk_state->operands[i] = NULL;
469 }
470 }
471
472 return_ACPI_STATUS (AE_OK);
473}
474#endif /* ACPI_FUTURE_USAGE */
475
476
477/*******************************************************************************
478 *
479 * FUNCTION: acpi_ds_obj_stack_push 411 * FUNCTION: acpi_ds_obj_stack_push
480 * 412 *
481 * PARAMETERS: Object - Object to push 413 * PARAMETERS: Object - Object to push
@@ -517,67 +449,6 @@ acpi_ds_obj_stack_push (
517} 449}
518 450
519 451
520#if 0
521/*******************************************************************************
522 *
523 * FUNCTION: acpi_ds_obj_stack_pop_object
524 *
525 * PARAMETERS: pop_count - Number of objects/entries to pop
526 * walk_state - Current Walk state
527 *
528 * RETURN: Status
529 *
530 * DESCRIPTION: Pop this walk's object stack. Objects on the stack are NOT
531 * deleted by this routine.
532 *
533 ******************************************************************************/
534
535acpi_status
536acpi_ds_obj_stack_pop_object (
537 union acpi_operand_object **object,
538 struct acpi_walk_state *walk_state)
539{
540 ACPI_FUNCTION_NAME ("ds_obj_stack_pop_object");
541
542
543 /* Check for stack underflow */
544
545 if (walk_state->num_operands == 0) {
546 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
547 "Missing operand/stack empty! State=%p #Ops=%X\n",
548 walk_state, walk_state->num_operands));
549 *object = NULL;
550 return (AE_AML_NO_OPERAND);
551 }
552
553 /* Pop the stack */
554
555 walk_state->num_operands--;
556
557 /* Check for a valid operand */
558
559 if (!walk_state->operands [walk_state->num_operands]) {
560 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
561 "Null operand! State=%p #Ops=%X\n",
562 walk_state, walk_state->num_operands));
563 *object = NULL;
564 return (AE_AML_NO_OPERAND);
565 }
566
567 /* Get operand and set stack entry to null */
568
569 *object = walk_state->operands [walk_state->num_operands];
570 walk_state->operands [walk_state->num_operands] = NULL;
571
572 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n",
573 *object, acpi_ut_get_object_type_name (*object),
574 walk_state, walk_state->num_operands));
575
576 return (AE_OK);
577}
578#endif
579
580
581/******************************************************************************* 452/*******************************************************************************
582 * 453 *
583 * FUNCTION: acpi_ds_obj_stack_pop 454 * FUNCTION: acpi_ds_obj_stack_pop
@@ -680,48 +551,6 @@ acpi_ds_obj_stack_pop_and_delete (
680 551
681/******************************************************************************* 552/*******************************************************************************
682 * 553 *
683 * FUNCTION: acpi_ds_obj_stack_get_value
684 *
685 * PARAMETERS: Index - Stack index whose value is desired. Based
686 * on the top of the stack (index=0 == top)
687 * walk_state - Current Walk state
688 *
689 * RETURN: Status
690 *
691 * DESCRIPTION: Retrieve an object from this walk's object stack. Index must
692 * be within the range of the current stack pointer.
693 *
694 ******************************************************************************/
695#ifdef ACPI_FUTURE_USAGE
696void *
697acpi_ds_obj_stack_get_value (
698 u32 index,
699 struct acpi_walk_state *walk_state)
700{
701
702 ACPI_FUNCTION_TRACE_PTR ("ds_obj_stack_get_value", walk_state);
703
704
705 /* Can't do it if the stack is empty */
706
707 if (walk_state->num_operands == 0) {
708 return_PTR (NULL);
709 }
710
711 /* or if the index is past the top of the stack */
712
713 if (index > (walk_state->num_operands - (u32) 1)) {
714 return_PTR (NULL);
715 }
716
717 return_PTR (walk_state->operands[(acpi_native_uint)(walk_state->num_operands - 1) -
718 index]);
719}
720#endif /* ACPI_FUTURE_USAGE */
721
722
723/*******************************************************************************
724 *
725 * FUNCTION: acpi_ds_get_current_walk_state 554 * FUNCTION: acpi_ds_get_current_walk_state
726 * 555 *
727 * PARAMETERS: Thread - Get current active state for this Thread 556 * PARAMETERS: Thread - Get current active state for this Thread
@@ -757,11 +586,11 @@ acpi_ds_get_current_walk_state (
757 * FUNCTION: acpi_ds_push_walk_state 586 * FUNCTION: acpi_ds_push_walk_state
758 * 587 *
759 * PARAMETERS: walk_state - State to push 588 * PARAMETERS: walk_state - State to push
760 * walk_list - The list that owns the walk stack 589 * Thread - Thread state object
761 * 590 *
762 * RETURN: None 591 * RETURN: None
763 * 592 *
764 * DESCRIPTION: Place the walk_state at the head of the state list. 593 * DESCRIPTION: Place the Thread state at the head of the state list.
765 * 594 *
766 ******************************************************************************/ 595 ******************************************************************************/
767 596
@@ -784,9 +613,9 @@ acpi_ds_push_walk_state (
784 * 613 *
785 * FUNCTION: acpi_ds_pop_walk_state 614 * FUNCTION: acpi_ds_pop_walk_state
786 * 615 *
787 * PARAMETERS: walk_list - The list that owns the walk stack 616 * PARAMETERS: Thread - Current thread state
788 * 617 *
789 * RETURN: A walk_state object popped from the stack 618 * RETURN: A walk_state object popped from the thread's stack
790 * 619 *
791 * DESCRIPTION: Remove and return the walkstate object that is at the head of 620 * DESCRIPTION: Remove and return the walkstate object that is at the head of
792 * the walk stack for the given walk list. NULL indicates that 621 * the walk stack for the given walk list. NULL indicates that
@@ -814,7 +643,7 @@ acpi_ds_pop_walk_state (
814 /* 643 /*
815 * Don't clear the NEXT field, this serves as an indicator 644 * Don't clear the NEXT field, this serves as an indicator
816 * that there is a parent WALK STATE 645 * that there is a parent WALK STATE
817 * NO: walk_state->Next = NULL; 646 * Do Not: walk_state->Next = NULL;
818 */ 647 */
819 } 648 }
820 649
@@ -826,7 +655,9 @@ acpi_ds_pop_walk_state (
826 * 655 *
827 * FUNCTION: acpi_ds_create_walk_state 656 * FUNCTION: acpi_ds_create_walk_state
828 * 657 *
829 * PARAMETERS: Origin - Starting point for this walk 658 * PARAMETERS: owner_id - ID for object creation
659 * Origin - Starting point for this walk
660 * mth_desc - Method object
830 * Thread - Current thread state 661 * Thread - Current thread state
831 * 662 *
832 * RETURN: Pointer to the new walk state. 663 * RETURN: Pointer to the new walk state.
@@ -896,8 +727,7 @@ acpi_ds_create_walk_state (
896 * method_node - Control method NS node, if any 727 * method_node - Control method NS node, if any
897 * aml_start - Start of AML 728 * aml_start - Start of AML
898 * aml_length - Length of AML 729 * aml_length - Length of AML
899 * Params - Method args, if any 730 * Info - Method info block (params, etc.)
900 * return_obj_desc - Where to store a return object, if any
901 * pass_number - 1, 2, or 3 731 * pass_number - 1, 2, or 3
902 * 732 *
903 * RETURN: Status 733 * RETURN: Status
@@ -931,7 +761,7 @@ acpi_ds_init_aml_walk (
931 761
932 /* The next_op of the next_walk will be the beginning of the method */ 762 /* The next_op of the next_walk will be the beginning of the method */
933 763
934 walk_state->next_op = NULL; 764 walk_state->next_op = NULL;
935 765
936 if (info) { 766 if (info) {
937 if (info->parameter_type == ACPI_PARAM_GPE) { 767 if (info->parameter_type == ACPI_PARAM_GPE) {
@@ -939,8 +769,8 @@ acpi_ds_init_aml_walk (
939 info->parameters); 769 info->parameters);
940 } 770 }
941 else { 771 else {
942 walk_state->params = info->parameters; 772 walk_state->params = info->parameters;
943 walk_state->caller_return_desc = &info->return_object; 773 walk_state->caller_return_desc = &info->return_object;
944 } 774 }
945 } 775 }
946 776
@@ -964,7 +794,8 @@ acpi_ds_init_aml_walk (
964 794
965 /* Init the method arguments */ 795 /* Init the method arguments */
966 796
967 status = acpi_ds_method_data_init_args (walk_state->params, ACPI_METHOD_NUM_ARGS, walk_state); 797 status = acpi_ds_method_data_init_args (walk_state->params,
798 ACPI_METHOD_NUM_ARGS, walk_state);
968 if (ACPI_FAILURE (status)) { 799 if (ACPI_FAILURE (status)) {
969 return_ACPI_STATUS (status); 800 return_ACPI_STATUS (status);
970 } 801 }
@@ -1031,12 +862,14 @@ acpi_ds_delete_walk_state (
1031 } 862 }
1032 863
1033 if (walk_state->data_type != ACPI_DESC_TYPE_WALK) { 864 if (walk_state->data_type != ACPI_DESC_TYPE_WALK) {
1034 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "%p is not a valid walk state\n", walk_state)); 865 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "%p is not a valid walk state\n",
866 walk_state));
1035 return; 867 return;
1036 } 868 }
1037 869
1038 if (walk_state->parser_state.scope) { 870 if (walk_state->parser_state.scope) {
1039 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "%p walk still has a scope list\n", walk_state)); 871 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "%p walk still has a scope list\n",
872 walk_state));
1040 } 873 }
1041 874
1042 /* Always must free any linked control states */ 875 /* Always must free any linked control states */
@@ -1078,7 +911,7 @@ acpi_ds_delete_walk_state (
1078 * 911 *
1079 * PARAMETERS: None 912 * PARAMETERS: None
1080 * 913 *
1081 * RETURN: Status 914 * RETURN: None
1082 * 915 *
1083 * DESCRIPTION: Purge the global state object cache. Used during subsystem 916 * DESCRIPTION: Purge the global state object cache. Used during subsystem
1084 * termination. 917 * termination.
@@ -1098,3 +931,200 @@ acpi_ds_delete_walk_state_cache (
1098#endif 931#endif
1099 932
1100 933
934#ifdef ACPI_OBSOLETE_FUNCTIONS
935/*******************************************************************************
936 *
937 * FUNCTION: acpi_ds_result_insert
938 *
939 * PARAMETERS: Object - Object to push
940 * Index - Where to insert the object
941 * walk_state - Current Walk state
942 *
943 * RETURN: Status
944 *
945 * DESCRIPTION: Insert an object onto this walk's result stack
946 *
947 ******************************************************************************/
948
949acpi_status
950acpi_ds_result_insert (
951 void *object,
952 u32 index,
953 struct acpi_walk_state *walk_state)
954{
955 union acpi_generic_state *state;
956
957
958 ACPI_FUNCTION_NAME ("ds_result_insert");
959
960
961 state = walk_state->results;
962 if (!state) {
963 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No result object pushed! State=%p\n",
964 walk_state));
965 return (AE_NOT_EXIST);
966 }
967
968 if (index >= ACPI_OBJ_NUM_OPERANDS) {
969 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
970 "Index out of range: %X Obj=%p State=%p Num=%X\n",
971 index, object, walk_state, state->results.num_results));
972 return (AE_BAD_PARAMETER);
973 }
974
975 if (!object) {
976 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
977 "Null Object! Index=%X Obj=%p State=%p Num=%X\n",
978 index, object, walk_state, state->results.num_results));
979 return (AE_BAD_PARAMETER);
980 }
981
982 state->results.obj_desc [index] = object;
983 state->results.num_results++;
984
985 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
986 "Obj=%p [%s] State=%p Num=%X Cur=%X\n",
987 object, object ? acpi_ut_get_object_type_name ((union acpi_operand_object *) object) : "NULL",
988 walk_state, state->results.num_results, walk_state->current_result));
989
990 return (AE_OK);
991}
992
993
994/*******************************************************************************
995 *
996 * FUNCTION: acpi_ds_obj_stack_delete_all
997 *
998 * PARAMETERS: walk_state - Current Walk state
999 *
1000 * RETURN: Status
1001 *
1002 * DESCRIPTION: Clear the object stack by deleting all objects that are on it.
1003 * Should be used with great care, if at all!
1004 *
1005 ******************************************************************************/
1006
1007acpi_status
1008acpi_ds_obj_stack_delete_all (
1009 struct acpi_walk_state *walk_state)
1010{
1011 u32 i;
1012
1013
1014 ACPI_FUNCTION_TRACE_PTR ("ds_obj_stack_delete_all", walk_state);
1015
1016
1017 /* The stack size is configurable, but fixed */
1018
1019 for (i = 0; i < ACPI_OBJ_NUM_OPERANDS; i++) {
1020 if (walk_state->operands[i]) {
1021 acpi_ut_remove_reference (walk_state->operands[i]);
1022 walk_state->operands[i] = NULL;
1023 }
1024 }
1025
1026 return_ACPI_STATUS (AE_OK);
1027}
1028
1029
1030/*******************************************************************************
1031 *
1032 * FUNCTION: acpi_ds_obj_stack_pop_object
1033 *
1034 * PARAMETERS: Object - Where to return the popped object
1035 * walk_state - Current Walk state
1036 *
1037 * RETURN: Status
1038 *
1039 * DESCRIPTION: Pop this walk's object stack. Objects on the stack are NOT
1040 * deleted by this routine.
1041 *
1042 ******************************************************************************/
1043
1044acpi_status
1045acpi_ds_obj_stack_pop_object (
1046 union acpi_operand_object **object,
1047 struct acpi_walk_state *walk_state)
1048{
1049 ACPI_FUNCTION_NAME ("ds_obj_stack_pop_object");
1050
1051
1052 /* Check for stack underflow */
1053
1054 if (walk_state->num_operands == 0) {
1055 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
1056 "Missing operand/stack empty! State=%p #Ops=%X\n",
1057 walk_state, walk_state->num_operands));
1058 *object = NULL;
1059 return (AE_AML_NO_OPERAND);
1060 }
1061
1062 /* Pop the stack */
1063
1064 walk_state->num_operands--;
1065
1066 /* Check for a valid operand */
1067
1068 if (!walk_state->operands [walk_state->num_operands]) {
1069 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
1070 "Null operand! State=%p #Ops=%X\n",
1071 walk_state, walk_state->num_operands));
1072 *object = NULL;
1073 return (AE_AML_NO_OPERAND);
1074 }
1075
1076 /* Get operand and set stack entry to null */
1077
1078 *object = walk_state->operands [walk_state->num_operands];
1079 walk_state->operands [walk_state->num_operands] = NULL;
1080
1081 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n",
1082 *object, acpi_ut_get_object_type_name (*object),
1083 walk_state, walk_state->num_operands));
1084
1085 return (AE_OK);
1086}
1087
1088
1089/*******************************************************************************
1090 *
1091 * FUNCTION: acpi_ds_obj_stack_get_value
1092 *
1093 * PARAMETERS: Index - Stack index whose value is desired. Based
1094 * on the top of the stack (index=0 == top)
1095 * walk_state - Current Walk state
1096 *
1097 * RETURN: Pointer to the requested operand
1098 *
1099 * DESCRIPTION: Retrieve an object from this walk's operand stack. Index must
1100 * be within the range of the current stack pointer.
1101 *
1102 ******************************************************************************/
1103
1104void *
1105acpi_ds_obj_stack_get_value (
1106 u32 index,
1107 struct acpi_walk_state *walk_state)
1108{
1109
1110 ACPI_FUNCTION_TRACE_PTR ("ds_obj_stack_get_value", walk_state);
1111
1112
1113 /* Can't do it if the stack is empty */
1114
1115 if (walk_state->num_operands == 0) {
1116 return_PTR (NULL);
1117 }
1118
1119 /* or if the index is past the top of the stack */
1120
1121 if (index > (walk_state->num_operands - (u32) 1)) {
1122 return_PTR (NULL);
1123 }
1124
1125 return_PTR (walk_state->operands[(acpi_native_uint)(walk_state->num_operands - 1) -
1126 index]);
1127}
1128#endif
1129
1130
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
index fdf143b405be..8e665f2e3138 100644
--- a/drivers/acpi/ec.c
+++ b/drivers/acpi/ec.c
@@ -31,6 +31,7 @@
31#include <linux/delay.h> 31#include <linux/delay.h>
32#include <linux/proc_fs.h> 32#include <linux/proc_fs.h>
33#include <linux/seq_file.h> 33#include <linux/seq_file.h>
34#include <linux/interrupt.h>
34#include <asm/io.h> 35#include <asm/io.h>
35#include <acpi/acpi_bus.h> 36#include <acpi/acpi_bus.h>
36#include <acpi/acpi_drivers.h> 37#include <acpi/acpi_drivers.h>
@@ -49,17 +50,19 @@ ACPI_MODULE_NAME ("acpi_ec")
49 50
50#define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */ 51#define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */
51#define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */ 52#define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */
53#define ACPI_EC_FLAG_BURST 0x10 /* burst mode */
52#define ACPI_EC_FLAG_SCI 0x20 /* EC-SCI occurred */ 54#define ACPI_EC_FLAG_SCI 0x20 /* EC-SCI occurred */
53 55
54#define ACPI_EC_EVENT_OBF 0x01 /* Output buffer full */ 56#define ACPI_EC_EVENT_OBF 0x01 /* Output buffer full */
55#define ACPI_EC_EVENT_IBE 0x02 /* Input buffer empty */ 57#define ACPI_EC_EVENT_IBE 0x02 /* Input buffer empty */
56 58
57#define ACPI_EC_UDELAY 100 /* Poll @ 100us increments */ 59#define ACPI_EC_DELAY 50 /* Wait 50ms max. during EC ops */
58#define ACPI_EC_UDELAY_COUNT 1000 /* Wait 10ms max. during EC ops */
59#define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */ 60#define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */
60 61
61#define ACPI_EC_COMMAND_READ 0x80 62#define ACPI_EC_COMMAND_READ 0x80
62#define ACPI_EC_COMMAND_WRITE 0x81 63#define ACPI_EC_COMMAND_WRITE 0x81
64#define ACPI_EC_BURST_ENABLE 0x82
65#define ACPI_EC_BURST_DISABLE 0x83
63#define ACPI_EC_COMMAND_QUERY 0x84 66#define ACPI_EC_COMMAND_QUERY 0x84
64 67
65static int acpi_ec_add (struct acpi_device *device); 68static int acpi_ec_add (struct acpi_device *device);
@@ -87,7 +90,11 @@ struct acpi_ec {
87 struct acpi_generic_address command_addr; 90 struct acpi_generic_address command_addr;
88 struct acpi_generic_address data_addr; 91 struct acpi_generic_address data_addr;
89 unsigned long global_lock; 92 unsigned long global_lock;
90 spinlock_t lock; 93 unsigned int expect_event;
94 atomic_t leaving_burst; /* 0 : No, 1 : Yes, 2: abort*/
95 atomic_t pending_gpe;
96 struct semaphore sem;
97 wait_queue_head_t wait;
91}; 98};
92 99
93/* If we find an EC via the ECDT, we need to keep a ptr to its context */ 100/* If we find an EC via the ECDT, we need to keep a ptr to its context */
@@ -100,42 +107,122 @@ static struct acpi_device *first_ec;
100 Transaction Management 107 Transaction Management
101 -------------------------------------------------------------------------- */ 108 -------------------------------------------------------------------------- */
102 109
103static int 110static inline u32 acpi_ec_read_status(struct acpi_ec *ec)
104acpi_ec_wait (
105 struct acpi_ec *ec,
106 u8 event)
107{ 111{
108 u32 acpi_ec_status = 0; 112 u32 status = 0;
109 u32 i = ACPI_EC_UDELAY_COUNT;
110 113
111 if (!ec) 114 acpi_hw_low_level_read(8, &status, &ec->status_addr);
112 return -EINVAL; 115 return status;
116}
117
118static int acpi_ec_wait(struct acpi_ec *ec, unsigned int event)
119{
120 int result = 0;
121
122 ACPI_FUNCTION_TRACE("acpi_ec_wait");
113 123
114 /* Poll the EC status register waiting for the event to occur. */ 124 ec->expect_event = event;
125 smp_mb();
126
127 result = wait_event_interruptible_timeout(ec->wait,
128 !ec->expect_event,
129 msecs_to_jiffies(ACPI_EC_DELAY));
130
131 ec->expect_event = 0;
132 smp_mb();
133
134 if (result < 0){
135 ACPI_DEBUG_PRINT((ACPI_DB_ERROR," result = %d ", result));
136 return_VALUE(result);
137 }
138
139 /*
140 * Verify that the event in question has actually happened by
141 * querying EC status. Do the check even if operation timed-out
142 * to make sure that we did not miss interrupt.
143 */
115 switch (event) { 144 switch (event) {
116 case ACPI_EC_EVENT_OBF: 145 case ACPI_EC_EVENT_OBF:
117 do { 146 if (acpi_ec_read_status(ec) & ACPI_EC_FLAG_OBF)
118 acpi_hw_low_level_read(8, &acpi_ec_status, &ec->status_addr); 147 return_VALUE(0);
119 if (acpi_ec_status & ACPI_EC_FLAG_OBF)
120 return 0;
121 udelay(ACPI_EC_UDELAY);
122 } while (--i>0);
123 break; 148 break;
149
124 case ACPI_EC_EVENT_IBE: 150 case ACPI_EC_EVENT_IBE:
125 do { 151 if (~acpi_ec_read_status(ec) & ACPI_EC_FLAG_IBF)
126 acpi_hw_low_level_read(8, &acpi_ec_status, &ec->status_addr); 152 return_VALUE(0);
127 if (!(acpi_ec_status & ACPI_EC_FLAG_IBF))
128 return 0;
129 udelay(ACPI_EC_UDELAY);
130 } while (--i>0);
131 break; 153 break;
132 default:
133 return -EINVAL;
134 } 154 }
135 155
136 return -ETIME; 156 return_VALUE(-ETIME);
157}
158
159
160
161static int
162acpi_ec_enter_burst_mode (
163 struct acpi_ec *ec)
164{
165 u32 tmp = 0;
166 int status = 0;
167
168 ACPI_FUNCTION_TRACE("acpi_ec_enter_burst_mode");
169
170 status = acpi_ec_read_status(ec);
171 if (status != -EINVAL &&
172 !(status & ACPI_EC_FLAG_BURST)){
173 ACPI_DEBUG_PRINT((ACPI_DB_INFO,"entering burst mode \n"));
174 acpi_hw_low_level_write(8, ACPI_EC_BURST_ENABLE, &ec->command_addr);
175 status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF);
176 if (status){
177 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
178 ACPI_DEBUG_PRINT((ACPI_DB_ERROR," status = %d\n", status));
179 return_VALUE(-EINVAL);
180 }
181 acpi_hw_low_level_read(8, &tmp, &ec->data_addr);
182 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
183 if(tmp != 0x90 ) {/* Burst ACK byte*/
184 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,"Ack failed \n"));
185 return_VALUE(-EINVAL);
186 }
187 } else
188 ACPI_DEBUG_PRINT((ACPI_DB_INFO,"already be in burst mode \n"));
189 atomic_set(&ec->leaving_burst , 0);
190 return_VALUE(0);
137} 191}
138 192
193static int
194acpi_ec_leave_burst_mode (
195 struct acpi_ec *ec)
196{
197 int status =0;
198
199 ACPI_FUNCTION_TRACE("acpi_ec_leave_burst_mode");
200
201 atomic_set(&ec->leaving_burst , 1);
202 status = acpi_ec_read_status(ec);
203 if (status != -EINVAL &&
204 (status & ACPI_EC_FLAG_BURST)){
205 ACPI_DEBUG_PRINT((ACPI_DB_INFO,"leaving burst mode\n"));
206 acpi_hw_low_level_write(8, ACPI_EC_BURST_DISABLE, &ec->command_addr);
207 status = acpi_ec_wait(ec, ACPI_EC_FLAG_IBF);
208 if (status){
209 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
210 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,"------->wait fail\n"));
211 return_VALUE(-EINVAL);
212 }
213 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
214 status = acpi_ec_read_status(ec);
215 if (status != -EINVAL &&
216 (status & ACPI_EC_FLAG_BURST)) {
217 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,"------->status fail\n"));
218 return_VALUE(-EINVAL);
219 }
220 }else
221 ACPI_DEBUG_PRINT((ACPI_DB_INFO,"already be in Non-burst mode \n"));
222 ACPI_DEBUG_PRINT((ACPI_DB_INFO,"leaving burst mode\n"));
223
224 return_VALUE(0);
225}
139 226
140static int 227static int
141acpi_ec_read ( 228acpi_ec_read (
@@ -143,16 +230,15 @@ acpi_ec_read (
143 u8 address, 230 u8 address,
144 u32 *data) 231 u32 *data)
145{ 232{
146 acpi_status status = AE_OK; 233 int status = 0;
147 int result = 0; 234 u32 glk;
148 unsigned long flags = 0;
149 u32 glk = 0;
150 235
151 ACPI_FUNCTION_TRACE("acpi_ec_read"); 236 ACPI_FUNCTION_TRACE("acpi_ec_read");
152 237
153 if (!ec || !data) 238 if (!ec || !data)
154 return_VALUE(-EINVAL); 239 return_VALUE(-EINVAL);
155 240
241retry:
156 *data = 0; 242 *data = 0;
157 243
158 if (ec->global_lock) { 244 if (ec->global_lock) {
@@ -160,32 +246,50 @@ acpi_ec_read (
160 if (ACPI_FAILURE(status)) 246 if (ACPI_FAILURE(status))
161 return_VALUE(-ENODEV); 247 return_VALUE(-ENODEV);
162 } 248 }
163 249
164 spin_lock_irqsave(&ec->lock, flags); 250 WARN_ON(in_interrupt());
251 down(&ec->sem);
252
253 if(acpi_ec_enter_burst_mode(ec))
254 goto end;
165 255
166 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_READ, &ec->command_addr); 256 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_READ, &ec->command_addr);
167 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); 257 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
168 if (result) 258 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
259 if (status) {
169 goto end; 260 goto end;
261 }
170 262
171 acpi_hw_low_level_write(8, address, &ec->data_addr); 263 acpi_hw_low_level_write(8, address, &ec->data_addr);
172 result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); 264 status= acpi_ec_wait(ec, ACPI_EC_EVENT_OBF);
173 if (result) 265 if (status){
266 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
174 goto end; 267 goto end;
175 268 }
176 269
177 acpi_hw_low_level_read(8, data, &ec->data_addr); 270 acpi_hw_low_level_read(8, data, &ec->data_addr);
271 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
178 272
179 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Read [%02x] from address [%02x]\n", 273 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Read [%02x] from address [%02x]\n",
180 *data, address)); 274 *data, address));
181 275
182end: 276end:
183 spin_unlock_irqrestore(&ec->lock, flags); 277 acpi_ec_leave_burst_mode(ec);
278 up(&ec->sem);
184 279
185 if (ec->global_lock) 280 if (ec->global_lock)
186 acpi_release_global_lock(glk); 281 acpi_release_global_lock(glk);
187 282
188 return_VALUE(result); 283 if(atomic_read(&ec->leaving_burst) == 2){
284 ACPI_DEBUG_PRINT((ACPI_DB_INFO,"aborted, retry ...\n"));
285 while(atomic_read(&ec->pending_gpe)){
286 msleep(1);
287 }
288 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
289 goto retry;
290 }
291
292 return_VALUE(status);
189} 293}
190 294
191 295
@@ -195,49 +299,80 @@ acpi_ec_write (
195 u8 address, 299 u8 address,
196 u8 data) 300 u8 data)
197{ 301{
198 int result = 0; 302 int status = 0;
199 acpi_status status = AE_OK; 303 u32 glk;
200 unsigned long flags = 0; 304 u32 tmp;
201 u32 glk = 0;
202 305
203 ACPI_FUNCTION_TRACE("acpi_ec_write"); 306 ACPI_FUNCTION_TRACE("acpi_ec_write");
204 307
205 if (!ec) 308 if (!ec)
206 return_VALUE(-EINVAL); 309 return_VALUE(-EINVAL);
207 310retry:
208 if (ec->global_lock) { 311 if (ec->global_lock) {
209 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); 312 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
210 if (ACPI_FAILURE(status)) 313 if (ACPI_FAILURE(status))
211 return_VALUE(-ENODEV); 314 return_VALUE(-ENODEV);
212 } 315 }
213 316
214 spin_lock_irqsave(&ec->lock, flags); 317 WARN_ON(in_interrupt());
318 down(&ec->sem);
319
320 if(acpi_ec_enter_burst_mode(ec))
321 goto end;
322
323 status = acpi_ec_read_status(ec);
324 if (status != -EINVAL &&
325 !(status & ACPI_EC_FLAG_BURST)){
326 acpi_hw_low_level_write(8, ACPI_EC_BURST_ENABLE, &ec->command_addr);
327 status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF);
328 if (status)
329 goto end;
330 acpi_hw_low_level_read(8, &tmp, &ec->data_addr);
331 if(tmp != 0x90 ) /* Burst ACK byte*/
332 goto end;
333 }
334 /*Now we are in burst mode*/
215 335
216 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_WRITE, &ec->command_addr); 336 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_WRITE, &ec->command_addr);
217 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); 337 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
218 if (result) 338 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
339 if (status){
219 goto end; 340 goto end;
341 }
220 342
221 acpi_hw_low_level_write(8, address, &ec->data_addr); 343 acpi_hw_low_level_write(8, address, &ec->data_addr);
222 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); 344 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
223 if (result) 345 if (status){
346 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
224 goto end; 347 goto end;
348 }
225 349
226 acpi_hw_low_level_write(8, data, &ec->data_addr); 350 acpi_hw_low_level_write(8, data, &ec->data_addr);
227 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); 351 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
228 if (result) 352 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
353 if (status)
229 goto end; 354 goto end;
230 355
231 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Wrote [%02x] to address [%02x]\n", 356 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Wrote [%02x] to address [%02x]\n",
232 data, address)); 357 data, address));
233 358
234end: 359end:
235 spin_unlock_irqrestore(&ec->lock, flags); 360 acpi_ec_leave_burst_mode(ec);
361 up(&ec->sem);
236 362
237 if (ec->global_lock) 363 if (ec->global_lock)
238 acpi_release_global_lock(glk); 364 acpi_release_global_lock(glk);
239 365
240 return_VALUE(result); 366 if(atomic_read(&ec->leaving_burst) == 2){
367 ACPI_DEBUG_PRINT((ACPI_DB_INFO,"aborted, retry ...\n"));
368 while(atomic_read(&ec->pending_gpe)){
369 msleep(1);
370 }
371 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
372 goto retry;
373 }
374
375 return_VALUE(status);
241} 376}
242 377
243/* 378/*
@@ -289,16 +424,13 @@ acpi_ec_query (
289 struct acpi_ec *ec, 424 struct acpi_ec *ec,
290 u32 *data) 425 u32 *data)
291{ 426{
292 int result = 0; 427 int status = 0;
293 acpi_status status = AE_OK; 428 u32 glk;
294 unsigned long flags = 0;
295 u32 glk = 0;
296 429
297 ACPI_FUNCTION_TRACE("acpi_ec_query"); 430 ACPI_FUNCTION_TRACE("acpi_ec_query");
298 431
299 if (!ec || !data) 432 if (!ec || !data)
300 return_VALUE(-EINVAL); 433 return_VALUE(-EINVAL);
301
302 *data = 0; 434 *data = 0;
303 435
304 if (ec->global_lock) { 436 if (ec->global_lock) {
@@ -307,29 +439,39 @@ acpi_ec_query (
307 return_VALUE(-ENODEV); 439 return_VALUE(-ENODEV);
308 } 440 }
309 441
442 down(&ec->sem);
443 if(acpi_ec_enter_burst_mode(ec))
444 goto end;
310 /* 445 /*
311 * Query the EC to find out which _Qxx method we need to evaluate. 446 * Query the EC to find out which _Qxx method we need to evaluate.
312 * Note that successful completion of the query causes the ACPI_EC_SCI 447 * Note that successful completion of the query causes the ACPI_EC_SCI
313 * bit to be cleared (and thus clearing the interrupt source). 448 * bit to be cleared (and thus clearing the interrupt source).
314 */ 449 */
315 spin_lock_irqsave(&ec->lock, flags);
316
317 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_QUERY, &ec->command_addr); 450 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_QUERY, &ec->command_addr);
318 result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); 451 status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF);
319 if (result) 452 if (status){
453 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
320 goto end; 454 goto end;
321 455 }
456
322 acpi_hw_low_level_read(8, data, &ec->data_addr); 457 acpi_hw_low_level_read(8, data, &ec->data_addr);
458 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
323 if (!*data) 459 if (!*data)
324 result = -ENODATA; 460 status = -ENODATA;
325 461
326end: 462end:
327 spin_unlock_irqrestore(&ec->lock, flags); 463 acpi_ec_leave_burst_mode(ec);
464 up(&ec->sem);
328 465
329 if (ec->global_lock) 466 if (ec->global_lock)
330 acpi_release_global_lock(glk); 467 acpi_release_global_lock(glk);
331 468
332 return_VALUE(result); 469 if(atomic_read(&ec->leaving_burst) == 2){
470 ACPI_DEBUG_PRINT((ACPI_DB_INFO,"aborted, retry ...\n"));
471 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
472 status = -ENODATA;
473 }
474 return_VALUE(status);
333} 475}
334 476
335 477
@@ -347,42 +489,29 @@ acpi_ec_gpe_query (
347 void *ec_cxt) 489 void *ec_cxt)
348{ 490{
349 struct acpi_ec *ec = (struct acpi_ec *) ec_cxt; 491 struct acpi_ec *ec = (struct acpi_ec *) ec_cxt;
350 u32 value = 0; 492 u32 value;
351 unsigned long flags = 0; 493 int result = -ENODATA;
352 static char object_name[5] = {'_','Q','0','0','\0'}; 494 static char object_name[5] = {'_','Q','0','0','\0'};
353 const char hex[] = {'0','1','2','3','4','5','6','7', 495 const char hex[] = {'0','1','2','3','4','5','6','7',
354 '8','9','A','B','C','D','E','F'}; 496 '8','9','A','B','C','D','E','F'};
355 497
356 ACPI_FUNCTION_TRACE("acpi_ec_gpe_query"); 498 ACPI_FUNCTION_TRACE("acpi_ec_gpe_query");
357 499
358 if (!ec_cxt) 500 if (acpi_ec_read_status(ec) & ACPI_EC_FLAG_SCI)
359 goto end; 501 result = acpi_ec_query(ec, &value);
360
361 spin_lock_irqsave(&ec->lock, flags);
362 acpi_hw_low_level_read(8, &value, &ec->command_addr);
363 spin_unlock_irqrestore(&ec->lock, flags);
364 502
365 /* TBD: Implement asynch events! 503 if (result)
366 * NOTE: All we care about are EC-SCI's. Other EC events are
367 * handled via polling (yuck!). This is because some systems
368 * treat EC-SCIs as level (versus EDGE!) triggered, preventing
369 * a purely interrupt-driven approach (grumble, grumble).
370 */
371 if (!(value & ACPI_EC_FLAG_SCI))
372 goto end; 504 goto end;
373 505
374 if (acpi_ec_query(ec, &value))
375 goto end;
376
377 object_name[2] = hex[((value >> 4) & 0x0F)]; 506 object_name[2] = hex[((value >> 4) & 0x0F)];
378 object_name[3] = hex[(value & 0x0F)]; 507 object_name[3] = hex[(value & 0x0F)];
379 508
380 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluating %s\n", object_name)); 509 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluating %s\n", object_name));
381 510
382 acpi_evaluate_object(ec->handle, object_name, NULL, NULL); 511 acpi_evaluate_object(ec->handle, object_name, NULL, NULL);
383 512end:
384end: 513 atomic_dec(&ec->pending_gpe);
385 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); 514 return;
386} 515}
387 516
388static u32 517static u32
@@ -390,6 +519,7 @@ acpi_ec_gpe_handler (
390 void *data) 519 void *data)
391{ 520{
392 acpi_status status = AE_OK; 521 acpi_status status = AE_OK;
522 u32 value;
393 struct acpi_ec *ec = (struct acpi_ec *) data; 523 struct acpi_ec *ec = (struct acpi_ec *) data;
394 524
395 if (!ec) 525 if (!ec)
@@ -397,13 +527,41 @@ acpi_ec_gpe_handler (
397 527
398 acpi_disable_gpe(NULL, ec->gpe_bit, ACPI_ISR); 528 acpi_disable_gpe(NULL, ec->gpe_bit, ACPI_ISR);
399 529
400 status = acpi_os_queue_for_execution(OSD_PRIORITY_GPE, 530 value = acpi_ec_read_status(ec);
401 acpi_ec_gpe_query, ec);
402 531
403 if (status == AE_OK) 532 if((value & ACPI_EC_FLAG_IBF) &&
404 return ACPI_INTERRUPT_HANDLED; 533 !(value & ACPI_EC_FLAG_BURST) &&
405 else 534 (atomic_read(&ec->leaving_burst) == 0)) {
406 return ACPI_INTERRUPT_NOT_HANDLED; 535 /*
536 * the embedded controller disables
537 * burst mode for any reason other
538 * than the burst disable command
539 * to process critical event.
540 */
541 atomic_set(&ec->leaving_burst , 2); /* block current pending transaction
542 and retry */
543 wake_up(&ec->wait);
544 }else {
545 if ((ec->expect_event == ACPI_EC_EVENT_OBF &&
546 (value & ACPI_EC_FLAG_OBF)) ||
547 (ec->expect_event == ACPI_EC_EVENT_IBE &&
548 !(value & ACPI_EC_FLAG_IBF))) {
549 ec->expect_event = 0;
550 wake_up(&ec->wait);
551 return ACPI_INTERRUPT_HANDLED;
552 }
553 }
554
555 if (value & ACPI_EC_FLAG_SCI){
556 atomic_add(1, &ec->pending_gpe) ;
557 status = acpi_os_queue_for_execution(OSD_PRIORITY_GPE,
558 acpi_ec_gpe_query, ec);
559 return status == AE_OK ?
560 ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED;
561 }
562 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_ISR);
563 return status == AE_OK ?
564 ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED;
407} 565}
408 566
409/* -------------------------------------------------------------------------- 567/* --------------------------------------------------------------------------
@@ -421,10 +579,8 @@ acpi_ec_space_setup (
421 * The EC object is in the handler context and is needed 579 * The EC object is in the handler context and is needed
422 * when calling the acpi_ec_space_handler. 580 * when calling the acpi_ec_space_handler.
423 */ 581 */
424 if(function == ACPI_REGION_DEACTIVATE) 582 *return_context = (function != ACPI_REGION_DEACTIVATE) ?
425 *return_context = NULL; 583 handler_context : NULL;
426 else
427 *return_context = handler_context;
428 584
429 return AE_OK; 585 return AE_OK;
430} 586}
@@ -441,7 +597,7 @@ acpi_ec_space_handler (
441{ 597{
442 int result = 0; 598 int result = 0;
443 struct acpi_ec *ec = NULL; 599 struct acpi_ec *ec = NULL;
444 u32 temp = 0; 600 u64 temp = *value;
445 acpi_integer f_v = 0; 601 acpi_integer f_v = 0;
446 int i = 0; 602 int i = 0;
447 603
@@ -450,10 +606,9 @@ acpi_ec_space_handler (
450 if ((address > 0xFF) || !value || !handler_context) 606 if ((address > 0xFF) || !value || !handler_context)
451 return_VALUE(AE_BAD_PARAMETER); 607 return_VALUE(AE_BAD_PARAMETER);
452 608
453 if(bit_width != 8) { 609 if (bit_width != 8 && acpi_strict) {
454 printk(KERN_WARNING PREFIX "acpi_ec_space_handler: bit_width should be 8\n"); 610 printk(KERN_WARNING PREFIX "acpi_ec_space_handler: bit_width should be 8\n");
455 if (acpi_strict) 611 return_VALUE(AE_BAD_PARAMETER);
456 return_VALUE(AE_BAD_PARAMETER);
457 } 612 }
458 613
459 ec = (struct acpi_ec *) handler_context; 614 ec = (struct acpi_ec *) handler_context;
@@ -461,11 +616,11 @@ acpi_ec_space_handler (
461next_byte: 616next_byte:
462 switch (function) { 617 switch (function) {
463 case ACPI_READ: 618 case ACPI_READ:
464 result = acpi_ec_read(ec, (u8) address, &temp); 619 temp = 0;
465 *value = (acpi_integer) temp; 620 result = acpi_ec_read(ec, (u8) address, (u32 *)&temp);
466 break; 621 break;
467 case ACPI_WRITE: 622 case ACPI_WRITE:
468 result = acpi_ec_write(ec, (u8) address, (u8) *value); 623 result = acpi_ec_write(ec, (u8) address, (u8) temp);
469 break; 624 break;
470 default: 625 default:
471 result = -EINVAL; 626 result = -EINVAL;
@@ -474,19 +629,18 @@ next_byte:
474 } 629 }
475 630
476 bit_width -= 8; 631 bit_width -= 8;
477 if(bit_width){ 632 if (bit_width) {
478 633 if (function == ACPI_READ)
479 if(function == ACPI_READ) 634 f_v |= temp << 8 * i;
480 f_v |= (acpi_integer) (*value) << 8*i; 635 if (function == ACPI_WRITE)
481 if(function == ACPI_WRITE) 636 temp >>= 8;
482 (*value) >>=8;
483 i++; 637 i++;
638 address++;
484 goto next_byte; 639 goto next_byte;
485 } 640 }
486 641
487 642 if (function == ACPI_READ) {
488 if(function == ACPI_READ){ 643 f_v |= temp << 8 * i;
489 f_v |= (acpi_integer) (*value) << 8*i;
490 *value = f_v; 644 *value = f_v;
491 } 645 }
492 646
@@ -505,8 +659,6 @@ out:
505 default: 659 default:
506 return_VALUE(AE_OK); 660 return_VALUE(AE_OK);
507 } 661 }
508
509
510} 662}
511 663
512 664
@@ -533,6 +685,7 @@ acpi_ec_read_info (struct seq_file *seq, void *offset)
533 (u32) ec->status_addr.address, (u32) ec->data_addr.address); 685 (u32) ec->status_addr.address, (u32) ec->data_addr.address);
534 seq_printf(seq, "use global lock: %s\n", 686 seq_printf(seq, "use global lock: %s\n",
535 ec->global_lock?"yes":"no"); 687 ec->global_lock?"yes":"no");
688 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
536 689
537end: 690end:
538 return_VALUE(0); 691 return_VALUE(0);
@@ -555,7 +708,7 @@ static int
555acpi_ec_add_fs ( 708acpi_ec_add_fs (
556 struct acpi_device *device) 709 struct acpi_device *device)
557{ 710{
558 struct proc_dir_entry *entry = NULL; 711 struct proc_dir_entry *entry;
559 712
560 ACPI_FUNCTION_TRACE("acpi_ec_add_fs"); 713 ACPI_FUNCTION_TRACE("acpi_ec_add_fs");
561 714
@@ -606,9 +759,9 @@ static int
606acpi_ec_add ( 759acpi_ec_add (
607 struct acpi_device *device) 760 struct acpi_device *device)
608{ 761{
609 int result = 0; 762 int result;
610 acpi_status status = AE_OK; 763 acpi_status status;
611 struct acpi_ec *ec = NULL; 764 struct acpi_ec *ec;
612 unsigned long uid; 765 unsigned long uid;
613 766
614 ACPI_FUNCTION_TRACE("acpi_ec_add"); 767 ACPI_FUNCTION_TRACE("acpi_ec_add");
@@ -623,7 +776,10 @@ acpi_ec_add (
623 776
624 ec->handle = device->handle; 777 ec->handle = device->handle;
625 ec->uid = -1; 778 ec->uid = -1;
626 spin_lock_init(&ec->lock); 779 atomic_set(&ec->pending_gpe, 0);
780 atomic_set(&ec->leaving_burst , 1);
781 init_MUTEX(&ec->sem);
782 init_waitqueue_head(&ec->wait);
627 strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME); 783 strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME);
628 strcpy(acpi_device_class(device), ACPI_EC_CLASS); 784 strcpy(acpi_device_class(device), ACPI_EC_CLASS);
629 acpi_driver_data(device) = ec; 785 acpi_driver_data(device) = ec;
@@ -637,7 +793,7 @@ acpi_ec_add (
637 if (ec_ecdt && ec_ecdt->uid == uid) { 793 if (ec_ecdt && ec_ecdt->uid == uid) {
638 acpi_remove_address_space_handler(ACPI_ROOT_OBJECT, 794 acpi_remove_address_space_handler(ACPI_ROOT_OBJECT,
639 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler); 795 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler);
640 796
641 acpi_remove_gpe_handler(NULL, ec_ecdt->gpe_bit, &acpi_ec_gpe_handler); 797 acpi_remove_gpe_handler(NULL, ec_ecdt->gpe_bit, &acpi_ec_gpe_handler);
642 798
643 kfree(ec_ecdt); 799 kfree(ec_ecdt);
@@ -677,7 +833,7 @@ acpi_ec_remove (
677 struct acpi_device *device, 833 struct acpi_device *device,
678 int type) 834 int type)
679{ 835{
680 struct acpi_ec *ec = NULL; 836 struct acpi_ec *ec;
681 837
682 ACPI_FUNCTION_TRACE("acpi_ec_remove"); 838 ACPI_FUNCTION_TRACE("acpi_ec_remove");
683 839
@@ -732,8 +888,8 @@ static int
732acpi_ec_start ( 888acpi_ec_start (
733 struct acpi_device *device) 889 struct acpi_device *device)
734{ 890{
735 acpi_status status = AE_OK; 891 acpi_status status;
736 struct acpi_ec *ec = NULL; 892 struct acpi_ec *ec;
737 893
738 ACPI_FUNCTION_TRACE("acpi_ec_start"); 894 ACPI_FUNCTION_TRACE("acpi_ec_start");
739 895
@@ -789,8 +945,8 @@ acpi_ec_stop (
789 struct acpi_device *device, 945 struct acpi_device *device,
790 int type) 946 int type)
791{ 947{
792 acpi_status status = AE_OK; 948 acpi_status status;
793 struct acpi_ec *ec = NULL; 949 struct acpi_ec *ec;
794 950
795 ACPI_FUNCTION_TRACE("acpi_ec_stop"); 951 ACPI_FUNCTION_TRACE("acpi_ec_stop");
796 952
@@ -832,7 +988,6 @@ acpi_fake_ecdt_callback (
832 status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec_ecdt->gpe_bit); 988 status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec_ecdt->gpe_bit);
833 if (ACPI_FAILURE(status)) 989 if (ACPI_FAILURE(status))
834 return status; 990 return status;
835 spin_lock_init(&ec_ecdt->lock);
836 ec_ecdt->global_lock = TRUE; 991 ec_ecdt->global_lock = TRUE;
837 ec_ecdt->handle = handle; 992 ec_ecdt->handle = handle;
838 993
@@ -890,7 +1045,7 @@ acpi_ec_get_real_ecdt(void)
890 acpi_status status; 1045 acpi_status status;
891 struct acpi_table_ecdt *ecdt_ptr; 1046 struct acpi_table_ecdt *ecdt_ptr;
892 1047
893 status = acpi_get_firmware_table("ECDT", 1, ACPI_LOGICAL_ADDRESSING, 1048 status = acpi_get_firmware_table("ECDT", 1, ACPI_LOGICAL_ADDRESSING,
894 (struct acpi_table_header **) &ecdt_ptr); 1049 (struct acpi_table_header **) &ecdt_ptr);
895 if (ACPI_FAILURE(status)) 1050 if (ACPI_FAILURE(status))
896 return -ENODEV; 1051 return -ENODEV;
@@ -905,11 +1060,12 @@ acpi_ec_get_real_ecdt(void)
905 return -ENOMEM; 1060 return -ENOMEM;
906 memset(ec_ecdt, 0, sizeof(struct acpi_ec)); 1061 memset(ec_ecdt, 0, sizeof(struct acpi_ec));
907 1062
1063 init_MUTEX(&ec_ecdt->sem);
1064 init_waitqueue_head(&ec_ecdt->wait);
908 ec_ecdt->command_addr = ecdt_ptr->ec_control; 1065 ec_ecdt->command_addr = ecdt_ptr->ec_control;
909 ec_ecdt->status_addr = ecdt_ptr->ec_control; 1066 ec_ecdt->status_addr = ecdt_ptr->ec_control;
910 ec_ecdt->data_addr = ecdt_ptr->ec_data; 1067 ec_ecdt->data_addr = ecdt_ptr->ec_data;
911 ec_ecdt->gpe_bit = ecdt_ptr->gpe_bit; 1068 ec_ecdt->gpe_bit = ecdt_ptr->gpe_bit;
912 spin_lock_init(&ec_ecdt->lock);
913 /* use the GL just to be safe */ 1069 /* use the GL just to be safe */
914 ec_ecdt->global_lock = TRUE; 1070 ec_ecdt->global_lock = TRUE;
915 ec_ecdt->uid = ecdt_ptr->uid; 1071 ec_ecdt->uid = ecdt_ptr->uid;
@@ -978,7 +1134,7 @@ error:
978 1134
979static int __init acpi_ec_init (void) 1135static int __init acpi_ec_init (void)
980{ 1136{
981 int result = 0; 1137 int result;
982 1138
983 ACPI_FUNCTION_TRACE("acpi_ec_init"); 1139 ACPI_FUNCTION_TRACE("acpi_ec_init");
984 1140
diff --git a/drivers/acpi/events/evevent.c b/drivers/acpi/events/evevent.c
index 2a213604ae51..dd3a72a869f4 100644
--- a/drivers/acpi/events/evevent.c
+++ b/drivers/acpi/events/evevent.c
@@ -47,6 +47,16 @@
47#define _COMPONENT ACPI_EVENTS 47#define _COMPONENT ACPI_EVENTS
48 ACPI_MODULE_NAME ("evevent") 48 ACPI_MODULE_NAME ("evevent")
49 49
50/* Local prototypes */
51
52static acpi_status
53acpi_ev_fixed_event_initialize (
54 void);
55
56static u32
57acpi_ev_fixed_event_dispatch (
58 u32 event);
59
50 60
51/******************************************************************************* 61/*******************************************************************************
52 * 62 *
@@ -56,7 +66,7 @@
56 * 66 *
57 * RETURN: Status 67 * RETURN: Status
58 * 68 *
59 * DESCRIPTION: Initialize global data structures for events. 69 * DESCRIPTION: Initialize global data structures for ACPI events (Fixed, GPE)
60 * 70 *
61 ******************************************************************************/ 71 ******************************************************************************/
62 72
@@ -78,9 +88,9 @@ acpi_ev_initialize_events (
78 } 88 }
79 89
80 /* 90 /*
81 * Initialize the Fixed and General Purpose Events. This is 91 * Initialize the Fixed and General Purpose Events. This is done prior to
82 * done prior to enabling SCIs to prevent interrupts from 92 * enabling SCIs to prevent interrupts from occurring before the handlers are
83 * occurring before handers are installed. 93 * installed.
84 */ 94 */
85 status = acpi_ev_fixed_event_initialize (); 95 status = acpi_ev_fixed_event_initialize ();
86 if (ACPI_FAILURE (status)) { 96 if (ACPI_FAILURE (status)) {
@@ -161,7 +171,7 @@ acpi_ev_install_xrupt_handlers (
161 * 171 *
162 ******************************************************************************/ 172 ******************************************************************************/
163 173
164acpi_status 174static acpi_status
165acpi_ev_fixed_event_initialize ( 175acpi_ev_fixed_event_initialize (
166 void) 176 void)
167{ 177{
@@ -180,7 +190,8 @@ acpi_ev_fixed_event_initialize (
180 /* Enable the fixed event */ 190 /* Enable the fixed event */
181 191
182 if (acpi_gbl_fixed_event_info[i].enable_register_id != 0xFF) { 192 if (acpi_gbl_fixed_event_info[i].enable_register_id != 0xFF) {
183 status = acpi_set_register (acpi_gbl_fixed_event_info[i].enable_register_id, 193 status = acpi_set_register (
194 acpi_gbl_fixed_event_info[i].enable_register_id,
184 0, ACPI_MTX_LOCK); 195 0, ACPI_MTX_LOCK);
185 if (ACPI_FAILURE (status)) { 196 if (ACPI_FAILURE (status)) {
186 return (status); 197 return (status);
@@ -200,7 +211,7 @@ acpi_ev_fixed_event_initialize (
200 * 211 *
201 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED 212 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
202 * 213 *
203 * DESCRIPTION: Checks the PM status register for fixed events 214 * DESCRIPTION: Checks the PM status register for active fixed events
204 * 215 *
205 ******************************************************************************/ 216 ******************************************************************************/
206 217
@@ -221,8 +232,10 @@ acpi_ev_fixed_event_detect (
221 * Read the fixed feature status and enable registers, as all the cases 232 * Read the fixed feature status and enable registers, as all the cases
222 * depend on their values. Ignore errors here. 233 * depend on their values. Ignore errors here.
223 */ 234 */
224 (void) acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1_STATUS, &fixed_status); 235 (void) acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1_STATUS,
225 (void) acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1_ENABLE, &fixed_enable); 236 &fixed_status);
237 (void) acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1_ENABLE,
238 &fixed_enable);
226 239
227 ACPI_DEBUG_PRINT ((ACPI_DB_INTERRUPTS, 240 ACPI_DEBUG_PRINT ((ACPI_DB_INTERRUPTS,
228 "Fixed Event Block: Enable %08X Status %08X\n", 241 "Fixed Event Block: Enable %08X Status %08X\n",
@@ -259,7 +272,7 @@ acpi_ev_fixed_event_detect (
259 * 272 *
260 ******************************************************************************/ 273 ******************************************************************************/
261 274
262u32 275static u32
263acpi_ev_fixed_event_dispatch ( 276acpi_ev_fixed_event_dispatch (
264 u32 event) 277 u32 event)
265{ 278{
diff --git a/drivers/acpi/events/evgpe.c b/drivers/acpi/events/evgpe.c
index 118d72ac7c76..081120b109ba 100644
--- a/drivers/acpi/events/evgpe.c
+++ b/drivers/acpi/events/evgpe.c
@@ -48,6 +48,12 @@
48#define _COMPONENT ACPI_EVENTS 48#define _COMPONENT ACPI_EVENTS
49 ACPI_MODULE_NAME ("evgpe") 49 ACPI_MODULE_NAME ("evgpe")
50 50
51/* Local prototypes */
52
53static void ACPI_SYSTEM_XFACE
54acpi_ev_asynch_execute_gpe_method (
55 void *context);
56
51 57
52/******************************************************************************* 58/*******************************************************************************
53 * 59 *
@@ -335,8 +341,10 @@ acpi_ev_get_gpe_event_info (
335 gpe_block = acpi_gbl_gpe_fadt_blocks[i]; 341 gpe_block = acpi_gbl_gpe_fadt_blocks[i];
336 if (gpe_block) { 342 if (gpe_block) {
337 if ((gpe_number >= gpe_block->block_base_number) && 343 if ((gpe_number >= gpe_block->block_base_number) &&
338 (gpe_number < gpe_block->block_base_number + (gpe_block->register_count * 8))) { 344 (gpe_number < gpe_block->block_base_number +
339 return (&gpe_block->event_info[gpe_number - gpe_block->block_base_number]); 345 (gpe_block->register_count * 8))) {
346 return (&gpe_block->event_info[gpe_number -
347 gpe_block->block_base_number]);
340 } 348 }
341 } 349 }
342 } 350 }
@@ -437,7 +445,7 @@ acpi_ev_gpe_detect (
437 "Read GPE Register at GPE%X: Status=%02X, Enable=%02X\n", 445 "Read GPE Register at GPE%X: Status=%02X, Enable=%02X\n",
438 gpe_register_info->base_gpe_number, status_reg, enable_reg)); 446 gpe_register_info->base_gpe_number, status_reg, enable_reg));
439 447
440 /* First check if there is anything active at all in this register */ 448 /* Check if there is anything active at all in this register */
441 449
442 enabled_status_byte = (u8) (status_reg & enable_reg); 450 enabled_status_byte = (u8) (status_reg & enable_reg);
443 if (!enabled_status_byte) { 451 if (!enabled_status_byte) {
@@ -457,8 +465,8 @@ acpi_ev_gpe_detect (
457 * or method. 465 * or method.
458 */ 466 */
459 int_status |= acpi_ev_gpe_dispatch ( 467 int_status |= acpi_ev_gpe_dispatch (
460 &gpe_block->event_info[(i * ACPI_GPE_REGISTER_WIDTH) + j], 468 &gpe_block->event_info[(i * ACPI_GPE_REGISTER_WIDTH) + j],
461 (u32) j + gpe_register_info->base_gpe_number); 469 (u32) j + gpe_register_info->base_gpe_number);
462 } 470 }
463 } 471 }
464 } 472 }
@@ -523,7 +531,8 @@ acpi_ev_asynch_execute_gpe_method (
523 * Take a snapshot of the GPE info for this level - we copy the 531 * Take a snapshot of the GPE info for this level - we copy the
524 * info to prevent a race condition with remove_handler/remove_block. 532 * info to prevent a race condition with remove_handler/remove_block.
525 */ 533 */
526 ACPI_MEMCPY (&local_gpe_event_info, gpe_event_info, sizeof (struct acpi_gpe_event_info)); 534 ACPI_MEMCPY (&local_gpe_event_info, gpe_event_info,
535 sizeof (struct acpi_gpe_event_info));
527 536
528 status = acpi_ut_release_mutex (ACPI_MTX_EVENTS); 537 status = acpi_ut_release_mutex (ACPI_MTX_EVENTS);
529 if (ACPI_FAILURE (status)) { 538 if (ACPI_FAILURE (status)) {
@@ -534,7 +543,8 @@ acpi_ev_asynch_execute_gpe_method (
534 * Must check for control method type dispatch one more 543 * Must check for control method type dispatch one more
535 * time to avoid race with ev_gpe_install_handler 544 * time to avoid race with ev_gpe_install_handler
536 */ 545 */
537 if ((local_gpe_event_info.flags & ACPI_GPE_DISPATCH_MASK) == ACPI_GPE_DISPATCH_METHOD) { 546 if ((local_gpe_event_info.flags & ACPI_GPE_DISPATCH_MASK) ==
547 ACPI_GPE_DISPATCH_METHOD) {
538 /* 548 /*
539 * Invoke the GPE Method (_Lxx, _Exx) i.e., evaluate the _Lxx/_Exx 549 * Invoke the GPE Method (_Lxx, _Exx) i.e., evaluate the _Lxx/_Exx
540 * control method that corresponds to this GPE 550 * control method that corresponds to this GPE
@@ -553,7 +563,8 @@ acpi_ev_asynch_execute_gpe_method (
553 } 563 }
554 } 564 }
555 565
556 if ((local_gpe_event_info.flags & ACPI_GPE_XRUPT_TYPE_MASK) == ACPI_GPE_LEVEL_TRIGGERED) { 566 if ((local_gpe_event_info.flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
567 ACPI_GPE_LEVEL_TRIGGERED) {
557 /* 568 /*
558 * GPE is level-triggered, we clear the GPE status bit after 569 * GPE is level-triggered, we clear the GPE status bit after
559 * handling the event. 570 * handling the event.
@@ -575,7 +586,7 @@ acpi_ev_asynch_execute_gpe_method (
575 * 586 *
576 * FUNCTION: acpi_ev_gpe_dispatch 587 * FUNCTION: acpi_ev_gpe_dispatch
577 * 588 *
578 * PARAMETERS: gpe_event_info - info for this GPE 589 * PARAMETERS: gpe_event_info - Info for this GPE
579 * gpe_number - Number relative to the parent GPE block 590 * gpe_number - Number relative to the parent GPE block
580 * 591 *
581 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED 592 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
@@ -602,10 +613,12 @@ acpi_ev_gpe_dispatch (
602 * If edge-triggered, clear the GPE status bit now. Note that 613 * If edge-triggered, clear the GPE status bit now. Note that
603 * level-triggered events are cleared after the GPE is serviced. 614 * level-triggered events are cleared after the GPE is serviced.
604 */ 615 */
605 if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) == ACPI_GPE_EDGE_TRIGGERED) { 616 if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
617 ACPI_GPE_EDGE_TRIGGERED) {
606 status = acpi_hw_clear_gpe (gpe_event_info); 618 status = acpi_hw_clear_gpe (gpe_event_info);
607 if (ACPI_FAILURE (status)) { 619 if (ACPI_FAILURE (status)) {
608 ACPI_REPORT_ERROR (("acpi_ev_gpe_dispatch: %s, Unable to clear GPE[%2X]\n", 620 ACPI_REPORT_ERROR ((
621 "acpi_ev_gpe_dispatch: %s, Unable to clear GPE[%2X]\n",
609 acpi_format_exception (status), gpe_number)); 622 acpi_format_exception (status), gpe_number));
610 return_VALUE (ACPI_INTERRUPT_NOT_HANDLED); 623 return_VALUE (ACPI_INTERRUPT_NOT_HANDLED);
611 } 624 }
@@ -639,7 +652,8 @@ acpi_ev_gpe_dispatch (
639 652
640 /* It is now safe to clear level-triggered events. */ 653 /* It is now safe to clear level-triggered events. */
641 654
642 if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) == ACPI_GPE_LEVEL_TRIGGERED) { 655 if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
656 ACPI_GPE_LEVEL_TRIGGERED) {
643 status = acpi_hw_clear_gpe (gpe_event_info); 657 status = acpi_hw_clear_gpe (gpe_event_info);
644 if (ACPI_FAILURE (status)) { 658 if (ACPI_FAILURE (status)) {
645 ACPI_REPORT_ERROR (( 659 ACPI_REPORT_ERROR ((
@@ -704,7 +718,6 @@ acpi_ev_gpe_dispatch (
704 718
705 719
706#ifdef ACPI_GPE_NOTIFY_CHECK 720#ifdef ACPI_GPE_NOTIFY_CHECK
707
708/******************************************************************************* 721/*******************************************************************************
709 * TBD: NOT USED, PROTOTYPE ONLY AND WILL PROBABLY BE REMOVED 722 * TBD: NOT USED, PROTOTYPE ONLY AND WILL PROBABLY BE REMOVED
710 * 723 *
diff --git a/drivers/acpi/events/evgpeblk.c b/drivers/acpi/events/evgpeblk.c
index 00d981f53c6a..84186a7d17b2 100644
--- a/drivers/acpi/events/evgpeblk.c
+++ b/drivers/acpi/events/evgpeblk.c
@@ -48,6 +48,39 @@
48#define _COMPONENT ACPI_EVENTS 48#define _COMPONENT ACPI_EVENTS
49 ACPI_MODULE_NAME ("evgpeblk") 49 ACPI_MODULE_NAME ("evgpeblk")
50 50
51/* Local prototypes */
52
53static acpi_status
54acpi_ev_save_method_info (
55 acpi_handle obj_handle,
56 u32 level,
57 void *obj_desc,
58 void **return_value);
59
60static acpi_status
61acpi_ev_match_prw_and_gpe (
62 acpi_handle obj_handle,
63 u32 level,
64 void *info,
65 void **return_value);
66
67static struct acpi_gpe_xrupt_info *
68acpi_ev_get_gpe_xrupt_block (
69 u32 interrupt_level);
70
71static acpi_status
72acpi_ev_delete_gpe_xrupt (
73 struct acpi_gpe_xrupt_info *gpe_xrupt);
74
75static acpi_status
76acpi_ev_install_gpe_block (
77 struct acpi_gpe_block_info *gpe_block,
78 u32 interrupt_level);
79
80static acpi_status
81acpi_ev_create_gpe_info_blocks (
82 struct acpi_gpe_block_info *gpe_block);
83
51 84
52/******************************************************************************* 85/*******************************************************************************
53 * 86 *
@@ -155,7 +188,7 @@ unlock_and_exit:
155} 188}
156 189
157 190
158/****************************************************************************** 191/*******************************************************************************
159 * 192 *
160 * FUNCTION: acpi_ev_delete_gpe_handlers 193 * FUNCTION: acpi_ev_delete_gpe_handlers
161 * 194 *
@@ -190,7 +223,8 @@ acpi_ev_delete_gpe_handlers (
190 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) { 223 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
191 gpe_event_info = &gpe_block->event_info[(i * ACPI_GPE_REGISTER_WIDTH) + j]; 224 gpe_event_info = &gpe_block->event_info[(i * ACPI_GPE_REGISTER_WIDTH) + j];
192 225
193 if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) == ACPI_GPE_DISPATCH_HANDLER) { 226 if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
227 ACPI_GPE_DISPATCH_HANDLER) {
194 ACPI_MEM_FREE (gpe_event_info->dispatch.handler); 228 ACPI_MEM_FREE (gpe_event_info->dispatch.handler);
195 gpe_event_info->dispatch.handler = NULL; 229 gpe_event_info->dispatch.handler = NULL;
196 gpe_event_info->flags &= ~ACPI_GPE_DISPATCH_MASK; 230 gpe_event_info->flags &= ~ACPI_GPE_DISPATCH_MASK;
@@ -471,7 +505,7 @@ acpi_ev_get_gpe_xrupt_block (
471 ACPI_FUNCTION_TRACE ("ev_get_gpe_xrupt_block"); 505 ACPI_FUNCTION_TRACE ("ev_get_gpe_xrupt_block");
472 506
473 507
474 /* No need for spin lock since we are not changing any list elements here */ 508 /* No need for lock since we are not changing any list elements here */
475 509
476 next_gpe_xrupt = acpi_gbl_gpe_xrupt_list_head; 510 next_gpe_xrupt = acpi_gbl_gpe_xrupt_list_head;
477 while (next_gpe_xrupt) { 511 while (next_gpe_xrupt) {
@@ -619,7 +653,7 @@ acpi_ev_install_gpe_block (
619 goto unlock_and_exit; 653 goto unlock_and_exit;
620 } 654 }
621 655
622 /* Install the new block at the end of the list for this interrupt with lock */ 656 /* Install the new block at the end of the list with lock */
623 657
624 acpi_os_acquire_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR); 658 acpi_os_acquire_lock (acpi_gbl_gpe_lock, ACPI_NOT_ISR);
625 if (gpe_xrupt_block->gpe_block_list_head) { 659 if (gpe_xrupt_block->gpe_block_list_head) {
@@ -756,10 +790,12 @@ acpi_ev_create_gpe_info_blocks (
756 * per register. Initialization to zeros is sufficient. 790 * per register. Initialization to zeros is sufficient.
757 */ 791 */
758 gpe_event_info = ACPI_MEM_CALLOCATE ( 792 gpe_event_info = ACPI_MEM_CALLOCATE (
759 ((acpi_size) gpe_block->register_count * ACPI_GPE_REGISTER_WIDTH) * 793 ((acpi_size) gpe_block->register_count *
794 ACPI_GPE_REGISTER_WIDTH) *
760 sizeof (struct acpi_gpe_event_info)); 795 sizeof (struct acpi_gpe_event_info));
761 if (!gpe_event_info) { 796 if (!gpe_event_info) {
762 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not allocate the gpe_event_info table\n")); 797 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
798 "Could not allocate the gpe_event_info table\n"));
763 status = AE_NO_MEMORY; 799 status = AE_NO_MEMORY;
764 goto error_exit; 800 goto error_exit;
765 } 801 }
@@ -899,7 +935,8 @@ acpi_ev_create_gpe_block (
899 gpe_block->block_base_number = gpe_block_base_number; 935 gpe_block->block_base_number = gpe_block_base_number;
900 gpe_block->node = gpe_device; 936 gpe_block->node = gpe_device;
901 937
902 ACPI_MEMCPY (&gpe_block->block_address, gpe_block_address, sizeof (struct acpi_generic_address)); 938 ACPI_MEMCPY (&gpe_block->block_address, gpe_block_address,
939 sizeof (struct acpi_generic_address));
903 940
904 /* Create the register_info and event_info sub-structures */ 941 /* Create the register_info and event_info sub-structures */
905 942
@@ -1061,8 +1098,9 @@ acpi_ev_gpe_initialize (
1061 1098
1062 /* Install GPE Block 0 */ 1099 /* Install GPE Block 0 */
1063 1100
1064 status = acpi_ev_create_gpe_block (acpi_gbl_fadt_gpe_device, &acpi_gbl_FADT->xgpe0_blk, 1101 status = acpi_ev_create_gpe_block (acpi_gbl_fadt_gpe_device,
1065 register_count0, 0, acpi_gbl_FADT->sci_int, &acpi_gbl_gpe_fadt_blocks[0]); 1102 &acpi_gbl_FADT->xgpe0_blk, register_count0, 0,
1103 acpi_gbl_FADT->sci_int, &acpi_gbl_gpe_fadt_blocks[0]);
1066 1104
1067 if (ACPI_FAILURE (status)) { 1105 if (ACPI_FAILURE (status)) {
1068 ACPI_REPORT_ERROR (( 1106 ACPI_REPORT_ERROR ((
@@ -1094,8 +1132,9 @@ acpi_ev_gpe_initialize (
1094 else { 1132 else {
1095 /* Install GPE Block 1 */ 1133 /* Install GPE Block 1 */
1096 1134
1097 status = acpi_ev_create_gpe_block (acpi_gbl_fadt_gpe_device, &acpi_gbl_FADT->xgpe1_blk, 1135 status = acpi_ev_create_gpe_block (acpi_gbl_fadt_gpe_device,
1098 register_count1, acpi_gbl_FADT->gpe1_base, 1136 &acpi_gbl_FADT->xgpe1_blk, register_count1,
1137 acpi_gbl_FADT->gpe1_base,
1099 acpi_gbl_FADT->sci_int, &acpi_gbl_gpe_fadt_blocks[1]); 1138 acpi_gbl_FADT->sci_int, &acpi_gbl_gpe_fadt_blocks[1]);
1100 1139
1101 if (ACPI_FAILURE (status)) { 1140 if (ACPI_FAILURE (status)) {
@@ -1109,7 +1148,7 @@ acpi_ev_gpe_initialize (
1109 * space. However, GPE0 always starts at GPE number zero. 1148 * space. However, GPE0 always starts at GPE number zero.
1110 */ 1149 */
1111 gpe_number_max = acpi_gbl_FADT->gpe1_base + 1150 gpe_number_max = acpi_gbl_FADT->gpe1_base +
1112 ((register_count1 * ACPI_GPE_REGISTER_WIDTH) - 1); 1151 ((register_count1 * ACPI_GPE_REGISTER_WIDTH) - 1);
1113 } 1152 }
1114 } 1153 }
1115 1154
diff --git a/drivers/acpi/events/evmisc.c b/drivers/acpi/events/evmisc.c
index 2548efa7a45f..659e90956112 100644
--- a/drivers/acpi/events/evmisc.c
+++ b/drivers/acpi/events/evmisc.c
@@ -50,6 +50,35 @@
50 ACPI_MODULE_NAME ("evmisc") 50 ACPI_MODULE_NAME ("evmisc")
51 51
52 52
53#ifdef ACPI_DEBUG_OUTPUT
54static const char *acpi_notify_value_names[] =
55{
56 "Bus Check",
57 "Device Check",
58 "Device Wake",
59 "Eject request",
60 "Device Check Light",
61 "Frequency Mismatch",
62 "Bus Mode Mismatch",
63 "Power Fault"
64};
65#endif
66
67/* Local prototypes */
68
69static void ACPI_SYSTEM_XFACE
70acpi_ev_notify_dispatch (
71 void *context);
72
73static void ACPI_SYSTEM_XFACE
74acpi_ev_global_lock_thread (
75 void *context);
76
77static u32
78acpi_ev_global_lock_handler (
79 void *context);
80
81
53/******************************************************************************* 82/*******************************************************************************
54 * 83 *
55 * FUNCTION: acpi_ev_is_notify_object 84 * FUNCTION: acpi_ev_is_notify_object
@@ -98,20 +127,6 @@ acpi_ev_is_notify_object (
98 * 127 *
99 ******************************************************************************/ 128 ******************************************************************************/
100 129
101#ifdef ACPI_DEBUG_OUTPUT
102static const char *acpi_notify_value_names[] =
103{
104 "Bus Check",
105 "Device Check",
106 "Device Wake",
107 "Eject request",
108 "Device Check Light",
109 "Frequency Mismatch",
110 "Bus Mode Mismatch",
111 "Power Fault"
112};
113#endif
114
115acpi_status 130acpi_status
116acpi_ev_queue_notify_request ( 131acpi_ev_queue_notify_request (
117 struct acpi_namespace_node *node, 132 struct acpi_namespace_node *node,
@@ -128,9 +143,10 @@ acpi_ev_queue_notify_request (
128 143
129 /* 144 /*
130 * For value 3 (Ejection Request), some device method may need to be run. 145 * For value 3 (Ejection Request), some device method may need to be run.
131 * For value 2 (Device Wake) if _PRW exists, the _PS0 method may need to be run. 146 * For value 2 (Device Wake) if _PRW exists, the _PS0 method may need
147 * to be run.
132 * For value 0x80 (Status Change) on the power button or sleep button, 148 * For value 0x80 (Status Change) on the power button or sleep button,
133 * initiate soft-off or sleep operation? 149 * initiate soft-off or sleep operation?
134 */ 150 */
135 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, 151 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
136 "Dispatching Notify(%X) on node %p\n", notify_value, node)); 152 "Dispatching Notify(%X) on node %p\n", notify_value, node));
@@ -140,8 +156,9 @@ acpi_ev_queue_notify_request (
140 acpi_notify_value_names[notify_value])); 156 acpi_notify_value_names[notify_value]));
141 } 157 }
142 else { 158 else {
143 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Notify value: 0x%2.2X **Device Specific**\n", 159 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
144 notify_value)); 160 "Notify value: 0x%2.2X **Device Specific**\n",
161 notify_value));
145 } 162 }
146 163
147 /* Get the notify object attached to the NS Node */ 164 /* Get the notify object attached to the NS Node */
@@ -210,7 +227,7 @@ acpi_ev_queue_notify_request (
210 * 227 *
211 * FUNCTION: acpi_ev_notify_dispatch 228 * FUNCTION: acpi_ev_notify_dispatch
212 * 229 *
213 * PARAMETERS: Context - To be passsed to the notify handler 230 * PARAMETERS: Context - To be passed to the notify handler
214 * 231 *
215 * RETURN: None. 232 * RETURN: None.
216 * 233 *
@@ -219,7 +236,7 @@ acpi_ev_queue_notify_request (
219 * 236 *
220 ******************************************************************************/ 237 ******************************************************************************/
221 238
222void ACPI_SYSTEM_XFACE 239static void ACPI_SYSTEM_XFACE
223acpi_ev_notify_dispatch ( 240acpi_ev_notify_dispatch (
224 void *context) 241 void *context)
225{ 242{
@@ -234,7 +251,8 @@ acpi_ev_notify_dispatch (
234 251
235 /* 252 /*
236 * We will invoke a global notify handler if installed. 253 * We will invoke a global notify handler if installed.
237 * This is done _before_ we invoke the per-device handler attached to the device. 254 * This is done _before_ we invoke the per-device handler attached
255 * to the device.
238 */ 256 */
239 if (notify_info->notify.value <= ACPI_MAX_SYS_NOTIFY) { 257 if (notify_info->notify.value <= ACPI_MAX_SYS_NOTIFY) {
240 /* Global system notification handler */ 258 /* Global system notification handler */
@@ -256,15 +274,17 @@ acpi_ev_notify_dispatch (
256 /* Invoke the system handler first, if present */ 274 /* Invoke the system handler first, if present */
257 275
258 if (global_handler) { 276 if (global_handler) {
259 global_handler (notify_info->notify.node, notify_info->notify.value, global_context); 277 global_handler (notify_info->notify.node, notify_info->notify.value,
278 global_context);
260 } 279 }
261 280
262 /* Now invoke the per-device handler, if present */ 281 /* Now invoke the per-device handler, if present */
263 282
264 handler_obj = notify_info->notify.handler_obj; 283 handler_obj = notify_info->notify.handler_obj;
265 if (handler_obj) { 284 if (handler_obj) {
266 handler_obj->notify.handler (notify_info->notify.node, notify_info->notify.value, 285 handler_obj->notify.handler (notify_info->notify.node,
267 handler_obj->notify.context); 286 notify_info->notify.value,
287 handler_obj->notify.context);
268 } 288 }
269 289
270 /* All done with the info object */ 290 /* All done with the info object */
@@ -370,7 +390,8 @@ acpi_ev_global_lock_handler (
370 ******************************************************************************/ 390 ******************************************************************************/
371 391
372acpi_status 392acpi_status
373acpi_ev_init_global_lock_handler (void) 393acpi_ev_init_global_lock_handler (
394 void)
374{ 395{
375 acpi_status status; 396 acpi_status status;
376 397
@@ -380,7 +401,7 @@ acpi_ev_init_global_lock_handler (void)
380 401
381 acpi_gbl_global_lock_present = TRUE; 402 acpi_gbl_global_lock_present = TRUE;
382 status = acpi_install_fixed_event_handler (ACPI_EVENT_GLOBAL, 403 status = acpi_install_fixed_event_handler (ACPI_EVENT_GLOBAL,
383 acpi_ev_global_lock_handler, NULL); 404 acpi_ev_global_lock_handler, NULL);
384 405
385 /* 406 /*
386 * If the global lock does not exist on this platform, the attempt 407 * If the global lock does not exist on this platform, the attempt
@@ -433,8 +454,10 @@ acpi_ev_acquire_global_lock (
433 454
434 acpi_gbl_global_lock_thread_count++; 455 acpi_gbl_global_lock_thread_count++;
435 456
436 /* If we (OS side vs. BIOS side) have the hardware lock already, we are done */ 457 /*
437 458 * If we (OS side vs. BIOS side) have the hardware lock already,
459 * we are done
460 */
438 if (acpi_gbl_global_lock_acquired) { 461 if (acpi_gbl_global_lock_acquired) {
439 return_ACPI_STATUS (AE_OK); 462 return_ACPI_STATUS (AE_OK);
440 } 463 }
@@ -480,7 +503,8 @@ acpi_ev_acquire_global_lock (
480 ******************************************************************************/ 503 ******************************************************************************/
481 504
482acpi_status 505acpi_status
483acpi_ev_release_global_lock (void) 506acpi_ev_release_global_lock (
507 void)
484{ 508{
485 u8 pending = FALSE; 509 u8 pending = FALSE;
486 acpi_status status = AE_OK; 510 acpi_status status = AE_OK;
@@ -490,7 +514,8 @@ acpi_ev_release_global_lock (void)
490 514
491 515
492 if (!acpi_gbl_global_lock_thread_count) { 516 if (!acpi_gbl_global_lock_thread_count) {
493 ACPI_REPORT_WARNING(("Cannot release HW Global Lock, it has not been acquired\n")); 517 ACPI_REPORT_WARNING((
518 "Cannot release HW Global Lock, it has not been acquired\n"));
494 return_ACPI_STATUS (AE_NOT_ACQUIRED); 519 return_ACPI_STATUS (AE_NOT_ACQUIRED);
495 } 520 }
496 521
@@ -515,7 +540,8 @@ acpi_ev_release_global_lock (void)
515 * register 540 * register
516 */ 541 */
517 if (pending) { 542 if (pending) {
518 status = acpi_set_register (ACPI_BITREG_GLOBAL_LOCK_RELEASE, 1, ACPI_MTX_LOCK); 543 status = acpi_set_register (ACPI_BITREG_GLOBAL_LOCK_RELEASE,
544 1, ACPI_MTX_LOCK);
519 } 545 }
520 546
521 return_ACPI_STATUS (status); 547 return_ACPI_STATUS (status);
@@ -535,7 +561,8 @@ acpi_ev_release_global_lock (void)
535 ******************************************************************************/ 561 ******************************************************************************/
536 562
537void 563void
538acpi_ev_terminate (void) 564acpi_ev_terminate (
565 void)
539{ 566{
540 acpi_native_uint i; 567 acpi_native_uint i;
541 acpi_status status; 568 acpi_status status;
@@ -555,7 +582,8 @@ acpi_ev_terminate (void)
555 for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) { 582 for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) {
556 status = acpi_disable_event ((u32) i, 0); 583 status = acpi_disable_event ((u32) i, 0);
557 if (ACPI_FAILURE (status)) { 584 if (ACPI_FAILURE (status)) {
558 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not disable fixed event %d\n", (u32) i)); 585 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
586 "Could not disable fixed event %d\n", (u32) i));
559 } 587 }
560 } 588 }
561 589
@@ -567,7 +595,8 @@ acpi_ev_terminate (void)
567 595
568 status = acpi_ev_remove_sci_handler (); 596 status = acpi_ev_remove_sci_handler ();
569 if (ACPI_FAILURE(status)) { 597 if (ACPI_FAILURE(status)) {
570 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not remove SCI handler\n")); 598 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
599 "Could not remove SCI handler\n"));
571 } 600 }
572 } 601 }
573 602
diff --git a/drivers/acpi/events/evregion.c b/drivers/acpi/events/evregion.c
index 772342708a7a..a1d7276c5742 100644
--- a/drivers/acpi/events/evregion.c
+++ b/drivers/acpi/events/evregion.c
@@ -58,6 +58,22 @@ static u8 acpi_gbl_default_address_spaces[ACPI_NUM_DEFAULT_SPA
58 ACPI_ADR_SPACE_PCI_CONFIG, 58 ACPI_ADR_SPACE_PCI_CONFIG,
59 ACPI_ADR_SPACE_DATA_TABLE}; 59 ACPI_ADR_SPACE_DATA_TABLE};
60 60
61/* Local prototypes */
62
63static acpi_status
64acpi_ev_reg_run (
65 acpi_handle obj_handle,
66 u32 level,
67 void *context,
68 void **return_value);
69
70static acpi_status
71acpi_ev_install_handler (
72 acpi_handle obj_handle,
73 u32 level,
74 void *context,
75 void **return_value);
76
61 77
62/******************************************************************************* 78/*******************************************************************************
63 * 79 *
@@ -179,8 +195,8 @@ acpi_ev_initialize_op_regions (
179 * 195 *
180 * FUNCTION: acpi_ev_execute_reg_method 196 * FUNCTION: acpi_ev_execute_reg_method
181 * 197 *
182 * PARAMETERS: region_obj - Object structure 198 * PARAMETERS: region_obj - Region object
183 * Function - Passed to _REG: On (1) or Off (0) 199 * Function - Passed to _REG: On (1) or Off (0)
184 * 200 *
185 * RETURN: Status 201 * RETURN: Status
186 * 202 *
@@ -323,14 +339,16 @@ acpi_ev_address_space_dispatch (
323 if (!region_setup) { 339 if (!region_setup) {
324 /* No initialization routine, exit with error */ 340 /* No initialization routine, exit with error */
325 341
326 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No init routine for region(%p) [%s]\n", 342 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
343 "No init routine for region(%p) [%s]\n",
327 region_obj, acpi_ut_get_region_name (region_obj->region.space_id))); 344 region_obj, acpi_ut_get_region_name (region_obj->region.space_id)));
328 return_ACPI_STATUS (AE_NOT_EXIST); 345 return_ACPI_STATUS (AE_NOT_EXIST);
329 } 346 }
330 347
331 /* 348 /*
332 * We must exit the interpreter because the region setup will potentially 349 * We must exit the interpreter because the region
333 * execute control methods (e.g., _REG method for this region) 350 * setup will potentially execute control methods
351 * (e.g., _REG method for this region)
334 */ 352 */
335 acpi_ex_exit_interpreter (); 353 acpi_ex_exit_interpreter ();
336 354
@@ -621,7 +639,7 @@ acpi_ev_attach_region (
621 * 639 *
622 ******************************************************************************/ 640 ******************************************************************************/
623 641
624acpi_status 642static acpi_status
625acpi_ev_install_handler ( 643acpi_ev_install_handler (
626 acpi_handle obj_handle, 644 acpi_handle obj_handle,
627 u32 level, 645 u32 level,
@@ -848,7 +866,8 @@ acpi_ev_install_space_handler (
848 if (handler_obj->address_space.handler == handler) { 866 if (handler_obj->address_space.handler == handler) {
849 /* 867 /*
850 * It is (relatively) OK to attempt to install the SAME 868 * It is (relatively) OK to attempt to install the SAME
851 * handler twice. This can easily happen with PCI_Config space. 869 * handler twice. This can easily happen
870 * with PCI_Config space.
852 */ 871 */
853 status = AE_SAME_HANDLER; 872 status = AE_SAME_HANDLER;
854 goto unlock_and_exit; 873 goto unlock_and_exit;
@@ -1011,7 +1030,7 @@ acpi_ev_execute_reg_methods (
1011 * 1030 *
1012 ******************************************************************************/ 1031 ******************************************************************************/
1013 1032
1014acpi_status 1033static acpi_status
1015acpi_ev_reg_run ( 1034acpi_ev_reg_run (
1016 acpi_handle obj_handle, 1035 acpi_handle obj_handle,
1017 u32 level, 1036 u32 level,
diff --git a/drivers/acpi/events/evrgnini.c b/drivers/acpi/events/evrgnini.c
index 4983a3378be5..95bc09c73a6a 100644
--- a/drivers/acpi/events/evrgnini.c
+++ b/drivers/acpi/events/evrgnini.c
@@ -61,7 +61,7 @@
61 * 61 *
62 * RETURN: Status 62 * RETURN: Status
63 * 63 *
64 * DESCRIPTION: Do any prep work for region handling, a nop for now 64 * DESCRIPTION: Setup a system_memory operation region
65 * 65 *
66 ******************************************************************************/ 66 ******************************************************************************/
67 67
@@ -115,7 +115,7 @@ acpi_ev_system_memory_region_setup (
115 * 115 *
116 * RETURN: Status 116 * RETURN: Status
117 * 117 *
118 * DESCRIPTION: Do any prep work for region handling 118 * DESCRIPTION: Setup a IO operation region
119 * 119 *
120 ******************************************************************************/ 120 ******************************************************************************/
121 121
@@ -144,14 +144,14 @@ acpi_ev_io_space_region_setup (
144 * 144 *
145 * FUNCTION: acpi_ev_pci_config_region_setup 145 * FUNCTION: acpi_ev_pci_config_region_setup
146 * 146 *
147 * PARAMETERS: Handle - Region we are interested in 147 * PARAMETERS: Handle - Region we are interested in
148 * Function - Start or stop 148 * Function - Start or stop
149 * handler_context - Address space handler context 149 * handler_context - Address space handler context
150 * region_context - Region specific context 150 * region_context - Region specific context
151 * 151 *
152 * RETURN: Status 152 * RETURN: Status
153 * 153 *
154 * DESCRIPTION: Do any prep work for region handling 154 * DESCRIPTION: Setup a PCI_Config operation region
155 * 155 *
156 * MUTEX: Assumes namespace is not locked 156 * MUTEX: Assumes namespace is not locked
157 * 157 *
@@ -324,7 +324,7 @@ acpi_ev_pci_config_region_setup (
324 * 324 *
325 * RETURN: Status 325 * RETURN: Status
326 * 326 *
327 * DESCRIPTION: Do any prep work for region handling 327 * DESCRIPTION: Setup a pci_bAR operation region
328 * 328 *
329 * MUTEX: Assumes namespace is not locked 329 * MUTEX: Assumes namespace is not locked
330 * 330 *
@@ -355,7 +355,7 @@ acpi_ev_pci_bar_region_setup (
355 * 355 *
356 * RETURN: Status 356 * RETURN: Status
357 * 357 *
358 * DESCRIPTION: Do any prep work for region handling 358 * DESCRIPTION: Setup a CMOS operation region
359 * 359 *
360 * MUTEX: Assumes namespace is not locked 360 * MUTEX: Assumes namespace is not locked
361 * 361 *
@@ -386,7 +386,7 @@ acpi_ev_cmos_region_setup (
386 * 386 *
387 * RETURN: Status 387 * RETURN: Status
388 * 388 *
389 * DESCRIPTION: Do any prep work for region handling 389 * DESCRIPTION: Default region initialization
390 * 390 *
391 ******************************************************************************/ 391 ******************************************************************************/
392 392
diff --git a/drivers/acpi/events/evsci.c b/drivers/acpi/events/evsci.c
index 46b31995c827..f3123c26ae98 100644
--- a/drivers/acpi/events/evsci.c
+++ b/drivers/acpi/events/evsci.c
@@ -49,6 +49,12 @@
49#define _COMPONENT ACPI_EVENTS 49#define _COMPONENT ACPI_EVENTS
50 ACPI_MODULE_NAME ("evsci") 50 ACPI_MODULE_NAME ("evsci")
51 51
52/* Local prototypes */
53
54static u32 ACPI_SYSTEM_XFACE
55acpi_ev_sci_xrupt_handler (
56 void *context);
57
52 58
53/******************************************************************************* 59/*******************************************************************************
54 * 60 *
@@ -146,7 +152,8 @@ acpi_ev_gpe_xrupt_handler (
146 ******************************************************************************/ 152 ******************************************************************************/
147 153
148u32 154u32
149acpi_ev_install_sci_handler (void) 155acpi_ev_install_sci_handler (
156 void)
150{ 157{
151 u32 status = AE_OK; 158 u32 status = AE_OK;
152 159
@@ -180,7 +187,8 @@ acpi_ev_install_sci_handler (void)
180 ******************************************************************************/ 187 ******************************************************************************/
181 188
182acpi_status 189acpi_status
183acpi_ev_remove_sci_handler (void) 190acpi_ev_remove_sci_handler (
191 void)
184{ 192{
185 acpi_status status; 193 acpi_status status;
186 194
diff --git a/drivers/acpi/events/evxface.c b/drivers/acpi/events/evxface.c
index 0bfec10a5f1e..4092d47f6758 100644
--- a/drivers/acpi/events/evxface.c
+++ b/drivers/acpi/events/evxface.c
@@ -64,6 +64,7 @@
64 * DESCRIPTION: Saves the pointer to the handler function 64 * DESCRIPTION: Saves the pointer to the handler function
65 * 65 *
66 ******************************************************************************/ 66 ******************************************************************************/
67
67#ifdef ACPI_FUTURE_USAGE 68#ifdef ACPI_FUTURE_USAGE
68acpi_status 69acpi_status
69acpi_install_exception_handler ( 70acpi_install_exception_handler (
@@ -457,7 +458,8 @@ acpi_remove_notify_handler (
457 /* Root Object */ 458 /* Root Object */
458 459
459 if (device == ACPI_ROOT_OBJECT) { 460 if (device == ACPI_ROOT_OBJECT) {
460 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Removing notify handler for ROOT object.\n")); 461 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
462 "Removing notify handler for ROOT object.\n"));
461 463
462 if (((handler_type & ACPI_SYSTEM_NOTIFY) && 464 if (((handler_type & ACPI_SYSTEM_NOTIFY) &&
463 !acpi_gbl_system_notify.handler) || 465 !acpi_gbl_system_notify.handler) ||
@@ -564,8 +566,9 @@ EXPORT_SYMBOL(acpi_remove_notify_handler);
564 * 566 *
565 * FUNCTION: acpi_install_gpe_handler 567 * FUNCTION: acpi_install_gpe_handler
566 * 568 *
567 * PARAMETERS: gpe_number - The GPE number within the GPE block 569 * PARAMETERS: gpe_device - Namespace node for the GPE (NULL for FADT
568 * gpe_block - GPE block (NULL == FADT GPEs) 570 * defined GPEs)
571 * gpe_number - The GPE number within the GPE block
569 * Type - Whether this GPE should be treated as an 572 * Type - Whether this GPE should be treated as an
570 * edge- or level-triggered interrupt. 573 * edge- or level-triggered interrupt.
571 * Address - Address of the handler 574 * Address - Address of the handler
@@ -662,8 +665,9 @@ EXPORT_SYMBOL(acpi_install_gpe_handler);
662 * 665 *
663 * FUNCTION: acpi_remove_gpe_handler 666 * FUNCTION: acpi_remove_gpe_handler
664 * 667 *
665 * PARAMETERS: gpe_number - The event to remove a handler 668 * PARAMETERS: gpe_device - Namespace node for the GPE (NULL for FADT
666 * gpe_block - GPE block (NULL == FADT GPEs) 669 * defined GPEs)
670 * gpe_number - The event to remove a handler
667 * Address - Address of the handler 671 * Address - Address of the handler
668 * 672 *
669 * RETURN: Status 673 * RETURN: Status
@@ -766,7 +770,8 @@ EXPORT_SYMBOL(acpi_remove_gpe_handler);
766 * FUNCTION: acpi_acquire_global_lock 770 * FUNCTION: acpi_acquire_global_lock
767 * 771 *
768 * PARAMETERS: Timeout - How long the caller is willing to wait 772 * PARAMETERS: Timeout - How long the caller is willing to wait
769 * out_handle - A handle to the lock if acquired 773 * Handle - Where the handle to the lock is returned
774 * (if acquired)
770 * 775 *
771 * RETURN: Status 776 * RETURN: Status
772 * 777 *
@@ -812,7 +817,7 @@ EXPORT_SYMBOL(acpi_acquire_global_lock);
812 * 817 *
813 * RETURN: Status 818 * RETURN: Status
814 * 819 *
815 * DESCRIPTION: Release the ACPI Global Lock 820 * DESCRIPTION: Release the ACPI Global Lock. The handle must be valid.
816 * 821 *
817 ******************************************************************************/ 822 ******************************************************************************/
818 823
diff --git a/drivers/acpi/events/evxfevnt.c b/drivers/acpi/events/evxfevnt.c
index fa8d5f25be62..f337dc2cc569 100644
--- a/drivers/acpi/events/evxfevnt.c
+++ b/drivers/acpi/events/evxfevnt.c
@@ -64,7 +64,8 @@
64 ******************************************************************************/ 64 ******************************************************************************/
65 65
66acpi_status 66acpi_status
67acpi_enable (void) 67acpi_enable (
68 void)
68{ 69{
69 acpi_status status = AE_OK; 70 acpi_status status = AE_OK;
70 71
@@ -91,7 +92,8 @@ acpi_enable (void)
91 return_ACPI_STATUS (status); 92 return_ACPI_STATUS (status);
92 } 93 }
93 94
94 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "Transition to ACPI mode successful\n")); 95 ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
96 "Transition to ACPI mode successful\n"));
95 } 97 }
96 98
97 return_ACPI_STATUS (status); 99 return_ACPI_STATUS (status);
@@ -106,12 +108,13 @@ acpi_enable (void)
106 * 108 *
107 * RETURN: Status 109 * RETURN: Status
108 * 110 *
109 * DESCRIPTION: Transfers the system into LEGACY mode. 111 * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
110 * 112 *
111 ******************************************************************************/ 113 ******************************************************************************/
112 114
113acpi_status 115acpi_status
114acpi_disable (void) 116acpi_disable (
117 void)
115{ 118{
116 acpi_status status = AE_OK; 119 acpi_status status = AE_OK;
117 120
@@ -125,7 +128,8 @@ acpi_disable (void)
125 } 128 }
126 129
127 if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) { 130 if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {
128 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "System is already in legacy (non-ACPI) mode\n")); 131 ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
132 "System is already in legacy (non-ACPI) mode\n"));
129 } 133 }
130 else { 134 else {
131 /* Transition to LEGACY mode */ 135 /* Transition to LEGACY mode */
@@ -133,7 +137,8 @@ acpi_disable (void)
133 status = acpi_hw_set_mode (ACPI_SYS_MODE_LEGACY); 137 status = acpi_hw_set_mode (ACPI_SYS_MODE_LEGACY);
134 138
135 if (ACPI_FAILURE (status)) { 139 if (ACPI_FAILURE (status)) {
136 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not exit ACPI mode to legacy mode")); 140 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
141 "Could not exit ACPI mode to legacy mode"));
137 return_ACPI_STATUS (status); 142 return_ACPI_STATUS (status);
138 } 143 }
139 144
@@ -214,7 +219,7 @@ EXPORT_SYMBOL(acpi_enable_event);
214 * 219 *
215 * RETURN: Status 220 * RETURN: Status
216 * 221 *
217 * DESCRIPTION: Enable an ACPI event (general purpose) 222 * DESCRIPTION: Set the type of an individual GPE
218 * 223 *
219 ******************************************************************************/ 224 ******************************************************************************/
220 225
@@ -519,13 +524,12 @@ unlock_and_exit:
519 524
520 525
521#ifdef ACPI_FUTURE_USAGE 526#ifdef ACPI_FUTURE_USAGE
522
523/******************************************************************************* 527/*******************************************************************************
524 * 528 *
525 * FUNCTION: acpi_get_event_status 529 * FUNCTION: acpi_get_event_status
526 * 530 *
527 * PARAMETERS: Event - The fixed event 531 * PARAMETERS: Event - The fixed event
528 * Event Status - Where the current status of the event will 532 * event_status - Where the current status of the event will
529 * be returned 533 * be returned
530 * 534 *
531 * RETURN: Status 535 * RETURN: Status
@@ -571,7 +575,7 @@ acpi_get_event_status (
571 * PARAMETERS: gpe_device - Parent GPE Device 575 * PARAMETERS: gpe_device - Parent GPE Device
572 * gpe_number - GPE level within the GPE block 576 * gpe_number - GPE level within the GPE block
573 * Flags - Called from an ISR or not 577 * Flags - Called from an ISR or not
574 * Event Status - Where the current status of the event will 578 * event_status - Where the current status of the event will
575 * be returned 579 * be returned
576 * 580 *
577 * RETURN: Status 581 * RETURN: Status
@@ -775,4 +779,5 @@ unlock_and_exit:
775 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE); 779 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
776 return_ACPI_STATUS (status); 780 return_ACPI_STATUS (status);
777} 781}
782
778EXPORT_SYMBOL(acpi_remove_gpe_block); 783EXPORT_SYMBOL(acpi_remove_gpe_block);
diff --git a/drivers/acpi/executer/exconfig.c b/drivers/acpi/executer/exconfig.c
index ac3c061967f2..734b2f24af48 100644
--- a/drivers/acpi/executer/exconfig.c
+++ b/drivers/acpi/executer/exconfig.c
@@ -54,6 +54,14 @@
54#define _COMPONENT ACPI_EXECUTER 54#define _COMPONENT ACPI_EXECUTER
55 ACPI_MODULE_NAME ("exconfig") 55 ACPI_MODULE_NAME ("exconfig")
56 56
57/* Local prototypes */
58
59static acpi_status
60acpi_ex_add_table (
61 struct acpi_table_header *table,
62 struct acpi_namespace_node *parent_node,
63 union acpi_operand_object **ddb_handle);
64
57 65
58/******************************************************************************* 66/*******************************************************************************
59 * 67 *
@@ -70,7 +78,7 @@
70 * 78 *
71 ******************************************************************************/ 79 ******************************************************************************/
72 80
73acpi_status 81static acpi_status
74acpi_ex_add_table ( 82acpi_ex_add_table (
75 struct acpi_table_header *table, 83 struct acpi_table_header *table,
76 struct acpi_namespace_node *parent_node, 84 struct acpi_namespace_node *parent_node,
@@ -95,10 +103,10 @@ acpi_ex_add_table (
95 103
96 ACPI_MEMSET (&table_info, 0, sizeof (struct acpi_table_desc)); 104 ACPI_MEMSET (&table_info, 0, sizeof (struct acpi_table_desc));
97 105
98 table_info.type = ACPI_TABLE_SSDT; 106 table_info.type = ACPI_TABLE_SSDT;
99 table_info.pointer = table; 107 table_info.pointer = table;
100 table_info.length = (acpi_size) table->length; 108 table_info.length = (acpi_size) table->length;
101 table_info.allocation = ACPI_MEM_ALLOCATED; 109 table_info.allocation = ACPI_MEM_ALLOCATED;
102 110
103 status = acpi_tb_install_table (&table_info); 111 status = acpi_tb_install_table (&table_info);
104 if (ACPI_FAILURE (status)) { 112 if (ACPI_FAILURE (status)) {
@@ -226,11 +234,10 @@ acpi_ex_load_table_op (
226 start_node = parent_node; 234 start_node = parent_node;
227 } 235 }
228 236
229 /* 237 /* Find the node referenced by the parameter_path_string */
230 * Find the node referenced by the parameter_path_string 238
231 */
232 status = acpi_ns_get_node_by_path (operand[4]->string.pointer, start_node, 239 status = acpi_ns_get_node_by_path (operand[4]->string.pointer, start_node,
233 ACPI_NS_SEARCH_PARENT, &parameter_node); 240 ACPI_NS_SEARCH_PARENT, &parameter_node);
234 if (ACPI_FAILURE (status)) { 241 if (ACPI_FAILURE (status)) {
235 return_ACPI_STATUS (status); 242 return_ACPI_STATUS (status);
236 } 243 }
@@ -248,7 +255,8 @@ acpi_ex_load_table_op (
248 if (parameter_node) { 255 if (parameter_node) {
249 /* Store the parameter data into the optional parameter object */ 256 /* Store the parameter data into the optional parameter object */
250 257
251 status = acpi_ex_store (operand[5], ACPI_CAST_PTR (union acpi_operand_object, parameter_node), 258 status = acpi_ex_store (operand[5],
259 ACPI_CAST_PTR (union acpi_operand_object, parameter_node),
252 walk_state); 260 walk_state);
253 if (ACPI_FAILURE (status)) { 261 if (ACPI_FAILURE (status)) {
254 (void) acpi_ex_unload_table (ddb_handle); 262 (void) acpi_ex_unload_table (ddb_handle);
@@ -371,7 +379,8 @@ acpi_ex_load_op (
371 goto cleanup; 379 goto cleanup;
372 } 380 }
373 381
374 table_ptr = ACPI_CAST_PTR (struct acpi_table_header, buffer_desc->buffer.pointer); 382 table_ptr = ACPI_CAST_PTR (struct acpi_table_header,
383 buffer_desc->buffer.pointer);
375 384
376 /* Sanity check the table length */ 385 /* Sanity check the table length */
377 386
diff --git a/drivers/acpi/executer/exconvrt.c b/drivers/acpi/executer/exconvrt.c
index df7ba1219bf6..97856c48bd74 100644
--- a/drivers/acpi/executer/exconvrt.c
+++ b/drivers/acpi/executer/exconvrt.c
@@ -50,6 +50,15 @@
50#define _COMPONENT ACPI_EXECUTER 50#define _COMPONENT ACPI_EXECUTER
51 ACPI_MODULE_NAME ("exconvrt") 51 ACPI_MODULE_NAME ("exconvrt")
52 52
53/* Local prototypes */
54
55static u32
56acpi_ex_convert_to_ascii (
57 acpi_integer integer,
58 u16 base,
59 u8 *string,
60 u8 max_length);
61
53 62
54/******************************************************************************* 63/*******************************************************************************
55 * 64 *
@@ -115,9 +124,8 @@ acpi_ex_convert_to_integer (
115 */ 124 */
116 result = 0; 125 result = 0;
117 126
118 /* 127 /* String conversion is different than Buffer conversion */
119 * String conversion is different than Buffer conversion 128
120 */
121 switch (ACPI_GET_OBJECT_TYPE (obj_desc)) { 129 switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
122 case ACPI_TYPE_STRING: 130 case ACPI_TYPE_STRING:
123 131
@@ -168,9 +176,8 @@ acpi_ex_convert_to_integer (
168 break; 176 break;
169 } 177 }
170 178
171 /* 179 /* Create a new integer */
172 * Create a new integer 180
173 */
174 return_desc = acpi_ut_create_internal_object (ACPI_TYPE_INTEGER); 181 return_desc = acpi_ut_create_internal_object (ACPI_TYPE_INTEGER);
175 if (!return_desc) { 182 if (!return_desc) {
176 return_ACPI_STATUS (AE_NO_MEMORY); 183 return_ACPI_STATUS (AE_NO_MEMORY);
@@ -251,7 +258,8 @@ acpi_ex_convert_to_buffer (
251 * ASL/AML code that depends on the null being transferred to the new 258 * ASL/AML code that depends on the null being transferred to the new
252 * buffer. 259 * buffer.
253 */ 260 */
254 return_desc = acpi_ut_create_buffer_object ((acpi_size) obj_desc->string.length + 1); 261 return_desc = acpi_ut_create_buffer_object (
262 (acpi_size) obj_desc->string.length + 1);
255 if (!return_desc) { 263 if (!return_desc) {
256 return_ACPI_STATUS (AE_NO_MEMORY); 264 return_ACPI_STATUS (AE_NO_MEMORY);
257 } 265 }
@@ -291,7 +299,7 @@ acpi_ex_convert_to_buffer (
291 * 299 *
292 ******************************************************************************/ 300 ******************************************************************************/
293 301
294u32 302static u32
295acpi_ex_convert_to_ascii ( 303acpi_ex_convert_to_ascii (
296 acpi_integer integer, 304 acpi_integer integer,
297 u16 base, 305 u16 base,
@@ -357,8 +365,9 @@ acpi_ex_convert_to_ascii (
357 365
358 case 16: 366 case 16:
359 367
360 hex_length = ACPI_MUL_2 (data_width); /* 2 ascii hex chars per data byte */ 368 /* hex_length: 2 ascii hex chars per data byte */
361 369
370 hex_length = ACPI_MUL_2 (data_width);
362 for (i = 0, j = (hex_length-1); i < hex_length; i++, j--) { 371 for (i = 0, j = (hex_length-1); i < hex_length; i++, j--) {
363 /* Get one hex digit, most significant digits first */ 372 /* Get one hex digit, most significant digits first */
364 373
@@ -475,7 +484,7 @@ acpi_ex_convert_to_string (
475 /* Setup string length, base, and separator */ 484 /* Setup string length, base, and separator */
476 485
477 switch (type) { 486 switch (type) {
478 case ACPI_EXPLICIT_CONVERT_DECIMAL: /* Used by to_decimal_string operator */ 487 case ACPI_EXPLICIT_CONVERT_DECIMAL: /* Used by to_decimal_string */
479 /* 488 /*
480 * From ACPI: "If Data is a buffer, it is converted to a string of 489 * From ACPI: "If Data is a buffer, it is converted to a string of
481 * decimal values separated by commas." 490 * decimal values separated by commas."
@@ -509,7 +518,7 @@ acpi_ex_convert_to_string (
509 string_length = (obj_desc->buffer.length * 3); 518 string_length = (obj_desc->buffer.length * 3);
510 break; 519 break;
511 520
512 case ACPI_EXPLICIT_CONVERT_HEX: /* Used by to_hex_string operator */ 521 case ACPI_EXPLICIT_CONVERT_HEX: /* Used by to_hex_string */
513 /* 522 /*
514 * From ACPI: "If Data is a buffer, it is converted to a string of 523 * From ACPI: "If Data is a buffer, it is converted to a string of
515 * hexadecimal values separated by commas." 524 * hexadecimal values separated by commas."
@@ -530,9 +539,8 @@ acpi_ex_convert_to_string (
530 return_ACPI_STATUS (AE_AML_STRING_LIMIT); 539 return_ACPI_STATUS (AE_AML_STRING_LIMIT);
531 } 540 }
532 541
533 /* 542 /* Create a new string object and string buffer */
534 * Create a new string object and string buffer 543
535 */
536 return_desc = acpi_ut_create_string_object ((acpi_size) string_length); 544 return_desc = acpi_ut_create_string_object ((acpi_size) string_length);
537 if (!return_desc) { 545 if (!return_desc) {
538 return_ACPI_STATUS (AE_NO_MEMORY); 546 return_ACPI_STATUS (AE_NO_MEMORY);
@@ -551,8 +559,10 @@ acpi_ex_convert_to_string (
551 *new_buf++ = separator; /* each separated by a comma or space */ 559 *new_buf++ = separator; /* each separated by a comma or space */
552 } 560 }
553 561
554 /* Null terminate the string (overwrites final comma/space from above) */ 562 /*
555 563 * Null terminate the string
564 * (overwrites final comma/space from above)
565 */
556 new_buf--; 566 new_buf--;
557 *new_buf = 0; 567 *new_buf = 0;
558 break; 568 break;
@@ -645,7 +655,6 @@ acpi_ex_convert_to_target_type (
645 655
646 656
647 case ACPI_TYPE_STRING: 657 case ACPI_TYPE_STRING:
648
649 /* 658 /*
650 * The operand must be a String. We can convert an 659 * The operand must be a String. We can convert an
651 * Integer or Buffer if necessary 660 * Integer or Buffer if necessary
@@ -656,7 +665,6 @@ acpi_ex_convert_to_target_type (
656 665
657 666
658 case ACPI_TYPE_BUFFER: 667 case ACPI_TYPE_BUFFER:
659
660 /* 668 /*
661 * The operand must be a Buffer. We can convert an 669 * The operand must be a Buffer. We can convert an
662 * Integer or String if necessary 670 * Integer or String if necessary
diff --git a/drivers/acpi/executer/excreate.c b/drivers/acpi/executer/excreate.c
index d94c260dac6d..812cdcb2e370 100644
--- a/drivers/acpi/executer/excreate.c
+++ b/drivers/acpi/executer/excreate.c
@@ -55,7 +55,7 @@
55 55
56 56
57#ifndef ACPI_NO_METHOD_EXECUTION 57#ifndef ACPI_NO_METHOD_EXECUTION
58/***************************************************************************** 58/*******************************************************************************
59 * 59 *
60 * FUNCTION: acpi_ex_create_alias 60 * FUNCTION: acpi_ex_create_alias
61 * 61 *
@@ -65,7 +65,7 @@
65 * 65 *
66 * DESCRIPTION: Create a new named alias 66 * DESCRIPTION: Create a new named alias
67 * 67 *
68 ****************************************************************************/ 68 ******************************************************************************/
69 69
70acpi_status 70acpi_status
71acpi_ex_create_alias ( 71acpi_ex_create_alias (
@@ -140,8 +140,7 @@ acpi_ex_create_alias (
140 * target node or the alias Node 140 * target node or the alias Node
141 */ 141 */
142 status = acpi_ns_attach_object (alias_node, 142 status = acpi_ns_attach_object (alias_node,
143 acpi_ns_get_attached_object (target_node), 143 acpi_ns_get_attached_object (target_node), target_node->type);
144 target_node->type);
145 break; 144 break;
146 } 145 }
147 146
@@ -151,7 +150,7 @@ acpi_ex_create_alias (
151} 150}
152 151
153 152
154/***************************************************************************** 153/*******************************************************************************
155 * 154 *
156 * FUNCTION: acpi_ex_create_event 155 * FUNCTION: acpi_ex_create_event
157 * 156 *
@@ -161,7 +160,7 @@ acpi_ex_create_alias (
161 * 160 *
162 * DESCRIPTION: Create a new event object 161 * DESCRIPTION: Create a new event object
163 * 162 *
164 ****************************************************************************/ 163 ******************************************************************************/
165 164
166acpi_status 165acpi_status
167acpi_ex_create_event ( 166acpi_ex_create_event (
@@ -185,7 +184,7 @@ acpi_ex_create_event (
185 * that the event is created in an unsignalled state 184 * that the event is created in an unsignalled state
186 */ 185 */
187 status = acpi_os_create_semaphore (ACPI_NO_UNIT_LIMIT, 0, 186 status = acpi_os_create_semaphore (ACPI_NO_UNIT_LIMIT, 0,
188 &obj_desc->event.semaphore); 187 &obj_desc->event.semaphore);
189 if (ACPI_FAILURE (status)) { 188 if (ACPI_FAILURE (status)) {
190 goto cleanup; 189 goto cleanup;
191 } 190 }
@@ -193,7 +192,7 @@ acpi_ex_create_event (
193 /* Attach object to the Node */ 192 /* Attach object to the Node */
194 193
195 status = acpi_ns_attach_object ((struct acpi_namespace_node *) walk_state->operands[0], 194 status = acpi_ns_attach_object ((struct acpi_namespace_node *) walk_state->operands[0],
196 obj_desc, ACPI_TYPE_EVENT); 195 obj_desc, ACPI_TYPE_EVENT);
197 196
198cleanup: 197cleanup:
199 /* 198 /*
@@ -205,7 +204,7 @@ cleanup:
205} 204}
206 205
207 206
208/***************************************************************************** 207/*******************************************************************************
209 * 208 *
210 * FUNCTION: acpi_ex_create_mutex 209 * FUNCTION: acpi_ex_create_mutex
211 * 210 *
@@ -217,7 +216,7 @@ cleanup:
217 * 216 *
218 * Mutex (Name[0], sync_level[1]) 217 * Mutex (Name[0], sync_level[1])
219 * 218 *
220 ****************************************************************************/ 219 ******************************************************************************/
221 220
222acpi_status 221acpi_status
223acpi_ex_create_mutex ( 222acpi_ex_create_mutex (
@@ -267,20 +266,20 @@ cleanup:
267} 266}
268 267
269 268
270/***************************************************************************** 269/*******************************************************************************
271 * 270 *
272 * FUNCTION: acpi_ex_create_region 271 * FUNCTION: acpi_ex_create_region
273 * 272 *
274 * PARAMETERS: aml_start - Pointer to the region declaration AML 273 * PARAMETERS: aml_start - Pointer to the region declaration AML
275 * aml_length - Max length of the declaration AML 274 * aml_length - Max length of the declaration AML
276 * Operands - List of operands for the opcode 275 * region_space - space_iD for the region
277 * walk_state - Current state 276 * walk_state - Current state
278 * 277 *
279 * RETURN: Status 278 * RETURN: Status
280 * 279 *
281 * DESCRIPTION: Create a new operation region object 280 * DESCRIPTION: Create a new operation region object
282 * 281 *
283 ****************************************************************************/ 282 ******************************************************************************/
284 283
285acpi_status 284acpi_status
286acpi_ex_create_region ( 285acpi_ex_create_region (
@@ -321,7 +320,7 @@ acpi_ex_create_region (
321 } 320 }
322 321
323 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "Region Type - %s (%X)\n", 322 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "Region Type - %s (%X)\n",
324 acpi_ut_get_region_name (region_space), region_space)); 323 acpi_ut_get_region_name (region_space), region_space));
325 324
326 /* Create the region descriptor */ 325 /* Create the region descriptor */
327 326
@@ -360,7 +359,7 @@ cleanup:
360} 359}
361 360
362 361
363/***************************************************************************** 362/*******************************************************************************
364 * 363 *
365 * FUNCTION: acpi_ex_create_table_region 364 * FUNCTION: acpi_ex_create_table_region
366 * 365 *
@@ -370,7 +369,7 @@ cleanup:
370 * 369 *
371 * DESCRIPTION: Create a new data_table_region object 370 * DESCRIPTION: Create a new data_table_region object
372 * 371 *
373 ****************************************************************************/ 372 ******************************************************************************/
374 373
375acpi_status 374acpi_status
376acpi_ex_create_table_region ( 375acpi_ex_create_table_region (
@@ -455,7 +454,7 @@ cleanup:
455} 454}
456 455
457 456
458/***************************************************************************** 457/*******************************************************************************
459 * 458 *
460 * FUNCTION: acpi_ex_create_processor 459 * FUNCTION: acpi_ex_create_processor
461 * 460 *
@@ -467,7 +466,7 @@ cleanup:
467 * 466 *
468 * Processor (Name[0], cpu_iD[1], pblock_addr[2], pblock_length[3]) 467 * Processor (Name[0], cpu_iD[1], pblock_addr[2], pblock_length[3])
469 * 468 *
470 ****************************************************************************/ 469 ******************************************************************************/
471 470
472acpi_status 471acpi_status
473acpi_ex_create_processor ( 472acpi_ex_create_processor (
@@ -488,9 +487,8 @@ acpi_ex_create_processor (
488 return_ACPI_STATUS (AE_NO_MEMORY); 487 return_ACPI_STATUS (AE_NO_MEMORY);
489 } 488 }
490 489
491 /* 490 /* Initialize the processor object from the operands */
492 * Initialize the processor object from the operands 491
493 */
494 obj_desc->processor.proc_id = (u8) operand[1]->integer.value; 492 obj_desc->processor.proc_id = (u8) operand[1]->integer.value;
495 obj_desc->processor.address = (acpi_io_address) operand[2]->integer.value; 493 obj_desc->processor.address = (acpi_io_address) operand[2]->integer.value;
496 obj_desc->processor.length = (u8) operand[3]->integer.value; 494 obj_desc->processor.length = (u8) operand[3]->integer.value;
@@ -507,7 +505,7 @@ acpi_ex_create_processor (
507} 505}
508 506
509 507
510/***************************************************************************** 508/*******************************************************************************
511 * 509 *
512 * FUNCTION: acpi_ex_create_power_resource 510 * FUNCTION: acpi_ex_create_power_resource
513 * 511 *
@@ -519,7 +517,7 @@ acpi_ex_create_processor (
519 * 517 *
520 * power_resource (Name[0], system_level[1], resource_order[2]) 518 * power_resource (Name[0], system_level[1], resource_order[2])
521 * 519 *
522 ****************************************************************************/ 520 ******************************************************************************/
523 521
524acpi_status 522acpi_status
525acpi_ex_create_power_resource ( 523acpi_ex_create_power_resource (
@@ -555,10 +553,10 @@ acpi_ex_create_power_resource (
555 acpi_ut_remove_reference (obj_desc); 553 acpi_ut_remove_reference (obj_desc);
556 return_ACPI_STATUS (status); 554 return_ACPI_STATUS (status);
557} 555}
558
559#endif 556#endif
560 557
561/***************************************************************************** 558
559/*******************************************************************************
562 * 560 *
563 * FUNCTION: acpi_ex_create_method 561 * FUNCTION: acpi_ex_create_method
564 * 562 *
@@ -570,7 +568,7 @@ acpi_ex_create_power_resource (
570 * 568 *
571 * DESCRIPTION: Create a new method object 569 * DESCRIPTION: Create a new method object
572 * 570 *
573 ****************************************************************************/ 571 ******************************************************************************/
574 572
575acpi_status 573acpi_status
576acpi_ex_create_method ( 574acpi_ex_create_method (
diff --git a/drivers/acpi/executer/exdump.c b/drivers/acpi/executer/exdump.c
index e2f7c32f28de..408500648114 100644
--- a/drivers/acpi/executer/exdump.c
+++ b/drivers/acpi/executer/exdump.c
@@ -51,23 +51,48 @@
51#define _COMPONENT ACPI_EXECUTER 51#define _COMPONENT ACPI_EXECUTER
52 ACPI_MODULE_NAME ("exdump") 52 ACPI_MODULE_NAME ("exdump")
53 53
54/* Local prototypes */
55
56#ifdef ACPI_FUTURE_USAGE
57static void
58acpi_ex_out_string (
59 char *title,
60 char *value);
61
62static void
63acpi_ex_out_pointer (
64 char *title,
65 void *value);
66
67static void
68acpi_ex_out_integer (
69 char *title,
70 u32 value);
71
72static void
73acpi_ex_out_address (
74 char *title,
75 acpi_physical_address value);
76#endif /* ACPI_FUTURE_USAGE */
77
54 78
55/* 79/*
56 * The following routines are used for debug output only 80 * The following routines are used for debug output only
57 */ 81 */
58#if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER) 82#if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
59 83
60/***************************************************************************** 84/*******************************************************************************
61 * 85 *
62 * FUNCTION: acpi_ex_dump_operand 86 * FUNCTION: acpi_ex_dump_operand
63 * 87 *
64 * PARAMETERS: *obj_desc - Pointer to entry to be dumped 88 * PARAMETERS: *obj_desc - Pointer to entry to be dumped
89 * Depth - Current nesting depth
65 * 90 *
66 * RETURN: None 91 * RETURN: None
67 * 92 *
68 * DESCRIPTION: Dump an operand object 93 * DESCRIPTION: Dump an operand object
69 * 94 *
70 ****************************************************************************/ 95 ******************************************************************************/
71 96
72void 97void
73acpi_ex_dump_operand ( 98acpi_ex_dump_operand (
@@ -86,9 +111,8 @@ acpi_ex_dump_operand (
86 } 111 }
87 112
88 if (!obj_desc) { 113 if (!obj_desc) {
89 /* 114 /* This could be a null element of a package */
90 * This could be a null element of a package 115
91 */
92 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Null Object Descriptor\n")); 116 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Null Object Descriptor\n"));
93 return; 117 return;
94 } 118 }
@@ -117,6 +141,8 @@ acpi_ex_dump_operand (
117 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%p ", obj_desc)); 141 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%p ", obj_desc));
118 } 142 }
119 143
144 /* Decode object type */
145
120 switch (ACPI_GET_OBJECT_TYPE (obj_desc)) { 146 switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
121 case ACPI_TYPE_LOCAL_REFERENCE: 147 case ACPI_TYPE_LOCAL_REFERENCE:
122 148
@@ -274,7 +300,9 @@ acpi_ex_dump_operand (
274 case ACPI_TYPE_STRING: 300 case ACPI_TYPE_STRING:
275 301
276 acpi_os_printf ("String length %X @ %p ", 302 acpi_os_printf ("String length %X @ %p ",
277 obj_desc->string.length, obj_desc->string.pointer); 303 obj_desc->string.length,
304 obj_desc->string.pointer);
305
278 acpi_ut_print_string (obj_desc->string.pointer, ACPI_UINT8_MAX); 306 acpi_ut_print_string (obj_desc->string.pointer, ACPI_UINT8_MAX);
279 acpi_os_printf ("\n"); 307 acpi_os_printf ("\n");
280 break; 308 break;
@@ -290,10 +318,13 @@ acpi_ex_dump_operand (
290 318
291 acpi_os_printf ( 319 acpi_os_printf (
292 "region_field: Bits=%X acc_width=%X Lock=%X Update=%X at byte=%X bit=%X of below:\n", 320 "region_field: Bits=%X acc_width=%X Lock=%X Update=%X at byte=%X bit=%X of below:\n",
293 obj_desc->field.bit_length, obj_desc->field.access_byte_width, 321 obj_desc->field.bit_length,
322 obj_desc->field.access_byte_width,
294 obj_desc->field.field_flags & AML_FIELD_LOCK_RULE_MASK, 323 obj_desc->field.field_flags & AML_FIELD_LOCK_RULE_MASK,
295 obj_desc->field.field_flags & AML_FIELD_UPDATE_RULE_MASK, 324 obj_desc->field.field_flags & AML_FIELD_UPDATE_RULE_MASK,
296 obj_desc->field.base_byte_offset, obj_desc->field.start_field_bit_offset); 325 obj_desc->field.base_byte_offset,
326 obj_desc->field.start_field_bit_offset);
327
297 acpi_ex_dump_operand (obj_desc->field.region_obj, depth+1); 328 acpi_ex_dump_operand (obj_desc->field.region_obj, depth+1);
298 break; 329 break;
299 330
@@ -308,13 +339,15 @@ acpi_ex_dump_operand (
308 339
309 acpi_os_printf ( 340 acpi_os_printf (
310 "buffer_field: %X bits at byte %X bit %X of \n", 341 "buffer_field: %X bits at byte %X bit %X of \n",
311 obj_desc->buffer_field.bit_length, obj_desc->buffer_field.base_byte_offset, 342 obj_desc->buffer_field.bit_length,
343 obj_desc->buffer_field.base_byte_offset,
312 obj_desc->buffer_field.start_field_bit_offset); 344 obj_desc->buffer_field.start_field_bit_offset);
313 345
314 if (!obj_desc->buffer_field.buffer_obj) { 346 if (!obj_desc->buffer_field.buffer_obj) {
315 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "*NULL* \n")); 347 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "*NULL* \n"));
316 } 348 }
317 else if (ACPI_GET_OBJECT_TYPE (obj_desc->buffer_field.buffer_obj) != ACPI_TYPE_BUFFER) { 349 else if (ACPI_GET_OBJECT_TYPE (obj_desc->buffer_field.buffer_obj) !=
350 ACPI_TYPE_BUFFER) {
318 acpi_os_printf ("*not a Buffer* \n"); 351 acpi_os_printf ("*not a Buffer* \n");
319 } 352 }
320 else { 353 else {
@@ -331,10 +364,10 @@ acpi_ex_dump_operand (
331 364
332 case ACPI_TYPE_METHOD: 365 case ACPI_TYPE_METHOD:
333 366
334 acpi_os_printf ( 367 acpi_os_printf ("Method(%X) @ %p:%X\n",
335 "Method(%X) @ %p:%X\n",
336 obj_desc->method.param_count, 368 obj_desc->method.param_count,
337 obj_desc->method.aml_start, obj_desc->method.aml_length); 369 obj_desc->method.aml_start,
370 obj_desc->method.aml_length);
338 break; 371 break;
339 372
340 373
@@ -379,7 +412,7 @@ acpi_ex_dump_operand (
379} 412}
380 413
381 414
382/***************************************************************************** 415/*******************************************************************************
383 * 416 *
384 * FUNCTION: acpi_ex_dump_operands 417 * FUNCTION: acpi_ex_dump_operands
385 * 418 *
@@ -393,7 +426,7 @@ acpi_ex_dump_operand (
393 * 426 *
394 * DESCRIPTION: Dump the object stack 427 * DESCRIPTION: Dump the object stack
395 * 428 *
396 ****************************************************************************/ 429 ******************************************************************************/
397 430
398void 431void
399acpi_ex_dump_operands ( 432acpi_ex_dump_operands (
@@ -441,10 +474,9 @@ acpi_ex_dump_operands (
441 474
442 475
443#ifdef ACPI_FUTURE_USAGE 476#ifdef ACPI_FUTURE_USAGE
444 477/*******************************************************************************
445/*****************************************************************************
446 * 478 *
447 * FUNCTION: acpi_ex_out* 479 * FUNCTION: acpi_ex_out* functions
448 * 480 *
449 * PARAMETERS: Title - Descriptive text 481 * PARAMETERS: Title - Descriptive text
450 * Value - Value to be displayed 482 * Value - Value to be displayed
@@ -453,9 +485,9 @@ acpi_ex_dump_operands (
453 * reduce the number of format strings required and keeps them 485 * reduce the number of format strings required and keeps them
454 * all in one place for easy modification. 486 * all in one place for easy modification.
455 * 487 *
456 ****************************************************************************/ 488 ******************************************************************************/
457 489
458void 490static void
459acpi_ex_out_string ( 491acpi_ex_out_string (
460 char *title, 492 char *title,
461 char *value) 493 char *value)
@@ -463,7 +495,7 @@ acpi_ex_out_string (
463 acpi_os_printf ("%20s : %s\n", title, value); 495 acpi_os_printf ("%20s : %s\n", title, value);
464} 496}
465 497
466void 498static void
467acpi_ex_out_pointer ( 499acpi_ex_out_pointer (
468 char *title, 500 char *title,
469 void *value) 501 void *value)
@@ -471,7 +503,7 @@ acpi_ex_out_pointer (
471 acpi_os_printf ("%20s : %p\n", title, value); 503 acpi_os_printf ("%20s : %p\n", title, value);
472} 504}
473 505
474void 506static void
475acpi_ex_out_integer ( 507acpi_ex_out_integer (
476 char *title, 508 char *title,
477 u32 value) 509 u32 value)
@@ -479,7 +511,7 @@ acpi_ex_out_integer (
479 acpi_os_printf ("%20s : %X\n", title, value); 511 acpi_os_printf ("%20s : %X\n", title, value);
480} 512}
481 513
482void 514static void
483acpi_ex_out_address ( 515acpi_ex_out_address (
484 char *title, 516 char *title,
485 acpi_physical_address value) 517 acpi_physical_address value)
@@ -493,16 +525,16 @@ acpi_ex_out_address (
493} 525}
494 526
495 527
496/***************************************************************************** 528/*******************************************************************************
497 * 529 *
498 * FUNCTION: acpi_ex_dump_node 530 * FUNCTION: acpi_ex_dump_node
499 * 531 *
500 * PARAMETERS: *Node - Descriptor to dump 532 * PARAMETERS: *Node - Descriptor to dump
501 * Flags - Force display 533 * Flags - Force display if TRUE
502 * 534 *
503 * DESCRIPTION: Dumps the members of the given.Node 535 * DESCRIPTION: Dumps the members of the given.Node
504 * 536 *
505 ****************************************************************************/ 537 ******************************************************************************/
506 538
507void 539void
508acpi_ex_dump_node ( 540acpi_ex_dump_node (
@@ -531,16 +563,16 @@ acpi_ex_dump_node (
531} 563}
532 564
533 565
534/***************************************************************************** 566/*******************************************************************************
535 * 567 *
536 * FUNCTION: acpi_ex_dump_object_descriptor 568 * FUNCTION: acpi_ex_dump_object_descriptor
537 * 569 *
538 * PARAMETERS: *Object - Descriptor to dump 570 * PARAMETERS: *Object - Descriptor to dump
539 * Flags - Force display 571 * Flags - Force display if TRUE
540 * 572 *
541 * DESCRIPTION: Dumps the members of the object descriptor given. 573 * DESCRIPTION: Dumps the members of the object descriptor given.
542 * 574 *
543 ****************************************************************************/ 575 ******************************************************************************/
544 576
545void 577void
546acpi_ex_dump_object_descriptor ( 578acpi_ex_dump_object_descriptor (
@@ -553,6 +585,10 @@ acpi_ex_dump_object_descriptor (
553 ACPI_FUNCTION_TRACE ("ex_dump_object_descriptor"); 585 ACPI_FUNCTION_TRACE ("ex_dump_object_descriptor");
554 586
555 587
588 if (!obj_desc) {
589 return_VOID;
590 }
591
556 if (!flags) { 592 if (!flags) {
557 if (!((ACPI_LV_OBJECTS & acpi_dbg_level) && (_COMPONENT & acpi_dbg_layer))) { 593 if (!((ACPI_LV_OBJECTS & acpi_dbg_level) && (_COMPONENT & acpi_dbg_layer))) {
558 return_VOID; 594 return_VOID;
@@ -747,11 +783,17 @@ acpi_ex_dump_object_descriptor (
747 case ACPI_TYPE_LOCAL_REFERENCE: 783 case ACPI_TYPE_LOCAL_REFERENCE:
748 784
749 acpi_ex_out_integer ("target_type", obj_desc->reference.target_type); 785 acpi_ex_out_integer ("target_type", obj_desc->reference.target_type);
750 acpi_ex_out_string ("Opcode", (acpi_ps_get_opcode_info (obj_desc->reference.opcode))->name); 786 acpi_ex_out_string ("Opcode", (acpi_ps_get_opcode_info (
787 obj_desc->reference.opcode))->name);
751 acpi_ex_out_integer ("Offset", obj_desc->reference.offset); 788 acpi_ex_out_integer ("Offset", obj_desc->reference.offset);
752 acpi_ex_out_pointer ("obj_desc", obj_desc->reference.object); 789 acpi_ex_out_pointer ("obj_desc", obj_desc->reference.object);
753 acpi_ex_out_pointer ("Node", obj_desc->reference.node); 790 acpi_ex_out_pointer ("Node", obj_desc->reference.node);
754 acpi_ex_out_pointer ("Where", obj_desc->reference.where); 791 acpi_ex_out_pointer ("Where", obj_desc->reference.where);
792
793 if (obj_desc->reference.object) {
794 acpi_os_printf ("\nReferenced Object:\n");
795 acpi_ex_dump_object_descriptor (obj_desc->reference.object, flags);
796 }
755 break; 797 break;
756 798
757 799
@@ -788,6 +830,5 @@ acpi_ex_dump_object_descriptor (
788} 830}
789 831
790#endif /* ACPI_FUTURE_USAGE */ 832#endif /* ACPI_FUTURE_USAGE */
791
792#endif 833#endif
793 834
diff --git a/drivers/acpi/executer/exfield.c b/drivers/acpi/executer/exfield.c
index be7f2124fa02..22c8fa480f60 100644
--- a/drivers/acpi/executer/exfield.c
+++ b/drivers/acpi/executer/exfield.c
@@ -120,8 +120,8 @@ acpi_ex_read_data_from_field (
120 * Note: Smbus protocol value is passed in upper 16-bits of Function 120 * Note: Smbus protocol value is passed in upper 16-bits of Function
121 */ 121 */
122 status = acpi_ex_access_region (obj_desc, 0, 122 status = acpi_ex_access_region (obj_desc, 0,
123 ACPI_CAST_PTR (acpi_integer, buffer_desc->buffer.pointer), 123 ACPI_CAST_PTR (acpi_integer, buffer_desc->buffer.pointer),
124 ACPI_READ | (obj_desc->field.attribute << 16)); 124 ACPI_READ | (obj_desc->field.attribute << 16));
125 acpi_ex_release_global_lock (locked); 125 acpi_ex_release_global_lock (locked);
126 goto exit; 126 goto exit;
127 } 127 }
@@ -196,6 +196,7 @@ exit:
196 * 196 *
197 * PARAMETERS: source_desc - Contains data to write 197 * PARAMETERS: source_desc - Contains data to write
198 * obj_desc - The named field 198 * obj_desc - The named field
199 * result_desc - Where the return value is returned, if any
199 * 200 *
200 * RETURN: Status 201 * RETURN: Status
201 * 202 *
@@ -250,12 +251,15 @@ acpi_ex_write_data_to_field (
250 if (ACPI_GET_OBJECT_TYPE (source_desc) != ACPI_TYPE_BUFFER) { 251 if (ACPI_GET_OBJECT_TYPE (source_desc) != ACPI_TYPE_BUFFER) {
251 ACPI_REPORT_ERROR (("SMBus write requires Buffer, found type %s\n", 252 ACPI_REPORT_ERROR (("SMBus write requires Buffer, found type %s\n",
252 acpi_ut_get_object_type_name (source_desc))); 253 acpi_ut_get_object_type_name (source_desc)));
254
253 return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 255 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
254 } 256 }
255 257
256 if (source_desc->buffer.length < ACPI_SMBUS_BUFFER_SIZE) { 258 if (source_desc->buffer.length < ACPI_SMBUS_BUFFER_SIZE) {
257 ACPI_REPORT_ERROR (("SMBus write requires Buffer of length %X, found length %X\n", 259 ACPI_REPORT_ERROR ((
260 "SMBus write requires Buffer of length %X, found length %X\n",
258 ACPI_SMBUS_BUFFER_SIZE, source_desc->buffer.length)); 261 ACPI_SMBUS_BUFFER_SIZE, source_desc->buffer.length));
262
259 return_ACPI_STATUS (AE_AML_BUFFER_LIMIT); 263 return_ACPI_STATUS (AE_AML_BUFFER_LIMIT);
260 } 264 }
261 265
@@ -265,14 +269,16 @@ acpi_ex_write_data_to_field (
265 } 269 }
266 270
267 buffer = buffer_desc->buffer.pointer; 271 buffer = buffer_desc->buffer.pointer;
268 ACPI_MEMCPY (buffer, source_desc->buffer.pointer, ACPI_SMBUS_BUFFER_SIZE); 272 ACPI_MEMCPY (buffer, source_desc->buffer.pointer,
273 ACPI_SMBUS_BUFFER_SIZE);
269 274
270 /* Lock entire transaction if requested */ 275 /* Lock entire transaction if requested */
271 276
272 locked = acpi_ex_acquire_global_lock (obj_desc->common_field.field_flags); 277 locked = acpi_ex_acquire_global_lock (obj_desc->common_field.field_flags);
273 278
274 /* 279 /*
275 * Perform the write (returns status and perhaps data in the same buffer) 280 * Perform the write (returns status and perhaps data in the
281 * same buffer)
276 * Note: SMBus protocol type is passed in upper 16-bits of Function. 282 * Note: SMBus protocol type is passed in upper 16-bits of Function.
277 */ 283 */
278 status = acpi_ex_access_region (obj_desc, 0, 284 status = acpi_ex_access_region (obj_desc, 0,
@@ -284,9 +290,8 @@ acpi_ex_write_data_to_field (
284 return_ACPI_STATUS (status); 290 return_ACPI_STATUS (status);
285 } 291 }
286 292
287 /* 293 /* Get a pointer to the data to be written */
288 * Get a pointer to the data to be written 294
289 */
290 switch (ACPI_GET_OBJECT_TYPE (source_desc)) { 295 switch (ACPI_GET_OBJECT_TYPE (source_desc)) {
291 case ACPI_TYPE_INTEGER: 296 case ACPI_TYPE_INTEGER:
292 buffer = &source_desc->integer.value; 297 buffer = &source_desc->integer.value;
@@ -314,7 +319,8 @@ acpi_ex_write_data_to_field (
314 * the ACPI specification. 319 * the ACPI specification.
315 */ 320 */
316 new_buffer = NULL; 321 new_buffer = NULL;
317 required_length = ACPI_ROUND_BITS_UP_TO_BYTES (obj_desc->common_field.bit_length); 322 required_length = ACPI_ROUND_BITS_UP_TO_BYTES (
323 obj_desc->common_field.bit_length);
318 324
319 if (length < required_length) { 325 if (length < required_length) {
320 /* We need to create a new buffer */ 326 /* We need to create a new buffer */
@@ -338,6 +344,7 @@ acpi_ex_write_data_to_field (
338 "field_write [FROM]: Obj %p (%s:%X), Buf %p, byte_len %X\n", 344 "field_write [FROM]: Obj %p (%s:%X), Buf %p, byte_len %X\n",
339 source_desc, acpi_ut_get_type_name (ACPI_GET_OBJECT_TYPE (source_desc)), 345 source_desc, acpi_ut_get_type_name (ACPI_GET_OBJECT_TYPE (source_desc)),
340 ACPI_GET_OBJECT_TYPE (source_desc), buffer, length)); 346 ACPI_GET_OBJECT_TYPE (source_desc), buffer, length));
347
341 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 348 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
342 "field_write [TO]: Obj %p (%s:%X), bit_len %X, bit_off %X, byte_off %X\n", 349 "field_write [TO]: Obj %p (%s:%X), bit_len %X, bit_off %X, byte_off %X\n",
343 obj_desc, acpi_ut_get_type_name (ACPI_GET_OBJECT_TYPE (obj_desc)), 350 obj_desc, acpi_ut_get_type_name (ACPI_GET_OBJECT_TYPE (obj_desc)),
diff --git a/drivers/acpi/executer/exfldio.c b/drivers/acpi/executer/exfldio.c
index 9d0f9d2e9061..3c2f89e00f78 100644
--- a/drivers/acpi/executer/exfldio.c
+++ b/drivers/acpi/executer/exfldio.c
@@ -52,12 +52,31 @@
52#define _COMPONENT ACPI_EXECUTER 52#define _COMPONENT ACPI_EXECUTER
53 ACPI_MODULE_NAME ("exfldio") 53 ACPI_MODULE_NAME ("exfldio")
54 54
55/* Local prototypes */
56
57static acpi_status
58acpi_ex_field_datum_io (
59 union acpi_operand_object *obj_desc,
60 u32 field_datum_byte_offset,
61 acpi_integer *value,
62 u32 read_write);
63
64static u8
65acpi_ex_register_overflow (
66 union acpi_operand_object *obj_desc,
67 acpi_integer value);
68
69static acpi_status
70acpi_ex_setup_region (
71 union acpi_operand_object *obj_desc,
72 u32 field_datum_byte_offset);
73
55 74
56/******************************************************************************* 75/*******************************************************************************
57 * 76 *
58 * FUNCTION: acpi_ex_setup_region 77 * FUNCTION: acpi_ex_setup_region
59 * 78 *
60 * PARAMETERS: *obj_desc - Field to be read or written 79 * PARAMETERS: obj_desc - Field to be read or written
61 * field_datum_byte_offset - Byte offset of this datum within the 80 * field_datum_byte_offset - Byte offset of this datum within the
62 * parent field 81 * parent field
63 * 82 *
@@ -69,7 +88,7 @@
69 * 88 *
70 ******************************************************************************/ 89 ******************************************************************************/
71 90
72acpi_status 91static acpi_status
73acpi_ex_setup_region ( 92acpi_ex_setup_region (
74 union acpi_operand_object *obj_desc, 93 union acpi_operand_object *obj_desc,
75 u32 field_datum_byte_offset) 94 u32 field_datum_byte_offset)
@@ -127,9 +146,9 @@ acpi_ex_setup_region (
127 * length of one field datum (access width) must fit within the region. 146 * length of one field datum (access width) must fit within the region.
128 * (Region length is specified in bytes) 147 * (Region length is specified in bytes)
129 */ 148 */
130 if (rgn_desc->region.length < (obj_desc->common_field.base_byte_offset 149 if (rgn_desc->region.length < (obj_desc->common_field.base_byte_offset +
131 + field_datum_byte_offset 150 field_datum_byte_offset +
132 + obj_desc->common_field.access_byte_width)) { 151 obj_desc->common_field.access_byte_width)) {
133 if (acpi_gbl_enable_interpreter_slack) { 152 if (acpi_gbl_enable_interpreter_slack) {
134 /* 153 /*
135 * Slack mode only: We will go ahead and allow access to this 154 * Slack mode only: We will go ahead and allow access to this
@@ -155,7 +174,8 @@ acpi_ex_setup_region (
155 "Field [%4.4s] access width (%d bytes) too large for region [%4.4s] (length %X)\n", 174 "Field [%4.4s] access width (%d bytes) too large for region [%4.4s] (length %X)\n",
156 acpi_ut_get_node_name (obj_desc->common_field.node), 175 acpi_ut_get_node_name (obj_desc->common_field.node),
157 obj_desc->common_field.access_byte_width, 176 obj_desc->common_field.access_byte_width,
158 acpi_ut_get_node_name (rgn_desc->region.node), rgn_desc->region.length)); 177 acpi_ut_get_node_name (rgn_desc->region.node),
178 rgn_desc->region.length));
159 } 179 }
160 180
161 /* 181 /*
@@ -167,7 +187,8 @@ acpi_ex_setup_region (
167 acpi_ut_get_node_name (obj_desc->common_field.node), 187 acpi_ut_get_node_name (obj_desc->common_field.node),
168 obj_desc->common_field.base_byte_offset, 188 obj_desc->common_field.base_byte_offset,
169 field_datum_byte_offset, obj_desc->common_field.access_byte_width, 189 field_datum_byte_offset, obj_desc->common_field.access_byte_width,
170 acpi_ut_get_node_name (rgn_desc->region.node), rgn_desc->region.length)); 190 acpi_ut_get_node_name (rgn_desc->region.node),
191 rgn_desc->region.length));
171 192
172 return_ACPI_STATUS (AE_AML_REGION_LIMIT); 193 return_ACPI_STATUS (AE_AML_REGION_LIMIT);
173 } 194 }
@@ -180,10 +201,10 @@ acpi_ex_setup_region (
180 * 201 *
181 * FUNCTION: acpi_ex_access_region 202 * FUNCTION: acpi_ex_access_region
182 * 203 *
183 * PARAMETERS: *obj_desc - Field to be read 204 * PARAMETERS: obj_desc - Field to be read
184 * field_datum_byte_offset - Byte offset of this datum within the 205 * field_datum_byte_offset - Byte offset of this datum within the
185 * parent field 206 * parent field
186 * *Value - Where to store value (must at least 207 * Value - Where to store value (must at least
187 * the size of acpi_integer) 208 * the size of acpi_integer)
188 * Function - Read or Write flag plus other region- 209 * Function - Read or Write flag plus other region-
189 * dependent flags 210 * dependent flags
@@ -226,9 +247,9 @@ acpi_ex_access_region (
226 * 3) The current offset into the field 247 * 3) The current offset into the field
227 */ 248 */
228 rgn_desc = obj_desc->common_field.region_obj; 249 rgn_desc = obj_desc->common_field.region_obj;
229 address = rgn_desc->region.address 250 address = rgn_desc->region.address +
230 + obj_desc->common_field.base_byte_offset 251 obj_desc->common_field.base_byte_offset +
231 + field_datum_byte_offset; 252 field_datum_byte_offset;
232 253
233 if ((function & ACPI_IO_MASK) == ACPI_READ) { 254 if ((function & ACPI_IO_MASK) == ACPI_READ) {
234 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, "[READ]")); 255 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, "[READ]"));
@@ -249,7 +270,8 @@ acpi_ex_access_region (
249 /* Invoke the appropriate address_space/op_region handler */ 270 /* Invoke the appropriate address_space/op_region handler */
250 271
251 status = acpi_ev_address_space_dispatch (rgn_desc, function, 272 status = acpi_ev_address_space_dispatch (rgn_desc, function,
252 address, ACPI_MUL_8 (obj_desc->common_field.access_byte_width), value); 273 address,
274 ACPI_MUL_8 (obj_desc->common_field.access_byte_width), value);
253 275
254 if (ACPI_FAILURE (status)) { 276 if (ACPI_FAILURE (status)) {
255 if (status == AE_NOT_IMPLEMENTED) { 277 if (status == AE_NOT_IMPLEMENTED) {
@@ -274,7 +296,7 @@ acpi_ex_access_region (
274 * 296 *
275 * FUNCTION: acpi_ex_register_overflow 297 * FUNCTION: acpi_ex_register_overflow
276 * 298 *
277 * PARAMETERS: *obj_desc - Register(Field) to be written 299 * PARAMETERS: obj_desc - Register(Field) to be written
278 * Value - Value to be stored 300 * Value - Value to be stored
279 * 301 *
280 * RETURN: TRUE if value overflows the field, FALSE otherwise 302 * RETURN: TRUE if value overflows the field, FALSE otherwise
@@ -287,7 +309,7 @@ acpi_ex_access_region (
287 * 309 *
288 ******************************************************************************/ 310 ******************************************************************************/
289 311
290u8 312static u8
291acpi_ex_register_overflow ( 313acpi_ex_register_overflow (
292 union acpi_operand_object *obj_desc, 314 union acpi_operand_object *obj_desc,
293 acpi_integer value) 315 acpi_integer value)
@@ -319,10 +341,10 @@ acpi_ex_register_overflow (
319 * 341 *
320 * FUNCTION: acpi_ex_field_datum_io 342 * FUNCTION: acpi_ex_field_datum_io
321 * 343 *
322 * PARAMETERS: *obj_desc - Field to be read 344 * PARAMETERS: obj_desc - Field to be read
323 * field_datum_byte_offset - Byte offset of this datum within the 345 * field_datum_byte_offset - Byte offset of this datum within the
324 * parent field 346 * parent field
325 * *Value - Where to store value (must be 64 bits) 347 * Value - Where to store value (must be 64 bits)
326 * read_write - Read or Write flag 348 * read_write - Read or Write flag
327 * 349 *
328 * RETURN: Status 350 * RETURN: Status
@@ -333,7 +355,7 @@ acpi_ex_register_overflow (
333 * 355 *
334 ******************************************************************************/ 356 ******************************************************************************/
335 357
336acpi_status 358static acpi_status
337acpi_ex_field_datum_io ( 359acpi_ex_field_datum_io (
338 union acpi_operand_object *obj_desc, 360 union acpi_operand_object *obj_desc,
339 u32 field_datum_byte_offset, 361 u32 field_datum_byte_offset,
@@ -350,7 +372,9 @@ acpi_ex_field_datum_io (
350 if (read_write == ACPI_READ) { 372 if (read_write == ACPI_READ) {
351 if (!value) { 373 if (!value) {
352 local_value = 0; 374 local_value = 0;
353 value = &local_value; /* To support reads without saving return value */ 375
376 /* To support reads without saving return value */
377 value = &local_value;
354 } 378 }
355 379
356 /* Clear the entire return buffer first, [Very Important!] */ 380 /* Clear the entire return buffer first, [Very Important!] */
@@ -363,8 +387,10 @@ acpi_ex_field_datum_io (
363 * 387 *
364 * buffer_field - Read/write from/to a Buffer 388 * buffer_field - Read/write from/to a Buffer
365 * region_field - Read/write from/to a Operation Region. 389 * region_field - Read/write from/to a Operation Region.
366 * bank_field - Write to a Bank Register, then read/write from/to an op_region 390 * bank_field - Write to a Bank Register, then read/write from/to an
367 * index_field - Write to an Index Register, then read/write from/to a Data Register 391 * operation_region
392 * index_field - Write to an Index Register, then read/write from/to a
393 * Data Register
368 */ 394 */
369 switch (ACPI_GET_OBJECT_TYPE (obj_desc)) { 395 switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
370 case ACPI_TYPE_BUFFER_FIELD: 396 case ACPI_TYPE_BUFFER_FIELD:
@@ -384,19 +410,20 @@ acpi_ex_field_datum_io (
384 * Copy the data from the source buffer. 410 * Copy the data from the source buffer.
385 * Length is the field width in bytes. 411 * Length is the field width in bytes.
386 */ 412 */
387 ACPI_MEMCPY (value, (obj_desc->buffer_field.buffer_obj)->buffer.pointer 413 ACPI_MEMCPY (value,
388 + obj_desc->buffer_field.base_byte_offset 414 (obj_desc->buffer_field.buffer_obj)->buffer.pointer +
389 + field_datum_byte_offset, 415 obj_desc->buffer_field.base_byte_offset +
390 obj_desc->common_field.access_byte_width); 416 field_datum_byte_offset,
417 obj_desc->common_field.access_byte_width);
391 } 418 }
392 else { 419 else {
393 /* 420 /*
394 * Copy the data to the target buffer. 421 * Copy the data to the target buffer.
395 * Length is the field width in bytes. 422 * Length is the field width in bytes.
396 */ 423 */
397 ACPI_MEMCPY ((obj_desc->buffer_field.buffer_obj)->buffer.pointer 424 ACPI_MEMCPY ((obj_desc->buffer_field.buffer_obj)->buffer.pointer +
398 + obj_desc->buffer_field.base_byte_offset 425 obj_desc->buffer_field.base_byte_offset +
399 + field_datum_byte_offset, 426 field_datum_byte_offset,
400 value, obj_desc->common_field.access_byte_width); 427 value, obj_desc->common_field.access_byte_width);
401 } 428 }
402 429
@@ -406,8 +433,10 @@ acpi_ex_field_datum_io (
406 433
407 case ACPI_TYPE_LOCAL_BANK_FIELD: 434 case ACPI_TYPE_LOCAL_BANK_FIELD:
408 435
409 /* Ensure that the bank_value is not beyond the capacity of the register */ 436 /*
410 437 * Ensure that the bank_value is not beyond the capacity of
438 * the register
439 */
411 if (acpi_ex_register_overflow (obj_desc->bank_field.bank_obj, 440 if (acpi_ex_register_overflow (obj_desc->bank_field.bank_obj,
412 (acpi_integer) obj_desc->bank_field.value)) { 441 (acpi_integer) obj_desc->bank_field.value)) {
413 return_ACPI_STATUS (AE_AML_REGISTER_LIMIT); 442 return_ACPI_STATUS (AE_AML_REGISTER_LIMIT);
@@ -445,8 +474,10 @@ acpi_ex_field_datum_io (
445 case ACPI_TYPE_LOCAL_INDEX_FIELD: 474 case ACPI_TYPE_LOCAL_INDEX_FIELD:
446 475
447 476
448 /* Ensure that the index_value is not beyond the capacity of the register */ 477 /*
449 478 * Ensure that the index_value is not beyond the capacity of
479 * the register
480 */
450 if (acpi_ex_register_overflow (obj_desc->index_field.index_obj, 481 if (acpi_ex_register_overflow (obj_desc->index_field.index_obj,
451 (acpi_integer) obj_desc->index_field.value)) { 482 (acpi_integer) obj_desc->index_field.value)) {
452 return_ACPI_STATUS (AE_AML_REGISTER_LIMIT); 483 return_ACPI_STATUS (AE_AML_REGISTER_LIMIT);
@@ -496,14 +527,16 @@ acpi_ex_field_datum_io (
496 527
497 if (ACPI_SUCCESS (status)) { 528 if (ACPI_SUCCESS (status)) {
498 if (read_write == ACPI_READ) { 529 if (read_write == ACPI_READ) {
499 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, "Value Read %8.8X%8.8X, Width %d\n", 530 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
500 ACPI_FORMAT_UINT64 (*value), 531 "Value Read %8.8X%8.8X, Width %d\n",
501 obj_desc->common_field.access_byte_width)); 532 ACPI_FORMAT_UINT64 (*value),
533 obj_desc->common_field.access_byte_width));
502 } 534 }
503 else { 535 else {
504 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, "Value Written %8.8X%8.8X, Width %d\n", 536 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
505 ACPI_FORMAT_UINT64 (*value), 537 "Value Written %8.8X%8.8X, Width %d\n",
506 obj_desc->common_field.access_byte_width)); 538 ACPI_FORMAT_UINT64 (*value),
539 obj_desc->common_field.access_byte_width));
507 } 540 }
508 } 541 }
509 542
@@ -515,8 +548,10 @@ acpi_ex_field_datum_io (
515 * 548 *
516 * FUNCTION: acpi_ex_write_with_update_rule 549 * FUNCTION: acpi_ex_write_with_update_rule
517 * 550 *
518 * PARAMETERS: *obj_desc - Field to be set 551 * PARAMETERS: obj_desc - Field to be written
519 * Value - Value to store 552 * Mask - bitmask within field datum
553 * field_value - Value to write
554 * field_datum_byte_offset - Offset of datum within field
520 * 555 *
521 * RETURN: Status 556 * RETURN: Status
522 * 557 *
@@ -689,7 +724,8 @@ acpi_ex_extract_from_field (
689 /* Merge with previous datum if necessary */ 724 /* Merge with previous datum if necessary */
690 725
691 merged_datum |= raw_datum << 726 merged_datum |= raw_datum <<
692 (obj_desc->common_field.access_bit_width - obj_desc->common_field.start_field_bit_offset); 727 (obj_desc->common_field.access_bit_width -
728 obj_desc->common_field.start_field_bit_offset);
693 729
694 if (i == datum_count) { 730 if (i == datum_count) {
695 break; 731 break;
@@ -707,7 +743,8 @@ acpi_ex_extract_from_field (
707 743
708 /* Mask off any extra bits in the last datum */ 744 /* Mask off any extra bits in the last datum */
709 745
710 buffer_tail_bits = obj_desc->common_field.bit_length % obj_desc->common_field.access_bit_width; 746 buffer_tail_bits = obj_desc->common_field.bit_length %
747 obj_desc->common_field.access_bit_width;
711 if (buffer_tail_bits) { 748 if (buffer_tail_bits) {
712 merged_datum &= ACPI_MASK_BITS_ABOVE (buffer_tail_bits); 749 merged_datum &= ACPI_MASK_BITS_ABOVE (buffer_tail_bits);
713 } 750 }
@@ -791,7 +828,8 @@ acpi_ex_insert_into_field (
791 /* Write merged datum to the target field */ 828 /* Write merged datum to the target field */
792 829
793 merged_datum &= mask; 830 merged_datum &= mask;
794 status = acpi_ex_write_with_update_rule (obj_desc, mask, merged_datum, field_offset); 831 status = acpi_ex_write_with_update_rule (obj_desc, mask,
832 merged_datum, field_offset);
795 if (ACPI_FAILURE (status)) { 833 if (ACPI_FAILURE (status)) {
796 return_ACPI_STATUS (status); 834 return_ACPI_STATUS (status);
797 } 835 }
@@ -800,7 +838,8 @@ acpi_ex_insert_into_field (
800 838
801 field_offset += obj_desc->common_field.access_byte_width; 839 field_offset += obj_desc->common_field.access_byte_width;
802 merged_datum = raw_datum >> 840 merged_datum = raw_datum >>
803 (obj_desc->common_field.access_bit_width - obj_desc->common_field.start_field_bit_offset); 841 (obj_desc->common_field.access_bit_width -
842 obj_desc->common_field.start_field_bit_offset);
804 mask = ACPI_INTEGER_MAX; 843 mask = ACPI_INTEGER_MAX;
805 844
806 if (i == datum_count) { 845 if (i == datum_count) {
@@ -819,7 +858,8 @@ acpi_ex_insert_into_field (
819 /* Mask off any extra bits in the last datum */ 858 /* Mask off any extra bits in the last datum */
820 859
821 buffer_tail_bits = (obj_desc->common_field.bit_length + 860 buffer_tail_bits = (obj_desc->common_field.bit_length +
822 obj_desc->common_field.start_field_bit_offset) % obj_desc->common_field.access_bit_width; 861 obj_desc->common_field.start_field_bit_offset) %
862 obj_desc->common_field.access_bit_width;
823 if (buffer_tail_bits) { 863 if (buffer_tail_bits) {
824 mask &= ACPI_MASK_BITS_ABOVE (buffer_tail_bits); 864 mask &= ACPI_MASK_BITS_ABOVE (buffer_tail_bits);
825 } 865 }
@@ -827,7 +867,8 @@ acpi_ex_insert_into_field (
827 /* Write the last datum to the field */ 867 /* Write the last datum to the field */
828 868
829 merged_datum &= mask; 869 merged_datum &= mask;
830 status = acpi_ex_write_with_update_rule (obj_desc, mask, merged_datum, field_offset); 870 status = acpi_ex_write_with_update_rule (obj_desc,
871 mask, merged_datum, field_offset);
831 872
832 return_ACPI_STATUS (status); 873 return_ACPI_STATUS (status);
833} 874}
diff --git a/drivers/acpi/executer/exmisc.c b/drivers/acpi/executer/exmisc.c
index b542dcd58c07..022f281345b8 100644
--- a/drivers/acpi/executer/exmisc.c
+++ b/drivers/acpi/executer/exmisc.c
@@ -139,8 +139,9 @@ acpi_ex_get_object_reference (
139 reference_obj->reference.object = referenced_obj; 139 reference_obj->reference.object = referenced_obj;
140 *return_desc = reference_obj; 140 *return_desc = reference_obj;
141 141
142 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Object %p Type [%s], returning Reference %p\n", 142 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
143 obj_desc, acpi_ut_get_object_type_name (obj_desc), *return_desc)); 143 "Object %p Type [%s], returning Reference %p\n",
144 obj_desc, acpi_ut_get_object_type_name (obj_desc), *return_desc));
144 145
145 return_ACPI_STATUS (AE_OK); 146 return_ACPI_STATUS (AE_OK);
146} 147}
@@ -456,7 +457,7 @@ acpi_ex_do_math_op (
456 return (integer0 * integer1); 457 return (integer0 * integer1);
457 458
458 459
459 case AML_SHIFT_LEFT_OP: /* shift_left (Operand, shift_count, Result) */ 460 case AML_SHIFT_LEFT_OP: /* shift_left (Operand, shift_count, Result)*/
460 461
461 return (integer0 << integer1); 462 return (integer0 << integer1);
462 463
diff --git a/drivers/acpi/executer/exmutex.c b/drivers/acpi/executer/exmutex.c
index 68c4bb1970a5..c3cb714d2cba 100644
--- a/drivers/acpi/executer/exmutex.c
+++ b/drivers/acpi/executer/exmutex.c
@@ -49,6 +49,13 @@
49#define _COMPONENT ACPI_EXECUTER 49#define _COMPONENT ACPI_EXECUTER
50 ACPI_MODULE_NAME ("exmutex") 50 ACPI_MODULE_NAME ("exmutex")
51 51
52/* Local prototypes */
53
54static void
55acpi_ex_link_mutex (
56 union acpi_operand_object *obj_desc,
57 struct acpi_thread_state *thread);
58
52 59
53/******************************************************************************* 60/*******************************************************************************
54 * 61 *
@@ -56,7 +63,7 @@
56 * 63 *
57 * PARAMETERS: obj_desc - The mutex to be unlinked 64 * PARAMETERS: obj_desc - The mutex to be unlinked
58 * 65 *
59 * RETURN: Status 66 * RETURN: None
60 * 67 *
61 * DESCRIPTION: Remove a mutex from the "acquired_mutex" list 68 * DESCRIPTION: Remove a mutex from the "acquired_mutex" list
62 * 69 *
@@ -92,16 +99,16 @@ acpi_ex_unlink_mutex (
92 * 99 *
93 * FUNCTION: acpi_ex_link_mutex 100 * FUNCTION: acpi_ex_link_mutex
94 * 101 *
95 * PARAMETERS: obj_desc - The mutex to be linked 102 * PARAMETERS: obj_desc - The mutex to be linked
96 * list_head - head of the "acquired_mutex" list 103 * Thread - Current executing thread object
97 * 104 *
98 * RETURN: Status 105 * RETURN: None
99 * 106 *
100 * DESCRIPTION: Add a mutex to the "acquired_mutex" list for this walk 107 * DESCRIPTION: Add a mutex to the "acquired_mutex" list for this walk
101 * 108 *
102 ******************************************************************************/ 109 ******************************************************************************/
103 110
104void 111static void
105acpi_ex_link_mutex ( 112acpi_ex_link_mutex (
106 union acpi_operand_object *obj_desc, 113 union acpi_operand_object *obj_desc,
107 struct acpi_thread_state *thread) 114 struct acpi_thread_state *thread)
@@ -132,8 +139,9 @@ acpi_ex_link_mutex (
132 * 139 *
133 * FUNCTION: acpi_ex_acquire_mutex 140 * FUNCTION: acpi_ex_acquire_mutex
134 * 141 *
135 * PARAMETERS: time_desc - The 'time to delay' object descriptor 142 * PARAMETERS: time_desc - Timeout integer
136 * obj_desc - The object descriptor for this op 143 * obj_desc - Mutex object
144 * walk_state - Current method execution state
137 * 145 *
138 * RETURN: Status 146 * RETURN: Status
139 * 147 *
@@ -161,7 +169,7 @@ acpi_ex_acquire_mutex (
161 169
162 if (!walk_state->thread) { 170 if (!walk_state->thread) {
163 ACPI_REPORT_ERROR (("Cannot acquire Mutex [%4.4s], null thread info\n", 171 ACPI_REPORT_ERROR (("Cannot acquire Mutex [%4.4s], null thread info\n",
164 acpi_ut_get_node_name (obj_desc->mutex.node))); 172 acpi_ut_get_node_name (obj_desc->mutex.node)));
165 return_ACPI_STATUS (AE_AML_INTERNAL); 173 return_ACPI_STATUS (AE_AML_INTERNAL);
166 } 174 }
167 175
@@ -170,8 +178,9 @@ acpi_ex_acquire_mutex (
170 * mutex. This mechanism provides some deadlock prevention 178 * mutex. This mechanism provides some deadlock prevention
171 */ 179 */
172 if (walk_state->thread->current_sync_level > obj_desc->mutex.sync_level) { 180 if (walk_state->thread->current_sync_level > obj_desc->mutex.sync_level) {
173 ACPI_REPORT_ERROR (("Cannot acquire Mutex [%4.4s], incorrect sync_level\n", 181 ACPI_REPORT_ERROR ((
174 acpi_ut_get_node_name (obj_desc->mutex.node))); 182 "Cannot acquire Mutex [%4.4s], incorrect sync_level\n",
183 acpi_ut_get_node_name (obj_desc->mutex.node)));
175 return_ACPI_STATUS (AE_AML_MUTEX_ORDER); 184 return_ACPI_STATUS (AE_AML_MUTEX_ORDER);
176 } 185 }
177 186
@@ -180,8 +189,10 @@ acpi_ex_acquire_mutex (
180 if (obj_desc->mutex.owner_thread) { 189 if (obj_desc->mutex.owner_thread) {
181 /* Special case for Global Lock, allow all threads */ 190 /* Special case for Global Lock, allow all threads */
182 191
183 if ((obj_desc->mutex.owner_thread->thread_id == walk_state->thread->thread_id) || 192 if ((obj_desc->mutex.owner_thread->thread_id ==
184 (obj_desc->mutex.semaphore == acpi_gbl_global_lock_semaphore)) { 193 walk_state->thread->thread_id) ||
194 (obj_desc->mutex.semaphore ==
195 acpi_gbl_global_lock_semaphore)) {
185 /* 196 /*
186 * The mutex is already owned by this thread, 197 * The mutex is already owned by this thread,
187 * just increment the acquisition depth 198 * just increment the acquisition depth
@@ -221,6 +232,7 @@ acpi_ex_acquire_mutex (
221 * FUNCTION: acpi_ex_release_mutex 232 * FUNCTION: acpi_ex_release_mutex
222 * 233 *
223 * PARAMETERS: obj_desc - The object descriptor for this op 234 * PARAMETERS: obj_desc - The object descriptor for this op
235 * walk_state - Current method execution state
224 * 236 *
225 * RETURN: Status 237 * RETURN: Status
226 * 238 *
@@ -278,8 +290,9 @@ acpi_ex_release_mutex (
278 * equal to the current sync level 290 * equal to the current sync level
279 */ 291 */
280 if (obj_desc->mutex.sync_level > walk_state->thread->current_sync_level) { 292 if (obj_desc->mutex.sync_level > walk_state->thread->current_sync_level) {
281 ACPI_REPORT_ERROR (("Cannot release Mutex [%4.4s], incorrect sync_level\n", 293 ACPI_REPORT_ERROR ((
282 acpi_ut_get_node_name (obj_desc->mutex.node))); 294 "Cannot release Mutex [%4.4s], incorrect sync_level\n",
295 acpi_ut_get_node_name (obj_desc->mutex.node)));
283 return_ACPI_STATUS (AE_AML_MUTEX_ORDER); 296 return_ACPI_STATUS (AE_AML_MUTEX_ORDER);
284 } 297 }
285 298
@@ -313,11 +326,11 @@ acpi_ex_release_mutex (
313 * 326 *
314 * FUNCTION: acpi_ex_release_all_mutexes 327 * FUNCTION: acpi_ex_release_all_mutexes
315 * 328 *
316 * PARAMETERS: mutex_list - Head of the mutex list 329 * PARAMETERS: Thread - Current executing thread object
317 * 330 *
318 * RETURN: Status 331 * RETURN: Status
319 * 332 *
320 * DESCRIPTION: Release all mutexes in the list 333 * DESCRIPTION: Release all mutexes held by this thread
321 * 334 *
322 ******************************************************************************/ 335 ******************************************************************************/
323 336
diff --git a/drivers/acpi/executer/exnames.c b/drivers/acpi/executer/exnames.c
index 7911c533c265..639f0bd3f6d8 100644
--- a/drivers/acpi/executer/exnames.c
+++ b/drivers/acpi/executer/exnames.c
@@ -50,13 +50,17 @@
50#define _COMPONENT ACPI_EXECUTER 50#define _COMPONENT ACPI_EXECUTER
51 ACPI_MODULE_NAME ("exnames") 51 ACPI_MODULE_NAME ("exnames")
52 52
53/* Local prototypes */
53 54
54/* AML Package Length encodings */ 55static char *
56acpi_ex_allocate_name_string (
57 u32 prefix_count,
58 u32 num_name_segs);
55 59
56#define ACPI_AML_PACKAGE_TYPE1 0x40 60static acpi_status
57#define ACPI_AML_PACKAGE_TYPE2 0x4000 61acpi_ex_name_segment (
58#define ACPI_AML_PACKAGE_TYPE3 0x400000 62 u8 **in_aml_address,
59#define ACPI_AML_PACKAGE_TYPE4 0x40000000 63 char *name_string);
60 64
61 65
62/******************************************************************************* 66/*******************************************************************************
@@ -64,7 +68,7 @@
64 * FUNCTION: acpi_ex_allocate_name_string 68 * FUNCTION: acpi_ex_allocate_name_string
65 * 69 *
66 * PARAMETERS: prefix_count - Count of parent levels. Special cases: 70 * PARAMETERS: prefix_count - Count of parent levels. Special cases:
67 * (-1) = root, 0 = none 71 * (-1)==root, 0==none
68 * num_name_segs - count of 4-character name segments 72 * num_name_segs - count of 4-character name segments
69 * 73 *
70 * RETURN: A pointer to the allocated string segment. This segment must 74 * RETURN: A pointer to the allocated string segment. This segment must
@@ -75,7 +79,7 @@
75 * 79 *
76 ******************************************************************************/ 80 ******************************************************************************/
77 81
78char * 82static char *
79acpi_ex_allocate_name_string ( 83acpi_ex_allocate_name_string (
80 u32 prefix_count, 84 u32 prefix_count,
81 u32 num_name_segs) 85 u32 num_name_segs)
@@ -88,7 +92,7 @@ acpi_ex_allocate_name_string (
88 92
89 93
90 /* 94 /*
91 * Allow room for all \ and ^ prefixes, all segments, and a multi_name_prefix. 95 * Allow room for all \ and ^ prefixes, all segments and a multi_name_prefix.
92 * Also, one byte for the null terminator. 96 * Also, one byte for the null terminator.
93 * This may actually be somewhat longer than needed. 97 * This may actually be somewhat longer than needed.
94 */ 98 */
@@ -107,7 +111,8 @@ acpi_ex_allocate_name_string (
107 */ 111 */
108 name_string = ACPI_MEM_ALLOCATE (size_needed); 112 name_string = ACPI_MEM_ALLOCATE (size_needed);
109 if (!name_string) { 113 if (!name_string) {
110 ACPI_REPORT_ERROR (("ex_allocate_name_string: Could not allocate size %d\n", size_needed)); 114 ACPI_REPORT_ERROR ((
115 "ex_allocate_name_string: Could not allocate size %d\n", size_needed));
111 return_PTR (NULL); 116 return_PTR (NULL);
112 } 117 }
113 118
@@ -152,15 +157,17 @@ acpi_ex_allocate_name_string (
152 * 157 *
153 * FUNCTION: acpi_ex_name_segment 158 * FUNCTION: acpi_ex_name_segment
154 * 159 *
155 * PARAMETERS: interpreter_mode - Current running mode (load1/Load2/Exec) 160 * PARAMETERS: in_aml_address - Pointer to the name in the AML code
161 * name_string - Where to return the name. The name is appended
162 * to any existing string to form a namepath
156 * 163 *
157 * RETURN: Status 164 * RETURN: Status
158 * 165 *
159 * DESCRIPTION: Execute a name segment (4 bytes) 166 * DESCRIPTION: Extract an ACPI name (4 bytes) from the AML byte stream
160 * 167 *
161 ******************************************************************************/ 168 ******************************************************************************/
162 169
163acpi_status 170static acpi_status
164acpi_ex_name_segment ( 171acpi_ex_name_segment (
165 u8 **in_aml_address, 172 u8 **in_aml_address,
166 char *name_string) 173 char *name_string)
@@ -223,10 +230,13 @@ acpi_ex_name_segment (
223 status = AE_CTRL_PENDING; 230 status = AE_CTRL_PENDING;
224 } 231 }
225 else { 232 else {
226 /* Segment started with one or more valid characters, but fewer than 4 */ 233 /*
227 234 * Segment started with one or more valid characters, but fewer than
235 * the required 4
236 */
228 status = AE_AML_BAD_NAME; 237 status = AE_AML_BAD_NAME;
229 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Bad character %02x in name, at %p\n", 238 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
239 "Bad character %02x in name, at %p\n",
230 *aml_address, aml_address)); 240 *aml_address, aml_address));
231 } 241 }
232 242
@@ -239,11 +249,16 @@ acpi_ex_name_segment (
239 * 249 *
240 * FUNCTION: acpi_ex_get_name_string 250 * FUNCTION: acpi_ex_get_name_string
241 * 251 *
242 * PARAMETERS: data_type - Data type to be associated with this name 252 * PARAMETERS: data_type - Object type to be associated with this
253 * name
254 * in_aml_address - Pointer to the namestring in the AML code
255 * out_name_string - Where the namestring is returned
256 * out_name_length - Length of the returned string
243 * 257 *
244 * RETURN: Status 258 * RETURN: Status, namestring and length
245 * 259 *
246 * DESCRIPTION: Get a name, including any prefixes. 260 * DESCRIPTION: Extract a full namepath from the AML byte stream,
261 * including any prefixes.
247 * 262 *
248 ******************************************************************************/ 263 ******************************************************************************/
249 264
@@ -286,7 +301,8 @@ acpi_ex_get_name_string (
286 switch (*aml_address) { 301 switch (*aml_address) {
287 case AML_ROOT_PREFIX: 302 case AML_ROOT_PREFIX:
288 303
289 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "root_prefix(\\) at %p\n", aml_address)); 304 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "root_prefix(\\) at %p\n",
305 aml_address));
290 306
291 /* 307 /*
292 * Remember that we have a root_prefix -- 308 * Remember that we have a root_prefix --
@@ -303,7 +319,8 @@ acpi_ex_get_name_string (
303 /* Increment past possibly multiple parent prefixes */ 319 /* Increment past possibly multiple parent prefixes */
304 320
305 do { 321 do {
306 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "parent_prefix (^) at %p\n", aml_address)); 322 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "parent_prefix (^) at %p\n",
323 aml_address));
307 324
308 aml_address++; 325 aml_address++;
309 prefix_count++; 326 prefix_count++;
@@ -321,13 +338,13 @@ acpi_ex_get_name_string (
321 break; 338 break;
322 } 339 }
323 340
324
325 /* Examine first character of name for name segment prefix operator */ 341 /* Examine first character of name for name segment prefix operator */
326 342
327 switch (*aml_address) { 343 switch (*aml_address) {
328 case AML_DUAL_NAME_PREFIX: 344 case AML_DUAL_NAME_PREFIX:
329 345
330 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "dual_name_prefix at %p\n", aml_address)); 346 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "dual_name_prefix at %p\n",
347 aml_address));
331 348
332 aml_address++; 349 aml_address++;
333 name_string = acpi_ex_allocate_name_string (prefix_count, 2); 350 name_string = acpi_ex_allocate_name_string (prefix_count, 2);
@@ -349,7 +366,8 @@ acpi_ex_get_name_string (
349 366
350 case AML_MULTI_NAME_PREFIX_OP: 367 case AML_MULTI_NAME_PREFIX_OP:
351 368
352 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "multi_name_prefix at %p\n", aml_address)); 369 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "multi_name_prefix at %p\n",
370 aml_address));
353 371
354 /* Fetch count of segments remaining in name path */ 372 /* Fetch count of segments remaining in name path */
355 373
@@ -368,7 +386,8 @@ acpi_ex_get_name_string (
368 has_prefix = TRUE; 386 has_prefix = TRUE;
369 387
370 while (num_segments && 388 while (num_segments &&
371 (status = acpi_ex_name_segment (&aml_address, name_string)) == AE_OK) { 389 (status = acpi_ex_name_segment (&aml_address, name_string)) ==
390 AE_OK) {
372 num_segments--; 391 num_segments--;
373 } 392 }
374 393
@@ -380,7 +399,8 @@ acpi_ex_get_name_string (
380 /* null_name valid as of 8-12-98 ASL/AML Grammar Update */ 399 /* null_name valid as of 8-12-98 ASL/AML Grammar Update */
381 400
382 if (prefix_count == ACPI_UINT32_MAX) { 401 if (prefix_count == ACPI_UINT32_MAX) {
383 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "name_seg is \"\\\" followed by NULL\n")); 402 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
403 "name_seg is \"\\\" followed by NULL\n"));
384 } 404 }
385 405
386 /* Consume the NULL byte */ 406 /* Consume the NULL byte */
diff --git a/drivers/acpi/executer/exoparg1.c b/drivers/acpi/executer/exoparg1.c
index 8482aefaf38b..dbdf8262ba00 100644
--- a/drivers/acpi/executer/exoparg1.c
+++ b/drivers/acpi/executer/exoparg1.c
@@ -97,7 +97,8 @@ acpi_ex_opcode_0A_0T_1R (
97 union acpi_operand_object *return_desc = NULL; 97 union acpi_operand_object *return_desc = NULL;
98 98
99 99
100 ACPI_FUNCTION_TRACE_STR ("ex_opcode_0A_0T_1R", acpi_ps_get_opcode_name (walk_state->opcode)); 100 ACPI_FUNCTION_TRACE_STR ("ex_opcode_0A_0T_1R",
101 acpi_ps_get_opcode_name (walk_state->opcode));
101 102
102 103
103 /* Examine the AML opcode */ 104 /* Examine the AML opcode */
@@ -161,7 +162,8 @@ acpi_ex_opcode_1A_0T_0R (
161 acpi_status status = AE_OK; 162 acpi_status status = AE_OK;
162 163
163 164
164 ACPI_FUNCTION_TRACE_STR ("ex_opcode_1A_0T_0R", acpi_ps_get_opcode_name (walk_state->opcode)); 165 ACPI_FUNCTION_TRACE_STR ("ex_opcode_1A_0T_0R",
166 acpi_ps_get_opcode_name (walk_state->opcode));
165 167
166 168
167 /* Examine the AML opcode */ 169 /* Examine the AML opcode */
@@ -236,7 +238,8 @@ acpi_ex_opcode_1A_1T_0R (
236 union acpi_operand_object **operand = &walk_state->operands[0]; 238 union acpi_operand_object **operand = &walk_state->operands[0];
237 239
238 240
239 ACPI_FUNCTION_TRACE_STR ("ex_opcode_1A_1T_0R", acpi_ps_get_opcode_name (walk_state->opcode)); 241 ACPI_FUNCTION_TRACE_STR ("ex_opcode_1A_1T_0R",
242 acpi_ps_get_opcode_name (walk_state->opcode));
240 243
241 244
242 /* Examine the AML opcode */ 245 /* Examine the AML opcode */
@@ -289,7 +292,8 @@ acpi_ex_opcode_1A_1T_1R (
289 acpi_integer digit; 292 acpi_integer digit;
290 293
291 294
292 ACPI_FUNCTION_TRACE_STR ("ex_opcode_1A_1T_1R", acpi_ps_get_opcode_name (walk_state->opcode)); 295 ACPI_FUNCTION_TRACE_STR ("ex_opcode_1A_1T_1R",
296 acpi_ps_get_opcode_name (walk_state->opcode));
293 297
294 298
295 /* Examine the AML opcode */ 299 /* Examine the AML opcode */
@@ -409,8 +413,10 @@ acpi_ex_opcode_1A_1T_1R (
409 for (i = 0; (i < acpi_gbl_integer_nybble_width) && (digit > 0); i++) { 413 for (i = 0; (i < acpi_gbl_integer_nybble_width) && (digit > 0); i++) {
410 (void) acpi_ut_short_divide (digit, 10, &digit, &temp32); 414 (void) acpi_ut_short_divide (digit, 10, &digit, &temp32);
411 415
412 /* Insert the BCD digit that resides in the remainder from above */ 416 /*
413 417 * Insert the BCD digit that resides in the
418 * remainder from above
419 */
414 return_desc->integer.value |= (((acpi_integer) temp32) << 420 return_desc->integer.value |= (((acpi_integer) temp32) <<
415 ACPI_MUL_4 (i)); 421 ACPI_MUL_4 (i));
416 } 422 }
@@ -445,7 +451,8 @@ acpi_ex_opcode_1A_1T_1R (
445 451
446 /* Get the object reference, store it, and remove our reference */ 452 /* Get the object reference, store it, and remove our reference */
447 453
448 status = acpi_ex_get_object_reference (operand[0], &return_desc2, walk_state); 454 status = acpi_ex_get_object_reference (operand[0],
455 &return_desc2, walk_state);
449 if (ACPI_FAILURE (status)) { 456 if (ACPI_FAILURE (status)) {
450 goto cleanup; 457 goto cleanup;
451 } 458 }
@@ -482,10 +489,10 @@ acpi_ex_opcode_1A_1T_1R (
482 489
483 if (!walk_state->result_obj) { 490 if (!walk_state->result_obj) {
484 /* 491 /*
485 * Normally, we would remove a reference on the Operand[0] parameter; 492 * Normally, we would remove a reference on the Operand[0]
486 * But since it is being used as the internal return object 493 * parameter; But since it is being used as the internal return
487 * (meaning we would normally increment it), the two cancel out, 494 * object (meaning we would normally increment it), the two
488 * and we simply don't do anything. 495 * cancel out, and we simply don't do anything.
489 */ 496 */
490 walk_state->result_obj = operand[0]; 497 walk_state->result_obj = operand[0];
491 walk_state->operands[0] = NULL; /* Prevent deletion */ 498 walk_state->operands[0] = NULL; /* Prevent deletion */
@@ -549,9 +556,8 @@ acpi_ex_opcode_1A_1T_1R (
549 case AML_SHIFT_LEFT_BIT_OP: /* shift_left_bit (Source, bit_num) */ 556 case AML_SHIFT_LEFT_BIT_OP: /* shift_left_bit (Source, bit_num) */
550 case AML_SHIFT_RIGHT_BIT_OP: /* shift_right_bit (Source, bit_num) */ 557 case AML_SHIFT_RIGHT_BIT_OP: /* shift_right_bit (Source, bit_num) */
551 558
552 /* 559 /* These are two obsolete opcodes */
553 * These are two obsolete opcodes 560
554 */
555 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 561 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
556 "%s is obsolete and not implemented\n", 562 "%s is obsolete and not implemented\n",
557 acpi_ps_get_opcode_name (walk_state->opcode))); 563 acpi_ps_get_opcode_name (walk_state->opcode)));
@@ -568,9 +574,8 @@ acpi_ex_opcode_1A_1T_1R (
568 } 574 }
569 575
570 if (ACPI_SUCCESS (status)) { 576 if (ACPI_SUCCESS (status)) {
571 /* 577 /* Store the return value computed above into the target object */
572 * Store the return value computed above into the target object 578
573 */
574 status = acpi_ex_store (return_desc, operand[1], walk_state); 579 status = acpi_ex_store (return_desc, operand[1], walk_state);
575 } 580 }
576 581
@@ -615,7 +620,8 @@ acpi_ex_opcode_1A_0T_1R (
615 acpi_integer value; 620 acpi_integer value;
616 621
617 622
618 ACPI_FUNCTION_TRACE_STR ("ex_opcode_1A_0T_1R", acpi_ps_get_opcode_name (walk_state->opcode)); 623 ACPI_FUNCTION_TRACE_STR ("ex_opcode_1A_0T_1R",
624 acpi_ps_get_opcode_name (walk_state->opcode));
619 625
620 626
621 /* Examine the AML opcode */ 627 /* Examine the AML opcode */
@@ -706,9 +712,9 @@ acpi_ex_opcode_1A_0T_1R (
706 712
707 /* 713 /*
708 * Note: The operand is not resolved at this point because we want to 714 * Note: The operand is not resolved at this point because we want to
709 * get the associated object, not its value. For example, we don't want 715 * get the associated object, not its value. For example, we don't
710 * to resolve a field_unit to its value, we want the actual field_unit 716 * want to resolve a field_unit to its value, we want the actual
711 * object. 717 * field_unit object.
712 */ 718 */
713 719
714 /* Get the type of the base object */ 720 /* Get the type of the base object */
@@ -738,7 +744,8 @@ acpi_ex_opcode_1A_0T_1R (
738 744
739 /* Get the base object */ 745 /* Get the base object */
740 746
741 status = acpi_ex_resolve_multiple (walk_state, operand[0], &type, &temp_desc); 747 status = acpi_ex_resolve_multiple (walk_state,
748 operand[0], &type, &temp_desc);
742 if (ACPI_FAILURE (status)) { 749 if (ACPI_FAILURE (status)) {
743 goto cleanup; 750 goto cleanup;
744 } 751 }
@@ -818,8 +825,10 @@ acpi_ex_opcode_1A_0T_1R (
818 825
819 /* Set Operand[0] to the value of the local/arg */ 826 /* Set Operand[0] to the value of the local/arg */
820 827
821 status = acpi_ds_method_data_get_value (operand[0]->reference.opcode, 828 status = acpi_ds_method_data_get_value (
822 operand[0]->reference.offset, walk_state, &temp_desc); 829 operand[0]->reference.opcode,
830 operand[0]->reference.offset,
831 walk_state, &temp_desc);
823 if (ACPI_FAILURE (status)) { 832 if (ACPI_FAILURE (status)) {
824 goto cleanup; 833 goto cleanup;
825 } 834 }
@@ -852,21 +861,26 @@ acpi_ex_opcode_1A_0T_1R (
852 case ACPI_TYPE_STRING: 861 case ACPI_TYPE_STRING:
853 862
854 /* 863 /*
855 * This is a deref_of (String). The string is a reference to a named ACPI object. 864 * This is a deref_of (String). The string is a reference
865 * to a named ACPI object.
856 * 866 *
857 * 1) Find the owning Node 867 * 1) Find the owning Node
858 * 2) Dereference the node to an actual object. Could be a Field, so we nee 868 * 2) Dereference the node to an actual object. Could be a
859 * to resolve the node to a value. 869 * Field, so we need to resolve the node to a value.
860 */ 870 */
861 status = acpi_ns_get_node_by_path (operand[0]->string.pointer, 871 status = acpi_ns_get_node_by_path (operand[0]->string.pointer,
862 walk_state->scope_info->scope.node, ACPI_NS_SEARCH_PARENT, 872 walk_state->scope_info->scope.node,
863 ACPI_CAST_INDIRECT_PTR (struct acpi_namespace_node, &return_desc)); 873 ACPI_NS_SEARCH_PARENT,
874 ACPI_CAST_INDIRECT_PTR (
875 struct acpi_namespace_node, &return_desc));
864 if (ACPI_FAILURE (status)) { 876 if (ACPI_FAILURE (status)) {
865 goto cleanup; 877 goto cleanup;
866 } 878 }
867 879
868 status = acpi_ex_resolve_node_to_value ( 880 status = acpi_ex_resolve_node_to_value (
869 ACPI_CAST_INDIRECT_PTR (struct acpi_namespace_node, &return_desc), walk_state); 881 ACPI_CAST_INDIRECT_PTR (
882 struct acpi_namespace_node, &return_desc),
883 walk_state);
870 goto cleanup; 884 goto cleanup;
871 885
872 886
@@ -883,14 +897,16 @@ acpi_ex_opcode_1A_0T_1R (
883 /* 897 /*
884 * This is a deref_of (object_reference) 898 * This is a deref_of (object_reference)
885 * Get the actual object from the Node (This is the dereference). 899 * Get the actual object from the Node (This is the dereference).
886 * -- This case may only happen when a local_x or arg_x is dereferenced above. 900 * This case may only happen when a local_x or arg_x is
901 * dereferenced above.
887 */ 902 */
888 return_desc = acpi_ns_get_attached_object ((struct acpi_namespace_node *) operand[0]); 903 return_desc = acpi_ns_get_attached_object (
904 (struct acpi_namespace_node *) operand[0]);
889 } 905 }
890 else { 906 else {
891 /* 907 /*
892 * This must be a reference object produced by either the Index() or 908 * This must be a reference object produced by either the
893 * ref_of() operator 909 * Index() or ref_of() operator
894 */ 910 */
895 switch (operand[0]->reference.opcode) { 911 switch (operand[0]->reference.opcode) {
896 case AML_INDEX_OP: 912 case AML_INDEX_OP:
@@ -931,8 +947,8 @@ acpi_ex_opcode_1A_0T_1R (
931 case ACPI_TYPE_PACKAGE: 947 case ACPI_TYPE_PACKAGE:
932 948
933 /* 949 /*
934 * Return the referenced element of the package. We must add 950 * Return the referenced element of the package. We must
935 * another reference to the referenced object, however. 951 * add another reference to the referenced object, however.
936 */ 952 */
937 return_desc = *(operand[0]->reference.where); 953 return_desc = *(operand[0]->reference.where);
938 if (!return_desc) { 954 if (!return_desc) {
@@ -967,9 +983,11 @@ acpi_ex_opcode_1A_0T_1R (
967 983
968 return_desc = operand[0]->reference.object; 984 return_desc = operand[0]->reference.object;
969 985
970 if (ACPI_GET_DESCRIPTOR_TYPE (return_desc) == ACPI_DESC_TYPE_NAMED) { 986 if (ACPI_GET_DESCRIPTOR_TYPE (return_desc) ==
987 ACPI_DESC_TYPE_NAMED) {
971 988
972 return_desc = acpi_ns_get_attached_object ((struct acpi_namespace_node *) return_desc); 989 return_desc = acpi_ns_get_attached_object (
990 (struct acpi_namespace_node *) return_desc);
973 } 991 }
974 992
975 /* Add another reference to the object! */ 993 /* Add another reference to the object! */
diff --git a/drivers/acpi/executer/exoparg2.c b/drivers/acpi/executer/exoparg2.c
index 8be4d80ceed5..7429032c2b6c 100644
--- a/drivers/acpi/executer/exoparg2.c
+++ b/drivers/acpi/executer/exoparg2.c
@@ -118,7 +118,7 @@ acpi_ex_opcode_2A_0T_0R (
118 118
119 value = (u32) operand[1]->integer.value; 119 value = (u32) operand[1]->integer.value;
120 120
121 /* Notifies allowed on this object? */ 121 /* Are notifies allowed on this object? */
122 122
123 if (!acpi_ev_is_notify_object (node)) { 123 if (!acpi_ev_is_notify_object (node)) {
124 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 124 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
@@ -203,11 +203,12 @@ acpi_ex_opcode_2A_2T_1R (
203 acpi_ps_get_opcode_name (walk_state->opcode)); 203 acpi_ps_get_opcode_name (walk_state->opcode));
204 204
205 205
206 /* 206 /* Execute the opcode */
207 * Execute the opcode 207
208 */
209 switch (walk_state->opcode) { 208 switch (walk_state->opcode) {
210 case AML_DIVIDE_OP: /* Divide (Dividend, Divisor, remainder_result quotient_result) */ 209 case AML_DIVIDE_OP:
210
211 /* Divide (Dividend, Divisor, remainder_result quotient_result) */
211 212
212 return_desc1 = acpi_ut_create_internal_object (ACPI_TYPE_INTEGER); 213 return_desc1 = acpi_ut_create_internal_object (ACPI_TYPE_INTEGER);
213 if (!return_desc1) { 214 if (!return_desc1) {
@@ -241,7 +242,6 @@ acpi_ex_opcode_2A_2T_1R (
241 goto cleanup; 242 goto cleanup;
242 } 243 }
243 244
244
245 /* Store the results to the target reference operands */ 245 /* Store the results to the target reference operands */
246 246
247 status = acpi_ex_store (return_desc2, operand[2], walk_state); 247 status = acpi_ex_store (return_desc2, operand[2], walk_state);
@@ -295,7 +295,7 @@ acpi_ex_opcode_2A_1T_1R (
295{ 295{
296 union acpi_operand_object **operand = &walk_state->operands[0]; 296 union acpi_operand_object **operand = &walk_state->operands[0];
297 union acpi_operand_object *return_desc = NULL; 297 union acpi_operand_object *return_desc = NULL;
298 u32 index; 298 acpi_integer index;
299 acpi_status status = AE_OK; 299 acpi_status status = AE_OK;
300 acpi_size length; 300 acpi_size length;
301 301
@@ -304,9 +304,8 @@ acpi_ex_opcode_2A_1T_1R (
304 acpi_ps_get_opcode_name (walk_state->opcode)); 304 acpi_ps_get_opcode_name (walk_state->opcode));
305 305
306 306
307 /* 307 /* Execute the opcode */
308 * Execute the opcode 308
309 */
310 if (walk_state->op_info->flags & AML_MATH) { 309 if (walk_state->op_info->flags & AML_MATH) {
311 /* All simple math opcodes (add, etc.) */ 310 /* All simple math opcodes (add, etc.) */
312 311
@@ -322,9 +321,8 @@ acpi_ex_opcode_2A_1T_1R (
322 goto store_result_to_target; 321 goto store_result_to_target;
323 } 322 }
324 323
325
326 switch (walk_state->opcode) { 324 switch (walk_state->opcode) {
327 case AML_MOD_OP: /* Mod (Dividend, Divisor, remainder_result (ACPI 2.0) */ 325 case AML_MOD_OP: /* Mod (Dividend, Divisor, remainder_result (ACPI 2.0) */
328 326
329 return_desc = acpi_ut_create_internal_object (ACPI_TYPE_INTEGER); 327 return_desc = acpi_ut_create_internal_object (ACPI_TYPE_INTEGER);
330 if (!return_desc) { 328 if (!return_desc) {
@@ -341,18 +339,19 @@ acpi_ex_opcode_2A_1T_1R (
341 break; 339 break;
342 340
343 341
344 case AML_CONCAT_OP: /* Concatenate (Data1, Data2, Result) */ 342 case AML_CONCAT_OP: /* Concatenate (Data1, Data2, Result) */
345 343
346 status = acpi_ex_do_concatenate (operand[0], operand[1], 344 status = acpi_ex_do_concatenate (operand[0], operand[1],
347 &return_desc, walk_state); 345 &return_desc, walk_state);
348 break; 346 break;
349 347
350 348
351 case AML_TO_STRING_OP: /* to_string (Buffer, Length, Result) (ACPI 2.0) */ 349 case AML_TO_STRING_OP: /* to_string (Buffer, Length, Result) (ACPI 2.0) */
352 350
353 /* 351 /*
354 * Input object is guaranteed to be a buffer at this point (it may have 352 * Input object is guaranteed to be a buffer at this point (it may have
355 * been converted.) Copy the raw buffer data to a new object of type String. 353 * been converted.) Copy the raw buffer data to a new object of
354 * type String.
356 */ 355 */
357 356
358 /* 357 /*
@@ -383,14 +382,16 @@ acpi_ex_opcode_2A_1T_1R (
383 goto cleanup; 382 goto cleanup;
384 } 383 }
385 384
386 /* Copy the raw buffer data with no transform. NULL terminated already. */ 385 /* Copy the raw buffer data with no transform. NULL terminated already*/
387 386
388 ACPI_MEMCPY (return_desc->string.pointer, 387 ACPI_MEMCPY (return_desc->string.pointer,
389 operand[0]->buffer.pointer, length); 388 operand[0]->buffer.pointer, length);
390 break; 389 break;
391 390
392 391
393 case AML_CONCAT_RES_OP: /* concatenate_res_template (Buffer, Buffer, Result) (ACPI 2.0) */ 392 case AML_CONCAT_RES_OP:
393
394 /* concatenate_res_template (Buffer, Buffer, Result) (ACPI 2.0) */
394 395
395 status = acpi_ex_concat_template (operand[0], operand[1], 396 status = acpi_ex_concat_template (operand[0], operand[1],
396 &return_desc, walk_state); 397 &return_desc, walk_state);
@@ -407,33 +408,33 @@ acpi_ex_opcode_2A_1T_1R (
407 goto cleanup; 408 goto cleanup;
408 } 409 }
409 410
410 index = (u32) operand[1]->integer.value; 411 index = operand[1]->integer.value;
412
413 /* At this point, the Source operand is a Package, Buffer, or String */
411 414
412 /*
413 * At this point, the Source operand is a Package, Buffer, or String
414 */
415 if (ACPI_GET_OBJECT_TYPE (operand[0]) == ACPI_TYPE_PACKAGE) { 415 if (ACPI_GET_OBJECT_TYPE (operand[0]) == ACPI_TYPE_PACKAGE) {
416 /* Object to be indexed is a Package */ 416 /* Object to be indexed is a Package */
417 417
418 if (index >= operand[0]->package.count) { 418 if (index >= operand[0]->package.count) {
419 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 419 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
420 "Index value (%X) beyond package end (%X)\n", 420 "Index value (%X%8.8X) beyond package end (%X)\n",
421 index, operand[0]->package.count)); 421 ACPI_FORMAT_UINT64 (index), operand[0]->package.count));
422 status = AE_AML_PACKAGE_LIMIT; 422 status = AE_AML_PACKAGE_LIMIT;
423 goto cleanup; 423 goto cleanup;
424 } 424 }
425 425
426 return_desc->reference.target_type = ACPI_TYPE_PACKAGE; 426 return_desc->reference.target_type = ACPI_TYPE_PACKAGE;
427 return_desc->reference.object = operand[0]; 427 return_desc->reference.object = operand[0];
428 return_desc->reference.where = &operand[0]->package.elements [index]; 428 return_desc->reference.where = &operand[0]->package.elements [
429 index];
429 } 430 }
430 else { 431 else {
431 /* Object to be indexed is a Buffer/String */ 432 /* Object to be indexed is a Buffer/String */
432 433
433 if (index >= operand[0]->buffer.length) { 434 if (index >= operand[0]->buffer.length) {
434 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 435 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
435 "Index value (%X) beyond end of buffer (%X)\n", 436 "Index value (%X%8.8X) beyond end of buffer (%X)\n",
436 index, operand[0]->buffer.length)); 437 ACPI_FORMAT_UINT64 (index), operand[0]->buffer.length));
437 status = AE_AML_BUFFER_LIMIT; 438 status = AE_AML_BUFFER_LIMIT;
438 goto cleanup; 439 goto cleanup;
439 } 440 }
@@ -451,7 +452,7 @@ acpi_ex_opcode_2A_1T_1R (
451 /* Complete the Index reference object */ 452 /* Complete the Index reference object */
452 453
453 return_desc->reference.opcode = AML_INDEX_OP; 454 return_desc->reference.opcode = AML_INDEX_OP;
454 return_desc->reference.offset = index; 455 return_desc->reference.offset = (u32) index;
455 456
456 /* Store the reference to the Target */ 457 /* Store the reference to the Target */
457 458
@@ -536,22 +537,24 @@ acpi_ex_opcode_2A_0T_1R (
536 goto cleanup; 537 goto cleanup;
537 } 538 }
538 539
539 /* 540 /* Execute the Opcode */
540 * Execute the Opcode 541
541 */ 542 if (walk_state->op_info->flags & AML_LOGICAL_NUMERIC) {
542 if (walk_state->op_info->flags & AML_LOGICAL_NUMERIC) /* logical_op (Operand0, Operand1) */ { 543 /* logical_op (Operand0, Operand1) */
544
543 status = acpi_ex_do_logical_numeric_op (walk_state->opcode, 545 status = acpi_ex_do_logical_numeric_op (walk_state->opcode,
544 operand[0]->integer.value, operand[1]->integer.value, 546 operand[0]->integer.value, operand[1]->integer.value,
545 &logical_result); 547 &logical_result);
546 goto store_logical_result; 548 goto store_logical_result;
547 } 549 }
548 else if (walk_state->op_info->flags & AML_LOGICAL) /* logical_op (Operand0, Operand1) */ { 550 else if (walk_state->op_info->flags & AML_LOGICAL) {
551 /* logical_op (Operand0, Operand1) */
552
549 status = acpi_ex_do_logical_op (walk_state->opcode, operand[0], 553 status = acpi_ex_do_logical_op (walk_state->opcode, operand[0],
550 operand[1], &logical_result); 554 operand[1], &logical_result);
551 goto store_logical_result; 555 goto store_logical_result;
552 } 556 }
553 557
554
555 switch (walk_state->opcode) { 558 switch (walk_state->opcode) {
556 case AML_ACQUIRE_OP: /* Acquire (mutex_object, Timeout) */ 559 case AML_ACQUIRE_OP: /* Acquire (mutex_object, Timeout) */
557 560
diff --git a/drivers/acpi/executer/exoparg3.c b/drivers/acpi/executer/exoparg3.c
index 29d0b167745d..23b068adbf58 100644
--- a/drivers/acpi/executer/exoparg3.c
+++ b/drivers/acpi/executer/exoparg3.c
@@ -97,11 +97,12 @@ acpi_ex_opcode_3A_0T_0R (
97 acpi_status status = AE_OK; 97 acpi_status status = AE_OK;
98 98
99 99
100 ACPI_FUNCTION_TRACE_STR ("ex_opcode_3A_0T_0R", acpi_ps_get_opcode_name (walk_state->opcode)); 100 ACPI_FUNCTION_TRACE_STR ("ex_opcode_3A_0T_0R",
101 acpi_ps_get_opcode_name (walk_state->opcode));
101 102
102 103
103 switch (walk_state->opcode) { 104 switch (walk_state->opcode) {
104 case AML_FATAL_OP: /* Fatal (fatal_type fatal_code fatal_arg) */ 105 case AML_FATAL_OP: /* Fatal (fatal_type fatal_code fatal_arg) */
105 106
106 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, 107 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
107 "fatal_op: Type %X Code %X Arg %X <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n", 108 "fatal_op: Type %X Code %X Arg %X <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n",
@@ -116,9 +117,8 @@ acpi_ex_opcode_3A_0T_0R (
116 fatal->argument = (u32) operand[2]->integer.value; 117 fatal->argument = (u32) operand[2]->integer.value;
117 } 118 }
118 119
119 /* 120 /* Always signal the OS! */
120 * Always signal the OS! 121
121 */
122 status = acpi_os_signal (ACPI_SIGNAL_FATAL, fatal); 122 status = acpi_os_signal (ACPI_SIGNAL_FATAL, fatal);
123 123
124 /* Might return while OS is shutting down, just continue */ 124 /* Might return while OS is shutting down, just continue */
@@ -162,21 +162,23 @@ acpi_ex_opcode_3A_1T_1R (
162 union acpi_operand_object *return_desc = NULL; 162 union acpi_operand_object *return_desc = NULL;
163 char *buffer; 163 char *buffer;
164 acpi_status status = AE_OK; 164 acpi_status status = AE_OK;
165 acpi_native_uint index; 165 acpi_integer index;
166 acpi_size length; 166 acpi_size length;
167 167
168 168
169 ACPI_FUNCTION_TRACE_STR ("ex_opcode_3A_1T_1R", acpi_ps_get_opcode_name (walk_state->opcode)); 169 ACPI_FUNCTION_TRACE_STR ("ex_opcode_3A_1T_1R",
170 acpi_ps_get_opcode_name (walk_state->opcode));
170 171
171 172
172 switch (walk_state->opcode) { 173 switch (walk_state->opcode) {
173 case AML_MID_OP: /* Mid (Source[0], Index[1], Length[2], Result[3]) */ 174 case AML_MID_OP: /* Mid (Source[0], Index[1], Length[2], Result[3]) */
174 175
175 /* 176 /*
176 * Create the return object. The Source operand is guaranteed to be 177 * Create the return object. The Source operand is guaranteed to be
177 * either a String or a Buffer, so just use its type. 178 * either a String or a Buffer, so just use its type.
178 */ 179 */
179 return_desc = acpi_ut_create_internal_object (ACPI_GET_OBJECT_TYPE (operand[0])); 180 return_desc = acpi_ut_create_internal_object (
181 ACPI_GET_OBJECT_TYPE (operand[0]));
180 if (!return_desc) { 182 if (!return_desc) {
181 status = AE_NO_MEMORY; 183 status = AE_NO_MEMORY;
182 goto cleanup; 184 goto cleanup;
@@ -184,7 +186,7 @@ acpi_ex_opcode_3A_1T_1R (
184 186
185 /* Get the Integer values from the objects */ 187 /* Get the Integer values from the objects */
186 188
187 index = (acpi_native_uint) operand[1]->integer.value; 189 index = operand[1]->integer.value;
188 length = (acpi_size) operand[2]->integer.value; 190 length = (acpi_size) operand[2]->integer.value;
189 191
190 /* 192 /*
@@ -197,7 +199,8 @@ acpi_ex_opcode_3A_1T_1R (
197 199
198 if ((index + length) > 200 if ((index + length) >
199 operand[0]->string.length) { 201 operand[0]->string.length) {
200 length = (acpi_size) operand[0]->string.length - index; 202 length = (acpi_size) operand[0]->string.length -
203 (acpi_size) index;
201 } 204 }
202 205
203 /* Allocate a new buffer for the String/Buffer */ 206 /* Allocate a new buffer for the String/Buffer */
diff --git a/drivers/acpi/executer/exoparg6.c b/drivers/acpi/executer/exoparg6.c
index d32624331626..17f81d42ee41 100644
--- a/drivers/acpi/executer/exoparg6.c
+++ b/drivers/acpi/executer/exoparg6.c
@@ -75,6 +75,14 @@
75 * fully resolved operands. 75 * fully resolved operands.
76!*/ 76!*/
77 77
78/* Local prototypes */
79
80static u8
81acpi_ex_do_match (
82 u32 match_op,
83 union acpi_operand_object *package_obj,
84 union acpi_operand_object *match_obj);
85
78 86
79/******************************************************************************* 87/*******************************************************************************
80 * 88 *
@@ -92,7 +100,7 @@
92 * 100 *
93 ******************************************************************************/ 101 ******************************************************************************/
94 102
95u8 103static u8
96acpi_ex_do_match ( 104acpi_ex_do_match (
97 u32 match_op, 105 u32 match_op,
98 union acpi_operand_object *package_obj, 106 union acpi_operand_object *package_obj,
@@ -216,11 +224,12 @@ acpi_ex_opcode_6A_0T_1R (
216 union acpi_operand_object **operand = &walk_state->operands[0]; 224 union acpi_operand_object **operand = &walk_state->operands[0];
217 union acpi_operand_object *return_desc = NULL; 225 union acpi_operand_object *return_desc = NULL;
218 acpi_status status = AE_OK; 226 acpi_status status = AE_OK;
219 u32 index; 227 acpi_integer index;
220 union acpi_operand_object *this_element; 228 union acpi_operand_object *this_element;
221 229
222 230
223 ACPI_FUNCTION_TRACE_STR ("ex_opcode_6A_0T_1R", acpi_ps_get_opcode_name (walk_state->opcode)); 231 ACPI_FUNCTION_TRACE_STR ("ex_opcode_6A_0T_1R",
232 acpi_ps_get_opcode_name (walk_state->opcode));
224 233
225 234
226 switch (walk_state->opcode) { 235 switch (walk_state->opcode) {
@@ -241,9 +250,11 @@ acpi_ex_opcode_6A_0T_1R (
241 250
242 /* Get the package start_index, validate against the package length */ 251 /* Get the package start_index, validate against the package length */
243 252
244 index = (u32) operand[5]->integer.value; 253 index = operand[5]->integer.value;
245 if (index >= (u32) operand[0]->package.count) { 254 if (index >= operand[0]->package.count) {
246 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Index beyond package end\n")); 255 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
256 "Index (%X%8.8X) beyond package end (%X)\n",
257 ACPI_FORMAT_UINT64 (index), operand[0]->package.count));
247 status = AE_AML_PACKAGE_LIMIT; 258 status = AE_AML_PACKAGE_LIMIT;
248 goto cleanup; 259 goto cleanup;
249 } 260 }
@@ -314,13 +325,12 @@ acpi_ex_opcode_6A_0T_1R (
314 325
315 default: 326 default:
316 327
317 ACPI_REPORT_ERROR (("acpi_ex_opcode_3A_0T_0R: Unknown opcode %X\n", 328 ACPI_REPORT_ERROR (("acpi_ex_opcode_6A_0T_1R: Unknown opcode %X\n",
318 walk_state->opcode)); 329 walk_state->opcode));
319 status = AE_AML_BAD_OPCODE; 330 status = AE_AML_BAD_OPCODE;
320 goto cleanup; 331 goto cleanup;
321 } 332 }
322 333
323
324 walk_state->result_obj = return_desc; 334 walk_state->result_obj = return_desc;
325 335
326 336
diff --git a/drivers/acpi/executer/exprep.c b/drivers/acpi/executer/exprep.c
index 264ef3bba31b..c9e3c68b5549 100644
--- a/drivers/acpi/executer/exprep.c
+++ b/drivers/acpi/executer/exprep.c
@@ -52,8 +52,23 @@
52#define _COMPONENT ACPI_EXECUTER 52#define _COMPONENT ACPI_EXECUTER
53 ACPI_MODULE_NAME ("exprep") 53 ACPI_MODULE_NAME ("exprep")
54 54
55/* Local prototypes */
56
57static u32
58acpi_ex_decode_field_access (
59 union acpi_operand_object *obj_desc,
60 u8 field_flags,
61 u32 *return_byte_alignment);
62
55 63
56#ifdef ACPI_UNDER_DEVELOPMENT 64#ifdef ACPI_UNDER_DEVELOPMENT
65
66static u32
67acpi_ex_generate_access (
68 u32 field_bit_offset,
69 u32 field_bit_length,
70 u32 region_length);
71
57/******************************************************************************* 72/*******************************************************************************
58 * 73 *
59 * FUNCTION: acpi_ex_generate_access 74 * FUNCTION: acpi_ex_generate_access
@@ -99,12 +114,14 @@ acpi_ex_generate_access (
99 /* Round Field start offset and length to "minimal" byte boundaries */ 114 /* Round Field start offset and length to "minimal" byte boundaries */
100 115
101 field_byte_offset = ACPI_DIV_8 (ACPI_ROUND_DOWN (field_bit_offset, 8)); 116 field_byte_offset = ACPI_DIV_8 (ACPI_ROUND_DOWN (field_bit_offset, 8));
102 field_byte_end_offset = ACPI_DIV_8 (ACPI_ROUND_UP (field_bit_length + field_bit_offset, 8)); 117 field_byte_end_offset = ACPI_DIV_8 (ACPI_ROUND_UP (field_bit_length +
118 field_bit_offset, 8));
103 field_byte_length = field_byte_end_offset - field_byte_offset; 119 field_byte_length = field_byte_end_offset - field_byte_offset;
104 120
105 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 121 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
106 "Bit length %d, Bit offset %d\n", 122 "Bit length %d, Bit offset %d\n",
107 field_bit_length, field_bit_offset)); 123 field_bit_length, field_bit_offset));
124
108 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 125 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
109 "Byte Length %d, Byte Offset %d, End Offset %d\n", 126 "Byte Length %d, Byte Offset %d, End Offset %d\n",
110 field_byte_length, field_byte_offset, field_byte_end_offset)); 127 field_byte_length, field_byte_offset, field_byte_end_offset));
@@ -117,20 +134,26 @@ acpi_ex_generate_access (
117 */ 134 */
118 for (access_byte_width = 1; access_byte_width <= 8; access_byte_width <<= 1) { 135 for (access_byte_width = 1; access_byte_width <= 8; access_byte_width <<= 1) {
119 /* 136 /*
120 * 1) Round end offset up to next access boundary and make sure that this 137 * 1) Round end offset up to next access boundary and make sure that
121 * does not go beyond the end of the parent region. 138 * this does not go beyond the end of the parent region.
122 * 2) When the Access width is greater than the field_byte_length, we are done. 139 * 2) When the Access width is greater than the field_byte_length, we
123 * (This does not optimize for the perfectly aligned case yet). 140 * are done. (This does not optimize for the perfectly aligned
141 * case yet).
124 */ 142 */
125 if (ACPI_ROUND_UP (field_byte_end_offset, access_byte_width) <= region_length) { 143 if (ACPI_ROUND_UP (field_byte_end_offset, access_byte_width) <= region_length) {
126 field_start_offset = ACPI_ROUND_DOWN (field_byte_offset, access_byte_width) / 144 field_start_offset =
127 access_byte_width; 145 ACPI_ROUND_DOWN (field_byte_offset, access_byte_width) /
128 field_end_offset = ACPI_ROUND_UP ((field_byte_length + field_byte_offset), 146 access_byte_width;
129 access_byte_width) / access_byte_width; 147
130 accesses = field_end_offset - field_start_offset; 148 field_end_offset =
149 ACPI_ROUND_UP ((field_byte_length + field_byte_offset),
150 access_byte_width) / access_byte_width;
151
152 accesses = field_end_offset - field_start_offset;
131 153
132 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 154 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
133 "access_width %d end is within region\n", access_byte_width)); 155 "access_width %d end is within region\n", access_byte_width));
156
134 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 157 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
135 "Field Start %d, Field End %d -- requires %d accesses\n", 158 "Field Start %d, Field End %d -- requires %d accesses\n",
136 field_start_offset, field_end_offset, accesses)); 159 field_start_offset, field_end_offset, accesses));
@@ -139,8 +162,8 @@ acpi_ex_generate_access (
139 162
140 if (accesses <= 1) { 163 if (accesses <= 1) {
141 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 164 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
142 "Entire field can be accessed with one operation of size %d\n", 165 "Entire field can be accessed with one operation of size %d\n",
143 access_byte_width)); 166 access_byte_width));
144 return_VALUE (access_byte_width); 167 return_VALUE (access_byte_width);
145 } 168 }
146 169
@@ -155,15 +178,20 @@ acpi_ex_generate_access (
155 } 178 }
156 else { 179 else {
157 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 180 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
158 "access_width %d end is NOT within region\n", access_byte_width)); 181 "access_width %d end is NOT within region\n", access_byte_width));
159 if (access_byte_width == 1) { 182 if (access_byte_width == 1) {
160 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 183 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
161 "Field goes beyond end-of-region!\n")); 184 "Field goes beyond end-of-region!\n"));
162 return_VALUE (0); /* Field does not fit in the region at all */
163 }
164 185
165 /* This width goes beyond the end-of-region, back off to previous access */ 186 /* Field does not fit in the region at all */
166 187
188 return_VALUE (0);
189 }
190
191 /*
192 * This width goes beyond the end-of-region, back off to
193 * previous access
194 */
167 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 195 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
168 "Backing off to previous optimal access width of %d\n", 196 "Backing off to previous optimal access width of %d\n",
169 minimum_access_width)); 197 minimum_access_width));
@@ -171,8 +199,10 @@ acpi_ex_generate_access (
171 } 199 }
172 } 200 }
173 201
174 /* Could not read/write field with one operation, just use max access width */ 202 /*
175 203 * Could not read/write field with one operation,
204 * just use max access width
205 */
176 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, 206 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
177 "Cannot access field in one operation, using width 8\n")); 207 "Cannot access field in one operation, using width 8\n"));
178 return_VALUE (8); 208 return_VALUE (8);
@@ -184,8 +214,9 @@ acpi_ex_generate_access (
184 * 214 *
185 * FUNCTION: acpi_ex_decode_field_access 215 * FUNCTION: acpi_ex_decode_field_access
186 * 216 *
187 * PARAMETERS: Access - Encoded field access bits 217 * PARAMETERS: obj_desc - Field object
188 * Length - Field length. 218 * field_flags - Encoded fieldflags (contains access bits)
219 * return_byte_alignment - Where the byte alignment is returned
189 * 220 *
190 * RETURN: Field granularity (8, 16, 32 or 64) and 221 * RETURN: Field granularity (8, 16, 32 or 64) and
191 * byte_alignment (1, 2, 3, or 4) 222 * byte_alignment (1, 2, 3, or 4)
@@ -214,9 +245,10 @@ acpi_ex_decode_field_access (
214 case AML_FIELD_ACCESS_ANY: 245 case AML_FIELD_ACCESS_ANY:
215 246
216#ifdef ACPI_UNDER_DEVELOPMENT 247#ifdef ACPI_UNDER_DEVELOPMENT
217 byte_alignment = acpi_ex_generate_access (obj_desc->common_field.start_field_bit_offset, 248 byte_alignment =
218 obj_desc->common_field.bit_length, 249 acpi_ex_generate_access (obj_desc->common_field.start_field_bit_offset,
219 0xFFFFFFFF /* Temp until we pass region_length as param */); 250 obj_desc->common_field.bit_length,
251 0xFFFFFFFF /* Temp until we pass region_length as parameter */);
220 bit_length = byte_alignment * 8; 252 bit_length = byte_alignment * 8;
221#endif 253#endif
222 254
@@ -276,6 +308,7 @@ acpi_ex_decode_field_access (
276 * field_flags - Access, lock_rule, and update_rule. 308 * field_flags - Access, lock_rule, and update_rule.
277 * The format of a field_flag is described 309 * The format of a field_flag is described
278 * in the ACPI specification 310 * in the ACPI specification
311 * field_attribute - Special attributes (not used)
279 * field_bit_position - Field start position 312 * field_bit_position - Field start position
280 * field_bit_length - Field length in number of bits 313 * field_bit_length - Field length in number of bits
281 * 314 *
@@ -337,7 +370,7 @@ acpi_ex_prep_common_field_object (
337 /* Setup width (access granularity) fields */ 370 /* Setup width (access granularity) fields */
338 371
339 obj_desc->common_field.access_byte_width = (u8) 372 obj_desc->common_field.access_byte_width = (u8)
340 ACPI_DIV_8 (access_bit_width); /* 1, 2, 4, 8 */ 373 ACPI_DIV_8 (access_bit_width); /* 1, 2, 4, 8 */
341 374
342 obj_desc->common_field.access_bit_width = (u8) access_bit_width; 375 obj_desc->common_field.access_bit_width = (u8) access_bit_width;
343 376
@@ -380,11 +413,7 @@ acpi_ex_prep_common_field_object (
380 * 413 *
381 * FUNCTION: acpi_ex_prep_field_value 414 * FUNCTION: acpi_ex_prep_field_value
382 * 415 *
383 * PARAMETERS: Node - Owning Node 416 * PARAMETERS: Info - Contains all field creation info
384 * region_node - Region in which field is being defined
385 * field_flags - Access, lock_rule, and update_rule.
386 * field_bit_position - Field start position
387 * field_bit_length - Field length in number of bits
388 * 417 *
389 * RETURN: Status 418 * RETURN: Status
390 * 419 *
@@ -445,7 +474,7 @@ acpi_ex_prep_field_value (
445 switch (info->field_type) { 474 switch (info->field_type) {
446 case ACPI_TYPE_LOCAL_REGION_FIELD: 475 case ACPI_TYPE_LOCAL_REGION_FIELD:
447 476
448 obj_desc->field.region_obj = acpi_ns_get_attached_object (info->region_node); 477 obj_desc->field.region_obj = acpi_ns_get_attached_object (info->region_node);
449 478
450 /* An additional reference for the container */ 479 /* An additional reference for the container */
451 480
@@ -461,8 +490,10 @@ acpi_ex_prep_field_value (
461 case ACPI_TYPE_LOCAL_BANK_FIELD: 490 case ACPI_TYPE_LOCAL_BANK_FIELD:
462 491
463 obj_desc->bank_field.value = info->bank_value; 492 obj_desc->bank_field.value = info->bank_value;
464 obj_desc->bank_field.region_obj = acpi_ns_get_attached_object (info->region_node); 493 obj_desc->bank_field.region_obj = acpi_ns_get_attached_object (
465 obj_desc->bank_field.bank_obj = acpi_ns_get_attached_object (info->register_node); 494 info->region_node);
495 obj_desc->bank_field.bank_obj = acpi_ns_get_attached_object (
496 info->register_node);
466 497
467 /* An additional reference for the attached objects */ 498 /* An additional reference for the attached objects */
468 499
@@ -481,10 +512,13 @@ acpi_ex_prep_field_value (
481 512
482 case ACPI_TYPE_LOCAL_INDEX_FIELD: 513 case ACPI_TYPE_LOCAL_INDEX_FIELD:
483 514
484 obj_desc->index_field.index_obj = acpi_ns_get_attached_object (info->register_node); 515 obj_desc->index_field.index_obj = acpi_ns_get_attached_object (
485 obj_desc->index_field.data_obj = acpi_ns_get_attached_object (info->data_register_node); 516 info->register_node);
517 obj_desc->index_field.data_obj = acpi_ns_get_attached_object (
518 info->data_register_node);
486 obj_desc->index_field.value = (u32) 519 obj_desc->index_field.value = (u32)
487 (info->field_bit_position / ACPI_MUL_8 (obj_desc->field.access_byte_width)); 520 (info->field_bit_position / ACPI_MUL_8 (
521 obj_desc->field.access_byte_width));
488 522
489 if (!obj_desc->index_field.data_obj || !obj_desc->index_field.index_obj) { 523 if (!obj_desc->index_field.data_obj || !obj_desc->index_field.index_obj) {
490 ACPI_REPORT_ERROR (("Null Index Object during field prep\n")); 524 ACPI_REPORT_ERROR (("Null Index Object during field prep\n"));
diff --git a/drivers/acpi/executer/exregion.c b/drivers/acpi/executer/exregion.c
index 7cfd0684c70b..723aaef4bb4a 100644
--- a/drivers/acpi/executer/exregion.c
+++ b/drivers/acpi/executer/exregion.c
@@ -115,7 +115,6 @@ acpi_ex_system_memory_space_handler (
115 return_ACPI_STATUS (AE_AML_OPERAND_VALUE); 115 return_ACPI_STATUS (AE_AML_OPERAND_VALUE);
116 } 116 }
117 117
118
119#ifndef ACPI_MISALIGNED_TRANSFERS 118#ifndef ACPI_MISALIGNED_TRANSFERS
120 /* 119 /*
121 * Hardware does not support non-aligned data transfers, we must verify 120 * Hardware does not support non-aligned data transfers, we must verify
@@ -134,7 +133,8 @@ acpi_ex_system_memory_space_handler (
134 */ 133 */
135 if ((address < mem_info->mapped_physical_address) || 134 if ((address < mem_info->mapped_physical_address) ||
136 (((acpi_integer) address + length) > 135 (((acpi_integer) address + length) >
137 ((acpi_integer) mem_info->mapped_physical_address + mem_info->mapped_length))) { 136 ((acpi_integer)
137 mem_info->mapped_physical_address + mem_info->mapped_length))) {
138 /* 138 /*
139 * The request cannot be resolved by the current memory mapping; 139 * The request cannot be resolved by the current memory mapping;
140 * Delete the existing mapping and create a new one. 140 * Delete the existing mapping and create a new one.
@@ -150,7 +150,9 @@ acpi_ex_system_memory_space_handler (
150 * Don't attempt to map memory beyond the end of the region, and 150 * Don't attempt to map memory beyond the end of the region, and
151 * constrain the maximum mapping size to something reasonable. 151 * constrain the maximum mapping size to something reasonable.
152 */ 152 */
153 window_size = (acpi_size) ((mem_info->address + mem_info->length) - address); 153 window_size = (acpi_size)
154 ((mem_info->address + mem_info->length) - address);
155
154 if (window_size > ACPI_SYSMEM_REGION_WINDOW_SIZE) { 156 if (window_size > ACPI_SYSMEM_REGION_WINDOW_SIZE) {
155 window_size = ACPI_SYSMEM_REGION_WINDOW_SIZE; 157 window_size = ACPI_SYSMEM_REGION_WINDOW_SIZE;
156 } 158 }
@@ -160,8 +162,9 @@ acpi_ex_system_memory_space_handler (
160 status = acpi_os_map_memory (address, window_size, 162 status = acpi_os_map_memory (address, window_size,
161 (void **) &mem_info->mapped_logical_address); 163 (void **) &mem_info->mapped_logical_address);
162 if (ACPI_FAILURE (status)) { 164 if (ACPI_FAILURE (status)) {
163 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not map memory at %8.8X%8.8X, size %X\n", 165 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
164 ACPI_FORMAT_UINT64 (address), (u32) window_size)); 166 "Could not map memory at %8.8X%8.8X, size %X\n",
167 ACPI_FORMAT_UINT64 (address), (u32) window_size));
165 mem_info->mapped_length = 0; 168 mem_info->mapped_length = 0;
166 return_ACPI_STATUS (status); 169 return_ACPI_STATUS (status);
167 } 170 }
@@ -177,10 +180,12 @@ acpi_ex_system_memory_space_handler (
177 * access 180 * access
178 */ 181 */
179 logical_addr_ptr = mem_info->mapped_logical_address + 182 logical_addr_ptr = mem_info->mapped_logical_address +
180 ((acpi_integer) address - (acpi_integer) mem_info->mapped_physical_address); 183 ((acpi_integer) address -
184 (acpi_integer) mem_info->mapped_physical_address);
181 185
182 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, 186 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
183 "system_memory %d (%d width) Address=%8.8X%8.8X\n", function, bit_width, 187 "system_memory %d (%d width) Address=%8.8X%8.8X\n",
188 function, bit_width,
184 ACPI_FORMAT_UINT64 (address))); 189 ACPI_FORMAT_UINT64 (address)));
185 190
186 /* 191 /*
@@ -298,13 +303,15 @@ acpi_ex_system_io_space_handler (
298 switch (function) { 303 switch (function) {
299 case ACPI_READ: 304 case ACPI_READ:
300 305
301 status = acpi_os_read_port ((acpi_io_address) address, &value32, bit_width); 306 status = acpi_os_read_port ((acpi_io_address) address,
307 &value32, bit_width);
302 *value = value32; 308 *value = value32;
303 break; 309 break;
304 310
305 case ACPI_WRITE: 311 case ACPI_WRITE:
306 312
307 status = acpi_os_write_port ((acpi_io_address) address, (u32) *value, bit_width); 313 status = acpi_os_write_port ((acpi_io_address) address,
314 (u32) *value, bit_width);
308 break; 315 break;
309 316
310 default: 317 default:
@@ -375,12 +382,14 @@ acpi_ex_pci_config_space_handler (
375 case ACPI_READ: 382 case ACPI_READ:
376 383
377 *value = 0; 384 *value = 0;
378 status = acpi_os_read_pci_configuration (pci_id, pci_register, value, bit_width); 385 status = acpi_os_read_pci_configuration (pci_id, pci_register,
386 value, bit_width);
379 break; 387 break;
380 388
381 case ACPI_WRITE: 389 case ACPI_WRITE:
382 390
383 status = acpi_os_write_pci_configuration (pci_id, pci_register, *value, bit_width); 391 status = acpi_os_write_pci_configuration (pci_id, pci_register,
392 *value, bit_width);
384 break; 393 break;
385 394
386 default: 395 default:
@@ -505,8 +514,7 @@ acpi_ex_data_table_space_handler (
505 514
506 logical_addr_ptr = ACPI_PHYSADDR_TO_PTR (address); 515 logical_addr_ptr = ACPI_PHYSADDR_TO_PTR (address);
507 516
508 517 /* Perform the memory read or write */
509 /* Perform the memory read or write */
510 518
511 switch (function) { 519 switch (function) {
512 case ACPI_READ: 520 case ACPI_READ:
diff --git a/drivers/acpi/executer/exresnte.c b/drivers/acpi/executer/exresnte.c
index 7936329a0e35..21d5c74fa309 100644
--- a/drivers/acpi/executer/exresnte.c
+++ b/drivers/acpi/executer/exresnte.c
@@ -210,15 +210,15 @@ acpi_ex_resolve_node_to_value (
210 case ACPI_TYPE_LOCAL_BANK_FIELD: 210 case ACPI_TYPE_LOCAL_BANK_FIELD:
211 case ACPI_TYPE_LOCAL_INDEX_FIELD: 211 case ACPI_TYPE_LOCAL_INDEX_FIELD:
212 212
213 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "field_read Node=%p source_desc=%p Type=%X\n", 213 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
214 "field_read Node=%p source_desc=%p Type=%X\n",
214 node, source_desc, entry_type)); 215 node, source_desc, entry_type));
215 216
216 status = acpi_ex_read_data_from_field (walk_state, source_desc, &obj_desc); 217 status = acpi_ex_read_data_from_field (walk_state, source_desc, &obj_desc);
217 break; 218 break;
218 219
219 /* 220 /* For these objects, just return the object attached to the Node */
220 * For these objects, just return the object attached to the Node 221
221 */
222 case ACPI_TYPE_MUTEX: 222 case ACPI_TYPE_MUTEX:
223 case ACPI_TYPE_METHOD: 223 case ACPI_TYPE_METHOD:
224 case ACPI_TYPE_POWER: 224 case ACPI_TYPE_POWER:
@@ -233,12 +233,12 @@ acpi_ex_resolve_node_to_value (
233 acpi_ut_add_reference (obj_desc); 233 acpi_ut_add_reference (obj_desc);
234 break; 234 break;
235 235
236
237 /* TYPE_ANY is untyped, and thus there is no object associated with it */ 236 /* TYPE_ANY is untyped, and thus there is no object associated with it */
238 237
239 case ACPI_TYPE_ANY: 238 case ACPI_TYPE_ANY:
240 239
241 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Untyped entry %p, no attached object!\n", 240 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
241 "Untyped entry %p, no attached object!\n",
242 node)); 242 node));
243 243
244 return_ACPI_STATUS (AE_AML_OPERAND_TYPE); /* Cannot be AE_TYPE */ 244 return_ACPI_STATUS (AE_AML_OPERAND_TYPE); /* Cannot be AE_TYPE */
@@ -259,7 +259,8 @@ acpi_ex_resolve_node_to_value (
259 default: 259 default:
260 /* No named references are allowed here */ 260 /* No named references are allowed here */
261 261
262 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unsupported Reference opcode %X (%s)\n", 262 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
263 "Unsupported Reference opcode %X (%s)\n",
263 source_desc->reference.opcode, 264 source_desc->reference.opcode,
264 acpi_ps_get_opcode_name (source_desc->reference.opcode))); 265 acpi_ps_get_opcode_name (source_desc->reference.opcode)));
265 266
@@ -268,11 +269,12 @@ acpi_ex_resolve_node_to_value (
268 break; 269 break;
269 270
270 271
271 /* Default case is for unknown types */
272
273 default: 272 default:
274 273
275 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Node %p - Unknown object type %X\n", 274 /* Default case is for unknown types */
275
276 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
277 "Node %p - Unknown object type %X\n",
276 node, entry_type)); 278 node, entry_type));
277 279
278 return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 280 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
@@ -280,7 +282,7 @@ acpi_ex_resolve_node_to_value (
280 } /* switch (entry_type) */ 282 } /* switch (entry_type) */
281 283
282 284
283 /* Put the object descriptor on the stack */ 285 /* Return the object descriptor */
284 286
285 *object_ptr = (void *) obj_desc; 287 *object_ptr = (void *) obj_desc;
286 return_ACPI_STATUS (status); 288 return_ACPI_STATUS (status);
diff --git a/drivers/acpi/executer/exresolv.c b/drivers/acpi/executer/exresolv.c
index 7be604911156..3de45672379a 100644
--- a/drivers/acpi/executer/exresolv.c
+++ b/drivers/acpi/executer/exresolv.c
@@ -54,6 +54,13 @@
54#define _COMPONENT ACPI_EXECUTER 54#define _COMPONENT ACPI_EXECUTER
55 ACPI_MODULE_NAME ("exresolv") 55 ACPI_MODULE_NAME ("exresolv")
56 56
57/* Local prototypes */
58
59static acpi_status
60acpi_ex_resolve_object_to_value (
61 union acpi_operand_object **stack_ptr,
62 struct acpi_walk_state *walk_state);
63
57 64
58/******************************************************************************* 65/*******************************************************************************
59 * 66 *
@@ -96,6 +103,11 @@ acpi_ex_resolve_to_value (
96 if (ACPI_FAILURE (status)) { 103 if (ACPI_FAILURE (status)) {
97 return_ACPI_STATUS (status); 104 return_ACPI_STATUS (status);
98 } 105 }
106
107 if (!*stack_ptr) {
108 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Internal - null pointer\n"));
109 return_ACPI_STATUS (AE_AML_NO_OPERAND);
110 }
99 } 111 }
100 112
101 /* 113 /*
@@ -120,18 +132,17 @@ acpi_ex_resolve_to_value (
120 * 132 *
121 * FUNCTION: acpi_ex_resolve_object_to_value 133 * FUNCTION: acpi_ex_resolve_object_to_value
122 * 134 *
123 * PARAMETERS: stack_ptr - Pointer to a stack location that contains a 135 * PARAMETERS: stack_ptr - Pointer to an internal object
124 * ptr to an internal object.
125 * walk_state - Current method state 136 * walk_state - Current method state
126 * 137 *
127 * RETURN: Status 138 * RETURN: Status
128 * 139 *
129 * DESCRIPTION: Retrieve the value from an internal object. The Reference type 140 * DESCRIPTION: Retrieve the value from an internal object. The Reference type
130 * uses the associated AML opcode to determine the value. 141 * uses the associated AML opcode to determine the value.
131 * 142 *
132 ******************************************************************************/ 143 ******************************************************************************/
133 144
134acpi_status 145static acpi_status
135acpi_ex_resolve_object_to_value ( 146acpi_ex_resolve_object_to_value (
136 union acpi_operand_object **stack_ptr, 147 union acpi_operand_object **stack_ptr,
137 struct acpi_walk_state *walk_state) 148 struct acpi_walk_state *walk_state)
@@ -159,7 +170,7 @@ acpi_ex_resolve_object_to_value (
159 case AML_NAME_OP: 170 case AML_NAME_OP:
160 171
161 /* 172 /*
162 * Convert indirect name ptr to a direct name ptr. 173 * Convert name reference to a namespace node
163 * Then, acpi_ex_resolve_node_to_value can be used to get the value 174 * Then, acpi_ex_resolve_node_to_value can be used to get the value
164 */ 175 */
165 temp_node = stack_desc->reference.object; 176 temp_node = stack_desc->reference.object;
@@ -168,7 +179,7 @@ acpi_ex_resolve_object_to_value (
168 179
169 acpi_ut_remove_reference (stack_desc); 180 acpi_ut_remove_reference (stack_desc);
170 181
171 /* Put direct name pointer onto stack and exit */ 182 /* Return the namespace node */
172 183
173 (*stack_ptr) = temp_node; 184 (*stack_ptr) = temp_node;
174 break; 185 break;
@@ -255,10 +266,19 @@ acpi_ex_resolve_object_to_value (
255 266
256 break; 267 break;
257 268
269 case AML_INT_NAMEPATH_OP: /* Reference to a named object */
270
271 /* Get the object pointed to by the namespace node */
272
273 *stack_ptr = (stack_desc->reference.node)->object;
274 acpi_ut_add_reference (*stack_ptr);
275 acpi_ut_remove_reference (stack_desc);
276 break;
258 277
259 default: 278 default:
260 279
261 ACPI_REPORT_ERROR (("During resolve, Unknown Reference opcode %X (%s) in %p\n", 280 ACPI_REPORT_ERROR ((
281 "During resolve, Unknown Reference opcode %X (%s) in %p\n",
262 opcode, acpi_ps_get_opcode_name (opcode), stack_desc)); 282 opcode, acpi_ps_get_opcode_name (opcode), stack_desc));
263 status = AE_AML_INTERNAL; 283 status = AE_AML_INTERNAL;
264 break; 284 break;
@@ -278,9 +298,8 @@ acpi_ex_resolve_object_to_value (
278 break; 298 break;
279 299
280 300
281 /* 301 /* These cases may never happen here, but just in case.. */
282 * These cases may never happen here, but just in case.. 302
283 */
284 case ACPI_TYPE_BUFFER_FIELD: 303 case ACPI_TYPE_BUFFER_FIELD:
285 case ACPI_TYPE_LOCAL_REGION_FIELD: 304 case ACPI_TYPE_LOCAL_REGION_FIELD:
286 case ACPI_TYPE_LOCAL_BANK_FIELD: 305 case ACPI_TYPE_LOCAL_BANK_FIELD:
@@ -333,9 +352,8 @@ acpi_ex_resolve_multiple (
333 ACPI_FUNCTION_TRACE ("acpi_ex_resolve_multiple"); 352 ACPI_FUNCTION_TRACE ("acpi_ex_resolve_multiple");
334 353
335 354
336 /* 355 /* Operand can be either a namespace node or an operand descriptor */
337 * Operand can be either a namespace node or an operand descriptor 356
338 */
339 switch (ACPI_GET_DESCRIPTOR_TYPE (obj_desc)) { 357 switch (ACPI_GET_DESCRIPTOR_TYPE (obj_desc)) {
340 case ACPI_DESC_TYPE_OPERAND: 358 case ACPI_DESC_TYPE_OPERAND:
341 type = obj_desc->common.type; 359 type = obj_desc->common.type;
@@ -357,10 +375,8 @@ acpi_ex_resolve_multiple (
357 return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 375 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
358 } 376 }
359 377
378 /* If type is anything other than a reference, we are done */
360 379
361 /*
362 * If type is anything other than a reference, we are done
363 */
364 if (type != ACPI_TYPE_LOCAL_REFERENCE) { 380 if (type != ACPI_TYPE_LOCAL_REFERENCE) {
365 goto exit; 381 goto exit;
366 } 382 }
@@ -382,8 +398,9 @@ acpi_ex_resolve_multiple (
382 /* All "References" point to a NS node */ 398 /* All "References" point to a NS node */
383 399
384 if (ACPI_GET_DESCRIPTOR_TYPE (node) != ACPI_DESC_TYPE_NAMED) { 400 if (ACPI_GET_DESCRIPTOR_TYPE (node) != ACPI_DESC_TYPE_NAMED) {
385 ACPI_REPORT_ERROR (("acpi_ex_resolve_multiple: Not a NS node %p [%s]\n", 401 ACPI_REPORT_ERROR ((
386 node, acpi_ut_get_descriptor_name (node))); 402 "acpi_ex_resolve_multiple: Not a NS node %p [%s]\n",
403 node, acpi_ut_get_descriptor_name (node)));
387 return_ACPI_STATUS (AE_AML_INTERNAL); 404 return_ACPI_STATUS (AE_AML_INTERNAL);
388 } 405 }
389 406
@@ -440,8 +457,9 @@ acpi_ex_resolve_multiple (
440 /* All "References" point to a NS node */ 457 /* All "References" point to a NS node */
441 458
442 if (ACPI_GET_DESCRIPTOR_TYPE (node) != ACPI_DESC_TYPE_NAMED) { 459 if (ACPI_GET_DESCRIPTOR_TYPE (node) != ACPI_DESC_TYPE_NAMED) {
443 ACPI_REPORT_ERROR (("acpi_ex_resolve_multiple: Not a NS node %p [%s]\n", 460 ACPI_REPORT_ERROR ((
444 node, acpi_ut_get_descriptor_name (node))); 461 "acpi_ex_resolve_multiple: Not a NS node %p [%s]\n",
462 node, acpi_ut_get_descriptor_name (node)));
445 return_ACPI_STATUS (AE_AML_INTERNAL); 463 return_ACPI_STATUS (AE_AML_INTERNAL);
446 } 464 }
447 465
@@ -468,7 +486,7 @@ acpi_ex_resolve_multiple (
468 486
469 if (return_desc) { 487 if (return_desc) {
470 status = acpi_ds_method_data_get_value (obj_desc->reference.opcode, 488 status = acpi_ds_method_data_get_value (obj_desc->reference.opcode,
471 obj_desc->reference.offset, walk_state, &obj_desc); 489 obj_desc->reference.offset, walk_state, &obj_desc);
472 if (ACPI_FAILURE (status)) { 490 if (ACPI_FAILURE (status)) {
473 return_ACPI_STATUS (status); 491 return_ACPI_STATUS (status);
474 } 492 }
@@ -500,7 +518,8 @@ acpi_ex_resolve_multiple (
500 518
501 default: 519 default:
502 520
503 ACPI_REPORT_ERROR (("acpi_ex_resolve_multiple: Unknown Reference subtype %X\n", 521 ACPI_REPORT_ERROR ((
522 "acpi_ex_resolve_multiple: Unknown Reference subtype %X\n",
504 obj_desc->reference.opcode)); 523 obj_desc->reference.opcode));
505 return_ACPI_STATUS (AE_AML_INTERNAL); 524 return_ACPI_STATUS (AE_AML_INTERNAL);
506 } 525 }
diff --git a/drivers/acpi/executer/exresop.c b/drivers/acpi/executer/exresop.c
index c92890220c32..d8b470eefe7a 100644
--- a/drivers/acpi/executer/exresop.c
+++ b/drivers/acpi/executer/exresop.c
@@ -52,6 +52,14 @@
52#define _COMPONENT ACPI_EXECUTER 52#define _COMPONENT ACPI_EXECUTER
53 ACPI_MODULE_NAME ("exresop") 53 ACPI_MODULE_NAME ("exresop")
54 54
55/* Local prototypes */
56
57static acpi_status
58acpi_ex_check_object_type (
59 acpi_object_type type_needed,
60 acpi_object_type this_type,
61 void *object);
62
55 63
56/******************************************************************************* 64/*******************************************************************************
57 * 65 *
@@ -67,7 +75,7 @@
67 * 75 *
68 ******************************************************************************/ 76 ******************************************************************************/
69 77
70acpi_status 78static acpi_status
71acpi_ex_check_object_type ( 79acpi_ex_check_object_type (
72 acpi_object_type type_needed, 80 acpi_object_type type_needed,
73 acpi_object_type this_type, 81 acpi_object_type this_type,
@@ -142,6 +150,7 @@ acpi_ex_resolve_operands (
142 const struct acpi_opcode_info *op_info; 150 const struct acpi_opcode_info *op_info;
143 u32 this_arg_type; 151 u32 this_arg_type;
144 acpi_object_type type_needed; 152 acpi_object_type type_needed;
153 u16 target_op = 0;
145 154
146 155
147 ACPI_FUNCTION_TRACE_U32 ("ex_resolve_operands", opcode); 156 ACPI_FUNCTION_TRACE_U32 ("ex_resolve_operands", opcode);
@@ -160,7 +169,8 @@ acpi_ex_resolve_operands (
160 return_ACPI_STATUS (AE_AML_INTERNAL); 169 return_ACPI_STATUS (AE_AML_INTERNAL);
161 } 170 }
162 171
163 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Opcode %X [%s] required_operand_types=%8.8X \n", 172 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
173 "Opcode %X [%s] required_operand_types=%8.8X \n",
164 opcode, op_info->name, arg_types)); 174 opcode, op_info->name, arg_types));
165 175
166 /* 176 /*
@@ -187,7 +197,7 @@ acpi_ex_resolve_operands (
187 switch (ACPI_GET_DESCRIPTOR_TYPE (obj_desc)) { 197 switch (ACPI_GET_DESCRIPTOR_TYPE (obj_desc)) {
188 case ACPI_DESC_TYPE_NAMED: 198 case ACPI_DESC_TYPE_NAMED:
189 199
190 /* Node */ 200 /* Namespace Node */
191 201
192 object_type = ((struct acpi_namespace_node *) obj_desc)->type; 202 object_type = ((struct acpi_namespace_node *) obj_desc)->type;
193 break; 203 break;
@@ -202,16 +212,16 @@ acpi_ex_resolve_operands (
202 /* Check for bad acpi_object_type */ 212 /* Check for bad acpi_object_type */
203 213
204 if (!acpi_ut_valid_object_type (object_type)) { 214 if (!acpi_ut_valid_object_type (object_type)) {
205 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Bad operand object type [%X]\n", 215 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
216 "Bad operand object type [%X]\n",
206 object_type)); 217 object_type));
207 218
208 return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 219 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
209 } 220 }
210 221
211 if (object_type == (u8) ACPI_TYPE_LOCAL_REFERENCE) { 222 if (object_type == (u8) ACPI_TYPE_LOCAL_REFERENCE) {
212 /* 223 /* Decode the Reference */
213 * Decode the Reference 224
214 */
215 op_info = acpi_ps_get_opcode_info (opcode); 225 op_info = acpi_ps_get_opcode_info (opcode);
216 if (op_info->class == AML_CLASS_UNKNOWN) { 226 if (op_info->class == AML_CLASS_UNKNOWN) {
217 return_ACPI_STATUS (AE_AML_BAD_OPCODE); 227 return_ACPI_STATUS (AE_AML_BAD_OPCODE);
@@ -219,12 +229,17 @@ acpi_ex_resolve_operands (
219 229
220 switch (obj_desc->reference.opcode) { 230 switch (obj_desc->reference.opcode) {
221 case AML_DEBUG_OP: 231 case AML_DEBUG_OP:
232 target_op = AML_DEBUG_OP;
233
234 /*lint -fallthrough */
235
222 case AML_NAME_OP: 236 case AML_NAME_OP:
223 case AML_INDEX_OP: 237 case AML_INDEX_OP:
224 case AML_REF_OF_OP: 238 case AML_REF_OF_OP:
225 case AML_ARG_OP: 239 case AML_ARG_OP:
226 case AML_LOCAL_OP: 240 case AML_LOCAL_OP:
227 case AML_LOAD_OP: /* ddb_handle from LOAD_OP or LOAD_TABLE_OP */ 241 case AML_LOAD_OP: /* ddb_handle from LOAD_OP or LOAD_TABLE_OP */
242 case AML_INT_NAMEPATH_OP: /* Reference to a named object */
228 243
229 ACPI_DEBUG_ONLY_MEMBERS (ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 244 ACPI_DEBUG_ONLY_MEMBERS (ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
230 "Operand is a Reference, ref_opcode [%s]\n", 245 "Operand is a Reference, ref_opcode [%s]\n",
@@ -254,10 +269,8 @@ acpi_ex_resolve_operands (
254 return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 269 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
255 } 270 }
256 271
272 /* Get one argument type, point to the next */
257 273
258 /*
259 * Get one argument type, point to the next
260 */
261 this_arg_type = GET_CURRENT_ARG_TYPE (arg_types); 274 this_arg_type = GET_CURRENT_ARG_TYPE (arg_types);
262 INCREMENT_ARG_LIST (arg_types); 275 INCREMENT_ARG_LIST (arg_types);
263 276
@@ -271,26 +284,31 @@ acpi_ex_resolve_operands (
271 if ((ACPI_GET_DESCRIPTOR_TYPE (obj_desc) == ACPI_DESC_TYPE_OPERAND) && 284 if ((ACPI_GET_DESCRIPTOR_TYPE (obj_desc) == ACPI_DESC_TYPE_OPERAND) &&
272 (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_STRING)) { 285 (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_STRING)) {
273 /* 286 /*
274 * String found - the string references a named object and must be 287 * String found - the string references a named object and
275 * resolved to a node 288 * must be resolved to a node
276 */ 289 */
277 goto next_operand; 290 goto next_operand;
278 } 291 }
279 292
280 /* Else not a string - fall through to the normal Reference case below */ 293 /*
294 * Else not a string - fall through to the normal Reference
295 * case below
296 */
281 /*lint -fallthrough */ 297 /*lint -fallthrough */
282 298
283 case ARGI_REFERENCE: /* References: */ 299 case ARGI_REFERENCE: /* References: */
284 case ARGI_INTEGER_REF: 300 case ARGI_INTEGER_REF:
285 case ARGI_OBJECT_REF: 301 case ARGI_OBJECT_REF:
286 case ARGI_DEVICE_REF: 302 case ARGI_DEVICE_REF:
287 case ARGI_TARGETREF: /* Allows implicit conversion rules before store */ 303 case ARGI_TARGETREF: /* Allows implicit conversion rules before store */
288 case ARGI_FIXED_TARGET: /* No implicit conversion before store to target */ 304 case ARGI_FIXED_TARGET: /* No implicit conversion before store to target */
289 case ARGI_SIMPLE_TARGET: /* Name, Local, or Arg - no implicit conversion */ 305 case ARGI_SIMPLE_TARGET: /* Name, Local, or Arg - no implicit conversion */
290
291 /* Need an operand of type ACPI_TYPE_LOCAL_REFERENCE */
292 306
293 if (ACPI_GET_DESCRIPTOR_TYPE (obj_desc) == ACPI_DESC_TYPE_NAMED) /* Node (name) ptr OK as-is */ { 307 /*
308 * Need an operand of type ACPI_TYPE_LOCAL_REFERENCE
309 * A Namespace Node is OK as-is
310 */
311 if (ACPI_GET_DESCRIPTOR_TYPE (obj_desc) == ACPI_DESC_TYPE_NAMED) {
294 goto next_operand; 312 goto next_operand;
295 } 313 }
296 314
@@ -300,11 +318,9 @@ acpi_ex_resolve_operands (
300 return_ACPI_STATUS (status); 318 return_ACPI_STATUS (status);
301 } 319 }
302 320
303 if (AML_NAME_OP == obj_desc->reference.opcode) { 321 if (obj_desc->reference.opcode == AML_NAME_OP) {
304 /* 322 /* Convert a named reference to the actual named object */
305 * Convert an indirect name ptr to direct name ptr and put 323
306 * it on the stack
307 */
308 temp_node = obj_desc->reference.object; 324 temp_node = obj_desc->reference.object;
309 acpi_ut_remove_reference (obj_desc); 325 acpi_ut_remove_reference (obj_desc);
310 (*stack_ptr) = temp_node; 326 (*stack_ptr) = temp_node;
@@ -332,7 +348,6 @@ acpi_ex_resolve_operands (
332 break; 348 break;
333 } 349 }
334 350
335
336 /* 351 /*
337 * Resolve this object to a value 352 * Resolve this object to a value
338 */ 353 */
@@ -392,7 +407,7 @@ acpi_ex_resolve_operands (
392 /* 407 /*
393 * The more complex cases allow multiple resolved object types 408 * The more complex cases allow multiple resolved object types
394 */ 409 */
395 case ARGI_INTEGER: /* Number */ 410 case ARGI_INTEGER:
396 411
397 /* 412 /*
398 * Need an operand of type ACPI_TYPE_INTEGER, 413 * Need an operand of type ACPI_TYPE_INTEGER,
@@ -563,7 +578,7 @@ acpi_ex_resolve_operands (
563 578
564 case ARGI_REGION_OR_FIELD: 579 case ARGI_REGION_OR_FIELD:
565 580
566 /* Need an operand of type ACPI_TYPE_REGION or a FIELD in a region */ 581 /* Need an operand of type REGION or a FIELD in a region */
567 582
568 switch (ACPI_GET_OBJECT_TYPE (obj_desc)) { 583 switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
569 case ACPI_TYPE_REGION: 584 case ACPI_TYPE_REGION:
@@ -614,6 +629,12 @@ acpi_ex_resolve_operands (
614 break; 629 break;
615 } 630 }
616 631
632 if (target_op == AML_DEBUG_OP) {
633 /* Allow store of any object to the Debug object */
634
635 break;
636 }
637
617 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 638 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
618 "Needed Integer/Buffer/String/Package/Ref/Ddb], found [%s] %p\n", 639 "Needed Integer/Buffer/String/Package/Ref/Ddb], found [%s] %p\n",
619 acpi_ut_get_object_type_name (obj_desc), obj_desc)); 640 acpi_ut_get_object_type_name (obj_desc), obj_desc));
@@ -652,8 +673,7 @@ next_operand:
652 if (GET_CURRENT_ARG_TYPE (arg_types)) { 673 if (GET_CURRENT_ARG_TYPE (arg_types)) {
653 stack_ptr--; 674 stack_ptr--;
654 } 675 }
655 676 }
656 } /* while (*Types) */
657 677
658 return_ACPI_STATUS (status); 678 return_ACPI_STATUS (status);
659} 679}
diff --git a/drivers/acpi/executer/exstore.c b/drivers/acpi/executer/exstore.c
index e0fc6aba1253..2725db0901b8 100644
--- a/drivers/acpi/executer/exstore.c
+++ b/drivers/acpi/executer/exstore.c
@@ -48,11 +48,171 @@
48#include <acpi/acinterp.h> 48#include <acpi/acinterp.h>
49#include <acpi/amlcode.h> 49#include <acpi/amlcode.h>
50#include <acpi/acnamesp.h> 50#include <acpi/acnamesp.h>
51#include <acpi/acparser.h>
51 52
52 53
53#define _COMPONENT ACPI_EXECUTER 54#define _COMPONENT ACPI_EXECUTER
54 ACPI_MODULE_NAME ("exstore") 55 ACPI_MODULE_NAME ("exstore")
55 56
57/* Local prototypes */
58
59static void
60acpi_ex_do_debug_object (
61 union acpi_operand_object *source_desc,
62 u32 level,
63 u32 index);
64
65static acpi_status
66acpi_ex_store_object_to_index (
67 union acpi_operand_object *val_desc,
68 union acpi_operand_object *dest_desc,
69 struct acpi_walk_state *walk_state);
70
71
72/*******************************************************************************
73 *
74 * FUNCTION: acpi_ex_do_debug_object
75 *
76 * PARAMETERS: source_desc - Value to be stored
77 * Level - Indentation level (used for packages)
78 * Index - Current package element, zero if not pkg
79 *
80 * RETURN: None
81 *
82 * DESCRIPTION: Handles stores to the Debug Object.
83 *
84 ******************************************************************************/
85
86static void
87acpi_ex_do_debug_object (
88 union acpi_operand_object *source_desc,
89 u32 level,
90 u32 index)
91{
92 u32 i;
93
94
95 ACPI_FUNCTION_TRACE_PTR ("ex_do_debug_object", source_desc);
96
97
98 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[ACPI Debug] %*s",
99 level, " "));
100
101 /* Display index for package output only */
102
103 if (index > 0) {
104 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT,
105 "(%.2u) ", index -1));
106 }
107
108 if (!source_desc) {
109 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "<Null Object>\n"));
110 return_VOID;
111 }
112
113 if (ACPI_GET_DESCRIPTOR_TYPE (source_desc) == ACPI_DESC_TYPE_OPERAND) {
114 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "%s: ",
115 acpi_ut_get_object_type_name (source_desc)));
116
117 if (!acpi_ut_valid_internal_object (source_desc)) {
118 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT,
119 "%p, Invalid Internal Object!\n", source_desc));
120 return_VOID;
121 }
122 }
123 else if (ACPI_GET_DESCRIPTOR_TYPE (source_desc) == ACPI_DESC_TYPE_NAMED) {
124 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "%s: %p\n",
125 acpi_ut_get_type_name (((struct acpi_namespace_node *) source_desc)->type),
126 source_desc));
127 return_VOID;
128 }
129 else {
130 return_VOID;
131 }
132
133 switch (ACPI_GET_OBJECT_TYPE (source_desc)) {
134 case ACPI_TYPE_INTEGER:
135
136 /* Output correct integer width */
137
138 if (acpi_gbl_integer_byte_width == 4) {
139 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "0x%8.8X\n",
140 (u32) source_desc->integer.value));
141 }
142 else {
143 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "0x%8.8X%8.8X\n",
144 ACPI_FORMAT_UINT64 (source_desc->integer.value)));
145 }
146 break;
147
148 case ACPI_TYPE_BUFFER:
149
150 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[0x%.2X]",
151 (u32) source_desc->buffer.length));
152 ACPI_DUMP_BUFFER (source_desc->buffer.pointer,
153 (source_desc->buffer.length < 32) ? source_desc->buffer.length : 32);
154 break;
155
156 case ACPI_TYPE_STRING:
157
158 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[0x%.2X] \"%s\"\n",
159 source_desc->string.length, source_desc->string.pointer));
160 break;
161
162 case ACPI_TYPE_PACKAGE:
163
164 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[0x%.2X Elements]\n",
165 source_desc->package.count));
166
167 /* Output the entire contents of the package */
168
169 for (i = 0; i < source_desc->package.count; i++) {
170 acpi_ex_do_debug_object (source_desc->package.elements[i],
171 level+4, i+1);
172 }
173 break;
174
175 case ACPI_TYPE_LOCAL_REFERENCE:
176
177 if (source_desc->reference.opcode == AML_INDEX_OP) {
178 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[%s, 0x%X]\n",
179 acpi_ps_get_opcode_name (source_desc->reference.opcode),
180 source_desc->reference.offset));
181 }
182 else {
183 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[%s]\n",
184 acpi_ps_get_opcode_name (source_desc->reference.opcode)));
185 }
186
187
188 if (source_desc->reference.object) {
189 if (ACPI_GET_DESCRIPTOR_TYPE (source_desc->reference.object) ==
190 ACPI_DESC_TYPE_NAMED) {
191 acpi_ex_do_debug_object (((struct acpi_namespace_node *)
192 source_desc->reference.object)->object,
193 level+4, 0);
194 }
195 else {
196 acpi_ex_do_debug_object (source_desc->reference.object, level+4, 0);
197 }
198 }
199 else if (source_desc->reference.node) {
200 acpi_ex_do_debug_object ((source_desc->reference.node)->object,
201 level+4, 0);
202 }
203 break;
204
205 default:
206
207 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "%p %s\n",
208 source_desc, acpi_ut_get_object_type_name (source_desc)));
209 break;
210 }
211
212 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC, "\n"));
213 return_VOID;
214}
215
56 216
57/******************************************************************************* 217/*******************************************************************************
58 * 218 *
@@ -154,8 +314,9 @@ acpi_ex_store (
154 314
155 /* Storing an object into a Name "container" */ 315 /* Storing an object into a Name "container" */
156 316
157 status = acpi_ex_store_object_to_node (source_desc, ref_desc->reference.object, 317 status = acpi_ex_store_object_to_node (source_desc,
158 walk_state, ACPI_IMPLICIT_CONVERSION); 318 ref_desc->reference.object,
319 walk_state, ACPI_IMPLICIT_CONVERSION);
159 break; 320 break;
160 321
161 322
@@ -173,7 +334,7 @@ acpi_ex_store (
173 /* Store to a method local/arg */ 334 /* Store to a method local/arg */
174 335
175 status = acpi_ds_store_object_to_local (ref_desc->reference.opcode, 336 status = acpi_ds_store_object_to_local (ref_desc->reference.opcode,
176 ref_desc->reference.offset, source_desc, walk_state); 337 ref_desc->reference.offset, source_desc, walk_state);
177 break; 338 break;
178 339
179 340
@@ -187,60 +348,7 @@ acpi_ex_store (
187 "**** Write to Debug Object: Object %p %s ****:\n\n", 348 "**** Write to Debug Object: Object %p %s ****:\n\n",
188 source_desc, acpi_ut_get_object_type_name (source_desc))); 349 source_desc, acpi_ut_get_object_type_name (source_desc)));
189 350
190 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[ACPI Debug] %s: ", 351 acpi_ex_do_debug_object (source_desc, 0, 0);
191 acpi_ut_get_object_type_name (source_desc)));
192
193 if (!acpi_ut_valid_internal_object (source_desc)) {
194 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT,
195 "%p, Invalid Internal Object!\n", source_desc));
196 break;
197 }
198
199 switch (ACPI_GET_OBJECT_TYPE (source_desc)) {
200 case ACPI_TYPE_INTEGER:
201
202 if (acpi_gbl_integer_byte_width == 4) {
203 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "0x%8.8X\n",
204 (u32) source_desc->integer.value));
205 }
206 else {
207 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "0x%8.8X%8.8X\n",
208 ACPI_FORMAT_UINT64 (source_desc->integer.value)));
209 }
210 break;
211
212
213 case ACPI_TYPE_BUFFER:
214
215 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[0x%.2X]",
216 (u32) source_desc->buffer.length));
217 ACPI_DUMP_BUFFER (source_desc->buffer.pointer,
218 (source_desc->buffer.length < 32) ? source_desc->buffer.length : 32);
219 break;
220
221
222 case ACPI_TYPE_STRING:
223
224 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[0x%.2X] \"%s\"\n",
225 source_desc->string.length, source_desc->string.pointer));
226 break;
227
228
229 case ACPI_TYPE_PACKAGE:
230
231 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[0x%.2X] Elements Ptr - %p\n",
232 source_desc->package.count, source_desc->package.elements));
233 break;
234
235
236 default:
237
238 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "%p\n",
239 source_desc));
240 break;
241 }
242
243 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC, "\n"));
244 break; 352 break;
245 353
246 354
@@ -272,7 +380,7 @@ acpi_ex_store (
272 * 380 *
273 ******************************************************************************/ 381 ******************************************************************************/
274 382
275acpi_status 383static acpi_status
276acpi_ex_store_object_to_index ( 384acpi_ex_store_object_to_index (
277 union acpi_operand_object *source_desc, 385 union acpi_operand_object *source_desc,
278 union acpi_operand_object *index_desc, 386 union acpi_operand_object *index_desc,
@@ -313,16 +421,22 @@ acpi_ex_store_object_to_index (
313 if (obj_desc) { 421 if (obj_desc) {
314 /* Decrement reference count by the ref count of the parent package */ 422 /* Decrement reference count by the ref count of the parent package */
315 423
316 for (i = 0; i < ((union acpi_operand_object *) index_desc->reference.object)->common.reference_count; i++) { 424 for (i = 0;
425 i < ((union acpi_operand_object *)
426 index_desc->reference.object)->common.reference_count;
427 i++) {
317 acpi_ut_remove_reference (obj_desc); 428 acpi_ut_remove_reference (obj_desc);
318 } 429 }
319 } 430 }
320 431
321 *(index_desc->reference.where) = new_desc; 432 *(index_desc->reference.where) = new_desc;
322 433
323 /* Increment reference count by the ref count of the parent package -1 */ 434 /* Increment ref count by the ref count of the parent package-1 */
324 435
325 for (i = 1; i < ((union acpi_operand_object *) index_desc->reference.object)->common.reference_count; i++) { 436 for (i = 1;
437 i < ((union acpi_operand_object *)
438 index_desc->reference.object)->common.reference_count;
439 i++) {
326 acpi_ut_add_reference (new_desc); 440 acpi_ut_add_reference (new_desc);
327 } 441 }
328 442
@@ -440,9 +554,8 @@ acpi_ex_store_object_to_node (
440 ACPI_FUNCTION_TRACE_PTR ("ex_store_object_to_node", source_desc); 554 ACPI_FUNCTION_TRACE_PTR ("ex_store_object_to_node", source_desc);
441 555
442 556
443 /* 557 /* Get current type of the node, and object attached to Node */
444 * Get current type of the node, and object attached to Node 558
445 */
446 target_type = acpi_ns_get_type (node); 559 target_type = acpi_ns_get_type (node);
447 target_desc = acpi_ns_get_attached_object (node); 560 target_desc = acpi_ns_get_attached_object (node);
448 561
@@ -467,19 +580,18 @@ acpi_ex_store_object_to_node (
467 target_type = ACPI_TYPE_ANY; 580 target_type = ACPI_TYPE_ANY;
468 } 581 }
469 582
470 /* 583 /* Do the actual store operation */
471 * Do the actual store operation 584
472 */
473 switch (target_type) { 585 switch (target_type) {
474 case ACPI_TYPE_BUFFER_FIELD: 586 case ACPI_TYPE_BUFFER_FIELD:
475 case ACPI_TYPE_LOCAL_REGION_FIELD: 587 case ACPI_TYPE_LOCAL_REGION_FIELD:
476 case ACPI_TYPE_LOCAL_BANK_FIELD: 588 case ACPI_TYPE_LOCAL_BANK_FIELD:
477 case ACPI_TYPE_LOCAL_INDEX_FIELD: 589 case ACPI_TYPE_LOCAL_INDEX_FIELD:
478 590
479 /* 591 /* For fields, copy the source data to the target field. */
480 * For fields, copy the source data to the target field. 592
481 */ 593 status = acpi_ex_write_data_to_field (source_desc, target_desc,
482 status = acpi_ex_write_data_to_field (source_desc, target_desc, &walk_state->result_obj); 594 &walk_state->result_obj);
483 break; 595 break;
484 596
485 597
@@ -493,7 +605,8 @@ acpi_ex_store_object_to_node (
493 * 605 *
494 * Copy and/or convert the source object to a new target object 606 * Copy and/or convert the source object to a new target object
495 */ 607 */
496 status = acpi_ex_store_object_to_object (source_desc, target_desc, &new_desc, walk_state); 608 status = acpi_ex_store_object_to_object (source_desc, target_desc,
609 &new_desc, walk_state);
497 if (ACPI_FAILURE (status)) { 610 if (ACPI_FAILURE (status)) {
498 return_ACPI_STATUS (status); 611 return_ACPI_STATUS (status);
499 } 612 }
@@ -526,7 +639,8 @@ acpi_ex_store_object_to_node (
526 639
527 /* No conversions for all other types. Just attach the source object */ 640 /* No conversions for all other types. Just attach the source object */
528 641
529 status = acpi_ns_attach_object (node, source_desc, ACPI_GET_OBJECT_TYPE (source_desc)); 642 status = acpi_ns_attach_object (node, source_desc,
643 ACPI_GET_OBJECT_TYPE (source_desc));
530 break; 644 break;
531 } 645 }
532 646
diff --git a/drivers/acpi/executer/exstoren.c b/drivers/acpi/executer/exstoren.c
index d3677feb07fd..120f30ed0bd4 100644
--- a/drivers/acpi/executer/exstoren.c
+++ b/drivers/acpi/executer/exstoren.c
@@ -81,9 +81,8 @@ acpi_ex_resolve_object (
81 ACPI_FUNCTION_TRACE ("ex_resolve_object"); 81 ACPI_FUNCTION_TRACE ("ex_resolve_object");
82 82
83 83
84 /* 84 /* Ensure we have a Target that can be stored to */
85 * Ensure we have a Target that can be stored to 85
86 */
87 switch (target_type) { 86 switch (target_type) {
88 case ACPI_TYPE_BUFFER_FIELD: 87 case ACPI_TYPE_BUFFER_FIELD:
89 case ACPI_TYPE_LOCAL_REGION_FIELD: 88 case ACPI_TYPE_LOCAL_REGION_FIELD:
@@ -118,16 +117,14 @@ acpi_ex_resolve_object (
118 break; 117 break;
119 } 118 }
120 119
121 /* 120 /* Must have a Integer, Buffer, or String */
122 * Must have a Integer, Buffer, or String 121
123 */
124 if ((ACPI_GET_OBJECT_TYPE (source_desc) != ACPI_TYPE_INTEGER) && 122 if ((ACPI_GET_OBJECT_TYPE (source_desc) != ACPI_TYPE_INTEGER) &&
125 (ACPI_GET_OBJECT_TYPE (source_desc) != ACPI_TYPE_BUFFER) && 123 (ACPI_GET_OBJECT_TYPE (source_desc) != ACPI_TYPE_BUFFER) &&
126 (ACPI_GET_OBJECT_TYPE (source_desc) != ACPI_TYPE_STRING) && 124 (ACPI_GET_OBJECT_TYPE (source_desc) != ACPI_TYPE_STRING) &&
127 !((ACPI_GET_OBJECT_TYPE (source_desc) == ACPI_TYPE_LOCAL_REFERENCE) && (source_desc->reference.opcode == AML_LOAD_OP))) { 125 !((ACPI_GET_OBJECT_TYPE (source_desc) == ACPI_TYPE_LOCAL_REFERENCE) && (source_desc->reference.opcode == AML_LOAD_OP))) {
128 /* 126 /* Conversion successful but still not a valid type */
129 * Conversion successful but still not a valid type 127
130 */
131 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 128 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
132 "Cannot assign type %s to %s (must be type Int/Str/Buf)\n", 129 "Cannot assign type %s to %s (must be type Int/Str/Buf)\n",
133 acpi_ut_get_object_type_name (source_desc), 130 acpi_ut_get_object_type_name (source_desc),
@@ -140,9 +137,8 @@ acpi_ex_resolve_object (
140 case ACPI_TYPE_LOCAL_ALIAS: 137 case ACPI_TYPE_LOCAL_ALIAS:
141 case ACPI_TYPE_LOCAL_METHOD_ALIAS: 138 case ACPI_TYPE_LOCAL_METHOD_ALIAS:
142 139
143 /* 140 /* Aliases are resolved by acpi_ex_prep_operands */
144 * Aliases are resolved by acpi_ex_prep_operands 141
145 */
146 ACPI_REPORT_ERROR (("Store into Alias - should never happen\n")); 142 ACPI_REPORT_ERROR (("Store into Alias - should never happen\n"));
147 status = AE_AML_INTERNAL; 143 status = AE_AML_INTERNAL;
148 break; 144 break;
diff --git a/drivers/acpi/executer/exstorob.c b/drivers/acpi/executer/exstorob.c
index 05e1ecae8d92..12d1527669c8 100644
--- a/drivers/acpi/executer/exstorob.c
+++ b/drivers/acpi/executer/exstorob.c
@@ -128,7 +128,8 @@ acpi_ex_store_buffer_to_buffer (
128 else { 128 else {
129 /* Truncate the source, copy only what will fit */ 129 /* Truncate the source, copy only what will fit */
130 130
131 ACPI_MEMCPY (target_desc->buffer.pointer, buffer, target_desc->buffer.length); 131 ACPI_MEMCPY (target_desc->buffer.pointer, buffer,
132 target_desc->buffer.length);
132 133
133 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, 134 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
134 "Truncating source buffer from %X to %X\n", 135 "Truncating source buffer from %X to %X\n",
@@ -183,7 +184,8 @@ acpi_ex_store_string_to_string (
183 * String will fit in existing non-static buffer. 184 * String will fit in existing non-static buffer.
184 * Clear old string and copy in the new one 185 * Clear old string and copy in the new one
185 */ 186 */
186 ACPI_MEMSET (target_desc->string.pointer, 0, (acpi_size) target_desc->string.length + 1); 187 ACPI_MEMSET (target_desc->string.pointer, 0,
188 (acpi_size) target_desc->string.length + 1);
187 ACPI_MEMCPY (target_desc->string.pointer, buffer, length); 189 ACPI_MEMCPY (target_desc->string.pointer, buffer, length);
188 } 190 }
189 else { 191 else {
@@ -198,7 +200,8 @@ acpi_ex_store_string_to_string (
198 ACPI_MEM_FREE (target_desc->string.pointer); 200 ACPI_MEM_FREE (target_desc->string.pointer);
199 } 201 }
200 202
201 target_desc->string.pointer = ACPI_MEM_CALLOCATE ((acpi_size) length + 1); 203 target_desc->string.pointer = ACPI_MEM_CALLOCATE (
204 (acpi_size) length + 1);
202 if (!target_desc->string.pointer) { 205 if (!target_desc->string.pointer) {
203 return_ACPI_STATUS (AE_NO_MEMORY); 206 return_ACPI_STATUS (AE_NO_MEMORY);
204 } 207 }
diff --git a/drivers/acpi/executer/exsystem.c b/drivers/acpi/executer/exsystem.c
index f92efc512890..cafa702108dc 100644
--- a/drivers/acpi/executer/exsystem.c
+++ b/drivers/acpi/executer/exsystem.c
@@ -55,8 +55,8 @@
55 * 55 *
56 * FUNCTION: acpi_ex_system_wait_semaphore 56 * FUNCTION: acpi_ex_system_wait_semaphore
57 * 57 *
58 * PARAMETERS: Semaphore - OSD semaphore to wait on 58 * PARAMETERS: Semaphore - Semaphore to wait on
59 * Timeout - Max time to wait 59 * Timeout - Max time to wait
60 * 60 *
61 * RETURN: Status 61 * RETURN: Status
62 * 62 *
@@ -90,7 +90,8 @@ acpi_ex_system_wait_semaphore (
90 90
91 status = acpi_os_wait_semaphore (semaphore, 1, timeout); 91 status = acpi_os_wait_semaphore (semaphore, 1, timeout);
92 92
93 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "*** Thread awake after blocking, %s\n", 93 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
94 "*** Thread awake after blocking, %s\n",
94 acpi_format_exception (status))); 95 acpi_format_exception (status)));
95 96
96 /* Reacquire the interpreter */ 97 /* Reacquire the interpreter */
@@ -111,8 +112,8 @@ acpi_ex_system_wait_semaphore (
111 * 112 *
112 * FUNCTION: acpi_ex_system_do_stall 113 * FUNCTION: acpi_ex_system_do_stall
113 * 114 *
114 * PARAMETERS: how_long - The amount of time to stall, 115 * PARAMETERS: how_long - The amount of time to stall,
115 * in microseconds 116 * in microseconds
116 * 117 *
117 * RETURN: Status 118 * RETURN: Status
118 * 119 *
@@ -141,7 +142,8 @@ acpi_ex_system_do_stall (
141 * (ACPI specifies 100 usec as max, but this gives some slack in 142 * (ACPI specifies 100 usec as max, but this gives some slack in
142 * order to support existing BIOSs) 143 * order to support existing BIOSs)
143 */ 144 */
144 ACPI_REPORT_ERROR (("Stall: Time parameter is too large (%d)\n", how_long)); 145 ACPI_REPORT_ERROR (("Stall: Time parameter is too large (%d)\n",
146 how_long));
145 status = AE_AML_OPERAND_VALUE; 147 status = AE_AML_OPERAND_VALUE;
146 } 148 }
147 else { 149 else {
@@ -156,8 +158,8 @@ acpi_ex_system_do_stall (
156 * 158 *
157 * FUNCTION: acpi_ex_system_do_suspend 159 * FUNCTION: acpi_ex_system_do_suspend
158 * 160 *
159 * PARAMETERS: how_long - The amount of time to suspend, 161 * PARAMETERS: how_long - The amount of time to suspend,
160 * in milliseconds 162 * in milliseconds
161 * 163 *
162 * RETURN: None 164 * RETURN: None
163 * 165 *
@@ -192,8 +194,8 @@ acpi_ex_system_do_suspend (
192 * 194 *
193 * FUNCTION: acpi_ex_system_acquire_mutex 195 * FUNCTION: acpi_ex_system_acquire_mutex
194 * 196 *
195 * PARAMETERS: *time_desc - The 'time to delay' object descriptor 197 * PARAMETERS: time_desc - The 'time to delay' object descriptor
196 * *obj_desc - The object descriptor for this op 198 * obj_desc - The object descriptor for this op
197 * 199 *
198 * RETURN: Status 200 * RETURN: Status
199 * 201 *
@@ -218,16 +220,15 @@ acpi_ex_system_acquire_mutex (
218 return_ACPI_STATUS (AE_BAD_PARAMETER); 220 return_ACPI_STATUS (AE_BAD_PARAMETER);
219 } 221 }
220 222
221 /* 223 /* Support for the _GL_ Mutex object -- go get the global lock */
222 * Support for the _GL_ Mutex object -- go get the global lock 224
223 */
224 if (obj_desc->mutex.semaphore == acpi_gbl_global_lock_semaphore) { 225 if (obj_desc->mutex.semaphore == acpi_gbl_global_lock_semaphore) {
225 status = acpi_ev_acquire_global_lock ((u16) time_desc->integer.value); 226 status = acpi_ev_acquire_global_lock ((u16) time_desc->integer.value);
226 return_ACPI_STATUS (status); 227 return_ACPI_STATUS (status);
227 } 228 }
228 229
229 status = acpi_ex_system_wait_semaphore (obj_desc->mutex.semaphore, 230 status = acpi_ex_system_wait_semaphore (obj_desc->mutex.semaphore,
230 (u16) time_desc->integer.value); 231 (u16) time_desc->integer.value);
231 return_ACPI_STATUS (status); 232 return_ACPI_STATUS (status);
232} 233}
233 234
@@ -236,7 +237,7 @@ acpi_ex_system_acquire_mutex (
236 * 237 *
237 * FUNCTION: acpi_ex_system_release_mutex 238 * FUNCTION: acpi_ex_system_release_mutex
238 * 239 *
239 * PARAMETERS: *obj_desc - The object descriptor for this op 240 * PARAMETERS: obj_desc - The object descriptor for this op
240 * 241 *
241 * RETURN: Status 242 * RETURN: Status
242 * 243 *
@@ -261,9 +262,8 @@ acpi_ex_system_release_mutex (
261 return_ACPI_STATUS (AE_BAD_PARAMETER); 262 return_ACPI_STATUS (AE_BAD_PARAMETER);
262 } 263 }
263 264
264 /* 265 /* Support for the _GL_ Mutex object -- release the global lock */
265 * Support for the _GL_ Mutex object -- release the global lock 266
266 */
267 if (obj_desc->mutex.semaphore == acpi_gbl_global_lock_semaphore) { 267 if (obj_desc->mutex.semaphore == acpi_gbl_global_lock_semaphore) {
268 status = acpi_ev_release_global_lock (); 268 status = acpi_ev_release_global_lock ();
269 return_ACPI_STATUS (status); 269 return_ACPI_STATUS (status);
@@ -278,9 +278,9 @@ acpi_ex_system_release_mutex (
278 * 278 *
279 * FUNCTION: acpi_ex_system_signal_event 279 * FUNCTION: acpi_ex_system_signal_event
280 * 280 *
281 * PARAMETERS: *obj_desc - The object descriptor for this op 281 * PARAMETERS: obj_desc - The object descriptor for this op
282 * 282 *
283 * RETURN: AE_OK 283 * RETURN: Status
284 * 284 *
285 * DESCRIPTION: Provides an access point to perform synchronization operations 285 * DESCRIPTION: Provides an access point to perform synchronization operations
286 * within the AML. 286 * within the AML.
@@ -309,8 +309,8 @@ acpi_ex_system_signal_event (
309 * 309 *
310 * FUNCTION: acpi_ex_system_wait_event 310 * FUNCTION: acpi_ex_system_wait_event
311 * 311 *
312 * PARAMETERS: *time_desc - The 'time to delay' object descriptor 312 * PARAMETERS: time_desc - The 'time to delay' object descriptor
313 * *obj_desc - The object descriptor for this op 313 * obj_desc - The object descriptor for this op
314 * 314 *
315 * RETURN: Status 315 * RETURN: Status
316 * 316 *
@@ -333,7 +333,7 @@ acpi_ex_system_wait_event (
333 333
334 if (obj_desc) { 334 if (obj_desc) {
335 status = acpi_ex_system_wait_semaphore (obj_desc->event.semaphore, 335 status = acpi_ex_system_wait_semaphore (obj_desc->event.semaphore,
336 (u16) time_desc->integer.value); 336 (u16) time_desc->integer.value);
337 } 337 }
338 338
339 return_ACPI_STATUS (status); 339 return_ACPI_STATUS (status);
@@ -344,7 +344,7 @@ acpi_ex_system_wait_event (
344 * 344 *
345 * FUNCTION: acpi_ex_system_reset_event 345 * FUNCTION: acpi_ex_system_reset_event
346 * 346 *
347 * PARAMETERS: *obj_desc - The object descriptor for this op 347 * PARAMETERS: obj_desc - The object descriptor for this op
348 * 348 *
349 * RETURN: Status 349 * RETURN: Status
350 * 350 *
diff --git a/drivers/acpi/executer/exutils.c b/drivers/acpi/executer/exutils.c
index 40c6abb8b49a..5c7ec0c04177 100644
--- a/drivers/acpi/executer/exutils.c
+++ b/drivers/acpi/executer/exutils.c
@@ -67,22 +67,31 @@
67#define _COMPONENT ACPI_EXECUTER 67#define _COMPONENT ACPI_EXECUTER
68 ACPI_MODULE_NAME ("exutils") 68 ACPI_MODULE_NAME ("exutils")
69 69
70/* Local prototypes */
70 71
71#ifndef ACPI_NO_METHOD_EXECUTION 72static u32
73acpi_ex_digits_needed (
74 acpi_integer value,
75 u32 base);
72 76
77
78#ifndef ACPI_NO_METHOD_EXECUTION
73/******************************************************************************* 79/*******************************************************************************
74 * 80 *
75 * FUNCTION: acpi_ex_enter_interpreter 81 * FUNCTION: acpi_ex_enter_interpreter
76 * 82 *
77 * PARAMETERS: None 83 * PARAMETERS: None
78 * 84 *
85 * RETURN: Status
86 *
79 * DESCRIPTION: Enter the interpreter execution region. Failure to enter 87 * DESCRIPTION: Enter the interpreter execution region. Failure to enter
80 * the interpreter region is a fatal system error 88 * the interpreter region is a fatal system error
81 * 89 *
82 ******************************************************************************/ 90 ******************************************************************************/
83 91
84acpi_status 92acpi_status
85acpi_ex_enter_interpreter (void) 93acpi_ex_enter_interpreter (
94 void)
86{ 95{
87 acpi_status status; 96 acpi_status status;
88 97
@@ -104,6 +113,8 @@ acpi_ex_enter_interpreter (void)
104 * 113 *
105 * PARAMETERS: None 114 * PARAMETERS: None
106 * 115 *
116 * RETURN: None
117 *
107 * DESCRIPTION: Exit the interpreter execution region 118 * DESCRIPTION: Exit the interpreter execution region
108 * 119 *
109 * Cases where the interpreter is unlocked: 120 * Cases where the interpreter is unlocked:
@@ -119,7 +130,8 @@ acpi_ex_enter_interpreter (void)
119 ******************************************************************************/ 130 ******************************************************************************/
120 131
121void 132void
122acpi_ex_exit_interpreter (void) 133acpi_ex_exit_interpreter (
134 void)
123{ 135{
124 acpi_status status; 136 acpi_status status;
125 137
@@ -212,7 +224,8 @@ acpi_ex_acquire_global_lock (
212 locked = TRUE; 224 locked = TRUE;
213 } 225 }
214 else { 226 else {
215 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not acquire Global Lock, %s\n", 227 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
228 "Could not acquire Global Lock, %s\n",
216 acpi_format_exception (status))); 229 acpi_format_exception (status)));
217 } 230 }
218 } 231 }
@@ -228,7 +241,7 @@ acpi_ex_acquire_global_lock (
228 * PARAMETERS: locked_by_me - Return value from corresponding call to 241 * PARAMETERS: locked_by_me - Return value from corresponding call to
229 * acquire_global_lock. 242 * acquire_global_lock.
230 * 243 *
231 * RETURN: Status 244 * RETURN: None
232 * 245 *
233 * DESCRIPTION: Release the global lock if it is locked. 246 * DESCRIPTION: Release the global lock if it is locked.
234 * 247 *
@@ -269,11 +282,14 @@ acpi_ex_release_global_lock (
269 * PARAMETERS: Value - Value to be represented 282 * PARAMETERS: Value - Value to be represented
270 * Base - Base of representation 283 * Base - Base of representation
271 * 284 *
272 * RETURN: the number of digits needed to represent Value in Base 285 * RETURN: The number of digits.
286 *
287 * DESCRIPTION: Calculate the number of digits needed to represent the Value
288 * in the given Base (Radix)
273 * 289 *
274 ******************************************************************************/ 290 ******************************************************************************/
275 291
276u32 292static u32
277acpi_ex_digits_needed ( 293acpi_ex_digits_needed (
278 acpi_integer value, 294 acpi_integer value,
279 u32 base) 295 u32 base)
@@ -312,6 +328,8 @@ acpi_ex_digits_needed (
312 * PARAMETERS: numeric_id - EISA ID to be converted 328 * PARAMETERS: numeric_id - EISA ID to be converted
313 * out_string - Where to put the converted string (8 bytes) 329 * out_string - Where to put the converted string (8 bytes)
314 * 330 *
331 * RETURN: None
332 *
315 * DESCRIPTION: Convert a numeric EISA ID to string representation 333 * DESCRIPTION: Convert a numeric EISA ID to string representation
316 * 334 *
317 ******************************************************************************/ 335 ******************************************************************************/
@@ -349,7 +367,10 @@ acpi_ex_eisa_id_to_string (
349 * PARAMETERS: Value - Value to be converted 367 * PARAMETERS: Value - Value to be converted
350 * out_string - Where to put the converted string (8 bytes) 368 * out_string - Where to put the converted string (8 bytes)
351 * 369 *
352 * RETURN: Convert a number to string representation 370 * RETURN: None, string
371 *
372 * DESCRIPTOIN: Convert a number to string representation. Assumes string
373 * buffer is large enough to hold the string.
353 * 374 *
354 ******************************************************************************/ 375 ******************************************************************************/
355 376
diff --git a/drivers/acpi/glue.c b/drivers/acpi/glue.c
new file mode 100644
index 000000000000..770cfc8b17e0
--- /dev/null
+++ b/drivers/acpi/glue.c
@@ -0,0 +1,360 @@
1/*
2 * Link physical devices with ACPI devices support
3 *
4 * Copyright (c) 2005 David Shaohua Li <shaohua.li@intel.com>
5 * Copyright (c) 2005 Intel Corp.
6 *
7 * This file is released under the GPLv2.
8 */
9#include <linux/init.h>
10#include <linux/list.h>
11#include <linux/device.h>
12#include <linux/rwsem.h>
13#include <linux/acpi.h>
14
15#define ACPI_GLUE_DEBUG 0
16#if ACPI_GLUE_DEBUG
17#define DBG(x...) printk(PREFIX x)
18#else
19#define DBG(x...)
20#endif
21static LIST_HEAD(bus_type_list);
22static DECLARE_RWSEM(bus_type_sem);
23
24int register_acpi_bus_type(struct acpi_bus_type *type)
25{
26 if (acpi_disabled)
27 return -ENODEV;
28 if (type && type->bus && type->find_device) {
29 down_write(&bus_type_sem);
30 list_add_tail(&type->list, &bus_type_list);
31 up_write(&bus_type_sem);
32 printk(KERN_INFO PREFIX "bus type %s registered\n", type->bus->name);
33 return 0;
34 }
35 return -ENODEV;
36}
37
38EXPORT_SYMBOL(register_acpi_bus_type);
39
40int unregister_acpi_bus_type(struct acpi_bus_type *type)
41{
42 if (acpi_disabled)
43 return 0;
44 if (type) {
45 down_write(&bus_type_sem);
46 list_del_init(&type->list);
47 up_write(&bus_type_sem);
48 printk(KERN_INFO PREFIX "ACPI bus type %s unregistered\n", type->bus->name);
49 return 0;
50 }
51 return -ENODEV;
52}
53
54EXPORT_SYMBOL(unregister_acpi_bus_type);
55
56static struct acpi_bus_type *acpi_get_bus_type(struct bus_type *type)
57{
58 struct acpi_bus_type *tmp, *ret = NULL;
59
60 down_read(&bus_type_sem);
61 list_for_each_entry(tmp, &bus_type_list, list) {
62 if (tmp->bus == type) {
63 ret = tmp;
64 break;
65 }
66 }
67 up_read(&bus_type_sem);
68 return ret;
69}
70
71static int acpi_find_bridge_device(struct device *dev, acpi_handle * handle)
72{
73 struct acpi_bus_type *tmp;
74 int ret = -ENODEV;
75
76 down_read(&bus_type_sem);
77 list_for_each_entry(tmp, &bus_type_list, list) {
78 if (tmp->find_bridge && !tmp->find_bridge(dev, handle)) {
79 ret = 0;
80 break;
81 }
82 }
83 up_read(&bus_type_sem);
84 return ret;
85}
86
87/* Get PCI root bridge's handle from its segment and bus number */
88struct acpi_find_pci_root {
89 unsigned int seg;
90 unsigned int bus;
91 acpi_handle handle;
92};
93
94static acpi_status
95do_root_bridge_busnr_callback(struct acpi_resource *resource, void *data)
96{
97 int *busnr = (int *)data;
98 struct acpi_resource_address64 address;
99
100 if (resource->id != ACPI_RSTYPE_ADDRESS16 &&
101 resource->id != ACPI_RSTYPE_ADDRESS32 &&
102 resource->id != ACPI_RSTYPE_ADDRESS64)
103 return AE_OK;
104
105 acpi_resource_to_address64(resource, &address);
106 if ((address.address_length > 0) &&
107 (address.resource_type == ACPI_BUS_NUMBER_RANGE))
108 *busnr = address.min_address_range;
109
110 return AE_OK;
111}
112
113static int get_root_bridge_busnr(acpi_handle handle)
114{
115 acpi_status status;
116 int bus, bbn;
117 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
118
119 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
120
121 status = acpi_evaluate_integer(handle, METHOD_NAME__BBN, NULL,
122 (unsigned long *)&bbn);
123 if (status == AE_NOT_FOUND) {
124 /* Assume bus = 0 */
125 printk(KERN_INFO PREFIX
126 "Assume root bridge [%s] bus is 0\n",
127 (char *)buffer.pointer);
128 status = AE_OK;
129 bbn = 0;
130 }
131 if (ACPI_FAILURE(status)) {
132 bbn = -ENODEV;
133 goto exit;
134 }
135 if (bbn > 0)
136 goto exit;
137
138 /* _BBN in some systems return 0 for all root bridges */
139 bus = -1;
140 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
141 do_root_bridge_busnr_callback, &bus);
142 /* If _CRS failed, we just use _BBN */
143 if (ACPI_FAILURE(status) || (bus == -1))
144 goto exit;
145 /* We select _CRS */
146 if (bbn != bus) {
147 printk(KERN_INFO PREFIX
148 "_BBN and _CRS returns different value for %s. Select _CRS\n",
149 (char *)buffer.pointer);
150 bbn = bus;
151 }
152 exit:
153 acpi_os_free(buffer.pointer);
154 return bbn;
155}
156
157static acpi_status
158find_pci_rootbridge(acpi_handle handle, u32 lvl, void *context, void **rv)
159{
160 struct acpi_find_pci_root *find = (struct acpi_find_pci_root *)context;
161 unsigned long seg, bus;
162 acpi_status status;
163 int tmp;
164 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
165
166 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
167
168 status = acpi_evaluate_integer(handle, METHOD_NAME__SEG, NULL, &seg);
169 if (status == AE_NOT_FOUND) {
170 /* Assume seg = 0 */
171 printk(KERN_INFO PREFIX
172 "Assume root bridge [%s] segment is 0\n",
173 (char *)buffer.pointer);
174 status = AE_OK;
175 seg = 0;
176 }
177 if (ACPI_FAILURE(status)) {
178 status = AE_CTRL_DEPTH;
179 goto exit;
180 }
181
182 tmp = get_root_bridge_busnr(handle);
183 if (tmp < 0) {
184 printk(KERN_ERR PREFIX
185 "Find root bridge failed for %s\n",
186 (char *)buffer.pointer);
187 status = AE_CTRL_DEPTH;
188 goto exit;
189 }
190 bus = tmp;
191
192 if (seg == find->seg && bus == find->bus)
193 find->handle = handle;
194 status = AE_OK;
195 exit:
196 acpi_os_free(buffer.pointer);
197 return status;
198}
199
200acpi_handle acpi_get_pci_rootbridge_handle(unsigned int seg, unsigned int bus)
201{
202 struct acpi_find_pci_root find = { seg, bus, NULL };
203
204 acpi_get_devices(PCI_ROOT_HID_STRING, find_pci_rootbridge, &find, NULL);
205 return find.handle;
206}
207
208/* Get device's handler per its address under its parent */
209struct acpi_find_child {
210 acpi_handle handle;
211 acpi_integer address;
212};
213
214static acpi_status
215do_acpi_find_child(acpi_handle handle, u32 lvl, void *context, void **rv)
216{
217 acpi_status status;
218 struct acpi_device_info *info;
219 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
220 struct acpi_find_child *find = (struct acpi_find_child *)context;
221
222 status = acpi_get_object_info(handle, &buffer);
223 if (ACPI_SUCCESS(status)) {
224 info = buffer.pointer;
225 if (info->address == find->address)
226 find->handle = handle;
227 acpi_os_free(buffer.pointer);
228 }
229 return AE_OK;
230}
231
232acpi_handle acpi_get_child(acpi_handle parent, acpi_integer address)
233{
234 struct acpi_find_child find = { NULL, address };
235
236 if (!parent)
237 return NULL;
238 acpi_walk_namespace(ACPI_TYPE_DEVICE, parent,
239 1, do_acpi_find_child, &find, NULL);
240 return find.handle;
241}
242
243EXPORT_SYMBOL(acpi_get_child);
244
245/* Link ACPI devices with physical devices */
246static void acpi_glue_data_handler(acpi_handle handle,
247 u32 function, void *context)
248{
249 /* we provide an empty handler */
250}
251
252/* Note: a success call will increase reference count by one */
253struct device *acpi_get_physical_device(acpi_handle handle)
254{
255 acpi_status status;
256 struct device *dev;
257
258 status = acpi_get_data(handle, acpi_glue_data_handler, (void **)&dev);
259 if (ACPI_SUCCESS(status))
260 return get_device(dev);
261 return NULL;
262}
263
264EXPORT_SYMBOL(acpi_get_physical_device);
265
266static int acpi_bind_one(struct device *dev, acpi_handle handle)
267{
268 acpi_status status;
269
270 if (dev->firmware_data) {
271 printk(KERN_WARNING PREFIX
272 "Drivers changed 'firmware_data' for %s\n", dev->bus_id);
273 return -EINVAL;
274 }
275 get_device(dev);
276 status = acpi_attach_data(handle, acpi_glue_data_handler, dev);
277 if (ACPI_FAILURE(status)) {
278 put_device(dev);
279 return -EINVAL;
280 }
281 dev->firmware_data = handle;
282
283 return 0;
284}
285
286static int acpi_unbind_one(struct device *dev)
287{
288 if (!dev->firmware_data)
289 return 0;
290 if (dev == acpi_get_physical_device(dev->firmware_data)) {
291 /* acpi_get_physical_device increase refcnt by one */
292 put_device(dev);
293 acpi_detach_data(dev->firmware_data, acpi_glue_data_handler);
294 dev->firmware_data = NULL;
295 /* acpi_bind_one increase refcnt by one */
296 put_device(dev);
297 } else {
298 printk(KERN_ERR PREFIX
299 "Oops, 'firmware_data' corrupt for %s\n", dev->bus_id);
300 }
301 return 0;
302}
303
304static int acpi_platform_notify(struct device *dev)
305{
306 struct acpi_bus_type *type;
307 acpi_handle handle;
308 int ret = -EINVAL;
309
310 if (!dev->bus || !dev->parent) {
311 /* bridge devices genernally haven't bus or parent */
312 ret = acpi_find_bridge_device(dev, &handle);
313 goto end;
314 }
315 type = acpi_get_bus_type(dev->bus);
316 if (!type) {
317 DBG("No ACPI bus support for %s\n", dev->bus_id);
318 ret = -EINVAL;
319 goto end;
320 }
321 if ((ret = type->find_device(dev, &handle)) != 0)
322 DBG("Can't get handler for %s\n", dev->bus_id);
323 end:
324 if (!ret)
325 acpi_bind_one(dev, handle);
326
327#if ACPI_GLUE_DEBUG
328 if (!ret) {
329 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
330
331 acpi_get_name(dev->firmware_data, ACPI_FULL_PATHNAME, &buffer);
332 DBG("Device %s -> %s\n", dev->bus_id, (char *)buffer.pointer);
333 acpi_os_free(buffer.pointer);
334 } else
335 DBG("Device %s -> No ACPI support\n", dev->bus_id);
336#endif
337
338 return ret;
339}
340
341static int acpi_platform_notify_remove(struct device *dev)
342{
343 acpi_unbind_one(dev);
344 return 0;
345}
346
347static int __init init_acpi_device_notify(void)
348{
349 if (acpi_disabled)
350 return 0;
351 if (platform_notify || platform_notify_remove) {
352 printk(KERN_ERR PREFIX "Can't use platform_notify\n");
353 return 0;
354 }
355 platform_notify = acpi_platform_notify;
356 platform_notify_remove = acpi_platform_notify_remove;
357 return 0;
358}
359
360arch_initcall(init_acpi_device_notify);
diff --git a/drivers/acpi/hardware/hwacpi.c b/drivers/acpi/hardware/hwacpi.c
index 529e922bdc85..b51001e74eea 100644
--- a/drivers/acpi/hardware/hwacpi.c
+++ b/drivers/acpi/hardware/hwacpi.c
@@ -58,7 +58,8 @@
58 * 58 *
59 * RETURN: Status 59 * RETURN: Status
60 * 60 *
61 * DESCRIPTION: Initialize and validate various ACPI registers 61 * DESCRIPTION: Initialize and validate the various ACPI registers defined in
62 * the FADT.
62 * 63 *
63 ******************************************************************************/ 64 ******************************************************************************/
64 65
@@ -75,7 +76,7 @@ acpi_hw_initialize (
75 /* We must have the ACPI tables by the time we get here */ 76 /* We must have the ACPI tables by the time we get here */
76 77
77 if (!acpi_gbl_FADT) { 78 if (!acpi_gbl_FADT) {
78 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "A FADT is not loaded\n")); 79 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No FADT is present\n"));
79 80
80 return_ACPI_STATUS (AE_NO_ACPI_TABLES); 81 return_ACPI_STATUS (AE_NO_ACPI_TABLES);
81 } 82 }
@@ -131,7 +132,8 @@ acpi_hw_set_mode (
131 * transitions are not supported. 132 * transitions are not supported.
132 */ 133 */
133 if (!acpi_gbl_FADT->acpi_enable && !acpi_gbl_FADT->acpi_disable) { 134 if (!acpi_gbl_FADT->acpi_enable && !acpi_gbl_FADT->acpi_disable) {
134 ACPI_REPORT_ERROR (("No ACPI mode transition supported in this system (enable/disable both zero)\n")); 135 ACPI_REPORT_ERROR ((
136 "No ACPI mode transition supported in this system (enable/disable both zero)\n"));
135 return_ACPI_STATUS (AE_OK); 137 return_ACPI_STATUS (AE_OK);
136 } 138 }
137 139
@@ -162,7 +164,8 @@ acpi_hw_set_mode (
162 } 164 }
163 165
164 if (ACPI_FAILURE (status)) { 166 if (ACPI_FAILURE (status)) {
165 ACPI_REPORT_ERROR (("Could not write mode change, %s\n", acpi_format_exception (status))); 167 ACPI_REPORT_ERROR (("Could not write mode change, %s\n",
168 acpi_format_exception (status)));
166 return_ACPI_STATUS (status); 169 return_ACPI_STATUS (status);
167 } 170 }
168 171
@@ -173,7 +176,8 @@ acpi_hw_set_mode (
173 retry = 3000; 176 retry = 3000;
174 while (retry) { 177 while (retry) {
175 if (acpi_hw_get_mode() == mode) { 178 if (acpi_hw_get_mode() == mode) {
176 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Mode %X successfully enabled\n", mode)); 179 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Mode %X successfully enabled\n",
180 mode));
177 return_ACPI_STATUS (AE_OK); 181 return_ACPI_STATUS (AE_OK);
178 } 182 }
179 acpi_os_stall(1000); 183 acpi_os_stall(1000);
@@ -185,7 +189,7 @@ acpi_hw_set_mode (
185} 189}
186 190
187 191
188/****************************************************************************** 192/*******************************************************************************
189 * 193 *
190 * FUNCTION: acpi_hw_get_mode 194 * FUNCTION: acpi_hw_get_mode
191 * 195 *
@@ -199,7 +203,8 @@ acpi_hw_set_mode (
199 ******************************************************************************/ 203 ******************************************************************************/
200 204
201u32 205u32
202acpi_hw_get_mode (void) 206acpi_hw_get_mode (
207 void)
203{ 208{
204 acpi_status status; 209 acpi_status status;
205 u32 value; 210 u32 value;
diff --git a/drivers/acpi/hardware/hwgpe.c b/drivers/acpi/hardware/hwgpe.c
index 9ac1d639bf51..8daeabb2fc7a 100644
--- a/drivers/acpi/hardware/hwgpe.c
+++ b/drivers/acpi/hardware/hwgpe.c
@@ -48,6 +48,13 @@
48#define _COMPONENT ACPI_HARDWARE 48#define _COMPONENT ACPI_HARDWARE
49 ACPI_MODULE_NAME ("hwgpe") 49 ACPI_MODULE_NAME ("hwgpe")
50 50
51/* Local prototypes */
52
53static acpi_status
54acpi_hw_enable_wakeup_gpe_block (
55 struct acpi_gpe_xrupt_info *gpe_xrupt_info,
56 struct acpi_gpe_block_info *gpe_block);
57
51 58
52/****************************************************************************** 59/******************************************************************************
53 * 60 *
@@ -135,6 +142,7 @@ acpi_hw_clear_gpe (
135 * DESCRIPTION: Return the status of a single GPE. 142 * DESCRIPTION: Return the status of a single GPE.
136 * 143 *
137 ******************************************************************************/ 144 ******************************************************************************/
145
138#ifdef ACPI_FUTURE_USAGE 146#ifdef ACPI_FUTURE_USAGE
139acpi_status 147acpi_status
140acpi_hw_get_gpe_status ( 148acpi_hw_get_gpe_status (
@@ -206,7 +214,7 @@ unlock_and_exit:
206 * 214 *
207 * RETURN: Status 215 * RETURN: Status
208 * 216 *
209 * DESCRIPTION: Disable all GPEs within a GPE block 217 * DESCRIPTION: Disable all GPEs within a single GPE block
210 * 218 *
211 ******************************************************************************/ 219 ******************************************************************************/
212 220
@@ -244,7 +252,7 @@ acpi_hw_disable_gpe_block (
244 * 252 *
245 * RETURN: Status 253 * RETURN: Status
246 * 254 *
247 * DESCRIPTION: Clear status bits for all GPEs within a GPE block 255 * DESCRIPTION: Clear status bits for all GPEs within a single GPE block
248 * 256 *
249 ******************************************************************************/ 257 ******************************************************************************/
250 258
@@ -282,8 +290,8 @@ acpi_hw_clear_gpe_block (
282 * 290 *
283 * RETURN: Status 291 * RETURN: Status
284 * 292 *
285 * DESCRIPTION: Enable all "runtime" GPEs within a GPE block. (Includes 293 * DESCRIPTION: Enable all "runtime" GPEs within a single GPE block. Includes
286 * combination wake/run GPEs.) 294 * combination wake/run GPEs.
287 * 295 *
288 ******************************************************************************/ 296 ******************************************************************************/
289 297
@@ -327,12 +335,12 @@ acpi_hw_enable_runtime_gpe_block (
327 * 335 *
328 * RETURN: Status 336 * RETURN: Status
329 * 337 *
330 * DESCRIPTION: Enable all "wake" GPEs within a GPE block. (Includes 338 * DESCRIPTION: Enable all "wake" GPEs within a single GPE block. Includes
331 * combination wake/run GPEs.) 339 * combination wake/run GPEs.
332 * 340 *
333 ******************************************************************************/ 341 ******************************************************************************/
334 342
335acpi_status 343static acpi_status
336acpi_hw_enable_wakeup_gpe_block ( 344acpi_hw_enable_wakeup_gpe_block (
337 struct acpi_gpe_xrupt_info *gpe_xrupt_info, 345 struct acpi_gpe_xrupt_info *gpe_xrupt_info,
338 struct acpi_gpe_block_info *gpe_block) 346 struct acpi_gpe_block_info *gpe_block)
@@ -350,7 +358,8 @@ acpi_hw_enable_wakeup_gpe_block (
350 358
351 /* Enable all "wake" GPEs in this register */ 359 /* Enable all "wake" GPEs in this register */
352 360
353 status = acpi_hw_low_level_write (8, gpe_block->register_info[i].enable_for_wake, 361 status = acpi_hw_low_level_write (8,
362 gpe_block->register_info[i].enable_for_wake,
354 &gpe_block->register_info[i].enable_address); 363 &gpe_block->register_info[i].enable_address);
355 if (ACPI_FAILURE (status)) { 364 if (ACPI_FAILURE (status)) {
356 return (status); 365 return (status);
@@ -369,7 +378,7 @@ acpi_hw_enable_wakeup_gpe_block (
369 * 378 *
370 * RETURN: Status 379 * RETURN: Status
371 * 380 *
372 * DESCRIPTION: Disable and clear all GPEs 381 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
373 * 382 *
374 ******************************************************************************/ 383 ******************************************************************************/
375 384
@@ -397,7 +406,7 @@ acpi_hw_disable_all_gpes (
397 * 406 *
398 * RETURN: Status 407 * RETURN: Status
399 * 408 *
400 * DESCRIPTION: Enable all GPEs of the given type 409 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
401 * 410 *
402 ******************************************************************************/ 411 ******************************************************************************/
403 412
@@ -424,7 +433,7 @@ acpi_hw_enable_all_runtime_gpes (
424 * 433 *
425 * RETURN: Status 434 * RETURN: Status
426 * 435 *
427 * DESCRIPTION: Enable all GPEs of the given type 436 * DESCRIPTION: Enable all "wakeup" GPEs, in all GPE blocks
428 * 437 *
429 ******************************************************************************/ 438 ******************************************************************************/
430 439
diff --git a/drivers/acpi/hardware/hwregs.c b/drivers/acpi/hardware/hwregs.c
index 91af0c2ddcf7..6d9e4eb84836 100644
--- a/drivers/acpi/hardware/hwregs.c
+++ b/drivers/acpi/hardware/hwregs.c
@@ -87,8 +87,9 @@ acpi_hw_clear_acpi_status (
87 } 87 }
88 } 88 }
89 89
90 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1_STATUS, 90 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK,
91 ACPI_BITMASK_ALL_FIXED_STATUS); 91 ACPI_REGISTER_PM1_STATUS,
92 ACPI_BITMASK_ALL_FIXED_STATUS);
92 if (ACPI_FAILURE (status)) { 93 if (ACPI_FAILURE (status)) {
93 goto unlock_and_exit; 94 goto unlock_and_exit;
94 } 95 }
@@ -138,28 +139,30 @@ acpi_get_sleep_type_data (
138{ 139{
139 acpi_status status = AE_OK; 140 acpi_status status = AE_OK;
140 struct acpi_parameter_info info; 141 struct acpi_parameter_info info;
142 char *sleep_state_name;
141 143
142 144
143 ACPI_FUNCTION_TRACE ("acpi_get_sleep_type_data"); 145 ACPI_FUNCTION_TRACE ("acpi_get_sleep_type_data");
144 146
145 147
146 /* 148 /* Validate parameters */
147 * Validate parameters 149
148 */
149 if ((sleep_state > ACPI_S_STATES_MAX) || 150 if ((sleep_state > ACPI_S_STATES_MAX) ||
150 !sleep_type_a || !sleep_type_b) { 151 !sleep_type_a || !sleep_type_b) {
151 return_ACPI_STATUS (AE_BAD_PARAMETER); 152 return_ACPI_STATUS (AE_BAD_PARAMETER);
152 } 153 }
153 154
154 /* 155 /* Evaluate the namespace object containing the values for this state */
155 * Evaluate the namespace object containing the values for this state 156
156 */
157 info.parameters = NULL; 157 info.parameters = NULL;
158 status = acpi_ns_evaluate_by_name ((char *) acpi_gbl_sleep_state_names[sleep_state], 158 info.return_object = NULL;
159 &info); 159 sleep_state_name = (char *) acpi_gbl_sleep_state_names[sleep_state];
160
161 status = acpi_ns_evaluate_by_name (sleep_state_name, &info);
160 if (ACPI_FAILURE (status)) { 162 if (ACPI_FAILURE (status)) {
161 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%s while evaluating sleep_state [%s]\n", 163 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
162 acpi_format_exception (status), acpi_gbl_sleep_state_names[sleep_state])); 164 "%s while evaluating sleep_state [%s]\n",
165 acpi_format_exception (status), sleep_state_name));
163 166
164 return_ACPI_STATUS (status); 167 return_ACPI_STATUS (status);
165 } 168 }
@@ -167,45 +170,57 @@ acpi_get_sleep_type_data (
167 /* Must have a return object */ 170 /* Must have a return object */
168 171
169 if (!info.return_object) { 172 if (!info.return_object) {
170 ACPI_REPORT_ERROR (("Missing Sleep State object\n")); 173 ACPI_REPORT_ERROR (("No Sleep State object returned from [%s]\n",
174 sleep_state_name));
171 status = AE_NOT_EXIST; 175 status = AE_NOT_EXIST;
172 } 176 }
173 177
174 /* It must be of type Package */ 178 /* It must be of type Package */
175 179
176 else if (ACPI_GET_OBJECT_TYPE (info.return_object) != ACPI_TYPE_PACKAGE) { 180 else if (ACPI_GET_OBJECT_TYPE (info.return_object) != ACPI_TYPE_PACKAGE) {
177 ACPI_REPORT_ERROR (("Sleep State object not a Package\n")); 181 ACPI_REPORT_ERROR (("Sleep State return object is not a Package\n"));
178 status = AE_AML_OPERAND_TYPE; 182 status = AE_AML_OPERAND_TYPE;
179 } 183 }
180 184
181 /* The package must have at least two elements */ 185 /*
182 186 * The package must have at least two elements. NOTE (March 2005): This
187 * goes against the current ACPI spec which defines this object as a
188 * package with one encoded DWORD element. However, existing practice
189 * by BIOS vendors seems to be to have 2 or more elements, at least
190 * one per sleep type (A/B).
191 */
183 else if (info.return_object->package.count < 2) { 192 else if (info.return_object->package.count < 2) {
184 ACPI_REPORT_ERROR (("Sleep State package does not have at least two elements\n")); 193 ACPI_REPORT_ERROR ((
194 "Sleep State return package does not have at least two elements\n"));
185 status = AE_AML_NO_OPERAND; 195 status = AE_AML_NO_OPERAND;
186 } 196 }
187 197
188 /* The first two elements must both be of type Integer */ 198 /* The first two elements must both be of type Integer */
189 199
190 else if ((ACPI_GET_OBJECT_TYPE (info.return_object->package.elements[0]) != ACPI_TYPE_INTEGER) || 200 else if ((ACPI_GET_OBJECT_TYPE (info.return_object->package.elements[0])
191 (ACPI_GET_OBJECT_TYPE (info.return_object->package.elements[1]) != ACPI_TYPE_INTEGER)) { 201 != ACPI_TYPE_INTEGER) ||
192 ACPI_REPORT_ERROR (("Sleep State package elements are not both Integers (%s, %s)\n", 202 (ACPI_GET_OBJECT_TYPE (info.return_object->package.elements[1])
203 != ACPI_TYPE_INTEGER)) {
204 ACPI_REPORT_ERROR ((
205 "Sleep State return package elements are not both Integers (%s, %s)\n",
193 acpi_ut_get_object_type_name (info.return_object->package.elements[0]), 206 acpi_ut_get_object_type_name (info.return_object->package.elements[0]),
194 acpi_ut_get_object_type_name (info.return_object->package.elements[1]))); 207 acpi_ut_get_object_type_name (info.return_object->package.elements[1])));
195 status = AE_AML_OPERAND_TYPE; 208 status = AE_AML_OPERAND_TYPE;
196 } 209 }
197 else { 210 else {
198 /* 211 /* Valid _Sx_ package size, type, and value */
199 * Valid _Sx_ package size, type, and value 212
200 */ 213 *sleep_type_a = (u8)
201 *sleep_type_a = (u8) (info.return_object->package.elements[0])->integer.value; 214 (info.return_object->package.elements[0])->integer.value;
202 *sleep_type_b = (u8) (info.return_object->package.elements[1])->integer.value; 215 *sleep_type_b = (u8)
216 (info.return_object->package.elements[1])->integer.value;
203 } 217 }
204 218
205 if (ACPI_FAILURE (status)) { 219 if (ACPI_FAILURE (status)) {
206 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 220 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
207 "While evaluating sleep_state [%s], bad Sleep object %p type %s\n", 221 "%s While evaluating sleep_state [%s], bad Sleep object %p type %s\n",
208 acpi_gbl_sleep_state_names[sleep_state], info.return_object, 222 acpi_format_exception (status),
223 sleep_state_name, info.return_object,
209 acpi_ut_get_object_type_name (info.return_object))); 224 acpi_ut_get_object_type_name (info.return_object)));
210 } 225 }
211 226
@@ -221,9 +236,9 @@ EXPORT_SYMBOL(acpi_get_sleep_type_data);
221 * 236 *
222 * PARAMETERS: register_id - Index of ACPI Register to access 237 * PARAMETERS: register_id - Index of ACPI Register to access
223 * 238 *
224 * RETURN: The bit mask to be used when accessing the register 239 * RETURN: The bitmask to be used when accessing the register
225 * 240 *
226 * DESCRIPTION: Map register_id into a register bit mask. 241 * DESCRIPTION: Map register_id into a register bitmask.
227 * 242 *
228 ******************************************************************************/ 243 ******************************************************************************/
229 244
@@ -359,7 +374,7 @@ acpi_set_register (
359 /* Always do a register read first so we can insert the new bits */ 374 /* Always do a register read first so we can insert the new bits */
360 375
361 status = acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK, 376 status = acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK,
362 bit_reg_info->parent_register, &register_value); 377 bit_reg_info->parent_register, &register_value);
363 if (ACPI_FAILURE (status)) { 378 if (ACPI_FAILURE (status)) {
364 goto unlock_and_exit; 379 goto unlock_and_exit;
365 } 380 }
@@ -396,7 +411,7 @@ acpi_set_register (
396 bit_reg_info->access_bit_mask, value); 411 bit_reg_info->access_bit_mask, value);
397 412
398 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK, 413 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK,
399 ACPI_REGISTER_PM1_ENABLE, (u16) register_value); 414 ACPI_REGISTER_PM1_ENABLE, (u16) register_value);
400 break; 415 break;
401 416
402 417
@@ -413,7 +428,7 @@ acpi_set_register (
413 bit_reg_info->access_bit_mask, value); 428 bit_reg_info->access_bit_mask, value);
414 429
415 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK, 430 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK,
416 ACPI_REGISTER_PM1_CONTROL, (u16) register_value); 431 ACPI_REGISTER_PM1_CONTROL, (u16) register_value);
417 break; 432 break;
418 433
419 434
@@ -427,17 +442,19 @@ acpi_set_register (
427 442
428 ACPI_DEBUG_PRINT ((ACPI_DB_IO, "PM2 control: Read %X from %8.8X%8.8X\n", 443 ACPI_DEBUG_PRINT ((ACPI_DB_IO, "PM2 control: Read %X from %8.8X%8.8X\n",
429 register_value, 444 register_value,
430 ACPI_FORMAT_UINT64 (acpi_gbl_FADT->xpm2_cnt_blk.address))); 445 ACPI_FORMAT_UINT64 (
446 acpi_gbl_FADT->xpm2_cnt_blk.address)));
431 447
432 ACPI_REGISTER_INSERT_VALUE (register_value, bit_reg_info->bit_position, 448 ACPI_REGISTER_INSERT_VALUE (register_value, bit_reg_info->bit_position,
433 bit_reg_info->access_bit_mask, value); 449 bit_reg_info->access_bit_mask, value);
434 450
435 ACPI_DEBUG_PRINT ((ACPI_DB_IO, "About to write %4.4X to %8.8X%8.8X\n", 451 ACPI_DEBUG_PRINT ((ACPI_DB_IO, "About to write %4.4X to %8.8X%8.8X\n",
436 register_value, 452 register_value,
437 ACPI_FORMAT_UINT64 (acpi_gbl_FADT->xpm2_cnt_blk.address))); 453 ACPI_FORMAT_UINT64 (
454 acpi_gbl_FADT->xpm2_cnt_blk.address)));
438 455
439 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK, 456 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK,
440 ACPI_REGISTER_PM2_CONTROL, (u8) (register_value)); 457 ACPI_REGISTER_PM2_CONTROL, (u8) (register_value));
441 break; 458 break;
442 459
443 460
@@ -454,7 +471,9 @@ unlock_and_exit:
454 471
455 /* Normalize the value that was read */ 472 /* Normalize the value that was read */
456 473
457 ACPI_DEBUG_EXEC (register_value = ((register_value & bit_reg_info->access_bit_mask) >> bit_reg_info->bit_position)); 474 ACPI_DEBUG_EXEC (register_value =
475 ((register_value & bit_reg_info->access_bit_mask) >>
476 bit_reg_info->bit_position));
458 477
459 ACPI_DEBUG_PRINT ((ACPI_DB_IO, "Set bits: %8.8X actual %8.8X register %X\n", 478 ACPI_DEBUG_PRINT ((ACPI_DB_IO, "Set bits: %8.8X actual %8.8X register %X\n",
460 value, register_value, bit_reg_info->parent_register)); 479 value, register_value, bit_reg_info->parent_register));
@@ -469,7 +488,7 @@ EXPORT_SYMBOL(acpi_set_register);
469 * 488 *
470 * PARAMETERS: use_lock - Mutex hw access 489 * PARAMETERS: use_lock - Mutex hw access
471 * register_id - register_iD + Offset 490 * register_id - register_iD + Offset
472 * return_value - Value that was read from the register 491 * return_value - Where the register value is returned
473 * 492 *
474 * RETURN: Status and the value read. 493 * RETURN: Status and the value read.
475 * 494 *
@@ -557,7 +576,8 @@ acpi_hw_register_read (
557 break; 576 break;
558 577
559 default: 578 default:
560 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown Register ID: %X\n", register_id)); 579 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown Register ID: %X\n",
580 register_id));
561 status = AE_BAD_PARAMETER; 581 status = AE_BAD_PARAMETER;
562 break; 582 break;
563 } 583 }
@@ -763,10 +783,11 @@ acpi_hw_low_level_read (
763 return (AE_BAD_PARAMETER); 783 return (AE_BAD_PARAMETER);
764 } 784 }
765 785
766 ACPI_DEBUG_PRINT ((ACPI_DB_IO, "Read: %8.8X width %2d from %8.8X%8.8X (%s)\n", 786 ACPI_DEBUG_PRINT ((ACPI_DB_IO,
767 *value, width, 787 "Read: %8.8X width %2d from %8.8X%8.8X (%s)\n",
768 ACPI_FORMAT_UINT64 (address), 788 *value, width,
769 acpi_ut_get_region_name (reg->address_space_id))); 789 ACPI_FORMAT_UINT64 (address),
790 acpi_ut_get_region_name (reg->address_space_id)));
770 791
771 return (status); 792 return (status);
772} 793}
@@ -841,10 +862,11 @@ acpi_hw_low_level_write (
841 return (AE_BAD_PARAMETER); 862 return (AE_BAD_PARAMETER);
842 } 863 }
843 864
844 ACPI_DEBUG_PRINT ((ACPI_DB_IO, "Wrote: %8.8X width %2d to %8.8X%8.8X (%s)\n", 865 ACPI_DEBUG_PRINT ((ACPI_DB_IO,
845 value, width, 866 "Wrote: %8.8X width %2d to %8.8X%8.8X (%s)\n",
846 ACPI_FORMAT_UINT64 (address), 867 value, width,
847 acpi_ut_get_region_name (reg->address_space_id))); 868 ACPI_FORMAT_UINT64 (address),
869 acpi_ut_get_region_name (reg->address_space_id)));
848 870
849 return (status); 871 return (status);
850} 872}
diff --git a/drivers/acpi/hardware/hwsleep.c b/drivers/acpi/hardware/hwsleep.c
index 77b3e9a8550b..415d342aeab5 100644
--- a/drivers/acpi/hardware/hwsleep.c
+++ b/drivers/acpi/hardware/hwsleep.c
@@ -43,27 +43,13 @@
43 */ 43 */
44 44
45#include <linux/module.h> 45#include <linux/module.h>
46
47#include <acpi/acpi.h> 46#include <acpi/acpi.h>
48 47
49#define _COMPONENT ACPI_HARDWARE 48#define _COMPONENT ACPI_HARDWARE
50 ACPI_MODULE_NAME ("hwsleep") 49 ACPI_MODULE_NAME ("hwsleep")
51 50
52 51
53#define METHOD_NAME__BFS "\\_BFS" 52/*******************************************************************************
54#define METHOD_NAME__GTS "\\_GTS"
55#define METHOD_NAME__PTS "\\_PTS"
56#define METHOD_NAME__SST "\\_SI._SST"
57#define METHOD_NAME__WAK "\\_WAK"
58
59#define ACPI_SST_INDICATOR_OFF 0
60#define ACPI_SST_WORKING 1
61#define ACPI_SST_WAKING 2
62#define ACPI_SST_SLEEPING 3
63#define ACPI_SST_SLEEP_CONTEXT 4
64
65
66/******************************************************************************
67 * 53 *
68 * FUNCTION: acpi_set_firmware_waking_vector 54 * FUNCTION: acpi_set_firmware_waking_vector
69 * 55 *
@@ -72,7 +58,7 @@
72 * 58 *
73 * RETURN: Status 59 * RETURN: Status
74 * 60 *
75 * DESCRIPTION: access function for d_firmware_waking_vector field in FACS 61 * DESCRIPTION: Access function for the firmware_waking_vector field in FACS
76 * 62 *
77 ******************************************************************************/ 63 ******************************************************************************/
78 64
@@ -99,19 +85,20 @@ acpi_set_firmware_waking_vector (
99} 85}
100 86
101 87
102/****************************************************************************** 88/*******************************************************************************
103 * 89 *
104 * FUNCTION: acpi_get_firmware_waking_vector 90 * FUNCTION: acpi_get_firmware_waking_vector
105 * 91 *
106 * PARAMETERS: *physical_address - Output buffer where contents of 92 * PARAMETERS: *physical_address - Where the contents of
107 * the firmware_waking_vector field of 93 * the firmware_waking_vector field of
108 * the FACS will be stored. 94 * the FACS will be returned.
109 * 95 *
110 * RETURN: Status 96 * RETURN: Status, vector
111 * 97 *
112 * DESCRIPTION: Access function for firmware_waking_vector field in FACS 98 * DESCRIPTION: Access function for the firmware_waking_vector field in FACS
113 * 99 *
114 ******************************************************************************/ 100 ******************************************************************************/
101
115#ifdef ACPI_FUTURE_USAGE 102#ifdef ACPI_FUTURE_USAGE
116acpi_status 103acpi_status
117acpi_get_firmware_waking_vector ( 104acpi_get_firmware_waking_vector (
@@ -141,7 +128,7 @@ acpi_get_firmware_waking_vector (
141#endif 128#endif
142 129
143 130
144/****************************************************************************** 131/*******************************************************************************
145 * 132 *
146 * FUNCTION: acpi_enter_sleep_state_prep 133 * FUNCTION: acpi_enter_sleep_state_prep
147 * 134 *
@@ -215,7 +202,7 @@ acpi_enter_sleep_state_prep (
215 break; 202 break;
216 203
217 default: 204 default:
218 arg.integer.value = ACPI_SST_INDICATOR_OFF; /* Default is indicator off */ 205 arg.integer.value = ACPI_SST_INDICATOR_OFF; /* Default is off */
219 break; 206 break;
220 } 207 }
221 208
@@ -223,14 +210,15 @@ acpi_enter_sleep_state_prep (
223 210
224 status = acpi_evaluate_object (NULL, METHOD_NAME__SST, &arg_list, NULL); 211 status = acpi_evaluate_object (NULL, METHOD_NAME__SST, &arg_list, NULL);
225 if (ACPI_FAILURE (status) && status != AE_NOT_FOUND) { 212 if (ACPI_FAILURE (status) && status != AE_NOT_FOUND) {
226 ACPI_REPORT_ERROR (("Method _SST failed, %s\n", acpi_format_exception (status))); 213 ACPI_REPORT_ERROR (("Method _SST failed, %s\n",
214 acpi_format_exception (status)));
227 } 215 }
228 216
229 return_ACPI_STATUS (AE_OK); 217 return_ACPI_STATUS (AE_OK);
230} 218}
231 219
232 220
233/****************************************************************************** 221/*******************************************************************************
234 * 222 *
235 * FUNCTION: acpi_enter_sleep_state 223 * FUNCTION: acpi_enter_sleep_state
236 * 224 *
@@ -299,15 +287,18 @@ acpi_enter_sleep_state (
299 287
300 /* Get current value of PM1A control */ 288 /* Get current value of PM1A control */
301 289
302 status = acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1_CONTROL, &PM1Acontrol); 290 status = acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK,
291 ACPI_REGISTER_PM1_CONTROL, &PM1Acontrol);
303 if (ACPI_FAILURE (status)) { 292 if (ACPI_FAILURE (status)) {
304 return_ACPI_STATUS (status); 293 return_ACPI_STATUS (status);
305 } 294 }
306 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "Entering sleep state [S%d]\n", sleep_state)); 295 ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
296 "Entering sleep state [S%d]\n", sleep_state));
307 297
308 /* Clear SLP_EN and SLP_TYP fields */ 298 /* Clear SLP_EN and SLP_TYP fields */
309 299
310 PM1Acontrol &= ~(sleep_type_reg_info->access_bit_mask | sleep_enable_reg_info->access_bit_mask); 300 PM1Acontrol &= ~(sleep_type_reg_info->access_bit_mask |
301 sleep_enable_reg_info->access_bit_mask);
311 PM1Bcontrol = PM1Acontrol; 302 PM1Bcontrol = PM1Acontrol;
312 303
313 /* Insert SLP_TYP bits */ 304 /* Insert SLP_TYP bits */
@@ -322,12 +313,14 @@ acpi_enter_sleep_state (
322 313
323 /* Write #1: fill in SLP_TYP data */ 314 /* Write #1: fill in SLP_TYP data */
324 315
325 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1A_CONTROL, PM1Acontrol); 316 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK,
317 ACPI_REGISTER_PM1A_CONTROL, PM1Acontrol);
326 if (ACPI_FAILURE (status)) { 318 if (ACPI_FAILURE (status)) {
327 return_ACPI_STATUS (status); 319 return_ACPI_STATUS (status);
328 } 320 }
329 321
330 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1B_CONTROL, PM1Bcontrol); 322 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK,
323 ACPI_REGISTER_PM1B_CONTROL, PM1Bcontrol);
331 if (ACPI_FAILURE (status)) { 324 if (ACPI_FAILURE (status)) {
332 return_ACPI_STATUS (status); 325 return_ACPI_STATUS (status);
333 } 326 }
@@ -341,22 +334,25 @@ acpi_enter_sleep_state (
341 334
342 ACPI_FLUSH_CPU_CACHE (); 335 ACPI_FLUSH_CPU_CACHE ();
343 336
344 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1A_CONTROL, PM1Acontrol); 337 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK,
338 ACPI_REGISTER_PM1A_CONTROL, PM1Acontrol);
345 if (ACPI_FAILURE (status)) { 339 if (ACPI_FAILURE (status)) {
346 return_ACPI_STATUS (status); 340 return_ACPI_STATUS (status);
347 } 341 }
348 342
349 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1B_CONTROL, PM1Bcontrol); 343 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK,
344 ACPI_REGISTER_PM1B_CONTROL, PM1Bcontrol);
350 if (ACPI_FAILURE (status)) { 345 if (ACPI_FAILURE (status)) {
351 return_ACPI_STATUS (status); 346 return_ACPI_STATUS (status);
352 } 347 }
353 348
354 if (sleep_state > ACPI_STATE_S3) { 349 if (sleep_state > ACPI_STATE_S3) {
355 /* 350 /*
356 * We wanted to sleep > S3, but it didn't happen (by virtue of the fact that 351 * We wanted to sleep > S3, but it didn't happen (by virtue of the
357 * we are still executing!) 352 * fact that we are still executing!)
358 * 353 *
359 * Wait ten seconds, then try again. This is to get S4/S5 to work on all machines. 354 * Wait ten seconds, then try again. This is to get S4/S5 to work on
355 * all machines.
360 * 356 *
361 * We wait so long to allow chipsets that poll this reg very slowly to 357 * We wait so long to allow chipsets that poll this reg very slowly to
362 * still read the right value. Ideally, this block would go 358 * still read the right value. Ideally, this block would go
@@ -364,7 +360,8 @@ acpi_enter_sleep_state (
364 */ 360 */
365 acpi_os_stall (10000000); 361 acpi_os_stall (10000000);
366 362
367 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1_CONTROL, 363 status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK,
364 ACPI_REGISTER_PM1_CONTROL,
368 sleep_enable_reg_info->access_bit_mask); 365 sleep_enable_reg_info->access_bit_mask);
369 if (ACPI_FAILURE (status)) { 366 if (ACPI_FAILURE (status)) {
370 return_ACPI_STATUS (status); 367 return_ACPI_STATUS (status);
@@ -374,7 +371,8 @@ acpi_enter_sleep_state (
374 /* Wait until we enter sleep state */ 371 /* Wait until we enter sleep state */
375 372
376 do { 373 do {
377 status = acpi_get_register (ACPI_BITREG_WAKE_STATUS, &in_value, ACPI_MTX_DO_NOT_LOCK); 374 status = acpi_get_register (ACPI_BITREG_WAKE_STATUS, &in_value,
375 ACPI_MTX_DO_NOT_LOCK);
378 if (ACPI_FAILURE (status)) { 376 if (ACPI_FAILURE (status)) {
379 return_ACPI_STATUS (status); 377 return_ACPI_STATUS (status);
380 } 378 }
@@ -388,7 +386,7 @@ acpi_enter_sleep_state (
388EXPORT_SYMBOL(acpi_enter_sleep_state); 386EXPORT_SYMBOL(acpi_enter_sleep_state);
389 387
390 388
391/****************************************************************************** 389/*******************************************************************************
392 * 390 *
393 * FUNCTION: acpi_enter_sleep_state_s4bios 391 * FUNCTION: acpi_enter_sleep_state_s4bios
394 * 392 *
@@ -439,11 +437,13 @@ acpi_enter_sleep_state_s4bios (
439 437
440 ACPI_FLUSH_CPU_CACHE (); 438 ACPI_FLUSH_CPU_CACHE ();
441 439
442 status = acpi_os_write_port (acpi_gbl_FADT->smi_cmd, (u32) acpi_gbl_FADT->S4bios_req, 8); 440 status = acpi_os_write_port (acpi_gbl_FADT->smi_cmd,
441 (u32) acpi_gbl_FADT->S4bios_req, 8);
443 442
444 do { 443 do {
445 acpi_os_stall(1000); 444 acpi_os_stall(1000);
446 status = acpi_get_register (ACPI_BITREG_WAKE_STATUS, &in_value, ACPI_MTX_DO_NOT_LOCK); 445 status = acpi_get_register (ACPI_BITREG_WAKE_STATUS, &in_value,
446 ACPI_MTX_DO_NOT_LOCK);
447 if (ACPI_FAILURE (status)) { 447 if (ACPI_FAILURE (status)) {
448 return_ACPI_STATUS (status); 448 return_ACPI_STATUS (status);
449 } 449 }
@@ -454,7 +454,7 @@ acpi_enter_sleep_state_s4bios (
454EXPORT_SYMBOL(acpi_enter_sleep_state_s4bios); 454EXPORT_SYMBOL(acpi_enter_sleep_state_s4bios);
455 455
456 456
457/****************************************************************************** 457/*******************************************************************************
458 * 458 *
459 * FUNCTION: acpi_leave_sleep_state 459 * FUNCTION: acpi_leave_sleep_state
460 * 460 *
@@ -534,18 +534,21 @@ acpi_leave_sleep_state (
534 arg.integer.value = ACPI_SST_WAKING; 534 arg.integer.value = ACPI_SST_WAKING;
535 status = acpi_evaluate_object (NULL, METHOD_NAME__SST, &arg_list, NULL); 535 status = acpi_evaluate_object (NULL, METHOD_NAME__SST, &arg_list, NULL);
536 if (ACPI_FAILURE (status) && status != AE_NOT_FOUND) { 536 if (ACPI_FAILURE (status) && status != AE_NOT_FOUND) {
537 ACPI_REPORT_ERROR (("Method _SST failed, %s\n", acpi_format_exception (status))); 537 ACPI_REPORT_ERROR (("Method _SST failed, %s\n",
538 acpi_format_exception (status)));
538 } 539 }
539 540
540 arg.integer.value = sleep_state; 541 arg.integer.value = sleep_state;
541 status = acpi_evaluate_object (NULL, METHOD_NAME__BFS, &arg_list, NULL); 542 status = acpi_evaluate_object (NULL, METHOD_NAME__BFS, &arg_list, NULL);
542 if (ACPI_FAILURE (status) && status != AE_NOT_FOUND) { 543 if (ACPI_FAILURE (status) && status != AE_NOT_FOUND) {
543 ACPI_REPORT_ERROR (("Method _BFS failed, %s\n", acpi_format_exception (status))); 544 ACPI_REPORT_ERROR (("Method _BFS failed, %s\n",
545 acpi_format_exception (status)));
544 } 546 }
545 547
546 status = acpi_evaluate_object (NULL, METHOD_NAME__WAK, &arg_list, NULL); 548 status = acpi_evaluate_object (NULL, METHOD_NAME__WAK, &arg_list, NULL);
547 if (ACPI_FAILURE (status) && status != AE_NOT_FOUND) { 549 if (ACPI_FAILURE (status) && status != AE_NOT_FOUND) {
548 ACPI_REPORT_ERROR (("Method _WAK failed, %s\n", acpi_format_exception (status))); 550 ACPI_REPORT_ERROR (("Method _WAK failed, %s\n",
551 acpi_format_exception (status)));
549 } 552 }
550 /* TBD: _WAK "sometimes" returns stuff - do we want to look at it? */ 553 /* TBD: _WAK "sometimes" returns stuff - do we want to look at it? */
551 554
@@ -567,15 +570,19 @@ acpi_leave_sleep_state (
567 570
568 /* Enable power button */ 571 /* Enable power button */
569 572
570 (void) acpi_set_register(acpi_gbl_fixed_event_info[ACPI_EVENT_POWER_BUTTON].enable_register_id, 573 (void) acpi_set_register(
574 acpi_gbl_fixed_event_info[ACPI_EVENT_POWER_BUTTON].enable_register_id,
571 1, ACPI_MTX_DO_NOT_LOCK); 575 1, ACPI_MTX_DO_NOT_LOCK);
572 (void) acpi_set_register(acpi_gbl_fixed_event_info[ACPI_EVENT_POWER_BUTTON].status_register_id, 576
577 (void) acpi_set_register(
578 acpi_gbl_fixed_event_info[ACPI_EVENT_POWER_BUTTON].status_register_id,
573 1, ACPI_MTX_DO_NOT_LOCK); 579 1, ACPI_MTX_DO_NOT_LOCK);
574 580
575 arg.integer.value = ACPI_SST_WORKING; 581 arg.integer.value = ACPI_SST_WORKING;
576 status = acpi_evaluate_object (NULL, METHOD_NAME__SST, &arg_list, NULL); 582 status = acpi_evaluate_object (NULL, METHOD_NAME__SST, &arg_list, NULL);
577 if (ACPI_FAILURE (status) && status != AE_NOT_FOUND) { 583 if (ACPI_FAILURE (status) && status != AE_NOT_FOUND) {
578 ACPI_REPORT_ERROR (("Method _SST failed, %s\n", acpi_format_exception (status))); 584 ACPI_REPORT_ERROR (("Method _SST failed, %s\n",
585 acpi_format_exception (status)));
579 } 586 }
580 587
581 return_ACPI_STATUS (status); 588 return_ACPI_STATUS (status);
diff --git a/drivers/acpi/hardware/hwtimer.c b/drivers/acpi/hardware/hwtimer.c
index 1906167d7294..49d7b395322e 100644
--- a/drivers/acpi/hardware/hwtimer.c
+++ b/drivers/acpi/hardware/hwtimer.c
@@ -43,7 +43,6 @@
43 */ 43 */
44 44
45#include <linux/module.h> 45#include <linux/module.h>
46
47#include <acpi/acpi.h> 46#include <acpi/acpi.h>
48 47
49#define _COMPONENT ACPI_HARDWARE 48#define _COMPONENT ACPI_HARDWARE
@@ -90,7 +89,7 @@ acpi_get_timer_resolution (
90 * 89 *
91 * PARAMETERS: Ticks - Where the timer value is returned 90 * PARAMETERS: Ticks - Where the timer value is returned
92 * 91 *
93 * RETURN: Status and current ticks 92 * RETURN: Status and current timer value (ticks)
94 * 93 *
95 * DESCRIPTION: Obtains current value of ACPI PM Timer (in ticks). 94 * DESCRIPTION: Obtains current value of ACPI PM Timer (in ticks).
96 * 95 *
@@ -199,5 +198,6 @@ acpi_get_timer_duration (
199 *time_elapsed = (u32) quotient; 198 *time_elapsed = (u32) quotient;
200 return_ACPI_STATUS (status); 199 return_ACPI_STATUS (status);
201} 200}
201
202EXPORT_SYMBOL(acpi_get_timer_duration); 202EXPORT_SYMBOL(acpi_get_timer_duration);
203 203
diff --git a/drivers/acpi/hotkey.c b/drivers/acpi/hotkey.c
new file mode 100644
index 000000000000..babdf762eadb
--- /dev/null
+++ b/drivers/acpi/hotkey.c
@@ -0,0 +1,1019 @@
1/*
2 * hotkey.c - ACPI Hotkey Driver ($Revision:$)
3 *
4 * Copyright (C) 2004 Luming Yu <luming.yu@intel.com>
5 *
6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or (at
11 * your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 *
22 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 */
24#include <linux/kernel.h>
25#include <linux/module.h>
26#include <linux/init.h>
27#include <linux/types.h>
28#include <linux/proc_fs.h>
29#include <linux/sched.h>
30#include <linux/kmod.h>
31#include <linux/seq_file.h>
32#include <acpi/acpi_drivers.h>
33#include <acpi/acpi_bus.h>
34#include <asm/uaccess.h>
35
36#define HOTKEY_ACPI_VERSION "0.1"
37
38#define HOTKEY_PROC "hotkey"
39#define HOTKEY_EV_CONFIG "event_config"
40#define HOTKEY_PL_CONFIG "poll_config"
41#define HOTKEY_ACTION "action"
42#define HOTKEY_INFO "info"
43
44#define ACPI_HOTK_NAME "Generic Hotkey Driver"
45#define ACPI_HOTK_CLASS "Hotkey"
46#define ACPI_HOTK_DEVICE_NAME "Hotkey"
47#define ACPI_HOTK_HID "Unknown?"
48#define ACPI_HOTKEY_COMPONENT 0x20000000
49
50#define ACPI_HOTKEY_EVENT 0x1
51#define ACPI_HOTKEY_POLLING 0x2
52#define ACPI_UNDEFINED_EVENT 0xf
53
54#define MAX_CONFIG_RECORD_LEN 80
55#define MAX_NAME_PATH_LEN 80
56#define MAX_CALL_PARM 80
57
58#define IS_EVENT(e) 0xff /* ((e) & 0x40000000) */
59#define IS_POLL(e) 0xff /* (~((e) & 0x40000000)) */
60
61#define _COMPONENT ACPI_HOTKEY_COMPONENT
62ACPI_MODULE_NAME("acpi_hotkey")
63
64 MODULE_AUTHOR("luming.yu@intel.com");
65MODULE_DESCRIPTION(ACPI_HOTK_NAME);
66MODULE_LICENSE("GPL");
67
68/* standardized internal hotkey number/event */
69enum {
70 /* Video Extension event */
71 HK_EVENT_CYCLE_OUTPUT_DEVICE = 0x80,
72 HK_EVENT_OUTPUT_DEVICE_STATUS_CHANGE,
73 HK_EVENT_CYCLE_DISPLAY_OUTPUT,
74 HK_EVENT_NEXT_DISPLAY_OUTPUT,
75 HK_EVENT_PREVIOUS_DISPLAY_OUTPUT,
76 HK_EVENT_CYCLE_BRIGHTNESS,
77 HK_EVENT_INCREASE_BRIGHTNESS,
78 HK_EVENT_DECREASE_BRIGHTNESS,
79 HK_EVENT_ZERO_BRIGHTNESS,
80 HK_EVENT_DISPLAY_DEVICE_OFF,
81
82 /* Snd Card event */
83 HK_EVENT_VOLUME_MUTE,
84 HK_EVENT_VOLUME_INCLREASE,
85 HK_EVENT_VOLUME_DECREASE,
86
87 /* running state control */
88 HK_EVENT_ENTERRING_S3,
89 HK_EVENT_ENTERRING_S4,
90 HK_EVENT_ENTERRING_S5,
91};
92
93/* procdir we use */
94static struct proc_dir_entry *hotkey_proc_dir;
95static struct proc_dir_entry *hotkey_config;
96static struct proc_dir_entry *hotkey_poll_config;
97static struct proc_dir_entry *hotkey_action;
98static struct proc_dir_entry *hotkey_info;
99
100/* linkage for all type of hotkey */
101struct acpi_hotkey_link {
102 struct list_head entries;
103 int hotkey_type; /* event or polling based hotkey */
104 int hotkey_standard_num; /* standardized hotkey(event) number */
105};
106
107/* event based hotkey */
108struct acpi_event_hotkey {
109 struct acpi_hotkey_link hotkey_link;
110 int flag;
111 acpi_handle bus_handle; /* bus to install notify handler */
112 int external_hotkey_num; /* external hotkey/event number */
113 acpi_handle action_handle; /* acpi handle attached aml action method */
114 char *action_method; /* action method */
115};
116
117/*
118 * There are two ways to poll status
119 * 1. directy call read_xxx method, without any arguments passed in
120 * 2. call write_xxx method, with arguments passed in, you need
121 * the result is saved in acpi_polling_hotkey.poll_result.
122 * anthoer read command through polling interface.
123 *
124 */
125
126/* polling based hotkey */
127struct acpi_polling_hotkey {
128 struct acpi_hotkey_link hotkey_link;
129 int flag;
130 acpi_handle poll_handle; /* acpi handle attached polling method */
131 char *poll_method; /* poll method */
132 acpi_handle action_handle; /* acpi handle attached action method */
133 char *action_method; /* action method */
134 void *poll_result; /* polling_result */
135 struct proc_dir_entry *proc;
136};
137
138/* hotkey object union */
139union acpi_hotkey {
140 struct list_head entries;
141 struct acpi_hotkey_link link;
142 struct acpi_event_hotkey event_hotkey;
143 struct acpi_polling_hotkey poll_hotkey;
144};
145
146/* hotkey object list */
147struct acpi_hotkey_list {
148 struct list_head *entries;
149 int count;
150};
151
152static int auto_hotkey_add(struct acpi_device *device);
153static int auto_hotkey_remove(struct acpi_device *device, int type);
154
155static struct acpi_driver hotkey_driver = {
156 .name = ACPI_HOTK_NAME,
157 .class = ACPI_HOTK_CLASS,
158 .ids = ACPI_HOTK_HID,
159 .ops = {
160 .add = auto_hotkey_add,
161 .remove = auto_hotkey_remove,
162 },
163};
164
165static int hotkey_open_config(struct inode *inode, struct file *file);
166static ssize_t hotkey_write_config(struct file *file,
167 const char __user * buffer,
168 size_t count, loff_t * data);
169static ssize_t hotkey_write_poll_config(struct file *file,
170 const char __user * buffer,
171 size_t count, loff_t * data);
172static int hotkey_info_open_fs(struct inode *inode, struct file *file);
173static int hotkey_action_open_fs(struct inode *inode, struct file *file);
174static ssize_t hotkey_execute_aml_method(struct file *file,
175 const char __user * buffer,
176 size_t count, loff_t * data);
177static int hotkey_config_seq_show(struct seq_file *seq, void *offset);
178static int hotkey_polling_open_fs(struct inode *inode, struct file *file);
179
180/* event based config */
181static struct file_operations hotkey_config_fops = {
182 .open = hotkey_open_config,
183 .read = seq_read,
184 .write = hotkey_write_config,
185 .llseek = seq_lseek,
186 .release = single_release,
187};
188
189/* polling based config */
190static struct file_operations hotkey_poll_config_fops = {
191 .open = hotkey_open_config,
192 .read = seq_read,
193 .write = hotkey_write_poll_config,
194 .llseek = seq_lseek,
195 .release = single_release,
196};
197
198/* hotkey driver info */
199static struct file_operations hotkey_info_fops = {
200 .open = hotkey_info_open_fs,
201 .read = seq_read,
202 .llseek = seq_lseek,
203 .release = single_release,
204};
205
206/* action */
207static struct file_operations hotkey_action_fops = {
208 .open = hotkey_action_open_fs,
209 .read = seq_read,
210 .write = hotkey_execute_aml_method,
211 .llseek = seq_lseek,
212 .release = single_release,
213};
214
215/* polling results */
216static struct file_operations hotkey_polling_fops = {
217 .open = hotkey_polling_open_fs,
218 .read = seq_read,
219 .llseek = seq_lseek,
220 .release = single_release,
221};
222
223struct acpi_hotkey_list global_hotkey_list; /* link all ev or pl hotkey */
224struct list_head hotkey_entries; /* head of the list of hotkey_list */
225
226static int hotkey_info_seq_show(struct seq_file *seq, void *offset)
227{
228 ACPI_FUNCTION_TRACE("hotkey_info_seq_show");
229
230 seq_printf(seq, "Hotkey generic driver ver: %s", HOTKEY_ACPI_VERSION);
231
232 return_VALUE(0);
233}
234
235static int hotkey_info_open_fs(struct inode *inode, struct file *file)
236{
237 return single_open(file, hotkey_info_seq_show, PDE(inode)->data);
238}
239
240static char *format_result(union acpi_object *object)
241{
242 char *buf = (char *)kmalloc(sizeof(union acpi_object), GFP_KERNEL);
243
244 memset(buf, 0, sizeof(union acpi_object));
245
246 /* Now, just support integer type */
247 if (object->type == ACPI_TYPE_INTEGER)
248 sprintf(buf, "%d", (u32) object->integer.value);
249
250 return buf;
251}
252
253static int hotkey_polling_seq_show(struct seq_file *seq, void *offset)
254{
255 struct acpi_polling_hotkey *poll_hotkey =
256 (struct acpi_polling_hotkey *)seq->private;
257
258 ACPI_FUNCTION_TRACE("hotkey_polling_seq_show");
259
260 if (poll_hotkey->poll_result)
261 seq_printf(seq, "%s", format_result(poll_hotkey->poll_result));
262
263 return_VALUE(0);
264}
265
266static int hotkey_polling_open_fs(struct inode *inode, struct file *file)
267{
268 return single_open(file, hotkey_polling_seq_show, PDE(inode)->data);
269}
270
271static int hotkey_action_open_fs(struct inode *inode, struct file *file)
272{
273 return single_open(file, hotkey_info_seq_show, PDE(inode)->data);
274}
275
276/* Mapping external hotkey number to standardized hotkey event num */
277static int hotkey_get_internal_event(int event, struct acpi_hotkey_list *list)
278{
279 struct list_head *entries, *next;
280 int val = 0;
281
282 ACPI_FUNCTION_TRACE("hotkey_get_internal_event");
283
284 list_for_each_safe(entries, next, list->entries) {
285 union acpi_hotkey *key =
286 container_of(entries, union acpi_hotkey, entries);
287 if (key->link.hotkey_type == ACPI_HOTKEY_EVENT
288 && key->event_hotkey.external_hotkey_num == event)
289 val = key->link.hotkey_standard_num;
290 else
291 val = -1;
292 }
293
294 return_VALUE(val);
295}
296
297static void
298acpi_hotkey_notify_handler(acpi_handle handle, u32 event, void *data)
299{
300 struct acpi_device *device = NULL;
301 u32 internal_event;
302
303 ACPI_FUNCTION_TRACE("acpi_hotkey_notify_handler");
304
305 if (acpi_bus_get_device(handle, &device))
306 return_VOID;
307
308 internal_event = hotkey_get_internal_event(event, &global_hotkey_list);
309 acpi_bus_generate_event(device, event, 0);
310
311 return_VOID;
312}
313
314/* Need to invent automatically hotkey add method */
315static int auto_hotkey_add(struct acpi_device *device)
316{
317 /* Implement me */
318 return 0;
319}
320
321/* Need to invent automatically hotkey remove method */
322static int auto_hotkey_remove(struct acpi_device *device, int type)
323{
324 /* Implement me */
325 return 0;
326}
327
328/* Create a proc file for each polling method */
329static int create_polling_proc(union acpi_hotkey *device)
330{
331 struct proc_dir_entry *proc;
332 mode_t mode;
333
334 ACPI_FUNCTION_TRACE("create_polling_proc");
335 mode = S_IFREG | S_IRUGO | S_IWUGO;
336
337 proc = create_proc_entry(device->poll_hotkey.action_method,
338 mode, hotkey_proc_dir);
339
340 if (!proc) {
341 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
342 "Hotkey: Unable to create %s entry\n",
343 device->poll_hotkey.poll_method));
344 return_VALUE(-ENODEV);
345 } else {
346 proc->proc_fops = &hotkey_polling_fops;
347 proc->owner = THIS_MODULE;
348 proc->data = device;
349 proc->uid = 0;
350 proc->gid = 0;
351 device->poll_hotkey.proc = proc;
352 }
353 return_VALUE(0);
354}
355
356static int is_valid_acpi_path(const char *pathname)
357{
358 acpi_handle handle;
359 acpi_status status;
360 ACPI_FUNCTION_TRACE("is_valid_acpi_path");
361
362 status = acpi_get_handle(NULL, (char *)pathname, &handle);
363 return_VALUE(!ACPI_FAILURE(status));
364}
365
366static int is_valid_hotkey(union acpi_hotkey *device)
367{
368 ACPI_FUNCTION_TRACE("is_valid_hotkey");
369 /* Implement valid check */
370 return_VALUE(1);
371}
372
373static int hotkey_add(union acpi_hotkey *device)
374{
375 int status = 0;
376 struct acpi_device *dev = NULL;
377
378 ACPI_FUNCTION_TRACE("hotkey_add");
379
380 if (device->link.hotkey_type == ACPI_HOTKEY_EVENT) {
381 status =
382 acpi_bus_get_device(device->event_hotkey.bus_handle, &dev);
383 if (status)
384 return_VALUE(status);
385
386 status = acpi_install_notify_handler(dev->handle,
387 ACPI_SYSTEM_NOTIFY,
388 acpi_hotkey_notify_handler,
389 device);
390 } else /* Add polling hotkey */
391 create_polling_proc(device);
392
393 global_hotkey_list.count++;
394
395 list_add_tail(&device->link.entries, global_hotkey_list.entries);
396
397 return_VALUE(status);
398}
399
400static int hotkey_remove(union acpi_hotkey *device)
401{
402 struct list_head *entries, *next;
403
404 ACPI_FUNCTION_TRACE("hotkey_remove");
405
406 list_for_each_safe(entries, next, global_hotkey_list.entries) {
407 union acpi_hotkey *key =
408 container_of(entries, union acpi_hotkey, entries);
409 if (key->link.hotkey_standard_num ==
410 device->link.hotkey_standard_num) {
411 list_del(&key->link.entries);
412 remove_proc_entry(key->poll_hotkey.action_method,
413 hotkey_proc_dir);
414 global_hotkey_list.count--;
415 break;
416 }
417 }
418 return_VALUE(0);
419}
420
421static void hotkey_update(union acpi_hotkey *key)
422{
423 struct list_head *entries, *next;
424
425 ACPI_FUNCTION_TRACE("hotkey_update");
426
427 list_for_each_safe(entries, next, global_hotkey_list.entries) {
428 union acpi_hotkey *key =
429 container_of(entries, union acpi_hotkey, entries);
430 if (key->link.hotkey_standard_num ==
431 key->link.hotkey_standard_num) {
432 key->event_hotkey.bus_handle =
433 key->event_hotkey.bus_handle;
434 key->event_hotkey.external_hotkey_num =
435 key->event_hotkey.external_hotkey_num;
436 key->event_hotkey.action_handle =
437 key->event_hotkey.action_handle;
438 key->event_hotkey.action_method =
439 key->event_hotkey.action_method;
440 break;
441 }
442 }
443
444 return_VOID;
445}
446
447static void free_hotkey_device(union acpi_hotkey *key)
448{
449 struct acpi_device *dev;
450 int status;
451
452 ACPI_FUNCTION_TRACE("free_hotkey_device");
453
454 if (key->link.hotkey_type == ACPI_HOTKEY_EVENT) {
455 status =
456 acpi_bus_get_device(key->event_hotkey.bus_handle, &dev);
457 if (dev->handle)
458 acpi_remove_notify_handler(dev->handle,
459 ACPI_SYSTEM_NOTIFY,
460 acpi_hotkey_notify_handler);
461 } else
462 remove_proc_entry(key->poll_hotkey.action_method,
463 hotkey_proc_dir);
464 kfree(key);
465 return_VOID;
466}
467
468static int
469init_hotkey_device(union acpi_hotkey *key, char *bus_str, char *action_str,
470 char *method, int std_num, int external_num)
471{
472 ACPI_FUNCTION_TRACE("init_hotkey_device");
473
474 key->link.hotkey_type = ACPI_HOTKEY_EVENT;
475 key->link.hotkey_standard_num = std_num;
476 key->event_hotkey.flag = 0;
477 if (is_valid_acpi_path(bus_str))
478 acpi_get_handle((acpi_handle) 0,
479 bus_str, &(key->event_hotkey.bus_handle));
480 else
481 return_VALUE(-ENODEV);
482 key->event_hotkey.external_hotkey_num = external_num;
483 if (is_valid_acpi_path(action_str))
484 acpi_get_handle((acpi_handle) 0,
485 action_str, &(key->event_hotkey.action_handle));
486 key->event_hotkey.action_method = kmalloc(sizeof(method), GFP_KERNEL);
487 strcpy(key->event_hotkey.action_method, method);
488
489 return_VALUE(!is_valid_hotkey(key));
490}
491
492static int
493init_poll_hotkey_device(union acpi_hotkey *key,
494 char *poll_str,
495 char *poll_method,
496 char *action_str, char *action_method, int std_num)
497{
498 ACPI_FUNCTION_TRACE("init_poll_hotkey_device");
499
500 key->link.hotkey_type = ACPI_HOTKEY_POLLING;
501 key->link.hotkey_standard_num = std_num;
502 key->poll_hotkey.flag = 0;
503 if (is_valid_acpi_path(poll_str))
504 acpi_get_handle((acpi_handle) 0,
505 poll_str, &(key->poll_hotkey.poll_handle));
506 else
507 return_VALUE(-ENODEV);
508 key->poll_hotkey.poll_method = poll_method;
509 if (is_valid_acpi_path(action_str))
510 acpi_get_handle((acpi_handle) 0,
511 action_str, &(key->poll_hotkey.action_handle));
512 key->poll_hotkey.action_method =
513 kmalloc(sizeof(action_method), GFP_KERNEL);
514 strcpy(key->poll_hotkey.action_method, action_method);
515 key->poll_hotkey.poll_result =
516 (union acpi_object *)kmalloc(sizeof(union acpi_object), GFP_KERNEL);
517 return_VALUE(is_valid_hotkey(key));
518}
519
520static int check_hotkey_valid(union acpi_hotkey *key,
521 struct acpi_hotkey_list *list)
522{
523 ACPI_FUNCTION_TRACE("check_hotkey_valid");
524 return_VALUE(0);
525}
526
527static int hotkey_open_config(struct inode *inode, struct file *file)
528{
529 ACPI_FUNCTION_TRACE("hotkey_open_config");
530 return_VALUE(single_open
531 (file, hotkey_config_seq_show, PDE(inode)->data));
532}
533
534static int hotkey_config_seq_show(struct seq_file *seq, void *offset)
535{
536 struct acpi_hotkey_list *hotkey_list = &global_hotkey_list;
537 struct list_head *entries, *next;
538 char bus_name[ACPI_PATHNAME_MAX] = { 0 };
539 char action_name[ACPI_PATHNAME_MAX] = { 0 };
540 struct acpi_buffer bus = { ACPI_PATHNAME_MAX, bus_name };
541 struct acpi_buffer act = { ACPI_PATHNAME_MAX, action_name };
542
543 ACPI_FUNCTION_TRACE(("hotkey_config_seq_show"));
544
545 if (!hotkey_list)
546 goto end;
547
548 list_for_each_safe(entries, next, hotkey_list->entries) {
549 union acpi_hotkey *key =
550 container_of(entries, union acpi_hotkey, entries);
551 if (key->link.hotkey_type == ACPI_HOTKEY_EVENT) {
552 acpi_get_name(key->event_hotkey.bus_handle,
553 ACPI_NAME_TYPE_MAX, &bus);
554 acpi_get_name(key->event_hotkey.action_handle,
555 ACPI_NAME_TYPE_MAX, &act);
556 seq_printf(seq, "%s:%s:%s:%d:%d", bus_name,
557 action_name,
558 key->event_hotkey.action_method,
559 key->link.hotkey_standard_num,
560 key->event_hotkey.external_hotkey_num);
561 } /* ACPI_HOTKEY_POLLING */
562 else {
563 acpi_get_name(key->poll_hotkey.poll_handle,
564 ACPI_NAME_TYPE_MAX, &bus);
565 acpi_get_name(key->poll_hotkey.action_handle,
566 ACPI_NAME_TYPE_MAX, &act);
567 seq_printf(seq, "%s:%s:%s:%s:%d", bus_name,
568 key->poll_hotkey.poll_method,
569 action_name,
570 key->poll_hotkey.action_method,
571 key->link.hotkey_standard_num);
572 }
573 }
574 seq_puts(seq, "\n");
575 end:
576 return_VALUE(0);
577}
578
579static int
580get_parms(char *config_record,
581 int *cmd,
582 char *bus_handle,
583 char *bus_method,
584 char *action_handle,
585 char *method, int *internal_event_num, int *external_event_num)
586{
587 char *tmp, *tmp1;
588 ACPI_FUNCTION_TRACE(("get_parms"));
589
590 sscanf(config_record, "%d", cmd);
591
592 tmp = strchr(config_record, ':');
593 tmp++;
594 tmp1 = strchr(tmp, ':');
595 strncpy(bus_handle, tmp, tmp1 - tmp);
596 bus_handle[tmp1 - tmp] = 0;
597
598 tmp = tmp1;
599 tmp++;
600 tmp1 = strchr(tmp, ':');
601 strncpy(bus_method, tmp, tmp1 - tmp);
602 bus_method[tmp1 - tmp] = 0;
603
604 tmp = tmp1;
605 tmp++;
606 tmp1 = strchr(tmp, ':');
607 strncpy(action_handle, tmp, tmp1 - tmp);
608 action_handle[tmp1 - tmp] = 0;
609
610 tmp = tmp1;
611 tmp++;
612 tmp1 = strchr(tmp, ':');
613 strncpy(method, tmp, tmp1 - tmp);
614 method[tmp1 - tmp] = 0;
615
616 sscanf(tmp1 + 1, "%d:%d", internal_event_num, external_event_num);
617 return_VALUE(6);
618}
619
620/* count is length for one input record */
621static ssize_t hotkey_write_config(struct file *file,
622 const char __user * buffer,
623 size_t count, loff_t * data)
624{
625 struct acpi_hotkey_list *hotkey_list = &global_hotkey_list;
626 char config_record[MAX_CONFIG_RECORD_LEN];
627 char bus_handle[MAX_NAME_PATH_LEN];
628 char bus_method[MAX_NAME_PATH_LEN];
629 char action_handle[MAX_NAME_PATH_LEN];
630 char method[20];
631 int cmd, internal_event_num, external_event_num;
632 int ret = 0;
633 union acpi_hotkey *key = NULL;
634
635 ACPI_FUNCTION_TRACE(("hotkey_write_config"));
636
637 if (!hotkey_list || count > MAX_CONFIG_RECORD_LEN) {
638 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid arguments\n"));
639 return_VALUE(-EINVAL);
640 }
641
642 if (copy_from_user(config_record, buffer, count)) {
643 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid data \n"));
644 return_VALUE(-EINVAL);
645 }
646 config_record[count] = '\0';
647
648 ret = get_parms(config_record,
649 &cmd,
650 bus_handle,
651 bus_method,
652 action_handle,
653 method, &internal_event_num, &external_event_num);
654 if (ret != 6) {
655 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
656 "Invalid data format ret=%d\n", ret));
657 return_VALUE(-EINVAL);
658 }
659
660 key = kmalloc(sizeof(union acpi_hotkey), GFP_KERNEL);
661 ret = init_hotkey_device(key, bus_handle, action_handle, method,
662 internal_event_num, external_event_num);
663
664 if (ret || check_hotkey_valid(key, hotkey_list)) {
665 kfree(key);
666 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid hotkey \n"));
667 return_VALUE(-EINVAL);
668 }
669 switch (cmd) {
670 case 0:
671 hotkey_add(key);
672 break;
673 case 1:
674 hotkey_remove(key);
675 free_hotkey_device(key);
676 break;
677 case 2:
678 hotkey_update(key);
679 break;
680 default:
681 break;
682 }
683 return_VALUE(count);
684}
685
686/* count is length for one input record */
687static ssize_t hotkey_write_poll_config(struct file *file,
688 const char __user * buffer,
689 size_t count, loff_t * data)
690{
691 struct seq_file *m = (struct seq_file *)file->private_data;
692 struct acpi_hotkey_list *hotkey_list =
693 (struct acpi_hotkey_list *)m->private;
694
695 char config_record[MAX_CONFIG_RECORD_LEN];
696 char polling_handle[MAX_NAME_PATH_LEN];
697 char action_handle[MAX_NAME_PATH_LEN];
698 char poll_method[20], action_method[20];
699 int ret, internal_event_num, cmd, external_event_num;
700 union acpi_hotkey *key = NULL;
701
702 ACPI_FUNCTION_TRACE("hotkey_write_poll_config");
703
704 if (!hotkey_list || count > MAX_CONFIG_RECORD_LEN) {
705 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid arguments\n"));
706 return_VALUE(-EINVAL);
707 }
708
709 if (copy_from_user(config_record, buffer, count)) {
710 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid data \n"));
711 return_VALUE(-EINVAL);
712 }
713 config_record[count] = '\0';
714
715 ret = get_parms(config_record,
716 &cmd,
717 polling_handle,
718 poll_method,
719 action_handle,
720 action_method,
721 &internal_event_num, &external_event_num);
722
723 if (ret != 6) {
724 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid data format\n"));
725 return_VALUE(-EINVAL);
726 }
727
728 key = kmalloc(sizeof(union acpi_hotkey), GFP_KERNEL);
729 ret = init_poll_hotkey_device(key, polling_handle, poll_method,
730 action_handle, action_method,
731 internal_event_num);
732 if (ret || check_hotkey_valid(key, hotkey_list)) {
733 kfree(key);
734 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid hotkey \n"));
735 return_VALUE(-EINVAL);
736 }
737 switch (cmd) {
738 case 0:
739 hotkey_add(key);
740 break;
741 case 1:
742 hotkey_remove(key);
743 break;
744 case 2:
745 hotkey_update(key);
746 break;
747 default:
748 break;
749 }
750 return_VALUE(count);
751}
752
753/*
754 * This function evaluates an ACPI method, given an int as parameter, the
755 * method is searched within the scope of the handle, can be NULL. The output
756 * of the method is written is output, which can also be NULL
757 *
758 * returns 1 if write is successful, 0 else.
759 */
760static int write_acpi_int(acpi_handle handle, const char *method, int val,
761 struct acpi_buffer *output)
762{
763 struct acpi_object_list params; /* list of input parameters (an int here) */
764 union acpi_object in_obj; /* the only param we use */
765 acpi_status status;
766
767 ACPI_FUNCTION_TRACE("write_acpi_int");
768 params.count = 1;
769 params.pointer = &in_obj;
770 in_obj.type = ACPI_TYPE_INTEGER;
771 in_obj.integer.value = val;
772
773 status = acpi_evaluate_object(handle, (char *)method, &params, output);
774
775 return_VALUE(status == AE_OK);
776}
777
778static int read_acpi_int(acpi_handle handle, const char *method, int *val)
779{
780 struct acpi_buffer output;
781 union acpi_object out_obj;
782 acpi_status status;
783
784 ACPI_FUNCTION_TRACE("read_acpi_int");
785 output.length = sizeof(out_obj);
786 output.pointer = &out_obj;
787
788 status = acpi_evaluate_object(handle, (char *)method, NULL, &output);
789 *val = out_obj.integer.value;
790 return_VALUE((status == AE_OK)
791 && (out_obj.type == ACPI_TYPE_INTEGER));
792}
793
794static acpi_handle
795get_handle_from_hotkeylist(struct acpi_hotkey_list *hotkey_list, int event_num)
796{
797 struct list_head *entries, *next;
798
799 list_for_each_safe(entries, next, hotkey_list->entries) {
800 union acpi_hotkey *key =
801 container_of(entries, union acpi_hotkey, entries);
802 if (key->link.hotkey_type == ACPI_HOTKEY_EVENT
803 && key->link.hotkey_standard_num == event_num) {
804 return (key->event_hotkey.action_handle);
805 }
806 }
807 return (NULL);
808}
809
810static
811char *get_method_from_hotkeylist(struct acpi_hotkey_list *hotkey_list,
812 int event_num)
813{
814 struct list_head *entries, *next;
815
816 list_for_each_safe(entries, next, hotkey_list->entries) {
817 union acpi_hotkey *key =
818 container_of(entries, union acpi_hotkey, entries);
819
820 if (key->link.hotkey_type == ACPI_HOTKEY_EVENT &&
821 key->link.hotkey_standard_num == event_num)
822 return (key->event_hotkey.action_method);
823 }
824 return (NULL);
825}
826
827static struct acpi_polling_hotkey *get_hotkey_by_event(struct
828 acpi_hotkey_list
829 *hotkey_list, int event)
830{
831 struct list_head *entries, *next;
832
833 list_for_each_safe(entries, next, hotkey_list->entries) {
834 union acpi_hotkey *key =
835 container_of(entries, union acpi_hotkey, entries);
836 if (key->link.hotkey_type == ACPI_HOTKEY_POLLING
837 && key->link.hotkey_standard_num == event) {
838 return (&key->poll_hotkey);
839 }
840 }
841 return (NULL);
842}
843
844/*
845 * user call AML method interface:
846 * Call convention:
847 * echo "event_num: arg type : value"
848 * example: echo "1:1:30" > /proc/acpi/action
849 * Just support 1 integer arg passing to AML method
850 */
851
852static ssize_t hotkey_execute_aml_method(struct file *file,
853 const char __user * buffer,
854 size_t count, loff_t * data)
855{
856 struct acpi_hotkey_list *hotkey_list = &global_hotkey_list;
857 char arg[MAX_CALL_PARM];
858 int event, type, value;
859
860 char *method;
861 acpi_handle handle;
862
863 ACPI_FUNCTION_TRACE("hotkey_execte_aml_method");
864
865 if (!hotkey_list || count > MAX_CALL_PARM) {
866 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid argument 1"));
867 return_VALUE(-EINVAL);
868 }
869
870 if (copy_from_user(arg, buffer, count)) {
871 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid argument 2"));
872 return_VALUE(-EINVAL);
873 }
874
875 arg[count] = '\0';
876
877 if (sscanf(arg, "%d:%d:%d", &event, &type, &value) != 3) {
878 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid argument 3"));
879 return_VALUE(-EINVAL);
880 }
881
882 if (type == ACPI_TYPE_INTEGER) {
883 handle = get_handle_from_hotkeylist(hotkey_list, event);
884 method = (char *)get_method_from_hotkeylist(hotkey_list, event);
885 if (IS_EVENT(event))
886 write_acpi_int(handle, method, value, NULL);
887 else if (IS_POLL(event)) {
888 struct acpi_polling_hotkey *key;
889 key = (struct acpi_polling_hotkey *)
890 get_hotkey_by_event(hotkey_list, event);
891 read_acpi_int(handle, method, key->poll_result);
892 }
893 } else {
894 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Not supported"));
895 return_VALUE(-EINVAL);
896 }
897
898 return_VALUE(count);
899}
900
901static int __init hotkey_init(void)
902{
903 int result;
904 mode_t mode = S_IFREG | S_IRUGO | S_IWUGO;
905
906 ACPI_FUNCTION_TRACE("hotkey_init");
907
908 if (acpi_disabled)
909 return -ENODEV;
910
911 if (acpi_specific_hotkey_enabled) {
912 printk("Using specific hotkey driver\n");
913 return -ENODEV;
914 }
915
916 hotkey_proc_dir = proc_mkdir(HOTKEY_PROC, acpi_root_dir);
917 if (!hotkey_proc_dir) {
918 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
919 "Hotkey: Unable to create %s entry\n",
920 HOTKEY_PROC));
921 return (-ENODEV);
922 }
923 hotkey_proc_dir->owner = THIS_MODULE;
924
925 hotkey_config =
926 create_proc_entry(HOTKEY_EV_CONFIG, mode, hotkey_proc_dir);
927 if (!hotkey_config) {
928 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
929 "Hotkey: Unable to create %s entry\n",
930 HOTKEY_EV_CONFIG));
931 return (-ENODEV);
932 } else {
933 hotkey_config->proc_fops = &hotkey_config_fops;
934 hotkey_config->data = &global_hotkey_list;
935 hotkey_config->owner = THIS_MODULE;
936 hotkey_config->uid = 0;
937 hotkey_config->gid = 0;
938 }
939
940 hotkey_poll_config =
941 create_proc_entry(HOTKEY_PL_CONFIG, mode, hotkey_proc_dir);
942 if (!hotkey_poll_config) {
943 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
944 "Hotkey: Unable to create %s entry\n",
945 HOTKEY_EV_CONFIG));
946 return (-ENODEV);
947 } else {
948 hotkey_poll_config->proc_fops = &hotkey_poll_config_fops;
949 hotkey_poll_config->data = &global_hotkey_list;
950 hotkey_poll_config->owner = THIS_MODULE;
951 hotkey_poll_config->uid = 0;
952 hotkey_poll_config->gid = 0;
953 }
954
955 hotkey_action = create_proc_entry(HOTKEY_ACTION, mode, hotkey_proc_dir);
956 if (!hotkey_action) {
957 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
958 "Hotkey: Unable to create %s entry\n",
959 HOTKEY_ACTION));
960 return (-ENODEV);
961 } else {
962 hotkey_action->proc_fops = &hotkey_action_fops;
963 hotkey_action->owner = THIS_MODULE;
964 hotkey_action->uid = 0;
965 hotkey_action->gid = 0;
966 }
967
968 hotkey_info = create_proc_entry(HOTKEY_INFO, mode, hotkey_proc_dir);
969 if (!hotkey_info) {
970 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
971 "Hotkey: Unable to create %s entry\n",
972 HOTKEY_INFO));
973 return (-ENODEV);
974 } else {
975 hotkey_info->proc_fops = &hotkey_info_fops;
976 hotkey_info->owner = THIS_MODULE;
977 hotkey_info->uid = 0;
978 hotkey_info->gid = 0;
979 }
980
981 result = acpi_bus_register_driver(&hotkey_driver);
982 if (result < 0) {
983 remove_proc_entry(HOTKEY_PROC, acpi_root_dir);
984 return (-ENODEV);
985 }
986 global_hotkey_list.count = 0;
987 global_hotkey_list.entries = &hotkey_entries;
988
989 INIT_LIST_HEAD(&hotkey_entries);
990
991 return (0);
992}
993
994static void __exit hotkey_exit(void)
995{
996 struct list_head *entries, *next;
997
998 ACPI_FUNCTION_TRACE("hotkey_remove");
999
1000 list_for_each_safe(entries, next, global_hotkey_list.entries) {
1001 union acpi_hotkey *key =
1002 container_of(entries, union acpi_hotkey, entries);
1003
1004 acpi_os_wait_events_complete(NULL);
1005 list_del(&key->link.entries);
1006 global_hotkey_list.count--;
1007 free_hotkey_device(key);
1008 }
1009 acpi_bus_unregister_driver(&hotkey_driver);
1010 remove_proc_entry(HOTKEY_EV_CONFIG, hotkey_proc_dir);
1011 remove_proc_entry(HOTKEY_PL_CONFIG, hotkey_proc_dir);
1012 remove_proc_entry(HOTKEY_ACTION, hotkey_proc_dir);
1013 remove_proc_entry(HOTKEY_INFO, hotkey_proc_dir);
1014 remove_proc_entry(HOTKEY_PROC, acpi_root_dir);
1015 return;
1016}
1017
1018module_init(hotkey_init);
1019module_exit(hotkey_exit);
diff --git a/drivers/acpi/ibm_acpi.c b/drivers/acpi/ibm_acpi.c
index 0fb731a470dc..ad85e10001f4 100644
--- a/drivers/acpi/ibm_acpi.c
+++ b/drivers/acpi/ibm_acpi.c
@@ -1025,7 +1025,7 @@ static int setup_notify(struct ibm_struct *ibm)
1025 return 0; 1025 return 0;
1026} 1026}
1027 1027
1028static int device_add(struct acpi_device *device) 1028static int ibmacpi_device_add(struct acpi_device *device)
1029{ 1029{
1030 return 0; 1030 return 0;
1031} 1031}
@@ -1043,7 +1043,7 @@ static int register_driver(struct ibm_struct *ibm)
1043 memset(ibm->driver, 0, sizeof(struct acpi_driver)); 1043 memset(ibm->driver, 0, sizeof(struct acpi_driver));
1044 sprintf(ibm->driver->name, "%s/%s", IBM_NAME, ibm->name); 1044 sprintf(ibm->driver->name, "%s/%s", IBM_NAME, ibm->name);
1045 ibm->driver->ids = ibm->hid; 1045 ibm->driver->ids = ibm->hid;
1046 ibm->driver->ops.add = &device_add; 1046 ibm->driver->ops.add = &ibmacpi_device_add;
1047 1047
1048 ret = acpi_bus_register_driver(ibm->driver); 1048 ret = acpi_bus_register_driver(ibm->driver);
1049 if (ret < 0) { 1049 if (ret < 0) {
@@ -1185,6 +1185,10 @@ static int __init acpi_ibm_init(void)
1185 if (acpi_disabled) 1185 if (acpi_disabled)
1186 return -ENODEV; 1186 return -ENODEV;
1187 1187
1188 if (!acpi_specific_hotkey_enabled){
1189 printk(IBM_ERR "Using generic hotkey driver\n");
1190 return -ENODEV;
1191 }
1188 /* these handles are required */ 1192 /* these handles are required */
1189 if (IBM_HANDLE_INIT(ec, 1) < 0 || 1193 if (IBM_HANDLE_INIT(ec, 1) < 0 ||
1190 IBM_HANDLE_INIT(hkey, 1) < 0 || 1194 IBM_HANDLE_INIT(hkey, 1) < 0 ||
diff --git a/drivers/acpi/namespace/nsaccess.c b/drivers/acpi/namespace/nsaccess.c
index 1c0c12336c57..ece7a9dedd5c 100644
--- a/drivers/acpi/namespace/nsaccess.c
+++ b/drivers/acpi/namespace/nsaccess.c
@@ -67,7 +67,8 @@
67 ******************************************************************************/ 67 ******************************************************************************/
68 68
69acpi_status 69acpi_status
70acpi_ns_root_initialize (void) 70acpi_ns_root_initialize (
71 void)
71{ 72{
72 acpi_status status; 73 acpi_status status;
73 const struct acpi_predefined_names *init_val = NULL; 74 const struct acpi_predefined_names *init_val = NULL;
@@ -265,7 +266,7 @@ unlock_and_exit:
265 * 266 *
266 * FUNCTION: acpi_ns_lookup 267 * FUNCTION: acpi_ns_lookup
267 * 268 *
268 * PARAMETERS: prefix_node - Search scope if name is not fully qualified 269 * PARAMETERS: scope_info - Current scope info block
269 * Pathname - Search pathname, in internal format 270 * Pathname - Search pathname, in internal format
270 * (as represented in the AML stream) 271 * (as represented in the AML stream)
271 * Type - Type associated with name 272 * Type - Type associated with name
diff --git a/drivers/acpi/namespace/nsalloc.c b/drivers/acpi/namespace/nsalloc.c
index bfd922c5c7d1..5653a19d7172 100644
--- a/drivers/acpi/namespace/nsalloc.c
+++ b/drivers/acpi/namespace/nsalloc.c
@@ -49,14 +49,20 @@
49#define _COMPONENT ACPI_NAMESPACE 49#define _COMPONENT ACPI_NAMESPACE
50 ACPI_MODULE_NAME ("nsalloc") 50 ACPI_MODULE_NAME ("nsalloc")
51 51
52/* Local prototypes */
53
54static void
55acpi_ns_remove_reference (
56 struct acpi_namespace_node *node);
57
52 58
53/******************************************************************************* 59/*******************************************************************************
54 * 60 *
55 * FUNCTION: acpi_ns_create_node 61 * FUNCTION: acpi_ns_create_node
56 * 62 *
57 * PARAMETERS: acpi_name - Name of the new node 63 * PARAMETERS: Name - Name of the new node (4 char ACPI name)
58 * 64 *
59 * RETURN: None 65 * RETURN: New namespace node (Null on failure)
60 * 66 *
61 * DESCRIPTION: Create a namespace node 67 * DESCRIPTION: Create a namespace node
62 * 68 *
@@ -145,7 +151,6 @@ acpi_ns_delete_node (
145 } 151 }
146 } 152 }
147 153
148
149 ACPI_MEM_TRACKING (acpi_gbl_memory_lists[ACPI_MEM_LIST_NSNODE].total_freed++); 154 ACPI_MEM_TRACKING (acpi_gbl_memory_lists[ACPI_MEM_LIST_NSNODE].total_freed++);
150 155
151 /* 156 /*
@@ -157,57 +162,6 @@ acpi_ns_delete_node (
157} 162}
158 163
159 164
160#ifdef ACPI_ALPHABETIC_NAMESPACE
161/*******************************************************************************
162 *
163 * FUNCTION: acpi_ns_compare_names
164 *
165 * PARAMETERS: Name1 - First name to compare
166 * Name2 - Second name to compare
167 *
168 * RETURN: value from strncmp
169 *
170 * DESCRIPTION: Compare two ACPI names. Names that are prefixed with an
171 * underscore are forced to be alphabetically first.
172 *
173 ******************************************************************************/
174
175int
176acpi_ns_compare_names (
177 char *name1,
178 char *name2)
179{
180 char reversed_name1[ACPI_NAME_SIZE];
181 char reversed_name2[ACPI_NAME_SIZE];
182 u32 i;
183 u32 j;
184
185
186 /*
187 * Replace all instances of "underscore" with a value that is smaller so
188 * that all names that are prefixed with underscore(s) are alphabetically
189 * first.
190 *
191 * Reverse the name bytewise so we can just do a 32-bit compare instead
192 * of a strncmp.
193 */
194 for (i = 0, j= (ACPI_NAME_SIZE - 1); i < ACPI_NAME_SIZE; i++, j--) {
195 reversed_name1[j] = name1[i];
196 if (name1[i] == '_') {
197 reversed_name1[j] = '*';
198 }
199
200 reversed_name2[j] = name2[i];
201 if (name2[i] == '_') {
202 reversed_name2[j] = '*';
203 }
204 }
205
206 return (*(int *) reversed_name1 - *(int *) reversed_name2);
207}
208#endif
209
210
211/******************************************************************************* 165/*******************************************************************************
212 * 166 *
213 * FUNCTION: acpi_ns_install_node 167 * FUNCTION: acpi_ns_install_node
@@ -271,7 +225,8 @@ acpi_ns_install_node (
271 * alphabetic placement. 225 * alphabetic placement.
272 */ 226 */
273 previous_child_node = NULL; 227 previous_child_node = NULL;
274 while (acpi_ns_compare_names (acpi_ut_get_node_name (child_node), acpi_ut_get_node_name (node)) < 0) { 228 while (acpi_ns_compare_names (acpi_ut_get_node_name (child_node),
229 acpi_ut_get_node_name (node)) < 0) {
275 if (child_node->flags & ANOBJ_END_OF_PEER_LIST) { 230 if (child_node->flags & ANOBJ_END_OF_PEER_LIST) {
276 /* Last peer; Clear end-of-list flag */ 231 /* Last peer; Clear end-of-list flag */
277 232
@@ -429,7 +384,8 @@ acpi_ns_delete_children (
429 /* There should be only one reference remaining on this node */ 384 /* There should be only one reference remaining on this node */
430 385
431 if (child_node->reference_count != 1) { 386 if (child_node->reference_count != 1) {
432 ACPI_REPORT_WARNING (("Existing references (%d) on node being deleted (%p)\n", 387 ACPI_REPORT_WARNING ((
388 "Existing references (%d) on node being deleted (%p)\n",
433 child_node->reference_count, child_node)); 389 child_node->reference_count, child_node));
434 } 390 }
435 391
@@ -548,7 +504,7 @@ acpi_ns_delete_namespace_subtree (
548 * 504 *
549 ******************************************************************************/ 505 ******************************************************************************/
550 506
551void 507static void
552acpi_ns_remove_reference ( 508acpi_ns_remove_reference (
553 struct acpi_namespace_node *node) 509 struct acpi_namespace_node *node)
554{ 510{
@@ -683,3 +639,54 @@ acpi_ns_delete_namespace_by_owner (
683} 639}
684 640
685 641
642#ifdef ACPI_ALPHABETIC_NAMESPACE
643/*******************************************************************************
644 *
645 * FUNCTION: acpi_ns_compare_names
646 *
647 * PARAMETERS: Name1 - First name to compare
648 * Name2 - Second name to compare
649 *
650 * RETURN: value from strncmp
651 *
652 * DESCRIPTION: Compare two ACPI names. Names that are prefixed with an
653 * underscore are forced to be alphabetically first.
654 *
655 ******************************************************************************/
656
657int
658acpi_ns_compare_names (
659 char *name1,
660 char *name2)
661{
662 char reversed_name1[ACPI_NAME_SIZE];
663 char reversed_name2[ACPI_NAME_SIZE];
664 u32 i;
665 u32 j;
666
667
668 /*
669 * Replace all instances of "underscore" with a value that is smaller so
670 * that all names that are prefixed with underscore(s) are alphabetically
671 * first.
672 *
673 * Reverse the name bytewise so we can just do a 32-bit compare instead
674 * of a strncmp.
675 */
676 for (i = 0, j= (ACPI_NAME_SIZE - 1); i < ACPI_NAME_SIZE; i++, j--) {
677 reversed_name1[j] = name1[i];
678 if (name1[i] == '_') {
679 reversed_name1[j] = '*';
680 }
681
682 reversed_name2[j] = name2[i];
683 if (name2[i] == '_') {
684 reversed_name2[j] = '*';
685 }
686 }
687
688 return (*(int *) reversed_name1 - *(int *) reversed_name2);
689}
690#endif
691
692
diff --git a/drivers/acpi/namespace/nsdump.c b/drivers/acpi/namespace/nsdump.c
index 1f6af3eb6c91..6c2aef0e0dd4 100644
--- a/drivers/acpi/namespace/nsdump.c
+++ b/drivers/acpi/namespace/nsdump.c
@@ -50,16 +50,32 @@
50#define _COMPONENT ACPI_NAMESPACE 50#define _COMPONENT ACPI_NAMESPACE
51 ACPI_MODULE_NAME ("nsdump") 51 ACPI_MODULE_NAME ("nsdump")
52 52
53/* Local prototypes */
53 54
54#if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER) 55#ifdef ACPI_OBSOLETE_FUNCTIONS
56void
57acpi_ns_dump_root_devices (
58 void);
55 59
60static acpi_status
61acpi_ns_dump_one_device (
62 acpi_handle obj_handle,
63 u32 level,
64 void *context,
65 void **return_value);
66#endif
67
68
69#if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
56/******************************************************************************* 70/*******************************************************************************
57 * 71 *
58 * FUNCTION: acpi_ns_print_pathname 72 * FUNCTION: acpi_ns_print_pathname
59 * 73 *
60 * PARAMETERS: num_segment - Number of ACPI name segments 74 * PARAMETERS: num_segments - Number of ACPI name segments
61 * Pathname - The compressed (internal) path 75 * Pathname - The compressed (internal) path
62 * 76 *
77 * RETURN: None
78 *
63 * DESCRIPTION: Print an object's full namespace pathname 79 * DESCRIPTION: Print an object's full namespace pathname
64 * 80 *
65 ******************************************************************************/ 81 ******************************************************************************/
@@ -103,6 +119,8 @@ acpi_ns_print_pathname (
103 * Level - Desired debug level 119 * Level - Desired debug level
104 * Component - Caller's component ID 120 * Component - Caller's component ID
105 * 121 *
122 * RETURN: None
123 *
106 * DESCRIPTION: Print an object's full namespace pathname 124 * DESCRIPTION: Print an object's full namespace pathname
107 * Manages allocation/freeing of a pathname buffer 125 * Manages allocation/freeing of a pathname buffer
108 * 126 *
@@ -137,9 +155,12 @@ acpi_ns_dump_pathname (
137 * 155 *
138 * FUNCTION: acpi_ns_dump_one_object 156 * FUNCTION: acpi_ns_dump_one_object
139 * 157 *
140 * PARAMETERS: Handle - Node to be dumped 158 * PARAMETERS: obj_handle - Node to be dumped
141 * Level - Nesting level of the handle 159 * Level - Nesting level of the handle
142 * Context - Passed into walk_namespace 160 * Context - Passed into walk_namespace
161 * return_value - Not used
162 *
163 * RETURN: Status
143 * 164 *
144 * DESCRIPTION: Dump a single Node 165 * DESCRIPTION: Dump a single Node
145 * This procedure is a user_function called by acpi_ns_walk_namespace. 166 * This procedure is a user_function called by acpi_ns_walk_namespace.
@@ -394,8 +415,7 @@ acpi_ns_dump_one_object (
394 return (AE_OK); 415 return (AE_OK);
395 } 416 }
396 417
397 acpi_os_printf ("(R%d)", 418 acpi_os_printf ("(R%d)", obj_desc->common.reference_count);
398 obj_desc->common.reference_count);
399 419
400 switch (type) { 420 switch (type) {
401 case ACPI_TYPE_METHOD: 421 case ACPI_TYPE_METHOD:
@@ -551,18 +571,20 @@ cleanup:
551 571
552 572
553#ifdef ACPI_FUTURE_USAGE 573#ifdef ACPI_FUTURE_USAGE
554
555/******************************************************************************* 574/*******************************************************************************
556 * 575 *
557 * FUNCTION: acpi_ns_dump_objects 576 * FUNCTION: acpi_ns_dump_objects
558 * 577 *
559 * PARAMETERS: Type - Object type to be dumped 578 * PARAMETERS: Type - Object type to be dumped
579 * display_type - 0 or ACPI_DISPLAY_SUMMARY
560 * max_depth - Maximum depth of dump. Use ACPI_UINT32_MAX 580 * max_depth - Maximum depth of dump. Use ACPI_UINT32_MAX
561 * for an effectively unlimited depth. 581 * for an effectively unlimited depth.
562 * owner_id - Dump only objects owned by this ID. Use 582 * owner_id - Dump only objects owned by this ID. Use
563 * ACPI_UINT32_MAX to match all owners. 583 * ACPI_UINT32_MAX to match all owners.
564 * start_handle - Where in namespace to start/end search 584 * start_handle - Where in namespace to start/end search
565 * 585 *
586 * RETURN: None
587 *
566 * DESCRIPTION: Dump typed objects within the loaded namespace. 588 * DESCRIPTION: Dump typed objects within the loaded namespace.
567 * Uses acpi_ns_walk_namespace in conjunction with acpi_ns_dump_one_object. 589 * Uses acpi_ns_walk_namespace in conjunction with acpi_ns_dump_one_object.
568 * 590 *
@@ -590,10 +612,44 @@ acpi_ns_dump_objects (
590 ACPI_NS_WALK_NO_UNLOCK, acpi_ns_dump_one_object, 612 ACPI_NS_WALK_NO_UNLOCK, acpi_ns_dump_one_object,
591 (void *) &info, NULL); 613 (void *) &info, NULL);
592} 614}
615#endif /* ACPI_FUTURE_USAGE */
593 616
594 617
595/******************************************************************************* 618/*******************************************************************************
596 * 619 *
620 * FUNCTION: acpi_ns_dump_entry
621 *
622 * PARAMETERS: Handle - Node to be dumped
623 * debug_level - Output level
624 *
625 * RETURN: None
626 *
627 * DESCRIPTION: Dump a single Node
628 *
629 ******************************************************************************/
630
631void
632acpi_ns_dump_entry (
633 acpi_handle handle,
634 u32 debug_level)
635{
636 struct acpi_walk_info info;
637
638
639 ACPI_FUNCTION_ENTRY ();
640
641
642 info.debug_level = debug_level;
643 info.owner_id = ACPI_UINT32_MAX;
644 info.display_type = ACPI_DISPLAY_SUMMARY;
645
646 (void) acpi_ns_dump_one_object (handle, 1, &info, NULL);
647}
648
649
650#ifdef _ACPI_ASL_COMPILER
651/*******************************************************************************
652 *
597 * FUNCTION: acpi_ns_dump_tables 653 * FUNCTION: acpi_ns_dump_tables
598 * 654 *
599 * PARAMETERS: search_base - Root of subtree to be dumped, or 655 * PARAMETERS: search_base - Root of subtree to be dumped, or
@@ -601,6 +657,8 @@ acpi_ns_dump_objects (
601 * max_depth - Maximum depth of dump. Use INT_MAX 657 * max_depth - Maximum depth of dump. Use INT_MAX
602 * for an effectively unlimited depth. 658 * for an effectively unlimited depth.
603 * 659 *
660 * RETURN: None
661 *
604 * DESCRIPTION: Dump the name space, or a portion of it. 662 * DESCRIPTION: Dump the name space, or a portion of it.
605 * 663 *
606 ******************************************************************************/ 664 ******************************************************************************/
@@ -626,7 +684,7 @@ acpi_ns_dump_tables (
626 } 684 }
627 685
628 if (ACPI_NS_ALL == search_base) { 686 if (ACPI_NS_ALL == search_base) {
629 /* entire namespace */ 687 /* Entire namespace */
630 688
631 search_handle = acpi_gbl_root_node; 689 search_handle = acpi_gbl_root_node;
632 ACPI_DEBUG_PRINT ((ACPI_DB_TABLES, "\\\n")); 690 ACPI_DEBUG_PRINT ((ACPI_DB_TABLES, "\\\n"));
@@ -636,38 +694,5 @@ acpi_ns_dump_tables (
636 ACPI_UINT32_MAX, search_handle); 694 ACPI_UINT32_MAX, search_handle);
637 return_VOID; 695 return_VOID;
638} 696}
639 697#endif /* _ACPI_ASL_COMPILER */
640#endif /* ACPI_FUTURE_USAGE */ 698#endif /* defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER) */
641
642
643/*******************************************************************************
644 *
645 * FUNCTION: acpi_ns_dump_entry
646 *
647 * PARAMETERS: Handle - Node to be dumped
648 * debug_level - Output level
649 *
650 * DESCRIPTION: Dump a single Node
651 *
652 ******************************************************************************/
653
654void
655acpi_ns_dump_entry (
656 acpi_handle handle,
657 u32 debug_level)
658{
659 struct acpi_walk_info info;
660
661
662 ACPI_FUNCTION_ENTRY ();
663
664
665 info.debug_level = debug_level;
666 info.owner_id = ACPI_UINT32_MAX;
667 info.display_type = ACPI_DISPLAY_SUMMARY;
668
669 (void) acpi_ns_dump_one_object (handle, 1, &info, NULL);
670}
671
672#endif
673
diff --git a/drivers/acpi/namespace/nsdumpdv.c b/drivers/acpi/namespace/nsdumpdv.c
index d30a59e6b07d..27c4f7cd2a43 100644
--- a/drivers/acpi/namespace/nsdumpdv.c
+++ b/drivers/acpi/namespace/nsdumpdv.c
@@ -43,15 +43,18 @@
43 43
44 44
45#include <acpi/acpi.h> 45#include <acpi/acpi.h>
46#include <acpi/acnamesp.h>
47 46
48 47
48/* TBD: This entire module is apparently obsolete and should be removed */
49
49#define _COMPONENT ACPI_NAMESPACE 50#define _COMPONENT ACPI_NAMESPACE
50 ACPI_MODULE_NAME ("nsdumpdv") 51 ACPI_MODULE_NAME ("nsdumpdv")
51 52
52 53#ifdef ACPI_OBSOLETE_FUNCTIONS
53#if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER) 54#if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
54 55
56#include <acpi/acnamesp.h>
57
55/******************************************************************************* 58/*******************************************************************************
56 * 59 *
57 * FUNCTION: acpi_ns_dump_one_device 60 * FUNCTION: acpi_ns_dump_one_device
@@ -59,13 +62,16 @@
59 * PARAMETERS: Handle - Node to be dumped 62 * PARAMETERS: Handle - Node to be dumped
60 * Level - Nesting level of the handle 63 * Level - Nesting level of the handle
61 * Context - Passed into walk_namespace 64 * Context - Passed into walk_namespace
65 * return_value - Not used
66 *
67 * RETURN: Status
62 * 68 *
63 * DESCRIPTION: Dump a single Node that represents a device 69 * DESCRIPTION: Dump a single Node that represents a device
64 * This procedure is a user_function called by acpi_ns_walk_namespace. 70 * This procedure is a user_function called by acpi_ns_walk_namespace.
65 * 71 *
66 ******************************************************************************/ 72 ******************************************************************************/
67 73
68acpi_status 74static acpi_status
69acpi_ns_dump_one_device ( 75acpi_ns_dump_one_device (
70 acpi_handle obj_handle, 76 acpi_handle obj_handle,
71 u32 level, 77 u32 level,
@@ -108,12 +114,15 @@ acpi_ns_dump_one_device (
108 * 114 *
109 * PARAMETERS: None 115 * PARAMETERS: None
110 * 116 *
117 * RETURN: None
118 *
111 * DESCRIPTION: Dump all objects of type "device" 119 * DESCRIPTION: Dump all objects of type "device"
112 * 120 *
113 ******************************************************************************/ 121 ******************************************************************************/
114 122
115void 123void
116acpi_ns_dump_root_devices (void) 124acpi_ns_dump_root_devices (
125 void)
117{ 126{
118 acpi_handle sys_bus_handle; 127 acpi_handle sys_bus_handle;
119 acpi_status status; 128 acpi_status status;
@@ -142,5 +151,6 @@ acpi_ns_dump_root_devices (void)
142} 151}
143 152
144#endif 153#endif
154#endif
145 155
146 156
diff --git a/drivers/acpi/namespace/nseval.c b/drivers/acpi/namespace/nseval.c
index 0d008d53657e..1ae89a1c8826 100644
--- a/drivers/acpi/namespace/nseval.c
+++ b/drivers/acpi/namespace/nseval.c
@@ -52,19 +52,33 @@
52#define _COMPONENT ACPI_NAMESPACE 52#define _COMPONENT ACPI_NAMESPACE
53 ACPI_MODULE_NAME ("nseval") 53 ACPI_MODULE_NAME ("nseval")
54 54
55/* Local prototypes */
56
57static acpi_status
58acpi_ns_execute_control_method (
59 struct acpi_parameter_info *info);
60
61static acpi_status
62acpi_ns_get_object_value (
63 struct acpi_parameter_info *info);
64
55 65
56/******************************************************************************* 66/*******************************************************************************
57 * 67 *
58 * FUNCTION: acpi_ns_evaluate_relative 68 * FUNCTION: acpi_ns_evaluate_relative
59 * 69 *
60 * PARAMETERS: Pathname - Name of method to execute, If NULL, the 70 * PARAMETERS: Pathname - Name of method to execute, If NULL, the
61 * handle is the object to execute 71 * handle is the object to execute
62 * Info - Method info block 72 * Info - Method info block, contains:
73 * return_object - Where to put method's return value (if
74 * any). If NULL, no value is returned.
75 * Params - List of parameters to pass to the method,
76 * terminated by NULL. Params itself may be
77 * NULL if no parameters are being passed.
63 * 78 *
64 * RETURN: Status 79 * RETURN: Status
65 * 80 *
66 * DESCRIPTION: Find and execute the requested method using the handle as a 81 * DESCRIPTION: Evaluate the object or find and execute the requested method
67 * scope
68 * 82 *
69 * MUTEX: Locks Namespace 83 * MUTEX: Locks Namespace
70 * 84 *
@@ -157,8 +171,8 @@ cleanup1:
157 * 171 *
158 * FUNCTION: acpi_ns_evaluate_by_name 172 * FUNCTION: acpi_ns_evaluate_by_name
159 * 173 *
160 * PARAMETERS: Pathname - Fully qualified pathname to the object 174 * PARAMETERS: Pathname - Fully qualified pathname to the object
161 * Info - Contains: 175 * Info - Method info block, contains:
162 * return_object - Where to put method's return value (if 176 * return_object - Where to put method's return value (if
163 * any). If NULL, no value is returned. 177 * any). If NULL, no value is returned.
164 * Params - List of parameters to pass to the method, 178 * Params - List of parameters to pass to the method,
@@ -167,8 +181,8 @@ cleanup1:
167 * 181 *
168 * RETURN: Status 182 * RETURN: Status
169 * 183 *
170 * DESCRIPTION: Find and execute the requested method passing the given 184 * DESCRIPTION: Evaluate the object or rind and execute the requested method
171 * parameters 185 * passing the given parameters
172 * 186 *
173 * MUTEX: Locks Namespace 187 * MUTEX: Locks Namespace
174 * 188 *
@@ -241,17 +255,21 @@ cleanup:
241 * 255 *
242 * FUNCTION: acpi_ns_evaluate_by_handle 256 * FUNCTION: acpi_ns_evaluate_by_handle
243 * 257 *
244 * PARAMETERS: Handle - Method Node to execute 258 * PARAMETERS: Info - Method info block, contains:
245 * Params - List of parameters to pass to the method, 259 * Node - Method/Object Node to execute
246 * terminated by NULL. Params itself may be 260 * Parameters - List of parameters to pass to the method,
261 * terminated by NULL. Params itself may be
247 * NULL if no parameters are being passed. 262 * NULL if no parameters are being passed.
248 * param_type - Type of Parameter list 263 * return_object - Where to put method's return value (if
249 * return_object - Where to put method's return value (if 264 * any). If NULL, no value is returned.
250 * any). If NULL, no value is returned. 265 * parameter_type - Type of Parameter list
266 * return_object - Where to put method's return value (if
267 * any). If NULL, no value is returned.
251 * 268 *
252 * RETURN: Status 269 * RETURN: Status
253 * 270 *
254 * DESCRIPTION: Execute the requested method passing the given parameters 271 * DESCRIPTION: Evaluate object or execute the requested method passing the
272 * given parameters
255 * 273 *
256 * MUTEX: Locks Namespace 274 * MUTEX: Locks Namespace
257 * 275 *
@@ -345,7 +363,16 @@ acpi_ns_evaluate_by_handle (
345 * 363 *
346 * FUNCTION: acpi_ns_execute_control_method 364 * FUNCTION: acpi_ns_execute_control_method
347 * 365 *
348 * PARAMETERS: Info - Method info block (w/params) 366 * PARAMETERS: Info - Method info block, contains:
367 * Node - Method Node to execute
368 * Parameters - List of parameters to pass to the method,
369 * terminated by NULL. Params itself may be
370 * NULL if no parameters are being passed.
371 * return_object - Where to put method's return value (if
372 * any). If NULL, no value is returned.
373 * parameter_type - Type of Parameter list
374 * return_object - Where to put method's return value (if
375 * any). If NULL, no value is returned.
349 * 376 *
350 * RETURN: Status 377 * RETURN: Status
351 * 378 *
@@ -355,7 +382,7 @@ acpi_ns_evaluate_by_handle (
355 * 382 *
356 ******************************************************************************/ 383 ******************************************************************************/
357 384
358acpi_status 385static acpi_status
359acpi_ns_execute_control_method ( 386acpi_ns_execute_control_method (
360 struct acpi_parameter_info *info) 387 struct acpi_parameter_info *info)
361{ 388{
@@ -414,7 +441,10 @@ acpi_ns_execute_control_method (
414 * 441 *
415 * FUNCTION: acpi_ns_get_object_value 442 * FUNCTION: acpi_ns_get_object_value
416 * 443 *
417 * PARAMETERS: Info - Method info block (w/params) 444 * PARAMETERS: Info - Method info block, contains:
445 * Node - Object's NS node
446 * return_object - Where to put object value (if
447 * any). If NULL, no value is returned.
418 * 448 *
419 * RETURN: Status 449 * RETURN: Status
420 * 450 *
@@ -424,7 +454,7 @@ acpi_ns_execute_control_method (
424 * 454 *
425 ******************************************************************************/ 455 ******************************************************************************/
426 456
427acpi_status 457static acpi_status
428acpi_ns_get_object_value ( 458acpi_ns_get_object_value (
429 struct acpi_parameter_info *info) 459 struct acpi_parameter_info *info)
430{ 460{
diff --git a/drivers/acpi/namespace/nsinit.c b/drivers/acpi/namespace/nsinit.c
index 4a46b380605b..362802ae29a2 100644
--- a/drivers/acpi/namespace/nsinit.c
+++ b/drivers/acpi/namespace/nsinit.c
@@ -50,6 +50,22 @@
50#define _COMPONENT ACPI_NAMESPACE 50#define _COMPONENT ACPI_NAMESPACE
51 ACPI_MODULE_NAME ("nsinit") 51 ACPI_MODULE_NAME ("nsinit")
52 52
53/* Local prototypes */
54
55static acpi_status
56acpi_ns_init_one_object (
57 acpi_handle obj_handle,
58 u32 level,
59 void *context,
60 void **return_value);
61
62static acpi_status
63acpi_ns_init_one_device (
64 acpi_handle obj_handle,
65 u32 nesting_level,
66 void *context,
67 void **return_value);
68
53 69
54/******************************************************************************* 70/*******************************************************************************
55 * 71 *
@@ -191,7 +207,7 @@ acpi_ns_initialize_devices (
191 * 207 *
192 ******************************************************************************/ 208 ******************************************************************************/
193 209
194acpi_status 210static acpi_status
195acpi_ns_init_one_object ( 211acpi_ns_init_one_object (
196 acpi_handle obj_handle, 212 acpi_handle obj_handle,
197 u32 level, 213 u32 level,
@@ -331,7 +347,7 @@ acpi_ns_init_one_object (
331 * 347 *
332 ******************************************************************************/ 348 ******************************************************************************/
333 349
334acpi_status 350static acpi_status
335acpi_ns_init_one_device ( 351acpi_ns_init_one_device (
336 acpi_handle obj_handle, 352 acpi_handle obj_handle,
337 u32 nesting_level, 353 u32 nesting_level,
@@ -374,7 +390,8 @@ acpi_ns_init_one_device (
374 /* 390 /*
375 * Run _STA to determine if we can run _INI on the device. 391 * Run _STA to determine if we can run _INI on the device.
376 */ 392 */
377 ACPI_DEBUG_EXEC (acpi_ut_display_init_pathname (ACPI_TYPE_METHOD, pinfo.node, "_STA")); 393 ACPI_DEBUG_EXEC (acpi_ut_display_init_pathname (ACPI_TYPE_METHOD,
394 pinfo.node, METHOD_NAME__STA));
378 status = acpi_ut_execute_STA (pinfo.node, &flags); 395 status = acpi_ut_execute_STA (pinfo.node, &flags);
379 396
380 if (ACPI_FAILURE (status)) { 397 if (ACPI_FAILURE (status)) {
@@ -399,8 +416,9 @@ acpi_ns_init_one_device (
399 /* 416 /*
400 * The device is present. Run _INI. 417 * The device is present. Run _INI.
401 */ 418 */
402 ACPI_DEBUG_EXEC (acpi_ut_display_init_pathname (ACPI_TYPE_METHOD, pinfo.node, "_INI")); 419 ACPI_DEBUG_EXEC (acpi_ut_display_init_pathname (ACPI_TYPE_METHOD,
403 status = acpi_ns_evaluate_relative ("_INI", &pinfo); 420 pinfo.node, METHOD_NAME__INI));
421 status = acpi_ns_evaluate_relative (METHOD_NAME__INI, &pinfo);
404 if (ACPI_FAILURE (status)) { 422 if (ACPI_FAILURE (status)) {
405 /* No _INI (AE_NOT_FOUND) means device requires no initialization */ 423 /* No _INI (AE_NOT_FOUND) means device requires no initialization */
406 424
diff --git a/drivers/acpi/namespace/nsload.c b/drivers/acpi/namespace/nsload.c
index 1d7aedf68a77..34e497016601 100644
--- a/drivers/acpi/namespace/nsload.c
+++ b/drivers/acpi/namespace/nsload.c
@@ -50,9 +50,24 @@
50#define _COMPONENT ACPI_NAMESPACE 50#define _COMPONENT ACPI_NAMESPACE
51 ACPI_MODULE_NAME ("nsload") 51 ACPI_MODULE_NAME ("nsload")
52 52
53/* Local prototypes */
53 54
54#ifndef ACPI_NO_METHOD_EXECUTION 55static acpi_status
56acpi_ns_load_table_by_type (
57 acpi_table_type table_type);
58
59#ifdef ACPI_FUTURE_IMPLEMENTATION
60acpi_status
61acpi_ns_unload_namespace (
62 acpi_handle handle);
63
64static acpi_status
65acpi_ns_delete_subtree (
66 acpi_handle start_handle);
67#endif
55 68
69
70#ifndef ACPI_NO_METHOD_EXECUTION
56/******************************************************************************* 71/*******************************************************************************
57 * 72 *
58 * FUNCTION: acpi_ns_load_table 73 * FUNCTION: acpi_ns_load_table
@@ -159,7 +174,7 @@ acpi_ns_load_table (
159 * 174 *
160 ******************************************************************************/ 175 ******************************************************************************/
161 176
162acpi_status 177static acpi_status
163acpi_ns_load_table_by_type ( 178acpi_ns_load_table_by_type (
164 acpi_table_type table_type) 179 acpi_table_type table_type)
165{ 180{
@@ -321,8 +336,7 @@ acpi_ns_load_namespace (
321} 336}
322 337
323 338
324#ifdef ACPI_FUTURE_USAGE 339#ifdef ACPI_FUTURE_IMPLEMENTATION
325
326/******************************************************************************* 340/*******************************************************************************
327 * 341 *
328 * FUNCTION: acpi_ns_delete_subtree 342 * FUNCTION: acpi_ns_delete_subtree
@@ -339,7 +353,7 @@ acpi_ns_load_namespace (
339 * 353 *
340 ******************************************************************************/ 354 ******************************************************************************/
341 355
342acpi_status 356static acpi_status
343acpi_ns_delete_subtree ( 357acpi_ns_delete_subtree (
344 acpi_handle start_handle) 358 acpi_handle start_handle)
345{ 359{
@@ -453,8 +467,6 @@ acpi_ns_unload_namespace (
453 467
454 return_ACPI_STATUS (status); 468 return_ACPI_STATUS (status);
455} 469}
456 470#endif
457#endif /* ACPI_FUTURE_USAGE */
458
459#endif 471#endif
460 472
diff --git a/drivers/acpi/namespace/nsnames.c b/drivers/acpi/namespace/nsnames.c
index b6f8f910eff0..d8ce7e39795f 100644
--- a/drivers/acpi/namespace/nsnames.c
+++ b/drivers/acpi/namespace/nsnames.c
@@ -50,6 +50,14 @@
50#define _COMPONENT ACPI_NAMESPACE 50#define _COMPONENT ACPI_NAMESPACE
51 ACPI_MODULE_NAME ("nsnames") 51 ACPI_MODULE_NAME ("nsnames")
52 52
53/* Local prototypes */
54
55static void
56acpi_ns_build_external_path (
57 struct acpi_namespace_node *node,
58 acpi_size size,
59 char *name_buffer);
60
53 61
54/******************************************************************************* 62/*******************************************************************************
55 * 63 *
@@ -66,7 +74,7 @@
66 * 74 *
67 ******************************************************************************/ 75 ******************************************************************************/
68 76
69void 77static void
70acpi_ns_build_external_path ( 78acpi_ns_build_external_path (
71 struct acpi_namespace_node *node, 79 struct acpi_namespace_node *node,
72 acpi_size size, 80 acpi_size size,
@@ -126,7 +134,7 @@ acpi_ns_build_external_path (
126 * 134 *
127 * FUNCTION: acpi_ns_get_external_pathname 135 * FUNCTION: acpi_ns_get_external_pathname
128 * 136 *
129 * PARAMETERS: Node - NS node whose pathname is needed 137 * PARAMETERS: Node - Namespace node whose pathname is needed
130 * 138 *
131 * RETURN: Pointer to storage containing the fully qualified name of 139 * RETURN: Pointer to storage containing the fully qualified name of
132 * the node, In external format (name segments separated by path 140 * the node, In external format (name segments separated by path
diff --git a/drivers/acpi/namespace/nsobject.c b/drivers/acpi/namespace/nsobject.c
index 4e41e66db61f..27258c1ca4f1 100644
--- a/drivers/acpi/namespace/nsobject.c
+++ b/drivers/acpi/namespace/nsobject.c
@@ -60,6 +60,8 @@
60 * Type - Type of object, or ACPI_TYPE_ANY if not 60 * Type - Type of object, or ACPI_TYPE_ANY if not
61 * known 61 * known
62 * 62 *
63 * RETURN: Status
64 *
63 * DESCRIPTION: Record the given object as the value associated with the 65 * DESCRIPTION: Record the given object as the value associated with the
64 * name whose acpi_handle is passed. If Object is NULL 66 * name whose acpi_handle is passed. If Object is NULL
65 * and Type is ACPI_TYPE_ANY, set the name as having no value. 67 * and Type is ACPI_TYPE_ANY, set the name as having no value.
@@ -97,7 +99,8 @@ acpi_ns_attach_object (
97 if (!object && (ACPI_TYPE_ANY != type)) { 99 if (!object && (ACPI_TYPE_ANY != type)) {
98 /* Null object */ 100 /* Null object */
99 101
100 ACPI_REPORT_ERROR (("ns_attach_object: Null object, but type not ACPI_TYPE_ANY\n")); 102 ACPI_REPORT_ERROR ((
103 "ns_attach_object: Null object, but type not ACPI_TYPE_ANY\n"));
101 return_ACPI_STATUS (AE_BAD_PARAMETER); 104 return_ACPI_STATUS (AE_BAD_PARAMETER);
102 } 105 }
103 106
@@ -112,7 +115,8 @@ acpi_ns_attach_object (
112 /* Check if this object is already attached */ 115 /* Check if this object is already attached */
113 116
114 if (node->object == object) { 117 if (node->object == object) {
115 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj %p already installed in name_obj %p\n", 118 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
119 "Obj %p already installed in name_obj %p\n",
116 object, node)); 120 object, node));
117 121
118 return_ACPI_STATUS (AE_OK); 122 return_ACPI_STATUS (AE_OK);
@@ -192,7 +196,7 @@ acpi_ns_attach_object (
192 * 196 *
193 * FUNCTION: acpi_ns_detach_object 197 * FUNCTION: acpi_ns_detach_object
194 * 198 *
195 * PARAMETERS: Node - An node whose object will be detached 199 * PARAMETERS: Node - A Namespace node whose object will be detached
196 * 200 *
197 * RETURN: None. 201 * RETURN: None.
198 * 202 *
@@ -248,7 +252,7 @@ acpi_ns_detach_object (
248 * 252 *
249 * FUNCTION: acpi_ns_get_attached_object 253 * FUNCTION: acpi_ns_get_attached_object
250 * 254 *
251 * PARAMETERS: Node - Parent Node to be examined 255 * PARAMETERS: Node - Namespace node
252 * 256 *
253 * RETURN: Current value of the object field from the Node whose 257 * RETURN: Current value of the object field from the Node whose
254 * handle is passed 258 * handle is passed
@@ -284,7 +288,7 @@ acpi_ns_get_attached_object (
284 * 288 *
285 * FUNCTION: acpi_ns_get_secondary_object 289 * FUNCTION: acpi_ns_get_secondary_object
286 * 290 *
287 * PARAMETERS: Node - Parent Node to be examined 291 * PARAMETERS: Node - Namespace node
288 * 292 *
289 * RETURN: Current value of the object field from the Node whose 293 * RETURN: Current value of the object field from the Node whose
290 * handle is passed. 294 * handle is passed.
diff --git a/drivers/acpi/namespace/nssearch.c b/drivers/acpi/namespace/nssearch.c
index 0e6dea23603b..af8aaa9cc4f3 100644
--- a/drivers/acpi/namespace/nssearch.c
+++ b/drivers/acpi/namespace/nssearch.c
@@ -49,15 +49,24 @@
49#define _COMPONENT ACPI_NAMESPACE 49#define _COMPONENT ACPI_NAMESPACE
50 ACPI_MODULE_NAME ("nssearch") 50 ACPI_MODULE_NAME ("nssearch")
51 51
52/* Local prototypes */
53
54static acpi_status
55acpi_ns_search_parent_tree (
56 u32 target_name,
57 struct acpi_namespace_node *node,
58 acpi_object_type type,
59 struct acpi_namespace_node **return_node);
60
52 61
53/******************************************************************************* 62/*******************************************************************************
54 * 63 *
55 * FUNCTION: acpi_ns_search_node 64 * FUNCTION: acpi_ns_search_node
56 * 65 *
57 * PARAMETERS: *target_name - Ascii ACPI name to search for 66 * PARAMETERS: target_name - Ascii ACPI name to search for
58 * *Node - Starting node where search will begin 67 * Node - Starting node where search will begin
59 * Type - Object type to match 68 * Type - Object type to match
60 * **return_node - Where the matched Named obj is returned 69 * return_node - Where the matched Named obj is returned
61 * 70 *
62 * RETURN: Status 71 * RETURN: Status
63 * 72 *
@@ -163,10 +172,10 @@ acpi_ns_search_node (
163 * 172 *
164 * FUNCTION: acpi_ns_search_parent_tree 173 * FUNCTION: acpi_ns_search_parent_tree
165 * 174 *
166 * PARAMETERS: *target_name - Ascii ACPI name to search for 175 * PARAMETERS: target_name - Ascii ACPI name to search for
167 * *Node - Starting node where search will begin 176 * Node - Starting node where search will begin
168 * Type - Object type to match 177 * Type - Object type to match
169 * **return_node - Where the matched Node is returned 178 * return_node - Where the matched Node is returned
170 * 179 *
171 * RETURN: Status 180 * RETURN: Status
172 * 181 *
@@ -257,12 +266,12 @@ acpi_ns_search_parent_tree (
257 * 266 *
258 * PARAMETERS: target_name - Ascii ACPI name to search for (4 chars) 267 * PARAMETERS: target_name - Ascii ACPI name to search for (4 chars)
259 * walk_state - Current state of the walk 268 * walk_state - Current state of the walk
260 * *Node - Starting node where search will begin 269 * Node - Starting node where search will begin
261 * interpreter_mode - Add names only in ACPI_MODE_LOAD_PASS_x. 270 * interpreter_mode - Add names only in ACPI_MODE_LOAD_PASS_x.
262 * Otherwise,search only. 271 * Otherwise,search only.
263 * Type - Object type to match 272 * Type - Object type to match
264 * Flags - Flags describing the search restrictions 273 * Flags - Flags describing the search restrictions
265 * **return_node - Where the Node is returned 274 * return_node - Where the Node is returned
266 * 275 *
267 * RETURN: Status 276 * RETURN: Status
268 * 277 *
diff --git a/drivers/acpi/namespace/nsutils.c b/drivers/acpi/namespace/nsutils.c
index 75da76cc0b19..c53b82e94ce3 100644
--- a/drivers/acpi/namespace/nsutils.c
+++ b/drivers/acpi/namespace/nsutils.c
@@ -51,6 +51,18 @@
51#define _COMPONENT ACPI_NAMESPACE 51#define _COMPONENT ACPI_NAMESPACE
52 ACPI_MODULE_NAME ("nsutils") 52 ACPI_MODULE_NAME ("nsutils")
53 53
54/* Local prototypes */
55
56static u8
57acpi_ns_valid_path_separator (
58 char sep);
59
60#ifdef ACPI_OBSOLETE_FUNCTIONS
61acpi_name
62acpi_ns_find_parent_name (
63 struct acpi_namespace_node *node_to_search);
64#endif
65
54 66
55/******************************************************************************* 67/*******************************************************************************
56 * 68 *
@@ -59,7 +71,8 @@
59 * PARAMETERS: module_name - Caller's module name (for error output) 71 * PARAMETERS: module_name - Caller's module name (for error output)
60 * line_number - Caller's line number (for error output) 72 * line_number - Caller's line number (for error output)
61 * component_id - Caller's component ID (for error output) 73 * component_id - Caller's component ID (for error output)
62 * Message - Error message to use on failure 74 * internal_name - Name or path of the namespace node
75 * lookup_status - Exception code from NS lookup
63 * 76 *
64 * RETURN: None 77 * RETURN: None
65 * 78 *
@@ -121,6 +134,9 @@ acpi_ns_report_error (
121 * line_number - Caller's line number (for error output) 134 * line_number - Caller's line number (for error output)
122 * component_id - Caller's component ID (for error output) 135 * component_id - Caller's component ID (for error output)
123 * Message - Error message to use on failure 136 * Message - Error message to use on failure
137 * prefix_node - Prefix relative to the path
138 * Path - Path to the node
139 * method_status - Execution status
124 * 140 *
125 * RETURN: None 141 * RETURN: None
126 * 142 *
@@ -161,8 +177,8 @@ acpi_ns_report_method_error (
161 * 177 *
162 * FUNCTION: acpi_ns_print_node_pathname 178 * FUNCTION: acpi_ns_print_node_pathname
163 * 179 *
164 * PARAMETERS: Node - Object 180 * PARAMETERS: Node - Object
165 * Msg - Prefix message 181 * Message - Prefix message
166 * 182 *
167 * DESCRIPTION: Print an object's full namespace pathname 183 * DESCRIPTION: Print an object's full namespace pathname
168 * Manages allocation/freeing of a pathname buffer 184 * Manages allocation/freeing of a pathname buffer
@@ -172,7 +188,7 @@ acpi_ns_report_method_error (
172void 188void
173acpi_ns_print_node_pathname ( 189acpi_ns_print_node_pathname (
174 struct acpi_namespace_node *node, 190 struct acpi_namespace_node *node,
175 char *msg) 191 char *message)
176{ 192{
177 struct acpi_buffer buffer; 193 struct acpi_buffer buffer;
178 acpi_status status; 194 acpi_status status;
@@ -189,8 +205,8 @@ acpi_ns_print_node_pathname (
189 205
190 status = acpi_ns_handle_to_pathname (node, &buffer); 206 status = acpi_ns_handle_to_pathname (node, &buffer);
191 if (ACPI_SUCCESS (status)) { 207 if (ACPI_SUCCESS (status)) {
192 if (msg) { 208 if (message) {
193 acpi_os_printf ("%s ", msg); 209 acpi_os_printf ("%s ", message);
194 } 210 }
195 211
196 acpi_os_printf ("[%s] (Node %p)", (char *) buffer.pointer, node); 212 acpi_os_printf ("[%s] (Node %p)", (char *) buffer.pointer, node);
@@ -224,7 +240,7 @@ acpi_ns_valid_root_prefix (
224 * 240 *
225 * FUNCTION: acpi_ns_valid_path_separator 241 * FUNCTION: acpi_ns_valid_path_separator
226 * 242 *
227 * PARAMETERS: Sep - Character to be checked 243 * PARAMETERS: Sep - Character to be checked
228 * 244 *
229 * RETURN: TRUE if a valid path separator 245 * RETURN: TRUE if a valid path separator
230 * 246 *
@@ -232,7 +248,7 @@ acpi_ns_valid_root_prefix (
232 * 248 *
233 ******************************************************************************/ 249 ******************************************************************************/
234 250
235u8 251static u8
236acpi_ns_valid_path_separator ( 252acpi_ns_valid_path_separator (
237 char sep) 253 char sep)
238{ 254{
@@ -245,10 +261,12 @@ acpi_ns_valid_path_separator (
245 * 261 *
246 * FUNCTION: acpi_ns_get_type 262 * FUNCTION: acpi_ns_get_type
247 * 263 *
248 * PARAMETERS: Handle - Parent Node to be examined 264 * PARAMETERS: Node - Parent Node to be examined
249 * 265 *
250 * RETURN: Type field from Node whose handle is passed 266 * RETURN: Type field from Node whose handle is passed
251 * 267 *
268 * DESCRIPTION: Return the type of a Namespace node
269 *
252 ******************************************************************************/ 270 ******************************************************************************/
253 271
254acpi_object_type 272acpi_object_type
@@ -271,11 +289,13 @@ acpi_ns_get_type (
271 * 289 *
272 * FUNCTION: acpi_ns_local 290 * FUNCTION: acpi_ns_local
273 * 291 *
274 * PARAMETERS: Type - A namespace object type 292 * PARAMETERS: Type - A namespace object type
275 * 293 *
276 * RETURN: LOCAL if names must be found locally in objects of the 294 * RETURN: LOCAL if names must be found locally in objects of the
277 * passed type, 0 if enclosing scopes should be searched 295 * passed type, 0 if enclosing scopes should be searched
278 * 296 *
297 * DESCRIPTION: Returns scope rule for the given object type.
298 *
279 ******************************************************************************/ 299 ******************************************************************************/
280 300
281u32 301u32
@@ -303,7 +323,7 @@ acpi_ns_local (
303 * PARAMETERS: Info - Info struct initialized with the 323 * PARAMETERS: Info - Info struct initialized with the
304 * external name pointer. 324 * external name pointer.
305 * 325 *
306 * RETURN: Status 326 * RETURN: None
307 * 327 *
308 * DESCRIPTION: Calculate the length of the internal (AML) namestring 328 * DESCRIPTION: Calculate the length of the internal (AML) namestring
309 * corresponding to the external (ASL) namestring. 329 * corresponding to the external (ASL) namestring.
@@ -551,14 +571,16 @@ acpi_ns_internalize_name (
551 * 571 *
552 * FUNCTION: acpi_ns_externalize_name 572 * FUNCTION: acpi_ns_externalize_name
553 * 573 *
554 * PARAMETERS: *internal_name - Internal representation of name 574 * PARAMETERS: internal_name_length - Lenth of the internal name below
555 * **converted_name - Where to return the resulting 575 * internal_name - Internal representation of name
556 * external representation of name 576 * converted_name_length - Where the length is returned
577 * converted_name - Where the resulting external name
578 * is returned
557 * 579 *
558 * RETURN: Status 580 * RETURN: Status
559 * 581 *
560 * DESCRIPTION: Convert internal name (e.g. 5c 2f 02 5f 50 52 5f 43 50 55 30) 582 * DESCRIPTION: Convert internal name (e.g. 5c 2f 02 5f 50 52 5f 43 50 55 30)
561 * to its external form (e.g. "\_PR_.CPU0") 583 * to its external (printable) form (e.g. "\_PR_.CPU0")
562 * 584 *
563 ******************************************************************************/ 585 ******************************************************************************/
564 586
@@ -717,8 +739,9 @@ acpi_ns_externalize_name (
717 * 739 *
718 * DESCRIPTION: Convert a namespace handle to a real Node 740 * DESCRIPTION: Convert a namespace handle to a real Node
719 * 741 *
720 * Note: Real integer handles allow for more verification 742 * Note: Real integer handles would allow for more verification
721 * and keep all pointers within this subsystem. 743 * and keep all pointers within this subsystem - however this introduces
744 * more (and perhaps unnecessary) overhead.
722 * 745 *
723 ******************************************************************************/ 746 ******************************************************************************/
724 747
@@ -775,7 +798,7 @@ acpi_ns_convert_entry_to_handle (
775 return ((acpi_handle) node); 798 return ((acpi_handle) node);
776 799
777 800
778/* --------------------------------------------------- 801/* Example future implementation ---------------------
779 802
780 if (!Node) 803 if (!Node)
781 { 804 {
@@ -801,12 +824,13 @@ acpi_ns_convert_entry_to_handle (
801 * 824 *
802 * RETURN: none 825 * RETURN: none
803 * 826 *
804 * DESCRIPTION: free memory allocated for table storage. 827 * DESCRIPTION: free memory allocated for namespace and ACPI table storage.
805 * 828 *
806 ******************************************************************************/ 829 ******************************************************************************/
807 830
808void 831void
809acpi_ns_terminate (void) 832acpi_ns_terminate (
833 void)
810{ 834{
811 union acpi_operand_object *obj_desc; 835 union acpi_operand_object *obj_desc;
812 836
@@ -940,7 +964,6 @@ acpi_ns_get_node_by_path (
940 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE); 964 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
941 965
942cleanup: 966cleanup:
943 /* Cleanup */
944 if (internal_path) { 967 if (internal_path) {
945 ACPI_MEM_FREE (internal_path); 968 ACPI_MEM_FREE (internal_path);
946 } 969 }
@@ -950,55 +973,6 @@ cleanup:
950 973
951/******************************************************************************* 974/*******************************************************************************
952 * 975 *
953 * FUNCTION: acpi_ns_find_parent_name
954 *
955 * PARAMETERS: *child_node - Named Obj whose name is to be found
956 *
957 * RETURN: The ACPI name
958 *
959 * DESCRIPTION: Search for the given obj in its parent scope and return the
960 * name segment, or "????" if the parent name can't be found
961 * (which "should not happen").
962 *
963 ******************************************************************************/
964#ifdef ACPI_FUTURE_USAGE
965acpi_name
966acpi_ns_find_parent_name (
967 struct acpi_namespace_node *child_node)
968{
969 struct acpi_namespace_node *parent_node;
970
971
972 ACPI_FUNCTION_TRACE ("ns_find_parent_name");
973
974
975 if (child_node) {
976 /* Valid entry. Get the parent Node */
977
978 parent_node = acpi_ns_get_parent_node (child_node);
979 if (parent_node) {
980 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
981 "Parent of %p [%4.4s] is %p [%4.4s]\n",
982 child_node, acpi_ut_get_node_name (child_node),
983 parent_node, acpi_ut_get_node_name (parent_node)));
984
985 if (parent_node->name.integer) {
986 return_VALUE ((acpi_name) parent_node->name.integer);
987 }
988 }
989
990 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
991 "Unable to find parent of %p (%4.4s)\n",
992 child_node, acpi_ut_get_node_name (child_node)));
993 }
994
995 return_VALUE (ACPI_UNKNOWN_NAME);
996}
997#endif
998
999
1000/*******************************************************************************
1001 *
1002 * FUNCTION: acpi_ns_get_parent_node 976 * FUNCTION: acpi_ns_get_parent_node
1003 * 977 *
1004 * PARAMETERS: Node - Current table entry 978 * PARAMETERS: Node - Current table entry
@@ -1009,7 +983,6 @@ acpi_ns_find_parent_name (
1009 * 983 *
1010 ******************************************************************************/ 984 ******************************************************************************/
1011 985
1012
1013struct acpi_namespace_node * 986struct acpi_namespace_node *
1014acpi_ns_get_parent_node ( 987acpi_ns_get_parent_node (
1015 struct acpi_namespace_node *node) 988 struct acpi_namespace_node *node)
@@ -1030,7 +1003,6 @@ acpi_ns_get_parent_node (
1030 node = node->peer; 1003 node = node->peer;
1031 } 1004 }
1032 1005
1033
1034 return (node->peer); 1006 return (node->peer);
1035} 1007}
1036 1008
@@ -1049,7 +1021,6 @@ acpi_ns_get_parent_node (
1049 * 1021 *
1050 ******************************************************************************/ 1022 ******************************************************************************/
1051 1023
1052
1053struct acpi_namespace_node * 1024struct acpi_namespace_node *
1054acpi_ns_get_next_valid_node ( 1025acpi_ns_get_next_valid_node (
1055 struct acpi_namespace_node *node) 1026 struct acpi_namespace_node *node)
@@ -1067,3 +1038,53 @@ acpi_ns_get_next_valid_node (
1067} 1038}
1068 1039
1069 1040
1041#ifdef ACPI_OBSOLETE_FUNCTIONS
1042/*******************************************************************************
1043 *
1044 * FUNCTION: acpi_ns_find_parent_name
1045 *
1046 * PARAMETERS: *child_node - Named Obj whose name is to be found
1047 *
1048 * RETURN: The ACPI name
1049 *
1050 * DESCRIPTION: Search for the given obj in its parent scope and return the
1051 * name segment, or "????" if the parent name can't be found
1052 * (which "should not happen").
1053 *
1054 ******************************************************************************/
1055
1056acpi_name
1057acpi_ns_find_parent_name (
1058 struct acpi_namespace_node *child_node)
1059{
1060 struct acpi_namespace_node *parent_node;
1061
1062
1063 ACPI_FUNCTION_TRACE ("ns_find_parent_name");
1064
1065
1066 if (child_node) {
1067 /* Valid entry. Get the parent Node */
1068
1069 parent_node = acpi_ns_get_parent_node (child_node);
1070 if (parent_node) {
1071 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
1072 "Parent of %p [%4.4s] is %p [%4.4s]\n",
1073 child_node, acpi_ut_get_node_name (child_node),
1074 parent_node, acpi_ut_get_node_name (parent_node)));
1075
1076 if (parent_node->name.integer) {
1077 return_VALUE ((acpi_name) parent_node->name.integer);
1078 }
1079 }
1080
1081 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
1082 "Unable to find parent of %p (%4.4s)\n",
1083 child_node, acpi_ut_get_node_name (child_node)));
1084 }
1085
1086 return_VALUE (ACPI_UNKNOWN_NAME);
1087}
1088#endif
1089
1090
diff --git a/drivers/acpi/namespace/nswalk.c b/drivers/acpi/namespace/nswalk.c
index 4de2444df300..f9a7277dca6e 100644
--- a/drivers/acpi/namespace/nswalk.c
+++ b/drivers/acpi/namespace/nswalk.c
@@ -56,7 +56,7 @@
56 * 56 *
57 * PARAMETERS: Type - Type of node to be searched for 57 * PARAMETERS: Type - Type of node to be searched for
58 * parent_node - Parent node whose children we are 58 * parent_node - Parent node whose children we are
59 * getting 59 * getting
60 * child_node - Previous child that was found. 60 * child_node - Previous child that was found.
61 * The NEXT child will be returned 61 * The NEXT child will be returned
62 * 62 *
diff --git a/drivers/acpi/namespace/nsxfeval.c b/drivers/acpi/namespace/nsxfeval.c
index 1dc995586cbe..12ea202257fa 100644
--- a/drivers/acpi/namespace/nsxfeval.c
+++ b/drivers/acpi/namespace/nsxfeval.c
@@ -58,11 +58,11 @@
58 * FUNCTION: acpi_evaluate_object_typed 58 * FUNCTION: acpi_evaluate_object_typed
59 * 59 *
60 * PARAMETERS: Handle - Object handle (optional) 60 * PARAMETERS: Handle - Object handle (optional)
61 * *Pathname - Object pathname (optional) 61 * Pathname - Object pathname (optional)
62 * **external_params - List of parameters to pass to method, 62 * external_params - List of parameters to pass to method,
63 * terminated by NULL. May be NULL 63 * terminated by NULL. May be NULL
64 * if no parameters are being passed. 64 * if no parameters are being passed.
65 * *return_buffer - Where to put method's return value (if 65 * return_buffer - Where to put method's return value (if
66 * any). If NULL, no value is returned. 66 * any). If NULL, no value is returned.
67 * return_type - Expected type of return object 67 * return_type - Expected type of return object
68 * 68 *
@@ -73,6 +73,7 @@
73 * be valid (non-null) 73 * be valid (non-null)
74 * 74 *
75 ******************************************************************************/ 75 ******************************************************************************/
76
76#ifdef ACPI_FUTURE_USAGE 77#ifdef ACPI_FUTURE_USAGE
77acpi_status 78acpi_status
78acpi_evaluate_object_typed ( 79acpi_evaluate_object_typed (
@@ -307,7 +308,8 @@ acpi_evaluate_object (
307 if (ACPI_SUCCESS (status)) { 308 if (ACPI_SUCCESS (status)) {
308 /* Validate/Allocate/Clear caller buffer */ 309 /* Validate/Allocate/Clear caller buffer */
309 310
310 status = acpi_ut_initialize_buffer (return_buffer, buffer_space_needed); 311 status = acpi_ut_initialize_buffer (return_buffer,
312 buffer_space_needed);
311 if (ACPI_FAILURE (status)) { 313 if (ACPI_FAILURE (status)) {
312 /* 314 /*
313 * Caller's buffer is too small or a new one can't be allocated 315 * Caller's buffer is too small or a new one can't be allocated
@@ -423,7 +425,8 @@ acpi_walk_namespace (
423 return_ACPI_STATUS (status); 425 return_ACPI_STATUS (status);
424 } 426 }
425 427
426 status = acpi_ns_walk_namespace (type, start_object, max_depth, ACPI_NS_WALK_UNLOCK, 428 status = acpi_ns_walk_namespace (type, start_object, max_depth,
429 ACPI_NS_WALK_UNLOCK,
427 user_function, context, return_value); 430 user_function, context, return_value);
428 431
429 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE); 432 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
@@ -525,7 +528,8 @@ acpi_ns_get_device_callback (
525 } 528 }
526 } 529 }
527 530
528 status = info->user_function (obj_handle, nesting_level, info->context, return_value); 531 status = info->user_function (obj_handle, nesting_level, info->context,
532 return_value);
529 return (status); 533 return (status);
530} 534}
531 535
diff --git a/drivers/acpi/namespace/nsxfname.c b/drivers/acpi/namespace/nsxfname.c
index f2405efd1b9a..8d097914c49a 100644
--- a/drivers/acpi/namespace/nsxfname.c
+++ b/drivers/acpi/namespace/nsxfname.c
@@ -57,9 +57,9 @@
57 * FUNCTION: acpi_get_handle 57 * FUNCTION: acpi_get_handle
58 * 58 *
59 * PARAMETERS: Parent - Object to search under (search scope). 59 * PARAMETERS: Parent - Object to search under (search scope).
60 * path_name - Pointer to an asciiz string containing the 60 * Pathname - Pointer to an asciiz string containing the
61 * name 61 * name
62 * ret_handle - Where the return handle is placed 62 * ret_handle - Where the return handle is returned
63 * 63 *
64 * RETURN: Status 64 * RETURN: Status
65 * 65 *
@@ -220,7 +220,7 @@ EXPORT_SYMBOL(acpi_get_name);
220 * FUNCTION: acpi_get_object_info 220 * FUNCTION: acpi_get_object_info
221 * 221 *
222 * PARAMETERS: Handle - Object Handle 222 * PARAMETERS: Handle - Object Handle
223 * Info - Where the info is returned 223 * Buffer - Where the info is returned
224 * 224 *
225 * RETURN: Status 225 * RETURN: Status
226 * 226 *
diff --git a/drivers/acpi/namespace/nsxfobj.c b/drivers/acpi/namespace/nsxfobj.c
index 19acf32674b9..363e1f6cfb18 100644
--- a/drivers/acpi/namespace/nsxfobj.c
+++ b/drivers/acpi/namespace/nsxfobj.c
@@ -56,7 +56,7 @@
56 * FUNCTION: acpi_get_type 56 * FUNCTION: acpi_get_type
57 * 57 *
58 * PARAMETERS: Handle - Handle of object whose type is desired 58 * PARAMETERS: Handle - Handle of object whose type is desired
59 * *ret_type - Where the type will be placed 59 * ret_type - Where the type will be placed
60 * 60 *
61 * RETURN: Status 61 * RETURN: Status
62 * 62 *
@@ -258,5 +258,5 @@ unlock_and_exit:
258 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE); 258 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
259 return (status); 259 return (status);
260} 260}
261EXPORT_SYMBOL(acpi_get_next_object);
262 261
262EXPORT_SYMBOL(acpi_get_next_object);
diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c
index 5a9128de6226..bdd9f37f8101 100644
--- a/drivers/acpi/osl.c
+++ b/drivers/acpi/osl.c
@@ -71,6 +71,9 @@ EXPORT_SYMBOL(acpi_in_debugger);
71extern char line_buf[80]; 71extern char line_buf[80];
72#endif /*ENABLE_DEBUGGER*/ 72#endif /*ENABLE_DEBUGGER*/
73 73
74int acpi_specific_hotkey_enabled;
75EXPORT_SYMBOL(acpi_specific_hotkey_enabled);
76
74static unsigned int acpi_irq_irq; 77static unsigned int acpi_irq_irq;
75static acpi_osd_handler acpi_irq_handler; 78static acpi_osd_handler acpi_irq_handler;
76static void *acpi_irq_context; 79static void *acpi_irq_context;
@@ -1152,6 +1155,15 @@ acpi_wake_gpes_always_on_setup(char *str)
1152 1155
1153__setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup); 1156__setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup);
1154 1157
1158int __init
1159acpi_hotkey_setup(char *str)
1160{
1161 acpi_specific_hotkey_enabled = TRUE;
1162 return 1;
1163}
1164
1165__setup("acpi_specific_hotkey", acpi_hotkey_setup);
1166
1155/* 1167/*
1156 * max_cstate is defined in the base kernel so modules can 1168 * max_cstate is defined in the base kernel so modules can
1157 * change it w/o depending on the state of the processor module. 1169 * change it w/o depending on the state of the processor module.
diff --git a/drivers/acpi/parser/psargs.c b/drivers/acpi/parser/psargs.c
index b5d98895f6a8..b7ac68cc9e1c 100644
--- a/drivers/acpi/parser/psargs.c
+++ b/drivers/acpi/parser/psargs.c
@@ -50,6 +50,16 @@
50#define _COMPONENT ACPI_PARSER 50#define _COMPONENT ACPI_PARSER
51 ACPI_MODULE_NAME ("psargs") 51 ACPI_MODULE_NAME ("psargs")
52 52
53/* Local prototypes */
54
55static u32
56acpi_ps_get_next_package_length (
57 struct acpi_parse_state *parser_state);
58
59static union acpi_parse_object *
60acpi_ps_get_next_field (
61 struct acpi_parse_state *parser_state);
62
53 63
54/******************************************************************************* 64/*******************************************************************************
55 * 65 *
@@ -64,7 +74,7 @@
64 * 74 *
65 ******************************************************************************/ 75 ******************************************************************************/
66 76
67u32 77static u32
68acpi_ps_get_next_package_length ( 78acpi_ps_get_next_package_length (
69 struct acpi_parse_state *parser_state) 79 struct acpi_parse_state *parser_state)
70{ 80{
@@ -78,7 +88,6 @@ acpi_ps_get_next_package_length (
78 encoded_length = (u32) ACPI_GET8 (parser_state->aml); 88 encoded_length = (u32) ACPI_GET8 (parser_state->aml);
79 parser_state->aml++; 89 parser_state->aml++;
80 90
81
82 switch (encoded_length >> 6) /* bits 6-7 contain encoding scheme */ { 91 switch (encoded_length >> 6) /* bits 6-7 contain encoding scheme */ {
83 case 0: /* 1-byte encoding (bits 0-5) */ 92 case 0: /* 1-byte encoding (bits 0-5) */
84 93
@@ -287,13 +296,14 @@ acpi_ps_get_next_namepath (
287 * parent tree, but don't open a new scope -- we just want to lookup the 296 * parent tree, but don't open a new scope -- we just want to lookup the
288 * object (MUST BE mode EXECUTE to perform upsearch) 297 * object (MUST BE mode EXECUTE to perform upsearch)
289 */ 298 */
290 status = acpi_ns_lookup (&scope_info, path, ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE, 299 status = acpi_ns_lookup (&scope_info, path, ACPI_TYPE_ANY,
291 ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, NULL, &node); 300 ACPI_IMODE_EXECUTE,
301 ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
302 NULL, &node);
292 if (ACPI_SUCCESS (status) && method_call) { 303 if (ACPI_SUCCESS (status) && method_call) {
293 if (node->type == ACPI_TYPE_METHOD) { 304 if (node->type == ACPI_TYPE_METHOD) {
294 /* 305 /* This name is actually a control method invocation */
295 * This name is actually a control method invocation 306
296 */
297 method_desc = acpi_ns_get_attached_object (node); 307 method_desc = acpi_ns_get_attached_object (node);
298 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, 308 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
299 "Control Method - %p Desc %p Path=%p\n", 309 "Control Method - %p Desc %p Path=%p\n",
@@ -360,7 +370,7 @@ acpi_ps_get_next_namepath (
360 /* 370 /*
361 * We got a NOT_FOUND during table load or we encountered 371 * We got a NOT_FOUND during table load or we encountered
362 * a cond_ref_of(x) where the target does not exist. 372 * a cond_ref_of(x) where the target does not exist.
363 * -- either case is ok 373 * Either case is ok
364 */ 374 */
365 status = AE_OK; 375 status = AE_OK;
366 } 376 }
@@ -486,12 +496,13 @@ acpi_ps_get_next_simple_arg (
486 * 496 *
487 ******************************************************************************/ 497 ******************************************************************************/
488 498
489union acpi_parse_object * 499static union acpi_parse_object *
490acpi_ps_get_next_field ( 500acpi_ps_get_next_field (
491 struct acpi_parse_state *parser_state) 501 struct acpi_parse_state *parser_state)
492{ 502{
493 u32 aml_offset = (u32) ACPI_PTR_DIFF (parser_state->aml, 503 u32 aml_offset = (u32)
494 parser_state->aml_start); 504 ACPI_PTR_DIFF (parser_state->aml,
505 parser_state->aml_start);
495 union acpi_parse_object *field; 506 union acpi_parse_object *field;
496 u16 opcode; 507 u16 opcode;
497 u32 name; 508 u32 name;
@@ -500,7 +511,7 @@ acpi_ps_get_next_field (
500 ACPI_FUNCTION_TRACE ("ps_get_next_field"); 511 ACPI_FUNCTION_TRACE ("ps_get_next_field");
501 512
502 513
503 /* determine field type */ 514 /* Determine field type */
504 515
505 switch (ACPI_GET8 (parser_state->aml)) { 516 switch (ACPI_GET8 (parser_state->aml)) {
506 default: 517 default:
@@ -521,7 +532,6 @@ acpi_ps_get_next_field (
521 break; 532 break;
522 } 533 }
523 534
524
525 /* Allocate a new field op */ 535 /* Allocate a new field op */
526 536
527 field = acpi_ps_alloc_op (opcode); 537 field = acpi_ps_alloc_op (opcode);
@@ -582,10 +592,10 @@ acpi_ps_get_next_field (
582 * 592 *
583 * FUNCTION: acpi_ps_get_next_arg 593 * FUNCTION: acpi_ps_get_next_arg
584 * 594 *
585 * PARAMETERS: parser_state - Current parser state object 595 * PARAMETERS: walk_state - Current state
596 * parser_state - Current parser state object
586 * arg_type - The argument type (AML_*_ARG) 597 * arg_type - The argument type (AML_*_ARG)
587 * arg_count - If the argument points to a control method 598 * return_arg - Where the next arg is returned
588 * the method's argument is returned here.
589 * 599 *
590 * RETURN: Status, and an op object containing the next argument. 600 * RETURN: Status, and an op object containing the next argument.
591 * 601 *
@@ -619,7 +629,7 @@ acpi_ps_get_next_arg (
619 case ARGP_NAME: 629 case ARGP_NAME:
620 case ARGP_NAMESTRING: 630 case ARGP_NAMESTRING:
621 631
622 /* constants, strings, and namestrings are all the same size */ 632 /* Constants, strings, and namestrings are all the same size */
623 633
624 arg = acpi_ps_alloc_op (AML_BYTE_OP); 634 arg = acpi_ps_alloc_op (AML_BYTE_OP);
625 if (!arg) { 635 if (!arg) {
@@ -654,7 +664,6 @@ acpi_ps_get_next_arg (
654 else { 664 else {
655 arg = field; 665 arg = field;
656 } 666 }
657
658 prev = field; 667 prev = field;
659 } 668 }
660 669
@@ -677,8 +686,8 @@ acpi_ps_get_next_arg (
677 686
678 /* Fill in bytelist data */ 687 /* Fill in bytelist data */
679 688
680 arg->common.value.size = (u32) ACPI_PTR_DIFF (parser_state->pkg_end, 689 arg->common.value.size = (u32)
681 parser_state->aml); 690 ACPI_PTR_DIFF (parser_state->pkg_end, parser_state->aml);
682 arg->named.data = parser_state->aml; 691 arg->named.data = parser_state->aml;
683 692
684 /* Skip to End of byte data */ 693 /* Skip to End of byte data */
@@ -706,7 +715,7 @@ acpi_ps_get_next_arg (
706 status = acpi_ps_get_next_namepath (walk_state, parser_state, arg, 0); 715 status = acpi_ps_get_next_namepath (walk_state, parser_state, arg, 0);
707 } 716 }
708 else { 717 else {
709 /* single complex argument, nothing returned */ 718 /* Single complex argument, nothing returned */
710 719
711 walk_state->arg_count = 1; 720 walk_state->arg_count = 1;
712 } 721 }
@@ -716,7 +725,7 @@ acpi_ps_get_next_arg (
716 case ARGP_DATAOBJ: 725 case ARGP_DATAOBJ:
717 case ARGP_TERMARG: 726 case ARGP_TERMARG:
718 727
719 /* single complex argument, nothing returned */ 728 /* Single complex argument, nothing returned */
720 729
721 walk_state->arg_count = 1; 730 walk_state->arg_count = 1;
722 break; 731 break;
@@ -727,7 +736,7 @@ acpi_ps_get_next_arg (
727 case ARGP_OBJLIST: 736 case ARGP_OBJLIST:
728 737
729 if (parser_state->aml < parser_state->pkg_end) { 738 if (parser_state->aml < parser_state->pkg_end) {
730 /* non-empty list of variable arguments, nothing returned */ 739 /* Non-empty list of variable arguments, nothing returned */
731 740
732 walk_state->arg_count = ACPI_VAR_ARGS; 741 walk_state->arg_count = ACPI_VAR_ARGS;
733 } 742 }
diff --git a/drivers/acpi/parser/psopcode.c b/drivers/acpi/parser/psopcode.c
index 03e33fedc11a..5744673568c0 100644
--- a/drivers/acpi/parser/psopcode.c
+++ b/drivers/acpi/parser/psopcode.c
@@ -44,6 +44,7 @@
44 44
45#include <acpi/acpi.h> 45#include <acpi/acpi.h>
46#include <acpi/acparser.h> 46#include <acpi/acparser.h>
47#include <acpi/acopcode.h>
47#include <acpi/amlcode.h> 48#include <acpi/amlcode.h>
48 49
49 50
@@ -51,23 +52,6 @@
51 ACPI_MODULE_NAME ("psopcode") 52 ACPI_MODULE_NAME ("psopcode")
52 53
53 54
54#define _UNK 0x6B
55/*
56 * Reserved ASCII characters. Do not use any of these for
57 * internal opcodes, since they are used to differentiate
58 * name strings from AML opcodes
59 */
60#define _ASC 0x6C
61#define _NAM 0x6C
62#define _PFX 0x6D
63#define _UNKNOWN_OPCODE 0x02 /* An example unknown opcode */
64
65#define MAX_EXTENDED_OPCODE 0x88
66#define NUM_EXTENDED_OPCODE (MAX_EXTENDED_OPCODE + 1)
67#define MAX_INTERNAL_OPCODE
68#define NUM_INTERNAL_OPCODE (MAX_INTERNAL_OPCODE + 1)
69
70
71/******************************************************************************* 55/*******************************************************************************
72 * 56 *
73 * NAME: acpi_gbl_aml_op_info 57 * NAME: acpi_gbl_aml_op_info
@@ -79,274 +63,9 @@
79 * 63 *
80 ******************************************************************************/ 64 ******************************************************************************/
81 65
82
83/*
84 * All AML opcodes and the parse-time arguments for each. Used by the AML parser Each list is compressed
85 * into a 32-bit number and stored in the master opcode table at the end of this file.
86 */
87
88
89#define ARGP_ACCESSFIELD_OP ARGP_LIST1 (ARGP_NAMESTRING)
90#define ARGP_ACQUIRE_OP ARGP_LIST2 (ARGP_SUPERNAME, ARGP_WORDDATA)
91#define ARGP_ADD_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
92#define ARGP_ALIAS_OP ARGP_LIST2 (ARGP_NAMESTRING, ARGP_NAME)
93#define ARGP_ARG0 ARG_NONE
94#define ARGP_ARG1 ARG_NONE
95#define ARGP_ARG2 ARG_NONE
96#define ARGP_ARG3 ARG_NONE
97#define ARGP_ARG4 ARG_NONE
98#define ARGP_ARG5 ARG_NONE
99#define ARGP_ARG6 ARG_NONE
100#define ARGP_BANK_FIELD_OP ARGP_LIST6 (ARGP_PKGLENGTH, ARGP_NAMESTRING, ARGP_NAMESTRING,ARGP_TERMARG, ARGP_BYTEDATA, ARGP_FIELDLIST)
101#define ARGP_BIT_AND_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
102#define ARGP_BIT_NAND_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
103#define ARGP_BIT_NOR_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
104#define ARGP_BIT_NOT_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TARGET)
105#define ARGP_BIT_OR_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
106#define ARGP_BIT_XOR_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
107#define ARGP_BREAK_OP ARG_NONE
108#define ARGP_BREAK_POINT_OP ARG_NONE
109#define ARGP_BUFFER_OP ARGP_LIST3 (ARGP_PKGLENGTH, ARGP_TERMARG, ARGP_BYTELIST)
110#define ARGP_BYTE_OP ARGP_LIST1 (ARGP_BYTEDATA)
111#define ARGP_BYTELIST_OP ARGP_LIST1 (ARGP_NAMESTRING)
112#define ARGP_CONCAT_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
113#define ARGP_CONCAT_RES_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
114#define ARGP_COND_REF_OF_OP ARGP_LIST2 (ARGP_SUPERNAME, ARGP_SUPERNAME)
115#define ARGP_CONTINUE_OP ARG_NONE
116#define ARGP_COPY_OP ARGP_LIST2 (ARGP_SUPERNAME, ARGP_SIMPLENAME)
117#define ARGP_CREATE_BIT_FIELD_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_NAME)
118#define ARGP_CREATE_BYTE_FIELD_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_NAME)
119#define ARGP_CREATE_DWORD_FIELD_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_NAME)
120#define ARGP_CREATE_FIELD_OP ARGP_LIST4 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TERMARG, ARGP_NAME)
121#define ARGP_CREATE_QWORD_FIELD_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_NAME)
122#define ARGP_CREATE_WORD_FIELD_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_NAME)
123#define ARGP_DATA_REGION_OP ARGP_LIST4 (ARGP_NAME, ARGP_TERMARG, ARGP_TERMARG, ARGP_TERMARG)
124#define ARGP_DEBUG_OP ARG_NONE
125#define ARGP_DECREMENT_OP ARGP_LIST1 (ARGP_SUPERNAME)
126#define ARGP_DEREF_OF_OP ARGP_LIST1 (ARGP_TERMARG)
127#define ARGP_DEVICE_OP ARGP_LIST3 (ARGP_PKGLENGTH, ARGP_NAME, ARGP_OBJLIST)
128#define ARGP_DIVIDE_OP ARGP_LIST4 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET, ARGP_TARGET)
129#define ARGP_DWORD_OP ARGP_LIST1 (ARGP_DWORDDATA)
130#define ARGP_ELSE_OP ARGP_LIST2 (ARGP_PKGLENGTH, ARGP_TERMLIST)
131#define ARGP_EVENT_OP ARGP_LIST1 (ARGP_NAME)
132#define ARGP_FATAL_OP ARGP_LIST3 (ARGP_BYTEDATA, ARGP_DWORDDATA, ARGP_TERMARG)
133#define ARGP_FIELD_OP ARGP_LIST4 (ARGP_PKGLENGTH, ARGP_NAMESTRING, ARGP_BYTEDATA, ARGP_FIELDLIST)
134#define ARGP_FIND_SET_LEFT_BIT_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TARGET)
135#define ARGP_FIND_SET_RIGHT_BIT_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TARGET)
136#define ARGP_FROM_BCD_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TARGET)
137#define ARGP_IF_OP ARGP_LIST3 (ARGP_PKGLENGTH, ARGP_TERMARG, ARGP_TERMLIST)
138#define ARGP_INCREMENT_OP ARGP_LIST1 (ARGP_SUPERNAME)
139#define ARGP_INDEX_FIELD_OP ARGP_LIST5 (ARGP_PKGLENGTH, ARGP_NAMESTRING, ARGP_NAMESTRING,ARGP_BYTEDATA, ARGP_FIELDLIST)
140#define ARGP_INDEX_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
141#define ARGP_LAND_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TERMARG)
142#define ARGP_LEQUAL_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TERMARG)
143#define ARGP_LGREATER_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TERMARG)
144#define ARGP_LGREATEREQUAL_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TERMARG)
145#define ARGP_LLESS_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TERMARG)
146#define ARGP_LLESSEQUAL_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TERMARG)
147#define ARGP_LNOT_OP ARGP_LIST1 (ARGP_TERMARG)
148#define ARGP_LNOTEQUAL_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TERMARG)
149#define ARGP_LOAD_OP ARGP_LIST2 (ARGP_NAMESTRING, ARGP_SUPERNAME)
150#define ARGP_LOAD_TABLE_OP ARGP_LIST6 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TERMARG, ARGP_TERMARG, ARGP_TERMARG, ARGP_TERMARG)
151#define ARGP_LOCAL0 ARG_NONE
152#define ARGP_LOCAL1 ARG_NONE
153#define ARGP_LOCAL2 ARG_NONE
154#define ARGP_LOCAL3 ARG_NONE
155#define ARGP_LOCAL4 ARG_NONE
156#define ARGP_LOCAL5 ARG_NONE
157#define ARGP_LOCAL6 ARG_NONE
158#define ARGP_LOCAL7 ARG_NONE
159#define ARGP_LOR_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TERMARG)
160#define ARGP_MATCH_OP ARGP_LIST6 (ARGP_TERMARG, ARGP_BYTEDATA, ARGP_TERMARG, ARGP_BYTEDATA, ARGP_TERMARG, ARGP_TERMARG)
161#define ARGP_METHOD_OP ARGP_LIST4 (ARGP_PKGLENGTH, ARGP_NAME, ARGP_BYTEDATA, ARGP_TERMLIST)
162#define ARGP_METHODCALL_OP ARGP_LIST1 (ARGP_NAMESTRING)
163#define ARGP_MID_OP ARGP_LIST4 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
164#define ARGP_MOD_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
165#define ARGP_MULTIPLY_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
166#define ARGP_MUTEX_OP ARGP_LIST2 (ARGP_NAME, ARGP_BYTEDATA)
167#define ARGP_NAME_OP ARGP_LIST2 (ARGP_NAME, ARGP_DATAOBJ)
168#define ARGP_NAMEDFIELD_OP ARGP_LIST1 (ARGP_NAMESTRING)
169#define ARGP_NAMEPATH_OP ARGP_LIST1 (ARGP_NAMESTRING)
170#define ARGP_NOOP_OP ARG_NONE
171#define ARGP_NOTIFY_OP ARGP_LIST2 (ARGP_SUPERNAME, ARGP_TERMARG)
172#define ARGP_ONE_OP ARG_NONE
173#define ARGP_ONES_OP ARG_NONE
174#define ARGP_PACKAGE_OP ARGP_LIST3 (ARGP_PKGLENGTH, ARGP_BYTEDATA, ARGP_DATAOBJLIST)
175#define ARGP_POWER_RES_OP ARGP_LIST5 (ARGP_PKGLENGTH, ARGP_NAME, ARGP_BYTEDATA, ARGP_WORDDATA, ARGP_OBJLIST)
176#define ARGP_PROCESSOR_OP ARGP_LIST6 (ARGP_PKGLENGTH, ARGP_NAME, ARGP_BYTEDATA, ARGP_DWORDDATA, ARGP_BYTEDATA, ARGP_OBJLIST)
177#define ARGP_QWORD_OP ARGP_LIST1 (ARGP_QWORDDATA)
178#define ARGP_REF_OF_OP ARGP_LIST1 (ARGP_SUPERNAME)
179#define ARGP_REGION_OP ARGP_LIST4 (ARGP_NAME, ARGP_BYTEDATA, ARGP_TERMARG, ARGP_TERMARG)
180#define ARGP_RELEASE_OP ARGP_LIST1 (ARGP_SUPERNAME)
181#define ARGP_RESERVEDFIELD_OP ARGP_LIST1 (ARGP_NAMESTRING)
182#define ARGP_RESET_OP ARGP_LIST1 (ARGP_SUPERNAME)
183#define ARGP_RETURN_OP ARGP_LIST1 (ARGP_TERMARG)
184#define ARGP_REVISION_OP ARG_NONE
185#define ARGP_SCOPE_OP ARGP_LIST3 (ARGP_PKGLENGTH, ARGP_NAME, ARGP_TERMLIST)
186#define ARGP_SHIFT_LEFT_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
187#define ARGP_SHIFT_RIGHT_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
188#define ARGP_SIGNAL_OP ARGP_LIST1 (ARGP_SUPERNAME)
189#define ARGP_SIZE_OF_OP ARGP_LIST1 (ARGP_SUPERNAME)
190#define ARGP_SLEEP_OP ARGP_LIST1 (ARGP_TERMARG)
191#define ARGP_STALL_OP ARGP_LIST1 (ARGP_TERMARG)
192#define ARGP_STATICSTRING_OP ARGP_LIST1 (ARGP_NAMESTRING)
193#define ARGP_STORE_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_SUPERNAME)
194#define ARGP_STRING_OP ARGP_LIST1 (ARGP_CHARLIST)
195#define ARGP_SUBTRACT_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
196#define ARGP_THERMAL_ZONE_OP ARGP_LIST3 (ARGP_PKGLENGTH, ARGP_NAME, ARGP_OBJLIST)
197#define ARGP_TIMER_OP ARG_NONE
198#define ARGP_TO_BCD_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TARGET)
199#define ARGP_TO_BUFFER_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TARGET)
200#define ARGP_TO_DEC_STR_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TARGET)
201#define ARGP_TO_HEX_STR_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TARGET)
202#define ARGP_TO_INTEGER_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TARGET)
203#define ARGP_TO_STRING_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
204#define ARGP_TYPE_OP ARGP_LIST1 (ARGP_SUPERNAME)
205#define ARGP_UNLOAD_OP ARGP_LIST1 (ARGP_SUPERNAME)
206#define ARGP_VAR_PACKAGE_OP ARGP_LIST3 (ARGP_PKGLENGTH, ARGP_TERMARG, ARGP_DATAOBJLIST)
207#define ARGP_WAIT_OP ARGP_LIST2 (ARGP_SUPERNAME, ARGP_TERMARG)
208#define ARGP_WHILE_OP ARGP_LIST3 (ARGP_PKGLENGTH, ARGP_TERMARG, ARGP_TERMLIST)
209#define ARGP_WORD_OP ARGP_LIST1 (ARGP_WORDDATA)
210#define ARGP_ZERO_OP ARG_NONE
211
212
213/*
214 * All AML opcodes and the runtime arguments for each. Used by the AML interpreter Each list is compressed
215 * into a 32-bit number and stored in the master opcode table at the end of this file.
216 *
217 * (Used by prep_operands procedure and the ASL Compiler)
218 */
219
220
221#define ARGI_ACCESSFIELD_OP ARGI_INVALID_OPCODE
222#define ARGI_ACQUIRE_OP ARGI_LIST2 (ARGI_MUTEX, ARGI_INTEGER)
223#define ARGI_ADD_OP ARGI_LIST3 (ARGI_INTEGER, ARGI_INTEGER, ARGI_TARGETREF)
224#define ARGI_ALIAS_OP ARGI_INVALID_OPCODE
225#define ARGI_ARG0 ARG_NONE
226#define ARGI_ARG1 ARG_NONE
227#define ARGI_ARG2 ARG_NONE
228#define ARGI_ARG3 ARG_NONE
229#define ARGI_ARG4 ARG_NONE
230#define ARGI_ARG5 ARG_NONE
231#define ARGI_ARG6 ARG_NONE
232#define ARGI_BANK_FIELD_OP ARGI_INVALID_OPCODE
233#define ARGI_BIT_AND_OP ARGI_LIST3 (ARGI_INTEGER, ARGI_INTEGER, ARGI_TARGETREF)
234#define ARGI_BIT_NAND_OP ARGI_LIST3 (ARGI_INTEGER, ARGI_INTEGER, ARGI_TARGETREF)
235#define ARGI_BIT_NOR_OP ARGI_LIST3 (ARGI_INTEGER, ARGI_INTEGER, ARGI_TARGETREF)
236#define ARGI_BIT_NOT_OP ARGI_LIST2 (ARGI_INTEGER, ARGI_TARGETREF)
237#define ARGI_BIT_OR_OP ARGI_LIST3 (ARGI_INTEGER, ARGI_INTEGER, ARGI_TARGETREF)
238#define ARGI_BIT_XOR_OP ARGI_LIST3 (ARGI_INTEGER, ARGI_INTEGER, ARGI_TARGETREF)
239#define ARGI_BREAK_OP ARG_NONE
240#define ARGI_BREAK_POINT_OP ARG_NONE
241#define ARGI_BUFFER_OP ARGI_LIST1 (ARGI_INTEGER)
242#define ARGI_BYTE_OP ARGI_INVALID_OPCODE
243#define ARGI_BYTELIST_OP ARGI_INVALID_OPCODE
244#define ARGI_CONCAT_OP ARGI_LIST3 (ARGI_COMPUTEDATA,ARGI_COMPUTEDATA, ARGI_TARGETREF)
245#define ARGI_CONCAT_RES_OP ARGI_LIST3 (ARGI_BUFFER, ARGI_BUFFER, ARGI_TARGETREF)
246#define ARGI_COND_REF_OF_OP ARGI_LIST2 (ARGI_OBJECT_REF, ARGI_TARGETREF)
247#define ARGI_CONTINUE_OP ARGI_INVALID_OPCODE
248#define ARGI_COPY_OP ARGI_LIST2 (ARGI_ANYTYPE, ARGI_SIMPLE_TARGET)
249#define ARGI_CREATE_BIT_FIELD_OP ARGI_LIST3 (ARGI_BUFFER, ARGI_INTEGER, ARGI_REFERENCE)
250#define ARGI_CREATE_BYTE_FIELD_OP ARGI_LIST3 (ARGI_BUFFER, ARGI_INTEGER, ARGI_REFERENCE)
251#define ARGI_CREATE_DWORD_FIELD_OP ARGI_LIST3 (ARGI_BUFFER, ARGI_INTEGER, ARGI_REFERENCE)
252#define ARGI_CREATE_FIELD_OP ARGI_LIST4 (ARGI_BUFFER, ARGI_INTEGER, ARGI_INTEGER, ARGI_REFERENCE)
253#define ARGI_CREATE_QWORD_FIELD_OP ARGI_LIST3 (ARGI_BUFFER, ARGI_INTEGER, ARGI_REFERENCE)
254#define ARGI_CREATE_WORD_FIELD_OP ARGI_LIST3 (ARGI_BUFFER, ARGI_INTEGER, ARGI_REFERENCE)
255#define ARGI_DATA_REGION_OP ARGI_LIST3 (ARGI_STRING, ARGI_STRING, ARGI_STRING)
256#define ARGI_DEBUG_OP ARG_NONE
257#define ARGI_DECREMENT_OP ARGI_LIST1 (ARGI_INTEGER_REF)
258#define ARGI_DEREF_OF_OP ARGI_LIST1 (ARGI_REF_OR_STRING)
259#define ARGI_DEVICE_OP ARGI_INVALID_OPCODE
260#define ARGI_DIVIDE_OP ARGI_LIST4 (ARGI_INTEGER, ARGI_INTEGER, ARGI_TARGETREF, ARGI_TARGETREF)
261#define ARGI_DWORD_OP ARGI_INVALID_OPCODE
262#define ARGI_ELSE_OP ARGI_INVALID_OPCODE
263#define ARGI_EVENT_OP ARGI_INVALID_OPCODE
264#define ARGI_FATAL_OP ARGI_LIST3 (ARGI_INTEGER, ARGI_INTEGER, ARGI_INTEGER)
265#define ARGI_FIELD_OP ARGI_INVALID_OPCODE
266#define ARGI_FIND_SET_LEFT_BIT_OP ARGI_LIST2 (ARGI_INTEGER, ARGI_TARGETREF)
267#define ARGI_FIND_SET_RIGHT_BIT_OP ARGI_LIST2 (ARGI_INTEGER, ARGI_TARGETREF)
268#define ARGI_FROM_BCD_OP ARGI_LIST2 (ARGI_INTEGER, ARGI_TARGETREF)
269#define ARGI_IF_OP ARGI_INVALID_OPCODE
270#define ARGI_INCREMENT_OP ARGI_LIST1 (ARGI_INTEGER_REF)
271#define ARGI_INDEX_FIELD_OP ARGI_INVALID_OPCODE
272#define ARGI_INDEX_OP ARGI_LIST3 (ARGI_COMPLEXOBJ, ARGI_INTEGER, ARGI_TARGETREF)
273#define ARGI_LAND_OP ARGI_LIST2 (ARGI_INTEGER, ARGI_INTEGER)
274#define ARGI_LEQUAL_OP ARGI_LIST2 (ARGI_COMPUTEDATA,ARGI_COMPUTEDATA)
275#define ARGI_LGREATER_OP ARGI_LIST2 (ARGI_COMPUTEDATA,ARGI_COMPUTEDATA)
276#define ARGI_LGREATEREQUAL_OP ARGI_INVALID_OPCODE
277#define ARGI_LLESS_OP ARGI_LIST2 (ARGI_COMPUTEDATA,ARGI_COMPUTEDATA)
278#define ARGI_LLESSEQUAL_OP ARGI_INVALID_OPCODE
279#define ARGI_LNOT_OP ARGI_LIST1 (ARGI_INTEGER)
280#define ARGI_LNOTEQUAL_OP ARGI_INVALID_OPCODE
281#define ARGI_LOAD_OP ARGI_LIST2 (ARGI_REGION_OR_FIELD,ARGI_TARGETREF)
282#define ARGI_LOAD_TABLE_OP ARGI_LIST6 (ARGI_STRING, ARGI_STRING, ARGI_STRING, ARGI_STRING, ARGI_STRING, ARGI_ANYTYPE)
283#define ARGI_LOCAL0 ARG_NONE
284#define ARGI_LOCAL1 ARG_NONE
285#define ARGI_LOCAL2 ARG_NONE
286#define ARGI_LOCAL3 ARG_NONE
287#define ARGI_LOCAL4 ARG_NONE
288#define ARGI_LOCAL5 ARG_NONE
289#define ARGI_LOCAL6 ARG_NONE
290#define ARGI_LOCAL7 ARG_NONE
291#define ARGI_LOR_OP ARGI_LIST2 (ARGI_INTEGER, ARGI_INTEGER)
292#define ARGI_MATCH_OP ARGI_LIST6 (ARGI_PACKAGE, ARGI_INTEGER, ARGI_COMPUTEDATA, ARGI_INTEGER,ARGI_COMPUTEDATA,ARGI_INTEGER)
293#define ARGI_METHOD_OP ARGI_INVALID_OPCODE
294#define ARGI_METHODCALL_OP ARGI_INVALID_OPCODE
295#define ARGI_MID_OP ARGI_LIST4 (ARGI_BUFFER_OR_STRING,ARGI_INTEGER, ARGI_INTEGER, ARGI_TARGETREF)
296#define ARGI_MOD_OP ARGI_LIST3 (ARGI_INTEGER, ARGI_INTEGER, ARGI_TARGETREF)
297#define ARGI_MULTIPLY_OP ARGI_LIST3 (ARGI_INTEGER, ARGI_INTEGER, ARGI_TARGETREF)
298#define ARGI_MUTEX_OP ARGI_INVALID_OPCODE
299#define ARGI_NAME_OP ARGI_INVALID_OPCODE
300#define ARGI_NAMEDFIELD_OP ARGI_INVALID_OPCODE
301#define ARGI_NAMEPATH_OP ARGI_INVALID_OPCODE
302#define ARGI_NOOP_OP ARG_NONE
303#define ARGI_NOTIFY_OP ARGI_LIST2 (ARGI_DEVICE_REF, ARGI_INTEGER)
304#define ARGI_ONE_OP ARG_NONE
305#define ARGI_ONES_OP ARG_NONE
306#define ARGI_PACKAGE_OP ARGI_LIST1 (ARGI_INTEGER)
307#define ARGI_POWER_RES_OP ARGI_INVALID_OPCODE
308#define ARGI_PROCESSOR_OP ARGI_INVALID_OPCODE
309#define ARGI_QWORD_OP ARGI_INVALID_OPCODE
310#define ARGI_REF_OF_OP ARGI_LIST1 (ARGI_OBJECT_REF)
311#define ARGI_REGION_OP ARGI_LIST2 (ARGI_INTEGER, ARGI_INTEGER)
312#define ARGI_RELEASE_OP ARGI_LIST1 (ARGI_MUTEX)
313#define ARGI_RESERVEDFIELD_OP ARGI_INVALID_OPCODE
314#define ARGI_RESET_OP ARGI_LIST1 (ARGI_EVENT)
315#define ARGI_RETURN_OP ARGI_INVALID_OPCODE
316#define ARGI_REVISION_OP ARG_NONE
317#define ARGI_SCOPE_OP ARGI_INVALID_OPCODE
318#define ARGI_SHIFT_LEFT_OP ARGI_LIST3 (ARGI_INTEGER, ARGI_INTEGER, ARGI_TARGETREF)
319#define ARGI_SHIFT_RIGHT_OP ARGI_LIST3 (ARGI_INTEGER, ARGI_INTEGER, ARGI_TARGETREF)
320#define ARGI_SIGNAL_OP ARGI_LIST1 (ARGI_EVENT)
321#define ARGI_SIZE_OF_OP ARGI_LIST1 (ARGI_DATAOBJECT)
322#define ARGI_SLEEP_OP ARGI_LIST1 (ARGI_INTEGER)
323#define ARGI_STALL_OP ARGI_LIST1 (ARGI_INTEGER)
324#define ARGI_STATICSTRING_OP ARGI_INVALID_OPCODE
325#define ARGI_STORE_OP ARGI_LIST2 (ARGI_DATAREFOBJ, ARGI_TARGETREF)
326#define ARGI_STRING_OP ARGI_INVALID_OPCODE
327#define ARGI_SUBTRACT_OP ARGI_LIST3 (ARGI_INTEGER, ARGI_INTEGER, ARGI_TARGETREF)
328#define ARGI_THERMAL_ZONE_OP ARGI_INVALID_OPCODE
329#define ARGI_TIMER_OP ARG_NONE
330#define ARGI_TO_BCD_OP ARGI_LIST2 (ARGI_INTEGER, ARGI_FIXED_TARGET)
331#define ARGI_TO_BUFFER_OP ARGI_LIST2 (ARGI_COMPUTEDATA,ARGI_FIXED_TARGET)
332#define ARGI_TO_DEC_STR_OP ARGI_LIST2 (ARGI_COMPUTEDATA,ARGI_FIXED_TARGET)
333#define ARGI_TO_HEX_STR_OP ARGI_LIST2 (ARGI_COMPUTEDATA,ARGI_FIXED_TARGET)
334#define ARGI_TO_INTEGER_OP ARGI_LIST2 (ARGI_COMPUTEDATA,ARGI_FIXED_TARGET)
335#define ARGI_TO_STRING_OP ARGI_LIST3 (ARGI_BUFFER, ARGI_INTEGER, ARGI_FIXED_TARGET)
336#define ARGI_TYPE_OP ARGI_LIST1 (ARGI_ANYTYPE)
337#define ARGI_UNLOAD_OP ARGI_LIST1 (ARGI_DDBHANDLE)
338#define ARGI_VAR_PACKAGE_OP ARGI_LIST1 (ARGI_INTEGER)
339#define ARGI_WAIT_OP ARGI_LIST2 (ARGI_EVENT, ARGI_INTEGER)
340#define ARGI_WHILE_OP ARGI_INVALID_OPCODE
341#define ARGI_WORD_OP ARGI_INVALID_OPCODE
342#define ARGI_ZERO_OP ARG_NONE
343
344
345/* 66/*
346 * Summary of opcode types/flags 67 * Summary of opcode types/flags
347 */ 68 *
348
349/******************************************************************************
350 69
351 Opcodes that have associated namespace objects (AML_NSOBJECT flag) 70 Opcodes that have associated namespace objects (AML_NSOBJECT flag)
352 71
@@ -460,14 +179,13 @@
460 AML_CREATE_DWORD_FIELD_OP 179 AML_CREATE_DWORD_FIELD_OP
461 AML_CREATE_QWORD_FIELD_OP 180 AML_CREATE_QWORD_FIELD_OP
462 181
463******************************************************************************/ 182 ******************************************************************************/
464 183
465 184
466/* 185/*
467 * Master Opcode information table. A summary of everything we know about each opcode, all in one place. 186 * Master Opcode information table. A summary of everything we know about each
187 * opcode, all in one place.
468 */ 188 */
469
470
471const struct acpi_opcode_info acpi_gbl_aml_op_info[AML_NUM_OPCODES] = 189const struct acpi_opcode_info acpi_gbl_aml_op_info[AML_NUM_OPCODES] =
472{ 190{
473/*! [Begin] no source code translation */ 191/*! [Begin] no source code translation */
@@ -693,8 +411,7 @@ static const u8 acpi_gbl_long_op_index[NUM_EXTENDED_OPCODE] =
693 * 411 *
694 * PARAMETERS: Opcode - The AML opcode 412 * PARAMETERS: Opcode - The AML opcode
695 * 413 *
696 * RETURN: A pointer to the info about the opcode. NULL if the opcode was 414 * RETURN: A pointer to the info about the opcode.
697 * not found in the table.
698 * 415 *
699 * DESCRIPTION: Find AML opcode description based on the opcode. 416 * DESCRIPTION: Find AML opcode description based on the opcode.
700 * NOTE: This procedure must ALWAYS return a valid pointer! 417 * NOTE: This procedure must ALWAYS return a valid pointer!
@@ -731,7 +448,8 @@ acpi_ps_get_opcode_info (
731 448
732 default: 449 default:
733 450
734 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown AML opcode [%4.4X]\n", opcode)); 451 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
452 "Unknown AML opcode [%4.4X]\n", opcode));
735 break; 453 break;
736 } 454 }
737 455
diff --git a/drivers/acpi/parser/psparse.c b/drivers/acpi/parser/psparse.c
index e79edb53cb3b..bbfdc1a58c27 100644
--- a/drivers/acpi/parser/psparse.c
+++ b/drivers/acpi/parser/psparse.c
@@ -64,6 +64,23 @@
64 64
65static u32 acpi_gbl_depth = 0; 65static u32 acpi_gbl_depth = 0;
66 66
67/* Local prototypes */
68
69static void
70acpi_ps_complete_this_op (
71 struct acpi_walk_state *walk_state,
72 union acpi_parse_object *op);
73
74static acpi_status
75acpi_ps_next_parse_state (
76 struct acpi_walk_state *walk_state,
77 union acpi_parse_object *op,
78 acpi_status callback_status);
79
80static acpi_status
81acpi_ps_parse_loop (
82 struct acpi_walk_state *walk_state);
83
67 84
68/******************************************************************************* 85/*******************************************************************************
69 * 86 *
@@ -100,7 +117,7 @@ acpi_ps_get_opcode_size (
100 * 117 *
101 * PARAMETERS: parser_state - A parser state object 118 * PARAMETERS: parser_state - A parser state object
102 * 119 *
103 * RETURN: Status 120 * RETURN: Next AML opcode
104 * 121 *
105 * DESCRIPTION: Get next AML opcode (without incrementing AML pointer) 122 * DESCRIPTION: Get next AML opcode (without incrementing AML pointer)
106 * 123 *
@@ -117,7 +134,6 @@ acpi_ps_peek_opcode (
117 aml = parser_state->aml; 134 aml = parser_state->aml;
118 opcode = (u16) ACPI_GET8 (aml); 135 opcode = (u16) ACPI_GET8 (aml);
119 136
120
121 if (opcode == AML_EXTOP) { 137 if (opcode == AML_EXTOP) {
122 /* Extended opcode */ 138 /* Extended opcode */
123 139
@@ -142,7 +158,7 @@ acpi_ps_peek_opcode (
142 * 158 *
143 ******************************************************************************/ 159 ******************************************************************************/
144 160
145void 161static void
146acpi_ps_complete_this_op ( 162acpi_ps_complete_this_op (
147 struct acpi_walk_state *walk_state, 163 struct acpi_walk_state *walk_state,
148 union acpi_parse_object *op) 164 union acpi_parse_object *op)
@@ -272,7 +288,6 @@ acpi_ps_complete_this_op (
272 next = NULL; 288 next = NULL;
273 } 289 }
274 } 290 }
275
276 prev = next; 291 prev = next;
277 } 292 }
278 } 293 }
@@ -280,7 +295,7 @@ acpi_ps_complete_this_op (
280 295
281cleanup: 296cleanup:
282 297
283 /* Now we can actually delete the subtree rooted at op */ 298 /* Now we can actually delete the subtree rooted at Op */
284 299
285 acpi_ps_delete_parse_tree (op); 300 acpi_ps_delete_parse_tree (op);
286 return_VOID; 301 return_VOID;
@@ -291,7 +306,9 @@ cleanup:
291 * 306 *
292 * FUNCTION: acpi_ps_next_parse_state 307 * FUNCTION: acpi_ps_next_parse_state
293 * 308 *
294 * PARAMETERS: parser_state - Current parser state object 309 * PARAMETERS: walk_state - Current state
310 * Op - Current parse op
311 * callback_status - Status from previous operation
295 * 312 *
296 * RETURN: Status 313 * RETURN: Status
297 * 314 *
@@ -300,7 +317,7 @@ cleanup:
300 * 317 *
301 ******************************************************************************/ 318 ******************************************************************************/
302 319
303acpi_status 320static acpi_status
304acpi_ps_next_parse_state ( 321acpi_ps_next_parse_state (
305 struct acpi_walk_state *walk_state, 322 struct acpi_walk_state *walk_state,
306 union acpi_parse_object *op, 323 union acpi_parse_object *op,
@@ -382,9 +399,8 @@ acpi_ps_next_parse_state (
382 399
383 case AE_CTRL_TRANSFER: 400 case AE_CTRL_TRANSFER:
384 401
385 /* 402 /* A method call (invocation) -- transfer control */
386 * A method call (invocation) -- transfer control 403
387 */
388 status = AE_CTRL_TRANSFER; 404 status = AE_CTRL_TRANSFER;
389 walk_state->prev_op = op; 405 walk_state->prev_op = op;
390 walk_state->method_call_op = op; 406 walk_state->method_call_op = op;
@@ -397,6 +413,7 @@ acpi_ps_next_parse_state (
397 413
398 414
399 default: 415 default:
416
400 status = callback_status; 417 status = callback_status;
401 if ((callback_status & AE_CODE_MASK) == AE_CODE_CONTROL) { 418 if ((callback_status & AE_CODE_MASK) == AE_CODE_CONTROL) {
402 status = AE_OK; 419 status = AE_OK;
@@ -412,7 +429,7 @@ acpi_ps_next_parse_state (
412 * 429 *
413 * FUNCTION: acpi_ps_parse_loop 430 * FUNCTION: acpi_ps_parse_loop
414 * 431 *
415 * PARAMETERS: parser_state - Current parser state object 432 * PARAMETERS: walk_state - Current state
416 * 433 *
417 * RETURN: Status 434 * RETURN: Status
418 * 435 *
@@ -421,7 +438,7 @@ acpi_ps_next_parse_state (
421 * 438 *
422 ******************************************************************************/ 439 ******************************************************************************/
423 440
424acpi_status 441static acpi_status
425acpi_ps_parse_loop ( 442acpi_ps_parse_loop (
426 struct acpi_walk_state *walk_state) 443 struct acpi_walk_state *walk_state)
427{ 444{
@@ -443,6 +460,7 @@ acpi_ps_parse_loop (
443 walk_state->arg_types = 0; 460 walk_state->arg_types = 0;
444 461
445#if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY)) 462#if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
463
446 if (walk_state->walk_type & ACPI_WALK_METHOD_RESTART) { 464 if (walk_state->walk_type & ACPI_WALK_METHOD_RESTART) {
447 /* We are restarting a preempted control method */ 465 /* We are restarting a preempted control method */
448 466
@@ -471,7 +489,8 @@ acpi_ps_parse_loop (
471 acpi_format_exception (status))); 489 acpi_format_exception (status)));
472 490
473 } 491 }
474 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "get_predicate Failed, %s\n", 492 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
493 "get_predicate Failed, %s\n",
475 acpi_format_exception (status))); 494 acpi_format_exception (status)));
476 return_ACPI_STATUS (status); 495 return_ACPI_STATUS (status);
477 } 496 }
@@ -492,16 +511,15 @@ acpi_ps_parse_loop (
492 } 511 }
493#endif 512#endif
494 513
495 /* 514 /* Iterative parsing loop, while there is more AML to process: */
496 * Iterative parsing loop, while there is more aml to process: 515
497 */
498 while ((parser_state->aml < parser_state->aml_end) || (op)) { 516 while ((parser_state->aml < parser_state->aml_end) || (op)) {
499 aml_op_start = parser_state->aml; 517 aml_op_start = parser_state->aml;
500 if (!op) { 518 if (!op) {
501 /* Get the next opcode from the AML stream */ 519 /* Get the next opcode from the AML stream */
502 520
503 walk_state->aml_offset = (u32) ACPI_PTR_DIFF (parser_state->aml, 521 walk_state->aml_offset = (u32) ACPI_PTR_DIFF (parser_state->aml,
504 parser_state->aml_start); 522 parser_state->aml_start);
505 walk_state->opcode = acpi_ps_peek_opcode (parser_state); 523 walk_state->opcode = acpi_ps_peek_opcode (parser_state);
506 524
507 /* 525 /*
@@ -578,8 +596,10 @@ acpi_ps_parse_loop (
578 INCREMENT_ARG_LIST (walk_state->arg_types); 596 INCREMENT_ARG_LIST (walk_state->arg_types);
579 } 597 }
580 598
581 /* Make sure that we found a NAME and didn't run out of arguments */ 599 /*
582 600 * Make sure that we found a NAME and didn't run out of
601 * arguments
602 */
583 if (!GET_CURRENT_ARG_TYPE (walk_state->arg_types)) { 603 if (!GET_CURRENT_ARG_TYPE (walk_state->arg_types)) {
584 status = AE_AML_NO_OPERAND; 604 status = AE_AML_NO_OPERAND;
585 goto close_this_op; 605 goto close_this_op;
@@ -597,12 +617,13 @@ acpi_ps_parse_loop (
597 617
598 status = walk_state->descending_callback (walk_state, &op); 618 status = walk_state->descending_callback (walk_state, &op);
599 if (ACPI_FAILURE (status)) { 619 if (ACPI_FAILURE (status)) {
600 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "During name lookup/catalog, %s\n", 620 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
601 acpi_format_exception (status))); 621 "During name lookup/catalog, %s\n",
622 acpi_format_exception (status)));
602 goto close_this_op; 623 goto close_this_op;
603 } 624 }
604 625
605 if (op == NULL) { 626 if (!op) {
606 continue; 627 continue;
607 } 628 }
608 629
@@ -659,7 +680,7 @@ acpi_ps_parse_loop (
659 680
660 if ((walk_state->descending_callback != NULL)) { 681 if ((walk_state->descending_callback != NULL)) {
661 /* 682 /*
662 * Find the object. This will either insert the object into 683 * Find the object. This will either insert the object into
663 * the namespace or simply look it up 684 * the namespace or simply look it up
664 */ 685 */
665 walk_state->op = op; 686 walk_state->op = op;
@@ -688,11 +709,15 @@ acpi_ps_parse_loop (
688 } 709 }
689 710
690 711
691 /* Start arg_count at zero because we don't know if there are any args yet */ 712 /*
692 713 * Start arg_count at zero because we don't know if there are
714 * any args yet
715 */
693 walk_state->arg_count = 0; 716 walk_state->arg_count = 0;
694 717
695 if (walk_state->arg_types) /* Are there any arguments that must be processed? */ { 718 /* Are there any arguments that must be processed? */
719
720 if (walk_state->arg_types) {
696 /* Get arguments */ 721 /* Get arguments */
697 722
698 switch (op->common.aml_opcode) { 723 switch (op->common.aml_opcode) {
@@ -720,14 +745,18 @@ acpi_ps_parse_loop (
720 745
721 default: 746 default:
722 747
723 /* Op is not a constant or string, append each argument to the Op */ 748 /*
724 749 * Op is not a constant or string, append each argument
750 * to the Op
751 */
725 while (GET_CURRENT_ARG_TYPE (walk_state->arg_types) && 752 while (GET_CURRENT_ARG_TYPE (walk_state->arg_types) &&
726 !walk_state->arg_count) { 753 !walk_state->arg_count) {
727 walk_state->aml_offset = (u32) ACPI_PTR_DIFF (parser_state->aml, 754 walk_state->aml_offset = (u32)
728 parser_state->aml_start); 755 ACPI_PTR_DIFF (parser_state->aml, parser_state->aml_start);
756
729 status = acpi_ps_get_next_arg (walk_state, parser_state, 757 status = acpi_ps_get_next_arg (walk_state, parser_state,
730 GET_CURRENT_ARG_TYPE (walk_state->arg_types), &arg); 758 GET_CURRENT_ARG_TYPE (walk_state->arg_types),
759 &arg);
731 if (ACPI_FAILURE (status)) { 760 if (ACPI_FAILURE (status)) {
732 goto close_this_op; 761 goto close_this_op;
733 } 762 }
@@ -752,7 +781,8 @@ acpi_ps_parse_loop (
752 * Save the length and address of the body 781 * Save the length and address of the body
753 */ 782 */
754 op->named.data = parser_state->aml; 783 op->named.data = parser_state->aml;
755 op->named.length = (u32) (parser_state->pkg_end - parser_state->aml); 784 op->named.length = (u32) (parser_state->pkg_end -
785 parser_state->aml);
756 786
757 /* Skip body of method */ 787 /* Skip body of method */
758 788
@@ -773,7 +803,8 @@ acpi_ps_parse_loop (
773 * to parse them correctly. 803 * to parse them correctly.
774 */ 804 */
775 op->named.data = aml_op_start; 805 op->named.data = aml_op_start;
776 op->named.length = (u32) (parser_state->pkg_end - aml_op_start); 806 op->named.length = (u32) (parser_state->pkg_end -
807 aml_op_start);
777 808
778 /* Skip body */ 809 /* Skip body */
779 810
@@ -785,7 +816,8 @@ acpi_ps_parse_loop (
785 case AML_WHILE_OP: 816 case AML_WHILE_OP:
786 817
787 if (walk_state->control_state) { 818 if (walk_state->control_state) {
788 walk_state->control_state->control.package_end = parser_state->pkg_end; 819 walk_state->control_state->control.package_end =
820 parser_state->pkg_end;
789 } 821 }
790 break; 822 break;
791 823
@@ -801,8 +833,10 @@ acpi_ps_parse_loop (
801 /* Check for arguments that need to be processed */ 833 /* Check for arguments that need to be processed */
802 834
803 if (walk_state->arg_count) { 835 if (walk_state->arg_count) {
804 /* There are arguments (complex ones), push Op and prepare for argument */ 836 /*
805 837 * There are arguments (complex ones), push Op and
838 * prepare for argument
839 */
806 status = acpi_ps_push_scope (parser_state, op, 840 status = acpi_ps_push_scope (parser_state, op,
807 walk_state->arg_types, walk_state->arg_count); 841 walk_state->arg_types, walk_state->arg_count);
808 if (ACPI_FAILURE (status)) { 842 if (ACPI_FAILURE (status)) {
@@ -812,8 +846,10 @@ acpi_ps_parse_loop (
812 continue; 846 continue;
813 } 847 }
814 848
815 /* All arguments have been processed -- Op is complete, prepare for next */ 849 /*
816 850 * All arguments have been processed -- Op is complete,
851 * prepare for next
852 */
817 walk_state->op_info = acpi_ps_get_opcode_info (op->common.aml_opcode); 853 walk_state->op_info = acpi_ps_get_opcode_info (op->common.aml_opcode);
818 if (walk_state->op_info->flags & AML_NAMED) { 854 if (walk_state->op_info->flags & AML_NAMED) {
819 if (acpi_gbl_depth) { 855 if (acpi_gbl_depth) {
@@ -880,9 +916,8 @@ close_this_op:
880 916
881 case AE_CTRL_TRANSFER: 917 case AE_CTRL_TRANSFER:
882 918
883 /* 919 /* We are about to transfer to a called method. */
884 * We are about to transfer to a called method. 920
885 */
886 walk_state->prev_op = op; 921 walk_state->prev_op = op;
887 walk_state->prev_arg_types = walk_state->arg_types; 922 walk_state->prev_arg_types = walk_state->arg_types;
888 return_ACPI_STATUS (status); 923 return_ACPI_STATUS (status);
@@ -1051,10 +1086,7 @@ close_this_op:
1051 * 1086 *
1052 * FUNCTION: acpi_ps_parse_aml 1087 * FUNCTION: acpi_ps_parse_aml
1053 * 1088 *
1054 * PARAMETERS: start_scope - The starting point of the parse. Becomes the 1089 * PARAMETERS: walk_state - Current state
1055 * root of the parsed op tree.
1056 * Aml - Pointer to the raw AML code to parse
1057 * aml_size - Length of the AML to parse
1058 * 1090 *
1059 * 1091 *
1060 * RETURN: Status 1092 * RETURN: Status
@@ -1076,8 +1108,10 @@ acpi_ps_parse_aml (
1076 1108
1077 ACPI_FUNCTION_TRACE ("ps_parse_aml"); 1109 ACPI_FUNCTION_TRACE ("ps_parse_aml");
1078 1110
1079 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Entered with walk_state=%p Aml=%p size=%X\n", 1111 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
1080 walk_state, walk_state->parser_state.aml, walk_state->parser_state.aml_size)); 1112 "Entered with walk_state=%p Aml=%p size=%X\n",
1113 walk_state, walk_state->parser_state.aml,
1114 walk_state->parser_state.aml_size));
1081 1115
1082 1116
1083 /* Create and initialize a new thread state */ 1117 /* Create and initialize a new thread state */
@@ -1142,9 +1176,10 @@ acpi_ps_parse_aml (
1142 if ((status == AE_ALREADY_EXISTS) && 1176 if ((status == AE_ALREADY_EXISTS) &&
1143 (!walk_state->method_desc->method.semaphore)) { 1177 (!walk_state->method_desc->method.semaphore)) {
1144 /* 1178 /*
1145 * This method is marked not_serialized, but it tried to create a named 1179 * This method is marked not_serialized, but it tried to create
1146 * object, causing the second thread entrance to fail. We will workaround 1180 * a named object, causing the second thread entrance to fail.
1147 * this by marking the method permanently as Serialized. 1181 * We will workaround this by marking the method permanently
1182 * as Serialized.
1148 */ 1183 */
1149 walk_state->method_desc->method.method_flags |= AML_METHOD_SERIALIZED; 1184 walk_state->method_desc->method.method_flags |= AML_METHOD_SERIALIZED;
1150 walk_state->method_desc->method.concurrency = 1; 1185 walk_state->method_desc->method.concurrency = 1;
@@ -1187,7 +1222,8 @@ acpi_ps_parse_aml (
1187 1222
1188 previous_walk_state = walk_state; 1223 previous_walk_state = walk_state;
1189 1224
1190 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "return_value=%p, implicit_value=%p State=%p\n", 1225 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
1226 "return_value=%p, implicit_value=%p State=%p\n",
1191 walk_state->return_desc, walk_state->implicit_return_obj, walk_state)); 1227 walk_state->return_desc, walk_state->implicit_return_obj, walk_state));
1192 1228
1193 /* Check if we have restarted a preempted walk */ 1229 /* Check if we have restarted a preempted walk */
@@ -1231,12 +1267,14 @@ acpi_ps_parse_aml (
1231 */ 1267 */
1232 else if (previous_walk_state->caller_return_desc) { 1268 else if (previous_walk_state->caller_return_desc) {
1233 if (previous_walk_state->implicit_return_obj) { 1269 if (previous_walk_state->implicit_return_obj) {
1234 *(previous_walk_state->caller_return_desc) = previous_walk_state->implicit_return_obj; 1270 *(previous_walk_state->caller_return_desc) =
1271 previous_walk_state->implicit_return_obj;
1235 } 1272 }
1236 else { 1273 else {
1237 /* NULL if no return value */ 1274 /* NULL if no return value */
1238 1275
1239 *(previous_walk_state->caller_return_desc) = previous_walk_state->return_desc; 1276 *(previous_walk_state->caller_return_desc) =
1277 previous_walk_state->return_desc;
1240 } 1278 }
1241 } 1279 }
1242 else { 1280 else {
diff --git a/drivers/acpi/parser/psscope.c b/drivers/acpi/parser/psscope.c
index dcbed49608b0..8dcd1b1e7131 100644
--- a/drivers/acpi/parser/psscope.c
+++ b/drivers/acpi/parser/psscope.c
@@ -65,6 +65,7 @@ union acpi_parse_object *
65acpi_ps_get_parent_scope ( 65acpi_ps_get_parent_scope (
66 struct acpi_parse_state *parser_state) 66 struct acpi_parse_state *parser_state)
67{ 67{
68
68 return (parser_state->scope->parse_scope.op); 69 return (parser_state->scope->parse_scope.op);
69} 70}
70 71
@@ -87,8 +88,10 @@ u8
87acpi_ps_has_completed_scope ( 88acpi_ps_has_completed_scope (
88 struct acpi_parse_state *parser_state) 89 struct acpi_parse_state *parser_state)
89{ 90{
90 return ((u8) ((parser_state->aml >= parser_state->scope->parse_scope.arg_end || 91
91 !parser_state->scope->parse_scope.arg_count))); 92 return ((u8)
93 ((parser_state->aml >= parser_state->scope->parse_scope.arg_end ||
94 !parser_state->scope->parse_scope.arg_count)));
92} 95}
93 96
94 97
@@ -167,23 +170,23 @@ acpi_ps_push_scope (
167 return_ACPI_STATUS (AE_NO_MEMORY); 170 return_ACPI_STATUS (AE_NO_MEMORY);
168 } 171 }
169 172
170 scope->common.data_type = ACPI_DESC_TYPE_STATE_PSCOPE; 173 scope->common.data_type = ACPI_DESC_TYPE_STATE_PSCOPE;
171 scope->parse_scope.op = op; 174 scope->parse_scope.op = op;
172 scope->parse_scope.arg_list = remaining_args; 175 scope->parse_scope.arg_list = remaining_args;
173 scope->parse_scope.arg_count = arg_count; 176 scope->parse_scope.arg_count = arg_count;
174 scope->parse_scope.pkg_end = parser_state->pkg_end; 177 scope->parse_scope.pkg_end = parser_state->pkg_end;
175 178
176 /* Push onto scope stack */ 179 /* Push onto scope stack */
177 180
178 acpi_ut_push_generic_state (&parser_state->scope, scope); 181 acpi_ut_push_generic_state (&parser_state->scope, scope);
179 182
180 if (arg_count == ACPI_VAR_ARGS) { 183 if (arg_count == ACPI_VAR_ARGS) {
181 /* multiple arguments */ 184 /* Multiple arguments */
182 185
183 scope->parse_scope.arg_end = parser_state->pkg_end; 186 scope->parse_scope.arg_end = parser_state->pkg_end;
184 } 187 }
185 else { 188 else {
186 /* single argument */ 189 /* Single argument */
187 190
188 scope->parse_scope.arg_end = ACPI_TO_POINTER (ACPI_MAX_PTR); 191 scope->parse_scope.arg_end = ACPI_TO_POINTER (ACPI_MAX_PTR);
189 } 192 }
@@ -221,18 +224,17 @@ acpi_ps_pop_scope (
221 ACPI_FUNCTION_TRACE ("ps_pop_scope"); 224 ACPI_FUNCTION_TRACE ("ps_pop_scope");
222 225
223 226
224 /* 227 /* Only pop the scope if there is in fact a next scope */
225 * Only pop the scope if there is in fact a next scope 228
226 */
227 if (scope->common.next) { 229 if (scope->common.next) {
228 scope = acpi_ut_pop_generic_state (&parser_state->scope); 230 scope = acpi_ut_pop_generic_state (&parser_state->scope);
229 231
230 /* return to parsing previous op */ 232 /* return to parsing previous op */
231 233
232 *op = scope->parse_scope.op; 234 *op = scope->parse_scope.op;
233 *arg_list = scope->parse_scope.arg_list; 235 *arg_list = scope->parse_scope.arg_list;
234 *arg_count = scope->parse_scope.arg_count; 236 *arg_count = scope->parse_scope.arg_count;
235 parser_state->pkg_end = scope->parse_scope.pkg_end; 237 parser_state->pkg_end = scope->parse_scope.pkg_end;
236 238
237 /* All done with this scope state structure */ 239 /* All done with this scope state structure */
238 240
@@ -241,12 +243,13 @@ acpi_ps_pop_scope (
241 else { 243 else {
242 /* empty parse stack, prepare to fetch next opcode */ 244 /* empty parse stack, prepare to fetch next opcode */
243 245
244 *op = NULL; 246 *op = NULL;
245 *arg_list = 0; 247 *arg_list = 0;
246 *arg_count = 0; 248 *arg_count = 0;
247 } 249 }
248 250
249 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Popped Op %p Args %X\n", *op, *arg_count)); 251 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
252 "Popped Op %p Args %X\n", *op, *arg_count));
250 return_VOID; 253 return_VOID;
251} 254}
252 255
@@ -257,7 +260,7 @@ acpi_ps_pop_scope (
257 * 260 *
258 * PARAMETERS: parser_state - Current parser state object 261 * PARAMETERS: parser_state - Current parser state object
259 * 262 *
260 * RETURN: Status 263 * RETURN: None
261 * 264 *
262 * DESCRIPTION: Destroy available list, remaining stack levels, and return 265 * DESCRIPTION: Destroy available list, remaining stack levels, and return
263 * root scope 266 * root scope
diff --git a/drivers/acpi/parser/pstree.c b/drivers/acpi/parser/pstree.c
index 2140bd1ac10b..d5aafe73fca0 100644
--- a/drivers/acpi/parser/pstree.c
+++ b/drivers/acpi/parser/pstree.c
@@ -49,6 +49,14 @@
49#define _COMPONENT ACPI_PARSER 49#define _COMPONENT ACPI_PARSER
50 ACPI_MODULE_NAME ("pstree") 50 ACPI_MODULE_NAME ("pstree")
51 51
52/* Local prototypes */
53
54#ifdef ACPI_OBSOLETE_FUNCTIONS
55union acpi_parse_object *
56acpi_ps_get_child (
57 union acpi_parse_object *op);
58#endif
59
52 60
53/******************************************************************************* 61/*******************************************************************************
54 * 62 *
@@ -57,7 +65,7 @@
57 * PARAMETERS: Op - Get an argument for this op 65 * PARAMETERS: Op - Get an argument for this op
58 * Argn - Nth argument to get 66 * Argn - Nth argument to get
59 * 67 *
60 * RETURN: The argument (as an Op object). NULL if argument does not exist 68 * RETURN: The argument (as an Op object). NULL if argument does not exist
61 * 69 *
62 * DESCRIPTION: Get the specified op's argument. 70 * DESCRIPTION: Get the specified op's argument.
63 * 71 *
@@ -152,7 +160,6 @@ acpi_ps_append_arg (
152 return; 160 return;
153 } 161 }
154 162
155
156 /* Append the argument to the linked argument list */ 163 /* Append the argument to the linked argument list */
157 164
158 if (op->common.value.arg) { 165 if (op->common.value.arg) {
@@ -164,14 +171,12 @@ acpi_ps_append_arg (
164 } 171 }
165 prev_arg->common.next = arg; 172 prev_arg->common.next = arg;
166 } 173 }
167
168 else { 174 else {
169 /* No argument list, this will be the first argument */ 175 /* No argument list, this will be the first argument */
170 176
171 op->common.value.arg = arg; 177 op->common.value.arg = arg;
172 } 178 }
173 179
174
175 /* Set the parent in this arg and any args linked after it */ 180 /* Set the parent in this arg and any args linked after it */
176 181
177 while (arg) { 182 while (arg) {
@@ -182,73 +187,6 @@ acpi_ps_append_arg (
182 187
183 188
184#ifdef ACPI_FUTURE_USAGE 189#ifdef ACPI_FUTURE_USAGE
185
186/*******************************************************************************
187 *
188 * FUNCTION: acpi_ps_get_child
189 *
190 * PARAMETERS: Op - Get the child of this Op
191 *
192 * RETURN: Child Op, Null if none is found.
193 *
194 * DESCRIPTION: Get op's children or NULL if none
195 *
196 ******************************************************************************/
197union acpi_parse_object *
198acpi_ps_get_child (
199 union acpi_parse_object *op)
200{
201 union acpi_parse_object *child = NULL;
202
203
204 ACPI_FUNCTION_ENTRY ();
205
206
207 switch (op->common.aml_opcode) {
208 case AML_SCOPE_OP:
209 case AML_ELSE_OP:
210 case AML_DEVICE_OP:
211 case AML_THERMAL_ZONE_OP:
212 case AML_INT_METHODCALL_OP:
213
214 child = acpi_ps_get_arg (op, 0);
215 break;
216
217
218 case AML_BUFFER_OP:
219 case AML_PACKAGE_OP:
220 case AML_METHOD_OP:
221 case AML_IF_OP:
222 case AML_WHILE_OP:
223 case AML_FIELD_OP:
224
225 child = acpi_ps_get_arg (op, 1);
226 break;
227
228
229 case AML_POWER_RES_OP:
230 case AML_INDEX_FIELD_OP:
231
232 child = acpi_ps_get_arg (op, 2);
233 break;
234
235
236 case AML_PROCESSOR_OP:
237 case AML_BANK_FIELD_OP:
238
239 child = acpi_ps_get_arg (op, 3);
240 break;
241
242
243 default:
244 /* All others have no children */
245 break;
246 }
247
248 return (child);
249}
250
251
252/******************************************************************************* 190/*******************************************************************************
253 * 191 *
254 * FUNCTION: acpi_ps_get_depth_next 192 * FUNCTION: acpi_ps_get_depth_next
@@ -280,21 +218,21 @@ acpi_ps_get_depth_next (
280 return (NULL); 218 return (NULL);
281 } 219 }
282 220
283 /* look for an argument or child */ 221 /* Look for an argument or child */
284 222
285 next = acpi_ps_get_arg (op, 0); 223 next = acpi_ps_get_arg (op, 0);
286 if (next) { 224 if (next) {
287 return (next); 225 return (next);
288 } 226 }
289 227
290 /* look for a sibling */ 228 /* Look for a sibling */
291 229
292 next = op->common.next; 230 next = op->common.next;
293 if (next) { 231 if (next) {
294 return (next); 232 return (next);
295 } 233 }
296 234
297 /* look for a sibling of parent */ 235 /* Look for a sibling of parent */
298 236
299 parent = op->common.parent; 237 parent = op->common.parent;
300 238
@@ -305,13 +243,13 @@ acpi_ps_get_depth_next (
305 } 243 }
306 244
307 if (arg == origin) { 245 if (arg == origin) {
308 /* reached parent of origin, end search */ 246 /* Reached parent of origin, end search */
309 247
310 return (NULL); 248 return (NULL);
311 } 249 }
312 250
313 if (parent->common.next) { 251 if (parent->common.next) {
314 /* found sibling of parent */ 252 /* Found sibling of parent */
315 253
316 return (parent->common.next); 254 return (parent->common.next);
317 } 255 }
@@ -323,5 +261,74 @@ acpi_ps_get_depth_next (
323 return (next); 261 return (next);
324} 262}
325 263
264
265#ifdef ACPI_OBSOLETE_FUNCTIONS
266/*******************************************************************************
267 *
268 * FUNCTION: acpi_ps_get_child
269 *
270 * PARAMETERS: Op - Get the child of this Op
271 *
272 * RETURN: Child Op, Null if none is found.
273 *
274 * DESCRIPTION: Get op's children or NULL if none
275 *
276 ******************************************************************************/
277
278union acpi_parse_object *
279acpi_ps_get_child (
280 union acpi_parse_object *op)
281{
282 union acpi_parse_object *child = NULL;
283
284
285 ACPI_FUNCTION_ENTRY ();
286
287
288 switch (op->common.aml_opcode) {
289 case AML_SCOPE_OP:
290 case AML_ELSE_OP:
291 case AML_DEVICE_OP:
292 case AML_THERMAL_ZONE_OP:
293 case AML_INT_METHODCALL_OP:
294
295 child = acpi_ps_get_arg (op, 0);
296 break;
297
298
299 case AML_BUFFER_OP:
300 case AML_PACKAGE_OP:
301 case AML_METHOD_OP:
302 case AML_IF_OP:
303 case AML_WHILE_OP:
304 case AML_FIELD_OP:
305
306 child = acpi_ps_get_arg (op, 1);
307 break;
308
309
310 case AML_POWER_RES_OP:
311 case AML_INDEX_FIELD_OP:
312
313 child = acpi_ps_get_arg (op, 2);
314 break;
315
316
317 case AML_PROCESSOR_OP:
318 case AML_BANK_FIELD_OP:
319
320 child = acpi_ps_get_arg (op, 3);
321 break;
322
323
324 default:
325 /* All others have no children */
326 break;
327 }
328
329 return (child);
330}
331#endif
332
326#endif /* ACPI_FUTURE_USAGE */ 333#endif /* ACPI_FUTURE_USAGE */
327 334
diff --git a/drivers/acpi/parser/psutils.c b/drivers/acpi/parser/psutils.c
index b3597cb19f88..a10f88715d43 100644
--- a/drivers/acpi/parser/psutils.c
+++ b/drivers/acpi/parser/psutils.c
@@ -45,7 +45,6 @@
45#include <acpi/acpi.h> 45#include <acpi/acpi.h>
46#include <acpi/acparser.h> 46#include <acpi/acparser.h>
47#include <acpi/amlcode.h> 47#include <acpi/amlcode.h>
48#include <acpi/acnamesp.h>
49 48
50#define _COMPONENT ACPI_PARSER 49#define _COMPONENT ACPI_PARSER
51 ACPI_MODULE_NAME ("psutils") 50 ACPI_MODULE_NAME ("psutils")
@@ -57,7 +56,7 @@
57 * 56 *
58 * PARAMETERS: None 57 * PARAMETERS: None
59 * 58 *
60 * RETURN: scope_op 59 * RETURN: A new Scope object, null on failure
61 * 60 *
62 * DESCRIPTION: Create a Scope and associated namepath op with the root name 61 * DESCRIPTION: Create a Scope and associated namepath op with the root name
63 * 62 *
@@ -75,7 +74,6 @@ acpi_ps_create_scope_op (
75 return (NULL); 74 return (NULL);
76 } 75 }
77 76
78
79 scope_op->named.name = ACPI_ROOT_NAME; 77 scope_op->named.name = ACPI_ROOT_NAME;
80 return (scope_op); 78 return (scope_op);
81} 79}
@@ -88,10 +86,9 @@ acpi_ps_create_scope_op (
88 * PARAMETERS: Op - A newly allocated Op object 86 * PARAMETERS: Op - A newly allocated Op object
89 * Opcode - Opcode to store in the Op 87 * Opcode - Opcode to store in the Op
90 * 88 *
91 * RETURN: Status 89 * RETURN: None
92 * 90 *
93 * DESCRIPTION: Allocate an acpi_op, choose op type (and thus size) based on 91 * DESCRIPTION: Initialize a parse (Op) object
94 * opcode
95 * 92 *
96 ******************************************************************************/ 93 ******************************************************************************/
97 94
@@ -107,7 +104,8 @@ acpi_ps_init_op (
107 op->common.aml_opcode = opcode; 104 op->common.aml_opcode = opcode;
108 105
109 ACPI_DISASM_ONLY_MEMBERS (ACPI_STRNCPY (op->common.aml_op_name, 106 ACPI_DISASM_ONLY_MEMBERS (ACPI_STRNCPY (op->common.aml_op_name,
110 (acpi_ps_get_opcode_info (opcode))->name, sizeof (op->common.aml_op_name))); 107 (acpi_ps_get_opcode_info (opcode))->name,
108 sizeof (op->common.aml_op_name)));
111} 109}
112 110
113 111
@@ -117,7 +115,7 @@ acpi_ps_init_op (
117 * 115 *
118 * PARAMETERS: Opcode - Opcode that will be stored in the new Op 116 * PARAMETERS: Opcode - Opcode that will be stored in the new Op
119 * 117 *
120 * RETURN: Pointer to the new Op. 118 * RETURN: Pointer to the new Op, null on failure
121 * 119 *
122 * DESCRIPTION: Allocate an acpi_op, choose op type (and thus size) based on 120 * DESCRIPTION: Allocate an acpi_op, choose op type (and thus size) based on
123 * opcode. A cache of opcodes is available for the pure 121 * opcode. A cache of opcodes is available for the pure
@@ -275,7 +273,6 @@ acpi_ps_get_name (
275 union acpi_parse_object *op) 273 union acpi_parse_object *op)
276{ 274{
277 275
278
279 /* The "generic" object has no name associated with it */ 276 /* The "generic" object has no name associated with it */
280 277
281 if (op->common.flags & ACPI_PARSEOP_GENERIC) { 278 if (op->common.flags & ACPI_PARSEOP_GENERIC) {
diff --git a/drivers/acpi/parser/pswalk.c b/drivers/acpi/parser/pswalk.c
index 110d2ce917b6..9d20cb2ceb51 100644
--- a/drivers/acpi/parser/pswalk.c
+++ b/drivers/acpi/parser/pswalk.c
@@ -90,17 +90,15 @@ acpi_ps_delete_parse_tree (
90 } 90 }
91 } 91 }
92 92
93 /* 93 /* No more children, this Op is complete. */
94 * No more children, this Op is complete. 94
95 */
96 next = op->common.next; 95 next = op->common.next;
97 parent = op->common.parent; 96 parent = op->common.parent;
98 97
99 acpi_ps_free_op (op); 98 acpi_ps_free_op (op);
100 99
101 /* 100 /* If we are back to the starting point, the walk is complete. */
102 * If we are back to the starting point, the walk is complete. 101
103 */
104 if (op == subtree_root) { 102 if (op == subtree_root) {
105 return_VOID; 103 return_VOID;
106 } 104 }
@@ -111,5 +109,6 @@ acpi_ps_delete_parse_tree (
111 op = parent; 109 op = parent;
112 } 110 }
113 } 111 }
112
114 return_VOID; 113 return_VOID;
115} 114}
diff --git a/drivers/acpi/parser/psxface.c b/drivers/acpi/parser/psxface.c
index b318ad24726d..dba893648e84 100644
--- a/drivers/acpi/parser/psxface.c
+++ b/drivers/acpi/parser/psxface.c
@@ -57,13 +57,16 @@
57 * 57 *
58 * FUNCTION: acpi_psx_execute 58 * FUNCTION: acpi_psx_execute
59 * 59 *
60 * PARAMETERS: Info->Node - A method object containing both the AML 60 * PARAMETERS: Info - Method info block, contains:
61 * address and length. 61 * Node - Method Node to execute
62 * **Params - List of parameters to pass to method, 62 * Parameters - List of parameters to pass to the method,
63 * terminated by NULL. Params itself may be 63 * terminated by NULL. Params itself may be
64 * NULL if no parameters are being passed. 64 * NULL if no parameters are being passed.
65 * **return_obj_desc - Return object from execution of the 65 * return_object - Where to put method's return value (if
66 * method. 66 * any). If NULL, no value is returned.
67 * parameter_type - Type of Parameter list
68 * return_object - Where to put method's return value (if
69 * any). If NULL, no value is returned.
67 * 70 *
68 * RETURN: Status 71 * RETURN: Status
69 * 72 *
@@ -196,9 +199,8 @@ acpi_psx_execute (
196 goto cleanup3; 199 goto cleanup3;
197 } 200 }
198 201
199 /* 202 /* The walk of the parse tree is where we actually execute the method */
200 * The walk of the parse tree is where we actually execute the method 203
201 */
202 status = acpi_ps_parse_aml (walk_state); 204 status = acpi_ps_parse_aml (walk_state);
203 goto cleanup2; /* Walk state already deleted */ 205 goto cleanup2; /* Walk state already deleted */
204 206
@@ -217,7 +219,8 @@ cleanup1:
217 for (i = 0; info->parameters[i]; i++) { 219 for (i = 0; info->parameters[i]; i++) {
218 /* Ignore errors, just do them all */ 220 /* Ignore errors, just do them all */
219 221
220 (void) acpi_ut_update_object_reference (info->parameters[i], REF_DECREMENT); 222 (void) acpi_ut_update_object_reference (
223 info->parameters[i], REF_DECREMENT);
221 } 224 }
222 } 225 }
223 226
diff --git a/drivers/acpi/pci_link.c b/drivers/acpi/pci_link.c
index 520b28ad0740..6ad0e77df9b3 100644
--- a/drivers/acpi/pci_link.c
+++ b/drivers/acpi/pci_link.c
@@ -72,10 +72,12 @@ struct acpi_pci_link_irq {
72 u8 active; /* Current IRQ */ 72 u8 active; /* Current IRQ */
73 u8 edge_level; /* All IRQs */ 73 u8 edge_level; /* All IRQs */
74 u8 active_high_low; /* All IRQs */ 74 u8 active_high_low; /* All IRQs */
75 u8 initialized;
76 u8 resource_type; 75 u8 resource_type;
77 u8 possible_count; 76 u8 possible_count;
78 u8 possible[ACPI_PCI_LINK_MAX_POSSIBLE]; 77 u8 possible[ACPI_PCI_LINK_MAX_POSSIBLE];
78 u8 initialized:1;
79 u8 suspend_resume:1;
80 u8 reserved:6;
79}; 81};
80 82
81struct acpi_pci_link { 83struct acpi_pci_link {
@@ -530,6 +532,10 @@ static int acpi_pci_link_allocate(
530 532
531 ACPI_FUNCTION_TRACE("acpi_pci_link_allocate"); 533 ACPI_FUNCTION_TRACE("acpi_pci_link_allocate");
532 534
535 if (link->irq.suspend_resume) {
536 acpi_pci_link_set(link, link->irq.active);
537 link->irq.suspend_resume = 0;
538 }
533 if (link->irq.initialized) 539 if (link->irq.initialized)
534 return_VALUE(0); 540 return_VALUE(0);
535 541
@@ -713,38 +719,24 @@ end:
713 return_VALUE(result); 719 return_VALUE(result);
714} 720}
715 721
716
717static int
718acpi_pci_link_resume (
719 struct acpi_pci_link *link)
720{
721 ACPI_FUNCTION_TRACE("acpi_pci_link_resume");
722
723 if (link->irq.active && link->irq.initialized)
724 return_VALUE(acpi_pci_link_set(link, link->irq.active));
725 else
726 return_VALUE(0);
727}
728
729
730static int 722static int
731irqrouter_resume( 723irqrouter_suspend(
732 struct sys_device *dev) 724 struct sys_device *dev,
725 u32 state)
733{ 726{
734 struct list_head *node = NULL; 727 struct list_head *node = NULL;
735 struct acpi_pci_link *link = NULL; 728 struct acpi_pci_link *link = NULL;
736 729
737 ACPI_FUNCTION_TRACE("irqrouter_resume"); 730 ACPI_FUNCTION_TRACE("irqrouter_suspend");
738 731
739 list_for_each(node, &acpi_link.entries) { 732 list_for_each(node, &acpi_link.entries) {
740
741 link = list_entry(node, struct acpi_pci_link, node); 733 link = list_entry(node, struct acpi_pci_link, node);
742 if (!link) { 734 if (!link) {
743 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid link context\n")); 735 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid link context\n"));
744 continue; 736 continue;
745 } 737 }
746 738 if (link->irq.active && link->irq.initialized)
747 acpi_pci_link_resume(link); 739 link->irq.suspend_resume = 1;
748 } 740 }
749 return_VALUE(0); 741 return_VALUE(0);
750} 742}
@@ -812,9 +804,12 @@ static int __init acpi_irq_penalty_update(char *str, int used)
812 * There is no ISA_POSSIBLE weight, so we simply use 804 * There is no ISA_POSSIBLE weight, so we simply use
813 * the (small) PCI_USING penalty. 805 * the (small) PCI_USING penalty.
814 */ 806 */
815void acpi_penalize_isa_irq(int irq) 807void acpi_penalize_isa_irq(int irq, int active)
816{ 808{
817 acpi_irq_penalty[irq] += PIRQ_PENALTY_PCI_USING; 809 if (active)
810 acpi_irq_penalty[irq] += PIRQ_PENALTY_ISA_USED;
811 else
812 acpi_irq_penalty[irq] += PIRQ_PENALTY_PCI_USING;
818} 813}
819 814
820/* 815/*
@@ -856,7 +851,7 @@ __setup("acpi_irq_balance", acpi_irq_balance_set);
856 851
857static struct sysdev_class irqrouter_sysdev_class = { 852static struct sysdev_class irqrouter_sysdev_class = {
858 set_kset_name("irqrouter"), 853 set_kset_name("irqrouter"),
859 .resume = irqrouter_resume, 854 .suspend = irqrouter_suspend,
860}; 855};
861 856
862 857
diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c
index 76156ac91bd3..d56a439ac614 100644
--- a/drivers/acpi/processor_core.c
+++ b/drivers/acpi/processor_core.c
@@ -256,6 +256,43 @@ acpi_processor_errata (
256 256
257 257
258/* -------------------------------------------------------------------------- 258/* --------------------------------------------------------------------------
259 Common ACPI processor fucntions
260 -------------------------------------------------------------------------- */
261
262/*
263 * _PDC is required for a BIOS-OS handshake for most of the newer
264 * ACPI processor features.
265 */
266
267int acpi_processor_set_pdc(struct acpi_processor *pr,
268 struct acpi_object_list *pdc_in)
269{
270 acpi_status status = AE_OK;
271 u32 arg0_buf[3];
272 union acpi_object arg0 = {ACPI_TYPE_BUFFER};
273 struct acpi_object_list no_object = {1, &arg0};
274 struct acpi_object_list *pdc;
275
276 ACPI_FUNCTION_TRACE("acpi_processor_set_pdc");
277
278 arg0.buffer.length = 12;
279 arg0.buffer.pointer = (u8 *) arg0_buf;
280 arg0_buf[0] = ACPI_PDC_REVISION_ID;
281 arg0_buf[1] = 0;
282 arg0_buf[2] = 0;
283
284 pdc = (pdc_in) ? pdc_in : &no_object;
285
286 status = acpi_evaluate_object(pr->handle, "_PDC", pdc, NULL);
287
288 if ((ACPI_FAILURE(status)) && (pdc_in))
289 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Error evaluating _PDC, using legacy perf. control...\n"));
290
291 return_VALUE(status);
292}
293
294
295/* --------------------------------------------------------------------------
259 FS Interface (/proc) 296 FS Interface (/proc)
260 -------------------------------------------------------------------------- */ 297 -------------------------------------------------------------------------- */
261 298
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index c9d671cf7857..893b074e3d1a 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -6,6 +6,8 @@
6 * Copyright (C) 2004 Dominik Brodowski <linux@brodo.de> 6 * Copyright (C) 2004 Dominik Brodowski <linux@brodo.de>
7 * Copyright (C) 2004 Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com> 7 * Copyright (C) 2004 Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
8 * - Added processor hotplug support 8 * - Added processor hotplug support
9 * Copyright (C) 2005 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
10 * - Added support for C3 on SMP
9 * 11 *
10 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 12 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11 * 13 *
@@ -142,7 +144,7 @@ acpi_processor_power_activate (
142 switch (old->type) { 144 switch (old->type) {
143 case ACPI_STATE_C3: 145 case ACPI_STATE_C3:
144 /* Disable bus master reload */ 146 /* Disable bus master reload */
145 if (new->type != ACPI_STATE_C3) 147 if (new->type != ACPI_STATE_C3 && pr->flags.bm_check)
146 acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 0, ACPI_MTX_DO_NOT_LOCK); 148 acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 0, ACPI_MTX_DO_NOT_LOCK);
147 break; 149 break;
148 } 150 }
@@ -152,7 +154,7 @@ acpi_processor_power_activate (
152 switch (new->type) { 154 switch (new->type) {
153 case ACPI_STATE_C3: 155 case ACPI_STATE_C3:
154 /* Enable bus master reload */ 156 /* Enable bus master reload */
155 if (old->type != ACPI_STATE_C3) 157 if (old->type != ACPI_STATE_C3 && pr->flags.bm_check)
156 acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 1, ACPI_MTX_DO_NOT_LOCK); 158 acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 1, ACPI_MTX_DO_NOT_LOCK);
157 break; 159 break;
158 } 160 }
@@ -163,6 +165,9 @@ acpi_processor_power_activate (
163} 165}
164 166
165 167
168static atomic_t c3_cpu_count;
169
170
166static void acpi_processor_idle (void) 171static void acpi_processor_idle (void)
167{ 172{
168 struct acpi_processor *pr = NULL; 173 struct acpi_processor *pr = NULL;
@@ -297,8 +302,22 @@ static void acpi_processor_idle (void)
297 break; 302 break;
298 303
299 case ACPI_STATE_C3: 304 case ACPI_STATE_C3:
300 /* Disable bus master arbitration */ 305
301 acpi_set_register(ACPI_BITREG_ARB_DISABLE, 1, ACPI_MTX_DO_NOT_LOCK); 306 if (pr->flags.bm_check) {
307 if (atomic_inc_return(&c3_cpu_count) ==
308 num_online_cpus()) {
309 /*
310 * All CPUs are trying to go to C3
311 * Disable bus master arbitration
312 */
313 acpi_set_register(ACPI_BITREG_ARB_DISABLE, 1,
314 ACPI_MTX_DO_NOT_LOCK);
315 }
316 } else {
317 /* SMP with no shared cache... Invalidate cache */
318 ACPI_FLUSH_CPU_CACHE();
319 }
320
302 /* Get start time (ticks) */ 321 /* Get start time (ticks) */
303 t1 = inl(acpi_fadt.xpm_tmr_blk.address); 322 t1 = inl(acpi_fadt.xpm_tmr_blk.address);
304 /* Invoke C3 */ 323 /* Invoke C3 */
@@ -307,8 +326,12 @@ static void acpi_processor_idle (void)
307 t2 = inl(acpi_fadt.xpm_tmr_blk.address); 326 t2 = inl(acpi_fadt.xpm_tmr_blk.address);
308 /* Get end time (ticks) */ 327 /* Get end time (ticks) */
309 t2 = inl(acpi_fadt.xpm_tmr_blk.address); 328 t2 = inl(acpi_fadt.xpm_tmr_blk.address);
310 /* Enable bus master arbitration */ 329 if (pr->flags.bm_check) {
311 acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0, ACPI_MTX_DO_NOT_LOCK); 330 /* Enable bus master arbitration */
331 atomic_dec(&c3_cpu_count);
332 acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0, ACPI_MTX_DO_NOT_LOCK);
333 }
334
312 /* Re-enable interrupts */ 335 /* Re-enable interrupts */
313 local_irq_enable(); 336 local_irq_enable();
314 /* Compute time (ticks) that we were actually asleep */ 337 /* Compute time (ticks) that we were actually asleep */
@@ -519,6 +542,29 @@ static int acpi_processor_get_power_info_fadt (struct acpi_processor *pr)
519} 542}
520 543
521 544
545static int acpi_processor_get_power_info_default_c1 (struct acpi_processor *pr)
546{
547 int i;
548
549 ACPI_FUNCTION_TRACE("acpi_processor_get_power_info_default_c1");
550
551 for (i = 0; i < ACPI_PROCESSOR_MAX_POWER; i++)
552 memset(pr->power.states, 0, sizeof(struct acpi_processor_cx));
553
554 /* if info is obtained from pblk/fadt, type equals state */
555 pr->power.states[ACPI_STATE_C1].type = ACPI_STATE_C1;
556 pr->power.states[ACPI_STATE_C2].type = ACPI_STATE_C2;
557 pr->power.states[ACPI_STATE_C3].type = ACPI_STATE_C3;
558
559 /* the C0 state only exists as a filler in our array,
560 * and all processors need to support C1 */
561 pr->power.states[ACPI_STATE_C0].valid = 1;
562 pr->power.states[ACPI_STATE_C1].valid = 1;
563
564 return_VALUE(0);
565}
566
567
522static int acpi_processor_get_power_info_cst (struct acpi_processor *pr) 568static int acpi_processor_get_power_info_cst (struct acpi_processor *pr)
523{ 569{
524 acpi_status status = 0; 570 acpi_status status = 0;
@@ -529,9 +575,6 @@ static int acpi_processor_get_power_info_cst (struct acpi_processor *pr)
529 575
530 ACPI_FUNCTION_TRACE("acpi_processor_get_power_info_cst"); 576 ACPI_FUNCTION_TRACE("acpi_processor_get_power_info_cst");
531 577
532 if (errata.smp)
533 return_VALUE(-ENODEV);
534
535 if (nocst) 578 if (nocst)
536 return_VALUE(-ENODEV); 579 return_VALUE(-ENODEV);
537 580
@@ -664,13 +707,6 @@ static void acpi_processor_power_verify_c2(struct acpi_processor_cx *cx)
664 return_VOID; 707 return_VOID;
665 } 708 }
666 709
667 /* We're (currently) only supporting C2 on UP */
668 else if (errata.smp) {
669 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
670 "C2 not supported in SMP mode\n"));
671 return_VOID;
672 }
673
674 /* 710 /*
675 * Otherwise we've met all of our C2 requirements. 711 * Otherwise we've met all of our C2 requirements.
676 * Normalize the C2 latency to expidite policy 712 * Normalize the C2 latency to expidite policy
@@ -686,6 +722,8 @@ static void acpi_processor_power_verify_c3(
686 struct acpi_processor *pr, 722 struct acpi_processor *pr,
687 struct acpi_processor_cx *cx) 723 struct acpi_processor_cx *cx)
688{ 724{
725 static int bm_check_flag;
726
689 ACPI_FUNCTION_TRACE("acpi_processor_get_power_verify_c3"); 727 ACPI_FUNCTION_TRACE("acpi_processor_get_power_verify_c3");
690 728
691 if (!cx->address) 729 if (!cx->address)
@@ -702,20 +740,6 @@ static void acpi_processor_power_verify_c3(
702 return_VOID; 740 return_VOID;
703 } 741 }
704 742
705 /* bus mastering control is necessary */
706 else if (!pr->flags.bm_control) {
707 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
708 "C3 support requires bus mastering control\n"));
709 return_VOID;
710 }
711
712 /* We're (currently) only supporting C2 on UP */
713 else if (errata.smp) {
714 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
715 "C3 not supported in SMP mode\n"));
716 return_VOID;
717 }
718
719 /* 743 /*
720 * PIIX4 Erratum #18: We don't support C3 when Type-F (fast) 744 * PIIX4 Erratum #18: We don't support C3 when Type-F (fast)
721 * DMA transfers are used by any ISA device to avoid livelock. 745 * DMA transfers are used by any ISA device to avoid livelock.
@@ -729,6 +753,39 @@ static void acpi_processor_power_verify_c3(
729 return_VOID; 753 return_VOID;
730 } 754 }
731 755
756 /* All the logic here assumes flags.bm_check is same across all CPUs */
757 if (!bm_check_flag) {
758 /* Determine whether bm_check is needed based on CPU */
759 acpi_processor_power_init_bm_check(&(pr->flags), pr->id);
760 bm_check_flag = pr->flags.bm_check;
761 } else {
762 pr->flags.bm_check = bm_check_flag;
763 }
764
765 if (pr->flags.bm_check) {
766 printk("Disabling BM access before entering C3\n");
767 /* bus mastering control is necessary */
768 if (!pr->flags.bm_control) {
769 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
770 "C3 support requires bus mastering control\n"));
771 return_VOID;
772 }
773 } else {
774 printk("Invalidating cache before entering C3\n");
775 /*
776 * WBINVD should be set in fadt, for C3 state to be
777 * supported on when bm_check is not required.
778 */
779 if (acpi_fadt.wb_invd != 1) {
780 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
781 "Cache invalidation should work properly"
782 " for C3 to be enabled on SMP systems\n"));
783 return_VOID;
784 }
785 acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD,
786 0, ACPI_MTX_DO_NOT_LOCK);
787 }
788
732 /* 789 /*
733 * Otherwise we've met all of our C3 requirements. 790 * Otherwise we've met all of our C3 requirements.
734 * Normalize the C3 latency to expidite policy. Enable 791 * Normalize the C3 latency to expidite policy. Enable
@@ -737,7 +794,6 @@ static void acpi_processor_power_verify_c3(
737 */ 794 */
738 cx->valid = 1; 795 cx->valid = 1;
739 cx->latency_ticks = US_TO_PM_TIMER_TICKS(cx->latency); 796 cx->latency_ticks = US_TO_PM_TIMER_TICKS(cx->latency);
740 pr->flags.bm_check = 1;
741 797
742 return_VOID; 798 return_VOID;
743} 799}
@@ -787,10 +843,7 @@ static int acpi_processor_get_power_info (
787 if ((result) || (acpi_processor_power_verify(pr) < 2)) { 843 if ((result) || (acpi_processor_power_verify(pr) < 2)) {
788 result = acpi_processor_get_power_info_fadt(pr); 844 result = acpi_processor_get_power_info_fadt(pr);
789 if (result) 845 if (result)
790 return_VALUE(result); 846 result = acpi_processor_get_power_info_default_c1(pr);
791
792 if (acpi_processor_power_verify(pr) < 2)
793 return_VALUE(-ENODEV);
794 } 847 }
795 848
796 /* 849 /*
@@ -810,11 +863,10 @@ static int acpi_processor_get_power_info (
810 * CPU as being "idle manageable" 863 * CPU as being "idle manageable"
811 */ 864 */
812 for (i = 1; i < ACPI_PROCESSOR_MAX_POWER; i++) { 865 for (i = 1; i < ACPI_PROCESSOR_MAX_POWER; i++) {
813 if (pr->power.states[i].valid) 866 if (pr->power.states[i].valid) {
814 pr->power.count = i; 867 pr->power.count = i;
815 if ((pr->power.states[i].valid) &&
816 (pr->power.states[i].type >= ACPI_STATE_C2))
817 pr->flags.power = 1; 868 pr->flags.power = 1;
869 }
818 } 870 }
819 871
820 return_VALUE(0); 872 return_VALUE(0);
@@ -829,7 +881,7 @@ int acpi_processor_cst_has_changed (struct acpi_processor *pr)
829 if (!pr) 881 if (!pr)
830 return_VALUE(-EINVAL); 882 return_VALUE(-EINVAL);
831 883
832 if (errata.smp || nocst) { 884 if ( nocst) {
833 return_VALUE(-ENODEV); 885 return_VALUE(-ENODEV);
834 } 886 }
835 887
@@ -929,7 +981,6 @@ static struct file_operations acpi_processor_power_fops = {
929 .release = single_release, 981 .release = single_release,
930}; 982};
931 983
932
933int acpi_processor_power_init(struct acpi_processor *pr, struct acpi_device *device) 984int acpi_processor_power_init(struct acpi_processor *pr, struct acpi_device *device)
934{ 985{
935 acpi_status status = 0; 986 acpi_status status = 0;
@@ -946,7 +997,10 @@ int acpi_processor_power_init(struct acpi_processor *pr, struct acpi_device *dev
946 first_run++; 997 first_run++;
947 } 998 }
948 999
949 if (!errata.smp && (pr->id == 0) && acpi_fadt.cst_cnt && !nocst) { 1000 if (!pr)
1001 return_VALUE(-EINVAL);
1002
1003 if (acpi_fadt.cst_cnt && !nocst) {
950 status = acpi_os_write_port(acpi_fadt.smi_cmd, acpi_fadt.cst_cnt, 8); 1004 status = acpi_os_write_port(acpi_fadt.smi_cmd, acpi_fadt.cst_cnt, 8);
951 if (ACPI_FAILURE(status)) { 1005 if (ACPI_FAILURE(status)) {
952 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1006 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
@@ -954,6 +1008,8 @@ int acpi_processor_power_init(struct acpi_processor *pr, struct acpi_device *dev
954 } 1008 }
955 } 1009 }
956 1010
1011 acpi_processor_power_init_pdc(&(pr->power), pr->id);
1012 acpi_processor_set_pdc(pr, pr->power.pdc);
957 acpi_processor_get_power_info(pr); 1013 acpi_processor_get_power_info(pr);
958 1014
959 /* 1015 /*
diff --git a/drivers/acpi/processor_perflib.c b/drivers/acpi/processor_perflib.c
index a9a1a8fe3199..1f0d6256302f 100644
--- a/drivers/acpi/processor_perflib.c
+++ b/drivers/acpi/processor_perflib.c
@@ -165,37 +165,6 @@ void acpi_processor_ppc_exit(void) {
165 acpi_processor_ppc_status &= ~PPC_REGISTERED; 165 acpi_processor_ppc_status &= ~PPC_REGISTERED;
166} 166}
167 167
168/*
169 * when registering a cpufreq driver with this ACPI processor driver, the
170 * _PCT and _PSS structures are read out and written into struct
171 * acpi_processor_performance.
172 */
173static int acpi_processor_set_pdc (struct acpi_processor *pr)
174{
175 acpi_status status = AE_OK;
176 u32 arg0_buf[3];
177 union acpi_object arg0 = {ACPI_TYPE_BUFFER};
178 struct acpi_object_list no_object = {1, &arg0};
179 struct acpi_object_list *pdc;
180
181 ACPI_FUNCTION_TRACE("acpi_processor_set_pdc");
182
183 arg0.buffer.length = 12;
184 arg0.buffer.pointer = (u8 *) arg0_buf;
185 arg0_buf[0] = ACPI_PDC_REVISION_ID;
186 arg0_buf[1] = 0;
187 arg0_buf[2] = 0;
188
189 pdc = (pr->performance->pdc) ? pr->performance->pdc : &no_object;
190
191 status = acpi_evaluate_object(pr->handle, "_PDC", pdc, NULL);
192
193 if ((ACPI_FAILURE(status)) && (pr->performance->pdc))
194 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Error evaluating _PDC, using legacy perf. control...\n"));
195
196 return_VALUE(status);
197}
198
199 168
200static int 169static int
201acpi_processor_get_performance_control ( 170acpi_processor_get_performance_control (
@@ -357,7 +326,7 @@ acpi_processor_get_performance_info (
357 if (!pr || !pr->performance || !pr->handle) 326 if (!pr || !pr->performance || !pr->handle)
358 return_VALUE(-EINVAL); 327 return_VALUE(-EINVAL);
359 328
360 acpi_processor_set_pdc(pr); 329 acpi_processor_set_pdc(pr, pr->performance->pdc);
361 330
362 status = acpi_get_handle(pr->handle, "_PCT", &handle); 331 status = acpi_get_handle(pr->handle, "_PCT", &handle);
363 if (ACPI_FAILURE(status)) { 332 if (ACPI_FAILURE(status)) {
diff --git a/drivers/acpi/resources/rsaddr.c b/drivers/acpi/resources/rsaddr.c
index 4788c079735d..55d264771c48 100644
--- a/drivers/acpi/resources/rsaddr.c
+++ b/drivers/acpi/resources/rsaddr.c
@@ -77,21 +77,21 @@ acpi_rs_address16_resource (
77 u8 **output_buffer, 77 u8 **output_buffer,
78 acpi_size *structure_size) 78 acpi_size *structure_size)
79{ 79{
80 u8 *buffer = byte_stream_buffer;
81 struct acpi_resource *output_struct = (void *) *output_buffer;
82 u8 *temp_ptr;
83 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_address16);
84 u32 index; 80 u32 index;
85 u16 temp16; 81 u16 temp16;
86 u8 temp8; 82 u8 temp8;
83 u8 *temp_ptr;
84 u8 *buffer = byte_stream_buffer;
85 struct acpi_resource *output_struct = (void *) *output_buffer;
86 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (
87 struct acpi_resource_address16);
87 88
88 89
89 ACPI_FUNCTION_TRACE ("rs_address16_resource"); 90 ACPI_FUNCTION_TRACE ("rs_address16_resource");
90 91
91 92
92 /* 93 /* Point past the Descriptor to get the number of bytes consumed */
93 * Point past the Descriptor to get the number of bytes consumed 94
94 */
95 buffer += 1; 95 buffer += 1;
96 ACPI_MOVE_16_TO_16 (&temp16, buffer); 96 ACPI_MOVE_16_TO_16 (&temp16, buffer);
97 97
@@ -104,9 +104,8 @@ acpi_rs_address16_resource (
104 *bytes_consumed = temp16 + 3; 104 *bytes_consumed = temp16 + 3;
105 output_struct->id = ACPI_RSTYPE_ADDRESS16; 105 output_struct->id = ACPI_RSTYPE_ADDRESS16;
106 106
107 /* 107 /* Get the Resource Type (Byte3) */
108 * Get the Resource Type (Byte3) 108
109 */
110 buffer += 2; 109 buffer += 2;
111 temp8 = *buffer; 110 temp8 = *buffer;
112 111
@@ -118,9 +117,8 @@ acpi_rs_address16_resource (
118 117
119 output_struct->data.address16.resource_type = temp8; 118 output_struct->data.address16.resource_type = temp8;
120 119
121 /* 120 /* Get the General Flags (Byte4) */
122 * Get the General Flags (Byte4) 121
123 */
124 buffer += 1; 122 buffer += 1;
125 temp8 = *buffer; 123 temp8 = *buffer;
126 124
@@ -140,9 +138,8 @@ acpi_rs_address16_resource (
140 138
141 output_struct->data.address16.max_address_fixed = (temp8 >> 3) & 0x01; 139 output_struct->data.address16.max_address_fixed = (temp8 >> 3) & 0x01;
142 140
143 /* 141 /* Get the Type Specific Flags (Byte5) */
144 * Get the Type Specific Flags (Byte5) 142
145 */
146 buffer += 1; 143 buffer += 1;
147 temp8 = *buffer; 144 temp8 = *buffer;
148 145
@@ -165,39 +162,34 @@ acpi_rs_address16_resource (
165 } 162 }
166 } 163 }
167 164
168 /* 165 /* Get Granularity (Bytes 6-7) */
169 * Get Granularity (Bytes 6-7) 166
170 */
171 buffer += 1; 167 buffer += 1;
172 ACPI_MOVE_16_TO_32 (&output_struct->data.address16.granularity, buffer); 168 ACPI_MOVE_16_TO_32 (&output_struct->data.address16.granularity, buffer);
173 169
174 /* 170 /* Get min_address_range (Bytes 8-9) */
175 * Get min_address_range (Bytes 8-9) 171
176 */
177 buffer += 2; 172 buffer += 2;
178 ACPI_MOVE_16_TO_32 (&output_struct->data.address16.min_address_range, buffer); 173 ACPI_MOVE_16_TO_32 (&output_struct->data.address16.min_address_range, buffer);
179 174
180 /* 175 /* Get max_address_range (Bytes 10-11) */
181 * Get max_address_range (Bytes 10-11) 176
182 */
183 buffer += 2; 177 buffer += 2;
184 ACPI_MOVE_16_TO_32 (&output_struct->data.address16.max_address_range, buffer); 178 ACPI_MOVE_16_TO_32 (&output_struct->data.address16.max_address_range, buffer);
185 179
186 /* 180 /* Get address_translation_offset (Bytes 12-13) */
187 * Get address_translation_offset (Bytes 12-13) 181
188 */
189 buffer += 2; 182 buffer += 2;
190 ACPI_MOVE_16_TO_32 (&output_struct->data.address16.address_translation_offset, buffer); 183 ACPI_MOVE_16_TO_32 (&output_struct->data.address16.address_translation_offset,
184 buffer);
185
186 /* Get address_length (Bytes 14-15) */
191 187
192 /*
193 * Get address_length (Bytes 14-15)
194 */
195 buffer += 2; 188 buffer += 2;
196 ACPI_MOVE_16_TO_32 (&output_struct->data.address16.address_length, buffer); 189 ACPI_MOVE_16_TO_32 (&output_struct->data.address16.address_length, buffer);
197 190
198 /* 191 /* Resource Source Index (if present) */
199 * Resource Source Index (if present) 192
200 */
201 buffer += 2; 193 buffer += 2;
202 194
203 /* 195 /*
@@ -225,7 +217,8 @@ acpi_rs_address16_resource (
225 output_struct->data.address16.resource_source.string_ptr = 217 output_struct->data.address16.resource_source.string_ptr =
226 (char *)((u8 * )output_struct + struct_size); 218 (char *)((u8 * )output_struct + struct_size);
227 219
228 temp_ptr = (u8 *) output_struct->data.address16.resource_source.string_ptr; 220 temp_ptr = (u8 *)
221 output_struct->data.address16.resource_source.string_ptr;
229 222
230 /* Copy the string into the buffer */ 223 /* Copy the string into the buffer */
231 224
@@ -239,9 +232,8 @@ acpi_rs_address16_resource (
239 index += 1; 232 index += 1;
240 } 233 }
241 234
242 /* 235 /* Add the terminating null */
243 * Add the terminating null 236
244 */
245 *temp_ptr = 0x00; 237 *temp_ptr = 0x00;
246 238
247 output_struct->data.address16.resource_source.string_length = index + 1; 239 output_struct->data.address16.resource_source.string_length = index + 1;
@@ -260,14 +252,12 @@ acpi_rs_address16_resource (
260 output_struct->data.address16.resource_source.string_ptr = NULL; 252 output_struct->data.address16.resource_source.string_ptr = NULL;
261 } 253 }
262 254
263 /* 255 /* Set the Length parameter */
264 * Set the Length parameter 256
265 */
266 output_struct->length = (u32) struct_size; 257 output_struct->length = (u32) struct_size;
267 258
268 /* 259 /* Return the final size of the structure */
269 * Return the final size of the structure 260
270 */
271 *structure_size = struct_size; 261 *structure_size = struct_size;
272 return_ACPI_STATUS (AE_OK); 262 return_ACPI_STATUS (AE_OK);
273} 263}
@@ -305,28 +295,24 @@ acpi_rs_address16_stream (
305 ACPI_FUNCTION_TRACE ("rs_address16_stream"); 295 ACPI_FUNCTION_TRACE ("rs_address16_stream");
306 296
307 297
308 /* 298 /* The descriptor field is static */
309 * The descriptor field is static 299
310 */
311 *buffer = 0x88; 300 *buffer = 0x88;
312 buffer += 1; 301 buffer += 1;
313 302
314 /* 303 /* Save a pointer to the Length field - to be filled in later */
315 * Save a pointer to the Length field - to be filled in later 304
316 */
317 length_field = buffer; 305 length_field = buffer;
318 buffer += 2; 306 buffer += 2;
319 307
320 /* 308 /* Set the Resource Type (Memory, Io, bus_number) */
321 * Set the Resource Type (Memory, Io, bus_number) 309
322 */
323 temp8 = (u8) (linked_list->data.address16.resource_type & 0x03); 310 temp8 = (u8) (linked_list->data.address16.resource_type & 0x03);
324 *buffer = temp8; 311 *buffer = temp8;
325 buffer += 1; 312 buffer += 1;
326 313
327 /* 314 /* Set the general flags */
328 * Set the general flags 315
329 */
330 temp8 = (u8) (linked_list->data.address16.producer_consumer & 0x01); 316 temp8 = (u8) (linked_list->data.address16.producer_consumer & 0x01);
331 317
332 temp8 |= (linked_list->data.address16.decode & 0x01) << 1; 318 temp8 |= (linked_list->data.address16.decode & 0x01) << 1;
@@ -336,9 +322,8 @@ acpi_rs_address16_stream (
336 *buffer = temp8; 322 *buffer = temp8;
337 buffer += 1; 323 buffer += 1;
338 324
339 /* 325 /* Set the type specific flags */
340 * Set the type specific flags 326
341 */
342 temp8 = 0; 327 temp8 = 0;
343 328
344 if (ACPI_MEMORY_RANGE == linked_list->data.address16.resource_type) { 329 if (ACPI_MEMORY_RANGE == linked_list->data.address16.resource_type) {
@@ -362,39 +347,34 @@ acpi_rs_address16_stream (
362 *buffer = temp8; 347 *buffer = temp8;
363 buffer += 1; 348 buffer += 1;
364 349
365 /* 350 /* Set the address space granularity */
366 * Set the address space granularity 351
367 */
368 ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.address16.granularity); 352 ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.address16.granularity);
369 buffer += 2; 353 buffer += 2;
370 354
371 /* 355 /* Set the address range minimum */
372 * Set the address range minimum 356
373 */
374 ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.address16.min_address_range); 357 ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.address16.min_address_range);
375 buffer += 2; 358 buffer += 2;
376 359
377 /* 360 /* Set the address range maximum */
378 * Set the address range maximum 361
379 */
380 ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.address16.max_address_range); 362 ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.address16.max_address_range);
381 buffer += 2; 363 buffer += 2;
382 364
383 /* 365 /* Set the address translation offset */
384 * Set the address translation offset 366
385 */ 367 ACPI_MOVE_32_TO_16 (buffer,
386 ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.address16.address_translation_offset); 368 &linked_list->data.address16.address_translation_offset);
387 buffer += 2; 369 buffer += 2;
388 370
389 /* 371 /* Set the address length */
390 * Set the address length 372
391 */
392 ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.address16.address_length); 373 ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.address16.address_length);
393 buffer += 2; 374 buffer += 2;
394 375
395 /* 376 /* Resource Source Index and Resource Source are optional */
396 * Resource Source Index and Resource Source are optional 377
397 */
398 if (0 != linked_list->data.address16.resource_source.string_length) { 378 if (0 != linked_list->data.address16.resource_source.string_length) {
399 temp8 = (u8) linked_list->data.address16.resource_source.index; 379 temp8 = (u8) linked_list->data.address16.resource_source.index;
400 380
@@ -403,9 +383,8 @@ acpi_rs_address16_stream (
403 383
404 temp_pointer = (char *) buffer; 384 temp_pointer = (char *) buffer;
405 385
406 /* 386 /* Copy the string */
407 * Copy the string 387
408 */
409 ACPI_STRCPY (temp_pointer, 388 ACPI_STRCPY (temp_pointer,
410 linked_list->data.address16.resource_source.string_ptr); 389 linked_list->data.address16.resource_source.string_ptr);
411 390
@@ -413,12 +392,12 @@ acpi_rs_address16_stream (
413 * Buffer needs to be set to the length of the sting + one for the 392 * Buffer needs to be set to the length of the sting + one for the
414 * terminating null 393 * terminating null
415 */ 394 */
416 buffer += (acpi_size)(ACPI_STRLEN (linked_list->data.address16.resource_source.string_ptr) + 1); 395 buffer += (acpi_size)(ACPI_STRLEN (
396 linked_list->data.address16.resource_source.string_ptr) + 1);
417 } 397 }
418 398
419 /* 399 /* Return the number of bytes consumed in this operation */
420 * Return the number of bytes consumed in this operation 400
421 */
422 actual_bytes = ACPI_PTR_DIFF (buffer, *output_buffer); 401 actual_bytes = ACPI_PTR_DIFF (buffer, *output_buffer);
423 *bytes_consumed = actual_bytes; 402 *bytes_consumed = actual_bytes;
424 403
@@ -475,9 +454,8 @@ acpi_rs_address32_resource (
475 buffer = byte_stream_buffer; 454 buffer = byte_stream_buffer;
476 struct_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_address32); 455 struct_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_address32);
477 456
478 /* 457 /* Point past the Descriptor to get the number of bytes consumed */
479 * Point past the Descriptor to get the number of bytes consumed 458
480 */
481 buffer += 1; 459 buffer += 1;
482 ACPI_MOVE_16_TO_16 (&temp16, buffer); 460 ACPI_MOVE_16_TO_16 (&temp16, buffer);
483 461
@@ -490,9 +468,8 @@ acpi_rs_address32_resource (
490 *bytes_consumed = temp16 + 3; 468 *bytes_consumed = temp16 + 3;
491 output_struct->id = ACPI_RSTYPE_ADDRESS32; 469 output_struct->id = ACPI_RSTYPE_ADDRESS32;
492 470
493 /* 471 /* Get the Resource Type (Byte3) */
494 * Get the Resource Type (Byte3) 472
495 */
496 buffer += 2; 473 buffer += 2;
497 temp8 = *buffer; 474 temp8 = *buffer;
498 475
@@ -504,35 +481,29 @@ acpi_rs_address32_resource (
504 481
505 output_struct->data.address32.resource_type = temp8; 482 output_struct->data.address32.resource_type = temp8;
506 483
507 /* 484 /* Get the General Flags (Byte4) */
508 * Get the General Flags (Byte4) 485
509 */
510 buffer += 1; 486 buffer += 1;
511 temp8 = *buffer; 487 temp8 = *buffer;
512 488
513 /* 489 /* Producer / Consumer */
514 * Producer / Consumer 490
515 */
516 output_struct->data.address32.producer_consumer = temp8 & 0x01; 491 output_struct->data.address32.producer_consumer = temp8 & 0x01;
517 492
518 /* 493 /* Decode */
519 * Decode 494
520 */
521 output_struct->data.address32.decode = (temp8 >> 1) & 0x01; 495 output_struct->data.address32.decode = (temp8 >> 1) & 0x01;
522 496
523 /* 497 /* Min Address Fixed */
524 * Min Address Fixed 498
525 */
526 output_struct->data.address32.min_address_fixed = (temp8 >> 2) & 0x01; 499 output_struct->data.address32.min_address_fixed = (temp8 >> 2) & 0x01;
527 500
528 /* 501 /* Max Address Fixed */
529 * Max Address Fixed 502
530 */
531 output_struct->data.address32.max_address_fixed = (temp8 >> 3) & 0x01; 503 output_struct->data.address32.max_address_fixed = (temp8 >> 3) & 0x01;
532 504
533 /* 505 /* Get the Type Specific Flags (Byte5) */
534 * Get the Type Specific Flags (Byte5) 506
535 */
536 buffer += 1; 507 buffer += 1;
537 temp8 = *buffer; 508 temp8 = *buffer;
538 509
@@ -556,39 +527,34 @@ acpi_rs_address32_resource (
556 } 527 }
557 } 528 }
558 529
559 /* 530 /* Get Granularity (Bytes 6-9) */
560 * Get Granularity (Bytes 6-9) 531
561 */
562 buffer += 1; 532 buffer += 1;
563 ACPI_MOVE_32_TO_32 (&output_struct->data.address32.granularity, buffer); 533 ACPI_MOVE_32_TO_32 (&output_struct->data.address32.granularity, buffer);
564 534
565 /* 535 /* Get min_address_range (Bytes 10-13) */
566 * Get min_address_range (Bytes 10-13) 536
567 */
568 buffer += 4; 537 buffer += 4;
569 ACPI_MOVE_32_TO_32 (&output_struct->data.address32.min_address_range, buffer); 538 ACPI_MOVE_32_TO_32 (&output_struct->data.address32.min_address_range, buffer);
570 539
571 /* 540 /* Get max_address_range (Bytes 14-17) */
572 * Get max_address_range (Bytes 14-17) 541
573 */
574 buffer += 4; 542 buffer += 4;
575 ACPI_MOVE_32_TO_32 (&output_struct->data.address32.max_address_range, buffer); 543 ACPI_MOVE_32_TO_32 (&output_struct->data.address32.max_address_range, buffer);
576 544
577 /* 545 /* Get address_translation_offset (Bytes 18-21) */
578 * Get address_translation_offset (Bytes 18-21) 546
579 */
580 buffer += 4; 547 buffer += 4;
581 ACPI_MOVE_32_TO_32 (&output_struct->data.address32.address_translation_offset, buffer); 548 ACPI_MOVE_32_TO_32 (&output_struct->data.address32.address_translation_offset,
549 buffer);
550
551 /* Get address_length (Bytes 22-25) */
582 552
583 /*
584 * Get address_length (Bytes 22-25)
585 */
586 buffer += 4; 553 buffer += 4;
587 ACPI_MOVE_32_TO_32 (&output_struct->data.address32.address_length, buffer); 554 ACPI_MOVE_32_TO_32 (&output_struct->data.address32.address_length, buffer);
588 555
589 /* 556 /* Resource Source Index (if present) */
590 * Resource Source Index (if present) 557
591 */
592 buffer += 4; 558 buffer += 4;
593 559
594 /* 560 /*
@@ -615,7 +581,8 @@ acpi_rs_address32_resource (
615 output_struct->data.address32.resource_source.string_ptr = 581 output_struct->data.address32.resource_source.string_ptr =
616 (char *)((u8 *)output_struct + struct_size); 582 (char *)((u8 *)output_struct + struct_size);
617 583
618 temp_ptr = (u8 *) output_struct->data.address32.resource_source.string_ptr; 584 temp_ptr = (u8 *)
585 output_struct->data.address32.resource_source.string_ptr;
619 586
620 /* Copy the string into the buffer */ 587 /* Copy the string into the buffer */
621 588
@@ -628,9 +595,8 @@ acpi_rs_address32_resource (
628 index += 1; 595 index += 1;
629 } 596 }
630 597
631 /* 598 /* Add the terminating null */
632 * Add the terminating null 599
633 */
634 *temp_ptr = 0x00; 600 *temp_ptr = 0x00;
635 output_struct->data.address32.resource_source.string_length = index + 1; 601 output_struct->data.address32.resource_source.string_length = index + 1;
636 602
@@ -648,14 +614,12 @@ acpi_rs_address32_resource (
648 output_struct->data.address32.resource_source.string_ptr = NULL; 614 output_struct->data.address32.resource_source.string_ptr = NULL;
649 } 615 }
650 616
651 /* 617 /* Set the Length parameter */
652 * Set the Length parameter 618
653 */
654 output_struct->length = (u32) struct_size; 619 output_struct->length = (u32) struct_size;
655 620
656 /* 621 /* Return the final size of the structure */
657 * Return the final size of the structure 622
658 */
659 *structure_size = struct_size; 623 *structure_size = struct_size;
660 return_ACPI_STATUS (AE_OK); 624 return_ACPI_STATUS (AE_OK);
661} 625}
@@ -694,29 +658,25 @@ acpi_rs_address32_stream (
694 658
695 buffer = *output_buffer; 659 buffer = *output_buffer;
696 660
697 /* 661 /* The descriptor field is static */
698 * The descriptor field is static 662
699 */
700 *buffer = 0x87; 663 *buffer = 0x87;
701 buffer += 1; 664 buffer += 1;
702 665
703 /* 666 /* Set a pointer to the Length field - to be filled in later */
704 * Set a pointer to the Length field - to be filled in later 667
705 */
706 length_field = ACPI_CAST_PTR (u16, buffer); 668 length_field = ACPI_CAST_PTR (u16, buffer);
707 buffer += 2; 669 buffer += 2;
708 670
709 /* 671 /* Set the Resource Type (Memory, Io, bus_number) */
710 * Set the Resource Type (Memory, Io, bus_number) 672
711 */
712 temp8 = (u8) (linked_list->data.address32.resource_type & 0x03); 673 temp8 = (u8) (linked_list->data.address32.resource_type & 0x03);
713 674
714 *buffer = temp8; 675 *buffer = temp8;
715 buffer += 1; 676 buffer += 1;
716 677
717 /* 678 /* Set the general flags */
718 * Set the general flags 679
719 */
720 temp8 = (u8) (linked_list->data.address32.producer_consumer & 0x01); 680 temp8 = (u8) (linked_list->data.address32.producer_consumer & 0x01);
721 temp8 |= (linked_list->data.address32.decode & 0x01) << 1; 681 temp8 |= (linked_list->data.address32.decode & 0x01) << 1;
722 temp8 |= (linked_list->data.address32.min_address_fixed & 0x01) << 2; 682 temp8 |= (linked_list->data.address32.min_address_fixed & 0x01) << 2;
@@ -725,9 +685,8 @@ acpi_rs_address32_stream (
725 *buffer = temp8; 685 *buffer = temp8;
726 buffer += 1; 686 buffer += 1;
727 687
728 /* 688 /* Set the type specific flags */
729 * Set the type specific flags 689
730 */
731 temp8 = 0; 690 temp8 = 0;
732 691
733 if (ACPI_MEMORY_RANGE == linked_list->data.address32.resource_type) { 692 if (ACPI_MEMORY_RANGE == linked_list->data.address32.resource_type) {
@@ -751,39 +710,34 @@ acpi_rs_address32_stream (
751 *buffer = temp8; 710 *buffer = temp8;
752 buffer += 1; 711 buffer += 1;
753 712
754 /* 713 /* Set the address space granularity */
755 * Set the address space granularity 714
756 */
757 ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.address32.granularity); 715 ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.address32.granularity);
758 buffer += 4; 716 buffer += 4;
759 717
760 /* 718 /* Set the address range minimum */
761 * Set the address range minimum 719
762 */
763 ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.address32.min_address_range); 720 ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.address32.min_address_range);
764 buffer += 4; 721 buffer += 4;
765 722
766 /* 723 /* Set the address range maximum */
767 * Set the address range maximum 724
768 */
769 ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.address32.max_address_range); 725 ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.address32.max_address_range);
770 buffer += 4; 726 buffer += 4;
771 727
772 /* 728 /* Set the address translation offset */
773 * Set the address translation offset 729
774 */ 730 ACPI_MOVE_32_TO_32 (buffer,
775 ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.address32.address_translation_offset); 731 &linked_list->data.address32.address_translation_offset);
776 buffer += 4; 732 buffer += 4;
777 733
778 /* 734 /* Set the address length */
779 * Set the address length 735
780 */
781 ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.address32.address_length); 736 ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.address32.address_length);
782 buffer += 4; 737 buffer += 4;
783 738
784 /* 739 /* Resource Source Index and Resource Source are optional */
785 * Resource Source Index and Resource Source are optional 740
786 */
787 if (0 != linked_list->data.address32.resource_source.string_length) { 741 if (0 != linked_list->data.address32.resource_source.string_length) {
788 temp8 = (u8) linked_list->data.address32.resource_source.index; 742 temp8 = (u8) linked_list->data.address32.resource_source.index;
789 743
@@ -792,9 +746,8 @@ acpi_rs_address32_stream (
792 746
793 temp_pointer = (char *) buffer; 747 temp_pointer = (char *) buffer;
794 748
795 /* 749 /* Copy the string */
796 * Copy the string 750
797 */
798 ACPI_STRCPY (temp_pointer, 751 ACPI_STRCPY (temp_pointer,
799 linked_list->data.address32.resource_source.string_ptr); 752 linked_list->data.address32.resource_source.string_ptr);
800 753
@@ -802,12 +755,12 @@ acpi_rs_address32_stream (
802 * Buffer needs to be set to the length of the sting + one for the 755 * Buffer needs to be set to the length of the sting + one for the
803 * terminating null 756 * terminating null
804 */ 757 */
805 buffer += (acpi_size)(ACPI_STRLEN (linked_list->data.address32.resource_source.string_ptr) + 1); 758 buffer += (acpi_size)(ACPI_STRLEN (
759 linked_list->data.address32.resource_source.string_ptr) + 1);
806 } 760 }
807 761
808 /* 762 /* Return the number of bytes consumed in this operation */
809 * Return the number of bytes consumed in this operation 763
810 */
811 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer); 764 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
812 765
813 /* 766 /*
@@ -864,9 +817,8 @@ acpi_rs_address64_resource (
864 struct_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_address64); 817 struct_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_address64);
865 resource_type = *buffer; 818 resource_type = *buffer;
866 819
867 /* 820 /* Point past the Descriptor to get the number of bytes consumed */
868 * Point past the Descriptor to get the number of bytes consumed 821
869 */
870 buffer += 1; 822 buffer += 1;
871 ACPI_MOVE_16_TO_16 (&temp16, buffer); 823 ACPI_MOVE_16_TO_16 (&temp16, buffer);
872 824
@@ -879,9 +831,8 @@ acpi_rs_address64_resource (
879 *bytes_consumed = temp16 + 3; 831 *bytes_consumed = temp16 + 3;
880 output_struct->id = ACPI_RSTYPE_ADDRESS64; 832 output_struct->id = ACPI_RSTYPE_ADDRESS64;
881 833
882 /* 834 /* Get the Resource Type (Byte3) */
883 * Get the Resource Type (Byte3) 835
884 */
885 buffer += 2; 836 buffer += 2;
886 temp8 = *buffer; 837 temp8 = *buffer;
887 838
@@ -893,35 +844,29 @@ acpi_rs_address64_resource (
893 844
894 output_struct->data.address64.resource_type = temp8; 845 output_struct->data.address64.resource_type = temp8;
895 846
896 /* 847 /* Get the General Flags (Byte4) */
897 * Get the General Flags (Byte4) 848
898 */
899 buffer += 1; 849 buffer += 1;
900 temp8 = *buffer; 850 temp8 = *buffer;
901 851
902 /* 852 /* Producer / Consumer */
903 * Producer / Consumer 853
904 */
905 output_struct->data.address64.producer_consumer = temp8 & 0x01; 854 output_struct->data.address64.producer_consumer = temp8 & 0x01;
906 855
907 /* 856 /* Decode */
908 * Decode 857
909 */
910 output_struct->data.address64.decode = (temp8 >> 1) & 0x01; 858 output_struct->data.address64.decode = (temp8 >> 1) & 0x01;
911 859
912 /* 860 /* Min Address Fixed */
913 * Min Address Fixed 861
914 */
915 output_struct->data.address64.min_address_fixed = (temp8 >> 2) & 0x01; 862 output_struct->data.address64.min_address_fixed = (temp8 >> 2) & 0x01;
916 863
917 /* 864 /* Max Address Fixed */
918 * Max Address Fixed 865
919 */
920 output_struct->data.address64.max_address_fixed = (temp8 >> 3) & 0x01; 866 output_struct->data.address64.max_address_fixed = (temp8 >> 3) & 0x01;
921 867
922 /* 868 /* Get the Type Specific Flags (Byte5) */
923 * Get the Type Specific Flags (Byte5) 869
924 */
925 buffer += 1; 870 buffer += 1;
926 temp8 = *buffer; 871 temp8 = *buffer;
927 872
@@ -951,33 +896,29 @@ acpi_rs_address64_resource (
951 buffer += 2; 896 buffer += 2;
952 } 897 }
953 898
954 /* 899 /* Get Granularity (Bytes 6-13) or (Bytes 8-15) */
955 * Get Granularity (Bytes 6-13) or (Bytes 8-15) 900
956 */
957 buffer += 1; 901 buffer += 1;
958 ACPI_MOVE_64_TO_64 (&output_struct->data.address64.granularity, buffer); 902 ACPI_MOVE_64_TO_64 (&output_struct->data.address64.granularity, buffer);
959 903
960 /* 904 /* Get min_address_range (Bytes 14-21) or (Bytes 16-23) */
961 * Get min_address_range (Bytes 14-21) or (Bytes 16-23) 905
962 */
963 buffer += 8; 906 buffer += 8;
964 ACPI_MOVE_64_TO_64 (&output_struct->data.address64.min_address_range, buffer); 907 ACPI_MOVE_64_TO_64 (&output_struct->data.address64.min_address_range, buffer);
965 908
966 /* 909 /* Get max_address_range (Bytes 22-29) or (Bytes 24-31) */
967 * Get max_address_range (Bytes 22-29) or (Bytes 24-31) 910
968 */
969 buffer += 8; 911 buffer += 8;
970 ACPI_MOVE_64_TO_64 (&output_struct->data.address64.max_address_range, buffer); 912 ACPI_MOVE_64_TO_64 (&output_struct->data.address64.max_address_range, buffer);
971 913
972 /* 914 /* Get address_translation_offset (Bytes 30-37) or (Bytes 32-39) */
973 * Get address_translation_offset (Bytes 30-37) or (Bytes 32-39) 915
974 */
975 buffer += 8; 916 buffer += 8;
976 ACPI_MOVE_64_TO_64 (&output_struct->data.address64.address_translation_offset, buffer); 917 ACPI_MOVE_64_TO_64 (&output_struct->data.address64.address_translation_offset,
918 buffer);
919
920 /* Get address_length (Bytes 38-45) or (Bytes 40-47) */
977 921
978 /*
979 * Get address_length (Bytes 38-45) or (Bytes 40-47)
980 */
981 buffer += 8; 922 buffer += 8;
982 ACPI_MOVE_64_TO_64 (&output_struct->data.address64.address_length, buffer); 923 ACPI_MOVE_64_TO_64 (&output_struct->data.address64.address_length, buffer);
983 924
@@ -989,14 +930,15 @@ acpi_rs_address64_resource (
989 /* Get type_specific_attribute (Bytes 48-55) */ 930 /* Get type_specific_attribute (Bytes 48-55) */
990 931
991 buffer += 8; 932 buffer += 8;
992 ACPI_MOVE_64_TO_64 (&output_struct->data.address64.type_specific_attributes, buffer); 933 ACPI_MOVE_64_TO_64 (
934 &output_struct->data.address64.type_specific_attributes,
935 buffer);
993 } 936 }
994 else { 937 else {
995 output_struct->data.address64.type_specific_attributes = 0; 938 output_struct->data.address64.type_specific_attributes = 0;
996 939
997 /* 940 /* Resource Source Index (if present) */
998 * Resource Source Index (if present) 941
999 */
1000 buffer += 8; 942 buffer += 8;
1001 943
1002 /* 944 /*
@@ -1025,7 +967,8 @@ acpi_rs_address64_resource (
1025 output_struct->data.address64.resource_source.string_ptr = 967 output_struct->data.address64.resource_source.string_ptr =
1026 (char *)((u8 *)output_struct + struct_size); 968 (char *)((u8 *)output_struct + struct_size);
1027 969
1028 temp_ptr = (u8 *) output_struct->data.address64.resource_source.string_ptr; 970 temp_ptr = (u8 *)
971 output_struct->data.address64.resource_source.string_ptr;
1029 972
1030 /* Copy the string into the buffer */ 973 /* Copy the string into the buffer */
1031 974
@@ -1042,7 +985,8 @@ acpi_rs_address64_resource (
1042 * Add the terminating null 985 * Add the terminating null
1043 */ 986 */
1044 *temp_ptr = 0x00; 987 *temp_ptr = 0x00;
1045 output_struct->data.address64.resource_source.string_length = index + 1; 988 output_struct->data.address64.resource_source.string_length =
989 index + 1;
1046 990
1047 /* 991 /*
1048 * In order for the struct_size to fall on a 32-bit boundary, 992 * In order for the struct_size to fall on a 32-bit boundary,
@@ -1054,14 +998,12 @@ acpi_rs_address64_resource (
1054 } 998 }
1055 } 999 }
1056 1000
1057 /* 1001 /* Set the Length parameter */
1058 * Set the Length parameter 1002
1059 */
1060 output_struct->length = (u32) struct_size; 1003 output_struct->length = (u32) struct_size;
1061 1004
1062 /* 1005 /* Return the final size of the structure */
1063 * Return the final size of the structure 1006
1064 */
1065 *structure_size = struct_size; 1007 *structure_size = struct_size;
1066 return_ACPI_STATUS (AE_OK); 1008 return_ACPI_STATUS (AE_OK);
1067} 1009}
@@ -1100,29 +1042,25 @@ acpi_rs_address64_stream (
1100 1042
1101 buffer = *output_buffer; 1043 buffer = *output_buffer;
1102 1044
1103 /* 1045 /* The descriptor field is static */
1104 * The descriptor field is static 1046
1105 */
1106 *buffer = 0x8A; 1047 *buffer = 0x8A;
1107 buffer += 1; 1048 buffer += 1;
1108 1049
1109 /* 1050 /* Set a pointer to the Length field - to be filled in later */
1110 * Set a pointer to the Length field - to be filled in later 1051
1111 */
1112 length_field = ACPI_CAST_PTR (u16, buffer); 1052 length_field = ACPI_CAST_PTR (u16, buffer);
1113 buffer += 2; 1053 buffer += 2;
1114 1054
1115 /* 1055 /* Set the Resource Type (Memory, Io, bus_number) */
1116 * Set the Resource Type (Memory, Io, bus_number) 1056
1117 */
1118 temp8 = (u8) (linked_list->data.address64.resource_type & 0x03); 1057 temp8 = (u8) (linked_list->data.address64.resource_type & 0x03);
1119 1058
1120 *buffer = temp8; 1059 *buffer = temp8;
1121 buffer += 1; 1060 buffer += 1;
1122 1061
1123 /* 1062 /* Set the general flags */
1124 * Set the general flags 1063
1125 */
1126 temp8 = (u8) (linked_list->data.address64.producer_consumer & 0x01); 1064 temp8 = (u8) (linked_list->data.address64.producer_consumer & 0x01);
1127 temp8 |= (linked_list->data.address64.decode & 0x01) << 1; 1065 temp8 |= (linked_list->data.address64.decode & 0x01) << 1;
1128 temp8 |= (linked_list->data.address64.min_address_fixed & 0x01) << 2; 1066 temp8 |= (linked_list->data.address64.min_address_fixed & 0x01) << 2;
@@ -1131,9 +1069,8 @@ acpi_rs_address64_stream (
1131 *buffer = temp8; 1069 *buffer = temp8;
1132 buffer += 1; 1070 buffer += 1;
1133 1071
1134 /* 1072 /* Set the type specific flags */
1135 * Set the type specific flags 1073
1136 */
1137 temp8 = 0; 1074 temp8 = 0;
1138 1075
1139 if (ACPI_MEMORY_RANGE == linked_list->data.address64.resource_type) { 1076 if (ACPI_MEMORY_RANGE == linked_list->data.address64.resource_type) {
@@ -1157,39 +1094,34 @@ acpi_rs_address64_stream (
1157 *buffer = temp8; 1094 *buffer = temp8;
1158 buffer += 1; 1095 buffer += 1;
1159 1096
1160 /* 1097 /* Set the address space granularity */
1161 * Set the address space granularity 1098
1162 */
1163 ACPI_MOVE_64_TO_64 (buffer, &linked_list->data.address64.granularity); 1099 ACPI_MOVE_64_TO_64 (buffer, &linked_list->data.address64.granularity);
1164 buffer += 8; 1100 buffer += 8;
1165 1101
1166 /* 1102 /* Set the address range minimum */
1167 * Set the address range minimum 1103
1168 */
1169 ACPI_MOVE_64_TO_64 (buffer, &linked_list->data.address64.min_address_range); 1104 ACPI_MOVE_64_TO_64 (buffer, &linked_list->data.address64.min_address_range);
1170 buffer += 8; 1105 buffer += 8;
1171 1106
1172 /* 1107 /* Set the address range maximum */
1173 * Set the address range maximum 1108
1174 */
1175 ACPI_MOVE_64_TO_64 (buffer, &linked_list->data.address64.max_address_range); 1109 ACPI_MOVE_64_TO_64 (buffer, &linked_list->data.address64.max_address_range);
1176 buffer += 8; 1110 buffer += 8;
1177 1111
1178 /* 1112 /* Set the address translation offset */
1179 * Set the address translation offset 1113
1180 */ 1114 ACPI_MOVE_64_TO_64 (buffer,
1181 ACPI_MOVE_64_TO_64 (buffer, &linked_list->data.address64.address_translation_offset); 1115 &linked_list->data.address64.address_translation_offset);
1182 buffer += 8; 1116 buffer += 8;
1183 1117
1184 /* 1118 /* Set the address length */
1185 * Set the address length 1119
1186 */
1187 ACPI_MOVE_64_TO_64 (buffer, &linked_list->data.address64.address_length); 1120 ACPI_MOVE_64_TO_64 (buffer, &linked_list->data.address64.address_length);
1188 buffer += 8; 1121 buffer += 8;
1189 1122
1190 /* 1123 /* Resource Source Index and Resource Source are optional */
1191 * Resource Source Index and Resource Source are optional 1124
1192 */
1193 if (0 != linked_list->data.address64.resource_source.string_length) { 1125 if (0 != linked_list->data.address64.resource_source.string_length) {
1194 temp8 = (u8) linked_list->data.address64.resource_source.index; 1126 temp8 = (u8) linked_list->data.address64.resource_source.index;
1195 1127
@@ -1198,21 +1130,21 @@ acpi_rs_address64_stream (
1198 1130
1199 temp_pointer = (char *) buffer; 1131 temp_pointer = (char *) buffer;
1200 1132
1201 /* 1133 /* Copy the string */
1202 * Copy the string 1134
1203 */ 1135 ACPI_STRCPY (temp_pointer,
1204 ACPI_STRCPY (temp_pointer, linked_list->data.address64.resource_source.string_ptr); 1136 linked_list->data.address64.resource_source.string_ptr);
1205 1137
1206 /* 1138 /*
1207 * Buffer needs to be set to the length of the sting + one for the 1139 * Buffer needs to be set to the length of the sting + one for the
1208 * terminating null 1140 * terminating null
1209 */ 1141 */
1210 buffer += (acpi_size)(ACPI_STRLEN (linked_list->data.address64.resource_source.string_ptr) + 1); 1142 buffer += (acpi_size)(ACPI_STRLEN (
1143 linked_list->data.address64.resource_source.string_ptr) + 1);
1211 } 1144 }
1212 1145
1213 /* 1146 /* Return the number of bytes consumed in this operation */
1214 * Return the number of bytes consumed in this operation 1147
1215 */
1216 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer); 1148 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
1217 1149
1218 /* 1150 /*
diff --git a/drivers/acpi/resources/rscalc.c b/drivers/acpi/resources/rscalc.c
index 8a5f0a52371d..98176f2fcb5d 100644
--- a/drivers/acpi/resources/rscalc.c
+++ b/drivers/acpi/resources/rscalc.c
@@ -81,9 +81,8 @@ acpi_rs_get_byte_stream_length (
81 81
82 82
83 while (!done) { 83 while (!done) {
84 /* 84 /* Init the variable that will hold the size to add to the total. */
85 * Init the variable that will hold the size to add to the total. 85
86 */
87 segment_size = 0; 86 segment_size = 0;
88 87
89 switch (linked_list->id) { 88 switch (linked_list->id) {
@@ -196,7 +195,8 @@ acpi_rs_get_byte_stream_length (
196 segment_size = 16; 195 segment_size = 16;
197 196
198 if (linked_list->data.address16.resource_source.string_ptr) { 197 if (linked_list->data.address16.resource_source.string_ptr) {
199 segment_size += linked_list->data.address16.resource_source.string_length; 198 segment_size +=
199 linked_list->data.address16.resource_source.string_length;
200 segment_size++; 200 segment_size++;
201 } 201 }
202 break; 202 break;
@@ -212,7 +212,8 @@ acpi_rs_get_byte_stream_length (
212 segment_size = 26; 212 segment_size = 26;
213 213
214 if (linked_list->data.address32.resource_source.string_ptr) { 214 if (linked_list->data.address32.resource_source.string_ptr) {
215 segment_size += linked_list->data.address32.resource_source.string_length; 215 segment_size +=
216 linked_list->data.address32.resource_source.string_length;
216 segment_size++; 217 segment_size++;
217 } 218 }
218 break; 219 break;
@@ -227,7 +228,8 @@ acpi_rs_get_byte_stream_length (
227 segment_size = 46; 228 segment_size = 46;
228 229
229 if (linked_list->data.address64.resource_source.string_ptr) { 230 if (linked_list->data.address64.resource_source.string_ptr) {
230 segment_size += linked_list->data.address64.resource_source.string_length; 231 segment_size +=
232 linked_list->data.address64.resource_source.string_length;
231 segment_size++; 233 segment_size++;
232 } 234 }
233 break; 235 break;
@@ -241,38 +243,36 @@ acpi_rs_get_byte_stream_length (
241 * Index + the length of the null terminated string 243 * Index + the length of the null terminated string
242 * Resource Source + 1 for the null. 244 * Resource Source + 1 for the null.
243 */ 245 */
244 segment_size = 9 + 246 segment_size = 9 + (((acpi_size)
245 (((acpi_size) linked_list->data.extended_irq.number_of_interrupts - 1) * 4); 247 linked_list->data.extended_irq.number_of_interrupts - 1) * 4);
246 248
247 if (linked_list->data.extended_irq.resource_source.string_ptr) { 249 if (linked_list->data.extended_irq.resource_source.string_ptr) {
248 segment_size += linked_list->data.extended_irq.resource_source.string_length; 250 segment_size +=
251 linked_list->data.extended_irq.resource_source.string_length;
249 segment_size++; 252 segment_size++;
250 } 253 }
251 break; 254 break;
252 255
253 default: 256 default:
254 /* 257
255 * If we get here, everything is out of sync, exit with error 258 /* If we get here, everything is out of sync, exit with error */
256 */ 259
257 return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE); 260 return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE);
258 261
259 } /* switch (linked_list->Id) */ 262 } /* switch (linked_list->Id) */
260 263
261 /* 264 /* Update the total */
262 * Update the total 265
263 */
264 byte_stream_size_needed += segment_size; 266 byte_stream_size_needed += segment_size;
265 267
266 /* 268 /* Point to the next object */
267 * Point to the next object 269
268 */
269 linked_list = ACPI_PTR_ADD (struct acpi_resource, 270 linked_list = ACPI_PTR_ADD (struct acpi_resource,
270 linked_list, linked_list->length); 271 linked_list, linked_list->length);
271 } 272 }
272 273
273 /* 274 /* This is the data the caller needs */
274 * This is the data the caller needs 275
275 */
276 *size_needed = byte_stream_size_needed; 276 *size_needed = byte_stream_size_needed;
277 return_ACPI_STATUS (AE_OK); 277 return_ACPI_STATUS (AE_OK);
278} 278}
@@ -320,9 +320,8 @@ acpi_rs_get_list_length (
320 320
321 321
322 while (bytes_parsed < byte_stream_buffer_length) { 322 while (bytes_parsed < byte_stream_buffer_length) {
323 /* 323 /* The next byte in the stream is the resource type */
324 * The next byte in the stream is the resource type 324
325 */
326 resource_type = acpi_rs_get_resource_type (*byte_stream_buffer); 325 resource_type = acpi_rs_get_resource_type (*byte_stream_buffer);
327 326
328 switch (resource_type) { 327 switch (resource_type) {
@@ -346,9 +345,8 @@ acpi_rs_get_list_length (
346 ACPI_MOVE_16_TO_16 (&temp16, buffer); 345 ACPI_MOVE_16_TO_16 (&temp16, buffer);
347 bytes_consumed = temp16 + 3; 346 bytes_consumed = temp16 + 3;
348 347
349 /* 348 /* Ensure a 32-bit boundary for the structure */
350 * Ensure a 32-bit boundary for the structure 349
351 */
352 temp16 = (u16) ACPI_ROUND_UP_to_32_bITS (temp16); 350 temp16 = (u16) ACPI_ROUND_UP_to_32_bITS (temp16);
353 351
354 structure_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_vendor) + 352 structure_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_vendor) +
@@ -416,9 +414,8 @@ acpi_rs_get_list_length (
416 temp8 = 0; 414 temp8 = 0;
417 } 415 }
418 416
419 /* 417 /* Ensure a 64-bit boundary for the structure */
420 * Ensure a 64-bit boundary for the structure 418
421 */
422 temp8 = (u8) ACPI_ROUND_UP_to_64_bITS (temp8); 419 temp8 = (u8) ACPI_ROUND_UP_to_64_bITS (temp8);
423 420
424 structure_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_address64) + 421 structure_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_address64) +
@@ -452,9 +449,8 @@ acpi_rs_get_list_length (
452 temp8 = 0; 449 temp8 = 0;
453 } 450 }
454 451
455 /* 452 /* Ensure a 32-bit boundary for the structure */
456 * Ensure a 32-bit boundary for the structure 453
457 */
458 temp8 = (u8) ACPI_ROUND_UP_to_32_bITS (temp8); 454 temp8 = (u8) ACPI_ROUND_UP_to_32_bITS (temp8);
459 455
460 structure_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_address32) + 456 structure_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_address32) +
@@ -488,9 +484,8 @@ acpi_rs_get_list_length (
488 temp8 = 0; 484 temp8 = 0;
489 } 485 }
490 486
491 /* 487 /* Ensure a 32-bit boundary for the structure */
492 * Ensure a 32-bit boundary for the structure 488
493 */
494 temp8 = (u8) ACPI_ROUND_UP_to_32_bITS (temp8); 489 temp8 = (u8) ACPI_ROUND_UP_to_32_bITS (temp8);
495 490
496 structure_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_address16) + 491 structure_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_address16) +
@@ -537,9 +532,8 @@ acpi_rs_get_list_length (
537 temp8 = 0; 532 temp8 = 0;
538 } 533 }
539 534
540 /* 535 /* Ensure a 32-bit boundary for the structure */
541 * Ensure a 32-bit boundary for the structure 536
542 */
543 temp8 = (u8) ACPI_ROUND_UP_to_32_bITS (temp8); 537 temp8 = (u8) ACPI_ROUND_UP_to_32_bITS (temp8);
544 538
545 structure_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_ext_irq) + 539 structure_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_ext_irq) +
@@ -567,9 +561,8 @@ acpi_rs_get_list_length (
567 561
568 ++buffer; 562 ++buffer;
569 563
570 /* 564 /* Look at the number of bits set */
571 * Look at the number of bits set 565
572 */
573 ACPI_MOVE_16_TO_16 (&temp16, buffer); 566 ACPI_MOVE_16_TO_16 (&temp16, buffer);
574 567
575 for (index = 0; index < 16; index++) { 568 for (index = 0; index < 16; index++) {
@@ -596,9 +589,8 @@ acpi_rs_get_list_length (
596 589
597 ++buffer; 590 ++buffer;
598 591
599 /* 592 /* Look at the number of bits set */
600 * Look at the number of bits set 593
601 */
602 temp8 = *buffer; 594 temp8 = *buffer;
603 595
604 for(index = 0; index < 8; index++) { 596 for(index = 0; index < 8; index++) {
@@ -670,9 +662,8 @@ acpi_rs_get_list_length (
670 temp8 = (u8) (temp8 & 0x7); 662 temp8 = (u8) (temp8 & 0x7);
671 bytes_consumed = temp8 + 1; 663 bytes_consumed = temp8 + 1;
672 664
673 /* 665 /* Ensure a 32-bit boundary for the structure */
674 * Ensure a 32-bit boundary for the structure 666
675 */
676 temp8 = (u8) ACPI_ROUND_UP_to_32_bITS (temp8); 667 temp8 = (u8) ACPI_ROUND_UP_to_32_bITS (temp8);
677 structure_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_vendor) + 668 structure_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_vendor) +
678 (temp8 * sizeof (u8)); 669 (temp8 * sizeof (u8));
@@ -697,21 +688,18 @@ acpi_rs_get_list_length (
697 return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE); 688 return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE);
698 } 689 }
699 690
700 /* 691 /* Update the return value and counter */
701 * Update the return value and counter 692
702 */
703 buffer_size += (u32) ACPI_ALIGN_RESOURCE_SIZE (structure_size); 693 buffer_size += (u32) ACPI_ALIGN_RESOURCE_SIZE (structure_size);
704 bytes_parsed += bytes_consumed; 694 bytes_parsed += bytes_consumed;
705 695
706 /* 696 /* Set the byte stream to point to the next resource */
707 * Set the byte stream to point to the next resource 697
708 */
709 byte_stream_buffer += bytes_consumed; 698 byte_stream_buffer += bytes_consumed;
710 } 699 }
711 700
712 /* 701 /* This is the data the caller needs */
713 * This is the data the caller needs 702
714 */
715 *size_needed = buffer_size; 703 *size_needed = buffer_size;
716 return_ACPI_STATUS (AE_OK); 704 return_ACPI_STATUS (AE_OK);
717} 705}
@@ -767,9 +755,8 @@ acpi_rs_get_pci_routing_table_length (
767 top_object_list = package_object->package.elements; 755 top_object_list = package_object->package.elements;
768 756
769 for (index = 0; index < number_of_elements; index++) { 757 for (index = 0; index < number_of_elements; index++) {
770 /* 758 /* Dereference the sub-package */
771 * Dereference the sub-package 759
772 */
773 package_element = *top_object_list; 760 package_element = *top_object_list;
774 761
775 /* 762 /*
@@ -778,37 +765,40 @@ acpi_rs_get_pci_routing_table_length (
778 */ 765 */
779 sub_object_list = package_element->package.elements; 766 sub_object_list = package_element->package.elements;
780 767
781 /* 768 /* Scan the irq_table_elements for the Source Name String */
782 * Scan the irq_table_elements for the Source Name String 769
783 */
784 name_found = FALSE; 770 name_found = FALSE;
785 771
786 for (table_index = 0; table_index < 4 && !name_found; table_index++) { 772 for (table_index = 0; table_index < 4 && !name_found; table_index++) {
787 if ((ACPI_TYPE_STRING == ACPI_GET_OBJECT_TYPE (*sub_object_list)) || 773 if ((ACPI_TYPE_STRING ==
788 ((ACPI_TYPE_LOCAL_REFERENCE == ACPI_GET_OBJECT_TYPE (*sub_object_list)) && 774 ACPI_GET_OBJECT_TYPE (*sub_object_list)) ||
789 ((*sub_object_list)->reference.opcode == AML_INT_NAMEPATH_OP))) { 775
776 ((ACPI_TYPE_LOCAL_REFERENCE ==
777 ACPI_GET_OBJECT_TYPE (*sub_object_list)) &&
778
779 ((*sub_object_list)->reference.opcode ==
780 AML_INT_NAMEPATH_OP))) {
790 name_found = TRUE; 781 name_found = TRUE;
791 } 782 }
792 else { 783 else {
793 /* 784 /* Look at the next element */
794 * Look at the next element 785
795 */
796 sub_object_list++; 786 sub_object_list++;
797 } 787 }
798 } 788 }
799 789
800 temp_size_needed += (sizeof (struct acpi_pci_routing_table) - 4); 790 temp_size_needed += (sizeof (struct acpi_pci_routing_table) - 4);
801 791
802 /* 792 /* Was a String type found? */
803 * Was a String type found? 793
804 */
805 if (name_found) { 794 if (name_found) {
806 if (ACPI_GET_OBJECT_TYPE (*sub_object_list) == ACPI_TYPE_STRING) { 795 if (ACPI_GET_OBJECT_TYPE (*sub_object_list) == ACPI_TYPE_STRING) {
807 /* 796 /*
808 * The length String.Length field does not include the 797 * The length String.Length field does not include the
809 * terminating NULL, add 1 798 * terminating NULL, add 1
810 */ 799 */
811 temp_size_needed += ((acpi_size) (*sub_object_list)->string.length + 1); 800 temp_size_needed += ((acpi_size)
801 (*sub_object_list)->string.length + 1);
812 } 802 }
813 else { 803 else {
814 temp_size_needed += acpi_ns_get_pathname_length ( 804 temp_size_needed += acpi_ns_get_pathname_length (
@@ -827,14 +817,14 @@ acpi_rs_get_pci_routing_table_length (
827 817
828 temp_size_needed = ACPI_ROUND_UP_to_64_bITS (temp_size_needed); 818 temp_size_needed = ACPI_ROUND_UP_to_64_bITS (temp_size_needed);
829 819
830 /* 820 /* Point to the next union acpi_operand_object */
831 * Point to the next union acpi_operand_object 821
832 */
833 top_object_list++; 822 top_object_list++;
834 } 823 }
835 824
836 /* 825 /*
837 * Adding an extra element to the end of the list, essentially a NULL terminator 826 * Adding an extra element to the end of the list, essentially a
827 * NULL terminator
838 */ 828 */
839 *buffer_size_needed = temp_size_needed + sizeof (struct acpi_pci_routing_table); 829 *buffer_size_needed = temp_size_needed + sizeof (struct acpi_pci_routing_table);
840 return_ACPI_STATUS (AE_OK); 830 return_ACPI_STATUS (AE_OK);
diff --git a/drivers/acpi/resources/rscreate.c b/drivers/acpi/resources/rscreate.c
index a3a0cbfda68d..8e0eae0d50bb 100644
--- a/drivers/acpi/resources/rscreate.c
+++ b/drivers/acpi/resources/rscreate.c
@@ -87,9 +87,8 @@ acpi_rs_create_resource_list (
87 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "byte_stream_buffer = %p\n", 87 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "byte_stream_buffer = %p\n",
88 byte_stream_buffer)); 88 byte_stream_buffer));
89 89
90 /* 90 /* Params already validated, so we don't re-validate here */
91 * Params already validated, so we don't re-validate here 91
92 */
93 byte_stream_buffer_length = byte_stream_buffer->buffer.length; 92 byte_stream_buffer_length = byte_stream_buffer->buffer.length;
94 byte_stream_start = byte_stream_buffer->buffer.pointer; 93 byte_stream_start = byte_stream_buffer->buffer.pointer;
95 94
@@ -171,9 +170,8 @@ acpi_rs_create_pci_routing_table (
171 170
172 /* Params already validated, so we don't re-validate here */ 171 /* Params already validated, so we don't re-validate here */
173 172
174 /* 173 /* Get the required buffer length */
175 * Get the required buffer length 174
176 */
177 status = acpi_rs_get_pci_routing_table_length (package_object, 175 status = acpi_rs_get_pci_routing_table_length (package_object,
178 &buffer_size_needed); 176 &buffer_size_needed);
179 if (ACPI_FAILURE (status)) { 177 if (ACPI_FAILURE (status)) {
@@ -217,9 +215,8 @@ acpi_rs_create_pci_routing_table (
217 */ 215 */
218 user_prt->length = (sizeof (struct acpi_pci_routing_table) - 4); 216 user_prt->length = (sizeof (struct acpi_pci_routing_table) - 4);
219 217
220 /* 218 /* Each element of the top-level package must also be a package */
221 * Each element of the top-level package must also be a package 219
222 */
223 if (ACPI_GET_OBJECT_TYPE (*top_object_list) != ACPI_TYPE_PACKAGE) { 220 if (ACPI_GET_OBJECT_TYPE (*top_object_list) != ACPI_TYPE_PACKAGE) {
224 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 221 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
225 "(PRT[%X]) Need sub-package, found %s\n", 222 "(PRT[%X]) Need sub-package, found %s\n",
@@ -243,9 +240,8 @@ acpi_rs_create_pci_routing_table (
243 */ 240 */
244 sub_object_list = (*top_object_list)->package.elements; 241 sub_object_list = (*top_object_list)->package.elements;
245 242
246 /* 243 /* 1) First subobject: Dereference the PRT.Address */
247 * 1) First subobject: Dereference the PRT.Address 244
248 */
249 obj_desc = sub_object_list[0]; 245 obj_desc = sub_object_list[0];
250 if (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_INTEGER) { 246 if (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_INTEGER) {
251 user_prt->address = obj_desc->integer.value; 247 user_prt->address = obj_desc->integer.value;
@@ -257,9 +253,8 @@ acpi_rs_create_pci_routing_table (
257 return_ACPI_STATUS (AE_BAD_DATA); 253 return_ACPI_STATUS (AE_BAD_DATA);
258 } 254 }
259 255
260 /* 256 /* 2) Second subobject: Dereference the PRT.Pin */
261 * 2) Second subobject: Dereference the PRT.Pin 257
262 */
263 obj_desc = sub_object_list[1]; 258 obj_desc = sub_object_list[1];
264 if (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_INTEGER) { 259 if (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_INTEGER) {
265 user_prt->pin = (u32) obj_desc->integer.value; 260 user_prt->pin = (u32) obj_desc->integer.value;
@@ -271,9 +266,8 @@ acpi_rs_create_pci_routing_table (
271 return_ACPI_STATUS (AE_BAD_DATA); 266 return_ACPI_STATUS (AE_BAD_DATA);
272 } 267 }
273 268
274 /* 269 /* 3) Third subobject: Dereference the PRT.source_name */
275 * 3) Third subobject: Dereference the PRT.source_name 270
276 */
277 obj_desc = sub_object_list[2]; 271 obj_desc = sub_object_list[2];
278 switch (ACPI_GET_OBJECT_TYPE (obj_desc)) { 272 switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
279 case ACPI_TYPE_LOCAL_REFERENCE: 273 case ACPI_TYPE_LOCAL_REFERENCE:
@@ -296,7 +290,9 @@ acpi_rs_create_pci_routing_table (
296 290
297 status = acpi_ns_handle_to_pathname ((acpi_handle) node, &path_buffer); 291 status = acpi_ns_handle_to_pathname ((acpi_handle) node, &path_buffer);
298 292
299 user_prt->length += (u32) ACPI_STRLEN (user_prt->source) + 1; /* include null terminator */ 293 /* +1 to include null terminator */
294
295 user_prt->length += (u32) ACPI_STRLEN (user_prt->source) + 1;
300 break; 296 break;
301 297
302 298
@@ -304,8 +300,10 @@ acpi_rs_create_pci_routing_table (
304 300
305 ACPI_STRCPY (user_prt->source, obj_desc->string.pointer); 301 ACPI_STRCPY (user_prt->source, obj_desc->string.pointer);
306 302
307 /* Add to the Length field the length of the string (add 1 for terminator) */ 303 /*
308 304 * Add to the Length field the length of the string
305 * (add 1 for terminator)
306 */
309 user_prt->length += obj_desc->string.length + 1; 307 user_prt->length += obj_desc->string.length + 1;
310 break; 308 break;
311 309
@@ -333,9 +331,8 @@ acpi_rs_create_pci_routing_table (
333 331
334 user_prt->length = (u32) ACPI_ROUND_UP_to_64_bITS (user_prt->length); 332 user_prt->length = (u32) ACPI_ROUND_UP_to_64_bITS (user_prt->length);
335 333
336 /* 334 /* 4) Fourth subobject: Dereference the PRT.source_index */
337 * 4) Fourth subobject: Dereference the PRT.source_index 335
338 */
339 obj_desc = sub_object_list[3]; 336 obj_desc = sub_object_list[3];
340 if (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_INTEGER) { 337 if (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_INTEGER) {
341 user_prt->source_index = (u32) obj_desc->integer.value; 338 user_prt->source_index = (u32) obj_desc->integer.value;
diff --git a/drivers/acpi/resources/rsdump.c b/drivers/acpi/resources/rsdump.c
index eef1b1f2c685..1935dab2ab51 100644
--- a/drivers/acpi/resources/rsdump.c
+++ b/drivers/acpi/resources/rsdump.c
@@ -48,9 +48,62 @@
48#define _COMPONENT ACPI_RESOURCES 48#define _COMPONENT ACPI_RESOURCES
49 ACPI_MODULE_NAME ("rsdump") 49 ACPI_MODULE_NAME ("rsdump")
50 50
51/* Local prototypes */
51 52
52#if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER) 53static void
54acpi_rs_dump_irq (
55 union acpi_resource_data *data);
56
57static void
58acpi_rs_dump_address16 (
59 union acpi_resource_data *data);
60
61static void
62acpi_rs_dump_address32 (
63 union acpi_resource_data *data);
64
65static void
66acpi_rs_dump_address64 (
67 union acpi_resource_data *data);
68
69static void
70acpi_rs_dump_dma (
71 union acpi_resource_data *data);
72
73static void
74acpi_rs_dump_io (
75 union acpi_resource_data *data);
76
77static void
78acpi_rs_dump_extended_irq (
79 union acpi_resource_data *data);
53 80
81static void
82acpi_rs_dump_fixed_io (
83 union acpi_resource_data *data);
84
85static void
86acpi_rs_dump_fixed_memory32 (
87 union acpi_resource_data *data);
88
89static void
90acpi_rs_dump_memory24 (
91 union acpi_resource_data *data);
92
93static void
94acpi_rs_dump_memory32 (
95 union acpi_resource_data *data);
96
97static void
98acpi_rs_dump_start_depend_fns (
99 union acpi_resource_data *data);
100
101static void
102acpi_rs_dump_vendor_specific (
103 union acpi_resource_data *data);
104
105
106#if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
54/******************************************************************************* 107/*******************************************************************************
55 * 108 *
56 * FUNCTION: acpi_rs_dump_irq 109 * FUNCTION: acpi_rs_dump_irq
@@ -63,7 +116,7 @@
63 * 116 *
64 ******************************************************************************/ 117 ******************************************************************************/
65 118
66void 119static void
67acpi_rs_dump_irq ( 120acpi_rs_dump_irq (
68 union acpi_resource_data *data) 121 union acpi_resource_data *data)
69{ 122{
@@ -77,13 +130,13 @@ acpi_rs_dump_irq (
77 acpi_os_printf ("IRQ Resource\n"); 130 acpi_os_printf ("IRQ Resource\n");
78 131
79 acpi_os_printf (" %s Triggered\n", 132 acpi_os_printf (" %s Triggered\n",
80 ACPI_LEVEL_SENSITIVE == irq_data->edge_level ? "Level" : "Edge"); 133 ACPI_LEVEL_SENSITIVE == irq_data->edge_level ? "Level" : "Edge");
81 134
82 acpi_os_printf (" Active %s\n", 135 acpi_os_printf (" Active %s\n",
83 ACPI_ACTIVE_LOW == irq_data->active_high_low ? "Low" : "High"); 136 ACPI_ACTIVE_LOW == irq_data->active_high_low ? "Low" : "High");
84 137
85 acpi_os_printf (" %s\n", 138 acpi_os_printf (" %s\n",
86 ACPI_SHARED == irq_data->shared_exclusive ? "Shared" : "Exclusive"); 139 ACPI_SHARED == irq_data->shared_exclusive ? "Shared" : "Exclusive");
87 140
88 acpi_os_printf (" %X Interrupts ( ", irq_data->number_of_interrupts); 141 acpi_os_printf (" %X Interrupts ( ", irq_data->number_of_interrupts);
89 142
@@ -108,7 +161,7 @@ acpi_rs_dump_irq (
108 * 161 *
109 ******************************************************************************/ 162 ******************************************************************************/
110 163
111void 164static void
112acpi_rs_dump_dma ( 165acpi_rs_dump_dma (
113 union acpi_resource_data *data) 166 union acpi_resource_data *data)
114{ 167{
@@ -144,7 +197,7 @@ acpi_rs_dump_dma (
144 } 197 }
145 198
146 acpi_os_printf (" %sBus Master\n", 199 acpi_os_printf (" %sBus Master\n",
147 ACPI_BUS_MASTER == dma_data->bus_master ? "" : "Not a "); 200 ACPI_BUS_MASTER == dma_data->bus_master ? "" : "Not a ");
148 201
149 202
150 switch (dma_data->transfer) { 203 switch (dma_data->transfer) {
@@ -165,7 +218,8 @@ acpi_rs_dump_dma (
165 break; 218 break;
166 } 219 }
167 220
168 acpi_os_printf (" Number of Channels: %X ( ", dma_data->number_of_channels); 221 acpi_os_printf (" Number of Channels: %X ( ",
222 dma_data->number_of_channels);
169 223
170 for (index = 0; index < dma_data->number_of_channels; index++) { 224 for (index = 0; index < dma_data->number_of_channels; index++) {
171 acpi_os_printf ("%X ", dma_data->channels[index]); 225 acpi_os_printf ("%X ", dma_data->channels[index]);
@@ -188,7 +242,7 @@ acpi_rs_dump_dma (
188 * 242 *
189 ******************************************************************************/ 243 ******************************************************************************/
190 244
191void 245static void
192acpi_rs_dump_start_depend_fns ( 246acpi_rs_dump_start_depend_fns (
193 union acpi_resource_data *data) 247 union acpi_resource_data *data)
194{ 248{
@@ -232,8 +286,7 @@ acpi_rs_dump_start_depend_fns (
232 break; 286 break;
233 287
234 default: 288 default:
235 acpi_os_printf (" Invalid performance " 289 acpi_os_printf (" Invalid performance robustness preference\n");
236 "robustness preference\n");
237 break; 290 break;
238 } 291 }
239 292
@@ -253,7 +306,7 @@ acpi_rs_dump_start_depend_fns (
253 * 306 *
254 ******************************************************************************/ 307 ******************************************************************************/
255 308
256void 309static void
257acpi_rs_dump_io ( 310acpi_rs_dump_io (
258 union acpi_resource_data *data) 311 union acpi_resource_data *data)
259{ 312{
@@ -266,19 +319,15 @@ acpi_rs_dump_io (
266 acpi_os_printf ("Io Resource\n"); 319 acpi_os_printf ("Io Resource\n");
267 320
268 acpi_os_printf (" %d bit decode\n", 321 acpi_os_printf (" %d bit decode\n",
269 ACPI_DECODE_16 == io_data->io_decode ? 16 : 10); 322 ACPI_DECODE_16 == io_data->io_decode ? 16 : 10);
270 323
271 acpi_os_printf (" Range minimum base: %08X\n", 324 acpi_os_printf (" Range minimum base: %08X\n", io_data->min_base_address);
272 io_data->min_base_address);
273 325
274 acpi_os_printf (" Range maximum base: %08X\n", 326 acpi_os_printf (" Range maximum base: %08X\n", io_data->max_base_address);
275 io_data->max_base_address);
276 327
277 acpi_os_printf (" Alignment: %08X\n", 328 acpi_os_printf (" Alignment: %08X\n", io_data->alignment);
278 io_data->alignment);
279 329
280 acpi_os_printf (" Range Length: %08X\n", 330 acpi_os_printf (" Range Length: %08X\n", io_data->range_length);
281 io_data->range_length);
282 331
283 return; 332 return;
284} 333}
@@ -296,7 +345,7 @@ acpi_rs_dump_io (
296 * 345 *
297 ******************************************************************************/ 346 ******************************************************************************/
298 347
299void 348static void
300acpi_rs_dump_fixed_io ( 349acpi_rs_dump_fixed_io (
301 union acpi_resource_data *data) 350 union acpi_resource_data *data)
302{ 351{
@@ -307,11 +356,9 @@ acpi_rs_dump_fixed_io (
307 356
308 357
309 acpi_os_printf ("Fixed Io Resource\n"); 358 acpi_os_printf ("Fixed Io Resource\n");
310 acpi_os_printf (" Range base address: %08X", 359 acpi_os_printf (" Range base address: %08X", fixed_io_data->base_address);
311 fixed_io_data->base_address);
312 360
313 acpi_os_printf (" Range length: %08X", 361 acpi_os_printf (" Range length: %08X", fixed_io_data->range_length);
314 fixed_io_data->range_length);
315 362
316 return; 363 return;
317} 364}
@@ -329,7 +376,7 @@ acpi_rs_dump_fixed_io (
329 * 376 *
330 ******************************************************************************/ 377 ******************************************************************************/
331 378
332void 379static void
333acpi_rs_dump_vendor_specific ( 380acpi_rs_dump_vendor_specific (
334 union acpi_resource_data *data) 381 union acpi_resource_data *data)
335{ 382{
@@ -346,7 +393,7 @@ acpi_rs_dump_vendor_specific (
346 393
347 for (index = 0; index < vendor_data->length; index++) { 394 for (index = 0; index < vendor_data->length; index++) {
348 acpi_os_printf (" Byte %X: %08X\n", 395 acpi_os_printf (" Byte %X: %08X\n",
349 index, vendor_data->reserved[index]); 396 index, vendor_data->reserved[index]);
350 } 397 }
351 398
352 return; 399 return;
@@ -365,7 +412,7 @@ acpi_rs_dump_vendor_specific (
365 * 412 *
366 ******************************************************************************/ 413 ******************************************************************************/
367 414
368void 415static void
369acpi_rs_dump_memory24 ( 416acpi_rs_dump_memory24 (
370 union acpi_resource_data *data) 417 union acpi_resource_data *data)
371{ 418{
@@ -378,21 +425,19 @@ acpi_rs_dump_memory24 (
378 acpi_os_printf ("24-Bit Memory Range Resource\n"); 425 acpi_os_printf ("24-Bit Memory Range Resource\n");
379 426
380 acpi_os_printf (" Read%s\n", 427 acpi_os_printf (" Read%s\n",
381 ACPI_READ_WRITE_MEMORY == 428 ACPI_READ_WRITE_MEMORY ==
382 memory24_data->read_write_attribute ? 429 memory24_data->read_write_attribute ?
383 "/Write" : " only"); 430 "/Write" : " only");
384 431
385 acpi_os_printf (" Range minimum base: %08X\n", 432 acpi_os_printf (" Range minimum base: %08X\n",
386 memory24_data->min_base_address); 433 memory24_data->min_base_address);
387 434
388 acpi_os_printf (" Range maximum base: %08X\n", 435 acpi_os_printf (" Range maximum base: %08X\n",
389 memory24_data->max_base_address); 436 memory24_data->max_base_address);
390 437
391 acpi_os_printf (" Alignment: %08X\n", 438 acpi_os_printf (" Alignment: %08X\n", memory24_data->alignment);
392 memory24_data->alignment);
393 439
394 acpi_os_printf (" Range length: %08X\n", 440 acpi_os_printf (" Range length: %08X\n", memory24_data->range_length);
395 memory24_data->range_length);
396 441
397 return; 442 return;
398} 443}
@@ -410,7 +455,7 @@ acpi_rs_dump_memory24 (
410 * 455 *
411 ******************************************************************************/ 456 ******************************************************************************/
412 457
413void 458static void
414acpi_rs_dump_memory32 ( 459acpi_rs_dump_memory32 (
415 union acpi_resource_data *data) 460 union acpi_resource_data *data)
416{ 461{
@@ -423,21 +468,19 @@ acpi_rs_dump_memory32 (
423 acpi_os_printf ("32-Bit Memory Range Resource\n"); 468 acpi_os_printf ("32-Bit Memory Range Resource\n");
424 469
425 acpi_os_printf (" Read%s\n", 470 acpi_os_printf (" Read%s\n",
426 ACPI_READ_WRITE_MEMORY == 471 ACPI_READ_WRITE_MEMORY ==
427 memory32_data->read_write_attribute ? 472 memory32_data->read_write_attribute ?
428 "/Write" : " only"); 473 "/Write" : " only");
429 474
430 acpi_os_printf (" Range minimum base: %08X\n", 475 acpi_os_printf (" Range minimum base: %08X\n",
431 memory32_data->min_base_address); 476 memory32_data->min_base_address);
432 477
433 acpi_os_printf (" Range maximum base: %08X\n", 478 acpi_os_printf (" Range maximum base: %08X\n",
434 memory32_data->max_base_address); 479 memory32_data->max_base_address);
435 480
436 acpi_os_printf (" Alignment: %08X\n", 481 acpi_os_printf (" Alignment: %08X\n", memory32_data->alignment);
437 memory32_data->alignment);
438 482
439 acpi_os_printf (" Range length: %08X\n", 483 acpi_os_printf (" Range length: %08X\n", memory32_data->range_length);
440 memory32_data->range_length);
441 484
442 return; 485 return;
443} 486}
@@ -455,11 +498,12 @@ acpi_rs_dump_memory32 (
455 * 498 *
456 ******************************************************************************/ 499 ******************************************************************************/
457 500
458void 501static void
459acpi_rs_dump_fixed_memory32 ( 502acpi_rs_dump_fixed_memory32 (
460 union acpi_resource_data *data) 503 union acpi_resource_data *data)
461{ 504{
462 struct acpi_resource_fixed_mem32 *fixed_memory32_data = (struct acpi_resource_fixed_mem32 *) data; 505 struct acpi_resource_fixed_mem32 *fixed_memory32_data =
506 (struct acpi_resource_fixed_mem32 *) data;
463 507
464 508
465 ACPI_FUNCTION_ENTRY (); 509 ACPI_FUNCTION_ENTRY ();
@@ -468,15 +512,14 @@ acpi_rs_dump_fixed_memory32 (
468 acpi_os_printf ("32-Bit Fixed Location Memory Range Resource\n"); 512 acpi_os_printf ("32-Bit Fixed Location Memory Range Resource\n");
469 513
470 acpi_os_printf (" Read%s\n", 514 acpi_os_printf (" Read%s\n",
471 ACPI_READ_WRITE_MEMORY == 515 ACPI_READ_WRITE_MEMORY ==
472 fixed_memory32_data->read_write_attribute ? 516 fixed_memory32_data->read_write_attribute ? "/Write" : " Only");
473 "/Write" : " Only");
474 517
475 acpi_os_printf (" Range base address: %08X\n", 518 acpi_os_printf (" Range base address: %08X\n",
476 fixed_memory32_data->range_base_address); 519 fixed_memory32_data->range_base_address);
477 520
478 acpi_os_printf (" Range length: %08X\n", 521 acpi_os_printf (" Range length: %08X\n",
479 fixed_memory32_data->range_length); 522 fixed_memory32_data->range_length);
480 523
481 return; 524 return;
482} 525}
@@ -494,7 +537,7 @@ acpi_rs_dump_fixed_memory32 (
494 * 537 *
495 ******************************************************************************/ 538 ******************************************************************************/
496 539
497void 540static void
498acpi_rs_dump_address16 ( 541acpi_rs_dump_address16 (
499 union acpi_resource_data *data) 542 union acpi_resource_data *data)
500{ 543{
@@ -514,35 +557,30 @@ acpi_rs_dump_address16 (
514 557
515 switch (address16_data->attribute.memory.cache_attribute) { 558 switch (address16_data->attribute.memory.cache_attribute) {
516 case ACPI_NON_CACHEABLE_MEMORY: 559 case ACPI_NON_CACHEABLE_MEMORY:
517 acpi_os_printf (" Type Specific: " 560 acpi_os_printf (" Type Specific: Noncacheable memory\n");
518 "Noncacheable memory\n");
519 break; 561 break;
520 562
521 case ACPI_CACHABLE_MEMORY: 563 case ACPI_CACHABLE_MEMORY:
522 acpi_os_printf (" Type Specific: " 564 acpi_os_printf (" Type Specific: Cacheable memory\n");
523 "Cacheable memory\n");
524 break; 565 break;
525 566
526 case ACPI_WRITE_COMBINING_MEMORY: 567 case ACPI_WRITE_COMBINING_MEMORY:
527 acpi_os_printf (" Type Specific: " 568 acpi_os_printf (" Type Specific: Write-combining memory\n");
528 "Write-combining memory\n");
529 break; 569 break;
530 570
531 case ACPI_PREFETCHABLE_MEMORY: 571 case ACPI_PREFETCHABLE_MEMORY:
532 acpi_os_printf (" Type Specific: " 572 acpi_os_printf (" Type Specific: Prefetchable memory\n");
533 "Prefetchable memory\n");
534 break; 573 break;
535 574
536 default: 575 default:
537 acpi_os_printf (" Type Specific: " 576 acpi_os_printf (" Type Specific: Invalid cache attribute\n");
538 "Invalid cache attribute\n");
539 break; 577 break;
540 } 578 }
541 579
542 acpi_os_printf (" Type Specific: Read%s\n", 580 acpi_os_printf (" Type Specific: Read%s\n",
543 ACPI_READ_WRITE_MEMORY == 581 ACPI_READ_WRITE_MEMORY ==
544 address16_data->attribute.memory.read_write_attribute ? 582 address16_data->attribute.memory.read_write_attribute ?
545 "/Write" : " Only"); 583 "/Write" : " Only");
546 break; 584 break;
547 585
548 case ACPI_IO_RANGE: 586 case ACPI_IO_RANGE:
@@ -551,30 +589,26 @@ acpi_rs_dump_address16 (
551 589
552 switch (address16_data->attribute.io.range_attribute) { 590 switch (address16_data->attribute.io.range_attribute) {
553 case ACPI_NON_ISA_ONLY_RANGES: 591 case ACPI_NON_ISA_ONLY_RANGES:
554 acpi_os_printf (" Type Specific: " 592 acpi_os_printf (" Type Specific: Non-ISA Io Addresses\n");
555 "Non-ISA Io Addresses\n");
556 break; 593 break;
557 594
558 case ACPI_ISA_ONLY_RANGES: 595 case ACPI_ISA_ONLY_RANGES:
559 acpi_os_printf (" Type Specific: " 596 acpi_os_printf (" Type Specific: ISA Io Addresses\n");
560 "ISA Io Addresses\n");
561 break; 597 break;
562 598
563 case ACPI_ENTIRE_RANGE: 599 case ACPI_ENTIRE_RANGE:
564 acpi_os_printf (" Type Specific: " 600 acpi_os_printf (" Type Specific: ISA and non-ISA Io Addresses\n");
565 "ISA and non-ISA Io Addresses\n");
566 break; 601 break;
567 602
568 default: 603 default:
569 acpi_os_printf (" Type Specific: " 604 acpi_os_printf (" Type Specific: Invalid range attribute\n");
570 "Invalid range attribute\n");
571 break; 605 break;
572 } 606 }
573 607
574 acpi_os_printf (" Type Specific: %s Translation\n", 608 acpi_os_printf (" Type Specific: %s Translation\n",
575 ACPI_SPARSE_TRANSLATION == 609 ACPI_SPARSE_TRANSLATION ==
576 address16_data->attribute.io.translation_attribute ? 610 address16_data->attribute.io.translation_attribute ?
577 "Sparse" : "Dense"); 611 "Sparse" : "Dense");
578 break; 612 break;
579 613
580 case ACPI_BUS_NUMBER_RANGE: 614 case ACPI_BUS_NUMBER_RANGE:
@@ -589,41 +623,42 @@ acpi_rs_dump_address16 (
589 } 623 }
590 624
591 acpi_os_printf (" Resource %s\n", 625 acpi_os_printf (" Resource %s\n",
592 ACPI_CONSUMER == address16_data->producer_consumer ? 626 ACPI_CONSUMER == address16_data->producer_consumer ?
593 "Consumer" : "Producer"); 627 "Consumer" : "Producer");
594 628
595 acpi_os_printf (" %s decode\n", 629 acpi_os_printf (" %s decode\n",
596 ACPI_SUB_DECODE == address16_data->decode ? 630 ACPI_SUB_DECODE == address16_data->decode ?
597 "Subtractive" : "Positive"); 631 "Subtractive" : "Positive");
598 632
599 acpi_os_printf (" Min address is %s fixed\n", 633 acpi_os_printf (" Min address is %s fixed\n",
600 ACPI_ADDRESS_FIXED == address16_data->min_address_fixed ? 634 ACPI_ADDRESS_FIXED == address16_data->min_address_fixed ?
601 "" : "not"); 635 "" : "not");
602 636
603 acpi_os_printf (" Max address is %s fixed\n", 637 acpi_os_printf (" Max address is %s fixed\n",
604 ACPI_ADDRESS_FIXED == address16_data->max_address_fixed ? 638 ACPI_ADDRESS_FIXED == address16_data->max_address_fixed ?
605 "" : "not"); 639 "" : "not");
606 640
607 acpi_os_printf (" Granularity: %08X\n", 641 acpi_os_printf (" Granularity: %08X\n",
608 address16_data->granularity); 642 address16_data->granularity);
609 643
610 acpi_os_printf (" Address range min: %08X\n", 644 acpi_os_printf (" Address range min: %08X\n",
611 address16_data->min_address_range); 645 address16_data->min_address_range);
612 646
613 acpi_os_printf (" Address range max: %08X\n", 647 acpi_os_printf (" Address range max: %08X\n",
614 address16_data->max_address_range); 648 address16_data->max_address_range);
615 649
616 acpi_os_printf (" Address translation offset: %08X\n", 650 acpi_os_printf (" Address translation offset: %08X\n",
617 address16_data->address_translation_offset); 651 address16_data->address_translation_offset);
618 652
619 acpi_os_printf (" Address Length: %08X\n", 653 acpi_os_printf (" Address Length: %08X\n",
620 address16_data->address_length); 654 address16_data->address_length);
621 655
622 if (0xFF != address16_data->resource_source.index) { 656 if (0xFF != address16_data->resource_source.index) {
623 acpi_os_printf (" Resource Source Index: %X\n", 657 acpi_os_printf (" Resource Source Index: %X\n",
624 address16_data->resource_source.index); 658 address16_data->resource_source.index);
659
625 acpi_os_printf (" Resource Source: %s\n", 660 acpi_os_printf (" Resource Source: %s\n",
626 address16_data->resource_source.string_ptr); 661 address16_data->resource_source.string_ptr);
627 } 662 }
628 663
629 return; 664 return;
@@ -642,7 +677,7 @@ acpi_rs_dump_address16 (
642 * 677 *
643 ******************************************************************************/ 678 ******************************************************************************/
644 679
645void 680static void
646acpi_rs_dump_address32 ( 681acpi_rs_dump_address32 (
647 union acpi_resource_data *data) 682 union acpi_resource_data *data)
648{ 683{
@@ -661,35 +696,30 @@ acpi_rs_dump_address32 (
661 696
662 switch (address32_data->attribute.memory.cache_attribute) { 697 switch (address32_data->attribute.memory.cache_attribute) {
663 case ACPI_NON_CACHEABLE_MEMORY: 698 case ACPI_NON_CACHEABLE_MEMORY:
664 acpi_os_printf (" Type Specific: " 699 acpi_os_printf (" Type Specific: Noncacheable memory\n");
665 "Noncacheable memory\n");
666 break; 700 break;
667 701
668 case ACPI_CACHABLE_MEMORY: 702 case ACPI_CACHABLE_MEMORY:
669 acpi_os_printf (" Type Specific: " 703 acpi_os_printf (" Type Specific: Cacheable memory\n");
670 "Cacheable memory\n");
671 break; 704 break;
672 705
673 case ACPI_WRITE_COMBINING_MEMORY: 706 case ACPI_WRITE_COMBINING_MEMORY:
674 acpi_os_printf (" Type Specific: " 707 acpi_os_printf (" Type Specific: Write-combining memory\n");
675 "Write-combining memory\n");
676 break; 708 break;
677 709
678 case ACPI_PREFETCHABLE_MEMORY: 710 case ACPI_PREFETCHABLE_MEMORY:
679 acpi_os_printf (" Type Specific: " 711 acpi_os_printf (" Type Specific: Prefetchable memory\n");
680 "Prefetchable memory\n");
681 break; 712 break;
682 713
683 default: 714 default:
684 acpi_os_printf (" Type Specific: " 715 acpi_os_printf (" Type Specific: Invalid cache attribute\n");
685 "Invalid cache attribute\n");
686 break; 716 break;
687 } 717 }
688 718
689 acpi_os_printf (" Type Specific: Read%s\n", 719 acpi_os_printf (" Type Specific: Read%s\n",
690 ACPI_READ_WRITE_MEMORY == 720 ACPI_READ_WRITE_MEMORY ==
691 address32_data->attribute.memory.read_write_attribute ? 721 address32_data->attribute.memory.read_write_attribute ?
692 "/Write" : " Only"); 722 "/Write" : " Only");
693 break; 723 break;
694 724
695 case ACPI_IO_RANGE: 725 case ACPI_IO_RANGE:
@@ -698,30 +728,26 @@ acpi_rs_dump_address32 (
698 728
699 switch (address32_data->attribute.io.range_attribute) { 729 switch (address32_data->attribute.io.range_attribute) {
700 case ACPI_NON_ISA_ONLY_RANGES: 730 case ACPI_NON_ISA_ONLY_RANGES:
701 acpi_os_printf (" Type Specific: " 731 acpi_os_printf (" Type Specific: Non-ISA Io Addresses\n");
702 "Non-ISA Io Addresses\n");
703 break; 732 break;
704 733
705 case ACPI_ISA_ONLY_RANGES: 734 case ACPI_ISA_ONLY_RANGES:
706 acpi_os_printf (" Type Specific: " 735 acpi_os_printf (" Type Specific: ISA Io Addresses\n");
707 "ISA Io Addresses\n");
708 break; 736 break;
709 737
710 case ACPI_ENTIRE_RANGE: 738 case ACPI_ENTIRE_RANGE:
711 acpi_os_printf (" Type Specific: " 739 acpi_os_printf (" Type Specific: ISA and non-ISA Io Addresses\n");
712 "ISA and non-ISA Io Addresses\n");
713 break; 740 break;
714 741
715 default: 742 default:
716 acpi_os_printf (" Type Specific: " 743 acpi_os_printf (" Type Specific: Invalid Range attribute");
717 "Invalid Range attribute");
718 break; 744 break;
719 } 745 }
720 746
721 acpi_os_printf (" Type Specific: %s Translation\n", 747 acpi_os_printf (" Type Specific: %s Translation\n",
722 ACPI_SPARSE_TRANSLATION == 748 ACPI_SPARSE_TRANSLATION ==
723 address32_data->attribute.io.translation_attribute ? 749 address32_data->attribute.io.translation_attribute ?
724 "Sparse" : "Dense"); 750 "Sparse" : "Dense");
725 break; 751 break;
726 752
727 case ACPI_BUS_NUMBER_RANGE: 753 case ACPI_BUS_NUMBER_RANGE:
@@ -731,46 +757,48 @@ acpi_rs_dump_address32 (
731 757
732 default: 758 default:
733 759
734 acpi_os_printf (" Resource Type: 0x%2.2X\n", address32_data->resource_type); 760 acpi_os_printf (" Resource Type: 0x%2.2X\n",
761 address32_data->resource_type);
735 break; 762 break;
736 } 763 }
737 764
738 acpi_os_printf (" Resource %s\n", 765 acpi_os_printf (" Resource %s\n",
739 ACPI_CONSUMER == address32_data->producer_consumer ? 766 ACPI_CONSUMER == address32_data->producer_consumer ?
740 "Consumer" : "Producer"); 767 "Consumer" : "Producer");
741 768
742 acpi_os_printf (" %s decode\n", 769 acpi_os_printf (" %s decode\n",
743 ACPI_SUB_DECODE == address32_data->decode ? 770 ACPI_SUB_DECODE == address32_data->decode ?
744 "Subtractive" : "Positive"); 771 "Subtractive" : "Positive");
745 772
746 acpi_os_printf (" Min address is %s fixed\n", 773 acpi_os_printf (" Min address is %s fixed\n",
747 ACPI_ADDRESS_FIXED == address32_data->min_address_fixed ? 774 ACPI_ADDRESS_FIXED == address32_data->min_address_fixed ?
748 "" : "not "); 775 "" : "not ");
749 776
750 acpi_os_printf (" Max address is %s fixed\n", 777 acpi_os_printf (" Max address is %s fixed\n",
751 ACPI_ADDRESS_FIXED == address32_data->max_address_fixed ? 778 ACPI_ADDRESS_FIXED == address32_data->max_address_fixed ?
752 "" : "not "); 779 "" : "not ");
753 780
754 acpi_os_printf (" Granularity: %08X\n", 781 acpi_os_printf (" Granularity: %08X\n",
755 address32_data->granularity); 782 address32_data->granularity);
756 783
757 acpi_os_printf (" Address range min: %08X\n", 784 acpi_os_printf (" Address range min: %08X\n",
758 address32_data->min_address_range); 785 address32_data->min_address_range);
759 786
760 acpi_os_printf (" Address range max: %08X\n", 787 acpi_os_printf (" Address range max: %08X\n",
761 address32_data->max_address_range); 788 address32_data->max_address_range);
762 789
763 acpi_os_printf (" Address translation offset: %08X\n", 790 acpi_os_printf (" Address translation offset: %08X\n",
764 address32_data->address_translation_offset); 791 address32_data->address_translation_offset);
765 792
766 acpi_os_printf (" Address Length: %08X\n", 793 acpi_os_printf (" Address Length: %08X\n",
767 address32_data->address_length); 794 address32_data->address_length);
768 795
769 if(0xFF != address32_data->resource_source.index) { 796 if(0xFF != address32_data->resource_source.index) {
770 acpi_os_printf (" Resource Source Index: %X\n", 797 acpi_os_printf (" Resource Source Index: %X\n",
771 address32_data->resource_source.index); 798 address32_data->resource_source.index);
799
772 acpi_os_printf (" Resource Source: %s\n", 800 acpi_os_printf (" Resource Source: %s\n",
773 address32_data->resource_source.string_ptr); 801 address32_data->resource_source.string_ptr);
774 } 802 }
775 803
776 return; 804 return;
@@ -789,7 +817,7 @@ acpi_rs_dump_address32 (
789 * 817 *
790 ******************************************************************************/ 818 ******************************************************************************/
791 819
792void 820static void
793acpi_rs_dump_address64 ( 821acpi_rs_dump_address64 (
794 union acpi_resource_data *data) 822 union acpi_resource_data *data)
795{ 823{
@@ -808,35 +836,30 @@ acpi_rs_dump_address64 (
808 836
809 switch (address64_data->attribute.memory.cache_attribute) { 837 switch (address64_data->attribute.memory.cache_attribute) {
810 case ACPI_NON_CACHEABLE_MEMORY: 838 case ACPI_NON_CACHEABLE_MEMORY:
811 acpi_os_printf (" Type Specific: " 839 acpi_os_printf (" Type Specific: Noncacheable memory\n");
812 "Noncacheable memory\n");
813 break; 840 break;
814 841
815 case ACPI_CACHABLE_MEMORY: 842 case ACPI_CACHABLE_MEMORY:
816 acpi_os_printf (" Type Specific: " 843 acpi_os_printf (" Type Specific: Cacheable memory\n");
817 "Cacheable memory\n");
818 break; 844 break;
819 845
820 case ACPI_WRITE_COMBINING_MEMORY: 846 case ACPI_WRITE_COMBINING_MEMORY:
821 acpi_os_printf (" Type Specific: " 847 acpi_os_printf (" Type Specific: Write-combining memory\n");
822 "Write-combining memory\n");
823 break; 848 break;
824 849
825 case ACPI_PREFETCHABLE_MEMORY: 850 case ACPI_PREFETCHABLE_MEMORY:
826 acpi_os_printf (" Type Specific: " 851 acpi_os_printf (" Type Specific: Prefetchable memory\n");
827 "Prefetchable memory\n");
828 break; 852 break;
829 853
830 default: 854 default:
831 acpi_os_printf (" Type Specific: " 855 acpi_os_printf (" Type Specific: Invalid cache attribute\n");
832 "Invalid cache attribute\n");
833 break; 856 break;
834 } 857 }
835 858
836 acpi_os_printf (" Type Specific: Read%s\n", 859 acpi_os_printf (" Type Specific: Read%s\n",
837 ACPI_READ_WRITE_MEMORY == 860 ACPI_READ_WRITE_MEMORY ==
838 address64_data->attribute.memory.read_write_attribute ? 861 address64_data->attribute.memory.read_write_attribute ?
839 "/Write" : " Only"); 862 "/Write" : " Only");
840 break; 863 break;
841 864
842 case ACPI_IO_RANGE: 865 case ACPI_IO_RANGE:
@@ -845,30 +868,26 @@ acpi_rs_dump_address64 (
845 868
846 switch (address64_data->attribute.io.range_attribute) { 869 switch (address64_data->attribute.io.range_attribute) {
847 case ACPI_NON_ISA_ONLY_RANGES: 870 case ACPI_NON_ISA_ONLY_RANGES:
848 acpi_os_printf (" Type Specific: " 871 acpi_os_printf (" Type Specific: Non-ISA Io Addresses\n");
849 "Non-ISA Io Addresses\n");
850 break; 872 break;
851 873
852 case ACPI_ISA_ONLY_RANGES: 874 case ACPI_ISA_ONLY_RANGES:
853 acpi_os_printf (" Type Specific: " 875 acpi_os_printf (" Type Specific: ISA Io Addresses\n");
854 "ISA Io Addresses\n");
855 break; 876 break;
856 877
857 case ACPI_ENTIRE_RANGE: 878 case ACPI_ENTIRE_RANGE:
858 acpi_os_printf (" Type Specific: " 879 acpi_os_printf (" Type Specific: ISA and non-ISA Io Addresses\n");
859 "ISA and non-ISA Io Addresses\n");
860 break; 880 break;
861 881
862 default: 882 default:
863 acpi_os_printf (" Type Specific: " 883 acpi_os_printf (" Type Specific: Invalid Range attribute");
864 "Invalid Range attribute");
865 break; 884 break;
866 } 885 }
867 886
868 acpi_os_printf (" Type Specific: %s Translation\n", 887 acpi_os_printf (" Type Specific: %s Translation\n",
869 ACPI_SPARSE_TRANSLATION == 888 ACPI_SPARSE_TRANSLATION ==
870 address64_data->attribute.io.translation_attribute ? 889 address64_data->attribute.io.translation_attribute ?
871 "Sparse" : "Dense"); 890 "Sparse" : "Dense");
872 break; 891 break;
873 892
874 case ACPI_BUS_NUMBER_RANGE: 893 case ACPI_BUS_NUMBER_RANGE:
@@ -878,49 +897,51 @@ acpi_rs_dump_address64 (
878 897
879 default: 898 default:
880 899
881 acpi_os_printf (" Resource Type: 0x%2.2X\n", address64_data->resource_type); 900 acpi_os_printf (" Resource Type: 0x%2.2X\n",
901 address64_data->resource_type);
882 break; 902 break;
883 } 903 }
884 904
885 acpi_os_printf (" Resource %s\n", 905 acpi_os_printf (" Resource %s\n",
886 ACPI_CONSUMER == address64_data->producer_consumer ? 906 ACPI_CONSUMER == address64_data->producer_consumer ?
887 "Consumer" : "Producer"); 907 "Consumer" : "Producer");
888 908
889 acpi_os_printf (" %s decode\n", 909 acpi_os_printf (" %s decode\n",
890 ACPI_SUB_DECODE == address64_data->decode ? 910 ACPI_SUB_DECODE == address64_data->decode ?
891 "Subtractive" : "Positive"); 911 "Subtractive" : "Positive");
892 912
893 acpi_os_printf (" Min address is %s fixed\n", 913 acpi_os_printf (" Min address is %s fixed\n",
894 ACPI_ADDRESS_FIXED == address64_data->min_address_fixed ? 914 ACPI_ADDRESS_FIXED == address64_data->min_address_fixed ?
895 "" : "not "); 915 "" : "not ");
896 916
897 acpi_os_printf (" Max address is %s fixed\n", 917 acpi_os_printf (" Max address is %s fixed\n",
898 ACPI_ADDRESS_FIXED == address64_data->max_address_fixed ? 918 ACPI_ADDRESS_FIXED == address64_data->max_address_fixed ?
899 "" : "not "); 919 "" : "not ");
900 920
901 acpi_os_printf (" Granularity: %8.8X%8.8X\n", 921 acpi_os_printf (" Granularity: %8.8X%8.8X\n",
902 ACPI_FORMAT_UINT64 (address64_data->granularity)); 922 ACPI_FORMAT_UINT64 (address64_data->granularity));
903 923
904 acpi_os_printf (" Address range min: %8.8X%8.8X\n", 924 acpi_os_printf (" Address range min: %8.8X%8.8X\n",
905 ACPI_FORMAT_UINT64 (address64_data->min_address_range)); 925 ACPI_FORMAT_UINT64 (address64_data->min_address_range));
906 926
907 acpi_os_printf (" Address range max: %8.8X%8.8X\n", 927 acpi_os_printf (" Address range max: %8.8X%8.8X\n",
908 ACPI_FORMAT_UINT64 (address64_data->max_address_range)); 928 ACPI_FORMAT_UINT64 (address64_data->max_address_range));
909 929
910 acpi_os_printf (" Address translation offset: %8.8X%8.8X\n", 930 acpi_os_printf (" Address translation offset: %8.8X%8.8X\n",
911 ACPI_FORMAT_UINT64 (address64_data->address_translation_offset)); 931 ACPI_FORMAT_UINT64 (address64_data->address_translation_offset));
912 932
913 acpi_os_printf (" Address Length: %8.8X%8.8X\n", 933 acpi_os_printf (" Address Length: %8.8X%8.8X\n",
914 ACPI_FORMAT_UINT64 (address64_data->address_length)); 934 ACPI_FORMAT_UINT64 (address64_data->address_length));
915 935
916 acpi_os_printf (" Type Specific Attributes: %8.8X%8.8X\n", 936 acpi_os_printf (" Type Specific Attributes: %8.8X%8.8X\n",
917 ACPI_FORMAT_UINT64 (address64_data->type_specific_attributes)); 937 ACPI_FORMAT_UINT64 (address64_data->type_specific_attributes));
918 938
919 if (0xFF != address64_data->resource_source.index) { 939 if (0xFF != address64_data->resource_source.index) {
920 acpi_os_printf (" Resource Source Index: %X\n", 940 acpi_os_printf (" Resource Source Index: %X\n",
921 address64_data->resource_source.index); 941 address64_data->resource_source.index);
942
922 acpi_os_printf (" Resource Source: %s\n", 943 acpi_os_printf (" Resource Source: %s\n",
923 address64_data->resource_source.string_ptr); 944 address64_data->resource_source.string_ptr);
924 } 945 }
925 946
926 return; 947 return;
@@ -939,7 +960,7 @@ acpi_rs_dump_address64 (
939 * 960 *
940 ******************************************************************************/ 961 ******************************************************************************/
941 962
942void 963static void
943acpi_rs_dump_extended_irq ( 964acpi_rs_dump_extended_irq (
944 union acpi_resource_data *data) 965 union acpi_resource_data *data)
945{ 966{
@@ -953,23 +974,22 @@ acpi_rs_dump_extended_irq (
953 acpi_os_printf ("Extended IRQ Resource\n"); 974 acpi_os_printf ("Extended IRQ Resource\n");
954 975
955 acpi_os_printf (" Resource %s\n", 976 acpi_os_printf (" Resource %s\n",
956 ACPI_CONSUMER == ext_irq_data->producer_consumer ? 977 ACPI_CONSUMER == ext_irq_data->producer_consumer ?
957 "Consumer" : "Producer"); 978 "Consumer" : "Producer");
958 979
959 acpi_os_printf (" %s\n", 980 acpi_os_printf (" %s\n",
960 ACPI_LEVEL_SENSITIVE == ext_irq_data->edge_level ? 981 ACPI_LEVEL_SENSITIVE == ext_irq_data->edge_level ?
961 "Level" : "Edge"); 982 "Level" : "Edge");
962 983
963 acpi_os_printf (" Active %s\n", 984 acpi_os_printf (" Active %s\n",
964 ACPI_ACTIVE_LOW == ext_irq_data->active_high_low ? 985 ACPI_ACTIVE_LOW == ext_irq_data->active_high_low ?
965 "low" : "high"); 986 "low" : "high");
966 987
967 acpi_os_printf (" %s\n", 988 acpi_os_printf (" %s\n",
968 ACPI_SHARED == ext_irq_data->shared_exclusive ? 989 ACPI_SHARED == ext_irq_data->shared_exclusive ?
969 "Shared" : "Exclusive"); 990 "Shared" : "Exclusive");
970 991
971 acpi_os_printf (" Interrupts : %X ( ", 992 acpi_os_printf (" Interrupts : %X ( ", ext_irq_data->number_of_interrupts);
972 ext_irq_data->number_of_interrupts);
973 993
974 for (index = 0; index < ext_irq_data->number_of_interrupts; index++) { 994 for (index = 0; index < ext_irq_data->number_of_interrupts; index++) {
975 acpi_os_printf ("%X ", ext_irq_data->interrupts[index]); 995 acpi_os_printf ("%X ", ext_irq_data->interrupts[index]);
@@ -979,9 +999,10 @@ acpi_rs_dump_extended_irq (
979 999
980 if(0xFF != ext_irq_data->resource_source.index) { 1000 if(0xFF != ext_irq_data->resource_source.index) {
981 acpi_os_printf (" Resource Source Index: %X", 1001 acpi_os_printf (" Resource Source Index: %X",
982 ext_irq_data->resource_source.index); 1002 ext_irq_data->resource_source.index);
1003
983 acpi_os_printf (" Resource Source: %s", 1004 acpi_os_printf (" Resource Source: %s",
984 ext_irq_data->resource_source.string_ptr); 1005 ext_irq_data->resource_source.string_ptr);
985 } 1006 }
986 1007
987 return; 1008 return;
@@ -992,7 +1013,7 @@ acpi_rs_dump_extended_irq (
992 * 1013 *
993 * FUNCTION: acpi_rs_dump_resource_list 1014 * FUNCTION: acpi_rs_dump_resource_list
994 * 1015 *
995 * PARAMETERS: Data - pointer to the resource structure to dump. 1016 * PARAMETERS: Resource - pointer to the resource structure to dump.
996 * 1017 *
997 * RETURN: None 1018 * RETURN: None
998 * 1019 *
@@ -1096,7 +1117,7 @@ acpi_rs_dump_resource_list (
1096 * 1117 *
1097 * FUNCTION: acpi_rs_dump_irq_list 1118 * FUNCTION: acpi_rs_dump_irq_list
1098 * 1119 *
1099 * PARAMETERS: Data - pointer to the routing table to dump. 1120 * PARAMETERS: route_table - pointer to the routing table to dump.
1100 * 1121 *
1101 * RETURN: None 1122 * RETURN: None
1102 * 1123 *
@@ -1124,20 +1145,17 @@ acpi_rs_dump_irq_list (
1124 acpi_os_printf ("PCI IRQ Routing Table structure %X.\n", count++); 1145 acpi_os_printf ("PCI IRQ Routing Table structure %X.\n", count++);
1125 1146
1126 acpi_os_printf (" Address: %8.8X%8.8X\n", 1147 acpi_os_printf (" Address: %8.8X%8.8X\n",
1127 ACPI_FORMAT_UINT64 (prt_element->address)); 1148 ACPI_FORMAT_UINT64 (prt_element->address));
1128 1149
1129 acpi_os_printf (" Pin: %X\n", prt_element->pin); 1150 acpi_os_printf (" Pin: %X\n", prt_element->pin);
1130 1151
1131 acpi_os_printf (" Source: %s\n", prt_element->source); 1152 acpi_os_printf (" Source: %s\n", prt_element->source);
1132 1153
1133 acpi_os_printf (" source_index: %X\n", 1154 acpi_os_printf (" source_index: %X\n", prt_element->source_index);
1134 prt_element->source_index);
1135 1155
1136 buffer += prt_element->length; 1156 buffer += prt_element->length;
1137
1138 prt_element = ACPI_CAST_PTR (struct acpi_pci_routing_table, buffer); 1157 prt_element = ACPI_CAST_PTR (struct acpi_pci_routing_table, buffer);
1139 1158 if (0 == prt_element->length) {
1140 if(0 == prt_element->length) {
1141 done = TRUE; 1159 done = TRUE;
1142 } 1160 }
1143 } 1161 }
diff --git a/drivers/acpi/resources/rsio.c b/drivers/acpi/resources/rsio.c
index 972c746d37e4..23a4d149fac8 100644
--- a/drivers/acpi/resources/rsio.c
+++ b/drivers/acpi/resources/rsio.c
@@ -81,67 +81,60 @@ acpi_rs_io_resource (
81 struct acpi_resource *output_struct = (void *) *output_buffer; 81 struct acpi_resource *output_struct = (void *) *output_buffer;
82 u16 temp16 = 0; 82 u16 temp16 = 0;
83 u8 temp8 = 0; 83 u8 temp8 = 0;
84 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_io); 84 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (
85 struct acpi_resource_io);
85 86
86 87
87 ACPI_FUNCTION_TRACE ("rs_io_resource"); 88 ACPI_FUNCTION_TRACE ("rs_io_resource");
88 89
89 90
90 /* 91 /* The number of bytes consumed are Constant */
91 * The number of bytes consumed are Constant 92
92 */
93 *bytes_consumed = 8; 93 *bytes_consumed = 8;
94 94
95 output_struct->id = ACPI_RSTYPE_IO; 95 output_struct->id = ACPI_RSTYPE_IO;
96 96
97 /* 97 /* Check Decode */
98 * Check Decode 98
99 */
100 buffer += 1; 99 buffer += 1;
101 temp8 = *buffer; 100 temp8 = *buffer;
102 101
103 output_struct->data.io.io_decode = temp8 & 0x01; 102 output_struct->data.io.io_decode = temp8 & 0x01;
104 103
105 /* 104 /* Check min_base Address */
106 * Check min_base Address 105
107 */
108 buffer += 1; 106 buffer += 1;
109 ACPI_MOVE_16_TO_16 (&temp16, buffer); 107 ACPI_MOVE_16_TO_16 (&temp16, buffer);
110 108
111 output_struct->data.io.min_base_address = temp16; 109 output_struct->data.io.min_base_address = temp16;
112 110
113 /* 111 /* Check max_base Address */
114 * Check max_base Address 112
115 */
116 buffer += 2; 113 buffer += 2;
117 ACPI_MOVE_16_TO_16 (&temp16, buffer); 114 ACPI_MOVE_16_TO_16 (&temp16, buffer);
118 115
119 output_struct->data.io.max_base_address = temp16; 116 output_struct->data.io.max_base_address = temp16;
120 117
121 /* 118 /* Check Base alignment */
122 * Check Base alignment 119
123 */
124 buffer += 2; 120 buffer += 2;
125 temp8 = *buffer; 121 temp8 = *buffer;
126 122
127 output_struct->data.io.alignment = temp8; 123 output_struct->data.io.alignment = temp8;
128 124
129 /* 125 /* Check range_length */
130 * Check range_length 126
131 */
132 buffer += 1; 127 buffer += 1;
133 temp8 = *buffer; 128 temp8 = *buffer;
134 129
135 output_struct->data.io.range_length = temp8; 130 output_struct->data.io.range_length = temp8;
136 131
137 /* 132 /* Set the Length parameter */
138 * Set the Length parameter 133
139 */
140 output_struct->length = (u32) struct_size; 134 output_struct->length = (u32) struct_size;
141 135
142 /* 136 /* Return the final size of the structure */
143 * Return the final size of the structure 137
144 */
145 *structure_size = struct_size; 138 *structure_size = struct_size;
146 return_ACPI_STATUS (AE_OK); 139 return_ACPI_STATUS (AE_OK);
147} 140}
@@ -179,43 +172,39 @@ acpi_rs_fixed_io_resource (
179 struct acpi_resource *output_struct = (void *) *output_buffer; 172 struct acpi_resource *output_struct = (void *) *output_buffer;
180 u16 temp16 = 0; 173 u16 temp16 = 0;
181 u8 temp8 = 0; 174 u8 temp8 = 0;
182 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_fixed_io); 175 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (
176 struct acpi_resource_fixed_io);
183 177
184 178
185 ACPI_FUNCTION_TRACE ("rs_fixed_io_resource"); 179 ACPI_FUNCTION_TRACE ("rs_fixed_io_resource");
186 180
187 181
188 /* 182 /* The number of bytes consumed are Constant */
189 * The number of bytes consumed are Constant 183
190 */
191 *bytes_consumed = 4; 184 *bytes_consumed = 4;
192 185
193 output_struct->id = ACPI_RSTYPE_FIXED_IO; 186 output_struct->id = ACPI_RSTYPE_FIXED_IO;
194 187
195 /* 188 /* Check Range Base Address */
196 * Check Range Base Address 189
197 */
198 buffer += 1; 190 buffer += 1;
199 ACPI_MOVE_16_TO_16 (&temp16, buffer); 191 ACPI_MOVE_16_TO_16 (&temp16, buffer);
200 192
201 output_struct->data.fixed_io.base_address = temp16; 193 output_struct->data.fixed_io.base_address = temp16;
202 194
203 /* 195 /* Check range_length */
204 * Check range_length 196
205 */
206 buffer += 2; 197 buffer += 2;
207 temp8 = *buffer; 198 temp8 = *buffer;
208 199
209 output_struct->data.fixed_io.range_length = temp8; 200 output_struct->data.fixed_io.range_length = temp8;
210 201
211 /* 202 /* Set the Length parameter */
212 * Set the Length parameter 203
213 */
214 output_struct->length = (u32) struct_size; 204 output_struct->length = (u32) struct_size;
215 205
216 /* 206 /* Return the final size of the structure */
217 * Return the final size of the structure 207
218 */
219 *structure_size = struct_size; 208 *structure_size = struct_size;
220 return_ACPI_STATUS (AE_OK); 209 return_ACPI_STATUS (AE_OK);
221} 210}
@@ -251,55 +240,48 @@ acpi_rs_io_stream (
251 ACPI_FUNCTION_TRACE ("rs_io_stream"); 240 ACPI_FUNCTION_TRACE ("rs_io_stream");
252 241
253 242
254 /* 243 /* The descriptor field is static */
255 * The descriptor field is static 244
256 */
257 *buffer = 0x47; 245 *buffer = 0x47;
258 buffer += 1; 246 buffer += 1;
259 247
260 /* 248 /* Io Information Byte */
261 * Io Information Byte 249
262 */
263 temp8 = (u8) (linked_list->data.io.io_decode & 0x01); 250 temp8 = (u8) (linked_list->data.io.io_decode & 0x01);
264 251
265 *buffer = temp8; 252 *buffer = temp8;
266 buffer += 1; 253 buffer += 1;
267 254
268 /* 255 /* Set the Range minimum base address */
269 * Set the Range minimum base address 256
270 */
271 temp16 = (u16) linked_list->data.io.min_base_address; 257 temp16 = (u16) linked_list->data.io.min_base_address;
272 258
273 ACPI_MOVE_16_TO_16 (buffer, &temp16); 259 ACPI_MOVE_16_TO_16 (buffer, &temp16);
274 buffer += 2; 260 buffer += 2;
275 261
276 /* 262 /* Set the Range maximum base address */
277 * Set the Range maximum base address 263
278 */
279 temp16 = (u16) linked_list->data.io.max_base_address; 264 temp16 = (u16) linked_list->data.io.max_base_address;
280 265
281 ACPI_MOVE_16_TO_16 (buffer, &temp16); 266 ACPI_MOVE_16_TO_16 (buffer, &temp16);
282 buffer += 2; 267 buffer += 2;
283 268
284 /* 269 /* Set the base alignment */
285 * Set the base alignment 270
286 */
287 temp8 = (u8) linked_list->data.io.alignment; 271 temp8 = (u8) linked_list->data.io.alignment;
288 272
289 *buffer = temp8; 273 *buffer = temp8;
290 buffer += 1; 274 buffer += 1;
291 275
292 /* 276 /* Set the range length */
293 * Set the range length 277
294 */
295 temp8 = (u8) linked_list->data.io.range_length; 278 temp8 = (u8) linked_list->data.io.range_length;
296 279
297 *buffer = temp8; 280 *buffer = temp8;
298 buffer += 1; 281 buffer += 1;
299 282
300 /* 283 /* Return the number of bytes consumed in this operation */
301 * Return the number of bytes consumed in this operation 284
302 */
303 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer); 285 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
304 return_ACPI_STATUS (AE_OK); 286 return_ACPI_STATUS (AE_OK);
305} 287}
@@ -335,32 +317,28 @@ acpi_rs_fixed_io_stream (
335 ACPI_FUNCTION_TRACE ("rs_fixed_io_stream"); 317 ACPI_FUNCTION_TRACE ("rs_fixed_io_stream");
336 318
337 319
338 /* 320 /* The descriptor field is static */
339 * The descriptor field is static 321
340 */
341 *buffer = 0x4B; 322 *buffer = 0x4B;
342 323
343 buffer += 1; 324 buffer += 1;
344 325
345 /* 326 /* Set the Range base address */
346 * Set the Range base address 327
347 */
348 temp16 = (u16) linked_list->data.fixed_io.base_address; 328 temp16 = (u16) linked_list->data.fixed_io.base_address;
349 329
350 ACPI_MOVE_16_TO_16 (buffer, &temp16); 330 ACPI_MOVE_16_TO_16 (buffer, &temp16);
351 buffer += 2; 331 buffer += 2;
352 332
353 /* 333 /* Set the range length */
354 * Set the range length 334
355 */
356 temp8 = (u8) linked_list->data.fixed_io.range_length; 335 temp8 = (u8) linked_list->data.fixed_io.range_length;
357 336
358 *buffer = temp8; 337 *buffer = temp8;
359 buffer += 1; 338 buffer += 1;
360 339
361 /* 340 /* Return the number of bytes consumed in this operation */
362 * Return the number of bytes consumed in this operation 341
363 */
364 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer); 342 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
365 return_ACPI_STATUS (AE_OK); 343 return_ACPI_STATUS (AE_OK);
366} 344}
@@ -399,21 +377,20 @@ acpi_rs_dma_resource (
399 u8 temp8 = 0; 377 u8 temp8 = 0;
400 u8 index; 378 u8 index;
401 u8 i; 379 u8 i;
402 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_dma); 380 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (
381 struct acpi_resource_dma);
403 382
404 383
405 ACPI_FUNCTION_TRACE ("rs_dma_resource"); 384 ACPI_FUNCTION_TRACE ("rs_dma_resource");
406 385
407 386
408 /* 387 /* The number of bytes consumed are Constant */
409 * The number of bytes consumed are Constant 388
410 */
411 *bytes_consumed = 3; 389 *bytes_consumed = 3;
412 output_struct->id = ACPI_RSTYPE_DMA; 390 output_struct->id = ACPI_RSTYPE_DMA;
413 391
414 /* 392 /* Point to the 8-bits of Byte 1 */
415 * Point to the 8-bits of Byte 1 393
416 */
417 buffer += 1; 394 buffer += 1;
418 temp8 = *buffer; 395 temp8 = *buffer;
419 396
@@ -430,46 +407,40 @@ acpi_rs_dma_resource (
430 407
431 output_struct->data.dma.number_of_channels = i; 408 output_struct->data.dma.number_of_channels = i;
432 if (i > 0) { 409 if (i > 0) {
433 /* 410 /* Calculate the structure size based upon the number of interrupts */
434 * Calculate the structure size based upon the number of interrupts 411
435 */
436 struct_size += ((acpi_size) i - 1) * 4; 412 struct_size += ((acpi_size) i - 1) * 4;
437 } 413 }
438 414
439 /* 415 /* Point to Byte 2 */
440 * Point to Byte 2 416
441 */
442 buffer += 1; 417 buffer += 1;
443 temp8 = *buffer; 418 temp8 = *buffer;
444 419
445 /* 420 /* Check for transfer preference (Bits[1:0]) */
446 * Check for transfer preference (Bits[1:0]) 421
447 */
448 output_struct->data.dma.transfer = temp8 & 0x03; 422 output_struct->data.dma.transfer = temp8 & 0x03;
449 423
450 if (0x03 == output_struct->data.dma.transfer) { 424 if (0x03 == output_struct->data.dma.transfer) {
451 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Invalid DMA.Transfer preference (3)\n")); 425 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
426 "Invalid DMA.Transfer preference (3)\n"));
452 return_ACPI_STATUS (AE_BAD_DATA); 427 return_ACPI_STATUS (AE_BAD_DATA);
453 } 428 }
454 429
455 /* 430 /* Get bus master preference (Bit[2]) */
456 * Get bus master preference (Bit[2]) 431
457 */
458 output_struct->data.dma.bus_master = (temp8 >> 2) & 0x01; 432 output_struct->data.dma.bus_master = (temp8 >> 2) & 0x01;
459 433
460 /* 434 /* Get channel speed support (Bits[6:5]) */
461 * Get channel speed support (Bits[6:5]) 435
462 */
463 output_struct->data.dma.type = (temp8 >> 5) & 0x03; 436 output_struct->data.dma.type = (temp8 >> 5) & 0x03;
464 437
465 /* 438 /* Set the Length parameter */
466 * Set the Length parameter 439
467 */
468 output_struct->length = (u32) struct_size; 440 output_struct->length = (u32) struct_size;
469 441
470 /* 442 /* Return the final size of the structure */
471 * Return the final size of the structure 443
472 */
473 *structure_size = struct_size; 444 *structure_size = struct_size;
474 return_ACPI_STATUS (AE_OK); 445 return_ACPI_STATUS (AE_OK);
475} 446}
@@ -506,16 +477,14 @@ acpi_rs_dma_stream (
506 ACPI_FUNCTION_TRACE ("rs_dma_stream"); 477 ACPI_FUNCTION_TRACE ("rs_dma_stream");
507 478
508 479
509 /* 480 /* The descriptor field is static */
510 * The descriptor field is static 481
511 */
512 *buffer = 0x2A; 482 *buffer = 0x2A;
513 buffer += 1; 483 buffer += 1;
514 temp8 = 0; 484 temp8 = 0;
515 485
516 /* 486 /* Loop through all of the Channels and set the mask bits */
517 * Loop through all of the Channels and set the mask bits 487
518 */
519 for (index = 0; 488 for (index = 0;
520 index < linked_list->data.dma.number_of_channels; 489 index < linked_list->data.dma.number_of_channels;
521 index++) { 490 index++) {
@@ -526,9 +495,8 @@ acpi_rs_dma_stream (
526 *buffer = temp8; 495 *buffer = temp8;
527 buffer += 1; 496 buffer += 1;
528 497
529 /* 498 /* Set the DMA Info */
530 * Set the DMA Info 499
531 */
532 temp8 = (u8) ((linked_list->data.dma.type & 0x03) << 5); 500 temp8 = (u8) ((linked_list->data.dma.type & 0x03) << 5);
533 temp8 |= ((linked_list->data.dma.bus_master & 0x01) << 2); 501 temp8 |= ((linked_list->data.dma.bus_master & 0x01) << 2);
534 temp8 |= (linked_list->data.dma.transfer & 0x03); 502 temp8 |= (linked_list->data.dma.transfer & 0x03);
@@ -536,9 +504,8 @@ acpi_rs_dma_stream (
536 *buffer = temp8; 504 *buffer = temp8;
537 buffer += 1; 505 buffer += 1;
538 506
539 /* 507 /* Return the number of bytes consumed in this operation */
540 * Return the number of bytes consumed in this operation 508
541 */
542 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer); 509 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
543 return_ACPI_STATUS (AE_OK); 510 return_ACPI_STATUS (AE_OK);
544} 511}
diff --git a/drivers/acpi/resources/rsirq.c b/drivers/acpi/resources/rsirq.c
index fd07a8702fbe..8a2b630be45b 100644
--- a/drivers/acpi/resources/rsirq.c
+++ b/drivers/acpi/resources/rsirq.c
@@ -83,7 +83,8 @@ acpi_rs_irq_resource (
83 u8 temp8 = 0; 83 u8 temp8 = 0;
84 u8 index; 84 u8 index;
85 u8 i; 85 u8 i;
86 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_irq); 86 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (
87 struct acpi_resource_irq);
87 88
88 89
89 ACPI_FUNCTION_TRACE ("rs_irq_resource"); 90 ACPI_FUNCTION_TRACE ("rs_irq_resource");
@@ -91,15 +92,14 @@ acpi_rs_irq_resource (
91 92
92 /* 93 /*
93 * The number of bytes consumed are contained in the descriptor 94 * The number of bytes consumed are contained in the descriptor
94 * (Bits:0-1) 95 * (Bits:0-1)
95 */ 96 */
96 temp8 = *buffer; 97 temp8 = *buffer;
97 *bytes_consumed = (temp8 & 0x03) + 1; 98 *bytes_consumed = (temp8 & 0x03) + 1;
98 output_struct->id = ACPI_RSTYPE_IRQ; 99 output_struct->id = ACPI_RSTYPE_IRQ;
99 100
100 /* 101 /* Point to the 16-bits of Bytes 1 and 2 */
101 * Point to the 16-bits of Bytes 1 and 2 102
102 */
103 buffer += 1; 103 buffer += 1;
104 ACPI_MOVE_16_TO_16 (&temp16, buffer); 104 ACPI_MOVE_16_TO_16 (&temp16, buffer);
105 105
@@ -118,22 +118,19 @@ acpi_rs_irq_resource (
118 118
119 output_struct->data.irq.number_of_interrupts = i; 119 output_struct->data.irq.number_of_interrupts = i;
120 if (i > 0) { 120 if (i > 0) {
121 /* 121 /* Calculate the structure size based upon the number of interrupts */
122 * Calculate the structure size based upon the number of interrupts 122
123 */
124 struct_size += ((acpi_size) i - 1) * 4; 123 struct_size += ((acpi_size) i - 1) * 4;
125 } 124 }
126 125
127 /* 126 /* Point to Byte 3 if it is used */
128 * Point to Byte 3 if it is used 127
129 */
130 if (4 == *bytes_consumed) { 128 if (4 == *bytes_consumed) {
131 buffer += 2; 129 buffer += 2;
132 temp8 = *buffer; 130 temp8 = *buffer;
133 131
134 /* 132 /* Check for HE, LL interrupts */
135 * Check for HE, LL interrupts 133
136 */
137 switch (temp8 & 0x09) { 134 switch (temp8 & 0x09) {
138 case 0x01: /* HE */ 135 case 0x01: /* HE */
139 output_struct->data.irq.edge_level = ACPI_EDGE_SENSITIVE; 136 output_struct->data.irq.edge_level = ACPI_EDGE_SENSITIVE;
@@ -152,13 +149,13 @@ acpi_rs_irq_resource (
152 * so 0x00 and 0x09 are illegal. 149 * so 0x00 and 0x09 are illegal.
153 */ 150 */
154 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 151 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
155 "Invalid interrupt polarity/trigger in resource list, %X\n", temp8)); 152 "Invalid interrupt polarity/trigger in resource list, %X\n",
153 temp8));
156 return_ACPI_STATUS (AE_BAD_DATA); 154 return_ACPI_STATUS (AE_BAD_DATA);
157 } 155 }
158 156
159 /* 157 /* Check for sharable */
160 * Check for sharable 158
161 */
162 output_struct->data.irq.shared_exclusive = (temp8 >> 3) & 0x01; 159 output_struct->data.irq.shared_exclusive = (temp8 >> 3) & 0x01;
163 } 160 }
164 else { 161 else {
@@ -171,14 +168,12 @@ acpi_rs_irq_resource (
171 output_struct->data.irq.shared_exclusive = ACPI_EXCLUSIVE; 168 output_struct->data.irq.shared_exclusive = ACPI_EXCLUSIVE;
172 } 169 }
173 170
174 /* 171 /* Set the Length parameter */
175 * Set the Length parameter 172
176 */
177 output_struct->length = (u32) struct_size; 173 output_struct->length = (u32) struct_size;
178 174
179 /* 175 /* Return the final size of the structure */
180 * Return the final size of the structure 176
181 */
182 *structure_size = struct_size; 177 *structure_size = struct_size;
183 return_ACPI_STATUS (AE_OK); 178 return_ACPI_STATUS (AE_OK);
184} 179}
@@ -234,9 +229,8 @@ acpi_rs_irq_stream (
234 buffer += 1; 229 buffer += 1;
235 temp16 = 0; 230 temp16 = 0;
236 231
237 /* 232 /* Loop through all of the interrupts and set the mask bits */
238 * Loop through all of the interrupts and set the mask bits 233
239 */
240 for(index = 0; 234 for(index = 0;
241 index < linked_list->data.irq.number_of_interrupts; 235 index < linked_list->data.irq.number_of_interrupts;
242 index++) { 236 index++) {
@@ -247,9 +241,8 @@ acpi_rs_irq_stream (
247 ACPI_MOVE_16_TO_16 (buffer, &temp16); 241 ACPI_MOVE_16_TO_16 (buffer, &temp16);
248 buffer += 2; 242 buffer += 2;
249 243
250 /* 244 /* Set the IRQ Info byte if needed. */
251 * Set the IRQ Info byte if needed. 245
252 */
253 if (IRqinfo_byte_needed) { 246 if (IRqinfo_byte_needed) {
254 temp8 = 0; 247 temp8 = 0;
255 temp8 = (u8) ((linked_list->data.irq.shared_exclusive & 248 temp8 = (u8) ((linked_list->data.irq.shared_exclusive &
@@ -267,9 +260,8 @@ acpi_rs_irq_stream (
267 buffer += 1; 260 buffer += 1;
268 } 261 }
269 262
270 /* 263 /* Return the number of bytes consumed in this operation */
271 * Return the number of bytes consumed in this operation 264
272 */
273 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer); 265 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
274 return_ACPI_STATUS (AE_OK); 266 return_ACPI_STATUS (AE_OK);
275} 267}
@@ -309,15 +301,15 @@ acpi_rs_extended_irq_resource (
309 u8 temp8 = 0; 301 u8 temp8 = 0;
310 u8 *temp_ptr; 302 u8 *temp_ptr;
311 u8 index; 303 u8 index;
312 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_ext_irq); 304 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (
305 struct acpi_resource_ext_irq);
313 306
314 307
315 ACPI_FUNCTION_TRACE ("rs_extended_irq_resource"); 308 ACPI_FUNCTION_TRACE ("rs_extended_irq_resource");
316 309
317 310
318 /* 311 /* Point past the Descriptor to get the number of bytes consumed */
319 * Point past the Descriptor to get the number of bytes consumed 312
320 */
321 buffer += 1; 313 buffer += 1;
322 ACPI_MOVE_16_TO_16 (&temp16, buffer); 314 ACPI_MOVE_16_TO_16 (&temp16, buffer);
323 315
@@ -330,9 +322,8 @@ acpi_rs_extended_irq_resource (
330 *bytes_consumed = temp16 + 3; 322 *bytes_consumed = temp16 + 3;
331 output_struct->id = ACPI_RSTYPE_EXT_IRQ; 323 output_struct->id = ACPI_RSTYPE_EXT_IRQ;
332 324
333 /* 325 /* Point to the Byte3 */
334 * Point to the Byte3 326
335 */
336 buffer += 2; 327 buffer += 2;
337 temp8 = *buffer; 328 temp8 = *buffer;
338 329
@@ -347,21 +338,18 @@ acpi_rs_extended_irq_resource (
347 * - Edge/Level are defined opposite in the table vs the headers 338 * - Edge/Level are defined opposite in the table vs the headers
348 */ 339 */
349 output_struct->data.extended_irq.edge_level = 340 output_struct->data.extended_irq.edge_level =
350 (temp8 & 0x2) ? ACPI_EDGE_SENSITIVE : ACPI_LEVEL_SENSITIVE; 341 (temp8 & 0x2) ? ACPI_EDGE_SENSITIVE : ACPI_LEVEL_SENSITIVE;
342
343 /* Check Interrupt Polarity */
351 344
352 /*
353 * Check Interrupt Polarity
354 */
355 output_struct->data.extended_irq.active_high_low = (temp8 >> 2) & 0x1; 345 output_struct->data.extended_irq.active_high_low = (temp8 >> 2) & 0x1;
356 346
357 /* 347 /* Check for sharable */
358 * Check for sharable 348
359 */
360 output_struct->data.extended_irq.shared_exclusive = (temp8 >> 3) & 0x01; 349 output_struct->data.extended_irq.shared_exclusive = (temp8 >> 3) & 0x01;
361 350
362 /* 351 /* Point to Byte4 (IRQ Table length) */
363 * Point to Byte4 (IRQ Table length) 352
364 */
365 buffer += 1; 353 buffer += 1;
366 temp8 = *buffer; 354 temp8 = *buffer;
367 355
@@ -379,14 +367,12 @@ acpi_rs_extended_irq_resource (
379 */ 367 */
380 struct_size += (temp8 - 1) * 4; 368 struct_size += (temp8 - 1) * 4;
381 369
382 /* 370 /* Point to Byte5 (First IRQ Number) */
383 * Point to Byte5 (First IRQ Number) 371
384 */
385 buffer += 1; 372 buffer += 1;
386 373
387 /* 374 /* Cycle through every IRQ in the table */
388 * Cycle through every IRQ in the table 375
389 */
390 for (index = 0; index < temp8; index++) { 376 for (index = 0; index < temp8; index++) {
391 ACPI_MOVE_32_TO_32 ( 377 ACPI_MOVE_32_TO_32 (
392 &output_struct->data.extended_irq.interrupts[index], buffer); 378 &output_struct->data.extended_irq.interrupts[index], buffer);
@@ -407,7 +393,8 @@ acpi_rs_extended_irq_resource (
407 * we add 1 to the length. 393 * we add 1 to the length.
408 */ 394 */
409 if (*bytes_consumed > 395 if (*bytes_consumed >
410 ((acpi_size) output_struct->data.extended_irq.number_of_interrupts * 4) + (5 + 1)) { 396 ((acpi_size) output_struct->data.extended_irq.number_of_interrupts * 4) +
397 (5 + 1)) {
411 /* Dereference the Index */ 398 /* Dereference the Index */
412 399
413 temp8 = *buffer; 400 temp8 = *buffer;
@@ -417,13 +404,13 @@ acpi_rs_extended_irq_resource (
417 404
418 buffer += 1; 405 buffer += 1;
419 406
420 /* 407 /* Point the String pointer to the end of this structure. */
421 * Point the String pointer to the end of this structure. 408
422 */
423 output_struct->data.extended_irq.resource_source.string_ptr = 409 output_struct->data.extended_irq.resource_source.string_ptr =
424 (char *)((char *) output_struct + struct_size); 410 (char *)((char *) output_struct + struct_size);
425 411
426 temp_ptr = (u8 *) output_struct->data.extended_irq.resource_source.string_ptr; 412 temp_ptr = (u8 *)
413 output_struct->data.extended_irq.resource_source.string_ptr;
427 414
428 /* Copy the string into the buffer */ 415 /* Copy the string into the buffer */
429 416
@@ -436,9 +423,8 @@ acpi_rs_extended_irq_resource (
436 index += 1; 423 index += 1;
437 } 424 }
438 425
439 /* 426 /* Add the terminating null */
440 * Add the terminating null 427
441 */
442 *temp_ptr = 0x00; 428 *temp_ptr = 0x00;
443 output_struct->data.extended_irq.resource_source.string_length = index + 1; 429 output_struct->data.extended_irq.resource_source.string_length = index + 1;
444 430
@@ -456,14 +442,12 @@ acpi_rs_extended_irq_resource (
456 output_struct->data.extended_irq.resource_source.string_ptr = NULL; 442 output_struct->data.extended_irq.resource_source.string_ptr = NULL;
457 } 443 }
458 444
459 /* 445 /* Set the Length parameter */
460 * Set the Length parameter 446
461 */
462 output_struct->length = (u32) struct_size; 447 output_struct->length = (u32) struct_size;
463 448
464 /* 449 /* Return the final size of the structure */
465 * Return the final size of the structure 450
466 */
467 *structure_size = struct_size; 451 *structure_size = struct_size;
468 return_ACPI_STATUS (AE_OK); 452 return_ACPI_STATUS (AE_OK);
469} 453}
@@ -501,21 +485,18 @@ acpi_rs_extended_irq_stream (
501 ACPI_FUNCTION_TRACE ("rs_extended_irq_stream"); 485 ACPI_FUNCTION_TRACE ("rs_extended_irq_stream");
502 486
503 487
504 /* 488 /* The descriptor field is static */
505 * The descriptor field is static 489
506 */
507 *buffer = 0x89; 490 *buffer = 0x89;
508 buffer += 1; 491 buffer += 1;
509 492
510 /* 493 /* Set a pointer to the Length field - to be filled in later */
511 * Set a pointer to the Length field - to be filled in later 494
512 */
513 length_field = ACPI_CAST_PTR (u16, buffer); 495 length_field = ACPI_CAST_PTR (u16, buffer);
514 buffer += 2; 496 buffer += 2;
515 497
516 /* 498 /* Set the Interrupt vector flags */
517 * Set the Interrupt vector flags 499
518 */
519 temp8 = (u8)(linked_list->data.extended_irq.producer_consumer & 0x01); 500 temp8 = (u8)(linked_list->data.extended_irq.producer_consumer & 0x01);
520 temp8 |= ((linked_list->data.extended_irq.shared_exclusive & 0x01) << 3); 501 temp8 |= ((linked_list->data.extended_irq.shared_exclusive & 0x01) << 3);
521 502
@@ -532,17 +513,15 @@ acpi_rs_extended_irq_stream (
532 temp8 |= 0x2; 513 temp8 |= 0x2;
533 } 514 }
534 515
535 /* 516 /* Set the Interrupt Polarity */
536 * Set the Interrupt Polarity 517
537 */
538 temp8 |= ((linked_list->data.extended_irq.active_high_low & 0x1) << 2); 518 temp8 |= ((linked_list->data.extended_irq.active_high_low & 0x1) << 2);
539 519
540 *buffer = temp8; 520 *buffer = temp8;
541 buffer += 1; 521 buffer += 1;
542 522
543 /* 523 /* Set the Interrupt table length */
544 * Set the Interrupt table length 524
545 */
546 temp8 = (u8) linked_list->data.extended_irq.number_of_interrupts; 525 temp8 = (u8) linked_list->data.extended_irq.number_of_interrupts;
547 526
548 *buffer = temp8; 527 *buffer = temp8;
@@ -555,18 +534,16 @@ acpi_rs_extended_irq_stream (
555 buffer += 4; 534 buffer += 4;
556 } 535 }
557 536
558 /* 537 /* Resource Source Index and Resource Source are optional */
559 * Resource Source Index and Resource Source are optional 538
560 */
561 if (0 != linked_list->data.extended_irq.resource_source.string_length) { 539 if (0 != linked_list->data.extended_irq.resource_source.string_length) {
562 *buffer = (u8) linked_list->data.extended_irq.resource_source.index; 540 *buffer = (u8) linked_list->data.extended_irq.resource_source.index;
563 buffer += 1; 541 buffer += 1;
564 542
565 temp_pointer = (char *) buffer; 543 temp_pointer = (char *) buffer;
566 544
567 /* 545 /* Copy the string */
568 * Copy the string 546
569 */
570 ACPI_STRCPY (temp_pointer, 547 ACPI_STRCPY (temp_pointer,
571 linked_list->data.extended_irq.resource_source.string_ptr); 548 linked_list->data.extended_irq.resource_source.string_ptr);
572 549
@@ -574,12 +551,12 @@ acpi_rs_extended_irq_stream (
574 * Buffer needs to be set to the length of the sting + one for the 551 * Buffer needs to be set to the length of the sting + one for the
575 * terminating null 552 * terminating null
576 */ 553 */
577 buffer += (acpi_size)(ACPI_STRLEN (linked_list->data.extended_irq.resource_source.string_ptr) + 1); 554 buffer += (acpi_size) (ACPI_STRLEN (
555 linked_list->data.extended_irq.resource_source.string_ptr) + 1);
578 } 556 }
579 557
580 /* 558 /* Return the number of bytes consumed in this operation */
581 * Return the number of bytes consumed in this operation 559
582 */
583 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer); 560 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
584 561
585 /* 562 /*
diff --git a/drivers/acpi/resources/rslist.c b/drivers/acpi/resources/rslist.c
index e49c1e030f99..db7bcb4e60e3 100644
--- a/drivers/acpi/resources/rslist.c
+++ b/drivers/acpi/resources/rslist.c
@@ -55,7 +55,7 @@
55 * 55 *
56 * PARAMETERS: resource_start_byte - Byte 0 of a resource descriptor 56 * PARAMETERS: resource_start_byte - Byte 0 of a resource descriptor
57 * 57 *
58 * RETURN: The Resource Type (Name) with no extraneous bits 58 * RETURN: The Resource Type with no extraneous bits
59 * 59 *
60 * DESCRIPTION: Extract the Resource Type/Name from the first byte of 60 * DESCRIPTION: Extract the Resource Type/Name from the first byte of
61 * a resource descriptor. 61 * a resource descriptor.
@@ -70,28 +70,25 @@ acpi_rs_get_resource_type (
70 ACPI_FUNCTION_ENTRY (); 70 ACPI_FUNCTION_ENTRY ();
71 71
72 72
73 /* 73 /* Determine if this is a small or large resource */
74 * Determine if this is a small or large resource 74
75 */
76 switch (resource_start_byte & ACPI_RDESC_TYPE_MASK) { 75 switch (resource_start_byte & ACPI_RDESC_TYPE_MASK) {
77 case ACPI_RDESC_TYPE_SMALL: 76 case ACPI_RDESC_TYPE_SMALL:
78 77
79 /* 78 /* Small Resource Type -- Only bits 6:3 are valid */
80 * Small Resource Type -- Only bits 6:3 are valid 79
81 */
82 return ((u8) (resource_start_byte & ACPI_RDESC_SMALL_MASK)); 80 return ((u8) (resource_start_byte & ACPI_RDESC_SMALL_MASK));
83 81
84 82
85 case ACPI_RDESC_TYPE_LARGE: 83 case ACPI_RDESC_TYPE_LARGE:
86 84
87 /* 85 /* Large Resource Type -- All bits are valid */
88 * Large Resource Type -- All bits are valid 86
89 */
90 return (resource_start_byte); 87 return (resource_start_byte);
91 88
92 89
93 default: 90 default:
94 /* No other types of resource descriptor */ 91 /* Invalid type */
95 break; 92 break;
96 } 93 }
97 94
@@ -135,9 +132,8 @@ acpi_rs_byte_stream_to_list (
135 132
136 while (bytes_parsed < byte_stream_buffer_length && 133 while (bytes_parsed < byte_stream_buffer_length &&
137 !end_tag_processed) { 134 !end_tag_processed) {
138 /* 135 /* The next byte in the stream is the resource type */
139 * The next byte in the stream is the resource type 136
140 */
141 resource_type = acpi_rs_get_resource_type (*byte_stream_buffer); 137 resource_type = acpi_rs_get_resource_type (*byte_stream_buffer);
142 138
143 switch (resource_type) { 139 switch (resource_type) {
@@ -299,28 +295,23 @@ acpi_rs_byte_stream_to_list (
299 return_ACPI_STATUS (status); 295 return_ACPI_STATUS (status);
300 } 296 }
301 297
302 /* 298 /* Update the return value and counter */
303 * Update the return value and counter 299
304 */
305 bytes_parsed += bytes_consumed; 300 bytes_parsed += bytes_consumed;
306 301
307 /* 302 /* Set the byte stream to point to the next resource */
308 * Set the byte stream to point to the next resource 303
309 */
310 byte_stream_buffer += bytes_consumed; 304 byte_stream_buffer += bytes_consumed;
311 305
312 /* 306 /* Set the Buffer to the next structure */
313 * Set the Buffer to the next structure 307
314 */
315 resource = ACPI_CAST_PTR (struct acpi_resource, buffer); 308 resource = ACPI_CAST_PTR (struct acpi_resource, buffer);
316 resource->length = (u32) ACPI_ALIGN_RESOURCE_SIZE (resource->length); 309 resource->length = (u32) ACPI_ALIGN_RESOURCE_SIZE (resource->length);
317 buffer += ACPI_ALIGN_RESOURCE_SIZE (structure_size); 310 buffer += ACPI_ALIGN_RESOURCE_SIZE (structure_size);
311 }
318 312
319 } /* end while */ 313 /* Check the reason for exiting the while loop */
320 314
321 /*
322 * Check the reason for exiting the while loop
323 */
324 if (!end_tag_processed) { 315 if (!end_tag_processed) {
325 return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG); 316 return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);
326 } 317 }
@@ -424,9 +415,8 @@ acpi_rs_list_to_byte_stream (
424 */ 415 */
425 status = acpi_rs_end_tag_stream (linked_list, &buffer, &bytes_consumed); 416 status = acpi_rs_end_tag_stream (linked_list, &buffer, &bytes_consumed);
426 417
427 /* 418 /* An End Tag indicates the end of the Resource Template */
428 * An End Tag indicates the end of the Resource Template 419
429 */
430 done = TRUE; 420 done = TRUE;
431 break; 421 break;
432 422
@@ -488,27 +478,25 @@ acpi_rs_list_to_byte_stream (
488 default: 478 default:
489 /* 479 /*
490 * If we get here, everything is out of sync, 480 * If we get here, everything is out of sync,
491 * so exit with an error 481 * so exit with an error
492 */ 482 */
493 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Invalid descriptor type (%X) in resource list\n", 483 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
484 "Invalid descriptor type (%X) in resource list\n",
494 linked_list->id)); 485 linked_list->id));
495 status = AE_BAD_DATA; 486 status = AE_BAD_DATA;
496 break; 487 break;
497 488 }
498 } /* switch (linked_list->Id) */
499 489
500 if (ACPI_FAILURE (status)) { 490 if (ACPI_FAILURE (status)) {
501 return_ACPI_STATUS (status); 491 return_ACPI_STATUS (status);
502 } 492 }
503 493
504 /* 494 /* Set the Buffer to point to the open byte */
505 * Set the Buffer to point to the open byte 495
506 */
507 buffer += bytes_consumed; 496 buffer += bytes_consumed;
508 497
509 /* 498 /* Point to the next object */
510 * Point to the next object 499
511 */
512 linked_list = ACPI_PTR_ADD (struct acpi_resource, 500 linked_list = ACPI_PTR_ADD (struct acpi_resource,
513 linked_list, linked_list->length); 501 linked_list, linked_list->length);
514 } 502 }
diff --git a/drivers/acpi/resources/rsmemory.c b/drivers/acpi/resources/rsmemory.c
index 7c935aecf075..91d0207f01ac 100644
--- a/drivers/acpi/resources/rsmemory.c
+++ b/drivers/acpi/resources/rsmemory.c
@@ -81,15 +81,15 @@ acpi_rs_memory24_resource (
81 struct acpi_resource *output_struct = (void *) *output_buffer; 81 struct acpi_resource *output_struct = (void *) *output_buffer;
82 u16 temp16 = 0; 82 u16 temp16 = 0;
83 u8 temp8 = 0; 83 u8 temp8 = 0;
84 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_mem24); 84 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (
85 struct acpi_resource_mem24);
85 86
86 87
87 ACPI_FUNCTION_TRACE ("rs_memory24_resource"); 88 ACPI_FUNCTION_TRACE ("rs_memory24_resource");
88 89
89 90
90 /* 91 /* Point past the Descriptor to get the number of bytes consumed */
91 * Point past the Descriptor to get the number of bytes consumed 92
92 */
93 buffer += 1; 93 buffer += 1;
94 94
95 ACPI_MOVE_16_TO_16 (&temp16, buffer); 95 ACPI_MOVE_16_TO_16 (&temp16, buffer);
@@ -97,48 +97,41 @@ acpi_rs_memory24_resource (
97 *bytes_consumed = (acpi_size) temp16 + 3; 97 *bytes_consumed = (acpi_size) temp16 + 3;
98 output_struct->id = ACPI_RSTYPE_MEM24; 98 output_struct->id = ACPI_RSTYPE_MEM24;
99 99
100 /* 100 /* Check Byte 3 the Read/Write bit */
101 * Check Byte 3 the Read/Write bit 101
102 */
103 temp8 = *buffer; 102 temp8 = *buffer;
104 buffer += 1; 103 buffer += 1;
105 output_struct->data.memory24.read_write_attribute = temp8 & 0x01; 104 output_struct->data.memory24.read_write_attribute = temp8 & 0x01;
106 105
107 /* 106 /* Get min_base_address (Bytes 4-5) */
108 * Get min_base_address (Bytes 4-5) 107
109 */
110 ACPI_MOVE_16_TO_16 (&temp16, buffer); 108 ACPI_MOVE_16_TO_16 (&temp16, buffer);
111 buffer += 2; 109 buffer += 2;
112 output_struct->data.memory24.min_base_address = temp16; 110 output_struct->data.memory24.min_base_address = temp16;
113 111
114 /* 112 /* Get max_base_address (Bytes 6-7) */
115 * Get max_base_address (Bytes 6-7) 113
116 */
117 ACPI_MOVE_16_TO_16 (&temp16, buffer); 114 ACPI_MOVE_16_TO_16 (&temp16, buffer);
118 buffer += 2; 115 buffer += 2;
119 output_struct->data.memory24.max_base_address = temp16; 116 output_struct->data.memory24.max_base_address = temp16;
120 117
121 /* 118 /* Get Alignment (Bytes 8-9) */
122 * Get Alignment (Bytes 8-9) 119
123 */
124 ACPI_MOVE_16_TO_16 (&temp16, buffer); 120 ACPI_MOVE_16_TO_16 (&temp16, buffer);
125 buffer += 2; 121 buffer += 2;
126 output_struct->data.memory24.alignment = temp16; 122 output_struct->data.memory24.alignment = temp16;
127 123
128 /* 124 /* Get range_length (Bytes 10-11) */
129 * Get range_length (Bytes 10-11) 125
130 */
131 ACPI_MOVE_16_TO_16 (&temp16, buffer); 126 ACPI_MOVE_16_TO_16 (&temp16, buffer);
132 output_struct->data.memory24.range_length = temp16; 127 output_struct->data.memory24.range_length = temp16;
133 128
134 /* 129 /* Set the Length parameter */
135 * Set the Length parameter 130
136 */
137 output_struct->length = (u32) struct_size; 131 output_struct->length = (u32) struct_size;
138 132
139 /* 133 /* Return the final size of the structure */
140 * Return the final size of the structure 134
141 */
142 *structure_size = struct_size; 135 *structure_size = struct_size;
143 return_ACPI_STATUS (AE_OK); 136 return_ACPI_STATUS (AE_OK);
144} 137}
@@ -174,53 +167,45 @@ acpi_rs_memory24_stream (
174 ACPI_FUNCTION_TRACE ("rs_memory24_stream"); 167 ACPI_FUNCTION_TRACE ("rs_memory24_stream");
175 168
176 169
177 /* 170 /* The descriptor field is static */
178 * The descriptor field is static 171
179 */
180 *buffer = 0x81; 172 *buffer = 0x81;
181 buffer += 1; 173 buffer += 1;
182 174
183 /* 175 /* The length field is static */
184 * The length field is static 176
185 */
186 temp16 = 0x09; 177 temp16 = 0x09;
187 ACPI_MOVE_16_TO_16 (buffer, &temp16); 178 ACPI_MOVE_16_TO_16 (buffer, &temp16);
188 buffer += 2; 179 buffer += 2;
189 180
190 /* 181 /* Set the Information Byte */
191 * Set the Information Byte 182
192 */
193 temp8 = (u8) (linked_list->data.memory24.read_write_attribute & 0x01); 183 temp8 = (u8) (linked_list->data.memory24.read_write_attribute & 0x01);
194 *buffer = temp8; 184 *buffer = temp8;
195 buffer += 1; 185 buffer += 1;
196 186
197 /* 187 /* Set the Range minimum base address */
198 * Set the Range minimum base address 188
199 */
200 ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.memory24.min_base_address); 189 ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.memory24.min_base_address);
201 buffer += 2; 190 buffer += 2;
202 191
203 /* 192 /* Set the Range maximum base address */
204 * Set the Range maximum base address 193
205 */
206 ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.memory24.max_base_address); 194 ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.memory24.max_base_address);
207 buffer += 2; 195 buffer += 2;
208 196
209 /* 197 /* Set the base alignment */
210 * Set the base alignment 198
211 */
212 ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.memory24.alignment); 199 ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.memory24.alignment);
213 buffer += 2; 200 buffer += 2;
214 201
215 /* 202 /* Set the range length */
216 * Set the range length 203
217 */
218 ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.memory24.range_length); 204 ACPI_MOVE_32_TO_16 (buffer, &linked_list->data.memory24.range_length);
219 buffer += 2; 205 buffer += 2;
220 206
221 /* 207 /* Return the number of bytes consumed in this operation */
222 * Return the number of bytes consumed in this operation 208
223 */
224 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer); 209 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
225 return_ACPI_STATUS (AE_OK); 210 return_ACPI_STATUS (AE_OK);
226} 211}
@@ -258,15 +243,15 @@ acpi_rs_memory32_range_resource (
258 struct acpi_resource *output_struct = (void *) *output_buffer; 243 struct acpi_resource *output_struct = (void *) *output_buffer;
259 u16 temp16 = 0; 244 u16 temp16 = 0;
260 u8 temp8 = 0; 245 u8 temp8 = 0;
261 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_mem32); 246 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (
247 struct acpi_resource_mem32);
262 248
263 249
264 ACPI_FUNCTION_TRACE ("rs_memory32_range_resource"); 250 ACPI_FUNCTION_TRACE ("rs_memory32_range_resource");
265 251
266 252
267 /* 253 /* Point past the Descriptor to get the number of bytes consumed */
268 * Point past the Descriptor to get the number of bytes consumed 254
269 */
270 buffer += 1; 255 buffer += 1;
271 256
272 ACPI_MOVE_16_TO_16 (&temp16, buffer); 257 ACPI_MOVE_16_TO_16 (&temp16, buffer);
@@ -285,45 +270,38 @@ acpi_rs_memory32_range_resource (
285 * 4 * sizeof(RESOURCE_DATA) instead of 4 * sizeof(u8) 270 * 4 * sizeof(RESOURCE_DATA) instead of 4 * sizeof(u8)
286 */ 271 */
287 272
288 /* 273 /* Check Byte 3 the Read/Write bit */
289 * Check Byte 3 the Read/Write bit 274
290 */
291 temp8 = *buffer; 275 temp8 = *buffer;
292 buffer += 1; 276 buffer += 1;
293 277
294 output_struct->data.memory32.read_write_attribute = temp8 & 0x01; 278 output_struct->data.memory32.read_write_attribute = temp8 & 0x01;
295 279
296 /* 280 /* Get min_base_address (Bytes 4-7) */
297 * Get min_base_address (Bytes 4-7) 281
298 */
299 ACPI_MOVE_32_TO_32 (&output_struct->data.memory32.min_base_address, buffer); 282 ACPI_MOVE_32_TO_32 (&output_struct->data.memory32.min_base_address, buffer);
300 buffer += 4; 283 buffer += 4;
301 284
302 /* 285 /* Get max_base_address (Bytes 8-11) */
303 * Get max_base_address (Bytes 8-11) 286
304 */
305 ACPI_MOVE_32_TO_32 (&output_struct->data.memory32.max_base_address, buffer); 287 ACPI_MOVE_32_TO_32 (&output_struct->data.memory32.max_base_address, buffer);
306 buffer += 4; 288 buffer += 4;
307 289
308 /* 290 /* Get Alignment (Bytes 12-15) */
309 * Get Alignment (Bytes 12-15) 291
310 */
311 ACPI_MOVE_32_TO_32 (&output_struct->data.memory32.alignment, buffer); 292 ACPI_MOVE_32_TO_32 (&output_struct->data.memory32.alignment, buffer);
312 buffer += 4; 293 buffer += 4;
313 294
314 /* 295 /* Get range_length (Bytes 16-19) */
315 * Get range_length (Bytes 16-19) 296
316 */
317 ACPI_MOVE_32_TO_32 (&output_struct->data.memory32.range_length, buffer); 297 ACPI_MOVE_32_TO_32 (&output_struct->data.memory32.range_length, buffer);
318 298
319 /* 299 /* Set the Length parameter */
320 * Set the Length parameter 300
321 */
322 output_struct->length = (u32) struct_size; 301 output_struct->length = (u32) struct_size;
323 302
324 /* 303 /* Return the final size of the structure */
325 * Return the final size of the structure 304
326 */
327 *structure_size = struct_size; 305 *structure_size = struct_size;
328 return_ACPI_STATUS (AE_OK); 306 return_ACPI_STATUS (AE_OK);
329} 307}
@@ -361,15 +339,15 @@ acpi_rs_fixed_memory32_resource (
361 struct acpi_resource *output_struct = (void *) *output_buffer; 339 struct acpi_resource *output_struct = (void *) *output_buffer;
362 u16 temp16 = 0; 340 u16 temp16 = 0;
363 u8 temp8 = 0; 341 u8 temp8 = 0;
364 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_fixed_mem32); 342 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (
343 struct acpi_resource_fixed_mem32);
365 344
366 345
367 ACPI_FUNCTION_TRACE ("rs_fixed_memory32_resource"); 346 ACPI_FUNCTION_TRACE ("rs_fixed_memory32_resource");
368 347
369 348
370 /* 349 /* Point past the Descriptor to get the number of bytes consumed */
371 * Point past the Descriptor to get the number of bytes consumed 350
372 */
373 buffer += 1; 351 buffer += 1;
374 ACPI_MOVE_16_TO_16 (&temp16, buffer); 352 ACPI_MOVE_16_TO_16 (&temp16, buffer);
375 353
@@ -378,32 +356,28 @@ acpi_rs_fixed_memory32_resource (
378 356
379 output_struct->id = ACPI_RSTYPE_FIXED_MEM32; 357 output_struct->id = ACPI_RSTYPE_FIXED_MEM32;
380 358
381 /* 359 /* Check Byte 3 the Read/Write bit */
382 * Check Byte 3 the Read/Write bit 360
383 */
384 temp8 = *buffer; 361 temp8 = *buffer;
385 buffer += 1; 362 buffer += 1;
386 output_struct->data.fixed_memory32.read_write_attribute = temp8 & 0x01; 363 output_struct->data.fixed_memory32.read_write_attribute = temp8 & 0x01;
387 364
388 /* 365 /* Get range_base_address (Bytes 4-7) */
389 * Get range_base_address (Bytes 4-7) 366
390 */ 367 ACPI_MOVE_32_TO_32 (&output_struct->data.fixed_memory32.range_base_address,
391 ACPI_MOVE_32_TO_32 (&output_struct->data.fixed_memory32.range_base_address, buffer); 368 buffer);
392 buffer += 4; 369 buffer += 4;
393 370
394 /* 371 /* Get range_length (Bytes 8-11) */
395 * Get range_length (Bytes 8-11) 372
396 */
397 ACPI_MOVE_32_TO_32 (&output_struct->data.fixed_memory32.range_length, buffer); 373 ACPI_MOVE_32_TO_32 (&output_struct->data.fixed_memory32.range_length, buffer);
398 374
399 /* 375 /* Set the Length parameter */
400 * Set the Length parameter 376
401 */
402 output_struct->length = (u32) struct_size; 377 output_struct->length = (u32) struct_size;
403 378
404 /* 379 /* Return the final size of the structure */
405 * Return the final size of the structure 380
406 */
407 *structure_size = struct_size; 381 *structure_size = struct_size;
408 return_ACPI_STATUS (AE_OK); 382 return_ACPI_STATUS (AE_OK);
409} 383}
@@ -439,54 +413,46 @@ acpi_rs_memory32_range_stream (
439 ACPI_FUNCTION_TRACE ("rs_memory32_range_stream"); 413 ACPI_FUNCTION_TRACE ("rs_memory32_range_stream");
440 414
441 415
442 /* 416 /* The descriptor field is static */
443 * The descriptor field is static 417
444 */
445 *buffer = 0x85; 418 *buffer = 0x85;
446 buffer += 1; 419 buffer += 1;
447 420
448 /* 421 /* The length field is static */
449 * The length field is static 422
450 */
451 temp16 = 0x11; 423 temp16 = 0x11;
452 424
453 ACPI_MOVE_16_TO_16 (buffer, &temp16); 425 ACPI_MOVE_16_TO_16 (buffer, &temp16);
454 buffer += 2; 426 buffer += 2;
455 427
456 /* 428 /* Set the Information Byte */
457 * Set the Information Byte 429
458 */
459 temp8 = (u8) (linked_list->data.memory32.read_write_attribute & 0x01); 430 temp8 = (u8) (linked_list->data.memory32.read_write_attribute & 0x01);
460 *buffer = temp8; 431 *buffer = temp8;
461 buffer += 1; 432 buffer += 1;
462 433
463 /* 434 /* Set the Range minimum base address */
464 * Set the Range minimum base address 435
465 */
466 ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.memory32.min_base_address); 436 ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.memory32.min_base_address);
467 buffer += 4; 437 buffer += 4;
468 438
469 /* 439 /* Set the Range maximum base address */
470 * Set the Range maximum base address 440
471 */
472 ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.memory32.max_base_address); 441 ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.memory32.max_base_address);
473 buffer += 4; 442 buffer += 4;
474 443
475 /* 444 /* Set the base alignment */
476 * Set the base alignment 445
477 */
478 ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.memory32.alignment); 446 ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.memory32.alignment);
479 buffer += 4; 447 buffer += 4;
480 448
481 /* 449 /* Set the range length */
482 * Set the range length 450
483 */
484 ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.memory32.range_length); 451 ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.memory32.range_length);
485 buffer += 4; 452 buffer += 4;
486 453
487 /* 454 /* Return the number of bytes consumed in this operation */
488 * Return the number of bytes consumed in this operation 455
489 */
490 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer); 456 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
491 return_ACPI_STATUS (AE_OK); 457 return_ACPI_STATUS (AE_OK);
492} 458}
@@ -522,44 +488,38 @@ acpi_rs_fixed_memory32_stream (
522 ACPI_FUNCTION_TRACE ("rs_fixed_memory32_stream"); 488 ACPI_FUNCTION_TRACE ("rs_fixed_memory32_stream");
523 489
524 490
525 /* 491 /* The descriptor field is static */
526 * The descriptor field is static 492
527 */
528 *buffer = 0x86; 493 *buffer = 0x86;
529 buffer += 1; 494 buffer += 1;
530 495
531 /* 496 /* The length field is static */
532 * The length field is static 497
533 */
534 temp16 = 0x09; 498 temp16 = 0x09;
535 499
536 ACPI_MOVE_16_TO_16 (buffer, &temp16); 500 ACPI_MOVE_16_TO_16 (buffer, &temp16);
537 buffer += 2; 501 buffer += 2;
538 502
539 /* 503 /* Set the Information Byte */
540 * Set the Information Byte 504
541 */
542 temp8 = (u8) (linked_list->data.fixed_memory32.read_write_attribute & 0x01); 505 temp8 = (u8) (linked_list->data.fixed_memory32.read_write_attribute & 0x01);
543 *buffer = temp8; 506 *buffer = temp8;
544 buffer += 1; 507 buffer += 1;
545 508
546 /* 509 /* Set the Range base address */
547 * Set the Range base address 510
548 */
549 ACPI_MOVE_32_TO_32 (buffer, 511 ACPI_MOVE_32_TO_32 (buffer,
550 &linked_list->data.fixed_memory32.range_base_address); 512 &linked_list->data.fixed_memory32.range_base_address);
551 buffer += 4; 513 buffer += 4;
552 514
553 /* 515 /* Set the range length */
554 * Set the range length 516
555 */
556 ACPI_MOVE_32_TO_32 (buffer, 517 ACPI_MOVE_32_TO_32 (buffer,
557 &linked_list->data.fixed_memory32.range_length); 518 &linked_list->data.fixed_memory32.range_length);
558 buffer += 4; 519 buffer += 4;
559 520
560 /* 521 /* Return the number of bytes consumed in this operation */
561 * Return the number of bytes consumed in this operation 522
562 */
563 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer); 523 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
564 return_ACPI_STATUS (AE_OK); 524 return_ACPI_STATUS (AE_OK);
565} 525}
diff --git a/drivers/acpi/resources/rsmisc.c b/drivers/acpi/resources/rsmisc.c
index d16be44b5df7..a1f1741f0d83 100644
--- a/drivers/acpi/resources/rsmisc.c
+++ b/drivers/acpi/resources/rsmisc.c
@@ -84,24 +84,20 @@ acpi_rs_end_tag_resource (
84 ACPI_FUNCTION_TRACE ("rs_end_tag_resource"); 84 ACPI_FUNCTION_TRACE ("rs_end_tag_resource");
85 85
86 86
87 /* 87 /* The number of bytes consumed is static */
88 * The number of bytes consumed is static 88
89 */
90 *bytes_consumed = 2; 89 *bytes_consumed = 2;
91 90
92 /* 91 /* Fill out the structure */
93 * Fill out the structure 92
94 */
95 output_struct->id = ACPI_RSTYPE_END_TAG; 93 output_struct->id = ACPI_RSTYPE_END_TAG;
96 94
97 /* 95 /* Set the Length parameter */
98 * Set the Length parameter 96
99 */
100 output_struct->length = 0; 97 output_struct->length = 0;
101 98
102 /* 99 /* Return the final size of the structure */
103 * Return the final size of the structure 100
104 */
105 *structure_size = struct_size; 101 *structure_size = struct_size;
106 return_ACPI_STATUS (AE_OK); 102 return_ACPI_STATUS (AE_OK);
107} 103}
@@ -136,9 +132,8 @@ acpi_rs_end_tag_stream (
136 ACPI_FUNCTION_TRACE ("rs_end_tag_stream"); 132 ACPI_FUNCTION_TRACE ("rs_end_tag_stream");
137 133
138 134
139 /* 135 /* The descriptor field is static */
140 * The descriptor field is static 136
141 */
142 *buffer = 0x79; 137 *buffer = 0x79;
143 buffer += 1; 138 buffer += 1;
144 139
@@ -151,9 +146,8 @@ acpi_rs_end_tag_stream (
151 *buffer = temp8; 146 *buffer = temp8;
152 buffer += 1; 147 buffer += 1;
153 148
154 /* 149 /* Return the number of bytes consumed in this operation */
155 * Return the number of bytes consumed in this operation 150
156 */
157 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer); 151 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
158 return_ACPI_STATUS (AE_OK); 152 return_ACPI_STATUS (AE_OK);
159} 153}
@@ -192,21 +186,20 @@ acpi_rs_vendor_resource (
192 u16 temp16 = 0; 186 u16 temp16 = 0;
193 u8 temp8 = 0; 187 u8 temp8 = 0;
194 u8 index; 188 u8 index;
195 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_vendor); 189 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (
190 struct acpi_resource_vendor);
196 191
197 192
198 ACPI_FUNCTION_TRACE ("rs_vendor_resource"); 193 ACPI_FUNCTION_TRACE ("rs_vendor_resource");
199 194
200 195
201 /* 196 /* Dereference the Descriptor to find if this is a large or small item. */
202 * Dereference the Descriptor to find if this is a large or small item. 197
203 */
204 temp8 = *buffer; 198 temp8 = *buffer;
205 199
206 if (temp8 & 0x80) { 200 if (temp8 & 0x80) {
207 /* 201 /* Large Item, point to the length field */
208 * Large Item, point to the length field 202
209 */
210 buffer += 1; 203 buffer += 1;
211 204
212 /* Dereference */ 205 /* Dereference */
@@ -222,9 +215,8 @@ acpi_rs_vendor_resource (
222 buffer += 2; 215 buffer += 2;
223 } 216 }
224 else { 217 else {
225 /* 218 /* Small Item, dereference the size */
226 * Small Item, dereference the size 219
227 */
228 temp16 = (u8)(*buffer & 0x07); 220 temp16 = (u8)(*buffer & 0x07);
229 221
230 /* Calculate bytes consumed */ 222 /* Calculate bytes consumed */
@@ -251,14 +243,12 @@ acpi_rs_vendor_resource (
251 */ 243 */
252 struct_size += ACPI_ROUND_UP_to_32_bITS (temp16); 244 struct_size += ACPI_ROUND_UP_to_32_bITS (temp16);
253 245
254 /* 246 /* Set the Length parameter */
255 * Set the Length parameter 247
256 */
257 output_struct->length = (u32) struct_size; 248 output_struct->length = (u32) struct_size;
258 249
259 /* 250 /* Return the final size of the structure */
260 * Return the final size of the structure 251
261 */
262 *structure_size = struct_size; 252 *structure_size = struct_size;
263 return_ACPI_STATUS (AE_OK); 253 return_ACPI_STATUS (AE_OK);
264} 254}
@@ -295,13 +285,11 @@ acpi_rs_vendor_stream (
295 ACPI_FUNCTION_TRACE ("rs_vendor_stream"); 285 ACPI_FUNCTION_TRACE ("rs_vendor_stream");
296 286
297 287
298 /* 288 /* Dereference the length to find if this is a large or small item. */
299 * Dereference the length to find if this is a large or small item. 289
300 */
301 if(linked_list->data.vendor_specific.length > 7) { 290 if(linked_list->data.vendor_specific.length > 7) {
302 /* 291 /* Large Item, Set the descriptor field and length bytes */
303 * Large Item, Set the descriptor field and length bytes 292
304 */
305 *buffer = 0x84; 293 *buffer = 0x84;
306 buffer += 1; 294 buffer += 1;
307 295
@@ -311,9 +299,8 @@ acpi_rs_vendor_stream (
311 buffer += 2; 299 buffer += 2;
312 } 300 }
313 else { 301 else {
314 /* 302 /* Small Item, Set the descriptor field */
315 * Small Item, Set the descriptor field 303
316 */
317 temp8 = 0x70; 304 temp8 = 0x70;
318 temp8 |= (u8) linked_list->data.vendor_specific.length; 305 temp8 |= (u8) linked_list->data.vendor_specific.length;
319 306
@@ -321,9 +308,8 @@ acpi_rs_vendor_stream (
321 buffer += 1; 308 buffer += 1;
322 } 309 }
323 310
324 /* 311 /* Loop through all of the Vendor Specific fields */
325 * Loop through all of the Vendor Specific fields 312
326 */
327 for (index = 0; index < linked_list->data.vendor_specific.length; index++) { 313 for (index = 0; index < linked_list->data.vendor_specific.length; index++) {
328 temp8 = linked_list->data.vendor_specific.reserved[index]; 314 temp8 = linked_list->data.vendor_specific.reserved[index];
329 315
@@ -331,9 +317,8 @@ acpi_rs_vendor_stream (
331 buffer += 1; 317 buffer += 1;
332 } 318 }
333 319
334 /* 320 /* Return the number of bytes consumed in this operation */
335 * Return the number of bytes consumed in this operation 321
336 */
337 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer); 322 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
338 return_ACPI_STATUS (AE_OK); 323 return_ACPI_STATUS (AE_OK);
339} 324}
@@ -370,40 +355,37 @@ acpi_rs_start_depend_fns_resource (
370 u8 *buffer = byte_stream_buffer; 355 u8 *buffer = byte_stream_buffer;
371 struct acpi_resource *output_struct = (void *) *output_buffer; 356 struct acpi_resource *output_struct = (void *) *output_buffer;
372 u8 temp8 = 0; 357 u8 temp8 = 0;
373 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_start_dpf); 358 acpi_size struct_size = ACPI_SIZEOF_RESOURCE (
359 struct acpi_resource_start_dpf);
374 360
375 361
376 ACPI_FUNCTION_TRACE ("rs_start_depend_fns_resource"); 362 ACPI_FUNCTION_TRACE ("rs_start_depend_fns_resource");
377 363
378 364
379 /* 365 /* The number of bytes consumed are found in the descriptor (Bits:0-1) */
380 * The number of bytes consumed are contained in the descriptor (Bits:0-1) 366
381 */
382 temp8 = *buffer; 367 temp8 = *buffer;
383 368
384 *bytes_consumed = (temp8 & 0x01) + 1; 369 *bytes_consumed = (temp8 & 0x01) + 1;
385 370
386 output_struct->id = ACPI_RSTYPE_START_DPF; 371 output_struct->id = ACPI_RSTYPE_START_DPF;
387 372
388 /* 373 /* Point to Byte 1 if it is used */
389 * Point to Byte 1 if it is used 374
390 */
391 if (2 == *bytes_consumed) { 375 if (2 == *bytes_consumed) {
392 buffer += 1; 376 buffer += 1;
393 temp8 = *buffer; 377 temp8 = *buffer;
394 378
395 /* 379 /* Check Compatibility priority */
396 * Check Compatibility priority 380
397 */
398 output_struct->data.start_dpf.compatibility_priority = temp8 & 0x03; 381 output_struct->data.start_dpf.compatibility_priority = temp8 & 0x03;
399 382
400 if (3 == output_struct->data.start_dpf.compatibility_priority) { 383 if (3 == output_struct->data.start_dpf.compatibility_priority) {
401 return_ACPI_STATUS (AE_AML_BAD_RESOURCE_VALUE); 384 return_ACPI_STATUS (AE_AML_BAD_RESOURCE_VALUE);
402 } 385 }
403 386
404 /* 387 /* Check Performance/Robustness preference */
405 * Check Performance/Robustness preference 388
406 */
407 output_struct->data.start_dpf.performance_robustness = (temp8 >> 2) & 0x03; 389 output_struct->data.start_dpf.performance_robustness = (temp8 >> 2) & 0x03;
408 390
409 if (3 == output_struct->data.start_dpf.performance_robustness) { 391 if (3 == output_struct->data.start_dpf.performance_robustness) {
@@ -412,20 +394,18 @@ acpi_rs_start_depend_fns_resource (
412 } 394 }
413 else { 395 else {
414 output_struct->data.start_dpf.compatibility_priority = 396 output_struct->data.start_dpf.compatibility_priority =
415 ACPI_ACCEPTABLE_CONFIGURATION; 397 ACPI_ACCEPTABLE_CONFIGURATION;
416 398
417 output_struct->data.start_dpf.performance_robustness = 399 output_struct->data.start_dpf.performance_robustness =
418 ACPI_ACCEPTABLE_CONFIGURATION; 400 ACPI_ACCEPTABLE_CONFIGURATION;
419 } 401 }
420 402
421 /* 403 /* Set the Length parameter */
422 * Set the Length parameter 404
423 */
424 output_struct->length = (u32) struct_size; 405 output_struct->length = (u32) struct_size;
425 406
426 /* 407 /* Return the final size of the structure */
427 * Return the final size of the structure 408
428 */
429 *structure_size = struct_size; 409 *structure_size = struct_size;
430 return_ACPI_STATUS (AE_OK); 410 return_ACPI_STATUS (AE_OK);
431} 411}
@@ -466,24 +446,20 @@ acpi_rs_end_depend_fns_resource (
466 ACPI_FUNCTION_TRACE ("rs_end_depend_fns_resource"); 446 ACPI_FUNCTION_TRACE ("rs_end_depend_fns_resource");
467 447
468 448
469 /* 449 /* The number of bytes consumed is static */
470 * The number of bytes consumed is static 450
471 */
472 *bytes_consumed = 1; 451 *bytes_consumed = 1;
473 452
474 /* 453 /* Fill out the structure */
475 * Fill out the structure 454
476 */
477 output_struct->id = ACPI_RSTYPE_END_DPF; 455 output_struct->id = ACPI_RSTYPE_END_DPF;
478 456
479 /* 457 /* Set the Length parameter */
480 * Set the Length parameter 458
481 */
482 output_struct->length = (u32) struct_size; 459 output_struct->length = (u32) struct_size;
483 460
484 /* 461 /* Return the final size of the structure */
485 * Return the final size of the structure 462
486 */
487 *structure_size = struct_size; 463 *structure_size = struct_size;
488 return_ACPI_STATUS (AE_OK); 464 return_ACPI_STATUS (AE_OK);
489} 465}
@@ -533,9 +509,8 @@ acpi_rs_start_depend_fns_stream (
533 *buffer = 0x31; 509 *buffer = 0x31;
534 buffer += 1; 510 buffer += 1;
535 511
536 /* 512 /* Set the Priority Byte Definition */
537 * Set the Priority Byte Definition 513
538 */
539 temp8 = 0; 514 temp8 = 0;
540 temp8 = (u8) ((linked_list->data.start_dpf.performance_robustness & 515 temp8 = (u8) ((linked_list->data.start_dpf.performance_robustness &
541 0x03) << 2); 516 0x03) << 2);
@@ -546,9 +521,8 @@ acpi_rs_start_depend_fns_stream (
546 521
547 buffer += 1; 522 buffer += 1;
548 523
549 /* 524 /* Return the number of bytes consumed in this operation */
550 * Return the number of bytes consumed in this operation 525
551 */
552 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer); 526 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
553 return_ACPI_STATUS (AE_OK); 527 return_ACPI_STATUS (AE_OK);
554} 528}
@@ -582,15 +556,13 @@ acpi_rs_end_depend_fns_stream (
582 ACPI_FUNCTION_TRACE ("rs_end_depend_fns_stream"); 556 ACPI_FUNCTION_TRACE ("rs_end_depend_fns_stream");
583 557
584 558
585 /* 559 /* The descriptor field is static */
586 * The descriptor field is static 560
587 */
588 *buffer = 0x38; 561 *buffer = 0x38;
589 buffer += 1; 562 buffer += 1;
590 563
591 /* 564 /* Return the number of bytes consumed in this operation */
592 * Return the number of bytes consumed in this operation 565
593 */
594 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer); 566 *bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
595 return_ACPI_STATUS (AE_OK); 567 return_ACPI_STATUS (AE_OK);
596} 568}
diff --git a/drivers/acpi/resources/rsutils.c b/drivers/acpi/resources/rsutils.c
index ee9ce13c053d..700cf7d65d76 100644
--- a/drivers/acpi/resources/rsutils.c
+++ b/drivers/acpi/resources/rsutils.c
@@ -83,10 +83,10 @@ acpi_rs_get_prt_method_data (
83 83
84 /* Parameters guaranteed valid by caller */ 84 /* Parameters guaranteed valid by caller */
85 85
86 /* 86 /* Execute the method, no parameters */
87 * Execute the method, no parameters 87
88 */ 88 status = acpi_ut_evaluate_object (handle, METHOD_NAME__PRT,
89 status = acpi_ut_evaluate_object (handle, "_PRT", ACPI_BTYPE_PACKAGE, &obj_desc); 89 ACPI_BTYPE_PACKAGE, &obj_desc);
90 if (ACPI_FAILURE (status)) { 90 if (ACPI_FAILURE (status)) {
91 return_ACPI_STATUS (status); 91 return_ACPI_STATUS (status);
92 } 92 }
@@ -136,10 +136,10 @@ acpi_rs_get_crs_method_data (
136 136
137 /* Parameters guaranteed valid by caller */ 137 /* Parameters guaranteed valid by caller */
138 138
139 /* 139 /* Execute the method, no parameters */
140 * Execute the method, no parameters 140
141 */ 141 status = acpi_ut_evaluate_object (handle, METHOD_NAME__CRS,
142 status = acpi_ut_evaluate_object (handle, "_CRS", ACPI_BTYPE_BUFFER, &obj_desc); 142 ACPI_BTYPE_BUFFER, &obj_desc);
143 if (ACPI_FAILURE (status)) { 143 if (ACPI_FAILURE (status)) {
144 return_ACPI_STATUS (status); 144 return_ACPI_STATUS (status);
145 } 145 }
@@ -175,6 +175,7 @@ acpi_rs_get_crs_method_data (
175 * and the contents of the callers buffer is undefined. 175 * and the contents of the callers buffer is undefined.
176 * 176 *
177 ******************************************************************************/ 177 ******************************************************************************/
178
178#ifdef ACPI_FUTURE_USAGE 179#ifdef ACPI_FUTURE_USAGE
179acpi_status 180acpi_status
180acpi_rs_get_prs_method_data ( 181acpi_rs_get_prs_method_data (
@@ -190,10 +191,10 @@ acpi_rs_get_prs_method_data (
190 191
191 /* Parameters guaranteed valid by caller */ 192 /* Parameters guaranteed valid by caller */
192 193
193 /* 194 /* Execute the method, no parameters */
194 * Execute the method, no parameters 195
195 */ 196 status = acpi_ut_evaluate_object (handle, METHOD_NAME__PRS,
196 status = acpi_ut_evaluate_object (handle, "_PRS", ACPI_BTYPE_BUFFER, &obj_desc); 197 ACPI_BTYPE_BUFFER, &obj_desc);
197 if (ACPI_FAILURE (status)) { 198 if (ACPI_FAILURE (status)) {
198 return_ACPI_STATUS (status); 199 return_ACPI_STATUS (status);
199 } 200 }
@@ -218,6 +219,7 @@ acpi_rs_get_prs_method_data (
218 * FUNCTION: acpi_rs_get_method_data 219 * FUNCTION: acpi_rs_get_method_data
219 * 220 *
220 * PARAMETERS: Handle - a handle to the containing object 221 * PARAMETERS: Handle - a handle to the containing object
222 * Path - Path to method, relative to Handle
221 * ret_buffer - a pointer to a buffer structure for the 223 * ret_buffer - a pointer to a buffer structure for the
222 * results 224 * results
223 * 225 *
@@ -246,9 +248,8 @@ acpi_rs_get_method_data (
246 248
247 /* Parameters guaranteed valid by caller */ 249 /* Parameters guaranteed valid by caller */
248 250
249 /* 251 /* Execute the method, no parameters */
250 * Execute the method, no parameters 252
251 */
252 status = acpi_ut_evaluate_object (handle, path, ACPI_BTYPE_BUFFER, &obj_desc); 253 status = acpi_ut_evaluate_object (handle, path, ACPI_BTYPE_BUFFER, &obj_desc);
253 if (ACPI_FAILURE (status)) { 254 if (ACPI_FAILURE (status)) {
254 return_ACPI_STATUS (status); 255 return_ACPI_STATUS (status);
@@ -314,18 +315,16 @@ acpi_rs_set_srs_method_data (
314 return_ACPI_STATUS (status); 315 return_ACPI_STATUS (status);
315 } 316 }
316 317
317 /* 318 /* Init the param object */
318 * Init the param object 319
319 */
320 params[0] = acpi_ut_create_internal_object (ACPI_TYPE_BUFFER); 320 params[0] = acpi_ut_create_internal_object (ACPI_TYPE_BUFFER);
321 if (!params[0]) { 321 if (!params[0]) {
322 acpi_os_free (buffer.pointer); 322 acpi_os_free (buffer.pointer);
323 return_ACPI_STATUS (AE_NO_MEMORY); 323 return_ACPI_STATUS (AE_NO_MEMORY);
324 } 324 }
325 325
326 /* 326 /* Set up the parameter object */
327 * Set up the parameter object 327
328 */
329 params[0]->buffer.length = (u32) buffer.length; 328 params[0]->buffer.length = (u32) buffer.length;
330 params[0]->buffer.pointer = buffer.pointer; 329 params[0]->buffer.pointer = buffer.pointer;
331 params[0]->common.flags = AOPOBJ_DATA_VALID; 330 params[0]->common.flags = AOPOBJ_DATA_VALID;
@@ -335,10 +334,9 @@ acpi_rs_set_srs_method_data (
335 info.parameters = params; 334 info.parameters = params;
336 info.parameter_type = ACPI_PARAM_ARGS; 335 info.parameter_type = ACPI_PARAM_ARGS;
337 336
338 /* 337 /* Execute the method, no return value */
339 * Execute the method, no return value 338
340 */ 339 status = acpi_ns_evaluate_relative (METHOD_NAME__SRS, &info);
341 status = acpi_ns_evaluate_relative ("_SRS", &info);
342 if (ACPI_SUCCESS (status)) { 340 if (ACPI_SUCCESS (status)) {
343 /* Delete any return object (especially if implicit_return is enabled) */ 341 /* Delete any return object (especially if implicit_return is enabled) */
344 342
@@ -347,9 +345,8 @@ acpi_rs_set_srs_method_data (
347 } 345 }
348 } 346 }
349 347
350 /* 348 /* Clean up and return the status from acpi_ns_evaluate_relative */
351 * Clean up and return the status from acpi_ns_evaluate_relative 349
352 */
353 acpi_ut_remove_reference (params[0]); 350 acpi_ut_remove_reference (params[0]);
354 return_ACPI_STATUS (status); 351 return_ACPI_STATUS (status);
355} 352}
diff --git a/drivers/acpi/resources/rsxface.c b/drivers/acpi/resources/rsxface.c
index a9cdcbeb3432..83c944b8b097 100644
--- a/drivers/acpi/resources/rsxface.c
+++ b/drivers/acpi/resources/rsxface.c
@@ -49,6 +49,23 @@
49#define _COMPONENT ACPI_RESOURCES 49#define _COMPONENT ACPI_RESOURCES
50 ACPI_MODULE_NAME ("rsxface") 50 ACPI_MODULE_NAME ("rsxface")
51 51
52/* Local macros for 16,32-bit to 64-bit conversion */
53
54#define ACPI_COPY_FIELD(out, in, field) ((out)->field = (in)->field)
55#define ACPI_COPY_ADDRESS(out, in) \
56 ACPI_COPY_FIELD(out, in, resource_type); \
57 ACPI_COPY_FIELD(out, in, producer_consumer); \
58 ACPI_COPY_FIELD(out, in, decode); \
59 ACPI_COPY_FIELD(out, in, min_address_fixed); \
60 ACPI_COPY_FIELD(out, in, max_address_fixed); \
61 ACPI_COPY_FIELD(out, in, attribute); \
62 ACPI_COPY_FIELD(out, in, granularity); \
63 ACPI_COPY_FIELD(out, in, min_address_range); \
64 ACPI_COPY_FIELD(out, in, max_address_range); \
65 ACPI_COPY_FIELD(out, in, address_translation_offset); \
66 ACPI_COPY_FIELD(out, in, address_length); \
67 ACPI_COPY_FIELD(out, in, resource_source);
68
52 69
53/******************************************************************************* 70/*******************************************************************************
54 * 71 *
@@ -180,6 +197,7 @@ EXPORT_SYMBOL(acpi_get_current_resources);
180 * and the value of ret_buffer is undefined. 197 * and the value of ret_buffer is undefined.
181 * 198 *
182 ******************************************************************************/ 199 ******************************************************************************/
200
183#ifdef ACPI_FUTURE_USAGE 201#ifdef ACPI_FUTURE_USAGE
184acpi_status 202acpi_status
185acpi_get_possible_resources ( 203acpi_get_possible_resources (
@@ -346,9 +364,8 @@ acpi_set_current_resources (
346 ACPI_FUNCTION_TRACE ("acpi_set_current_resources"); 364 ACPI_FUNCTION_TRACE ("acpi_set_current_resources");
347 365
348 366
349 /* 367 /* Must have a valid handle and buffer */
350 * Must have a valid handle and buffer 368
351 */
352 if ((!device_handle) || 369 if ((!device_handle) ||
353 (!in_buffer) || 370 (!in_buffer) ||
354 (!in_buffer->pointer) || 371 (!in_buffer->pointer) ||
@@ -362,21 +379,6 @@ acpi_set_current_resources (
362EXPORT_SYMBOL(acpi_set_current_resources); 379EXPORT_SYMBOL(acpi_set_current_resources);
363 380
364 381
365#define ACPI_COPY_FIELD(out, in, field) ((out)->field = (in)->field)
366#define ACPI_COPY_ADDRESS(out, in) \
367 ACPI_COPY_FIELD(out, in, resource_type); \
368 ACPI_COPY_FIELD(out, in, producer_consumer); \
369 ACPI_COPY_FIELD(out, in, decode); \
370 ACPI_COPY_FIELD(out, in, min_address_fixed); \
371 ACPI_COPY_FIELD(out, in, max_address_fixed); \
372 ACPI_COPY_FIELD(out, in, attribute); \
373 ACPI_COPY_FIELD(out, in, granularity); \
374 ACPI_COPY_FIELD(out, in, min_address_range); \
375 ACPI_COPY_FIELD(out, in, max_address_range); \
376 ACPI_COPY_FIELD(out, in, address_translation_offset); \
377 ACPI_COPY_FIELD(out, in, address_length); \
378 ACPI_COPY_FIELD(out, in, resource_source);
379
380/****************************************************************************** 382/******************************************************************************
381 * 383 *
382 * FUNCTION: acpi_resource_to_address64 384 * FUNCTION: acpi_resource_to_address64
@@ -408,14 +410,14 @@ acpi_resource_to_address64 (
408 case ACPI_RSTYPE_ADDRESS16: 410 case ACPI_RSTYPE_ADDRESS16:
409 411
410 address16 = (struct acpi_resource_address16 *) &resource->data; 412 address16 = (struct acpi_resource_address16 *) &resource->data;
411 ACPI_COPY_ADDRESS(out, address16); 413 ACPI_COPY_ADDRESS (out, address16);
412 break; 414 break;
413 415
414 416
415 case ACPI_RSTYPE_ADDRESS32: 417 case ACPI_RSTYPE_ADDRESS32:
416 418
417 address32 = (struct acpi_resource_address32 *) &resource->data; 419 address32 = (struct acpi_resource_address32 *) &resource->data;
418 ACPI_COPY_ADDRESS(out, address32); 420 ACPI_COPY_ADDRESS (out, address32);
419 break; 421 break;
420 422
421 423
@@ -434,4 +436,3 @@ acpi_resource_to_address64 (
434 return (AE_OK); 436 return (AE_OK);
435} 437}
436EXPORT_SYMBOL(acpi_resource_to_address64); 438EXPORT_SYMBOL(acpi_resource_to_address64);
437
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 337d49b5564b..cbcda30c172d 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -1061,13 +1061,15 @@ acpi_add_single_object (
1061 /* 1061 /*
1062 * Status 1062 * Status
1063 * ------ 1063 * ------
1064 * See if the device is present. We always assume that non-Device() 1064 * See if the device is present. We always assume that non-Device
1065 * objects (e.g. thermal zones, power resources, processors, etc.) are 1065 * and non-Processor objects (e.g. thermal zones, power resources,
1066 * present, functioning, etc. (at least when parent object is present). 1066 * etc.) are present, functioning, etc. (at least when parent object
1067 * Note that _STA has a different meaning for some objects (e.g. 1067 * is present). Note that _STA has a different meaning for some
1068 * power resources) so we need to be careful how we use it. 1068 * objects (e.g. power resources) so we need to be careful how we use
1069 * it.
1069 */ 1070 */
1070 switch (type) { 1071 switch (type) {
1072 case ACPI_BUS_TYPE_PROCESSOR:
1071 case ACPI_BUS_TYPE_DEVICE: 1073 case ACPI_BUS_TYPE_DEVICE:
1072 result = acpi_bus_get_status(device); 1074 result = acpi_bus_get_status(device);
1073 if (ACPI_FAILURE(result) || !device->status.present) { 1075 if (ACPI_FAILURE(result) || !device->status.present) {
diff --git a/drivers/acpi/sleep/main.c b/drivers/acpi/sleep/main.c
index 0a5d2a94131e..7249ba2b7a27 100644
--- a/drivers/acpi/sleep/main.c
+++ b/drivers/acpi/sleep/main.c
@@ -1,6 +1,7 @@
1/* 1/*
2 * sleep.c - ACPI sleep support. 2 * sleep.c - ACPI sleep support.
3 * 3 *
4 * Copyright (c) 2005 Alexey Starikovskiy <alexey.y.starikovskiy@intel.com>
4 * Copyright (c) 2004 David Shaohua Li <shaohua.li@intel.com> 5 * Copyright (c) 2004 David Shaohua Li <shaohua.li@intel.com>
5 * Copyright (c) 2000-2003 Patrick Mochel 6 * Copyright (c) 2000-2003 Patrick Mochel
6 * Copyright (c) 2003 Open Source Development Lab 7 * Copyright (c) 2003 Open Source Development Lab
@@ -14,7 +15,6 @@
14#include <linux/dmi.h> 15#include <linux/dmi.h>
15#include <linux/device.h> 16#include <linux/device.h>
16#include <linux/suspend.h> 17#include <linux/suspend.h>
17#include <asm/io.h>
18#include <acpi/acpi_bus.h> 18#include <acpi/acpi_bus.h>
19#include <acpi/acpi_drivers.h> 19#include <acpi/acpi_drivers.h>
20#include "sleep.h" 20#include "sleep.h"
@@ -27,10 +27,11 @@ extern void do_suspend_lowlevel_s4bios(void);
27extern void do_suspend_lowlevel(void); 27extern void do_suspend_lowlevel(void);
28 28
29static u32 acpi_suspend_states[] = { 29static u32 acpi_suspend_states[] = {
30 [PM_SUSPEND_ON] = ACPI_STATE_S0, 30 [PM_SUSPEND_ON] = ACPI_STATE_S0,
31 [PM_SUSPEND_STANDBY] = ACPI_STATE_S1, 31 [PM_SUSPEND_STANDBY] = ACPI_STATE_S1,
32 [PM_SUSPEND_MEM] = ACPI_STATE_S3, 32 [PM_SUSPEND_MEM] = ACPI_STATE_S3,
33 [PM_SUSPEND_DISK] = ACPI_STATE_S4, 33 [PM_SUSPEND_DISK] = ACPI_STATE_S4,
34 [PM_SUSPEND_MAX] = ACPI_STATE_S5
34}; 35};
35 36
36static int init_8259A_after_S1; 37static int init_8259A_after_S1;
@@ -44,30 +45,20 @@ static int init_8259A_after_S1;
44 * wakeup code to the waking vector. 45 * wakeup code to the waking vector.
45 */ 46 */
46 47
48extern int acpi_sleep_prepare(u32 acpi_state);
49extern void acpi_power_off(void);
50
47static int acpi_pm_prepare(suspend_state_t pm_state) 51static int acpi_pm_prepare(suspend_state_t pm_state)
48{ 52{
49 u32 acpi_state = acpi_suspend_states[pm_state]; 53 u32 acpi_state = acpi_suspend_states[pm_state];
50 54
51 if (!sleep_states[acpi_state]) 55 if (!sleep_states[acpi_state]) {
56 printk("acpi_pm_prepare does not support %d \n", pm_state);
52 return -EPERM; 57 return -EPERM;
53
54 /* do we have a wakeup address for S2 and S3? */
55 /* Here, we support only S4BIOS, those we set the wakeup address */
56 /* S4OS is only supported for now via swsusp.. */
57 if (pm_state == PM_SUSPEND_MEM || pm_state == PM_SUSPEND_DISK) {
58 if (!acpi_wakeup_address)
59 return -EFAULT;
60 acpi_set_firmware_waking_vector(
61 (acpi_physical_address) virt_to_phys(
62 (void *)acpi_wakeup_address));
63 } 58 }
64 ACPI_FLUSH_CPU_CACHE(); 59 return acpi_sleep_prepare(acpi_state);
65 acpi_enable_wakeup_device_prep(acpi_state);
66 acpi_enter_sleep_state_prep(acpi_state);
67 return 0;
68} 60}
69 61
70
71/** 62/**
72 * acpi_pm_enter - Actually enter a sleep state. 63 * acpi_pm_enter - Actually enter a sleep state.
73 * @pm_state: State we're entering. 64 * @pm_state: State we're entering.
@@ -92,11 +83,9 @@ static int acpi_pm_enter(suspend_state_t pm_state)
92 return error; 83 return error;
93 } 84 }
94 85
95
96 local_irq_save(flags); 86 local_irq_save(flags);
97 acpi_enable_wakeup_device(acpi_state); 87 acpi_enable_wakeup_device(acpi_state);
98 switch (pm_state) 88 switch (pm_state) {
99 {
100 case PM_SUSPEND_STANDBY: 89 case PM_SUSPEND_STANDBY:
101 barrier(); 90 barrier();
102 status = acpi_enter_sleep_state(acpi_state); 91 status = acpi_enter_sleep_state(acpi_state);
@@ -112,6 +101,10 @@ static int acpi_pm_enter(suspend_state_t pm_state)
112 else 101 else
113 do_suspend_lowlevel_s4bios(); 102 do_suspend_lowlevel_s4bios();
114 break; 103 break;
104 case PM_SUSPEND_MAX:
105 acpi_power_off();
106 break;
107
115 default: 108 default:
116 return -EINVAL; 109 return -EINVAL;
117 } 110 }
@@ -126,11 +119,9 @@ static int acpi_pm_enter(suspend_state_t pm_state)
126 if (pm_state > PM_SUSPEND_STANDBY) 119 if (pm_state > PM_SUSPEND_STANDBY)
127 acpi_restore_state_mem(); 120 acpi_restore_state_mem();
128 121
129
130 return ACPI_SUCCESS(status) ? 0 : -EFAULT; 122 return ACPI_SUCCESS(status) ? 0 : -EFAULT;
131} 123}
132 124
133
134/** 125/**
135 * acpi_pm_finish - Finish up suspend sequence. 126 * acpi_pm_finish - Finish up suspend sequence.
136 * @pm_state: State we're coming out of. 127 * @pm_state: State we're coming out of.
@@ -156,27 +147,26 @@ static int acpi_pm_finish(suspend_state_t pm_state)
156 return 0; 147 return 0;
157} 148}
158 149
159
160int acpi_suspend(u32 acpi_state) 150int acpi_suspend(u32 acpi_state)
161{ 151{
162 suspend_state_t states[] = { 152 suspend_state_t states[] = {
163 [1] = PM_SUSPEND_STANDBY, 153 [1] = PM_SUSPEND_STANDBY,
164 [3] = PM_SUSPEND_MEM, 154 [3] = PM_SUSPEND_MEM,
165 [4] = PM_SUSPEND_DISK, 155 [4] = PM_SUSPEND_DISK,
156 [5] = PM_SUSPEND_MAX
166 }; 157 };
167 158
168 if (acpi_state <= 4 && states[acpi_state]) 159 if (acpi_state < 6 && states[acpi_state])
169 return pm_suspend(states[acpi_state]); 160 return pm_suspend(states[acpi_state]);
170 return -EINVAL; 161 return -EINVAL;
171} 162}
172 163
173static struct pm_ops acpi_pm_ops = { 164static struct pm_ops acpi_pm_ops = {
174 .prepare = acpi_pm_prepare, 165 .prepare = acpi_pm_prepare,
175 .enter = acpi_pm_enter, 166 .enter = acpi_pm_enter,
176 .finish = acpi_pm_finish, 167 .finish = acpi_pm_finish,
177}; 168};
178 169
179
180/* 170/*
181 * Toshiba fails to preserve interrupts over S1, reinitialization 171 * Toshiba fails to preserve interrupts over S1, reinitialization
182 * of 8259 is needed after S1 resume. 172 * of 8259 is needed after S1 resume.
@@ -190,16 +180,16 @@ static int __init init_ints_after_s1(struct dmi_system_id *d)
190 180
191static struct dmi_system_id __initdata acpisleep_dmi_table[] = { 181static struct dmi_system_id __initdata acpisleep_dmi_table[] = {
192 { 182 {
193 .callback = init_ints_after_s1, 183 .callback = init_ints_after_s1,
194 .ident = "Toshiba Satellite 4030cdt", 184 .ident = "Toshiba Satellite 4030cdt",
195 .matches = { DMI_MATCH(DMI_PRODUCT_NAME, "S4030CDT/4.3"), }, 185 .matches = {DMI_MATCH(DMI_PRODUCT_NAME, "S4030CDT/4.3"),},
196 }, 186 },
197 { }, 187 {},
198}; 188};
199 189
200static int __init acpi_sleep_init(void) 190static int __init acpi_sleep_init(void)
201{ 191{
202 int i = 0; 192 int i = 0;
203 193
204 dmi_check_system(acpisleep_dmi_table); 194 dmi_check_system(acpisleep_dmi_table);
205 195
@@ -207,7 +197,7 @@ static int __init acpi_sleep_init(void)
207 return 0; 197 return 0;
208 198
209 printk(KERN_INFO PREFIX "(supports"); 199 printk(KERN_INFO PREFIX "(supports");
210 for (i=0; i < ACPI_S_STATE_COUNT; i++) { 200 for (i = 0; i < ACPI_S_STATE_COUNT; i++) {
211 acpi_status status; 201 acpi_status status;
212 u8 type_a, type_b; 202 u8 type_a, type_b;
213 status = acpi_get_sleep_type_data(i, &type_a, &type_b); 203 status = acpi_get_sleep_type_data(i, &type_a, &type_b);
diff --git a/drivers/acpi/sleep/poweroff.c b/drivers/acpi/sleep/poweroff.c
index da237754ded9..1fc86e6b5ab9 100644
--- a/drivers/acpi/sleep/poweroff.c
+++ b/drivers/acpi/sleep/poweroff.c
@@ -3,35 +3,100 @@
3 * 3 *
4 * AKA S5, but it is independent of whether or not the kernel supports 4 * AKA S5, but it is independent of whether or not the kernel supports
5 * any other sleep support in the system. 5 * any other sleep support in the system.
6 *
7 * Copyright (c) 2005 Alexey Starikovskiy <alexey.y.starikovskiy@intel.com>
8 *
9 * This file is released under the GPLv2.
6 */ 10 */
7 11
8#include <linux/pm.h> 12#include <linux/pm.h>
9#include <linux/init.h> 13#include <linux/init.h>
10#include <acpi/acpi_bus.h> 14#include <acpi/acpi_bus.h>
11#include <linux/sched.h> 15#include <linux/sched.h>
16#include <linux/sysdev.h>
17#include <asm/io.h>
12#include "sleep.h" 18#include "sleep.h"
13 19
14static void 20int acpi_sleep_prepare(u32 acpi_state)
15acpi_power_off (void) 21{
22 /* Flag to do not allow second time invocation for S5 state */
23 static int shutdown_prepared = 0;
24#ifdef CONFIG_ACPI_SLEEP
25 /* do we have a wakeup address for S2 and S3? */
26 /* Here, we support only S4BIOS, those we set the wakeup address */
27 /* S4OS is only supported for now via swsusp.. */
28 if (acpi_state == ACPI_STATE_S3 || acpi_state == ACPI_STATE_S4) {
29 if (!acpi_wakeup_address) {
30 return -EFAULT;
31 }
32 acpi_set_firmware_waking_vector((acpi_physical_address)
33 virt_to_phys((void *)
34 acpi_wakeup_address));
35
36 }
37 ACPI_FLUSH_CPU_CACHE();
38 acpi_enable_wakeup_device_prep(acpi_state);
39#endif
40 if (acpi_state == ACPI_STATE_S5) {
41 /* Check if we were already called */
42 if (shutdown_prepared)
43 return 0;
44 acpi_wakeup_gpe_poweroff_prepare();
45 shutdown_prepared = 1;
46 }
47 acpi_enter_sleep_state_prep(acpi_state);
48 return 0;
49}
50
51void acpi_power_off(void)
16{ 52{
17 printk("%s called\n",__FUNCTION__); 53 printk("%s called\n", __FUNCTION__);
54 acpi_sleep_prepare(ACPI_STATE_S5);
55 local_irq_disable();
18 /* Some SMP machines only can poweroff in boot CPU */ 56 /* Some SMP machines only can poweroff in boot CPU */
19 set_cpus_allowed(current, cpumask_of_cpu(0)); 57 set_cpus_allowed(current, cpumask_of_cpu(0));
20 acpi_wakeup_gpe_poweroff_prepare();
21 acpi_enter_sleep_state_prep(ACPI_STATE_S5);
22 ACPI_DISABLE_IRQS();
23 acpi_enter_sleep_state(ACPI_STATE_S5); 58 acpi_enter_sleep_state(ACPI_STATE_S5);
24} 59}
25 60
61#ifdef CONFIG_PM
62
63static int acpi_shutdown(struct sys_device *x)
64{
65 return acpi_sleep_prepare(ACPI_STATE_S5);
66}
67
68static struct sysdev_class acpi_sysclass = {
69 set_kset_name("acpi"),
70 .shutdown = acpi_shutdown
71};
72
73static struct sys_device device_acpi = {
74 .id = 0,
75 .cls = &acpi_sysclass,
76};
77
78#endif
79
26static int acpi_poweroff_init(void) 80static int acpi_poweroff_init(void)
27{ 81{
28 if (!acpi_disabled) { 82 if (!acpi_disabled) {
29 u8 type_a, type_b; 83 u8 type_a, type_b;
30 acpi_status status; 84 acpi_status status;
31 85
32 status = acpi_get_sleep_type_data(ACPI_STATE_S5, &type_a, &type_b); 86 status =
33 if (ACPI_SUCCESS(status)) 87 acpi_get_sleep_type_data(ACPI_STATE_S5, &type_a, &type_b);
88 if (ACPI_SUCCESS(status)) {
34 pm_power_off = acpi_power_off; 89 pm_power_off = acpi_power_off;
90#ifdef CONFIG_PM
91 {
92 int error;
93 error = sysdev_class_register(&acpi_sysclass);
94 if (!error)
95 error = sysdev_register(&device_acpi);
96 return error;
97 }
98#endif
99 }
35 } 100 }
36 return 0; 101 return 0;
37} 102}
diff --git a/drivers/acpi/sleep/proc.c b/drivers/acpi/sleep/proc.c
index fd7c5a0649af..1be99f0996d6 100644
--- a/drivers/acpi/sleep/proc.c
+++ b/drivers/acpi/sleep/proc.c
@@ -13,13 +13,17 @@
13 13
14#include "sleep.h" 14#include "sleep.h"
15 15
16#ifdef CONFIG_ACPI_SLEEP_PROC_SLEEP
16#define ACPI_SYSTEM_FILE_SLEEP "sleep" 17#define ACPI_SYSTEM_FILE_SLEEP "sleep"
18#endif
19
17#define ACPI_SYSTEM_FILE_ALARM "alarm" 20#define ACPI_SYSTEM_FILE_ALARM "alarm"
18#define ACPI_SYSTEM_FILE_WAKEUP_DEVICE "wakeup" 21#define ACPI_SYSTEM_FILE_WAKEUP_DEVICE "wakeup"
19 22
20#define _COMPONENT ACPI_SYSTEM_COMPONENT 23#define _COMPONENT ACPI_SYSTEM_COMPONENT
21ACPI_MODULE_NAME ("sleep") 24ACPI_MODULE_NAME ("sleep")
22 25
26#ifdef CONFIG_ACPI_SLEEP_PROC_SLEEP
23 27
24static int acpi_system_sleep_seq_show(struct seq_file *seq, void *offset) 28static int acpi_system_sleep_seq_show(struct seq_file *seq, void *offset)
25{ 29{
@@ -78,6 +82,7 @@ acpi_system_write_sleep (
78 Done: 82 Done:
79 return error ? error : count; 83 return error ? error : count;
80} 84}
85#endif /* CONFIG_ACPI_SLEEP_PROC_SLEEP */
81 86
82static int acpi_system_alarm_seq_show(struct seq_file *seq, void *offset) 87static int acpi_system_alarm_seq_show(struct seq_file *seq, void *offset)
83{ 88{
@@ -452,6 +457,7 @@ static struct file_operations acpi_system_wakeup_device_fops = {
452 .release = single_release, 457 .release = single_release,
453}; 458};
454 459
460#ifdef CONFIG_ACPI_SLEEP_PROC_SLEEP
455static struct file_operations acpi_system_sleep_fops = { 461static struct file_operations acpi_system_sleep_fops = {
456 .open = acpi_system_sleep_open_fs, 462 .open = acpi_system_sleep_open_fs,
457 .read = seq_read, 463 .read = seq_read,
@@ -459,6 +465,7 @@ static struct file_operations acpi_system_sleep_fops = {
459 .llseek = seq_lseek, 465 .llseek = seq_lseek,
460 .release = single_release, 466 .release = single_release,
461}; 467};
468#endif /* CONFIG_ACPI_SLEEP_PROC_SLEEP */
462 469
463static struct file_operations acpi_system_alarm_fops = { 470static struct file_operations acpi_system_alarm_fops = {
464 .open = acpi_system_alarm_open_fs, 471 .open = acpi_system_alarm_open_fs,
@@ -484,11 +491,13 @@ static int acpi_sleep_proc_init(void)
484 if (acpi_disabled) 491 if (acpi_disabled)
485 return 0; 492 return 0;
486 493
494#ifdef CONFIG_ACPI_SLEEP_PROC_SLEEP
487 /* 'sleep' [R/W]*/ 495 /* 'sleep' [R/W]*/
488 entry = create_proc_entry(ACPI_SYSTEM_FILE_SLEEP, 496 entry = create_proc_entry(ACPI_SYSTEM_FILE_SLEEP,
489 S_IFREG|S_IRUGO|S_IWUSR, acpi_root_dir); 497 S_IFREG|S_IRUGO|S_IWUSR, acpi_root_dir);
490 if (entry) 498 if (entry)
491 entry->proc_fops = &acpi_system_sleep_fops; 499 entry->proc_fops = &acpi_system_sleep_fops;
500#endif
492 501
493 /* 'alarm' [R/W] */ 502 /* 'alarm' [R/W] */
494 entry = create_proc_entry(ACPI_SYSTEM_FILE_ALARM, 503 entry = create_proc_entry(ACPI_SYSTEM_FILE_ALARM,
diff --git a/drivers/acpi/tables/tbconvrt.c b/drivers/acpi/tables/tbconvrt.c
index 334327c1f66f..92e0c31539be 100644
--- a/drivers/acpi/tables/tbconvrt.c
+++ b/drivers/acpi/tables/tbconvrt.c
@@ -50,6 +50,24 @@
50#define _COMPONENT ACPI_TABLES 50#define _COMPONENT ACPI_TABLES
51 ACPI_MODULE_NAME ("tbconvrt") 51 ACPI_MODULE_NAME ("tbconvrt")
52 52
53/* Local prototypes */
54
55static void
56acpi_tb_init_generic_address (
57 struct acpi_generic_address *new_gas_struct,
58 u8 register_bit_width,
59 acpi_physical_address address);
60
61static void
62acpi_tb_convert_fadt1 (
63 struct fadt_descriptor_rev2 *local_fadt,
64 struct fadt_descriptor_rev1 *original_fadt);
65
66static void
67acpi_tb_convert_fadt2 (
68 struct fadt_descriptor_rev2 *local_fadt,
69 struct fadt_descriptor_rev2 *original_fadt);
70
53 71
54u8 acpi_fadt_is_v1; 72u8 acpi_fadt_is_v1;
55EXPORT_SYMBOL(acpi_fadt_is_v1); 73EXPORT_SYMBOL(acpi_fadt_is_v1);
@@ -142,11 +160,13 @@ acpi_tb_convert_to_xsdt (
142 for (i = 0; i < acpi_gbl_rsdt_table_count; i++) { 160 for (i = 0; i < acpi_gbl_rsdt_table_count; i++) {
143 if (acpi_gbl_RSDP->revision < 2) { 161 if (acpi_gbl_RSDP->revision < 2) {
144 ACPI_STORE_ADDRESS (new_table->table_offset_entry[i], 162 ACPI_STORE_ADDRESS (new_table->table_offset_entry[i],
145 (ACPI_CAST_PTR (struct rsdt_descriptor_rev1, table_info->pointer))->table_offset_entry[i]); 163 (ACPI_CAST_PTR (struct rsdt_descriptor_rev1,
164 table_info->pointer))->table_offset_entry[i]);
146 } 165 }
147 else { 166 else {
148 new_table->table_offset_entry[i] = 167 new_table->table_offset_entry[i] =
149 (ACPI_CAST_PTR (XSDT_DESCRIPTOR, table_info->pointer))->table_offset_entry[i]; 168 (ACPI_CAST_PTR (XSDT_DESCRIPTOR,
169 table_info->pointer))->table_offset_entry[i];
150 } 170 }
151 } 171 }
152 172
@@ -164,7 +184,7 @@ acpi_tb_convert_to_xsdt (
164} 184}
165 185
166 186
167/****************************************************************************** 187/*******************************************************************************
168 * 188 *
169 * FUNCTION: acpi_tb_init_generic_address 189 * FUNCTION: acpi_tb_init_generic_address
170 * 190 *
@@ -201,7 +221,7 @@ acpi_tb_init_generic_address (
201 * PARAMETERS: local_fadt - Pointer to new FADT 221 * PARAMETERS: local_fadt - Pointer to new FADT
202 * original_fadt - Pointer to old FADT 222 * original_fadt - Pointer to old FADT
203 * 223 *
204 * RETURN: Populates local_fadt 224 * RETURN: None, populates local_fadt
205 * 225 *
206 * DESCRIPTION: Convert an ACPI 1.0 FADT to common internal format 226 * DESCRIPTION: Convert an ACPI 1.0 FADT to common internal format
207 * 227 *
@@ -213,7 +233,6 @@ acpi_tb_convert_fadt1 (
213 struct fadt_descriptor_rev1 *original_fadt) 233 struct fadt_descriptor_rev1 *original_fadt)
214{ 234{
215 235
216
217 /* ACPI 1.0 FACS */ 236 /* ACPI 1.0 FACS */
218 /* The BIOS stored FADT should agree with Revision 1.0 */ 237 /* The BIOS stored FADT should agree with Revision 1.0 */
219 acpi_fadt_is_v1 = 1; 238 acpi_fadt_is_v1 = 1;
@@ -232,7 +251,8 @@ acpi_tb_convert_fadt1 (
232 ACPI_STORE_ADDRESS (local_fadt->Xdsdt, local_fadt->V1_dsdt); 251 ACPI_STORE_ADDRESS (local_fadt->Xdsdt, local_fadt->V1_dsdt);
233 252
234 /* 253 /*
235 * System Interrupt Model isn't used in ACPI 2.0 (local_fadt->Reserved1 = 0;) 254 * System Interrupt Model isn't used in ACPI 2.0
255 * (local_fadt->Reserved1 = 0;)
236 */ 256 */
237 257
238 /* 258 /*
@@ -269,7 +289,8 @@ acpi_tb_convert_fadt1 (
269 * that immediately follows. 289 * that immediately follows.
270 */ 290 */
271 ACPI_MEMCPY (&local_fadt->reset_register, 291 ACPI_MEMCPY (&local_fadt->reset_register,
272 &(ACPI_CAST_PTR (struct fadt_descriptor_rev2_minus, original_fadt))->reset_register, 292 &(ACPI_CAST_PTR (struct fadt_descriptor_rev2_minus,
293 original_fadt))->reset_register,
273 sizeof (struct acpi_generic_address) + 1); 294 sizeof (struct acpi_generic_address) + 1);
274 } 295 }
275 else { 296 else {
@@ -304,7 +325,8 @@ acpi_tb_convert_fadt1 (
304 325
305 acpi_tb_init_generic_address (&acpi_gbl_xpm1a_enable, 326 acpi_tb_init_generic_address (&acpi_gbl_xpm1a_enable,
306 (u8) ACPI_DIV_2 (acpi_gbl_FADT->pm1_evt_len), 327 (u8) ACPI_DIV_2 (acpi_gbl_FADT->pm1_evt_len),
307 (acpi_physical_address) (local_fadt->xpm1a_evt_blk.address + 328 (acpi_physical_address)
329 (local_fadt->xpm1a_evt_blk.address +
308 ACPI_DIV_2 (acpi_gbl_FADT->pm1_evt_len))); 330 ACPI_DIV_2 (acpi_gbl_FADT->pm1_evt_len)));
309 331
310 /* PM1B is optional; leave null if not present */ 332 /* PM1B is optional; leave null if not present */
@@ -312,7 +334,8 @@ acpi_tb_convert_fadt1 (
312 if (local_fadt->xpm1b_evt_blk.address) { 334 if (local_fadt->xpm1b_evt_blk.address) {
313 acpi_tb_init_generic_address (&acpi_gbl_xpm1b_enable, 335 acpi_tb_init_generic_address (&acpi_gbl_xpm1b_enable,
314 (u8) ACPI_DIV_2 (acpi_gbl_FADT->pm1_evt_len), 336 (u8) ACPI_DIV_2 (acpi_gbl_FADT->pm1_evt_len),
315 (acpi_physical_address) (local_fadt->xpm1b_evt_blk.address + 337 (acpi_physical_address)
338 (local_fadt->xpm1b_evt_blk.address +
316 ACPI_DIV_2 (acpi_gbl_FADT->pm1_evt_len))); 339 ACPI_DIV_2 (acpi_gbl_FADT->pm1_evt_len)));
317 } 340 }
318} 341}
@@ -325,7 +348,7 @@ acpi_tb_convert_fadt1 (
325 * PARAMETERS: local_fadt - Pointer to new FADT 348 * PARAMETERS: local_fadt - Pointer to new FADT
326 * original_fadt - Pointer to old FADT 349 * original_fadt - Pointer to old FADT
327 * 350 *
328 * RETURN: Populates local_fadt 351 * RETURN: None, populates local_fadt
329 * 352 *
330 * DESCRIPTION: Convert an ACPI 2.0 FADT to common internal format. 353 * DESCRIPTION: Convert an ACPI 2.0 FADT to common internal format.
331 * Handles optional "X" fields. 354 * Handles optional "X" fields.
@@ -348,7 +371,8 @@ acpi_tb_convert_fadt2 (
348 * is zero. 371 * is zero.
349 */ 372 */
350 if (!(local_fadt->xfirmware_ctrl)) { 373 if (!(local_fadt->xfirmware_ctrl)) {
351 ACPI_STORE_ADDRESS (local_fadt->xfirmware_ctrl, local_fadt->V1_firmware_ctrl); 374 ACPI_STORE_ADDRESS (local_fadt->xfirmware_ctrl,
375 local_fadt->V1_firmware_ctrl);
352 } 376 }
353 377
354 if (!(local_fadt->Xdsdt)) { 378 if (!(local_fadt->Xdsdt)) {
@@ -357,32 +381,38 @@ acpi_tb_convert_fadt2 (
357 381
358 if (!(local_fadt->xpm1a_evt_blk.address)) { 382 if (!(local_fadt->xpm1a_evt_blk.address)) {
359 acpi_tb_init_generic_address (&local_fadt->xpm1a_evt_blk, 383 acpi_tb_init_generic_address (&local_fadt->xpm1a_evt_blk,
360 local_fadt->pm1_evt_len, (acpi_physical_address) local_fadt->V1_pm1a_evt_blk); 384 local_fadt->pm1_evt_len,
385 (acpi_physical_address) local_fadt->V1_pm1a_evt_blk);
361 } 386 }
362 387
363 if (!(local_fadt->xpm1b_evt_blk.address)) { 388 if (!(local_fadt->xpm1b_evt_blk.address)) {
364 acpi_tb_init_generic_address (&local_fadt->xpm1b_evt_blk, 389 acpi_tb_init_generic_address (&local_fadt->xpm1b_evt_blk,
365 local_fadt->pm1_evt_len, (acpi_physical_address) local_fadt->V1_pm1b_evt_blk); 390 local_fadt->pm1_evt_len,
391 (acpi_physical_address) local_fadt->V1_pm1b_evt_blk);
366 } 392 }
367 393
368 if (!(local_fadt->xpm1a_cnt_blk.address)) { 394 if (!(local_fadt->xpm1a_cnt_blk.address)) {
369 acpi_tb_init_generic_address (&local_fadt->xpm1a_cnt_blk, 395 acpi_tb_init_generic_address (&local_fadt->xpm1a_cnt_blk,
370 local_fadt->pm1_cnt_len, (acpi_physical_address) local_fadt->V1_pm1a_cnt_blk); 396 local_fadt->pm1_cnt_len,
397 (acpi_physical_address) local_fadt->V1_pm1a_cnt_blk);
371 } 398 }
372 399
373 if (!(local_fadt->xpm1b_cnt_blk.address)) { 400 if (!(local_fadt->xpm1b_cnt_blk.address)) {
374 acpi_tb_init_generic_address (&local_fadt->xpm1b_cnt_blk, 401 acpi_tb_init_generic_address (&local_fadt->xpm1b_cnt_blk,
375 local_fadt->pm1_cnt_len, (acpi_physical_address) local_fadt->V1_pm1b_cnt_blk); 402 local_fadt->pm1_cnt_len,
403 (acpi_physical_address) local_fadt->V1_pm1b_cnt_blk);
376 } 404 }
377 405
378 if (!(local_fadt->xpm2_cnt_blk.address)) { 406 if (!(local_fadt->xpm2_cnt_blk.address)) {
379 acpi_tb_init_generic_address (&local_fadt->xpm2_cnt_blk, 407 acpi_tb_init_generic_address (&local_fadt->xpm2_cnt_blk,
380 local_fadt->pm2_cnt_len, (acpi_physical_address) local_fadt->V1_pm2_cnt_blk); 408 local_fadt->pm2_cnt_len,
409 (acpi_physical_address) local_fadt->V1_pm2_cnt_blk);
381 } 410 }
382 411
383 if (!(local_fadt->xpm_tmr_blk.address)) { 412 if (!(local_fadt->xpm_tmr_blk.address)) {
384 acpi_tb_init_generic_address (&local_fadt->xpm_tmr_blk, 413 acpi_tb_init_generic_address (&local_fadt->xpm_tmr_blk,
385 local_fadt->pm_tm_len, (acpi_physical_address) local_fadt->V1_pm_tmr_blk); 414 local_fadt->pm_tm_len,
415 (acpi_physical_address) local_fadt->V1_pm_tmr_blk);
386 } 416 }
387 417
388 if (!(local_fadt->xgpe0_blk.address)) { 418 if (!(local_fadt->xgpe0_blk.address)) {
@@ -399,18 +429,24 @@ acpi_tb_convert_fadt2 (
399 429
400 acpi_tb_init_generic_address (&acpi_gbl_xpm1a_enable, 430 acpi_tb_init_generic_address (&acpi_gbl_xpm1a_enable,
401 (u8) ACPI_DIV_2 (acpi_gbl_FADT->pm1_evt_len), 431 (u8) ACPI_DIV_2 (acpi_gbl_FADT->pm1_evt_len),
402 (acpi_physical_address) (local_fadt->xpm1a_evt_blk.address + 432 (acpi_physical_address)
433 (local_fadt->xpm1a_evt_blk.address +
403 ACPI_DIV_2 (acpi_gbl_FADT->pm1_evt_len))); 434 ACPI_DIV_2 (acpi_gbl_FADT->pm1_evt_len)));
404 acpi_gbl_xpm1a_enable.address_space_id = local_fadt->xpm1a_evt_blk.address_space_id; 435
436 acpi_gbl_xpm1a_enable.address_space_id =
437 local_fadt->xpm1a_evt_blk.address_space_id;
405 438
406 /* PM1B is optional; leave null if not present */ 439 /* PM1B is optional; leave null if not present */
407 440
408 if (local_fadt->xpm1b_evt_blk.address) { 441 if (local_fadt->xpm1b_evt_blk.address) {
409 acpi_tb_init_generic_address (&acpi_gbl_xpm1b_enable, 442 acpi_tb_init_generic_address (&acpi_gbl_xpm1b_enable,
410 (u8) ACPI_DIV_2 (acpi_gbl_FADT->pm1_evt_len), 443 (u8) ACPI_DIV_2 (acpi_gbl_FADT->pm1_evt_len),
411 (acpi_physical_address) (local_fadt->xpm1b_evt_blk.address + 444 (acpi_physical_address)
445 (local_fadt->xpm1b_evt_blk.address +
412 ACPI_DIV_2 (acpi_gbl_FADT->pm1_evt_len))); 446 ACPI_DIV_2 (acpi_gbl_FADT->pm1_evt_len)));
413 acpi_gbl_xpm1b_enable.address_space_id = local_fadt->xpm1b_evt_blk.address_space_id; 447
448 acpi_gbl_xpm1b_enable.address_space_id =
449 local_fadt->xpm1b_evt_blk.address_space_id;
414 } 450 }
415} 451}
416 452
@@ -432,7 +468,8 @@ acpi_tb_convert_fadt2 (
432 ******************************************************************************/ 468 ******************************************************************************/
433 469
434acpi_status 470acpi_status
435acpi_tb_convert_table_fadt (void) 471acpi_tb_convert_table_fadt (
472 void)
436{ 473{
437 struct fadt_descriptor_rev2 *local_fadt; 474 struct fadt_descriptor_rev2 *local_fadt;
438 struct acpi_table_desc *table_desc; 475 struct acpi_table_desc *table_desc;
@@ -446,7 +483,8 @@ acpi_tb_convert_table_fadt (void)
446 * at least as long as the version 1.0 FADT 483 * at least as long as the version 1.0 FADT
447 */ 484 */
448 if (acpi_gbl_FADT->length < sizeof (struct fadt_descriptor_rev1)) { 485 if (acpi_gbl_FADT->length < sizeof (struct fadt_descriptor_rev1)) {
449 ACPI_REPORT_ERROR (("FADT is invalid, too short: 0x%X\n", acpi_gbl_FADT->length)); 486 ACPI_REPORT_ERROR (("FADT is invalid, too short: 0x%X\n",
487 acpi_gbl_FADT->length));
450 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH); 488 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
451 } 489 }
452 490
@@ -461,8 +499,9 @@ acpi_tb_convert_table_fadt (void)
461 if (acpi_gbl_FADT->length < sizeof (struct fadt_descriptor_rev2)) { 499 if (acpi_gbl_FADT->length < sizeof (struct fadt_descriptor_rev2)) {
462 /* Length is too short to be a V2.0 table */ 500 /* Length is too short to be a V2.0 table */
463 501
464 ACPI_REPORT_WARNING (("Inconsistent FADT length (0x%X) and revision (0x%X), using FADT V1.0 portion of table\n", 502 ACPI_REPORT_WARNING ((
465 acpi_gbl_FADT->length, acpi_gbl_FADT->revision)); 503 "Inconsistent FADT length (0x%X) and revision (0x%X), using FADT V1.0 portion of table\n",
504 acpi_gbl_FADT->length, acpi_gbl_FADT->revision));
466 505
467 acpi_tb_convert_fadt1 (local_fadt, (void *) acpi_gbl_FADT); 506 acpi_tb_convert_fadt1 (local_fadt, (void *) acpi_gbl_FADT);
468 } 507 }
@@ -478,9 +517,8 @@ acpi_tb_convert_table_fadt (void)
478 acpi_tb_convert_fadt1 (local_fadt, (void *) acpi_gbl_FADT); 517 acpi_tb_convert_fadt1 (local_fadt, (void *) acpi_gbl_FADT);
479 } 518 }
480 519
481 /* 520 /* Global FADT pointer will point to the new common V2.0 FADT */
482 * Global FADT pointer will point to the new common V2.0 FADT 521
483 */
484 acpi_gbl_FADT = local_fadt; 522 acpi_gbl_FADT = local_fadt;
485 acpi_gbl_FADT->length = sizeof (FADT_DESCRIPTOR); 523 acpi_gbl_FADT->length = sizeof (FADT_DESCRIPTOR);
486 524
@@ -508,7 +546,7 @@ acpi_tb_convert_table_fadt (void)
508 546
509/******************************************************************************* 547/*******************************************************************************
510 * 548 *
511 * FUNCTION: acpi_tb_convert_table_facs 549 * FUNCTION: acpi_tb_build_common_facs
512 * 550 *
513 * PARAMETERS: table_info - Info for currently installed FACS 551 * PARAMETERS: table_info - Info for currently installed FACS
514 * 552 *
@@ -530,12 +568,14 @@ acpi_tb_build_common_facs (
530 /* Absolute minimum length is 24, but the ACPI spec says 64 */ 568 /* Absolute minimum length is 24, but the ACPI spec says 64 */
531 569
532 if (acpi_gbl_FACS->length < 24) { 570 if (acpi_gbl_FACS->length < 24) {
533 ACPI_REPORT_ERROR (("Invalid FACS table length: 0x%X\n", acpi_gbl_FACS->length)); 571 ACPI_REPORT_ERROR (("Invalid FACS table length: 0x%X\n",
572 acpi_gbl_FACS->length));
534 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH); 573 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
535 } 574 }
536 575
537 if (acpi_gbl_FACS->length < 64) { 576 if (acpi_gbl_FACS->length < 64) {
538 ACPI_REPORT_WARNING (("FACS is shorter than the ACPI specification allows: 0x%X, using anyway\n", 577 ACPI_REPORT_WARNING ((
578 "FACS is shorter than the ACPI specification allows: 0x%X, using anyway\n",
539 acpi_gbl_FACS->length)); 579 acpi_gbl_FACS->length));
540 } 580 }
541 581
@@ -548,7 +588,8 @@ acpi_tb_build_common_facs (
548 (!(acpi_gbl_FACS->xfirmware_waking_vector))) { 588 (!(acpi_gbl_FACS->xfirmware_waking_vector))) {
549 /* ACPI 1.0 FACS or short table or optional X_ field is zero */ 589 /* ACPI 1.0 FACS or short table or optional X_ field is zero */
550 590
551 acpi_gbl_common_fACS.firmware_waking_vector = ACPI_CAST_PTR (u64, &(acpi_gbl_FACS->firmware_waking_vector)); 591 acpi_gbl_common_fACS.firmware_waking_vector = ACPI_CAST_PTR (u64,
592 &(acpi_gbl_FACS->firmware_waking_vector));
552 acpi_gbl_common_fACS.vector_width = 32; 593 acpi_gbl_common_fACS.vector_width = 32;
553 } 594 }
554 else { 595 else {
diff --git a/drivers/acpi/tables/tbget.c b/drivers/acpi/tables/tbget.c
index 896f3ddda62e..4ab2aadc6133 100644
--- a/drivers/acpi/tables/tbget.c
+++ b/drivers/acpi/tables/tbget.c
@@ -49,6 +49,19 @@
49#define _COMPONENT ACPI_TABLES 49#define _COMPONENT ACPI_TABLES
50 ACPI_MODULE_NAME ("tbget") 50 ACPI_MODULE_NAME ("tbget")
51 51
52/* Local prototypes */
53
54static acpi_status
55acpi_tb_get_this_table (
56 struct acpi_pointer *address,
57 struct acpi_table_header *header,
58 struct acpi_table_desc *table_info);
59
60static acpi_status
61acpi_tb_table_override (
62 struct acpi_table_header *header,
63 struct acpi_table_desc *table_info);
64
52 65
53/******************************************************************************* 66/*******************************************************************************
54 * 67 *
@@ -76,9 +89,8 @@ acpi_tb_get_table (
76 ACPI_FUNCTION_TRACE ("tb_get_table"); 89 ACPI_FUNCTION_TRACE ("tb_get_table");
77 90
78 91
79 /* 92 /* Get the header in order to get signature and table size */
80 * Get the header in order to get signature and table size 93
81 */
82 status = acpi_tb_get_table_header (address, &header); 94 status = acpi_tb_get_table_header (address, &header);
83 if (ACPI_FAILURE (status)) { 95 if (ACPI_FAILURE (status)) {
84 return_ACPI_STATUS (status); 96 return_ACPI_STATUS (status);
@@ -127,8 +139,8 @@ acpi_tb_get_table_header (
127 139
128 140
129 /* 141 /*
130 * Flags contains the current processor mode (Virtual or Physical addressing) 142 * Flags contains the current processor mode (Virtual or Physical
131 * The pointer_type is either Logical or Physical 143 * addressing) The pointer_type is either Logical or Physical
132 */ 144 */
133 switch (address->pointer_type) { 145 switch (address->pointer_type) {
134 case ACPI_PHYSMODE_PHYSPTR: 146 case ACPI_PHYSMODE_PHYSPTR:
@@ -136,7 +148,8 @@ acpi_tb_get_table_header (
136 148
137 /* Pointer matches processor mode, copy the header */ 149 /* Pointer matches processor mode, copy the header */
138 150
139 ACPI_MEMCPY (return_header, address->pointer.logical, sizeof (struct acpi_table_header)); 151 ACPI_MEMCPY (return_header, address->pointer.logical,
152 sizeof (struct acpi_table_header));
140 break; 153 break;
141 154
142 155
@@ -144,10 +157,11 @@ acpi_tb_get_table_header (
144 157
145 /* Create a logical address for the physical pointer*/ 158 /* Create a logical address for the physical pointer*/
146 159
147 status = acpi_os_map_memory (address->pointer.physical, sizeof (struct acpi_table_header), 160 status = acpi_os_map_memory (address->pointer.physical,
148 (void *) &header); 161 sizeof (struct acpi_table_header), (void *) &header);
149 if (ACPI_FAILURE (status)) { 162 if (ACPI_FAILURE (status)) {
150 ACPI_REPORT_ERROR (("Could not map memory at %8.8X%8.8X for length %X\n", 163 ACPI_REPORT_ERROR ((
164 "Could not map memory at %8.8X%8.8X for length %X\n",
151 ACPI_FORMAT_UINT64 (address->pointer.physical), 165 ACPI_FORMAT_UINT64 (address->pointer.physical),
152 sizeof (struct acpi_table_header))); 166 sizeof (struct acpi_table_header)));
153 return_ACPI_STATUS (status); 167 return_ACPI_STATUS (status);
@@ -210,9 +224,8 @@ acpi_tb_get_table_body (
210 return_ACPI_STATUS (AE_BAD_PARAMETER); 224 return_ACPI_STATUS (AE_BAD_PARAMETER);
211 } 225 }
212 226
213 /* 227 /* Attempt table override. */
214 * Attempt table override. 228
215 */
216 status = acpi_tb_table_override (header, table_info); 229 status = acpi_tb_table_override (header, table_info);
217 if (ACPI_SUCCESS (status)) { 230 if (ACPI_SUCCESS (status)) {
218 /* Table was overridden by the host OS */ 231 /* Table was overridden by the host OS */
@@ -241,7 +254,7 @@ acpi_tb_get_table_body (
241 * 254 *
242 ******************************************************************************/ 255 ******************************************************************************/
243 256
244acpi_status 257static acpi_status
245acpi_tb_table_override ( 258acpi_tb_table_override (
246 struct acpi_table_header *header, 259 struct acpi_table_header *header,
247 struct acpi_table_desc *table_info) 260 struct acpi_table_desc *table_info)
@@ -315,7 +328,7 @@ acpi_tb_table_override (
315 * 328 *
316 ******************************************************************************/ 329 ******************************************************************************/
317 330
318acpi_status 331static acpi_status
319acpi_tb_get_this_table ( 332acpi_tb_get_this_table (
320 struct acpi_pointer *address, 333 struct acpi_pointer *address,
321 struct acpi_table_header *header, 334 struct acpi_table_header *header,
@@ -330,8 +343,8 @@ acpi_tb_get_this_table (
330 343
331 344
332 /* 345 /*
333 * Flags contains the current processor mode (Virtual or Physical addressing) 346 * Flags contains the current processor mode (Virtual or Physical
334 * The pointer_type is either Logical or Physical 347 * addressing) The pointer_type is either Logical or Physical
335 */ 348 */
336 switch (address->pointer_type) { 349 switch (address->pointer_type) {
337 case ACPI_PHYSMODE_PHYSPTR: 350 case ACPI_PHYSMODE_PHYSPTR:
@@ -341,7 +354,8 @@ acpi_tb_get_this_table (
341 354
342 full_table = ACPI_MEM_ALLOCATE (header->length); 355 full_table = ACPI_MEM_ALLOCATE (header->length);
343 if (!full_table) { 356 if (!full_table) {
344 ACPI_REPORT_ERROR (("Could not allocate table memory for [%4.4s] length %X\n", 357 ACPI_REPORT_ERROR ((
358 "Could not allocate table memory for [%4.4s] length %X\n",
345 header->signature, header->length)); 359 header->signature, header->length));
346 return_ACPI_STATUS (AE_NO_MEMORY); 360 return_ACPI_STATUS (AE_NO_MEMORY);
347 } 361 }
@@ -362,12 +376,14 @@ acpi_tb_get_this_table (
362 * Just map the table's physical memory 376 * Just map the table's physical memory
363 * into our address space. 377 * into our address space.
364 */ 378 */
365 status = acpi_os_map_memory (address->pointer.physical, (acpi_size) header->length, 379 status = acpi_os_map_memory (address->pointer.physical,
366 (void *) &full_table); 380 (acpi_size) header->length, (void *) &full_table);
367 if (ACPI_FAILURE (status)) { 381 if (ACPI_FAILURE (status)) {
368 ACPI_REPORT_ERROR (("Could not map memory for table [%4.4s] at %8.8X%8.8X for length %X\n", 382 ACPI_REPORT_ERROR ((
383 "Could not map memory for table [%4.4s] at %8.8X%8.8X for length %X\n",
369 header->signature, 384 header->signature,
370 ACPI_FORMAT_UINT64 (address->pointer.physical), header->length)); 385 ACPI_FORMAT_UINT64 (address->pointer.physical),
386 header->length));
371 return (status); 387 return (status);
372 } 388 }
373 389
@@ -465,9 +481,8 @@ acpi_tb_get_table_ptr (
465 return_ACPI_STATUS (AE_OK); 481 return_ACPI_STATUS (AE_OK);
466 } 482 }
467 483
468 /* 484 /* Check for instance out of range */
469 * Check for instance out of range 485
470 */
471 if (instance > acpi_gbl_table_lists[table_type].count) { 486 if (instance > acpi_gbl_table_lists[table_type].count) {
472 return_ACPI_STATUS (AE_NOT_EXIST); 487 return_ACPI_STATUS (AE_NOT_EXIST);
473 } 488 }
diff --git a/drivers/acpi/tables/tbgetall.c b/drivers/acpi/tables/tbgetall.c
index adc4270988bc..eea5b8cb5ebb 100644
--- a/drivers/acpi/tables/tbgetall.c
+++ b/drivers/acpi/tables/tbgetall.c
@@ -49,6 +49,19 @@
49#define _COMPONENT ACPI_TABLES 49#define _COMPONENT ACPI_TABLES
50 ACPI_MODULE_NAME ("tbgetall") 50 ACPI_MODULE_NAME ("tbgetall")
51 51
52/* Local prototypes */
53
54static acpi_status
55acpi_tb_get_primary_table (
56 struct acpi_pointer *address,
57 struct acpi_table_desc *table_info);
58
59static acpi_status
60acpi_tb_get_secondary_table (
61 struct acpi_pointer *address,
62 acpi_string signature,
63 struct acpi_table_desc *table_info);
64
52 65
53/******************************************************************************* 66/*******************************************************************************
54 * 67 *
@@ -63,7 +76,7 @@
63 * 76 *
64 ******************************************************************************/ 77 ******************************************************************************/
65 78
66acpi_status 79static acpi_status
67acpi_tb_get_primary_table ( 80acpi_tb_get_primary_table (
68 struct acpi_pointer *address, 81 struct acpi_pointer *address,
69 struct acpi_table_desc *table_info) 82 struct acpi_table_desc *table_info)
@@ -81,9 +94,8 @@ acpi_tb_get_primary_table (
81 return_ACPI_STATUS (AE_OK); 94 return_ACPI_STATUS (AE_OK);
82 } 95 }
83 96
84 /* 97 /* Get the header in order to get signature and table size */
85 * Get the header in order to get signature and table size 98
86 */
87 status = acpi_tb_get_table_header (address, &header); 99 status = acpi_tb_get_table_header (address, &header);
88 if (ACPI_FAILURE (status)) { 100 if (ACPI_FAILURE (status)) {
89 return_ACPI_STATUS (status); 101 return_ACPI_STATUS (status);
@@ -130,7 +142,7 @@ acpi_tb_get_primary_table (
130 * 142 *
131 ******************************************************************************/ 143 ******************************************************************************/
132 144
133acpi_status 145static acpi_status
134acpi_tb_get_secondary_table ( 146acpi_tb_get_secondary_table (
135 struct acpi_pointer *address, 147 struct acpi_pointer *address,
136 acpi_string signature, 148 acpi_string signature,
@@ -153,7 +165,8 @@ acpi_tb_get_secondary_table (
153 /* Signature must match request */ 165 /* Signature must match request */
154 166
155 if (ACPI_STRNCMP (header.signature, signature, ACPI_NAME_SIZE)) { 167 if (ACPI_STRNCMP (header.signature, signature, ACPI_NAME_SIZE)) {
156 ACPI_REPORT_ERROR (("Incorrect table signature - wanted [%s] found [%4.4s]\n", 168 ACPI_REPORT_ERROR ((
169 "Incorrect table signature - wanted [%s] found [%4.4s]\n",
157 signature, header.signature)); 170 signature, header.signature));
158 return_ACPI_STATUS (AE_BAD_SIGNATURE); 171 return_ACPI_STATUS (AE_BAD_SIGNATURE);
159 } 172 }
@@ -230,7 +243,8 @@ acpi_tb_get_required_tables (
230 for (i = 0; i < acpi_gbl_rsdt_table_count; i++) { 243 for (i = 0; i < acpi_gbl_rsdt_table_count; i++) {
231 /* Get the table address from the common internal XSDT */ 244 /* Get the table address from the common internal XSDT */
232 245
233 address.pointer.value = acpi_gbl_XSDT->table_offset_entry[i]; 246 address.pointer.value =
247 acpi_gbl_XSDT->table_offset_entry[i];
234 248
235 /* 249 /*
236 * Get the tables needed by this subsystem (FADT and any SSDTs). 250 * Get the tables needed by this subsystem (FADT and any SSDTs).
@@ -252,18 +266,18 @@ acpi_tb_get_required_tables (
252 } 266 }
253 267
254 /* 268 /*
255 * Convert the FADT to a common format. This allows earlier revisions of the 269 * Convert the FADT to a common format. This allows earlier revisions of
256 * table to coexist with newer versions, using common access code. 270 * the table to coexist with newer versions, using common access code.
257 */ 271 */
258 status = acpi_tb_convert_table_fadt (); 272 status = acpi_tb_convert_table_fadt ();
259 if (ACPI_FAILURE (status)) { 273 if (ACPI_FAILURE (status)) {
260 ACPI_REPORT_ERROR (("Could not convert FADT to internal common format\n")); 274 ACPI_REPORT_ERROR ((
275 "Could not convert FADT to internal common format\n"));
261 return_ACPI_STATUS (status); 276 return_ACPI_STATUS (status);
262 } 277 }
263 278
264 /* 279 /* Get the FACS (Pointed to by the FADT) */
265 * Get the FACS (Pointed to by the FADT) 280
266 */
267 address.pointer.value = acpi_gbl_FADT->xfirmware_ctrl; 281 address.pointer.value = acpi_gbl_FADT->xfirmware_ctrl;
268 282
269 status = acpi_tb_get_secondary_table (&address, FACS_SIG, &table_info); 283 status = acpi_tb_get_secondary_table (&address, FACS_SIG, &table_info);
@@ -282,9 +296,8 @@ acpi_tb_get_required_tables (
282 return_ACPI_STATUS (status); 296 return_ACPI_STATUS (status);
283 } 297 }
284 298
285 /* 299 /* Get/install the DSDT (Pointed to by the FADT) */
286 * Get/install the DSDT (Pointed to by the FADT) 300
287 */
288 address.pointer.value = acpi_gbl_FADT->Xdsdt; 301 address.pointer.value = acpi_gbl_FADT->Xdsdt;
289 302
290 status = acpi_tb_get_secondary_table (&address, DSDT_SIG, &table_info); 303 status = acpi_tb_get_secondary_table (&address, DSDT_SIG, &table_info);
diff --git a/drivers/acpi/tables/tbinstal.c b/drivers/acpi/tables/tbinstal.c
index 85d5bb01022c..629b64c8193d 100644
--- a/drivers/acpi/tables/tbinstal.c
+++ b/drivers/acpi/tables/tbinstal.c
@@ -49,6 +49,14 @@
49#define _COMPONENT ACPI_TABLES 49#define _COMPONENT ACPI_TABLES
50 ACPI_MODULE_NAME ("tbinstal") 50 ACPI_MODULE_NAME ("tbinstal")
51 51
52/* Local prototypes */
53
54static acpi_status
55acpi_tb_match_signature (
56 char *signature,
57 struct acpi_table_desc *table_info,
58 u8 search_type);
59
52 60
53/******************************************************************************* 61/*******************************************************************************
54 * 62 *
@@ -56,6 +64,7 @@
56 * 64 *
57 * PARAMETERS: Signature - Table signature to match 65 * PARAMETERS: Signature - Table signature to match
58 * table_info - Return data 66 * table_info - Return data
67 * search_type - Table type to match (primary/secondary)
59 * 68 *
60 * RETURN: Status 69 * RETURN: Status
61 * 70 *
@@ -64,7 +73,7 @@
64 * 73 *
65 ******************************************************************************/ 74 ******************************************************************************/
66 75
67acpi_status 76static acpi_status
68acpi_tb_match_signature ( 77acpi_tb_match_signature (
69 char *signature, 78 char *signature,
70 struct acpi_table_desc *table_info, 79 struct acpi_table_desc *table_info,
@@ -76,9 +85,8 @@ acpi_tb_match_signature (
76 ACPI_FUNCTION_TRACE ("tb_match_signature"); 85 ACPI_FUNCTION_TRACE ("tb_match_signature");
77 86
78 87
79 /* 88 /* Search for a signature match among the known table types */
80 * Search for a signature match among the known table types 89
81 */
82 for (i = 0; i < NUM_ACPI_TABLE_TYPES; i++) { 90 for (i = 0; i < NUM_ACPI_TABLE_TYPES; i++) {
83 if (!(acpi_gbl_table_data[i].flags & search_type)) { 91 if (!(acpi_gbl_table_data[i].flags & search_type)) {
84 continue; 92 continue;
@@ -161,6 +169,7 @@ acpi_tb_install_table (
161 * FUNCTION: acpi_tb_recognize_table 169 * FUNCTION: acpi_tb_recognize_table
162 * 170 *
163 * PARAMETERS: table_info - Return value from acpi_tb_get_table_body 171 * PARAMETERS: table_info - Return value from acpi_tb_get_table_body
172 * search_type - Table type to match (primary/secondary)
164 * 173 *
165 * RETURN: Status 174 * RETURN: Status
166 * 175 *
@@ -203,7 +212,8 @@ acpi_tb_recognize_table (
203 * This can be any one of many valid ACPI tables, it just isn't one of 212 * This can be any one of many valid ACPI tables, it just isn't one of
204 * the tables that is consumed by the core subsystem 213 * the tables that is consumed by the core subsystem
205 */ 214 */
206 status = acpi_tb_match_signature (table_header->signature, table_info, search_type); 215 status = acpi_tb_match_signature (table_header->signature,
216 table_info, search_type);
207 if (ACPI_FAILURE (status)) { 217 if (ACPI_FAILURE (status)) {
208 return_ACPI_STATUS (status); 218 return_ACPI_STATUS (status);
209 } 219 }
@@ -253,9 +263,8 @@ acpi_tb_init_table_descriptor (
253 return_ACPI_STATUS (AE_NO_MEMORY); 263 return_ACPI_STATUS (AE_NO_MEMORY);
254 } 264 }
255 265
256 /* 266 /* Install the table into the global data structure */
257 * Install the table into the global data structure 267
258 */
259 list_head = &acpi_gbl_table_lists[table_type]; 268 list_head = &acpi_gbl_table_lists[table_type];
260 269
261 /* 270 /*
@@ -316,7 +325,8 @@ acpi_tb_init_table_descriptor (
316 table_desc->aml_start = (u8 *) (table_desc->pointer + 1), 325 table_desc->aml_start = (u8 *) (table_desc->pointer + 1),
317 table_desc->aml_length = (u32) (table_desc->length - 326 table_desc->aml_length = (u32) (table_desc->length -
318 (u32) sizeof (struct acpi_table_header)); 327 (u32) sizeof (struct acpi_table_header));
319 table_desc->table_id = acpi_ut_allocate_owner_id (ACPI_OWNER_TYPE_TABLE); 328 table_desc->table_id = acpi_ut_allocate_owner_id (
329 ACPI_OWNER_TYPE_TABLE);
320 table_desc->loaded_into_namespace = FALSE; 330 table_desc->loaded_into_namespace = FALSE;
321 331
322 /* 332 /*
@@ -349,7 +359,8 @@ acpi_tb_init_table_descriptor (
349 ******************************************************************************/ 359 ******************************************************************************/
350 360
351void 361void
352acpi_tb_delete_all_tables (void) 362acpi_tb_delete_all_tables (
363 void)
353{ 364{
354 acpi_table_type type; 365 acpi_table_type type;
355 366
diff --git a/drivers/acpi/tables/tbrsdt.c b/drivers/acpi/tables/tbrsdt.c
index 9c6913238d52..b7ffe39c3626 100644
--- a/drivers/acpi/tables/tbrsdt.c
+++ b/drivers/acpi/tables/tbrsdt.c
@@ -84,8 +84,9 @@ acpi_tb_verify_rsdp (
84 /* 84 /*
85 * Obtain access to the RSDP structure 85 * Obtain access to the RSDP structure
86 */ 86 */
87 status = acpi_os_map_memory (address->pointer.physical, sizeof (struct rsdp_descriptor), 87 status = acpi_os_map_memory (address->pointer.physical,
88 (void *) &rsdp); 88 sizeof (struct rsdp_descriptor),
89 (void *) &rsdp);
89 if (ACPI_FAILURE (status)) { 90 if (ACPI_FAILURE (status)) {
90 return_ACPI_STATUS (status); 91 return_ACPI_STATUS (status);
91 } 92 }
@@ -154,9 +155,9 @@ cleanup:
154 * 155 *
155 * FUNCTION: acpi_tb_get_rsdt_address 156 * FUNCTION: acpi_tb_get_rsdt_address
156 * 157 *
157 * PARAMETERS: None 158 * PARAMETERS: out_address - Where the address is returned
158 * 159 *
159 * RETURN: RSDT physical address 160 * RETURN: None, Address
160 * 161 *
161 * DESCRIPTION: Extract the address of the RSDT or XSDT, depending on the 162 * DESCRIPTION: Extract the address of the RSDT or XSDT, depending on the
162 * version of the RSDP 163 * version of the RSDP
@@ -181,7 +182,8 @@ acpi_tb_get_rsdt_address (
181 out_address->pointer.value = acpi_gbl_RSDP->rsdt_physical_address; 182 out_address->pointer.value = acpi_gbl_RSDP->rsdt_physical_address;
182 } 183 }
183 else { 184 else {
184 out_address->pointer.value = acpi_gbl_RSDP->xsdt_physical_address; 185 out_address->pointer.value =
186 acpi_gbl_RSDP->xsdt_physical_address;
185 } 187 }
186} 188}
187 189
@@ -224,7 +226,8 @@ acpi_tb_validate_rsdt (
224 if (no_match) { 226 if (no_match) {
225 /* Invalid RSDT or XSDT signature */ 227 /* Invalid RSDT or XSDT signature */
226 228
227 ACPI_REPORT_ERROR (("Invalid signature where RSDP indicates RSDT/XSDT should be located\n")); 229 ACPI_REPORT_ERROR ((
230 "Invalid signature where RSDP indicates RSDT/XSDT should be located\n"));
228 231
229 ACPI_DUMP_BUFFER (acpi_gbl_RSDP, 20); 232 ACPI_DUMP_BUFFER (acpi_gbl_RSDP, 20);
230 233
@@ -282,6 +285,7 @@ acpi_tb_get_table_rsdt (
282 if (ACPI_FAILURE (status)) { 285 if (ACPI_FAILURE (status)) {
283 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not get the RSDT/XSDT, %s\n", 286 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not get the RSDT/XSDT, %s\n",
284 acpi_format_exception (status))); 287 acpi_format_exception (status)));
288
285 return_ACPI_STATUS (status); 289 return_ACPI_STATUS (status);
286 } 290 }
287 291
@@ -299,7 +303,8 @@ acpi_tb_get_table_rsdt (
299 303
300 /* Get the number of tables defined in the RSDT or XSDT */ 304 /* Get the number of tables defined in the RSDT or XSDT */
301 305
302 acpi_gbl_rsdt_table_count = acpi_tb_get_table_count (acpi_gbl_RSDP, table_info.pointer); 306 acpi_gbl_rsdt_table_count = acpi_tb_get_table_count (acpi_gbl_RSDP,
307 table_info.pointer);
303 308
304 /* Convert and/or copy to an XSDT structure */ 309 /* Convert and/or copy to an XSDT structure */
305 310
diff --git a/drivers/acpi/tables/tbutils.c b/drivers/acpi/tables/tbutils.c
index fede5804c783..e69d01d443d2 100644
--- a/drivers/acpi/tables/tbutils.c
+++ b/drivers/acpi/tables/tbutils.c
@@ -49,48 +49,14 @@
49#define _COMPONENT ACPI_TABLES 49#define _COMPONENT ACPI_TABLES
50 ACPI_MODULE_NAME ("tbutils") 50 ACPI_MODULE_NAME ("tbutils")
51 51
52/* Local prototypes */
52 53
53/******************************************************************************* 54#ifdef ACPI_OBSOLETE_FUNCTIONS
54 *
55 * FUNCTION: acpi_tb_handle_to_object
56 *
57 * PARAMETERS: table_id - Id for which the function is searching
58 * table_desc - Pointer to return the matching table
59 * descriptor.
60 *
61 * RETURN: Search the tables to find one with a matching table_id and
62 * return a pointer to that table descriptor.
63 *
64 ******************************************************************************/
65#ifdef ACPI_FUTURE_USAGE
66acpi_status 55acpi_status
67acpi_tb_handle_to_object ( 56acpi_tb_handle_to_object (
68 u16 table_id, 57 u16 table_id,
69 struct acpi_table_desc **return_table_desc) 58 struct acpi_table_desc **table_desc);
70{ 59#endif
71 u32 i;
72 struct acpi_table_desc *table_desc;
73
74
75 ACPI_FUNCTION_NAME ("tb_handle_to_object");
76
77
78 for (i = 0; i < ACPI_TABLE_MAX; i++) {
79 table_desc = acpi_gbl_table_lists[i].next;
80 while (table_desc) {
81 if (table_desc->table_id == table_id) {
82 *return_table_desc = table_desc;
83 return (AE_OK);
84 }
85
86 table_desc = table_desc->next;
87 }
88 }
89
90 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "table_id=%X does not exist\n", table_id));
91 return (AE_BAD_PARAMETER);
92}
93#endif /* ACPI_FUTURE_USAGE */
94 60
95 61
96/******************************************************************************* 62/*******************************************************************************
@@ -128,6 +94,7 @@ acpi_tb_validate_table_header (
128 if (!acpi_os_readable (table_header, sizeof (struct acpi_table_header))) { 94 if (!acpi_os_readable (table_header, sizeof (struct acpi_table_header))) {
129 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 95 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
130 "Cannot read table header at %p\n", table_header)); 96 "Cannot read table header at %p\n", table_header));
97
131 return (AE_BAD_ADDRESS); 98 return (AE_BAD_ADDRESS);
132 } 99 }
133 100
@@ -141,6 +108,7 @@ acpi_tb_validate_table_header (
141 108
142 ACPI_REPORT_WARNING (("Invalid table signature found: [%4.4s]\n", 109 ACPI_REPORT_WARNING (("Invalid table signature found: [%4.4s]\n",
143 (char *) &signature)); 110 (char *) &signature));
111
144 ACPI_DUMP_BUFFER (table_header, sizeof (struct acpi_table_header)); 112 ACPI_DUMP_BUFFER (table_header, sizeof (struct acpi_table_header));
145 return (AE_BAD_SIGNATURE); 113 return (AE_BAD_SIGNATURE);
146 } 114 }
@@ -154,6 +122,7 @@ acpi_tb_validate_table_header (
154 122
155 ACPI_REPORT_WARNING (("Invalid table header length (0x%X) found\n", 123 ACPI_REPORT_WARNING (("Invalid table header length (0x%X) found\n",
156 (u32) table_header->length)); 124 (u32) table_header->length));
125
157 ACPI_DUMP_BUFFER (table_header, sizeof (struct acpi_table_header)); 126 ACPI_DUMP_BUFFER (table_header, sizeof (struct acpi_table_header));
158 return (AE_BAD_HEADER); 127 return (AE_BAD_HEADER);
159 } 128 }
@@ -193,8 +162,10 @@ acpi_tb_verify_table_checksum (
193 /* Return the appropriate exception */ 162 /* Return the appropriate exception */
194 163
195 if (checksum) { 164 if (checksum) {
196 ACPI_REPORT_WARNING (("Invalid checksum in table [%4.4s] (%02X, sum %02X is not zero)\n", 165 ACPI_REPORT_WARNING ((
197 table_header->signature, (u32) table_header->checksum, (u32) checksum)); 166 "Invalid checksum in table [%4.4s] (%02X, sum %02X is not zero)\n",
167 table_header->signature, (u32) table_header->checksum,
168 (u32) checksum));
198 169
199 status = AE_BAD_CHECKSUM; 170 status = AE_BAD_CHECKSUM;
200 } 171 }
@@ -209,7 +180,7 @@ acpi_tb_verify_table_checksum (
209 * PARAMETERS: Buffer - Buffer to checksum 180 * PARAMETERS: Buffer - Buffer to checksum
210 * Length - Size of the buffer 181 * Length - Size of the buffer
211 * 182 *
212 * RETURNS 8 bit checksum of buffer 183 * RETURN: 8 bit checksum of buffer
213 * 184 *
214 * DESCRIPTION: Computes an 8 bit checksum of the buffer(length) and returns it. 185 * DESCRIPTION: Computes an 8 bit checksum of the buffer(length) and returns it.
215 * 186 *
@@ -238,3 +209,47 @@ acpi_tb_checksum (
238} 209}
239 210
240 211
212#ifdef ACPI_OBSOLETE_FUNCTIONS
213/*******************************************************************************
214 *
215 * FUNCTION: acpi_tb_handle_to_object
216 *
217 * PARAMETERS: table_id - Id for which the function is searching
218 * table_desc - Pointer to return the matching table
219 * descriptor.
220 *
221 * RETURN: Search the tables to find one with a matching table_id and
222 * return a pointer to that table descriptor.
223 *
224 ******************************************************************************/
225
226acpi_status
227acpi_tb_handle_to_object (
228 u16 table_id,
229 struct acpi_table_desc **return_table_desc)
230{
231 u32 i;
232 struct acpi_table_desc *table_desc;
233
234
235 ACPI_FUNCTION_NAME ("tb_handle_to_object");
236
237
238 for (i = 0; i < ACPI_TABLE_MAX; i++) {
239 table_desc = acpi_gbl_table_lists[i].next;
240 while (table_desc) {
241 if (table_desc->table_id == table_id) {
242 *return_table_desc = table_desc;
243 return (AE_OK);
244 }
245
246 table_desc = table_desc->next;
247 }
248 }
249
250 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "table_id=%X does not exist\n", table_id));
251 return (AE_BAD_PARAMETER);
252}
253#endif
254
255
diff --git a/drivers/acpi/tables/tbxface.c b/drivers/acpi/tables/tbxface.c
index 7715043461c4..0c0b9085dbeb 100644
--- a/drivers/acpi/tables/tbxface.c
+++ b/drivers/acpi/tables/tbxface.c
@@ -67,7 +67,8 @@
67 ******************************************************************************/ 67 ******************************************************************************/
68 68
69acpi_status 69acpi_status
70acpi_load_tables (void) 70acpi_load_tables (
71 void)
71{ 72{
72 struct acpi_pointer rsdp_address; 73 struct acpi_pointer rsdp_address;
73 acpi_status status; 74 acpi_status status;
@@ -82,7 +83,7 @@ acpi_load_tables (void)
82 &rsdp_address); 83 &rsdp_address);
83 if (ACPI_FAILURE (status)) { 84 if (ACPI_FAILURE (status)) {
84 ACPI_REPORT_ERROR (("acpi_load_tables: Could not get RSDP, %s\n", 85 ACPI_REPORT_ERROR (("acpi_load_tables: Could not get RSDP, %s\n",
85 acpi_format_exception (status))); 86 acpi_format_exception (status)));
86 goto error_exit; 87 goto error_exit;
87 } 88 }
88 89
@@ -93,7 +94,7 @@ acpi_load_tables (void)
93 status = acpi_tb_verify_rsdp (&rsdp_address); 94 status = acpi_tb_verify_rsdp (&rsdp_address);
94 if (ACPI_FAILURE (status)) { 95 if (ACPI_FAILURE (status)) {
95 ACPI_REPORT_ERROR (("acpi_load_tables: RSDP Failed validation: %s\n", 96 ACPI_REPORT_ERROR (("acpi_load_tables: RSDP Failed validation: %s\n",
96 acpi_format_exception (status))); 97 acpi_format_exception (status)));
97 goto error_exit; 98 goto error_exit;
98 } 99 }
99 100
@@ -102,7 +103,7 @@ acpi_load_tables (void)
102 status = acpi_tb_get_table_rsdt (); 103 status = acpi_tb_get_table_rsdt ();
103 if (ACPI_FAILURE (status)) { 104 if (ACPI_FAILURE (status)) {
104 ACPI_REPORT_ERROR (("acpi_load_tables: Could not load RSDT: %s\n", 105 ACPI_REPORT_ERROR (("acpi_load_tables: Could not load RSDT: %s\n",
105 acpi_format_exception (status))); 106 acpi_format_exception (status)));
106 goto error_exit; 107 goto error_exit;
107 } 108 }
108 109
@@ -110,20 +111,20 @@ acpi_load_tables (void)
110 111
111 status = acpi_tb_get_required_tables (); 112 status = acpi_tb_get_required_tables ();
112 if (ACPI_FAILURE (status)) { 113 if (ACPI_FAILURE (status)) {
113 ACPI_REPORT_ERROR (("acpi_load_tables: Error getting required tables (DSDT/FADT/FACS): %s\n", 114 ACPI_REPORT_ERROR ((
114 acpi_format_exception (status))); 115 "acpi_load_tables: Error getting required tables (DSDT/FADT/FACS): %s\n",
116 acpi_format_exception (status)));
115 goto error_exit; 117 goto error_exit;
116 } 118 }
117 119
118 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "ACPI Tables successfully acquired\n")); 120 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "ACPI Tables successfully acquired\n"));
119 121
120
121 /* Load the namespace from the tables */ 122 /* Load the namespace from the tables */
122 123
123 status = acpi_ns_load_namespace (); 124 status = acpi_ns_load_namespace ();
124 if (ACPI_FAILURE (status)) { 125 if (ACPI_FAILURE (status)) {
125 ACPI_REPORT_ERROR (("acpi_load_tables: Could not load namespace: %s\n", 126 ACPI_REPORT_ERROR (("acpi_load_tables: Could not load namespace: %s\n",
126 acpi_format_exception (status))); 127 acpi_format_exception (status)));
127 goto error_exit; 128 goto error_exit;
128 } 129 }
129 130
@@ -139,7 +140,6 @@ error_exit:
139 140
140 141
141#ifdef ACPI_FUTURE_USAGE 142#ifdef ACPI_FUTURE_USAGE
142
143/******************************************************************************* 143/*******************************************************************************
144 * 144 *
145 * FUNCTION: acpi_load_table 145 * FUNCTION: acpi_load_table
@@ -250,7 +250,6 @@ acpi_unload_table (
250 return_ACPI_STATUS (AE_BAD_PARAMETER); 250 return_ACPI_STATUS (AE_BAD_PARAMETER);
251 } 251 }
252 252
253
254 /* Find all tables of the requested type */ 253 /* Find all tables of the requested type */
255 254
256 table_desc = acpi_gbl_table_lists[table_type].next; 255 table_desc = acpi_gbl_table_lists[table_type].next;
@@ -321,7 +320,6 @@ acpi_get_table_header (
321 return_ACPI_STATUS (AE_BAD_PARAMETER); 320 return_ACPI_STATUS (AE_BAD_PARAMETER);
322 } 321 }
323 322
324
325 /* Get a pointer to the entire table */ 323 /* Get a pointer to the entire table */
326 324
327 status = acpi_tb_get_table_ptr (table_type, instance, &tbl_ptr); 325 status = acpi_tb_get_table_ptr (table_type, instance, &tbl_ptr);
@@ -329,23 +327,20 @@ acpi_get_table_header (
329 return_ACPI_STATUS (status); 327 return_ACPI_STATUS (status);
330 } 328 }
331 329
332 /* 330 /* The function will return a NULL pointer if the table is not loaded */
333 * The function will return a NULL pointer if the table is not loaded 331
334 */
335 if (tbl_ptr == NULL) { 332 if (tbl_ptr == NULL) {
336 return_ACPI_STATUS (AE_NOT_EXIST); 333 return_ACPI_STATUS (AE_NOT_EXIST);
337 } 334 }
338 335
339 /* 336 /* Copy the header to the caller's buffer */
340 * Copy the header to the caller's buffer 337
341 */
342 ACPI_MEMCPY ((void *) out_table_header, (void *) tbl_ptr, 338 ACPI_MEMCPY ((void *) out_table_header, (void *) tbl_ptr,
343 sizeof (struct acpi_table_header)); 339 sizeof (struct acpi_table_header));
344 340
345 return_ACPI_STATUS (status); 341 return_ACPI_STATUS (status);
346} 342}
347 343
348
349#endif /* ACPI_FUTURE_USAGE */ 344#endif /* ACPI_FUTURE_USAGE */
350 345
351/******************************************************************************* 346/*******************************************************************************
@@ -404,7 +399,6 @@ acpi_get_table (
404 return_ACPI_STATUS (AE_BAD_PARAMETER); 399 return_ACPI_STATUS (AE_BAD_PARAMETER);
405 } 400 }
406 401
407
408 /* Get a pointer to the entire table */ 402 /* Get a pointer to the entire table */
409 403
410 status = acpi_tb_get_table_ptr (table_type, instance, &tbl_ptr); 404 status = acpi_tb_get_table_ptr (table_type, instance, &tbl_ptr);
@@ -423,9 +417,8 @@ acpi_get_table (
423 /* Get the table length */ 417 /* Get the table length */
424 418
425 if (table_type == ACPI_TABLE_RSDP) { 419 if (table_type == ACPI_TABLE_RSDP) {
426 /* 420 /* RSD PTR is the only "table" without a header */
427 * RSD PTR is the only "table" without a header 421
428 */
429 table_length = sizeof (struct rsdp_descriptor); 422 table_length = sizeof (struct rsdp_descriptor);
430 } 423 }
431 else { 424 else {
diff --git a/drivers/acpi/tables/tbxfroot.c b/drivers/acpi/tables/tbxfroot.c
index 6e8072ebbac6..dc3c3f6a9f62 100644
--- a/drivers/acpi/tables/tbxfroot.c
+++ b/drivers/acpi/tables/tbxfroot.c
@@ -50,6 +50,18 @@
50#define _COMPONENT ACPI_TABLES 50#define _COMPONENT ACPI_TABLES
51 ACPI_MODULE_NAME ("tbxfroot") 51 ACPI_MODULE_NAME ("tbxfroot")
52 52
53/* Local prototypes */
54
55static acpi_status
56acpi_tb_find_rsdp (
57 struct acpi_table_desc *table_info,
58 u32 flags);
59
60static u8 *
61acpi_tb_scan_memory_for_rsdp (
62 u8 *start_address,
63 u32 length);
64
53 65
54/******************************************************************************* 66/*******************************************************************************
55 * 67 *
@@ -57,7 +69,8 @@
57 * 69 *
58 * PARAMETERS: Signature - String with ACPI table signature 70 * PARAMETERS: Signature - String with ACPI table signature
59 * oem_id - String with the table OEM ID 71 * oem_id - String with the table OEM ID
60 * oem_table_id - String with the OEM Table ID. 72 * oem_table_id - String with the OEM Table ID
73 * table_ptr - Where the table pointer is returned
61 * 74 *
62 * RETURN: Status 75 * RETURN: Status
63 * 76 *
@@ -99,14 +112,13 @@ acpi_tb_find_table (
99 if (!acpi_gbl_DSDT) { 112 if (!acpi_gbl_DSDT) {
100 return_ACPI_STATUS (AE_NO_ACPI_TABLES); 113 return_ACPI_STATUS (AE_NO_ACPI_TABLES);
101 } 114 }
102
103 table = acpi_gbl_DSDT; 115 table = acpi_gbl_DSDT;
104 } 116 }
105 else { 117 else {
106 /* Find the table */ 118 /* Find the table */
107 119
108 status = acpi_get_firmware_table (signature, 1, 120 status = acpi_get_firmware_table (signature, 1,
109 ACPI_LOGICAL_ADDRESSING, &table); 121 ACPI_LOGICAL_ADDRESSING, &table);
110 if (ACPI_FAILURE (status)) { 122 if (ACPI_FAILURE (status)) {
111 return_ACPI_STATUS (status); 123 return_ACPI_STATUS (status);
112 } 124 }
@@ -114,14 +126,19 @@ acpi_tb_find_table (
114 126
115 /* Check oem_id and oem_table_id */ 127 /* Check oem_id and oem_table_id */
116 128
117 if ((oem_id[0] && ACPI_STRNCMP ( 129 if ((oem_id[0] && ACPI_STRNCMP (
118 oem_id, table->oem_id, sizeof (table->oem_id))) || 130 oem_id, table->oem_id,
131 sizeof (table->oem_id))) ||
132
119 (oem_table_id[0] && ACPI_STRNCMP ( 133 (oem_table_id[0] && ACPI_STRNCMP (
120 oem_table_id, table->oem_table_id, sizeof (table->oem_table_id)))) { 134 oem_table_id, table->oem_table_id,
135 sizeof (table->oem_table_id)))) {
121 return_ACPI_STATUS (AE_AML_NAME_NOT_FOUND); 136 return_ACPI_STATUS (AE_AML_NAME_NOT_FOUND);
122 } 137 }
123 138
124 ACPI_DEBUG_PRINT ((ACPI_DB_TABLES, "Found table [%4.4s]\n", table->signature)); 139 ACPI_DEBUG_PRINT ((ACPI_DB_TABLES, "Found table [%4.4s]\n",
140 table->signature));
141
125 *table_ptr = table; 142 *table_ptr = table;
126 return_ACPI_STATUS (AE_OK); 143 return_ACPI_STATUS (AE_OK);
127} 144}
@@ -191,8 +208,8 @@ acpi_get_firmware_table (
191 /* Map and validate the RSDP */ 208 /* Map and validate the RSDP */
192 209
193 if ((flags & ACPI_MEMORY_MODE) == ACPI_LOGICAL_ADDRESSING) { 210 if ((flags & ACPI_MEMORY_MODE) == ACPI_LOGICAL_ADDRESSING) {
194 status = acpi_os_map_memory (address.pointer.physical, sizeof (struct rsdp_descriptor), 211 status = acpi_os_map_memory (address.pointer.physical,
195 (void *) &acpi_gbl_RSDP); 212 sizeof (struct rsdp_descriptor), (void *) &acpi_gbl_RSDP);
196 if (ACPI_FAILURE (status)) { 213 if (ACPI_FAILURE (status)) {
197 return_ACPI_STATUS (status); 214 return_ACPI_STATUS (status);
198 } 215 }
@@ -203,7 +220,8 @@ acpi_get_firmware_table (
203 220
204 /* The signature and checksum must both be correct */ 221 /* The signature and checksum must both be correct */
205 222
206 if (ACPI_STRNCMP ((char *) acpi_gbl_RSDP, RSDP_SIG, sizeof (RSDP_SIG)-1) != 0) { 223 if (ACPI_STRNCMP ((char *) acpi_gbl_RSDP, RSDP_SIG,
224 sizeof (RSDP_SIG)-1) != 0) {
207 /* Nope, BAD Signature */ 225 /* Nope, BAD Signature */
208 226
209 return_ACPI_STATUS (AE_BAD_SIGNATURE); 227 return_ACPI_STATUS (AE_BAD_SIGNATURE);
@@ -313,7 +331,8 @@ acpi_get_firmware_table (
313 331
314 332
315cleanup: 333cleanup:
316 acpi_os_unmap_memory (rsdt_info->pointer, (acpi_size) rsdt_info->pointer->length); 334 acpi_os_unmap_memory (rsdt_info->pointer,
335 (acpi_size) rsdt_info->pointer->length);
317 ACPI_MEM_FREE (rsdt_info); 336 ACPI_MEM_FREE (rsdt_info);
318 337
319 if (header) { 338 if (header) {
@@ -335,8 +354,8 @@ EXPORT_SYMBOL(acpi_get_firmware_table);
335 * 354 *
336 * FUNCTION: acpi_find_root_pointer 355 * FUNCTION: acpi_find_root_pointer
337 * 356 *
338 * PARAMETERS: **rsdp_address - Where to place the RSDP address 357 * PARAMETERS: Flags - Logical/Physical addressing
339 * Flags - Logical/Physical addressing 358 * rsdp_address - Where to place the RSDP address
340 * 359 *
341 * RETURN: Status, Physical address of the RSDP 360 * RETURN: Status, Physical address of the RSDP
342 * 361 *
@@ -363,6 +382,7 @@ acpi_find_root_pointer (
363 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 382 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
364 "RSDP structure not found, %s Flags=%X\n", 383 "RSDP structure not found, %s Flags=%X\n",
365 acpi_format_exception (status), flags)); 384 acpi_format_exception (status), flags));
385
366 return_ACPI_STATUS (AE_NO_ACPI_TABLES); 386 return_ACPI_STATUS (AE_NO_ACPI_TABLES);
367 } 387 }
368 388
@@ -385,7 +405,7 @@ acpi_find_root_pointer (
385 * 405 *
386 ******************************************************************************/ 406 ******************************************************************************/
387 407
388u8 * 408static u8 *
389acpi_tb_scan_memory_for_rsdp ( 409acpi_tb_scan_memory_for_rsdp (
390 u8 *start_address, 410 u8 *start_address,
391 u32 length) 411 u32 length)
@@ -406,7 +426,8 @@ acpi_tb_scan_memory_for_rsdp (
406 mem_rover += ACPI_RSDP_SCAN_STEP) { 426 mem_rover += ACPI_RSDP_SCAN_STEP) {
407 /* The signature and checksum must both be correct */ 427 /* The signature and checksum must both be correct */
408 428
409 if (ACPI_STRNCMP ((char *) mem_rover, RSDP_SIG, sizeof (RSDP_SIG)-1) != 0) { 429 if (ACPI_STRNCMP ((char *) mem_rover,
430 RSDP_SIG, sizeof (RSDP_SIG) - 1) != 0) {
410 /* No signature match, keep looking */ 431 /* No signature match, keep looking */
411 432
412 continue; 433 continue;
@@ -450,7 +471,7 @@ acpi_tb_scan_memory_for_rsdp (
450 * 471 *
451 * FUNCTION: acpi_tb_find_rsdp 472 * FUNCTION: acpi_tb_find_rsdp
452 * 473 *
453 * PARAMETERS: *table_info - Where the table info is returned 474 * PARAMETERS: table_info - Where the table info is returned
454 * Flags - Current memory mode (logical vs. 475 * Flags - Current memory mode (logical vs.
455 * physical addressing) 476 * physical addressing)
456 * 477 *
@@ -468,7 +489,7 @@ acpi_tb_scan_memory_for_rsdp (
468 * 489 *
469 ******************************************************************************/ 490 ******************************************************************************/
470 491
471acpi_status 492static acpi_status
472acpi_tb_find_rsdp ( 493acpi_tb_find_rsdp (
473 struct acpi_table_desc *table_info, 494 struct acpi_table_desc *table_info,
474 u32 flags) 495 u32 flags)
@@ -483,43 +504,49 @@ acpi_tb_find_rsdp (
483 504
484 505
485 /* 506 /*
486 * Scan supports either 1) Logical addressing or 2) Physical addressing 507 * Scan supports either logical addressing or physical addressing
487 */ 508 */
488 if ((flags & ACPI_MEMORY_MODE) == ACPI_LOGICAL_ADDRESSING) { 509 if ((flags & ACPI_MEMORY_MODE) == ACPI_LOGICAL_ADDRESSING) {
489 /* 510 /* 1a) Get the location of the Extended BIOS Data Area (EBDA) */
490 * 1a) Get the location of the EBDA 511
491 */ 512 status = acpi_os_map_memory (
492 status = acpi_os_map_memory ((acpi_physical_address) ACPI_EBDA_PTR_LOCATION, 513 (acpi_physical_address) ACPI_EBDA_PTR_LOCATION,
493 ACPI_EBDA_PTR_LENGTH, 514 ACPI_EBDA_PTR_LENGTH, (void *) &table_ptr);
494 (void *) &table_ptr);
495 if (ACPI_FAILURE (status)) { 515 if (ACPI_FAILURE (status)) {
496 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 516 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
497 "Could not map memory at %8.8X for length %X\n", 517 "Could not map memory at %8.8X for length %X\n",
498 ACPI_EBDA_PTR_LOCATION, ACPI_EBDA_PTR_LENGTH)); 518 ACPI_EBDA_PTR_LOCATION, ACPI_EBDA_PTR_LENGTH));
519
499 return_ACPI_STATUS (status); 520 return_ACPI_STATUS (status);
500 } 521 }
501 522
502 ACPI_MOVE_16_TO_32 (&physical_address, table_ptr); 523 ACPI_MOVE_16_TO_32 (&physical_address, table_ptr);
503 physical_address <<= 4; /* Convert segment to physical address */ 524
525 /* Convert segment part to physical address */
526
527 physical_address <<= 4;
504 acpi_os_unmap_memory (table_ptr, ACPI_EBDA_PTR_LENGTH); 528 acpi_os_unmap_memory (table_ptr, ACPI_EBDA_PTR_LENGTH);
505 529
506 /* EBDA present? */ 530 /* EBDA present? */
507 531
508 if (physical_address > 0x400) { 532 if (physical_address > 0x400) {
509 /* 533 /*
510 * 1b) Search EBDA paragraphs (EBDa is required to be a minimum of 1_k length) 534 * 1b) Search EBDA paragraphs (EBDa is required to be a
535 * minimum of 1_k length)
511 */ 536 */
512 status = acpi_os_map_memory ((acpi_physical_address) physical_address, 537 status = acpi_os_map_memory (
513 ACPI_EBDA_WINDOW_SIZE, 538 (acpi_physical_address) physical_address,
514 (void *) &table_ptr); 539 ACPI_EBDA_WINDOW_SIZE, (void *) &table_ptr);
515 if (ACPI_FAILURE (status)) { 540 if (ACPI_FAILURE (status)) {
516 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 541 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
517 "Could not map memory at %8.8X for length %X\n", 542 "Could not map memory at %8.8X for length %X\n",
518 physical_address, ACPI_EBDA_WINDOW_SIZE)); 543 physical_address, ACPI_EBDA_WINDOW_SIZE));
544
519 return_ACPI_STATUS (status); 545 return_ACPI_STATUS (status);
520 } 546 }
521 547
522 mem_rover = acpi_tb_scan_memory_for_rsdp (table_ptr, ACPI_EBDA_WINDOW_SIZE); 548 mem_rover = acpi_tb_scan_memory_for_rsdp (table_ptr,
549 ACPI_EBDA_WINDOW_SIZE);
523 acpi_os_unmap_memory (table_ptr, ACPI_EBDA_WINDOW_SIZE); 550 acpi_os_unmap_memory (table_ptr, ACPI_EBDA_WINDOW_SIZE);
524 551
525 if (mem_rover) { 552 if (mem_rover) {
@@ -527,7 +554,8 @@ acpi_tb_find_rsdp (
527 554
528 physical_address += ACPI_PTR_DIFF (mem_rover, table_ptr); 555 physical_address += ACPI_PTR_DIFF (mem_rover, table_ptr);
529 556
530 table_info->physical_address = (acpi_physical_address) physical_address; 557 table_info->physical_address =
558 (acpi_physical_address) physical_address;
531 return_ACPI_STATUS (AE_OK); 559 return_ACPI_STATUS (AE_OK);
532 } 560 }
533 } 561 }
@@ -535,13 +563,15 @@ acpi_tb_find_rsdp (
535 /* 563 /*
536 * 2) Search upper memory: 16-byte boundaries in E0000h-FFFFFh 564 * 2) Search upper memory: 16-byte boundaries in E0000h-FFFFFh
537 */ 565 */
538 status = acpi_os_map_memory ((acpi_physical_address) ACPI_HI_RSDP_WINDOW_BASE, 566 status = acpi_os_map_memory (
539 ACPI_HI_RSDP_WINDOW_SIZE, 567 (acpi_physical_address) ACPI_HI_RSDP_WINDOW_BASE,
540 (void *) &table_ptr); 568 ACPI_HI_RSDP_WINDOW_SIZE, (void *) &table_ptr);
569
541 if (ACPI_FAILURE (status)) { 570 if (ACPI_FAILURE (status)) {
542 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 571 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
543 "Could not map memory at %8.8X for length %X\n", 572 "Could not map memory at %8.8X for length %X\n",
544 ACPI_HI_RSDP_WINDOW_BASE, ACPI_HI_RSDP_WINDOW_SIZE)); 573 ACPI_HI_RSDP_WINDOW_BASE, ACPI_HI_RSDP_WINDOW_SIZE));
574
545 return_ACPI_STATUS (status); 575 return_ACPI_STATUS (status);
546 } 576 }
547 577
@@ -551,9 +581,11 @@ acpi_tb_find_rsdp (
551 if (mem_rover) { 581 if (mem_rover) {
552 /* Found it, return the physical address */ 582 /* Found it, return the physical address */
553 583
554 physical_address = ACPI_HI_RSDP_WINDOW_BASE + ACPI_PTR_DIFF (mem_rover, table_ptr); 584 physical_address =
585 ACPI_HI_RSDP_WINDOW_BASE + ACPI_PTR_DIFF (mem_rover, table_ptr);
555 586
556 table_info->physical_address = (acpi_physical_address) physical_address; 587 table_info->physical_address =
588 (acpi_physical_address) physical_address;
557 return_ACPI_STATUS (AE_OK); 589 return_ACPI_STATUS (AE_OK);
558 } 590 }
559 } 591 }
@@ -562,9 +594,8 @@ acpi_tb_find_rsdp (
562 * Physical addressing 594 * Physical addressing
563 */ 595 */
564 else { 596 else {
565 /* 597 /* 1a) Get the location of the EBDA */
566 * 1a) Get the location of the EBDA 598
567 */
568 ACPI_MOVE_16_TO_32 (&physical_address, ACPI_EBDA_PTR_LOCATION); 599 ACPI_MOVE_16_TO_32 (&physical_address, ACPI_EBDA_PTR_LOCATION);
569 physical_address <<= 4; /* Convert segment to physical address */ 600 physical_address <<= 4; /* Convert segment to physical address */
570 601
@@ -572,9 +603,11 @@ acpi_tb_find_rsdp (
572 603
573 if (physical_address > 0x400) { 604 if (physical_address > 0x400) {
574 /* 605 /*
575 * 1b) Search EBDA paragraphs (EBDa is required to be a minimum of 1_k length) 606 * 1b) Search EBDA paragraphs (EBDa is required to be a minimum of
607 * 1_k length)
576 */ 608 */
577 mem_rover = acpi_tb_scan_memory_for_rsdp (ACPI_PHYSADDR_TO_PTR (physical_address), 609 mem_rover = acpi_tb_scan_memory_for_rsdp (
610 ACPI_PHYSADDR_TO_PTR (physical_address),
578 ACPI_EBDA_WINDOW_SIZE); 611 ACPI_EBDA_WINDOW_SIZE);
579 if (mem_rover) { 612 if (mem_rover) {
580 /* Found it, return the physical address */ 613 /* Found it, return the physical address */
@@ -584,10 +617,10 @@ acpi_tb_find_rsdp (
584 } 617 }
585 } 618 }
586 619
587 /* 620 /* 2) Search upper memory: 16-byte boundaries in E0000h-FFFFFh */
588 * 2) Search upper memory: 16-byte boundaries in E0000h-FFFFFh 621
589 */ 622 mem_rover = acpi_tb_scan_memory_for_rsdp (
590 mem_rover = acpi_tb_scan_memory_for_rsdp (ACPI_PHYSADDR_TO_PTR (ACPI_HI_RSDP_WINDOW_BASE), 623 ACPI_PHYSADDR_TO_PTR (ACPI_HI_RSDP_WINDOW_BASE),
591 ACPI_HI_RSDP_WINDOW_SIZE); 624 ACPI_HI_RSDP_WINDOW_SIZE);
592 if (mem_rover) { 625 if (mem_rover) {
593 /* Found it, return the physical address */ 626 /* Found it, return the physical address */
diff --git a/drivers/acpi/toshiba_acpi.c b/drivers/acpi/toshiba_acpi.c
index c84997c9f964..73b1d8aeae9d 100644
--- a/drivers/acpi/toshiba_acpi.c
+++ b/drivers/acpi/toshiba_acpi.c
@@ -263,6 +263,9 @@ dispatch_write(struct file* file, const char __user * buffer,
263 * destination so that sscanf can be used on it safely. 263 * destination so that sscanf can be used on it safely.
264 */ 264 */
265 tmp_buffer = kmalloc(count + 1, GFP_KERNEL); 265 tmp_buffer = kmalloc(count + 1, GFP_KERNEL);
266 if(!tmp_buffer)
267 return -ENOMEM;
268
266 if (copy_from_user(tmp_buffer, buffer, count)) { 269 if (copy_from_user(tmp_buffer, buffer, count)) {
267 result = -EFAULT; 270 result = -EFAULT;
268 } 271 }
@@ -529,6 +532,11 @@ toshiba_acpi_init(void)
529 532
530 if (acpi_disabled) 533 if (acpi_disabled)
531 return -ENODEV; 534 return -ENODEV;
535
536 if (!acpi_specific_hotkey_enabled){
537 printk(MY_INFO "Using generic hotkey driver\n");
538 return -ENODEV;
539 }
532 /* simple device detection: look for HCI method */ 540 /* simple device detection: look for HCI method */
533 if (is_valid_acpi_path(METHOD_HCI_1)) 541 if (is_valid_acpi_path(METHOD_HCI_1))
534 method_hci = METHOD_HCI_1; 542 method_hci = METHOD_HCI_1;
diff --git a/drivers/acpi/utilities/utalloc.c b/drivers/acpi/utilities/utalloc.c
index 3313439c4bc7..c4e7f989a2bd 100644
--- a/drivers/acpi/utilities/utalloc.c
+++ b/drivers/acpi/utilities/utalloc.c
@@ -47,8 +47,35 @@
47#define _COMPONENT ACPI_UTILITIES 47#define _COMPONENT ACPI_UTILITIES
48 ACPI_MODULE_NAME ("utalloc") 48 ACPI_MODULE_NAME ("utalloc")
49 49
50/* Local prototypes */
50 51
51/****************************************************************************** 52#ifdef ACPI_DBG_TRACK_ALLOCATIONS
53static struct acpi_debug_mem_block *
54acpi_ut_find_allocation (
55 u32 list_id,
56 void *allocation);
57
58static acpi_status
59acpi_ut_track_allocation (
60 u32 list_id,
61 struct acpi_debug_mem_block *address,
62 acpi_size size,
63 u8 alloc_type,
64 u32 component,
65 char *module,
66 u32 line);
67
68static acpi_status
69acpi_ut_remove_allocation (
70 u32 list_id,
71 struct acpi_debug_mem_block *address,
72 u32 component,
73 char *module,
74 u32 line);
75#endif /* ACPI_DBG_TRACK_ALLOCATIONS */
76
77
78/*******************************************************************************
52 * 79 *
53 * FUNCTION: acpi_ut_release_to_cache 80 * FUNCTION: acpi_ut_release_to_cache
54 * 81 *
@@ -98,7 +125,8 @@ acpi_ut_release_to_cache (
98 125
99 /* Put the object at the head of the cache list */ 126 /* Put the object at the head of the cache list */
100 127
101 * (ACPI_CAST_INDIRECT_PTR (char, &(((char *) object)[cache_info->link_offset]))) = cache_info->list_head; 128 * (ACPI_CAST_INDIRECT_PTR (char,
129 &(((char *) object)[cache_info->link_offset]))) = cache_info->list_head;
102 cache_info->list_head = object; 130 cache_info->list_head = object;
103 cache_info->cache_depth++; 131 cache_info->cache_depth++;
104 132
@@ -115,7 +143,7 @@ acpi_ut_release_to_cache (
115} 143}
116 144
117 145
118/****************************************************************************** 146/*******************************************************************************
119 * 147 *
120 * FUNCTION: acpi_ut_acquire_from_cache 148 * FUNCTION: acpi_ut_acquire_from_cache
121 * 149 *
@@ -156,7 +184,8 @@ acpi_ut_acquire_from_cache (
156 /* There is an object available, use it */ 184 /* There is an object available, use it */
157 185
158 object = cache_info->list_head; 186 object = cache_info->list_head;
159 cache_info->list_head = *(ACPI_CAST_INDIRECT_PTR (char, &(((char *) object)[cache_info->link_offset]))); 187 cache_info->list_head = *(ACPI_CAST_INDIRECT_PTR (char,
188 &(((char *) object)[cache_info->link_offset])));
160 189
161 ACPI_MEM_TRACKING (cache_info->cache_hits++); 190 ACPI_MEM_TRACKING (cache_info->cache_hits++);
162 cache_info->cache_depth--; 191 cache_info->cache_depth--;
@@ -201,7 +230,7 @@ acpi_ut_acquire_from_cache (
201 230
202 231
203#ifdef ACPI_ENABLE_OBJECT_CACHE 232#ifdef ACPI_ENABLE_OBJECT_CACHE
204/****************************************************************************** 233/*******************************************************************************
205 * 234 *
206 * FUNCTION: acpi_ut_delete_generic_cache 235 * FUNCTION: acpi_ut_delete_generic_cache
207 * 236 *
@@ -228,7 +257,8 @@ acpi_ut_delete_generic_cache (
228 while (cache_info->list_head) { 257 while (cache_info->list_head) {
229 /* Delete one cached state object */ 258 /* Delete one cached state object */
230 259
231 next = *(ACPI_CAST_INDIRECT_PTR (char, &(((char *) cache_info->list_head)[cache_info->link_offset]))); 260 next = *(ACPI_CAST_INDIRECT_PTR (char,
261 &(((char *) cache_info->list_head)[cache_info->link_offset])));
232 ACPI_MEM_FREE (cache_info->list_head); 262 ACPI_MEM_FREE (cache_info->list_head);
233 263
234 cache_info->list_head = next; 264 cache_info->list_head = next;
@@ -497,8 +527,8 @@ acpi_ut_allocate_and_track (
497 acpi_status status; 527 acpi_status status;
498 528
499 529
500 allocation = acpi_ut_allocate (size + sizeof (struct acpi_debug_mem_header), component, 530 allocation = acpi_ut_allocate (size + sizeof (struct acpi_debug_mem_header),
501 module, line); 531 component, module, line);
502 if (!allocation) { 532 if (!allocation) {
503 return (NULL); 533 return (NULL);
504 } 534 }
@@ -543,8 +573,8 @@ acpi_ut_callocate_and_track (
543 acpi_status status; 573 acpi_status status;
544 574
545 575
546 allocation = acpi_ut_callocate (size + sizeof (struct acpi_debug_mem_header), component, 576 allocation = acpi_ut_callocate (size + sizeof (struct acpi_debug_mem_header),
547 module, line); 577 component, module, line);
548 if (!allocation) { 578 if (!allocation) {
549 /* Report allocation error */ 579 /* Report allocation error */
550 580
@@ -637,7 +667,7 @@ acpi_ut_free_and_track (
637 * 667 *
638 ******************************************************************************/ 668 ******************************************************************************/
639 669
640struct acpi_debug_mem_block * 670static struct acpi_debug_mem_block *
641acpi_ut_find_allocation ( 671acpi_ut_find_allocation (
642 u32 list_id, 672 u32 list_id,
643 void *allocation) 673 void *allocation)
@@ -686,7 +716,7 @@ acpi_ut_find_allocation (
686 * 716 *
687 ******************************************************************************/ 717 ******************************************************************************/
688 718
689acpi_status 719static acpi_status
690acpi_ut_track_allocation ( 720acpi_ut_track_allocation (
691 u32 list_id, 721 u32 list_id,
692 struct acpi_debug_mem_block *allocation, 722 struct acpi_debug_mem_block *allocation,
@@ -721,10 +751,12 @@ acpi_ut_track_allocation (
721 751
722 element = acpi_ut_find_allocation (list_id, allocation); 752 element = acpi_ut_find_allocation (list_id, allocation);
723 if (element) { 753 if (element) {
724 ACPI_REPORT_ERROR (("ut_track_allocation: Allocation already present in list! (%p)\n", 754 ACPI_REPORT_ERROR ((
755 "ut_track_allocation: Allocation already present in list! (%p)\n",
725 allocation)); 756 allocation));
726 757
727 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Element %p Address %p\n", element, allocation)); 758 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Element %p Address %p\n",
759 element, allocation));
728 760
729 goto unlock_and_exit; 761 goto unlock_and_exit;
730 } 762 }
@@ -773,7 +805,7 @@ unlock_and_exit:
773 * 805 *
774 ******************************************************************************/ 806 ******************************************************************************/
775 807
776acpi_status 808static acpi_status
777acpi_ut_remove_allocation ( 809acpi_ut_remove_allocation (
778 u32 list_id, 810 u32 list_id,
779 struct acpi_debug_mem_block *allocation, 811 struct acpi_debug_mem_block *allocation,
@@ -797,7 +829,7 @@ acpi_ut_remove_allocation (
797 /* No allocations! */ 829 /* No allocations! */
798 830
799 _ACPI_REPORT_ERROR (module, line, component, 831 _ACPI_REPORT_ERROR (module, line, component,
800 ("ut_remove_allocation: Empty allocation list, nothing to free!\n")); 832 ("ut_remove_allocation: Empty allocation list, nothing to free!\n"));
801 833
802 return_ACPI_STATUS (AE_OK); 834 return_ACPI_STATUS (AE_OK);
803 } 835 }
@@ -824,7 +856,8 @@ acpi_ut_remove_allocation (
824 856
825 ACPI_MEMSET (&allocation->user_space, 0xEA, allocation->size); 857 ACPI_MEMSET (&allocation->user_space, 0xEA, allocation->size);
826 858
827 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Freeing size 0%X\n", allocation->size)); 859 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Freeing size 0%X\n",
860 allocation->size));
828 861
829 status = acpi_ut_release_mutex (ACPI_MTX_MEMORY); 862 status = acpi_ut_release_mutex (ACPI_MTX_MEMORY);
830 return_ACPI_STATUS (status); 863 return_ACPI_STATUS (status);
@@ -842,6 +875,7 @@ acpi_ut_remove_allocation (
842 * DESCRIPTION: Print some info about the outstanding allocations. 875 * DESCRIPTION: Print some info about the outstanding allocations.
843 * 876 *
844 ******************************************************************************/ 877 ******************************************************************************/
878
845#ifdef ACPI_FUTURE_USAGE 879#ifdef ACPI_FUTURE_USAGE
846void 880void
847acpi_ut_dump_allocation_info ( 881acpi_ut_dump_allocation_info (
@@ -884,7 +918,8 @@ acpi_ut_dump_allocation_info (
884 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES, 918 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
885 ("%30s: %4d (%3d Kb)\n", "Max Nodes", 919 ("%30s: %4d (%3d Kb)\n", "Max Nodes",
886 acpi_gbl_max_concurrent_node_count, 920 acpi_gbl_max_concurrent_node_count,
887 ROUND_UP_TO_1K ((acpi_gbl_max_concurrent_node_count * sizeof (struct acpi_namespace_node))))); 921 ROUND_UP_TO_1K ((acpi_gbl_max_concurrent_node_count *
922 sizeof (struct acpi_namespace_node)))));
888*/ 923*/
889 return_VOID; 924 return_VOID;
890} 925}
@@ -933,26 +968,26 @@ acpi_ut_dump_allocations (
933 descriptor = ACPI_CAST_PTR (union acpi_descriptor, &element->user_space); 968 descriptor = ACPI_CAST_PTR (union acpi_descriptor, &element->user_space);
934 if (descriptor->descriptor_id != ACPI_DESC_TYPE_CACHED) { 969 if (descriptor->descriptor_id != ACPI_DESC_TYPE_CACHED) {
935 acpi_os_printf ("%p Len %04X %9.9s-%d [%s] ", 970 acpi_os_printf ("%p Len %04X %9.9s-%d [%s] ",
936 descriptor, element->size, element->module, 971 descriptor, element->size, element->module,
937 element->line, acpi_ut_get_descriptor_name (descriptor)); 972 element->line, acpi_ut_get_descriptor_name (descriptor));
938 973
939 /* Most of the elements will be Operand objects. */ 974 /* Most of the elements will be Operand objects. */
940 975
941 switch (ACPI_GET_DESCRIPTOR_TYPE (descriptor)) { 976 switch (ACPI_GET_DESCRIPTOR_TYPE (descriptor)) {
942 case ACPI_DESC_TYPE_OPERAND: 977 case ACPI_DESC_TYPE_OPERAND:
943 acpi_os_printf ("%12.12s R%hd", 978 acpi_os_printf ("%12.12s R%hd",
944 acpi_ut_get_type_name (descriptor->object.common.type), 979 acpi_ut_get_type_name (descriptor->object.common.type),
945 descriptor->object.common.reference_count); 980 descriptor->object.common.reference_count);
946 break; 981 break;
947 982
948 case ACPI_DESC_TYPE_PARSER: 983 case ACPI_DESC_TYPE_PARSER:
949 acpi_os_printf ("aml_opcode %04hX", 984 acpi_os_printf ("aml_opcode %04hX",
950 descriptor->op.asl.aml_opcode); 985 descriptor->op.asl.aml_opcode);
951 break; 986 break;
952 987
953 case ACPI_DESC_TYPE_NAMED: 988 case ACPI_DESC_TYPE_NAMED:
954 acpi_os_printf ("%4.4s", 989 acpi_os_printf ("%4.4s",
955 acpi_ut_get_node_name (&descriptor->node)); 990 acpi_ut_get_node_name (&descriptor->node));
956 break; 991 break;
957 992
958 default: 993 default:
@@ -983,6 +1018,5 @@ acpi_ut_dump_allocations (
983 return_VOID; 1018 return_VOID;
984} 1019}
985 1020
986
987#endif /* #ifdef ACPI_DBG_TRACK_ALLOCATIONS */ 1021#endif /* #ifdef ACPI_DBG_TRACK_ALLOCATIONS */
988 1022
diff --git a/drivers/acpi/utilities/utcopy.c b/drivers/acpi/utilities/utcopy.c
index 0fcd98bde0d1..11e884957162 100644
--- a/drivers/acpi/utilities/utcopy.c
+++ b/drivers/acpi/utilities/utcopy.c
@@ -49,21 +49,69 @@
49#define _COMPONENT ACPI_UTILITIES 49#define _COMPONENT ACPI_UTILITIES
50 ACPI_MODULE_NAME ("utcopy") 50 ACPI_MODULE_NAME ("utcopy")
51 51
52/* Local prototypes */
53
54static acpi_status
55acpi_ut_copy_isimple_to_esimple (
56 union acpi_operand_object *internal_object,
57 union acpi_object *external_object,
58 u8 *data_space,
59 acpi_size *buffer_space_used);
60
61static acpi_status
62acpi_ut_copy_ielement_to_ielement (
63 u8 object_type,
64 union acpi_operand_object *source_object,
65 union acpi_generic_state *state,
66 void *context);
67
68static acpi_status
69acpi_ut_copy_ipackage_to_epackage (
70 union acpi_operand_object *internal_object,
71 u8 *buffer,
72 acpi_size *space_used);
73
74static acpi_status
75acpi_ut_copy_esimple_to_isimple(
76 union acpi_object *user_obj,
77 union acpi_operand_object **return_obj);
78
79static acpi_status
80acpi_ut_copy_simple_object (
81 union acpi_operand_object *source_desc,
82 union acpi_operand_object *dest_desc);
83
84static acpi_status
85acpi_ut_copy_ielement_to_eelement (
86 u8 object_type,
87 union acpi_operand_object *source_object,
88 union acpi_generic_state *state,
89 void *context);
90
91static acpi_status
92acpi_ut_copy_ipackage_to_ipackage (
93 union acpi_operand_object *source_obj,
94 union acpi_operand_object *dest_obj,
95 struct acpi_walk_state *walk_state);
96
52 97
53/******************************************************************************* 98/*******************************************************************************
54 * 99 *
55 * FUNCTION: acpi_ut_copy_isimple_to_esimple 100 * FUNCTION: acpi_ut_copy_isimple_to_esimple
56 * 101 *
57 * PARAMETERS: *internal_object - Pointer to the object we are examining 102 * PARAMETERS: internal_object - Source object to be copied
58 * *Buffer - Where the object is returned 103 * external_object - Where to return the copied object
59 * *space_used - Where the data length is returned 104 * data_space - Where object data is returned (such as
105 * buffer and string data)
106 * buffer_space_used - Length of data_space that was used
60 * 107 *
61 * RETURN: Status 108 * RETURN: Status
62 * 109 *
63 * DESCRIPTION: This function is called to place a simple object in a user 110 * DESCRIPTION: This function is called to copy a simple internal object to
64 * buffer. 111 * an external object.
65 * 112 *
66 * The buffer is assumed to have sufficient space for the object. 113 * The data_space buffer is assumed to have sufficient space for
114 * the object.
67 * 115 *
68 ******************************************************************************/ 116 ******************************************************************************/
69 117
@@ -107,10 +155,12 @@ acpi_ut_copy_isimple_to_esimple (
107 155
108 external_object->string.pointer = (char *) data_space; 156 external_object->string.pointer = (char *) data_space;
109 external_object->string.length = internal_object->string.length; 157 external_object->string.length = internal_object->string.length;
110 *buffer_space_used = ACPI_ROUND_UP_TO_NATIVE_WORD ((acpi_size) internal_object->string.length + 1); 158 *buffer_space_used = ACPI_ROUND_UP_TO_NATIVE_WORD (
159 (acpi_size) internal_object->string.length + 1);
111 160
112 ACPI_MEMCPY ((void *) data_space, (void *) internal_object->string.pointer, 161 ACPI_MEMCPY ((void *) data_space,
113 (acpi_size) internal_object->string.length + 1); 162 (void *) internal_object->string.pointer,
163 (acpi_size) internal_object->string.length + 1);
114 break; 164 break;
115 165
116 166
@@ -118,10 +168,12 @@ acpi_ut_copy_isimple_to_esimple (
118 168
119 external_object->buffer.pointer = data_space; 169 external_object->buffer.pointer = data_space;
120 external_object->buffer.length = internal_object->buffer.length; 170 external_object->buffer.length = internal_object->buffer.length;
121 *buffer_space_used = ACPI_ROUND_UP_TO_NATIVE_WORD (internal_object->string.length); 171 *buffer_space_used = ACPI_ROUND_UP_TO_NATIVE_WORD (
172 internal_object->string.length);
122 173
123 ACPI_MEMCPY ((void *) data_space, (void *) internal_object->buffer.pointer, 174 ACPI_MEMCPY ((void *) data_space,
124 internal_object->buffer.length); 175 (void *) internal_object->buffer.pointer,
176 internal_object->buffer.length);
125 break; 177 break;
126 178
127 179
@@ -194,7 +246,7 @@ acpi_ut_copy_isimple_to_esimple (
194 * 246 *
195 ******************************************************************************/ 247 ******************************************************************************/
196 248
197acpi_status 249static acpi_status
198acpi_ut_copy_ielement_to_eelement ( 250acpi_ut_copy_ielement_to_eelement (
199 u8 object_type, 251 u8 object_type,
200 union acpi_operand_object *source_object, 252 union acpi_operand_object *source_object,
@@ -213,7 +265,7 @@ acpi_ut_copy_ielement_to_eelement (
213 265
214 this_index = state->pkg.index; 266 this_index = state->pkg.index;
215 target_object = (union acpi_object *) 267 target_object = (union acpi_object *)
216 &((union acpi_object *)(state->pkg.dest_object))->package.elements[this_index]; 268 &((union acpi_object *)(state->pkg.dest_object))->package.elements[this_index];
217 269
218 switch (object_type) { 270 switch (object_type) {
219 case ACPI_COPY_TYPE_SIMPLE: 271 case ACPI_COPY_TYPE_SIMPLE:
@@ -236,7 +288,8 @@ acpi_ut_copy_ielement_to_eelement (
236 */ 288 */
237 target_object->type = ACPI_TYPE_PACKAGE; 289 target_object->type = ACPI_TYPE_PACKAGE;
238 target_object->package.count = source_object->package.count; 290 target_object->package.count = source_object->package.count;
239 target_object->package.elements = ACPI_CAST_PTR (union acpi_object, info->free_space); 291 target_object->package.elements =
292 ACPI_CAST_PTR (union acpi_object, info->free_space);
240 293
241 /* 294 /*
242 * Pass the new package object back to the package walk routine 295 * Pass the new package object back to the package walk routine
@@ -248,7 +301,8 @@ acpi_ut_copy_ielement_to_eelement (
248 * update the buffer length counter 301 * update the buffer length counter
249 */ 302 */
250 object_space = ACPI_ROUND_UP_TO_NATIVE_WORD ( 303 object_space = ACPI_ROUND_UP_TO_NATIVE_WORD (
251 (acpi_size) target_object->package.count * sizeof (union acpi_object)); 304 (acpi_size) target_object->package.count *
305 sizeof (union acpi_object));
252 break; 306 break;
253 307
254 308
@@ -266,9 +320,9 @@ acpi_ut_copy_ielement_to_eelement (
266 * 320 *
267 * FUNCTION: acpi_ut_copy_ipackage_to_epackage 321 * FUNCTION: acpi_ut_copy_ipackage_to_epackage
268 * 322 *
269 * PARAMETERS: *internal_object - Pointer to the object we are returning 323 * PARAMETERS: internal_object - Pointer to the object we are returning
270 * *Buffer - Where the object is returned 324 * Buffer - Where the object is returned
271 * *space_used - Where the object length is returned 325 * space_used - Where the object length is returned
272 * 326 *
273 * RETURN: Status 327 * RETURN: Status
274 * 328 *
@@ -304,13 +358,15 @@ acpi_ut_copy_ipackage_to_epackage (
304 * Free space begins right after the first package 358 * Free space begins right after the first package
305 */ 359 */
306 info.length = ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (union acpi_object)); 360 info.length = ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (union acpi_object));
307 info.free_space = buffer + ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (union acpi_object)); 361 info.free_space = buffer + ACPI_ROUND_UP_TO_NATIVE_WORD (
362 sizeof (union acpi_object));
308 info.object_space = 0; 363 info.object_space = 0;
309 info.num_packages = 1; 364 info.num_packages = 1;
310 365
311 external_object->type = ACPI_GET_OBJECT_TYPE (internal_object); 366 external_object->type = ACPI_GET_OBJECT_TYPE (internal_object);
312 external_object->package.count = internal_object->package.count; 367 external_object->package.count = internal_object->package.count;
313 external_object->package.elements = ACPI_CAST_PTR (union acpi_object, info.free_space); 368 external_object->package.elements = ACPI_CAST_PTR (union acpi_object,
369 info.free_space);
314 370
315 /* 371 /*
316 * Leave room for an array of ACPI_OBJECTS in the buffer 372 * Leave room for an array of ACPI_OBJECTS in the buffer
@@ -333,8 +389,8 @@ acpi_ut_copy_ipackage_to_epackage (
333 * 389 *
334 * FUNCTION: acpi_ut_copy_iobject_to_eobject 390 * FUNCTION: acpi_ut_copy_iobject_to_eobject
335 * 391 *
336 * PARAMETERS: *internal_object - The internal object to be converted 392 * PARAMETERS: internal_object - The internal object to be converted
337 * *buffer_ptr - Where the object is returned 393 * buffer_ptr - Where the object is returned
338 * 394 *
339 * RETURN: Status 395 * RETURN: Status
340 * 396 *
@@ -367,10 +423,10 @@ acpi_ut_copy_iobject_to_eobject (
367 * Build a simple object (no nested objects) 423 * Build a simple object (no nested objects)
368 */ 424 */
369 status = acpi_ut_copy_isimple_to_esimple (internal_object, 425 status = acpi_ut_copy_isimple_to_esimple (internal_object,
370 (union acpi_object *) ret_buffer->pointer, 426 (union acpi_object *) ret_buffer->pointer,
371 ((u8 *) ret_buffer->pointer + 427 ((u8 *) ret_buffer->pointer +
372 ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (union acpi_object))), 428 ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (union acpi_object))),
373 &ret_buffer->length); 429 &ret_buffer->length);
374 /* 430 /*
375 * build simple does not include the object size in the length 431 * build simple does not include the object size in the length
376 * so we add it in here 432 * so we add it in here
@@ -386,8 +442,8 @@ acpi_ut_copy_iobject_to_eobject (
386 * 442 *
387 * FUNCTION: acpi_ut_copy_esimple_to_isimple 443 * FUNCTION: acpi_ut_copy_esimple_to_isimple
388 * 444 *
389 * PARAMETERS: *external_object - The external object to be converted 445 * PARAMETERS: external_object - The external object to be converted
390 * *internal_object - Where the internal object is returned 446 * ret_internal_object - Where the internal object is returned
391 * 447 *
392 * RETURN: Status 448 * RETURN: Status
393 * 449 *
@@ -398,7 +454,7 @@ acpi_ut_copy_iobject_to_eobject (
398 * 454 *
399 ******************************************************************************/ 455 ******************************************************************************/
400 456
401acpi_status 457static acpi_status
402acpi_ut_copy_esimple_to_isimple ( 458acpi_ut_copy_esimple_to_isimple (
403 union acpi_object *external_object, 459 union acpi_object *external_object,
404 union acpi_operand_object **ret_internal_object) 460 union acpi_operand_object **ret_internal_object)
@@ -417,7 +473,8 @@ acpi_ut_copy_esimple_to_isimple (
417 case ACPI_TYPE_BUFFER: 473 case ACPI_TYPE_BUFFER:
418 case ACPI_TYPE_INTEGER: 474 case ACPI_TYPE_INTEGER:
419 475
420 internal_object = acpi_ut_create_internal_object ((u8) external_object->type); 476 internal_object = acpi_ut_create_internal_object (
477 (u8) external_object->type);
421 if (!internal_object) { 478 if (!internal_object) {
422 return_ACPI_STATUS (AE_NO_MEMORY); 479 return_ACPI_STATUS (AE_NO_MEMORY);
423 } 480 }
@@ -486,7 +543,6 @@ error_exit:
486 543
487 544
488#ifdef ACPI_FUTURE_IMPLEMENTATION 545#ifdef ACPI_FUTURE_IMPLEMENTATION
489
490/* Code to convert packages that are parameters to control methods */ 546/* Code to convert packages that are parameters to control methods */
491 547
492/******************************************************************************* 548/*******************************************************************************
@@ -614,7 +670,7 @@ acpi_ut_copy_eobject_to_iobject (
614 * 670 *
615 ******************************************************************************/ 671 ******************************************************************************/
616 672
617acpi_status 673static acpi_status
618acpi_ut_copy_simple_object ( 674acpi_ut_copy_simple_object (
619 union acpi_operand_object *source_desc, 675 union acpi_operand_object *source_desc,
620 union acpi_operand_object *dest_desc) 676 union acpi_operand_object *dest_desc)
@@ -724,7 +780,7 @@ acpi_ut_copy_simple_object (
724 * 780 *
725 ******************************************************************************/ 781 ******************************************************************************/
726 782
727acpi_status 783static acpi_status
728acpi_ut_copy_ielement_to_ielement ( 784acpi_ut_copy_ielement_to_ielement (
729 u8 object_type, 785 u8 object_type,
730 union acpi_operand_object *source_object, 786 union acpi_operand_object *source_object,
@@ -837,7 +893,7 @@ error_exit:
837 * 893 *
838 ******************************************************************************/ 894 ******************************************************************************/
839 895
840acpi_status 896static acpi_status
841acpi_ut_copy_ipackage_to_ipackage ( 897acpi_ut_copy_ipackage_to_ipackage (
842 union acpi_operand_object *source_obj, 898 union acpi_operand_object *source_obj,
843 union acpi_operand_object *dest_obj, 899 union acpi_operand_object *dest_obj,
diff --git a/drivers/acpi/utilities/utdebug.c b/drivers/acpi/utilities/utdebug.c
index 985c5d045b78..794c7df3f2ad 100644
--- a/drivers/acpi/utilities/utdebug.c
+++ b/drivers/acpi/utilities/utdebug.c
@@ -56,7 +56,7 @@ static char *acpi_gbl_fn_entry_str = "----Entry";
56static char *acpi_gbl_fn_exit_str = "----Exit-"; 56static char *acpi_gbl_fn_exit_str = "----Exit-";
57 57
58 58
59/***************************************************************************** 59/*******************************************************************************
60 * 60 *
61 * FUNCTION: acpi_ut_init_stack_ptr_trace 61 * FUNCTION: acpi_ut_init_stack_ptr_trace
62 * 62 *
@@ -64,9 +64,9 @@ static char *acpi_gbl_fn_exit_str = "----Exit-";
64 * 64 *
65 * RETURN: None 65 * RETURN: None
66 * 66 *
67 * DESCRIPTION: Save the current stack pointer 67 * DESCRIPTION: Save the current CPU stack pointer at subsystem startup
68 * 68 *
69 ****************************************************************************/ 69 ******************************************************************************/
70 70
71void 71void
72acpi_ut_init_stack_ptr_trace ( 72acpi_ut_init_stack_ptr_trace (
@@ -79,7 +79,7 @@ acpi_ut_init_stack_ptr_trace (
79} 79}
80 80
81 81
82/***************************************************************************** 82/*******************************************************************************
83 * 83 *
84 * FUNCTION: acpi_ut_track_stack_ptr 84 * FUNCTION: acpi_ut_track_stack_ptr
85 * 85 *
@@ -87,9 +87,9 @@ acpi_ut_init_stack_ptr_trace (
87 * 87 *
88 * RETURN: None 88 * RETURN: None
89 * 89 *
90 * DESCRIPTION: Save the current stack pointer 90 * DESCRIPTION: Save the current CPU stack pointer
91 * 91 *
92 ****************************************************************************/ 92 ******************************************************************************/
93 93
94void 94void
95acpi_ut_track_stack_ptr ( 95acpi_ut_track_stack_ptr (
@@ -110,16 +110,16 @@ acpi_ut_track_stack_ptr (
110} 110}
111 111
112 112
113/***************************************************************************** 113/*******************************************************************************
114 * 114 *
115 * FUNCTION: acpi_ut_debug_print 115 * FUNCTION: acpi_ut_debug_print
116 * 116 *
117 * PARAMETERS: debug_level - Requested debug print level 117 * PARAMETERS: requested_debug_level - Requested debug print level
118 * proc_name - Caller's procedure name
119 * module_name - Caller's module name (for error output)
120 * line_number - Caller's line number (for error output) 118 * line_number - Caller's line number (for error output)
121 * component_id - Caller's component ID (for error output) 119 * dbg_info - Contains:
122 * 120 * proc_name - Caller's procedure name
121 * module_name - Caller's module name
122 * component_id - Caller's component ID
123 * Format - Printf format field 123 * Format - Printf format field
124 * ... - Optional printf arguments 124 * ... - Optional printf arguments
125 * 125 *
@@ -128,7 +128,7 @@ acpi_ut_track_stack_ptr (
128 * DESCRIPTION: Print error message with prefix consisting of the module name, 128 * DESCRIPTION: Print error message with prefix consisting of the module name,
129 * line number, and component ID. 129 * line number, and component ID.
130 * 130 *
131 ****************************************************************************/ 131 ******************************************************************************/
132 132
133void ACPI_INTERNAL_VAR_XFACE 133void ACPI_INTERNAL_VAR_XFACE
134acpi_ut_debug_print ( 134acpi_ut_debug_print (
@@ -157,7 +157,8 @@ acpi_ut_debug_print (
157 157
158 if (thread_id != acpi_gbl_prev_thread_id) { 158 if (thread_id != acpi_gbl_prev_thread_id) {
159 if (ACPI_LV_THREADS & acpi_dbg_level) { 159 if (ACPI_LV_THREADS & acpi_dbg_level) {
160 acpi_os_printf ("\n**** Context Switch from TID %X to TID %X ****\n\n", 160 acpi_os_printf (
161 "\n**** Context Switch from TID %X to TID %X ****\n\n",
161 acpi_gbl_prev_thread_id, thread_id); 162 acpi_gbl_prev_thread_id, thread_id);
162 } 163 }
163 164
@@ -174,15 +175,16 @@ acpi_ut_debug_print (
174 acpi_os_printf ("[%04lX] ", thread_id); 175 acpi_os_printf ("[%04lX] ", thread_id);
175 } 176 }
176 177
177 acpi_os_printf ("[%02ld] %-22.22s: ", acpi_gbl_nesting_level, dbg_info->proc_name); 178 acpi_os_printf ("[%02ld] %-22.22s: ",
179 acpi_gbl_nesting_level, dbg_info->proc_name);
178 180
179 va_start (args, format); 181 va_start (args, format);
180 acpi_os_vprintf (format, args); 182 acpi_os_vprintf (format, args);
181} 183}
182EXPORT_SYMBOL(acpi_ut_debug_print);
183 184
185EXPORT_SYMBOL(acpi_ut_debug_print);
184 186
185/***************************************************************************** 187/*******************************************************************************
186 * 188 *
187 * FUNCTION: acpi_ut_debug_print_raw 189 * FUNCTION: acpi_ut_debug_print_raw
188 * 190 *
@@ -200,7 +202,7 @@ EXPORT_SYMBOL(acpi_ut_debug_print);
200 * DESCRIPTION: Print message with no headers. Has same interface as 202 * DESCRIPTION: Print message with no headers. Has same interface as
201 * debug_print so that the same macros can be used. 203 * debug_print so that the same macros can be used.
202 * 204 *
203 ****************************************************************************/ 205 ******************************************************************************/
204 206
205void ACPI_INTERNAL_VAR_XFACE 207void ACPI_INTERNAL_VAR_XFACE
206acpi_ut_debug_print_raw ( 208acpi_ut_debug_print_raw (
@@ -224,7 +226,7 @@ acpi_ut_debug_print_raw (
224EXPORT_SYMBOL(acpi_ut_debug_print_raw); 226EXPORT_SYMBOL(acpi_ut_debug_print_raw);
225 227
226 228
227/***************************************************************************** 229/*******************************************************************************
228 * 230 *
229 * FUNCTION: acpi_ut_trace 231 * FUNCTION: acpi_ut_trace
230 * 232 *
@@ -239,7 +241,7 @@ EXPORT_SYMBOL(acpi_ut_debug_print_raw);
239 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is 241 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
240 * set in debug_level 242 * set in debug_level
241 * 243 *
242 ****************************************************************************/ 244 ******************************************************************************/
243 245
244void 246void
245acpi_ut_trace ( 247acpi_ut_trace (
@@ -256,7 +258,7 @@ acpi_ut_trace (
256EXPORT_SYMBOL(acpi_ut_trace); 258EXPORT_SYMBOL(acpi_ut_trace);
257 259
258 260
259/***************************************************************************** 261/*******************************************************************************
260 * 262 *
261 * FUNCTION: acpi_ut_trace_ptr 263 * FUNCTION: acpi_ut_trace_ptr
262 * 264 *
@@ -272,7 +274,7 @@ EXPORT_SYMBOL(acpi_ut_trace);
272 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is 274 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
273 * set in debug_level 275 * set in debug_level
274 * 276 *
275 ****************************************************************************/ 277 ******************************************************************************/
276 278
277void 279void
278acpi_ut_trace_ptr ( 280acpi_ut_trace_ptr (
@@ -288,7 +290,7 @@ acpi_ut_trace_ptr (
288} 290}
289 291
290 292
291/***************************************************************************** 293/*******************************************************************************
292 * 294 *
293 * FUNCTION: acpi_ut_trace_str 295 * FUNCTION: acpi_ut_trace_str
294 * 296 *
@@ -304,7 +306,7 @@ acpi_ut_trace_ptr (
304 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is 306 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
305 * set in debug_level 307 * set in debug_level
306 * 308 *
307 ****************************************************************************/ 309 ******************************************************************************/
308 310
309void 311void
310acpi_ut_trace_str ( 312acpi_ut_trace_str (
@@ -321,7 +323,7 @@ acpi_ut_trace_str (
321} 323}
322 324
323 325
324/***************************************************************************** 326/*******************************************************************************
325 * 327 *
326 * FUNCTION: acpi_ut_trace_u32 328 * FUNCTION: acpi_ut_trace_u32
327 * 329 *
@@ -337,7 +339,7 @@ acpi_ut_trace_str (
337 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is 339 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
338 * set in debug_level 340 * set in debug_level
339 * 341 *
340 ****************************************************************************/ 342 ******************************************************************************/
341 343
342void 344void
343acpi_ut_trace_u32 ( 345acpi_ut_trace_u32 (
@@ -354,7 +356,7 @@ acpi_ut_trace_u32 (
354} 356}
355 357
356 358
357/***************************************************************************** 359/*******************************************************************************
358 * 360 *
359 * FUNCTION: acpi_ut_exit 361 * FUNCTION: acpi_ut_exit
360 * 362 *
@@ -369,7 +371,7 @@ acpi_ut_trace_u32 (
369 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is 371 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
370 * set in debug_level 372 * set in debug_level
371 * 373 *
372 ****************************************************************************/ 374 ******************************************************************************/
373 375
374void 376void
375acpi_ut_exit ( 377acpi_ut_exit (
@@ -385,7 +387,7 @@ acpi_ut_exit (
385EXPORT_SYMBOL(acpi_ut_exit); 387EXPORT_SYMBOL(acpi_ut_exit);
386 388
387 389
388/***************************************************************************** 390/*******************************************************************************
389 * 391 *
390 * FUNCTION: acpi_ut_status_exit 392 * FUNCTION: acpi_ut_status_exit
391 * 393 *
@@ -401,7 +403,7 @@ EXPORT_SYMBOL(acpi_ut_exit);
401 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is 403 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
402 * set in debug_level. Prints exit status also. 404 * set in debug_level. Prints exit status also.
403 * 405 *
404 ****************************************************************************/ 406 ******************************************************************************/
405 407
406void 408void
407acpi_ut_status_exit ( 409acpi_ut_status_exit (
@@ -426,7 +428,7 @@ acpi_ut_status_exit (
426EXPORT_SYMBOL(acpi_ut_status_exit); 428EXPORT_SYMBOL(acpi_ut_status_exit);
427 429
428 430
429/***************************************************************************** 431/*******************************************************************************
430 * 432 *
431 * FUNCTION: acpi_ut_value_exit 433 * FUNCTION: acpi_ut_value_exit
432 * 434 *
@@ -442,7 +444,7 @@ EXPORT_SYMBOL(acpi_ut_status_exit);
442 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is 444 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
443 * set in debug_level. Prints exit value also. 445 * set in debug_level. Prints exit value also.
444 * 446 *
445 ****************************************************************************/ 447 ******************************************************************************/
446 448
447void 449void
448acpi_ut_value_exit ( 450acpi_ut_value_exit (
@@ -460,7 +462,7 @@ acpi_ut_value_exit (
460EXPORT_SYMBOL(acpi_ut_value_exit); 462EXPORT_SYMBOL(acpi_ut_value_exit);
461 463
462 464
463/***************************************************************************** 465/*******************************************************************************
464 * 466 *
465 * FUNCTION: acpi_ut_ptr_exit 467 * FUNCTION: acpi_ut_ptr_exit
466 * 468 *
@@ -469,14 +471,14 @@ EXPORT_SYMBOL(acpi_ut_value_exit);
469 * proc_name - Caller's procedure name 471 * proc_name - Caller's procedure name
470 * module_name - Caller's module name 472 * module_name - Caller's module name
471 * component_id - Caller's component ID 473 * component_id - Caller's component ID
472 * Value - Value to be printed with exit msg 474 * Ptr - Pointer to display
473 * 475 *
474 * RETURN: None 476 * RETURN: None
475 * 477 *
476 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is 478 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
477 * set in debug_level. Prints exit value also. 479 * set in debug_level. Prints exit value also.
478 * 480 *
479 ****************************************************************************/ 481 ******************************************************************************/
480 482
481void 483void
482acpi_ut_ptr_exit ( 484acpi_ut_ptr_exit (
@@ -494,7 +496,7 @@ acpi_ut_ptr_exit (
494#endif 496#endif
495 497
496 498
497/***************************************************************************** 499/*******************************************************************************
498 * 500 *
499 * FUNCTION: acpi_ut_dump_buffer 501 * FUNCTION: acpi_ut_dump_buffer
500 * 502 *
@@ -507,7 +509,7 @@ acpi_ut_ptr_exit (
507 * 509 *
508 * DESCRIPTION: Generic dump buffer in both hex and ascii. 510 * DESCRIPTION: Generic dump buffer in both hex and ascii.
509 * 511 *
510 ****************************************************************************/ 512 ******************************************************************************/
511 513
512void 514void
513acpi_ut_dump_buffer ( 515acpi_ut_dump_buffer (
@@ -533,34 +535,28 @@ acpi_ut_dump_buffer (
533 display = DB_BYTE_DISPLAY; 535 display = DB_BYTE_DISPLAY;
534 } 536 }
535 537
536 acpi_os_printf ("\nOffset Value\n"); 538 /* Nasty little dump buffer routine! */
537 539
538 /*
539 * Nasty little dump buffer routine!
540 */
541 while (i < count) { 540 while (i < count) {
542 /* Print current offset */ 541 /* Print current offset */
543 542
544 acpi_os_printf ("%05X ", (u32) i); 543 acpi_os_printf ("%6.4X: ", (u32) i);
545 544
546 /* Print 16 hex chars */ 545 /* Print 16 hex chars */
547 546
548 for (j = 0; j < 16;) { 547 for (j = 0; j < 16;) {
549 if (i + j >= count) { 548 if (i + j >= count) {
550 acpi_os_printf ("\n"); 549 /* Dump fill spaces */
551 return;
552 }
553 550
554 /* Make sure that the s8 doesn't get sign-extended! */ 551 acpi_os_printf ("%*s", ((display * 2) + 1), " ");
552 j += display;
553 continue;
554 }
555 555
556 switch (display) { 556 switch (display) {
557 /* Default is BYTE display */ 557 default: /* Default is BYTE display */
558 558
559 default: 559 acpi_os_printf ("%02X ", buffer[i + j]);
560
561 acpi_os_printf ("%02X ",
562 *((u8 *) &buffer[i + j]));
563 j += 1;
564 break; 560 break;
565 561
566 562
@@ -568,7 +564,6 @@ acpi_ut_dump_buffer (
568 564
569 ACPI_MOVE_16_TO_32 (&temp32, &buffer[i + j]); 565 ACPI_MOVE_16_TO_32 (&temp32, &buffer[i + j]);
570 acpi_os_printf ("%04X ", temp32); 566 acpi_os_printf ("%04X ", temp32);
571 j += 2;
572 break; 567 break;
573 568
574 569
@@ -576,7 +571,6 @@ acpi_ut_dump_buffer (
576 571
577 ACPI_MOVE_32_TO_32 (&temp32, &buffer[i + j]); 572 ACPI_MOVE_32_TO_32 (&temp32, &buffer[i + j]);
578 acpi_os_printf ("%08X ", temp32); 573 acpi_os_printf ("%08X ", temp32);
579 j += 4;
580 break; 574 break;
581 575
582 576
@@ -587,15 +581,17 @@ acpi_ut_dump_buffer (
587 581
588 ACPI_MOVE_32_TO_32 (&temp32, &buffer[i + j + 4]); 582 ACPI_MOVE_32_TO_32 (&temp32, &buffer[i + j + 4]);
589 acpi_os_printf ("%08X ", temp32); 583 acpi_os_printf ("%08X ", temp32);
590 j += 8;
591 break; 584 break;
592 } 585 }
586
587 j += display;
593 } 588 }
594 589
595 /* 590 /*
596 * Print the ASCII equivalent characters 591 * Print the ASCII equivalent characters
597 * But watch out for the bad unprintable ones... 592 * But watch out for the bad unprintable ones...
598 */ 593 */
594 acpi_os_printf (" ");
599 for (j = 0; j < 16; j++) { 595 for (j = 0; j < 16; j++) {
600 if (i + j >= count) { 596 if (i + j >= count) {
601 acpi_os_printf ("\n"); 597 acpi_os_printf ("\n");
diff --git a/drivers/acpi/utilities/utdelete.c b/drivers/acpi/utilities/utdelete.c
index 9a52ad52a23a..bc5403022681 100644
--- a/drivers/acpi/utilities/utdelete.c
+++ b/drivers/acpi/utilities/utdelete.c
@@ -51,12 +51,23 @@
51#define _COMPONENT ACPI_UTILITIES 51#define _COMPONENT ACPI_UTILITIES
52 ACPI_MODULE_NAME ("utdelete") 52 ACPI_MODULE_NAME ("utdelete")
53 53
54/* Local prototypes */
55
56static void
57acpi_ut_delete_internal_obj (
58 union acpi_operand_object *object);
59
60static void
61acpi_ut_update_ref_count (
62 union acpi_operand_object *object,
63 u32 action);
64
54 65
55/******************************************************************************* 66/*******************************************************************************
56 * 67 *
57 * FUNCTION: acpi_ut_delete_internal_obj 68 * FUNCTION: acpi_ut_delete_internal_obj
58 * 69 *
59 * PARAMETERS: *Object - Pointer to the list to be deleted 70 * PARAMETERS: Object - Object to be deleted
60 * 71 *
61 * RETURN: None 72 * RETURN: None
62 * 73 *
@@ -65,7 +76,7 @@
65 * 76 *
66 ******************************************************************************/ 77 ******************************************************************************/
67 78
68void 79static void
69acpi_ut_delete_internal_obj ( 80acpi_ut_delete_internal_obj (
70 union acpi_operand_object *object) 81 union acpi_operand_object *object)
71{ 82{
@@ -152,7 +163,8 @@ acpi_ut_delete_internal_obj (
152 163
153 case ACPI_TYPE_MUTEX: 164 case ACPI_TYPE_MUTEX:
154 165
155 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "***** Mutex %p, Semaphore %p\n", 166 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
167 "***** Mutex %p, Semaphore %p\n",
156 object, object->mutex.semaphore)); 168 object, object->mutex.semaphore));
157 169
158 acpi_ex_unlink_mutex (object); 170 acpi_ex_unlink_mutex (object);
@@ -162,7 +174,8 @@ acpi_ut_delete_internal_obj (
162 174
163 case ACPI_TYPE_EVENT: 175 case ACPI_TYPE_EVENT:
164 176
165 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "***** Event %p, Semaphore %p\n", 177 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
178 "***** Event %p, Semaphore %p\n",
166 object, object->event.semaphore)); 179 object, object->event.semaphore));
167 180
168 (void) acpi_os_delete_semaphore (object->event.semaphore); 181 (void) acpi_os_delete_semaphore (object->event.semaphore);
@@ -172,7 +185,8 @@ acpi_ut_delete_internal_obj (
172 185
173 case ACPI_TYPE_METHOD: 186 case ACPI_TYPE_METHOD:
174 187
175 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "***** Method %p\n", object)); 188 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
189 "***** Method %p\n", object));
176 190
177 /* Delete the method semaphore if it exists */ 191 /* Delete the method semaphore if it exists */
178 192
@@ -185,7 +199,8 @@ acpi_ut_delete_internal_obj (
185 199
186 case ACPI_TYPE_REGION: 200 case ACPI_TYPE_REGION:
187 201
188 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "***** Region %p\n", object)); 202 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
203 "***** Region %p\n", object));
189 204
190 second_desc = acpi_ns_get_secondary_object (object); 205 second_desc = acpi_ns_get_secondary_object (object);
191 if (second_desc) { 206 if (second_desc) {
@@ -212,7 +227,8 @@ acpi_ut_delete_internal_obj (
212 227
213 case ACPI_TYPE_BUFFER_FIELD: 228 case ACPI_TYPE_BUFFER_FIELD:
214 229
215 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "***** Buffer Field %p\n", object)); 230 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
231 "***** Buffer Field %p\n", object));
216 232
217 second_desc = acpi_ns_get_secondary_object (object); 233 second_desc = acpi_ns_get_secondary_object (object);
218 if (second_desc) { 234 if (second_desc) {
@@ -247,7 +263,7 @@ acpi_ut_delete_internal_obj (
247 * 263 *
248 * FUNCTION: acpi_ut_delete_internal_object_list 264 * FUNCTION: acpi_ut_delete_internal_object_list
249 * 265 *
250 * PARAMETERS: *obj_list - Pointer to the list to be deleted 266 * PARAMETERS: obj_list - Pointer to the list to be deleted
251 * 267 *
252 * RETURN: None 268 * RETURN: None
253 * 269 *
@@ -283,7 +299,7 @@ acpi_ut_delete_internal_object_list (
283 * 299 *
284 * FUNCTION: acpi_ut_update_ref_count 300 * FUNCTION: acpi_ut_update_ref_count
285 * 301 *
286 * PARAMETERS: *Object - Object whose ref count is to be updated 302 * PARAMETERS: Object - Object whose ref count is to be updated
287 * Action - What to do 303 * Action - What to do
288 * 304 *
289 * RETURN: New ref count 305 * RETURN: New ref count
@@ -312,7 +328,8 @@ acpi_ut_update_ref_count (
312 new_count = count; 328 new_count = count;
313 329
314 /* 330 /*
315 * Perform the reference count action (increment, decrement, or force delete) 331 * Perform the reference count action
332 * (increment, decrement, or force delete)
316 */ 333 */
317 switch (action) { 334 switch (action) {
318 335
@@ -321,7 +338,8 @@ acpi_ut_update_ref_count (
321 new_count++; 338 new_count++;
322 object->common.reference_count = new_count; 339 object->common.reference_count = new_count;
323 340
324 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Obj %p Refs=%X, [Incremented]\n", 341 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
342 "Obj %p Refs=%X, [Incremented]\n",
325 object, new_count)); 343 object, new_count));
326 break; 344 break;
327 345
@@ -329,7 +347,8 @@ acpi_ut_update_ref_count (
329 case REF_DECREMENT: 347 case REF_DECREMENT:
330 348
331 if (count < 1) { 349 if (count < 1) {
332 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Obj %p Refs=%X, can't decrement! (Set to 0)\n", 350 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
351 "Obj %p Refs=%X, can't decrement! (Set to 0)\n",
333 object, new_count)); 352 object, new_count));
334 353
335 new_count = 0; 354 new_count = 0;
@@ -337,12 +356,14 @@ acpi_ut_update_ref_count (
337 else { 356 else {
338 new_count--; 357 new_count--;
339 358
340 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Obj %p Refs=%X, [Decremented]\n", 359 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
360 "Obj %p Refs=%X, [Decremented]\n",
341 object, new_count)); 361 object, new_count));
342 } 362 }
343 363
344 if (ACPI_GET_OBJECT_TYPE (object) == ACPI_TYPE_METHOD) { 364 if (ACPI_GET_OBJECT_TYPE (object) == ACPI_TYPE_METHOD) {
345 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Method Obj %p Refs=%X, [Decremented]\n", 365 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
366 "Method Obj %p Refs=%X, [Decremented]\n",
346 object, new_count)); 367 object, new_count));
347 } 368 }
348 369
@@ -356,7 +377,8 @@ acpi_ut_update_ref_count (
356 377
357 case REF_FORCE_DELETE: 378 case REF_FORCE_DELETE:
358 379
359 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Obj %p Refs=%X, Force delete! (Set to 0)\n", 380 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
381 "Obj %p Refs=%X, Force delete! (Set to 0)\n",
360 object, count)); 382 object, count));
361 383
362 new_count = 0; 384 new_count = 0;
@@ -390,7 +412,7 @@ acpi_ut_update_ref_count (
390 * 412 *
391 * FUNCTION: acpi_ut_update_object_reference 413 * FUNCTION: acpi_ut_update_object_reference
392 * 414 *
393 * PARAMETERS: *Object - Increment ref count for this object 415 * PARAMETERS: Object - Increment ref count for this object
394 * and all sub-objects 416 * and all sub-objects
395 * Action - Either REF_INCREMENT or REF_DECREMENT or 417 * Action - Either REF_INCREMENT or REF_DECREMENT or
396 * REF_FORCE_DELETE 418 * REF_FORCE_DELETE
@@ -431,7 +453,8 @@ acpi_ut_update_object_reference (
431 /* Make sure that this isn't a namespace handle */ 453 /* Make sure that this isn't a namespace handle */
432 454
433 if (ACPI_GET_DESCRIPTOR_TYPE (object) == ACPI_DESC_TYPE_NAMED) { 455 if (ACPI_GET_DESCRIPTOR_TYPE (object) == ACPI_DESC_TYPE_NAMED) {
434 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Object %p is NS handle\n", object)); 456 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
457 "Object %p is NS handle\n", object));
435 return_ACPI_STATUS (AE_OK); 458 return_ACPI_STATUS (AE_OK);
436 } 459 }
437 460
@@ -614,8 +637,8 @@ error_exit:
614 * 637 *
615 * FUNCTION: acpi_ut_add_reference 638 * FUNCTION: acpi_ut_add_reference
616 * 639 *
617 * PARAMETERS: *Object - Object whose reference count is to be 640 * PARAMETERS: Object - Object whose reference count is to be
618 * incremented 641 * incremented
619 * 642 *
620 * RETURN: None 643 * RETURN: None
621 * 644 *
@@ -652,7 +675,7 @@ acpi_ut_add_reference (
652 * 675 *
653 * FUNCTION: acpi_ut_remove_reference 676 * FUNCTION: acpi_ut_remove_reference
654 * 677 *
655 * PARAMETERS: *Object - Object whose ref count will be decremented 678 * PARAMETERS: Object - Object whose ref count will be decremented
656 * 679 *
657 * RETURN: None 680 * RETURN: None
658 * 681 *
diff --git a/drivers/acpi/utilities/uteval.c b/drivers/acpi/utilities/uteval.c
index ead27d2c4d18..00046dd5d925 100644
--- a/drivers/acpi/utilities/uteval.c
+++ b/drivers/acpi/utilities/uteval.c
@@ -50,6 +50,19 @@
50#define _COMPONENT ACPI_UTILITIES 50#define _COMPONENT ACPI_UTILITIES
51 ACPI_MODULE_NAME ("uteval") 51 ACPI_MODULE_NAME ("uteval")
52 52
53/* Local prototypes */
54
55static void
56acpi_ut_copy_id_string (
57 char *destination,
58 char *source,
59 acpi_size max_length);
60
61static acpi_status
62acpi_ut_translate_one_cid (
63 union acpi_operand_object *obj_desc,
64 struct acpi_compatible_id *one_cid);
65
53 66
54/******************************************************************************* 67/*******************************************************************************
55 * 68 *
@@ -237,9 +250,9 @@ acpi_ut_evaluate_object (
237 * 250 *
238 * FUNCTION: acpi_ut_evaluate_numeric_object 251 * FUNCTION: acpi_ut_evaluate_numeric_object
239 * 252 *
240 * PARAMETERS: *object_name - Object name to be evaluated 253 * PARAMETERS: object_name - Object name to be evaluated
241 * device_node - Node for the device 254 * device_node - Node for the device
242 * *Address - Where the value is returned 255 * Address - Where the value is returned
243 * 256 *
244 * RETURN: Status 257 * RETURN: Status
245 * 258 *
@@ -303,7 +316,6 @@ acpi_ut_copy_id_string (
303 acpi_size max_length) 316 acpi_size max_length)
304{ 317{
305 318
306
307 /* 319 /*
308 * Workaround for ID strings that have a leading asterisk. This construct 320 * Workaround for ID strings that have a leading asterisk. This construct
309 * is not allowed by the ACPI specification (ID strings must be 321 * is not allowed by the ACPI specification (ID strings must be
@@ -325,7 +337,7 @@ acpi_ut_copy_id_string (
325 * FUNCTION: acpi_ut_execute_HID 337 * FUNCTION: acpi_ut_execute_HID
326 * 338 *
327 * PARAMETERS: device_node - Node for the device 339 * PARAMETERS: device_node - Node for the device
328 * *Hid - Where the HID is returned 340 * Hid - Where the HID is returned
329 * 341 *
330 * RETURN: Status 342 * RETURN: Status
331 * 343 *
@@ -429,7 +441,7 @@ acpi_ut_translate_one_cid (
429 * FUNCTION: acpi_ut_execute_CID 441 * FUNCTION: acpi_ut_execute_CID
430 * 442 *
431 * PARAMETERS: device_node - Node for the device 443 * PARAMETERS: device_node - Node for the device
432 * *Cid - Where the CID is returned 444 * return_cid_list - Where the CID list is returned
433 * 445 *
434 * RETURN: Status 446 * RETURN: Status
435 * 447 *
@@ -488,10 +500,10 @@ acpi_ut_execute_CID (
488 cid_list->size = size; 500 cid_list->size = size;
489 501
490 /* 502 /*
491 * A _CID can return either a single compatible ID or a package of compatible 503 * A _CID can return either a single compatible ID or a package of
492 * IDs. Each compatible ID can be one of the following: 504 * compatible IDs. Each compatible ID can be one of the following:
493 * -- Number (32 bit compressed EISA ID) or 505 * 1) Integer (32 bit compressed EISA ID) or
494 * -- String (PCI ID format, e.g. "PCI\VEN_vvvv&DEV_dddd&SUBSYS_ssssssss"). 506 * 2) String (PCI ID format, e.g. "PCI\VEN_vvvv&DEV_dddd&SUBSYS_ssssssss")
495 */ 507 */
496 508
497 /* The _CID object can be either a single CID or a package (list) of CIDs */ 509 /* The _CID object can be either a single CID or a package (list) of CIDs */
@@ -534,7 +546,7 @@ acpi_ut_execute_CID (
534 * FUNCTION: acpi_ut_execute_UID 546 * FUNCTION: acpi_ut_execute_UID
535 * 547 *
536 * PARAMETERS: device_node - Node for the device 548 * PARAMETERS: device_node - Node for the device
537 * *Uid - Where the UID is returned 549 * Uid - Where the UID is returned
538 * 550 *
539 * RETURN: Status 551 * RETURN: Status
540 * 552 *
@@ -587,7 +599,7 @@ acpi_ut_execute_UID (
587 * FUNCTION: acpi_ut_execute_STA 599 * FUNCTION: acpi_ut_execute_STA
588 * 600 *
589 * PARAMETERS: device_node - Node for the device 601 * PARAMETERS: device_node - Node for the device
590 * *Flags - Where the status flags are returned 602 * Flags - Where the status flags are returned
591 * 603 *
592 * RETURN: Status 604 * RETURN: Status
593 * 605 *
@@ -641,7 +653,7 @@ acpi_ut_execute_STA (
641 * FUNCTION: acpi_ut_execute_Sxds 653 * FUNCTION: acpi_ut_execute_Sxds
642 * 654 *
643 * PARAMETERS: device_node - Node for the device 655 * PARAMETERS: device_node - Node for the device
644 * *Flags - Where the status flags are returned 656 * Flags - Where the status flags are returned
645 * 657 *
646 * RETURN: Status 658 * RETURN: Status
647 * 659 *
diff --git a/drivers/acpi/utilities/utglobal.c b/drivers/acpi/utilities/utglobal.c
index 25b0f8ae1bc6..4146019b543f 100644
--- a/drivers/acpi/utilities/utglobal.c
+++ b/drivers/acpi/utilities/utglobal.c
@@ -44,7 +44,6 @@
44#define DEFINE_ACPI_GLOBALS 44#define DEFINE_ACPI_GLOBALS
45 45
46#include <linux/module.h> 46#include <linux/module.h>
47
48#include <acpi/acpi.h> 47#include <acpi/acpi.h>
49#include <acpi/acnamesp.h> 48#include <acpi/acnamesp.h>
50 49
@@ -52,13 +51,14 @@
52 ACPI_MODULE_NAME ("utglobal") 51 ACPI_MODULE_NAME ("utglobal")
53 52
54 53
55/****************************************************************************** 54/*******************************************************************************
56 * 55 *
57 * FUNCTION: acpi_format_exception 56 * FUNCTION: acpi_format_exception
58 * 57 *
59 * PARAMETERS: Status - The acpi_status code to be formatted 58 * PARAMETERS: Status - The acpi_status code to be formatted
60 * 59 *
61 * RETURN: A string containing the exception text 60 * RETURN: A string containing the exception text. A valid pointer is
61 * always returned.
62 * 62 *
63 * DESCRIPTION: This function translates an ACPI exception into an ASCII string. 63 * DESCRIPTION: This function translates an ACPI exception into an ASCII string.
64 * 64 *
@@ -68,8 +68,8 @@ const char *
68acpi_format_exception ( 68acpi_format_exception (
69 acpi_status status) 69 acpi_status status)
70{ 70{
71 const char *exception = "UNKNOWN_STATUS_CODE";
72 acpi_status sub_status; 71 acpi_status sub_status;
72 const char *exception = NULL;
73 73
74 74
75 ACPI_FUNCTION_NAME ("format_exception"); 75 ACPI_FUNCTION_NAME ("format_exception");
@@ -82,57 +82,55 @@ acpi_format_exception (
82 82
83 if (sub_status <= AE_CODE_ENV_MAX) { 83 if (sub_status <= AE_CODE_ENV_MAX) {
84 exception = acpi_gbl_exception_names_env [sub_status]; 84 exception = acpi_gbl_exception_names_env [sub_status];
85 break;
86 } 85 }
87 goto unknown; 86 break;
88 87
89 case AE_CODE_PROGRAMMER: 88 case AE_CODE_PROGRAMMER:
90 89
91 if (sub_status <= AE_CODE_PGM_MAX) { 90 if (sub_status <= AE_CODE_PGM_MAX) {
92 exception = acpi_gbl_exception_names_pgm [sub_status -1]; 91 exception = acpi_gbl_exception_names_pgm [sub_status -1];
93 break;
94 } 92 }
95 goto unknown; 93 break;
96 94
97 case AE_CODE_ACPI_TABLES: 95 case AE_CODE_ACPI_TABLES:
98 96
99 if (sub_status <= AE_CODE_TBL_MAX) { 97 if (sub_status <= AE_CODE_TBL_MAX) {
100 exception = acpi_gbl_exception_names_tbl [sub_status -1]; 98 exception = acpi_gbl_exception_names_tbl [sub_status -1];
101 break;
102 } 99 }
103 goto unknown; 100 break;
104 101
105 case AE_CODE_AML: 102 case AE_CODE_AML:
106 103
107 if (sub_status <= AE_CODE_AML_MAX) { 104 if (sub_status <= AE_CODE_AML_MAX) {
108 exception = acpi_gbl_exception_names_aml [sub_status -1]; 105 exception = acpi_gbl_exception_names_aml [sub_status -1];
109 break;
110 } 106 }
111 goto unknown; 107 break;
112 108
113 case AE_CODE_CONTROL: 109 case AE_CODE_CONTROL:
114 110
115 if (sub_status <= AE_CODE_CTRL_MAX) { 111 if (sub_status <= AE_CODE_CTRL_MAX) {
116 exception = acpi_gbl_exception_names_ctrl [sub_status -1]; 112 exception = acpi_gbl_exception_names_ctrl [sub_status -1];
117 break;
118 } 113 }
119 goto unknown; 114 break;
120 115
121 default: 116 default:
122 goto unknown; 117 break;
123 } 118 }
124 119
120 if (!exception) {
121 /* Exception code was not recognized */
125 122
126 return ((const char *) exception); 123 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
124 "Unknown exception code: 0x%8.8X\n", status));
127 125
128unknown: 126 return ((const char *) "UNKNOWN_STATUS_CODE");
127 }
129 128
130 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown exception code: 0x%8.8X\n", status));
131 return ((const char *) exception); 129 return ((const char *) exception);
132} 130}
133 131
134 132
135/****************************************************************************** 133/*******************************************************************************
136 * 134 *
137 * Static global variable initialization. 135 * Static global variable initialization.
138 * 136 *
@@ -212,13 +210,12 @@ const char *acpi_gbl_valid_osi_strings[ACPI_NUM_OSI_STR
212}; 210};
213 211
214 212
215/****************************************************************************** 213/*******************************************************************************
216 * 214 *
217 * Namespace globals 215 * Namespace globals
218 * 216 *
219 ******************************************************************************/ 217 ******************************************************************************/
220 218
221
222/* 219/*
223 * Predefined ACPI Names (Built-in to the Interpreter) 220 * Predefined ACPI Names (Built-in to the Interpreter)
224 * 221 *
@@ -241,9 +238,11 @@ const struct acpi_predefined_names acpi_gbl_pre_defined_names[] =
241#if !defined (ACPI_NO_METHOD_EXECUTION) || defined (ACPI_CONSTANT_EVAL_ONLY) 238#if !defined (ACPI_NO_METHOD_EXECUTION) || defined (ACPI_CONSTANT_EVAL_ONLY)
242 {"_OSI", ACPI_TYPE_METHOD, (char *) 1}, 239 {"_OSI", ACPI_TYPE_METHOD, (char *) 1},
243#endif 240#endif
244 {NULL, ACPI_TYPE_ANY, NULL} /* Table terminator */
245};
246 241
242 /* Table terminator */
243
244 {NULL, ACPI_TYPE_ANY, NULL}
245};
247 246
248/* 247/*
249 * Properties of the ACPI Object Types, both internal and external. 248 * Properties of the ACPI Object Types, both internal and external.
@@ -288,22 +287,25 @@ const u8 acpi_gbl_ns_properties[] =
288/* Hex to ASCII conversion table */ 287/* Hex to ASCII conversion table */
289 288
290static const char acpi_gbl_hex_to_ascii[] = 289static const char acpi_gbl_hex_to_ascii[] =
291 {'0','1','2','3','4','5','6','7', 290{
292 '8','9','A','B','C','D','E','F'}; 291 '0','1','2','3','4','5','6','7',
292 '8','9','A','B','C','D','E','F'
293};
294
293 295
294/***************************************************************************** 296/*******************************************************************************
295 * 297 *
296 * FUNCTION: acpi_ut_hex_to_ascii_char 298 * FUNCTION: acpi_ut_hex_to_ascii_char
297 * 299 *
298 * PARAMETERS: Integer - Contains the hex digit 300 * PARAMETERS: Integer - Contains the hex digit
299 * Position - bit position of the digit within the 301 * Position - bit position of the digit within the
300 * integer 302 * integer (multiple of 4)
301 * 303 *
302 * RETURN: Ascii character 304 * RETURN: The converted Ascii character
303 * 305 *
304 * DESCRIPTION: Convert a hex digit to an ascii character 306 * DESCRIPTION: Convert a hex digit to an Ascii character
305 * 307 *
306 ****************************************************************************/ 308 ******************************************************************************/
307 309
308char 310char
309acpi_ut_hex_to_ascii_char ( 311acpi_ut_hex_to_ascii_char (
@@ -315,7 +317,7 @@ acpi_ut_hex_to_ascii_char (
315} 317}
316 318
317 319
318/****************************************************************************** 320/*******************************************************************************
319 * 321 *
320 * Table name globals 322 * Table name globals
321 * 323 *
@@ -324,7 +326,7 @@ acpi_ut_hex_to_ascii_char (
324 * that are not used by the subsystem are simply ignored. 326 * that are not used by the subsystem are simply ignored.
325 * 327 *
326 * Do NOT add any table to this list that is not consumed directly by this 328 * Do NOT add any table to this list that is not consumed directly by this
327 * subsystem. 329 * subsystem (No MADT, ECDT, SBST, etc.)
328 * 330 *
329 ******************************************************************************/ 331 ******************************************************************************/
330 332
@@ -391,7 +393,7 @@ struct acpi_fixed_event_info acpi_gbl_fixed_event_info[ACPI_NUM_FIXED_EVE
391 /* ACPI_EVENT_RTC */ {ACPI_BITREG_RT_CLOCK_STATUS, ACPI_BITREG_RT_CLOCK_ENABLE, ACPI_BITMASK_RT_CLOCK_STATUS, ACPI_BITMASK_RT_CLOCK_ENABLE}, 393 /* ACPI_EVENT_RTC */ {ACPI_BITREG_RT_CLOCK_STATUS, ACPI_BITREG_RT_CLOCK_ENABLE, ACPI_BITMASK_RT_CLOCK_STATUS, ACPI_BITMASK_RT_CLOCK_ENABLE},
392}; 394};
393 395
394/***************************************************************************** 396/*******************************************************************************
395 * 397 *
396 * FUNCTION: acpi_ut_get_region_name 398 * FUNCTION: acpi_ut_get_region_name
397 * 399 *
@@ -401,7 +403,7 @@ struct acpi_fixed_event_info acpi_gbl_fixed_event_info[ACPI_NUM_FIXED_EVE
401 * 403 *
402 * DESCRIPTION: Translate a Space ID into a name string (Debug only) 404 * DESCRIPTION: Translate a Space ID into a name string (Debug only)
403 * 405 *
404 ****************************************************************************/ 406 ******************************************************************************/
405 407
406/* Region type decoding */ 408/* Region type decoding */
407 409
@@ -429,7 +431,6 @@ acpi_ut_get_region_name (
429 { 431 {
430 return ("user_defined_region"); 432 return ("user_defined_region");
431 } 433 }
432
433 else if (space_id >= ACPI_NUM_PREDEFINED_REGIONS) 434 else if (space_id >= ACPI_NUM_PREDEFINED_REGIONS)
434 { 435 {
435 return ("invalid_space_id"); 436 return ("invalid_space_id");
@@ -439,7 +440,7 @@ acpi_ut_get_region_name (
439} 440}
440 441
441 442
442/***************************************************************************** 443/*******************************************************************************
443 * 444 *
444 * FUNCTION: acpi_ut_get_event_name 445 * FUNCTION: acpi_ut_get_event_name
445 * 446 *
@@ -449,7 +450,7 @@ acpi_ut_get_region_name (
449 * 450 *
450 * DESCRIPTION: Translate a Event ID into a name string (Debug only) 451 * DESCRIPTION: Translate a Event ID into a name string (Debug only)
451 * 452 *
452 ****************************************************************************/ 453 ******************************************************************************/
453 454
454/* Event type decoding */ 455/* Event type decoding */
455 456
@@ -477,7 +478,7 @@ acpi_ut_get_event_name (
477} 478}
478 479
479 480
480/***************************************************************************** 481/*******************************************************************************
481 * 482 *
482 * FUNCTION: acpi_ut_get_type_name 483 * FUNCTION: acpi_ut_get_type_name
483 * 484 *
@@ -487,20 +488,21 @@ acpi_ut_get_event_name (
487 * 488 *
488 * DESCRIPTION: Translate a Type ID into a name string (Debug only) 489 * DESCRIPTION: Translate a Type ID into a name string (Debug only)
489 * 490 *
490 ****************************************************************************/ 491 ******************************************************************************/
491 492
492/* 493/*
493 * Elements of acpi_gbl_ns_type_names below must match 494 * Elements of acpi_gbl_ns_type_names below must match
494 * one-to-one with values of acpi_object_type 495 * one-to-one with values of acpi_object_type
495 * 496 *
496 * The type ACPI_TYPE_ANY (Untyped) is used as a "don't care" when searching; when 497 * The type ACPI_TYPE_ANY (Untyped) is used as a "don't care" when searching;
497 * stored in a table it really means that we have thus far seen no evidence to 498 * when stored in a table it really means that we have thus far seen no
498 * indicate what type is actually going to be stored for this entry. 499 * evidence to indicate what type is actually going to be stored for this entry.
499 */ 500 */
500static const char acpi_gbl_bad_type[] = "UNDEFINED"; 501static const char acpi_gbl_bad_type[] = "UNDEFINED";
501#define TYPE_NAME_LENGTH 12 /* Maximum length of each string */
502 502
503static const char *acpi_gbl_ns_type_names[] = /* printable names of ACPI types */ 503/* Printable names of the ACPI object types */
504
505static const char *acpi_gbl_ns_type_names[] =
504{ 506{
505 /* 00 */ "Untyped", 507 /* 00 */ "Untyped",
506 /* 01 */ "Integer", 508 /* 01 */ "Integer",
@@ -564,7 +566,7 @@ acpi_ut_get_object_type_name (
564} 566}
565 567
566 568
567/***************************************************************************** 569/*******************************************************************************
568 * 570 *
569 * FUNCTION: acpi_ut_get_node_name 571 * FUNCTION: acpi_ut_get_node_name
570 * 572 *
@@ -574,7 +576,7 @@ acpi_ut_get_object_type_name (
574 * 576 *
575 * DESCRIPTION: Validate the node and return the node's ACPI name. 577 * DESCRIPTION: Validate the node and return the node's ACPI name.
576 * 578 *
577 ****************************************************************************/ 579 ******************************************************************************/
578 580
579char * 581char *
580acpi_ut_get_node_name ( 582acpi_ut_get_node_name (
@@ -618,7 +620,7 @@ acpi_ut_get_node_name (
618} 620}
619 621
620 622
621/***************************************************************************** 623/*******************************************************************************
622 * 624 *
623 * FUNCTION: acpi_ut_get_descriptor_name 625 * FUNCTION: acpi_ut_get_descriptor_name
624 * 626 *
@@ -628,9 +630,11 @@ acpi_ut_get_node_name (
628 * 630 *
629 * DESCRIPTION: Validate object and return the descriptor type 631 * DESCRIPTION: Validate object and return the descriptor type
630 * 632 *
631 ****************************************************************************/ 633 ******************************************************************************/
634
635/* Printable names of object descriptor types */
632 636
633static const char *acpi_gbl_desc_type_names[] = /* printable names of descriptor types */ 637static const char *acpi_gbl_desc_type_names[] =
634{ 638{
635 /* 00 */ "Invalid", 639 /* 00 */ "Invalid",
636 /* 01 */ "Cached", 640 /* 01 */ "Cached",
@@ -676,17 +680,18 @@ acpi_ut_get_descriptor_name (
676 * Strings and procedures used for debug only 680 * Strings and procedures used for debug only
677 */ 681 */
678 682
679/***************************************************************************** 683/*******************************************************************************
680 * 684 *
681 * FUNCTION: acpi_ut_get_mutex_name 685 * FUNCTION: acpi_ut_get_mutex_name
682 * 686 *
683 * PARAMETERS: None. 687 * PARAMETERS: mutex_id - The predefined ID for this mutex.
684 * 688 *
685 * RETURN: Status 689 * RETURN: String containing the name of the mutex. Always returns a valid
690 * pointer.
686 * 691 *
687 * DESCRIPTION: Translate a mutex ID into a name string (Debug only) 692 * DESCRIPTION: Translate a mutex ID into a name string (Debug only)
688 * 693 *
689 ****************************************************************************/ 694 ******************************************************************************/
690 695
691char * 696char *
692acpi_ut_get_mutex_name ( 697acpi_ut_get_mutex_name (
@@ -700,21 +705,20 @@ acpi_ut_get_mutex_name (
700 705
701 return (acpi_gbl_mutex_names[mutex_id]); 706 return (acpi_gbl_mutex_names[mutex_id]);
702} 707}
703
704#endif 708#endif
705 709
706 710
707/***************************************************************************** 711/*******************************************************************************
708 * 712 *
709 * FUNCTION: acpi_ut_valid_object_type 713 * FUNCTION: acpi_ut_valid_object_type
710 * 714 *
711 * PARAMETERS: Type - Object type to be validated 715 * PARAMETERS: Type - Object type to be validated
712 * 716 *
713 * RETURN: TRUE if valid object type 717 * RETURN: TRUE if valid object type, FALSE otherwise
714 * 718 *
715 * DESCRIPTION: Validate an object type 719 * DESCRIPTION: Validate an object type
716 * 720 *
717 ****************************************************************************/ 721 ******************************************************************************/
718 722
719u8 723u8
720acpi_ut_valid_object_type ( 724acpi_ut_valid_object_type (
@@ -732,7 +736,7 @@ acpi_ut_valid_object_type (
732} 736}
733 737
734 738
735/**************************************************************************** 739/*******************************************************************************
736 * 740 *
737 * FUNCTION: acpi_ut_allocate_owner_id 741 * FUNCTION: acpi_ut_allocate_owner_id
738 * 742 *
@@ -740,7 +744,10 @@ acpi_ut_valid_object_type (
740 * 744 *
741 * DESCRIPTION: Allocate a table or method owner id 745 * DESCRIPTION: Allocate a table or method owner id
742 * 746 *
743 ***************************************************************************/ 747 * NOTE: this algorithm has a wraparound problem at 64_k method invocations, and
748 * should be revisited (TBD)
749 *
750 ******************************************************************************/
744 751
745acpi_owner_id 752acpi_owner_id
746acpi_ut_allocate_owner_id ( 753acpi_ut_allocate_owner_id (
@@ -796,16 +803,18 @@ acpi_ut_allocate_owner_id (
796} 803}
797 804
798 805
799/**************************************************************************** 806/*******************************************************************************
800 * 807 *
801 * FUNCTION: acpi_ut_init_globals 808 * FUNCTION: acpi_ut_init_globals
802 * 809 *
803 * PARAMETERS: none 810 * PARAMETERS: None
811 *
812 * RETURN: None
804 * 813 *
805 * DESCRIPTION: Init library globals. All globals that require specific 814 * DESCRIPTION: Init library globals. All globals that require specific
806 * initialization should be initialized here! 815 * initialization should be initialized here!
807 * 816 *
808 ***************************************************************************/ 817 ******************************************************************************/
809 818
810void 819void
811acpi_ut_init_globals ( 820acpi_ut_init_globals (
diff --git a/drivers/acpi/utilities/utinit.c b/drivers/acpi/utilities/utinit.c
index bdbadaf48d29..7f3713889ff0 100644
--- a/drivers/acpi/utilities/utinit.c
+++ b/drivers/acpi/utilities/utinit.c
@@ -49,19 +49,29 @@
49#define _COMPONENT ACPI_UTILITIES 49#define _COMPONENT ACPI_UTILITIES
50 ACPI_MODULE_NAME ("utinit") 50 ACPI_MODULE_NAME ("utinit")
51 51
52/* Local prototypes */
53
54static void
55acpi_ut_fadt_register_error (
56 char *register_name,
57 u32 value,
58 acpi_size offset);
59
60static void acpi_ut_terminate (
61 void);
62
52 63
53/******************************************************************************* 64/*******************************************************************************
54 * 65 *
55 * FUNCTION: acpi_ut_fadt_register_error 66 * FUNCTION: acpi_ut_fadt_register_error
56 * 67 *
57 * PARAMETERS: *register_name - Pointer to string identifying register 68 * PARAMETERS: register_name - Pointer to string identifying register
58 * Value - Actual register contents value 69 * Value - Actual register contents value
59 * acpi_test_spec_section - TDS section containing assertion 70 * Offset - Byte offset in the FADT
60 * acpi_assertion - Assertion number being tested
61 * 71 *
62 * RETURN: AE_BAD_VALUE 72 * RETURN: AE_BAD_VALUE
63 * 73 *
64 * DESCRIPTION: Display failure message and link failure to TDS assertion 74 * DESCRIPTION: Display failure message
65 * 75 *
66 ******************************************************************************/ 76 ******************************************************************************/
67 77
@@ -166,12 +176,13 @@ acpi_ut_validate_fadt (
166 * 176 *
167 * RETURN: none 177 * RETURN: none
168 * 178 *
169 * DESCRIPTION: free global memory 179 * DESCRIPTION: Free global memory
170 * 180 *
171 ******************************************************************************/ 181 ******************************************************************************/
172 182
173void 183static void
174acpi_ut_terminate (void) 184acpi_ut_terminate (
185 void)
175{ 186{
176 struct acpi_gpe_block_info *gpe_block; 187 struct acpi_gpe_block_info *gpe_block;
177 struct acpi_gpe_block_info *next_gpe_block; 188 struct acpi_gpe_block_info *next_gpe_block;
@@ -183,8 +194,6 @@ acpi_ut_terminate (void)
183 194
184 195
185 /* Free global tables, etc. */ 196 /* Free global tables, etc. */
186
187
188 /* Free global GPE blocks and related info structures */ 197 /* Free global GPE blocks and related info structures */
189 198
190 gpe_xrupt_info = acpi_gbl_gpe_xrupt_list_head; 199 gpe_xrupt_info = acpi_gbl_gpe_xrupt_list_head;
@@ -221,7 +230,8 @@ acpi_ut_terminate (void)
221 ******************************************************************************/ 230 ******************************************************************************/
222 231
223void 232void
224acpi_ut_subsystem_shutdown (void) 233acpi_ut_subsystem_shutdown (
234 void)
225{ 235{
226 236
227 ACPI_FUNCTION_TRACE ("ut_subsystem_shutdown"); 237 ACPI_FUNCTION_TRACE ("ut_subsystem_shutdown");
@@ -229,14 +239,16 @@ acpi_ut_subsystem_shutdown (void)
229 /* Just exit if subsystem is already shutdown */ 239 /* Just exit if subsystem is already shutdown */
230 240
231 if (acpi_gbl_shutdown) { 241 if (acpi_gbl_shutdown) {
232 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "ACPI Subsystem is already terminated\n")); 242 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
243 "ACPI Subsystem is already terminated\n"));
233 return_VOID; 244 return_VOID;
234 } 245 }
235 246
236 /* Subsystem appears active, go ahead and shut it down */ 247 /* Subsystem appears active, go ahead and shut it down */
237 248
238 acpi_gbl_shutdown = TRUE; 249 acpi_gbl_shutdown = TRUE;
239 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Shutting down ACPI Subsystem...\n")); 250 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
251 "Shutting down ACPI Subsystem...\n"));
240 252
241 /* Close the acpi_event Handling */ 253 /* Close the acpi_event Handling */
242 254
diff --git a/drivers/acpi/utilities/utmath.c b/drivers/acpi/utilities/utmath.c
index 2525c1a93547..0d527c91543c 100644
--- a/drivers/acpi/utilities/utmath.c
+++ b/drivers/acpi/utilities/utmath.c
@@ -259,6 +259,8 @@ acpi_ut_divide (
259 * 259 *
260 * FUNCTION: acpi_ut_short_divide, acpi_ut_divide 260 * FUNCTION: acpi_ut_short_divide, acpi_ut_divide
261 * 261 *
262 * PARAMETERS: See function headers above
263 *
262 * DESCRIPTION: Native versions of the ut_divide functions. Use these if either 264 * DESCRIPTION: Native versions of the ut_divide functions. Use these if either
263 * 1) The target is a 64-bit platform and therefore 64-bit 265 * 1) The target is a 64-bit platform and therefore 64-bit
264 * integer math is supported directly by the machine. 266 * integer math is supported directly by the machine.
diff --git a/drivers/acpi/utilities/utmisc.c b/drivers/acpi/utilities/utmisc.c
index f6598547389b..f6de4ed3d527 100644
--- a/drivers/acpi/utilities/utmisc.c
+++ b/drivers/acpi/utilities/utmisc.c
@@ -49,12 +49,57 @@
49#define _COMPONENT ACPI_UTILITIES 49#define _COMPONENT ACPI_UTILITIES
50 ACPI_MODULE_NAME ("utmisc") 50 ACPI_MODULE_NAME ("utmisc")
51 51
52/* Local prototypes */
53
54static acpi_status
55acpi_ut_create_mutex (
56 acpi_mutex_handle mutex_id);
57
58static acpi_status
59acpi_ut_delete_mutex (
60 acpi_mutex_handle mutex_id);
61
62
63/*******************************************************************************
64 *
65 * FUNCTION: acpi_ut_strupr (strupr)
66 *
67 * PARAMETERS: src_string - The source string to convert
68 *
69 * RETURN: Converted src_string (same as input pointer)
70 *
71 * DESCRIPTION: Convert string to uppercase
72 *
73 * NOTE: This is not a POSIX function, so it appears here, not in utclib.c
74 *
75 ******************************************************************************/
76
77char *
78acpi_ut_strupr (
79 char *src_string)
80{
81 char *string;
82
83
84 ACPI_FUNCTION_ENTRY ();
85
86
87 /* Walk entire string, uppercasing the letters */
88
89 for (string = src_string; *string; string++) {
90 *string = (char) ACPI_TOUPPER (*string);
91 }
92
93 return (src_string);
94}
95
52 96
53/******************************************************************************* 97/*******************************************************************************
54 * 98 *
55 * FUNCTION: acpi_ut_print_string 99 * FUNCTION: acpi_ut_print_string
56 * 100 *
57 * PARAMETERS: String - Null terminated ASCII string 101 * PARAMETERS: String - Null terminated ASCII string
102 * max_length - Maximum output length
58 * 103 *
59 * RETURN: None 104 * RETURN: None
60 * 105 *
@@ -148,6 +193,8 @@ acpi_ut_print_string (
148 * 193 *
149 * PARAMETERS: Value - Value to be converted 194 * PARAMETERS: Value - Value to be converted
150 * 195 *
196 * RETURN: u32 integer with bytes swapped
197 *
151 * DESCRIPTION: Convert a 32-bit value to big-endian (swap the bytes) 198 * DESCRIPTION: Convert a 32-bit value to big-endian (swap the bytes)
152 * 199 *
153 ******************************************************************************/ 200 ******************************************************************************/
@@ -160,7 +207,6 @@ acpi_ut_dword_byte_swap (
160 u32 value; 207 u32 value;
161 u8 bytes[4]; 208 u8 bytes[4];
162 } out; 209 } out;
163
164 union { 210 union {
165 u32 value; 211 u32 value;
166 u8 bytes[4]; 212 u8 bytes[4];
@@ -219,7 +265,8 @@ acpi_ut_set_integer_width (
219 * 265 *
220 * FUNCTION: acpi_ut_display_init_pathname 266 * FUNCTION: acpi_ut_display_init_pathname
221 * 267 *
222 * PARAMETERS: obj_handle - Handle whose pathname will be displayed 268 * PARAMETERS: Type - Object type of the node
269 * obj_handle - Handle whose pathname will be displayed
223 * Path - Additional path string to be appended. 270 * Path - Additional path string to be appended.
224 * (NULL if no extra path) 271 * (NULL if no extra path)
225 * 272 *
@@ -270,7 +317,8 @@ acpi_ut_display_init_pathname (
270 317
271 /* Print the object type and pathname */ 318 /* Print the object type and pathname */
272 319
273 acpi_os_printf ("%-12s %s", acpi_ut_get_type_name (type), (char *) buffer.pointer); 320 acpi_os_printf ("%-12s %s",
321 acpi_ut_get_type_name (type), (char *) buffer.pointer);
274 322
275 /* Extra path is used to append names like _STA, _INI, etc. */ 323 /* Extra path is used to append names like _STA, _INI, etc. */
276 324
@@ -288,9 +336,9 @@ acpi_ut_display_init_pathname (
288 * 336 *
289 * FUNCTION: acpi_ut_valid_acpi_name 337 * FUNCTION: acpi_ut_valid_acpi_name
290 * 338 *
291 * PARAMETERS: Character - The character to be examined 339 * PARAMETERS: Name - The name to be examined
292 * 340 *
293 * RETURN: 1 if Character may appear in a name, else 0 341 * RETURN: TRUE if the name is valid, FALSE otherwise
294 * 342 *
295 * DESCRIPTION: Check for a valid ACPI name. Each character must be one of: 343 * DESCRIPTION: Check for a valid ACPI name. Each character must be one of:
296 * 1) Upper case alpha 344 * 1) Upper case alpha
@@ -495,40 +543,6 @@ error_exit:
495 543
496/******************************************************************************* 544/*******************************************************************************
497 * 545 *
498 * FUNCTION: acpi_ut_strupr
499 *
500 * PARAMETERS: src_string - The source string to convert to
501 *
502 * RETURN: src_string
503 *
504 * DESCRIPTION: Convert string to uppercase
505 *
506 ******************************************************************************/
507#ifdef ACPI_FUTURE_USAGE
508char *
509acpi_ut_strupr (
510 char *src_string)
511{
512 char *string;
513
514
515 ACPI_FUNCTION_ENTRY ();
516
517
518 /* Walk entire string, uppercasing the letters */
519
520 for (string = src_string; *string; ) {
521 *string = (char) ACPI_TOUPPER (*string);
522 string++;
523 }
524
525 return (src_string);
526}
527#endif /* ACPI_FUTURE_USAGE */
528
529
530/*******************************************************************************
531 *
532 * FUNCTION: acpi_ut_mutex_initialize 546 * FUNCTION: acpi_ut_mutex_initialize
533 * 547 *
534 * PARAMETERS: None. 548 * PARAMETERS: None.
@@ -611,7 +625,7 @@ acpi_ut_mutex_terminate (
611 * 625 *
612 ******************************************************************************/ 626 ******************************************************************************/
613 627
614acpi_status 628static acpi_status
615acpi_ut_create_mutex ( 629acpi_ut_create_mutex (
616 acpi_mutex_handle mutex_id) 630 acpi_mutex_handle mutex_id)
617{ 631{
@@ -648,7 +662,7 @@ acpi_ut_create_mutex (
648 * 662 *
649 ******************************************************************************/ 663 ******************************************************************************/
650 664
651acpi_status 665static acpi_status
652acpi_ut_delete_mutex ( 666acpi_ut_delete_mutex (
653 acpi_mutex_handle mutex_id) 667 acpi_mutex_handle mutex_id)
654{ 668{
@@ -715,16 +729,16 @@ acpi_ut_acquire_mutex (
715 if (acpi_gbl_mutex_info[i].owner_id == this_thread_id) { 729 if (acpi_gbl_mutex_info[i].owner_id == this_thread_id) {
716 if (i == mutex_id) { 730 if (i == mutex_id) {
717 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 731 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
718 "Mutex [%s] already acquired by this thread [%X]\n", 732 "Mutex [%s] already acquired by this thread [%X]\n",
719 acpi_ut_get_mutex_name (mutex_id), this_thread_id)); 733 acpi_ut_get_mutex_name (mutex_id), this_thread_id));
720 734
721 return (AE_ALREADY_ACQUIRED); 735 return (AE_ALREADY_ACQUIRED);
722 } 736 }
723 737
724 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 738 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
725 "Invalid acquire order: Thread %X owns [%s], wants [%s]\n", 739 "Invalid acquire order: Thread %X owns [%s], wants [%s]\n",
726 this_thread_id, acpi_ut_get_mutex_name (i), 740 this_thread_id, acpi_ut_get_mutex_name (i),
727 acpi_ut_get_mutex_name (mutex_id))); 741 acpi_ut_get_mutex_name (mutex_id)));
728 742
729 return (AE_ACQUIRE_DEADLOCK); 743 return (AE_ACQUIRE_DEADLOCK);
730 } 744 }
@@ -733,22 +747,23 @@ acpi_ut_acquire_mutex (
733#endif 747#endif
734 748
735 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, 749 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX,
736 "Thread %X attempting to acquire Mutex [%s]\n", 750 "Thread %X attempting to acquire Mutex [%s]\n",
737 this_thread_id, acpi_ut_get_mutex_name (mutex_id))); 751 this_thread_id, acpi_ut_get_mutex_name (mutex_id)));
738 752
739 status = acpi_os_wait_semaphore (acpi_gbl_mutex_info[mutex_id].mutex, 753 status = acpi_os_wait_semaphore (acpi_gbl_mutex_info[mutex_id].mutex,
740 1, ACPI_WAIT_FOREVER); 754 1, ACPI_WAIT_FOREVER);
741 if (ACPI_SUCCESS (status)) { 755 if (ACPI_SUCCESS (status)) {
742 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %X acquired Mutex [%s]\n", 756 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %X acquired Mutex [%s]\n",
743 this_thread_id, acpi_ut_get_mutex_name (mutex_id))); 757 this_thread_id, acpi_ut_get_mutex_name (mutex_id)));
744 758
745 acpi_gbl_mutex_info[mutex_id].use_count++; 759 acpi_gbl_mutex_info[mutex_id].use_count++;
746 acpi_gbl_mutex_info[mutex_id].owner_id = this_thread_id; 760 acpi_gbl_mutex_info[mutex_id].owner_id = this_thread_id;
747 } 761 }
748 else { 762 else {
749 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Thread %X could not acquire Mutex [%s] %s\n", 763 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
750 this_thread_id, acpi_ut_get_mutex_name (mutex_id), 764 "Thread %X could not acquire Mutex [%s] %s\n",
751 acpi_format_exception (status))); 765 this_thread_id, acpi_ut_get_mutex_name (mutex_id),
766 acpi_format_exception (status)));
752 } 767 }
753 768
754 return (status); 769 return (status);
@@ -793,8 +808,8 @@ acpi_ut_release_mutex (
793 */ 808 */
794 if (acpi_gbl_mutex_info[mutex_id].owner_id == ACPI_MUTEX_NOT_ACQUIRED) { 809 if (acpi_gbl_mutex_info[mutex_id].owner_id == ACPI_MUTEX_NOT_ACQUIRED) {
795 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 810 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
796 "Mutex [%s] is not acquired, cannot release\n", 811 "Mutex [%s] is not acquired, cannot release\n",
797 acpi_ut_get_mutex_name (mutex_id))); 812 acpi_ut_get_mutex_name (mutex_id)));
798 813
799 return (AE_NOT_ACQUIRED); 814 return (AE_NOT_ACQUIRED);
800 } 815 }
@@ -812,8 +827,8 @@ acpi_ut_release_mutex (
812 } 827 }
813 828
814 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 829 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
815 "Invalid release order: owns [%s], releasing [%s]\n", 830 "Invalid release order: owns [%s], releasing [%s]\n",
816 acpi_ut_get_mutex_name (i), acpi_ut_get_mutex_name (mutex_id))); 831 acpi_ut_get_mutex_name (i), acpi_ut_get_mutex_name (mutex_id)));
817 832
818 return (AE_RELEASE_DEADLOCK); 833 return (AE_RELEASE_DEADLOCK);
819 } 834 }
@@ -826,13 +841,14 @@ acpi_ut_release_mutex (
826 status = acpi_os_signal_semaphore (acpi_gbl_mutex_info[mutex_id].mutex, 1); 841 status = acpi_os_signal_semaphore (acpi_gbl_mutex_info[mutex_id].mutex, 1);
827 842
828 if (ACPI_FAILURE (status)) { 843 if (ACPI_FAILURE (status)) {
829 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Thread %X could not release Mutex [%s] %s\n", 844 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
830 this_thread_id, acpi_ut_get_mutex_name (mutex_id), 845 "Thread %X could not release Mutex [%s] %s\n",
831 acpi_format_exception (status))); 846 this_thread_id, acpi_ut_get_mutex_name (mutex_id),
847 acpi_format_exception (status)));
832 } 848 }
833 else { 849 else {
834 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %X released Mutex [%s]\n", 850 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %X released Mutex [%s]\n",
835 this_thread_id, acpi_ut_get_mutex_name (mutex_id))); 851 this_thread_id, acpi_ut_get_mutex_name (mutex_id)));
836 } 852 }
837 853
838 return (status); 854 return (status);
@@ -843,11 +859,11 @@ acpi_ut_release_mutex (
843 * 859 *
844 * FUNCTION: acpi_ut_create_update_state_and_push 860 * FUNCTION: acpi_ut_create_update_state_and_push
845 * 861 *
846 * PARAMETERS: *Object - Object to be added to the new state 862 * PARAMETERS: Object - Object to be added to the new state
847 * Action - Increment/Decrement 863 * Action - Increment/Decrement
848 * state_list - List the state will be added to 864 * state_list - List the state will be added to
849 * 865 *
850 * RETURN: None 866 * RETURN: Status
851 * 867 *
852 * DESCRIPTION: Create a new state and push it 868 * DESCRIPTION: Create a new state and push it
853 * 869 *
@@ -885,15 +901,16 @@ acpi_ut_create_update_state_and_push (
885 * 901 *
886 * FUNCTION: acpi_ut_create_pkg_state_and_push 902 * FUNCTION: acpi_ut_create_pkg_state_and_push
887 * 903 *
888 * PARAMETERS: *Object - Object to be added to the new state 904 * PARAMETERS: Object - Object to be added to the new state
889 * Action - Increment/Decrement 905 * Action - Increment/Decrement
890 * state_list - List the state will be added to 906 * state_list - List the state will be added to
891 * 907 *
892 * RETURN: None 908 * RETURN: Status
893 * 909 *
894 * DESCRIPTION: Create a new state and push it 910 * DESCRIPTION: Create a new state and push it
895 * 911 *
896 ******************************************************************************/ 912 ******************************************************************************/
913
897#ifdef ACPI_FUTURE_USAGE 914#ifdef ACPI_FUTURE_USAGE
898acpi_status 915acpi_status
899acpi_ut_create_pkg_state_and_push ( 916acpi_ut_create_pkg_state_and_push (
@@ -925,7 +942,7 @@ acpi_ut_create_pkg_state_and_push (
925 * PARAMETERS: list_head - Head of the state stack 942 * PARAMETERS: list_head - Head of the state stack
926 * State - State object to push 943 * State - State object to push
927 * 944 *
928 * RETURN: Status 945 * RETURN: None
929 * 946 *
930 * DESCRIPTION: Push a state object onto a state stack 947 * DESCRIPTION: Push a state object onto a state stack
931 * 948 *
@@ -954,7 +971,7 @@ acpi_ut_push_generic_state (
954 * 971 *
955 * PARAMETERS: list_head - Head of the state stack 972 * PARAMETERS: list_head - Head of the state stack
956 * 973 *
957 * RETURN: Status 974 * RETURN: The popped state object
958 * 975 *
959 * DESCRIPTION: Pop a state object from a state stack 976 * DESCRIPTION: Pop a state object from a state stack
960 * 977 *
@@ -989,7 +1006,7 @@ acpi_ut_pop_generic_state (
989 * 1006 *
990 * PARAMETERS: None 1007 * PARAMETERS: None
991 * 1008 *
992 * RETURN: Status 1009 * RETURN: The new state object. NULL on failure.
993 * 1010 *
994 * DESCRIPTION: Create a generic state object. Attempt to obtain one from 1011 * DESCRIPTION: Create a generic state object. Attempt to obtain one from
995 * the global state cache; If none available, create a new one. 1012 * the global state cache; If none available, create a new one.
@@ -997,7 +1014,8 @@ acpi_ut_pop_generic_state (
997 ******************************************************************************/ 1014 ******************************************************************************/
998 1015
999union acpi_generic_state * 1016union acpi_generic_state *
1000acpi_ut_create_generic_state (void) 1017acpi_ut_create_generic_state (
1018 void)
1001{ 1019{
1002 union acpi_generic_state *state; 1020 union acpi_generic_state *state;
1003 1021
@@ -1023,7 +1041,7 @@ acpi_ut_create_generic_state (void)
1023 * 1041 *
1024 * PARAMETERS: None 1042 * PARAMETERS: None
1025 * 1043 *
1026 * RETURN: Thread State 1044 * RETURN: New Thread State. NULL on failure
1027 * 1045 *
1028 * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used 1046 * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used
1029 * to track per-thread info during method execution 1047 * to track per-thread info during method execution
@@ -1060,11 +1078,10 @@ acpi_ut_create_thread_state (
1060 * 1078 *
1061 * FUNCTION: acpi_ut_create_update_state 1079 * FUNCTION: acpi_ut_create_update_state
1062 * 1080 *
1063 * PARAMETERS: Object - Initial Object to be installed in the 1081 * PARAMETERS: Object - Initial Object to be installed in the state
1064 * state 1082 * Action - Update action to be performed
1065 * Action - Update action to be performed
1066 * 1083 *
1067 * RETURN: Status 1084 * RETURN: New state object, null on failure
1068 * 1085 *
1069 * DESCRIPTION: Create an "Update State" - a flavor of the generic state used 1086 * DESCRIPTION: Create an "Update State" - a flavor of the generic state used
1070 * to update reference counts and delete complex objects such 1087 * to update reference counts and delete complex objects such
@@ -1104,11 +1121,10 @@ acpi_ut_create_update_state (
1104 * 1121 *
1105 * FUNCTION: acpi_ut_create_pkg_state 1122 * FUNCTION: acpi_ut_create_pkg_state
1106 * 1123 *
1107 * PARAMETERS: Object - Initial Object to be installed in the 1124 * PARAMETERS: Object - Initial Object to be installed in the state
1108 * state 1125 * Action - Update action to be performed
1109 * Action - Update action to be performed
1110 * 1126 *
1111 * RETURN: Status 1127 * RETURN: New state object, null on failure
1112 * 1128 *
1113 * DESCRIPTION: Create a "Package State" 1129 * DESCRIPTION: Create a "Package State"
1114 * 1130 *
@@ -1151,7 +1167,7 @@ acpi_ut_create_pkg_state (
1151 * 1167 *
1152 * PARAMETERS: None 1168 * PARAMETERS: None
1153 * 1169 *
1154 * RETURN: Status 1170 * RETURN: New state object, null on failure
1155 * 1171 *
1156 * DESCRIPTION: Create a "Control State" - a flavor of the generic state used 1172 * DESCRIPTION: Create a "Control State" - a flavor of the generic state used
1157 * to support nested IF/WHILE constructs in the AML. 1173 * to support nested IF/WHILE constructs in the AML.
@@ -1190,7 +1206,7 @@ acpi_ut_create_control_state (
1190 * 1206 *
1191 * PARAMETERS: State - The state object to be deleted 1207 * PARAMETERS: State - The state object to be deleted
1192 * 1208 *
1193 * RETURN: Status 1209 * RETURN: None
1194 * 1210 *
1195 * DESCRIPTION: Put a state object back into the global state cache. The object 1211 * DESCRIPTION: Put a state object back into the global state cache. The object
1196 * is not actually freed at this time. 1212 * is not actually freed at this time.
@@ -1216,7 +1232,7 @@ acpi_ut_delete_generic_state (
1216 * 1232 *
1217 * PARAMETERS: None 1233 * PARAMETERS: None
1218 * 1234 *
1219 * RETURN: Status 1235 * RETURN: None
1220 * 1236 *
1221 * DESCRIPTION: Purge the global state object cache. Used during subsystem 1237 * DESCRIPTION: Purge the global state object cache. Used during subsystem
1222 * termination. 1238 * termination.
@@ -1240,7 +1256,10 @@ acpi_ut_delete_generic_state_cache (
1240 * 1256 *
1241 * FUNCTION: acpi_ut_walk_package_tree 1257 * FUNCTION: acpi_ut_walk_package_tree
1242 * 1258 *
1243 * PARAMETERS: obj_desc - The Package object on which to resolve refs 1259 * PARAMETERS: source_object - The package to walk
1260 * target_object - Target object (if package is being copied)
1261 * walk_callback - Called once for each package element
1262 * Context - Passed to the callback function
1244 * 1263 *
1245 * RETURN: Status 1264 * RETURN: Status
1246 * 1265 *
@@ -1359,7 +1378,7 @@ acpi_ut_walk_package_tree (
1359 * PARAMETERS: Buffer - Buffer to be scanned 1378 * PARAMETERS: Buffer - Buffer to be scanned
1360 * Length - number of bytes to examine 1379 * Length - number of bytes to examine
1361 * 1380 *
1362 * RETURN: checksum 1381 * RETURN: The generated checksum
1363 * 1382 *
1364 * DESCRIPTION: Generate a checksum on a raw buffer 1383 * DESCRIPTION: Generate a checksum on a raw buffer
1365 * 1384 *
@@ -1442,7 +1461,6 @@ acpi_ut_get_resource_end_tag (
1442 * PARAMETERS: module_name - Caller's module name (for error output) 1461 * PARAMETERS: module_name - Caller's module name (for error output)
1443 * line_number - Caller's line number (for error output) 1462 * line_number - Caller's line number (for error output)
1444 * component_id - Caller's component ID (for error output) 1463 * component_id - Caller's component ID (for error output)
1445 * Message - Error message to use on failure
1446 * 1464 *
1447 * RETURN: None 1465 * RETURN: None
1448 * 1466 *
@@ -1457,7 +1475,6 @@ acpi_ut_report_error (
1457 u32 component_id) 1475 u32 component_id)
1458{ 1476{
1459 1477
1460
1461 acpi_os_printf ("%8s-%04d: *** Error: ", module_name, line_number); 1478 acpi_os_printf ("%8s-%04d: *** Error: ", module_name, line_number);
1462} 1479}
1463 1480
@@ -1469,7 +1486,6 @@ acpi_ut_report_error (
1469 * PARAMETERS: module_name - Caller's module name (for error output) 1486 * PARAMETERS: module_name - Caller's module name (for error output)
1470 * line_number - Caller's line number (for error output) 1487 * line_number - Caller's line number (for error output)
1471 * component_id - Caller's component ID (for error output) 1488 * component_id - Caller's component ID (for error output)
1472 * Message - Error message to use on failure
1473 * 1489 *
1474 * RETURN: None 1490 * RETURN: None
1475 * 1491 *
@@ -1495,7 +1511,6 @@ acpi_ut_report_warning (
1495 * PARAMETERS: module_name - Caller's module name (for error output) 1511 * PARAMETERS: module_name - Caller's module name (for error output)
1496 * line_number - Caller's line number (for error output) 1512 * line_number - Caller's line number (for error output)
1497 * component_id - Caller's component ID (for error output) 1513 * component_id - Caller's component ID (for error output)
1498 * Message - Error message to use on failure
1499 * 1514 *
1500 * RETURN: None 1515 * RETURN: None
1501 * 1516 *
diff --git a/drivers/acpi/utilities/utobject.c b/drivers/acpi/utilities/utobject.c
index 9ee40a484e07..cd3899b9cc5a 100644
--- a/drivers/acpi/utilities/utobject.c
+++ b/drivers/acpi/utilities/utobject.c
@@ -50,6 +50,25 @@
50#define _COMPONENT ACPI_UTILITIES 50#define _COMPONENT ACPI_UTILITIES
51 ACPI_MODULE_NAME ("utobject") 51 ACPI_MODULE_NAME ("utobject")
52 52
53/* Local prototypes */
54
55static acpi_status
56acpi_ut_get_simple_object_size (
57 union acpi_operand_object *obj,
58 acpi_size *obj_length);
59
60static acpi_status
61acpi_ut_get_package_object_size (
62 union acpi_operand_object *obj,
63 acpi_size *obj_length);
64
65static acpi_status
66acpi_ut_get_element_length (
67 u8 object_type,
68 union acpi_operand_object *source_object,
69 union acpi_generic_state *state,
70 void *context);
71
53 72
54/******************************************************************************* 73/*******************************************************************************
55 * 74 *
@@ -60,7 +79,7 @@
60 * component_id - Component type of caller 79 * component_id - Component type of caller
61 * Type - ACPI Type of the new object 80 * Type - ACPI Type of the new object
62 * 81 *
63 * RETURN: Object - The new object. Null on failure 82 * RETURN: A new internal object, null on failure
64 * 83 *
65 * DESCRIPTION: Create and initialize a new internal object. 84 * DESCRIPTION: Create and initialize a new internal object.
66 * 85 *
@@ -83,7 +102,8 @@ acpi_ut_create_internal_object_dbg (
83 union acpi_operand_object *second_object; 102 union acpi_operand_object *second_object;
84 103
85 104
86 ACPI_FUNCTION_TRACE_STR ("ut_create_internal_object_dbg", acpi_ut_get_type_name (type)); 105 ACPI_FUNCTION_TRACE_STR ("ut_create_internal_object_dbg",
106 acpi_ut_get_type_name (type));
87 107
88 108
89 /* Allocate the raw object descriptor */ 109 /* Allocate the raw object descriptor */
@@ -99,7 +119,8 @@ acpi_ut_create_internal_object_dbg (
99 119
100 /* These types require a secondary object */ 120 /* These types require a secondary object */
101 121
102 second_object = acpi_ut_allocate_object_desc_dbg (module_name, line_number, component_id); 122 second_object = acpi_ut_allocate_object_desc_dbg (module_name,
123 line_number, component_id);
103 if (!second_object) { 124 if (!second_object) {
104 acpi_ut_delete_object_desc (object); 125 acpi_ut_delete_object_desc (object);
105 return_PTR (NULL); 126 return_PTR (NULL);
@@ -138,7 +159,7 @@ acpi_ut_create_internal_object_dbg (
138 * 159 *
139 * PARAMETERS: buffer_size - Size of buffer to be created 160 * PARAMETERS: buffer_size - Size of buffer to be created
140 * 161 *
141 * RETURN: Pointer to a new Buffer object 162 * RETURN: Pointer to a new Buffer object, null on failure
142 * 163 *
143 * DESCRIPTION: Create a fully initialized buffer object 164 * DESCRIPTION: Create a fully initialized buffer object
144 * 165 *
@@ -192,9 +213,9 @@ acpi_ut_create_buffer_object (
192 * 213 *
193 * FUNCTION: acpi_ut_create_string_object 214 * FUNCTION: acpi_ut_create_string_object
194 * 215 *
195 * PARAMETERS: string_size - Size of string to be created. Does not 216 * PARAMETERS: string_size - Size of string to be created. Does not
196 * include NULL terminator, this is added 217 * include NULL terminator, this is added
197 * automatically. 218 * automatically.
198 * 219 *
199 * RETURN: Pointer to a new String object 220 * RETURN: Pointer to a new String object
200 * 221 *
@@ -249,7 +270,9 @@ acpi_ut_create_string_object (
249 * 270 *
250 * PARAMETERS: Object - Object to be validated 271 * PARAMETERS: Object - Object to be validated
251 * 272 *
252 * RETURN: Validate a pointer to be an union acpi_operand_object 273 * RETURN: TRUE if object is valid, FALSE otherwise
274 *
275 * DESCRIPTION: Validate a pointer to be an union acpi_operand_object
253 * 276 *
254 ******************************************************************************/ 277 ******************************************************************************/
255 278
@@ -399,8 +422,8 @@ acpi_ut_delete_object_cache (
399 * 422 *
400 * FUNCTION: acpi_ut_get_simple_object_size 423 * FUNCTION: acpi_ut_get_simple_object_size
401 * 424 *
402 * PARAMETERS: *internal_object - Pointer to the object we are examining 425 * PARAMETERS: internal_object - An ACPI operand object
403 * *obj_length - Where the length is returned 426 * obj_length - Where the length is returned
404 * 427 *
405 * RETURN: Status 428 * RETURN: Status
406 * 429 *
@@ -412,7 +435,7 @@ acpi_ut_delete_object_cache (
412 * 435 *
413 ******************************************************************************/ 436 ******************************************************************************/
414 437
415acpi_status 438static acpi_status
416acpi_ut_get_simple_object_size ( 439acpi_ut_get_simple_object_size (
417 union acpi_operand_object *internal_object, 440 union acpi_operand_object *internal_object,
418 acpi_size *obj_length) 441 acpi_size *obj_length)
@@ -424,8 +447,10 @@ acpi_ut_get_simple_object_size (
424 ACPI_FUNCTION_TRACE_PTR ("ut_get_simple_object_size", internal_object); 447 ACPI_FUNCTION_TRACE_PTR ("ut_get_simple_object_size", internal_object);
425 448
426 449
427 /* Handle a null object (Could be a uninitialized package element -- which is legal) */ 450 /*
428 451 * Handle a null object (Could be a uninitialized package
452 * element -- which is legal)
453 */
429 if (!internal_object) { 454 if (!internal_object) {
430 *obj_length = 0; 455 *obj_length = 0;
431 return_ACPI_STATUS (AE_OK); 456 return_ACPI_STATUS (AE_OK);
@@ -480,7 +505,8 @@ acpi_ut_get_simple_object_size (
480 * Get the actual length of the full pathname to this object. 505 * Get the actual length of the full pathname to this object.
481 * The reference will be converted to the pathname to the object 506 * The reference will be converted to the pathname to the object
482 */ 507 */
483 length += ACPI_ROUND_UP_TO_NATIVE_WORD (acpi_ns_get_pathname_length (internal_object->reference.node)); 508 length += ACPI_ROUND_UP_TO_NATIVE_WORD (
509 acpi_ns_get_pathname_length (internal_object->reference.node));
484 break; 510 break;
485 511
486 default: 512 default:
@@ -530,7 +556,7 @@ acpi_ut_get_simple_object_size (
530 * 556 *
531 ******************************************************************************/ 557 ******************************************************************************/
532 558
533acpi_status 559static acpi_status
534acpi_ut_get_element_length ( 560acpi_ut_get_element_length (
535 u8 object_type, 561 u8 object_type,
536 union acpi_operand_object *source_object, 562 union acpi_operand_object *source_object,
@@ -582,8 +608,8 @@ acpi_ut_get_element_length (
582 * 608 *
583 * FUNCTION: acpi_ut_get_package_object_size 609 * FUNCTION: acpi_ut_get_package_object_size
584 * 610 *
585 * PARAMETERS: *internal_object - Pointer to the object we are examining 611 * PARAMETERS: internal_object - An ACPI internal object
586 * *obj_length - Where the length is returned 612 * obj_length - Where the length is returned
587 * 613 *
588 * RETURN: Status 614 * RETURN: Status
589 * 615 *
@@ -595,7 +621,7 @@ acpi_ut_get_element_length (
595 * 621 *
596 ******************************************************************************/ 622 ******************************************************************************/
597 623
598acpi_status 624static acpi_status
599acpi_ut_get_package_object_size ( 625acpi_ut_get_package_object_size (
600 union acpi_operand_object *internal_object, 626 union acpi_operand_object *internal_object,
601 acpi_size *obj_length) 627 acpi_size *obj_length)
@@ -636,8 +662,8 @@ acpi_ut_get_package_object_size (
636 * 662 *
637 * FUNCTION: acpi_ut_get_object_size 663 * FUNCTION: acpi_ut_get_object_size
638 * 664 *
639 * PARAMETERS: *internal_object - Pointer to the object we are examining 665 * PARAMETERS: internal_object - An ACPI internal object
640 * *obj_length - Where the length will be returned 666 * obj_length - Where the length will be returned
641 * 667 *
642 * RETURN: Status 668 * RETURN: Status
643 * 669 *
@@ -647,7 +673,7 @@ acpi_ut_get_package_object_size (
647 ******************************************************************************/ 673 ******************************************************************************/
648 674
649acpi_status 675acpi_status
650acpi_ut_get_object_size( 676acpi_ut_get_object_size (
651 union acpi_operand_object *internal_object, 677 union acpi_operand_object *internal_object,
652 acpi_size *obj_length) 678 acpi_size *obj_length)
653{ 679{
diff --git a/drivers/acpi/utilities/utxface.c b/drivers/acpi/utilities/utxface.c
index 97a91f3f06f0..e8803d810656 100644
--- a/drivers/acpi/utilities/utxface.c
+++ b/drivers/acpi/utilities/utxface.c
@@ -73,6 +73,7 @@ acpi_initialize_subsystem (
73{ 73{
74 acpi_status status; 74 acpi_status status;
75 75
76
76 ACPI_FUNCTION_TRACE ("acpi_initialize_subsystem"); 77 ACPI_FUNCTION_TRACE ("acpi_initialize_subsystem");
77 78
78 79
@@ -105,7 +106,6 @@ acpi_initialize_subsystem (
105 * Initialize the namespace manager and 106 * Initialize the namespace manager and
106 * the root of the namespace tree 107 * the root of the namespace tree
107 */ 108 */
108
109 status = acpi_ns_root_initialize (); 109 status = acpi_ns_root_initialize ();
110 if (ACPI_FAILURE (status)) { 110 if (ACPI_FAILURE (status)) {
111 ACPI_REPORT_ERROR (("Namespace initialization failure, %s\n", 111 ACPI_REPORT_ERROR (("Namespace initialization failure, %s\n",
@@ -113,7 +113,6 @@ acpi_initialize_subsystem (
113 return_ACPI_STATUS (status); 113 return_ACPI_STATUS (status);
114 } 114 }
115 115
116
117 /* If configured, initialize the AML debugger */ 116 /* If configured, initialize the AML debugger */
118 117
119 ACPI_DEBUGGER_EXEC (status = acpi_db_initialize ()); 118 ACPI_DEBUGGER_EXEC (status = acpi_db_initialize ());
@@ -150,7 +149,8 @@ acpi_enable_subsystem (
150 * The values from the FADT are validated here. 149 * The values from the FADT are validated here.
151 */ 150 */
152 if (!(flags & ACPI_NO_HARDWARE_INIT)) { 151 if (!(flags & ACPI_NO_HARDWARE_INIT)) {
153 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[Init] Initializing ACPI hardware\n")); 152 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
153 "[Init] Initializing ACPI hardware\n"));
154 154
155 status = acpi_hw_initialize (); 155 status = acpi_hw_initialize ();
156 if (ACPI_FAILURE (status)) { 156 if (ACPI_FAILURE (status)) {
@@ -178,7 +178,8 @@ acpi_enable_subsystem (
178 * install_address_space_handler interface. 178 * install_address_space_handler interface.
179 */ 179 */
180 if (!(flags & ACPI_NO_ADDRESS_SPACE_INIT)) { 180 if (!(flags & ACPI_NO_ADDRESS_SPACE_INIT)) {
181 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[Init] Installing default address space handlers\n")); 181 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
182 "[Init] Installing default address space handlers\n"));
182 183
183 status = acpi_ev_install_region_handlers (); 184 status = acpi_ev_install_region_handlers ();
184 if (ACPI_FAILURE (status)) { 185 if (ACPI_FAILURE (status)) {
@@ -189,12 +190,14 @@ acpi_enable_subsystem (
189 /* 190 /*
190 * Initialize ACPI Event handling (Fixed and General Purpose) 191 * Initialize ACPI Event handling (Fixed and General Purpose)
191 * 192 *
192 * NOTE: We must have the hardware AND events initialized before we can execute 193 * NOTE: We must have the hardware AND events initialized before we can
193 * ANY control methods SAFELY. Any control method can require ACPI hardware 194 * execute ANY control methods SAFELY. Any control method can require
194 * support, so the hardware MUST be initialized before execution! 195 * ACPI hardware support, so the hardware MUST be initialized before
196 * execution!
195 */ 197 */
196 if (!(flags & ACPI_NO_EVENT_INIT)) { 198 if (!(flags & ACPI_NO_EVENT_INIT)) {
197 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[Init] Initializing ACPI events\n")); 199 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
200 "[Init] Initializing ACPI events\n"));
198 201
199 status = acpi_ev_initialize_events (); 202 status = acpi_ev_initialize_events ();
200 if (ACPI_FAILURE (status)) { 203 if (ACPI_FAILURE (status)) {
@@ -205,7 +208,8 @@ acpi_enable_subsystem (
205 /* Install the SCI handler and Global Lock handler */ 208 /* Install the SCI handler and Global Lock handler */
206 209
207 if (!(flags & ACPI_NO_HANDLER_INIT)) { 210 if (!(flags & ACPI_NO_HANDLER_INIT)) {
208 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[Init] Installing SCI/GL handlers\n")); 211 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
212 "[Init] Installing SCI/GL handlers\n"));
209 213
210 status = acpi_ev_install_xrupt_handlers (); 214 status = acpi_ev_install_xrupt_handlers ();
211 if (ACPI_FAILURE (status)) { 215 if (ACPI_FAILURE (status)) {
@@ -247,7 +251,8 @@ acpi_initialize_objects (
247 * contain executable AML (see call to acpi_ns_initialize_objects below). 251 * contain executable AML (see call to acpi_ns_initialize_objects below).
248 */ 252 */
249 if (!(flags & ACPI_NO_ADDRESS_SPACE_INIT)) { 253 if (!(flags & ACPI_NO_ADDRESS_SPACE_INIT)) {
250 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[Init] Executing _REG op_region methods\n")); 254 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
255 "[Init] Executing _REG op_region methods\n"));
251 256
252 status = acpi_ev_initialize_op_regions (); 257 status = acpi_ev_initialize_op_regions ();
253 if (ACPI_FAILURE (status)) { 258 if (ACPI_FAILURE (status)) {
@@ -261,7 +266,8 @@ acpi_initialize_objects (
261 * objects: operation_regions, buffer_fields, Buffers, and Packages. 266 * objects: operation_regions, buffer_fields, Buffers, and Packages.
262 */ 267 */
263 if (!(flags & ACPI_NO_OBJECT_INIT)) { 268 if (!(flags & ACPI_NO_OBJECT_INIT)) {
264 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[Init] Completing Initialization of ACPI Objects\n")); 269 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
270 "[Init] Completing Initialization of ACPI Objects\n"));
265 271
266 status = acpi_ns_initialize_objects (); 272 status = acpi_ns_initialize_objects ();
267 if (ACPI_FAILURE (status)) { 273 if (ACPI_FAILURE (status)) {
@@ -274,7 +280,8 @@ acpi_initialize_objects (
274 * This runs the _STA and _INI methods. 280 * This runs the _STA and _INI methods.
275 */ 281 */
276 if (!(flags & ACPI_NO_DEVICE_INIT)) { 282 if (!(flags & ACPI_NO_DEVICE_INIT)) {
277 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[Init] Initializing ACPI Devices\n")); 283 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
284 "[Init] Initializing ACPI Devices\n"));
278 285
279 status = acpi_ns_initialize_devices (); 286 status = acpi_ns_initialize_devices ();
280 if (ACPI_FAILURE (status)) { 287 if (ACPI_FAILURE (status)) {
@@ -307,7 +314,8 @@ acpi_initialize_objects (
307 ******************************************************************************/ 314 ******************************************************************************/
308 315
309acpi_status 316acpi_status
310acpi_terminate (void) 317acpi_terminate (
318 void)
311{ 319{
312 acpi_status status; 320 acpi_status status;
313 321
@@ -344,8 +352,7 @@ acpi_terminate (void)
344 352
345 353
346#ifdef ACPI_FUTURE_USAGE 354#ifdef ACPI_FUTURE_USAGE
347 355/*******************************************************************************
348/*****************************************************************************
349 * 356 *
350 * FUNCTION: acpi_subsystem_status 357 * FUNCTION: acpi_subsystem_status
351 * 358 *
@@ -354,14 +361,16 @@ acpi_terminate (void)
354 * RETURN: Status of the ACPI subsystem 361 * RETURN: Status of the ACPI subsystem
355 * 362 *
356 * DESCRIPTION: Other drivers that use the ACPI subsystem should call this 363 * DESCRIPTION: Other drivers that use the ACPI subsystem should call this
357 * before making any other calls, to ensure the subsystem initial- 364 * before making any other calls, to ensure the subsystem
358 * ized successfully. 365 * initialized successfully.
359 * 366 *
360 ****************************************************************************/ 367 ******************************************************************************/
361 368
362acpi_status 369acpi_status
363acpi_subsystem_status (void) 370acpi_subsystem_status (
371 void)
364{ 372{
373
365 if (acpi_gbl_startup_flags & ACPI_INITIALIZED_OK) { 374 if (acpi_gbl_startup_flags & ACPI_INITIALIZED_OK) {
366 return (AE_OK); 375 return (AE_OK);
367 } 376 }
@@ -371,13 +380,12 @@ acpi_subsystem_status (void)
371} 380}
372 381
373 382
374/****************************************************************************** 383/*******************************************************************************
375 * 384 *
376 * FUNCTION: acpi_get_system_info 385 * FUNCTION: acpi_get_system_info
377 * 386 *
378 * PARAMETERS: out_buffer - a pointer to a buffer to receive the 387 * PARAMETERS: out_buffer - A buffer to receive the resources for the
379 * resources for the device 388 * device
380 * buffer_length - the number of bytes available in the buffer
381 * 389 *
382 * RETURN: Status - the status of the call 390 * RETURN: Status - the status of the call
383 * 391 *
@@ -395,8 +403,8 @@ acpi_get_system_info (
395 struct acpi_buffer *out_buffer) 403 struct acpi_buffer *out_buffer)
396{ 404{
397 struct acpi_system_info *info_ptr; 405 struct acpi_system_info *info_ptr;
398 u32 i;
399 acpi_status status; 406 acpi_status status;
407 u32 i;
400 408
401 409
402 ACPI_FUNCTION_TRACE ("acpi_get_system_info"); 410 ACPI_FUNCTION_TRACE ("acpi_get_system_info");
@@ -466,6 +474,7 @@ EXPORT_SYMBOL(acpi_get_system_info);
466 * FUNCTION: acpi_install_initialization_handler 474 * FUNCTION: acpi_install_initialization_handler
467 * 475 *
468 * PARAMETERS: Handler - Callback procedure 476 * PARAMETERS: Handler - Callback procedure
477 * Function - Not (currently) used, see below
469 * 478 *
470 * RETURN: Status 479 * RETURN: Status
471 * 480 *
@@ -495,7 +504,6 @@ acpi_install_initialization_handler (
495 504
496#endif /* ACPI_FUTURE_USAGE */ 505#endif /* ACPI_FUTURE_USAGE */
497 506
498
499/***************************************************************************** 507/*****************************************************************************
500 * 508 *
501 * FUNCTION: acpi_purge_cached_objects 509 * FUNCTION: acpi_purge_cached_objects
@@ -509,7 +517,8 @@ acpi_install_initialization_handler (
509 ****************************************************************************/ 517 ****************************************************************************/
510 518
511acpi_status 519acpi_status
512acpi_purge_cached_objects (void) 520acpi_purge_cached_objects (
521 void)
513{ 522{
514 ACPI_FUNCTION_TRACE ("acpi_purge_cached_objects"); 523 ACPI_FUNCTION_TRACE ("acpi_purge_cached_objects");
515 524
diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
index 71fa1011715f..2cf264fd52e0 100644
--- a/drivers/acpi/video.c
+++ b/drivers/acpi/video.c
@@ -564,12 +564,13 @@ acpi_video_device_find_cap (struct acpi_video_device *device)
564 int count = 0; 564 int count = 0;
565 union acpi_object *o; 565 union acpi_object *o;
566 566
567 br = kmalloc(sizeof &br, GFP_KERNEL); 567 br = kmalloc(sizeof(*br), GFP_KERNEL);
568 if (!br) { 568 if (!br) {
569 printk(KERN_ERR "can't allocate memory\n"); 569 printk(KERN_ERR "can't allocate memory\n");
570 } else { 570 } else {
571 memset(br, 0, sizeof &br); 571 memset(br, 0, sizeof(*br));
572 br->levels = kmalloc(obj->package.count * sizeof &br->levels, GFP_KERNEL); 572 br->levels = kmalloc(obj->package.count *
573 sizeof *(br->levels), GFP_KERNEL);
573 if (!br->levels) 574 if (!br->levels)
574 goto out; 575 goto out;
575 576
@@ -584,8 +585,7 @@ acpi_video_device_find_cap (struct acpi_video_device *device)
584 } 585 }
585out: 586out:
586 if (count < 2) { 587 if (count < 2) {
587 if (br->levels) 588 kfree(br->levels);
588 kfree(br->levels);
589 kfree(br); 589 kfree(br);
590 } else { 590 } else {
591 br->count = count; 591 br->count = count;
@@ -595,8 +595,7 @@ out:
595 } 595 }
596 } 596 }
597 597
598 if (obj) 598 kfree(obj);
599 kfree(obj);
600 599
601 return_VOID; 600 return_VOID;
602} 601}
@@ -1585,7 +1584,7 @@ acpi_video_switch_output(
1585 ACPI_FUNCTION_TRACE("acpi_video_switch_output"); 1584 ACPI_FUNCTION_TRACE("acpi_video_switch_output");
1586 1585
1587 list_for_each_safe(node, next, &video->video_device_list) { 1586 list_for_each_safe(node, next, &video->video_device_list) {
1588 struct acpi_video_device * dev = container_of(node, struct acpi_video_device, entry); 1587 dev = container_of(node, struct acpi_video_device, entry);
1589 status = acpi_video_device_get_state(dev, &state); 1588 status = acpi_video_device_get_state(dev, &state);
1590 if (state & 0x2){ 1589 if (state & 0x2){
1591 dev_next = container_of(node->next, struct acpi_video_device, entry); 1590 dev_next = container_of(node->next, struct acpi_video_device, entry);
diff --git a/drivers/base/sys.c b/drivers/base/sys.c
index f37a13de804a..214b96435409 100644
--- a/drivers/base/sys.c
+++ b/drivers/base/sys.c
@@ -22,7 +22,6 @@
22#include <linux/string.h> 22#include <linux/string.h>
23#include <linux/pm.h> 23#include <linux/pm.h>
24 24
25
26extern struct subsystem devices_subsys; 25extern struct subsystem devices_subsys;
27 26
28#define to_sysdev(k) container_of(k, struct sys_device, kobj) 27#define to_sysdev(k) container_of(k, struct sys_device, kobj)
diff --git a/drivers/char/tb0219.c b/drivers/char/tb0219.c
index 5413f2908859..eb7058cbf015 100644
--- a/drivers/char/tb0219.c
+++ b/drivers/char/tb0219.c
@@ -24,6 +24,8 @@
24 24
25#include <asm/io.h> 25#include <asm/io.h>
26#include <asm/reboot.h> 26#include <asm/reboot.h>
27#include <asm/vr41xx/giu.h>
28#include <asm/vr41xx/tb0219.h>
27 29
28MODULE_AUTHOR("Yoichi Yuasa <yuasa@hh.iij4u.or.jp>"); 30MODULE_AUTHOR("Yoichi Yuasa <yuasa@hh.iij4u.or.jp>");
29MODULE_DESCRIPTION("TANBAC TB0219 base board driver"); 31MODULE_DESCRIPTION("TANBAC TB0219 base board driver");
@@ -266,6 +268,21 @@ static void tb0219_restart(char *command)
266 tb0219_write(TB0219_RESET, 0); 268 tb0219_write(TB0219_RESET, 0);
267} 269}
268 270
271static void tb0219_pci_irq_init(void)
272{
273 /* PCI Slot 1 */
274 vr41xx_set_irq_trigger(TB0219_PCI_SLOT1_PIN, IRQ_TRIGGER_LEVEL, IRQ_SIGNAL_THROUGH);
275 vr41xx_set_irq_level(TB0219_PCI_SLOT1_PIN, IRQ_LEVEL_LOW);
276
277 /* PCI Slot 2 */
278 vr41xx_set_irq_trigger(TB0219_PCI_SLOT2_PIN, IRQ_TRIGGER_LEVEL, IRQ_SIGNAL_THROUGH);
279 vr41xx_set_irq_level(TB0219_PCI_SLOT2_PIN, IRQ_LEVEL_LOW);
280
281 /* PCI Slot 3 */
282 vr41xx_set_irq_trigger(TB0219_PCI_SLOT3_PIN, IRQ_TRIGGER_LEVEL, IRQ_SIGNAL_THROUGH);
283 vr41xx_set_irq_level(TB0219_PCI_SLOT3_PIN, IRQ_LEVEL_LOW);
284}
285
269static int tb0219_probe(struct device *dev) 286static int tb0219_probe(struct device *dev)
270{ 287{
271 int retval; 288 int retval;
@@ -292,6 +309,8 @@ static int tb0219_probe(struct device *dev)
292 old_machine_restart = _machine_restart; 309 old_machine_restart = _machine_restart;
293 _machine_restart = tb0219_restart; 310 _machine_restart = tb0219_restart;
294 311
312 tb0219_pci_irq_init();
313
295 if (major == 0) { 314 if (major == 0) {
296 major = retval; 315 major = retval;
297 printk(KERN_INFO "TB0219: major number %d\n", major); 316 printk(KERN_INFO "TB0219: major number %d\n", major);
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
new file mode 100644
index 000000000000..140d5f851a5b
--- /dev/null
+++ b/drivers/hwmon/Kconfig
@@ -0,0 +1,420 @@
1#
2# I2C Sensor chip drivers configuration
3#
4
5menu "Hardware Monitoring support"
6
7config HWMON
8 tristate "Hardware Monitoring support"
9 default y
10 help
11 Hardware monitoring devices let you monitor the hardware health
12 of a system. Most modern motherboards include such a device. It
13 can include temperature sensors, voltage sensors, fan speed
14 sensors and various additional features such as the ability to
15 control the speed of the fans.
16
17config SENSORS_ADM1021
18 tristate "Analog Devices ADM1021 and compatibles"
19 depends on HWMON && I2C
20 select I2C_SENSOR
21 help
22 If you say yes here you get support for Analog Devices ADM1021
23 and ADM1023 sensor chips and clones: Maxim MAX1617 and MAX1617A,
24 Genesys Logic GL523SM, National Semiconductor LM84, TI THMC10,
25 and the XEON processor built-in sensor.
26
27 This driver can also be built as a module. If so, the module
28 will be called adm1021.
29
30config SENSORS_ADM1025
31 tristate "Analog Devices ADM1025 and compatibles"
32 depends on HWMON && I2C && EXPERIMENTAL
33 select I2C_SENSOR
34 help
35 If you say yes here you get support for Analog Devices ADM1025
36 and Philips NE1619 sensor chips.
37
38 This driver can also be built as a module. If so, the module
39 will be called adm1025.
40
41config SENSORS_ADM1026
42 tristate "Analog Devices ADM1026 and compatibles"
43 depends on HWMON && I2C && EXPERIMENTAL
44 select I2C_SENSOR
45 help
46 If you say yes here you get support for Analog Devices ADM1026
47 sensor chip.
48
49 This driver can also be built as a module. If so, the module
50 will be called adm1026.
51
52config SENSORS_ADM1031
53 tristate "Analog Devices ADM1031 and compatibles"
54 depends on HWMON && I2C && EXPERIMENTAL
55 select I2C_SENSOR
56 help
57 If you say yes here you get support for Analog Devices ADM1031
58 and ADM1030 sensor chips.
59
60 This driver can also be built as a module. If so, the module
61 will be called adm1031.
62
63config SENSORS_ADM9240
64 tristate "Analog Devices ADM9240 and compatibles"
65 depends on HWMON && I2C && EXPERIMENTAL
66 select I2C_SENSOR
67 help
68 If you say yes here you get support for Analog Devices ADM9240,
69 Dallas DS1780, National Semiconductor LM81 sensor chips.
70
71 This driver can also be built as a module. If so, the module
72 will be called adm9240.
73
74config SENSORS_ASB100
75 tristate "Asus ASB100 Bach"
76 depends on HWMON && I2C && EXPERIMENTAL
77 select I2C_SENSOR
78 help
79 If you say yes here you get support for the ASB100 Bach sensor
80 chip found on some Asus mainboards.
81
82 This driver can also be built as a module. If so, the module
83 will be called asb100.
84
85config SENSORS_ATXP1
86 tristate "Attansic ATXP1 VID controller"
87 depends on HWMON && I2C && EXPERIMENTAL
88 select I2C_SENSOR
89 help
90 If you say yes here you get support for the Attansic ATXP1 VID
91 controller.
92
93 If your board have such a chip, you are able to control your CPU
94 core and other voltages.
95
96 This driver can also be built as a module. If so, the module
97 will be called atxp1.
98
99config SENSORS_DS1621
100 tristate "Dallas Semiconductor DS1621 and DS1625"
101 depends on HWMON && I2C && EXPERIMENTAL
102 select I2C_SENSOR
103 help
104 If you say yes here you get support for Dallas Semiconductor
105 DS1621 and DS1625 sensor chips.
106
107 This driver can also be built as a module. If so, the module
108 will be called ds1621.
109
110config SENSORS_FSCHER
111 tristate "FSC Hermes"
112 depends on HWMON && I2C && EXPERIMENTAL
113 select I2C_SENSOR
114 help
115 If you say yes here you get support for Fujitsu Siemens
116 Computers Hermes sensor chips.
117
118 This driver can also be built as a module. If so, the module
119 will be called fscher.
120
121config SENSORS_FSCPOS
122 tristate "FSC Poseidon"
123 depends on HWMON && I2C && EXPERIMENTAL
124 select I2C_SENSOR
125 help
126 If you say yes here you get support for Fujitsu Siemens
127 Computers Poseidon sensor chips.
128
129 This driver can also be built as a module. If so, the module
130 will be called fscpos.
131
132config SENSORS_GL518SM
133 tristate "Genesys Logic GL518SM"
134 depends on HWMON && I2C
135 select I2C_SENSOR
136 help
137 If you say yes here you get support for Genesys Logic GL518SM
138 sensor chips.
139
140 This driver can also be built as a module. If so, the module
141 will be called gl518sm.
142
143config SENSORS_GL520SM
144 tristate "Genesys Logic GL520SM"
145 depends on HWMON && I2C && EXPERIMENTAL
146 select I2C_SENSOR
147 help
148 If you say yes here you get support for Genesys Logic GL520SM
149 sensor chips.
150
151 This driver can also be built as a module. If so, the module
152 will be called gl520sm.
153
154config SENSORS_IT87
155 tristate "ITE IT87xx and compatibles"
156 depends on HWMON && I2C
157 select I2C_SENSOR
158 help
159 If you say yes here you get support for ITE IT87xx sensor chips
160 and clones: SiS960.
161
162 This driver can also be built as a module. If so, the module
163 will be called it87.
164
165config SENSORS_LM63
166 tristate "National Semiconductor LM63"
167 depends on HWMON && I2C && EXPERIMENTAL
168 select I2C_SENSOR
169 help
170 If you say yes here you get support for the National Semiconductor
171 LM63 remote diode digital temperature sensor with integrated fan
172 control. Such chips are found on the Tyan S4882 (Thunder K8QS Pro)
173 motherboard, among others.
174
175 This driver can also be built as a module. If so, the module
176 will be called lm63.
177
178config SENSORS_LM75
179 tristate "National Semiconductor LM75 and compatibles"
180 depends on HWMON && I2C
181 select I2C_SENSOR
182 help
183 If you say yes here you get support for National Semiconductor LM75
184 sensor chips and clones: Dallas Semiconductor DS75 and DS1775 (in
185 9-bit precision mode), and TelCom (now Microchip) TCN75.
186
187 The DS75 and DS1775 in 10- to 12-bit precision modes will require
188 a force module parameter. The driver will not handle the extra
189 precision anyhow.
190
191 This driver can also be built as a module. If so, the module
192 will be called lm75.
193
194config SENSORS_LM77
195 tristate "National Semiconductor LM77"
196 depends on HWMON && I2C && EXPERIMENTAL
197 select I2C_SENSOR
198 help
199 If you say yes here you get support for National Semiconductor LM77
200 sensor chips.
201
202 This driver can also be built as a module. If so, the module
203 will be called lm77.
204
205config SENSORS_LM78
206 tristate "National Semiconductor LM78 and compatibles"
207 depends on HWMON && I2C && EXPERIMENTAL
208 select I2C_SENSOR
209 help
210 If you say yes here you get support for National Semiconductor LM78,
211 LM78-J and LM79.
212
213 This driver can also be built as a module. If so, the module
214 will be called lm78.
215
216config SENSORS_LM80
217 tristate "National Semiconductor LM80"
218 depends on HWMON && I2C && EXPERIMENTAL
219 select I2C_SENSOR
220 help
221 If you say yes here you get support for National Semiconductor
222 LM80 sensor chips.
223
224 This driver can also be built as a module. If so, the module
225 will be called lm80.
226
227config SENSORS_LM83
228 tristate "National Semiconductor LM83"
229 depends on HWMON && I2C
230 select I2C_SENSOR
231 help
232 If you say yes here you get support for National Semiconductor
233 LM83 sensor chips.
234
235 This driver can also be built as a module. If so, the module
236 will be called lm83.
237
238config SENSORS_LM85
239 tristate "National Semiconductor LM85 and compatibles"
240 depends on HWMON && I2C && EXPERIMENTAL
241 select I2C_SENSOR
242 help
243 If you say yes here you get support for National Semiconductor LM85
244 sensor chips and clones: ADT7463, EMC6D100, EMC6D102 and ADM1027.
245
246 This driver can also be built as a module. If so, the module
247 will be called lm85.
248
249config SENSORS_LM87
250 tristate "National Semiconductor LM87"
251 depends on HWMON && I2C && EXPERIMENTAL
252 select I2C_SENSOR
253 help
254 If you say yes here you get support for National Semiconductor LM87
255 sensor chips.
256
257 This driver can also be built as a module. If so, the module
258 will be called lm87.
259
260config SENSORS_LM90
261 tristate "National Semiconductor LM90 and compatibles"
262 depends on HWMON && I2C
263 select I2C_SENSOR
264 help
265 If you say yes here you get support for National Semiconductor LM90,
266 LM86, LM89 and LM99, Analog Devices ADM1032 and Maxim MAX6657 and
267 MAX6658 sensor chips.
268
269 The Analog Devices ADT7461 sensor chip is also supported, but only
270 if found in ADM1032 compatibility mode.
271
272 This driver can also be built as a module. If so, the module
273 will be called lm90.
274
275config SENSORS_LM92
276 tristate "National Semiconductor LM92 and compatibles"
277 depends on HWMON && I2C && EXPERIMENTAL
278 select I2C_SENSOR
279 help
280 If you say yes here you get support for National Semiconductor LM92
281 and Maxim MAX6635 sensor chips.
282
283 This driver can also be built as a module. If so, the module
284 will be called lm92.
285
286config SENSORS_MAX1619
287 tristate "Maxim MAX1619 sensor chip"
288 depends on HWMON && I2C && EXPERIMENTAL
289 select I2C_SENSOR
290 help
291 If you say yes here you get support for MAX1619 sensor chip.
292
293 This driver can also be built as a module. If so, the module
294 will be called max1619.
295
296config SENSORS_PC87360
297 tristate "National Semiconductor PC87360 family"
298 depends on HWMON && I2C && EXPERIMENTAL
299 select I2C_SENSOR
300 select I2C_ISA
301 help
302 If you say yes here you get access to the hardware monitoring
303 functions of the National Semiconductor PC8736x Super-I/O chips.
304 The PC87360, PC87363 and PC87364 only have fan monitoring and
305 control. The PC87365 and PC87366 additionally have voltage and
306 temperature monitoring.
307
308 This driver can also be built as a module. If so, the module
309 will be called pc87360.
310
311config SENSORS_SIS5595
312 tristate "Silicon Integrated Systems Corp. SiS5595"
313 depends on HWMON && I2C && PCI && EXPERIMENTAL
314 select I2C_SENSOR
315 select I2C_ISA
316 help
317 If you say yes here you get support for the integrated sensors in
318 SiS5595 South Bridges.
319
320 This driver can also be built as a module. If so, the module
321 will be called sis5595.
322
323config SENSORS_SMSC47M1
324 tristate "SMSC LPC47M10x and compatibles"
325 depends on HWMON && I2C && EXPERIMENTAL
326 select I2C_SENSOR
327 select I2C_ISA
328 help
329 If you say yes here you get support for the integrated fan
330 monitoring and control capabilities of the SMSC LPC47B27x,
331 LPC47M10x, LPC47M13x, LPC47M14x, LPC47M15x and LPC47M192 chips.
332
333 This driver can also be built as a module. If so, the module
334 will be called smsc47m1.
335
336config SENSORS_SMSC47B397
337 tristate "SMSC LPC47B397-NC"
338 depends on HWMON && I2C && EXPERIMENTAL
339 select I2C_SENSOR
340 select I2C_ISA
341 help
342 If you say yes here you get support for the SMSC LPC47B397-NC
343 sensor chip.
344
345 This driver can also be built as a module. If so, the module
346 will be called smsc47b397.
347
348config SENSORS_VIA686A
349 tristate "VIA686A"
350 depends on HWMON && I2C && PCI
351 select I2C_SENSOR
352 select I2C_ISA
353 help
354 If you say yes here you get support for the integrated sensors in
355 Via 686A/B South Bridges.
356
357 This driver can also be built as a module. If so, the module
358 will be called via686a.
359
360config SENSORS_W83781D
361 tristate "Winbond W83781D, W83782D, W83783S, W83627HF, Asus AS99127F"
362 depends on HWMON && I2C
363 select I2C_SENSOR
364 help
365 If you say yes here you get support for the Winbond W8378x series
366 of sensor chips: the W83781D, W83782D, W83783S and W83627HF,
367 and the similar Asus AS99127F.
368
369 This driver can also be built as a module. If so, the module
370 will be called w83781d.
371
372config SENSORS_W83L785TS
373 tristate "Winbond W83L785TS-S"
374 depends on HWMON && I2C && EXPERIMENTAL
375 select I2C_SENSOR
376 help
377 If you say yes here you get support for the Winbond W83L785TS-S
378 sensor chip, which is used on the Asus A7N8X, among other
379 motherboards.
380
381 This driver can also be built as a module. If so, the module
382 will be called w83l785ts.
383
384config SENSORS_W83627HF
385 tristate "Winbond W83627HF, W83627THF, W83637HF, W83697HF"
386 depends on HWMON && I2C && EXPERIMENTAL
387 select I2C_SENSOR
388 select I2C_ISA
389 help
390 If you say yes here you get support for the Winbond W836X7 series
391 of sensor chips: the W83627HF, W83627THF, W83637HF, and the W83697HF
392
393 This driver can also be built as a module. If so, the module
394 will be called w83627hf.
395
396config SENSORS_W83627EHF
397 tristate "Winbond W83627EHF"
398 depends on HWMON && I2C && EXPERIMENTAL
399 select I2C_SENSOR
400 select I2C_ISA
401 help
402 If you say yes here you get preliminary support for the hardware
403 monitoring functionality of the Winbond W83627EHF Super-I/O chip.
404 Only fan and temperature inputs are supported at the moment, while
405 the chip does much more than that.
406
407 This driver can also be built as a module. If so, the module
408 will be called w83627ehf.
409
410config HWMON_DEBUG_CHIP
411 bool "Hardware Monitoring Chip debugging messages"
412 depends on HWMON
413 default n
414 help
415 Say Y here if you want the I2C chip drivers to produce a bunch of
416 debug messages to the system log. Select this if you are having
417 a problem with I2C support and want to see more of what is going
418 on.
419
420endmenu
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
new file mode 100644
index 000000000000..2781403a0236
--- /dev/null
+++ b/drivers/hwmon/Makefile
@@ -0,0 +1,44 @@
1#
2# Makefile for sensor chip drivers.
3#
4
5# asb100, then w83781d go first, as they can override other drivers' addresses.
6obj-$(CONFIG_SENSORS_ASB100) += asb100.o
7obj-$(CONFIG_SENSORS_W83627HF) += w83627hf.o
8obj-$(CONFIG_SENSORS_W83781D) += w83781d.o
9
10obj-$(CONFIG_SENSORS_ADM1021) += adm1021.o
11obj-$(CONFIG_SENSORS_ADM1025) += adm1025.o
12obj-$(CONFIG_SENSORS_ADM1026) += adm1026.o
13obj-$(CONFIG_SENSORS_ADM1031) += adm1031.o
14obj-$(CONFIG_SENSORS_ADM9240) += adm9240.o
15obj-$(CONFIG_SENSORS_ATXP1) += atxp1.o
16obj-$(CONFIG_SENSORS_DS1621) += ds1621.o
17obj-$(CONFIG_SENSORS_FSCHER) += fscher.o
18obj-$(CONFIG_SENSORS_FSCPOS) += fscpos.o
19obj-$(CONFIG_SENSORS_GL518SM) += gl518sm.o
20obj-$(CONFIG_SENSORS_GL520SM) += gl520sm.o
21obj-$(CONFIG_SENSORS_IT87) += it87.o
22obj-$(CONFIG_SENSORS_LM63) += lm63.o
23obj-$(CONFIG_SENSORS_LM75) += lm75.o
24obj-$(CONFIG_SENSORS_LM77) += lm77.o
25obj-$(CONFIG_SENSORS_LM78) += lm78.o
26obj-$(CONFIG_SENSORS_LM80) += lm80.o
27obj-$(CONFIG_SENSORS_LM83) += lm83.o
28obj-$(CONFIG_SENSORS_LM85) += lm85.o
29obj-$(CONFIG_SENSORS_LM87) += lm87.o
30obj-$(CONFIG_SENSORS_LM90) += lm90.o
31obj-$(CONFIG_SENSORS_LM92) += lm92.o
32obj-$(CONFIG_SENSORS_MAX1619) += max1619.o
33obj-$(CONFIG_SENSORS_PC87360) += pc87360.o
34obj-$(CONFIG_SENSORS_SIS5595) += sis5595.o
35obj-$(CONFIG_SENSORS_SMSC47B397)+= smsc47b397.o
36obj-$(CONFIG_SENSORS_SMSC47M1) += smsc47m1.o
37obj-$(CONFIG_SENSORS_VIA686A) += via686a.o
38obj-$(CONFIG_SENSORS_W83627EHF) += w83627ehf.o
39obj-$(CONFIG_SENSORS_W83L785TS) += w83l785ts.o
40
41ifeq ($(CONFIG_HWMON_DEBUG_CHIP),y)
42EXTRA_CFLAGS += -DDEBUG
43endif
44
diff --git a/drivers/i2c/chips/adm1021.c b/drivers/hwmon/adm1021.c
index d2c774c32f45..d2c774c32f45 100644
--- a/drivers/i2c/chips/adm1021.c
+++ b/drivers/hwmon/adm1021.c
diff --git a/drivers/i2c/chips/adm1025.c b/drivers/hwmon/adm1025.c
index e452d0daf906..e452d0daf906 100644
--- a/drivers/i2c/chips/adm1025.c
+++ b/drivers/hwmon/adm1025.c
diff --git a/drivers/i2c/chips/adm1026.c b/drivers/hwmon/adm1026.c
index 3c85fe150cd7..3c85fe150cd7 100644
--- a/drivers/i2c/chips/adm1026.c
+++ b/drivers/hwmon/adm1026.c
diff --git a/drivers/i2c/chips/adm1031.c b/drivers/hwmon/adm1031.c
index 9168e983ca1d..9168e983ca1d 100644
--- a/drivers/i2c/chips/adm1031.c
+++ b/drivers/hwmon/adm1031.c
diff --git a/drivers/i2c/chips/adm9240.c b/drivers/hwmon/adm9240.c
index 5c68e9c311aa..5c68e9c311aa 100644
--- a/drivers/i2c/chips/adm9240.c
+++ b/drivers/hwmon/adm9240.c
diff --git a/drivers/i2c/chips/asb100.c b/drivers/hwmon/asb100.c
index 70d996d6fe0a..70d996d6fe0a 100644
--- a/drivers/i2c/chips/asb100.c
+++ b/drivers/hwmon/asb100.c
diff --git a/drivers/i2c/chips/atxp1.c b/drivers/hwmon/atxp1.c
index 0bcf82b4c07b..0bcf82b4c07b 100644
--- a/drivers/i2c/chips/atxp1.c
+++ b/drivers/hwmon/atxp1.c
diff --git a/drivers/i2c/chips/ds1621.c b/drivers/hwmon/ds1621.c
index 5360d58804f6..5360d58804f6 100644
--- a/drivers/i2c/chips/ds1621.c
+++ b/drivers/hwmon/ds1621.c
diff --git a/drivers/i2c/chips/fscher.c b/drivers/hwmon/fscher.c
index da411741c2c5..da411741c2c5 100644
--- a/drivers/i2c/chips/fscher.c
+++ b/drivers/hwmon/fscher.c
diff --git a/drivers/i2c/chips/fscpos.c b/drivers/hwmon/fscpos.c
index 3beaa6191ef4..3beaa6191ef4 100644
--- a/drivers/i2c/chips/fscpos.c
+++ b/drivers/hwmon/fscpos.c
diff --git a/drivers/i2c/chips/gl518sm.c b/drivers/hwmon/gl518sm.c
index 6bedf729dcf5..6bedf729dcf5 100644
--- a/drivers/i2c/chips/gl518sm.c
+++ b/drivers/hwmon/gl518sm.c
diff --git a/drivers/i2c/chips/gl520sm.c b/drivers/hwmon/gl520sm.c
index a13a504f5bfa..a13a504f5bfa 100644
--- a/drivers/i2c/chips/gl520sm.c
+++ b/drivers/hwmon/gl520sm.c
diff --git a/drivers/i2c/chips/it87.c b/drivers/hwmon/it87.c
index db20c9e47393..db20c9e47393 100644
--- a/drivers/i2c/chips/it87.c
+++ b/drivers/hwmon/it87.c
diff --git a/drivers/i2c/chips/lm63.c b/drivers/hwmon/lm63.c
index 7c6f9ea5a254..7c6f9ea5a254 100644
--- a/drivers/i2c/chips/lm63.c
+++ b/drivers/hwmon/lm63.c
diff --git a/drivers/i2c/chips/lm75.c b/drivers/hwmon/lm75.c
index 5be164ed278e..5be164ed278e 100644
--- a/drivers/i2c/chips/lm75.c
+++ b/drivers/hwmon/lm75.c
diff --git a/drivers/i2c/chips/lm75.h b/drivers/hwmon/lm75.h
index 63e3f2fb4c21..63e3f2fb4c21 100644
--- a/drivers/i2c/chips/lm75.h
+++ b/drivers/hwmon/lm75.h
diff --git a/drivers/i2c/chips/lm77.c b/drivers/hwmon/lm77.c
index b98f44952997..b98f44952997 100644
--- a/drivers/i2c/chips/lm77.c
+++ b/drivers/hwmon/lm77.c
diff --git a/drivers/i2c/chips/lm78.c b/drivers/hwmon/lm78.c
index 29241469dcba..29241469dcba 100644
--- a/drivers/i2c/chips/lm78.c
+++ b/drivers/hwmon/lm78.c
diff --git a/drivers/i2c/chips/lm80.c b/drivers/hwmon/lm80.c
index 8100595feb44..8100595feb44 100644
--- a/drivers/i2c/chips/lm80.c
+++ b/drivers/hwmon/lm80.c
diff --git a/drivers/i2c/chips/lm83.c b/drivers/hwmon/lm83.c
index a49008b444c8..a49008b444c8 100644
--- a/drivers/i2c/chips/lm83.c
+++ b/drivers/hwmon/lm83.c
diff --git a/drivers/i2c/chips/lm85.c b/drivers/hwmon/lm85.c
index b4d7fd418264..b4d7fd418264 100644
--- a/drivers/i2c/chips/lm85.c
+++ b/drivers/hwmon/lm85.c
diff --git a/drivers/i2c/chips/lm87.c b/drivers/hwmon/lm87.c
index 1921ed1af182..1921ed1af182 100644
--- a/drivers/i2c/chips/lm87.c
+++ b/drivers/hwmon/lm87.c
diff --git a/drivers/i2c/chips/lm90.c b/drivers/hwmon/lm90.c
index a67dcadf7cb0..a67dcadf7cb0 100644
--- a/drivers/i2c/chips/lm90.c
+++ b/drivers/hwmon/lm90.c
diff --git a/drivers/i2c/chips/lm92.c b/drivers/hwmon/lm92.c
index 215c8e40ffdd..215c8e40ffdd 100644
--- a/drivers/i2c/chips/lm92.c
+++ b/drivers/hwmon/lm92.c
diff --git a/drivers/i2c/chips/max1619.c b/drivers/hwmon/max1619.c
index bf553dcd97d6..bf553dcd97d6 100644
--- a/drivers/i2c/chips/max1619.c
+++ b/drivers/hwmon/max1619.c
diff --git a/drivers/i2c/chips/pc87360.c b/drivers/hwmon/pc87360.c
index 876c68f3af31..876c68f3af31 100644
--- a/drivers/i2c/chips/pc87360.c
+++ b/drivers/hwmon/pc87360.c
diff --git a/drivers/i2c/chips/sis5595.c b/drivers/hwmon/sis5595.c
index 6bbfc8fb4f13..6bbfc8fb4f13 100644
--- a/drivers/i2c/chips/sis5595.c
+++ b/drivers/hwmon/sis5595.c
diff --git a/drivers/i2c/chips/smsc47b397.c b/drivers/hwmon/smsc47b397.c
index 251ac2659554..251ac2659554 100644
--- a/drivers/i2c/chips/smsc47b397.c
+++ b/drivers/hwmon/smsc47b397.c
diff --git a/drivers/i2c/chips/smsc47m1.c b/drivers/hwmon/smsc47m1.c
index 897117a7213f..897117a7213f 100644
--- a/drivers/i2c/chips/smsc47m1.c
+++ b/drivers/hwmon/smsc47m1.c
diff --git a/drivers/i2c/chips/via686a.c b/drivers/hwmon/via686a.c
index 137d9b7cacd4..164d47948390 100644
--- a/drivers/i2c/chips/via686a.c
+++ b/drivers/hwmon/via686a.c
@@ -1,9 +1,9 @@
1/* 1/*
2 via686a.c - Part of lm_sensors, Linux kernel modules 2 via686a.c - Part of lm_sensors, Linux kernel modules
3 for hardware monitoring 3 for hardware monitoring
4 4
5 Copyright (c) 1998 - 2002 Frodo Looijaard <frodol@dds.nl>, 5 Copyright (c) 1998 - 2002 Frodo Looijaard <frodol@dds.nl>,
6 Kyösti Mälkki <kmalkki@cc.hut.fi>, 6 Kyösti Mälkki <kmalkki@cc.hut.fi>,
7 Mark Studebaker <mdsxyz123@yahoo.com>, 7 Mark Studebaker <mdsxyz123@yahoo.com>,
8 and Bob Dougherty <bobd@stanford.edu> 8 and Bob Dougherty <bobd@stanford.edu>
9 (Some conversion-factor data were contributed by Jonathan Teh Soon Yew 9 (Some conversion-factor data were contributed by Jonathan Teh Soon Yew
@@ -171,18 +171,18 @@ static inline u8 FAN_TO_REG(long rpm, int div)
171/******** TEMP CONVERSIONS (Bob Dougherty) *********/ 171/******** TEMP CONVERSIONS (Bob Dougherty) *********/
172/* linear fits from HWMon.cpp (Copyright 1998-2000 Jonathan Teh Soon Yew) 172/* linear fits from HWMon.cpp (Copyright 1998-2000 Jonathan Teh Soon Yew)
173 if(temp<169) 173 if(temp<169)
174 return double(temp)*0.427-32.08; 174 return double(temp)*0.427-32.08;
175 else if(temp>=169 && temp<=202) 175 else if(temp>=169 && temp<=202)
176 return double(temp)*0.582-58.16; 176 return double(temp)*0.582-58.16;
177 else 177 else
178 return double(temp)*0.924-127.33; 178 return double(temp)*0.924-127.33;
179 179
180 A fifth-order polynomial fits the unofficial data (provided by Alex van 180 A fifth-order polynomial fits the unofficial data (provided by Alex van
181 Kaam <darkside@chello.nl>) a bit better. It also give more reasonable 181 Kaam <darkside@chello.nl>) a bit better. It also give more reasonable
182 numbers on my machine (ie. they agree with what my BIOS tells me). 182 numbers on my machine (ie. they agree with what my BIOS tells me).
183 Here's the fifth-order fit to the 8-bit data: 183 Here's the fifth-order fit to the 8-bit data:
184 temp = 1.625093e-10*val^5 - 1.001632e-07*val^4 + 2.457653e-05*val^3 - 184 temp = 1.625093e-10*val^5 - 1.001632e-07*val^4 + 2.457653e-05*val^3 -
185 2.967619e-03*val^2 + 2.175144e-01*val - 7.090067e+0. 185 2.967619e-03*val^2 + 2.175144e-01*val - 7.090067e+0.
186 186
187 (2000-10-25- RFD: thanks to Uwe Andersen <uandersen@mayah.com> for 187 (2000-10-25- RFD: thanks to Uwe Andersen <uandersen@mayah.com> for
188 finding my typos in this formula!) 188 finding my typos in this formula!)
diff --git a/drivers/i2c/chips/w83627ehf.c b/drivers/hwmon/w83627ehf.c
index 8a40b6976e1a..8a40b6976e1a 100644
--- a/drivers/i2c/chips/w83627ehf.c
+++ b/drivers/hwmon/w83627ehf.c
diff --git a/drivers/i2c/chips/w83627hf.c b/drivers/hwmon/w83627hf.c
index bd87a42e068a..bd87a42e068a 100644
--- a/drivers/i2c/chips/w83627hf.c
+++ b/drivers/hwmon/w83627hf.c
diff --git a/drivers/i2c/chips/w83781d.c b/drivers/hwmon/w83781d.c
index 0bb131ce09eb..0bb131ce09eb 100644
--- a/drivers/i2c/chips/w83781d.c
+++ b/drivers/hwmon/w83781d.c
diff --git a/drivers/i2c/chips/w83l785ts.c b/drivers/hwmon/w83l785ts.c
index 4469d52aba4c..4469d52aba4c 100644
--- a/drivers/i2c/chips/w83l785ts.c
+++ b/drivers/hwmon/w83l785ts.c
diff --git a/drivers/i2c/algos/i2c-algo-ite.c b/drivers/i2c/algos/i2c-algo-ite.c
index 68e9e6832ca0..e6cae39f47aa 100644
--- a/drivers/i2c/algos/i2c-algo-ite.c
+++ b/drivers/i2c/algos/i2c-algo-ite.c
@@ -208,7 +208,7 @@ static int test_bus(struct i2c_algo_iic_data *adap, char *name) {
208 goto bailout; 208 goto bailout;
209 } 209 }
210 sdalo(adap); 210 sdalo(adap);
211 printk("test_bus:1 scl: %d sda: %d \n",getscl(adap), 211 printk("test_bus:1 scl: %d sda: %d\n", getscl(adap),
212 getsda(adap)); 212 getsda(adap));
213 if ( 0 != getsda(adap) ) { 213 if ( 0 != getsda(adap) ) {
214 printk("test_bus: %s SDA stuck high!\n",name); 214 printk("test_bus: %s SDA stuck high!\n",name);
@@ -221,7 +221,7 @@ static int test_bus(struct i2c_algo_iic_data *adap, char *name) {
221 goto bailout; 221 goto bailout;
222 } 222 }
223 sdahi(adap); 223 sdahi(adap);
224 printk("test_bus:2 scl: %d sda: %d \n",getscl(adap), 224 printk("test_bus:2 scl: %d sda: %d\n", getscl(adap),
225 getsda(adap)); 225 getsda(adap));
226 if ( 0 == getsda(adap) ) { 226 if ( 0 == getsda(adap) ) {
227 printk("test_bus: %s SDA stuck low!\n",name); 227 printk("test_bus: %s SDA stuck low!\n",name);
@@ -234,7 +234,7 @@ static int test_bus(struct i2c_algo_iic_data *adap, char *name) {
234 goto bailout; 234 goto bailout;
235 } 235 }
236 scllo(adap); 236 scllo(adap);
237 printk("test_bus:3 scl: %d sda: %d \n",getscl(adap), 237 printk("test_bus:3 scl: %d sda: %d\n", getscl(adap),
238 getsda(adap)); 238 getsda(adap));
239 if ( 0 != getscl(adap) ) { 239 if ( 0 != getscl(adap) ) {
240 240
@@ -247,7 +247,7 @@ static int test_bus(struct i2c_algo_iic_data *adap, char *name) {
247 goto bailout; 247 goto bailout;
248 } 248 }
249 sclhi(adap); 249 sclhi(adap);
250 printk("test_bus:4 scl: %d sda: %d \n",getscl(adap), 250 printk("test_bus:4 scl: %d sda: %d\n", getscl(adap),
251 getsda(adap)); 251 getsda(adap));
252 if ( 0 == getscl(adap) ) { 252 if ( 0 == getscl(adap) ) {
253 printk("test_bus: %s SCL stuck low!\n",name); 253 printk("test_bus: %s SCL stuck low!\n",name);
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index 45e6efb1dcd1..0ab7e37f5b00 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -194,7 +194,7 @@ static int i801_transaction(void)
194 /* Make sure the SMBus host is ready to start transmitting */ 194 /* Make sure the SMBus host is ready to start transmitting */
195 /* 0x1f = Failed, Bus_Err, Dev_Err, Intr, Host_Busy */ 195 /* 0x1f = Failed, Bus_Err, Dev_Err, Intr, Host_Busy */
196 if ((temp = (0x1f & inb_p(SMBHSTSTS))) != 0x00) { 196 if ((temp = (0x1f & inb_p(SMBHSTSTS))) != 0x00) {
197 dev_dbg(&I801_dev->dev, "SMBus busy (%02x). Resetting... \n", 197 dev_dbg(&I801_dev->dev, "SMBus busy (%02x). Resetting...\n",
198 temp); 198 temp);
199 outb_p(temp, SMBHSTSTS); 199 outb_p(temp, SMBHSTSTS);
200 if ((temp = (0x1f & inb_p(SMBHSTSTS))) != 0x00) { 200 if ((temp = (0x1f & inb_p(SMBHSTSTS))) != 0x00) {
@@ -315,7 +315,7 @@ static int i801_block_transaction(union i2c_smbus_data *data, char read_write,
315 } 315 }
316 if (temp & errmask) { 316 if (temp & errmask) {
317 dev_dbg(&I801_dev->dev, "SMBus busy (%02x). " 317 dev_dbg(&I801_dev->dev, "SMBus busy (%02x). "
318 "Resetting... \n", temp); 318 "Resetting...\n", temp);
319 outb_p(temp, SMBHSTSTS); 319 outb_p(temp, SMBHSTSTS);
320 if (((temp = inb_p(SMBHSTSTS)) & errmask) != 0x00) { 320 if (((temp = inb_p(SMBHSTSTS)) & errmask) != 0x00) {
321 dev_err(&I801_dev->dev, 321 dev_err(&I801_dev->dev,
diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
index 1f80ba9da6f1..6d34ee381ce1 100644
--- a/drivers/i2c/busses/i2c-piix4.c
+++ b/drivers/i2c/busses/i2c-piix4.c
@@ -243,7 +243,7 @@ static int piix4_transaction(void)
243 /* Make sure the SMBus host is ready to start transmitting */ 243 /* Make sure the SMBus host is ready to start transmitting */
244 if ((temp = inb_p(SMBHSTSTS)) != 0x00) { 244 if ((temp = inb_p(SMBHSTSTS)) != 0x00) {
245 dev_dbg(&piix4_adapter.dev, "SMBus busy (%02x). " 245 dev_dbg(&piix4_adapter.dev, "SMBus busy (%02x). "
246 "Resetting... \n", temp); 246 "Resetting...\n", temp);
247 outb_p(temp, SMBHSTSTS); 247 outb_p(temp, SMBHSTSTS);
248 if ((temp = inb_p(SMBHSTSTS)) != 0x00) { 248 if ((temp = inb_p(SMBHSTSTS)) != 0x00) {
249 dev_err(&piix4_adapter.dev, "Failed! (%02x)\n", temp); 249 dev_err(&piix4_adapter.dev, "Failed! (%02x)\n", temp);
diff --git a/drivers/i2c/busses/i2c-sis5595.c b/drivers/i2c/busses/i2c-sis5595.c
index 2b5911cfb7b5..bbd5e4e52f09 100644
--- a/drivers/i2c/busses/i2c-sis5595.c
+++ b/drivers/i2c/busses/i2c-sis5595.c
@@ -228,7 +228,7 @@ static int sis5595_transaction(struct i2c_adapter *adap)
228 /* Make sure the SMBus host is ready to start transmitting */ 228 /* Make sure the SMBus host is ready to start transmitting */
229 temp = sis5595_read(SMB_STS_LO) + (sis5595_read(SMB_STS_HI) << 8); 229 temp = sis5595_read(SMB_STS_LO) + (sis5595_read(SMB_STS_HI) << 8);
230 if (temp != 0x00) { 230 if (temp != 0x00) {
231 dev_dbg(&adap->dev, "SMBus busy (%04x). Resetting... \n", temp); 231 dev_dbg(&adap->dev, "SMBus busy (%04x). Resetting...\n", temp);
232 sis5595_write(SMB_STS_LO, temp & 0xff); 232 sis5595_write(SMB_STS_LO, temp & 0xff);
233 sis5595_write(SMB_STS_HI, temp >> 8); 233 sis5595_write(SMB_STS_HI, temp >> 8);
234 if ((temp = sis5595_read(SMB_STS_LO) + (sis5595_read(SMB_STS_HI) << 8)) != 0x00) { 234 if ((temp = sis5595_read(SMB_STS_LO) + (sis5595_read(SMB_STS_HI) << 8)) != 0x00) {
diff --git a/drivers/i2c/chips/Kconfig b/drivers/i2c/chips/Kconfig
index a0982da09803..43f70dbfc03f 100644
--- a/drivers/i2c/chips/Kconfig
+++ b/drivers/i2c/chips/Kconfig
@@ -1,409 +1,12 @@
1# 1#
2# I2C Sensor and "other" chip configuration 2# Miscellaneous I2C chip drivers configuration
3# 3#
4 4
5menu "Hardware Sensors Chip support"
6 depends on I2C
7
8config I2C_SENSOR 5config I2C_SENSOR
9 tristate 6 tristate
10 default n 7 default n
11 8
12config SENSORS_ADM1021 9menu "Miscellaneous I2C Chip support"
13 tristate "Analog Devices ADM1021 and compatibles"
14 depends on I2C
15 select I2C_SENSOR
16 help
17 If you say yes here you get support for Analog Devices ADM1021
18 and ADM1023 sensor chips and clones: Maxim MAX1617 and MAX1617A,
19 Genesys Logic GL523SM, National Semiconductor LM84, TI THMC10,
20 and the XEON processor built-in sensor.
21
22 This driver can also be built as a module. If so, the module
23 will be called adm1021.
24
25config SENSORS_ADM1025
26 tristate "Analog Devices ADM1025 and compatibles"
27 depends on I2C && EXPERIMENTAL
28 select I2C_SENSOR
29 help
30 If you say yes here you get support for Analog Devices ADM1025
31 and Philips NE1619 sensor chips.
32
33 This driver can also be built as a module. If so, the module
34 will be called adm1025.
35
36config SENSORS_ADM1026
37 tristate "Analog Devices ADM1026 and compatibles"
38 depends on I2C && EXPERIMENTAL
39 select I2C_SENSOR
40 help
41 If you say yes here you get support for Analog Devices ADM1026
42 sensor chip.
43
44 This driver can also be built as a module. If so, the module
45 will be called adm1026.
46
47config SENSORS_ADM1031
48 tristate "Analog Devices ADM1031 and compatibles"
49 depends on I2C && EXPERIMENTAL
50 select I2C_SENSOR
51 help
52 If you say yes here you get support for Analog Devices ADM1031
53 and ADM1030 sensor chips.
54
55 This driver can also be built as a module. If so, the module
56 will be called adm1031.
57
58config SENSORS_ADM9240
59 tristate "Analog Devices ADM9240 and compatibles"
60 depends on I2C && EXPERIMENTAL
61 select I2C_SENSOR
62 help
63 If you say yes here you get support for Analog Devices ADM9240,
64 Dallas DS1780, National Semiconductor LM81 sensor chips.
65
66 This driver can also be built as a module. If so, the module
67 will be called adm9240.
68
69config SENSORS_ASB100
70 tristate "Asus ASB100 Bach"
71 depends on I2C && EXPERIMENTAL
72 select I2C_SENSOR
73 help
74 If you say yes here you get support for the ASB100 Bach sensor
75 chip found on some Asus mainboards.
76
77 This driver can also be built as a module. If so, the module
78 will be called asb100.
79
80config SENSORS_ATXP1
81 tristate "Attansic ATXP1 VID controller"
82 depends on I2C && EXPERIMENTAL
83 help
84 If you say yes here you get support for the Attansic ATXP1 VID
85 controller.
86
87 If your board have such a chip, you are able to control your CPU
88 core and other voltages.
89
90 This driver can also be built as a module. If so, the module
91 will be called atxp1.
92
93config SENSORS_DS1621
94 tristate "Dallas Semiconductor DS1621 and DS1625"
95 depends on I2C && EXPERIMENTAL
96 select I2C_SENSOR
97 help
98 If you say yes here you get support for Dallas Semiconductor
99 DS1621 and DS1625 sensor chips.
100
101 This driver can also be built as a module. If so, the module
102 will be called ds1621.
103
104config SENSORS_FSCHER
105 tristate "FSC Hermes"
106 depends on I2C && EXPERIMENTAL
107 select I2C_SENSOR
108 help
109 If you say yes here you get support for Fujitsu Siemens
110 Computers Hermes sensor chips.
111
112 This driver can also be built as a module. If so, the module
113 will be called fscher.
114
115config SENSORS_FSCPOS
116 tristate "FSC Poseidon"
117 depends on I2C && EXPERIMENTAL
118 select I2C_SENSOR
119 help
120 If you say yes here you get support for Fujitsu Siemens
121 Computers Poseidon sensor chips.
122
123 This driver can also be built as a module. If so, the module
124 will be called fscpos.
125
126config SENSORS_GL518SM
127 tristate "Genesys Logic GL518SM"
128 depends on I2C
129 select I2C_SENSOR
130 help
131 If you say yes here you get support for Genesys Logic GL518SM
132 sensor chips.
133
134 This driver can also be built as a module. If so, the module
135 will be called gl518sm.
136
137config SENSORS_GL520SM
138 tristate "Genesys Logic GL520SM"
139 depends on I2C && EXPERIMENTAL
140 select I2C_SENSOR
141 help
142 If you say yes here you get support for Genesys Logic GL520SM
143 sensor chips.
144
145 This driver can also be built as a module. If so, the module
146 will be called gl520sm.
147
148config SENSORS_IT87
149 tristate "ITE IT87xx and compatibles"
150 depends on I2C
151 select I2C_SENSOR
152 help
153 If you say yes here you get support for ITE IT87xx sensor chips
154 and clones: SiS960.
155
156 This driver can also be built as a module. If so, the module
157 will be called it87.
158
159config SENSORS_LM63
160 tristate "National Semiconductor LM63"
161 depends on I2C && EXPERIMENTAL
162 select I2C_SENSOR
163 help
164 If you say yes here you get support for the National Semiconductor
165 LM63 remote diode digital temperature sensor with integrated fan
166 control. Such chips are found on the Tyan S4882 (Thunder K8QS Pro)
167 motherboard, among others.
168
169 This driver can also be built as a module. If so, the module
170 will be called lm63.
171
172config SENSORS_LM75
173 tristate "National Semiconductor LM75 and compatibles"
174 depends on I2C
175 select I2C_SENSOR
176 help
177 If you say yes here you get support for National Semiconductor LM75
178 sensor chips and clones: Dallas Semiconductor DS75 and DS1775 (in
179 9-bit precision mode), and TelCom (now Microchip) TCN75.
180
181 The DS75 and DS1775 in 10- to 12-bit precision modes will require
182 a force module parameter. The driver will not handle the extra
183 precision anyhow.
184
185 This driver can also be built as a module. If so, the module
186 will be called lm75.
187
188config SENSORS_LM77
189 tristate "National Semiconductor LM77"
190 depends on I2C && EXPERIMENTAL
191 select I2C_SENSOR
192 help
193 If you say yes here you get support for National Semiconductor LM77
194 sensor chips.
195
196 This driver can also be built as a module. If so, the module
197 will be called lm77.
198
199config SENSORS_LM78
200 tristate "National Semiconductor LM78 and compatibles"
201 depends on I2C && EXPERIMENTAL
202 select I2C_SENSOR
203 help
204 If you say yes here you get support for National Semiconductor LM78,
205 LM78-J and LM79.
206
207 This driver can also be built as a module. If so, the module
208 will be called lm78.
209
210config SENSORS_LM80
211 tristate "National Semiconductor LM80"
212 depends on I2C && EXPERIMENTAL
213 select I2C_SENSOR
214 help
215 If you say yes here you get support for National Semiconductor
216 LM80 sensor chips.
217
218 This driver can also be built as a module. If so, the module
219 will be called lm80.
220
221config SENSORS_LM83
222 tristate "National Semiconductor LM83"
223 depends on I2C
224 select I2C_SENSOR
225 help
226 If you say yes here you get support for National Semiconductor
227 LM83 sensor chips.
228
229 This driver can also be built as a module. If so, the module
230 will be called lm83.
231
232config SENSORS_LM85
233 tristate "National Semiconductor LM85 and compatibles"
234 depends on I2C && EXPERIMENTAL
235 select I2C_SENSOR
236 help
237 If you say yes here you get support for National Semiconductor LM85
238 sensor chips and clones: ADT7463, EMC6D100, EMC6D102 and ADM1027.
239
240 This driver can also be built as a module. If so, the module
241 will be called lm85.
242
243config SENSORS_LM87
244 tristate "National Semiconductor LM87"
245 depends on I2C && EXPERIMENTAL
246 select I2C_SENSOR
247 help
248 If you say yes here you get support for National Semiconductor LM87
249 sensor chips.
250
251 This driver can also be built as a module. If so, the module
252 will be called lm87.
253
254config SENSORS_LM90
255 tristate "National Semiconductor LM90 and compatibles"
256 depends on I2C
257 select I2C_SENSOR
258 help
259 If you say yes here you get support for National Semiconductor LM90,
260 LM86, LM89 and LM99, Analog Devices ADM1032 and Maxim MAX6657 and
261 MAX6658 sensor chips.
262
263 The Analog Devices ADT7461 sensor chip is also supported, but only
264 if found in ADM1032 compatibility mode.
265
266 This driver can also be built as a module. If so, the module
267 will be called lm90.
268
269config SENSORS_LM92
270 tristate "National Semiconductor LM92 and compatibles"
271 depends on I2C && EXPERIMENTAL
272 select I2C_SENSOR
273 help
274 If you say yes here you get support for National Semiconductor LM92
275 and Maxim MAX6635 sensor chips.
276
277 This driver can also be built as a module. If so, the module
278 will be called lm92.
279
280config SENSORS_MAX1619
281 tristate "Maxim MAX1619 sensor chip"
282 depends on I2C && EXPERIMENTAL
283 select I2C_SENSOR
284 help
285 If you say yes here you get support for MAX1619 sensor chip.
286
287 This driver can also be built as a module. If so, the module
288 will be called max1619.
289
290config SENSORS_PC87360
291 tristate "National Semiconductor PC87360 family"
292 depends on I2C && EXPERIMENTAL
293 select I2C_SENSOR
294 select I2C_ISA
295 help
296 If you say yes here you get access to the hardware monitoring
297 functions of the National Semiconductor PC8736x Super-I/O chips.
298 The PC87360, PC87363 and PC87364 only have fan monitoring and
299 control. The PC87365 and PC87366 additionally have voltage and
300 temperature monitoring.
301
302 This driver can also be built as a module. If so, the module
303 will be called pc87360.
304
305config SENSORS_SMSC47B397
306 tristate "SMSC LPC47B397-NC"
307 depends on I2C && EXPERIMENTAL
308 select I2C_SENSOR
309 select I2C_ISA
310 help
311 If you say yes here you get support for the SMSC LPC47B397-NC
312 sensor chip.
313
314 This driver can also be built as a module. If so, the module
315 will be called smsc47b397.
316
317config SENSORS_SIS5595
318 tristate "Silicon Integrated Systems Corp. SiS5595"
319 depends on I2C && PCI && EXPERIMENTAL
320 select I2C_SENSOR
321 select I2C_ISA
322 help
323 If you say yes here you get support for the integrated sensors in
324 SiS5595 South Bridges.
325
326 This driver can also be built as a module. If so, the module
327 will be called sis5595.
328
329config SENSORS_SMSC47M1
330 tristate "SMSC LPC47M10x and compatibles"
331 depends on I2C && EXPERIMENTAL
332 select I2C_SENSOR
333 select I2C_ISA
334 help
335 If you say yes here you get support for the integrated fan
336 monitoring and control capabilities of the SMSC LPC47B27x,
337 LPC47M10x, LPC47M13x, LPC47M14x, LPC47M15x and LPC47M192 chips.
338
339 This driver can also be built as a module. If so, the module
340 will be called smsc47m1.
341
342config SENSORS_VIA686A
343 tristate "VIA686A"
344 depends on I2C && PCI
345 select I2C_SENSOR
346 select I2C_ISA
347 help
348 If you say yes here you get support for the integrated sensors in
349 Via 686A/B South Bridges.
350
351 This driver can also be built as a module. If so, the module
352 will be called via686a.
353
354config SENSORS_W83781D
355 tristate "Winbond W83781D, W83782D, W83783S, W83627HF, Asus AS99127F"
356 depends on I2C
357 select I2C_SENSOR
358 help
359 If you say yes here you get support for the Winbond W8378x series
360 of sensor chips: the W83781D, W83782D, W83783S and W83627HF,
361 and the similar Asus AS99127F.
362
363 This driver can also be built as a module. If so, the module
364 will be called w83781d.
365
366config SENSORS_W83L785TS
367 tristate "Winbond W83L785TS-S"
368 depends on I2C && EXPERIMENTAL
369 select I2C_SENSOR
370 help
371 If you say yes here you get support for the Winbond W83L785TS-S
372 sensor chip, which is used on the Asus A7N8X, among other
373 motherboards.
374
375 This driver can also be built as a module. If so, the module
376 will be called w83l785ts.
377
378config SENSORS_W83627HF
379 tristate "Winbond W83627HF, W83627THF, W83637HF, W83697HF"
380 depends on I2C && EXPERIMENTAL
381 select I2C_SENSOR
382 select I2C_ISA
383 help
384 If you say yes here you get support for the Winbond W836X7 series
385 of sensor chips: the W83627HF, W83627THF, W83637HF, and the W83697HF
386
387 This driver can also be built as a module. If so, the module
388 will be called w83627hf.
389
390config SENSORS_W83627EHF
391 tristate "Winbond W83627EHF"
392 depends on I2C && EXPERIMENTAL
393 select I2C_SENSOR
394 select I2C_ISA
395 help
396 If you say yes here you get preliminary support for the hardware
397 monitoring functionality of the Winbond W83627EHF Super-I/O chip.
398 Only fan and temperature inputs are supported at the moment, while
399 the chip does much more than that.
400
401 This driver can also be built as a module. If so, the module
402 will be called w83627ehf.
403
404endmenu
405
406menu "Other I2C Chip support"
407 depends on I2C 10 depends on I2C
408 11
409config SENSORS_DS1337 12config SENSORS_DS1337
@@ -509,7 +112,6 @@ config TPS65010
509 This driver can also be built as a module. If so, the module 112 This driver can also be built as a module. If so, the module
510 will be called tps65010. 113 will be called tps65010.
511 114
512
513config SENSORS_M41T00 115config SENSORS_M41T00
514 tristate "ST M41T00 RTC chip" 116 tristate "ST M41T00 RTC chip"
515 depends on I2C && PPC32 117 depends on I2C && PPC32
@@ -520,13 +122,16 @@ config SENSORS_M41T00
520 will be called m41t00. 122 will be called m41t00.
521 123
522config SENSORS_MAX6875 124config SENSORS_MAX6875
523 tristate "MAXIM MAX6875 Power supply supervisor" 125 tristate "Maxim MAX6875 Power supply supervisor"
524 depends on I2C && EXPERIMENTAL 126 depends on I2C && EXPERIMENTAL
525 help 127 help
526 If you say yes here you get support for the MAX6875 128 If you say yes here you get support for the Maxim MAX6875
527 EEPROM-Programmable, Hex/Quad, Power-Suppy Sequencers/Supervisors. 129 EEPROM-programmable, quad power-supply sequencer/supervisor.
130
131 This provides an interface to program the EEPROM and reset the chip.
528 132
529 This provides a interface to program the EEPROM and reset the chip. 133 This driver also supports the Maxim MAX6874 hex power-supply
134 sequencer/supervisor if found at a compatible address.
530 135
531 This driver can also be built as a module. If so, the module 136 This driver can also be built as a module. If so, the module
532 will be called max6875. 137 will be called max6875.
diff --git a/drivers/i2c/chips/Makefile b/drivers/i2c/chips/Makefile
index b5e6d2f84f97..a876dd42b860 100644
--- a/drivers/i2c/chips/Makefile
+++ b/drivers/i2c/chips/Makefile
@@ -1,52 +1,16 @@
1# 1#
2# Makefile for sensor and "other" I2C chip drivers. 2# Makefile for miscellaneous I2C chip drivers.
3# 3#
4 4
5# asb100, then w83781d go first, as they can override other drivers' addresses.
6obj-$(CONFIG_SENSORS_ASB100) += asb100.o
7obj-$(CONFIG_SENSORS_W83627HF) += w83627hf.o
8obj-$(CONFIG_SENSORS_W83781D) += w83781d.o
9
10obj-$(CONFIG_SENSORS_ADM1021) += adm1021.o
11obj-$(CONFIG_SENSORS_ADM1025) += adm1025.o
12obj-$(CONFIG_SENSORS_ADM1026) += adm1026.o
13obj-$(CONFIG_SENSORS_ADM1031) += adm1031.o
14obj-$(CONFIG_SENSORS_ADM9240) += adm9240.o
15obj-$(CONFIG_SENSORS_ATXP1) += atxp1.o
16obj-$(CONFIG_SENSORS_DS1337) += ds1337.o 5obj-$(CONFIG_SENSORS_DS1337) += ds1337.o
17obj-$(CONFIG_SENSORS_DS1374) += ds1374.o 6obj-$(CONFIG_SENSORS_DS1374) += ds1374.o
18obj-$(CONFIG_SENSORS_DS1621) += ds1621.o
19obj-$(CONFIG_SENSORS_EEPROM) += eeprom.o 7obj-$(CONFIG_SENSORS_EEPROM) += eeprom.o
20obj-$(CONFIG_SENSORS_FSCHER) += fscher.o
21obj-$(CONFIG_SENSORS_FSCPOS) += fscpos.o
22obj-$(CONFIG_SENSORS_GL518SM) += gl518sm.o
23obj-$(CONFIG_SENSORS_GL520SM) += gl520sm.o
24obj-$(CONFIG_SENSORS_IT87) += it87.o
25obj-$(CONFIG_SENSORS_LM63) += lm63.o
26obj-$(CONFIG_SENSORS_LM75) += lm75.o
27obj-$(CONFIG_SENSORS_LM77) += lm77.o
28obj-$(CONFIG_SENSORS_LM78) += lm78.o
29obj-$(CONFIG_SENSORS_LM80) += lm80.o
30obj-$(CONFIG_SENSORS_LM83) += lm83.o
31obj-$(CONFIG_SENSORS_LM85) += lm85.o
32obj-$(CONFIG_SENSORS_LM87) += lm87.o
33obj-$(CONFIG_SENSORS_LM90) += lm90.o
34obj-$(CONFIG_SENSORS_LM92) += lm92.o
35obj-$(CONFIG_SENSORS_MAX1619) += max1619.o
36obj-$(CONFIG_SENSORS_MAX6875) += max6875.o 8obj-$(CONFIG_SENSORS_MAX6875) += max6875.o
37obj-$(CONFIG_SENSORS_M41T00) += m41t00.o 9obj-$(CONFIG_SENSORS_M41T00) += m41t00.o
38obj-$(CONFIG_SENSORS_PC87360) += pc87360.o
39obj-$(CONFIG_SENSORS_PCA9539) += pca9539.o 10obj-$(CONFIG_SENSORS_PCA9539) += pca9539.o
40obj-$(CONFIG_SENSORS_PCF8574) += pcf8574.o 11obj-$(CONFIG_SENSORS_PCF8574) += pcf8574.o
41obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o 12obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o
42obj-$(CONFIG_SENSORS_RTC8564) += rtc8564.o 13obj-$(CONFIG_SENSORS_RTC8564) += rtc8564.o
43obj-$(CONFIG_SENSORS_SIS5595) += sis5595.o
44obj-$(CONFIG_SENSORS_SMSC47B397)+= smsc47b397.o
45obj-$(CONFIG_SENSORS_SMSC47M1) += smsc47m1.o
46obj-$(CONFIG_SENSORS_VIA686A) += via686a.o
47obj-$(CONFIG_SENSORS_W83627EHF) += w83627ehf.o
48obj-$(CONFIG_SENSORS_W83L785TS) += w83l785ts.o
49
50obj-$(CONFIG_ISP1301_OMAP) += isp1301_omap.o 14obj-$(CONFIG_ISP1301_OMAP) += isp1301_omap.o
51obj-$(CONFIG_TPS65010) += tps65010.o 15obj-$(CONFIG_TPS65010) += tps65010.o
52 16
diff --git a/drivers/i2c/chips/eeprom.c b/drivers/i2c/chips/eeprom.c
index addf0adc24d4..6ea413f6d5e5 100644
--- a/drivers/i2c/chips/eeprom.c
+++ b/drivers/i2c/chips/eeprom.c
@@ -173,9 +173,6 @@ int eeprom_detect(struct i2c_adapter *adapter, int address, int kind)
173 | I2C_FUNC_SMBUS_BYTE)) 173 | I2C_FUNC_SMBUS_BYTE))
174 goto exit; 174 goto exit;
175 175
176 /* OK. For now, we presume we have a valid client. We now create the
177 client structure, even though we cannot fill it completely yet.
178 But it allows us to access eeprom_{read,write}_value. */
179 if (!(data = kmalloc(sizeof(struct eeprom_data), GFP_KERNEL))) { 176 if (!(data = kmalloc(sizeof(struct eeprom_data), GFP_KERNEL))) {
180 err = -ENOMEM; 177 err = -ENOMEM;
181 goto exit; 178 goto exit;
diff --git a/drivers/i2c/chips/m41t00.c b/drivers/i2c/chips/m41t00.c
index 5e463c47bfbc..778d7e12859d 100644
--- a/drivers/i2c/chips/m41t00.c
+++ b/drivers/i2c/chips/m41t00.c
@@ -207,7 +207,7 @@ m41t00_detach(struct i2c_client *client)
207 int rc; 207 int rc;
208 208
209 if ((rc = i2c_detach_client(client)) == 0) { 209 if ((rc = i2c_detach_client(client)) == 0) {
210 kfree(i2c_get_clientdata(client)); 210 kfree(client);
211 tasklet_kill(&m41t00_tasklet); 211 tasklet_kill(&m41t00_tasklet);
212 } 212 }
213 return rc; 213 return rc;
diff --git a/drivers/i2c/chips/max6875.c b/drivers/i2c/chips/max6875.c
index fe6b150ec4c2..c4f14d9623c4 100644
--- a/drivers/i2c/chips/max6875.c
+++ b/drivers/i2c/chips/max6875.c
@@ -37,7 +37,8 @@
37#include <linux/i2c-sensor.h> 37#include <linux/i2c-sensor.h>
38 38
39/* Addresses to scan */ 39/* Addresses to scan */
40static unsigned short normal_i2c[] = {0x50, 0x52, I2C_CLIENT_END}; 40/* No address scanned by default, as this could corrupt standard EEPROMS. */
41static unsigned short normal_i2c[] = {I2C_CLIENT_END};
41static unsigned int normal_isa[] = {I2C_CLIENT_ISA_END}; 42static unsigned int normal_isa[] = {I2C_CLIENT_ISA_END};
42 43
43/* Insmod parameters */ 44/* Insmod parameters */
@@ -369,6 +370,9 @@ static int max6875_detect(struct i2c_adapter *adapter, int address, int kind)
369 new_client->driver = &max6875_driver; 370 new_client->driver = &max6875_driver;
370 new_client->flags = 0; 371 new_client->flags = 0;
371 372
373 /* Prevent 24RF08 corruption */
374 i2c_smbus_write_quick(new_client, 0);
375
372 /* Setup the user section */ 376 /* Setup the user section */
373 data->blocks[max6875_eeprom_user].type = max6875_eeprom_user; 377 data->blocks[max6875_eeprom_user].type = max6875_eeprom_user;
374 data->blocks[max6875_eeprom_user].slices = USER_EEPROM_SLICES; 378 data->blocks[max6875_eeprom_user].slices = USER_EEPROM_SLICES;
diff --git a/drivers/i2c/chips/tps65010.c b/drivers/i2c/chips/tps65010.c
index c0ac01b60039..280e9638c0f8 100644
--- a/drivers/i2c/chips/tps65010.c
+++ b/drivers/i2c/chips/tps65010.c
@@ -18,7 +18,6 @@
18 * along with this program; if not, write to the Free Software 18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */ 20 */
21#undef DEBUG
22 21
23#include <linux/config.h> 22#include <linux/config.h>
24#include <linux/kernel.h> 23#include <linux/kernel.h>
@@ -49,11 +48,7 @@
49MODULE_DESCRIPTION("TPS6501x Power Management Driver"); 48MODULE_DESCRIPTION("TPS6501x Power Management Driver");
50MODULE_LICENSE("GPL"); 49MODULE_LICENSE("GPL");
51 50
52/* only two addresses possible */ 51static unsigned short normal_i2c[] = { 0x48, /* 0x49, */ I2C_CLIENT_END };
53#define TPS_BASE 0x48
54static unsigned short normal_i2c[] = {
55 TPS_BASE,
56 I2C_CLIENT_END };
57static unsigned short normal_i2c_range[] = { I2C_CLIENT_END }; 52static unsigned short normal_i2c_range[] = { I2C_CLIENT_END };
58 53
59I2C_CLIENT_INSMOD; 54I2C_CLIENT_INSMOD;
@@ -102,7 +97,7 @@ struct tps65010 {
102 u8 chgstatus, regstatus, chgconf; 97 u8 chgstatus, regstatus, chgconf;
103 u8 nmask1, nmask2; 98 u8 nmask1, nmask2;
104 99
105 /* plus four GPIOs, probably used to switch power */ 100 /* not currently tracking GPIO state */
106}; 101};
107 102
108#define POWER_POLL_DELAY msecs_to_jiffies(800) 103#define POWER_POLL_DELAY msecs_to_jiffies(800)
@@ -135,7 +130,7 @@ static void dbg_regstat(char *buf, size_t len, u8 regstatus)
135 (regstatus & TPS_REG_COVER) ? " uncover" : "", 130 (regstatus & TPS_REG_COVER) ? " uncover" : "",
136 (regstatus & TPS_REG_UVLO) ? " UVLO" : "", 131 (regstatus & TPS_REG_UVLO) ? " UVLO" : "",
137 (regstatus & TPS_REG_NO_CHG) ? " NO_CHG" : "", 132 (regstatus & TPS_REG_NO_CHG) ? " NO_CHG" : "",
138 (regstatus & TPS_REG_PG_LD02) ? " ld01_bad" : "", 133 (regstatus & TPS_REG_PG_LD02) ? " ld02_bad" : "",
139 (regstatus & TPS_REG_PG_LD01) ? " ld01_bad" : "", 134 (regstatus & TPS_REG_PG_LD01) ? " ld01_bad" : "",
140 (regstatus & TPS_REG_PG_MAIN) ? " main_bad" : "", 135 (regstatus & TPS_REG_PG_MAIN) ? " main_bad" : "",
141 (regstatus & TPS_REG_PG_CORE) ? " core_bad" : ""); 136 (regstatus & TPS_REG_PG_CORE) ? " core_bad" : "");
@@ -143,7 +138,7 @@ static void dbg_regstat(char *buf, size_t len, u8 regstatus)
143 138
144static void dbg_chgconf(int por, char *buf, size_t len, u8 chgconfig) 139static void dbg_chgconf(int por, char *buf, size_t len, u8 chgconfig)
145{ 140{
146 char *hibit; 141 const char *hibit;
147 142
148 if (por) 143 if (por)
149 hibit = (chgconfig & TPS_CHARGE_POR) 144 hibit = (chgconfig & TPS_CHARGE_POR)
@@ -295,7 +290,7 @@ static int dbg_show(struct seq_file *s, void *_)
295 seq_printf(s, "defgpio %02x mask3 %02x\n", value, v2); 290 seq_printf(s, "defgpio %02x mask3 %02x\n", value, v2);
296 291
297 for (i = 0; i < 4; i++) { 292 for (i = 0; i < 4; i++) {
298 if (value & (1 << (4 +i))) 293 if (value & (1 << (4 + i)))
299 seq_printf(s, " gpio%d-out %s\n", i + 1, 294 seq_printf(s, " gpio%d-out %s\n", i + 1,
300 (value & (1 << i)) ? "low" : "hi "); 295 (value & (1 << i)) ? "low" : "hi ");
301 else 296 else
@@ -481,7 +476,7 @@ static int __exit tps65010_detach_client(struct i2c_client *client)
481 debugfs_remove(tps->file); 476 debugfs_remove(tps->file);
482 if (i2c_detach_client(client) == 0) 477 if (i2c_detach_client(client) == 0)
483 kfree(tps); 478 kfree(tps);
484 the_tps = 0; 479 the_tps = NULL;
485 return 0; 480 return 0;
486} 481}
487 482
@@ -514,7 +509,6 @@ tps65010_probe(struct i2c_adapter *bus, int address, int kind)
514 INIT_WORK(&tps->work, tps65010_work, tps); 509 INIT_WORK(&tps->work, tps65010_work, tps);
515 tps->irq = -1; 510 tps->irq = -1;
516 tps->client.addr = address; 511 tps->client.addr = address;
517 i2c_set_clientdata(&tps->client, tps);
518 tps->client.adapter = bus; 512 tps->client.adapter = bus;
519 tps->client.driver = &tps65010_driver; 513 tps->client.driver = &tps65010_driver;
520 strlcpy(tps->client.name, DRIVER_NAME, I2C_NAME_SIZE); 514 strlcpy(tps->client.name, DRIVER_NAME, I2C_NAME_SIZE);
@@ -523,9 +517,7 @@ tps65010_probe(struct i2c_adapter *bus, int address, int kind)
523 if (status < 0) { 517 if (status < 0) {
524 dev_dbg(&bus->dev, "can't attach %s to device %d, err %d\n", 518 dev_dbg(&bus->dev, "can't attach %s to device %d, err %d\n",
525 DRIVER_NAME, address, status); 519 DRIVER_NAME, address, status);
526fail1: 520 goto fail1;
527 kfree(tps);
528 return 0;
529 } 521 }
530 522
531#ifdef CONFIG_ARM 523#ifdef CONFIG_ARM
@@ -535,7 +527,7 @@ fail1:
535 tps->irq = OMAP_GPIO_IRQ(58); 527 tps->irq = OMAP_GPIO_IRQ(58);
536 omap_request_gpio(58); 528 omap_request_gpio(58);
537 omap_set_gpio_direction(58, 1); 529 omap_set_gpio_direction(58, 1);
538 omap_set_gpio_edge_ctrl(58, OMAP_GPIO_FALLING_EDGE); 530 set_irq_type(tps->irq, IRQT_FALLING);
539 } 531 }
540 if (machine_is_omap_osk()) { 532 if (machine_is_omap_osk()) {
541 tps->model = TPS65010; 533 tps->model = TPS65010;
@@ -543,7 +535,7 @@ fail1:
543 tps->irq = OMAP_GPIO_IRQ(OMAP_MPUIO(1)); 535 tps->irq = OMAP_GPIO_IRQ(OMAP_MPUIO(1));
544 omap_request_gpio(OMAP_MPUIO(1)); 536 omap_request_gpio(OMAP_MPUIO(1));
545 omap_set_gpio_direction(OMAP_MPUIO(1), 1); 537 omap_set_gpio_direction(OMAP_MPUIO(1), 1);
546 omap_set_gpio_edge_ctrl(OMAP_MPUIO(1), OMAP_GPIO_FALLING_EDGE); 538 set_irq_type(tps->irq, IRQT_FALLING);
547 } 539 }
548 if (machine_is_omap_h3()) { 540 if (machine_is_omap_h3()) {
549 tps->model = TPS65013; 541 tps->model = TPS65013;
@@ -633,6 +625,9 @@ fail1:
633 tps->file = debugfs_create_file(DRIVER_NAME, S_IRUGO, NULL, 625 tps->file = debugfs_create_file(DRIVER_NAME, S_IRUGO, NULL,
634 tps, DEBUG_FOPS); 626 tps, DEBUG_FOPS);
635 return 0; 627 return 0;
628fail1:
629 kfree(tps);
630 return 0;
636} 631}
637 632
638static int __init tps65010_scan_bus(struct i2c_adapter *bus) 633static int __init tps65010_scan_bus(struct i2c_adapter *bus)
@@ -645,7 +640,6 @@ static int __init tps65010_scan_bus(struct i2c_adapter *bus)
645static struct i2c_driver tps65010_driver = { 640static struct i2c_driver tps65010_driver = {
646 .owner = THIS_MODULE, 641 .owner = THIS_MODULE,
647 .name = "tps65010", 642 .name = "tps65010",
648 .id = 888, /* FIXME assign "official" value */
649 .flags = I2C_DF_NOTIFY, 643 .flags = I2C_DF_NOTIFY,
650 .attach_adapter = tps65010_scan_bus, 644 .attach_adapter = tps65010_scan_bus,
651 .detach_client = __exit_p(tps65010_detach_client), 645 .detach_client = __exit_p(tps65010_detach_client),
@@ -744,7 +738,7 @@ int tps65010_set_led(unsigned led, unsigned mode)
744 if (!the_tps) 738 if (!the_tps)
745 return -ENODEV; 739 return -ENODEV;
746 740
747 if(led == LED1) 741 if (led == LED1)
748 offs = 0; 742 offs = 0;
749 else { 743 else {
750 offs = 2; 744 offs = 2;
@@ -753,11 +747,13 @@ int tps65010_set_led(unsigned led, unsigned mode)
753 747
754 down(&the_tps->lock); 748 down(&the_tps->lock);
755 749
756 dev_dbg (&the_tps->client.dev, "led%i_on 0x%02x\n", led, 750 pr_debug("%s: led%i_on 0x%02x\n", DRIVER_NAME, led,
757 i2c_smbus_read_byte_data(&the_tps->client, TPS_LED1_ON + offs)); 751 i2c_smbus_read_byte_data(&the_tps->client,
752 TPS_LED1_ON + offs));
758 753
759 dev_dbg (&the_tps->client.dev, "led%i_per 0x%02x\n", led, 754 pr_debug("%s: led%i_per 0x%02x\n", DRIVER_NAME, led,
760 i2c_smbus_read_byte_data(&the_tps->client, TPS_LED1_PER + offs)); 755 i2c_smbus_read_byte_data(&the_tps->client,
756 TPS_LED1_PER + offs));
761 757
762 switch (mode) { 758 switch (mode) {
763 case OFF: 759 case OFF:
@@ -773,7 +769,7 @@ int tps65010_set_led(unsigned led, unsigned mode)
773 led_per = 0x08 | (1 << 7); 769 led_per = 0x08 | (1 << 7);
774 break; 770 break;
775 default: 771 default:
776 printk(KERN_ERR "%s: Wrong mode parameter for tps65010_set_led()\n", 772 printk(KERN_ERR "%s: Wrong mode parameter for set_led()\n",
777 DRIVER_NAME); 773 DRIVER_NAME);
778 up(&the_tps->lock); 774 up(&the_tps->lock);
779 return -EINVAL; 775 return -EINVAL;
@@ -789,7 +785,7 @@ int tps65010_set_led(unsigned led, unsigned mode)
789 return status; 785 return status;
790 } 786 }
791 787
792 dev_dbg (&the_tps->client.dev, "led%i_on 0x%02x\n", led, 788 pr_debug("%s: led%i_on 0x%02x\n", DRIVER_NAME, led,
793 i2c_smbus_read_byte_data(&the_tps->client, TPS_LED1_ON + offs)); 789 i2c_smbus_read_byte_data(&the_tps->client, TPS_LED1_ON + offs));
794 790
795 status = i2c_smbus_write_byte_data(&the_tps->client, 791 status = i2c_smbus_write_byte_data(&the_tps->client,
@@ -802,8 +798,9 @@ int tps65010_set_led(unsigned led, unsigned mode)
802 return status; 798 return status;
803 } 799 }
804 800
805 dev_dbg (&the_tps->client.dev, "led%i_per 0x%02x\n", led, 801 pr_debug("%s: led%i_per 0x%02x\n", DRIVER_NAME, led,
806 i2c_smbus_read_byte_data(&the_tps->client, TPS_LED1_PER + offs)); 802 i2c_smbus_read_byte_data(&the_tps->client,
803 TPS_LED1_PER + offs));
807 804
808 up(&the_tps->lock); 805 up(&the_tps->lock);
809 806
@@ -874,7 +871,7 @@ int tps65010_set_low_pwr(unsigned mode)
874 871
875 if (status != 0) 872 if (status != 0)
876 printk(KERN_ERR "%s: Failed to write vdcdc1 register\n", 873 printk(KERN_ERR "%s: Failed to write vdcdc1 register\n",
877 DRIVER_NAME); 874 DRIVER_NAME);
878 else 875 else
879 pr_debug("%s: vdcdc1 0x%02x\n", DRIVER_NAME, 876 pr_debug("%s: vdcdc1 0x%02x\n", DRIVER_NAME,
880 i2c_smbus_read_byte_data(&the_tps->client, TPS_VDCDC1)); 877 i2c_smbus_read_byte_data(&the_tps->client, TPS_VDCDC1));
@@ -900,14 +897,14 @@ int tps65010_config_vregs1(unsigned value)
900 down(&the_tps->lock); 897 down(&the_tps->lock);
901 898
902 pr_debug("%s: vregs1 0x%02x\n", DRIVER_NAME, 899 pr_debug("%s: vregs1 0x%02x\n", DRIVER_NAME,
903 i2c_smbus_read_byte_data(&the_tps->client, TPS_VREGS1)); 900 i2c_smbus_read_byte_data(&the_tps->client, TPS_VREGS1));
904 901
905 status = i2c_smbus_write_byte_data(&the_tps->client, 902 status = i2c_smbus_write_byte_data(&the_tps->client,
906 TPS_VREGS1, value); 903 TPS_VREGS1, value);
907 904
908 if (status != 0) 905 if (status != 0)
909 printk(KERN_ERR "%s: Failed to write vregs1 register\n", 906 printk(KERN_ERR "%s: Failed to write vregs1 register\n",
910 DRIVER_NAME); 907 DRIVER_NAME);
911 else 908 else
912 pr_debug("%s: vregs1 0x%02x\n", DRIVER_NAME, 909 pr_debug("%s: vregs1 0x%02x\n", DRIVER_NAME,
913 i2c_smbus_read_byte_data(&the_tps->client, TPS_VREGS1)); 910 i2c_smbus_read_byte_data(&the_tps->client, TPS_VREGS1));
@@ -1009,7 +1006,7 @@ static int __init tps_init(void)
1009 msleep(10); 1006 msleep(10);
1010 } 1007 }
1011 1008
1012#if defined(CONFIG_ARM) 1009#ifdef CONFIG_ARM
1013 if (machine_is_omap_osk()) { 1010 if (machine_is_omap_osk()) {
1014 1011
1015 // FIXME: More should be placed in the initialization code 1012 // FIXME: More should be placed in the initialization code
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 51ce268998cd..4fd4f52c8e9b 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -156,7 +156,7 @@ int i2c_add_adapter(struct i2c_adapter *adap)
156 goto out_unlock; 156 goto out_unlock;
157 } 157 }
158 158
159 res = idr_get_new(&i2c_adapter_idr, NULL, &id); 159 res = idr_get_new(&i2c_adapter_idr, adap, &id);
160 if (res < 0) { 160 if (res < 0) {
161 if (res == -EAGAIN) 161 if (res == -EAGAIN)
162 res = -ENOMEM; 162 res = -ENOMEM;
@@ -765,20 +765,15 @@ int i2c_adapter_id(struct i2c_adapter *adap)
765 765
766struct i2c_adapter* i2c_get_adapter(int id) 766struct i2c_adapter* i2c_get_adapter(int id)
767{ 767{
768 struct list_head *item;
769 struct i2c_adapter *adapter; 768 struct i2c_adapter *adapter;
770 769
771 down(&core_lists); 770 down(&core_lists);
772 list_for_each(item,&adapters) { 771 adapter = (struct i2c_adapter *)idr_find(&i2c_adapter_idr, id);
773 adapter = list_entry(item, struct i2c_adapter, list); 772 if (adapter && !try_module_get(adapter->owner))
774 if (id == adapter->nr && 773 adapter = NULL;
775 try_module_get(adapter->owner)) { 774
776 up(&core_lists);
777 return adapter;
778 }
779 }
780 up(&core_lists); 775 up(&core_lists);
781 return NULL; 776 return adapter;
782} 777}
783 778
784void i2c_put_adapter(struct i2c_adapter *adap) 779void i2c_put_adapter(struct i2c_adapter *adap)
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
index 0a31cfda08a0..74af7e074868 100644
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -431,7 +431,7 @@ void cdrom_analyze_sense_data(ide_drive_t *drive,
431#if VERBOSE_IDE_CD_ERRORS 431#if VERBOSE_IDE_CD_ERRORS
432 { 432 {
433 int i; 433 int i;
434 const char *s; 434 const char *s = "bad sense key!";
435 char buf[80]; 435 char buf[80];
436 436
437 printk ("ATAPI device %s:\n", drive->name); 437 printk ("ATAPI device %s:\n", drive->name);
@@ -446,8 +446,6 @@ void cdrom_analyze_sense_data(ide_drive_t *drive,
446 446
447 if (sense->sense_key < ARY_LEN(sense_key_texts)) 447 if (sense->sense_key < ARY_LEN(sense_key_texts))
448 s = sense_key_texts[sense->sense_key]; 448 s = sense_key_texts[sense->sense_key];
449 else
450 s = "bad sense key!";
451 449
452 printk("%s -- (Sense key=0x%02x)\n", s, sense->sense_key); 450 printk("%s -- (Sense key=0x%02x)\n", s, sense->sense_key);
453 451
diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c
index 0c1b8520ef86..785806bdb248 100644
--- a/drivers/md/dm-mpath.c
+++ b/drivers/md/dm-mpath.c
@@ -63,6 +63,7 @@ struct multipath {
63 unsigned nr_priority_groups; 63 unsigned nr_priority_groups;
64 struct list_head priority_groups; 64 struct list_head priority_groups;
65 unsigned pg_init_required; /* pg_init needs calling? */ 65 unsigned pg_init_required; /* pg_init needs calling? */
66 unsigned pg_init_in_progress; /* Only one pg_init allowed at once */
66 67
67 unsigned nr_valid_paths; /* Total number of usable paths */ 68 unsigned nr_valid_paths; /* Total number of usable paths */
68 struct pgpath *current_pgpath; 69 struct pgpath *current_pgpath;
@@ -72,7 +73,7 @@ struct multipath {
72 73
73 unsigned queue_io; /* Must we queue all I/O? */ 74 unsigned queue_io; /* Must we queue all I/O? */
74 unsigned queue_if_no_path; /* Queue I/O if last path fails? */ 75 unsigned queue_if_no_path; /* Queue I/O if last path fails? */
75 unsigned suspended; /* Has dm core suspended our I/O? */ 76 unsigned saved_queue_if_no_path;/* Saved state during suspension */
76 77
77 struct work_struct process_queued_ios; 78 struct work_struct process_queued_ios;
78 struct bio_list queued_ios; 79 struct bio_list queued_ios;
@@ -304,11 +305,12 @@ static int map_io(struct multipath *m, struct bio *bio, struct mpath_io *mpio,
304 m->queue_size--; 305 m->queue_size--;
305 306
306 if ((pgpath && m->queue_io) || 307 if ((pgpath && m->queue_io) ||
307 (!pgpath && m->queue_if_no_path && !m->suspended)) { 308 (!pgpath && m->queue_if_no_path)) {
308 /* Queue for the daemon to resubmit */ 309 /* Queue for the daemon to resubmit */
309 bio_list_add(&m->queued_ios, bio); 310 bio_list_add(&m->queued_ios, bio);
310 m->queue_size++; 311 m->queue_size++;
311 if (m->pg_init_required || !m->queue_io) 312 if ((m->pg_init_required && !m->pg_init_in_progress) ||
313 !m->queue_io)
312 queue_work(kmultipathd, &m->process_queued_ios); 314 queue_work(kmultipathd, &m->process_queued_ios);
313 pgpath = NULL; 315 pgpath = NULL;
314 r = 0; 316 r = 0;
@@ -333,8 +335,9 @@ static int queue_if_no_path(struct multipath *m, unsigned queue_if_no_path)
333 335
334 spin_lock_irqsave(&m->lock, flags); 336 spin_lock_irqsave(&m->lock, flags);
335 337
338 m->saved_queue_if_no_path = m->queue_if_no_path;
336 m->queue_if_no_path = queue_if_no_path; 339 m->queue_if_no_path = queue_if_no_path;
337 if (!m->queue_if_no_path) 340 if (!m->queue_if_no_path && m->queue_size)
338 queue_work(kmultipathd, &m->process_queued_ios); 341 queue_work(kmultipathd, &m->process_queued_ios);
339 342
340 spin_unlock_irqrestore(&m->lock, flags); 343 spin_unlock_irqrestore(&m->lock, flags);
@@ -379,25 +382,31 @@ static void process_queued_ios(void *data)
379{ 382{
380 struct multipath *m = (struct multipath *) data; 383 struct multipath *m = (struct multipath *) data;
381 struct hw_handler *hwh = &m->hw_handler; 384 struct hw_handler *hwh = &m->hw_handler;
382 struct pgpath *pgpath; 385 struct pgpath *pgpath = NULL;
383 unsigned init_required, must_queue = 0; 386 unsigned init_required = 0, must_queue = 1;
384 unsigned long flags; 387 unsigned long flags;
385 388
386 spin_lock_irqsave(&m->lock, flags); 389 spin_lock_irqsave(&m->lock, flags);
387 390
391 if (!m->queue_size)
392 goto out;
393
388 if (!m->current_pgpath) 394 if (!m->current_pgpath)
389 __choose_pgpath(m); 395 __choose_pgpath(m);
390 396
391 pgpath = m->current_pgpath; 397 pgpath = m->current_pgpath;
392 398
393 if ((pgpath && m->queue_io) || 399 if ((pgpath && !m->queue_io) ||
394 (!pgpath && m->queue_if_no_path && !m->suspended)) 400 (!pgpath && !m->queue_if_no_path))
395 must_queue = 1; 401 must_queue = 0;
396 402
397 init_required = m->pg_init_required; 403 if (m->pg_init_required && !m->pg_init_in_progress) {
398 if (init_required)
399 m->pg_init_required = 0; 404 m->pg_init_required = 0;
405 m->pg_init_in_progress = 1;
406 init_required = 1;
407 }
400 408
409out:
401 spin_unlock_irqrestore(&m->lock, flags); 410 spin_unlock_irqrestore(&m->lock, flags);
402 411
403 if (init_required) 412 if (init_required)
@@ -752,6 +761,8 @@ static int multipath_ctr(struct dm_target *ti, unsigned int argc,
752static void multipath_dtr(struct dm_target *ti) 761static void multipath_dtr(struct dm_target *ti)
753{ 762{
754 struct multipath *m = (struct multipath *) ti->private; 763 struct multipath *m = (struct multipath *) ti->private;
764
765 flush_workqueue(kmultipathd);
755 free_multipath(m); 766 free_multipath(m);
756} 767}
757 768
@@ -765,6 +776,9 @@ static int multipath_map(struct dm_target *ti, struct bio *bio,
765 struct mpath_io *mpio; 776 struct mpath_io *mpio;
766 struct multipath *m = (struct multipath *) ti->private; 777 struct multipath *m = (struct multipath *) ti->private;
767 778
779 if (bio_barrier(bio))
780 return -EOPNOTSUPP;
781
768 mpio = mempool_alloc(m->mpio_pool, GFP_NOIO); 782 mpio = mempool_alloc(m->mpio_pool, GFP_NOIO);
769 dm_bio_record(&mpio->details, bio); 783 dm_bio_record(&mpio->details, bio);
770 784
@@ -837,7 +851,7 @@ static int reinstate_path(struct pgpath *pgpath)
837 pgpath->path.is_active = 1; 851 pgpath->path.is_active = 1;
838 852
839 m->current_pgpath = NULL; 853 m->current_pgpath = NULL;
840 if (!m->nr_valid_paths++) 854 if (!m->nr_valid_paths++ && m->queue_size)
841 queue_work(kmultipathd, &m->process_queued_ios); 855 queue_work(kmultipathd, &m->process_queued_ios);
842 856
843 queue_work(kmultipathd, &m->trigger_event); 857 queue_work(kmultipathd, &m->trigger_event);
@@ -963,12 +977,13 @@ void dm_pg_init_complete(struct path *path, unsigned err_flags)
963 bypass_pg(m, pg, 1); 977 bypass_pg(m, pg, 1);
964 978
965 spin_lock_irqsave(&m->lock, flags); 979 spin_lock_irqsave(&m->lock, flags);
966 if (!err_flags) 980 if (err_flags) {
967 m->queue_io = 0;
968 else {
969 m->current_pgpath = NULL; 981 m->current_pgpath = NULL;
970 m->current_pg = NULL; 982 m->current_pg = NULL;
971 } 983 } else if (!m->pg_init_required)
984 m->queue_io = 0;
985
986 m->pg_init_in_progress = 0;
972 queue_work(kmultipathd, &m->process_queued_ios); 987 queue_work(kmultipathd, &m->process_queued_ios);
973 spin_unlock_irqrestore(&m->lock, flags); 988 spin_unlock_irqrestore(&m->lock, flags);
974} 989}
@@ -988,9 +1003,12 @@ static int do_end_io(struct multipath *m, struct bio *bio,
988 if ((error == -EWOULDBLOCK) && bio_rw_ahead(bio)) 1003 if ((error == -EWOULDBLOCK) && bio_rw_ahead(bio))
989 return error; 1004 return error;
990 1005
1006 if (error == -EOPNOTSUPP)
1007 return error;
1008
991 spin_lock(&m->lock); 1009 spin_lock(&m->lock);
992 if (!m->nr_valid_paths) { 1010 if (!m->nr_valid_paths) {
993 if (!m->queue_if_no_path || m->suspended) { 1011 if (!m->queue_if_no_path) {
994 spin_unlock(&m->lock); 1012 spin_unlock(&m->lock);
995 return -EIO; 1013 return -EIO;
996 } else { 1014 } else {
@@ -1051,27 +1069,27 @@ static int multipath_end_io(struct dm_target *ti, struct bio *bio,
1051 1069
1052/* 1070/*
1053 * Suspend can't complete until all the I/O is processed so if 1071 * Suspend can't complete until all the I/O is processed so if
1054 * the last path failed we will now error any queued I/O. 1072 * the last path fails we must error any remaining I/O.
1073 * Note that if the freeze_bdev fails while suspending, the
1074 * queue_if_no_path state is lost - userspace should reset it.
1055 */ 1075 */
1056static void multipath_presuspend(struct dm_target *ti) 1076static void multipath_presuspend(struct dm_target *ti)
1057{ 1077{
1058 struct multipath *m = (struct multipath *) ti->private; 1078 struct multipath *m = (struct multipath *) ti->private;
1059 unsigned long flags;
1060 1079
1061 spin_lock_irqsave(&m->lock, flags); 1080 queue_if_no_path(m, 0);
1062 m->suspended = 1;
1063 if (m->queue_if_no_path)
1064 queue_work(kmultipathd, &m->process_queued_ios);
1065 spin_unlock_irqrestore(&m->lock, flags);
1066} 1081}
1067 1082
1083/*
1084 * Restore the queue_if_no_path setting.
1085 */
1068static void multipath_resume(struct dm_target *ti) 1086static void multipath_resume(struct dm_target *ti)
1069{ 1087{
1070 struct multipath *m = (struct multipath *) ti->private; 1088 struct multipath *m = (struct multipath *) ti->private;
1071 unsigned long flags; 1089 unsigned long flags;
1072 1090
1073 spin_lock_irqsave(&m->lock, flags); 1091 spin_lock_irqsave(&m->lock, flags);
1074 m->suspended = 0; 1092 m->queue_if_no_path = m->saved_queue_if_no_path;
1075 spin_unlock_irqrestore(&m->lock, flags); 1093 spin_unlock_irqrestore(&m->lock, flags);
1076} 1094}
1077 1095
diff --git a/drivers/md/dm-snap.c b/drivers/md/dm-snap.c
index 7e691ab9a748..ab54f99b7c3b 100644
--- a/drivers/md/dm-snap.c
+++ b/drivers/md/dm-snap.c
@@ -777,7 +777,7 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio,
777 777
778 /* Full snapshots are not usable */ 778 /* Full snapshots are not usable */
779 if (!s->valid) 779 if (!s->valid)
780 return -1; 780 return -EIO;
781 781
782 /* 782 /*
783 * Write to snapshot - higher level takes care of RW/RO 783 * Write to snapshot - higher level takes care of RW/RO
@@ -931,6 +931,10 @@ static int __origin_write(struct list_head *snapshots, struct bio *bio)
931 if (!snap->valid) 931 if (!snap->valid)
932 continue; 932 continue;
933 933
934 /* Nothing to do if writing beyond end of snapshot */
935 if (bio->bi_sector >= dm_table_get_size(snap->table))
936 continue;
937
934 down_write(&snap->lock); 938 down_write(&snap->lock);
935 939
936 /* 940 /*
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index 18e9b9953fcd..a5a4c0ed8a14 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -943,6 +943,7 @@ EXPORT_SYMBOL(dm_vcalloc);
943EXPORT_SYMBOL(dm_get_device); 943EXPORT_SYMBOL(dm_get_device);
944EXPORT_SYMBOL(dm_put_device); 944EXPORT_SYMBOL(dm_put_device);
945EXPORT_SYMBOL(dm_table_event); 945EXPORT_SYMBOL(dm_table_event);
946EXPORT_SYMBOL(dm_table_get_size);
946EXPORT_SYMBOL(dm_table_get_mode); 947EXPORT_SYMBOL(dm_table_get_mode);
947EXPORT_SYMBOL(dm_table_put); 948EXPORT_SYMBOL(dm_table_put);
948EXPORT_SYMBOL(dm_table_get); 949EXPORT_SYMBOL(dm_table_get);
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index f6b03957efc7..54fabbf06678 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -384,7 +384,7 @@ static void __map_bio(struct dm_target *ti, struct bio *clone,
384 /* error the io and bail out */ 384 /* error the io and bail out */
385 struct dm_io *io = tio->io; 385 struct dm_io *io = tio->io;
386 free_tio(tio->io->md, tio); 386 free_tio(tio->io->md, tio);
387 dec_pending(io, -EIO); 387 dec_pending(io, r);
388 bio_put(clone); 388 bio_put(clone);
389 } 389 }
390} 390}
@@ -966,23 +966,20 @@ static void __flush_deferred_io(struct mapped_device *md, struct bio *c)
966 */ 966 */
967int dm_swap_table(struct mapped_device *md, struct dm_table *table) 967int dm_swap_table(struct mapped_device *md, struct dm_table *table)
968{ 968{
969 int r; 969 int r = -EINVAL;
970 970
971 down_write(&md->lock); 971 down_write(&md->lock);
972 972
973 /* device must be suspended */ 973 /* device must be suspended */
974 if (!test_bit(DMF_SUSPENDED, &md->flags)) { 974 if (!test_bit(DMF_SUSPENDED, &md->flags))
975 up_write(&md->lock); 975 goto out;
976 return -EPERM;
977 }
978 976
979 __unbind(md); 977 __unbind(md);
980 r = __bind(md, table); 978 r = __bind(md, table);
981 if (r)
982 return r;
983 979
980out:
984 up_write(&md->lock); 981 up_write(&md->lock);
985 return 0; 982 return r;
986} 983}
987 984
988/* 985/*
@@ -1055,14 +1052,17 @@ int dm_suspend(struct mapped_device *md)
1055 if (test_bit(DMF_BLOCK_IO, &md->flags)) 1052 if (test_bit(DMF_BLOCK_IO, &md->flags))
1056 goto out_read_unlock; 1053 goto out_read_unlock;
1057 1054
1058 error = __lock_fs(md);
1059 if (error)
1060 goto out_read_unlock;
1061
1062 map = dm_get_table(md); 1055 map = dm_get_table(md);
1063 if (map) 1056 if (map)
1057 /* This does not get reverted if there's an error later. */
1064 dm_table_presuspend_targets(map); 1058 dm_table_presuspend_targets(map);
1065 1059
1060 error = __lock_fs(md);
1061 if (error) {
1062 dm_table_put(map);
1063 goto out_read_unlock;
1064 }
1065
1066 up_read(&md->lock); 1066 up_read(&md->lock);
1067 1067
1068 /* 1068 /*
@@ -1121,7 +1121,6 @@ int dm_suspend(struct mapped_device *md)
1121 return 0; 1121 return 0;
1122 1122
1123out_unfreeze: 1123out_unfreeze:
1124 /* FIXME Undo dm_table_presuspend_targets */
1125 __unlock_fs(md); 1124 __unlock_fs(md);
1126 clear_bit(DMF_BLOCK_IO, &md->flags); 1125 clear_bit(DMF_BLOCK_IO, &md->flags);
1127out_write_unlock: 1126out_write_unlock:
diff --git a/drivers/media/common/ir-common.c b/drivers/media/common/ir-common.c
index 4adb2843f8be..ab7a1fba4427 100644
--- a/drivers/media/common/ir-common.c
+++ b/drivers/media/common/ir-common.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: ir-common.c,v 1.10 2005/05/22 19:23:39 nsh Exp $ 2 * $Id: ir-common.c,v 1.11 2005/07/07 14:44:43 mchehab Exp $
3 * 3 *
4 * some common structs and functions to handle infrared remotes via 4 * some common structs and functions to handle infrared remotes via
5 * input layer ... 5 * input layer ...
@@ -46,79 +46,49 @@ module_param(debug, int, 0644);
46/* see http://users.pandora.be/nenya/electronics/rc5/codes00.htm */ 46/* see http://users.pandora.be/nenya/electronics/rc5/codes00.htm */
47/* used by old (black) Hauppauge remotes */ 47/* used by old (black) Hauppauge remotes */
48IR_KEYTAB_TYPE ir_codes_rc5_tv[IR_KEYTAB_SIZE] = { 48IR_KEYTAB_TYPE ir_codes_rc5_tv[IR_KEYTAB_SIZE] = {
49 [ 0x00 ] = KEY_KP0, // 0 49 /* Keys 0 to 9 */
50 [ 0x01 ] = KEY_KP1, // 1 50 [ 0x00 ] = KEY_KP0,
51 [ 0x02 ] = KEY_KP2, // 2 51 [ 0x01 ] = KEY_KP1,
52 [ 0x03 ] = KEY_KP3, // 3 52 [ 0x02 ] = KEY_KP2,
53 [ 0x04 ] = KEY_KP4, // 4 53 [ 0x03 ] = KEY_KP3,
54 [ 0x05 ] = KEY_KP5, // 5 54 [ 0x04 ] = KEY_KP4,
55 [ 0x06 ] = KEY_KP6, // 6 55 [ 0x05 ] = KEY_KP5,
56 [ 0x07 ] = KEY_KP7, // 7 56 [ 0x06 ] = KEY_KP6,
57 [ 0x08 ] = KEY_KP8, // 8 57 [ 0x07 ] = KEY_KP7,
58 [ 0x09 ] = KEY_KP9, // 9 58 [ 0x08 ] = KEY_KP8,
59 59 [ 0x09 ] = KEY_KP9,
60 [ 0x0b ] = KEY_CHANNEL, // channel / program (japan: 11) 60
61 [ 0x0c ] = KEY_POWER, // standby 61 [ 0x0b ] = KEY_CHANNEL, /* channel / program (japan: 11) */
62 [ 0x0d ] = KEY_MUTE, // mute / demute 62 [ 0x0c ] = KEY_POWER, /* standby */
63 [ 0x0f ] = KEY_TV, // display 63 [ 0x0d ] = KEY_MUTE, /* mute / demute */
64 [ 0x10 ] = KEY_VOLUMEUP, // volume + 64 [ 0x0f ] = KEY_TV, /* display */
65 [ 0x11 ] = KEY_VOLUMEDOWN, // volume - 65 [ 0x10 ] = KEY_VOLUMEUP,
66 [ 0x12 ] = KEY_BRIGHTNESSUP, // brightness + 66 [ 0x11 ] = KEY_VOLUMEDOWN,
67 [ 0x13 ] = KEY_BRIGHTNESSDOWN, // brightness - 67 [ 0x12 ] = KEY_BRIGHTNESSUP,
68 [ 0x1e ] = KEY_SEARCH, // search + 68 [ 0x13 ] = KEY_BRIGHTNESSDOWN,
69 [ 0x20 ] = KEY_CHANNELUP, // channel / program + 69 [ 0x1e ] = KEY_SEARCH, /* search + */
70 [ 0x21 ] = KEY_CHANNELDOWN, // channel / program - 70 [ 0x20 ] = KEY_CHANNELUP, /* channel / program + */
71 [ 0x22 ] = KEY_CHANNEL, // alt / channel 71 [ 0x21 ] = KEY_CHANNELDOWN, /* channel / program - */
72 [ 0x23 ] = KEY_LANGUAGE, // 1st / 2nd language 72 [ 0x22 ] = KEY_CHANNEL, /* alt / channel */
73 [ 0x26 ] = KEY_SLEEP, // sleeptimer 73 [ 0x23 ] = KEY_LANGUAGE, /* 1st / 2nd language */
74 [ 0x2e ] = KEY_MENU, // 2nd controls (USA: menu) 74 [ 0x26 ] = KEY_SLEEP, /* sleeptimer */
75 [ 0x30 ] = KEY_PAUSE, // pause 75 [ 0x2e ] = KEY_MENU, /* 2nd controls (USA: menu) */
76 [ 0x32 ] = KEY_REWIND, // rewind 76 [ 0x30 ] = KEY_PAUSE,
77 [ 0x33 ] = KEY_GOTO, // go to 77 [ 0x32 ] = KEY_REWIND,
78 [ 0x35 ] = KEY_PLAY, // play 78 [ 0x33 ] = KEY_GOTO,
79 [ 0x36 ] = KEY_STOP, // stop 79 [ 0x35 ] = KEY_PLAY,
80 [ 0x37 ] = KEY_RECORD, // recording 80 [ 0x36 ] = KEY_STOP,
81 [ 0x3c ] = KEY_TEXT, // teletext submode (Japan: 12) 81 [ 0x37 ] = KEY_RECORD, /* recording */
82 [ 0x3d ] = KEY_SUSPEND, // system standby 82 [ 0x3c ] = KEY_TEXT, /* teletext submode (Japan: 12) */
83 83 [ 0x3d ] = KEY_SUSPEND, /* system standby */
84#if 0 /* FIXME */ 84
85 [ 0x0a ] = KEY_RESERVED, // 1/2/3 digits (japan: 10)
86 [ 0x0e ] = KEY_RESERVED, // P.P. (personal preference)
87 [ 0x14 ] = KEY_RESERVED, // colour saturation +
88 [ 0x15 ] = KEY_RESERVED, // colour saturation -
89 [ 0x16 ] = KEY_RESERVED, // bass +
90 [ 0x17 ] = KEY_RESERVED, // bass -
91 [ 0x18 ] = KEY_RESERVED, // treble +
92 [ 0x19 ] = KEY_RESERVED, // treble -
93 [ 0x1a ] = KEY_RESERVED, // balance right
94 [ 0x1b ] = KEY_RESERVED, // balance left
95 [ 0x1c ] = KEY_RESERVED, // contrast +
96 [ 0x1d ] = KEY_RESERVED, // contrast -
97 [ 0x1f ] = KEY_RESERVED, // tint/hue +
98 [ 0x24 ] = KEY_RESERVED, // spacial stereo on/off
99 [ 0x25 ] = KEY_RESERVED, // mono / stereo (USA)
100 [ 0x27 ] = KEY_RESERVED, // tint / hue -
101 [ 0x28 ] = KEY_RESERVED, // RF switch/PIP select
102 [ 0x29 ] = KEY_RESERVED, // vote
103 [ 0x2a ] = KEY_RESERVED, // timed page/channel clck
104 [ 0x2b ] = KEY_RESERVED, // increment (USA)
105 [ 0x2c ] = KEY_RESERVED, // decrement (USA)
106 [ 0x2d ] = KEY_RESERVED, //
107 [ 0x2f ] = KEY_RESERVED, // PIP shift
108 [ 0x31 ] = KEY_RESERVED, // erase
109 [ 0x34 ] = KEY_RESERVED, // wind
110 [ 0x38 ] = KEY_RESERVED, // external 1
111 [ 0x39 ] = KEY_RESERVED, // external 2
112 [ 0x3a ] = KEY_RESERVED, // PIP display mode
113 [ 0x3b ] = KEY_RESERVED, // view data mode / advance
114 [ 0x3e ] = KEY_RESERVED, // crispener on/off
115 [ 0x3f ] = KEY_RESERVED, // system select
116#endif
117}; 85};
118EXPORT_SYMBOL_GPL(ir_codes_rc5_tv); 86EXPORT_SYMBOL_GPL(ir_codes_rc5_tv);
119 87
120/* Table for Leadtek Winfast Remote Controls - used by both bttv and cx88 */ 88/* Table for Leadtek Winfast Remote Controls - used by both bttv and cx88 */
121IR_KEYTAB_TYPE ir_codes_winfast[IR_KEYTAB_SIZE] = { 89IR_KEYTAB_TYPE ir_codes_winfast[IR_KEYTAB_SIZE] = {
90 /* Keys 0 to 9 */
91 [ 18 ] = KEY_KP0,
122 [ 5 ] = KEY_KP1, 92 [ 5 ] = KEY_KP1,
123 [ 6 ] = KEY_KP2, 93 [ 6 ] = KEY_KP2,
124 [ 7 ] = KEY_KP3, 94 [ 7 ] = KEY_KP3,
@@ -128,39 +98,31 @@ IR_KEYTAB_TYPE ir_codes_winfast[IR_KEYTAB_SIZE] = {
128 [ 13 ] = KEY_KP7, 98 [ 13 ] = KEY_KP7,
129 [ 14 ] = KEY_KP8, 99 [ 14 ] = KEY_KP8,
130 [ 15 ] = KEY_KP9, 100 [ 15 ] = KEY_KP9,
131 [ 18 ] = KEY_KP0,
132 101
133 [ 0 ] = KEY_POWER, 102 [ 0 ] = KEY_POWER,
134// [ 27 ] = MTS button 103 [ 2 ] = KEY_TUNER, /* TV/FM */
135 [ 2 ] = KEY_TUNER, // TV/FM
136 [ 30 ] = KEY_VIDEO, 104 [ 30 ] = KEY_VIDEO,
137// [ 22 ] = display button
138 [ 4 ] = KEY_VOLUMEUP, 105 [ 4 ] = KEY_VOLUMEUP,
139 [ 8 ] = KEY_VOLUMEDOWN, 106 [ 8 ] = KEY_VOLUMEDOWN,
140 [ 12 ] = KEY_CHANNELUP, 107 [ 12 ] = KEY_CHANNELUP,
141 [ 16 ] = KEY_CHANNELDOWN, 108 [ 16 ] = KEY_CHANNELDOWN,
142 [ 3 ] = KEY_ZOOM, // fullscreen 109 [ 3 ] = KEY_ZOOM, /* fullscreen */
143 [ 31 ] = KEY_SUBTITLE, // closed caption/teletext 110 [ 31 ] = KEY_SUBTITLE, /* closed caption/teletext */
144 [ 32 ] = KEY_SLEEP, 111 [ 32 ] = KEY_SLEEP,
145// [ 41 ] = boss key
146 [ 20 ] = KEY_MUTE, 112 [ 20 ] = KEY_MUTE,
147 [ 43 ] = KEY_RED, 113 [ 43 ] = KEY_RED,
148 [ 44 ] = KEY_GREEN, 114 [ 44 ] = KEY_GREEN,
149 [ 45 ] = KEY_YELLOW, 115 [ 45 ] = KEY_YELLOW,
150 [ 46 ] = KEY_BLUE, 116 [ 46 ] = KEY_BLUE,
151 [ 24 ] = KEY_KPPLUS, //fine tune + 117 [ 24 ] = KEY_KPPLUS, /* fine tune + */
152 [ 25 ] = KEY_KPMINUS, //fine tune - 118 [ 25 ] = KEY_KPMINUS, /* fine tune - */
153// [ 42 ] = picture in picture
154 [ 33 ] = KEY_KPDOT, 119 [ 33 ] = KEY_KPDOT,
155 [ 19 ] = KEY_KPENTER, 120 [ 19 ] = KEY_KPENTER,
156// [ 17 ] = recall
157 [ 34 ] = KEY_BACK, 121 [ 34 ] = KEY_BACK,
158 [ 35 ] = KEY_PLAYPAUSE, 122 [ 35 ] = KEY_PLAYPAUSE,
159 [ 36 ] = KEY_NEXT, 123 [ 36 ] = KEY_NEXT,
160// [ 37 ] = time shifting
161 [ 38 ] = KEY_STOP, 124 [ 38 ] = KEY_STOP,
162 [ 39 ] = KEY_RECORD 125 [ 39 ] = KEY_RECORD
163// [ 40 ] = snapshot
164}; 126};
165EXPORT_SYMBOL_GPL(ir_codes_winfast); 127EXPORT_SYMBOL_GPL(ir_codes_winfast);
166 128
@@ -174,54 +136,61 @@ EXPORT_SYMBOL_GPL(ir_codes_empty);
174 * slightly different versions), shipped with cx88+ivtv cards. 136 * slightly different versions), shipped with cx88+ivtv cards.
175 * almost rc5 coding, but some non-standard keys */ 137 * almost rc5 coding, but some non-standard keys */
176IR_KEYTAB_TYPE ir_codes_hauppauge_new[IR_KEYTAB_SIZE] = { 138IR_KEYTAB_TYPE ir_codes_hauppauge_new[IR_KEYTAB_SIZE] = {
177 [ 0x00 ] = KEY_KP0, // 0 139 /* Keys 0 to 9 */
178 [ 0x01 ] = KEY_KP1, // 1 140 [ 0x00 ] = KEY_KP0,
179 [ 0x02 ] = KEY_KP2, // 2 141 [ 0x01 ] = KEY_KP1,
180 [ 0x03 ] = KEY_KP3, // 3 142 [ 0x02 ] = KEY_KP2,
181 [ 0x04 ] = KEY_KP4, // 4 143 [ 0x03 ] = KEY_KP3,
182 [ 0x05 ] = KEY_KP5, // 5 144 [ 0x04 ] = KEY_KP4,
183 [ 0x06 ] = KEY_KP6, // 6 145 [ 0x05 ] = KEY_KP5,
184 [ 0x07 ] = KEY_KP7, // 7 146 [ 0x06 ] = KEY_KP6,
185 [ 0x08 ] = KEY_KP8, // 8 147 [ 0x07 ] = KEY_KP7,
186 [ 0x09 ] = KEY_KP9, // 9 148 [ 0x08 ] = KEY_KP8,
187 [ 0x0a ] = KEY_TEXT, // keypad asterisk as well 149 [ 0x09 ] = KEY_KP9,
188 [ 0x0b ] = KEY_RED, // red button 150
189 [ 0x0c ] = KEY_RADIO, // radio 151 [ 0x0a ] = KEY_TEXT, /* keypad asterisk as well */
190 [ 0x0d ] = KEY_MENU, // menu 152 [ 0x0b ] = KEY_RED, /* red button */
191 [ 0x0e ] = KEY_SUBTITLE, // also the # key 153 [ 0x0c ] = KEY_RADIO,
192 [ 0x0f ] = KEY_MUTE, // mute 154 [ 0x0d ] = KEY_MENU,
193 [ 0x10 ] = KEY_VOLUMEUP, // volume + 155 [ 0x0e ] = KEY_SUBTITLE, /* also the # key */
194 [ 0x11 ] = KEY_VOLUMEDOWN, // volume - 156 [ 0x0f ] = KEY_MUTE,
195 [ 0x12 ] = KEY_PREVIOUS, // previous channel 157 [ 0x10 ] = KEY_VOLUMEUP,
196 [ 0x14 ] = KEY_UP, // up 158 [ 0x11 ] = KEY_VOLUMEDOWN,
197 [ 0x15 ] = KEY_DOWN, // down 159 [ 0x12 ] = KEY_PREVIOUS, /* previous channel */
198 [ 0x16 ] = KEY_LEFT, // left 160 [ 0x14 ] = KEY_UP,
199 [ 0x17 ] = KEY_RIGHT, // right 161 [ 0x15 ] = KEY_DOWN,
200 [ 0x18 ] = KEY_VIDEO, // Videos 162 [ 0x16 ] = KEY_LEFT,
201 [ 0x19 ] = KEY_AUDIO, // Music 163 [ 0x17 ] = KEY_RIGHT,
202 [ 0x1a ] = KEY_MHP, // Pictures - presume this means "Multimedia Home Platform"- no "PICTURES" key in input.h 164 [ 0x18 ] = KEY_VIDEO, /* Videos */
203 [ 0x1b ] = KEY_EPG, // Guide 165 [ 0x19 ] = KEY_AUDIO, /* Music */
204 [ 0x1c ] = KEY_TV, // TV 166 /* 0x1a: Pictures - presume this means
205 [ 0x1e ] = KEY_NEXTSONG, // skip >| 167 "Multimedia Home Platform" -
206 [ 0x1f ] = KEY_EXIT, // back/exit 168 no "PICTURES" key in input.h
207 [ 0x20 ] = KEY_CHANNELUP, // channel / program + 169 */
208 [ 0x21 ] = KEY_CHANNELDOWN, // channel / program - 170 [ 0x1a ] = KEY_MHP,
209 [ 0x22 ] = KEY_CHANNEL, // source (old black remote) 171
210 [ 0x24 ] = KEY_PREVIOUSSONG, // replay |< 172 [ 0x1b ] = KEY_EPG, /* Guide */
211 [ 0x25 ] = KEY_ENTER, // OK 173 [ 0x1c ] = KEY_TV,
212 [ 0x26 ] = KEY_SLEEP, // minimize (old black remote) 174 [ 0x1e ] = KEY_NEXTSONG, /* skip >| */
213 [ 0x29 ] = KEY_BLUE, // blue key 175 [ 0x1f ] = KEY_EXIT, /* back/exit */
214 [ 0x2e ] = KEY_GREEN, // green button 176 [ 0x20 ] = KEY_CHANNELUP, /* channel / program + */
215 [ 0x30 ] = KEY_PAUSE, // pause 177 [ 0x21 ] = KEY_CHANNELDOWN, /* channel / program - */
216 [ 0x32 ] = KEY_REWIND, // backward << 178 [ 0x22 ] = KEY_CHANNEL, /* source (old black remote) */
217 [ 0x34 ] = KEY_FASTFORWARD, // forward >> 179 [ 0x24 ] = KEY_PREVIOUSSONG, /* replay |< */
218 [ 0x35 ] = KEY_PLAY, // play 180 [ 0x25 ] = KEY_ENTER, /* OK */
219 [ 0x36 ] = KEY_STOP, // stop 181 [ 0x26 ] = KEY_SLEEP, /* minimize (old black remote) */
220 [ 0x37 ] = KEY_RECORD, // recording 182 [ 0x29 ] = KEY_BLUE, /* blue key */
221 [ 0x38 ] = KEY_YELLOW, // yellow key 183 [ 0x2e ] = KEY_GREEN, /* green button */
222 [ 0x3b ] = KEY_SELECT, // top right button 184 [ 0x30 ] = KEY_PAUSE, /* pause */
223 [ 0x3c ] = KEY_ZOOM, // full 185 [ 0x32 ] = KEY_REWIND, /* backward << */
224 [ 0x3d ] = KEY_POWER, // system power (green button) 186 [ 0x34 ] = KEY_FASTFORWARD, /* forward >> */
187 [ 0x35 ] = KEY_PLAY,
188 [ 0x36 ] = KEY_STOP,
189 [ 0x37 ] = KEY_RECORD, /* recording */
190 [ 0x38 ] = KEY_YELLOW, /* yellow key */
191 [ 0x3b ] = KEY_SELECT, /* top right button */
192 [ 0x3c ] = KEY_ZOOM, /* full */
193 [ 0x3d ] = KEY_POWER, /* system power (green button) */
225}; 194};
226EXPORT_SYMBOL(ir_codes_hauppauge_new); 195EXPORT_SYMBOL(ir_codes_hauppauge_new);
227 196
@@ -237,9 +206,9 @@ IR_KEYTAB_TYPE ir_codes_pixelview[IR_KEYTAB_SIZE] = {
237 [ 10 ] = KEY_KP8, 206 [ 10 ] = KEY_KP8,
238 [ 18 ] = KEY_KP9, 207 [ 18 ] = KEY_KP9,
239 208
240 [ 3 ] = KEY_TUNER, // TV/FM 209 [ 3 ] = KEY_TUNER, /* TV/FM */
241 [ 7 ] = KEY_SEARCH, // scan 210 [ 7 ] = KEY_SEARCH, /* scan */
242 [ 28 ] = KEY_ZOOM, // full screen 211 [ 28 ] = KEY_ZOOM, /* full screen */
243 [ 30 ] = KEY_POWER, 212 [ 30 ] = KEY_POWER,
244 [ 23 ] = KEY_VOLUMEDOWN, 213 [ 23 ] = KEY_VOLUMEDOWN,
245 [ 31 ] = KEY_VOLUMEUP, 214 [ 31 ] = KEY_VOLUMEUP,
@@ -247,14 +216,14 @@ IR_KEYTAB_TYPE ir_codes_pixelview[IR_KEYTAB_SIZE] = {
247 [ 22 ] = KEY_CHANNELUP, 216 [ 22 ] = KEY_CHANNELUP,
248 [ 24 ] = KEY_MUTE, 217 [ 24 ] = KEY_MUTE,
249 218
250 [ 0 ] = KEY_LIST, // source 219 [ 0 ] = KEY_LIST, /* source */
251 [ 19 ] = KEY_INFO, // loop 220 [ 19 ] = KEY_INFO, /* loop */
252 [ 16 ] = KEY_LAST, // +100 221 [ 16 ] = KEY_LAST, /* +100 */
253 [ 13 ] = KEY_CLEAR, // reset 222 [ 13 ] = KEY_CLEAR, /* reset */
254 [ 12 ] = BTN_RIGHT, // fun++ 223 [ 12 ] = BTN_RIGHT, /* fun++ */
255 [ 4 ] = BTN_LEFT, // fun-- 224 [ 4 ] = BTN_LEFT, /* fun-- */
256 [ 14 ] = KEY_GOTO, // function 225 [ 14 ] = KEY_GOTO, /* function */
257 [ 15 ] = KEY_STOP, // freeze 226 [ 15 ] = KEY_STOP, /* freeze */
258}; 227};
259EXPORT_SYMBOL(ir_codes_pixelview); 228EXPORT_SYMBOL(ir_codes_pixelview);
260 229
@@ -321,10 +290,6 @@ void ir_input_keydown(struct input_dev *dev, struct ir_input_state *ir,
321 ir->keypressed = 1; 290 ir->keypressed = 1;
322 ir_input_key_event(dev,ir); 291 ir_input_key_event(dev,ir);
323 } 292 }
324#if 0
325 /* maybe do something like this ??? */
326 input_event(a, EV_IR, ir->ir_type, ir->ir_raw);
327#endif
328} 293}
329 294
330/* -------------------------------------------------------------------------- */ 295/* -------------------------------------------------------------------------- */
diff --git a/drivers/media/dvb/bt8xx/dst.c b/drivers/media/dvb/bt8xx/dst.c
index 9bd12832e3d9..07a0b0a968a6 100644
--- a/drivers/media/dvb/bt8xx/dst.c
+++ b/drivers/media/dvb/bt8xx/dst.c
@@ -928,7 +928,7 @@ static int dst_get_signal(struct dst_state* state)
928{ 928{
929 int retval; 929 int retval;
930 u8 get_signal[] = { 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb }; 930 u8 get_signal[] = { 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb };
931 printk("%s: Getting Signal strength and other parameters !!!!!!!!\n", __FUNCTION__); 931 dprintk("%s: Getting Signal strength and other parameters\n", __FUNCTION__);
932 if ((state->diseq_flags & ATTEMPT_TUNE) == 0) { 932 if ((state->diseq_flags & ATTEMPT_TUNE) == 0) {
933 state->decode_lock = state->decode_strength = state->decode_snr = 0; 933 state->decode_lock = state->decode_strength = state->decode_snr = 0;
934 return 0; 934 return 0;
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-dvb.c b/drivers/media/dvb/dvb-usb/dvb-usb-dvb.c
index bdd72f779707..3491ff40885c 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-dvb.c
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-dvb.c
@@ -175,7 +175,7 @@ static int dvb_usb_fe_sleep(struct dvb_frontend *fe)
175int dvb_usb_fe_init(struct dvb_usb_device* d) 175int dvb_usb_fe_init(struct dvb_usb_device* d)
176{ 176{
177 if (d->props.frontend_attach == NULL) { 177 if (d->props.frontend_attach == NULL) {
178 err("strange '%s' don't want to attach a frontend.",d->desc->name); 178 err("strange '%s' doesn't want to attach a frontend.",d->desc->name);
179 return 0; 179 return 0;
180 } 180 }
181 181
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-init.c b/drivers/media/dvb/dvb-usb/dvb-usb-init.c
index c3b3ae4f3ec7..65f0c095abc9 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-init.c
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-init.c
@@ -51,17 +51,17 @@ static int dvb_usb_init(struct dvb_usb_device *d)
51 51
52/* speed - when running at FULL speed we need a HW PID filter */ 52/* speed - when running at FULL speed we need a HW PID filter */
53 if (d->udev->speed == USB_SPEED_FULL && !(d->props.caps & DVB_USB_HAS_PID_FILTER)) { 53 if (d->udev->speed == USB_SPEED_FULL && !(d->props.caps & DVB_USB_HAS_PID_FILTER)) {
54 err("This USB2.0 device cannot be run on a USB1.1 port. (it lacks a HW PID filter)"); 54 err("This USB2.0 device cannot be run on a USB1.1 port. (it lacks a hardware PID filter)");
55 return -ENODEV; 55 return -ENODEV;
56 } 56 }
57 57
58 if ((d->udev->speed == USB_SPEED_FULL && d->props.caps & DVB_USB_HAS_PID_FILTER) || 58 if ((d->udev->speed == USB_SPEED_FULL && d->props.caps & DVB_USB_HAS_PID_FILTER) ||
59 (d->props.caps & DVB_USB_NEED_PID_FILTERING)) { 59 (d->props.caps & DVB_USB_NEED_PID_FILTERING)) {
60 info("will use the device's hw PID filter."); 60 info("will use the device's hardware PID filter (table count: %d).",d->props.pid_filter_count);
61 d->pid_filtering = 1; 61 d->pid_filtering = 1;
62 d->max_feed_count = d->props.pid_filter_count; 62 d->max_feed_count = d->props.pid_filter_count;
63 } else { 63 } else {
64 info("will pass the complete MPEG2 transport stream to the demuxer."); 64 info("will pass the complete MPEG2 transport stream to the software demuxer.");
65 d->pid_filtering = 0; 65 d->pid_filtering = 0;
66 d->max_feed_count = 255; 66 d->max_feed_count = 255;
67 } 67 }
diff --git a/drivers/media/dvb/dvb-usb/vp7045.c b/drivers/media/dvb/dvb-usb/vp7045.c
index 5adc5d69ec84..9ac95f54f9fc 100644
--- a/drivers/media/dvb/dvb-usb/vp7045.c
+++ b/drivers/media/dvb/dvb-usb/vp7045.c
@@ -128,7 +128,7 @@ static struct dvb_usb_rc_key vp7045_rc_keys[] = {
128 { 0x00, 0x0f, KEY_TEXT } /* Teletext */ 128 { 0x00, 0x0f, KEY_TEXT } /* Teletext */
129}; 129};
130 130
131static int vp7045_rc_query(struct dvb_usb_device *d, u32 *key_buf, int *state) 131static int vp7045_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
132{ 132{
133 u8 key; 133 u8 key;
134 int i; 134 int i;
@@ -144,7 +144,7 @@ static int vp7045_rc_query(struct dvb_usb_device *d, u32 *key_buf, int *state)
144 for (i = 0; i < sizeof(vp7045_rc_keys)/sizeof(struct dvb_usb_rc_key); i++) 144 for (i = 0; i < sizeof(vp7045_rc_keys)/sizeof(struct dvb_usb_rc_key); i++)
145 if (vp7045_rc_keys[i].data == key) { 145 if (vp7045_rc_keys[i].data == key) {
146 *state = REMOTE_KEY_PRESSED; 146 *state = REMOTE_KEY_PRESSED;
147 *key_buf = vp7045_rc_keys[i].event; 147 *event = vp7045_rc_keys[i].event;
148 break; 148 break;
149 } 149 }
150 return 0; 150 return 0;
diff --git a/drivers/media/dvb/frontends/lgdt3302.c b/drivers/media/dvb/frontends/lgdt3302.c
index 09c914256e49..2eea03d218cd 100644
--- a/drivers/media/dvb/frontends/lgdt3302.c
+++ b/drivers/media/dvb/frontends/lgdt3302.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: lgdt3302.c,v 1.5 2005/07/07 03:47:15 mkrufky Exp $
3 *
4 * Support for LGDT3302 (DViCO FustionHDTV 3 Gold) - VSB/QAM 2 * Support for LGDT3302 (DViCO FustionHDTV 3 Gold) - VSB/QAM
5 * 3 *
6 * Copyright (C) 2005 Wilson Michaels <wilsonmichaels@earthlink.net> 4 * Copyright (C) 2005 Wilson Michaels <wilsonmichaels@earthlink.net>
@@ -83,7 +81,10 @@ static int i2c_writebytes (struct lgdt3302_state* state,
83 81
84 if ((err = i2c_transfer(state->i2c, &msg, 1)) != 1) { 82 if ((err = i2c_transfer(state->i2c, &msg, 1)) != 1) {
85 printk(KERN_WARNING "lgdt3302: %s error (addr %02x <- %02x, err == %i)\n", __FUNCTION__, addr, buf[0], err); 83 printk(KERN_WARNING "lgdt3302: %s error (addr %02x <- %02x, err == %i)\n", __FUNCTION__, addr, buf[0], err);
86 return -EREMOTEIO; 84 if (err < 0)
85 return err;
86 else
87 return -EREMOTEIO;
87 } 88 }
88 } else { 89 } else {
89 u8 tmp[] = { buf[0], buf[1] }; 90 u8 tmp[] = { buf[0], buf[1] };
@@ -96,7 +97,10 @@ static int i2c_writebytes (struct lgdt3302_state* state,
96 tmp[1] = buf[i]; 97 tmp[1] = buf[i];
97 if ((err = i2c_transfer(state->i2c, &msg, 1)) != 1) { 98 if ((err = i2c_transfer(state->i2c, &msg, 1)) != 1) {
98 printk(KERN_WARNING "lgdt3302: %s error (addr %02x <- %02x, err == %i)\n", __FUNCTION__, addr, buf[0], err); 99 printk(KERN_WARNING "lgdt3302: %s error (addr %02x <- %02x, err == %i)\n", __FUNCTION__, addr, buf[0], err);
99 return -EREMOTEIO; 100 if (err < 0)
101 return err;
102 else
103 return -EREMOTEIO;
100 } 104 }
101 tmp[0]++; 105 tmp[0]++;
102 } 106 }
@@ -218,6 +222,8 @@ static int lgdt3302_set_parameters(struct dvb_frontend* fe,
218 222
219 /* Change only if we are actually changing the modulation */ 223 /* Change only if we are actually changing the modulation */
220 if (state->current_modulation != param->u.vsb.modulation) { 224 if (state->current_modulation != param->u.vsb.modulation) {
225 int value;
226
221 switch(param->u.vsb.modulation) { 227 switch(param->u.vsb.modulation) {
222 case VSB_8: 228 case VSB_8:
223 dprintk("%s: VSB_8 MODE\n", __FUNCTION__); 229 dprintk("%s: VSB_8 MODE\n", __FUNCTION__);
@@ -266,36 +272,29 @@ static int lgdt3302_set_parameters(struct dvb_frontend* fe,
266 i2c_writebytes(state, state->config->demod_address, 272 i2c_writebytes(state, state->config->demod_address,
267 demux_ctrl_cfg, sizeof(demux_ctrl_cfg)); 273 demux_ctrl_cfg, sizeof(demux_ctrl_cfg));
268 274
269 if (param->u.vsb.modulation == VSB_8) { 275 /* Change the value of NCOCTFV[25:0] of carrier
270 /* Initialization for VSB modes only */ 276 recovery center frequency register */
271 /* Change the value of NCOCTFV[25:0]of carrier 277 i2c_writebytes(state, state->config->demod_address,
272 recovery center frequency register for VSB */
273 i2c_writebytes(state, state->config->demod_address,
274 vsb_freq_cfg, sizeof(vsb_freq_cfg)); 278 vsb_freq_cfg, sizeof(vsb_freq_cfg));
275 } else { 279 /* Set the value of 'INLVTHD' register 0x2a/0x2c
276 /* Initialization for QAM modes only */ 280 to value from 'IFACC' register 0x39/0x3b -1 */
277 /* Set the value of 'INLVTHD' register 0x2a/0x2c 281 i2c_selectreadbytes(state, AGC_RFIF_ACC0,
278 to value from 'IFACC' register 0x39/0x3b -1 */ 282 &agc_delay_cfg[1], 3);
279 int value; 283 value = ((agc_delay_cfg[1] & 0x0f) << 8) | agc_delay_cfg[3];
280 i2c_selectreadbytes(state, AGC_RFIF_ACC0, 284 value = value -1;
281 &agc_delay_cfg[1], 3); 285 dprintk("%s IFACC -1 = 0x%03x\n", __FUNCTION__, value);
282 value = ((agc_delay_cfg[1] & 0x0f) << 8) | agc_delay_cfg[3]; 286 agc_delay_cfg[1] = (value >> 8) & 0x0f;
283 value = value -1; 287 agc_delay_cfg[2] = 0x00;
284 dprintk("%s IFACC -1 = 0x%03x\n", __FUNCTION__, value); 288 agc_delay_cfg[3] = value & 0xff;
285 agc_delay_cfg[1] = (value >> 8) & 0x0f; 289 i2c_writebytes(state, state->config->demod_address,
286 agc_delay_cfg[2] = 0x00; 290 agc_delay_cfg, sizeof(agc_delay_cfg));
287 agc_delay_cfg[3] = value & 0xff; 291
288 i2c_writebytes(state, state->config->demod_address, 292 /* Change the value of IAGCBW[15:8]
289 agc_delay_cfg, sizeof(agc_delay_cfg)); 293 of inner AGC loop filter bandwith */
290 294 i2c_writebytes(state, state->config->demod_address,
291 /* Change the value of IAGCBW[15:8] 295 agc_loop_cfg, sizeof(agc_loop_cfg));
292 of inner AGC loop filter bandwith */
293 i2c_writebytes(state, state->config->demod_address,
294 agc_loop_cfg, sizeof(agc_loop_cfg));
295 }
296 296
297 state->config->set_ts_params(fe, 0); 297 state->config->set_ts_params(fe, 0);
298 lgdt3302_SwReset(state);
299 state->current_modulation = param->u.vsb.modulation; 298 state->current_modulation = param->u.vsb.modulation;
300 } 299 }
301 300
@@ -311,11 +310,10 @@ static int lgdt3302_set_parameters(struct dvb_frontend* fe,
311 i2c_readbytes(state, state->config->pll_address, buf, 1); 310 i2c_readbytes(state, state->config->pll_address, buf, 1);
312 dprintk("%s: tuner status byte = 0x%02x\n", __FUNCTION__, buf[0]); 311 dprintk("%s: tuner status byte = 0x%02x\n", __FUNCTION__, buf[0]);
313 312
314 lgdt3302_SwReset(state);
315
316 /* Update current frequency */ 313 /* Update current frequency */
317 state->current_frequency = param->frequency; 314 state->current_frequency = param->frequency;
318 } 315 }
316 lgdt3302_SwReset(state);
319 return 0; 317 return 0;
320} 318}
321 319
diff --git a/drivers/media/dvb/ttpci/budget-av.c b/drivers/media/dvb/ttpci/budget-av.c
index b65f4b0a481f..9746d2bb916f 100644
--- a/drivers/media/dvb/ttpci/budget-av.c
+++ b/drivers/media/dvb/ttpci/budget-av.c
@@ -1022,7 +1022,7 @@ static struct pci_device_id pci_tbl[] = {
1022MODULE_DEVICE_TABLE(pci, pci_tbl); 1022MODULE_DEVICE_TABLE(pci, pci_tbl);
1023 1023
1024static struct saa7146_extension budget_extension = { 1024static struct saa7146_extension budget_extension = {
1025 .name = "budget dvb /w video in\0", 1025 .name = "budget_av",
1026 .pci_tbl = pci_tbl, 1026 .pci_tbl = pci_tbl,
1027 1027
1028 .module = THIS_MODULE, 1028 .module = THIS_MODULE,
diff --git a/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c b/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c
index 2c17a5f58340..aa43b5fcb8e7 100644
--- a/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c
+++ b/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c
@@ -1626,7 +1626,7 @@ static struct usb_device_id ttusb_table[] = {
1626MODULE_DEVICE_TABLE(usb, ttusb_table); 1626MODULE_DEVICE_TABLE(usb, ttusb_table);
1627 1627
1628static struct usb_driver ttusb_driver = { 1628static struct usb_driver ttusb_driver = {
1629 .name = "Technotrend/Hauppauge USB-Nova", 1629 .name = "ttusb",
1630 .probe = ttusb_probe, 1630 .probe = ttusb_probe,
1631 .disconnect = ttusb_disconnect, 1631 .disconnect = ttusb_disconnect,
1632 .id_table = ttusb_table, 1632 .id_table = ttusb_table,
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index e771064689e6..f461750c7646 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -7,19 +7,6 @@ menu "Video For Linux"
7 7
8comment "Video Adapters" 8comment "Video Adapters"
9 9
10config TUNER_MULTI_I2C
11 bool "Enable support for multiple I2C devices on Video Adapters (EXPERIMENTAL)"
12 depends on VIDEO_DEV && EXPERIMENTAL
13 ---help---
14 Some video adapters have more than one tuner inside. This patch
15 enables support for using more than one tuner. This is required
16 for some cards to allow tunning both video and radio.
17 It also improves I2C autodetection for these cards.
18
19 Only few tuners currently is supporting this. More to come.
20
21 It is safe to say 'Y' here even if your card has only one I2C tuner.
22
23config VIDEO_BT848 10config VIDEO_BT848
24 tristate "BT848 Video For Linux" 11 tristate "BT848 Video For Linux"
25 depends on VIDEO_DEV && PCI && I2C 12 depends on VIDEO_DEV && PCI && I2C
diff --git a/drivers/media/video/bt832.c b/drivers/media/video/bt832.c
index 9a642c7de545..a070417e65e6 100644
--- a/drivers/media/video/bt832.c
+++ b/drivers/media/video/bt832.c
@@ -138,25 +138,13 @@ int bt832_init(struct i2c_client *i2c_client_s)
138 138
139 bt832_hexdump(i2c_client_s,buf); 139 bt832_hexdump(i2c_client_s,buf);
140 140
141#if 0
142 // Full 30/25 Frame rate
143 printk("Full 30/25 Frame rate\n");
144 buf[0]=BT832_VP_CONTROL0; // Reg.39
145 buf[1]= 0x00;
146 if (2 != (rc = i2c_master_send(i2c_client_s,buf,2)))
147 printk("bt832: i2c i/o error FFR: rc == %d (should be 2)\n",rc);
148
149 bt832_hexdump(i2c_client_s,buf);
150#endif
151 141
152#if 1
153 // for testing (even works when no camera attached) 142 // for testing (even works when no camera attached)
154 printk("bt832: *** Generate NTSC M Bars *****\n"); 143 printk("bt832: *** Generate NTSC M Bars *****\n");
155 buf[0]=BT832_VP_TESTCONTROL0; // Reg. 42 144 buf[0]=BT832_VP_TESTCONTROL0; // Reg. 42
156 buf[1]=3; // Generate NTSC System M bars, Generate Frame timing internally 145 buf[1]=3; // Generate NTSC System M bars, Generate Frame timing internally
157 if (2 != (rc = i2c_master_send(i2c_client_s,buf,2))) 146 if (2 != (rc = i2c_master_send(i2c_client_s,buf,2)))
158 printk("bt832: i2c i/o error MBAR: rc == %d (should be 2)\n",rc); 147 printk("bt832: i2c i/o error MBAR: rc == %d (should be 2)\n",rc);
159#endif
160 148
161 printk("Bt832: Camera Present: %s\n", 149 printk("Bt832: Camera Present: %s\n",
162 (buf[1+BT832_CAM_STATUS] & BT832_56_CAMERA_PRESENT) ? "yes":"no"); 150 (buf[1+BT832_CAM_STATUS] & BT832_56_CAMERA_PRESENT) ? "yes":"no");
diff --git a/drivers/media/video/bttv-cards.c b/drivers/media/video/bttv-cards.c
index 251092e7f19f..2dbf5ec43abd 100644
--- a/drivers/media/video/bttv-cards.c
+++ b/drivers/media/video/bttv-cards.c
@@ -1,5 +1,5 @@
1/* 1/*
2 $Id: bttv-cards.c,v 1.49 2005/06/10 17:20:24 mchehab Exp $ 2 $Id: bttv-cards.c,v 1.53 2005/07/05 17:37:35 nsh Exp $
3 3
4 bttv-cards.c 4 bttv-cards.c
5 5
@@ -39,9 +39,6 @@
39#include <asm/io.h> 39#include <asm/io.h>
40 40
41#include "bttvp.h" 41#include "bttvp.h"
42#if 0 /* not working yet */
43#include "bt832.h"
44#endif
45 42
46/* fwd decl */ 43/* fwd decl */
47static void boot_msp34xx(struct bttv *btv, int pin); 44static void boot_msp34xx(struct bttv *btv, int pin);
@@ -513,13 +510,8 @@ struct tvcard bttv_tvcards[] = {
513 .svhs = 2, 510 .svhs = 2,
514 .gpiomask = 0x01fe00, 511 .gpiomask = 0x01fe00,
515 .muxsel = { 2, 3, 1, 1}, 512 .muxsel = { 2, 3, 1, 1},
516#if 0
517 // old
518 .audiomux = { 0x01c000, 0, 0x018000, 0x014000, 0x002000, 0 },
519#else
520 // 2003-10-20 by "Anton A. Arapov" <arapov@mail.ru> 513 // 2003-10-20 by "Anton A. Arapov" <arapov@mail.ru>
521 .audiomux = { 0x001e00, 0, 0x018000, 0x014000, 0x002000, 0 }, 514 .audiomux = { 0x001e00, 0, 0x018000, 0x014000, 0x002000, 0 },
522#endif
523 .needs_tvaudio = 1, 515 .needs_tvaudio = 1,
524 .pll = PLL_28, 516 .pll = PLL_28,
525 .tuner_type = -1, 517 .tuner_type = -1,
@@ -766,14 +758,9 @@ struct tvcard bttv_tvcards[] = {
766 .tuner = 0, 758 .tuner = 0,
767 .svhs = 2, 759 .svhs = 2,
768 .muxsel = { 2, 3, 1, 1, 0}, // TV, CVid, SVid, CVid over SVid connector 760 .muxsel = { 2, 3, 1, 1, 0}, // TV, CVid, SVid, CVid over SVid connector
769#if 0
770 .gpiomask = 0xc33000,
771 .audiomux = { 0x422000,0x1000,0x0000,0x620000,0x800000 },
772#else
773 /* Alexander Varakin <avarakin@hotmail.com> [stereo version] */ 761 /* Alexander Varakin <avarakin@hotmail.com> [stereo version] */
774 .gpiomask = 0xb33000, 762 .gpiomask = 0xb33000,
775 .audiomux = { 0x122000,0x1000,0x0000,0x620000,0x800000 }, 763 .audiomux = { 0x122000,0x1000,0x0000,0x620000,0x800000 },
776#endif
777 /* Audio Routing for "WinFast 2000 XP" (no tv stereo !) 764 /* Audio Routing for "WinFast 2000 XP" (no tv stereo !)
778 gpio23 -- hef4052:nEnable (0x800000) 765 gpio23 -- hef4052:nEnable (0x800000)
779 gpio12 -- hef4052:A1 766 gpio12 -- hef4052:A1
@@ -1603,20 +1590,11 @@ struct tvcard bttv_tvcards[] = {
1603 .video_inputs = 4, 1590 .video_inputs = 4,
1604 .audio_inputs = 1, 1591 .audio_inputs = 1,
1605 .tuner = -1, 1592 .tuner = -1,
1606#if 0 /* TODO ... */
1607 .svhs = OSPREY540_SVID_ANALOG,
1608 .muxsel = { [OSPREY540_COMP_ANALOG] = 2,
1609 [OSPREY540_SVID_ANALOG] = 3, },
1610#endif
1611 .pll = PLL_28, 1593 .pll = PLL_28,
1612 .tuner_type = -1, 1594 .tuner_type = -1,
1613 .no_msp34xx = 1, 1595 .no_msp34xx = 1,
1614 .no_tda9875 = 1, 1596 .no_tda9875 = 1,
1615 .no_tda7432 = 1, 1597 .no_tda7432 = 1,
1616#if 0 /* TODO ... */
1617 .muxsel_hook = osprey_540_muxsel,
1618 .picture_hook = osprey_540_set_picture,
1619#endif
1620},{ 1598},{
1621 1599
1622 /* ---- card 0x5C ---------------------------------- */ 1600 /* ---- card 0x5C ---------------------------------- */
@@ -2546,21 +2524,12 @@ static void eagle_muxsel(struct bttv *btv, unsigned int input)
2546 btaor((2)<<5, ~(3<<5), BT848_IFORM); 2524 btaor((2)<<5, ~(3<<5), BT848_IFORM);
2547 gpio_bits(3,bttv_tvcards[btv->c.type].muxsel[input&7]); 2525 gpio_bits(3,bttv_tvcards[btv->c.type].muxsel[input&7]);
2548 2526
2549#if 0
2550 /* svhs */
2551 /* wake chroma ADC */
2552 btand(~BT848_ADC_C_SLEEP, BT848_ADC);
2553 /* set to YC video */
2554 btor(BT848_CONTROL_COMP, BT848_E_CONTROL);
2555 btor(BT848_CONTROL_COMP, BT848_O_CONTROL);
2556#else
2557 /* composite */ 2527 /* composite */
2558 /* set chroma ADC to sleep */ 2528 /* set chroma ADC to sleep */
2559 btor(BT848_ADC_C_SLEEP, BT848_ADC); 2529 btor(BT848_ADC_C_SLEEP, BT848_ADC);
2560 /* set to composite video */ 2530 /* set to composite video */
2561 btand(~BT848_CONTROL_COMP, BT848_E_CONTROL); 2531 btand(~BT848_CONTROL_COMP, BT848_E_CONTROL);
2562 btand(~BT848_CONTROL_COMP, BT848_O_CONTROL); 2532 btand(~BT848_CONTROL_COMP, BT848_O_CONTROL);
2563#endif
2564 2533
2565 /* switch sync drive off */ 2534 /* switch sync drive off */
2566 gpio_bits(LM1882_SYNC_DRIVE,LM1882_SYNC_DRIVE); 2535 gpio_bits(LM1882_SYNC_DRIVE,LM1882_SYNC_DRIVE);
@@ -2813,10 +2782,18 @@ void __devinit bttv_init_card2(struct bttv *btv)
2813 btv->tuner_type = tuner[btv->c.nr]; 2782 btv->tuner_type = tuner[btv->c.nr];
2814 printk("bttv%d: using tuner=%d\n",btv->c.nr,btv->tuner_type); 2783 printk("bttv%d: using tuner=%d\n",btv->c.nr,btv->tuner_type);
2815 if (btv->pinnacle_id != UNSET) 2784 if (btv->pinnacle_id != UNSET)
2816 bttv_call_i2c_clients(btv,AUDC_CONFIG_PINNACLE, 2785 bttv_call_i2c_clients(btv, AUDC_CONFIG_PINNACLE,
2817 &btv->pinnacle_id); 2786 &btv->pinnacle_id);
2818 if (btv->tuner_type != UNSET) 2787 if (btv->tuner_type != UNSET) {
2819 bttv_call_i2c_clients(btv,TUNER_SET_TYPE,&btv->tuner_type); 2788 struct tuner_setup tun_setup;
2789
2790 tun_setup.mode_mask = T_RADIO | T_ANALOG_TV | T_DIGITAL_TV;
2791 tun_setup.type = btv->tuner_type;
2792 tun_setup.addr = ADDR_UNSET;
2793
2794 bttv_call_i2c_clients(btv, TUNER_SET_TYPE_ADDR, &tun_setup);
2795 }
2796
2820 btv->svhs = bttv_tvcards[btv->c.type].svhs; 2797 btv->svhs = bttv_tvcards[btv->c.type].svhs;
2821 if (svhs[btv->c.nr] != UNSET) 2798 if (svhs[btv->c.nr] != UNSET)
2822 btv->svhs = svhs[btv->c.nr]; 2799 btv->svhs = svhs[btv->c.nr];
@@ -3125,14 +3102,6 @@ static int tuner_0_table[] = {
3125 TUNER_PHILIPS_SECAM, TUNER_PHILIPS_SECAM, 3102 TUNER_PHILIPS_SECAM, TUNER_PHILIPS_SECAM,
3126 TUNER_PHILIPS_SECAM, TUNER_PHILIPS_PAL, 3103 TUNER_PHILIPS_SECAM, TUNER_PHILIPS_PAL,
3127 TUNER_PHILIPS_FM1216ME_MK3 }; 3104 TUNER_PHILIPS_FM1216ME_MK3 };
3128#if 0
3129int tuner_0_fm_table[] = {
3130 PHILIPS_FR1236_NTSC, PHILIPS_FR1216_PAL,
3131 PHILIPS_FR1216_PAL, PHILIPS_FR1216_PAL,
3132 PHILIPS_FR1216_PAL, PHILIPS_FR1216_PAL,
3133 PHILIPS_FR1236_SECAM, PHILIPS_FR1236_SECAM,
3134 PHILIPS_FR1236_SECAM, PHILIPS_FR1216_PAL};
3135#endif
3136 3105
3137static int tuner_1_table[] = { 3106static int tuner_1_table[] = {
3138 TUNER_TEMIC_NTSC, TUNER_TEMIC_PAL, 3107 TUNER_TEMIC_NTSC, TUNER_TEMIC_PAL,
@@ -3218,36 +3187,6 @@ static void __devinit boot_msp34xx(struct bttv *btv, int pin)
3218 3187
3219static void __devinit boot_bt832(struct bttv *btv) 3188static void __devinit boot_bt832(struct bttv *btv)
3220{ 3189{
3221#if 0 /* not working yet */
3222 int resetbit=0;
3223
3224 switch (btv->c.type) {
3225 case BTTV_PXELVWPLTVPAK:
3226 resetbit = 0x400000;
3227 break;
3228 case BTTV_MODTEC_205:
3229 resetbit = 1<<9;
3230 break;
3231 default:
3232 BUG();
3233 }
3234
3235 request_module("bt832");
3236 bttv_call_i2c_clients(btv, BT832_HEXDUMP, NULL);
3237
3238 printk("bttv%d: Reset Bt832 [line=0x%x]\n",btv->c.nr,resetbit);
3239 gpio_write(0);
3240 gpio_inout(resetbit, resetbit);
3241 udelay(5);
3242 gpio_bits(resetbit, resetbit);
3243 udelay(5);
3244 gpio_bits(resetbit, 0);
3245 udelay(5);
3246
3247 // bt832 on pixelview changes from i2c 0x8a to 0x88 after
3248 // being reset as above. So we must follow by this:
3249 bttv_call_i2c_clients(btv, BT832_REATTACH, NULL);
3250#endif
3251} 3190}
3252 3191
3253/* ----------------------------------------------------------------------- */ 3192/* ----------------------------------------------------------------------- */
@@ -3572,11 +3511,6 @@ void tea5757_set_freq(struct bttv *btv, unsigned short freq)
3572{ 3511{
3573 dprintk("tea5757_set_freq %d\n",freq); 3512 dprintk("tea5757_set_freq %d\n",freq);
3574 tea5757_write(btv, 5 * freq + 0x358); /* add 10.7MHz (see docs) */ 3513 tea5757_write(btv, 5 * freq + 0x358); /* add 10.7MHz (see docs) */
3575#if 0
3576 /* breaks Miro PCTV */
3577 value = tea5757_read(btv);
3578 dprintk("bttv%d: tea5757 readback=0x%x\n",btv->c.nr,value);
3579#endif
3580} 3514}
3581 3515
3582 3516
@@ -3656,13 +3590,8 @@ gvbctv5pci_audio(struct bttv *btv, struct video_audio *v, int set)
3656{ 3590{
3657 unsigned int val, con; 3591 unsigned int val, con;
3658 3592
3659#if BTTV_VERSION_CODE > KERNEL_VERSION(0,8,0)
3660 if (btv->radio_user) 3593 if (btv->radio_user)
3661 return; 3594 return;
3662#else
3663 if (btv->radio)
3664 return;
3665#endif
3666 3595
3667 val = gpio_read(); 3596 val = gpio_read();
3668 if (set) { 3597 if (set) {
@@ -3851,13 +3780,8 @@ pvbt878p9b_audio(struct bttv *btv, struct video_audio *v, int set)
3851{ 3780{
3852 unsigned int val = 0; 3781 unsigned int val = 0;
3853 3782
3854#if BTTV_VERSION_CODE > KERNEL_VERSION(0,8,0)
3855 if (btv->radio_user) 3783 if (btv->radio_user)
3856 return; 3784 return;
3857#else
3858 if (btv->radio)
3859 return;
3860#endif
3861 3785
3862 if (set) { 3786 if (set) {
3863 if (v->mode & VIDEO_SOUND_MONO) { 3787 if (v->mode & VIDEO_SOUND_MONO) {
@@ -3888,13 +3812,8 @@ fv2000s_audio(struct bttv *btv, struct video_audio *v, int set)
3888{ 3812{
3889 unsigned int val = 0xffff; 3813 unsigned int val = 0xffff;
3890 3814
3891#if BTTV_VERSION_CODE > KERNEL_VERSION(0,8,0)
3892 if (btv->radio_user) 3815 if (btv->radio_user)
3893 return; 3816 return;
3894#else
3895 if (btv->radio)
3896 return;
3897#endif
3898 if (set) { 3817 if (set) {
3899 if (v->mode & VIDEO_SOUND_MONO) { 3818 if (v->mode & VIDEO_SOUND_MONO) {
3900 val = 0x0000; 3819 val = 0x0000;
@@ -4371,11 +4290,6 @@ void __devinit bttv_check_chipset(void)
4371 latency = 0x0A; 4290 latency = 0x0A;
4372#endif 4291#endif
4373 4292
4374#if 0
4375 /* print which chipset we have */
4376 while ((dev = pci_find_class(PCI_CLASS_BRIDGE_HOST << 8,dev)))
4377 printk(KERN_INFO "bttv: Host bridge is %s\n",pci_name(dev));
4378#endif
4379 4293
4380 /* print warnings about any quirks found */ 4294 /* print warnings about any quirks found */
4381 if (triton1) 4295 if (triton1)
diff --git a/drivers/media/video/bttv-driver.c b/drivers/media/video/bttv-driver.c
index 7d62b394c509..51a0f6d68e73 100644
--- a/drivers/media/video/bttv-driver.c
+++ b/drivers/media/video/bttv-driver.c
@@ -1,5 +1,5 @@
1/* 1/*
2 $Id: bttv-driver.c,v 1.40 2005/06/16 21:38:45 nsh Exp $ 2 $Id: bttv-driver.c,v 1.42 2005/07/05 17:37:35 nsh Exp $
3 3
4 bttv - Bt848 frame grabber driver 4 bttv - Bt848 frame grabber driver
5 5
@@ -35,6 +35,7 @@
35#include <linux/sched.h> 35#include <linux/sched.h>
36#include <linux/interrupt.h> 36#include <linux/interrupt.h>
37#include <linux/kdev_t.h> 37#include <linux/kdev_t.h>
38#include <linux/dma-mapping.h>
38 39
39#include <asm/io.h> 40#include <asm/io.h>
40#include <asm/byteorder.h> 41#include <asm/byteorder.h>
@@ -698,12 +699,10 @@ int locked_btres(struct bttv *btv, int bit)
698static 699static
699void free_btres(struct bttv *btv, struct bttv_fh *fh, int bits) 700void free_btres(struct bttv *btv, struct bttv_fh *fh, int bits)
700{ 701{
701#if 1 /* DEBUG */
702 if ((fh->resources & bits) != bits) { 702 if ((fh->resources & bits) != bits) {
703 /* trying to free ressources not allocated by us ... */ 703 /* trying to free ressources not allocated by us ... */
704 printk("bttv: BUG! (btres)\n"); 704 printk("bttv: BUG! (btres)\n");
705 } 705 }
706#endif
707 down(&btv->reslock); 706 down(&btv->reslock);
708 fh->resources &= ~bits; 707 fh->resources &= ~bits;
709 btv->resources &= ~bits; 708 btv->resources &= ~bits;
@@ -943,11 +942,6 @@ audio_mux(struct bttv *btv, int mode)
943 i2c_mux = mux = (btv->audio & AUDIO_MUTE) ? AUDIO_OFF : btv->audio; 942 i2c_mux = mux = (btv->audio & AUDIO_MUTE) ? AUDIO_OFF : btv->audio;
944 if (btv->opt_automute && !signal && !btv->radio_user) 943 if (btv->opt_automute && !signal && !btv->radio_user)
945 mux = AUDIO_OFF; 944 mux = AUDIO_OFF;
946#if 0
947 printk("bttv%d: amux: mode=%d audio=%d signal=%s mux=%d/%d irq=%s\n",
948 btv->c.nr, mode, btv->audio, signal ? "yes" : "no",
949 mux, i2c_mux, in_interrupt() ? "yes" : "no");
950#endif
951 945
952 val = bttv_tvcards[btv->c.type].audiomux[mux]; 946 val = bttv_tvcards[btv->c.type].audiomux[mux];
953 gpio_bits(bttv_tvcards[btv->c.type].gpiomask,val); 947 gpio_bits(bttv_tvcards[btv->c.type].gpiomask,val);
@@ -994,11 +988,6 @@ set_tvnorm(struct bttv *btv, unsigned int norm)
994 case BTTV_VOODOOTV_FM: 988 case BTTV_VOODOOTV_FM:
995 bttv_tda9880_setnorm(btv,norm); 989 bttv_tda9880_setnorm(btv,norm);
996 break; 990 break;
997#if 0
998 case BTTV_OSPREY540:
999 osprey_540_set_norm(btv,norm);
1000 break;
1001#endif
1002 } 991 }
1003 return 0; 992 return 0;
1004} 993}
@@ -1849,7 +1838,7 @@ static int bttv_common_ioctls(struct bttv *btv, unsigned int cmd, void *arg)
1849 1838
1850 if (unlikely(f->tuner != 0)) 1839 if (unlikely(f->tuner != 0))
1851 return -EINVAL; 1840 return -EINVAL;
1852 if (unlikely(f->type != V4L2_TUNER_ANALOG_TV)) 1841 if (unlikely (f->type != V4L2_TUNER_ANALOG_TV))
1853 return -EINVAL; 1842 return -EINVAL;
1854 down(&btv->lock); 1843 down(&btv->lock);
1855 btv->freq = f->frequency; 1844 btv->freq = f->frequency;
@@ -3865,7 +3854,7 @@ static int __devinit bttv_probe(struct pci_dev *dev,
3865 btv->c.nr); 3854 btv->c.nr);
3866 return -EIO; 3855 return -EIO;
3867 } 3856 }
3868 if (pci_set_dma_mask(dev, 0xffffffff)) { 3857 if (pci_set_dma_mask(dev, DMA_32BIT_MASK)) {
3869 printk(KERN_WARNING "bttv%d: No suitable DMA available.\n", 3858 printk(KERN_WARNING "bttv%d: No suitable DMA available.\n",
3870 btv->c.nr); 3859 btv->c.nr);
3871 return -EIO; 3860 return -EIO;
diff --git a/drivers/media/video/bttv-i2c.c b/drivers/media/video/bttv-i2c.c
index da448a5f9e9c..234a85563769 100644
--- a/drivers/media/video/bttv-i2c.c
+++ b/drivers/media/video/bttv-i2c.c
@@ -1,5 +1,5 @@
1/* 1/*
2 $Id: bttv-i2c.c,v 1.21 2005/06/10 17:20:24 mchehab Exp $ 2 $Id: bttv-i2c.c,v 1.25 2005/07/05 17:37:35 nsh Exp $
3 3
4 bttv-i2c.c -- all the i2c code is here 4 bttv-i2c.c -- all the i2c code is here
5 5
@@ -295,14 +295,26 @@ static int attach_inform(struct i2c_client *client)
295{ 295{
296 struct bttv *btv = i2c_get_adapdata(client->adapter); 296 struct bttv *btv = i2c_get_adapdata(client->adapter);
297 297
298 if (btv->tuner_type != UNSET) 298 if (bttv_debug)
299 bttv_call_i2c_clients(btv,TUNER_SET_TYPE,&btv->tuner_type); 299 printk(KERN_DEBUG "bttv%d: %s i2c attach [addr=0x%x,client=%s]\n",
300 btv->c.nr,client->driver->name,client->addr,
301 i2c_clientname(client));
302 if (!client->driver->command)
303 return 0;
304
305 if (btv->tuner_type != UNSET) {
306 struct tuner_setup tun_setup;
307
308 tun_setup.mode_mask = T_RADIO | T_ANALOG_TV | T_DIGITAL_TV;
309 tun_setup.type = btv->tuner_type;
310 tun_setup.addr = ADDR_UNSET;
311
312 client->driver->command (client, TUNER_SET_TYPE_ADDR, &tun_setup);
313 }
314
300 if (btv->pinnacle_id != UNSET) 315 if (btv->pinnacle_id != UNSET)
301 bttv_call_i2c_clients(btv,AUDC_CONFIG_PINNACLE, 316 client->driver->command(client,AUDC_CONFIG_PINNACLE,
302 &btv->pinnacle_id); 317 &btv->pinnacle_id);
303 if (bttv_debug)
304 printk("bttv%d: i2c attach [client=%s]\n",
305 btv->c.nr, i2c_clientname(client));
306 return 0; 318 return 0;
307} 319}
308 320
diff --git a/drivers/media/video/bttv-risc.c b/drivers/media/video/bttv-risc.c
index bdc5ce6c43b9..9ed21fd190c6 100644
--- a/drivers/media/video/bttv-risc.c
+++ b/drivers/media/video/bttv-risc.c
@@ -334,10 +334,6 @@ bttv_calc_geo(struct bttv *btv, struct bttv_geometry *geo,
334 } 334 }
335 335
336 vdelay = tvnorm->vdelay; 336 vdelay = tvnorm->vdelay;
337#if 0 /* FIXME */
338 if (vdelay < btv->vbi.lines*2)
339 vdelay = btv->vbi.lines*2;
340#endif
341 337
342 xsf = (width*scaledtwidth)/swidth; 338 xsf = (width*scaledtwidth)/swidth;
343 geo->hscale = ((totalwidth*4096UL)/xsf-4096); 339 geo->hscale = ((totalwidth*4096UL)/xsf-4096);
@@ -776,13 +772,8 @@ bttv_overlay_risc(struct bttv *btv,
776 bttv_risc_overlay(btv, &buf->bottom, fmt, ov, 0, 0); 772 bttv_risc_overlay(btv, &buf->bottom, fmt, ov, 0, 0);
777 break; 773 break;
778 case V4L2_FIELD_INTERLACED: 774 case V4L2_FIELD_INTERLACED:
779#if 0
780 bttv_risc_overlay(btv, &buf->top, fmt, ov, 1, 0);
781 bttv_risc_overlay(btv, &buf->bottom, fmt, ov, 0, 1);
782#else
783 bttv_risc_overlay(btv, &buf->top, fmt, ov, 0, 1); 775 bttv_risc_overlay(btv, &buf->top, fmt, ov, 0, 1);
784 bttv_risc_overlay(btv, &buf->bottom, fmt, ov, 1, 0); 776 bttv_risc_overlay(btv, &buf->bottom, fmt, ov, 1, 0);
785#endif
786 break; 777 break;
787 default: 778 default:
788 BUG(); 779 BUG();
diff --git a/drivers/media/video/cx88/cx88-blackbird.c b/drivers/media/video/cx88/cx88-blackbird.c
index 91f8afeded88..4f39688f780a 100644
--- a/drivers/media/video/cx88/cx88-blackbird.c
+++ b/drivers/media/video/cx88/cx88-blackbird.c
@@ -690,11 +690,9 @@ static void blackbird_codec_settings(struct cx8802_dev *dev)
690 int bitrate_mode = 1; 690 int bitrate_mode = 1;
691 int bitrate = 7500000; 691 int bitrate = 7500000;
692 int bitrate_peak = 7500000; 692 int bitrate_peak = 7500000;
693#if 1
694 bitrate_mode = BLACKBIRD_VIDEO_CBR; 693 bitrate_mode = BLACKBIRD_VIDEO_CBR;
695 bitrate = 4000*1024; 694 bitrate = 4000*1024;
696 bitrate_peak = 4000*1024; 695 bitrate_peak = 4000*1024;
697#endif
698 696
699 /* assign stream type */ 697 /* assign stream type */
700 blackbird_api_cmd(dev, BLACKBIRD_API_SET_STREAM_TYPE, 1, 0, BLACKBIRD_STREAM_PROGRAM); 698 blackbird_api_cmd(dev, BLACKBIRD_API_SET_STREAM_TYPE, 1, 0, BLACKBIRD_STREAM_PROGRAM);
@@ -810,9 +808,6 @@ static int blackbird_initialize_codec(struct cx8802_dev *dev)
810 cx_write(MO_VBOS_CONTROL, 0x84A00); /* no 656 mode, 8-bit pixels, disable VBI */ 808 cx_write(MO_VBOS_CONTROL, 0x84A00); /* no 656 mode, 8-bit pixels, disable VBI */
811 cx_clear(MO_OUTPUT_FORMAT, 0x0008); /* Normal Y-limits to let the mpeg encoder sync */ 809 cx_clear(MO_OUTPUT_FORMAT, 0x0008); /* Normal Y-limits to let the mpeg encoder sync */
812 810
813#if 0 /* FIXME */
814 set_scale(dev, 720, 480, V4L2_FIELD_INTERLACED);
815#endif
816 blackbird_codec_settings(dev); 811 blackbird_codec_settings(dev);
817 msleep(1); 812 msleep(1);
818 813
diff --git a/drivers/media/video/cx88/cx88-core.c b/drivers/media/video/cx88/cx88-core.c
index 96cb0ff33bbd..5e868f5cd0c0 100644
--- a/drivers/media/video/cx88/cx88-core.c
+++ b/drivers/media/video/cx88/cx88-core.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: cx88-core.c,v 1.31 2005/06/22 22:58:04 mchehab Exp $ 2 * $Id: cx88-core.c,v 1.33 2005/07/07 14:17:47 mchehab Exp $
3 * 3 *
4 * device driver for Conexant 2388x based TV cards 4 * device driver for Conexant 2388x based TV cards
5 * driver core 5 * driver core
@@ -470,25 +470,6 @@ int cx88_risc_decode(u32 risc)
470 return incr[risc >> 28] ? incr[risc >> 28] : 1; 470 return incr[risc >> 28] ? incr[risc >> 28] : 1;
471} 471}
472 472
473#if 0 /* currently unused, but useful for debugging */
474void cx88_risc_disasm(struct cx88_core *core,
475 struct btcx_riscmem *risc)
476{
477 unsigned int i,j,n;
478
479 printk("%s: risc disasm: %p [dma=0x%08lx]\n",
480 core->name, risc->cpu, (unsigned long)risc->dma);
481 for (i = 0; i < (risc->size >> 2); i += n) {
482 printk("%s: %04d: ", core->name, i);
483 n = cx88_risc_decode(risc->cpu[i]);
484 for (j = 1; j < n; j++)
485 printk("%s: %04d: 0x%08x [ arg #%d ]\n",
486 core->name, i+j, risc->cpu[i+j], j);
487 if (risc->cpu[i] == RISC_JUMP)
488 break;
489 }
490}
491#endif
492 473
493void cx88_sram_channel_dump(struct cx88_core *core, 474void cx88_sram_channel_dump(struct cx88_core *core,
494 struct sram_channel *ch) 475 struct sram_channel *ch)
@@ -545,30 +526,12 @@ void cx88_sram_channel_dump(struct cx88_core *core,
545 core->name,cx_read(ch->cnt2_reg)); 526 core->name,cx_read(ch->cnt2_reg));
546} 527}
547 528
548/* Used only on cx88-core */
549static char *cx88_pci_irqs[32] = { 529static char *cx88_pci_irqs[32] = {
550 "vid", "aud", "ts", "vip", "hst", "5", "6", "tm1", 530 "vid", "aud", "ts", "vip", "hst", "5", "6", "tm1",
551 "src_dma", "dst_dma", "risc_rd_err", "risc_wr_err", 531 "src_dma", "dst_dma", "risc_rd_err", "risc_wr_err",
552 "brdg_err", "src_dma_err", "dst_dma_err", "ipb_dma_err", 532 "brdg_err", "src_dma_err", "dst_dma_err", "ipb_dma_err",
553 "i2c", "i2c_rack", "ir_smp", "gpio0", "gpio1" 533 "i2c", "i2c_rack", "ir_smp", "gpio0", "gpio1"
554}; 534};
555/* Used only on cx88-video */
556char *cx88_vid_irqs[32] = {
557 "y_risci1", "u_risci1", "v_risci1", "vbi_risc1",
558 "y_risci2", "u_risci2", "v_risci2", "vbi_risc2",
559 "y_oflow", "u_oflow", "v_oflow", "vbi_oflow",
560 "y_sync", "u_sync", "v_sync", "vbi_sync",
561 "opc_err", "par_err", "rip_err", "pci_abort",
562};
563/* Used only on cx88-mpeg */
564char *cx88_mpeg_irqs[32] = {
565 "ts_risci1", NULL, NULL, NULL,
566 "ts_risci2", NULL, NULL, NULL,
567 "ts_oflow", NULL, NULL, NULL,
568 "ts_sync", NULL, NULL, NULL,
569 "opc_err", "par_err", "rip_err", "pci_abort",
570 "ts_err?",
571};
572 535
573void cx88_print_irqbits(char *name, char *tag, char **strings, 536void cx88_print_irqbits(char *name, char *tag, char **strings,
574 u32 bits, u32 mask) 537 u32 bits, u32 mask)
@@ -618,16 +581,11 @@ void cx88_wakeup(struct cx88_core *core,
618 break; 581 break;
619 buf = list_entry(q->active.next, 582 buf = list_entry(q->active.next,
620 struct cx88_buffer, vb.queue); 583 struct cx88_buffer, vb.queue);
621#if 0
622 if (buf->count > count)
623 break;
624#else
625 /* count comes from the hw and is is 16bit wide -- 584 /* count comes from the hw and is is 16bit wide --
626 * this trick handles wrap-arounds correctly for 585 * this trick handles wrap-arounds correctly for
627 * up to 32767 buffers in flight... */ 586 * up to 32767 buffers in flight... */
628 if ((s16) (count - buf->count) < 0) 587 if ((s16) (count - buf->count) < 0)
629 break; 588 break;
630#endif
631 do_gettimeofday(&buf->vb.ts); 589 do_gettimeofday(&buf->vb.ts);
632 dprintk(2,"[%p/%d] wakeup reg=%d buf=%d\n",buf,buf->vb.i, 590 dprintk(2,"[%p/%d] wakeup reg=%d buf=%d\n",buf,buf->vb.i,
633 count, buf->count); 591 count, buf->count);
@@ -955,12 +913,10 @@ int cx88_set_tvnorm(struct cx88_core *core, struct cx88_tvnorm *norm)
955 norm->cxiformat, cx_read(MO_INPUT_FORMAT) & 0x0f); 913 norm->cxiformat, cx_read(MO_INPUT_FORMAT) & 0x0f);
956 cx_andor(MO_INPUT_FORMAT, 0xf, norm->cxiformat); 914 cx_andor(MO_INPUT_FORMAT, 0xf, norm->cxiformat);
957 915
958#if 1
959 // FIXME: as-is from DScaler 916 // FIXME: as-is from DScaler
960 dprintk(1,"set_tvnorm: MO_OUTPUT_FORMAT 0x%08x [old=0x%08x]\n", 917 dprintk(1,"set_tvnorm: MO_OUTPUT_FORMAT 0x%08x [old=0x%08x]\n",
961 norm->cxoformat, cx_read(MO_OUTPUT_FORMAT)); 918 norm->cxoformat, cx_read(MO_OUTPUT_FORMAT));
962 cx_write(MO_OUTPUT_FORMAT, norm->cxoformat); 919 cx_write(MO_OUTPUT_FORMAT, norm->cxoformat);
963#endif
964 920
965 // MO_SCONV_REG = adc clock / video dec clock * 2^17 921 // MO_SCONV_REG = adc clock / video dec clock * 2^17
966 tmp64 = adc_clock * (u64)(1 << 17); 922 tmp64 = adc_clock * (u64)(1 << 17);
@@ -1219,8 +1175,6 @@ void cx88_core_put(struct cx88_core *core, struct pci_dev *pci)
1219/* ------------------------------------------------------------------ */ 1175/* ------------------------------------------------------------------ */
1220 1176
1221EXPORT_SYMBOL(cx88_print_ioctl); 1177EXPORT_SYMBOL(cx88_print_ioctl);
1222EXPORT_SYMBOL(cx88_vid_irqs);
1223EXPORT_SYMBOL(cx88_mpeg_irqs);
1224EXPORT_SYMBOL(cx88_print_irqbits); 1178EXPORT_SYMBOL(cx88_print_irqbits);
1225 1179
1226EXPORT_SYMBOL(cx88_core_irq); 1180EXPORT_SYMBOL(cx88_core_irq);
diff --git a/drivers/media/video/cx88/cx88-dvb.c b/drivers/media/video/cx88/cx88-dvb.c
index 690477a67917..8db68f2d1351 100644
--- a/drivers/media/video/cx88/cx88-dvb.c
+++ b/drivers/media/video/cx88/cx88-dvb.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: cx88-dvb.c,v 1.39 2005/07/02 20:00:46 mkrufky Exp $ 2 * $Id: cx88-dvb.c,v 1.41 2005/07/04 19:35:05 mkrufky Exp $
3 * 3 *
4 * device driver for Conexant 2388x based TV cards 4 * device driver for Conexant 2388x based TV cards
5 * MPEG Transport Stream (DVB) routines 5 * MPEG Transport Stream (DVB) routines
@@ -30,22 +30,25 @@
30#include <linux/file.h> 30#include <linux/file.h>
31#include <linux/suspend.h> 31#include <linux/suspend.h>
32 32
33/* these three frontends need merging via linuxtv cvs ... */ 33#define CONFIG_DVB_MT352 1
34#define HAVE_CX22702 1 34#define CONFIG_DVB_CX22702 1
35#define HAVE_OR51132 1 35#define CONFIG_DVB_OR51132 1
36#define HAVE_LGDT3302 1 36#define CONFIG_DVB_LGDT3302 1
37 37
38#include "cx88.h" 38#include "cx88.h"
39#include "dvb-pll.h" 39#include "dvb-pll.h"
40#include "mt352.h" 40
41#include "mt352_priv.h" 41#if CONFIG_DVB_MT352
42#if HAVE_CX22702 42# include "mt352.h"
43# include "mt352_priv.h"
44#endif
45#if CONFIG_DVB_CX22702
43# include "cx22702.h" 46# include "cx22702.h"
44#endif 47#endif
45#if HAVE_OR51132 48#if CONFIG_DVB_OR51132
46# include "or51132.h" 49# include "or51132.h"
47#endif 50#endif
48#if HAVE_LGDT3302 51#if CONFIG_DVB_LGDT3302
49# include "lgdt3302.h" 52# include "lgdt3302.h"
50#endif 53#endif
51 54
@@ -104,6 +107,7 @@ static struct videobuf_queue_ops dvb_qops = {
104 107
105/* ------------------------------------------------------------------ */ 108/* ------------------------------------------------------------------ */
106 109
110#if CONFIG_DVB_MT352
107static int dvico_fusionhdtv_demod_init(struct dvb_frontend* fe) 111static int dvico_fusionhdtv_demod_init(struct dvb_frontend* fe)
108{ 112{
109 static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x39 }; 113 static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x39 };
@@ -171,8 +175,9 @@ static struct mt352_config dntv_live_dvbt_config = {
171 .demod_init = dntv_live_dvbt_demod_init, 175 .demod_init = dntv_live_dvbt_demod_init,
172 .pll_set = mt352_pll_set, 176 .pll_set = mt352_pll_set,
173}; 177};
178#endif
174 179
175#if HAVE_CX22702 180#if CONFIG_DVB_CX22702
176static struct cx22702_config connexant_refboard_config = { 181static struct cx22702_config connexant_refboard_config = {
177 .demod_address = 0x43, 182 .demod_address = 0x43,
178 .pll_address = 0x60, 183 .pll_address = 0x60,
@@ -186,7 +191,7 @@ static struct cx22702_config hauppauge_novat_config = {
186}; 191};
187#endif 192#endif
188 193
189#if HAVE_OR51132 194#if CONFIG_DVB_OR51132
190static int or51132_set_ts_param(struct dvb_frontend* fe, 195static int or51132_set_ts_param(struct dvb_frontend* fe,
191 int is_punctured) 196 int is_punctured)
192{ 197{
@@ -203,7 +208,7 @@ static struct or51132_config pchdtv_hd3000 = {
203}; 208};
204#endif 209#endif
205 210
206#if HAVE_LGDT3302 211#if CONFIG_DVB_LGDT3302
207static int lgdt3302_set_ts_param(struct dvb_frontend* fe, int is_punctured) 212static int lgdt3302_set_ts_param(struct dvb_frontend* fe, int is_punctured)
208{ 213{
209 struct cx8802_dev *dev= fe->dvb->priv; 214 struct cx8802_dev *dev= fe->dvb->priv;
@@ -237,7 +242,7 @@ static int dvb_register(struct cx8802_dev *dev)
237 242
238 /* init frontend */ 243 /* init frontend */
239 switch (dev->core->board) { 244 switch (dev->core->board) {
240#if HAVE_CX22702 245#if CONFIG_DVB_CX22702
241 case CX88_BOARD_HAUPPAUGE_DVB_T1: 246 case CX88_BOARD_HAUPPAUGE_DVB_T1:
242 dev->dvb.frontend = cx22702_attach(&hauppauge_novat_config, 247 dev->dvb.frontend = cx22702_attach(&hauppauge_novat_config,
243 &dev->core->i2c_adap); 248 &dev->core->i2c_adap);
@@ -248,6 +253,7 @@ static int dvb_register(struct cx8802_dev *dev)
248 &dev->core->i2c_adap); 253 &dev->core->i2c_adap);
249 break; 254 break;
250#endif 255#endif
256#if CONFIG_DVB_MT352
251 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1: 257 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1:
252 dev->core->pll_addr = 0x61; 258 dev->core->pll_addr = 0x61;
253 dev->core->pll_desc = &dvb_pll_lg_z201; 259 dev->core->pll_desc = &dvb_pll_lg_z201;
@@ -268,13 +274,14 @@ static int dvb_register(struct cx8802_dev *dev)
268 dev->dvb.frontend = mt352_attach(&dntv_live_dvbt_config, 274 dev->dvb.frontend = mt352_attach(&dntv_live_dvbt_config,
269 &dev->core->i2c_adap); 275 &dev->core->i2c_adap);
270 break; 276 break;
271#if HAVE_OR51132 277#endif
278#if CONFIG_DVB_OR51132
272 case CX88_BOARD_PCHDTV_HD3000: 279 case CX88_BOARD_PCHDTV_HD3000:
273 dev->dvb.frontend = or51132_attach(&pchdtv_hd3000, 280 dev->dvb.frontend = or51132_attach(&pchdtv_hd3000,
274 &dev->core->i2c_adap); 281 &dev->core->i2c_adap);
275 break; 282 break;
276#endif 283#endif
277#if HAVE_LGDT3302 284#if CONFIG_DVB_LGDT3302
278 case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q: 285 case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q:
279 dev->ts_gen_cntrl = 0x08; 286 dev->ts_gen_cntrl = 0x08;
280 { 287 {
diff --git a/drivers/media/video/cx88/cx88-i2c.c b/drivers/media/video/cx88/cx88-i2c.c
index b5342234b305..8403c4e95050 100644
--- a/drivers/media/video/cx88/cx88-i2c.c
+++ b/drivers/media/video/cx88/cx88-i2c.c
@@ -1,5 +1,5 @@
1/* 1/*
2 $Id: cx88-i2c.c,v 1.24 2005/06/17 18:46:23 mkrufky Exp $ 2 $Id: cx88-i2c.c,v 1.28 2005/07/05 17:37:35 nsh Exp $
3 3
4 cx88-i2c.c -- all the i2c code is here 4 cx88-i2c.c -- all the i2c code is here
5 5
@@ -91,25 +91,32 @@ static int cx8800_bit_getsda(void *data)
91 91
92static int attach_inform(struct i2c_client *client) 92static int attach_inform(struct i2c_client *client)
93{ 93{
94 struct tuner_addr tun_addr; 94 struct tuner_setup tun_setup;
95 struct cx88_core *core = i2c_get_adapdata(client->adapter); 95 struct cx88_core *core = i2c_get_adapdata(client->adapter);
96 96
97 dprintk(1, "i2c attach [addr=0x%x,client=%s]\n", 97 dprintk(1, "%s i2c attach [addr=0x%x,client=%s]\n",
98 client->addr, i2c_clientname(client)); 98 client->driver->name,client->addr,i2c_clientname(client));
99 if (!client->driver->command) 99 if (!client->driver->command)
100 return 0; 100 return 0;
101 101
102 if (core->radio_type != UNSET) { 102 if (core->radio_type != UNSET) {
103 tun_addr.v4l2_tuner = V4L2_TUNER_RADIO; 103 if ((core->radio_addr==ADDR_UNSET)||(core->radio_addr==client->addr)) {
104 tun_addr.type = core->radio_type; 104 tun_setup.mode_mask = T_RADIO;
105 tun_addr.addr = core->radio_addr; 105 tun_setup.type = core->radio_type;
106 client->driver->command(client,TUNER_SET_TYPE_ADDR, &tun_addr); 106 tun_setup.addr = core->radio_addr;
107
108 client->driver->command (client, TUNER_SET_TYPE_ADDR, &tun_setup);
109 }
107 } 110 }
108 if (core->tuner_type != UNSET) { 111 if (core->tuner_type != UNSET) {
109 tun_addr.v4l2_tuner = V4L2_TUNER_ANALOG_TV; 112 if ((core->tuner_addr==ADDR_UNSET)||(core->tuner_addr==client->addr)) {
110 tun_addr.type = core->tuner_type; 113
111 tun_addr.addr = core->tuner_addr; 114 tun_setup.mode_mask = T_ANALOG_TV;
112 client->driver->command(client,TUNER_SET_TYPE_ADDR, &tun_addr); 115 tun_setup.type = core->tuner_type;
116 tun_setup.addr = core->tuner_addr;
117
118 client->driver->command (client,TUNER_SET_TYPE_ADDR, &tun_setup);
119 }
113 } 120 }
114 121
115 if (core->tda9887_conf) 122 if (core->tda9887_conf)
diff --git a/drivers/media/video/cx88/cx88-input.c b/drivers/media/video/cx88/cx88-input.c
index bdc26e75ab5f..214887798192 100644
--- a/drivers/media/video/cx88/cx88-input.c
+++ b/drivers/media/video/cx88/cx88-input.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: cx88-input.c,v 1.13 2005/06/13 16:07:46 nsh Exp $ 2 * $Id: cx88-input.c,v 1.15 2005/07/07 13:58:38 mchehab Exp $
3 * 3 *
4 * Device driver for GPIO attached remote control interfaces 4 * Device driver for GPIO attached remote control interfaces
5 * on Conexant 2388x based TV/DVB cards. 5 * on Conexant 2388x based TV/DVB cards.
@@ -38,199 +38,206 @@
38 38
39/* DigitalNow DNTV Live DVB-T Remote */ 39/* DigitalNow DNTV Live DVB-T Remote */
40static IR_KEYTAB_TYPE ir_codes_dntv_live_dvb_t[IR_KEYTAB_SIZE] = { 40static IR_KEYTAB_TYPE ir_codes_dntv_live_dvb_t[IR_KEYTAB_SIZE] = {
41 [ 0x00 ] = KEY_ESC, // 'go up a level?' 41 [0x00] = KEY_ESC, /* 'go up a level?' */
42 [ 0x01 ] = KEY_KP1, // '1' 42 /* Keys 0 to 9 */
43 [ 0x02 ] = KEY_KP2, // '2' 43 [0x0a] = KEY_KP0,
44 [ 0x03 ] = KEY_KP3, // '3' 44 [0x01] = KEY_KP1,
45 [ 0x04 ] = KEY_KP4, // '4' 45 [0x02] = KEY_KP2,
46 [ 0x05 ] = KEY_KP5, // '5' 46 [0x03] = KEY_KP3,
47 [ 0x06 ] = KEY_KP6, // '6' 47 [0x04] = KEY_KP4,
48 [ 0x07 ] = KEY_KP7, // '7' 48 [0x05] = KEY_KP5,
49 [ 0x08 ] = KEY_KP8, // '8' 49 [0x06] = KEY_KP6,
50 [ 0x09 ] = KEY_KP9, // '9' 50 [0x07] = KEY_KP7,
51 [ 0x0a ] = KEY_KP0, // '0' 51 [0x08] = KEY_KP8,
52 [ 0x0b ] = KEY_TUNER, // 'tv/fm' 52 [0x09] = KEY_KP9,
53 [ 0x0c ] = KEY_SEARCH, // 'scan' 53
54 [ 0x0d ] = KEY_STOP, // 'stop' 54 [0x0b] = KEY_TUNER, /* tv/fm */
55 [ 0x0e ] = KEY_PAUSE, // 'pause' 55 [0x0c] = KEY_SEARCH, /* scan */
56 [ 0x0f ] = KEY_LIST, // 'source' 56 [0x0d] = KEY_STOP,
57 57 [0x0e] = KEY_PAUSE,
58 [ 0x10 ] = KEY_MUTE, // 'mute' 58 [0x0f] = KEY_LIST, /* source */
59 [ 0x11 ] = KEY_REWIND, // 'backward <<' 59
60 [ 0x12 ] = KEY_POWER, // 'power' 60 [0x10] = KEY_MUTE,
61 [ 0x13 ] = KEY_S, // 'snap' 61 [0x11] = KEY_REWIND, /* backward << */
62 [ 0x14 ] = KEY_AUDIO, // 'stereo' 62 [0x12] = KEY_POWER,
63 [ 0x15 ] = KEY_CLEAR, // 'reset' 63 [0x13] = KEY_S, /* snap */
64 [ 0x16 ] = KEY_PLAY, // 'play' 64 [0x14] = KEY_AUDIO, /* stereo */
65 [ 0x17 ] = KEY_ENTER, // 'enter' 65 [0x15] = KEY_CLEAR, /* reset */
66 [ 0x18 ] = KEY_ZOOM, // 'full screen' 66 [0x16] = KEY_PLAY,
67 [ 0x19 ] = KEY_FASTFORWARD, // 'forward >>' 67 [0x17] = KEY_ENTER,
68 [ 0x1a ] = KEY_CHANNELUP, // 'channel +' 68 [0x18] = KEY_ZOOM, /* full screen */
69 [ 0x1b ] = KEY_VOLUMEUP, // 'volume +' 69 [0x19] = KEY_FASTFORWARD, /* forward >> */
70 [ 0x1c ] = KEY_INFO, // 'preview' 70 [0x1a] = KEY_CHANNELUP,
71 [ 0x1d ] = KEY_RECORD, // 'record' 71 [0x1b] = KEY_VOLUMEUP,
72 [ 0x1e ] = KEY_CHANNELDOWN, // 'channel -' 72 [0x1c] = KEY_INFO, /* preview */
73 [ 0x1f ] = KEY_VOLUMEDOWN, // 'volume -' 73 [0x1d] = KEY_RECORD, /* record */
74 [0x1e] = KEY_CHANNELDOWN,
75 [0x1f] = KEY_VOLUMEDOWN,
74}; 76};
75 77
76/* ---------------------------------------------------------------------- */ 78/* ---------------------------------------------------------------------- */
77 79
78/* IO-DATA BCTV7E Remote */ 80/* IO-DATA BCTV7E Remote */
79static IR_KEYTAB_TYPE ir_codes_iodata_bctv7e[IR_KEYTAB_SIZE] = { 81static IR_KEYTAB_TYPE ir_codes_iodata_bctv7e[IR_KEYTAB_SIZE] = {
80 [ 0x40 ] = KEY_TV, // TV 82 [0x40] = KEY_TV,
81 [ 0x20 ] = KEY_RADIO, // FM 83 [0x20] = KEY_RADIO, /* FM */
82 [ 0x60 ] = KEY_EPG, // EPG 84 [0x60] = KEY_EPG,
83 [ 0x00 ] = KEY_POWER, // power 85 [0x00] = KEY_POWER,
84 86
85 [ 0x50 ] = KEY_KP1, // 1 87 /* Keys 0 to 9 */
86 [ 0x30 ] = KEY_KP2, // 2 88 [0x44] = KEY_KP0, /* 10 */
87 [ 0x70 ] = KEY_KP3, // 3 89 [0x50] = KEY_KP1,
88 [ 0x10 ] = KEY_L, // Live 90 [0x30] = KEY_KP2,
89 91 [0x70] = KEY_KP3,
90 [ 0x48 ] = KEY_KP4, // 4 92 [0x48] = KEY_KP4,
91 [ 0x28 ] = KEY_KP5, // 5 93 [0x28] = KEY_KP5,
92 [ 0x68 ] = KEY_KP6, // 6 94 [0x68] = KEY_KP6,
93 [ 0x08 ] = KEY_T, // Time Shift 95 [0x58] = KEY_KP7,
94 96 [0x38] = KEY_KP8,
95 [ 0x58 ] = KEY_KP7, // 7 97 [0x78] = KEY_KP9,
96 [ 0x38 ] = KEY_KP8, // 8 98
97 [ 0x78 ] = KEY_KP9, // 9 99 [0x10] = KEY_L, /* Live */
98 [ 0x18 ] = KEY_PLAYPAUSE, // Play 100 [0x08] = KEY_T, /* Time Shift */
99 101
100 [ 0x44 ] = KEY_KP0, // 10 102 [0x18] = KEY_PLAYPAUSE, /* Play */
101 [ 0x24 ] = KEY_ENTER, // 11 103
102 [ 0x64 ] = KEY_ESC, // 12 104 [0x24] = KEY_ENTER, /* 11 */
103 [ 0x04 ] = KEY_M, // Multi 105 [0x64] = KEY_ESC, /* 12 */
104 106 [0x04] = KEY_M, /* Multi */
105 [ 0x54 ] = KEY_VIDEO, // VIDEO 107
106 [ 0x34 ] = KEY_CHANNELUP, // channel + 108 [0x54] = KEY_VIDEO,
107 [ 0x74 ] = KEY_VOLUMEUP, // volume + 109 [0x34] = KEY_CHANNELUP,
108 [ 0x14 ] = KEY_MUTE, // Mute 110 [0x74] = KEY_VOLUMEUP,
109 111 [0x14] = KEY_MUTE,
110 [ 0x4c ] = KEY_S, // SVIDEO 112
111 [ 0x2c ] = KEY_CHANNELDOWN, // channel - 113 [0x4c] = KEY_S, /* SVIDEO */
112 [ 0x6c ] = KEY_VOLUMEDOWN, // volume - 114 [0x2c] = KEY_CHANNELDOWN,
113 [ 0x0c ] = KEY_ZOOM, // Zoom 115 [0x6c] = KEY_VOLUMEDOWN,
114 116 [0x0c] = KEY_ZOOM,
115 [ 0x5c ] = KEY_PAUSE, // pause 117
116 [ 0x3c ] = KEY_C, // || (red) 118 [0x5c] = KEY_PAUSE,
117 [ 0x7c ] = KEY_RECORD, // recording 119 [0x3c] = KEY_C, /* || (red) */
118 [ 0x1c ] = KEY_STOP, // stop 120 [0x7c] = KEY_RECORD, /* recording */
119 121 [0x1c] = KEY_STOP,
120 [ 0x41 ] = KEY_REWIND, // backward << 122
121 [ 0x21 ] = KEY_PLAY, // play 123 [0x41] = KEY_REWIND, /* backward << */
122 [ 0x61 ] = KEY_FASTFORWARD, // forward >> 124 [0x21] = KEY_PLAY,
123 [ 0x01 ] = KEY_NEXT, // skip >| 125 [0x61] = KEY_FASTFORWARD, /* forward >> */
126 [0x01] = KEY_NEXT, /* skip >| */
124}; 127};
125 128
126/* ---------------------------------------------------------------------- */ 129/* ---------------------------------------------------------------------- */
127 130
128/* ADS Tech Instant TV DVB-T PCI Remote */ 131/* ADS Tech Instant TV DVB-T PCI Remote */
129static IR_KEYTAB_TYPE ir_codes_adstech_dvb_t_pci[IR_KEYTAB_SIZE] = { 132static IR_KEYTAB_TYPE ir_codes_adstech_dvb_t_pci[IR_KEYTAB_SIZE] = {
130 [ 0x5b ] = KEY_POWER, 133 /* Keys 0 to 9 */
131 [ 0x5f ] = KEY_MUTE, 134 [0x4d] = KEY_0,
132 [ 0x57 ] = KEY_1, 135 [0x57] = KEY_1,
133 [ 0x4f ] = KEY_2, 136 [0x4f] = KEY_2,
134 [ 0x53 ] = KEY_3, 137 [0x53] = KEY_3,
135 [ 0x56 ] = KEY_4, 138 [0x56] = KEY_4,
136 [ 0x4e ] = KEY_5, 139 [0x4e] = KEY_5,
137 [ 0x5e ] = KEY_6, 140 [0x5e] = KEY_6,
138 [ 0x54 ] = KEY_7, 141 [0x54] = KEY_7,
139 [ 0x4c ] = KEY_8, 142 [0x4c] = KEY_8,
140 [ 0x5c ] = KEY_9, 143 [0x5c] = KEY_9,
141 [ 0x4d ] = KEY_0, 144
142 [ 0x55 ] = KEY_GOTO, 145 [0x5b] = KEY_POWER,
143 [ 0x5d ] = KEY_SEARCH, 146 [0x5f] = KEY_MUTE,
144 [ 0x17 ] = KEY_EPG, // Guide 147 [0x55] = KEY_GOTO,
145 [ 0x1f ] = KEY_MENU, 148 [0x5d] = KEY_SEARCH,
146 [ 0x0f ] = KEY_UP, 149 [0x17] = KEY_EPG, /* Guide */
147 [ 0x46 ] = KEY_DOWN, 150 [0x1f] = KEY_MENU,
148 [ 0x16 ] = KEY_LEFT, 151 [0x0f] = KEY_UP,
149 [ 0x1e ] = KEY_RIGHT, 152 [0x46] = KEY_DOWN,
150 [ 0x0e ] = KEY_SELECT, // Enter 153 [0x16] = KEY_LEFT,
151 [ 0x5a ] = KEY_INFO, 154 [0x1e] = KEY_RIGHT,
152 [ 0x52 ] = KEY_EXIT, 155 [0x0e] = KEY_SELECT, /* Enter */
153 [ 0x59 ] = KEY_PREVIOUS, 156 [0x5a] = KEY_INFO,
154 [ 0x51 ] = KEY_NEXT, 157 [0x52] = KEY_EXIT,
155 [ 0x58 ] = KEY_REWIND, 158 [0x59] = KEY_PREVIOUS,
156 [ 0x50 ] = KEY_FORWARD, 159 [0x51] = KEY_NEXT,
157 [ 0x44 ] = KEY_PLAYPAUSE, 160 [0x58] = KEY_REWIND,
158 [ 0x07 ] = KEY_STOP, 161 [0x50] = KEY_FORWARD,
159 [ 0x1b ] = KEY_RECORD, 162 [0x44] = KEY_PLAYPAUSE,
160 [ 0x13 ] = KEY_TUNER, // Live 163 [0x07] = KEY_STOP,
161 [ 0x0a ] = KEY_A, 164 [0x1b] = KEY_RECORD,
162 [ 0x12 ] = KEY_B, 165 [0x13] = KEY_TUNER, /* Live */
163 [ 0x03 ] = KEY_PROG1, // 1 166 [0x0a] = KEY_A,
164 [ 0x01 ] = KEY_PROG2, // 2 167 [0x12] = KEY_B,
165 [ 0x00 ] = KEY_PROG3, // 3 168 [0x03] = KEY_PROG1, /* 1 */
166 [ 0x06 ] = KEY_DVD, 169 [0x01] = KEY_PROG2, /* 2 */
167 [ 0x48 ] = KEY_AUX, // Photo 170 [0x00] = KEY_PROG3, /* 3 */
168 [ 0x40 ] = KEY_VIDEO, 171 [0x06] = KEY_DVD,
169 [ 0x19 ] = KEY_AUDIO, // Music 172 [0x48] = KEY_AUX, /* Photo */
170 [ 0x0b ] = KEY_CHANNELUP, 173 [0x40] = KEY_VIDEO,
171 [ 0x08 ] = KEY_CHANNELDOWN, 174 [0x19] = KEY_AUDIO, /* Music */
172 [ 0x15 ] = KEY_VOLUMEUP, 175 [0x0b] = KEY_CHANNELUP,
173 [ 0x1c ] = KEY_VOLUMEDOWN, 176 [0x08] = KEY_CHANNELDOWN,
177 [0x15] = KEY_VOLUMEUP,
178 [0x1c] = KEY_VOLUMEDOWN,
174}; 179};
175 180
176/* ---------------------------------------------------------------------- */ 181/* ---------------------------------------------------------------------- */
177 182
178/* MSI TV@nywhere remote */ 183/* MSI TV@nywhere remote */
179static IR_KEYTAB_TYPE ir_codes_msi_tvanywhere[IR_KEYTAB_SIZE] = { 184static IR_KEYTAB_TYPE ir_codes_msi_tvanywhere[IR_KEYTAB_SIZE] = {
180 [ 0x00 ] = KEY_0, /* '0' */ 185 /* Keys 0 to 9 */
181 [ 0x01 ] = KEY_1, /* '1' */ 186 [0x00] = KEY_0,
182 [ 0x02 ] = KEY_2, /* '2' */ 187 [0x01] = KEY_1,
183 [ 0x03 ] = KEY_3, /* '3' */ 188 [0x02] = KEY_2,
184 [ 0x04 ] = KEY_4, /* '4' */ 189 [0x03] = KEY_3,
185 [ 0x05 ] = KEY_5, /* '5' */ 190 [0x04] = KEY_4,
186 [ 0x06 ] = KEY_6, /* '6' */ 191 [0x05] = KEY_5,
187 [ 0x07 ] = KEY_7, /* '7' */ 192 [0x06] = KEY_6,
188 [ 0x08 ] = KEY_8, /* '8' */ 193 [0x07] = KEY_7,
189 [ 0x09 ] = KEY_9, /* '9' */ 194 [0x08] = KEY_8,
190 [ 0x0c ] = KEY_MUTE, /* 'Mute' */ 195 [0x09] = KEY_9,
191 [ 0x0f ] = KEY_SCREEN, /* 'Full Screen' */ 196
192 [ 0x10 ] = KEY_F, /* 'Funtion' */ 197 [0x0c] = KEY_MUTE,
193 [ 0x11 ] = KEY_T, /* 'Time shift' */ 198 [0x0f] = KEY_SCREEN, /* Full Screen */
194 [ 0x12 ] = KEY_POWER, /* 'Power' */ 199 [0x10] = KEY_F, /* Funtion */
195 [ 0x13 ] = KEY_MEDIA, /* 'MTS' */ 200 [0x11] = KEY_T, /* Time shift */
196 [ 0x14 ] = KEY_SLOW, /* 'Slow' */ 201 [0x12] = KEY_POWER,
197 [ 0x16 ] = KEY_REWIND, /* 'backward <<' */ 202 [0x13] = KEY_MEDIA, /* MTS */
198 [ 0x17 ] = KEY_ENTER, /* 'Return' */ 203 [0x14] = KEY_SLOW,
199 [ 0x18 ] = KEY_FASTFORWARD, /* 'forward >>' */ 204 [0x16] = KEY_REWIND, /* backward << */
200 [ 0x1a ] = KEY_CHANNELUP, /* 'Channel+' */ 205 [0x17] = KEY_ENTER, /* Return */
201 [ 0x1b ] = KEY_VOLUMEUP, /* 'Volume+' */ 206 [0x18] = KEY_FASTFORWARD, /* forward >> */
202 [ 0x1e ] = KEY_CHANNELDOWN, /* 'Channel-' */ 207 [0x1a] = KEY_CHANNELUP,
203 [ 0x1f ] = KEY_VOLUMEDOWN, /* 'Volume-' */ 208 [0x1b] = KEY_VOLUMEUP,
209 [0x1e] = KEY_CHANNELDOWN,
210 [0x1f] = KEY_VOLUMEDOWN,
204}; 211};
205 212
206/* ---------------------------------------------------------------------- */ 213/* ---------------------------------------------------------------------- */
207 214
208struct cx88_IR { 215struct cx88_IR {
209 struct cx88_core *core; 216 struct cx88_core *core;
210 struct input_dev input; 217 struct input_dev input;
211 struct ir_input_state ir; 218 struct ir_input_state ir;
212 char name[32]; 219 char name[32];
213 char phys[32]; 220 char phys[32];
214 221
215 /* sample from gpio pin 16 */ 222 /* sample from gpio pin 16 */
216 int sampling; 223 int sampling;
217 u32 samples[16]; 224 u32 samples[16];
218 int scount; 225 int scount;
219 unsigned long release; 226 unsigned long release;
220 227
221 /* poll external decoder */ 228 /* poll external decoder */
222 int polling; 229 int polling;
223 struct work_struct work; 230 struct work_struct work;
224 struct timer_list timer; 231 struct timer_list timer;
225 u32 gpio_addr; 232 u32 gpio_addr;
226 u32 last_gpio; 233 u32 last_gpio;
227 u32 mask_keycode; 234 u32 mask_keycode;
228 u32 mask_keydown; 235 u32 mask_keydown;
229 u32 mask_keyup; 236 u32 mask_keyup;
230}; 237};
231 238
232static int ir_debug = 0; 239static int ir_debug = 0;
233module_param(ir_debug, int, 0644); /* debug level [IR] */ 240module_param(ir_debug, int, 0644); /* debug level [IR] */
234MODULE_PARM_DESC(ir_debug, "enable debug messages [IR]"); 241MODULE_PARM_DESC(ir_debug, "enable debug messages [IR]");
235 242
236#define ir_dprintk(fmt, arg...) if (ir_debug) \ 243#define ir_dprintk(fmt, arg...) if (ir_debug) \
@@ -254,37 +261,37 @@ static void cx88_ir_handle_key(struct cx88_IR *ir)
254 /* extract data */ 261 /* extract data */
255 data = ir_extract_bits(gpio, ir->mask_keycode); 262 data = ir_extract_bits(gpio, ir->mask_keycode);
256 ir_dprintk("irq gpio=0x%x code=%d | %s%s%s\n", 263 ir_dprintk("irq gpio=0x%x code=%d | %s%s%s\n",
257 gpio, data, 264 gpio, data,
258 ir->polling ? "poll" : "irq", 265 ir->polling ? "poll" : "irq",
259 (gpio & ir->mask_keydown) ? " down" : "", 266 (gpio & ir->mask_keydown) ? " down" : "",
260 (gpio & ir->mask_keyup) ? " up" : ""); 267 (gpio & ir->mask_keyup) ? " up" : "");
261 268
262 if (ir->mask_keydown) { 269 if (ir->mask_keydown) {
263 /* bit set on keydown */ 270 /* bit set on keydown */
264 if (gpio & ir->mask_keydown) { 271 if (gpio & ir->mask_keydown) {
265 ir_input_keydown(&ir->input,&ir->ir,data,data); 272 ir_input_keydown(&ir->input, &ir->ir, data, data);
266 } else { 273 } else {
267 ir_input_nokey(&ir->input,&ir->ir); 274 ir_input_nokey(&ir->input, &ir->ir);
268 } 275 }
269 276
270 } else if (ir->mask_keyup) { 277 } else if (ir->mask_keyup) {
271 /* bit cleared on keydown */ 278 /* bit cleared on keydown */
272 if (0 == (gpio & ir->mask_keyup)) { 279 if (0 == (gpio & ir->mask_keyup)) {
273 ir_input_keydown(&ir->input,&ir->ir,data,data); 280 ir_input_keydown(&ir->input, &ir->ir, data, data);
274 } else { 281 } else {
275 ir_input_nokey(&ir->input,&ir->ir); 282 ir_input_nokey(&ir->input, &ir->ir);
276 } 283 }
277 284
278 } else { 285 } else {
279 /* can't distinguish keydown/up :-/ */ 286 /* can't distinguish keydown/up :-/ */
280 ir_input_keydown(&ir->input,&ir->ir,data,data); 287 ir_input_keydown(&ir->input, &ir->ir, data, data);
281 ir_input_nokey(&ir->input,&ir->ir); 288 ir_input_nokey(&ir->input, &ir->ir);
282 } 289 }
283} 290}
284 291
285static void ir_timer(unsigned long data) 292static void ir_timer(unsigned long data)
286{ 293{
287 struct cx88_IR *ir = (struct cx88_IR*)data; 294 struct cx88_IR *ir = (struct cx88_IR *)data;
288 295
289 schedule_work(&ir->work); 296 schedule_work(&ir->work);
290} 297}
@@ -307,62 +314,62 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
307 IR_KEYTAB_TYPE *ir_codes = NULL; 314 IR_KEYTAB_TYPE *ir_codes = NULL;
308 int ir_type = IR_TYPE_OTHER; 315 int ir_type = IR_TYPE_OTHER;
309 316
310 ir = kmalloc(sizeof(*ir),GFP_KERNEL); 317 ir = kmalloc(sizeof(*ir), GFP_KERNEL);
311 if (NULL == ir) 318 if (NULL == ir)
312 return -ENOMEM; 319 return -ENOMEM;
313 memset(ir,0,sizeof(*ir)); 320 memset(ir, 0, sizeof(*ir));
314 321
315 /* detect & configure */ 322 /* detect & configure */
316 switch (core->board) { 323 switch (core->board) {
317 case CX88_BOARD_DNTV_LIVE_DVB_T: 324 case CX88_BOARD_DNTV_LIVE_DVB_T:
318 case CX88_BOARD_KWORLD_DVB_T: 325 case CX88_BOARD_KWORLD_DVB_T:
319 ir_codes = ir_codes_dntv_live_dvb_t; 326 ir_codes = ir_codes_dntv_live_dvb_t;
320 ir->gpio_addr = MO_GP1_IO; 327 ir->gpio_addr = MO_GP1_IO;
321 ir->mask_keycode = 0x1f; 328 ir->mask_keycode = 0x1f;
322 ir->mask_keyup = 0x60; 329 ir->mask_keyup = 0x60;
323 ir->polling = 50; // ms 330 ir->polling = 50; /* ms */
324 break; 331 break;
325 case CX88_BOARD_HAUPPAUGE: 332 case CX88_BOARD_HAUPPAUGE:
326 case CX88_BOARD_HAUPPAUGE_DVB_T1: 333 case CX88_BOARD_HAUPPAUGE_DVB_T1:
327 ir_codes = ir_codes_hauppauge_new; 334 ir_codes = ir_codes_hauppauge_new;
328 ir_type = IR_TYPE_RC5; 335 ir_type = IR_TYPE_RC5;
329 ir->sampling = 1; 336 ir->sampling = 1;
330 break; 337 break;
331 case CX88_BOARD_WINFAST2000XP_EXPERT: 338 case CX88_BOARD_WINFAST2000XP_EXPERT:
332 ir_codes = ir_codes_winfast; 339 ir_codes = ir_codes_winfast;
333 ir->gpio_addr = MO_GP0_IO; 340 ir->gpio_addr = MO_GP0_IO;
334 ir->mask_keycode = 0x8f8; 341 ir->mask_keycode = 0x8f8;
335 ir->mask_keyup = 0x100; 342 ir->mask_keyup = 0x100;
336 ir->polling = 1; // ms 343 ir->polling = 1; /* ms */
337 break; 344 break;
338 case CX88_BOARD_IODATA_GVBCTV7E: 345 case CX88_BOARD_IODATA_GVBCTV7E:
339 ir_codes = ir_codes_iodata_bctv7e; 346 ir_codes = ir_codes_iodata_bctv7e;
340 ir->gpio_addr = MO_GP0_IO; 347 ir->gpio_addr = MO_GP0_IO;
341 ir->mask_keycode = 0xfd; 348 ir->mask_keycode = 0xfd;
342 ir->mask_keydown = 0x02; 349 ir->mask_keydown = 0x02;
343 ir->polling = 5; // ms 350 ir->polling = 5; /* ms */
344 break; 351 break;
345 case CX88_BOARD_PIXELVIEW_PLAYTV_ULTRA_PRO: 352 case CX88_BOARD_PIXELVIEW_PLAYTV_ULTRA_PRO:
346 ir_codes = ir_codes_pixelview; 353 ir_codes = ir_codes_pixelview;
347 ir->gpio_addr = MO_GP1_IO; 354 ir->gpio_addr = MO_GP1_IO;
348 ir->mask_keycode = 0x1f; 355 ir->mask_keycode = 0x1f;
349 ir->mask_keyup = 0x80; 356 ir->mask_keyup = 0x80;
350 ir->polling = 1; // ms 357 ir->polling = 1; /* ms */
351 break; 358 break;
352 case CX88_BOARD_ADSTECH_DVB_T_PCI: 359 case CX88_BOARD_ADSTECH_DVB_T_PCI:
353 ir_codes = ir_codes_adstech_dvb_t_pci; 360 ir_codes = ir_codes_adstech_dvb_t_pci;
354 ir->gpio_addr = MO_GP1_IO; 361 ir->gpio_addr = MO_GP1_IO;
355 ir->mask_keycode = 0xbf; 362 ir->mask_keycode = 0xbf;
356 ir->mask_keyup = 0x40; 363 ir->mask_keyup = 0x40;
357 ir->polling = 50; // ms 364 ir->polling = 50; /* ms */
365 break;
366 case CX88_BOARD_MSI_TVANYWHERE_MASTER:
367 ir_codes = ir_codes_msi_tvanywhere;
368 ir->gpio_addr = MO_GP1_IO;
369 ir->mask_keycode = 0x1f;
370 ir->mask_keyup = 0x40;
371 ir->polling = 1; /* ms */
358 break; 372 break;
359 case CX88_BOARD_MSI_TVANYWHERE_MASTER:
360 ir_codes = ir_codes_msi_tvanywhere;
361 ir->gpio_addr = MO_GP1_IO;
362 ir->mask_keycode = 0x1f;
363 ir->mask_keyup = 0x40;
364 ir->polling = 1;
365 break;
366 } 373 }
367 374
368 if (NULL == ir_codes) { 375 if (NULL == ir_codes) {
@@ -373,8 +380,7 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
373 /* init input device */ 380 /* init input device */
374 snprintf(ir->name, sizeof(ir->name), "cx88 IR (%s)", 381 snprintf(ir->name, sizeof(ir->name), "cx88 IR (%s)",
375 cx88_boards[core->board].name); 382 cx88_boards[core->board].name);
376 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", 383 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", pci_name(pci));
377 pci_name(pci));
378 384
379 ir_input_init(&ir->input, &ir->ir, ir_type, ir_codes); 385 ir_input_init(&ir->input, &ir->ir, ir_type, ir_codes);
380 ir->input.name = ir->name; 386 ir->input.name = ir->name;
@@ -382,10 +388,10 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
382 ir->input.id.bustype = BUS_PCI; 388 ir->input.id.bustype = BUS_PCI;
383 ir->input.id.version = 1; 389 ir->input.id.version = 1;
384 if (pci->subsystem_vendor) { 390 if (pci->subsystem_vendor) {
385 ir->input.id.vendor = pci->subsystem_vendor; 391 ir->input.id.vendor = pci->subsystem_vendor;
386 ir->input.id.product = pci->subsystem_device; 392 ir->input.id.product = pci->subsystem_device;
387 } else { 393 } else {
388 ir->input.id.vendor = pci->vendor; 394 ir->input.id.vendor = pci->vendor;
389 ir->input.id.product = pci->device; 395 ir->input.id.product = pci->device;
390 } 396 }
391 397
@@ -397,13 +403,13 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
397 INIT_WORK(&ir->work, cx88_ir_work, ir); 403 INIT_WORK(&ir->work, cx88_ir_work, ir);
398 init_timer(&ir->timer); 404 init_timer(&ir->timer);
399 ir->timer.function = ir_timer; 405 ir->timer.function = ir_timer;
400 ir->timer.data = (unsigned long)ir; 406 ir->timer.data = (unsigned long)ir;
401 schedule_work(&ir->work); 407 schedule_work(&ir->work);
402 } 408 }
403 if (ir->sampling) { 409 if (ir->sampling) {
404 core->pci_irqmask |= (1<<18); // IR_SMP_INT 410 core->pci_irqmask |= (1 << 18); /* IR_SMP_INT */
405 cx_write(MO_DDS_IO, 0xa80a80); // 4 kHz sample rate 411 cx_write(MO_DDS_IO, 0xa80a80); /* 4 kHz sample rate */
406 cx_write(MO_DDSCFG_IO, 0x5); // enable 412 cx_write(MO_DDSCFG_IO, 0x5); /* enable */
407 } 413 }
408 414
409 /* all done */ 415 /* all done */
@@ -439,7 +445,7 @@ int cx88_ir_fini(struct cx88_core *core)
439void cx88_ir_irq(struct cx88_core *core) 445void cx88_ir_irq(struct cx88_core *core)
440{ 446{
441 struct cx88_IR *ir = core->ir; 447 struct cx88_IR *ir = core->ir;
442 u32 samples,rc5; 448 u32 samples, rc5;
443 int i; 449 int i;
444 450
445 if (NULL == ir) 451 if (NULL == ir)
@@ -448,7 +454,7 @@ void cx88_ir_irq(struct cx88_core *core)
448 return; 454 return;
449 455
450 samples = cx_read(MO_SAMPLE_IO); 456 samples = cx_read(MO_SAMPLE_IO);
451 if (0 != samples && 0xffffffff != samples) { 457 if (0 != samples && 0xffffffff != samples) {
452 /* record sample data */ 458 /* record sample data */
453 if (ir->scount < ARRAY_SIZE(ir->samples)) 459 if (ir->scount < ARRAY_SIZE(ir->samples))
454 ir->samples[ir->scount++] = samples; 460 ir->samples[ir->scount++] = samples;
@@ -456,8 +462,8 @@ void cx88_ir_irq(struct cx88_core *core)
456 } 462 }
457 if (!ir->scount) { 463 if (!ir->scount) {
458 /* nothing to sample */ 464 /* nothing to sample */
459 if (ir->ir.keypressed && time_after(jiffies,ir->release)) 465 if (ir->ir.keypressed && time_after(jiffies, ir->release))
460 ir_input_nokey(&ir->input,&ir->ir); 466 ir_input_nokey(&ir->input, &ir->ir);
461 return; 467 return;
462 } 468 }
463 469
@@ -467,14 +473,14 @@ void cx88_ir_irq(struct cx88_core *core)
467 for (i = 0; i < ir->scount; i++) 473 for (i = 0; i < ir->scount; i++)
468 ir->samples[i] = ~ir->samples[i]; 474 ir->samples[i] = ~ir->samples[i];
469 if (ir_debug) 475 if (ir_debug)
470 ir_dump_samples(ir->samples,ir->scount); 476 ir_dump_samples(ir->samples, ir->scount);
471 477
472 /* decode it */ 478 /* decode it */
473 switch (core->board) { 479 switch (core->board) {
474 case CX88_BOARD_HAUPPAUGE: 480 case CX88_BOARD_HAUPPAUGE:
475 case CX88_BOARD_HAUPPAUGE_DVB_T1: 481 case CX88_BOARD_HAUPPAUGE_DVB_T1:
476 rc5 = ir_decode_biphase(ir->samples,ir->scount,5,7); 482 rc5 = ir_decode_biphase(ir->samples, ir->scount, 5, 7);
477 ir_dprintk("biphase decoded: %x\n",rc5); 483 ir_dprintk("biphase decoded: %x\n", rc5);
478 if ((rc5 & 0xfffff000) != 0x3000) 484 if ((rc5 & 0xfffff000) != 0x3000)
479 break; 485 break;
480 ir_input_keydown(&ir->input, &ir->ir, rc5 & 0x3f, rc5); 486 ir_input_keydown(&ir->input, &ir->ir, rc5 & 0x3f, rc5);
diff --git a/drivers/media/video/cx88/cx88-mpeg.c b/drivers/media/video/cx88/cx88-mpeg.c
index 85da6dc8d0e0..fe2767c0ff94 100644
--- a/drivers/media/video/cx88/cx88-mpeg.c
+++ b/drivers/media/video/cx88/cx88-mpeg.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: cx88-mpeg.c,v 1.30 2005/07/05 19:44:40 mkrufky Exp $ 2 * $Id: cx88-mpeg.c,v 1.31 2005/07/07 14:17:47 mchehab Exp $
3 * 3 *
4 * Support for the mpeg transport stream transfers 4 * Support for the mpeg transport stream transfers
5 * PCI function #2 of the cx2388x. 5 * PCI function #2 of the cx2388x.
@@ -64,7 +64,6 @@ static int cx8802_start_dma(struct cx8802_dev *dev,
64 /* write TS length to chip */ 64 /* write TS length to chip */
65 cx_write(MO_TS_LNGTH, buf->vb.width); 65 cx_write(MO_TS_LNGTH, buf->vb.width);
66 66
67#if 1
68 /* FIXME: this needs a review. 67 /* FIXME: this needs a review.
69 * also: move to cx88-blackbird + cx88-dvb source files? */ 68 * also: move to cx88-blackbird + cx88-dvb source files? */
70 69
@@ -76,9 +75,9 @@ static int cx8802_start_dma(struct cx8802_dev *dev,
76 cx_write(TS_HW_SOP_CNTRL,0x47<<16|188<<4|0x01); 75 cx_write(TS_HW_SOP_CNTRL,0x47<<16|188<<4|0x01);
77 if ((core->board == CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q) || 76 if ((core->board == CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q) ||
78 (core->board == CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_T)) { 77 (core->board == CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_T)) {
79 cx_write(TS_SOP_STAT, 0<<16 | 0<<14 | 1<<13 | 0<<12); 78 cx_write(TS_SOP_STAT, 1<<13);
80 } else { 79 } else {
81 cx_write(TS_SOP_STAT,0x00); 80 cx_write(TS_SOP_STAT, 0x00);
82 } 81 }
83 cx_write(TS_GEN_CNTRL, dev->ts_gen_cntrl); 82 cx_write(TS_GEN_CNTRL, dev->ts_gen_cntrl);
84 udelay(100); 83 udelay(100);
@@ -98,7 +97,6 @@ static int cx8802_start_dma(struct cx8802_dev *dev,
98 cx_write(TS_GEN_CNTRL, 0x06); /* punctured clock TS & posedge driven */ 97 cx_write(TS_GEN_CNTRL, 0x06); /* punctured clock TS & posedge driven */
99 udelay(100); 98 udelay(100);
100 } 99 }
101#endif
102 100
103 /* reset counter */ 101 /* reset counter */
104 cx_write(MO_TS_GPCNTRL, GP_COUNT_CONTROL_RESET); 102 cx_write(MO_TS_GPCNTRL, GP_COUNT_CONTROL_RESET);
@@ -270,6 +268,15 @@ static void cx8802_timeout(unsigned long data)
270 do_cancel_buffers(dev,"timeout",1); 268 do_cancel_buffers(dev,"timeout",1);
271} 269}
272 270
271static char *cx88_mpeg_irqs[32] = {
272 "ts_risci1", NULL, NULL, NULL,
273 "ts_risci2", NULL, NULL, NULL,
274 "ts_oflow", NULL, NULL, NULL,
275 "ts_sync", NULL, NULL, NULL,
276 "opc_err", "par_err", "rip_err", "pci_abort",
277 "ts_err?",
278};
279
273static void cx8802_mpeg_irq(struct cx8802_dev *dev) 280static void cx8802_mpeg_irq(struct cx8802_dev *dev)
274{ 281{
275 struct cx88_core *core = dev->core; 282 struct cx88_core *core = dev->core;
@@ -282,10 +289,7 @@ static void cx8802_mpeg_irq(struct cx8802_dev *dev)
282 return; 289 return;
283 290
284 cx_write(MO_TS_INTSTAT, status); 291 cx_write(MO_TS_INTSTAT, status);
285#if 0 292
286 cx88_print_irqbits(core->name, "irq mpeg ",
287 cx88_mpeg_irqs, status, mask);
288#endif
289 if (debug || (status & mask & ~0xff)) 293 if (debug || (status & mask & ~0xff))
290 cx88_print_irqbits(core->name, "irq mpeg ", 294 cx88_print_irqbits(core->name, "irq mpeg ",
291 cx88_mpeg_irqs, status, mask); 295 cx88_mpeg_irqs, status, mask);
@@ -441,10 +445,8 @@ int cx8802_suspend_common(struct pci_dev *pci_dev, pm_message_t state)
441 } 445 }
442 spin_unlock(&dev->slock); 446 spin_unlock(&dev->slock);
443 447
444#if 1
445 /* FIXME -- shutdown device */ 448 /* FIXME -- shutdown device */
446 cx88_shutdown(dev->core); 449 cx88_shutdown(dev->core);
447#endif
448 450
449 pci_save_state(pci_dev); 451 pci_save_state(pci_dev);
450 if (0 != pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state))) { 452 if (0 != pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state))) {
@@ -466,10 +468,8 @@ int cx8802_resume_common(struct pci_dev *pci_dev)
466 pci_set_power_state(pci_dev, PCI_D0); 468 pci_set_power_state(pci_dev, PCI_D0);
467 pci_restore_state(pci_dev); 469 pci_restore_state(pci_dev);
468 470
469#if 1
470 /* FIXME: re-initialize hardware */ 471 /* FIXME: re-initialize hardware */
471 cx88_reset(dev->core); 472 cx88_reset(dev->core);
472#endif
473 473
474 /* restart video+vbi capture */ 474 /* restart video+vbi capture */
475 spin_lock(&dev->slock); 475 spin_lock(&dev->slock);
diff --git a/drivers/media/video/cx88/cx88-reg.h b/drivers/media/video/cx88/cx88-reg.h
index 63ad33f5818b..37f82662d265 100644
--- a/drivers/media/video/cx88/cx88-reg.h
+++ b/drivers/media/video/cx88/cx88-reg.h
@@ -1,5 +1,5 @@
1/* 1/*
2 $Id: cx88-reg.h,v 1.7 2005/06/03 13:31:51 mchehab Exp $ 2 $Id: cx88-reg.h,v 1.8 2005/07/07 13:58:38 mchehab Exp $
3 3
4 cx88x-hw.h - CX2388x register offsets 4 cx88x-hw.h - CX2388x register offsets
5 5
@@ -604,20 +604,11 @@
604#define EN_I2SIN_STR2DAC 0x00004000 604#define EN_I2SIN_STR2DAC 0x00004000
605#define EN_I2SIN_ENABLE 0x00008000 605#define EN_I2SIN_ENABLE 0x00008000
606 606
607#if 0
608/* old */
609#define EN_DMTRX_SUMDIFF 0x00000800
610#define EN_DMTRX_SUMR 0x00000880
611#define EN_DMTRX_LR 0x00000900
612#define EN_DMTRX_MONO 0x00000980
613#else
614/* dscaler cvs */
615#define EN_DMTRX_SUMDIFF (0 << 7) 607#define EN_DMTRX_SUMDIFF (0 << 7)
616#define EN_DMTRX_SUMR (1 << 7) 608#define EN_DMTRX_SUMR (1 << 7)
617#define EN_DMTRX_LR (2 << 7) 609#define EN_DMTRX_LR (2 << 7)
618#define EN_DMTRX_MONO (3 << 7) 610#define EN_DMTRX_MONO (3 << 7)
619#define EN_DMTRX_BYPASS (1 << 11) 611#define EN_DMTRX_BYPASS (1 << 11)
620#endif
621 612
622// Video 613// Video
623#define VID_CAPTURE_CONTROL 0x310180 614#define VID_CAPTURE_CONTROL 0x310180
diff --git a/drivers/media/video/cx88/cx88-tvaudio.c b/drivers/media/video/cx88/cx88-tvaudio.c
index 46d78b1dc9b2..91207f10bae7 100644
--- a/drivers/media/video/cx88/cx88-tvaudio.c
+++ b/drivers/media/video/cx88/cx88-tvaudio.c
@@ -1,5 +1,5 @@
1/* 1/*
2 $Id: cx88-tvaudio.c,v 1.36 2005/06/05 05:53:45 mchehab Exp $ 2 $Id: cx88-tvaudio.c,v 1.37 2005/07/07 13:58:38 mchehab Exp $
3 3
4 cx88x-audio.c - Conexant CX23880/23881 audio downstream driver driver 4 cx88x-audio.c - Conexant CX23880/23881 audio downstream driver driver
5 5
@@ -278,80 +278,6 @@ static void set_audio_standard_BTSC(struct cx88_core *core, unsigned int sap)
278 set_audio_finish(core); 278 set_audio_finish(core);
279} 279}
280 280
281#if 0
282static void set_audio_standard_NICAM(struct cx88_core *core)
283{
284 static const struct rlist nicam_common[] = {
285 /* from dscaler */
286 { AUD_RATE_ADJ1, 0x00000010 },
287 { AUD_RATE_ADJ2, 0x00000040 },
288 { AUD_RATE_ADJ3, 0x00000100 },
289 { AUD_RATE_ADJ4, 0x00000400 },
290 { AUD_RATE_ADJ5, 0x00001000 },
291 // { AUD_DMD_RA_DDS, 0x00c0d5ce },
292
293 // Deemphasis 1:
294 { AUD_DEEMPHGAIN_R, 0x000023c2 },
295 { AUD_DEEMPHNUMER1_R, 0x0002a7bc },
296 { AUD_DEEMPHNUMER2_R, 0x0003023e },
297 { AUD_DEEMPHDENOM1_R, 0x0000f3d0 },
298 { AUD_DEEMPHDENOM2_R, 0x00000000 },
299
300#if 0
301 // Deemphasis 2: (other tv norm?)
302 { AUD_DEEMPHGAIN_R, 0x0000c600 },
303 { AUD_DEEMPHNUMER1_R, 0x00066738 },
304 { AUD_DEEMPHNUMER2_R, 0x00066739 },
305 { AUD_DEEMPHDENOM1_R, 0x0001e88c },
306 { AUD_DEEMPHDENOM2_R, 0x0001e88c },
307#endif
308
309 { AUD_DEEMPHDENOM2_R, 0x00000000 },
310 { AUD_ERRLOGPERIOD_R, 0x00000fff },
311 { AUD_ERRINTRPTTHSHLD1_R, 0x000003ff },
312 { AUD_ERRINTRPTTHSHLD2_R, 0x000000ff },
313 { AUD_ERRINTRPTTHSHLD3_R, 0x0000003f },
314 { AUD_POLYPH80SCALEFAC, 0x00000003 },
315
316 // setup QAM registers
317 { AUD_PDF_DDS_CNST_BYTE2, 0x06 },
318 { AUD_PDF_DDS_CNST_BYTE1, 0x82 },
319 { AUD_PDF_DDS_CNST_BYTE0, 0x16 },
320 { AUD_QAM_MODE, 0x05 },
321
322 { /* end of list */ },
323 };
324 static const struct rlist nicam_pal_i[] = {
325 { AUD_PDF_DDS_CNST_BYTE0, 0x12 },
326 { AUD_PHACC_FREQ_8MSB, 0x3a },
327 { AUD_PHACC_FREQ_8LSB, 0x93 },
328
329 { /* end of list */ },
330 };
331 static const struct rlist nicam_default[] = {
332 { AUD_PDF_DDS_CNST_BYTE0, 0x16 },
333 { AUD_PHACC_FREQ_8MSB, 0x34 },
334 { AUD_PHACC_FREQ_8LSB, 0x4c },
335
336 { /* end of list */ },
337 };
338
339 set_audio_start(core, 0x0010,
340 EN_DMTRX_LR | EN_DMTRX_BYPASS | EN_NICAM_AUTO_STEREO);
341 set_audio_registers(core, nicam_common);
342 switch (core->tvaudio) {
343 case WW_NICAM_I:
344 dprintk("%s PAL-I NICAM (status: unknown)\n",__FUNCTION__);
345 set_audio_registers(core, nicam_pal_i);
346 break;
347 case WW_NICAM_BGDKL:
348 dprintk("%s PAL-BGDK NICAM (status: unknown)\n",__FUNCTION__);
349 set_audio_registers(core, nicam_default);
350 break;
351 };
352 set_audio_finish(core);
353}
354#endif
355 281
356static void set_audio_standard_NICAM_L(struct cx88_core *core, int stereo) 282static void set_audio_standard_NICAM_L(struct cx88_core *core, int stereo)
357{ 283{
diff --git a/drivers/media/video/cx88/cx88-video.c b/drivers/media/video/cx88/cx88-video.c
index dc997549b634..c44a079d08c0 100644
--- a/drivers/media/video/cx88/cx88-video.c
+++ b/drivers/media/video/cx88/cx88-video.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: cx88-video.c,v 1.70 2005/06/20 03:36:00 mkrufky Exp $ 2 * $Id: cx88-video.c,v 1.79 2005/07/07 14:17:47 mchehab Exp $
3 * 3 *
4 * device driver for Conexant 2388x based TV cards 4 * device driver for Conexant 2388x based TV cards
5 * video4linux video interface 5 * video4linux video interface
@@ -86,13 +86,6 @@ static struct cx88_tvnorm tvnorms[] = {
86 .id = V4L2_STD_NTSC_M_JP, 86 .id = V4L2_STD_NTSC_M_JP,
87 .cxiformat = VideoFormatNTSCJapan, 87 .cxiformat = VideoFormatNTSCJapan,
88 .cxoformat = 0x181f0008, 88 .cxoformat = 0x181f0008,
89#if 0
90 },{
91 .name = "NTSC-4.43",
92 .id = FIXME,
93 .cxiformat = VideoFormatNTSC443,
94 .cxoformat = 0x181f0008,
95#endif
96 },{ 89 },{
97 .name = "PAL-BG", 90 .name = "PAL-BG",
98 .id = V4L2_STD_PAL_BG, 91 .id = V4L2_STD_PAL_BG,
@@ -248,6 +241,7 @@ static struct cx88_ctrl cx8800_ctls[] = {
248 .default_value = 0, 241 .default_value = 0,
249 .type = V4L2_CTRL_TYPE_INTEGER, 242 .type = V4L2_CTRL_TYPE_INTEGER,
250 }, 243 },
244 .off = 0,
251 .reg = MO_CONTR_BRIGHT, 245 .reg = MO_CONTR_BRIGHT,
252 .mask = 0xff00, 246 .mask = 0xff00,
253 .shift = 8, 247 .shift = 8,
@@ -674,231 +668,6 @@ static struct videobuf_queue_ops cx8800_video_qops = {
674 668
675/* ------------------------------------------------------------------ */ 669/* ------------------------------------------------------------------ */
676 670
677#if 0 /* overlay support not finished yet */
678static u32* ov_risc_field(struct cx8800_dev *dev, struct cx8800_fh *fh,
679 u32 *rp, struct btcx_skiplist *skips,
680 u32 sync_line, int skip_even, int skip_odd)
681{
682 int line,maxy,start,end,skip,nskips;
683 u32 ri,ra;
684 u32 addr;
685
686 /* sync instruction */
687 *(rp++) = cpu_to_le32(RISC_RESYNC | sync_line);
688
689 addr = (unsigned long)dev->fbuf.base;
690 addr += dev->fbuf.fmt.bytesperline * fh->win.w.top;
691 addr += (fh->fmt->depth >> 3) * fh->win.w.left;
692
693 /* scan lines */
694 for (maxy = -1, line = 0; line < fh->win.w.height;
695 line++, addr += dev->fbuf.fmt.bytesperline) {
696 if ((line%2) == 0 && skip_even)
697 continue;
698 if ((line%2) == 1 && skip_odd)
699 continue;
700
701 /* calculate clipping */
702 if (line > maxy)
703 btcx_calc_skips(line, fh->win.w.width, &maxy,
704 skips, &nskips, fh->clips, fh->nclips);
705
706 /* write out risc code */
707 for (start = 0, skip = 0; start < fh->win.w.width; start = end) {
708 if (skip >= nskips) {
709 ri = RISC_WRITE;
710 end = fh->win.w.width;
711 } else if (start < skips[skip].start) {
712 ri = RISC_WRITE;
713 end = skips[skip].start;
714 } else {
715 ri = RISC_SKIP;
716 end = skips[skip].end;
717 skip++;
718 }
719 if (RISC_WRITE == ri)
720 ra = addr + (fh->fmt->depth>>3)*start;
721 else
722 ra = 0;
723
724 if (0 == start)
725 ri |= RISC_SOL;
726 if (fh->win.w.width == end)
727 ri |= RISC_EOL;
728 ri |= (fh->fmt->depth>>3) * (end-start);
729
730 *(rp++)=cpu_to_le32(ri);
731 if (0 != ra)
732 *(rp++)=cpu_to_le32(ra);
733 }
734 }
735 kfree(skips);
736 return rp;
737}
738
739static int ov_risc_frame(struct cx8800_dev *dev, struct cx8800_fh *fh,
740 struct cx88_buffer *buf)
741{
742 struct btcx_skiplist *skips;
743 u32 instructions,fields;
744 u32 *rp;
745 int rc;
746
747 /* skip list for window clipping */
748 if (NULL == (skips = kmalloc(sizeof(*skips) * fh->nclips,GFP_KERNEL)))
749 return -ENOMEM;
750
751 fields = 0;
752 if (V4L2_FIELD_HAS_TOP(fh->win.field))
753 fields++;
754 if (V4L2_FIELD_HAS_BOTTOM(fh->win.field))
755 fields++;
756
757 /* estimate risc mem: worst case is (clip+1) * lines instructions
758 + syncs + jump (all 2 dwords) */
759 instructions = (fh->nclips+1) * fh->win.w.height;
760 instructions += 3 + 4;
761 if ((rc = btcx_riscmem_alloc(dev->pci,&buf->risc,instructions*8)) < 0) {
762 kfree(skips);
763 return rc;
764 }
765
766 /* write risc instructions */
767 rp = buf->risc.cpu;
768 switch (fh->win.field) {
769 case V4L2_FIELD_TOP:
770 rp = ov_risc_field(dev, fh, rp, skips, 0, 0, 0);
771 break;
772 case V4L2_FIELD_BOTTOM:
773 rp = ov_risc_field(dev, fh, rp, skips, 0x200, 0, 0);
774 break;
775 case V4L2_FIELD_INTERLACED:
776 rp = ov_risc_field(dev, fh, rp, skips, 0, 0, 1);
777 rp = ov_risc_field(dev, fh, rp, skips, 0x200, 1, 0);
778 break;
779 default:
780 BUG();
781 }
782
783 /* save pointer to jmp instruction address */
784 buf->risc.jmp = rp;
785 kfree(skips);
786 return 0;
787}
788
789static int verify_window(struct cx8800_dev *dev, struct v4l2_window *win)
790{
791 enum v4l2_field field;
792 int maxw, maxh;
793
794 if (NULL == dev->fbuf.base)
795 return -EINVAL;
796 if (win->w.width < 48 || win->w.height < 32)
797 return -EINVAL;
798 if (win->clipcount > 2048)
799 return -EINVAL;
800
801 field = win->field;
802 maxw = norm_maxw(core->tvnorm);
803 maxh = norm_maxh(core->tvnorm);
804
805 if (V4L2_FIELD_ANY == field) {
806 field = (win->w.height > maxh/2)
807 ? V4L2_FIELD_INTERLACED
808 : V4L2_FIELD_TOP;
809 }
810 switch (field) {
811 case V4L2_FIELD_TOP:
812 case V4L2_FIELD_BOTTOM:
813 maxh = maxh / 2;
814 break;
815 case V4L2_FIELD_INTERLACED:
816 break;
817 default:
818 return -EINVAL;
819 }
820
821 win->field = field;
822 if (win->w.width > maxw)
823 win->w.width = maxw;
824 if (win->w.height > maxh)
825 win->w.height = maxh;
826 return 0;
827}
828
829static int setup_window(struct cx8800_dev *dev, struct cx8800_fh *fh,
830 struct v4l2_window *win)
831{
832 struct v4l2_clip *clips = NULL;
833 int n,size,retval = 0;
834
835 if (NULL == fh->fmt)
836 return -EINVAL;
837 retval = verify_window(dev,win);
838 if (0 != retval)
839 return retval;
840
841 /* copy clips -- luckily v4l1 + v4l2 are binary
842 compatible here ...*/
843 n = win->clipcount;
844 size = sizeof(*clips)*(n+4);
845 clips = kmalloc(size,GFP_KERNEL);
846 if (NULL == clips)
847 return -ENOMEM;
848 if (n > 0) {
849 if (copy_from_user(clips,win->clips,sizeof(struct v4l2_clip)*n)) {
850 kfree(clips);
851 return -EFAULT;
852 }
853 }
854
855 /* clip against screen */
856 if (NULL != dev->fbuf.base)
857 n = btcx_screen_clips(dev->fbuf.fmt.width, dev->fbuf.fmt.height,
858 &win->w, clips, n);
859 btcx_sort_clips(clips,n);
860
861 /* 4-byte alignments */
862 switch (fh->fmt->depth) {
863 case 8:
864 case 24:
865 btcx_align(&win->w, clips, n, 3);
866 break;
867 case 16:
868 btcx_align(&win->w, clips, n, 1);
869 break;
870 case 32:
871 /* no alignment fixups needed */
872 break;
873 default:
874 BUG();
875 }
876
877 down(&fh->vidq.lock);
878 if (fh->clips)
879 kfree(fh->clips);
880 fh->clips = clips;
881 fh->nclips = n;
882 fh->win = *win;
883#if 0
884 fh->ov.setup_ok = 1;
885#endif
886
887 /* update overlay if needed */
888 retval = 0;
889#if 0
890 if (check_btres(fh, RESOURCE_OVERLAY)) {
891 struct bttv_buffer *new;
892
893 new = videobuf_alloc(sizeof(*new));
894 bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new);
895 retval = bttv_switch_overlay(btv,fh,new);
896 }
897#endif
898 up(&fh->vidq.lock);
899 return retval;
900}
901#endif
902 671
903/* ------------------------------------------------------------------ */ 672/* ------------------------------------------------------------------ */
904 673
@@ -1327,9 +1096,6 @@ static int video_do_ioctl(struct inode *inode, struct file *file,
1327 struct cx8800_fh *fh = file->private_data; 1096 struct cx8800_fh *fh = file->private_data;
1328 struct cx8800_dev *dev = fh->dev; 1097 struct cx8800_dev *dev = fh->dev;
1329 struct cx88_core *core = dev->core; 1098 struct cx88_core *core = dev->core;
1330#if 0
1331 unsigned long flags;
1332#endif
1333 int err; 1099 int err;
1334 1100
1335 if (video_debug > 1) 1101 if (video_debug > 1)
@@ -1350,9 +1116,6 @@ static int video_do_ioctl(struct inode *inode, struct file *file,
1350 V4L2_CAP_READWRITE | 1116 V4L2_CAP_READWRITE |
1351 V4L2_CAP_STREAMING | 1117 V4L2_CAP_STREAMING |
1352 V4L2_CAP_VBI_CAPTURE | 1118 V4L2_CAP_VBI_CAPTURE |
1353#if 0
1354 V4L2_CAP_VIDEO_OVERLAY |
1355#endif
1356 0; 1119 0;
1357 if (UNSET != core->tuner_type) 1120 if (UNSET != core->tuner_type)
1358 cap->capabilities |= V4L2_CAP_TUNER; 1121 cap->capabilities |= V4L2_CAP_TUNER;
@@ -1453,36 +1216,6 @@ static int video_do_ioctl(struct inode *inode, struct file *file,
1453 } 1216 }
1454 1217
1455 1218
1456#if 0
1457 /* needs review */
1458 case VIDIOC_G_AUDIO:
1459 {
1460 struct v4l2_audio *a = arg;
1461 unsigned int n = a->index;
1462
1463 memset(a,0,sizeof(*a));
1464 a->index = n;
1465 switch (n) {
1466 case 0:
1467 if ((CX88_VMUX_TELEVISION == INPUT(n)->type)
1468 || (CX88_VMUX_CABLE == INPUT(n)->type)) {
1469 strcpy(a->name,"Television");
1470 // FIXME figure out if stereo received and set V4L2_AUDCAP_STEREO.
1471 return 0;
1472 }
1473 break;
1474 case 1:
1475 if (CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q == core->board) {
1476 strcpy(a->name,"Line In");
1477 a->capability = V4L2_AUDCAP_STEREO;
1478 return 0;
1479 }
1480 break;
1481 }
1482 // Audio input not available.
1483 return -EINVAL;
1484 }
1485#endif
1486 1219
1487 /* --- capture ioctls ---------------------------------------- */ 1220 /* --- capture ioctls ---------------------------------------- */
1488 case VIDIOC_ENUM_FMT: 1221 case VIDIOC_ENUM_FMT:
@@ -1592,6 +1325,9 @@ static int video_do_ioctl(struct inode *inode, struct file *file,
1592 1325
1593 f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; 1326 f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1594 f->frequency = dev->freq; 1327 f->frequency = dev->freq;
1328
1329 cx88_call_i2c_clients(dev->core,VIDIOC_G_FREQUENCY,f);
1330
1595 return 0; 1331 return 0;
1596 } 1332 }
1597 case VIDIOC_S_FREQUENCY: 1333 case VIDIOC_S_FREQUENCY:
@@ -1846,6 +1582,14 @@ static void cx8800_vid_timeout(unsigned long data)
1846 spin_unlock_irqrestore(&dev->slock,flags); 1582 spin_unlock_irqrestore(&dev->slock,flags);
1847} 1583}
1848 1584
1585static char *cx88_vid_irqs[32] = {
1586 "y_risci1", "u_risci1", "v_risci1", "vbi_risc1",
1587 "y_risci2", "u_risci2", "v_risci2", "vbi_risc2",
1588 "y_oflow", "u_oflow", "v_oflow", "vbi_oflow",
1589 "y_sync", "u_sync", "v_sync", "vbi_sync",
1590 "opc_err", "par_err", "rip_err", "pci_abort",
1591};
1592
1849static void cx8800_vid_irq(struct cx8800_dev *dev) 1593static void cx8800_vid_irq(struct cx8800_dev *dev)
1850{ 1594{
1851 struct cx88_core *core = dev->core; 1595 struct cx88_core *core = dev->core;
@@ -2013,7 +1757,6 @@ static int __devinit cx8800_initdev(struct pci_dev *pci_dev,
2013{ 1757{
2014 struct cx8800_dev *dev; 1758 struct cx8800_dev *dev;
2015 struct cx88_core *core; 1759 struct cx88_core *core;
2016 struct tuner_addr tun_addr;
2017 int err; 1760 int err;
2018 1761
2019 dev = kmalloc(sizeof(*dev),GFP_KERNEL); 1762 dev = kmalloc(sizeof(*dev),GFP_KERNEL);
@@ -2087,22 +1830,6 @@ static int __devinit cx8800_initdev(struct pci_dev *pci_dev,
2087 request_module("tuner"); 1830 request_module("tuner");
2088 if (core->tda9887_conf) 1831 if (core->tda9887_conf)
2089 request_module("tda9887"); 1832 request_module("tda9887");
2090 if (core->radio_type != UNSET) {
2091 tun_addr.v4l2_tuner = V4L2_TUNER_RADIO;
2092 tun_addr.type = core->radio_type;
2093 tun_addr.addr = core->radio_addr;
2094 cx88_call_i2c_clients(dev->core,TUNER_SET_TYPE_ADDR, &tun_addr);
2095 }
2096 if (core->tuner_type != UNSET) {
2097 tun_addr.v4l2_tuner = V4L2_TUNER_ANALOG_TV;
2098 tun_addr.type = core->tuner_type;
2099 tun_addr.addr = core->tuner_addr;
2100 cx88_call_i2c_clients(dev->core,TUNER_SET_TYPE_ADDR, &tun_addr);
2101 }
2102
2103 if (core->tda9887_conf)
2104 cx88_call_i2c_clients(dev->core,TDA9887_SET_CONFIG,&core->tda9887_conf);
2105
2106 /* register v4l devices */ 1833 /* register v4l devices */
2107 dev->video_dev = cx88_vdev_init(core,dev->pci, 1834 dev->video_dev = cx88_vdev_init(core,dev->pci,
2108 &cx8800_video_template,"video"); 1835 &cx8800_video_template,"video");
@@ -2212,10 +1939,8 @@ static int cx8800_suspend(struct pci_dev *pci_dev, pm_message_t state)
2212 } 1939 }
2213 spin_unlock(&dev->slock); 1940 spin_unlock(&dev->slock);
2214 1941
2215#if 1
2216 /* FIXME -- shutdown device */ 1942 /* FIXME -- shutdown device */
2217 cx88_shutdown(dev->core); 1943 cx88_shutdown(dev->core);
2218#endif
2219 1944
2220 pci_save_state(pci_dev); 1945 pci_save_state(pci_dev);
2221 if (0 != pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state))) { 1946 if (0 != pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state))) {
@@ -2237,10 +1962,8 @@ static int cx8800_resume(struct pci_dev *pci_dev)
2237 pci_set_power_state(pci_dev, PCI_D0); 1962 pci_set_power_state(pci_dev, PCI_D0);
2238 pci_restore_state(pci_dev); 1963 pci_restore_state(pci_dev);
2239 1964
2240#if 1
2241 /* FIXME: re-initialize hardware */ 1965 /* FIXME: re-initialize hardware */
2242 cx88_reset(dev->core); 1966 cx88_reset(dev->core);
2243#endif
2244 1967
2245 /* restart video+vbi capture */ 1968 /* restart video+vbi capture */
2246 spin_lock(&dev->slock); 1969 spin_lock(&dev->slock);
diff --git a/drivers/media/video/cx88/cx88.h b/drivers/media/video/cx88/cx88.h
index bc5e038bc0fe..307beae04f2a 100644
--- a/drivers/media/video/cx88/cx88.h
+++ b/drivers/media/video/cx88/cx88.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: cx88.h,v 1.67 2005/07/01 12:10:07 mkrufky Exp $ 2 * $Id: cx88.h,v 1.68 2005/07/07 14:17:47 mchehab Exp $
3 * 3 *
4 * v4l2 device driver for cx2388x based TV cards 4 * v4l2 device driver for cx2388x based TV cards
5 * 5 *
@@ -82,9 +82,9 @@ struct cx88_tvnorm {
82static unsigned int inline norm_maxw(struct cx88_tvnorm *norm) 82static unsigned int inline norm_maxw(struct cx88_tvnorm *norm)
83{ 83{
84 return (norm->id & V4L2_STD_625_50) ? 768 : 640; 84 return (norm->id & V4L2_STD_625_50) ? 768 : 640;
85// return (norm->id & V4L2_STD_625_50) ? 720 : 640;
86} 85}
87 86
87
88static unsigned int inline norm_maxh(struct cx88_tvnorm *norm) 88static unsigned int inline norm_maxh(struct cx88_tvnorm *norm)
89{ 89{
90 return (norm->id & V4L2_STD_625_50) ? 576 : 480; 90 return (norm->id & V4L2_STD_625_50) ? 576 : 480;
@@ -220,7 +220,6 @@ struct cx88_subid {
220#define RESOURCE_VBI 4 220#define RESOURCE_VBI 4
221 221
222#define BUFFER_TIMEOUT (HZ/2) /* 0.5 seconds */ 222#define BUFFER_TIMEOUT (HZ/2) /* 0.5 seconds */
223//#define BUFFER_TIMEOUT (HZ*2)
224 223
225/* buffer for one video frame */ 224/* buffer for one video frame */
226struct cx88_buffer { 225struct cx88_buffer {
@@ -336,11 +335,6 @@ struct cx8800_dev {
336 struct pci_dev *pci; 335 struct pci_dev *pci;
337 unsigned char pci_rev,pci_lat; 336 unsigned char pci_rev,pci_lat;
338 337
339#if 0
340 /* video overlay */
341 struct v4l2_framebuffer fbuf;
342 struct cx88_buffer *screen;
343#endif
344 338
345 /* capture queues */ 339 /* capture queues */
346 struct cx88_dmaqueue vidq; 340 struct cx88_dmaqueue vidq;
@@ -435,8 +429,6 @@ struct cx8802_dev {
435/* ----------------------------------------------------------- */ 429/* ----------------------------------------------------------- */
436/* cx88-core.c */ 430/* cx88-core.c */
437 431
438extern char *cx88_vid_irqs[32];
439extern char *cx88_mpeg_irqs[32];
440extern void cx88_print_irqbits(char *name, char *tag, char **strings, 432extern void cx88_print_irqbits(char *name, char *tag, char **strings,
441 u32 bits, u32 mask); 433 u32 bits, u32 mask);
442extern void cx88_print_ioctl(char *name, unsigned int cmd); 434extern void cx88_print_ioctl(char *name, unsigned int cmd);
diff --git a/drivers/media/video/ir-kbd-i2c.c b/drivers/media/video/ir-kbd-i2c.c
index 92664f75d327..9fc5055e001c 100644
--- a/drivers/media/video/ir-kbd-i2c.c
+++ b/drivers/media/video/ir-kbd-i2c.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: ir-kbd-i2c.c,v 1.10 2004/12/09 12:51:35 kraxel Exp $ 2 * $Id: ir-kbd-i2c.c,v 1.11 2005/07/07 16:42:11 mchehab Exp $
3 * 3 *
4 * keyboard input driver for i2c IR remote controls 4 * keyboard input driver for i2c IR remote controls
5 * 5 *
@@ -66,26 +66,26 @@ static IR_KEYTAB_TYPE ir_codes_pv951[IR_KEYTAB_SIZE] = {
66 [ 29 ] = KEY_PAGEDOWN, 66 [ 29 ] = KEY_PAGEDOWN,
67 [ 19 ] = KEY_SOUND, 67 [ 19 ] = KEY_SOUND,
68 68
69 [ 24 ] = KEY_KPPLUSMINUS, // CH +/- 69 [ 24 ] = KEY_KPPLUSMINUS, /* CH +/- */
70 [ 22 ] = KEY_SUBTITLE, // CC 70 [ 22 ] = KEY_SUBTITLE, /* CC */
71 [ 13 ] = KEY_TEXT, // TTX 71 [ 13 ] = KEY_TEXT, /* TTX */
72 [ 11 ] = KEY_TV, // AIR/CBL 72 [ 11 ] = KEY_TV, /* AIR/CBL */
73 [ 17 ] = KEY_PC, // PC/TV 73 [ 17 ] = KEY_PC, /* PC/TV */
74 [ 23 ] = KEY_OK, // CH RTN 74 [ 23 ] = KEY_OK, /* CH RTN */
75 [ 25 ] = KEY_MODE, // FUNC 75 [ 25 ] = KEY_MODE, /* FUNC */
76 [ 12 ] = KEY_SEARCH, // AUTOSCAN 76 [ 12 ] = KEY_SEARCH, /* AUTOSCAN */
77 77
78 /* Not sure what to do with these ones! */ 78 /* Not sure what to do with these ones! */
79 [ 15 ] = KEY_SELECT, // SOURCE 79 [ 15 ] = KEY_SELECT, /* SOURCE */
80 [ 10 ] = KEY_KPPLUS, // +100 80 [ 10 ] = KEY_KPPLUS, /* +100 */
81 [ 20 ] = KEY_KPEQUAL, // SYNC 81 [ 20 ] = KEY_KPEQUAL, /* SYNC */
82 [ 28 ] = KEY_MEDIA, // PC/TV 82 [ 28 ] = KEY_MEDIA, /* PC/TV */
83}; 83};
84 84
85static IR_KEYTAB_TYPE ir_codes_purpletv[IR_KEYTAB_SIZE] = { 85static IR_KEYTAB_TYPE ir_codes_purpletv[IR_KEYTAB_SIZE] = {
86 [ 0x3 ] = KEY_POWER, 86 [ 0x3 ] = KEY_POWER,
87 [ 0x6f ] = KEY_MUTE, 87 [ 0x6f ] = KEY_MUTE,
88 [ 0x10 ] = KEY_BACKSPACE, // Recall 88 [ 0x10 ] = KEY_BACKSPACE, /* Recall */
89 89
90 [ 0x11 ] = KEY_KP0, 90 [ 0x11 ] = KEY_KP0,
91 [ 0x4 ] = KEY_KP1, 91 [ 0x4 ] = KEY_KP1,
@@ -97,7 +97,7 @@ static IR_KEYTAB_TYPE ir_codes_purpletv[IR_KEYTAB_SIZE] = {
97 [ 0xc ] = KEY_KP7, 97 [ 0xc ] = KEY_KP7,
98 [ 0xd ] = KEY_KP8, 98 [ 0xd ] = KEY_KP8,
99 [ 0xe ] = KEY_KP9, 99 [ 0xe ] = KEY_KP9,
100 [ 0x12 ] = KEY_KPDOT, // 100+ 100 [ 0x12 ] = KEY_KPDOT, /* 100+ */
101 101
102 [ 0x7 ] = KEY_VOLUMEUP, 102 [ 0x7 ] = KEY_VOLUMEUP,
103 [ 0xb ] = KEY_VOLUMEDOWN, 103 [ 0xb ] = KEY_VOLUMEDOWN,
@@ -109,25 +109,16 @@ static IR_KEYTAB_TYPE ir_codes_purpletv[IR_KEYTAB_SIZE] = {
109 [ 0x13 ] = KEY_CHANNELDOWN, 109 [ 0x13 ] = KEY_CHANNELDOWN,
110 [ 0x48 ] = KEY_ZOOM, 110 [ 0x48 ] = KEY_ZOOM,
111 111
112 [ 0x1b ] = KEY_VIDEO, // Video source 112 [ 0x1b ] = KEY_VIDEO, /* Video source */
113#if 0 113 [ 0x49 ] = KEY_LANGUAGE, /* MTS Select */
114 [ 0x1f ] = KEY_S, // Snapshot 114 [ 0x19 ] = KEY_SEARCH, /* Auto Scan */
115#endif
116 [ 0x49 ] = KEY_LANGUAGE, // MTS Select
117 [ 0x19 ] = KEY_SEARCH, // Auto Scan
118 115
119 [ 0x4b ] = KEY_RECORD, 116 [ 0x4b ] = KEY_RECORD,
120 [ 0x46 ] = KEY_PLAY, 117 [ 0x46 ] = KEY_PLAY,
121 [ 0x45 ] = KEY_PAUSE, // Pause 118 [ 0x45 ] = KEY_PAUSE, /* Pause */
122 [ 0x44 ] = KEY_STOP, 119 [ 0x44 ] = KEY_STOP,
123#if 0 120 [ 0x40 ] = KEY_FORWARD, /* Forward ? */
124 [ 0x43 ] = KEY_T, // Time Shift 121 [ 0x42 ] = KEY_REWIND, /* Backward ? */
125 [ 0x47 ] = KEY_Y, // Time Shift OFF
126 [ 0x4a ] = KEY_O, // TOP
127 [ 0x17 ] = KEY_F, // SURF CH
128#endif
129 [ 0x40 ] = KEY_FORWARD, // Forward ?
130 [ 0x42 ] = KEY_REWIND, // Backward ?
131 122
132}; 123};
133 124
diff --git a/drivers/media/video/msp3400.c b/drivers/media/video/msp3400.c
index b4ee9dfe6d42..6239254db27e 100644
--- a/drivers/media/video/msp3400.c
+++ b/drivers/media/video/msp3400.c
@@ -567,10 +567,6 @@ static void msp3400c_set_audmode(struct i2c_client *client, int audmode)
567 switch (audmode) { 567 switch (audmode) {
568 case V4L2_TUNER_MODE_STEREO: 568 case V4L2_TUNER_MODE_STEREO:
569 src = 0x0020 | nicam; 569 src = 0x0020 | nicam;
570#if 0
571 /* spatial effect */
572 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0005,0x4000);
573#endif
574 break; 570 break;
575 case V4L2_TUNER_MODE_MONO: 571 case V4L2_TUNER_MODE_MONO:
576 if (msp->mode == MSP_MODE_AM_NICAM) { 572 if (msp->mode == MSP_MODE_AM_NICAM) {
@@ -741,16 +737,14 @@ static int msp34xx_sleep(struct msp3400c *msp, int timeout)
741 set_current_state(TASK_INTERRUPTIBLE); 737 set_current_state(TASK_INTERRUPTIBLE);
742 schedule(); 738 schedule();
743 } else { 739 } else {
744#if 0
745 /* hmm, that one doesn't return on wakeup ... */
746 msleep_interruptible(timeout);
747#else
748 set_current_state(TASK_INTERRUPTIBLE); 740 set_current_state(TASK_INTERRUPTIBLE);
749 schedule_timeout(msecs_to_jiffies(timeout)); 741 schedule_timeout(msecs_to_jiffies(timeout));
750#endif
751 } 742 }
752 } 743 }
753 try_to_freeze(); 744 if (current->flags & PF_FREEZE) {
745 refrigerator ();
746 }
747
754 remove_wait_queue(&msp->wq, &wait); 748 remove_wait_queue(&msp->wq, &wait);
755 return msp->restart; 749 return msp->restart;
756} 750}
@@ -1154,17 +1148,10 @@ static int msp3410d_thread(void *data)
1154 MSP_CARRIER(10.7)); 1148 MSP_CARRIER(10.7));
1155 /* scart routing */ 1149 /* scart routing */
1156 msp3400c_set_scart(client,SCART_IN2,0); 1150 msp3400c_set_scart(client,SCART_IN2,0);
1157#if 0
1158 /* radio from SCART_IN2 */
1159 msp3400c_write(client,I2C_MSP3400C_DFP, 0x08, 0x0220);
1160 msp3400c_write(client,I2C_MSP3400C_DFP, 0x09, 0x0220);
1161 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0b, 0x0220);
1162#else
1163 /* msp34xx does radio decoding */ 1151 /* msp34xx does radio decoding */
1164 msp3400c_write(client,I2C_MSP3400C_DFP, 0x08, 0x0020); 1152 msp3400c_write(client,I2C_MSP3400C_DFP, 0x08, 0x0020);
1165 msp3400c_write(client,I2C_MSP3400C_DFP, 0x09, 0x0020); 1153 msp3400c_write(client,I2C_MSP3400C_DFP, 0x09, 0x0020);
1166 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0b, 0x0020); 1154 msp3400c_write(client,I2C_MSP3400C_DFP, 0x0b, 0x0020);
1167#endif
1168 break; 1155 break;
1169 case 0x0003: 1156 case 0x0003:
1170 case 0x0004: 1157 case 0x0004:
@@ -1507,10 +1494,6 @@ static int msp_attach(struct i2c_adapter *adap, int addr, int kind)
1507 return -1; 1494 return -1;
1508 } 1495 }
1509 1496
1510#if 0
1511 /* this will turn on a 1kHz beep - might be useful for debugging... */
1512 msp3400c_write(c,I2C_MSP3400C_DFP, 0x0014, 0x1040);
1513#endif
1514 msp3400c_setvolume(c, msp->muted, msp->volume, msp->balance); 1497 msp3400c_setvolume(c, msp->muted, msp->volume, msp->balance);
1515 1498
1516 snprintf(c->name, sizeof(c->name), "MSP34%02d%c-%c%d", 1499 snprintf(c->name, sizeof(c->name), "MSP34%02d%c-%c%d",
diff --git a/drivers/media/video/mt20xx.c b/drivers/media/video/mt20xx.c
index 9c005cb128d7..2fb7c2d1787a 100644
--- a/drivers/media/video/mt20xx.c
+++ b/drivers/media/video/mt20xx.c
@@ -511,22 +511,6 @@ int microtune_init(struct i2c_client *c)
511 tuner_info("microtune: companycode=%04x part=%02x rev=%02x\n", 511 tuner_info("microtune: companycode=%04x part=%02x rev=%02x\n",
512 company_code,buf[0x13],buf[0x14]); 512 company_code,buf[0x13],buf[0x14]);
513 513
514#if 0
515 /* seems to cause more problems than it solves ... */
516 switch (company_code) {
517 case 0x30bf:
518 case 0x3cbf:
519 case 0x3dbf:
520 case 0x4d54:
521 case 0x8e81:
522 case 0x8e91:
523 /* ok (?) */
524 break;
525 default:
526 tuner_warn("tuner: microtune: unknown companycode\n");
527 return 0;
528 }
529#endif
530 514
531 if (buf[0x13] < ARRAY_SIZE(microtune_part) && 515 if (buf[0x13] < ARRAY_SIZE(microtune_part) &&
532 NULL != microtune_part[buf[0x13]]) 516 NULL != microtune_part[buf[0x13]])
diff --git a/drivers/media/video/mxb.c b/drivers/media/video/mxb.c
index 70bf1f1fad59..486234d41b56 100644
--- a/drivers/media/video/mxb.c
+++ b/drivers/media/video/mxb.c
@@ -326,6 +326,7 @@ static int mxb_init_done(struct saa7146_dev* dev)
326 struct mxb* mxb = (struct mxb*)dev->ext_priv; 326 struct mxb* mxb = (struct mxb*)dev->ext_priv;
327 struct video_decoder_init init; 327 struct video_decoder_init init;
328 struct i2c_msg msg; 328 struct i2c_msg msg;
329 struct tuner_setup tun_setup;
329 330
330 int i = 0, err = 0; 331 int i = 0, err = 0;
331 struct tea6415c_multiplex vm; 332 struct tea6415c_multiplex vm;
@@ -349,8 +350,10 @@ static int mxb_init_done(struct saa7146_dev* dev)
349 mxb->saa7111a->driver->command(mxb->saa7111a,DECODER_SET_VBI_BYPASS, &i); 350 mxb->saa7111a->driver->command(mxb->saa7111a,DECODER_SET_VBI_BYPASS, &i);
350 351
351 /* select a tuner type */ 352 /* select a tuner type */
352 i = 5; 353 tun_setup.mode_mask = T_ANALOG_TV;
353 mxb->tuner->driver->command(mxb->tuner,TUNER_SET_TYPE, &i); 354 tun_setup.addr = ADDR_UNSET;
355 tun_setup.type = 5;
356 mxb->tuner->driver->command(mxb->tuner,TUNER_SET_TYPE_ADDR, &tun_setup);
354 357
355 /* mute audio on tea6420s */ 358 /* mute audio on tea6420s */
356 mxb->tea6420_1->driver->command(mxb->tea6420_1,TEA6420_SWITCH, &TEA6420_line[6][0]); 359 mxb->tea6420_1->driver->command(mxb->tea6420_1,TEA6420_SWITCH, &TEA6420_line[6][0]);
diff --git a/drivers/media/video/saa7134/saa6752hs.c b/drivers/media/video/saa7134/saa6752hs.c
index e6d0a18833d6..79d05ea1b69b 100644
--- a/drivers/media/video/saa7134/saa6752hs.c
+++ b/drivers/media/video/saa7134/saa6752hs.c
@@ -155,10 +155,6 @@ static struct v4l2_mpeg_compression param_defaults =
155 .target = 256, 155 .target = 256,
156 }, 156 },
157 157
158#if 0
159 /* FIXME: size? via S_FMT? */
160 .video_format = MPEG_VIDEO_FORMAT_D1,
161#endif
162}; 158};
163 159
164/* ---------------------------------------------------------------------- */ 160/* ---------------------------------------------------------------------- */
diff --git a/drivers/media/video/saa7134/saa7134-cards.c b/drivers/media/video/saa7134/saa7134-cards.c
index 0c781e24c446..88b71a20b602 100644
--- a/drivers/media/video/saa7134/saa7134-cards.c
+++ b/drivers/media/video/saa7134/saa7134-cards.c
@@ -1,6 +1,5 @@
1
2/* 1/*
3 * $Id: saa7134-cards.c,v 1.58 2005/06/07 18:05:00 nsh Exp $ 2 * $Id: saa7134-cards.c,v 1.80 2005/07/07 01:49:30 mkrufky Exp $
4 * 3 *
5 * device driver for philips saa7134 based TV cards 4 * device driver for philips saa7134 based TV cards
6 * card-specific stuff. 5 * card-specific stuff.
@@ -47,6 +46,10 @@ struct saa7134_board saa7134_boards[] = {
47 .name = "UNKNOWN/GENERIC", 46 .name = "UNKNOWN/GENERIC",
48 .audio_clock = 0x00187de7, 47 .audio_clock = 0x00187de7,
49 .tuner_type = TUNER_ABSENT, 48 .tuner_type = TUNER_ABSENT,
49 .radio_type = UNSET,
50 .tuner_addr = ADDR_UNSET,
51 .radio_addr = ADDR_UNSET,
52
50 .inputs = {{ 53 .inputs = {{
51 .name = "default", 54 .name = "default",
52 .vmux = 0, 55 .vmux = 0,
@@ -58,6 +61,10 @@ struct saa7134_board saa7134_boards[] = {
58 .name = "Proteus Pro [philips reference design]", 61 .name = "Proteus Pro [philips reference design]",
59 .audio_clock = 0x00187de7, 62 .audio_clock = 0x00187de7,
60 .tuner_type = TUNER_PHILIPS_PAL, 63 .tuner_type = TUNER_PHILIPS_PAL,
64 .radio_type = UNSET,
65 .tuner_addr = ADDR_UNSET,
66 .radio_addr = ADDR_UNSET,
67
61 .inputs = {{ 68 .inputs = {{
62 .name = name_comp1, 69 .name = name_comp1,
63 .vmux = 0, 70 .vmux = 0,
@@ -83,6 +90,10 @@ struct saa7134_board saa7134_boards[] = {
83 .name = "LifeView FlyVIDEO3000", 90 .name = "LifeView FlyVIDEO3000",
84 .audio_clock = 0x00200000, 91 .audio_clock = 0x00200000,
85 .tuner_type = TUNER_PHILIPS_PAL, 92 .tuner_type = TUNER_PHILIPS_PAL,
93 .radio_type = UNSET,
94 .tuner_addr = ADDR_UNSET,
95 .radio_addr = ADDR_UNSET,
96
86 .gpiomask = 0xe000, 97 .gpiomask = 0xe000,
87 .inputs = {{ 98 .inputs = {{
88 .name = name_tv, 99 .name = name_tv,
@@ -90,7 +101,7 @@ struct saa7134_board saa7134_boards[] = {
90 .amux = TV, 101 .amux = TV,
91 .gpio = 0x8000, 102 .gpio = 0x8000,
92 .tv = 1, 103 .tv = 1,
93 },{ 104 },{
94 .name = name_tv_mono, 105 .name = name_tv_mono,
95 .vmux = 1, 106 .vmux = 1,
96 .amux = LINE2, 107 .amux = LINE2,
@@ -117,12 +128,21 @@ struct saa7134_board saa7134_boards[] = {
117 .amux = LINE2, 128 .amux = LINE2,
118 .gpio = 0x2000, 129 .gpio = 0x2000,
119 }, 130 },
131 .mute = {
132 .name = name_mute,
133 .amux = TV,
134 .gpio = 0x8000,
135 },
120 }, 136 },
121 [SAA7134_BOARD_FLYVIDEO2000] = { 137 [SAA7134_BOARD_FLYVIDEO2000] = {
122 /* "TC Wan" <tcwan@cs.usm.my> */ 138 /* "TC Wan" <tcwan@cs.usm.my> */
123 .name = "LifeView FlyVIDEO2000", 139 .name = "LifeView FlyVIDEO2000",
124 .audio_clock = 0x00200000, 140 .audio_clock = 0x00200000,
125 .tuner_type = TUNER_LG_PAL_NEW_TAPC, 141 .tuner_type = TUNER_LG_PAL_NEW_TAPC,
142 .radio_type = UNSET,
143 .tuner_addr = ADDR_UNSET,
144 .radio_addr = ADDR_UNSET,
145
126 .gpiomask = 0xe000, 146 .gpiomask = 0xe000,
127 .inputs = {{ 147 .inputs = {{
128 .name = name_tv, 148 .name = name_tv,
@@ -146,14 +166,14 @@ struct saa7134_board saa7134_boards[] = {
146 .amux = LINE2, 166 .amux = LINE2,
147 .gpio = 0x4000, 167 .gpio = 0x4000,
148 }}, 168 }},
149 .radio = { 169 .radio = {
150 .name = name_radio, 170 .name = name_radio,
151 .amux = LINE2, 171 .amux = LINE2,
152 .gpio = 0x2000, 172 .gpio = 0x2000,
153 }, 173 },
154 .mute = { 174 .mute = {
155 .name = name_mute, 175 .name = name_mute,
156 .amux = LINE2, 176 .amux = LINE2,
157 .gpio = 0x8000, 177 .gpio = 0x8000,
158 }, 178 },
159 }, 179 },
@@ -162,6 +182,10 @@ struct saa7134_board saa7134_boards[] = {
162 .name = "LifeView FlyTV Platinum Mini", 182 .name = "LifeView FlyTV Platinum Mini",
163 .audio_clock = 0x00200000, 183 .audio_clock = 0x00200000,
164 .tuner_type = TUNER_PHILIPS_TDA8290, 184 .tuner_type = TUNER_PHILIPS_TDA8290,
185 .radio_type = UNSET,
186 .tuner_addr = ADDR_UNSET,
187 .radio_addr = ADDR_UNSET,
188
165 .inputs = {{ 189 .inputs = {{
166 .name = name_tv, 190 .name = name_tv,
167 .vmux = 1, 191 .vmux = 1,
@@ -183,6 +207,10 @@ struct saa7134_board saa7134_boards[] = {
183 .name = "LifeView FlyTV Platinum FM", 207 .name = "LifeView FlyTV Platinum FM",
184 .audio_clock = 0x00200000, 208 .audio_clock = 0x00200000,
185 .tuner_type = TUNER_PHILIPS_TDA8290, 209 .tuner_type = TUNER_PHILIPS_TDA8290,
210 .radio_type = UNSET,
211 .tuner_addr = ADDR_UNSET,
212 .radio_addr = ADDR_UNSET,
213
186 .gpiomask = 0x1E000, /* Set GP16 and unused 15,14,13 to Output */ 214 .gpiomask = 0x1E000, /* Set GP16 and unused 15,14,13 to Output */
187 .inputs = {{ 215 .inputs = {{
188 .name = name_tv, 216 .name = name_tv,
@@ -190,7 +218,7 @@ struct saa7134_board saa7134_boards[] = {
190 .amux = TV, 218 .amux = TV,
191 .gpio = 0x10000, /* GP16=1 selects TV input */ 219 .gpio = 0x10000, /* GP16=1 selects TV input */
192 .tv = 1, 220 .tv = 1,
193 },{ 221 },{
194/* .name = name_tv_mono, 222/* .name = name_tv_mono,
195 .vmux = 1, 223 .vmux = 1,
196 .amux = LINE2, 224 .amux = LINE2,
@@ -200,29 +228,38 @@ struct saa7134_board saa7134_boards[] = {
200*/ .name = name_comp1, /* Composite signal on S-Video input */ 228*/ .name = name_comp1, /* Composite signal on S-Video input */
201 .vmux = 0, 229 .vmux = 0,
202 .amux = LINE2, 230 .amux = LINE2,
203// .gpio = 0x4000, 231/* .gpio = 0x4000, */
204 },{ 232 },{
205 .name = name_comp2, /* Composite input */ 233 .name = name_comp2, /* Composite input */
206 .vmux = 3, 234 .vmux = 3,
207 .amux = LINE2, 235 .amux = LINE2,
208// .gpio = 0x4000, 236/* .gpio = 0x4000, */
209 },{ 237 },{
210 .name = name_svideo, /* S-Video signal on S-Video input */ 238 .name = name_svideo, /* S-Video signal on S-Video input */
211 .vmux = 8, 239 .vmux = 8,
212 .amux = LINE2, 240 .amux = LINE2,
213// .gpio = 0x4000, 241/* .gpio = 0x4000, */
214 }}, 242 }},
215 .radio = { 243 .radio = {
216 .name = name_radio, 244 .name = name_radio,
217 .amux = TV, 245 .amux = TV,
218 .gpio = 0x00000, /* GP16=0 selects FM radio antenna */ 246 .gpio = 0x00000, /* GP16=0 selects FM radio antenna */
219 }, 247 },
248 .mute = {
249 .name = name_mute,
250 .amux = TV,
251 .gpio = 0x10000,
252 },
220 }, 253 },
221 [SAA7134_BOARD_EMPRESS] = { 254 [SAA7134_BOARD_EMPRESS] = {
222 /* "Gert Vervoort" <gert.vervoort@philips.com> */ 255 /* "Gert Vervoort" <gert.vervoort@philips.com> */
223 .name = "EMPRESS", 256 .name = "EMPRESS",
224 .audio_clock = 0x00187de7, 257 .audio_clock = 0x00187de7,
225 .tuner_type = TUNER_PHILIPS_PAL, 258 .tuner_type = TUNER_PHILIPS_PAL,
259 .radio_type = UNSET,
260 .tuner_addr = ADDR_UNSET,
261 .radio_addr = ADDR_UNSET,
262
226 .inputs = {{ 263 .inputs = {{
227 .name = name_comp1, 264 .name = name_comp1,
228 .vmux = 0, 265 .vmux = 0,
@@ -245,33 +282,40 @@ struct saa7134_board saa7134_boards[] = {
245 .video_out = CCIR656, 282 .video_out = CCIR656,
246 }, 283 },
247 [SAA7134_BOARD_MONSTERTV] = { 284 [SAA7134_BOARD_MONSTERTV] = {
248 /* "K.Ohta" <alpha292@bremen.or.jp> */ 285 /* "K.Ohta" <alpha292@bremen.or.jp> */
249 .name = "SKNet Monster TV", 286 .name = "SKNet Monster TV",
250 .audio_clock = 0x00187de7, 287 .audio_clock = 0x00187de7,
251 .tuner_type = TUNER_PHILIPS_NTSC_M, 288 .tuner_type = TUNER_PHILIPS_NTSC_M,
252 .inputs = {{ 289 .radio_type = UNSET,
253 .name = name_tv, 290 .tuner_addr = ADDR_UNSET,
254 .vmux = 1, 291 .radio_addr = ADDR_UNSET,
255 .amux = TV, 292
256 .tv = 1, 293 .inputs = {{
257 },{ 294 .name = name_tv,
258 .name = name_comp1, 295 .vmux = 1,
259 .vmux = 0, 296 .amux = TV,
260 .amux = LINE1, 297 .tv = 1,
261 },{ 298 },{
262 .name = name_svideo, 299 .name = name_comp1,
263 .vmux = 8, 300 .vmux = 0,
264 .amux = LINE1, 301 .amux = LINE1,
265 }}, 302 },{
266 .radio = { 303 .name = name_svideo,
267 .name = name_radio, 304 .vmux = 8,
268 .amux = LINE2, 305 .amux = LINE1,
269 }, 306 }},
307 .radio = {
308 .name = name_radio,
309 .amux = LINE2,
310 },
270 }, 311 },
271 [SAA7134_BOARD_MD9717] = { 312 [SAA7134_BOARD_MD9717] = {
272 .name = "Tevion MD 9717", 313 .name = "Tevion MD 9717",
273 .audio_clock = 0x00200000, 314 .audio_clock = 0x00200000,
274 .tuner_type = TUNER_PHILIPS_PAL, 315 .tuner_type = TUNER_PHILIPS_PAL,
316 .radio_type = UNSET,
317 .tuner_addr = ADDR_UNSET,
318 .radio_addr = ADDR_UNSET,
275 .inputs = {{ 319 .inputs = {{
276 .name = name_tv, 320 .name = name_tv,
277 .vmux = 1, 321 .vmux = 1,
@@ -302,10 +346,13 @@ struct saa7134_board saa7134_boards[] = {
302 }, 346 },
303 }, 347 },
304 [SAA7134_BOARD_TVSTATION_RDS] = { 348 [SAA7134_BOARD_TVSTATION_RDS] = {
305 /* Typhoon TV Tuner RDS: Art.Nr. 50694 */ 349 /* Typhoon TV Tuner RDS: Art.Nr. 50694 */
306 .name = "KNC One TV-Station RDS / Typhoon TV Tuner RDS", 350 .name = "KNC One TV-Station RDS / Typhoon TV Tuner RDS",
307 .audio_clock = 0x00200000, 351 .audio_clock = 0x00200000,
308 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3, 352 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
353 .radio_type = UNSET,
354 .tuner_addr = ADDR_UNSET,
355 .radio_addr = ADDR_UNSET,
309 .tda9887_conf = TDA9887_PRESENT, 356 .tda9887_conf = TDA9887_PRESENT,
310 .inputs = {{ 357 .inputs = {{
311 .name = name_tv, 358 .name = name_tv,
@@ -314,10 +361,10 @@ struct saa7134_board saa7134_boards[] = {
314 .tv = 1, 361 .tv = 1,
315 },{ 362 },{
316 .name = name_tv_mono, 363 .name = name_tv_mono,
317 .vmux = 1, 364 .vmux = 1,
318 .amux = LINE2, 365 .amux = LINE2,
319 .tv = 1, 366 .tv = 1,
320 },{ 367 },{
321 368
322 .name = name_svideo, 369 .name = name_svideo,
323 .vmux = 8, 370 .vmux = 8,
@@ -328,10 +375,10 @@ struct saa7134_board saa7134_boards[] = {
328 .amux = LINE1, 375 .amux = LINE1,
329 },{ 376 },{
330 377
331 .name = "CVid over SVid", 378 .name = "CVid over SVid",
332 .vmux = 0, 379 .vmux = 0,
333 .amux = LINE1, 380 .amux = LINE1,
334 }}, 381 }},
335 .radio = { 382 .radio = {
336 .name = name_radio, 383 .name = name_radio,
337 .amux = LINE2, 384 .amux = LINE2,
@@ -341,6 +388,9 @@ struct saa7134_board saa7134_boards[] = {
341 .name = "KNC One TV-Station DVR", 388 .name = "KNC One TV-Station DVR",
342 .audio_clock = 0x00200000, 389 .audio_clock = 0x00200000,
343 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3, 390 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
391 .radio_type = UNSET,
392 .tuner_addr = ADDR_UNSET,
393 .radio_addr = ADDR_UNSET,
344 .tda9887_conf = TDA9887_PRESENT, 394 .tda9887_conf = TDA9887_PRESENT,
345 .gpiomask = 0x820000, 395 .gpiomask = 0x820000,
346 .inputs = {{ 396 .inputs = {{
@@ -369,32 +419,38 @@ struct saa7134_board saa7134_boards[] = {
369 .video_out = CCIR656, 419 .video_out = CCIR656,
370 }, 420 },
371 [SAA7134_BOARD_CINERGY400] = { 421 [SAA7134_BOARD_CINERGY400] = {
372 .name = "Terratec Cinergy 400 TV", 422 .name = "Terratec Cinergy 400 TV",
373 .audio_clock = 0x00200000, 423 .audio_clock = 0x00200000,
374 .tuner_type = TUNER_PHILIPS_PAL, 424 .tuner_type = TUNER_PHILIPS_PAL,
375 .inputs = {{ 425 .radio_type = UNSET,
376 .name = name_tv, 426 .tuner_addr = ADDR_UNSET,
377 .vmux = 1, 427 .radio_addr = ADDR_UNSET,
378 .amux = TV, 428 .inputs = {{
379 .tv = 1, 429 .name = name_tv,
380 },{ 430 .vmux = 1,
381 .name = name_comp1, 431 .amux = TV,
382 .vmux = 4, 432 .tv = 1,
383 .amux = LINE1, 433 },{
384 },{ 434 .name = name_comp1,
385 .name = name_svideo, 435 .vmux = 4,
386 .vmux = 8, 436 .amux = LINE1,
387 .amux = LINE1, 437 },{
388 },{ 438 .name = name_svideo,
389 .name = name_comp2, // CVideo over SVideo Connector 439 .vmux = 8,
390 .vmux = 0, 440 .amux = LINE1,
391 .amux = LINE1, 441 },{
392 }} 442 .name = name_comp2, /* CVideo over SVideo Connector */
393 }, 443 .vmux = 0,
444 .amux = LINE1,
445 }}
446 },
394 [SAA7134_BOARD_MD5044] = { 447 [SAA7134_BOARD_MD5044] = {
395 .name = "Medion 5044", 448 .name = "Medion 5044",
396 .audio_clock = 0x00187de7, // was: 0x00200000, 449 .audio_clock = 0x00187de7, /* was: 0x00200000, */
397 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3, 450 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
451 .radio_type = UNSET,
452 .tuner_addr = ADDR_UNSET,
453 .radio_addr = ADDR_UNSET,
398 .tda9887_conf = TDA9887_PRESENT, 454 .tda9887_conf = TDA9887_PRESENT,
399 .inputs = {{ 455 .inputs = {{
400 .name = name_tv, 456 .name = name_tv,
@@ -426,57 +482,65 @@ struct saa7134_board saa7134_boards[] = {
426 }, 482 },
427 }, 483 },
428 [SAA7134_BOARD_KWORLD] = { 484 [SAA7134_BOARD_KWORLD] = {
429 .name = "Kworld/KuroutoShikou SAA7130-TVPCI", 485 .name = "Kworld/KuroutoShikou SAA7130-TVPCI",
430 .audio_clock = 0x00187de7, 486 .audio_clock = 0x00187de7,
431 .tuner_type = TUNER_PHILIPS_NTSC_M, 487 .tuner_type = TUNER_PHILIPS_NTSC_M,
432 .inputs = {{ 488 .radio_type = UNSET,
433 .name = name_svideo, 489 .tuner_addr = ADDR_UNSET,
434 .vmux = 8, 490 .radio_addr = ADDR_UNSET,
435 .amux = LINE1, 491 .inputs = {{
436 },{ 492 .name = name_svideo,
437 .name = name_comp1, 493 .vmux = 8,
438 .vmux = 3, 494 .amux = LINE1,
439 .amux = LINE1, 495 },{
440 },{ 496 .name = name_comp1,
441 .name = name_tv, 497 .vmux = 3,
442 .vmux = 1, 498 .amux = LINE1,
443 .amux = LINE2, 499 },{
444 .tv = 1, 500 .name = name_tv,
445 }}, 501 .vmux = 1,
446 }, 502 .amux = LINE2,
503 .tv = 1,
504 }},
505 },
447 [SAA7134_BOARD_CINERGY600] = { 506 [SAA7134_BOARD_CINERGY600] = {
448 .name = "Terratec Cinergy 600 TV", 507 .name = "Terratec Cinergy 600 TV",
449 .audio_clock = 0x00200000, 508 .audio_clock = 0x00200000,
450 .tuner_type = TUNER_PHILIPS_PAL, 509 .tuner_type = TUNER_PHILIPS_PAL,
510 .radio_type = UNSET,
511 .tuner_addr = ADDR_UNSET,
512 .radio_addr = ADDR_UNSET,
451 .tda9887_conf = TDA9887_PRESENT, 513 .tda9887_conf = TDA9887_PRESENT,
452 .inputs = {{ 514 .inputs = {{
453 .name = name_tv, 515 .name = name_tv,
454 .vmux = 1, 516 .vmux = 1,
455 .amux = TV, 517 .amux = TV,
456 .tv = 1, 518 .tv = 1,
457 },{ 519 },{
458 .name = name_comp1, 520 .name = name_comp1,
459 .vmux = 4, 521 .vmux = 4,
460 .amux = LINE1, 522 .amux = LINE1,
461 },{ 523 },{
462 .name = name_svideo, 524 .name = name_svideo,
463 .vmux = 8, 525 .vmux = 8,
464 .amux = LINE1, 526 .amux = LINE1,
465 },{ 527 },{
466 .name = name_comp2, // CVideo over SVideo Connector 528 .name = name_comp2, /* CVideo over SVideo Connector */
467 .vmux = 0, 529 .vmux = 0,
468 .amux = LINE1, 530 .amux = LINE1,
469 }}, 531 }},
470 .radio = { 532 .radio = {
471 .name = name_radio, 533 .name = name_radio,
472 .amux = LINE2, 534 .amux = LINE2,
473 }, 535 },
474 }, 536 },
475 [SAA7134_BOARD_MD7134] = { 537 [SAA7134_BOARD_MD7134] = {
476 .name = "Medion 7134", 538 .name = "Medion 7134",
477 //.audio_clock = 0x00200000,
478 .audio_clock = 0x00187de7, 539 .audio_clock = 0x00187de7,
479 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3, 540 .tuner_type = TUNER_PHILIPS_FMD1216ME_MK3,
541 .radio_type = UNSET,
542 .tuner_addr = ADDR_UNSET,
543 .radio_addr = ADDR_UNSET,
480 .tda9887_conf = TDA9887_PRESENT, 544 .tda9887_conf = TDA9887_PRESENT,
481 .mpeg = SAA7134_MPEG_DVB, 545 .mpeg = SAA7134_MPEG_DVB,
482 .inputs = {{ 546 .inputs = {{
@@ -504,6 +568,9 @@ struct saa7134_board saa7134_boards[] = {
504 .name = "Typhoon TV+Radio 90031", 568 .name = "Typhoon TV+Radio 90031",
505 .audio_clock = 0x00200000, 569 .audio_clock = 0x00200000,
506 .tuner_type = TUNER_PHILIPS_PAL, 570 .tuner_type = TUNER_PHILIPS_PAL,
571 .radio_type = UNSET,
572 .tuner_addr = ADDR_UNSET,
573 .radio_addr = ADDR_UNSET,
507 .tda9887_conf = TDA9887_PRESENT, 574 .tda9887_conf = TDA9887_PRESENT,
508 .inputs = {{ 575 .inputs = {{
509 .name = name_tv, 576 .name = name_tv,
@@ -523,11 +590,14 @@ struct saa7134_board saa7134_boards[] = {
523 .name = name_radio, 590 .name = name_radio,
524 .amux = LINE2, 591 .amux = LINE2,
525 }, 592 },
526 }, 593 },
527 [SAA7134_BOARD_ELSA] = { 594 [SAA7134_BOARD_ELSA] = {
528 .name = "ELSA EX-VISION 300TV", 595 .name = "ELSA EX-VISION 300TV",
529 .audio_clock = 0x00187de7, 596 .audio_clock = 0x00187de7,
530 .tuner_type = TUNER_HITACHI_NTSC, 597 .tuner_type = TUNER_HITACHI_NTSC,
598 .radio_type = UNSET,
599 .tuner_addr = ADDR_UNSET,
600 .radio_addr = ADDR_UNSET,
531 .inputs = {{ 601 .inputs = {{
532 .name = name_svideo, 602 .name = name_svideo,
533 .vmux = 8, 603 .vmux = 8,
@@ -542,11 +612,14 @@ struct saa7134_board saa7134_boards[] = {
542 .amux = LINE2, 612 .amux = LINE2,
543 .tv = 1, 613 .tv = 1,
544 }}, 614 }},
545 }, 615 },
546 [SAA7134_BOARD_ELSA_500TV] = { 616 [SAA7134_BOARD_ELSA_500TV] = {
547 .name = "ELSA EX-VISION 500TV", 617 .name = "ELSA EX-VISION 500TV",
548 .audio_clock = 0x00187de7, 618 .audio_clock = 0x00187de7,
549 .tuner_type = TUNER_HITACHI_NTSC, 619 .tuner_type = TUNER_HITACHI_NTSC,
620 .radio_type = UNSET,
621 .tuner_addr = ADDR_UNSET,
622 .radio_addr = ADDR_UNSET,
550 .inputs = {{ 623 .inputs = {{
551 .name = name_svideo, 624 .name = name_svideo,
552 .vmux = 7, 625 .vmux = 7,
@@ -562,83 +635,100 @@ struct saa7134_board saa7134_boards[] = {
562 .amux = LINE2, 635 .amux = LINE2,
563 .tv = 1, 636 .tv = 1,
564 }}, 637 }},
565 }, 638 },
566 [SAA7134_BOARD_ASUSTeK_TVFM7134] = { 639 [SAA7134_BOARD_ASUSTeK_TVFM7134] = {
567 .name = "ASUS TV-FM 7134", 640 .name = "ASUS TV-FM 7134",
568 .audio_clock = 0x00187de7, 641 .audio_clock = 0x00187de7,
569 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3, 642 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
570 .tda9887_conf = TDA9887_PRESENT, 643 .radio_type = UNSET,
571 .inputs = {{ 644 .tuner_addr = ADDR_UNSET,
572 .name = name_tv, 645 .radio_addr = ADDR_UNSET,
573 .vmux = 1, 646 .tda9887_conf = TDA9887_PRESENT,
574 .amux = TV, 647 .inputs = {{
575 .tv = 1, 648 .name = name_tv,
576 },{ 649 .vmux = 1,
577 .name = name_comp1, 650 .amux = TV,
578 .vmux = 4, 651 .tv = 1,
579 .amux = LINE2, 652 },{
580 },{ 653 .name = name_comp1,
581 .name = name_svideo, 654 .vmux = 4,
582 .vmux = 6, 655 .amux = LINE2,
583 .amux = LINE2, 656 },{
584 }}, 657 .name = name_svideo,
585 .radio = { 658 .vmux = 6,
586 .name = name_radio, 659 .amux = LINE2,
587 .amux = LINE1, 660 }},
588 }, 661 .radio = {
589 }, 662 .name = name_radio,
590 [SAA7135_BOARD_ASUSTeK_TVFM7135] = { 663 .amux = LINE1,
591 .name = "ASUS TV-FM 7135", 664 },
592 .audio_clock = 0x00187de7, 665 },
593 .tuner_type = TUNER_PHILIPS_TDA8290, 666 [SAA7134_BOARD_ASUSTeK_TVFM7135] = {
667 .name = "ASUS TV-FM 7135",
668 .audio_clock = 0x00187de7,
669 .tuner_type = TUNER_PHILIPS_TDA8290,
670 .radio_type = UNSET,
671 .tuner_addr = ADDR_UNSET,
672 .radio_addr = ADDR_UNSET,
594 .gpiomask = 0x200000, 673 .gpiomask = 0x200000,
595 .inputs = {{ 674 .inputs = {{
596 .name = name_tv, 675 .name = name_tv,
597 .vmux = 1, 676 .vmux = 1,
598 .amux = TV, 677 .amux = TV,
599 .gpio = 0x0000, 678 .gpio = 0x0000,
600 .tv = 1, 679 .tv = 1,
601 },{ 680 },{
602 .name = name_comp1, 681 .name = name_comp1,
603 .vmux = 4, 682 .vmux = 4,
604 .amux = LINE2, 683 .amux = LINE2,
605 .gpio = 0x0000, 684 .gpio = 0x0000,
606 },{ 685 },{
607 .name = name_svideo, 686 .name = name_svideo,
608 .vmux = 6, 687 .vmux = 6,
609 .amux = LINE2, 688 .amux = LINE2,
610 .gpio = 0x0000, 689 .gpio = 0x0000,
611 }}, 690 }},
612 .radio = { 691 .radio = {
613 .name = name_radio, 692 .name = name_radio,
614 .amux = TV, 693 .amux = TV,
615 .gpio = 0x200000, 694 .gpio = 0x200000,
616 }, 695 },
696 .mute = {
697 .name = name_mute,
698 .gpio = 0x0000,
699 },
700
617 }, 701 },
618 [SAA7134_BOARD_VA1000POWER] = { 702 [SAA7134_BOARD_VA1000POWER] = {
619 .name = "AOPEN VA1000 POWER", 703 .name = "AOPEN VA1000 POWER",
620 .audio_clock = 0x00187de7, 704 .audio_clock = 0x00187de7,
621 .tuner_type = TUNER_PHILIPS_NTSC, 705 .tuner_type = TUNER_PHILIPS_NTSC,
622 .inputs = {{ 706 .radio_type = UNSET,
623 .name = name_svideo, 707 .tuner_addr = ADDR_UNSET,
624 .vmux = 8, 708 .radio_addr = ADDR_UNSET,
625 .amux = LINE1, 709 .inputs = {{
626 },{ 710 .name = name_svideo,
627 .name = name_comp1, 711 .vmux = 8,
628 .vmux = 3, 712 .amux = LINE1,
629 .amux = LINE1, 713 },{
630 },{ 714 .name = name_comp1,
631 .name = name_tv, 715 .vmux = 3,
632 .vmux = 1, 716 .amux = LINE1,
633 .amux = LINE2, 717 },{
634 .tv = 1, 718 .name = name_tv,
635 }}, 719 .vmux = 1,
720 .amux = LINE2,
721 .tv = 1,
722 }},
636 }, 723 },
637 [SAA7134_BOARD_10MOONSTVMASTER] = { 724 [SAA7134_BOARD_10MOONSTVMASTER] = {
638 /* "lilicheng" <llc@linuxfans.org> */ 725 /* "lilicheng" <llc@linuxfans.org> */
639 .name = "10MOONS PCI TV CAPTURE CARD", 726 .name = "10MOONS PCI TV CAPTURE CARD",
640 .audio_clock = 0x00200000, 727 .audio_clock = 0x00200000,
641 .tuner_type = TUNER_LG_PAL_NEW_TAPC, 728 .tuner_type = TUNER_LG_PAL_NEW_TAPC,
729 .radio_type = UNSET,
730 .tuner_addr = ADDR_UNSET,
731 .radio_addr = ADDR_UNSET,
642 .gpiomask = 0xe000, 732 .gpiomask = 0xe000,
643 .inputs = {{ 733 .inputs = {{
644 .name = name_tv, 734 .name = name_tv,
@@ -662,14 +752,14 @@ struct saa7134_board saa7134_boards[] = {
662 .amux = LINE2, 752 .amux = LINE2,
663 .gpio = 0x4000, 753 .gpio = 0x4000,
664 }}, 754 }},
665 .radio = { 755 .radio = {
666 .name = name_radio, 756 .name = name_radio,
667 .amux = LINE2, 757 .amux = LINE2,
668 .gpio = 0x2000, 758 .gpio = 0x2000,
669 }, 759 },
670 .mute = { 760 .mute = {
671 .name = name_mute, 761 .name = name_mute,
672 .amux = LINE2, 762 .amux = LINE2,
673 .gpio = 0x8000, 763 .gpio = 0x8000,
674 }, 764 },
675 }, 765 },
@@ -678,6 +768,9 @@ struct saa7134_board saa7134_boards[] = {
678 .name = "BMK MPEX No Tuner", 768 .name = "BMK MPEX No Tuner",
679 .audio_clock = 0x200000, 769 .audio_clock = 0x200000,
680 .tuner_type = TUNER_ABSENT, 770 .tuner_type = TUNER_ABSENT,
771 .radio_type = UNSET,
772 .tuner_addr = ADDR_UNSET,
773 .radio_addr = ADDR_UNSET,
681 .inputs = {{ 774 .inputs = {{
682 .name = name_comp1, 775 .name = name_comp1,
683 .vmux = 4, 776 .vmux = 4,
@@ -706,80 +799,94 @@ struct saa7134_board saa7134_boards[] = {
706 .name = "Compro VideoMate TV", 799 .name = "Compro VideoMate TV",
707 .audio_clock = 0x00187de7, 800 .audio_clock = 0x00187de7,
708 .tuner_type = TUNER_PHILIPS_NTSC_M, 801 .tuner_type = TUNER_PHILIPS_NTSC_M,
709 .inputs = {{ 802 .radio_type = UNSET,
710 .name = name_svideo, 803 .tuner_addr = ADDR_UNSET,
711 .vmux = 8, 804 .radio_addr = ADDR_UNSET,
712 .amux = LINE1, 805 .inputs = {{
713 },{ 806 .name = name_svideo,
714 .name = name_comp1, 807 .vmux = 8,
715 .vmux = 3, 808 .amux = LINE1,
716 .amux = LINE1, 809 },{
717 },{ 810 .name = name_comp1,
718 .name = name_tv, 811 .vmux = 3,
719 .vmux = 1, 812 .amux = LINE1,
720 .amux = LINE2, 813 },{
721 .tv = 1, 814 .name = name_tv,
722 }}, 815 .vmux = 1,
723 }, 816 .amux = LINE2,
724 [SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUS] = { 817 .tv = 1,
818 }},
819 },
820 [SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUS] = {
725 .name = "Compro VideoMate TV Gold+", 821 .name = "Compro VideoMate TV Gold+",
726 .audio_clock = 0x00187de7, 822 .audio_clock = 0x00187de7,
727 .tuner_type = TUNER_PHILIPS_NTSC_M, 823 .tuner_type = TUNER_PHILIPS_NTSC_M,
728 .gpiomask = 0x800c0000, 824 .gpiomask = 0x800c0000,
729 .inputs = {{ 825 .radio_type = UNSET,
730 .name = name_svideo, 826 .tuner_addr = ADDR_UNSET,
731 .vmux = 8, 827 .radio_addr = ADDR_UNSET,
732 .amux = LINE1, 828 .inputs = {{
733 .gpio = 0x06c00012, 829 .name = name_svideo,
734 },{ 830 .vmux = 8,
735 .name = name_comp1, 831 .amux = LINE1,
736 .vmux = 3, 832 .gpio = 0x06c00012,
737 .amux = LINE1, 833 },{
738 .gpio = 0x0ac20012, 834 .name = name_comp1,
739 },{ 835 .vmux = 3,
740 .name = name_tv, 836 .amux = LINE1,
741 .vmux = 1, 837 .gpio = 0x0ac20012,
742 .amux = LINE2, 838 },{
743 .gpio = 0x08c20012, 839 .name = name_tv,
744 .tv = 1, 840 .vmux = 1,
745 }}, 841 .amux = LINE2,
746 }, 842 .gpio = 0x08c20012,
843 .tv = 1,
844 }}, /* radio and probably mute is missing */
845 },
747 [SAA7134_BOARD_CRONOS_PLUS] = { 846 [SAA7134_BOARD_CRONOS_PLUS] = {
748 /* gpio pins: 847 /*
749 0 .. 3 BASE_ID 848 gpio pins:
750 4 .. 7 PROTECT_ID 849 0 .. 3 BASE_ID
751 8 .. 11 USER_OUT 850 4 .. 7 PROTECT_ID
752 12 .. 13 USER_IN 851 8 .. 11 USER_OUT
753 14 .. 15 VIDIN_SEL */ 852 12 .. 13 USER_IN
853 14 .. 15 VIDIN_SEL
854 */
754 .name = "Matrox CronosPlus", 855 .name = "Matrox CronosPlus",
755 .tuner_type = TUNER_ABSENT, 856 .tuner_type = TUNER_ABSENT,
857 .radio_type = UNSET,
858 .tuner_addr = ADDR_UNSET,
859 .radio_addr = ADDR_UNSET,
756 .gpiomask = 0xcf00, 860 .gpiomask = 0xcf00,
757 .inputs = {{ 861 .inputs = {{
758 .name = name_comp1, 862 .name = name_comp1,
759 .vmux = 0, 863 .vmux = 0,
760 .gpio = 2 << 14, 864 .gpio = 2 << 14,
761 },{ 865 },{
762 .name = name_comp2, 866 .name = name_comp2,
763 .vmux = 0, 867 .vmux = 0,
764 .gpio = 1 << 14, 868 .gpio = 1 << 14,
765 },{ 869 },{
766 .name = name_comp3, 870 .name = name_comp3,
767 .vmux = 0, 871 .vmux = 0,
768 .gpio = 0 << 14, 872 .gpio = 0 << 14,
769 },{ 873 },{
770 .name = name_comp4, 874 .name = name_comp4,
771 .vmux = 0, 875 .vmux = 0,
772 .gpio = 3 << 14, 876 .gpio = 3 << 14,
773 },{ 877 },{
774 .name = name_svideo, 878 .name = name_svideo,
775 .vmux = 8, 879 .vmux = 8,
776 .gpio = 2 << 14, 880 .gpio = 2 << 14,
777 }}, 881 }},
778 }, 882 },
779 [SAA7134_BOARD_MD2819] = { 883 [SAA7134_BOARD_MD2819] = {
780 .name = "AverMedia M156 / Medion 2819", 884 .name = "AverMedia M156 / Medion 2819",
781 .audio_clock = 0x00187de7, 885 .audio_clock = 0x00187de7,
782 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3, 886 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
887 .radio_type = UNSET,
888 .tuner_addr = ADDR_UNSET,
889 .radio_addr = ADDR_UNSET,
783 .tda9887_conf = TDA9887_PRESENT, 890 .tda9887_conf = TDA9887_PRESENT,
784 .inputs = {{ 891 .inputs = {{
785 .name = name_tv, 892 .name = name_tv,
@@ -809,6 +916,9 @@ struct saa7134_board saa7134_boards[] = {
809 .name = "BMK MPEX Tuner", 916 .name = "BMK MPEX Tuner",
810 .audio_clock = 0x200000, 917 .audio_clock = 0x200000,
811 .tuner_type = TUNER_PHILIPS_PAL, 918 .tuner_type = TUNER_PHILIPS_PAL,
919 .radio_type = UNSET,
920 .tuner_addr = ADDR_UNSET,
921 .radio_addr = ADDR_UNSET,
812 .inputs = {{ 922 .inputs = {{
813 .name = name_comp1, 923 .name = name_comp1,
814 .vmux = 1, 924 .vmux = 1,
@@ -825,62 +935,72 @@ struct saa7134_board saa7134_boards[] = {
825 }}, 935 }},
826 .mpeg = SAA7134_MPEG_EMPRESS, 936 .mpeg = SAA7134_MPEG_EMPRESS,
827 .video_out = CCIR656, 937 .video_out = CCIR656,
828 }, 938 },
829 [SAA7134_BOARD_ASUSTEK_TVFM7133] = { 939 [SAA7134_BOARD_ASUSTEK_TVFM7133] = {
830 .name = "ASUS TV-FM 7133", 940 .name = "ASUS TV-FM 7133",
831 .audio_clock = 0x00187de7, 941 .audio_clock = 0x00187de7,
832 // probably wrong, the 7133 one is the NTSC version ... 942 /* probably wrong, the 7133 one is the NTSC version ...
833 // .tuner_type = TUNER_PHILIPS_FM1236_MK3 943 * .tuner_type = TUNER_PHILIPS_FM1236_MK3 */
834 .tuner_type = TUNER_LG_NTSC_NEW_TAPC, 944 .tuner_type = TUNER_LG_NTSC_NEW_TAPC,
835 .tda9887_conf = TDA9887_PRESENT, 945 .radio_type = UNSET,
836 .inputs = {{ 946 .tuner_addr = ADDR_UNSET,
837 .name = name_tv, 947 .radio_addr = ADDR_UNSET,
838 .vmux = 1, 948 .tda9887_conf = TDA9887_PRESENT,
839 .amux = TV, 949 .inputs = {{
840 .tv = 1, 950 .name = name_tv,
841 },{ 951 .vmux = 1,
842 .name = name_comp1, 952 .amux = TV,
843 .vmux = 4, 953 .tv = 1,
844 .amux = LINE2, 954
845 },{ 955 },{
846 .name = name_svideo, 956 .name = name_comp1,
847 .vmux = 6, 957 .vmux = 4,
848 .amux = LINE2, 958 .amux = LINE2,
849 }}, 959 },{
850 .radio = { 960 .name = name_svideo,
851 .name = name_radio, 961 .vmux = 6,
852 .amux = LINE1, 962 .amux = LINE2,
853 }, 963 }},
854 }, 964 .radio = {
965 .name = name_radio,
966 .amux = LINE1,
967 },
968 },
855 [SAA7134_BOARD_PINNACLE_PCTV_STEREO] = { 969 [SAA7134_BOARD_PINNACLE_PCTV_STEREO] = {
856 .name = "Pinnacle PCTV Stereo (saa7134)", 970 .name = "Pinnacle PCTV Stereo (saa7134)",
857 .audio_clock = 0x00187de7, 971 .audio_clock = 0x00187de7,
858 .tuner_type = TUNER_MT2032, 972 .tuner_type = TUNER_MT2032,
859 .tda9887_conf = TDA9887_PRESENT | TDA9887_INTERCARRIER, 973 .radio_type = UNSET,
860 .inputs = {{ 974 .tuner_addr = ADDR_UNSET,
861 .name = name_tv, 975 .radio_addr = ADDR_UNSET,
862 .vmux = 3, 976 .tda9887_conf = TDA9887_PRESENT | TDA9887_INTERCARRIER,
863 .amux = TV, 977 .inputs = {{
864 .tv = 1, 978 .name = name_tv,
865 },{ 979 .vmux = 3,
866 .name = name_comp1, 980 .amux = TV,
867 .vmux = 0, 981 .tv = 1,
868 .amux = LINE2, 982 },{
869 },{ 983 .name = name_comp1,
870 .name = name_comp2, 984 .vmux = 0,
871 .vmux = 1, 985 .amux = LINE2,
872 .amux = LINE2, 986 },{
873 },{ 987 .name = name_comp2,
874 .name = name_svideo, 988 .vmux = 1,
875 .vmux = 8, 989 .amux = LINE2,
876 .amux = LINE2, 990 },{
877 }}, 991 .name = name_svideo,
878 }, 992 .vmux = 8,
993 .amux = LINE2,
994 }},
995 },
879 [SAA7134_BOARD_MANLI_MTV002] = { 996 [SAA7134_BOARD_MANLI_MTV002] = {
880 /* Ognjen Nastic <ognjen@logosoft.ba> */ 997 /* Ognjen Nastic <ognjen@logosoft.ba> */
881 .name = "Manli MuchTV M-TV002/Behold TV 403 FM", 998 .name = "Manli MuchTV M-TV002/Behold TV 403 FM",
882 .audio_clock = 0x00200000, 999 .audio_clock = 0x00200000,
883 .tuner_type = TUNER_PHILIPS_PAL, 1000 .tuner_type = TUNER_PHILIPS_PAL,
1001 .radio_type = UNSET,
1002 .tuner_addr = ADDR_UNSET,
1003 .radio_addr = ADDR_UNSET,
884 .inputs = {{ 1004 .inputs = {{
885 .name = name_svideo, 1005 .name = name_svideo,
886 .vmux = 8, 1006 .vmux = 8,
@@ -905,6 +1025,9 @@ struct saa7134_board saa7134_boards[] = {
905 .name = "Manli MuchTV M-TV001/Behold TV 401", 1025 .name = "Manli MuchTV M-TV001/Behold TV 401",
906 .audio_clock = 0x00200000, 1026 .audio_clock = 0x00200000,
907 .tuner_type = TUNER_PHILIPS_PAL, 1027 .tuner_type = TUNER_PHILIPS_PAL,
1028 .radio_type = UNSET,
1029 .tuner_addr = ADDR_UNSET,
1030 .radio_addr = ADDR_UNSET,
908 .inputs = {{ 1031 .inputs = {{
909 .name = name_svideo, 1032 .name = name_svideo,
910 .vmux = 8, 1033 .vmux = 8,
@@ -921,14 +1044,17 @@ struct saa7134_board saa7134_boards[] = {
921 }}, 1044 }},
922 .mute = { 1045 .mute = {
923 .name = name_mute, 1046 .name = name_mute,
924 .amux = LINE1, 1047 .amux = LINE1,
925 }, 1048 },
926 }, 1049 },
927 [SAA7134_BOARD_TG3000TV] = { 1050 [SAA7134_BOARD_TG3000TV] = {
928 /* TransGear 3000TV */ 1051 /* TransGear 3000TV */
929 .name = "Nagase Sangyo TransGear 3000TV", 1052 .name = "Nagase Sangyo TransGear 3000TV",
930 .audio_clock = 0x00187de7, 1053 .audio_clock = 0x00187de7,
931 .tuner_type = TUNER_PHILIPS_NTSC_M, 1054 .tuner_type = TUNER_PHILIPS_NTSC_M,
1055 .radio_type = UNSET,
1056 .tuner_addr = ADDR_UNSET,
1057 .radio_addr = ADDR_UNSET,
932 .inputs = {{ 1058 .inputs = {{
933 .name = name_tv, 1059 .name = name_tv,
934 .vmux = 1, 1060 .vmux = 1,
@@ -944,81 +1070,90 @@ struct saa7134_board saa7134_boards[] = {
944 .amux = LINE2, 1070 .amux = LINE2,
945 }}, 1071 }},
946 }, 1072 },
947 [SAA7134_BOARD_ECS_TVP3XP] = { 1073 [SAA7134_BOARD_ECS_TVP3XP] = {
948 .name = "Elitegroup ECS TVP3XP FM1216 Tuner Card(PAL-BG,FM) ", 1074 .name = "Elitegroup ECS TVP3XP FM1216 Tuner Card(PAL-BG,FM) ",
949 .audio_clock = 0x187de7, // xtal 32.1 MHz 1075 .audio_clock = 0x187de7, /* xtal 32.1 MHz */
950 .tuner_type = TUNER_PHILIPS_PAL, 1076 .tuner_type = TUNER_PHILIPS_PAL,
951 .inputs = {{ 1077 .radio_type = UNSET,
952 .name = name_tv, 1078 .tuner_addr = ADDR_UNSET,
953 .vmux = 1, 1079 .radio_addr = ADDR_UNSET,
954 .amux = TV, 1080 .inputs = {{
955 .tv = 1, 1081 .name = name_tv,
956 },{ 1082 .vmux = 1,
957 .name = name_tv_mono, 1083 .amux = TV,
958 .vmux = 1, 1084 .tv = 1,
959 .amux = LINE2, 1085 },{
960 .tv = 1, 1086 .name = name_tv_mono,
961 },{ 1087 .vmux = 1,
962 .name = name_comp1, 1088 .amux = LINE2,
963 .vmux = 3, 1089 .tv = 1,
964 .amux = LINE1, 1090 },{
965 },{ 1091 .name = name_comp1,
966 .name = name_svideo, 1092 .vmux = 3,
967 .vmux = 8, 1093 .amux = LINE1,
968 .amux = LINE1, 1094 },{
1095 .name = name_svideo,
1096 .vmux = 8,
1097 .amux = LINE1,
969 },{ 1098 },{
970 .name = "CVid over SVid", 1099 .name = "CVid over SVid",
971 .vmux = 0, 1100 .vmux = 0,
972 .amux = LINE1, 1101 .amux = LINE1,
973 }}, 1102 }},
974 .radio = { 1103 .radio = {
975 .name = name_radio, 1104 .name = name_radio,
976 .amux = LINE2, 1105 .amux = LINE2,
977 }, 1106 },
978 }, 1107 },
979 [SAA7134_BOARD_ECS_TVP3XP_4CB5] = { 1108 [SAA7134_BOARD_ECS_TVP3XP_4CB5] = {
980 .name = "Elitegroup ECS TVP3XP FM1236 Tuner Card (NTSC,FM)", 1109 .name = "Elitegroup ECS TVP3XP FM1236 Tuner Card (NTSC,FM)",
981 .audio_clock = 0x187de7, 1110 .audio_clock = 0x187de7,
982 .tuner_type = TUNER_PHILIPS_NTSC, 1111 .tuner_type = TUNER_PHILIPS_NTSC,
983 .inputs = {{ 1112 .radio_type = UNSET,
984 .name = name_tv, 1113 .tuner_addr = ADDR_UNSET,
985 .vmux = 1, 1114 .radio_addr = ADDR_UNSET,
986 .amux = TV, 1115 .inputs = {{
987 .tv = 1, 1116 .name = name_tv,
988 },{ 1117 .vmux = 1,
989 .name = name_tv_mono, 1118 .amux = TV,
990 .vmux = 1, 1119 .tv = 1,
991 .amux = LINE2, 1120 },{
992 .tv = 1, 1121 .name = name_tv_mono,
993 },{ 1122 .vmux = 1,
994 .name = name_comp1, 1123 .amux = LINE2,
995 .vmux = 3, 1124 .tv = 1,
996 .amux = LINE1, 1125 },{
997 },{ 1126 .name = name_comp1,
998 .name = name_svideo, 1127 .vmux = 3,
999 .vmux = 8, 1128 .amux = LINE1,
1000 .amux = LINE1, 1129 },{
1001 },{ 1130 .name = name_svideo,
1002 .name = "CVid over SVid", 1131 .vmux = 8,
1003 .vmux = 0, 1132 .amux = LINE1,
1004 .amux = LINE1, 1133 },{
1005 }}, 1134 .name = "CVid over SVid",
1006 .radio = { 1135 .vmux = 0,
1007 .name = name_radio, 1136 .amux = LINE1,
1008 .amux = LINE2, 1137 }},
1009 }, 1138 .radio = {
1010 }, 1139 .name = name_radio,
1140 .amux = LINE2,
1141 },
1142 },
1011 [SAA7134_BOARD_AVACSSMARTTV] = { 1143 [SAA7134_BOARD_AVACSSMARTTV] = {
1012 /* Roman Pszonczenko <romka@kolos.math.uni.lodz.pl> */ 1144 /* Roman Pszonczenko <romka@kolos.math.uni.lodz.pl> */
1013 .name = "AVACS SmartTV", 1145 .name = "AVACS SmartTV",
1014 .audio_clock = 0x00187de7, 1146 .audio_clock = 0x00187de7,
1015 .tuner_type = TUNER_PHILIPS_PAL, 1147 .tuner_type = TUNER_PHILIPS_PAL,
1148 .radio_type = UNSET,
1149 .tuner_addr = ADDR_UNSET,
1150 .radio_addr = ADDR_UNSET,
1016 .inputs = {{ 1151 .inputs = {{
1017 .name = name_tv, 1152 .name = name_tv,
1018 .vmux = 1, 1153 .vmux = 1,
1019 .amux = TV, 1154 .amux = TV,
1020 .tv = 1, 1155 .tv = 1,
1021 },{ 1156 },{
1022 .name = name_tv_mono, 1157 .name = name_tv_mono,
1023 .vmux = 1, 1158 .vmux = 1,
1024 .amux = LINE2, 1159 .amux = LINE2,
@@ -1047,6 +1182,9 @@ struct saa7134_board saa7134_boards[] = {
1047 .name = "AVerMedia DVD EZMaker", 1182 .name = "AVerMedia DVD EZMaker",
1048 .audio_clock = 0x00187de7, 1183 .audio_clock = 0x00187de7,
1049 .tuner_type = TUNER_ABSENT, 1184 .tuner_type = TUNER_ABSENT,
1185 .radio_type = UNSET,
1186 .tuner_addr = ADDR_UNSET,
1187 .radio_addr = ADDR_UNSET,
1050 .inputs = {{ 1188 .inputs = {{
1051 .name = name_comp1, 1189 .name = name_comp1,
1052 .vmux = 3, 1190 .vmux = 3,
@@ -1055,28 +1193,34 @@ struct saa7134_board saa7134_boards[] = {
1055 .vmux = 8, 1193 .vmux = 8,
1056 }}, 1194 }},
1057 }, 1195 },
1058 [SAA7134_BOARD_NOVAC_PRIMETV7133] = { 1196 [SAA7134_BOARD_NOVAC_PRIMETV7133] = {
1059 /* toshii@netbsd.org */ 1197 /* toshii@netbsd.org */
1060 .name = "Noval Prime TV 7133", 1198 .name = "Noval Prime TV 7133",
1061 .audio_clock = 0x00200000, 1199 .audio_clock = 0x00200000,
1062 .tuner_type = TUNER_ALPS_TSBH1_NTSC, 1200 .tuner_type = TUNER_ALPS_TSBH1_NTSC,
1063 .inputs = {{ 1201 .radio_type = UNSET,
1064 .name = name_comp1, 1202 .tuner_addr = ADDR_UNSET,
1065 .vmux = 3, 1203 .radio_addr = ADDR_UNSET,
1066 },{ 1204 .inputs = {{
1067 .name = name_tv, 1205 .name = name_comp1,
1068 .vmux = 1, 1206 .vmux = 3,
1069 .amux = TV, 1207 },{
1070 .tv = 1, 1208 .name = name_tv,
1071 },{ 1209 .vmux = 1,
1072 .name = name_svideo, 1210 .amux = TV,
1073 .vmux = 8, 1211 .tv = 1,
1074 }}, 1212 },{
1075 }, 1213 .name = name_svideo,
1214 .vmux = 8,
1215 }},
1216 },
1076 [SAA7134_BOARD_AVERMEDIA_STUDIO_305] = { 1217 [SAA7134_BOARD_AVERMEDIA_STUDIO_305] = {
1077 .name = "AverMedia AverTV Studio 305", 1218 .name = "AverMedia AverTV Studio 305",
1078 .audio_clock = 0x00187de7, 1219 .audio_clock = 0x00187de7,
1079 .tuner_type = TUNER_PHILIPS_FM1256_IH3, 1220 .tuner_type = TUNER_PHILIPS_FM1256_IH3,
1221 .radio_type = UNSET,
1222 .tuner_addr = ADDR_UNSET,
1223 .radio_addr = ADDR_UNSET,
1080 .tda9887_conf = TDA9887_PRESENT, 1224 .tda9887_conf = TDA9887_PRESENT,
1081 .inputs = {{ 1225 .inputs = {{
1082 .name = name_tv, 1226 .name = name_tv,
@@ -1097,35 +1241,41 @@ struct saa7134_board saa7134_boards[] = {
1097 .amux = LINE2, 1241 .amux = LINE2,
1098 }}, 1242 }},
1099 .radio = { 1243 .radio = {
1100 .name = name_radio, 1244 .name = name_radio,
1101 .amux = LINE2, 1245 .amux = LINE2,
1102 }, 1246 },
1103 .mute = { 1247 .mute = {
1104 .name = name_mute, 1248 .name = name_mute,
1105 .amux = LINE1, 1249 .amux = LINE1,
1106 }, 1250 },
1107 }, 1251 },
1108 [SAA7133_BOARD_UPMOST_PURPLE_TV] = { 1252 [SAA7134_BOARD_UPMOST_PURPLE_TV] = {
1109 .name = "UPMOST PURPLE TV", 1253 .name = "UPMOST PURPLE TV",
1110 .audio_clock = 0x00187de7, 1254 .audio_clock = 0x00187de7,
1111 .tuner_type = TUNER_PHILIPS_FM1236_MK3, 1255 .tuner_type = TUNER_PHILIPS_FM1236_MK3,
1112 .tda9887_conf = TDA9887_PRESENT, 1256 .radio_type = UNSET,
1113 .inputs = {{ 1257 .tuner_addr = ADDR_UNSET,
1114 .name = name_tv, 1258 .radio_addr = ADDR_UNSET,
1115 .vmux = 7, 1259 .tda9887_conf = TDA9887_PRESENT,
1116 .amux = TV, 1260 .inputs = {{
1117 .tv = 1, 1261 .name = name_tv,
1118 },{ 1262 .vmux = 7,
1119 .name = name_svideo, 1263 .amux = TV,
1120 .vmux = 7, 1264 .tv = 1,
1121 .amux = LINE1, 1265 },{
1122 }}, 1266 .name = name_svideo,
1267 .vmux = 7,
1268 .amux = LINE1,
1269 }},
1123 }, 1270 },
1124 [SAA7134_BOARD_ITEMS_MTV005] = { 1271 [SAA7134_BOARD_ITEMS_MTV005] = {
1125 /* Norman Jonas <normanjonas@arcor.de> */ 1272 /* Norman Jonas <normanjonas@arcor.de> */
1126 .name = "Items MuchTV Plus / IT-005", 1273 .name = "Items MuchTV Plus / IT-005",
1127 .audio_clock = 0x00187de7, 1274 .audio_clock = 0x00187de7,
1128 .tuner_type = TUNER_PHILIPS_PAL, 1275 .tuner_type = TUNER_PHILIPS_PAL,
1276 .radio_type = UNSET,
1277 .tuner_addr = ADDR_UNSET,
1278 .radio_addr = ADDR_UNSET,
1129 .inputs = {{ 1279 .inputs = {{
1130 .name = name_tv, 1280 .name = name_tv,
1131 .vmux = 3, 1281 .vmux = 3,
@@ -1149,27 +1299,30 @@ struct saa7134_board saa7134_boards[] = {
1149 .name = "Terratec Cinergy 200 TV", 1299 .name = "Terratec Cinergy 200 TV",
1150 .audio_clock = 0x00200000, 1300 .audio_clock = 0x00200000,
1151 .tuner_type = TUNER_PHILIPS_PAL, 1301 .tuner_type = TUNER_PHILIPS_PAL,
1302 .radio_type = UNSET,
1303 .tuner_addr = ADDR_UNSET,
1304 .radio_addr = ADDR_UNSET,
1152 .inputs = {{ 1305 .inputs = {{
1153 .name = name_tv, 1306 .name = name_tv,
1154 .vmux = 1, 1307 .vmux = 1,
1155 .amux = LINE2, 1308 .amux = LINE2,
1156 .tv = 1, 1309 .tv = 1,
1157 },{ 1310 },{
1158 .name = name_comp1, 1311 .name = name_comp1,
1159 .vmux = 4, 1312 .vmux = 4,
1160 .amux = LINE1, 1313 .amux = LINE1,
1161 },{ 1314 },{
1162 .name = name_svideo, 1315 .name = name_svideo,
1163 .vmux = 8, 1316 .vmux = 8,
1164 .amux = LINE1, 1317 .amux = LINE1,
1165 },{ 1318 },{
1166 .name = name_comp2, // CVideo over SVideo Connector 1319 .name = name_comp2, /* CVideo over SVideo Connector */
1167 .vmux = 0, 1320 .vmux = 0,
1168 .amux = LINE1, 1321 .amux = LINE1,
1169 }}, 1322 }},
1170 .mute = { 1323 .mute = {
1171 .name = name_mute, 1324 .name = name_mute,
1172 .amux = LINE2, 1325 .amux = LINE2,
1173 }, 1326 },
1174 }, 1327 },
1175 [SAA7134_BOARD_VIDEOMATE_TV_PVR] = { 1328 [SAA7134_BOARD_VIDEOMATE_TV_PVR] = {
@@ -1177,84 +1330,96 @@ struct saa7134_board saa7134_boards[] = {
1177 .name = "Compro VideoMate TV PVR/FM", 1330 .name = "Compro VideoMate TV PVR/FM",
1178 .audio_clock = 0x00187de7, 1331 .audio_clock = 0x00187de7,
1179 .tuner_type = TUNER_PHILIPS_NTSC_M, 1332 .tuner_type = TUNER_PHILIPS_NTSC_M,
1333 .radio_type = UNSET,
1334 .tuner_addr = ADDR_UNSET,
1335 .radio_addr = ADDR_UNSET,
1180 .gpiomask = 0x808c0080, 1336 .gpiomask = 0x808c0080,
1181 .inputs = {{ 1337 .inputs = {{
1182 .name = name_svideo, 1338 .name = name_svideo,
1183 .vmux = 8, 1339 .vmux = 8,
1184 .amux = LINE1, 1340 .amux = LINE1,
1185 .gpio = 0x00080, 1341 .gpio = 0x00080,
1186 },{ 1342 },{
1187 .name = name_comp1, 1343 .name = name_comp1,
1188 .vmux = 3, 1344 .vmux = 3,
1189 .amux = LINE1, 1345 .amux = LINE1,
1190 .gpio = 0x00080, 1346 .gpio = 0x00080,
1191 },{ 1347 },{
1192 .name = name_tv, 1348 .name = name_tv,
1193 .vmux = 1, 1349 .vmux = 1,
1194 .amux = LINE2_LEFT, 1350 .amux = LINE2_LEFT,
1195 .tv = 1, 1351 .tv = 1,
1196 .gpio = 0x00080, 1352 .gpio = 0x00080,
1197 }}, 1353 }},
1198 .radio = { 1354 .radio = {
1199 .name = name_radio, 1355 .name = name_radio,
1200 .amux = LINE2, 1356 .amux = LINE2,
1201 .gpio = 0x80000, 1357 .gpio = 0x80000,
1202 }, 1358 },
1203 .mute = { 1359 .mute = {
1204 .name = name_mute, 1360 .name = name_mute,
1205 .amux = LINE2, 1361 .amux = LINE2,
1206 .gpio = 0x40000, 1362 .gpio = 0x40000,
1207 }, 1363 },
1208 }, 1364 },
1209 [SAA7134_BOARD_SABRENT_SBTTVFM] = { 1365 [SAA7134_BOARD_SABRENT_SBTTVFM] = {
1210 /* Michael Rodriguez-Torrent <mrtorrent@asu.edu> */ 1366 /* Michael Rodriguez-Torrent <mrtorrent@asu.edu> */
1211 .name = "Sabrent SBT-TVFM (saa7130)", 1367 .name = "Sabrent SBT-TVFM (saa7130)",
1212 .audio_clock = 0x00187de7, 1368 .audio_clock = 0x00187de7,
1213 .tuner_type = TUNER_PHILIPS_NTSC_M, 1369 .tuner_type = TUNER_PHILIPS_NTSC_M,
1214 .inputs = {{ 1370 .radio_type = UNSET,
1371 .tuner_addr = ADDR_UNSET,
1372 .radio_addr = ADDR_UNSET,
1373 .inputs = {{
1215 .name = name_comp1, 1374 .name = name_comp1,
1216 .vmux = 1, 1375 .vmux = 1,
1217 .amux = LINE2, 1376 .amux = LINE2,
1218 },{ 1377 },{
1219 .name = name_tv, 1378 .name = name_tv,
1220 .vmux = 3, 1379 .vmux = 3,
1221 .amux = LINE2, 1380 .amux = LINE2,
1222 .tv = 1, 1381 .tv = 1,
1223 },{ 1382 },{
1224 .name = name_svideo, 1383 .name = name_svideo,
1225 .vmux = 8, 1384 .vmux = 8,
1226 .amux = LINE2, 1385 .amux = LINE2,
1227 }}, 1386 }},
1228 .radio = { 1387 .radio = {
1229 .name = name_radio, 1388 .name = name_radio,
1230 .amux = LINE2, 1389 .amux = LINE2,
1231 }, 1390 },
1232 }, 1391 },
1233 [SAA7134_BOARD_ZOLID_XPERT_TV7134] = { 1392 [SAA7134_BOARD_ZOLID_XPERT_TV7134] = {
1234 /* Helge Jensen <helge.jensen@slog.dk> */ 1393 /* Helge Jensen <helge.jensen@slog.dk> */
1235 .name = ":Zolid Xpert TV7134", 1394 .name = ":Zolid Xpert TV7134",
1236 .audio_clock = 0x00187de7, 1395 .audio_clock = 0x00187de7,
1237 .tuner_type = TUNER_PHILIPS_NTSC, 1396 .tuner_type = TUNER_PHILIPS_NTSC,
1238 .inputs = {{ 1397 .radio_type = UNSET,
1398 .tuner_addr = ADDR_UNSET,
1399 .radio_addr = ADDR_UNSET,
1400 .inputs = {{
1239 .name = name_svideo, 1401 .name = name_svideo,
1240 .vmux = 8, 1402 .vmux = 8,
1241 .amux = LINE1, 1403 .amux = LINE1,
1242 },{ 1404 },{
1243 .name = name_comp1, 1405 .name = name_comp1,
1244 .vmux = 3, 1406 .vmux = 3,
1245 .amux = LINE1, 1407 .amux = LINE1,
1246 },{ 1408 },{
1247 .name = name_tv, 1409 .name = name_tv,
1248 .vmux = 1, 1410 .vmux = 1,
1249 .amux = LINE2, 1411 .amux = LINE2,
1250 .tv = 1, 1412 .tv = 1,
1251 }}, 1413 }},
1252 }, 1414 },
1253 [SAA7134_BOARD_EMPIRE_PCI_TV_RADIO_LE] = { 1415 [SAA7134_BOARD_EMPIRE_PCI_TV_RADIO_LE] = {
1254 /* "Matteo Az" <matte.az@nospam.libero.it> ;-) */ 1416 /* "Matteo Az" <matte.az@nospam.libero.it> ;-) */
1255 .name = "Empire PCI TV-Radio LE", 1417 .name = "Empire PCI TV-Radio LE",
1256 .audio_clock = 0x00187de7, 1418 .audio_clock = 0x00187de7,
1257 .tuner_type = TUNER_PHILIPS_PAL, 1419 .tuner_type = TUNER_PHILIPS_PAL,
1420 .radio_type = UNSET,
1421 .tuner_addr = ADDR_UNSET,
1422 .radio_addr = ADDR_UNSET,
1258 .gpiomask = 0x4000, 1423 .gpiomask = 0x4000,
1259 .inputs = {{ 1424 .inputs = {{
1260 .name = name_tv_mono, 1425 .name = name_tv_mono,
@@ -1273,18 +1438,18 @@ struct saa7134_board saa7134_boards[] = {
1273 .amux = LINE1, 1438 .amux = LINE1,
1274 .gpio = 0x8000, 1439 .gpio = 0x8000,
1275 }}, 1440 }},
1276 .radio = { 1441 .radio = {
1277 .name = name_radio, 1442 .name = name_radio,
1278 .amux = LINE1, 1443 .amux = LINE1,
1279 .gpio = 0x8000, 1444 .gpio = 0x8000,
1280 }, 1445 },
1281 .mute = { 1446 .mute = {
1282 .name = name_mute, 1447 .name = name_mute,
1283 .amux = TV, 1448 .amux = TV,
1284 .gpio =0x8000, 1449 .gpio =0x8000,
1285 } 1450 }
1286 }, 1451 },
1287 [SAA7134_BOARD_AVERMEDIA_STUDIO_307] = { 1452 [SAA7134_BOARD_AVERMEDIA_STUDIO_307] = {
1288 /* 1453 /*
1289 Nickolay V. Shmyrev <nshmyrev@yandex.ru> 1454 Nickolay V. Shmyrev <nshmyrev@yandex.ru>
1290 Lots of thanks to Andrey Zolotarev <zolotarev_andrey@mail.ru> 1455 Lots of thanks to Andrey Zolotarev <zolotarev_andrey@mail.ru>
@@ -1292,6 +1457,9 @@ struct saa7134_board saa7134_boards[] = {
1292 .name = "Avermedia AVerTV Studio 307", 1457 .name = "Avermedia AVerTV Studio 307",
1293 .audio_clock = 0x00187de7, 1458 .audio_clock = 0x00187de7,
1294 .tuner_type = TUNER_PHILIPS_FM1256_IH3, 1459 .tuner_type = TUNER_PHILIPS_FM1256_IH3,
1460 .radio_type = UNSET,
1461 .tuner_addr = ADDR_UNSET,
1462 .radio_addr = ADDR_UNSET,
1295 .tda9887_conf = TDA9887_PRESENT, 1463 .tda9887_conf = TDA9887_PRESENT,
1296 .gpiomask = 0x03, 1464 .gpiomask = 0x03,
1297 .inputs = {{ 1465 .inputs = {{
@@ -1321,13 +1489,21 @@ struct saa7134_board saa7134_boards[] = {
1321 .amux = LINE1, 1489 .amux = LINE1,
1322 .gpio = 0x01, 1490 .gpio = 0x01,
1323 }, 1491 },
1324 }, 1492 .mute = {
1325 [SAA7134_BOARD_AVERMEDIA_GO_007_FM] = { 1493 .name = name_mute,
1494 .amux = LINE1,
1495 .gpio = 0x00,
1496 },
1497 },
1498 [SAA7134_BOARD_AVERMEDIA_GO_007_FM] = {
1326 .name = "Avermedia AVerTV GO 007 FM", 1499 .name = "Avermedia AVerTV GO 007 FM",
1327 .audio_clock = 0x00187de7, 1500 .audio_clock = 0x00187de7,
1328 .tuner_type = TUNER_PHILIPS_TDA8290, 1501 .tuner_type = TUNER_PHILIPS_TDA8290,
1502 .radio_type = UNSET,
1503 .tuner_addr = ADDR_UNSET,
1504 .radio_addr = ADDR_UNSET,
1329 .gpiomask = 0x00300003, 1505 .gpiomask = 0x00300003,
1330// .gpiomask = 0x8c240003, 1506 /* .gpiomask = 0x8c240003, */
1331 .inputs = {{ 1507 .inputs = {{
1332 .name = name_tv, 1508 .name = name_tv,
1333 .vmux = 1, 1509 .vmux = 1,
@@ -1350,16 +1526,24 @@ struct saa7134_board saa7134_boards[] = {
1350 .amux = LINE1, 1526 .amux = LINE1,
1351 .gpio = 0x00300001, 1527 .gpio = 0x00300001,
1352 }, 1528 },
1353 }, 1529 .mute = {
1530 .name = name_mute,
1531 .amux = TV,
1532 .gpio = 0x01,
1533 },
1534 },
1354 [SAA7134_BOARD_AVERMEDIA_CARDBUS] = { 1535 [SAA7134_BOARD_AVERMEDIA_CARDBUS] = {
1355 /* Jon Westgate <oryn@oryn.fsck.tv> */ 1536 /* Kees.Blom@cwi.nl */
1356 .name = "AVerMedia Cardbus TV/Radio", 1537 .name = "AVerMedia Cardbus TV/Radio (E500)",
1357 .audio_clock = 0x00200000, 1538 .audio_clock = 0x187de7,
1358 .tuner_type = TUNER_PHILIPS_PAL, 1539 .tuner_type = TUNER_PHILIPS_TDA8290,
1540 .radio_type = UNSET,
1541 .tuner_addr = ADDR_UNSET,
1542 .radio_addr = ADDR_UNSET,
1359 .inputs = {{ 1543 .inputs = {{
1360 .name = name_tv, 1544 .name = name_tv,
1361 .vmux = 1, 1545 .vmux = 1,
1362 .amux = LINE2, 1546 .amux = TV,
1363 .tv = 1, 1547 .tv = 1,
1364 },{ 1548 },{
1365 .name = name_comp1, 1549 .name = name_comp1,
@@ -1368,10 +1552,10 @@ struct saa7134_board saa7134_boards[] = {
1368 },{ 1552 },{
1369 .name = name_svideo, 1553 .name = name_svideo,
1370 .vmux = 8, 1554 .vmux = 8,
1371 .amux = LINE2, 1555 .amux = LINE1,
1372 }}, 1556 }},
1373 .radio = { 1557 .radio = {
1374 .name = name_radio, 1558 .name = name_radio,
1375 .amux = LINE1, 1559 .amux = LINE1,
1376 }, 1560 },
1377 }, 1561 },
@@ -1379,119 +1563,134 @@ struct saa7134_board saa7134_boards[] = {
1379 .name = "Terratec Cinergy 400 mobile", 1563 .name = "Terratec Cinergy 400 mobile",
1380 .audio_clock = 0x187de7, 1564 .audio_clock = 0x187de7,
1381 .tuner_type = TUNER_ALPS_TSBE5_PAL, 1565 .tuner_type = TUNER_ALPS_TSBE5_PAL,
1382 .tda9887_conf = TDA9887_PRESENT, 1566 .radio_type = UNSET,
1567 .tuner_addr = ADDR_UNSET,
1568 .radio_addr = ADDR_UNSET,
1569 .tda9887_conf = TDA9887_PRESENT,
1383 .inputs = {{ 1570 .inputs = {{
1384 .name = name_tv, 1571 .name = name_tv,
1385 .vmux = 1, 1572 .vmux = 1,
1386 .amux = TV, 1573 .amux = TV,
1387 .tv = 1, 1574 .tv = 1,
1388 },{ 1575 },{
1389 .name = name_tv_mono, 1576 .name = name_tv_mono,
1390 .vmux = 1, 1577 .vmux = 1,
1391 .amux = LINE2, 1578 .amux = LINE2,
1392 .tv = 1, 1579 .tv = 1,
1393 },{ 1580 },{
1394 .name = name_comp1, 1581 .name = name_comp1,
1395 .vmux = 3, 1582 .vmux = 3,
1396 .amux = LINE1, 1583 .amux = LINE1,
1397 },{ 1584 },{
1398 .name = name_svideo, 1585 .name = name_svideo,
1399 .vmux = 8, 1586 .vmux = 8,
1400 .amux = LINE1, 1587 .amux = LINE1,
1401 }}, 1588 }},
1402 }, 1589 },
1403 [SAA7134_BOARD_CINERGY600_MK3] = { 1590 [SAA7134_BOARD_CINERGY600_MK3] = {
1404 .name = "Terratec Cinergy 600 TV MK3", 1591 .name = "Terratec Cinergy 600 TV MK3",
1405 .audio_clock = 0x00200000, 1592 .audio_clock = 0x00200000,
1406 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3, 1593 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
1407 .tda9887_conf = TDA9887_PRESENT, 1594 .radio_type = UNSET,
1408 .inputs = {{ 1595 .tuner_addr = ADDR_UNSET,
1409 .name = name_tv, 1596 .radio_addr = ADDR_UNSET,
1410 .vmux = 1, 1597 .tda9887_conf = TDA9887_PRESENT,
1411 .amux = TV, 1598 .inputs = {{
1412 .tv = 1, 1599 .name = name_tv,
1413 },{ 1600 .vmux = 1,
1414 .name = name_comp1, 1601 .amux = TV,
1415 .vmux = 4, 1602 .tv = 1,
1416 .amux = LINE1, 1603 },{
1417 },{ 1604 .name = name_comp1,
1418 .name = name_svideo, 1605 .vmux = 4,
1419 .vmux = 8, 1606 .amux = LINE1,
1420 .amux = LINE1, 1607 },{
1421 },{ 1608 .name = name_svideo,
1422 .name = name_comp2, // CVideo over SVideo Connector 1609 .vmux = 8,
1423 .vmux = 0, 1610 .amux = LINE1,
1424 .amux = LINE1, 1611 },{
1425 }}, 1612 .name = name_comp2, /* CVideo over SVideo Connector */
1613 .vmux = 0,
1614 .amux = LINE1,
1615 }},
1426 .radio = { 1616 .radio = {
1427 .name = name_radio, 1617 .name = name_radio,
1428 .amux = LINE2, 1618 .amux = LINE2,
1429 }, 1619 },
1430 }, 1620 },
1431 [SAA7134_BOARD_VIDEOMATE_GOLD_PLUS] = { 1621 [SAA7134_BOARD_VIDEOMATE_GOLD_PLUS] = {
1432 /* Dylan Walkden <dylan_walkden@hotmail.com> */ 1622 /* Dylan Walkden <dylan_walkden@hotmail.com> */
1433 .name = "Compro VideoMate Gold+ Pal", 1623 .name = "Compro VideoMate Gold+ Pal",
1434 .audio_clock = 0x00187de7, 1624 .audio_clock = 0x00187de7,
1435 .tuner_type = TUNER_PHILIPS_PAL, 1625 .tuner_type = TUNER_PHILIPS_PAL,
1436 .gpiomask = 0x1ce780, 1626 .radio_type = UNSET,
1437 .inputs = {{ 1627 .tuner_addr = ADDR_UNSET,
1438 .name = name_svideo, 1628 .radio_addr = ADDR_UNSET,
1439 .vmux = 0, // CVideo over SVideo Connector - ok? 1629 .gpiomask = 0x1ce780,
1440 .amux = LINE1, 1630 .inputs = {{
1441 .gpio = 0x008080, 1631 .name = name_svideo,
1442 },{ 1632 .vmux = 0, /* CVideo over SVideo Connector - ok? */
1443 .name = name_comp1, 1633 .amux = LINE1,
1444 .vmux = 3, 1634 .gpio = 0x008080,
1445 .amux = LINE1, 1635 },{
1446 .gpio = 0x008080, 1636 .name = name_comp1,
1447 },{ 1637 .vmux = 3,
1448 .name = name_tv, 1638 .amux = LINE1,
1449 .vmux = 1, 1639 .gpio = 0x008080,
1450 .amux = TV, 1640 },{
1451 .tv = 1, 1641 .name = name_tv,
1452 .gpio = 0x008080, 1642 .vmux = 1,
1453 }}, 1643 .amux = TV,
1454 .radio = { 1644 .tv = 1,
1455 .name = name_radio, 1645 .gpio = 0x008080,
1456 .amux = LINE2, 1646 }},
1457 .gpio = 0x80000, 1647 .radio = {
1458 }, 1648 .name = name_radio,
1459 .mute = { 1649 .amux = LINE2,
1460 .name = name_mute, 1650 .gpio = 0x80000,
1461 .amux = LINE2, 1651 },
1462 .gpio = 0x0c8000, 1652 .mute = {
1463 }, 1653 .name = name_mute,
1464 }, 1654 .amux = LINE2,
1655 .gpio = 0x0c8000,
1656 },
1657 },
1465 [SAA7134_BOARD_PINNACLE_300I_DVBT_PAL] = { 1658 [SAA7134_BOARD_PINNACLE_300I_DVBT_PAL] = {
1466 .name = "Pinnacle PCTV 300i DVB-T + PAL", 1659 .name = "Pinnacle PCTV 300i DVB-T + PAL",
1467 .audio_clock = 0x00187de7, 1660 .audio_clock = 0x00187de7,
1468 .tuner_type = TUNER_MT2032, 1661 .tuner_type = TUNER_MT2032,
1469 .tda9887_conf = TDA9887_PRESENT | TDA9887_INTERCARRIER, 1662 .radio_type = UNSET,
1663 .tuner_addr = ADDR_UNSET,
1664 .radio_addr = ADDR_UNSET,
1665 .tda9887_conf = TDA9887_PRESENT | TDA9887_INTERCARRIER,
1470 .mpeg = SAA7134_MPEG_DVB, 1666 .mpeg = SAA7134_MPEG_DVB,
1471 .inputs = {{ 1667 .inputs = {{
1472 .name = name_tv, 1668 .name = name_tv,
1473 .vmux = 3, 1669 .vmux = 3,
1474 .amux = TV, 1670 .amux = TV,
1475 .tv = 1, 1671 .tv = 1,
1476 },{ 1672 },{
1477 .name = name_comp1, 1673 .name = name_comp1,
1478 .vmux = 0, 1674 .vmux = 0,
1479 .amux = LINE2, 1675 .amux = LINE2,
1480 },{ 1676 },{
1481 .name = name_comp2, 1677 .name = name_comp2,
1482 .vmux = 1, 1678 .vmux = 1,
1483 .amux = LINE2, 1679 .amux = LINE2,
1484 },{ 1680 },{
1485 .name = name_svideo, 1681 .name = name_svideo,
1486 .vmux = 8, 1682 .vmux = 8,
1487 .amux = LINE2, 1683 .amux = LINE2,
1488 }}, 1684 }},
1489 }, 1685 },
1490 [SAA7134_BOARD_PROVIDEO_PV952] = { 1686 [SAA7134_BOARD_PROVIDEO_PV952] = {
1491 /* andreas.kretschmer@web.de */ 1687 /* andreas.kretschmer@web.de */
1492 .name = "ProVideo PV952", 1688 .name = "ProVideo PV952",
1493 .audio_clock = 0x00187de7, 1689 .audio_clock = 0x00187de7,
1494 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3, 1690 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
1691 .radio_type = UNSET,
1692 .tuner_addr = ADDR_UNSET,
1693 .radio_addr = ADDR_UNSET,
1495 .tda9887_conf = TDA9887_PRESENT, 1694 .tda9887_conf = TDA9887_PRESENT,
1496 .inputs = {{ 1695 .inputs = {{
1497 .name = name_comp1, 1696 .name = name_comp1,
@@ -1515,10 +1714,13 @@ struct saa7134_board saa7134_boards[] = {
1515 }, 1714 },
1516 [SAA7134_BOARD_AVERMEDIA_305] = { 1715 [SAA7134_BOARD_AVERMEDIA_305] = {
1517 /* much like the "studio" version but without radio 1716 /* much like the "studio" version but without radio
1518 * and another tuner (sirspiritus@yandex.ru) */ 1717 * and another tuner (sirspiritus@yandex.ru) */
1519 .name = "AverMedia AverTV/305", 1718 .name = "AverMedia AverTV/305",
1520 .audio_clock = 0x00187de7, 1719 .audio_clock = 0x00187de7,
1521 .tuner_type = TUNER_PHILIPS_FQ1216ME, 1720 .tuner_type = TUNER_PHILIPS_FQ1216ME,
1721 .radio_type = UNSET,
1722 .tuner_addr = ADDR_UNSET,
1723 .radio_addr = ADDR_UNSET,
1522 .tda9887_conf = TDA9887_PRESENT, 1724 .tda9887_conf = TDA9887_PRESENT,
1523 .inputs = {{ 1725 .inputs = {{
1524 .name = name_tv, 1726 .name = name_tv,
@@ -1539,115 +1741,268 @@ struct saa7134_board saa7134_boards[] = {
1539 .amux = LINE2, 1741 .amux = LINE2,
1540 }}, 1742 }},
1541 .mute = { 1743 .mute = {
1542 .name = name_mute, 1744 .name = name_mute,
1543 .amux = LINE1, 1745 .amux = LINE1,
1544 }, 1746 },
1545 }, 1747 },
1546 [SAA7134_BOARD_FLYDVBTDUO] = { 1748 [SAA7134_BOARD_FLYDVBTDUO] = {
1547 /* LifeView FlyDVB-T DUO */ 1749 /* LifeView FlyDVB-T DUO */
1548 /* "Nico Sabbi <nsabbi@tiscali.it> */ 1750 /* "Nico Sabbi <nsabbi@tiscali.it> Hartmut Hackmann hartmut.hackmann@t-online.de*/
1549 .name = "LifeView FlyDVB-T DUO", 1751 .name = "LifeView FlyDVB-T DUO",
1550 .audio_clock = 0x00200000, 1752 .audio_clock = 0x00200000,
1551 .tuner_type = TUNER_PHILIPS_TDA8290, 1753 .tuner_type = TUNER_PHILIPS_TDA8290,
1552// .gpiomask = 0xe000, 1754 .radio_type = UNSET,
1755 .tuner_addr = ADDR_UNSET,
1756 .radio_addr = ADDR_UNSET,
1757 .mpeg = SAA7134_MPEG_DVB,
1553 .inputs = {{ 1758 .inputs = {{
1554 .name = name_tv, 1759 .name = name_tv,
1555 .vmux = 1, 1760 .vmux = 1,
1556 .amux = TV, 1761 .amux = TV,
1557// .gpio = 0x0000,
1558 .tv = 1, 1762 .tv = 1,
1559 },{ 1763 },{
1560 .name = name_comp1, /* Composite signal on S-Video input */ 1764 .name = name_comp1, /* Composite signal on S-Video input */
1561 .vmux = 0, 1765 .vmux = 0,
1562 .amux = LINE2, 1766 .amux = LINE2,
1563// .gpio = 0x4000,
1564 },{ 1767 },{
1565 .name = name_comp2, /* Composite input */ 1768 .name = name_comp2, /* Composite input */
1566 .vmux = 3, 1769 .vmux = 3,
1567 .amux = LINE2, 1770 .amux = LINE2,
1568// .gpio = 0x4000,
1569 },{ 1771 },{
1570 .name = name_svideo, /* S-Video signal on S-Video input */ 1772 .name = name_svideo, /* S-Video signal on S-Video input */
1571 .vmux = 8, 1773 .vmux = 8,
1572 .amux = LINE2, 1774 .amux = LINE2,
1573// .gpio = 0x4000,
1574 }}, 1775 }},
1575 }, 1776 },
1576 [SAA7134_BOARD_AVERMEDIA_307] = { 1777 [SAA7134_BOARD_PHILIPS_TOUGH] = {
1577 /* 1778 .name = "Philips TOUGH DVB-T reference design",
1578 Davydov Vladimir <vladimir@iqmedia.com> 1779 .tuner_type = TUNER_ABSENT,
1579 */ 1780 .audio_clock = 0x00187de7,
1580 .name = "Avermedia AVerTV 307", 1781 .radio_type = UNSET,
1581 .audio_clock = 0x00187de7, 1782 .tuner_addr = ADDR_UNSET,
1582 .tuner_type = TUNER_PHILIPS_FQ1216ME, 1783 .radio_addr = ADDR_UNSET,
1583 .tda9887_conf = TDA9887_PRESENT, 1784 .mpeg = SAA7134_MPEG_DVB,
1584 .inputs = {{ 1785 .inputs = {{
1585 .name = name_tv, 1786 .name = name_comp1,
1586 .vmux = 1, 1787 .vmux = 0,
1587 .amux = TV, 1788 .amux = LINE1,
1588 .tv = 1, 1789 },{
1589 },{ 1790 .name = name_svideo,
1590 .name = name_comp1, 1791 .vmux = 8,
1591 .vmux = 0, 1792 .amux = LINE1,
1592 .amux = LINE1, 1793 }},
1593 },{ 1794 },
1594 .name = name_comp2, 1795 [SAA7134_BOARD_AVERMEDIA_307] = {
1595 .vmux = 3, 1796 /*
1596 .amux = LINE1, 1797 Davydov Vladimir <vladimir@iqmedia.com>
1597 },{ 1798 */
1598 .name = name_svideo, 1799 .name = "Avermedia AVerTV 307",
1599 .vmux = 8, 1800 .audio_clock = 0x00187de7,
1600 .amux = LINE1, 1801 .tuner_type = TUNER_PHILIPS_FQ1216ME,
1601 }}, 1802 .radio_type = UNSET,
1602 }, 1803 .tuner_addr = ADDR_UNSET,
1804 .radio_addr = ADDR_UNSET,
1805 .tda9887_conf = TDA9887_PRESENT,
1806 .inputs = {{
1807 .name = name_tv,
1808 .vmux = 1,
1809 .amux = TV,
1810 .tv = 1,
1811 },{
1812 .name = name_comp1,
1813 .vmux = 0,
1814 .amux = LINE1,
1815 },{
1816 .name = name_comp2,
1817 .vmux = 3,
1818 .amux = LINE1,
1819 },{
1820 .name = name_svideo,
1821 .vmux = 8,
1822 .amux = LINE1,
1823 }},
1824 },
1603 [SAA7134_BOARD_ADS_INSTANT_TV] = { 1825 [SAA7134_BOARD_ADS_INSTANT_TV] = {
1604 .name = "ADS Tech Instant TV (saa7135)", 1826 .name = "ADS Tech Instant TV (saa7135)",
1827 .audio_clock = 0x00187de7,
1828 .tuner_type = TUNER_PHILIPS_TDA8290,
1829 .radio_type = UNSET,
1830 .tuner_addr = ADDR_UNSET,
1831 .radio_addr = ADDR_UNSET,
1832 .inputs = {{
1833 .name = name_tv,
1834 .vmux = 1,
1835 .amux = TV,
1836 .tv = 1,
1837 },{
1838 .name = name_comp1,
1839 .vmux = 3,
1840 .amux = LINE2,
1841 },{
1842 .name = name_svideo,
1843 .vmux = 8,
1844 .amux = LINE2,
1845 }},
1846 },
1847 [SAA7134_BOARD_KWORLD_VSTREAM_XPERT] = {
1848 .name = "Kworld/Tevion V-Stream Xpert TV PVR7134",
1605 .audio_clock = 0x00187de7, 1849 .audio_clock = 0x00187de7,
1606 .tuner_type = TUNER_PHILIPS_TDA8290, 1850 .tuner_type = TUNER_PHILIPS_PAL_I,
1607 .inputs = {{ 1851 .radio_type = UNSET,
1608 .name = name_tv, 1852 .tuner_addr = ADDR_UNSET,
1609 .vmux = 1, 1853 .radio_addr = ADDR_UNSET,
1610 .amux = TV, 1854 .gpiomask = 0x0700,
1611 .tv = 1, 1855 .inputs = {{
1612 },{ 1856 .name = name_tv,
1613 .name = name_comp1, 1857 .vmux = 1,
1614 .vmux = 3, 1858 .amux = TV,
1615 .amux = LINE2, 1859 .tv = 1,
1616 },{ 1860 .gpio = 0x000,
1617 .name = name_svideo, 1861 },{
1618 .vmux = 8, 1862 .name = name_comp1,
1619 .amux = LINE2, 1863 .vmux = 3,
1620 }}, 1864 .amux = LINE1,
1621 }, 1865 .gpio = 0x200, /* gpio by DScaler */
1622 [SAA7134_BOARD_KWORLD_VSTREAM_XPERT] = { 1866 },{
1623 .name = "Kworld/Tevion V-Stream Xpert TV PVR7134", 1867 .name = name_svideo,
1624 .audio_clock = 0x00187de7, 1868 .vmux = 0,
1625 .tuner_type = TUNER_PHILIPS_PAL_I, 1869 .amux = LINE1,
1626 .gpiomask = 0x0700, 1870 .gpio = 0x200,
1627 .inputs = {{ 1871 }},
1628 .name = name_tv, 1872 .radio = {
1629 .vmux = 1, 1873 .name = name_radio,
1630 .amux = TV, 1874 .amux = LINE1,
1631 .tv = 1, 1875 .gpio = 0x100,
1632 .gpio = 0x000, 1876 },
1633 },{ 1877 .mute = {
1634 .name = name_comp1, 1878 .name = name_mute,
1635 .vmux = 3, 1879 .amux = TV,
1636 .amux = LINE1, 1880 .gpio = 0x000,
1637 .gpio = 0x200, //gpio by DScaler 1881 },
1638 },{ 1882 },
1639 .name = name_svideo, 1883 [SAA7134_BOARD_THYPHOON_DVBT_DUO_CARDBUS] = {
1640 .vmux = 0, 1884 .name = "Typhoon DVB-T Duo Digital/Analog Cardbus",
1641 .amux = LINE1, 1885 .audio_clock = 0x00200000,
1642 .gpio = 0x200, 1886 .tuner_type = TUNER_PHILIPS_TDA8290,
1643 }}, 1887 .radio_type = UNSET,
1644 .radio = { 1888 .tuner_addr = ADDR_UNSET,
1645 .name = name_radio, 1889 .radio_addr = ADDR_UNSET,
1646 .amux = LINE1, 1890 .mpeg = SAA7134_MPEG_DVB,
1647 .gpio = 0x100, 1891 /* .gpiomask = 0xe000, */
1648 }, 1892 .inputs = {{
1649 }, 1893 .name = name_tv,
1650 }; 1894 .vmux = 1,
1895 .amux = TV,
1896 /* .gpio = 0x0000, */
1897 .tv = 1,
1898 },{
1899 .name = name_comp1, /* Composite signal on S-Video input */
1900 .vmux = 0,
1901 .amux = LINE2,
1902 /* .gpio = 0x4000, */
1903 },{
1904 .name = name_comp2, /* Composite input */
1905 .vmux = 3,
1906 .amux = LINE2,
1907 /* .gpio = 0x4000, */
1908 },{
1909 .name = name_svideo, /* S-Video signal on S-Video input */
1910 .vmux = 8,
1911 .amux = LINE2,
1912 /* .gpio = 0x4000, */
1913 }},
1914 .radio = {
1915 .name = name_radio,
1916 .amux = LINE2,
1917 },
1918 .mute = {
1919 .name = name_mute,
1920 .amux = LINE1,
1921 },
1922 },
1923 [SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII] = {
1924 .name = "Compro VideoMate TV Gold+II",
1925 .audio_clock = 0x002187de7,
1926 .tuner_type = TUNER_LG_PAL_NEW_TAPC,
1927 .radio_type = TUNER_TEA5767,
1928 .tuner_addr = 0x63,
1929 .radio_addr = 0x60,
1930 .gpiomask = 0x8c1880,
1931 .inputs = {{
1932 .name = name_svideo,
1933 .vmux = 0,
1934 .amux = LINE1,
1935 .gpio = 0x800800,
1936 },{
1937 .name = name_comp1,
1938 .vmux = 3,
1939 .amux = LINE1,
1940 .gpio = 0x801000,
1941 },{
1942 .name = name_tv,
1943 .vmux = 1,
1944 .amux = TV,
1945 .tv = 1,
1946 .gpio = 0x800000,
1947 }},
1948 .radio = {
1949 .name = name_radio,
1950 .amux = TV,
1951 .gpio = 0x880000,
1952 },
1953 .mute = {
1954 .name = name_mute,
1955 .amux = LINE2,
1956 .gpio = 0x840000,
1957 },
1958 },
1959 [SAA7134_BOARD_KWORLD_XPERT] = {
1960 /*
1961 FIXME:
1962 - Remote control doesn't initialize properly.
1963 - Audio volume starts muted,
1964 then gradually increases after channel change.
1965 - Overlay scaling problems (application error?)
1966 - Composite S-Video untested.
1967 From: Konrad Rzepecki <hannibal@megapolis.pl>
1968 */
1969 .name = "Kworld Xpert TV PVR7134",
1970 .audio_clock = 0x00187de7,
1971 .tuner_type = TUNER_TENA_9533_DI,
1972 .radio_type = TUNER_TEA5767,
1973 .tuner_addr = 0x61,
1974 .radio_addr = 0x60,
1975 .gpiomask = 0x0700,
1976 .inputs = {{
1977 .name = name_tv,
1978 .vmux = 1,
1979 .amux = TV,
1980 .tv = 1,
1981 .gpio = 0x000,
1982 },{
1983 .name = name_comp1,
1984 .vmux = 3,
1985 .amux = LINE1,
1986 .gpio = 0x200, /* gpio by DScaler */
1987 },{
1988 .name = name_svideo,
1989 .vmux = 0,
1990 .amux = LINE1,
1991 .gpio = 0x200,
1992 }},
1993 .radio = {
1994 .name = name_radio,
1995 .amux = LINE1,
1996 .gpio = 0x100,
1997 },
1998 .mute = {
1999 .name = name_mute,
2000 .amux = TV,
2001 .gpio = 0x000,
2002 },
2003 },
2004};
2005
1651 2006
1652const unsigned int saa7134_bcount = ARRAY_SIZE(saa7134_boards); 2007const unsigned int saa7134_bcount = ARRAY_SIZE(saa7134_boards);
1653 2008
@@ -1661,13 +2016,13 @@ struct pci_device_id saa7134_pci_tbl[] = {
1661 .subvendor = PCI_VENDOR_ID_PHILIPS, 2016 .subvendor = PCI_VENDOR_ID_PHILIPS,
1662 .subdevice = 0x2001, 2017 .subdevice = 0x2001,
1663 .driver_data = SAA7134_BOARD_PROTEUS_PRO, 2018 .driver_data = SAA7134_BOARD_PROTEUS_PRO,
1664 },{ 2019 },{
1665 .vendor = PCI_VENDOR_ID_PHILIPS, 2020 .vendor = PCI_VENDOR_ID_PHILIPS,
1666 .device = PCI_DEVICE_ID_PHILIPS_SAA7133, 2021 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
1667 .subvendor = PCI_VENDOR_ID_PHILIPS, 2022 .subvendor = PCI_VENDOR_ID_PHILIPS,
1668 .subdevice = 0x2001, 2023 .subdevice = 0x2001,
1669 .driver_data = SAA7134_BOARD_PROTEUS_PRO, 2024 .driver_data = SAA7134_BOARD_PROTEUS_PRO,
1670 },{ 2025 },{
1671 .vendor = PCI_VENDOR_ID_PHILIPS, 2026 .vendor = PCI_VENDOR_ID_PHILIPS,
1672 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 2027 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1673 .subvendor = PCI_VENDOR_ID_PHILIPS, 2028 .subvendor = PCI_VENDOR_ID_PHILIPS,
@@ -1676,70 +2031,70 @@ struct pci_device_id saa7134_pci_tbl[] = {
1676 },{ 2031 },{
1677 .vendor = PCI_VENDOR_ID_PHILIPS, 2032 .vendor = PCI_VENDOR_ID_PHILIPS,
1678 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 2033 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1679 .subvendor = 0x1131, 2034 .subvendor = 0x1131,
1680 .subdevice = 0x4e85, 2035 .subdevice = 0x4e85,
1681 .driver_data = SAA7134_BOARD_MONSTERTV, 2036 .driver_data = SAA7134_BOARD_MONSTERTV,
1682 },{ 2037 },{
1683 .vendor = PCI_VENDOR_ID_PHILIPS, 2038 .vendor = PCI_VENDOR_ID_PHILIPS,
1684 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 2039 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1685 .subvendor = 0x153B, 2040 .subvendor = 0x153B,
1686 .subdevice = 0x1142, 2041 .subdevice = 0x1142,
1687 .driver_data = SAA7134_BOARD_CINERGY400, 2042 .driver_data = SAA7134_BOARD_CINERGY400,
1688 },{ 2043 },{
1689 .vendor = PCI_VENDOR_ID_PHILIPS, 2044 .vendor = PCI_VENDOR_ID_PHILIPS,
1690 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 2045 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1691 .subvendor = 0x153B, 2046 .subvendor = 0x153B,
1692 .subdevice = 0x1143, 2047 .subdevice = 0x1143,
1693 .driver_data = SAA7134_BOARD_CINERGY600, 2048 .driver_data = SAA7134_BOARD_CINERGY600,
1694 },{ 2049 },{
1695 .vendor = PCI_VENDOR_ID_PHILIPS, 2050 .vendor = PCI_VENDOR_ID_PHILIPS,
1696 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 2051 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1697 .subvendor = 0x153B, 2052 .subvendor = 0x153B,
1698 .subdevice = 0x1158, 2053 .subdevice = 0x1158,
1699 .driver_data = SAA7134_BOARD_CINERGY600_MK3, 2054 .driver_data = SAA7134_BOARD_CINERGY600_MK3,
1700 },{ 2055 },{
1701 .vendor = PCI_VENDOR_ID_PHILIPS, 2056 .vendor = PCI_VENDOR_ID_PHILIPS,
1702 .device = PCI_DEVICE_ID_PHILIPS_SAA7133, 2057 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
1703 .subvendor = 0x153b, 2058 .subvendor = 0x153b,
1704 .subdevice = 0x1162, 2059 .subdevice = 0x1162,
1705 .driver_data = SAA7134_BOARD_CINERGY400_CARDBUS, 2060 .driver_data = SAA7134_BOARD_CINERGY400_CARDBUS,
1706 },{ 2061 },{
1707 .vendor = PCI_VENDOR_ID_PHILIPS, 2062 .vendor = PCI_VENDOR_ID_PHILIPS,
1708 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 2063 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1709 .subvendor = 0x5168, 2064 .subvendor = 0x5168,
1710 .subdevice = 0x0138, 2065 .subdevice = 0x0138,
1711 .driver_data = SAA7134_BOARD_FLYVIDEO3000, 2066 .driver_data = SAA7134_BOARD_FLYVIDEO3000,
1712 },{ 2067 },{
1713 .vendor = PCI_VENDOR_ID_PHILIPS, 2068 .vendor = PCI_VENDOR_ID_PHILIPS,
1714 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 2069 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1715 .subvendor = 0x4e42, //"Typhoon PCI Capture TV Card" Art.No. 50673 2070 .subvendor = 0x4e42, /* "Typhoon PCI Capture TV Card" Art.No. 50673 */
1716 .subdevice = 0x0138, 2071 .subdevice = 0x0138,
1717 .driver_data = SAA7134_BOARD_FLYVIDEO3000, 2072 .driver_data = SAA7134_BOARD_FLYVIDEO3000,
1718 },{ 2073 },{
1719 .vendor = PCI_VENDOR_ID_PHILIPS, 2074 .vendor = PCI_VENDOR_ID_PHILIPS,
1720 .device = PCI_DEVICE_ID_PHILIPS_SAA7130, 2075 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
1721 .subvendor = 0x5168, 2076 .subvendor = 0x5168,
1722 .subdevice = 0x0138, 2077 .subdevice = 0x0138,
1723 .driver_data = SAA7134_BOARD_FLYVIDEO2000, 2078 .driver_data = SAA7134_BOARD_FLYVIDEO2000,
1724 },{ 2079 },{
1725 .vendor = PCI_VENDOR_ID_PHILIPS, 2080 .vendor = PCI_VENDOR_ID_PHILIPS,
1726 .device = PCI_DEVICE_ID_PHILIPS_SAA7135, 2081 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
1727 .subvendor = 0x5168, 2082 .subvendor = 0x5168,
1728 .subdevice = 0x0212, /* minipci, LR212 */ 2083 .subdevice = 0x0212, /* minipci, LR212 */
1729 .driver_data = SAA7134_BOARD_FLYTVPLATINUM_MINI, 2084 .driver_data = SAA7134_BOARD_FLYTVPLATINUM_MINI,
1730 },{ 2085 },{
1731 .vendor = PCI_VENDOR_ID_PHILIPS, 2086 .vendor = PCI_VENDOR_ID_PHILIPS,
1732 .device = PCI_DEVICE_ID_PHILIPS_SAA7133, 2087 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
1733 .subvendor = 0x5168, /* Animation Technologies (LifeView) */ 2088 .subvendor = 0x5168, /* Animation Technologies (LifeView) */
1734 .subdevice = 0x0214, /* Standard PCI, LR214WF */ 2089 .subdevice = 0x0214, /* Standard PCI, LR214WF */
1735 .driver_data = SAA7134_BOARD_FLYTVPLATINUM_FM, 2090 .driver_data = SAA7134_BOARD_FLYTVPLATINUM_FM,
1736 },{ 2091 },{
1737 .vendor = PCI_VENDOR_ID_PHILIPS, 2092 .vendor = PCI_VENDOR_ID_PHILIPS,
1738 .device = PCI_DEVICE_ID_PHILIPS_SAA7133, 2093 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
1739 .subvendor = 0x1489, /* KYE */ 2094 .subvendor = 0x1489, /* KYE */
1740 .subdevice = 0x0214, /* Genius VideoWonder ProTV */ 2095 .subdevice = 0x0214, /* Genius VideoWonder ProTV */
1741 .driver_data = SAA7134_BOARD_FLYTVPLATINUM_FM, /* is an LR214WF actually */ 2096 .driver_data = SAA7134_BOARD_FLYTVPLATINUM_FM, /* is an LR214WF actually */
1742 },{ 2097 },{
1743 .vendor = PCI_VENDOR_ID_PHILIPS, 2098 .vendor = PCI_VENDOR_ID_PHILIPS,
1744 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 2099 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1745 .subvendor = 0x16be, 2100 .subvendor = 0x16be,
@@ -1758,36 +2113,36 @@ struct pci_device_id saa7134_pci_tbl[] = {
1758 .subdevice = 0x226b, 2113 .subdevice = 0x226b,
1759 .driver_data = SAA7134_BOARD_ELSA_500TV, 2114 .driver_data = SAA7134_BOARD_ELSA_500TV,
1760 },{ 2115 },{
1761 .vendor = PCI_VENDOR_ID_PHILIPS, 2116 .vendor = PCI_VENDOR_ID_PHILIPS,
1762 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 2117 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1763 .subvendor = PCI_VENDOR_ID_ASUSTEK, 2118 .subvendor = PCI_VENDOR_ID_ASUSTEK,
1764 .subdevice = 0x4842, 2119 .subdevice = 0x4842,
1765 .driver_data = SAA7134_BOARD_ASUSTeK_TVFM7134, 2120 .driver_data = SAA7134_BOARD_ASUSTeK_TVFM7134,
1766 },{ 2121 },{
1767 .vendor = PCI_VENDOR_ID_PHILIPS, 2122 .vendor = PCI_VENDOR_ID_PHILIPS,
1768 .device = PCI_DEVICE_ID_PHILIPS_SAA7135, 2123 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
1769 .subvendor = PCI_VENDOR_ID_ASUSTEK, 2124 .subvendor = PCI_VENDOR_ID_ASUSTEK,
1770 .subdevice = 0x4845, 2125 .subdevice = 0x4845,
1771 .driver_data = SAA7135_BOARD_ASUSTeK_TVFM7135, 2126 .driver_data = SAA7134_BOARD_ASUSTeK_TVFM7135,
1772 },{ 2127 },{
1773 .vendor = PCI_VENDOR_ID_PHILIPS, 2128 .vendor = PCI_VENDOR_ID_PHILIPS,
1774 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 2129 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1775 .subvendor = PCI_VENDOR_ID_ASUSTEK, 2130 .subvendor = PCI_VENDOR_ID_ASUSTEK,
1776 .subdevice = 0x4830, 2131 .subdevice = 0x4830,
1777 .driver_data = SAA7134_BOARD_ASUSTeK_TVFM7134, 2132 .driver_data = SAA7134_BOARD_ASUSTeK_TVFM7134,
1778 },{ 2133 },{
1779 .vendor = PCI_VENDOR_ID_PHILIPS, 2134 .vendor = PCI_VENDOR_ID_PHILIPS,
1780 .device = PCI_DEVICE_ID_PHILIPS_SAA7133, 2135 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
1781 .subvendor = PCI_VENDOR_ID_ASUSTEK, 2136 .subvendor = PCI_VENDOR_ID_ASUSTEK,
1782 .subdevice = 0x4843, 2137 .subdevice = 0x4843,
1783 .driver_data = SAA7134_BOARD_ASUSTEK_TVFM7133, 2138 .driver_data = SAA7134_BOARD_ASUSTEK_TVFM7133,
2139 },{
2140 .vendor = PCI_VENDOR_ID_PHILIPS,
2141 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
2142 .subvendor = PCI_VENDOR_ID_ASUSTEK,
2143 .subdevice = 0x4840,
2144 .driver_data = SAA7134_BOARD_ASUSTeK_TVFM7134,
1784 },{ 2145 },{
1785 .vendor = PCI_VENDOR_ID_PHILIPS,
1786 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1787 .subvendor = PCI_VENDOR_ID_ASUSTEK,
1788 .subdevice = 0x4840,
1789 .driver_data = SAA7134_BOARD_ASUSTeK_TVFM7134,
1790 },{
1791 .vendor = PCI_VENDOR_ID_PHILIPS, 2146 .vendor = PCI_VENDOR_ID_PHILIPS,
1792 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 2147 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1793 .subvendor = PCI_VENDOR_ID_PHILIPS, 2148 .subvendor = PCI_VENDOR_ID_PHILIPS,
@@ -1808,118 +2163,118 @@ struct pci_device_id saa7134_pci_tbl[] = {
1808 },{ 2163 },{
1809 .vendor = PCI_VENDOR_ID_PHILIPS, 2164 .vendor = PCI_VENDOR_ID_PHILIPS,
1810 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 2165 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1811 .subvendor = 0x1131, 2166 .subvendor = 0x1131,
1812 .subdevice = 0x7133, 2167 .subdevice = 0x7133,
1813 .driver_data = SAA7134_BOARD_VA1000POWER, 2168 .driver_data = SAA7134_BOARD_VA1000POWER,
1814 },{ 2169 },{
1815 .vendor = PCI_VENDOR_ID_PHILIPS, 2170 .vendor = PCI_VENDOR_ID_PHILIPS,
1816 .device = PCI_DEVICE_ID_PHILIPS_SAA7130, 2171 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
1817 .subvendor = PCI_VENDOR_ID_PHILIPS, 2172 .subvendor = PCI_VENDOR_ID_PHILIPS,
1818 .subdevice = 0x2001, 2173 .subdevice = 0x2001,
1819 .driver_data = SAA7134_BOARD_10MOONSTVMASTER, 2174 .driver_data = SAA7134_BOARD_10MOONSTVMASTER,
1820 },{ 2175 },{
1821 .vendor = PCI_VENDOR_ID_PHILIPS, 2176 .vendor = PCI_VENDOR_ID_PHILIPS,
1822 .device = PCI_DEVICE_ID_PHILIPS_SAA7133, 2177 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
1823 .subvendor = 0x185b, 2178 .subvendor = 0x185b,
1824 .subdevice = 0xc100, 2179 .subdevice = 0xc100,
1825 .driver_data = SAA7134_BOARD_VIDEOMATE_TV, 2180 .driver_data = SAA7134_BOARD_VIDEOMATE_TV,
1826 },{ 2181 },{
1827 .vendor = PCI_VENDOR_ID_PHILIPS, 2182 .vendor = PCI_VENDOR_ID_PHILIPS,
1828 .device = PCI_DEVICE_ID_PHILIPS_SAA7133, 2183 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
1829 .subvendor = 0x185b, 2184 .subvendor = 0x185b,
1830 .subdevice = 0xc100, 2185 .subdevice = 0xc100,
1831 .driver_data = SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUS, 2186 .driver_data = SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUS,
1832 },{ 2187 },{
1833 .vendor = PCI_VENDOR_ID_PHILIPS, 2188 .vendor = PCI_VENDOR_ID_PHILIPS,
1834 .device = PCI_DEVICE_ID_PHILIPS_SAA7130, 2189 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
1835 .subvendor = PCI_VENDOR_ID_MATROX, 2190 .subvendor = PCI_VENDOR_ID_MATROX,
1836 .subdevice = 0x48d0, 2191 .subdevice = 0x48d0,
1837 .driver_data = SAA7134_BOARD_CRONOS_PLUS, 2192 .driver_data = SAA7134_BOARD_CRONOS_PLUS,
1838 },{ 2193 },{
1839 .vendor = PCI_VENDOR_ID_PHILIPS, 2194 .vendor = PCI_VENDOR_ID_PHILIPS,
1840 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 2195 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1841 .subvendor = 0x1461, /* Avermedia Technologies Inc */ 2196 .subvendor = 0x1461, /* Avermedia Technologies Inc */
1842 .subdevice = 0xa70b, 2197 .subdevice = 0xa70b,
1843 .driver_data = SAA7134_BOARD_MD2819, 2198 .driver_data = SAA7134_BOARD_MD2819,
1844 },{ 2199 },{
1845 .vendor = PCI_VENDOR_ID_PHILIPS, 2200 .vendor = PCI_VENDOR_ID_PHILIPS,
1846 .device = PCI_DEVICE_ID_PHILIPS_SAA7130, 2201 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
1847 .subvendor = 0x1461, /* Avermedia Technologies Inc */ 2202 .subvendor = 0x1461, /* Avermedia Technologies Inc */
1848 .subdevice = 0x2115, 2203 .subdevice = 0x2115,
1849 .driver_data = SAA7134_BOARD_AVERMEDIA_STUDIO_305, 2204 .driver_data = SAA7134_BOARD_AVERMEDIA_STUDIO_305,
1850 },{ 2205 },{
1851 .vendor = PCI_VENDOR_ID_PHILIPS, 2206 .vendor = PCI_VENDOR_ID_PHILIPS,
1852 .device = PCI_DEVICE_ID_PHILIPS_SAA7130, 2207 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
1853 .subvendor = 0x1461, /* Avermedia Technologies Inc */ 2208 .subvendor = 0x1461, /* Avermedia Technologies Inc */
1854 .subdevice = 0x2108, 2209 .subdevice = 0x2108,
1855 .driver_data = SAA7134_BOARD_AVERMEDIA_305, 2210 .driver_data = SAA7134_BOARD_AVERMEDIA_305,
1856 },{ 2211 },{
1857 .vendor = PCI_VENDOR_ID_PHILIPS, 2212 .vendor = PCI_VENDOR_ID_PHILIPS,
1858 .device = PCI_DEVICE_ID_PHILIPS_SAA7130, 2213 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
1859 .subvendor = 0x1461, /* Avermedia Technologies Inc */ 2214 .subvendor = 0x1461, /* Avermedia Technologies Inc */
1860 .subdevice = 0x10ff, 2215 .subdevice = 0x10ff,
1861 .driver_data = SAA7134_BOARD_AVERMEDIA_DVD_EZMAKER, 2216 .driver_data = SAA7134_BOARD_AVERMEDIA_DVD_EZMAKER,
1862 },{ 2217 },{
1863 /* AVerMedia CardBus */ 2218 /* AVerMedia CardBus */
1864 .vendor = PCI_VENDOR_ID_PHILIPS, 2219 .vendor = PCI_VENDOR_ID_PHILIPS,
1865 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 2220 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1866 .subvendor = 0x1461, /* Avermedia Technologies Inc */ 2221 .subvendor = 0x1461, /* Avermedia Technologies Inc */
1867 .subdevice = 0xd6ee, 2222 .subdevice = 0xd6ee,
1868 .driver_data = SAA7134_BOARD_AVERMEDIA_CARDBUS, 2223 .driver_data = SAA7134_BOARD_AVERMEDIA_CARDBUS,
1869 },{ 2224 },{
1870 /* TransGear 3000TV */ 2225 /* TransGear 3000TV */
1871 .vendor = PCI_VENDOR_ID_PHILIPS, 2226 .vendor = PCI_VENDOR_ID_PHILIPS,
1872 .device = PCI_DEVICE_ID_PHILIPS_SAA7130, 2227 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
1873 .subvendor = 0x1461, /* Avermedia Technologies Inc */ 2228 .subvendor = 0x1461, /* Avermedia Technologies Inc */
1874 .subdevice = 0x050c, 2229 .subdevice = 0x050c,
1875 .driver_data = SAA7134_BOARD_TG3000TV, 2230 .driver_data = SAA7134_BOARD_TG3000TV,
1876 },{ 2231 },{
1877 .vendor = PCI_VENDOR_ID_PHILIPS,
1878 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1879 .subvendor = 0x11bd,
1880 .subdevice = 0x002b,
1881 .driver_data = SAA7134_BOARD_PINNACLE_PCTV_STEREO,
1882 },{
1883 .vendor = PCI_VENDOR_ID_PHILIPS,
1884 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1885 .subvendor = 0x11bd,
1886 .subdevice = 0x002d,
1887 .driver_data = SAA7134_BOARD_PINNACLE_300I_DVBT_PAL,
1888 },{
1889 .vendor = PCI_VENDOR_ID_PHILIPS,
1890 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1891 .subvendor = 0x1019,
1892 .subdevice = 0x4cb4,
1893 .driver_data = SAA7134_BOARD_ECS_TVP3XP,
1894 },{
1895 .vendor = PCI_VENDOR_ID_PHILIPS,
1896 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
1897 .subvendor = 0x1019,
1898 .subdevice = 0x4cb5,
1899 .driver_data = SAA7134_BOARD_ECS_TVP3XP_4CB5,
1900 },{
1901 .vendor = PCI_VENDOR_ID_PHILIPS, 2232 .vendor = PCI_VENDOR_ID_PHILIPS,
1902 .device = PCI_DEVICE_ID_PHILIPS_SAA7133, 2233 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1903 .subvendor = 0x12ab, 2234 .subvendor = 0x11bd,
1904 .subdevice = 0x0800, 2235 .subdevice = 0x002b,
1905 .driver_data = SAA7133_BOARD_UPMOST_PURPLE_TV, 2236 .driver_data = SAA7134_BOARD_PINNACLE_PCTV_STEREO,
2237 },{
2238 .vendor = PCI_VENDOR_ID_PHILIPS,
2239 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
2240 .subvendor = 0x11bd,
2241 .subdevice = 0x002d,
2242 .driver_data = SAA7134_BOARD_PINNACLE_300I_DVBT_PAL,
2243 },{
2244 .vendor = PCI_VENDOR_ID_PHILIPS,
2245 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
2246 .subvendor = 0x1019,
2247 .subdevice = 0x4cb4,
2248 .driver_data = SAA7134_BOARD_ECS_TVP3XP,
2249 },{
2250 .vendor = PCI_VENDOR_ID_PHILIPS,
2251 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
2252 .subvendor = 0x1019,
2253 .subdevice = 0x4cb5,
2254 .driver_data = SAA7134_BOARD_ECS_TVP3XP_4CB5,
2255 },{
2256 .vendor = PCI_VENDOR_ID_PHILIPS,
2257 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
2258 .subvendor = 0x12ab,
2259 .subdevice = 0x0800,
2260 .driver_data = SAA7134_BOARD_UPMOST_PURPLE_TV,
1906 },{ 2261 },{
1907 .vendor = PCI_VENDOR_ID_PHILIPS, 2262 .vendor = PCI_VENDOR_ID_PHILIPS,
1908 .device = PCI_DEVICE_ID_PHILIPS_SAA7130, 2263 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
1909 .subvendor = 0x153B, 2264 .subvendor = 0x153B,
1910 .subdevice = 0x1152, 2265 .subdevice = 0x1152,
1911 .driver_data = SAA7134_BOARD_CINERGY200, 2266 .driver_data = SAA7134_BOARD_CINERGY200,
1912 },{ 2267 },{
1913 .vendor = PCI_VENDOR_ID_PHILIPS, 2268 .vendor = PCI_VENDOR_ID_PHILIPS,
1914 .device = PCI_DEVICE_ID_PHILIPS_SAA7130, 2269 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
1915 .subvendor = 0x185b, 2270 .subvendor = 0x185b,
1916 .subdevice = 0xc100, 2271 .subdevice = 0xc100,
1917 .driver_data = SAA7134_BOARD_VIDEOMATE_TV_PVR, 2272 .driver_data = SAA7134_BOARD_VIDEOMATE_TV_PVR,
1918 },{ 2273 },{
1919 .vendor = PCI_VENDOR_ID_PHILIPS, 2274 .vendor = PCI_VENDOR_ID_PHILIPS,
1920 .device = PCI_DEVICE_ID_PHILIPS_SAA7130, 2275 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
1921 .subvendor = 0x1131, 2276 .subvendor = 0x1131,
1922 .subdevice = 0, 2277 .subdevice = 0,
1923 .driver_data = SAA7134_BOARD_SABRENT_SBTTVFM, 2278 .driver_data = SAA7134_BOARD_SABRENT_SBTTVFM,
1924 },{ 2279 },{
1925 .vendor = PCI_VENDOR_ID_PHILIPS, 2280 .vendor = PCI_VENDOR_ID_PHILIPS,
@@ -1939,18 +2294,24 @@ struct pci_device_id saa7134_pci_tbl[] = {
1939 .subvendor = 0x185b, 2294 .subvendor = 0x185b,
1940 .subdevice = 0xc200, 2295 .subdevice = 0xc200,
1941 .driver_data = SAA7134_BOARD_VIDEOMATE_GOLD_PLUS, 2296 .driver_data = SAA7134_BOARD_VIDEOMATE_GOLD_PLUS,
1942 },{ 2297 },{
1943 .vendor = PCI_VENDOR_ID_PHILIPS, 2298 .vendor = PCI_VENDOR_ID_PHILIPS,
1944 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 2299 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1945 .subvendor = 0x1540, 2300 .subvendor = 0x1540,
1946 .subdevice = 0x9524, 2301 .subdevice = 0x9524,
1947 .driver_data = SAA7134_BOARD_PROVIDEO_PV952, 2302 .driver_data = SAA7134_BOARD_PROVIDEO_PV952,
1948 2303
1949 },{ 2304 },{
1950 .vendor = PCI_VENDOR_ID_PHILIPS, 2305 .vendor = PCI_VENDOR_ID_PHILIPS,
1951 .device = PCI_DEVICE_ID_PHILIPS_SAA7133, 2306 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
1952 .subvendor = 0x5168, 2307 .subvendor = 0x5168,
1953 .subdevice = 0x0306, 2308 .subdevice = 0x0502, /* Cardbus version */
2309 .driver_data = SAA7134_BOARD_FLYDVBTDUO,
2310 },{
2311 .vendor = PCI_VENDOR_ID_PHILIPS,
2312 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
2313 .subvendor = 0x5168,
2314 .subdevice = 0x0306, /* PCI version */
1954 .driver_data = SAA7134_BOARD_FLYDVBTDUO, 2315 .driver_data = SAA7134_BOARD_FLYDVBTDUO,
1955 },{ 2316 },{
1956 .vendor = PCI_VENDOR_ID_PHILIPS, 2317 .vendor = PCI_VENDOR_ID_PHILIPS,
@@ -1959,31 +2320,44 @@ struct pci_device_id saa7134_pci_tbl[] = {
1959 .subdevice = 0xf31f, 2320 .subdevice = 0xf31f,
1960 .driver_data = SAA7134_BOARD_AVERMEDIA_GO_007_FM, 2321 .driver_data = SAA7134_BOARD_AVERMEDIA_GO_007_FM,
1961 2322
1962 },{ 2323 },{
1963 .vendor = PCI_VENDOR_ID_PHILIPS, 2324 .vendor = PCI_VENDOR_ID_PHILIPS,
1964 .device = PCI_DEVICE_ID_PHILIPS_SAA7135, 2325 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
2326 .subvendor = PCI_VENDOR_ID_PHILIPS,
2327 .subdevice = 0x2004,
2328 .driver_data = SAA7134_BOARD_PHILIPS_TOUGH,
2329 },{
2330 .vendor = PCI_VENDOR_ID_PHILIPS,
2331 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
1965 .subvendor = 0x1421, 2332 .subvendor = 0x1421,
1966 .subdevice = 0x0350, /* PCI version */ 2333 .subdevice = 0x0350, /* PCI version */
1967 .driver_data = SAA7134_BOARD_ADS_INSTANT_TV, 2334 .driver_data = SAA7134_BOARD_ADS_INSTANT_TV,
1968 2335
1969 },{ 2336 },{
1970 .vendor = PCI_VENDOR_ID_PHILIPS, 2337 .vendor = PCI_VENDOR_ID_PHILIPS,
1971 .device = PCI_DEVICE_ID_PHILIPS_SAA7135, 2338 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
1972 .subvendor = 0x1421, 2339 .subvendor = 0x1421,
1973 .subdevice = 0x0370, /* cardbus version */ 2340 .subdevice = 0x0370, /* cardbus version */
1974 .driver_data = SAA7134_BOARD_ADS_INSTANT_TV, 2341 .driver_data = SAA7134_BOARD_ADS_INSTANT_TV,
1975 2342
1976 },{ 2343 },{ /* Typhoon DVB-T Duo Digital/Analog Cardbus */
2344 .vendor = PCI_VENDOR_ID_PHILIPS,
2345 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
2346 .subvendor = 0x4e42,
2347 .subdevice = 0x0502,
2348 .driver_data = SAA7134_BOARD_THYPHOON_DVBT_DUO_CARDBUS,
2349
2350 },{
1977 /* --- boards without eeprom + subsystem ID --- */ 2351 /* --- boards without eeprom + subsystem ID --- */
1978 .vendor = PCI_VENDOR_ID_PHILIPS, 2352 .vendor = PCI_VENDOR_ID_PHILIPS,
1979 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 2353 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
1980 .subvendor = PCI_VENDOR_ID_PHILIPS, 2354 .subvendor = PCI_VENDOR_ID_PHILIPS,
1981 .subdevice = 0, 2355 .subdevice = 0,
1982 .driver_data = SAA7134_BOARD_NOAUTO, 2356 .driver_data = SAA7134_BOARD_NOAUTO,
1983 },{ 2357 },{
1984 .vendor = PCI_VENDOR_ID_PHILIPS, 2358 .vendor = PCI_VENDOR_ID_PHILIPS,
1985 .device = PCI_DEVICE_ID_PHILIPS_SAA7130, 2359 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
1986 .subvendor = PCI_VENDOR_ID_PHILIPS, 2360 .subvendor = PCI_VENDOR_ID_PHILIPS,
1987 .subdevice = 0, 2361 .subdevice = 0,
1988 .driver_data = SAA7134_BOARD_NOAUTO, 2362 .driver_data = SAA7134_BOARD_NOAUTO,
1989 },{ 2363 },{
@@ -1991,26 +2365,26 @@ struct pci_device_id saa7134_pci_tbl[] = {
1991 /* --- default catch --- */ 2365 /* --- default catch --- */
1992 .vendor = PCI_VENDOR_ID_PHILIPS, 2366 .vendor = PCI_VENDOR_ID_PHILIPS,
1993 .device = PCI_DEVICE_ID_PHILIPS_SAA7130, 2367 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
1994 .subvendor = PCI_ANY_ID, 2368 .subvendor = PCI_ANY_ID,
1995 .subdevice = PCI_ANY_ID, 2369 .subdevice = PCI_ANY_ID,
1996 .driver_data = SAA7134_BOARD_UNKNOWN, 2370 .driver_data = SAA7134_BOARD_UNKNOWN,
1997 },{ 2371 },{
1998 .vendor = PCI_VENDOR_ID_PHILIPS, 2372 .vendor = PCI_VENDOR_ID_PHILIPS,
1999 .device = PCI_DEVICE_ID_PHILIPS_SAA7133, 2373 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
2000 .subvendor = PCI_ANY_ID, 2374 .subvendor = PCI_ANY_ID,
2001 .subdevice = PCI_ANY_ID, 2375 .subdevice = PCI_ANY_ID,
2002 .driver_data = SAA7134_BOARD_UNKNOWN, 2376 .driver_data = SAA7134_BOARD_UNKNOWN,
2003 },{ 2377 },{
2004 .vendor = PCI_VENDOR_ID_PHILIPS, 2378 .vendor = PCI_VENDOR_ID_PHILIPS,
2005 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 2379 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
2006 .subvendor = PCI_ANY_ID, 2380 .subvendor = PCI_ANY_ID,
2007 .subdevice = PCI_ANY_ID, 2381 .subdevice = PCI_ANY_ID,
2008 .driver_data = SAA7134_BOARD_UNKNOWN, 2382 .driver_data = SAA7134_BOARD_UNKNOWN,
2009 },{ 2383 },{
2010 .vendor = PCI_VENDOR_ID_PHILIPS, 2384 .vendor = PCI_VENDOR_ID_PHILIPS,
2011 .device = PCI_DEVICE_ID_PHILIPS_SAA7135, 2385 .device = PCI_DEVICE_ID_PHILIPS_SAA7135,
2012 .subvendor = PCI_ANY_ID, 2386 .subvendor = PCI_ANY_ID,
2013 .subdevice = PCI_ANY_ID, 2387 .subdevice = PCI_ANY_ID,
2014 .driver_data = SAA7134_BOARD_UNKNOWN, 2388 .driver_data = SAA7134_BOARD_UNKNOWN,
2015 },{ 2389 },{
2016 /* --- end of list --- */ 2390 /* --- end of list --- */
@@ -2021,46 +2395,9 @@ MODULE_DEVICE_TABLE(pci, saa7134_pci_tbl);
2021/* ----------------------------------------------------------- */ 2395/* ----------------------------------------------------------- */
2022/* flyvideo tweaks */ 2396/* flyvideo tweaks */
2023 2397
2024#if 0
2025static struct {
2026 char *model;
2027 int tuner_type;
2028} fly_list[0x20] = {
2029 /* default catch ... */
2030 [ 0 ... 0x1f ] = {
2031 .model = "UNKNOWN",
2032 .tuner_type = TUNER_ABSENT,
2033 },
2034 /* ... the ones known so far */
2035 [ 0x05 ] = {
2036 .model = "PAL-BG",
2037 .tuner_type = TUNER_LG_PAL_NEW_TAPC,
2038 },
2039 [ 0x10 ] = {
2040 .model = "PAL-BG / PAL-DK",
2041 .tuner_type = TUNER_PHILIPS_PAL,
2042 },
2043 [ 0x15 ] = {
2044 .model = "NTSC",
2045 .tuner_type = TUNER_ABSENT /* FIXME */,
2046 },
2047};
2048#endif
2049 2398
2050static void board_flyvideo(struct saa7134_dev *dev) 2399static void board_flyvideo(struct saa7134_dev *dev)
2051{ 2400{
2052#if 0
2053 /* non-working attempt to detect the correct tuner type ... */
2054 u32 value;
2055 int index;
2056
2057 value = dev->gpio_value;
2058 index = (value & 0x1f00) >> 8;
2059 printk(KERN_INFO "%s: flyvideo: gpio is 0x%x [model=%s,tuner=%d]\n",
2060 dev->name, value, fly_list[index].model,
2061 fly_list[index].tuner_type);
2062 dev->tuner_type = fly_list[index].tuner_type;
2063#endif
2064 printk("%s: there are different flyvideo cards with different tuners\n" 2401 printk("%s: there are different flyvideo cards with different tuners\n"
2065 "%s: out there, you might have to use the tuner=<nr> insmod\n" 2402 "%s: out there, you might have to use the tuner=<nr> insmod\n"
2066 "%s: option to override the default value.\n", 2403 "%s: option to override the default value.\n",
@@ -2071,7 +2408,7 @@ static void board_flyvideo(struct saa7134_dev *dev)
2071 2408
2072int saa7134_board_init1(struct saa7134_dev *dev) 2409int saa7134_board_init1(struct saa7134_dev *dev)
2073{ 2410{
2074 // Always print gpio, often manufacturers encode tuner type and other info. 2411 /* Always print gpio, often manufacturers encode tuner type and other info. */
2075 saa_writel(SAA7134_GPIO_GPMODE0 >> 2, 0); 2412 saa_writel(SAA7134_GPIO_GPMODE0 >> 2, 0);
2076 dev->gpio_value = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2); 2413 dev->gpio_value = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
2077 printk(KERN_INFO "%s: board init: gpio is %x\n", dev->name, dev->gpio_value); 2414 printk(KERN_INFO "%s: board init: gpio is %x\n", dev->name, dev->gpio_value);
@@ -2082,7 +2419,7 @@ int saa7134_board_init1(struct saa7134_dev *dev)
2082 dev->has_remote = 1; 2419 dev->has_remote = 1;
2083 board_flyvideo(dev); 2420 board_flyvideo(dev);
2084 break; 2421 break;
2085 case SAA7134_BOARD_FLYTVPLATINUM_FM: 2422 case SAA7134_BOARD_FLYTVPLATINUM_FM:
2086 case SAA7134_BOARD_CINERGY400: 2423 case SAA7134_BOARD_CINERGY400:
2087 case SAA7134_BOARD_CINERGY600: 2424 case SAA7134_BOARD_CINERGY600:
2088 case SAA7134_BOARD_CINERGY600_MK3: 2425 case SAA7134_BOARD_CINERGY600_MK3:
@@ -2090,23 +2427,25 @@ int saa7134_board_init1(struct saa7134_dev *dev)
2090 case SAA7134_BOARD_ECS_TVP3XP_4CB5: 2427 case SAA7134_BOARD_ECS_TVP3XP_4CB5:
2091 case SAA7134_BOARD_MD2819: 2428 case SAA7134_BOARD_MD2819:
2092 case SAA7134_BOARD_KWORLD_VSTREAM_XPERT: 2429 case SAA7134_BOARD_KWORLD_VSTREAM_XPERT:
2430 case SAA7134_BOARD_KWORLD_XPERT:
2093 case SAA7134_BOARD_AVERMEDIA_STUDIO_305: 2431 case SAA7134_BOARD_AVERMEDIA_STUDIO_305:
2094 case SAA7134_BOARD_AVERMEDIA_305: 2432 case SAA7134_BOARD_AVERMEDIA_305:
2095 case SAA7134_BOARD_AVERMEDIA_STUDIO_307: 2433 case SAA7134_BOARD_AVERMEDIA_STUDIO_307:
2096 case SAA7134_BOARD_AVERMEDIA_307: 2434 case SAA7134_BOARD_AVERMEDIA_307:
2097 case SAA7134_BOARD_AVERMEDIA_GO_007_FM: 2435 case SAA7134_BOARD_AVERMEDIA_GO_007_FM:
2098// case SAA7134_BOARD_SABRENT_SBTTVFM: /* not finished yet */ 2436/* case SAA7134_BOARD_SABRENT_SBTTVFM: */ /* not finished yet */
2099 case SAA7134_BOARD_VIDEOMATE_TV_PVR: 2437 case SAA7134_BOARD_VIDEOMATE_TV_PVR:
2100 case SAA7134_BOARD_MANLI_MTV001: 2438 case SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII:
2101 case SAA7134_BOARD_MANLI_MTV002: 2439 case SAA7134_BOARD_MANLI_MTV001:
2440 case SAA7134_BOARD_MANLI_MTV002:
2102 case SAA7134_BOARD_AVACSSMARTTV: 2441 case SAA7134_BOARD_AVACSSMARTTV:
2103 dev->has_remote = 1; 2442 dev->has_remote = 1;
2104 break; 2443 break;
2105 case SAA7134_BOARD_MD5044: 2444 case SAA7134_BOARD_MD5044:
2106 printk("%s: seems there are two different versions of the MD5044\n" 2445 printk("%s: seems there are two different versions of the MD5044\n"
2107 "%s: (with the same ID) out there. If sound doesn't work for\n" 2446 "%s: (with the same ID) out there. If sound doesn't work for\n"
2108 "%s: you try the audio_clock_override=0x200000 insmod option.\n", 2447 "%s: you try the audio_clock_override=0x200000 insmod option.\n",
2109 dev->name,dev->name,dev->name); 2448 dev->name,dev->name,dev->name);
2110 break; 2449 break;
2111 case SAA7134_BOARD_CINERGY400_CARDBUS: 2450 case SAA7134_BOARD_CINERGY400_CARDBUS:
2112 /* power-up tuner chip */ 2451 /* power-up tuner chip */
@@ -2114,11 +2453,19 @@ int saa7134_board_init1(struct saa7134_dev *dev)
2114 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0x00040000, 0x00000000); 2453 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0x00040000, 0x00000000);
2115 msleep(1); 2454 msleep(1);
2116 break; 2455 break;
2456 case SAA7134_BOARD_FLYDVBTDUO:
2457 case SAA7134_BOARD_THYPHOON_DVBT_DUO_CARDBUS:
2458 /* turn the fan on Hac: static for the time being */
2459 saa_writeb(SAA7134_GPIO_GPMODE3, 0x08);
2460 saa_writeb(SAA7134_GPIO_GPSTATUS3, 0x06);
2461 break;
2462 case SAA7134_BOARD_AVERMEDIA_CARDBUS:
2463 /* power-up tuner chip */
2464 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, 0xffffffff, 0xffffffff);
2465 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0xffffffff, 0xffffffff);
2466 msleep(1);
2467 break;
2117 } 2468 }
2118 if (dev->has_remote)
2119 dev->irq2_mask |= (SAA7134_IRQ2_INTE_GPIO18 |
2120 SAA7134_IRQ2_INTE_GPIO18A |
2121 SAA7134_IRQ2_INTE_GPIO16 );
2122 return 0; 2469 return 0;
2123} 2470}
2124 2471
@@ -2139,10 +2486,85 @@ int saa7134_board_init2(struct saa7134_dev *dev)
2139 break; 2486 break;
2140 dev->board = board; 2487 dev->board = board;
2141 printk("%s: board type fixup: %s\n", dev->name, 2488 printk("%s: board type fixup: %s\n", dev->name,
2142 saa7134_boards[dev->board].name); 2489 saa7134_boards[dev->board].name);
2143 dev->tuner_type = saa7134_boards[dev->board].tuner_type; 2490 dev->tuner_type = saa7134_boards[dev->board].tuner_type;
2144 if (TUNER_ABSENT != dev->tuner_type) 2491
2145 saa7134_i2c_call_clients(dev,TUNER_SET_TYPE,&dev->tuner_type); 2492 if (TUNER_ABSENT != dev->tuner_type) {
2493 struct tuner_setup tun_setup;
2494
2495 tun_setup.mode_mask = T_RADIO | T_ANALOG_TV | T_DIGITAL_TV;
2496 tun_setup.type = dev->tuner_type;
2497 tun_setup.addr = ADDR_UNSET;
2498
2499 saa7134_i2c_call_clients (dev, TUNER_SET_TYPE_ADDR, &tun_setup);
2500 }
2501 break;
2502case SAA7134_BOARD_MD7134:
2503 {
2504 struct tuner_setup tun_setup;
2505 u8 subaddr;
2506 u8 data[3];
2507 int ret, tuner_t;
2508
2509 struct i2c_msg msg[] = {{.addr=0x50, .flags=0, .buf=&subaddr, .len = 1},
2510 {.addr=0x50, .flags=I2C_M_RD, .buf=data, .len = 3}};
2511 subaddr= 0x14;
2512 tuner_t = 0;
2513 ret = i2c_transfer(&dev->i2c_adap, msg, 2);
2514 if (ret != 2) {
2515 printk(KERN_ERR "EEPROM read failure\n");
2516 } else if ((data[0] != 0) && (data[0] != 0xff)) {
2517 /* old config structure */
2518 subaddr = data[0] + 2;
2519 msg[1].len = 2;
2520 i2c_transfer(&dev->i2c_adap, msg, 2);
2521 tuner_t = (data[0] << 8) + data[1];
2522 switch (tuner_t){
2523 case 0x0103:
2524 dev->tuner_type = TUNER_PHILIPS_PAL;
2525 break;
2526 case 0x010C:
2527 dev->tuner_type = TUNER_PHILIPS_FM1216ME_MK3;
2528 break;
2529 default:
2530 printk(KERN_ERR "%s Cant determine tuner type %x from EEPROM\n", dev->name, tuner_t);
2531 }
2532 } else if ((data[1] != 0) && (data[1] != 0xff)) {
2533 /* new config structure */
2534 subaddr = data[1] + 1;
2535 msg[1].len = 1;
2536 i2c_transfer(&dev->i2c_adap, msg, 2);
2537 subaddr = data[0] + 1;
2538 msg[1].len = 2;
2539 i2c_transfer(&dev->i2c_adap, msg, 2);
2540 tuner_t = (data[1] << 8) + data[0];
2541 switch (tuner_t) {
2542 case 0x0005:
2543 dev->tuner_type = TUNER_PHILIPS_FM1216ME_MK3;
2544 break;
2545 case 0x001d:
2546 dev->tuner_type = TUNER_PHILIPS_FMD1216ME_MK3;
2547 printk(KERN_INFO "%s Board has DVB-T\n", dev->name);
2548 break;
2549 default:
2550 printk(KERN_ERR "%s Cant determine tuner type %x from EEPROM\n", dev->name, tuner_t);
2551 }
2552 } else {
2553 printk(KERN_ERR "%s unexpected config structure\n", dev->name);
2554 }
2555
2556 printk(KERN_INFO "%s Tuner type is %d\n", dev->name, dev->tuner_type);
2557 if (dev->tuner_type == TUNER_PHILIPS_FMD1216ME_MK3) {
2558 dev->tda9887_conf = TDA9887_PRESENT | TDA9887_PORT1_ACTIVE | TDA9887_PORT2_ACTIVE;
2559 saa7134_i2c_call_clients(dev,TDA9887_SET_CONFIG, &dev->tda9887_conf);
2560 }
2561
2562 tun_setup.mode_mask = T_RADIO | T_ANALOG_TV | T_DIGITAL_TV;
2563 tun_setup.type = dev->tuner_type;
2564 tun_setup.addr = ADDR_UNSET;
2565
2566 saa7134_i2c_call_clients (dev, TUNER_SET_TYPE_ADDR,&tun_setup);
2567 }
2146 break; 2568 break;
2147 } 2569 }
2148 return 0; 2570 return 0;
diff --git a/drivers/media/video/saa7134/saa7134-core.c b/drivers/media/video/saa7134/saa7134-core.c
index f61ed1849a2a..1dbe61755e9f 100644
--- a/drivers/media/video/saa7134/saa7134-core.c
+++ b/drivers/media/video/saa7134/saa7134-core.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: saa7134-core.c,v 1.30 2005/05/22 19:23:39 nsh Exp $ 2 * $Id: saa7134-core.c,v 1.39 2005/07/05 17:37:35 nsh Exp $
3 * 3 *
4 * device driver for philips saa7134 based TV cards 4 * device driver for philips saa7134 based TV cards
5 * driver core 5 * driver core
@@ -183,46 +183,6 @@ void saa7134_track_gpio(struct saa7134_dev *dev, char *msg)
183 183
184/* ------------------------------------------------------------------ */ 184/* ------------------------------------------------------------------ */
185 185
186#if 0
187static char *dec1_bits[8] = {
188 "DCSTD0", "DCSCT1", "WIPA", "GLIMB",
189 "GLIMT", "SLTCA", "HLCK"
190};
191static char *dec2_bits[8] = {
192 "RDCAP", "COPRO", "COLSTR", "TYPE3",
193 NULL, "FIDT", "HLVLN", "INTL"
194};
195static char *scale1_bits[8] = {
196 "VID_A", "VBI_A", NULL, NULL, "VID_B", "VBI_B"
197};
198static char *scale2_bits[8] = {
199 "TRERR", "CFERR", "LDERR", "WASRST",
200 "FIDSCI", "FIDSCO", "D6^D5", "TASK"
201};
202
203static void dump_statusreg(struct saa7134_dev *dev, int reg,
204 char *regname, char **bits)
205{
206 int value,i;
207
208 value = saa_readb(reg);
209 printk(KERN_DEBUG "%s: %s:", dev->name, regname);
210 for (i = 7; i >= 0; i--) {
211 if (NULL == bits[i])
212 continue;
213 printk(" %s=%d", bits[i], (value & (1 << i)) ? 1 : 0);
214 }
215 printk("\n");
216}
217
218static void dump_statusregs(struct saa7134_dev *dev)
219{
220 dump_statusreg(dev,SAA7134_STATUS_VIDEO1,"dec1",dec1_bits);
221 dump_statusreg(dev,SAA7134_STATUS_VIDEO2,"dec2",dec2_bits);
222 dump_statusreg(dev,SAA7134_SCALER_STATUS0,"scale0",scale1_bits);
223 dump_statusreg(dev,SAA7134_SCALER_STATUS1,"scale1",scale2_bits);
224}
225#endif
226 186
227/* ----------------------------------------------------------- */ 187/* ----------------------------------------------------------- */
228/* delayed request_module */ 188/* delayed request_module */
@@ -616,10 +576,6 @@ static irqreturn_t saa7134_irq(int irq, void *dev_id, struct pt_regs *regs)
616 if (irq_debug) 576 if (irq_debug)
617 print_irqstatus(dev,loop,report,status); 577 print_irqstatus(dev,loop,report,status);
618 578
619#if 0
620 if (report & SAA7134_IRQ_REPORT_CONF_ERR)
621 dump_statusregs(dev);
622#endif
623 579
624 if (report & SAA7134_IRQ_REPORT_RDCAP /* _INTL */) 580 if (report & SAA7134_IRQ_REPORT_RDCAP /* _INTL */)
625 saa7134_irq_video_intl(dev); 581 saa7134_irq_video_intl(dev);
@@ -711,7 +667,6 @@ static int saa7134_hwinit1(struct saa7134_dev *dev)
711 SAA7134_MAIN_CTRL_EVFE1 | 667 SAA7134_MAIN_CTRL_EVFE1 |
712 SAA7134_MAIN_CTRL_EVFE2 | 668 SAA7134_MAIN_CTRL_EVFE2 |
713 SAA7134_MAIN_CTRL_ESFE | 669 SAA7134_MAIN_CTRL_ESFE |
714 SAA7134_MAIN_CTRL_EBADC |
715 SAA7134_MAIN_CTRL_EBDAC); 670 SAA7134_MAIN_CTRL_EBDAC);
716 671
717 /* enable peripheral devices */ 672 /* enable peripheral devices */
@@ -726,14 +681,28 @@ static int saa7134_hwinit1(struct saa7134_dev *dev)
726/* late init (with i2c + irq) */ 681/* late init (with i2c + irq) */
727static int saa7134_hwinit2(struct saa7134_dev *dev) 682static int saa7134_hwinit2(struct saa7134_dev *dev)
728{ 683{
684 unsigned int irq2_mask;
729 dprintk("hwinit2\n"); 685 dprintk("hwinit2\n");
730 686
731 saa7134_video_init2(dev); 687 saa7134_video_init2(dev);
732 saa7134_tvaudio_init2(dev); 688 saa7134_tvaudio_init2(dev);
733 689
734 /* enable IRQ's */ 690 /* enable IRQ's */
691 irq2_mask =
692 SAA7134_IRQ2_INTE_DEC3 |
693 SAA7134_IRQ2_INTE_DEC2 |
694 SAA7134_IRQ2_INTE_DEC1 |
695 SAA7134_IRQ2_INTE_DEC0 |
696 SAA7134_IRQ2_INTE_PE |
697 SAA7134_IRQ2_INTE_AR;
698
699 if (dev->has_remote)
700 irq2_mask |= (SAA7134_IRQ2_INTE_GPIO18 |
701 SAA7134_IRQ2_INTE_GPIO18A |
702 SAA7134_IRQ2_INTE_GPIO16 );
703
735 saa_writel(SAA7134_IRQ1, 0); 704 saa_writel(SAA7134_IRQ1, 0);
736 saa_writel(SAA7134_IRQ2, dev->irq2_mask); 705 saa_writel(SAA7134_IRQ2, irq2_mask);
737 706
738 return 0; 707 return 0;
739} 708}
@@ -954,13 +923,6 @@ static int __devinit saa7134_initdev(struct pci_dev *pci_dev,
954 } 923 }
955 924
956 /* initialize hardware #1 */ 925 /* initialize hardware #1 */
957 dev->irq2_mask =
958 SAA7134_IRQ2_INTE_DEC3 |
959 SAA7134_IRQ2_INTE_DEC2 |
960 SAA7134_IRQ2_INTE_DEC1 |
961 SAA7134_IRQ2_INTE_DEC0 |
962 SAA7134_IRQ2_INTE_PE |
963 SAA7134_IRQ2_INTE_AR;
964 saa7134_board_init1(dev); 926 saa7134_board_init1(dev);
965 saa7134_hwinit1(dev); 927 saa7134_hwinit1(dev);
966 928
@@ -990,6 +952,7 @@ static int __devinit saa7134_initdev(struct pci_dev *pci_dev,
990 request_module("saa6752hs"); 952 request_module("saa6752hs");
991 request_module_depend("saa7134-empress",&need_empress); 953 request_module_depend("saa7134-empress",&need_empress);
992 } 954 }
955
993 if (card_is_dvb(dev)) 956 if (card_is_dvb(dev))
994 request_module_depend("saa7134-dvb",&need_dvb); 957 request_module_depend("saa7134-dvb",&need_dvb);
995 958
@@ -1144,9 +1107,6 @@ static void __devexit saa7134_finidev(struct pci_dev *pci_dev)
1144 release_mem_region(pci_resource_start(pci_dev,0), 1107 release_mem_region(pci_resource_start(pci_dev,0),
1145 pci_resource_len(pci_dev,0)); 1108 pci_resource_len(pci_dev,0));
1146 1109
1147#if 0 /* causes some trouble when reinserting the driver ... */
1148 pci_disable_device(pci_dev);
1149#endif
1150 pci_set_drvdata(pci_dev, NULL); 1110 pci_set_drvdata(pci_dev, NULL);
1151 1111
1152 /* free memory */ 1112 /* free memory */
diff --git a/drivers/media/video/saa7134/saa7134-dvb.c b/drivers/media/video/saa7134/saa7134-dvb.c
index aa8e2cf62d55..334bc1850092 100644
--- a/drivers/media/video/saa7134/saa7134-dvb.c
+++ b/drivers/media/video/saa7134/saa7134-dvb.c
@@ -1,8 +1,11 @@
1/* 1/*
2 * $Id: saa7134-dvb.c,v 1.13 2005/06/12 04:19:19 mchehab Exp $ 2 * $Id: saa7134-dvb.c,v 1.18 2005/07/04 16:05:50 mkrufky Exp $
3 * 3 *
4 * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs] 4 * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
5 * 5 *
6 * Extended 3 / 2005 by Hartmut Hackmann to support various
7 * cards with the tda10046 DVB-T channel decoder
8 *
6 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 10 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or 11 * the Free Software Foundation; either version 2 of the License, or
@@ -27,23 +30,31 @@
27#include <linux/kthread.h> 30#include <linux/kthread.h>
28#include <linux/suspend.h> 31#include <linux/suspend.h>
29 32
33#define CONFIG_DVB_MT352 1
34#define CONFIG_DVB_TDA1004X 1
35
30#include "saa7134-reg.h" 36#include "saa7134-reg.h"
31#include "saa7134.h" 37#include "saa7134.h"
32 38
33#include "dvb-pll.h" 39#if CONFIG_DVB_MT352
34#include "mt352.h" 40# include "mt352.h"
35#include "mt352_priv.h" /* FIXME */ 41# include "mt352_priv.h" /* FIXME */
36#include "tda1004x.h" 42#endif
43#if CONFIG_DVB_TDA1004X
44# include "tda1004x.h"
45#endif
37 46
38MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]"); 47MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
39MODULE_LICENSE("GPL"); 48MODULE_LICENSE("GPL");
40 49
41static unsigned int antenna_pwr = 0; 50static unsigned int antenna_pwr = 0;
51
42module_param(antenna_pwr, int, 0444); 52module_param(antenna_pwr, int, 0444);
43MODULE_PARM_DESC(antenna_pwr,"enable antenna power (Pinnacle 300i)"); 53MODULE_PARM_DESC(antenna_pwr,"enable antenna power (Pinnacle 300i)");
44 54
45/* ------------------------------------------------------------------ */ 55/* ------------------------------------------------------------------ */
46 56
57#if CONFIG_DVB_MT352
47static int pinnacle_antenna_pwr(struct saa7134_dev *dev, int on) 58static int pinnacle_antenna_pwr(struct saa7134_dev *dev, int on)
48{ 59{
49 u32 ok; 60 u32 ok;
@@ -138,51 +149,390 @@ static struct mt352_config pinnacle_300i = {
138 .demod_init = mt352_pinnacle_init, 149 .demod_init = mt352_pinnacle_init,
139 .pll_set = mt352_pinnacle_pll_set, 150 .pll_set = mt352_pinnacle_pll_set,
140}; 151};
152#endif
141 153
142/* ------------------------------------------------------------------ */ 154/* ------------------------------------------------------------------ */
143 155
144static int medion_cardbus_init(struct dvb_frontend* fe) 156#if CONFIG_DVB_TDA1004X
157static int philips_tu1216_pll_init(struct dvb_frontend *fe)
145{ 158{
146 /* anything to do here ??? */ 159 struct saa7134_dev *dev = fe->dvb->priv;
160 static u8 tu1216_init[] = { 0x0b, 0xf5, 0x85, 0xab };
161 struct i2c_msg tuner_msg = {.addr = 0x60,.flags = 0,.buf = tu1216_init,.len = sizeof(tu1216_init) };
162
163 /* setup PLL configuration */
164 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
165 return -EIO;
166 msleep(1);
167
147 return 0; 168 return 0;
148} 169}
149 170
150static int medion_cardbus_pll_set(struct dvb_frontend* fe, 171static int philips_tu1216_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
151 struct dvb_frontend_parameters* params)
152{ 172{
153 struct saa7134_dev *dev = fe->dvb->priv; 173 struct saa7134_dev *dev = fe->dvb->priv;
154 struct v4l2_frequency f; 174 u8 tuner_buf[4];
175 struct i2c_msg tuner_msg = {.addr = 0x60,.flags = 0,.buf = tuner_buf,.len =
176 sizeof(tuner_buf) };
177 int tuner_frequency = 0;
178 u8 band, cp, filter;
179
180 /* determine charge pump */
181 tuner_frequency = params->frequency + 36166000;
182 if (tuner_frequency < 87000000)
183 return -EINVAL;
184 else if (tuner_frequency < 130000000)
185 cp = 3;
186 else if (tuner_frequency < 160000000)
187 cp = 5;
188 else if (tuner_frequency < 200000000)
189 cp = 6;
190 else if (tuner_frequency < 290000000)
191 cp = 3;
192 else if (tuner_frequency < 420000000)
193 cp = 5;
194 else if (tuner_frequency < 480000000)
195 cp = 6;
196 else if (tuner_frequency < 620000000)
197 cp = 3;
198 else if (tuner_frequency < 830000000)
199 cp = 5;
200 else if (tuner_frequency < 895000000)
201 cp = 7;
202 else
203 return -EINVAL;
204
205 /* determine band */
206 if (params->frequency < 49000000)
207 return -EINVAL;
208 else if (params->frequency < 161000000)
209 band = 1;
210 else if (params->frequency < 444000000)
211 band = 2;
212 else if (params->frequency < 861000000)
213 band = 4;
214 else
215 return -EINVAL;
216
217 /* setup PLL filter */
218 switch (params->u.ofdm.bandwidth) {
219 case BANDWIDTH_6_MHZ:
220 filter = 0;
221 break;
155 222
156 /* 223 case BANDWIDTH_7_MHZ:
157 * this instructs tuner.o to set the frequency, the call will 224 filter = 0;
158 * end up in tuner_command(), VIDIOC_S_FREQUENCY switch. 225 break;
159 * tda9887.o will see that as well. 226
227 case BANDWIDTH_8_MHZ:
228 filter = 1;
229 break;
230
231 default:
232 return -EINVAL;
233 }
234
235 /* calculate divisor
236 * ((36166000+((1000000/6)/2)) + Finput)/(1000000/6)
160 */ 237 */
161 f.tuner = 0; 238 tuner_frequency = (((params->frequency / 1000) * 6) + 217496) / 1000;
162 f.type = V4L2_TUNER_DIGITAL_TV; 239
163 f.frequency = params->frequency / 1000 * 16 / 1000; 240 /* setup tuner buffer */
164 saa7134_i2c_call_clients(dev,VIDIOC_S_FREQUENCY,&f); 241 tuner_buf[0] = (tuner_frequency >> 8) & 0x7f;
242 tuner_buf[1] = tuner_frequency & 0xff;
243 tuner_buf[2] = 0xca;
244 tuner_buf[3] = (cp << 5) | (filter << 3) | band;
245
246 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
247 return -EIO;
248
249 msleep(1);
165 return 0; 250 return 0;
166} 251}
167 252
168static int fe_request_firmware(struct dvb_frontend* fe, 253static int philips_tu1216_request_firmware(struct dvb_frontend *fe,
169 const struct firmware **fw, char* name) 254 const struct firmware **fw, char *name)
170{ 255{
171 struct saa7134_dev *dev = fe->dvb->priv; 256 struct saa7134_dev *dev = fe->dvb->priv;
172 return request_firmware(fw, name, &dev->pci->dev); 257 return request_firmware(fw, name, &dev->pci->dev);
173} 258}
174 259
260static struct tda1004x_config philips_tu1216_config = {
261
262 .demod_address = 0x8,
263 .invert = 1,
264 .invert_oclk = 1,
265 .xtal_freq = TDA10046_XTAL_4M,
266 .agc_config = TDA10046_AGC_DEFAULT,
267 .if_freq = TDA10046_FREQ_3617,
268 .pll_init = philips_tu1216_pll_init,
269 .pll_set = philips_tu1216_pll_set,
270 .pll_sleep = NULL,
271 .request_firmware = philips_tu1216_request_firmware,
272};
273
274/* ------------------------------------------------------------------ */
275
276
277static int philips_fmd1216_pll_init(struct dvb_frontend *fe)
278{
279 struct saa7134_dev *dev = fe->dvb->priv;
280 /* this message is to set up ATC and ALC */
281 static u8 fmd1216_init[] = { 0x0b, 0xdc, 0x9c, 0xa0 };
282 struct i2c_msg tuner_msg = {.addr = 0x61,.flags = 0,.buf = fmd1216_init,.len = sizeof(fmd1216_init) };
283
284 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
285 return -EIO;
286 msleep(1);
287
288 return 0;
289}
290
291static void philips_fmd1216_analog(struct dvb_frontend *fe)
292{
293 struct saa7134_dev *dev = fe->dvb->priv;
294 /* this message actually turns the tuner back to analog mode */
295 static u8 fmd1216_init[] = { 0x0b, 0xdc, 0x9c, 0x60 };
296 struct i2c_msg tuner_msg = {.addr = 0x61,.flags = 0,.buf = fmd1216_init,.len = sizeof(fmd1216_init) };
297
298 i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
299 msleep(1);
300 fmd1216_init[2] = 0x86;
301 fmd1216_init[3] = 0x54;
302 i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
303 msleep(1);
304}
305
306static int philips_fmd1216_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
307{
308 struct saa7134_dev *dev = fe->dvb->priv;
309 u8 tuner_buf[4];
310 struct i2c_msg tuner_msg = {.addr = 0x61,.flags = 0,.buf = tuner_buf,.len =
311 sizeof(tuner_buf) };
312 int tuner_frequency = 0;
313 int divider = 0;
314 u8 band, mode, cp;
315
316 /* determine charge pump */
317 tuner_frequency = params->frequency + 36130000;
318 if (tuner_frequency < 87000000)
319 return -EINVAL;
320 /* low band */
321 else if (tuner_frequency < 180000000) {
322 band = 1;
323 mode = 7;
324 cp = 0;
325 } else if (tuner_frequency < 195000000) {
326 band = 1;
327 mode = 6;
328 cp = 1;
329 /* mid band */
330 } else if (tuner_frequency < 366000000) {
331 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
332 band = 10;
333 } else {
334 band = 2;
335 }
336 mode = 7;
337 cp = 0;
338 } else if (tuner_frequency < 478000000) {
339 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
340 band = 10;
341 } else {
342 band = 2;
343 }
344 mode = 6;
345 cp = 1;
346 /* high band */
347 } else if (tuner_frequency < 662000000) {
348 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
349 band = 12;
350 } else {
351 band = 4;
352 }
353 mode = 7;
354 cp = 0;
355 } else if (tuner_frequency < 840000000) {
356 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
357 band = 12;
358 } else {
359 band = 4;
360 }
361 mode = 6;
362 cp = 1;
363 } else {
364 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
365 band = 12;
366 } else {
367 band = 4;
368 }
369 mode = 7;
370 cp = 1;
371
372 }
373 /* calculate divisor */
374 /* ((36166000 + Finput) / 166666) rounded! */
375 divider = (tuner_frequency + 83333) / 166667;
376
377 /* setup tuner buffer */
378 tuner_buf[0] = (divider >> 8) & 0x7f;
379 tuner_buf[1] = divider & 0xff;
380 tuner_buf[2] = 0x80 | (cp << 6) | (mode << 3) | 4;
381 tuner_buf[3] = 0x40 | band;
382
383 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
384 return -EIO;
385 return 0;
386}
387
388
175static struct tda1004x_config medion_cardbus = { 389static struct tda1004x_config medion_cardbus = {
176 .demod_address = 0x08, /* not sure this is correct */ 390 .demod_address = 0x08,
177 .invert = 0, 391 .invert = 1,
178 .invert_oclk = 0, 392 .invert_oclk = 0,
179 .pll_init = medion_cardbus_init, 393 .xtal_freq = TDA10046_XTAL_16M,
180 .pll_set = medion_cardbus_pll_set, 394 .agc_config = TDA10046_AGC_IFO_AUTO_NEG,
181 .request_firmware = fe_request_firmware, 395 .if_freq = TDA10046_FREQ_3613,
396 .pll_init = philips_fmd1216_pll_init,
397 .pll_set = philips_fmd1216_pll_set,
398 .pll_sleep = philips_fmd1216_analog,
399 .request_firmware = NULL,
182}; 400};
183 401
184/* ------------------------------------------------------------------ */ 402/* ------------------------------------------------------------------ */
185 403
404struct tda827x_data {
405 u32 lomax;
406 u8 spd;
407 u8 bs;
408 u8 bp;
409 u8 cp;
410 u8 gc3;
411 u8 div1p5;
412};
413
414static struct tda827x_data tda827x_dvbt[] = {
415 { .lomax = 62000000, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 1},
416 { .lomax = 66000000, .spd = 3, .bs = 3, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 1},
417 { .lomax = 76000000, .spd = 3, .bs = 1, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 0},
418 { .lomax = 84000000, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 0},
419 { .lomax = 93000000, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 1, .div1p5 = 0},
420 { .lomax = 98000000, .spd = 3, .bs = 3, .bp = 0, .cp = 0, .gc3 = 1, .div1p5 = 0},
421 { .lomax = 109000000, .spd = 3, .bs = 3, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0},
422 { .lomax = 123000000, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 1},
423 { .lomax = 133000000, .spd = 2, .bs = 3, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 1},
424 { .lomax = 151000000, .spd = 2, .bs = 1, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0},
425 { .lomax = 154000000, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0},
426 { .lomax = 181000000, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 0, .div1p5 = 0},
427 { .lomax = 185000000, .spd = 2, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
428 { .lomax = 217000000, .spd = 2, .bs = 3, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
429 { .lomax = 244000000, .spd = 1, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 1},
430 { .lomax = 265000000, .spd = 1, .bs = 3, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 1},
431 { .lomax = 302000000, .spd = 1, .bs = 1, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
432 { .lomax = 324000000, .spd = 1, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
433 { .lomax = 370000000, .spd = 1, .bs = 2, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0},
434 { .lomax = 454000000, .spd = 1, .bs = 3, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0},
435 { .lomax = 493000000, .spd = 0, .bs = 2, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 1},
436 { .lomax = 530000000, .spd = 0, .bs = 3, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 1},
437 { .lomax = 554000000, .spd = 0, .bs = 1, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0},
438 { .lomax = 604000000, .spd = 0, .bs = 1, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0},
439 { .lomax = 696000000, .spd = 0, .bs = 2, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0},
440 { .lomax = 740000000, .spd = 0, .bs = 2, .bp = 4, .cp = 1, .gc3 = 0, .div1p5 = 0},
441 { .lomax = 820000000, .spd = 0, .bs = 3, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0},
442 { .lomax = 865000000, .spd = 0, .bs = 3, .bp = 4, .cp = 1, .gc3 = 0, .div1p5 = 0},
443 { .lomax = 0, .spd = 0, .bs = 0, .bp = 0, .cp = 0, .gc3 = 0, .div1p5 = 0}
444};
445
446static int philips_tda827x_pll_init(struct dvb_frontend *fe)
447{
448 return 0;
449}
450
451static int philips_tda827x_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
452{
453 struct saa7134_dev *dev = fe->dvb->priv;
454 u8 tuner_buf[14];
455
456 struct i2c_msg tuner_msg = {.addr = 0x60,.flags = 0,.buf = tuner_buf,
457 .len = sizeof(tuner_buf) };
458 int i, tuner_freq, if_freq;
459 u32 N;
460 switch (params->u.ofdm.bandwidth) {
461 case BANDWIDTH_6_MHZ:
462 if_freq = 4000000;
463 break;
464 case BANDWIDTH_7_MHZ:
465 if_freq = 4500000;
466 break;
467 default: /* 8 MHz or Auto */
468 if_freq = 5000000;
469 break;
470 }
471 tuner_freq = params->frequency + if_freq;
472
473 i = 0;
474 while (tda827x_dvbt[i].lomax < tuner_freq) {
475 if(tda827x_dvbt[i + 1].lomax == 0)
476 break;
477 i++;
478 }
479
480 N = ((tuner_freq + 125000) / 250000) << (tda827x_dvbt[i].spd + 2);
481 tuner_buf[0] = 0;
482 tuner_buf[1] = (N>>8) | 0x40;
483 tuner_buf[2] = N & 0xff;
484 tuner_buf[3] = 0;
485 tuner_buf[4] = 0x52;
486 tuner_buf[5] = (tda827x_dvbt[i].spd << 6) + (tda827x_dvbt[i].div1p5 << 5) +
487 (tda827x_dvbt[i].bs << 3) + tda827x_dvbt[i].bp;
488 tuner_buf[6] = (tda827x_dvbt[i].gc3 << 4) + 0x8f;
489 tuner_buf[7] = 0xbf;
490 tuner_buf[8] = 0x2a;
491 tuner_buf[9] = 0x05;
492 tuner_buf[10] = 0xff;
493 tuner_buf[11] = 0x00;
494 tuner_buf[12] = 0x00;
495 tuner_buf[13] = 0x40;
496
497 tuner_msg.len = 14;
498 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
499 return -EIO;
500
501 msleep(500);
502 /* correct CP value */
503 tuner_buf[0] = 0x30;
504 tuner_buf[1] = 0x50 + tda827x_dvbt[i].cp;
505 tuner_msg.len = 2;
506 i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
507
508 return 0;
509}
510
511static void philips_tda827x_pll_sleep(struct dvb_frontend *fe)
512{
513 struct saa7134_dev *dev = fe->dvb->priv;
514 static u8 tda827x_sleep[] = { 0x30, 0xd0};
515 struct i2c_msg tuner_msg = {.addr = 0x60,.flags = 0,.buf = tda827x_sleep,
516 .len = sizeof(tda827x_sleep) };
517 i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
518}
519
520static struct tda1004x_config tda827x_lifeview_config = {
521 .demod_address = 0x08,
522 .invert = 1,
523 .invert_oclk = 0,
524 .xtal_freq = TDA10046_XTAL_16M,
525 .agc_config = TDA10046_AGC_TDA827X,
526 .if_freq = TDA10046_FREQ_045,
527 .pll_init = philips_tda827x_pll_init,
528 .pll_set = philips_tda827x_pll_set,
529 .pll_sleep = philips_tda827x_pll_sleep,
530 .request_firmware = NULL,
531};
532#endif
533
534/* ------------------------------------------------------------------ */
535
186static int dvb_init(struct saa7134_dev *dev) 536static int dvb_init(struct saa7134_dev *dev)
187{ 537{
188 /* init struct videobuf_dvb */ 538 /* init struct videobuf_dvb */
@@ -197,18 +547,31 @@ static int dvb_init(struct saa7134_dev *dev)
197 dev); 547 dev);
198 548
199 switch (dev->board) { 549 switch (dev->board) {
550#if CONFIG_DVB_MT352
200 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL: 551 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
201 printk("%s: pinnacle 300i dvb setup\n",dev->name); 552 printk("%s: pinnacle 300i dvb setup\n",dev->name);
202 dev->dvb.frontend = mt352_attach(&pinnacle_300i, 553 dev->dvb.frontend = mt352_attach(&pinnacle_300i,
203 &dev->i2c_adap); 554 &dev->i2c_adap);
204 break; 555 break;
556#endif
557#if CONFIG_DVB_TDA1004X
205 case SAA7134_BOARD_MD7134: 558 case SAA7134_BOARD_MD7134:
206 dev->dvb.frontend = tda10046_attach(&medion_cardbus, 559 dev->dvb.frontend = tda10046_attach(&medion_cardbus,
207 &dev->i2c_adap); 560 &dev->i2c_adap);
208 if (NULL == dev->dvb.frontend)
209 printk("%s: Hmm, looks like this is the old MD7134 "
210 "version without DVB-T support\n",dev->name);
211 break; 561 break;
562 case SAA7134_BOARD_PHILIPS_TOUGH:
563 dev->dvb.frontend = tda10046_attach(&philips_tu1216_config,
564 &dev->i2c_adap);
565 break;
566 case SAA7134_BOARD_FLYDVBTDUO:
567 dev->dvb.frontend = tda10046_attach(&tda827x_lifeview_config,
568 &dev->i2c_adap);
569 break;
570 case SAA7134_BOARD_THYPHOON_DVBT_DUO_CARDBUS:
571 dev->dvb.frontend = tda10046_attach(&tda827x_lifeview_config,
572 &dev->i2c_adap);
573 break;
574#endif
212 default: 575 default:
213 printk("%s: Huh? unknown DVB card?\n",dev->name); 576 printk("%s: Huh? unknown DVB card?\n",dev->name);
214 break; 577 break;
@@ -227,8 +590,6 @@ static int dvb_fini(struct saa7134_dev *dev)
227{ 590{
228 static int on = TDA9887_PRESENT | TDA9887_PORT2_INACTIVE; 591 static int on = TDA9887_PRESENT | TDA9887_PORT2_INACTIVE;
229 592
230 printk("%s: %s\n",dev->name,__FUNCTION__);
231
232 switch (dev->board) { 593 switch (dev->board) {
233 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL: 594 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
234 /* otherwise we don't detect the tuner on next insmod */ 595 /* otherwise we don't detect the tuner on next insmod */
diff --git a/drivers/media/video/saa7134/saa7134-i2c.c b/drivers/media/video/saa7134/saa7134-i2c.c
index b6f002e8421d..93dd61978541 100644
--- a/drivers/media/video/saa7134/saa7134-i2c.c
+++ b/drivers/media/video/saa7134/saa7134-i2c.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: saa7134-i2c.c,v 1.11 2005/06/12 01:36:14 mchehab Exp $ 2 * $Id: saa7134-i2c.c,v 1.19 2005/07/07 01:49:30 mkrufky Exp $
3 * 3 *
4 * device driver for philips saa7134 based TV cards 4 * device driver for philips saa7134 based TV cards
5 * i2c interface support 5 * i2c interface support
@@ -197,10 +197,6 @@ static inline int i2c_send_byte(struct saa7134_dev *dev,
197 enum i2c_status status; 197 enum i2c_status status;
198 __u32 dword; 198 __u32 dword;
199 199
200#if 0
201 i2c_set_attr(dev,attr);
202 saa_writeb(SAA7134_I2C_DATA, data);
203#else
204 /* have to write both attr + data in one 32bit word */ 200 /* have to write both attr + data in one 32bit word */
205 dword = saa_readl(SAA7134_I2C_ATTR_STATUS >> 2); 201 dword = saa_readl(SAA7134_I2C_ATTR_STATUS >> 2);
206 dword &= 0x0f; 202 dword &= 0x0f;
@@ -210,7 +206,6 @@ static inline int i2c_send_byte(struct saa7134_dev *dev,
210// dword |= 0x40 << 16; /* 400 kHz */ 206// dword |= 0x40 << 16; /* 400 kHz */
211 dword |= 0xf0 << 24; 207 dword |= 0xf0 << 24;
212 saa_writel(SAA7134_I2C_ATTR_STATUS >> 2, dword); 208 saa_writel(SAA7134_I2C_ATTR_STATUS >> 2, dword);
213#endif
214 d2printk(KERN_DEBUG "%s: i2c data => 0x%x\n",dev->name,data); 209 d2printk(KERN_DEBUG "%s: i2c data => 0x%x\n",dev->name,data);
215 210
216 if (!i2c_is_busy_wait(dev)) 211 if (!i2c_is_busy_wait(dev))
@@ -331,12 +326,44 @@ static u32 functionality(struct i2c_adapter *adap)
331 326
332static int attach_inform(struct i2c_client *client) 327static int attach_inform(struct i2c_client *client)
333{ 328{
334 struct saa7134_dev *dev = client->adapter->algo_data; 329 struct saa7134_dev *dev = client->adapter->algo_data;
335 int tuner = dev->tuner_type; 330 int tuner = dev->tuner_type;
336 int conf = dev->tda9887_conf; 331 int conf = dev->tda9887_conf;
332 struct tuner_setup tun_setup;
333
334 d1printk( "%s i2c attach [addr=0x%x,client=%s]\n",
335 client->driver->name,client->addr,i2c_clientname(client));
336
337 if (!client->driver->command)
338 return 0;
339
340 if (saa7134_boards[dev->board].radio_type != UNSET) {
341
342 tun_setup.type = saa7134_boards[dev->board].radio_type;
343 tun_setup.addr = saa7134_boards[dev->board].radio_addr;
344
345 if ((tun_setup.addr == ADDR_UNSET) || (tun_setup.addr == client->addr)) {
346 tun_setup.mode_mask = T_RADIO;
347
348 client->driver->command(client, TUNER_SET_TYPE_ADDR, &tun_setup);
349 }
350 }
351
352 if (tuner != UNSET) {
353
354 tun_setup.type = tuner;
355 tun_setup.addr = saa7134_boards[dev->board].tuner_addr;
356
357 if ((tun_setup.addr == ADDR_UNSET)||(tun_setup.addr == client->addr)) {
358
359 tun_setup.mode_mask = T_ANALOG_TV;
360
361 client->driver->command(client,TUNER_SET_TYPE_ADDR, &tun_setup);
362 }
363 }
364
365 client->driver->command(client, TDA9887_SET_CONFIG, &conf);
337 366
338 saa7134_i2c_call_clients(dev,TUNER_SET_TYPE,&tuner);
339 saa7134_i2c_call_clients(dev,TDA9887_SET_CONFIG,&conf);
340 return 0; 367 return 0;
341} 368}
342 369
diff --git a/drivers/media/video/saa7134/saa7134-input.c b/drivers/media/video/saa7134/saa7134-input.c
index aba2b9de60de..213740122fe6 100644
--- a/drivers/media/video/saa7134/saa7134-input.c
+++ b/drivers/media/video/saa7134/saa7134-input.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: saa7134-input.c,v 1.19 2005/06/07 18:02:26 nsh Exp $ 2 * $Id: saa7134-input.c,v 1.21 2005/06/22 23:37:34 nsh Exp $
3 * 3 *
4 * handle saa7134 IR remotes via linux kernel input layer. 4 * handle saa7134 IR remotes via linux kernel input layer.
5 * 5 *
@@ -68,10 +68,8 @@ static IR_KEYTAB_TYPE flyvideo_codes[IR_KEYTAB_SIZE] = {
68 [ 6 ] = KEY_AGAIN, // Recal 68 [ 6 ] = KEY_AGAIN, // Recal
69 [ 16 ] = KEY_KPENTER, // Enter 69 [ 16 ] = KEY_KPENTER, // Enter
70 70
71#if 1 /* FIXME */
72 [ 26 ] = KEY_F22, // Stereo 71 [ 26 ] = KEY_F22, // Stereo
73 [ 24 ] = KEY_EDIT, // AV Source 72 [ 24 ] = KEY_EDIT, // AV Source
74#endif
75}; 73};
76 74
77static IR_KEYTAB_TYPE cinergy_codes[IR_KEYTAB_SIZE] = { 75static IR_KEYTAB_TYPE cinergy_codes[IR_KEYTAB_SIZE] = {
@@ -172,45 +170,45 @@ static IR_KEYTAB_TYPE eztv_codes[IR_KEYTAB_SIZE] = {
172}; 170};
173 171
174static IR_KEYTAB_TYPE avacssmart_codes[IR_KEYTAB_SIZE] = { 172static IR_KEYTAB_TYPE avacssmart_codes[IR_KEYTAB_SIZE] = {
175 [ 30 ] = KEY_POWER, // power 173 [ 30 ] = KEY_POWER, // power
176 [ 28 ] = KEY_SEARCH, // scan 174 [ 28 ] = KEY_SEARCH, // scan
177 [ 7 ] = KEY_SELECT, // source 175 [ 7 ] = KEY_SELECT, // source
178 176
179 [ 22 ] = KEY_VOLUMEUP, 177 [ 22 ] = KEY_VOLUMEUP,
180 [ 20 ] = KEY_VOLUMEDOWN, 178 [ 20 ] = KEY_VOLUMEDOWN,
181 [ 31 ] = KEY_CHANNELUP, 179 [ 31 ] = KEY_CHANNELUP,
182 [ 23 ] = KEY_CHANNELDOWN, 180 [ 23 ] = KEY_CHANNELDOWN,
183 [ 24 ] = KEY_MUTE, 181 [ 24 ] = KEY_MUTE,
184 182
185 [ 2 ] = KEY_KP0, 183 [ 2 ] = KEY_KP0,
186 [ 1 ] = KEY_KP1, 184 [ 1 ] = KEY_KP1,
187 [ 11 ] = KEY_KP2, 185 [ 11 ] = KEY_KP2,
188 [ 27 ] = KEY_KP3, 186 [ 27 ] = KEY_KP3,
189 [ 5 ] = KEY_KP4, 187 [ 5 ] = KEY_KP4,
190 [ 9 ] = KEY_KP5, 188 [ 9 ] = KEY_KP5,
191 [ 21 ] = KEY_KP6, 189 [ 21 ] = KEY_KP6,
192 [ 6 ] = KEY_KP7, 190 [ 6 ] = KEY_KP7,
193 [ 10 ] = KEY_KP8, 191 [ 10 ] = KEY_KP8,
194 [ 18 ] = KEY_KP9, 192 [ 18 ] = KEY_KP9,
195 [ 16 ] = KEY_KPDOT, 193 [ 16 ] = KEY_KPDOT,
196 194
197 [ 3 ] = KEY_TUNER, // tv/fm 195 [ 3 ] = KEY_TUNER, // tv/fm
198 [ 4 ] = KEY_REWIND, // fm tuning left or function left 196 [ 4 ] = KEY_REWIND, // fm tuning left or function left
199 [ 12 ] = KEY_FORWARD, // fm tuning right or function right 197 [ 12 ] = KEY_FORWARD, // fm tuning right or function right
200 198
201 [ 0 ] = KEY_RECORD, 199 [ 0 ] = KEY_RECORD,
202 [ 8 ] = KEY_STOP, 200 [ 8 ] = KEY_STOP,
203 [ 17 ] = KEY_PLAY, 201 [ 17 ] = KEY_PLAY,
204 202
205 [ 25 ] = KEY_ZOOM, 203 [ 25 ] = KEY_ZOOM,
206 [ 14 ] = KEY_MENU, // function 204 [ 14 ] = KEY_MENU, // function
207 [ 19 ] = KEY_AGAIN, // recall 205 [ 19 ] = KEY_AGAIN, // recall
208 [ 29 ] = KEY_RESTART, // reset 206 [ 29 ] = KEY_RESTART, // reset
207 [ 26 ] = KEY_SHUFFLE, // snapshot/shuffle
209 208
210// FIXME 209// FIXME
211 [ 13 ] = KEY_F21, // mts 210 [ 13 ] = KEY_F21, // mts
212 [ 15 ] = KEY_F22, // min 211 [ 15 ] = KEY_F22, // min
213 [ 26 ] = KEY_F23, // freeze
214}; 212};
215 213
216/* Alex Hermann <gaaf@gmx.net> */ 214/* Alex Hermann <gaaf@gmx.net> */
@@ -489,13 +487,14 @@ int saa7134_input_init1(struct saa7134_dev *dev)
489 break; 487 break;
490 case SAA7134_BOARD_ECS_TVP3XP: 488 case SAA7134_BOARD_ECS_TVP3XP:
491 case SAA7134_BOARD_ECS_TVP3XP_4CB5: 489 case SAA7134_BOARD_ECS_TVP3XP_4CB5:
492 ir_codes = eztv_codes; 490 ir_codes = eztv_codes;
493 mask_keycode = 0x00017c; 491 mask_keycode = 0x00017c;
494 mask_keyup = 0x000002; 492 mask_keyup = 0x000002;
495 polling = 50; // ms 493 polling = 50; // ms
496 break; 494 break;
495 case SAA7134_BOARD_KWORLD_XPERT:
497 case SAA7134_BOARD_AVACSSMARTTV: 496 case SAA7134_BOARD_AVACSSMARTTV:
498 ir_codes = avacssmart_codes; 497 ir_codes = avacssmart_codes;
499 mask_keycode = 0x00001F; 498 mask_keycode = 0x00001F;
500 mask_keyup = 0x000020; 499 mask_keyup = 0x000020;
501 polling = 50; // ms 500 polling = 50; // ms
@@ -524,6 +523,7 @@ int saa7134_input_init1(struct saa7134_dev *dev)
524 polling = 50; // ms 523 polling = 50; // ms
525 break; 524 break;
526 case SAA7134_BOARD_VIDEOMATE_TV_PVR: 525 case SAA7134_BOARD_VIDEOMATE_TV_PVR:
526 case SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII:
527 ir_codes = videomate_tv_pvr_codes; 527 ir_codes = videomate_tv_pvr_codes;
528 mask_keycode = 0x00003F; 528 mask_keycode = 0x00003F;
529 mask_keyup = 0x400000; 529 mask_keyup = 0x400000;
diff --git a/drivers/media/video/saa7134/saa7134-oss.c b/drivers/media/video/saa7134/saa7134-oss.c
index 81732904623f..b5bede95dbf5 100644
--- a/drivers/media/video/saa7134/saa7134-oss.c
+++ b/drivers/media/video/saa7134/saa7134-oss.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: saa7134-oss.c,v 1.14 2005/05/18 22:45:16 hhackmann Exp $ 2 * $Id: saa7134-oss.c,v 1.17 2005/06/28 23:41:47 mkrufky Exp $
3 * 3 *
4 * device driver for philips saa7134 based TV cards 4 * device driver for philips saa7134 based TV cards
5 * oss dsp interface 5 * oss dsp interface
@@ -556,21 +556,28 @@ mixer_recsrc_7134(struct saa7134_dev *dev)
556static int 556static int
557mixer_recsrc_7133(struct saa7134_dev *dev) 557mixer_recsrc_7133(struct saa7134_dev *dev)
558{ 558{
559 u32 value = 0xbbbbbb; 559 u32 anabar, xbarin;
560 560
561 xbarin = 0x03; // adc
562 anabar = 0;
561 switch (dev->oss.input) { 563 switch (dev->oss.input) {
562 case TV: 564 case TV:
563 value = 0xbbbb10; /* MAIN */ 565 xbarin = 0; // Demodulator
566 anabar = 2; // DACs
564 break; 567 break;
565 case LINE1: 568 case LINE1:
566 value = 0xbbbb32; /* AUX1 */ 569 anabar = 0; // aux1, aux1
567 break; 570 break;
568 case LINE2: 571 case LINE2:
569 case LINE2_LEFT: 572 case LINE2_LEFT:
570 value = 0xbbbb54; /* AUX2 */ 573 anabar = 9; // aux2, aux2
571 break; 574 break;
572 } 575 }
573 saa_dsp_writel(dev, 0x46c >> 2, value); 576 /* output xbar always main channel */
577 saa_dsp_writel(dev, 0x46c >> 2, 0xbbbb10);
578 saa_dsp_writel(dev, 0x464 >> 2, xbarin);
579 saa_writel(0x594 >> 2, anabar);
580
574 return 0; 581 return 0;
575} 582}
576 583
diff --git a/drivers/media/video/saa7134/saa7134-ts.c b/drivers/media/video/saa7134/saa7134-ts.c
index 345eb2a8c28d..4dd9f1b23928 100644
--- a/drivers/media/video/saa7134/saa7134-ts.c
+++ b/drivers/media/video/saa7134/saa7134-ts.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: saa7134-ts.c,v 1.14 2005/02/03 10:24:33 kraxel Exp $ 2 * $Id: saa7134-ts.c,v 1.15 2005/06/14 22:48:18 hhackmann Exp $
3 * 3 *
4 * device driver for philips saa7134 based TV cards 4 * device driver for philips saa7134 based TV cards
5 * video4linux video interface 5 * video4linux video interface
@@ -221,10 +221,10 @@ void saa7134_irq_ts_done(struct saa7134_dev *dev, unsigned long status)
221 if (dev->ts_q.curr) { 221 if (dev->ts_q.curr) {
222 field = dev->ts_q.curr->vb.field; 222 field = dev->ts_q.curr->vb.field;
223 if (field == V4L2_FIELD_TOP) { 223 if (field == V4L2_FIELD_TOP) {
224 if ((status & 0x100000) != 0x000000) 224 if ((status & 0x100000) != 0x100000)
225 goto done; 225 goto done;
226 } else { 226 } else {
227 if ((status & 0x100000) != 0x100000) 227 if ((status & 0x100000) != 0x000000)
228 goto done; 228 goto done;
229 } 229 }
230 saa7134_buffer_finish(dev,&dev->ts_q,STATE_DONE); 230 saa7134_buffer_finish(dev,&dev->ts_q,STATE_DONE);
diff --git a/drivers/media/video/saa7134/saa7134-tvaudio.c b/drivers/media/video/saa7134/saa7134-tvaudio.c
index 3617e7f7a410..eeafa5a71d2b 100644
--- a/drivers/media/video/saa7134/saa7134-tvaudio.c
+++ b/drivers/media/video/saa7134/saa7134-tvaudio.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: saa7134-tvaudio.c,v 1.25 2005/06/07 19:00:38 nsh Exp $ 2 * $Id: saa7134-tvaudio.c,v 1.30 2005/06/28 23:41:47 mkrufky Exp $
3 * 3 *
4 * device driver for philips saa7134 based TV cards 4 * device driver for philips saa7134 based TV cards
5 * tv audio decoder (fm stereo, nicam, ...) 5 * tv audio decoder (fm stereo, nicam, ...)
@@ -169,7 +169,7 @@ static void tvaudio_init(struct saa7134_dev *dev)
169 int clock = saa7134_boards[dev->board].audio_clock; 169 int clock = saa7134_boards[dev->board].audio_clock;
170 170
171 if (UNSET != audio_clock_override) 171 if (UNSET != audio_clock_override)
172 clock = audio_clock_override; 172 clock = audio_clock_override;
173 173
174 /* init all audio registers */ 174 /* init all audio registers */
175 saa_writeb(SAA7134_AUDIO_PLL_CTRL, 0x00); 175 saa_writeb(SAA7134_AUDIO_PLL_CTRL, 0x00);
@@ -219,14 +219,17 @@ static void mute_input_7134(struct saa7134_dev *dev)
219 in = dev->input; 219 in = dev->input;
220 mute = (dev->ctl_mute || 220 mute = (dev->ctl_mute ||
221 (dev->automute && (&card(dev).radio) != in)); 221 (dev->automute && (&card(dev).radio) != in));
222 if (PCI_DEVICE_ID_PHILIPS_SAA7130 == dev->pci->device && 222 if (card(dev).mute.name) {
223 card(dev).mute.name) { 223 /*
224 /* 7130 - we'll mute using some unconnected audio input */ 224 * 7130 - we'll mute using some unconnected audio input
225 * 7134 - we'll probably should switch external mux with gpio
226 */
225 if (mute) 227 if (mute)
226 in = &card(dev).mute; 228 in = &card(dev).mute;
227 } 229 }
230
228 if (dev->hw_mute == mute && 231 if (dev->hw_mute == mute &&
229 dev->hw_input == in) { 232 dev->hw_input == in) {
230 dprintk("mute/input: nothing to do [mute=%d,input=%s]\n", 233 dprintk("mute/input: nothing to do [mute=%d,input=%s]\n",
231 mute,in->name); 234 mute,in->name);
232 return; 235 return;
@@ -260,6 +263,7 @@ static void mute_input_7134(struct saa7134_dev *dev)
260 /* switch gpio-connected external audio mux */ 263 /* switch gpio-connected external audio mux */
261 if (0 == card(dev).gpiomask) 264 if (0 == card(dev).gpiomask)
262 return; 265 return;
266
263 mask = card(dev).gpiomask; 267 mask = card(dev).gpiomask;
264 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, mask, mask); 268 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, mask, mask);
265 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, mask, in->gpio); 269 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, mask, in->gpio);
@@ -339,13 +343,8 @@ static int tvaudio_sleep(struct saa7134_dev *dev, int timeout)
339 set_current_state(TASK_INTERRUPTIBLE); 343 set_current_state(TASK_INTERRUPTIBLE);
340 schedule(); 344 schedule();
341 } else { 345 } else {
342#if 0
343 /* hmm, that one doesn't return on wakeup ... */
344 msleep_interruptible(timeout);
345#else
346 set_current_state(TASK_INTERRUPTIBLE); 346 set_current_state(TASK_INTERRUPTIBLE);
347 schedule_timeout(msecs_to_jiffies(timeout)); 347 schedule_timeout(msecs_to_jiffies(timeout));
348#endif
349 } 348 }
350 } 349 }
351 remove_wait_queue(&dev->thread.wq, &wait); 350 remove_wait_queue(&dev->thread.wq, &wait);
@@ -400,27 +399,10 @@ static int tvaudio_checkcarrier(struct saa7134_dev *dev, struct mainscan *scan)
400 return value; 399 return value;
401} 400}
402 401
403#if 0
404static void sifdebug_dump_regs(struct saa7134_dev *dev)
405{
406 print_regb(AUDIO_STATUS);
407 print_regb(IDENT_SIF);
408 print_regb(LEVEL_READOUT1);
409 print_regb(LEVEL_READOUT2);
410 print_regb(DCXO_IDENT_CTRL);
411 print_regb(DEMODULATOR);
412 print_regb(AGC_GAIN_SELECT);
413 print_regb(MONITOR_SELECT);
414 print_regb(FM_DEEMPHASIS);
415 print_regb(FM_DEMATRIX);
416 print_regb(SIF_SAMPLE_FREQ);
417 print_regb(ANALOG_IO_SELECT);
418}
419#endif
420 402
421static int tvaudio_getstereo(struct saa7134_dev *dev, struct saa7134_tvaudio *audio) 403static int tvaudio_getstereo(struct saa7134_dev *dev, struct saa7134_tvaudio *audio)
422{ 404{
423 __u32 idp,nicam; 405 __u32 idp, nicam, nicam_status;
424 int retval = -1; 406 int retval = -1;
425 407
426 switch (audio->mode) { 408 switch (audio->mode) {
@@ -442,18 +424,24 @@ static int tvaudio_getstereo(struct saa7134_dev *dev, struct saa7134_tvaudio *au
442 break; 424 break;
443 case TVAUDIO_NICAM_FM: 425 case TVAUDIO_NICAM_FM:
444 case TVAUDIO_NICAM_AM: 426 case TVAUDIO_NICAM_AM:
445 nicam = saa_readb(SAA7134_NICAM_STATUS); 427 nicam = saa_readb(SAA7134_AUDIO_STATUS);
446 dprintk("getstereo: nicam=0x%x\n",nicam); 428 dprintk("getstereo: nicam=0x%x\n",nicam);
447 switch (nicam & 0x0b) { 429 if (nicam & 0x1) {
448 case 0x08: 430 nicam_status = saa_readb(SAA7134_NICAM_STATUS);
449 retval = V4L2_TUNER_SUB_MONO; 431 dprintk("getstereo: nicam_status=0x%x\n", nicam_status);
450 break; 432
451 case 0x09: 433 switch (nicam_status & 0x03) {
452 retval = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2; 434 case 0x01:
453 break; 435 retval = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
454 case 0x0a: 436 break;
455 retval = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO; 437 case 0x02:
456 break; 438 retval = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO;
439 break;
440 default:
441 retval = V4L2_TUNER_SUB_MONO;
442 }
443 } else {
444 /* No nicam detected */
457 } 445 }
458 break; 446 break;
459 } 447 }
@@ -489,15 +477,15 @@ static int tvaudio_setstereo(struct saa7134_dev *dev, struct saa7134_tvaudio *au
489 break; 477 break;
490 case TVAUDIO_FM_K_STEREO: 478 case TVAUDIO_FM_K_STEREO:
491 case TVAUDIO_FM_BG_STEREO: 479 case TVAUDIO_FM_BG_STEREO:
480 case TVAUDIO_NICAM_AM:
481 case TVAUDIO_NICAM_FM:
492 dprintk("setstereo [fm] => %s\n", 482 dprintk("setstereo [fm] => %s\n",
493 name[ mode % ARRAY_SIZE(name) ]); 483 name[ mode % ARRAY_SIZE(name) ]);
494 reg = fm[ mode % ARRAY_SIZE(fm) ]; 484 reg = fm[ mode % ARRAY_SIZE(fm) ];
495 saa_writeb(SAA7134_FM_DEMATRIX, reg); 485 saa_writeb(SAA7134_FM_DEMATRIX, reg);
496 break; 486 break;
497 case TVAUDIO_FM_SAT_STEREO: 487 case TVAUDIO_FM_SAT_STEREO:
498 case TVAUDIO_NICAM_AM: 488 /* Not implemented */
499 case TVAUDIO_NICAM_FM:
500 /* FIXME */
501 break; 489 break;
502 } 490 }
503 return 0; 491 return 0;
@@ -596,7 +584,7 @@ static int tvaudio_thread(void *data)
596 /* find the exact tv audio norm */ 584 /* find the exact tv audio norm */
597 for (audio = UNSET, i = 0; i < TVAUDIO; i++) { 585 for (audio = UNSET, i = 0; i < TVAUDIO; i++) {
598 if (dev->tvnorm->id != UNSET && 586 if (dev->tvnorm->id != UNSET &&
599 !(dev->tvnorm->id & tvaudio[i].std)) 587 !(dev->tvnorm->id & tvaudio[i].std))
600 continue; 588 continue;
601 if (tvaudio[i].carr1 != carrier) 589 if (tvaudio[i].carr1 != carrier)
602 continue; 590 continue;
@@ -703,24 +691,6 @@ static inline int saa_dsp_wait_bit(struct saa7134_dev *dev, int bit)
703 return 0; 691 return 0;
704} 692}
705 693
706#if 0
707static int saa_dsp_readl(struct saa7134_dev *dev, int reg, u32 *value)
708{
709 int err;
710
711 d2printk("dsp read reg 0x%x\n", reg<<2);
712 saa_readl(reg);
713 err = saa_dsp_wait_bit(dev,SAA7135_DSP_RWSTATE_RDB);
714 if (err < 0)
715 return err;
716 *value = saa_readl(reg);
717 d2printk("dsp read => 0x%06x\n", *value & 0xffffff);
718 err = saa_dsp_wait_bit(dev,SAA7135_DSP_RWSTATE_IDA);
719 if (err < 0)
720 return err;
721 return 0;
722}
723#endif
724 694
725int saa_dsp_writel(struct saa7134_dev *dev, int reg, u32 value) 695int saa_dsp_writel(struct saa7134_dev *dev, int reg, u32 value)
726{ 696{
@@ -753,31 +723,50 @@ static int getstereo_7133(struct saa7134_dev *dev)
753static int mute_input_7133(struct saa7134_dev *dev) 723static int mute_input_7133(struct saa7134_dev *dev)
754{ 724{
755 u32 reg = 0; 725 u32 reg = 0;
726 u32 xbarin, xbarout;
756 int mask; 727 int mask;
728 struct saa7134_input *in;
757 729
730 /* Hac 0506 route OSS sound simultanously */
731 xbarin = 0x03;
758 switch (dev->input->amux) { 732 switch (dev->input->amux) {
759 case TV: 733 case TV:
760 reg = 0x02; 734 reg = 0x02;
735 xbarin = 0;
761 break; 736 break;
762 case LINE1: 737 case LINE1:
763 reg = 0x00; 738 reg = 0x00;
764 break; 739 break;
765 case LINE2: 740 case LINE2:
766 case LINE2_LEFT: 741 case LINE2_LEFT:
767 reg = 0x01; 742 reg = 0x09;
768 break; 743 break;
769 } 744 }
770 if (dev->ctl_mute) 745 saa_dsp_writel(dev, 0x464 >> 2, xbarin);
746 if (dev->ctl_mute) {
771 reg = 0x07; 747 reg = 0x07;
748 xbarout = 0xbbbbbb;
749 } else
750 xbarout = 0xbbbb10;
751 saa_dsp_writel(dev, 0x46c >> 2, xbarout);
752
772 saa_writel(0x594 >> 2, reg); 753 saa_writel(0x594 >> 2, reg);
773 754
755
774 /* switch gpio-connected external audio mux */ 756 /* switch gpio-connected external audio mux */
775 if (0 != card(dev).gpiomask) { 757 if (0 != card(dev).gpiomask) {
776 mask = card(dev).gpiomask; 758 mask = card(dev).gpiomask;
759
760 if (card(dev).mute.name && dev->ctl_mute)
761 in = &card(dev).mute;
762 else
763 in = dev->input;
764
777 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, mask, mask); 765 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, mask, mask);
778 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, mask, dev->input->gpio); 766 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, mask, in->gpio);
779 saa7134_track_gpio(dev,dev->input->name); 767 saa7134_track_gpio(dev,in->name);
780 } 768 }
769
781 return 0; 770 return 0;
782} 771}
783 772
diff --git a/drivers/media/video/saa7134/saa7134-vbi.c b/drivers/media/video/saa7134/saa7134-vbi.c
index 3c33c591cc85..29e51cad2aaf 100644
--- a/drivers/media/video/saa7134/saa7134-vbi.c
+++ b/drivers/media/video/saa7134/saa7134-vbi.c
@@ -130,13 +130,7 @@ static int buffer_prepare(struct videobuf_queue *q,
130 lines = norm->vbi_v_stop_0 - norm->vbi_v_start_0 +1; 130 lines = norm->vbi_v_stop_0 - norm->vbi_v_start_0 +1;
131 if (lines > VBI_LINE_COUNT) 131 if (lines > VBI_LINE_COUNT)
132 lines = VBI_LINE_COUNT; 132 lines = VBI_LINE_COUNT;
133#if 1
134 llength = VBI_LINE_LENGTH; 133 llength = VBI_LINE_LENGTH;
135#else
136 llength = (norm->h_stop - norm->h_start +1) * 2;
137 if (llength > VBI_LINE_LENGTH)
138 llength = VBI_LINE_LENGTH;
139#endif
140 size = lines * llength * 2; 134 size = lines * llength * 2;
141 if (0 != buf->vb.baddr && buf->vb.bsize < size) 135 if (0 != buf->vb.baddr && buf->vb.bsize < size)
142 return -EINVAL; 136 return -EINVAL;
@@ -178,13 +172,7 @@ buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size)
178 int llength,lines; 172 int llength,lines;
179 173
180 lines = dev->tvnorm->vbi_v_stop_0 - dev->tvnorm->vbi_v_start_0 +1; 174 lines = dev->tvnorm->vbi_v_stop_0 - dev->tvnorm->vbi_v_start_0 +1;
181#if 1
182 llength = VBI_LINE_LENGTH; 175 llength = VBI_LINE_LENGTH;
183#else
184 llength = (norm->h_stop - norm->h_start +1) * 2;
185 if (llength > VBI_LINE_LENGTH)
186 llength = VBI_LINE_LENGTH;
187#endif
188 *size = lines * llength * 2; 176 *size = lines * llength * 2;
189 if (0 == *count) 177 if (0 == *count)
190 *count = vbibufs; 178 *count = vbibufs;
diff --git a/drivers/media/video/saa7134/saa7134-video.c b/drivers/media/video/saa7134/saa7134-video.c
index c0a2ee520531..a4c2f751d097 100644
--- a/drivers/media/video/saa7134/saa7134-video.c
+++ b/drivers/media/video/saa7134/saa7134-video.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: saa7134-video.c,v 1.30 2005/06/07 19:00:38 nsh Exp $ 2 * $Id: saa7134-video.c,v 1.36 2005/06/28 23:41:47 mkrufky Exp $
3 * 3 *
4 * device driver for philips saa7134 based TV cards 4 * device driver for philips saa7134 based TV cards
5 * video4linux video interface 5 * video4linux video interface
@@ -274,7 +274,7 @@ static struct saa7134_tvnorm tvnorms[] = {
274 274
275 .h_start = 0, 275 .h_start = 0,
276 .h_stop = 719, 276 .h_stop = 719,
277 .video_v_start = 23, 277 .video_v_start = 23,
278 .video_v_stop = 262, 278 .video_v_stop = 262,
279 .vbi_v_start_0 = 10, 279 .vbi_v_start_0 = 10,
280 .vbi_v_stop_0 = 21, 280 .vbi_v_stop_0 = 21,
@@ -1204,7 +1204,6 @@ static int video_open(struct inode *inode, struct file *file)
1204 struct list_head *list; 1204 struct list_head *list;
1205 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 1205 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1206 int radio = 0; 1206 int radio = 0;
1207
1208 list_for_each(list,&saa7134_devlist) { 1207 list_for_each(list,&saa7134_devlist) {
1209 h = list_entry(list, struct saa7134_dev, devlist); 1208 h = list_entry(list, struct saa7134_dev, devlist);
1210 if (h->video_dev && (h->video_dev->minor == minor)) 1209 if (h->video_dev && (h->video_dev->minor == minor))
@@ -1256,12 +1255,12 @@ static int video_open(struct inode *inode, struct file *file)
1256 if (fh->radio) { 1255 if (fh->radio) {
1257 /* switch to radio mode */ 1256 /* switch to radio mode */
1258 saa7134_tvaudio_setinput(dev,&card(dev).radio); 1257 saa7134_tvaudio_setinput(dev,&card(dev).radio);
1259 saa7134_i2c_call_clients(dev,AUDC_SET_RADIO,NULL); 1258 saa7134_i2c_call_clients(dev,AUDC_SET_RADIO, NULL);
1260 } else { 1259 } else {
1261 /* switch to video/vbi mode */ 1260 /* switch to video/vbi mode */
1262 video_mux(dev,dev->ctl_input); 1261 video_mux(dev,dev->ctl_input);
1263 } 1262 }
1264 return 0; 1263 return 0;
1265} 1264}
1266 1265
1267static ssize_t 1266static ssize_t
@@ -1304,10 +1303,10 @@ video_poll(struct file *file, struct poll_table_struct *wait)
1304 } else { 1303 } else {
1305 down(&fh->cap.lock); 1304 down(&fh->cap.lock);
1306 if (UNSET == fh->cap.read_off) { 1305 if (UNSET == fh->cap.read_off) {
1307 /* need to capture a new frame */ 1306 /* need to capture a new frame */
1308 if (res_locked(fh->dev,RESOURCE_VIDEO)) { 1307 if (res_locked(fh->dev,RESOURCE_VIDEO)) {
1309 up(&fh->cap.lock); 1308 up(&fh->cap.lock);
1310 return POLLERR; 1309 return POLLERR;
1311 } 1310 }
1312 if (0 != fh->cap.ops->buf_prepare(&fh->cap,fh->cap.read_buf,fh->cap.field)) { 1311 if (0 != fh->cap.ops->buf_prepare(&fh->cap,fh->cap.read_buf,fh->cap.field)) {
1313 up(&fh->cap.lock); 1312 up(&fh->cap.lock);
@@ -1363,6 +1362,36 @@ static int video_release(struct inode *inode, struct file *file)
1363 res_free(dev,fh,RESOURCE_VBI); 1362 res_free(dev,fh,RESOURCE_VBI);
1364 } 1363 }
1365 1364
1365 /* ts-capture will not work in planar mode, so turn it off Hac: 04.05*/
1366 saa_andorb(SAA7134_OFMT_VIDEO_A, 0x1f, 0);
1367 saa_andorb(SAA7134_OFMT_VIDEO_B, 0x1f, 0);
1368 saa_andorb(SAA7134_OFMT_DATA_A, 0x1f, 0);
1369 saa_andorb(SAA7134_OFMT_DATA_B, 0x1f, 0);
1370
1371 if (dev->tuner_type == TUNER_PHILIPS_TDA8290) {
1372 u8 data[2];
1373 int ret;
1374 struct i2c_msg msg = {.addr=I2C_ADDR_TDA8290, .flags=0, .buf=data, .len = 2};
1375 data[0] = 0x21;
1376 data[1] = 0xc0;
1377 ret = i2c_transfer(&dev->i2c_adap, &msg, 1);
1378 if (ret != 1)
1379 printk(KERN_ERR "TDA8290 access failure\n");
1380 msg.addr = I2C_ADDR_TDA8275;
1381 data[0] = 0x30;
1382 data[1] = 0xd0;
1383 ret = i2c_transfer(&dev->i2c_adap, &msg, 1);
1384 if (ret != 1)
1385 printk(KERN_ERR "TDA8275 access failure\n");
1386 msg.addr = I2C_ADDR_TDA8290;
1387 data[0] = 0x21;
1388 data[1] = 0x80;
1389 i2c_transfer(&dev->i2c_adap, &msg, 1);
1390 data[0] = 0x00;
1391 data[1] = 0x02;
1392 i2c_transfer(&dev->i2c_adap, &msg, 1);
1393 }
1394
1366 /* free stuff */ 1395 /* free stuff */
1367 videobuf_mmap_free(&fh->cap); 1396 videobuf_mmap_free(&fh->cap);
1368 videobuf_mmap_free(&fh->vbi); 1397 videobuf_mmap_free(&fh->vbi);
@@ -1399,13 +1428,6 @@ static void saa7134_vbi_fmt(struct saa7134_dev *dev, struct v4l2_format *f)
1399 f->fmt.vbi.count[1] = f->fmt.vbi.count[0]; 1428 f->fmt.vbi.count[1] = f->fmt.vbi.count[0];
1400 f->fmt.vbi.flags = 0; /* VBI_UNSYNC VBI_INTERLACED */ 1429 f->fmt.vbi.flags = 0; /* VBI_UNSYNC VBI_INTERLACED */
1401 1430
1402#if 0
1403 if (V4L2_STD_PAL == norm->id) {
1404 /* FIXME */
1405 f->fmt.vbi.start[0] += 3;
1406 f->fmt.vbi.start[1] += 3*2;
1407 }
1408#endif
1409} 1431}
1410 1432
1411static int saa7134_g_fmt(struct saa7134_dev *dev, struct saa7134_fh *fh, 1433static int saa7134_g_fmt(struct saa7134_dev *dev, struct saa7134_fh *fh,
@@ -2120,8 +2142,6 @@ static int radio_do_ioctl(struct inode *inode, struct file *file,
2120 2142
2121 memset(t,0,sizeof(*t)); 2143 memset(t,0,sizeof(*t));
2122 strcpy(t->name, "Radio"); 2144 strcpy(t->name, "Radio");
2123 t->rangelow = (int)(65*16);
2124 t->rangehigh = (int)(108*16);
2125 2145
2126 saa7134_i2c_call_clients(dev, VIDIOC_G_TUNER, t); 2146 saa7134_i2c_call_clients(dev, VIDIOC_G_TUNER, t);
2127 2147
diff --git a/drivers/media/video/saa7134/saa7134.h b/drivers/media/video/saa7134/saa7134.h
index d6b1c0d4d0f9..6836c07794fc 100644
--- a/drivers/media/video/saa7134/saa7134.h
+++ b/drivers/media/video/saa7134/saa7134.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: saa7134.h,v 1.41 2005/06/07 18:02:26 nsh Exp $ 2 * $Id: saa7134.h,v 1.48 2005/07/01 08:22:24 nsh Exp $
3 * 3 *
4 * v4l2 device driver for philips saa7134 based TV cards 4 * v4l2 device driver for philips saa7134 based TV cards
5 * 5 *
@@ -46,8 +46,6 @@
46#endif 46#endif
47#define UNSET (-1U) 47#define UNSET (-1U)
48 48
49/* 2.4 / 2.5 driver compatibility stuff */
50
51/* ----------------------------------------------------------- */ 49/* ----------------------------------------------------------- */
52/* enums */ 50/* enums */
53 51
@@ -159,7 +157,7 @@ struct saa7134_format {
159#define SAA7134_BOARD_AVERMEDIA_DVD_EZMAKER 33 157#define SAA7134_BOARD_AVERMEDIA_DVD_EZMAKER 33
160#define SAA7134_BOARD_NOVAC_PRIMETV7133 34 158#define SAA7134_BOARD_NOVAC_PRIMETV7133 34
161#define SAA7134_BOARD_AVERMEDIA_STUDIO_305 35 159#define SAA7134_BOARD_AVERMEDIA_STUDIO_305 35
162#define SAA7133_BOARD_UPMOST_PURPLE_TV 36 160#define SAA7134_BOARD_UPMOST_PURPLE_TV 36
163#define SAA7134_BOARD_ITEMS_MTV005 37 161#define SAA7134_BOARD_ITEMS_MTV005 37
164#define SAA7134_BOARD_CINERGY200 38 162#define SAA7134_BOARD_CINERGY200 38
165#define SAA7134_BOARD_FLYTVPLATINUM_MINI 39 163#define SAA7134_BOARD_FLYTVPLATINUM_MINI 39
@@ -176,13 +174,17 @@ struct saa7134_format {
176#define SAA7134_BOARD_PINNACLE_300I_DVBT_PAL 50 174#define SAA7134_BOARD_PINNACLE_300I_DVBT_PAL 50
177#define SAA7134_BOARD_PROVIDEO_PV952 51 175#define SAA7134_BOARD_PROVIDEO_PV952 51
178#define SAA7134_BOARD_AVERMEDIA_305 52 176#define SAA7134_BOARD_AVERMEDIA_305 52
179#define SAA7135_BOARD_ASUSTeK_TVFM7135 53 177#define SAA7134_BOARD_ASUSTeK_TVFM7135 53
180#define SAA7134_BOARD_FLYTVPLATINUM_FM 54 178#define SAA7134_BOARD_FLYTVPLATINUM_FM 54
181#define SAA7134_BOARD_FLYDVBTDUO 55 179#define SAA7134_BOARD_FLYDVBTDUO 55
182#define SAA7134_BOARD_AVERMEDIA_307 56 180#define SAA7134_BOARD_AVERMEDIA_307 56
183#define SAA7134_BOARD_AVERMEDIA_GO_007_FM 57 181#define SAA7134_BOARD_AVERMEDIA_GO_007_FM 57
184#define SAA7134_BOARD_ADS_INSTANT_TV 58 182#define SAA7134_BOARD_ADS_INSTANT_TV 58
185#define SAA7134_BOARD_KWORLD_VSTREAM_XPERT 59 183#define SAA7134_BOARD_KWORLD_VSTREAM_XPERT 59
184#define SAA7134_BOARD_THYPHOON_DVBT_DUO_CARDBUS 60
185#define SAA7134_BOARD_PHILIPS_TOUGH 61
186#define SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII 62
187#define SAA7134_BOARD_KWORLD_XPERT 63
186 188
187#define SAA7134_MAXBOARDS 8 189#define SAA7134_MAXBOARDS 8
188#define SAA7134_INPUT_MAX 8 190#define SAA7134_INPUT_MAX 8
@@ -213,6 +215,10 @@ struct saa7134_board {
213 215
214 /* i2c chip info */ 216 /* i2c chip info */
215 unsigned int tuner_type; 217 unsigned int tuner_type;
218 unsigned int radio_type;
219 unsigned char tuner_addr;
220 unsigned char radio_addr;
221
216 unsigned int tda9887_conf; 222 unsigned int tda9887_conf;
217 223
218 /* peripheral I/O */ 224 /* peripheral I/O */
@@ -403,9 +409,12 @@ struct saa7134_dev {
403 /* config info */ 409 /* config info */
404 unsigned int board; 410 unsigned int board;
405 unsigned int tuner_type; 411 unsigned int tuner_type;
412 unsigned int radio_type;
413 unsigned char tuner_addr;
414 unsigned char radio_addr;
415
406 unsigned int tda9887_conf; 416 unsigned int tda9887_conf;
407 unsigned int gpio_value; 417 unsigned int gpio_value;
408 unsigned int irq2_mask;
409 418
410 /* i2c i/o */ 419 /* i2c i/o */
411 struct i2c_adapter i2c_adap; 420 struct i2c_adapter i2c_adap;
diff --git a/drivers/media/video/tda7432.c b/drivers/media/video/tda7432.c
index 07ba6d3ed08c..7cb1fb3e66f9 100644
--- a/drivers/media/video/tda7432.c
+++ b/drivers/media/video/tda7432.c
@@ -243,19 +243,6 @@ static int tda7432_write(struct i2c_client *client, int subaddr, int val)
243} 243}
244 244
245/* I don't think we ever actually _read_ the chip... */ 245/* I don't think we ever actually _read_ the chip... */
246#if 0
247static int tda7432_read(struct i2c_client *client)
248{
249 unsigned char buffer;
250 d2printk("tda7432: In tda7432_read\n");
251 if (1 != i2c_master_recv(client,&buffer,1)) {
252 printk(KERN_WARNING "tda7432: I/O error, trying (read)\n");
253 return -1;
254 }
255 dprintk("tda7432: Read 0x%02x\n", buffer);
256 return buffer;
257}
258#endif
259 246
260static int tda7432_set(struct i2c_client *client) 247static int tda7432_set(struct i2c_client *client)
261{ 248{
diff --git a/drivers/media/video/tda8290.c b/drivers/media/video/tda8290.c
index f59d4601cc63..a8b6a8df5109 100644
--- a/drivers/media/video/tda8290.c
+++ b/drivers/media/video/tda8290.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: tda8290.c,v 1.11 2005/06/18 06:09:06 nsh Exp $ 2 * $Id: tda8290.c,v 1.15 2005/07/08 20:21:33 mchehab Exp $
3 * 3 *
4 * i2c tv tuner chip device driver 4 * i2c tv tuner chip device driver
5 * controls the philips tda8290+75 tuner chip combo. 5 * controls the philips tda8290+75 tuner chip combo.
@@ -136,15 +136,12 @@ static int tda8290_tune(struct i2c_client *c)
136 return 0; 136 return 0;
137} 137}
138 138
139static void set_frequency(struct tuner *t, u16 ifc) 139static void set_frequency(struct tuner *t, u16 ifc, unsigned int freq)
140{ 140{
141 u32 freq;
142 u32 N; 141 u32 N;
143 142
144 if (t->mode == V4L2_TUNER_RADIO) 143 if (t->mode == V4L2_TUNER_RADIO)
145 freq = t->freq / 1000; 144 freq = freq / 1000;
146 else
147 freq = t->freq;
148 145
149 N = (((freq<<3)+ifc)&0x3fffc); 146 N = (((freq<<3)+ifc)&0x3fffc);
150 147
@@ -187,14 +184,14 @@ static void set_tv_freq(struct i2c_client *c, unsigned int freq)
187 struct tuner *t = i2c_get_clientdata(c); 184 struct tuner *t = i2c_get_clientdata(c);
188 185
189 set_audio(t); 186 set_audio(t);
190 set_frequency(t, 864); 187 set_frequency(t, 864, freq);
191 tda8290_tune(c); 188 tda8290_tune(c);
192} 189}
193 190
194static void set_radio_freq(struct i2c_client *c, unsigned int freq) 191static void set_radio_freq(struct i2c_client *c, unsigned int freq)
195{ 192{
196 struct tuner *t = i2c_get_clientdata(c); 193 struct tuner *t = i2c_get_clientdata(c);
197 set_frequency(t, 704); 194 set_frequency(t, 704, freq);
198 tda8290_tune(c); 195 tda8290_tune(c);
199} 196}
200 197
diff --git a/drivers/media/video/tda9875.c b/drivers/media/video/tda9875.c
index 97b113e070f3..566e1a5ca135 100644
--- a/drivers/media/video/tda9875.c
+++ b/drivers/media/video/tda9875.c
@@ -123,19 +123,6 @@ static int tda9875_write(struct i2c_client *client, int subaddr, unsigned char v
123 return 0; 123 return 0;
124} 124}
125 125
126#if 0
127static int tda9875_read(struct i2c_client *client)
128{
129 unsigned char buffer;
130 dprintk("In tda9875_read\n");
131 if (1 != i2c_master_recv(client,&buffer,1)) {
132 printk(KERN_WARNING "tda9875: I/O error, trying (read)\n");
133 return -1;
134 }
135 dprintk("Read 0x%02x\n", buffer);
136 return buffer;
137}
138#endif
139 126
140static int i2c_read_register(struct i2c_adapter *adap, int addr, int reg) 127static int i2c_read_register(struct i2c_adapter *adap, int addr, int reg)
141{ 128{
diff --git a/drivers/media/video/tda9887.c b/drivers/media/video/tda9887.c
index ee35562f4d1a..108c3ad7d622 100644
--- a/drivers/media/video/tda9887.c
+++ b/drivers/media/video/tda9887.c
@@ -569,15 +569,6 @@ static int tda9887_configure(struct tda9887 *t)
569 tda9887_set_config(t,buf); 569 tda9887_set_config(t,buf);
570 tda9887_set_insmod(t,buf); 570 tda9887_set_insmod(t,buf);
571 571
572#if 0
573 /* This as-is breaks some cards, must be fixed in a
574 * card-specific way, probably using TDA9887_SET_CONFIG to
575 * turn on/off port2 */
576 if (t->std & V4L2_STD_SECAM_L) {
577 /* secam fixup (FIXME: move this to tvnorms array?) */
578 buf[1] &= ~cOutputPort2Inactive;
579 }
580#endif
581 572
582 dprintk(PREFIX "writing: b=0x%02x c=0x%02x e=0x%02x\n", 573 dprintk(PREFIX "writing: b=0x%02x c=0x%02x e=0x%02x\n",
583 buf[1],buf[2],buf[3]); 574 buf[1],buf[2],buf[3]);
diff --git a/drivers/media/video/tea5767.c b/drivers/media/video/tea5767.c
index a29f08f81f63..b53c748caf2a 100644
--- a/drivers/media/video/tea5767.c
+++ b/drivers/media/video/tea5767.c
@@ -2,7 +2,7 @@
2 * For Philips TEA5767 FM Chip used on some TV Cards like Prolink Pixelview 2 * For Philips TEA5767 FM Chip used on some TV Cards like Prolink Pixelview
3 * I2C address is allways 0xC0. 3 * I2C address is allways 0xC0.
4 * 4 *
5 * $Id: tea5767.c,v 1.11 2005/06/21 15:40:33 mchehab Exp $ 5 * $Id: tea5767.c,v 1.18 2005/07/07 03:02:55 mchehab Exp $
6 * 6 *
7 * Copyright (c) 2005 Mauro Carvalho Chehab (mchehab@brturbo.com.br) 7 * Copyright (c) 2005 Mauro Carvalho Chehab (mchehab@brturbo.com.br)
8 * This code is placed under the terms of the GNU General Public License 8 * This code is placed under the terms of the GNU General Public License
@@ -11,23 +11,11 @@
11 * from their contributions on DScaler. 11 * from their contributions on DScaler.
12 */ 12 */
13 13
14#include <linux/module.h>
15#include <linux/init.h>
16#include <linux/kernel.h>
17#include <linux/sched.h>
18#include <linux/string.h>
19#include <linux/timer.h>
20#include <linux/delay.h>
21#include <linux/errno.h>
22#include <linux/slab.h>
23#include <linux/videodev.h>
24#include <linux/i2c.h> 14#include <linux/i2c.h>
25#include <linux/i2c-algo-bit.h> 15#include <linux/videodev.h>
26 16#include <linux/delay.h>
17#include <media/tuner.h>
27#include <media/tuner.h> 18#include <media/tuner.h>
28
29/* Declared at tuner-core.c */
30extern unsigned int tuner_debug;
31 19
32#define PREFIX "TEA5767 " 20#define PREFIX "TEA5767 "
33 21
@@ -38,8 +26,8 @@ extern unsigned int tuner_debug;
38 ******************************/ 26 ******************************/
39 27
40/* First register */ 28/* First register */
41#define TEA5767_MUTE 0x80 /* Mutes output */ 29#define TEA5767_MUTE 0x80 /* Mutes output */
42#define TEA5767_SEARCH 0x40 /* Activates station search */ 30#define TEA5767_SEARCH 0x40 /* Activates station search */
43/* Bits 0-5 for divider MSB */ 31/* Bits 0-5 for divider MSB */
44 32
45/* Second register */ 33/* Second register */
@@ -130,6 +118,14 @@ extern unsigned int tuner_debug;
130/* Reserved for future extensions */ 118/* Reserved for future extensions */
131#define TEA5767_RESERVED_MASK 0xff 119#define TEA5767_RESERVED_MASK 0xff
132 120
121enum tea5767_xtal_freq {
122 TEA5767_LOW_LO_32768 = 0,
123 TEA5767_HIGH_LO_32768 = 1,
124 TEA5767_LOW_LO_13MHz = 2,
125 TEA5767_HIGH_LO_13MHz = 3,
126};
127
128
133/*****************************************************************************/ 129/*****************************************************************************/
134 130
135static void set_tv_freq(struct i2c_client *c, unsigned int freq) 131static void set_tv_freq(struct i2c_client *c, unsigned int freq)
@@ -153,103 +149,112 @@ static void tea5767_status_dump(unsigned char *buffer)
153 else 149 else
154 printk(PREFIX "Tuner not at band limit\n"); 150 printk(PREFIX "Tuner not at band limit\n");
155 151
156 div=((buffer[0]&0x3f)<<8) | buffer[1]; 152 div = ((buffer[0] & 0x3f) << 8) | buffer[1];
157 153
158 switch (TEA5767_HIGH_LO_32768) { 154 switch (TEA5767_HIGH_LO_32768) {
159 case TEA5767_HIGH_LO_13MHz: 155 case TEA5767_HIGH_LO_13MHz:
160 frq = 1000*(div*50-700-225)/4; /* Freq in KHz */ 156 frq = 1000 * (div * 50 - 700 - 225) / 4; /* Freq in KHz */
161 break; 157 break;
162 case TEA5767_LOW_LO_13MHz: 158 case TEA5767_LOW_LO_13MHz:
163 frq = 1000*(div*50+700+225)/4; /* Freq in KHz */ 159 frq = 1000 * (div * 50 + 700 + 225) / 4; /* Freq in KHz */
164 break; 160 break;
165 case TEA5767_LOW_LO_32768: 161 case TEA5767_LOW_LO_32768:
166 frq = 1000*(div*32768/1000+700+225)/4; /* Freq in KHz */ 162 frq = 1000 * (div * 32768 / 1000 + 700 + 225) / 4; /* Freq in KHz */
167 break; 163 break;
168 case TEA5767_HIGH_LO_32768: 164 case TEA5767_HIGH_LO_32768:
169 default: 165 default:
170 frq = 1000*(div*32768/1000-700-225)/4; /* Freq in KHz */ 166 frq = 1000 * (div * 32768 / 1000 - 700 - 225) / 4; /* Freq in KHz */
171 break; 167 break;
172 } 168 }
173 buffer[0] = (div>>8) & 0x3f; 169 buffer[0] = (div >> 8) & 0x3f;
174 buffer[1] = div & 0xff; 170 buffer[1] = div & 0xff;
175 171
176 printk(PREFIX "Frequency %d.%03d KHz (divider = 0x%04x)\n", 172 printk(PREFIX "Frequency %d.%03d KHz (divider = 0x%04x)\n",
177 frq/1000,frq%1000,div); 173 frq / 1000, frq % 1000, div);
178 174
179 if (TEA5767_STEREO_MASK & buffer[2]) 175 if (TEA5767_STEREO_MASK & buffer[2])
180 printk(PREFIX "Stereo\n"); 176 printk(PREFIX "Stereo\n");
181 else 177 else
182 printk(PREFIX "Mono\n"); 178 printk(PREFIX "Mono\n");
183 179
184 printk(PREFIX "IF Counter = %d\n",buffer[2] & TEA5767_IF_CNTR_MASK); 180 printk(PREFIX "IF Counter = %d\n", buffer[2] & TEA5767_IF_CNTR_MASK);
185 181
186 printk(PREFIX "ADC Level = %d\n",(buffer[3] & TEA5767_ADC_LEVEL_MASK)>>4); 182 printk(PREFIX "ADC Level = %d\n",
183 (buffer[3] & TEA5767_ADC_LEVEL_MASK) >> 4);
187 184
188 printk(PREFIX "Chip ID = %d\n",(buffer[3] & TEA5767_CHIP_ID_MASK)); 185 printk(PREFIX "Chip ID = %d\n", (buffer[3] & TEA5767_CHIP_ID_MASK));
189 186
190 printk(PREFIX "Reserved = 0x%02x\n",(buffer[4] & TEA5767_RESERVED_MASK)); 187 printk(PREFIX "Reserved = 0x%02x\n",
188 (buffer[4] & TEA5767_RESERVED_MASK));
191} 189}
192 190
193/* Freq should be specifyed at 62.5 Hz */ 191/* Freq should be specifyed at 62.5 Hz */
194static void set_radio_freq(struct i2c_client *c, unsigned int frq) 192static void set_radio_freq(struct i2c_client *c, unsigned int frq)
195{ 193{
196 struct tuner *t = i2c_get_clientdata(c); 194 struct tuner *t = i2c_get_clientdata(c);
197 unsigned char buffer[5]; 195 unsigned char buffer[5];
198 unsigned div; 196 unsigned div;
199 int rc; 197 int rc;
200 198
201 if ( tuner_debug ) 199 tuner_dbg (PREFIX "radio freq counter %d\n", frq);
202 printk(PREFIX "radio freq counter %d\n",frq);
203 200
204 /* Rounds freq to next decimal value - for 62.5 KHz step */ 201 /* Rounds freq to next decimal value - for 62.5 KHz step */
205 /* frq = 20*(frq/16)+radio_frq[frq%16]; */ 202 /* frq = 20*(frq/16)+radio_frq[frq%16]; */
206 203
207 buffer[2] = TEA5767_PORT1_HIGH; 204 buffer[2] = TEA5767_PORT1_HIGH;
208 buffer[3] = TEA5767_PORT2_HIGH | TEA5767_HIGH_CUT_CTRL | TEA5767_ST_NOISE_CTL | TEA5767_JAPAN_BAND; 205 buffer[3] = TEA5767_PORT2_HIGH | TEA5767_HIGH_CUT_CTRL |
209 buffer[4]=0; 206 TEA5767_ST_NOISE_CTL | TEA5767_JAPAN_BAND;
207 buffer[4] = 0;
208
209 if (t->mode == T_STANDBY) {
210 tuner_dbg("TEA5767 set to standby mode\n");
211 buffer[3] |= TEA5767_STDBY;
212 }
210 213
211 if (t->audmode == V4L2_TUNER_MODE_MONO) { 214 if (t->audmode == V4L2_TUNER_MODE_MONO) {
212 tuner_dbg("TEA5767 set to mono\n"); 215 tuner_dbg("TEA5767 set to mono\n");
213 buffer[2] |= TEA5767_MONO; 216 buffer[2] |= TEA5767_MONO;
214 } else 217 } else {
215 tuner_dbg("TEA5767 set to stereo\n"); 218 tuner_dbg("TEA5767 set to stereo\n");
219 }
216 220
217 switch (t->type) { 221 /* Should be replaced */
222 switch (TEA5767_HIGH_LO_32768) {
218 case TEA5767_HIGH_LO_13MHz: 223 case TEA5767_HIGH_LO_13MHz:
219 tuner_dbg("TEA5767 radio HIGH LO inject xtal @ 13 MHz\n"); 224 tuner_dbg ("TEA5767 radio HIGH LO inject xtal @ 13 MHz\n");
220 buffer[2] |= TEA5767_HIGH_LO_INJECT; 225 buffer[2] |= TEA5767_HIGH_LO_INJECT;
221 buffer[4] |= TEA5767_PLLREF_ENABLE; 226 buffer[4] |= TEA5767_PLLREF_ENABLE;
222 div = (frq*4/16+700+225+25)/50; 227 div = (frq * 4 / 16 + 700 + 225 + 25) / 50;
223 break; 228 break;
224 case TEA5767_LOW_LO_13MHz: 229 case TEA5767_LOW_LO_13MHz:
225 tuner_dbg("TEA5767 radio LOW LO inject xtal @ 13 MHz\n"); 230 tuner_dbg ("TEA5767 radio LOW LO inject xtal @ 13 MHz\n");
226 231
227 buffer[4] |= TEA5767_PLLREF_ENABLE; 232 buffer[4] |= TEA5767_PLLREF_ENABLE;
228 div = (frq*4/16-700-225+25)/50; 233 div = (frq * 4 / 16 - 700 - 225 + 25) / 50;
229 break; 234 break;
230 case TEA5767_LOW_LO_32768: 235 case TEA5767_LOW_LO_32768:
231 tuner_dbg("TEA5767 radio LOW LO inject xtal @ 32,768 MHz\n"); 236 tuner_dbg ("TEA5767 radio LOW LO inject xtal @ 32,768 MHz\n");
232 buffer[3] |= TEA5767_XTAL_32768; 237 buffer[3] |= TEA5767_XTAL_32768;
233 /* const 700=4000*175 Khz - to adjust freq to right value */ 238 /* const 700=4000*175 Khz - to adjust freq to right value */
234 div = (1000*(frq*4/16-700-225)+16384)>>15; 239 div = (1000 * (frq * 4 / 16 - 700 - 225) + 16384) >> 15;
235 break; 240 break;
236 case TEA5767_HIGH_LO_32768: 241 case TEA5767_HIGH_LO_32768:
237 default: 242 default:
238 tuner_dbg("TEA5767 radio HIGH LO inject xtal @ 32,768 MHz\n"); 243 tuner_dbg ("TEA5767 radio HIGH LO inject xtal @ 32,768 MHz\n");
239 244
240 buffer[2] |= TEA5767_HIGH_LO_INJECT; 245 buffer[2] |= TEA5767_HIGH_LO_INJECT;
241 buffer[3] |= TEA5767_XTAL_32768; 246 buffer[3] |= TEA5767_XTAL_32768;
242 div = (1000*(frq*4/16+700+225)+16384)>>15; 247 div = (1000 * (frq * 4 / 16 + 700 + 225) + 16384) >> 15;
243 break; 248 break;
244 } 249 }
245 buffer[0] = (div>>8) & 0x3f; 250 buffer[0] = (div >> 8) & 0x3f;
246 buffer[1] = div & 0xff; 251 buffer[1] = div & 0xff;
247 252
248 if ( tuner_debug ) 253 if (tuner_debug)
249 tea5767_status_dump(buffer); 254 tea5767_status_dump(buffer);
250 255
251 if (5 != (rc = i2c_master_send(c,buffer,5))) 256 if (5 != (rc = i2c_master_send(c, buffer, 5)))
252 tuner_warn("i2c i/o error: rc == %d (should be 5)\n",rc); 257 tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc);
253} 258}
254 259
255static int tea5767_signal(struct i2c_client *c) 260static int tea5767_signal(struct i2c_client *c)
@@ -258,11 +263,11 @@ static int tea5767_signal(struct i2c_client *c)
258 int rc; 263 int rc;
259 struct tuner *t = i2c_get_clientdata(c); 264 struct tuner *t = i2c_get_clientdata(c);
260 265
261 memset(buffer,0,sizeof(buffer)); 266 memset(buffer, 0, sizeof(buffer));
262 if (5 != (rc = i2c_master_recv(c,buffer,5))) 267 if (5 != (rc = i2c_master_recv(c, buffer, 5)))
263 tuner_warn ( "i2c i/o error: rc == %d (should be 5)\n",rc); 268 tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc);
264 269
265 return ((buffer[3] & TEA5767_ADC_LEVEL_MASK) <<(13-4)); 270 return ((buffer[3] & TEA5767_ADC_LEVEL_MASK) << (13 - 4));
266} 271}
267 272
268static int tea5767_stereo(struct i2c_client *c) 273static int tea5767_stereo(struct i2c_client *c)
@@ -271,47 +276,46 @@ static int tea5767_stereo(struct i2c_client *c)
271 int rc; 276 int rc;
272 struct tuner *t = i2c_get_clientdata(c); 277 struct tuner *t = i2c_get_clientdata(c);
273 278
274 memset(buffer,0,sizeof(buffer)); 279 memset(buffer, 0, sizeof(buffer));
275 if (5 != (rc = i2c_master_recv(c,buffer,5))) 280 if (5 != (rc = i2c_master_recv(c, buffer, 5)))
276 tuner_warn ( "i2c i/o error: rc == %d (should be 5)\n",rc); 281 tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc);
277 282
278 rc = buffer[2] & TEA5767_STEREO_MASK; 283 rc = buffer[2] & TEA5767_STEREO_MASK;
279 284
280 if ( tuner_debug ) 285 tuner_dbg("TEA5767 radio ST GET = %02x\n", rc);
281 tuner_dbg("TEA5767 radio ST GET = %02x\n", rc);
282 286
283 return ( (buffer[2] & TEA5767_STEREO_MASK) ? V4L2_TUNER_SUB_STEREO: 0); 287 return ((buffer[2] & TEA5767_STEREO_MASK) ? V4L2_TUNER_SUB_STEREO : 0);
284} 288}
285 289
286int tea_detection(struct i2c_client *c) 290int tea5767_autodetection(struct i2c_client *c)
287{ 291{
288 unsigned char buffer[5]= { 0xff, 0xff, 0xff, 0xff, 0xff }; 292 unsigned char buffer[5] = { 0xff, 0xff, 0xff, 0xff, 0xff };
289 int rc; 293 int rc;
290 struct tuner *t = i2c_get_clientdata(c); 294 struct tuner *t = i2c_get_clientdata(c);
291 295
292 if (5 != (rc = i2c_master_recv(c,buffer,5))) { 296 if (5 != (rc = i2c_master_recv(c, buffer, 5))) {
293 tuner_warn ( "it is not a TEA5767. Received %i chars.\n",rc ); 297 tuner_warn("it is not a TEA5767. Received %i chars.\n", rc);
294 return EINVAL; 298 return EINVAL;
295 } 299 }
296 300
297 /* If all bytes are the same then it's a TV tuner and not a tea5767 chip. */ 301 /* If all bytes are the same then it's a TV tuner and not a tea5767 chip. */
298 if (buffer[0] == buffer[1] && buffer[0] == buffer[2] && 302 if (buffer[0] == buffer[1] && buffer[0] == buffer[2] &&
299 buffer[0] == buffer[3] && buffer[0] == buffer[4]) { 303 buffer[0] == buffer[3] && buffer[0] == buffer[4]) {
300 tuner_warn ( "All bytes are equal. It is not a TEA5767\n" ); 304 tuner_warn("All bytes are equal. It is not a TEA5767\n");
301 return EINVAL; 305 return EINVAL;
302 } 306 }
303 307
304 /* Status bytes: 308 /* Status bytes:
305 * Byte 4: bit 3:1 : CI (Chip Identification) == 0 309 * Byte 4: bit 3:1 : CI (Chip Identification) == 0
306 * bit 0 : internally set to 0 310 * bit 0 : internally set to 0
307 * Byte 5: bit 7:0 : == 0 311 * Byte 5: bit 7:0 : == 0
308 */ 312 */
309 313
310 if (!((buffer[3] & 0x0f) == 0x00) && (buffer[4] == 0x00)) { 314 if (!((buffer[3] & 0x0f) == 0x00) && (buffer[4] == 0x00)) {
311 tuner_warn ( "Chip ID is not zero. It is not a TEA5767\n" ); 315 tuner_warn("Chip ID is not zero. It is not a TEA5767\n");
312 return EINVAL; 316 return EINVAL;
313 } 317 }
314 tuner_warn ( "TEA5767 detected.\n" ); 318 tuner_warn("TEA5767 detected.\n");
315 return 0; 319 return 0;
316} 320}
317 321
@@ -319,16 +323,16 @@ int tea5767_tuner_init(struct i2c_client *c)
319{ 323{
320 struct tuner *t = i2c_get_clientdata(c); 324 struct tuner *t = i2c_get_clientdata(c);
321 325
322 if (tea_detection(c)==EINVAL) return EINVAL; 326 if (tea5767_autodetection(c) == EINVAL)
327 return EINVAL;
323 328
324 tuner_info("type set to %d (%s)\n", 329 tuner_info("type set to %d (%s)\n", t->type, "Philips TEA5767HN FM Radio");
325 t->type, TEA5767_TUNER_NAME); 330 strlcpy(c->name, "tea5767", sizeof(c->name));
326 strlcpy(c->name, TEA5767_TUNER_NAME, sizeof(c->name));
327 331
328 t->tv_freq = set_tv_freq; 332 t->tv_freq = set_tv_freq;
329 t->radio_freq = set_radio_freq; 333 t->radio_freq = set_radio_freq;
330 t->has_signal = tea5767_signal; 334 t->has_signal = tea5767_signal;
331 t->is_stereo = tea5767_stereo; 335 t->is_stereo = tea5767_stereo;
332 336
333 return (0); 337 return (0);
334} 338}
diff --git a/drivers/media/video/tuner-3036.c b/drivers/media/video/tuner-3036.c
index 51748c6578d1..7d825e510ffd 100644
--- a/drivers/media/video/tuner-3036.c
+++ b/drivers/media/video/tuner-3036.c
@@ -152,7 +152,7 @@ tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
152 152
153 switch (cmd) 153 switch (cmd)
154 { 154 {
155 case TUNER_SET_TVFREQ: 155 case VIDIOCSFREQ:
156 set_tv_freq(client, *iarg); 156 set_tv_freq(client, *iarg);
157 break; 157 break;
158 158
diff --git a/drivers/media/video/tuner-core.c b/drivers/media/video/tuner-core.c
index 6f6bf4a633fc..de190630babb 100644
--- a/drivers/media/video/tuner-core.c
+++ b/drivers/media/video/tuner-core.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: tuner-core.c,v 1.29 2005/06/21 15:40:33 mchehab Exp $ 2 * $Id: tuner-core.c,v 1.55 2005/07/08 13:20:33 mchehab Exp $
3 * 3 *
4 * i2c tv tuner chip device driver 4 * i2c tv tuner chip device driver
5 * core core, i.e. kernel interfaces, registering and so on 5 * core core, i.e. kernel interfaces, registering and so on
@@ -23,42 +23,36 @@
23#include <media/tuner.h> 23#include <media/tuner.h>
24#include <media/audiochip.h> 24#include <media/audiochip.h>
25 25
26/*
27 * comment line bellow to return to old behavor, where only one I2C device is supported
28 */
29
30#define UNSET (-1U) 26#define UNSET (-1U)
31 27
32/* standard i2c insmod options */ 28/* standard i2c insmod options */
33static unsigned short normal_i2c[] = { 29static unsigned short normal_i2c[] = {
34 0x4b, /* tda8290 */ 30 0x4b, /* tda8290 */
35 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 31 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
36 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 32 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
37 I2C_CLIENT_END 33 I2C_CLIENT_END
38}; 34};
35
39I2C_CLIENT_INSMOD; 36I2C_CLIENT_INSMOD;
40 37
41/* insmod options used at init time => read/only */ 38/* insmod options used at init time => read/only */
42static unsigned int addr = 0; 39static unsigned int addr = 0;
43module_param(addr, int, 0444); 40module_param(addr, int, 0444);
44 41
45/* insmod options used at runtime => read/write */ 42/* insmod options used at runtime => read/write */
46unsigned int tuner_debug = 0; 43unsigned int tuner_debug = 0;
47module_param(tuner_debug, int, 0644); 44module_param(tuner_debug, int, 0644);
48 45
49static unsigned int tv_range[2] = { 44, 958 }; 46static unsigned int tv_range[2] = { 44, 958 };
50static unsigned int radio_range[2] = { 65, 108 }; 47static unsigned int radio_range[2] = { 65, 108 };
51 48
52module_param_array(tv_range, int, NULL, 0644); 49module_param_array(tv_range, int, NULL, 0644);
53module_param_array(radio_range, int, NULL, 0644); 50module_param_array(radio_range, int, NULL, 0644);
54 51
55MODULE_DESCRIPTION("device driver for various TV and TV+FM radio tuners"); 52MODULE_DESCRIPTION("device driver for various TV and TV+FM radio tuners");
56MODULE_AUTHOR("Ralph Metzler, Gerd Knorr, Gunther Mayer"); 53MODULE_AUTHOR("Ralph Metzler, Gerd Knorr, Gunther Mayer");
57MODULE_LICENSE("GPL"); 54MODULE_LICENSE("GPL");
58 55
59static int this_adap;
60static unsigned short first_tuner, tv_tuner, radio_tuner;
61
62static struct i2c_driver driver; 56static struct i2c_driver driver;
63static struct i2c_client client_template; 57static struct i2c_client client_template;
64 58
@@ -70,18 +64,19 @@ static void set_tv_freq(struct i2c_client *c, unsigned int freq)
70 struct tuner *t = i2c_get_clientdata(c); 64 struct tuner *t = i2c_get_clientdata(c);
71 65
72 if (t->type == UNSET) { 66 if (t->type == UNSET) {
73 tuner_info("tuner type not set\n"); 67 tuner_warn ("tuner type not set\n");
74 return; 68 return;
75 } 69 }
76 if (NULL == t->tv_freq) { 70 if (NULL == t->tv_freq) {
77 tuner_info("Huh? tv_set is NULL?\n"); 71 tuner_warn ("Tuner has no way to set tv freq\n");
78 return; 72 return;
79 } 73 }
80 if (freq < tv_range[0]*16 || freq > tv_range[1]*16) { 74 if (freq < tv_range[0] * 16 || freq > tv_range[1] * 16) {
81 tuner_info("TV freq (%d.%02d) out of range (%d-%d)\n", 75 tuner_dbg ("TV freq (%d.%02d) out of range (%d-%d)\n",
82 freq/16,freq%16*100/16,tv_range[0],tv_range[1]); 76 freq / 16, freq % 16 * 100 / 16, tv_range[0],
77 tv_range[1]);
83 } 78 }
84 t->tv_freq(c,freq); 79 t->tv_freq(c, freq);
85} 80}
86 81
87static void set_radio_freq(struct i2c_client *c, unsigned int freq) 82static void set_radio_freq(struct i2c_client *c, unsigned int freq)
@@ -89,24 +84,20 @@ static void set_radio_freq(struct i2c_client *c, unsigned int freq)
89 struct tuner *t = i2c_get_clientdata(c); 84 struct tuner *t = i2c_get_clientdata(c);
90 85
91 if (t->type == UNSET) { 86 if (t->type == UNSET) {
92 tuner_info("tuner type not set\n"); 87 tuner_warn ("tuner type not set\n");
93 return; 88 return;
94 } 89 }
95 if (NULL == t->radio_freq) { 90 if (NULL == t->radio_freq) {
96 tuner_info("no radio tuning for this one, sorry.\n"); 91 tuner_warn ("tuner has no way to set radio frequency\n");
97 return; 92 return;
98 } 93 }
99 if (freq >= radio_range[0]*16000 && freq <= radio_range[1]*16000) { 94 if (freq <= radio_range[0] * 16000 || freq >= radio_range[1] * 16000) {
100 if (tuner_debug) 95 tuner_dbg ("radio freq (%d.%02d) out of range (%d-%d)\n",
101 tuner_info("radio freq step 62.5Hz (%d.%06d)\n", 96 freq / 16000, freq % 16000 * 100 / 16000,
102 freq/16000,freq%16000*1000/16); 97 radio_range[0], radio_range[1]);
103 t->radio_freq(c,freq);
104 } else {
105 tuner_info("radio freq (%d.%02d) out of range (%d-%d)\n",
106 freq/16,freq%16*100/16,
107 radio_range[0],radio_range[1]);
108 } 98 }
109 99
100 t->radio_freq(c, freq);
110 return; 101 return;
111} 102}
112 103
@@ -117,42 +108,45 @@ static void set_freq(struct i2c_client *c, unsigned long freq)
117 switch (t->mode) { 108 switch (t->mode) {
118 case V4L2_TUNER_RADIO: 109 case V4L2_TUNER_RADIO:
119 tuner_dbg("radio freq set to %lu.%02lu\n", 110 tuner_dbg("radio freq set to %lu.%02lu\n",
120 freq/16,freq%16*100/16); 111 freq / 16000, freq % 16000 * 100 / 16000);
121 set_radio_freq(c,freq); 112 set_radio_freq(c, freq);
122 break; 113 break;
123 case V4L2_TUNER_ANALOG_TV: 114 case V4L2_TUNER_ANALOG_TV:
124 case V4L2_TUNER_DIGITAL_TV: 115 case V4L2_TUNER_DIGITAL_TV:
125 tuner_dbg("tv freq set to %lu.%02lu\n", 116 tuner_dbg("tv freq set to %lu.%02lu\n",
126 freq/16,freq%16*100/16); 117 freq / 16, freq % 16 * 100 / 16);
127 set_tv_freq(c, freq); 118 set_tv_freq(c, freq);
128 break; 119 break;
129 } 120 }
130 t->freq = freq; 121 t->freq = freq;
131} 122}
132 123
133static void set_type(struct i2c_client *c, unsigned int type) 124static void set_type(struct i2c_client *c, unsigned int type,
125 unsigned int new_mode_mask)
134{ 126{
135 struct tuner *t = i2c_get_clientdata(c); 127 struct tuner *t = i2c_get_clientdata(c);
136 unsigned char buffer[4]; 128 unsigned char buffer[4];
137 129
138 /* sanity check */ 130 if (type == UNSET || type == TUNER_ABSENT) {
139 if (type == UNSET || type == TUNER_ABSENT) 131 tuner_dbg ("tuner 0x%02x: Tuner type absent\n",c->addr);
140 return; 132 return;
141 if (type >= tuner_count) 133 }
134
135 if (type >= tuner_count) {
136 tuner_warn ("tuner 0x%02x: Tuner count greater than %d\n",c->addr,tuner_count);
142 return; 137 return;
138 }
143 139
140 /* This code detects calls by card attach_inform */
144 if (NULL == t->i2c.dev.driver) { 141 if (NULL == t->i2c.dev.driver) {
145 /* not registered yet */ 142 tuner_dbg ("tuner 0x%02x: called during i2c_client register by adapter's attach_inform\n", c->addr);
146 t->type = type; 143
144 t->type=type;
147 return; 145 return;
148 } 146 }
149 if ((t->initialized) && (t->type == type))
150 /* run only once except type change Hac 04/05*/
151 return;
152
153 t->initialized = 1;
154 147
155 t->type = type; 148 t->type = type;
149
156 switch (t->type) { 150 switch (t->type) {
157 case TUNER_MT2032: 151 case TUNER_MT2032:
158 microtune_init(c); 152 microtune_init(c);
@@ -161,136 +155,194 @@ static void set_type(struct i2c_client *c, unsigned int type)
161 tda8290_init(c); 155 tda8290_init(c);
162 break; 156 break;
163 case TUNER_TEA5767: 157 case TUNER_TEA5767:
164 if (tea5767_tuner_init(c)==EINVAL) t->type=TUNER_ABSENT; 158 if (tea5767_tuner_init(c) == EINVAL) {
159 t->type = TUNER_ABSENT;
160 t->mode_mask = T_UNINITIALIZED;
161 return;
162 }
163 t->mode_mask = T_RADIO;
165 break; 164 break;
166 case TUNER_PHILIPS_FMD1216ME_MK3: 165 case TUNER_PHILIPS_FMD1216ME_MK3:
167 buffer[0] = 0x0b; 166 buffer[0] = 0x0b;
168 buffer[1] = 0xdc; 167 buffer[1] = 0xdc;
169 buffer[2] = 0x9c; 168 buffer[2] = 0x9c;
170 buffer[3] = 0x60; 169 buffer[3] = 0x60;
171 i2c_master_send(c,buffer,4); 170 i2c_master_send(c, buffer, 4);
172 mdelay(1); 171 mdelay(1);
173 buffer[2] = 0x86; 172 buffer[2] = 0x86;
174 buffer[3] = 0x54; 173 buffer[3] = 0x54;
175 i2c_master_send(c,buffer,4); 174 i2c_master_send(c, buffer, 4);
176 default_tuner_init(c); 175 default_tuner_init(c);
177 break; 176 break;
178 default: 177 default:
179 /* TEA5767 autodetection code */
180 if (tea5767_tuner_init(c)!=EINVAL) {
181 t->type = TUNER_TEA5767;
182 if (first_tuner == 0x60)
183 first_tuner++;
184 break;
185 }
186
187 default_tuner_init(c); 178 default_tuner_init(c);
188 break; 179 break;
189 } 180 }
190 tuner_dbg ("I2C addr 0x%02x with type %d\n",c->addr<<1,type); 181
182 if (t->mode_mask == T_UNINITIALIZED)
183 t->mode_mask = new_mode_mask;
184
185 set_freq(c, t->freq);
186 tuner_dbg("%s %s I2C addr 0x%02x with type %d used for 0x%02x\n",
187 c->adapter->name, c->driver->name, c->addr << 1, type,
188 t->mode_mask);
191} 189}
192 190
193#define CHECK_ADDR(tp,cmd,tun) if (client->addr!=tp) { \ 191/*
194 return 0; } else if (tuner_debug) \ 192 * This function apply tuner config to tuner specified
195 tuner_info ("Cmd %s accepted to "tun"\n",cmd); 193 * by tun_setup structure. I addr is unset, then admin status
196#define CHECK_MODE(cmd) if (t->mode == V4L2_TUNER_RADIO) { \ 194 * and tun addr status is more precise then current status,
197 CHECK_ADDR(radio_tuner,cmd,"radio") } else \ 195 * it's applied. Otherwise status and type are applied only to
198 { CHECK_ADDR(tv_tuner,cmd,"TV"); } 196 * tuner with exactly the same addr.
197*/
198
199static void set_addr(struct i2c_client *c, struct tuner_setup *tun_setup)
200{
201 struct tuner *t = i2c_get_clientdata(c);
202
203 if (tun_setup->addr == ADDR_UNSET) {
204 if (t->mode_mask & tun_setup->mode_mask)
205 set_type(c, tun_setup->type, tun_setup->mode_mask);
206 } else if (tun_setup->addr == c->addr) {
207 set_type(c, tun_setup->type, tun_setup->mode_mask);
208 }
209}
199 210
200static void set_addr(struct i2c_client *c, struct tuner_addr *tun_addr) 211static inline int check_mode(struct tuner *t, char *cmd)
201{ 212{
202 /* ADDR_UNSET defaults to first available tuner */ 213 if (1 << t->mode & t->mode_mask) {
203 if ( tun_addr->addr == ADDR_UNSET ) { 214 switch (t->mode) {
204 if (first_tuner != c->addr)
205 return;
206 switch (tun_addr->v4l2_tuner) {
207 case V4L2_TUNER_RADIO: 215 case V4L2_TUNER_RADIO:
208 radio_tuner=c->addr; 216 tuner_dbg("Cmd %s accepted for radio\n", cmd);
209 break; 217 break;
210 default: 218 case V4L2_TUNER_ANALOG_TV:
211 tv_tuner=c->addr; 219 tuner_dbg("Cmd %s accepted for analog TV\n", cmd);
220 break;
221 case V4L2_TUNER_DIGITAL_TV:
222 tuner_dbg("Cmd %s accepted for digital TV\n", cmd);
212 break; 223 break;
213 } 224 }
214 } else { 225 return 0;
215 /* Sets tuner to its configured value */
216 switch (tun_addr->v4l2_tuner) {
217 case V4L2_TUNER_RADIO:
218 radio_tuner=tun_addr->addr;
219 if ( tun_addr->addr == c->addr ) set_type(c,tun_addr->type);
220 return;
221 default:
222 tv_tuner=tun_addr->addr;
223 if ( tun_addr->addr == c->addr ) set_type(c,tun_addr->type);
224 return;
225 }
226 } 226 }
227 set_type(c,tun_addr->type); 227 return EINVAL;
228} 228}
229 229
230static char pal[] = "-"; 230static char pal[] = "-";
231module_param_string(pal, pal, sizeof(pal), 0644); 231module_param_string(pal, pal, sizeof(pal), 0644);
232static char secam[] = "-";
233module_param_string(secam, secam, sizeof(secam), 0644);
232 234
235/* get more precise norm info from insmod option */
233static int tuner_fixup_std(struct tuner *t) 236static int tuner_fixup_std(struct tuner *t)
234{ 237{
235 if ((t->std & V4L2_STD_PAL) == V4L2_STD_PAL) { 238 if ((t->std & V4L2_STD_PAL) == V4L2_STD_PAL) {
236 /* get more precise norm info from insmod option */
237 switch (pal[0]) { 239 switch (pal[0]) {
238 case 'b': 240 case 'b':
239 case 'B': 241 case 'B':
240 case 'g': 242 case 'g':
241 case 'G': 243 case 'G':
242 tuner_dbg("insmod fixup: PAL => PAL-BG\n"); 244 tuner_dbg ("insmod fixup: PAL => PAL-BG\n");
243 t->std = V4L2_STD_PAL_BG; 245 t->std = V4L2_STD_PAL_BG;
244 break; 246 break;
245 case 'i': 247 case 'i':
246 case 'I': 248 case 'I':
247 tuner_dbg("insmod fixup: PAL => PAL-I\n"); 249 tuner_dbg ("insmod fixup: PAL => PAL-I\n");
248 t->std = V4L2_STD_PAL_I; 250 t->std = V4L2_STD_PAL_I;
249 break; 251 break;
250 case 'd': 252 case 'd':
251 case 'D': 253 case 'D':
252 case 'k': 254 case 'k':
253 case 'K': 255 case 'K':
254 tuner_dbg("insmod fixup: PAL => PAL-DK\n"); 256 tuner_dbg ("insmod fixup: PAL => PAL-DK\n");
255 t->std = V4L2_STD_PAL_DK; 257 t->std = V4L2_STD_PAL_DK;
256 break; 258 break;
259 case 'M':
260 case 'm':
261 tuner_dbg ("insmod fixup: PAL => PAL-M\n");
262 t->std = V4L2_STD_PAL_M;
263 break;
264 case 'N':
265 case 'n':
266 tuner_dbg ("insmod fixup: PAL => PAL-N\n");
267 t->std = V4L2_STD_PAL_N;
268 break;
257 } 269 }
258 } 270 }
271 if ((t->std & V4L2_STD_SECAM) == V4L2_STD_SECAM) {
272 switch (secam[0]) {
273 case 'd':
274 case 'D':
275 case 'k':
276 case 'K':
277 tuner_dbg ("insmod fixup: SECAM => SECAM-DK\n");
278 t->std = V4L2_STD_SECAM_DK;
279 break;
280 case 'l':
281 case 'L':
282 tuner_dbg ("insmod fixup: SECAM => SECAM-L\n");
283 t->std = V4L2_STD_SECAM_L;
284 break;
285 }
286 }
287
259 return 0; 288 return 0;
260} 289}
261 290
262/* ---------------------------------------------------------------------- */ 291/* ---------------------------------------------------------------------- */
263 292
293/* static var Used only in tuner_attach and tuner_probe */
294static unsigned default_mode_mask;
295
296/* During client attach, set_type is called by adapter's attach_inform callback.
297 set_type must then be completed by tuner_attach.
298 */
264static int tuner_attach(struct i2c_adapter *adap, int addr, int kind) 299static int tuner_attach(struct i2c_adapter *adap, int addr, int kind)
265{ 300{
266 struct tuner *t; 301 struct tuner *t;
267 302
268 /* by default, first I2C card is both tv and radio tuner */ 303 client_template.adapter = adap;
269 if (this_adap == 0) { 304 client_template.addr = addr;
270 first_tuner = addr;
271 tv_tuner = addr;
272 radio_tuner = addr;
273 }
274 this_adap++;
275
276 client_template.adapter = adap;
277 client_template.addr = addr;
278 305
279 t = kmalloc(sizeof(struct tuner),GFP_KERNEL); 306 t = kmalloc(sizeof(struct tuner), GFP_KERNEL);
280 if (NULL == t) 307 if (NULL == t)
281 return -ENOMEM; 308 return -ENOMEM;
282 memset(t,0,sizeof(struct tuner)); 309 memset(t, 0, sizeof(struct tuner));
283 memcpy(&t->i2c,&client_template,sizeof(struct i2c_client)); 310 memcpy(&t->i2c, &client_template, sizeof(struct i2c_client));
284 i2c_set_clientdata(&t->i2c, t); 311 i2c_set_clientdata(&t->i2c, t);
285 t->type = UNSET; 312 t->type = UNSET;
286 t->radio_if2 = 10700*1000; /* 10.7MHz - FM radio */ 313 t->radio_if2 = 10700 * 1000; /* 10.7MHz - FM radio */
287 t->audmode = V4L2_TUNER_MODE_STEREO; 314 t->audmode = V4L2_TUNER_MODE_STEREO;
315 t->mode_mask = T_UNINITIALIZED;
316
317
318 tuner_info("chip found @ 0x%x (%s)\n", addr << 1, adap->name);
319
320 /* TEA5767 autodetection code - only for addr = 0xc0 */
321 if (addr == 0x60) {
322 if (tea5767_autodetection(&t->i2c) != EINVAL) {
323 t->type = TUNER_TEA5767;
324 t->mode_mask = T_RADIO;
325 t->mode = T_STANDBY;
326 t->freq = 87.5 * 16; /* Sets freq to FM range */
327 default_mode_mask &= ~T_RADIO;
328
329 i2c_attach_client (&t->i2c);
330 set_type(&t->i2c,t->type, t->mode_mask);
331 return 0;
332 }
333 }
288 334
289 i2c_attach_client(&t->i2c); 335 /* Initializes only the first adapter found */
290 tuner_info("chip found @ 0x%x (%s)\n", 336 if (default_mode_mask != T_UNINITIALIZED) {
291 addr << 1, adap->name); 337 tuner_dbg ("Setting mode_mask to 0x%02x\n", default_mode_mask);
338 t->mode_mask = default_mode_mask;
339 t->freq = 400 * 16; /* Sets freq to VHF High */
340 default_mode_mask = T_UNINITIALIZED;
341 }
292 342
293 set_type(&t->i2c, t->type); 343 /* Should be just before return */
344 i2c_attach_client (&t->i2c);
345 set_type (&t->i2c,t->type, t->mode_mask);
294 return 0; 346 return 0;
295} 347}
296 348
@@ -300,11 +352,8 @@ static int tuner_probe(struct i2c_adapter *adap)
300 normal_i2c[0] = addr; 352 normal_i2c[0] = addr;
301 normal_i2c[1] = I2C_CLIENT_END; 353 normal_i2c[1] = I2C_CLIENT_END;
302 } 354 }
303 this_adap = 0;
304 355
305 first_tuner = 0; 356 default_mode_mask = T_RADIO | T_ANALOG_TV | T_DIGITAL_TV;
306 tv_tuner = 0;
307 radio_tuner = 0;
308 357
309 if (adap->class & I2C_CLASS_TV_ANALOG) 358 if (adap->class & I2C_CLASS_TV_ANALOG)
310 return i2c_probe(adap, &addr_data, tuner_attach); 359 return i2c_probe(adap, &addr_data, tuner_attach);
@@ -316,9 +365,10 @@ static int tuner_detach(struct i2c_client *client)
316 struct tuner *t = i2c_get_clientdata(client); 365 struct tuner *t = i2c_get_clientdata(client);
317 int err; 366 int err;
318 367
319 err=i2c_detach_client(&t->i2c); 368 err = i2c_detach_client(&t->i2c);
320 if (err) { 369 if (err) {
321 tuner_warn ("Client deregistration failed, client not detached.\n"); 370 tuner_warn
371 ("Client deregistration failed, client not detached.\n");
322 return err; 372 return err;
323 } 373 }
324 374
@@ -326,37 +376,65 @@ static int tuner_detach(struct i2c_client *client)
326 return 0; 376 return 0;
327} 377}
328 378
329#define SWITCH_V4L2 if (!t->using_v4l2 && tuner_debug) \ 379/*
330 tuner_info("switching to v4l2\n"); \ 380 * Switch tuner to other mode. If tuner support both tv and radio,
331 t->using_v4l2 = 1; 381 * set another frequency to some value (This is needed for some pal
332#define CHECK_V4L2 if (t->using_v4l2) { if (tuner_debug) \ 382 * tuners to avoid locking). Otherwise, just put second tuner in
333 tuner_info("ignore v4l1 call\n"); \ 383 * standby mode.
334 return 0; } 384 */
385
386static inline int set_mode(struct i2c_client *client, struct tuner *t, int mode, char *cmd)
387{
388 if (mode != t->mode) {
389
390 t->mode = mode;
391 if (check_mode(t, cmd) == EINVAL) {
392 t->mode = T_STANDBY;
393 if (V4L2_TUNER_RADIO == mode) {
394 set_tv_freq(client, 400 * 16);
395 } else {
396 set_radio_freq(client, 87.5 * 16000);
397 }
398 return EINVAL;
399 }
400 }
401 return 0;
402}
403
404#define switch_v4l2() if (!t->using_v4l2) \
405 tuner_dbg("switching to v4l2\n"); \
406 t->using_v4l2 = 1;
407
408static inline int check_v4l2(struct tuner *t)
409{
410 if (t->using_v4l2) {
411 tuner_dbg ("ignore v4l1 call\n");
412 return EINVAL;
413 }
414 return 0;
415}
335 416
336static int 417static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
337tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
338{ 418{
339 struct tuner *t = i2c_get_clientdata(client); 419 struct tuner *t = i2c_get_clientdata(client);
340 unsigned int *iarg = (int*)arg; 420 unsigned int *iarg = (int *)arg;
341 421
342 switch (cmd) { 422 switch (cmd) {
343 /* --- configuration --- */ 423 /* --- configuration --- */
344 case TUNER_SET_TYPE:
345 set_type(client,*iarg);
346 break;
347 case TUNER_SET_TYPE_ADDR: 424 case TUNER_SET_TYPE_ADDR:
348 set_addr(client,(struct tuner_addr *)arg); 425 tuner_dbg ("Calling set_type_addr for type=%d, addr=0x%02x, mode=0x%02x\n",
426 ((struct tuner_setup *)arg)->type,
427 ((struct tuner_setup *)arg)->addr,
428 ((struct tuner_setup *)arg)->mode_mask);
429
430 set_addr(client, (struct tuner_setup *)arg);
349 break; 431 break;
350 case AUDC_SET_RADIO: 432 case AUDC_SET_RADIO:
351 t->mode = V4L2_TUNER_RADIO; 433 set_mode(client,t,V4L2_TUNER_RADIO, "AUDC_SET_RADIO");
352 CHECK_ADDR(tv_tuner,"AUDC_SET_RADIO","TV");
353
354 if (V4L2_TUNER_RADIO != t->mode) {
355 set_tv_freq(client,400 * 16);
356 }
357 break; 434 break;
358 case AUDC_CONFIG_PINNACLE: 435 case AUDC_CONFIG_PINNACLE:
359 CHECK_ADDR(tv_tuner,"AUDC_CONFIG_PINNACLE","TV"); 436 if (check_mode(t, "AUDC_CONFIG_PINNACLE") == EINVAL)
437 return 0;
360 switch (*iarg) { 438 switch (*iarg) {
361 case 2: 439 case 2:
362 tuner_dbg("pinnacle pal\n"); 440 tuner_dbg("pinnacle pal\n");
@@ -368,219 +446,238 @@ tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
368 break; 446 break;
369 } 447 }
370 break; 448 break;
449 case TDA9887_SET_CONFIG:
450 break;
371 /* --- v4l ioctls --- */ 451 /* --- v4l ioctls --- */
372 /* take care: bttv does userspace copying, we'll get a 452 /* take care: bttv does userspace copying, we'll get a
373 kernel pointer here... */ 453 kernel pointer here... */
374 case VIDIOCSCHAN: 454 case VIDIOCSCHAN:
375 { 455 {
376 static const v4l2_std_id map[] = { 456 static const v4l2_std_id map[] = {
377 [ VIDEO_MODE_PAL ] = V4L2_STD_PAL, 457 [VIDEO_MODE_PAL] = V4L2_STD_PAL,
378 [ VIDEO_MODE_NTSC ] = V4L2_STD_NTSC_M, 458 [VIDEO_MODE_NTSC] = V4L2_STD_NTSC_M,
379 [ VIDEO_MODE_SECAM ] = V4L2_STD_SECAM, 459 [VIDEO_MODE_SECAM] = V4L2_STD_SECAM,
380 [ 4 /* bttv */ ] = V4L2_STD_PAL_M, 460 [4 /* bttv */ ] = V4L2_STD_PAL_M,
381 [ 5 /* bttv */ ] = V4L2_STD_PAL_N, 461 [5 /* bttv */ ] = V4L2_STD_PAL_N,
382 [ 6 /* bttv */ ] = V4L2_STD_NTSC_M_JP, 462 [6 /* bttv */ ] = V4L2_STD_NTSC_M_JP,
383 }; 463 };
384 struct video_channel *vc = arg; 464 struct video_channel *vc = arg;
385 465
386 CHECK_V4L2; 466 if (check_v4l2(t) == EINVAL)
387 t->mode = V4L2_TUNER_ANALOG_TV; 467 return 0;
388 CHECK_ADDR(tv_tuner,"VIDIOCSCHAN","TV"); 468
389 469 if (set_mode(client,t,V4L2_TUNER_ANALOG_TV, "VIDIOCSCHAN")==EINVAL)
390 if (vc->norm < ARRAY_SIZE(map)) 470 return 0;
391 t->std = map[vc->norm]; 471
392 tuner_fixup_std(t); 472 if (vc->norm < ARRAY_SIZE(map))
393 if (t->freq) 473 t->std = map[vc->norm];
394 set_tv_freq(client,t->freq); 474 tuner_fixup_std(t);
395 return 0; 475 if (t->freq)
396 } 476 set_tv_freq(client, t->freq);
477 return 0;
478 }
397 case VIDIOCSFREQ: 479 case VIDIOCSFREQ:
398 { 480 {
399 unsigned long *v = arg; 481 unsigned long *v = arg;
400 482
401 CHECK_MODE("VIDIOCSFREQ"); 483 if (check_mode(t, "VIDIOCSFREQ") == EINVAL)
402 CHECK_V4L2; 484 return 0;
403 set_freq(client,*v); 485 if (check_v4l2(t) == EINVAL)
404 return 0; 486 return 0;
405 } 487
488 set_freq(client, *v);
489 return 0;
490 }
406 case VIDIOCGTUNER: 491 case VIDIOCGTUNER:
407 { 492 {
408 struct video_tuner *vt = arg; 493 struct video_tuner *vt = arg;
409 494
410 CHECK_ADDR(radio_tuner,"VIDIOCGTUNER","radio"); 495 if (check_mode(t, "VIDIOCGTUNER") == EINVAL)
411 CHECK_V4L2; 496 return 0;
412 if (V4L2_TUNER_RADIO == t->mode) { 497 if (check_v4l2(t) == EINVAL)
413 if (t->has_signal) 498 return 0;
414 vt->signal = t->has_signal(client); 499
415 if (t->is_stereo) { 500 if (V4L2_TUNER_RADIO == t->mode) {
416 if (t->is_stereo(client)) 501 if (t->has_signal)
417 vt->flags |= VIDEO_TUNER_STEREO_ON; 502 vt->signal = t->has_signal(client);
418 else 503 if (t->is_stereo) {
419 vt->flags &= ~VIDEO_TUNER_STEREO_ON; 504 if (t->is_stereo(client))
420 } 505 vt->flags |=
421 vt->flags |= V4L2_TUNER_CAP_LOW; /* Allow freqs at 62.5 Hz */ 506 VIDEO_TUNER_STEREO_ON;
507 else
508 vt->flags &=
509 ~VIDEO_TUNER_STEREO_ON;
510 }
511 vt->flags |= VIDEO_TUNER_LOW; /* Allow freqs at 62.5 Hz */
422 512
423 vt->rangelow = radio_range[0] * 16000; 513 vt->rangelow = radio_range[0] * 16000;
424 vt->rangehigh = radio_range[1] * 16000; 514 vt->rangehigh = radio_range[1] * 16000;
425 515
426 } else { 516 } else {
427 vt->rangelow = tv_range[0] * 16; 517 vt->rangelow = tv_range[0] * 16;
428 vt->rangehigh = tv_range[1] * 16; 518 vt->rangehigh = tv_range[1] * 16;
429 } 519 }
430 520
431 return 0; 521 return 0;
432 } 522 }
433 case VIDIOCGAUDIO: 523 case VIDIOCGAUDIO:
434 { 524 {
435 struct video_audio *va = arg; 525 struct video_audio *va = arg;
436 526
437 CHECK_ADDR(radio_tuner,"VIDIOCGAUDIO","radio"); 527 if (check_mode(t, "VIDIOCGAUDIO") == EINVAL)
438 CHECK_V4L2; 528 return 0;
439 if (V4L2_TUNER_RADIO == t->mode && t->is_stereo) 529 if (check_v4l2(t) == EINVAL)
440 va->mode = t->is_stereo(client) 530 return 0;
441 ? VIDEO_SOUND_STEREO 531
442 : VIDEO_SOUND_MONO; 532 if (V4L2_TUNER_RADIO == t->mode && t->is_stereo)
443 return 0; 533 va->mode = t->is_stereo(client)
444 } 534 ? VIDEO_SOUND_STEREO : VIDEO_SOUND_MONO;
535 return 0;
536 }
445 537
446 case VIDIOC_S_STD: 538 case VIDIOC_S_STD:
447 { 539 {
448 v4l2_std_id *id = arg; 540 v4l2_std_id *id = arg;
449 541
450 SWITCH_V4L2; 542 if (set_mode (client, t, V4L2_TUNER_ANALOG_TV, "VIDIOC_S_STD")
451 t->mode = V4L2_TUNER_ANALOG_TV; 543 == EINVAL)
452 CHECK_ADDR(tv_tuner,"VIDIOC_S_STD","TV"); 544 return 0;
453 545
454 t->std = *id; 546 switch_v4l2();
455 tuner_fixup_std(t); 547
456 if (t->freq) 548 t->std = *id;
457 set_freq(client,t->freq); 549 tuner_fixup_std(t);
458 break; 550 if (t->freq)
459 } 551 set_freq(client, t->freq);
552 break;
553 }
460 case VIDIOC_S_FREQUENCY: 554 case VIDIOC_S_FREQUENCY:
461 { 555 {
462 struct v4l2_frequency *f = arg; 556 struct v4l2_frequency *f = arg;
463 557
464 CHECK_MODE("VIDIOC_S_FREQUENCY"); 558 t->freq = f->frequency;
465 SWITCH_V4L2; 559 switch_v4l2();
466 if (V4L2_TUNER_RADIO == f->type && 560 if (V4L2_TUNER_RADIO == f->type &&
467 V4L2_TUNER_RADIO != t->mode) 561 V4L2_TUNER_RADIO != t->mode) {
468 set_tv_freq(client,400*16); 562 if (set_mode (client, t, f->type, "VIDIOC_S_FREQUENCY")
469 t->mode = f->type; 563 == EINVAL)
470 set_freq(client,f->frequency); 564 return 0;
471 break; 565 }
472 } 566 set_freq(client,t->freq);
473 case VIDIOC_G_FREQUENCY:
474 {
475 struct v4l2_frequency *f = arg;
476 567
477 CHECK_MODE("VIDIOC_G_FREQUENCY"); 568 break;
478 SWITCH_V4L2; 569 }
479 f->type = t->mode; 570 case VIDIOC_G_FREQUENCY:
480 f->frequency = t->freq; 571 {
481 break; 572 struct v4l2_frequency *f = arg;
482 } 573
574 if (check_mode(t, "VIDIOC_G_FREQUENCY") == EINVAL)
575 return 0;
576 switch_v4l2();
577 f->type = t->mode;
578 f->frequency = t->freq;
579 break;
580 }
483 case VIDIOC_G_TUNER: 581 case VIDIOC_G_TUNER:
484 { 582 {
485 struct v4l2_tuner *tuner = arg; 583 struct v4l2_tuner *tuner = arg;
486 584
487 CHECK_MODE("VIDIOC_G_TUNER"); 585 if (check_mode(t, "VIDIOC_G_TUNER") == EINVAL)
488 SWITCH_V4L2; 586 return 0;
489 if (V4L2_TUNER_RADIO == t->mode) { 587 switch_v4l2();
490 if (t->has_signal) 588
491 tuner -> signal = t->has_signal(client); 589 if (V4L2_TUNER_RADIO == t->mode) {
492 if (t->is_stereo) { 590
493 if (t->is_stereo(client)) { 591 if (t->has_signal)
494 tuner -> rxsubchans = V4L2_TUNER_SUB_STEREO | V4L2_TUNER_SUB_MONO; 592 tuner->signal = t->has_signal(client);
495 } else { 593
496 tuner -> rxsubchans = V4L2_TUNER_SUB_MONO; 594 if (t->is_stereo) {
595 if (t->is_stereo(client)) {
596 tuner->rxsubchans =
597 V4L2_TUNER_SUB_STEREO |
598 V4L2_TUNER_SUB_MONO;
599 } else {
600 tuner->rxsubchans =
601 V4L2_TUNER_SUB_MONO;
602 }
497 } 603 }
604
605 tuner->capability |=
606 V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO;
607
608 tuner->audmode = t->audmode;
609
610 tuner->rangelow = radio_range[0] * 16000;
611 tuner->rangehigh = radio_range[1] * 16000;
612 } else {
613 tuner->rangelow = tv_range[0] * 16;
614 tuner->rangehigh = tv_range[1] * 16;
498 } 615 }
499 tuner->capability |= V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO; 616 break;
500 tuner->audmode = t->audmode; 617 }
501 618 case VIDIOC_S_TUNER:
502 tuner->rangelow = radio_range[0] * 16000; 619 {
503 tuner->rangehigh = radio_range[1] * 16000; 620 struct v4l2_tuner *tuner = arg;
504 } else { 621
505 tuner->rangelow = tv_range[0] * 16; 622 if (check_mode(t, "VIDIOC_S_TUNER") == EINVAL)
506 tuner->rangehigh = tv_range[1] * 16; 623 return 0;
624
625 switch_v4l2();
626
627 if (V4L2_TUNER_RADIO == t->mode) {
628 t->audmode = tuner->audmode;
629 set_radio_freq(client, t->freq);
630 }
631 break;
507 } 632 }
508 break;
509 }
510 case VIDIOC_S_TUNER: /* Allow changing radio range and audio mode */
511 {
512 struct v4l2_tuner *tuner = arg;
513
514 CHECK_ADDR(radio_tuner,"VIDIOC_S_TUNER","radio");
515 SWITCH_V4L2;
516
517 /* To switch the audio mode, applications initialize the
518 index and audmode fields and the reserved array and
519 call the VIDIOC_S_TUNER ioctl. */
520 /* rxsubchannels: V4L2_TUNER_MODE_MONO, V4L2_TUNER_MODE_STEREO,
521 V4L2_TUNER_MODE_LANG1, V4L2_TUNER_MODE_LANG2,
522 V4L2_TUNER_MODE_SAP */
523
524 if (tuner->audmode == V4L2_TUNER_MODE_MONO)
525 t->audmode = V4L2_TUNER_MODE_MONO;
526 else
527 t->audmode = V4L2_TUNER_MODE_STEREO;
528
529 set_radio_freq(client, t->freq);
530 break;
531 }
532 case TDA9887_SET_CONFIG: /* Nothing to do on tuner-core */
533 break;
534 default: 633 default:
535 tuner_dbg ("Unimplemented IOCTL 0x%08x called to tuner.\n", cmd); 634 tuner_dbg("Unimplemented IOCTL 0x%08x called to tuner.\n", cmd);
536 /* nothing */
537 break; 635 break;
538 } 636 }
539 637
540 return 0; 638 return 0;
541} 639}
542 640
543static int tuner_suspend(struct device * dev, u32 state, u32 level) 641static int tuner_suspend(struct device *dev, u32 state, u32 level)
544{ 642{
545 struct i2c_client *c = container_of(dev, struct i2c_client, dev); 643 struct i2c_client *c = container_of (dev, struct i2c_client, dev);
546 struct tuner *t = i2c_get_clientdata(c); 644 struct tuner *t = i2c_get_clientdata (c);
547 645
548 tuner_dbg("suspend\n"); 646 tuner_dbg ("suspend\n");
549 /* FIXME: power down ??? */ 647 /* FIXME: power down ??? */
550 return 0; 648 return 0;
551} 649}
552 650
553static int tuner_resume(struct device * dev, u32 level) 651static int tuner_resume(struct device *dev, u32 level)
554{ 652{
555 struct i2c_client *c = container_of(dev, struct i2c_client, dev); 653 struct i2c_client *c = container_of (dev, struct i2c_client, dev);
556 struct tuner *t = i2c_get_clientdata(c); 654 struct tuner *t = i2c_get_clientdata (c);
557 655
558 tuner_dbg("resume\n"); 656 tuner_dbg ("resume\n");
559 if (t->freq) 657 if (t->freq)
560 set_freq(c,t->freq); 658 set_freq(c, t->freq);
561 return 0; 659 return 0;
562} 660}
563 661
564/* ----------------------------------------------------------------------- */ 662/* ----------------------------------------------------------------------- */
565 663
566static struct i2c_driver driver = { 664static struct i2c_driver driver = {
567 .owner = THIS_MODULE, 665 .owner = THIS_MODULE,
568 .name = "tuner", 666 .name = "tuner",
569 .id = I2C_DRIVERID_TUNER, 667 .id = I2C_DRIVERID_TUNER,
570 .flags = I2C_DF_NOTIFY, 668 .flags = I2C_DF_NOTIFY,
571 .attach_adapter = tuner_probe, 669 .attach_adapter = tuner_probe,
572 .detach_client = tuner_detach, 670 .detach_client = tuner_detach,
573 .command = tuner_command, 671 .command = tuner_command,
574 .driver = { 672 .driver = {
575 .suspend = tuner_suspend, 673 .suspend = tuner_suspend,
576 .resume = tuner_resume, 674 .resume = tuner_resume,
577 }, 675 },
578}; 676};
579static struct i2c_client client_template = 677static struct i2c_client client_template = {
580{
581 I2C_DEVNAME("(tuner unset)"), 678 I2C_DEVNAME("(tuner unset)"),
582 .flags = I2C_CLIENT_ALLOW_USE, 679 .flags = I2C_CLIENT_ALLOW_USE,
583 .driver = &driver, 680 .driver = &driver,
584}; 681};
585 682
586static int __init tuner_init_module(void) 683static int __init tuner_init_module(void)
diff --git a/drivers/media/video/tuner-simple.c b/drivers/media/video/tuner-simple.c
index c39ed6226ee0..a3f8e83f5314 100644
--- a/drivers/media/video/tuner-simple.c
+++ b/drivers/media/video/tuner-simple.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: tuner-simple.c,v 1.31 2005/06/21 16:02:25 mkrufky Exp $ 2 * $Id: tuner-simple.c,v 1.39 2005/07/07 01:49:30 mkrufky Exp $
3 * 3 *
4 * i2c tv tuner chip device driver 4 * i2c tv tuner chip device driver
5 * controls all those simple 4-control-bytes style tuners. 5 * controls all those simple 4-control-bytes style tuners.
@@ -54,6 +54,27 @@
54#define PHILIPS_MF_SET_PAL_L 0x03 // France 54#define PHILIPS_MF_SET_PAL_L 0x03 // France
55#define PHILIPS_MF_SET_PAL_L2 0x02 // L' 55#define PHILIPS_MF_SET_PAL_L2 0x02 // L'
56 56
57/* Control byte */
58
59#define TUNER_RATIO_MASK 0x06 /* Bit cb1:cb2 */
60#define TUNER_RATIO_SELECT_50 0x00
61#define TUNER_RATIO_SELECT_32 0x02
62#define TUNER_RATIO_SELECT_166 0x04
63#define TUNER_RATIO_SELECT_62 0x06
64
65#define TUNER_CHARGE_PUMP 0x40 /* Bit cb6 */
66
67/* Status byte */
68
69#define TUNER_POR 0x80
70#define TUNER_FL 0x40
71#define TUNER_MODE 0x38
72#define TUNER_AFC 0x07
73#define TUNER_SIGNAL 0x07
74#define TUNER_STEREO 0x10
75
76#define TUNER_PLL_LOCKED 0x40
77#define TUNER_STEREO_MK3 0x04
57 78
58/* ---------------------------------------------------------------------- */ 79/* ---------------------------------------------------------------------- */
59 80
@@ -211,21 +232,17 @@ static struct tunertype tuners[] = {
211 16*160.00,16*442.00,0x01,0x02,0x04,0xce,623 }, 232 16*160.00,16*442.00,0x01,0x02,0x04,0xce,623 },
212 { "Philips FQ1236A MK4", Philips, NTSC, 233 { "Philips FQ1236A MK4", Philips, NTSC,
213 16*160.00,16*442.00,0x01,0x02,0x04,0x8e,732 }, 234 16*160.00,16*442.00,0x01,0x02,0x04,0x8e,732 },
214 235 { "Ymec TVision TVF-8531MF/8831MF/8731MF", Philips, NTSC,
215 /* Should work for TVF8531MF, TVF8831MF, TVF8731MF */
216 { "Ymec TVision TVF-8531MF", Philips, NTSC,
217 16*160.00,16*454.00,0xa0,0x90,0x30,0x8e,732}, 236 16*160.00,16*454.00,0xa0,0x90,0x30,0x8e,732},
218 { "Ymec TVision TVF-5533MF", Philips, NTSC, 237 { "Ymec TVision TVF-5533MF", Philips, NTSC,
219 16*160.00,16*454.00,0x01,0x02,0x04,0x8e,732}, 238 16*160.00,16*454.00,0x01,0x02,0x04,0x8e,732},
239
220 { "Thomson DDT 7611 (ATSC/NTSC)", THOMSON, ATSC, 240 { "Thomson DDT 7611 (ATSC/NTSC)", THOMSON, ATSC,
221 16*157.25,16*454.00,0x39,0x3a,0x3c,0x8e,732}, 241 16*157.25,16*454.00,0x39,0x3a,0x3c,0x8e,732},
222 /* Should work for TNF9533-D/IF, TNF9533-B/DF */ 242 { "Tena TNF9533-D/IF/TNF9533-B/DF", Philips, PAL,
223 { "Tena TNF9533-D/IF", Philips, PAL,
224 16*160.25,16*464.25,0x01,0x02,0x04,0x8e,623}, 243 16*160.25,16*464.25,0x01,0x02,0x04,0x8e,623},
225 244 { "Philips TEA5767HN FM Radio", Philips, RADIO,
226 /* This entry is for TEA5767 FM radio only chip used on several boards w/TV tuner */ 245 /* see tea5767.c for details */},
227 { TEA5767_TUNER_NAME, Philips, RADIO,
228 -1, -1, 0, 0, 0, TEA5767_LOW_LO_32768,0},
229 { "Philips FMD1216ME MK3 Hybrid Tuner", Philips, PAL, 246 { "Philips FMD1216ME MK3 Hybrid Tuner", Philips, PAL,
230 16*160.00,16*442.00,0x51,0x52,0x54,0x86,623 }, 247 16*160.00,16*442.00,0x51,0x52,0x54,0x86,623 },
231}; 248};
@@ -244,15 +261,6 @@ static int tuner_getstatus(struct i2c_client *c)
244 return byte; 261 return byte;
245} 262}
246 263
247#define TUNER_POR 0x80
248#define TUNER_FL 0x40
249#define TUNER_MODE 0x38
250#define TUNER_AFC 0x07
251
252#define TUNER_STEREO 0x10 /* radio mode */
253#define TUNER_STEREO_MK3 0x04 /* radio mode */
254#define TUNER_SIGNAL 0x07 /* radio mode */
255
256static int tuner_signal(struct i2c_client *c) 264static int tuner_signal(struct i2c_client *c)
257{ 265{
258 return (tuner_getstatus(c) & TUNER_SIGNAL) << 13; 266 return (tuner_getstatus(c) & TUNER_SIGNAL) << 13;
@@ -278,22 +286,6 @@ static int tuner_stereo(struct i2c_client *c)
278 return stereo; 286 return stereo;
279} 287}
280 288
281#if 0 /* unused */
282static int tuner_islocked (struct i2c_client *c)
283{
284 return (tuner_getstatus (c) & TUNER_FL);
285}
286
287static int tuner_afcstatus (struct i2c_client *c)
288{
289 return (tuner_getstatus (c) & TUNER_AFC) - 2;
290}
291
292static int tuner_mode (struct i2c_client *c)
293{
294 return (tuner_getstatus (c) & TUNER_MODE) >> 3;
295}
296#endif
297 289
298/* ---------------------------------------------------------------------- */ 290/* ---------------------------------------------------------------------- */
299 291
@@ -376,7 +368,7 @@ static void default_set_tv_freq(struct i2c_client *c, unsigned int freq)
376 368
377 case TUNER_MICROTUNE_4042FI5: 369 case TUNER_MICROTUNE_4042FI5:
378 /* Set the charge pump for fast tuning */ 370 /* Set the charge pump for fast tuning */
379 tun->config |= 0x40; 371 tun->config |= TUNER_CHARGE_PUMP;
380 break; 372 break;
381 } 373 }
382 374
@@ -425,14 +417,13 @@ static void default_set_tv_freq(struct i2c_client *c, unsigned int freq)
425 tuner_warn("i2c i/o read error: rc == %d (should be 1)\n",rc); 417 tuner_warn("i2c i/o read error: rc == %d (should be 1)\n",rc);
426 break; 418 break;
427 } 419 }
428 /* bit 6 is PLL locked indicator */ 420 if (status_byte & TUNER_PLL_LOCKED)
429 if (status_byte & 0x40)
430 break; 421 break;
431 udelay(10); 422 udelay(10);
432 } 423 }
433 424
434 /* Set the charge pump for optimized phase noise figure */ 425 /* Set the charge pump for optimized phase noise figure */
435 tun->config &= ~0x40; 426 tun->config &= ~TUNER_CHARGE_PUMP;
436 buffer[0] = (div>>8) & 0x7f; 427 buffer[0] = (div>>8) & 0x7f;
437 buffer[1] = div & 0xff; 428 buffer[1] = div & 0xff;
438 buffer[2] = tun->config; 429 buffer[2] = tun->config;
@@ -453,26 +444,22 @@ static void default_set_radio_freq(struct i2c_client *c, unsigned int freq)
453 unsigned div; 444 unsigned div;
454 int rc; 445 int rc;
455 446
456 tun=&tuners[t->type]; 447 tun = &tuners[t->type];
457 div = (freq / 1000) + (int)(16*10.7); 448 div = (20 * freq / 16000) + (int)(20*10.7); /* IF 10.7 MHz */
458 buffer[2] = tun->config; 449 buffer[2] = (tun->config & ~TUNER_RATIO_MASK) | TUNER_RATIO_SELECT_50; /* 50 kHz step */
459 450
460 switch (t->type) { 451 switch (t->type) {
461 case TUNER_TENA_9533_DI: 452 case TUNER_TENA_9533_DI:
462 case TUNER_YMEC_TVF_5533MF: 453 case TUNER_YMEC_TVF_5533MF:
463 /*These values are empirically determinated */ 454 tuner_dbg ("This tuner doesn't have FM. Most cards has a TEA5767 for FM\n");
464 div = (freq * 122) / 16000 - 20; 455 return;
465 buffer[2] = 0x88; /* could be also 0x80 */
466 buffer[3] = 0x19; /* could be also 0x10, 0x18, 0x99 */
467 break;
468 case TUNER_PHILIPS_FM1216ME_MK3: 456 case TUNER_PHILIPS_FM1216ME_MK3:
469 case TUNER_PHILIPS_FM1236_MK3: 457 case TUNER_PHILIPS_FM1236_MK3:
470 case TUNER_PHILIPS_FMD1216ME_MK3: 458 case TUNER_PHILIPS_FMD1216ME_MK3:
471 buffer[3] = 0x19; 459 buffer[3] = 0x19;
472 break; 460 break;
473 case TUNER_PHILIPS_FM1256_IH3: 461 case TUNER_PHILIPS_FM1256_IH3:
474 div = (20 * freq) / 16000 + 333 * 2; 462 div = (20 * freq) / 16000 + (int)(33.3 * 20); /* IF 33.3 MHz */
475 buffer[2] = 0x80;
476 buffer[3] = 0x19; 463 buffer[3] = 0x19;
477 break; 464 break;
478 case TUNER_LG_PAL_FM: 465 case TUNER_LG_PAL_FM:
diff --git a/drivers/media/video/tvaudio.c b/drivers/media/video/tvaudio.c
index 9a493bea76d8..d8b78f1d686b 100644
--- a/drivers/media/video/tvaudio.c
+++ b/drivers/media/video/tvaudio.c
@@ -864,13 +864,8 @@ static int tda9874a_getmode(struct CHIPSTATE *chip)
864 * But changing the mode to VIDEO_SOUND_MONO would switch 864 * But changing the mode to VIDEO_SOUND_MONO would switch
865 * external 4052 multiplexer in audio_hook(). 865 * external 4052 multiplexer in audio_hook().
866 */ 866 */
867#if 0
868 if((nsr & 0x02) && !(dsr & 0x10)) /* NSR.S/MB=1 and DSR.AMSTAT=0 */
869 mode |= VIDEO_SOUND_STEREO;
870#else
871 if(nsr & 0x02) /* NSR.S/MB=1 */ 867 if(nsr & 0x02) /* NSR.S/MB=1 */
872 mode |= VIDEO_SOUND_STEREO; 868 mode |= VIDEO_SOUND_STEREO;
873#endif
874 if(nsr & 0x01) /* NSR.D/SB=1 */ 869 if(nsr & 0x01) /* NSR.D/SB=1 */
875 mode |= VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2; 870 mode |= VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2;
876 } else { 871 } else {
diff --git a/drivers/media/video/tveeprom.c b/drivers/media/video/tveeprom.c
index 0f03c25489f1..e8d9440977cb 100644
--- a/drivers/media/video/tveeprom.c
+++ b/drivers/media/video/tveeprom.c
@@ -400,14 +400,6 @@ void tveeprom_hauppauge_analog(struct tveeprom *tvee, unsigned char *eeprom_data
400 } 400 }
401 } 401 }
402 402
403#if 0
404 if (t_format < sizeof(hauppauge_tuner_fmt)/sizeof(struct HAUPPAUGE_TUNER_FMT)) {
405 tvee->tuner_formats = hauppauge_tuner_fmt[t_format].id;
406 t_fmt_name = hauppauge_tuner_fmt[t_format].name;
407 } else {
408 t_fmt_name = "<unknown>";
409 }
410#endif
411 403
412 TVEEPROM_KERN_INFO("Hauppauge: model = %d, rev = %s, serial# = %d\n", 404 TVEEPROM_KERN_INFO("Hauppauge: model = %d, rev = %s, serial# = %d\n",
413 tvee->model, 405 tvee->model,
@@ -482,6 +474,7 @@ static unsigned short normal_i2c[] = {
482 0xa0 >> 1, 474 0xa0 >> 1,
483 I2C_CLIENT_END, 475 I2C_CLIENT_END,
484}; 476};
477
485I2C_CLIENT_INSMOD; 478I2C_CLIENT_INSMOD;
486 479
487struct i2c_driver i2c_driver_tveeprom; 480struct i2c_driver i2c_driver_tveeprom;
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 4cecdafeb87d..7fc692a8f5b0 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -6,8 +6,7 @@ menu "Misc devices"
6 6
7config IBM_ASM 7config IBM_ASM
8 tristate "Device driver for IBM RSA service processor" 8 tristate "Device driver for IBM RSA service processor"
9 depends on X86 && EXPERIMENTAL 9 depends on X86 && PCI && EXPERIMENTAL
10 default n
11 ---help--- 10 ---help---
12 This option enables device driver support for in-band access to the 11 This option enables device driver support for in-band access to the
13 IBM RSA (Condor) service processor in eServer xSeries systems. 12 IBM RSA (Condor) service processor in eServer xSeries systems.
@@ -22,7 +21,7 @@ config IBM_ASM
22 21
23 WARNING: This software may not be supported or function 22 WARNING: This software may not be supported or function
24 correctly on your IBM server. Please consult the IBM ServerProven 23 correctly on your IBM server. Please consult the IBM ServerProven
25 website <http://www.pc.ibm/ww/eserver/xseries/serverproven> for 24 website <http://www.pc.ibm.com/ww/eserver/xseries/serverproven> for
26 information on the specific driver level and support statement 25 information on the specific driver level and support statement
27 for your IBM server. 26 for your IBM server.
28 27
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index 2b55687f6ee9..9a07ff7a7777 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -3,6 +3,8 @@
3# Network device configuration 3# Network device configuration
4# 4#
5 5
6menu "Network device support"
7
6config NETDEVICES 8config NETDEVICES
7 depends on NET 9 depends on NET
8 bool "Network device support" 10 bool "Network device support"
@@ -2547,3 +2549,4 @@ config NETCONSOLE
2547 If you want to log kernel messages over the network, enable this. 2549 If you want to log kernel messages over the network, enable this.
2548 See <file:Documentation/networking/netconsole.txt> for details. 2550 See <file:Documentation/networking/netconsole.txt> for details.
2549 2551
2552endmenu
diff --git a/drivers/net/appletalk/Kconfig b/drivers/net/appletalk/Kconfig
index 69c488d933a2..b14e89004c3a 100644
--- a/drivers/net/appletalk/Kconfig
+++ b/drivers/net/appletalk/Kconfig
@@ -1,6 +1,33 @@
1# 1#
2# Appletalk driver configuration 2# Appletalk driver configuration
3# 3#
4config ATALK
5 tristate "Appletalk protocol support"
6 select LLC
7 ---help---
8 AppleTalk is the protocol that Apple computers can use to communicate
9 on a network. If your Linux box is connected to such a network and you
10 wish to connect to it, say Y. You will need to use the netatalk package
11 so that your Linux box can act as a print and file server for Macs as
12 well as access AppleTalk printers. Check out
13 <http://www.zettabyte.net/netatalk/> on the WWW for details.
14 EtherTalk is the name used for AppleTalk over Ethernet and the
15 cheaper and slower LocalTalk is AppleTalk over a proprietary Apple
16 network using serial links. EtherTalk and LocalTalk are fully
17 supported by Linux.
18
19 General information about how to connect Linux, Windows machines and
20 Macs is on the WWW at <http://www.eats.com/linux_mac_win.html>. The
21 NET-3-HOWTO, available from
22 <http://www.tldp.org/docs.html#howto>, contains valuable
23 information as well.
24
25 To compile this driver as a module, choose M here: the module will be
26 called appletalk. You almost certainly want to compile it as a
27 module so you can restart your AppleTalk stack without rebooting
28 your machine. I hear that the GNU boycott of Apple is over, so
29 even politically correct people are allowed to say Y here.
30
4config DEV_APPLETALK 31config DEV_APPLETALK
5 bool "Appletalk interfaces support" 32 bool "Appletalk interfaces support"
6 depends on ATALK 33 depends on ATALK
diff --git a/drivers/net/b44.c b/drivers/net/b44.c
index f1bd45e3da31..94939f570f78 100644
--- a/drivers/net/b44.c
+++ b/drivers/net/b44.c
@@ -1930,6 +1930,7 @@ static int b44_suspend(struct pci_dev *pdev, pm_message_t state)
1930 b44_free_rings(bp); 1930 b44_free_rings(bp);
1931 1931
1932 spin_unlock_irq(&bp->lock); 1932 spin_unlock_irq(&bp->lock);
1933 pci_disable_device(pdev);
1933 return 0; 1934 return 0;
1934} 1935}
1935 1936
@@ -1939,6 +1940,8 @@ static int b44_resume(struct pci_dev *pdev)
1939 struct b44 *bp = netdev_priv(dev); 1940 struct b44 *bp = netdev_priv(dev);
1940 1941
1941 pci_restore_state(pdev); 1942 pci_restore_state(pdev);
1943 pci_enable_device(pdev);
1944 pci_set_master(pdev);
1942 1945
1943 if (!netif_running(dev)) 1946 if (!netif_running(dev))
1944 return 0; 1947 return 0;
diff --git a/drivers/net/myri_sbus.c b/drivers/net/myri_sbus.c
index aad5494c83cf..f0996ce5c268 100644
--- a/drivers/net/myri_sbus.c
+++ b/drivers/net/myri_sbus.c
@@ -369,7 +369,7 @@ static void myri_tx(struct myri_eth *mp, struct net_device *dev)
369 * assume 802.3 if the type field is short enough to be a length. 369 * assume 802.3 if the type field is short enough to be a length.
370 * This is normal practice and works for any 'now in use' protocol. 370 * This is normal practice and works for any 'now in use' protocol.
371 */ 371 */
372static unsigned short myri_type_trans(struct sk_buff *skb, struct net_device *dev) 372static __be16 myri_type_trans(struct sk_buff *skb, struct net_device *dev)
373{ 373{
374 struct ethhdr *eth; 374 struct ethhdr *eth;
375 unsigned char *rawp; 375 unsigned char *rawp;
diff --git a/drivers/net/ne2k-pci.c b/drivers/net/ne2k-pci.c
index a1a6c08e7dcf..f1c01ac29102 100644
--- a/drivers/net/ne2k-pci.c
+++ b/drivers/net/ne2k-pci.c
@@ -660,6 +660,7 @@ static int ne2k_pci_suspend (struct pci_dev *pdev, pm_message_t state)
660 660
661 netif_device_detach(dev); 661 netif_device_detach(dev);
662 pci_save_state(pdev); 662 pci_save_state(pdev);
663 pci_disable_device(pdev);
663 pci_set_power_state(pdev, pci_choose_state(pdev, state)); 664 pci_set_power_state(pdev, pci_choose_state(pdev, state));
664 665
665 return 0; 666 return 0;
@@ -671,6 +672,8 @@ static int ne2k_pci_resume (struct pci_dev *pdev)
671 672
672 pci_set_power_state(pdev, 0); 673 pci_set_power_state(pdev, 0);
673 pci_restore_state(pdev); 674 pci_restore_state(pdev);
675 pci_enable_device(pdev);
676 pci_set_master(pdev);
674 NS8390_init(dev, 1); 677 NS8390_init(dev, 1);
675 netif_device_attach(dev); 678 netif_device_attach(dev);
676 679
diff --git a/drivers/net/plip.c b/drivers/net/plip.c
index f4b62405d2e5..21537ee3a6a7 100644
--- a/drivers/net/plip.c
+++ b/drivers/net/plip.c
@@ -540,7 +540,7 @@ plip_receive(unsigned short nibble_timeout, struct net_device *dev,
540 * in far too many old systems not all even running Linux. 540 * in far too many old systems not all even running Linux.
541 */ 541 */
542 542
543static unsigned short plip_type_trans(struct sk_buff *skb, struct net_device *dev) 543static __be16 plip_type_trans(struct sk_buff *skb, struct net_device *dev)
544{ 544{
545 struct ethhdr *eth; 545 struct ethhdr *eth;
546 unsigned char *rawp; 546 unsigned char *rawp;
diff --git a/drivers/net/wan/farsync.c b/drivers/net/wan/farsync.c
index 7217d44e8854..2c83cca34b86 100644
--- a/drivers/net/wan/farsync.c
+++ b/drivers/net/wan/farsync.c
@@ -861,8 +861,7 @@ fst_tx_dma_complete(struct fst_card_info *card, struct fst_port_info *port,
861/* 861/*
862 * Mark it for our own raw sockets interface 862 * Mark it for our own raw sockets interface
863 */ 863 */
864static unsigned short farsync_type_trans(struct sk_buff *skb, 864static __be16 farsync_type_trans(struct sk_buff *skb, struct net_device *dev)
865 struct net_device *dev)
866{ 865{
867 skb->dev = dev; 866 skb->dev = dev;
868 skb->mac.raw = skb->data; 867 skb->mac.raw = skb->data;
diff --git a/drivers/net/wan/hdlc_cisco.c b/drivers/net/wan/hdlc_cisco.c
index 87496843681a..48c03c11cd9a 100644
--- a/drivers/net/wan/hdlc_cisco.c
+++ b/drivers/net/wan/hdlc_cisco.c
@@ -91,8 +91,7 @@ static void cisco_keepalive_send(struct net_device *dev, u32 type,
91 91
92 92
93 93
94static unsigned short cisco_type_trans(struct sk_buff *skb, 94static __be16 cisco_type_trans(struct sk_buff *skb, struct net_device *dev)
95 struct net_device *dev)
96{ 95{
97 hdlc_header *data = (hdlc_header*)skb->data; 96 hdlc_header *data = (hdlc_header*)skb->data;
98 97
diff --git a/drivers/net/wan/hdlc_ppp.c b/drivers/net/wan/hdlc_ppp.c
index 7cd6195a2e46..b81263eaede0 100644
--- a/drivers/net/wan/hdlc_ppp.c
+++ b/drivers/net/wan/hdlc_ppp.c
@@ -66,8 +66,7 @@ static void ppp_close(struct net_device *dev)
66 66
67 67
68 68
69static unsigned short ppp_type_trans(struct sk_buff *skb, 69static __be16 ppp_type_trans(struct sk_buff *skb, struct net_device *dev)
70 struct net_device *dev)
71{ 70{
72 return __constant_htons(ETH_P_WAN_PPP); 71 return __constant_htons(ETH_P_WAN_PPP);
73} 72}
diff --git a/drivers/net/wan/hdlc_raw.c b/drivers/net/wan/hdlc_raw.c
index c41fb70b6929..9456d31cb1c1 100644
--- a/drivers/net/wan/hdlc_raw.c
+++ b/drivers/net/wan/hdlc_raw.c
@@ -24,8 +24,7 @@
24#include <linux/hdlc.h> 24#include <linux/hdlc.h>
25 25
26 26
27static unsigned short raw_type_trans(struct sk_buff *skb, 27static __be16 raw_type_trans(struct sk_buff *skb, struct net_device *dev)
28 struct net_device *dev)
29{ 28{
30 return __constant_htons(ETH_P_IP); 29 return __constant_htons(ETH_P_IP);
31} 30}
diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
index bc01d34e2634..e9e37abe1f76 100644
--- a/drivers/pci/pci-acpi.c
+++ b/drivers/pci/pci-acpi.c
@@ -1,9 +1,10 @@
1/* 1/*
2 * File: pci-acpi.c 2 * File: pci-acpi.c
3 * Purpose: Provide PCI supports in ACPI 3 * Purpose: Provide PCI support in ACPI
4 * 4 *
5 * Copyright (C) 2004 Intel 5 * Copyright (C) 2005 David Shaohua Li <shaohua.li@intel.com>
6 * Copyright (C) Tom Long Nguyen (tom.l.nguyen@intel.com) 6 * Copyright (C) 2004 Tom Long Nguyen <tom.l.nguyen@intel.com>
7 * Copyright (C) 2004 Intel Corp.
7 */ 8 */
8 9
9#include <linux/delay.h> 10#include <linux/delay.h>
@@ -16,6 +17,7 @@
16#include <acpi/acpi_bus.h> 17#include <acpi/acpi_bus.h>
17 18
18#include <linux/pci-acpi.h> 19#include <linux/pci-acpi.h>
20#include "pci.h"
19 21
20static u32 ctrlset_buf[3] = {0, 0, 0}; 22static u32 ctrlset_buf[3] = {0, 0, 0};
21static u32 global_ctrlsets = 0; 23static u32 global_ctrlsets = 0;
@@ -207,3 +209,105 @@ acpi_status pci_osc_control_set(u32 flags)
207 return status; 209 return status;
208} 210}
209EXPORT_SYMBOL(pci_osc_control_set); 211EXPORT_SYMBOL(pci_osc_control_set);
212
213/*
214 * _SxD returns the D-state with the highest power
215 * (lowest D-state number) supported in the S-state "x".
216 *
217 * If the devices does not have a _PRW
218 * (Power Resources for Wake) supporting system wakeup from "x"
219 * then the OS is free to choose a lower power (higher number
220 * D-state) than the return value from _SxD.
221 *
222 * But if _PRW is enabled at S-state "x", the OS
223 * must not choose a power lower than _SxD --
224 * unless the device has an _SxW method specifying
225 * the lowest power (highest D-state number) the device
226 * may enter while still able to wake the system.
227 *
228 * ie. depending on global OS policy:
229 *
230 * if (_PRW at S-state x)
231 * choose from highest power _SxD to lowest power _SxW
232 * else // no _PRW at S-state x
233 * choose highest power _SxD or any lower power
234 *
235 * currently we simply return _SxD, if present.
236 */
237
238static int acpi_pci_choose_state(struct pci_dev *pdev, pm_message_t state)
239{
240 /* TBD */
241
242 return -ENODEV;
243}
244
245static int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state)
246{
247 acpi_handle handle = DEVICE_ACPI_HANDLE(&dev->dev);
248 static int state_conv[] = {
249 [0] = 0,
250 [1] = 1,
251 [2] = 2,
252 [3] = 3,
253 [4] = 3
254 };
255 int acpi_state = state_conv[(int __force) state];
256
257 if (!handle)
258 return -ENODEV;
259 return acpi_bus_set_power(handle, acpi_state);
260}
261
262
263/* ACPI bus type */
264static int pci_acpi_find_device(struct device *dev, acpi_handle *handle)
265{
266 struct pci_dev * pci_dev;
267 acpi_integer addr;
268
269 pci_dev = to_pci_dev(dev);
270 /* Please ref to ACPI spec for the syntax of _ADR */
271 addr = (PCI_SLOT(pci_dev->devfn) << 16) | PCI_FUNC(pci_dev->devfn);
272 *handle = acpi_get_child(DEVICE_ACPI_HANDLE(dev->parent), addr);
273 if (!*handle)
274 return -ENODEV;
275 return 0;
276}
277
278static int pci_acpi_find_root_bridge(struct device *dev, acpi_handle *handle)
279{
280 int num;
281 unsigned int seg, bus;
282
283 /*
284 * The string should be the same as root bridge's name
285 * Please look at 'pci_scan_bus_parented'
286 */
287 num = sscanf(dev->bus_id, "pci%04x:%02x", &seg, &bus);
288 if (num != 2)
289 return -ENODEV;
290 *handle = acpi_get_pci_rootbridge_handle(seg, bus);
291 if (!*handle)
292 return -ENODEV;
293 return 0;
294}
295
296static struct acpi_bus_type pci_acpi_bus = {
297 .bus = &pci_bus_type,
298 .find_device = pci_acpi_find_device,
299 .find_bridge = pci_acpi_find_root_bridge,
300};
301
302static int __init pci_acpi_init(void)
303{
304 int ret;
305
306 ret = register_acpi_bus_type(&pci_acpi_bus);
307 if (ret)
308 return 0;
309 platform_pci_choose_state = acpi_pci_choose_state;
310 platform_pci_set_power_state = acpi_pci_set_power_state;
311 return 0;
312}
313arch_initcall(pci_acpi_init);
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index d382bdb7b560..1b34fc56067e 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -235,7 +235,7 @@ pci_find_parent_resource(const struct pci_dev *dev, struct resource *res)
235 * -EIO if device does not support PCI PM. 235 * -EIO if device does not support PCI PM.
236 * 0 if we can successfully change the power state. 236 * 0 if we can successfully change the power state.
237 */ 237 */
238 238int (*platform_pci_set_power_state)(struct pci_dev *dev, pci_power_t t);
239int 239int
240pci_set_power_state(struct pci_dev *dev, pci_power_t state) 240pci_set_power_state(struct pci_dev *dev, pci_power_t state)
241{ 241{
@@ -299,11 +299,20 @@ pci_set_power_state(struct pci_dev *dev, pci_power_t state)
299 msleep(10); 299 msleep(10);
300 else if (state == PCI_D2 || dev->current_state == PCI_D2) 300 else if (state == PCI_D2 || dev->current_state == PCI_D2)
301 udelay(200); 301 udelay(200);
302 dev->current_state = state;
303 302
303 /*
304 * Give firmware a chance to be called, such as ACPI _PRx, _PSx
305 * Firmware method after natice method ?
306 */
307 if (platform_pci_set_power_state)
308 platform_pci_set_power_state(dev, state);
309
310 dev->current_state = state;
304 return 0; 311 return 0;
305} 312}
306 313
314int (*platform_pci_choose_state)(struct pci_dev *dev, pm_message_t state);
315
307/** 316/**
308 * pci_choose_state - Choose the power state of a PCI device 317 * pci_choose_state - Choose the power state of a PCI device
309 * @dev: PCI device to be suspended 318 * @dev: PCI device to be suspended
@@ -316,10 +325,17 @@ pci_set_power_state(struct pci_dev *dev, pci_power_t state)
316 325
317pci_power_t pci_choose_state(struct pci_dev *dev, pm_message_t state) 326pci_power_t pci_choose_state(struct pci_dev *dev, pm_message_t state)
318{ 327{
328 int ret;
329
319 if (!pci_find_capability(dev, PCI_CAP_ID_PM)) 330 if (!pci_find_capability(dev, PCI_CAP_ID_PM))
320 return PCI_D0; 331 return PCI_D0;
321 332
322 switch (state) { 333 if (platform_pci_choose_state) {
334 ret = platform_pci_choose_state(dev, state);
335 if (ret >= 0)
336 state = ret;
337 }
338 switch (state) {
323 case 0: return PCI_D0; 339 case 0: return PCI_D0;
324 case 3: return PCI_D3hot; 340 case 3: return PCI_D3hot;
325 default: 341 default:
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 744da0d4ae5f..d94d7af4f7a0 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -11,6 +11,10 @@ extern int pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res,
11 void (*alignf)(void *, struct resource *, 11 void (*alignf)(void *, struct resource *,
12 unsigned long, unsigned long), 12 unsigned long, unsigned long),
13 void *alignf_data); 13 void *alignf_data);
14/* Firmware callbacks */
15extern int (*platform_pci_choose_state)(struct pci_dev *dev, pm_message_t state);
16extern int (*platform_pci_set_power_state)(struct pci_dev *dev, pci_power_t state);
17
14/* PCI /proc functions */ 18/* PCI /proc functions */
15#ifdef CONFIG_PROC_FS 19#ifdef CONFIG_PROC_FS
16extern int pci_proc_attach_device(struct pci_dev *dev); 20extern int pci_proc_attach_device(struct pci_dev *dev);
diff --git a/drivers/pcmcia/yenta_socket.c b/drivers/pcmcia/yenta_socket.c
index 0e7aa8176692..6837491f021c 100644
--- a/drivers/pcmcia/yenta_socket.c
+++ b/drivers/pcmcia/yenta_socket.c
@@ -527,98 +527,144 @@ static int yenta_sock_suspend(struct pcmcia_socket *sock)
527 * Use an adaptive allocation for the memory resource, 527 * Use an adaptive allocation for the memory resource,
528 * sometimes the memory behind pci bridges is limited: 528 * sometimes the memory behind pci bridges is limited:
529 * 1/8 of the size of the io window of the parent. 529 * 1/8 of the size of the io window of the parent.
530 * max 4 MB, min 16 kB. 530 * max 4 MB, min 16 kB. We try very hard to not get below
531 * the "ACC" values, though.
531 */ 532 */
532#define BRIDGE_MEM_MAX 4*1024*1024 533#define BRIDGE_MEM_MAX 4*1024*1024
534#define BRIDGE_MEM_ACC 128*1024
533#define BRIDGE_MEM_MIN 16*1024 535#define BRIDGE_MEM_MIN 16*1024
534 536
535#define BRIDGE_IO_MAX 256 537#define BRIDGE_IO_MAX 512
538#define BRIDGE_IO_ACC 256
536#define BRIDGE_IO_MIN 32 539#define BRIDGE_IO_MIN 32
537 540
538#ifndef PCIBIOS_MIN_CARDBUS_IO 541#ifndef PCIBIOS_MIN_CARDBUS_IO
539#define PCIBIOS_MIN_CARDBUS_IO PCIBIOS_MIN_IO 542#define PCIBIOS_MIN_CARDBUS_IO PCIBIOS_MIN_IO
540#endif 543#endif
541 544
542static void yenta_allocate_res(struct yenta_socket *socket, int nr, unsigned type) 545static int yenta_search_one_res(struct resource *root, struct resource *res,
546 u32 min)
547{
548 u32 align, size, start, end;
549
550 if (res->flags & IORESOURCE_IO) {
551 align = 1024;
552 size = BRIDGE_IO_MAX;
553 start = PCIBIOS_MIN_CARDBUS_IO;
554 end = ~0U;
555 } else {
556 unsigned long avail = root->end - root->start;
557 int i;
558 size = BRIDGE_MEM_MAX;
559 if (size > avail/8) {
560 size=(avail+1)/8;
561 /* round size down to next power of 2 */
562 i = 0;
563 while ((size /= 2) != 0)
564 i++;
565 size = 1 << i;
566 }
567 if (size < min)
568 size = min;
569 align = size;
570 start = PCIBIOS_MIN_MEM;
571 end = ~0U;
572 }
573
574 do {
575 if (allocate_resource(root, res, size, start, end, align,
576 NULL, NULL)==0) {
577 return 1;
578 }
579 size = size/2;
580 align = size;
581 } while (size >= min);
582
583 return 0;
584}
585
586
587static int yenta_search_res(struct yenta_socket *socket, struct resource *res,
588 u32 min)
589{
590 int i;
591 for (i=0; i<PCI_BUS_NUM_RESOURCES; i++) {
592 struct resource * root = socket->dev->bus->resource[i];
593 if (!root)
594 continue;
595
596 if ((res->flags ^ root->flags) &
597 (IORESOURCE_IO | IORESOURCE_MEM | IORESOURCE_PREFETCH))
598 continue; /* Wrong type */
599
600 if (yenta_search_one_res(root, res, min))
601 return 1;
602 }
603 return 0;
604}
605
606static void yenta_allocate_res(struct yenta_socket *socket, int nr, unsigned type, int addr_start, int addr_end)
543{ 607{
544 struct pci_bus *bus; 608 struct pci_bus *bus;
545 struct resource *root, *res; 609 struct resource *root, *res;
546 u32 start, end; 610 u32 start, end;
547 u32 align, size, min;
548 unsigned offset;
549 unsigned mask; 611 unsigned mask;
550 612
551 res = socket->dev->resource + PCI_BRIDGE_RESOURCES + nr; 613 res = socket->dev->resource + PCI_BRIDGE_RESOURCES + nr;
552 /* Already allocated? */ 614 /* Already allocated? */
553 if (res->parent) 615 if (res->parent)
554 return 0; 616 return;
555 617
556 /* The granularity of the memory limit is 4kB, on IO it's 4 bytes */ 618 /* The granularity of the memory limit is 4kB, on IO it's 4 bytes */
557 mask = ~0xfff; 619 mask = ~0xfff;
558 if (type & IORESOURCE_IO) 620 if (type & IORESOURCE_IO)
559 mask = ~3; 621 mask = ~3;
560 622
561 offset = 0x1c + 8*nr;
562 bus = socket->dev->subordinate; 623 bus = socket->dev->subordinate;
563 res->name = bus->name; 624 res->name = bus->name;
564 res->flags = type; 625 res->flags = type;
565 res->start = 0;
566 res->end = 0;
567 root = pci_find_parent_resource(socket->dev, res);
568 626
569 if (!root) 627 start = config_readl(socket, addr_start) & mask;
570 return; 628 end = config_readl(socket, addr_end) | ~mask;
571
572 start = config_readl(socket, offset) & mask;
573 end = config_readl(socket, offset+4) | ~mask;
574 if (start && end > start && !override_bios) { 629 if (start && end > start && !override_bios) {
575 res->start = start; 630 res->start = start;
576 res->end = end; 631 res->end = end;
577 if (request_resource(root, res) == 0) 632 root = pci_find_parent_resource(socket->dev, res);
633 if (root && (request_resource(root, res) == 0))
578 return; 634 return;
579 printk(KERN_INFO "yenta %s: Preassigned resource %d busy, reconfiguring...\n", 635 printk(KERN_INFO "yenta %s: Preassigned resource %d busy or not available, reconfiguring...\n",
580 pci_name(socket->dev), nr); 636 pci_name(socket->dev), nr);
581 res->start = res->end = 0;
582 } 637 }
583 638
584 if (type & IORESOURCE_IO) { 639 if (type & IORESOURCE_IO) {
585 align = 1024; 640 if ((yenta_search_res(socket, res, BRIDGE_IO_MAX)) ||
586 size = BRIDGE_IO_MAX; 641 (yenta_search_res(socket, res, BRIDGE_IO_ACC)) ||
587 min = BRIDGE_IO_MIN; 642 (yenta_search_res(socket, res, BRIDGE_IO_MIN))) {
588 start = PCIBIOS_MIN_CARDBUS_IO; 643 config_writel(socket, addr_start, res->start);
589 end = ~0U; 644 config_writel(socket, addr_end, res->end);
645 }
590 } else { 646 } else {
591 unsigned long avail = root->end - root->start; 647 if (type & IORESOURCE_PREFETCH) {
592 int i; 648 if ((yenta_search_res(socket, res, BRIDGE_MEM_MAX)) ||
593 size = BRIDGE_MEM_MAX; 649 (yenta_search_res(socket, res, BRIDGE_MEM_ACC)) ||
594 if (size > avail/8) { 650 (yenta_search_res(socket, res, BRIDGE_MEM_MIN))) {
595 size=(avail+1)/8; 651 config_writel(socket, addr_start, res->start);
596 /* round size down to next power of 2 */ 652 config_writel(socket, addr_end, res->end);
597 i = 0; 653 }
598 while ((size /= 2) != 0) 654 /* Approximating prefetchable by non-prefetchable */
599 i++; 655 res->flags = IORESOURCE_MEM;
600 size = 1 << i;
601 } 656 }
602 if (size < BRIDGE_MEM_MIN) 657 if ((yenta_search_res(socket, res, BRIDGE_MEM_MAX)) ||
603 size = BRIDGE_MEM_MIN; 658 (yenta_search_res(socket, res, BRIDGE_MEM_ACC)) ||
604 min = BRIDGE_MEM_MIN; 659 (yenta_search_res(socket, res, BRIDGE_MEM_MIN))) {
605 align = size; 660 config_writel(socket, addr_start, res->start);
606 start = PCIBIOS_MIN_MEM; 661 config_writel(socket, addr_end, res->end);
607 end = ~0U;
608 }
609
610 do {
611 if (allocate_resource(root, res, size, start, end, align, NULL, NULL)==0) {
612 config_writel(socket, offset, res->start);
613 config_writel(socket, offset+4, res->end);
614 return;
615 } 662 }
616 size = size/2; 663 }
617 align = size; 664
618 } while (size >= min);
619 printk(KERN_INFO "yenta %s: no resource of type %x available, trying to continue...\n", 665 printk(KERN_INFO "yenta %s: no resource of type %x available, trying to continue...\n",
620 pci_name(socket->dev), type); 666 pci_name(socket->dev), type);
621 res->start = res->end = 0; 667 res->start = res->end = res->flags = 0;
622} 668}
623 669
624/* 670/*
@@ -626,10 +672,14 @@ static void yenta_allocate_res(struct yenta_socket *socket, int nr, unsigned typ
626 */ 672 */
627static void yenta_allocate_resources(struct yenta_socket *socket) 673static void yenta_allocate_resources(struct yenta_socket *socket)
628{ 674{
629 yenta_allocate_res(socket, 0, IORESOURCE_MEM|IORESOURCE_PREFETCH); 675 yenta_allocate_res(socket, 0, IORESOURCE_IO,
630 yenta_allocate_res(socket, 1, IORESOURCE_MEM); 676 PCI_CB_IO_BASE_0, PCI_CB_IO_LIMIT_0);
631 yenta_allocate_res(socket, 2, IORESOURCE_IO); 677 yenta_allocate_res(socket, 1, IORESOURCE_IO,
632 yenta_allocate_res(socket, 3, IORESOURCE_IO); /* PCI isn't clever enough to use this one yet */ 678 PCI_CB_IO_BASE_1, PCI_CB_IO_LIMIT_1);
679 yenta_allocate_res(socket, 2, IORESOURCE_MEM|IORESOURCE_PREFETCH,
680 PCI_CB_MEMORY_BASE_0, PCI_CB_MEMORY_LIMIT_0);
681 yenta_allocate_res(socket, 3, IORESOURCE_MEM,
682 PCI_CB_MEMORY_BASE_1, PCI_CB_MEMORY_LIMIT_1);
633} 683}
634 684
635 685
@@ -1055,6 +1105,7 @@ static int yenta_dev_suspend (struct pci_dev *dev, pm_message_t state)
1055 pci_save_state(dev); 1105 pci_save_state(dev);
1056 pci_read_config_dword(dev, 16*4, &socket->saved_state[0]); 1106 pci_read_config_dword(dev, 16*4, &socket->saved_state[0]);
1057 pci_read_config_dword(dev, 17*4, &socket->saved_state[1]); 1107 pci_read_config_dword(dev, 17*4, &socket->saved_state[1]);
1108 pci_disable_device(dev);
1058 1109
1059 /* 1110 /*
1060 * Some laptops (IBM T22) do not like us putting the Cardbus 1111 * Some laptops (IBM T22) do not like us putting the Cardbus
@@ -1078,6 +1129,8 @@ static int yenta_dev_resume (struct pci_dev *dev)
1078 pci_restore_state(dev); 1129 pci_restore_state(dev);
1079 pci_write_config_dword(dev, 16*4, socket->saved_state[0]); 1130 pci_write_config_dword(dev, 16*4, socket->saved_state[0]);
1080 pci_write_config_dword(dev, 17*4, socket->saved_state[1]); 1131 pci_write_config_dword(dev, 17*4, socket->saved_state[1]);
1132 pci_enable_device(dev);
1133 pci_set_master(dev);
1081 1134
1082 if (socket->type && socket->type->restore_state) 1135 if (socket->type && socket->type->restore_state)
1083 socket->type->restore_state(socket); 1136 socket->type->restore_state(socket);
diff --git a/drivers/pnp/pnpacpi/rsparser.c b/drivers/pnp/pnpacpi/rsparser.c
index dd61e09029b1..75575f6c349c 100644
--- a/drivers/pnp/pnpacpi/rsparser.c
+++ b/drivers/pnp/pnpacpi/rsparser.c
@@ -160,7 +160,7 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
160 acpi_register_gsi(res->data.irq.interrupts[0], 160 acpi_register_gsi(res->data.irq.interrupts[0],
161 res->data.irq.edge_level, 161 res->data.irq.edge_level,
162 res->data.irq.active_high_low)); 162 res->data.irq.active_high_low));
163 pcibios_penalize_isa_irq(res->data.irq.interrupts[0]); 163 pcibios_penalize_isa_irq(res->data.irq.interrupts[0], 1);
164 } 164 }
165 break; 165 break;
166 166
@@ -171,7 +171,7 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
171 acpi_register_gsi(res->data.extended_irq.interrupts[0], 171 acpi_register_gsi(res->data.extended_irq.interrupts[0],
172 res->data.extended_irq.edge_level, 172 res->data.extended_irq.edge_level,
173 res->data.extended_irq.active_high_low)); 173 res->data.extended_irq.active_high_low));
174 pcibios_penalize_isa_irq(res->data.extended_irq.interrupts[0]); 174 pcibios_penalize_isa_irq(res->data.extended_irq.interrupts[0], 1);
175 } 175 }
176 break; 176 break;
177 case ACPI_RSTYPE_DMA: 177 case ACPI_RSTYPE_DMA:
@@ -444,6 +444,7 @@ pnpacpi_parse_fixed_mem32_option(struct pnp_option *option,
444 444
445struct acpipnp_parse_option_s { 445struct acpipnp_parse_option_s {
446 struct pnp_option *option; 446 struct pnp_option *option;
447 struct pnp_option *option_independent;
447 struct pnp_dev *dev; 448 struct pnp_dev *dev;
448}; 449};
449 450
@@ -507,7 +508,14 @@ static acpi_status pnpacpi_option_resource(struct acpi_resource *res,
507 parse_data->option = option; 508 parse_data->option = option;
508 break; 509 break;
509 case ACPI_RSTYPE_END_DPF: 510 case ACPI_RSTYPE_END_DPF:
510 return AE_CTRL_TERMINATE; 511 /*only one EndDependentFn is allowed*/
512 if (!parse_data->option_independent) {
513 pnp_warn("PnPACPI: more than one EndDependentFn");
514 return AE_ERROR;
515 }
516 parse_data->option = parse_data->option_independent;
517 parse_data->option_independent = NULL;
518 break;
511 default: 519 default:
512 pnp_warn("PnPACPI: unknown resource type %d", res->id); 520 pnp_warn("PnPACPI: unknown resource type %d", res->id);
513 return AE_ERROR; 521 return AE_ERROR;
@@ -525,6 +533,7 @@ acpi_status pnpacpi_parse_resource_option_data(acpi_handle handle,
525 parse_data.option = pnp_register_independent_option(dev); 533 parse_data.option = pnp_register_independent_option(dev);
526 if (!parse_data.option) 534 if (!parse_data.option)
527 return AE_ERROR; 535 return AE_ERROR;
536 parse_data.option_independent = parse_data.option;
528 parse_data.dev = dev; 537 parse_data.dev = dev;
529 status = acpi_walk_resources(handle, METHOD_NAME__PRS, 538 status = acpi_walk_resources(handle, METHOD_NAME__PRS,
530 pnpacpi_option_resource, &parse_data); 539 pnpacpi_option_resource, &parse_data);
diff --git a/drivers/pnp/pnpbios/rsparser.c b/drivers/pnp/pnpbios/rsparser.c
index 79bce7b75740..9001b6f0204d 100644
--- a/drivers/pnp/pnpbios/rsparser.c
+++ b/drivers/pnp/pnpbios/rsparser.c
@@ -64,7 +64,7 @@ pnpbios_parse_allocated_irqresource(struct pnp_resource_table * res, int irq)
64 } 64 }
65 res->irq_resource[i].start = 65 res->irq_resource[i].start =
66 res->irq_resource[i].end = (unsigned long) irq; 66 res->irq_resource[i].end = (unsigned long) irq;
67 pcibios_penalize_isa_irq(irq); 67 pcibios_penalize_isa_irq(irq, 1);
68 } 68 }
69} 69}
70 70
diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
index 2d1322dd7e19..887ad8939349 100644
--- a/drivers/pnp/resource.c
+++ b/drivers/pnp/resource.c
@@ -102,7 +102,7 @@ int pnp_register_irq_resource(struct pnp_option *option, struct pnp_irq *data)
102 102
103 for (i = 0; i < 16; i++) 103 for (i = 0; i < 16; i++)
104 if (test_bit(i, data->map)) 104 if (test_bit(i, data->map))
105 pcibios_penalize_isa_irq(i); 105 pcibios_penalize_isa_irq(i, 0);
106 } 106 }
107#endif 107#endif
108 return 0; 108 return 0;
diff --git a/drivers/s390/net/qeth_main.c b/drivers/s390/net/qeth_main.c
index 3cb88c770037..8f4d2999af8e 100644
--- a/drivers/s390/net/qeth_main.c
+++ b/drivers/s390/net/qeth_main.c
@@ -2210,7 +2210,7 @@ no_mem:
2210 return NULL; 2210 return NULL;
2211} 2211}
2212 2212
2213static inline unsigned short 2213static inline __be16
2214qeth_type_trans(struct sk_buff *skb, struct net_device *dev) 2214qeth_type_trans(struct sk_buff *skb, struct net_device *dev)
2215{ 2215{
2216 struct qeth_card *card; 2216 struct qeth_card *card;
diff --git a/drivers/scsi/aacraid/commctrl.c b/drivers/scsi/aacraid/commctrl.c
index 1fef92d55dee..390cd67c57c0 100644
--- a/drivers/scsi/aacraid/commctrl.c
+++ b/drivers/scsi/aacraid/commctrl.c
@@ -469,7 +469,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
469 goto cleanup; 469 goto cleanup;
470 } 470 }
471 471
472 user_srbcmd = kmalloc(GFP_KERNEL, fibsize); 472 user_srbcmd = kmalloc(fibsize, GFP_KERNEL);
473 if (!user_srbcmd) { 473 if (!user_srbcmd) {
474 dprintk((KERN_DEBUG"aacraid: Could not make a copy of the srb\n")); 474 dprintk((KERN_DEBUG"aacraid: Could not make a copy of the srb\n"));
475 rcode = -ENOMEM; 475 rcode = -ENOMEM;
diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
index d79cd218a551..df014c2a7c54 100644
--- a/drivers/usb/Makefile
+++ b/drivers/usb/Makefile
@@ -65,12 +65,14 @@ obj-$(CONFIG_USB_EMI26) += misc/
65obj-$(CONFIG_USB_EMI62) += misc/ 65obj-$(CONFIG_USB_EMI62) += misc/
66obj-$(CONFIG_USB_IDMOUSE) += misc/ 66obj-$(CONFIG_USB_IDMOUSE) += misc/
67obj-$(CONFIG_USB_LCD) += misc/ 67obj-$(CONFIG_USB_LCD) += misc/
68obj-$(CONFIG_USB_LD) += misc/
68obj-$(CONFIG_USB_LED) += misc/ 69obj-$(CONFIG_USB_LED) += misc/
69obj-$(CONFIG_USB_LEGOTOWER) += misc/ 70obj-$(CONFIG_USB_LEGOTOWER) += misc/
70obj-$(CONFIG_USB_RIO500) += misc/ 71obj-$(CONFIG_USB_RIO500) += misc/
71obj-$(CONFIG_USB_TEST) += misc/ 72obj-$(CONFIG_USB_TEST) += misc/
72obj-$(CONFIG_USB_USS720) += misc/ 73obj-$(CONFIG_USB_USS720) += misc/
73obj-$(CONFIG_USB_PHIDGETSERVO) += misc/ 74obj-$(CONFIG_USB_PHIDGETSERVO) += misc/
75obj-$(CONFIG_USB_SISUSBVGA) += misc/
74 76
75obj-$(CONFIG_USB_ATM) += atm/ 77obj-$(CONFIG_USB_ATM) += atm/
76obj-$(CONFIG_USB_SPEEDTOUCH) += atm/ 78obj-$(CONFIG_USB_SPEEDTOUCH) += atm/
diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
index cbd4a7d25d0b..8e184e2641cb 100644
--- a/drivers/usb/atm/cxacru.c
+++ b/drivers/usb/atm/cxacru.c
@@ -427,7 +427,7 @@ static void cxacru_poll_status(struct cxacru_data *instance)
427 atm_dev->link_rate = buf[CXINF_DOWNSTREAM_RATE] * 1000 / 424; 427 atm_dev->link_rate = buf[CXINF_DOWNSTREAM_RATE] * 1000 / 424;
428 atm_dev->signal = ATM_PHY_SIG_FOUND; 428 atm_dev->signal = ATM_PHY_SIG_FOUND;
429 429
430 dev_info(dev, "ADSL line: up (%d Kib/s down | %d Kib/s up)\n", 430 dev_info(dev, "ADSL line: up (%d kb/s down | %d kb/s up)\n",
431 buf[CXINF_DOWNSTREAM_RATE], buf[CXINF_UPSTREAM_RATE]); 431 buf[CXINF_DOWNSTREAM_RATE], buf[CXINF_UPSTREAM_RATE]);
432 break; 432 break;
433 433
diff --git a/drivers/usb/atm/speedtch.c b/drivers/usb/atm/speedtch.c
index 6a6eaa2a3b1c..d0cbbb7f0385 100644
--- a/drivers/usb/atm/speedtch.c
+++ b/drivers/usb/atm/speedtch.c
@@ -100,6 +100,8 @@ struct speedtch_instance_data {
100 100
101 struct work_struct status_checker; 101 struct work_struct status_checker;
102 102
103 unsigned char last_status;
104
103 int poll_delay; /* milliseconds */ 105 int poll_delay; /* milliseconds */
104 106
105 struct timer_list resubmit_timer; 107 struct timer_list resubmit_timer;
@@ -423,52 +425,48 @@ static void speedtch_check_status(struct speedtch_instance_data *instance)
423 struct usbatm_data *usbatm = instance->usbatm; 425 struct usbatm_data *usbatm = instance->usbatm;
424 struct atm_dev *atm_dev = usbatm->atm_dev; 426 struct atm_dev *atm_dev = usbatm->atm_dev;
425 unsigned char *buf = instance->scratch_buffer; 427 unsigned char *buf = instance->scratch_buffer;
426 int ret; 428 int down_speed, up_speed, ret;
429 unsigned char status;
427 430
428 atm_dbg(usbatm, "%s entered\n", __func__); 431 atm_dbg(usbatm, "%s entered\n", __func__);
429 432
430 ret = speedtch_read_status(instance); 433 ret = speedtch_read_status(instance);
431 if (ret < 0) { 434 if (ret < 0) {
432 atm_warn(usbatm, "error %d fetching device status\n", ret); 435 atm_warn(usbatm, "error %d fetching device status\n", ret);
433 if (instance->poll_delay < MAX_POLL_DELAY) 436 instance->poll_delay = min(2 * instance->poll_delay, MAX_POLL_DELAY);
434 instance->poll_delay *= 2;
435 return; 437 return;
436 } 438 }
437 439
438 if (instance->poll_delay > MIN_POLL_DELAY) 440 instance->poll_delay = max(instance->poll_delay / 2, MIN_POLL_DELAY);
439 instance->poll_delay /= 2;
440 441
441 atm_dbg(usbatm, "%s: line state %02x\n", __func__, buf[OFFSET_7]); 442 status = buf[OFFSET_7];
442 443
443 switch (buf[OFFSET_7]) { 444 atm_dbg(usbatm, "%s: line state %02x\n", __func__, status);
444 case 0: 445
445 if (atm_dev->signal != ATM_PHY_SIG_LOST) { 446 if ((status != instance->last_status) || !status) {
447 switch (status) {
448 case 0:
446 atm_dev->signal = ATM_PHY_SIG_LOST; 449 atm_dev->signal = ATM_PHY_SIG_LOST;
447 atm_info(usbatm, "ADSL line is down\n"); 450 if (instance->last_status)
448 /* It'll never resync again unless we ask it to... */ 451 atm_info(usbatm, "ADSL line is down\n");
452 /* It may never resync again unless we ask it to... */
449 ret = speedtch_start_synchro(instance); 453 ret = speedtch_start_synchro(instance);
450 } 454 break;
451 break;
452 455
453 case 0x08: 456 case 0x08:
454 if (atm_dev->signal != ATM_PHY_SIG_UNKNOWN) {
455 atm_dev->signal = ATM_PHY_SIG_UNKNOWN; 457 atm_dev->signal = ATM_PHY_SIG_UNKNOWN;
456 atm_info(usbatm, "ADSL line is blocked?\n"); 458 atm_info(usbatm, "ADSL line is blocked?\n");
457 } 459 break;
458 break;
459 460
460 case 0x10: 461 case 0x10:
461 if (atm_dev->signal != ATM_PHY_SIG_LOST) {
462 atm_dev->signal = ATM_PHY_SIG_LOST; 462 atm_dev->signal = ATM_PHY_SIG_LOST;
463 atm_info(usbatm, "ADSL line is synchronising\n"); 463 atm_info(usbatm, "ADSL line is synchronising\n");
464 } 464 break;
465 break;
466 465
467 case 0x20: 466 case 0x20:
468 if (atm_dev->signal != ATM_PHY_SIG_FOUND) { 467 down_speed = buf[OFFSET_b] | (buf[OFFSET_b + 1] << 8)
469 int down_speed = buf[OFFSET_b] | (buf[OFFSET_b + 1] << 8)
470 | (buf[OFFSET_b + 2] << 16) | (buf[OFFSET_b + 3] << 24); 468 | (buf[OFFSET_b + 2] << 16) | (buf[OFFSET_b + 3] << 24);
471 int up_speed = buf[OFFSET_b + 4] | (buf[OFFSET_b + 5] << 8) 469 up_speed = buf[OFFSET_b + 4] | (buf[OFFSET_b + 5] << 8)
472 | (buf[OFFSET_b + 6] << 16) | (buf[OFFSET_b + 7] << 24); 470 | (buf[OFFSET_b + 6] << 16) | (buf[OFFSET_b + 7] << 24);
473 471
474 if (!(down_speed & 0x0000ffff) && !(up_speed & 0x0000ffff)) { 472 if (!(down_speed & 0x0000ffff) && !(up_speed & 0x0000ffff)) {
@@ -480,17 +478,17 @@ static void speedtch_check_status(struct speedtch_instance_data *instance)
480 atm_dev->signal = ATM_PHY_SIG_FOUND; 478 atm_dev->signal = ATM_PHY_SIG_FOUND;
481 479
482 atm_info(usbatm, 480 atm_info(usbatm,
483 "ADSL line is up (%d Kib/s down | %d Kib/s up)\n", 481 "ADSL line is up (%d kb/s down | %d kb/s up)\n",
484 down_speed, up_speed); 482 down_speed, up_speed);
485 } 483 break;
486 break;
487 484
488 default: 485 default:
489 if (atm_dev->signal != ATM_PHY_SIG_UNKNOWN) {
490 atm_dev->signal = ATM_PHY_SIG_UNKNOWN; 486 atm_dev->signal = ATM_PHY_SIG_UNKNOWN;
491 atm_info(usbatm, "Unknown line state %02x\n", buf[OFFSET_7]); 487 atm_info(usbatm, "Unknown line state %02x\n", status);
488 break;
492 } 489 }
493 break; 490
491 instance->last_status = status;
494 } 492 }
495} 493}
496 494
@@ -730,6 +728,7 @@ static int speedtch_bind(struct usbatm_data *usbatm,
730 728
731 instance->status_checker.timer.function = speedtch_status_poll; 729 instance->status_checker.timer.function = speedtch_status_poll;
732 instance->status_checker.timer.data = (unsigned long)instance; 730 instance->status_checker.timer.data = (unsigned long)instance;
731 instance->last_status = 0xff;
733 instance->poll_delay = MIN_POLL_DELAY; 732 instance->poll_delay = MIN_POLL_DELAY;
734 733
735 init_timer(&instance->resubmit_timer); 734 init_timer(&instance->resubmit_timer);
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 69e859e0f51d..adff5a77e31f 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -422,6 +422,17 @@ bail_out:
422 return -EIO; 422 return -EIO;
423} 423}
424 424
425static void acm_tty_unregister(struct acm *acm)
426{
427 tty_unregister_device(acm_tty_driver, acm->minor);
428 usb_put_intf(acm->control);
429 acm_table[acm->minor] = NULL;
430 usb_free_urb(acm->ctrlurb);
431 usb_free_urb(acm->readurb);
432 usb_free_urb(acm->writeurb);
433 kfree(acm);
434}
435
425static void acm_tty_close(struct tty_struct *tty, struct file *filp) 436static void acm_tty_close(struct tty_struct *tty, struct file *filp)
426{ 437{
427 struct acm *acm = tty->driver_data; 438 struct acm *acm = tty->driver_data;
@@ -436,14 +447,8 @@ static void acm_tty_close(struct tty_struct *tty, struct file *filp)
436 usb_kill_urb(acm->ctrlurb); 447 usb_kill_urb(acm->ctrlurb);
437 usb_kill_urb(acm->writeurb); 448 usb_kill_urb(acm->writeurb);
438 usb_kill_urb(acm->readurb); 449 usb_kill_urb(acm->readurb);
439 } else { 450 } else
440 tty_unregister_device(acm_tty_driver, acm->minor); 451 acm_tty_unregister(acm);
441 acm_table[acm->minor] = NULL;
442 usb_free_urb(acm->ctrlurb);
443 usb_free_urb(acm->readurb);
444 usb_free_urb(acm->writeurb);
445 kfree(acm);
446 }
447 } 452 }
448 up(&open_sem); 453 up(&open_sem);
449} 454}
@@ -905,7 +910,8 @@ skip_normal_probe:
905 910
906 usb_driver_claim_interface(&acm_driver, data_interface, acm); 911 usb_driver_claim_interface(&acm_driver, data_interface, acm);
907 912
908 tty_register_device(acm_tty_driver, minor, &intf->dev); 913 usb_get_intf(control_interface);
914 tty_register_device(acm_tty_driver, minor, &control_interface->dev);
909 915
910 acm_table[minor] = acm; 916 acm_table[minor] = acm;
911 usb_set_intfdata (intf, acm); 917 usb_set_intfdata (intf, acm);
@@ -954,12 +960,7 @@ static void acm_disconnect(struct usb_interface *intf)
954 usb_driver_release_interface(&acm_driver, acm->data); 960 usb_driver_release_interface(&acm_driver, acm->data);
955 961
956 if (!acm->used) { 962 if (!acm->used) {
957 tty_unregister_device(acm_tty_driver, acm->minor); 963 acm_tty_unregister(acm);
958 acm_table[acm->minor] = NULL;
959 usb_free_urb(acm->ctrlurb);
960 usb_free_urb(acm->readurb);
961 usb_free_urb(acm->writeurb);
962 kfree(acm);
963 up(&open_sem); 964 up(&open_sem);
964 return; 965 return;
965 } 966 }
diff --git a/drivers/usb/core/buffer.c b/drivers/usb/core/buffer.c
index b7827df21f48..fc15b4acc8af 100644
--- a/drivers/usb/core/buffer.c
+++ b/drivers/usb/core/buffer.c
@@ -106,7 +106,7 @@ void hcd_buffer_destroy (struct usb_hcd *hcd)
106void *hcd_buffer_alloc ( 106void *hcd_buffer_alloc (
107 struct usb_bus *bus, 107 struct usb_bus *bus,
108 size_t size, 108 size_t size,
109 int mem_flags, 109 unsigned mem_flags,
110 dma_addr_t *dma 110 dma_addr_t *dma
111) 111)
112{ 112{
diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c
index 71b4a8d66318..fc056062c960 100644
--- a/drivers/usb/core/hcd-pci.c
+++ b/drivers/usb/core/hcd-pci.c
@@ -380,6 +380,7 @@ int usb_hcd_pci_resume (struct pci_dev *dev)
380 usb_hc_died (hcd); 380 usb_hc_died (hcd);
381 } 381 }
382 382
383 pci_enable_device(dev);
383 return retval; 384 return retval;
384} 385}
385EXPORT_SYMBOL (usb_hcd_pci_resume); 386EXPORT_SYMBOL (usb_hcd_pci_resume);
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 83e732a0d64a..8616356f55e8 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -1112,7 +1112,7 @@ static void urb_unlink (struct urb *urb)
1112 * expects usb_submit_urb() to have sanity checked and conditioned all 1112 * expects usb_submit_urb() to have sanity checked and conditioned all
1113 * inputs in the urb 1113 * inputs in the urb
1114 */ 1114 */
1115static int hcd_submit_urb (struct urb *urb, int mem_flags) 1115static int hcd_submit_urb (struct urb *urb, unsigned mem_flags)
1116{ 1116{
1117 int status; 1117 int status;
1118 struct usb_hcd *hcd = urb->dev->bus->hcpriv; 1118 struct usb_hcd *hcd = urb->dev->bus->hcpriv;
diff --git a/drivers/usb/core/hcd.h b/drivers/usb/core/hcd.h
index 8dc13cde2f73..67db4a999b93 100644
--- a/drivers/usb/core/hcd.h
+++ b/drivers/usb/core/hcd.h
@@ -142,12 +142,12 @@ struct hcd_timeout { /* timeouts we allocate */
142 142
143struct usb_operations { 143struct usb_operations {
144 int (*get_frame_number) (struct usb_device *usb_dev); 144 int (*get_frame_number) (struct usb_device *usb_dev);
145 int (*submit_urb) (struct urb *urb, int mem_flags); 145 int (*submit_urb) (struct urb *urb, unsigned mem_flags);
146 int (*unlink_urb) (struct urb *urb, int status); 146 int (*unlink_urb) (struct urb *urb, int status);
147 147
148 /* allocate dma-consistent buffer for URB_DMA_NOMAPPING */ 148 /* allocate dma-consistent buffer for URB_DMA_NOMAPPING */
149 void *(*buffer_alloc)(struct usb_bus *bus, size_t size, 149 void *(*buffer_alloc)(struct usb_bus *bus, size_t size,
150 int mem_flags, 150 unsigned mem_flags,
151 dma_addr_t *dma); 151 dma_addr_t *dma);
152 void (*buffer_free)(struct usb_bus *bus, size_t size, 152 void (*buffer_free)(struct usb_bus *bus, size_t size,
153 void *addr, dma_addr_t dma); 153 void *addr, dma_addr_t dma);
@@ -200,7 +200,7 @@ struct hc_driver {
200 int (*urb_enqueue) (struct usb_hcd *hcd, 200 int (*urb_enqueue) (struct usb_hcd *hcd,
201 struct usb_host_endpoint *ep, 201 struct usb_host_endpoint *ep,
202 struct urb *urb, 202 struct urb *urb,
203 int mem_flags); 203 unsigned mem_flags);
204 int (*urb_dequeue) (struct usb_hcd *hcd, struct urb *urb); 204 int (*urb_dequeue) (struct usb_hcd *hcd, struct urb *urb);
205 205
206 /* hw synch, freeing endpoint resources that urb_dequeue can't */ 206 /* hw synch, freeing endpoint resources that urb_dequeue can't */
@@ -247,7 +247,7 @@ int hcd_buffer_create (struct usb_hcd *hcd);
247void hcd_buffer_destroy (struct usb_hcd *hcd); 247void hcd_buffer_destroy (struct usb_hcd *hcd);
248 248
249void *hcd_buffer_alloc (struct usb_bus *bus, size_t size, 249void *hcd_buffer_alloc (struct usb_bus *bus, size_t size,
250 int mem_flags, dma_addr_t *dma); 250 unsigned mem_flags, dma_addr_t *dma);
251void hcd_buffer_free (struct usb_bus *bus, size_t size, 251void hcd_buffer_free (struct usb_bus *bus, size_t size,
252 void *addr, dma_addr_t dma); 252 void *addr, dma_addr_t dma);
253 253
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 32ff32181852..c3e46d24a37e 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -26,6 +26,7 @@
26#include <linux/ioctl.h> 26#include <linux/ioctl.h>
27#include <linux/usb.h> 27#include <linux/usb.h>
28#include <linux/usbdevice_fs.h> 28#include <linux/usbdevice_fs.h>
29#include <linux/kthread.h>
29 30
30#include <asm/semaphore.h> 31#include <asm/semaphore.h>
31#include <asm/uaccess.h> 32#include <asm/uaccess.h>
@@ -47,8 +48,7 @@ static LIST_HEAD(hub_event_list); /* List of hubs needing servicing */
47/* Wakes up khubd */ 48/* Wakes up khubd */
48static DECLARE_WAIT_QUEUE_HEAD(khubd_wait); 49static DECLARE_WAIT_QUEUE_HEAD(khubd_wait);
49 50
50static pid_t khubd_pid = 0; /* PID of khubd */ 51static struct task_struct *khubd_task;
51static DECLARE_COMPLETION(khubd_exited);
52 52
53/* cycle leds on hubs that aren't blinking for attention */ 53/* cycle leds on hubs that aren't blinking for attention */
54static int blinkenlights = 0; 54static int blinkenlights = 0;
@@ -2807,23 +2807,16 @@ loop:
2807 2807
2808static int hub_thread(void *__unused) 2808static int hub_thread(void *__unused)
2809{ 2809{
2810 /*
2811 * This thread doesn't need any user-level access,
2812 * so get rid of all our resources
2813 */
2814
2815 daemonize("khubd");
2816 allow_signal(SIGKILL);
2817
2818 /* Send me a signal to get me die (for debugging) */
2819 do { 2810 do {
2820 hub_events(); 2811 hub_events();
2821 wait_event_interruptible(khubd_wait, !list_empty(&hub_event_list)); 2812 wait_event_interruptible(khubd_wait,
2813 !list_empty(&hub_event_list) ||
2814 kthread_should_stop());
2822 try_to_freeze(); 2815 try_to_freeze();
2823 } while (!signal_pending(current)); 2816 } while (!kthread_should_stop() || !list_empty(&hub_event_list));
2824 2817
2825 pr_debug ("%s: khubd exiting\n", usbcore_name); 2818 pr_debug("%s: khubd exiting\n", usbcore_name);
2826 complete_and_exit(&khubd_exited, 0); 2819 return 0;
2827} 2820}
2828 2821
2829static struct usb_device_id hub_id_table [] = { 2822static struct usb_device_id hub_id_table [] = {
@@ -2849,20 +2842,15 @@ static struct usb_driver hub_driver = {
2849 2842
2850int usb_hub_init(void) 2843int usb_hub_init(void)
2851{ 2844{
2852 pid_t pid;
2853
2854 if (usb_register(&hub_driver) < 0) { 2845 if (usb_register(&hub_driver) < 0) {
2855 printk(KERN_ERR "%s: can't register hub driver\n", 2846 printk(KERN_ERR "%s: can't register hub driver\n",
2856 usbcore_name); 2847 usbcore_name);
2857 return -1; 2848 return -1;
2858 } 2849 }
2859 2850
2860 pid = kernel_thread(hub_thread, NULL, CLONE_KERNEL); 2851 khubd_task = kthread_run(hub_thread, NULL, "khubd");
2861 if (pid >= 0) { 2852 if (!IS_ERR(khubd_task))
2862 khubd_pid = pid;
2863
2864 return 0; 2853 return 0;
2865 }
2866 2854
2867 /* Fall through if kernel_thread failed */ 2855 /* Fall through if kernel_thread failed */
2868 usb_deregister(&hub_driver); 2856 usb_deregister(&hub_driver);
@@ -2873,12 +2861,7 @@ int usb_hub_init(void)
2873 2861
2874void usb_hub_cleanup(void) 2862void usb_hub_cleanup(void)
2875{ 2863{
2876 int ret; 2864 kthread_stop(khubd_task);
2877
2878 /* Kill the thread */
2879 ret = kill_proc(khubd_pid, SIGKILL, 1);
2880
2881 wait_for_completion(&khubd_exited);
2882 2865
2883 /* 2866 /*
2884 * Hub resources are freed for us by usb_deregister. It calls 2867 * Hub resources are freed for us by usb_deregister. It calls
@@ -2890,7 +2873,6 @@ void usb_hub_cleanup(void)
2890 usb_deregister(&hub_driver); 2873 usb_deregister(&hub_driver);
2891} /* usb_hub_cleanup() */ 2874} /* usb_hub_cleanup() */
2892 2875
2893
2894static int config_descriptors_changed(struct usb_device *udev) 2876static int config_descriptors_changed(struct usb_device *udev)
2895{ 2877{
2896 unsigned index; 2878 unsigned index;
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index f50aaf25c98e..a428ef479bd7 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -320,7 +320,7 @@ int usb_sg_init (
320 struct scatterlist *sg, 320 struct scatterlist *sg,
321 int nents, 321 int nents,
322 size_t length, 322 size_t length,
323 int mem_flags 323 unsigned mem_flags
324) 324)
325{ 325{
326 int i; 326 int i;
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index 740cb4c668df..00297f113849 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -196,6 +196,7 @@ usb_descriptor_attr (bDeviceClass, "%02x\n")
196usb_descriptor_attr (bDeviceSubClass, "%02x\n") 196usb_descriptor_attr (bDeviceSubClass, "%02x\n")
197usb_descriptor_attr (bDeviceProtocol, "%02x\n") 197usb_descriptor_attr (bDeviceProtocol, "%02x\n")
198usb_descriptor_attr (bNumConfigurations, "%d\n") 198usb_descriptor_attr (bNumConfigurations, "%d\n")
199usb_descriptor_attr (bMaxPacketSize0, "%d\n")
199 200
200static struct attribute *dev_attrs[] = { 201static struct attribute *dev_attrs[] = {
201 /* current configuration's attributes */ 202 /* current configuration's attributes */
@@ -211,6 +212,7 @@ static struct attribute *dev_attrs[] = {
211 &dev_attr_bDeviceSubClass.attr, 212 &dev_attr_bDeviceSubClass.attr,
212 &dev_attr_bDeviceProtocol.attr, 213 &dev_attr_bDeviceProtocol.attr,
213 &dev_attr_bNumConfigurations.attr, 214 &dev_attr_bNumConfigurations.attr,
215 &dev_attr_bMaxPacketSize0.attr,
214 &dev_attr_speed.attr, 216 &dev_attr_speed.attr,
215 &dev_attr_devnum.attr, 217 &dev_attr_devnum.attr,
216 &dev_attr_version.attr, 218 &dev_attr_version.attr,
diff --git a/drivers/usb/core/urb.c b/drivers/usb/core/urb.c
index 0faf18d511de..c0feee25ff0a 100644
--- a/drivers/usb/core/urb.c
+++ b/drivers/usb/core/urb.c
@@ -60,7 +60,7 @@ void usb_init_urb(struct urb *urb)
60 * 60 *
61 * The driver must call usb_free_urb() when it is finished with the urb. 61 * The driver must call usb_free_urb() when it is finished with the urb.
62 */ 62 */
63struct urb *usb_alloc_urb(int iso_packets, int mem_flags) 63struct urb *usb_alloc_urb(int iso_packets, unsigned mem_flags)
64{ 64{
65 struct urb *urb; 65 struct urb *urb;
66 66
@@ -224,7 +224,7 @@ struct urb * usb_get_urb(struct urb *urb)
224 * GFP_NOIO, unless b) or c) apply 224 * GFP_NOIO, unless b) or c) apply
225 * 225 *
226 */ 226 */
227int usb_submit_urb(struct urb *urb, int mem_flags) 227int usb_submit_urb(struct urb *urb, unsigned mem_flags)
228{ 228{
229 int pipe, temp, max; 229 int pipe, temp, max;
230 struct usb_device *dev; 230 struct usb_device *dev;
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index a3c42203213a..99c85d2f92da 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -1129,7 +1129,7 @@ int __usb_get_extra_descriptor(char *buffer, unsigned size,
1129void *usb_buffer_alloc ( 1129void *usb_buffer_alloc (
1130 struct usb_device *dev, 1130 struct usb_device *dev,
1131 size_t size, 1131 size_t size,
1132 int mem_flags, 1132 unsigned mem_flags,
1133 dma_addr_t *dma 1133 dma_addr_t *dma
1134) 1134)
1135{ 1135{
@@ -1532,6 +1532,9 @@ EXPORT_SYMBOL(usb_register);
1532EXPORT_SYMBOL(usb_deregister); 1532EXPORT_SYMBOL(usb_deregister);
1533EXPORT_SYMBOL(usb_disabled); 1533EXPORT_SYMBOL(usb_disabled);
1534 1534
1535EXPORT_SYMBOL_GPL(usb_get_intf);
1536EXPORT_SYMBOL_GPL(usb_put_intf);
1537
1535EXPORT_SYMBOL(usb_alloc_dev); 1538EXPORT_SYMBOL(usb_alloc_dev);
1536EXPORT_SYMBOL(usb_put_dev); 1539EXPORT_SYMBOL(usb_put_dev);
1537EXPORT_SYMBOL(usb_get_dev); 1540EXPORT_SYMBOL(usb_get_dev);
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index 4d692670f288..583db7c38cf1 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -470,7 +470,7 @@ static int dummy_disable (struct usb_ep *_ep)
470} 470}
471 471
472static struct usb_request * 472static struct usb_request *
473dummy_alloc_request (struct usb_ep *_ep, int mem_flags) 473dummy_alloc_request (struct usb_ep *_ep, unsigned mem_flags)
474{ 474{
475 struct dummy_ep *ep; 475 struct dummy_ep *ep;
476 struct dummy_request *req; 476 struct dummy_request *req;
@@ -507,7 +507,7 @@ dummy_alloc_buffer (
507 struct usb_ep *_ep, 507 struct usb_ep *_ep,
508 unsigned bytes, 508 unsigned bytes,
509 dma_addr_t *dma, 509 dma_addr_t *dma,
510 int mem_flags 510 unsigned mem_flags
511) { 511) {
512 char *retval; 512 char *retval;
513 struct dummy_ep *ep; 513 struct dummy_ep *ep;
@@ -540,7 +540,8 @@ fifo_complete (struct usb_ep *ep, struct usb_request *req)
540} 540}
541 541
542static int 542static int
543dummy_queue (struct usb_ep *_ep, struct usb_request *_req, int mem_flags) 543dummy_queue (struct usb_ep *_ep, struct usb_request *_req,
544 unsigned mem_flags)
544{ 545{
545 struct dummy_ep *ep; 546 struct dummy_ep *ep;
546 struct dummy_request *req; 547 struct dummy_request *req;
@@ -998,7 +999,7 @@ static int dummy_urb_enqueue (
998 struct usb_hcd *hcd, 999 struct usb_hcd *hcd,
999 struct usb_host_endpoint *ep, 1000 struct usb_host_endpoint *ep,
1000 struct urb *urb, 1001 struct urb *urb,
1001 int mem_flags 1002 unsigned mem_flags
1002) { 1003) {
1003 struct dummy *dum; 1004 struct dummy *dum;
1004 struct urbp *urbp; 1005 struct urbp *urbp;
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index 5bb53ae88969..8509e955007d 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -945,15 +945,16 @@ config_buf (enum usb_device_speed speed,
945 945
946/*-------------------------------------------------------------------------*/ 946/*-------------------------------------------------------------------------*/
947 947
948static void eth_start (struct eth_dev *dev, int gfp_flags); 948static void eth_start (struct eth_dev *dev, unsigned gfp_flags);
949static int alloc_requests (struct eth_dev *dev, unsigned n, int gfp_flags); 949static int alloc_requests (struct eth_dev *dev, unsigned n, unsigned gfp_flags);
950 950
951static int 951static int
952set_ether_config (struct eth_dev *dev, int gfp_flags) 952set_ether_config (struct eth_dev *dev, unsigned gfp_flags)
953{ 953{
954 int result = 0; 954 int result = 0;
955 struct usb_gadget *gadget = dev->gadget; 955 struct usb_gadget *gadget = dev->gadget;
956 956
957#if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS)
957 /* status endpoint used for RNDIS and (optionally) CDC */ 958 /* status endpoint used for RNDIS and (optionally) CDC */
958 if (!subset_active(dev) && dev->status_ep) { 959 if (!subset_active(dev) && dev->status_ep) {
959 dev->status = ep_desc (gadget, &hs_status_desc, 960 dev->status = ep_desc (gadget, &hs_status_desc,
@@ -967,6 +968,7 @@ set_ether_config (struct eth_dev *dev, int gfp_flags)
967 goto done; 968 goto done;
968 } 969 }
969 } 970 }
971#endif
970 972
971 dev->in = ep_desc (dev->gadget, &hs_source_desc, &fs_source_desc); 973 dev->in = ep_desc (dev->gadget, &hs_source_desc, &fs_source_desc);
972 dev->in_ep->driver_data = dev; 974 dev->in_ep->driver_data = dev;
@@ -1079,7 +1081,7 @@ static void eth_reset_config (struct eth_dev *dev)
1079 * that returns config descriptors, and altsetting code. 1081 * that returns config descriptors, and altsetting code.
1080 */ 1082 */
1081static int 1083static int
1082eth_set_config (struct eth_dev *dev, unsigned number, int gfp_flags) 1084eth_set_config (struct eth_dev *dev, unsigned number, unsigned gfp_flags)
1083{ 1085{
1084 int result = 0; 1086 int result = 0;
1085 struct usb_gadget *gadget = dev->gadget; 1087 struct usb_gadget *gadget = dev->gadget;
@@ -1596,7 +1598,7 @@ static void defer_kevent (struct eth_dev *dev, int flag)
1596static void rx_complete (struct usb_ep *ep, struct usb_request *req); 1598static void rx_complete (struct usb_ep *ep, struct usb_request *req);
1597 1599
1598static int 1600static int
1599rx_submit (struct eth_dev *dev, struct usb_request *req, int gfp_flags) 1601rx_submit (struct eth_dev *dev, struct usb_request *req, unsigned gfp_flags)
1600{ 1602{
1601 struct sk_buff *skb; 1603 struct sk_buff *skb;
1602 int retval = -ENOMEM; 1604 int retval = -ENOMEM;
@@ -1722,7 +1724,7 @@ clean:
1722} 1724}
1723 1725
1724static int prealloc (struct list_head *list, struct usb_ep *ep, 1726static int prealloc (struct list_head *list, struct usb_ep *ep,
1725 unsigned n, int gfp_flags) 1727 unsigned n, unsigned gfp_flags)
1726{ 1728{
1727 unsigned i; 1729 unsigned i;
1728 struct usb_request *req; 1730 struct usb_request *req;
@@ -1761,7 +1763,7 @@ extra:
1761 return 0; 1763 return 0;
1762} 1764}
1763 1765
1764static int alloc_requests (struct eth_dev *dev, unsigned n, int gfp_flags) 1766static int alloc_requests (struct eth_dev *dev, unsigned n, unsigned gfp_flags)
1765{ 1767{
1766 int status; 1768 int status;
1767 1769
@@ -1777,7 +1779,7 @@ fail:
1777 return status; 1779 return status;
1778} 1780}
1779 1781
1780static void rx_fill (struct eth_dev *dev, int gfp_flags) 1782static void rx_fill (struct eth_dev *dev, unsigned gfp_flags)
1781{ 1783{
1782 struct usb_request *req; 1784 struct usb_request *req;
1783 unsigned long flags; 1785 unsigned long flags;
@@ -2022,7 +2024,7 @@ static int rndis_control_ack (struct net_device *net)
2022 2024
2023#endif /* RNDIS */ 2025#endif /* RNDIS */
2024 2026
2025static void eth_start (struct eth_dev *dev, int gfp_flags) 2027static void eth_start (struct eth_dev *dev, unsigned gfp_flags)
2026{ 2028{
2027 DEBUG (dev, "%s\n", __FUNCTION__); 2029 DEBUG (dev, "%s\n", __FUNCTION__);
2028 2030
@@ -2428,7 +2430,7 @@ autoconf_fail:
2428 dev->req->complete = eth_setup_complete; 2430 dev->req->complete = eth_setup_complete;
2429 2431
2430 /* ... and maybe likewise for status transfer */ 2432 /* ... and maybe likewise for status transfer */
2431#ifdef DEV_CONFIG_CDC 2433#if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS)
2432 if (dev->status_ep) { 2434 if (dev->status_ep) {
2433 dev->stat_req = eth_req_alloc (dev->status_ep, 2435 dev->stat_req = eth_req_alloc (dev->status_ep,
2434 STATUS_BYTECOUNT, GFP_KERNEL); 2436 STATUS_BYTECOUNT, GFP_KERNEL);
diff --git a/drivers/usb/gadget/goku_udc.c b/drivers/usb/gadget/goku_udc.c
index ed773a9111de..eaab26f4ed37 100644
--- a/drivers/usb/gadget/goku_udc.c
+++ b/drivers/usb/gadget/goku_udc.c
@@ -269,7 +269,7 @@ static int goku_ep_disable(struct usb_ep *_ep)
269/*-------------------------------------------------------------------------*/ 269/*-------------------------------------------------------------------------*/
270 270
271static struct usb_request * 271static struct usb_request *
272goku_alloc_request(struct usb_ep *_ep, int gfp_flags) 272goku_alloc_request(struct usb_ep *_ep, unsigned gfp_flags)
273{ 273{
274 struct goku_request *req; 274 struct goku_request *req;
275 275
@@ -327,7 +327,7 @@ goku_free_request(struct usb_ep *_ep, struct usb_request *_req)
327 */ 327 */
328static void * 328static void *
329goku_alloc_buffer(struct usb_ep *_ep, unsigned bytes, 329goku_alloc_buffer(struct usb_ep *_ep, unsigned bytes,
330 dma_addr_t *dma, int gfp_flags) 330 dma_addr_t *dma, unsigned gfp_flags)
331{ 331{
332 void *retval; 332 void *retval;
333 struct goku_ep *ep; 333 struct goku_ep *ep;
@@ -789,7 +789,7 @@ finished:
789/*-------------------------------------------------------------------------*/ 789/*-------------------------------------------------------------------------*/
790 790
791static int 791static int
792goku_queue(struct usb_ep *_ep, struct usb_request *_req, int gfp_flags) 792goku_queue(struct usb_ep *_ep, struct usb_request *_req, unsigned gfp_flags)
793{ 793{
794 struct goku_request *req; 794 struct goku_request *req;
795 struct goku_ep *ep; 795 struct goku_ep *ep;
diff --git a/drivers/usb/gadget/lh7a40x_udc.c b/drivers/usb/gadget/lh7a40x_udc.c
index df75ab65a5ec..4842577789c9 100644
--- a/drivers/usb/gadget/lh7a40x_udc.c
+++ b/drivers/usb/gadget/lh7a40x_udc.c
@@ -1106,7 +1106,7 @@ static int lh7a40x_ep_disable(struct usb_ep *_ep)
1106} 1106}
1107 1107
1108static struct usb_request *lh7a40x_alloc_request(struct usb_ep *ep, 1108static struct usb_request *lh7a40x_alloc_request(struct usb_ep *ep,
1109 int gfp_flags) 1109 unsigned gfp_flags)
1110{ 1110{
1111 struct lh7a40x_request *req; 1111 struct lh7a40x_request *req;
1112 1112
@@ -1134,7 +1134,7 @@ static void lh7a40x_free_request(struct usb_ep *ep, struct usb_request *_req)
1134} 1134}
1135 1135
1136static void *lh7a40x_alloc_buffer(struct usb_ep *ep, unsigned bytes, 1136static void *lh7a40x_alloc_buffer(struct usb_ep *ep, unsigned bytes,
1137 dma_addr_t * dma, int gfp_flags) 1137 dma_addr_t * dma, unsigned gfp_flags)
1138{ 1138{
1139 char *retval; 1139 char *retval;
1140 1140
@@ -1158,7 +1158,7 @@ static void lh7a40x_free_buffer(struct usb_ep *ep, void *buf, dma_addr_t dma,
1158 * NOTE: Sets INDEX register 1158 * NOTE: Sets INDEX register
1159 */ 1159 */
1160static int lh7a40x_queue(struct usb_ep *_ep, struct usb_request *_req, 1160static int lh7a40x_queue(struct usb_ep *_ep, struct usb_request *_req,
1161 int gfp_flags) 1161 unsigned gfp_flags)
1162{ 1162{
1163 struct lh7a40x_request *req; 1163 struct lh7a40x_request *req;
1164 struct lh7a40x_ep *ep; 1164 struct lh7a40x_ep *ep;
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c
index 13a3dbc9949b..477fab2e74d1 100644
--- a/drivers/usb/gadget/net2280.c
+++ b/drivers/usb/gadget/net2280.c
@@ -376,7 +376,7 @@ static int net2280_disable (struct usb_ep *_ep)
376/*-------------------------------------------------------------------------*/ 376/*-------------------------------------------------------------------------*/
377 377
378static struct usb_request * 378static struct usb_request *
379net2280_alloc_request (struct usb_ep *_ep, int gfp_flags) 379net2280_alloc_request (struct usb_ep *_ep, unsigned gfp_flags)
380{ 380{
381 struct net2280_ep *ep; 381 struct net2280_ep *ep;
382 struct net2280_request *req; 382 struct net2280_request *req;
@@ -463,7 +463,7 @@ net2280_alloc_buffer (
463 struct usb_ep *_ep, 463 struct usb_ep *_ep,
464 unsigned bytes, 464 unsigned bytes,
465 dma_addr_t *dma, 465 dma_addr_t *dma,
466 int gfp_flags 466 unsigned gfp_flags
467) 467)
468{ 468{
469 void *retval; 469 void *retval;
@@ -897,7 +897,7 @@ done (struct net2280_ep *ep, struct net2280_request *req, int status)
897/*-------------------------------------------------------------------------*/ 897/*-------------------------------------------------------------------------*/
898 898
899static int 899static int
900net2280_queue (struct usb_ep *_ep, struct usb_request *_req, int gfp_flags) 900net2280_queue (struct usb_ep *_ep, struct usb_request *_req, unsigned gfp_flags)
901{ 901{
902 struct net2280_request *req; 902 struct net2280_request *req;
903 struct net2280_ep *ep; 903 struct net2280_ep *ep;
@@ -1490,7 +1490,7 @@ show_registers (struct device *_dev, struct device_attribute *attr, char *buf)
1490 unsigned long flags; 1490 unsigned long flags;
1491 int i; 1491 int i;
1492 u32 t1, t2; 1492 u32 t1, t2;
1493 char *s; 1493 const char *s;
1494 1494
1495 dev = dev_get_drvdata (_dev); 1495 dev = dev_get_drvdata (_dev);
1496 next = buf; 1496 next = buf;
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c
index a2b812af6e66..ff5533e69560 100644
--- a/drivers/usb/gadget/omap_udc.c
+++ b/drivers/usb/gadget/omap_udc.c
@@ -269,7 +269,7 @@ static int omap_ep_disable(struct usb_ep *_ep)
269/*-------------------------------------------------------------------------*/ 269/*-------------------------------------------------------------------------*/
270 270
271static struct usb_request * 271static struct usb_request *
272omap_alloc_request(struct usb_ep *ep, int gfp_flags) 272omap_alloc_request(struct usb_ep *ep, unsigned gfp_flags)
273{ 273{
274 struct omap_req *req; 274 struct omap_req *req;
275 275
@@ -298,7 +298,7 @@ omap_alloc_buffer(
298 struct usb_ep *_ep, 298 struct usb_ep *_ep,
299 unsigned bytes, 299 unsigned bytes,
300 dma_addr_t *dma, 300 dma_addr_t *dma,
301 int gfp_flags 301 unsigned gfp_flags
302) 302)
303{ 303{
304 void *retval; 304 void *retval;
@@ -937,7 +937,7 @@ static void dma_channel_release(struct omap_ep *ep)
937/*-------------------------------------------------------------------------*/ 937/*-------------------------------------------------------------------------*/
938 938
939static int 939static int
940omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, int gfp_flags) 940omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, unsigned gfp_flags)
941{ 941{
942 struct omap_ep *ep = container_of(_ep, struct omap_ep, ep); 942 struct omap_ep *ep = container_of(_ep, struct omap_ep, ep);
943 struct omap_req *req = container_of(_req, struct omap_req, req); 943 struct omap_req *req = container_of(_req, struct omap_req, req);
@@ -2908,6 +2908,7 @@ static int __exit omap_udc_remove(struct device *dev)
2908 * make host resumes and VBUS detection trigger OMAP wakeup events; that 2908 * make host resumes and VBUS detection trigger OMAP wakeup events; that
2909 * may involve talking to an external transceiver (e.g. isp1301). 2909 * may involve talking to an external transceiver (e.g. isp1301).
2910 */ 2910 */
2911
2911static int omap_udc_suspend(struct device *dev, pm_message_t message, u32 level) 2912static int omap_udc_suspend(struct device *dev, pm_message_t message, u32 level)
2912{ 2913{
2913 u32 devstat; 2914 u32 devstat;
@@ -2936,8 +2937,6 @@ static int omap_udc_resume(struct device *dev, u32 level)
2936 return 0; 2937 return 0;
2937 2938
2938 DBG("resume + wakeup/SRP\n"); 2939 DBG("resume + wakeup/SRP\n");
2939 udc->gadget.dev.parent->power.power_state = PMSG_ON;
2940 udc->gadget.dev.power.power_state = PMSG_ON;
2941 omap_pullup(&udc->gadget, 1); 2940 omap_pullup(&udc->gadget, 1);
2942 2941
2943 /* maybe the host would enumerate us if we nudged it */ 2942 /* maybe the host would enumerate us if we nudged it */
diff --git a/drivers/usb/gadget/pxa2xx_udc.c b/drivers/usb/gadget/pxa2xx_udc.c
index 6a0b957af335..1507738337c4 100644
--- a/drivers/usb/gadget/pxa2xx_udc.c
+++ b/drivers/usb/gadget/pxa2xx_udc.c
@@ -332,7 +332,7 @@ static int pxa2xx_ep_disable (struct usb_ep *_ep)
332 * pxa2xx_ep_alloc_request - allocate a request data structure 332 * pxa2xx_ep_alloc_request - allocate a request data structure
333 */ 333 */
334static struct usb_request * 334static struct usb_request *
335pxa2xx_ep_alloc_request (struct usb_ep *_ep, int gfp_flags) 335pxa2xx_ep_alloc_request (struct usb_ep *_ep, unsigned gfp_flags)
336{ 336{
337 struct pxa2xx_request *req; 337 struct pxa2xx_request *req;
338 338
@@ -367,7 +367,7 @@ pxa2xx_ep_free_request (struct usb_ep *_ep, struct usb_request *_req)
367 */ 367 */
368static void * 368static void *
369pxa2xx_ep_alloc_buffer(struct usb_ep *_ep, unsigned bytes, 369pxa2xx_ep_alloc_buffer(struct usb_ep *_ep, unsigned bytes,
370 dma_addr_t *dma, int gfp_flags) 370 dma_addr_t *dma, unsigned gfp_flags)
371{ 371{
372 char *retval; 372 char *retval;
373 373
@@ -874,7 +874,7 @@ done:
874/*-------------------------------------------------------------------------*/ 874/*-------------------------------------------------------------------------*/
875 875
876static int 876static int
877pxa2xx_ep_queue(struct usb_ep *_ep, struct usb_request *_req, int gfp_flags) 877pxa2xx_ep_queue(struct usb_ep *_ep, struct usb_request *_req, unsigned gfp_flags)
878{ 878{
879 struct pxa2xx_request *req; 879 struct pxa2xx_request *req;
880 struct pxa2xx_ep *ep; 880 struct pxa2xx_ep *ep;
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c
index a6e035e24479..bb9b2d94eed5 100644
--- a/drivers/usb/gadget/zero.c
+++ b/drivers/usb/gadget/zero.c
@@ -612,7 +612,7 @@ static void source_sink_complete (struct usb_ep *ep, struct usb_request *req)
612} 612}
613 613
614static struct usb_request * 614static struct usb_request *
615source_sink_start_ep (struct usb_ep *ep, int gfp_flags) 615source_sink_start_ep (struct usb_ep *ep, unsigned gfp_flags)
616{ 616{
617 struct usb_request *req; 617 struct usb_request *req;
618 int status; 618 int status;
@@ -640,7 +640,7 @@ source_sink_start_ep (struct usb_ep *ep, int gfp_flags)
640} 640}
641 641
642static int 642static int
643set_source_sink_config (struct zero_dev *dev, int gfp_flags) 643set_source_sink_config (struct zero_dev *dev, unsigned gfp_flags)
644{ 644{
645 int result = 0; 645 int result = 0;
646 struct usb_ep *ep; 646 struct usb_ep *ep;
@@ -744,7 +744,7 @@ static void loopback_complete (struct usb_ep *ep, struct usb_request *req)
744} 744}
745 745
746static int 746static int
747set_loopback_config (struct zero_dev *dev, int gfp_flags) 747set_loopback_config (struct zero_dev *dev, unsigned gfp_flags)
748{ 748{
749 int result = 0; 749 int result = 0;
750 struct usb_ep *ep; 750 struct usb_ep *ep;
@@ -845,7 +845,7 @@ static void zero_reset_config (struct zero_dev *dev)
845 * by limiting configuration choices (like the pxa2xx). 845 * by limiting configuration choices (like the pxa2xx).
846 */ 846 */
847static int 847static int
848zero_set_config (struct zero_dev *dev, unsigned number, int gfp_flags) 848zero_set_config (struct zero_dev *dev, unsigned number, unsigned gfp_flags)
849{ 849{
850 int result = 0; 850 int result = 0;
851 struct usb_gadget *gadget = dev->gadget; 851 struct usb_gadget *gadget = dev->gadget;
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 35248a37b717..149b13fc0a71 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -960,7 +960,7 @@ static int ehci_urb_enqueue (
960 struct usb_hcd *hcd, 960 struct usb_hcd *hcd,
961 struct usb_host_endpoint *ep, 961 struct usb_host_endpoint *ep,
962 struct urb *urb, 962 struct urb *urb,
963 int mem_flags 963 unsigned mem_flags
964) { 964) {
965 struct ehci_hcd *ehci = hcd_to_ehci (hcd); 965 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
966 struct list_head qtd_list; 966 struct list_head qtd_list;
diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c
index 45d89a7083b1..d74b2d68a50e 100644
--- a/drivers/usb/host/ehci-q.c
+++ b/drivers/usb/host/ehci-q.c
@@ -898,7 +898,7 @@ submit_async (
898 struct usb_host_endpoint *ep, 898 struct usb_host_endpoint *ep,
899 struct urb *urb, 899 struct urb *urb,
900 struct list_head *qtd_list, 900 struct list_head *qtd_list,
901 int mem_flags 901 unsigned mem_flags
902) { 902) {
903 struct ehci_qtd *qtd; 903 struct ehci_qtd *qtd;
904 int epnum; 904 int epnum;
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index c2104cad4033..9af4f64532a9 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -588,7 +588,7 @@ static int intr_submit (
588 struct usb_host_endpoint *ep, 588 struct usb_host_endpoint *ep,
589 struct urb *urb, 589 struct urb *urb,
590 struct list_head *qtd_list, 590 struct list_head *qtd_list,
591 int mem_flags 591 unsigned mem_flags
592) { 592) {
593 unsigned epnum; 593 unsigned epnum;
594 unsigned long flags; 594 unsigned long flags;
@@ -633,7 +633,7 @@ done:
633/* ehci_iso_stream ops work with both ITD and SITD */ 633/* ehci_iso_stream ops work with both ITD and SITD */
634 634
635static struct ehci_iso_stream * 635static struct ehci_iso_stream *
636iso_stream_alloc (int mem_flags) 636iso_stream_alloc (unsigned mem_flags)
637{ 637{
638 struct ehci_iso_stream *stream; 638 struct ehci_iso_stream *stream;
639 639
@@ -846,7 +846,7 @@ iso_stream_find (struct ehci_hcd *ehci, struct urb *urb)
846/* ehci_iso_sched ops can be ITD-only or SITD-only */ 846/* ehci_iso_sched ops can be ITD-only or SITD-only */
847 847
848static struct ehci_iso_sched * 848static struct ehci_iso_sched *
849iso_sched_alloc (unsigned packets, int mem_flags) 849iso_sched_alloc (unsigned packets, unsigned mem_flags)
850{ 850{
851 struct ehci_iso_sched *iso_sched; 851 struct ehci_iso_sched *iso_sched;
852 int size = sizeof *iso_sched; 852 int size = sizeof *iso_sched;
@@ -919,7 +919,7 @@ itd_urb_transaction (
919 struct ehci_iso_stream *stream, 919 struct ehci_iso_stream *stream,
920 struct ehci_hcd *ehci, 920 struct ehci_hcd *ehci,
921 struct urb *urb, 921 struct urb *urb,
922 int mem_flags 922 unsigned mem_flags
923) 923)
924{ 924{
925 struct ehci_itd *itd; 925 struct ehci_itd *itd;
@@ -1412,7 +1412,8 @@ itd_complete (
1412 1412
1413/*-------------------------------------------------------------------------*/ 1413/*-------------------------------------------------------------------------*/
1414 1414
1415static int itd_submit (struct ehci_hcd *ehci, struct urb *urb, int mem_flags) 1415static int itd_submit (struct ehci_hcd *ehci, struct urb *urb,
1416 unsigned mem_flags)
1416{ 1417{
1417 int status = -EINVAL; 1418 int status = -EINVAL;
1418 unsigned long flags; 1419 unsigned long flags;
@@ -1523,7 +1524,7 @@ sitd_urb_transaction (
1523 struct ehci_iso_stream *stream, 1524 struct ehci_iso_stream *stream,
1524 struct ehci_hcd *ehci, 1525 struct ehci_hcd *ehci,
1525 struct urb *urb, 1526 struct urb *urb,
1526 int mem_flags 1527 unsigned mem_flags
1527) 1528)
1528{ 1529{
1529 struct ehci_sitd *sitd; 1530 struct ehci_sitd *sitd;
@@ -1772,7 +1773,8 @@ sitd_complete (
1772} 1773}
1773 1774
1774 1775
1775static int sitd_submit (struct ehci_hcd *ehci, struct urb *urb, int mem_flags) 1776static int sitd_submit (struct ehci_hcd *ehci, struct urb *urb,
1777 unsigned mem_flags)
1776{ 1778{
1777 int status = -EINVAL; 1779 int status = -EINVAL;
1778 unsigned long flags; 1780 unsigned long flags;
@@ -1822,7 +1824,8 @@ done:
1822#else 1824#else
1823 1825
1824static inline int 1826static inline int
1825sitd_submit (struct ehci_hcd *ehci, struct urb *urb, int mem_flags) 1827sitd_submit (struct ehci_hcd *ehci, struct urb *urb,
1828 unsigned mem_flags)
1826{ 1829{
1827 ehci_dbg (ehci, "split iso support is disabled\n"); 1830 ehci_dbg (ehci, "split iso support is disabled\n");
1828 return -ENOSYS; 1831 return -ENOSYS;
diff --git a/drivers/usb/host/hc_crisv10.c b/drivers/usb/host/hc_crisv10.c
index d9883d774d3a..81f8f6b7fdce 100644
--- a/drivers/usb/host/hc_crisv10.c
+++ b/drivers/usb/host/hc_crisv10.c
@@ -463,7 +463,8 @@ static void etrax_usb_free_epid(int epid);
463 463
464static int etrax_remove_from_sb_list(struct urb *urb); 464static int etrax_remove_from_sb_list(struct urb *urb);
465 465
466static void* etrax_usb_buffer_alloc(struct usb_bus* bus, size_t size, int mem_flags, dma_addr_t *dma); 466static void* etrax_usb_buffer_alloc(struct usb_bus* bus, size_t size,
467 unsigned mem_flags, dma_addr_t *dma);
467static void etrax_usb_buffer_free(struct usb_bus *bus, size_t size, void *addr, dma_addr_t dma); 468static void etrax_usb_buffer_free(struct usb_bus *bus, size_t size, void *addr, dma_addr_t dma);
468 469
469static void etrax_usb_add_to_bulk_sb_list(struct urb *urb, int epid); 470static void etrax_usb_add_to_bulk_sb_list(struct urb *urb, int epid);
@@ -476,7 +477,7 @@ static int etrax_usb_submit_ctrl_urb(struct urb *urb);
476static int etrax_usb_submit_intr_urb(struct urb *urb); 477static int etrax_usb_submit_intr_urb(struct urb *urb);
477static int etrax_usb_submit_isoc_urb(struct urb *urb); 478static int etrax_usb_submit_isoc_urb(struct urb *urb);
478 479
479static int etrax_usb_submit_urb(struct urb *urb, int mem_flags); 480static int etrax_usb_submit_urb(struct urb *urb, unsigned mem_flags);
480static int etrax_usb_unlink_urb(struct urb *urb, int status); 481static int etrax_usb_unlink_urb(struct urb *urb, int status);
481static int etrax_usb_get_frame_number(struct usb_device *usb_dev); 482static int etrax_usb_get_frame_number(struct usb_device *usb_dev);
482 483
@@ -1262,7 +1263,7 @@ static int etrax_usb_allocate_epid(void)
1262 return -1; 1263 return -1;
1263} 1264}
1264 1265
1265static int etrax_usb_submit_urb(struct urb *urb, int mem_flags) 1266static int etrax_usb_submit_urb(struct urb *urb, unsigned mem_flags)
1266{ 1267{
1267 etrax_hc_t *hc; 1268 etrax_hc_t *hc;
1268 int ret = -EINVAL; 1269 int ret = -EINVAL;
@@ -4277,7 +4278,8 @@ etrax_usb_bulk_eot_timer_func(unsigned long dummy)
4277} 4278}
4278 4279
4279static void* 4280static void*
4280etrax_usb_buffer_alloc(struct usb_bus* bus, size_t size, int mem_flags, dma_addr_t *dma) 4281etrax_usb_buffer_alloc(struct usb_bus* bus, size_t size,
4282 unsigned mem_flags, dma_addr_t *dma)
4281{ 4283{
4282 return kmalloc(size, mem_flags); 4284 return kmalloc(size, mem_flags);
4283} 4285}
diff --git a/drivers/usb/host/isp116x-hcd.c b/drivers/usb/host/isp116x-hcd.c
index ff0a168e8eed..50b1970fe6b6 100644
--- a/drivers/usb/host/isp116x-hcd.c
+++ b/drivers/usb/host/isp116x-hcd.c
@@ -17,7 +17,7 @@
17 * The driver basically works. A number of people have used it with a range 17 * The driver basically works. A number of people have used it with a range
18 * of devices. 18 * of devices.
19 * 19 *
20 *The driver passes all usbtests 1-14. 20 * The driver passes all usbtests 1-14.
21 * 21 *
22 * Suspending/resuming of root hub via sysfs works. Remote wakeup works too. 22 * Suspending/resuming of root hub via sysfs works. Remote wakeup works too.
23 * And suspending/resuming of platform device works too. Suspend/resume 23 * And suspending/resuming of platform device works too. Suspend/resume
@@ -229,7 +229,7 @@ static void preproc_atl_queue(struct isp116x *isp116x)
229 struct isp116x_ep *ep; 229 struct isp116x_ep *ep;
230 struct urb *urb; 230 struct urb *urb;
231 struct ptd *ptd; 231 struct ptd *ptd;
232 u16 toggle, dir, len; 232 u16 toggle = 0, dir = PTD_DIR_SETUP, len;
233 233
234 for (ep = isp116x->atl_active; ep; ep = ep->active) { 234 for (ep = isp116x->atl_active; ep; ep = ep->active) {
235 BUG_ON(list_empty(&ep->hep->urb_list)); 235 BUG_ON(list_empty(&ep->hep->urb_list));
@@ -251,8 +251,6 @@ static void preproc_atl_queue(struct isp116x *isp116x)
251 dir = PTD_DIR_OUT; 251 dir = PTD_DIR_OUT;
252 break; 252 break;
253 case USB_PID_SETUP: 253 case USB_PID_SETUP:
254 toggle = 0;
255 dir = PTD_DIR_SETUP;
256 len = sizeof(struct usb_ctrlrequest); 254 len = sizeof(struct usb_ctrlrequest);
257 ep->data = urb->setup_packet; 255 ep->data = urb->setup_packet;
258 break; 256 break;
@@ -264,11 +262,9 @@ static void preproc_atl_queue(struct isp116x *isp116x)
264 ? PTD_DIR_OUT : PTD_DIR_IN; 262 ? PTD_DIR_OUT : PTD_DIR_IN;
265 break; 263 break;
266 default: 264 default:
267 /* To please gcc */
268 toggle = dir = 0;
269 ERR("%s %d: ep->nextpid %d\n", __func__, __LINE__, 265 ERR("%s %d: ep->nextpid %d\n", __func__, __LINE__,
270 ep->nextpid); 266 ep->nextpid);
271 BUG_ON(1); 267 BUG();
272 } 268 }
273 269
274 ptd->count = PTD_CC_MSK | PTD_ACTIVE_MSK | PTD_TOGGLE(toggle); 270 ptd->count = PTD_CC_MSK | PTD_ACTIVE_MSK | PTD_TOGGLE(toggle);
@@ -697,7 +693,7 @@ static int balance(struct isp116x *isp116x, u16 period, u16 load)
697 693
698static int isp116x_urb_enqueue(struct usb_hcd *hcd, 694static int isp116x_urb_enqueue(struct usb_hcd *hcd,
699 struct usb_host_endpoint *hep, struct urb *urb, 695 struct usb_host_endpoint *hep, struct urb *urb,
700 int mem_flags) 696 unsigned mem_flags)
701{ 697{
702 struct isp116x *isp116x = hcd_to_isp116x(hcd); 698 struct isp116x *isp116x = hcd_to_isp116x(hcd);
703 struct usb_device *udev = urb->dev; 699 struct usb_device *udev = urb->dev;
@@ -719,7 +715,7 @@ static int isp116x_urb_enqueue(struct usb_hcd *hcd,
719 } 715 }
720 /* avoid all allocations within spinlocks: request or endpoint */ 716 /* avoid all allocations within spinlocks: request or endpoint */
721 if (!hep->hcpriv) { 717 if (!hep->hcpriv) {
722 ep = kcalloc(1, sizeof *ep, (__force unsigned)mem_flags); 718 ep = kcalloc(1, sizeof *ep, mem_flags);
723 if (!ep) 719 if (!ep)
724 return -ENOMEM; 720 return -ENOMEM;
725 } 721 }
@@ -1054,7 +1050,7 @@ static int isp116x_hub_control(struct usb_hcd *hcd,
1054 break; 1050 break;
1055 case GetHubStatus: 1051 case GetHubStatus:
1056 DBG("GetHubStatus\n"); 1052 DBG("GetHubStatus\n");
1057 *(__le32 *) buf = cpu_to_le32(0); 1053 *(__le32 *) buf = 0;
1058 break; 1054 break;
1059 case GetPortStatus: 1055 case GetPortStatus:
1060 DBG("GetPortStatus\n"); 1056 DBG("GetPortStatus\n");
@@ -1810,9 +1806,9 @@ static int isp116x_suspend(struct device *dev, pm_message_t state, u32 phase)
1810 ret = usb_suspend_device(hcd->self.root_hub, state); 1806 ret = usb_suspend_device(hcd->self.root_hub, state);
1811 if (!ret) { 1807 if (!ret) {
1812 dev->power.power_state = state; 1808 dev->power.power_state = state;
1813 INFO("%s suspended\n", (char *)hcd_name); 1809 INFO("%s suspended\n", hcd_name);
1814 } else 1810 } else
1815 ERR("%s suspend failed\n", (char *)hcd_name); 1811 ERR("%s suspend failed\n", hcd_name);
1816 1812
1817 return ret; 1813 return ret;
1818} 1814}
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index 13cd2177b557..68decab280dd 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -180,7 +180,7 @@ static int ohci_urb_enqueue (
180 struct usb_hcd *hcd, 180 struct usb_hcd *hcd,
181 struct usb_host_endpoint *ep, 181 struct usb_host_endpoint *ep,
182 struct urb *urb, 182 struct urb *urb,
183 int mem_flags 183 unsigned mem_flags
184) { 184) {
185 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 185 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
186 struct ed *ed; 186 struct ed *ed;
@@ -673,8 +673,10 @@ retry:
673 673
674 ohci_dump (ohci, 1); 674 ohci_dump (ohci, 1);
675 675
676 if (ohci_to_hcd(ohci)->self.root_hub == NULL) 676 if (ohci_to_hcd(ohci)->self.root_hub == NULL) {
677 register_reboot_notifier (&ohci->reboot_notifier);
677 create_debug_files (ohci); 678 create_debug_files (ohci);
679 }
678 680
679 return 0; 681 return 0;
680} 682}
diff --git a/drivers/usb/host/ohci-hub.c b/drivers/usb/host/ohci-hub.c
index e2fc4129dfc6..83ca4549a50e 100644
--- a/drivers/usb/host/ohci-hub.c
+++ b/drivers/usb/host/ohci-hub.c
@@ -419,10 +419,11 @@ ohci_hub_descriptor (
419 419
420 /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */ 420 /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */
421 rh = roothub_b (ohci); 421 rh = roothub_b (ohci);
422 memset(desc->bitmap, 0xff, sizeof(desc->bitmap));
422 desc->bitmap [0] = rh & RH_B_DR; 423 desc->bitmap [0] = rh & RH_B_DR;
423 if (ports > 7) { 424 if (ports > 7) {
424 desc->bitmap [1] = (rh & RH_B_DR) >> 8; 425 desc->bitmap [1] = (rh & RH_B_DR) >> 8;
425 desc->bitmap [2] = desc->bitmap [3] = 0xff; 426 desc->bitmap [2] = 0xff;
426 } else 427 } else
427 desc->bitmap [1] = 0xff; 428 desc->bitmap [1] = 0xff;
428} 429}
diff --git a/drivers/usb/host/ohci-mem.c b/drivers/usb/host/ohci-mem.c
index 23735a36af00..fd3c4d3714bd 100644
--- a/drivers/usb/host/ohci-mem.c
+++ b/drivers/usb/host/ohci-mem.c
@@ -84,7 +84,7 @@ dma_to_td (struct ohci_hcd *hc, dma_addr_t td_dma)
84 84
85/* TDs ... */ 85/* TDs ... */
86static struct td * 86static struct td *
87td_alloc (struct ohci_hcd *hc, int mem_flags) 87td_alloc (struct ohci_hcd *hc, unsigned mem_flags)
88{ 88{
89 dma_addr_t dma; 89 dma_addr_t dma;
90 struct td *td; 90 struct td *td;
@@ -118,7 +118,7 @@ td_free (struct ohci_hcd *hc, struct td *td)
118 118
119/* EDs ... */ 119/* EDs ... */
120static struct ed * 120static struct ed *
121ed_alloc (struct ohci_hcd *hc, int mem_flags) 121ed_alloc (struct ohci_hcd *hc, unsigned mem_flags)
122{ 122{
123 dma_addr_t dma; 123 dma_addr_t dma;
124 struct ed *ed; 124 struct ed *ed;
diff --git a/drivers/usb/host/ohci-omap.c b/drivers/usb/host/ohci-omap.c
index b62d69937694..5cde76faab93 100644
--- a/drivers/usb/host/ohci-omap.c
+++ b/drivers/usb/host/ohci-omap.c
@@ -456,34 +456,22 @@ static int ohci_hcd_omap_drv_remove(struct device *dev)
456 456
457#ifdef CONFIG_PM 457#ifdef CONFIG_PM
458 458
459/* states match PCI usage, always suspending the root hub except that 459static int ohci_omap_suspend(struct device *dev, pm_message_t message, u32 level)
460 * 4 ~= D3cold (ACPI D3) with clock off (resume sees reset).
461 *
462 * FIXME: above comment is not right, and code is wrong, too :-(.
463 */
464
465static int ohci_omap_suspend(struct device *dev, pm_message_t state, u32 level)
466{ 460{
467 struct ohci_hcd *ohci = hcd_to_ohci(dev_get_drvdata(dev)); 461 struct ohci_hcd *ohci = hcd_to_ohci(dev_get_drvdata(dev));
468 int status = -EINVAL; 462 int status = -EINVAL;
469 463
470 if (level != SUSPEND_POWER_DOWN) 464 if (level != SUSPEND_POWER_DOWN)
471 return 0; 465 return 0;
472 if (state <= dev->power.power_state)
473 return 0;
474 466
475 dev_dbg(dev, "suspend to %d\n", state);
476 down(&ohci_to_hcd(ohci)->self.root_hub->serialize); 467 down(&ohci_to_hcd(ohci)->self.root_hub->serialize);
477 status = ohci_hub_suspend(ohci_to_hcd(ohci)); 468 status = ohci_hub_suspend(ohci_to_hcd(ohci));
478 if (status == 0) { 469 if (status == 0) {
479 if (state >= 4) { 470 omap_ohci_clock_power(0);
480 omap_ohci_clock_power(0); 471 ohci_to_hcd(ohci)->self.root_hub->state =
481 ohci_to_hcd(ohci)->self.root_hub->state = 472 USB_STATE_SUSPENDED;
482 USB_STATE_SUSPENDED;
483 state = 4;
484 }
485 ohci_to_hcd(ohci)->state = HC_STATE_SUSPENDED; 473 ohci_to_hcd(ohci)->state = HC_STATE_SUSPENDED;
486 dev->power.power_state = state; 474 dev->power.power_state = PMSG_SUSPEND;
487 } 475 }
488 up(&ohci_to_hcd(ohci)->self.root_hub->serialize); 476 up(&ohci_to_hcd(ohci)->self.root_hub->serialize);
489 return status; 477 return status;
@@ -497,29 +485,20 @@ static int ohci_omap_resume(struct device *dev, u32 level)
497 if (level != RESUME_POWER_ON) 485 if (level != RESUME_POWER_ON)
498 return 0; 486 return 0;
499 487
500 switch (dev->power.power_state) { 488 if (time_before(jiffies, ohci->next_statechange))
501 case 0: 489 msleep(5);
502 break; 490 ohci->next_statechange = jiffies;
503 case 4: 491 omap_ohci_clock_power(1);
504 if (time_before(jiffies, ohci->next_statechange))
505 msleep(5);
506 ohci->next_statechange = jiffies;
507 omap_ohci_clock_power(1);
508 /* FALLTHROUGH */
509 default:
510 dev_dbg(dev, "resume from %d\n", dev->power.power_state);
511#ifdef CONFIG_USB_SUSPEND 492#ifdef CONFIG_USB_SUSPEND
512 /* get extra cleanup even if remote wakeup isn't in use */ 493 /* get extra cleanup even if remote wakeup isn't in use */
513 status = usb_resume_device(ohci_to_hcd(ohci)->self.root_hub); 494 status = usb_resume_device(ohci_to_hcd(ohci)->self.root_hub);
514#else 495#else
515 down(&ohci_to_hcd(ohci)->self.root_hub->serialize); 496 down(&ohci_to_hcd(ohci)->self.root_hub->serialize);
516 status = ohci_hub_resume(ohci_to_hcd(ohci)); 497 status = ohci_hub_resume(ohci_to_hcd(ohci));
517 up(&ohci_to_hcd(ohci)->self.root_hub->serialize); 498 up(&ohci_to_hcd(ohci)->self.root_hub->serialize);
518#endif 499#endif
519 if (status == 0) 500 if (status == 0)
520 dev->power.power_state = 0; 501 dev->power.power_state = PMSG_ON;
521 break;
522 }
523 return status; 502 return status;
524} 503}
525 504
diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c
index 6c3f910bc307..7a890a65f55d 100644
--- a/drivers/usb/host/sl811-hcd.c
+++ b/drivers/usb/host/sl811-hcd.c
@@ -815,7 +815,7 @@ static int sl811h_urb_enqueue(
815 struct usb_hcd *hcd, 815 struct usb_hcd *hcd,
816 struct usb_host_endpoint *hep, 816 struct usb_host_endpoint *hep,
817 struct urb *urb, 817 struct urb *urb,
818 int mem_flags 818 unsigned mem_flags
819) { 819) {
820 struct sl811 *sl811 = hcd_to_sl811(hcd); 820 struct sl811 *sl811 = hcd_to_sl811(hcd);
821 struct usb_device *udev = urb->dev; 821 struct usb_device *udev = urb->dev;
diff --git a/drivers/usb/host/uhci-q.c b/drivers/usb/host/uhci-q.c
index 5f18084a116d..bbb36cd6ed61 100644
--- a/drivers/usb/host/uhci-q.c
+++ b/drivers/usb/host/uhci-q.c
@@ -1164,7 +1164,7 @@ static struct urb *uhci_find_urb_ep(struct uhci_hcd *uhci, struct urb *urb)
1164 1164
1165static int uhci_urb_enqueue(struct usb_hcd *hcd, 1165static int uhci_urb_enqueue(struct usb_hcd *hcd,
1166 struct usb_host_endpoint *ep, 1166 struct usb_host_endpoint *ep,
1167 struct urb *urb, int mem_flags) 1167 struct urb *urb, unsigned mem_flags)
1168{ 1168{
1169 int ret; 1169 int ret;
1170 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 1170 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
diff --git a/drivers/usb/input/Kconfig b/drivers/usb/input/Kconfig
index fd59f6bdd67f..298e4a25e3d3 100644
--- a/drivers/usb/input/Kconfig
+++ b/drivers/usb/input/Kconfig
@@ -259,3 +259,16 @@ config USB_ATI_REMOTE
259 To compile this driver as a module, choose M here: the module will be 259 To compile this driver as a module, choose M here: the module will be
260 called ati_remote. 260 called ati_remote.
261 261
262config USB_KEYSPAN_REMOTE
263 tristate "Keyspan DMR USB remote control (EXPERIMENTAL)"
264 depends on USB && INPUT && EXPERIMENTAL
265 ---help---
266 Say Y here if you want to use a Keyspan DMR USB remote control.
267 Currently only the UIA-11 type of receiver has been tested. The tag
268 on the receiver that connects to the USB port should have a P/N that
269 will tell you what type of DMR you have. The UIA-10 type is not
270 supported at this time. This driver maps all buttons to keypress
271 events.
272
273 To compile this driver as a module, choose M here: the module will
274 be called keyspan_remote.
diff --git a/drivers/usb/input/Makefile b/drivers/usb/input/Makefile
index 831b2b0f1f05..f1547be632d4 100644
--- a/drivers/usb/input/Makefile
+++ b/drivers/usb/input/Makefile
@@ -31,6 +31,7 @@ obj-$(CONFIG_USB_ATI_REMOTE) += ati_remote.o
31obj-$(CONFIG_USB_HID) += usbhid.o 31obj-$(CONFIG_USB_HID) += usbhid.o
32obj-$(CONFIG_USB_KBD) += usbkbd.o 32obj-$(CONFIG_USB_KBD) += usbkbd.o
33obj-$(CONFIG_USB_KBTAB) += kbtab.o 33obj-$(CONFIG_USB_KBTAB) += kbtab.o
34obj-$(CONFIG_USB_KEYSPAN_REMOTE) += keyspan_remote.o
34obj-$(CONFIG_USB_MOUSE) += usbmouse.o 35obj-$(CONFIG_USB_MOUSE) += usbmouse.o
35obj-$(CONFIG_USB_MTOUCH) += mtouchusb.o 36obj-$(CONFIG_USB_MTOUCH) += mtouchusb.o
36obj-$(CONFIG_USB_ITMTOUCH) += itmtouch.o 37obj-$(CONFIG_USB_ITMTOUCH) += itmtouch.o
diff --git a/drivers/usb/input/hid-core.c b/drivers/usb/input/hid-core.c
index 100b49bd1d3e..2350e7a5ad70 100644
--- a/drivers/usb/input/hid-core.c
+++ b/drivers/usb/input/hid-core.c
@@ -1428,6 +1428,19 @@ void hid_init_reports(struct hid_device *hid)
1428#define USB_DEVICE_ID_VERNIER_SKIP 0x0003 1428#define USB_DEVICE_ID_VERNIER_SKIP 0x0003
1429#define USB_DEVICE_ID_VERNIER_CYCLOPS 0x0004 1429#define USB_DEVICE_ID_VERNIER_CYCLOPS 0x0004
1430 1430
1431#define USB_VENDOR_ID_LD 0x0f11
1432#define USB_DEVICE_ID_CASSY 0x1000
1433#define USB_DEVICE_ID_POCKETCASSY 0x1010
1434#define USB_DEVICE_ID_MOBILECASSY 0x1020
1435#define USB_DEVICE_ID_JWM 0x1080
1436#define USB_DEVICE_ID_DMMP 0x1081
1437#define USB_DEVICE_ID_UMIP 0x1090
1438#define USB_DEVICE_ID_VIDEOCOM 0x1200
1439#define USB_DEVICE_ID_COM3LAB 0x2000
1440#define USB_DEVICE_ID_TELEPORT 0x2010
1441#define USB_DEVICE_ID_NETWORKANALYSER 0x2020
1442#define USB_DEVICE_ID_POWERCONTROL 0x2030
1443
1431 1444
1432/* 1445/*
1433 * Alphabetically sorted blacklist by quirk type. 1446 * Alphabetically sorted blacklist by quirk type.
@@ -1463,6 +1476,17 @@ static struct hid_blacklist {
1463 { USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_POWERMATE, HID_QUIRK_IGNORE }, 1476 { USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_POWERMATE, HID_QUIRK_IGNORE },
1464 { USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_SOUNDKNOB, HID_QUIRK_IGNORE }, 1477 { USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_SOUNDKNOB, HID_QUIRK_IGNORE },
1465 { USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO, HID_QUIRK_IGNORE }, 1478 { USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO, HID_QUIRK_IGNORE },
1479 { USB_VENDOR_ID_LD, USB_DEVICE_ID_CASSY, HID_QUIRK_IGNORE },
1480 { USB_VENDOR_ID_LD, USB_DEVICE_ID_POCKETCASSY, HID_QUIRK_IGNORE },
1481 { USB_VENDOR_ID_LD, USB_DEVICE_ID_MOBILECASSY, HID_QUIRK_IGNORE },
1482 { USB_VENDOR_ID_LD, USB_DEVICE_ID_JWM, HID_QUIRK_IGNORE },
1483 { USB_VENDOR_ID_LD, USB_DEVICE_ID_DMMP, HID_QUIRK_IGNORE },
1484 { USB_VENDOR_ID_LD, USB_DEVICE_ID_UMIP, HID_QUIRK_IGNORE },
1485 { USB_VENDOR_ID_LD, USB_DEVICE_ID_VIDEOCOM, HID_QUIRK_IGNORE },
1486 { USB_VENDOR_ID_LD, USB_DEVICE_ID_COM3LAB, HID_QUIRK_IGNORE },
1487 { USB_VENDOR_ID_LD, USB_DEVICE_ID_TELEPORT, HID_QUIRK_IGNORE },
1488 { USB_VENDOR_ID_LD, USB_DEVICE_ID_NETWORKANALYSER, HID_QUIRK_IGNORE },
1489 { USB_VENDOR_ID_LD, USB_DEVICE_ID_POWERCONTROL, HID_QUIRK_IGNORE },
1466 { USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1024LS, HID_QUIRK_IGNORE }, 1490 { USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1024LS, HID_QUIRK_IGNORE },
1467 { USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1208LS, HID_QUIRK_IGNORE }, 1491 { USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1208LS, HID_QUIRK_IGNORE },
1468 { USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS, HID_QUIRK_IGNORE }, 1492 { USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS, HID_QUIRK_IGNORE },
diff --git a/drivers/usb/input/keyspan_remote.c b/drivers/usb/input/keyspan_remote.c
new file mode 100644
index 000000000000..67dc93685203
--- /dev/null
+++ b/drivers/usb/input/keyspan_remote.c
@@ -0,0 +1,633 @@
1/*
2 * keyspan_remote: USB driver for the Keyspan DMR
3 *
4 * Copyright (C) 2005 Zymeta Corporation - Michael Downey (downey@zymeta.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2.
9 *
10 * This driver has been put together with the support of Innosys, Inc.
11 * and Keyspan, Inc the manufacturers of the Keyspan USB DMR product.
12 */
13
14#include <linux/config.h>
15#include <linux/kernel.h>
16#include <linux/errno.h>
17#include <linux/init.h>
18#include <linux/slab.h>
19#include <linux/module.h>
20#include <linux/moduleparam.h>
21#include <linux/input.h>
22#include <linux/usb.h>
23
24#define DRIVER_VERSION "v0.1"
25#define DRIVER_AUTHOR "Michael Downey <downey@zymeta.com>"
26#define DRIVER_DESC "Driver for the USB Keyspan remote control."
27#define DRIVER_LICENSE "GPL"
28
29/* Parameters that can be passed to the driver. */
30static int debug;
31module_param(debug, int, 0444);
32MODULE_PARM_DESC(debug, "Enable extra debug messages and information");
33
34/* Vendor and product ids */
35#define USB_KEYSPAN_VENDOR_ID 0x06CD
36#define USB_KEYSPAN_PRODUCT_UIA11 0x0202
37
38/* Defines for converting the data from the remote. */
39#define ZERO 0x18
40#define ZERO_MASK 0x1F /* 5 bits for a 0 */
41#define ONE 0x3C
42#define ONE_MASK 0x3F /* 6 bits for a 1 */
43#define SYNC 0x3F80
44#define SYNC_MASK 0x3FFF /* 14 bits for a SYNC sequence */
45#define STOP 0x00
46#define STOP_MASK 0x1F /* 5 bits for the STOP sequence */
47#define GAP 0xFF
48
49#define RECV_SIZE 8 /* The UIA-11 type have a 8 byte limit. */
50
51/* table of devices that work with this driver */
52static struct usb_device_id keyspan_table[] = {
53 { USB_DEVICE(USB_KEYSPAN_VENDOR_ID, USB_KEYSPAN_PRODUCT_UIA11) },
54 { } /* Terminating entry */
55};
56
57/* Structure to store all the real stuff that a remote sends to us. */
58struct keyspan_message {
59 u16 system;
60 u8 button;
61 u8 toggle;
62};
63
64/* Structure used for all the bit testing magic needed to be done. */
65struct bit_tester {
66 u32 tester;
67 int len;
68 int pos;
69 int bits_left;
70 u8 buffer[32];
71};
72
73/* Structure to hold all of our driver specific stuff */
74struct usb_keyspan {
75 char name[128];
76 char phys[64];
77 struct usb_device* udev;
78 struct input_dev input;
79 struct usb_interface* interface;
80 struct usb_endpoint_descriptor* in_endpoint;
81 struct urb* irq_urb;
82 int open;
83 dma_addr_t in_dma;
84 unsigned char* in_buffer;
85
86 /* variables used to parse messages from remote. */
87 struct bit_tester data;
88 int stage;
89 int toggle;
90};
91
92/*
93 * Table that maps the 31 possible keycodes to input keys.
94 * Currently there are 15 and 17 button models so RESERVED codes
95 * are blank areas in the mapping.
96 */
97static int keyspan_key_table[] = {
98 KEY_RESERVED, /* 0 is just a place holder. */
99 KEY_RESERVED,
100 KEY_STOP,
101 KEY_PLAYCD,
102 KEY_RESERVED,
103 KEY_PREVIOUSSONG,
104 KEY_REWIND,
105 KEY_FORWARD,
106 KEY_NEXTSONG,
107 KEY_RESERVED,
108 KEY_RESERVED,
109 KEY_RESERVED,
110 KEY_PAUSE,
111 KEY_VOLUMEUP,
112 KEY_RESERVED,
113 KEY_RESERVED,
114 KEY_RESERVED,
115 KEY_VOLUMEDOWN,
116 KEY_RESERVED,
117 KEY_UP,
118 KEY_RESERVED,
119 KEY_MUTE,
120 KEY_LEFT,
121 KEY_ENTER,
122 KEY_RIGHT,
123 KEY_RESERVED,
124 KEY_RESERVED,
125 KEY_DOWN,
126 KEY_RESERVED,
127 KEY_KPASTERISK,
128 KEY_RESERVED,
129 KEY_MENU
130};
131
132static struct usb_driver keyspan_driver;
133
134/*
135 * Debug routine that prints out what we've received from the remote.
136 */
137static void keyspan_print(struct usb_keyspan* dev) /*unsigned char* data)*/
138{
139 char codes[4*RECV_SIZE];
140 int i;
141
142 for (i = 0; i < RECV_SIZE; i++) {
143 snprintf(codes+i*3, 4, "%02x ", dev->in_buffer[i]);
144 }
145
146 dev_info(&dev->udev->dev, "%s\n", codes);
147}
148
149/*
150 * Routine that manages the bit_tester structure. It makes sure that there are
151 * at least bits_needed bits loaded into the tester.
152 */
153static int keyspan_load_tester(struct usb_keyspan* dev, int bits_needed)
154{
155 if (dev->data.bits_left >= bits_needed)
156 return(0);
157
158 /*
159 * Somehow we've missed the last message. The message will be repeated
160 * though so it's not too big a deal
161 */
162 if (dev->data.pos >= dev->data.len) {
163 dev_dbg(&dev->udev, "%s - Error ran out of data. pos: %d, len: %d\n",
164 __FUNCTION__, dev->data.pos, dev->data.len);
165 return(-1);
166 }
167
168 /* Load as much as we can into the tester. */
169 while ((dev->data.bits_left + 7 < (sizeof(dev->data.tester) * 8)) &&
170 (dev->data.pos < dev->data.len)) {
171 dev->data.tester += (dev->data.buffer[dev->data.pos++] << dev->data.bits_left);
172 dev->data.bits_left += 8;
173 }
174
175 return(0);
176}
177
178/*
179 * Routine that handles all the logic needed to parse out the message from the remote.
180 */
181static void keyspan_check_data(struct usb_keyspan *remote, struct pt_regs *regs)
182{
183 int i;
184 int found = 0;
185 struct keyspan_message message;
186
187 switch(remote->stage) {
188 case 0:
189 /*
190 * In stage 0 we want to find the start of a message. The remote sends a 0xFF as filler.
191 * So the first byte that isn't a FF should be the start of a new message.
192 */
193 for (i = 0; i < RECV_SIZE && remote->in_buffer[i] == GAP; ++i);
194
195 if (i < RECV_SIZE) {
196 memcpy(remote->data.buffer, remote->in_buffer, RECV_SIZE);
197 remote->data.len = RECV_SIZE;
198 remote->data.pos = 0;
199 remote->data.tester = 0;
200 remote->data.bits_left = 0;
201 remote->stage = 1;
202 }
203 break;
204
205 case 1:
206 /*
207 * Stage 1 we should have 16 bytes and should be able to detect a
208 * SYNC. The SYNC is 14 bits, 7 0's and then 7 1's.
209 */
210 memcpy(remote->data.buffer + remote->data.len, remote->in_buffer, RECV_SIZE);
211 remote->data.len += RECV_SIZE;
212
213 found = 0;
214 while ((remote->data.bits_left >= 14 || remote->data.pos < remote->data.len) && !found) {
215 for (i = 0; i < 8; ++i) {
216 if (keyspan_load_tester(remote, 14) != 0) {
217 remote->stage = 0;
218 return;
219 }
220
221 if ((remote->data.tester & SYNC_MASK) == SYNC) {
222 remote->data.tester = remote->data.tester >> 14;
223 remote->data.bits_left -= 14;
224 found = 1;
225 break;
226 } else {
227 remote->data.tester = remote->data.tester >> 1;
228 --remote->data.bits_left;
229 }
230 }
231 }
232
233 if (!found) {
234 remote->stage = 0;
235 remote->data.len = 0;
236 } else {
237 remote->stage = 2;
238 }
239 break;
240
241 case 2:
242 /*
243 * Stage 2 we should have 24 bytes which will be enough for a full
244 * message. We need to parse out the system code, button code,
245 * toggle code, and stop.
246 */
247 memcpy(remote->data.buffer + remote->data.len, remote->in_buffer, RECV_SIZE);
248 remote->data.len += RECV_SIZE;
249
250 message.system = 0;
251 for (i = 0; i < 9; i++) {
252 keyspan_load_tester(remote, 6);
253
254 if ((remote->data.tester & ZERO_MASK) == ZERO) {
255 message.system = message.system << 1;
256 remote->data.tester = remote->data.tester >> 5;
257 remote->data.bits_left -= 5;
258 } else if ((remote->data.tester & ONE_MASK) == ONE) {
259 message.system = (message.system << 1) + 1;
260 remote->data.tester = remote->data.tester >> 6;
261 remote->data.bits_left -= 6;
262 } else {
263 err("%s - Unknown sequence found in system data.\n", __FUNCTION__);
264 remote->stage = 0;
265 return;
266 }
267 }
268
269 message.button = 0;
270 for (i = 0; i < 5; i++) {
271 keyspan_load_tester(remote, 6);
272
273 if ((remote->data.tester & ZERO_MASK) == ZERO) {
274 message.button = message.button << 1;
275 remote->data.tester = remote->data.tester >> 5;
276 remote->data.bits_left -= 5;
277 } else if ((remote->data.tester & ONE_MASK) == ONE) {
278 message.button = (message.button << 1) + 1;
279 remote->data.tester = remote->data.tester >> 6;
280 remote->data.bits_left -= 6;
281 } else {
282 err("%s - Unknown sequence found in button data.\n", __FUNCTION__);
283 remote->stage = 0;
284 return;
285 }
286 }
287
288 keyspan_load_tester(remote, 6);
289 if ((remote->data.tester & ZERO_MASK) == ZERO) {
290 message.toggle = 0;
291 remote->data.tester = remote->data.tester >> 5;
292 remote->data.bits_left -= 5;
293 } else if ((remote->data.tester & ONE_MASK) == ONE) {
294 message.toggle = 1;
295 remote->data.tester = remote->data.tester >> 6;
296 remote->data.bits_left -= 6;
297 } else {
298 err("%s - Error in message, invalid toggle.\n", __FUNCTION__);
299 }
300
301 keyspan_load_tester(remote, 5);
302 if ((remote->data.tester & STOP_MASK) == STOP) {
303 remote->data.tester = remote->data.tester >> 5;
304 remote->data.bits_left -= 5;
305 } else {
306 err("Bad message recieved, no stop bit found.\n");
307 }
308
309 dev_dbg(&remote->udev,
310 "%s found valid message: system: %d, button: %d, toggle: %d\n",
311 __FUNCTION__, message.system, message.button, message.toggle);
312
313 if (message.toggle != remote->toggle) {
314 input_regs(&remote->input, regs);
315 input_report_key(&remote->input, keyspan_key_table[message.button], 1);
316 input_report_key(&remote->input, keyspan_key_table[message.button], 0);
317 input_sync(&remote->input);
318 remote->toggle = message.toggle;
319 }
320
321 remote->stage = 0;
322 break;
323 }
324}
325
326/*
327 * Routine for sending all the initialization messages to the remote.
328 */
329static int keyspan_setup(struct usb_device* dev)
330{
331 int retval = 0;
332
333 retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
334 0x11, 0x40, 0x5601, 0x0, NULL, 0, 0);
335 if (retval) {
336 dev_dbg(&dev->dev, "%s - failed to set bit rate due to error: %d\n",
337 __FUNCTION__, retval);
338 return(retval);
339 }
340
341 retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
342 0x44, 0x40, 0x0, 0x0, NULL, 0, 0);
343 if (retval) {
344 dev_dbg(&dev->dev, "%s - failed to set resume sensitivity due to error: %d\n",
345 __FUNCTION__, retval);
346 return(retval);
347 }
348
349 retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
350 0x22, 0x40, 0x0, 0x0, NULL, 0, 0);
351 if (retval) {
352 dev_dbg(&dev->dev, "%s - failed to turn receive on due to error: %d\n",
353 __FUNCTION__, retval);
354 return(retval);
355 }
356
357 dev_dbg(&dev->dev, "%s - Setup complete.\n", __FUNCTION__);
358 return(retval);
359}
360
361/*
362 * Routine used to handle a new message that has come in.
363 */
364static void keyspan_irq_recv(struct urb *urb, struct pt_regs *regs)
365{
366 struct usb_keyspan *dev = urb->context;
367 int retval;
368
369 /* Check our status in case we need to bail out early. */
370 switch (urb->status) {
371 case 0:
372 break;
373
374 /* Device went away so don't keep trying to read from it. */
375 case -ECONNRESET:
376 case -ENOENT:
377 case -ESHUTDOWN:
378 return;
379
380 default:
381 goto resubmit;
382 break;
383 }
384
385 if (debug)
386 keyspan_print(dev);
387
388 keyspan_check_data(dev, regs);
389
390resubmit:
391 retval = usb_submit_urb(urb, GFP_ATOMIC);
392 if (retval)
393 err ("%s - usb_submit_urb failed with result: %d", __FUNCTION__, retval);
394}
395
396static int keyspan_open(struct input_dev *dev)
397{
398 struct usb_keyspan *remote = dev->private;
399
400 if (remote->open++)
401 return 0;
402
403 remote->irq_urb->dev = remote->udev;
404 if (usb_submit_urb(remote->irq_urb, GFP_KERNEL)) {
405 remote->open--;
406 return -EIO;
407 }
408
409 return 0;
410}
411
412static void keyspan_close(struct input_dev *dev)
413{
414 struct usb_keyspan *remote = dev->private;
415
416 if (!--remote->open)
417 usb_kill_urb(remote->irq_urb);
418}
419
420/*
421 * Routine that sets up the driver to handle a specific USB device detected on the bus.
422 */
423static int keyspan_probe(struct usb_interface *interface, const struct usb_device_id *id)
424{
425 int i;
426 int retval = -ENOMEM;
427 char path[64];
428 char *buf;
429 struct usb_keyspan *remote = NULL;
430 struct usb_host_interface *iface_desc;
431 struct usb_endpoint_descriptor *endpoint;
432 struct usb_device *udev = usb_get_dev(interface_to_usbdev(interface));
433
434 /* See if the offered device matches what we can accept */
435 if ((udev->descriptor.idVendor != USB_KEYSPAN_VENDOR_ID) ||
436 (udev->descriptor.idProduct != USB_KEYSPAN_PRODUCT_UIA11) )
437 return -ENODEV;
438
439 /* allocate memory for our device state and initialize it */
440 remote = kmalloc(sizeof(*remote), GFP_KERNEL);
441 if (remote == NULL) {
442 err("Out of memory\n");
443 goto error;
444 }
445 memset(remote, 0x00, sizeof(*remote));
446
447 remote->udev = udev;
448 remote->interface = interface;
449 remote->toggle = -1; /* Set to -1 so we will always not match the toggle from the first remote message. */
450
451 /* set up the endpoint information */
452 /* use only the first in interrupt endpoint */
453 iface_desc = interface->cur_altsetting;
454 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
455 endpoint = &iface_desc->endpoint[i].desc;
456
457 if (!remote->in_endpoint &&
458 (endpoint->bEndpointAddress & USB_DIR_IN) &&
459 ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT)) {
460 /* we found our interrupt in endpoint */
461 remote->in_endpoint = endpoint;
462
463 remote->in_buffer = usb_buffer_alloc(remote->udev, RECV_SIZE, SLAB_ATOMIC, &remote->in_dma);
464 if (!remote->in_buffer) {
465 retval = -ENOMEM;
466 goto error;
467 }
468 }
469 }
470
471 if (!remote->in_endpoint) {
472 err("Could not find interrupt input endpoint.\n");
473 retval = -ENODEV;
474 goto error;
475 }
476
477 remote->irq_urb = usb_alloc_urb(0, GFP_KERNEL);
478 if (!remote->irq_urb) {
479 err("Failed to allocate urb.\n");
480 retval = -ENOMEM;
481 goto error;
482 }
483
484 retval = keyspan_setup(remote->udev);
485 if (retval) {
486 err("Failed to setup device.\n");
487 retval = -ENODEV;
488 goto error;
489 }
490
491 /*
492 * Setup the input system with the bits we are going to be reporting
493 */
494 remote->input.evbit[0] = BIT(EV_KEY); /* We will only report KEY events. */
495 for (i = 0; i < 32; ++i) {
496 if (keyspan_key_table[i] != KEY_RESERVED) {
497 set_bit(keyspan_key_table[i], remote->input.keybit);
498 }
499 }
500
501 remote->input.private = remote;
502 remote->input.open = keyspan_open;
503 remote->input.close = keyspan_close;
504
505 usb_make_path(remote->udev, path, 64);
506 sprintf(remote->phys, "%s/input0", path);
507
508 remote->input.name = remote->name;
509 remote->input.phys = remote->phys;
510 remote->input.id.bustype = BUS_USB;
511 remote->input.id.vendor = le16_to_cpu(remote->udev->descriptor.idVendor);
512 remote->input.id.product = le16_to_cpu(remote->udev->descriptor.idProduct);
513 remote->input.id.version = le16_to_cpu(remote->udev->descriptor.bcdDevice);
514
515 if (!(buf = kmalloc(63, GFP_KERNEL))) {
516 usb_buffer_free(remote->udev, RECV_SIZE, remote->in_buffer, remote->in_dma);
517 kfree(remote);
518 return -ENOMEM;
519 }
520
521 if (remote->udev->descriptor.iManufacturer &&
522 usb_string(remote->udev, remote->udev->descriptor.iManufacturer, buf, 63) > 0)
523 strcat(remote->name, buf);
524
525 if (remote->udev->descriptor.iProduct &&
526 usb_string(remote->udev, remote->udev->descriptor.iProduct, buf, 63) > 0)
527 sprintf(remote->name, "%s %s", remote->name, buf);
528
529 if (!strlen(remote->name))
530 sprintf(remote->name, "USB Keyspan Remote %04x:%04x",
531 remote->input.id.vendor, remote->input.id.product);
532
533 kfree(buf);
534
535 /*
536 * Initialize the URB to access the device. The urb gets sent to the device in keyspan_open()
537 */
538 usb_fill_int_urb(remote->irq_urb,
539 remote->udev, usb_rcvintpipe(remote->udev, remote->in_endpoint->bEndpointAddress),
540 remote->in_buffer, RECV_SIZE, keyspan_irq_recv, remote,
541 remote->in_endpoint->bInterval);
542 remote->irq_urb->transfer_dma = remote->in_dma;
543 remote->irq_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
544
545 /* we can register the device now, as it is ready */
546 input_register_device(&remote->input);
547
548 /* save our data pointer in this interface device */
549 usb_set_intfdata(interface, remote);
550
551 /* let the user know what node this device is now attached to */
552 info("connected: %s on %s", remote->name, path);
553 return 0;
554
555error:
556 /*
557 * In case of error we need to clean up any allocated buffers
558 */
559 if (remote->irq_urb)
560 usb_free_urb(remote->irq_urb);
561
562 if (remote->in_buffer)
563 usb_buffer_free(remote->udev, RECV_SIZE, remote->in_buffer, remote->in_dma);
564
565 if (remote)
566 kfree(remote);
567
568 return retval;
569}
570
571/*
572 * Routine called when a device is disconnected from the USB.
573 */
574static void keyspan_disconnect(struct usb_interface *interface)
575{
576 struct usb_keyspan *remote;
577
578 /* prevent keyspan_open() from racing keyspan_disconnect() */
579 lock_kernel();
580
581 remote = usb_get_intfdata(interface);
582 usb_set_intfdata(interface, NULL);
583
584 if (remote) { /* We have a valid driver structure so clean up everything we allocated. */
585 input_unregister_device(&remote->input);
586 usb_kill_urb(remote->irq_urb);
587 usb_free_urb(remote->irq_urb);
588 usb_buffer_free(interface_to_usbdev(interface), RECV_SIZE, remote->in_buffer, remote->in_dma);
589 kfree(remote);
590 }
591
592 unlock_kernel();
593
594 info("USB Keyspan now disconnected");
595}
596
597/*
598 * Standard driver set up sections
599 */
600static struct usb_driver keyspan_driver =
601{
602 .owner = THIS_MODULE,
603 .name = "keyspan_remote",
604 .probe = keyspan_probe,
605 .disconnect = keyspan_disconnect,
606 .id_table = keyspan_table
607};
608
609static int __init usb_keyspan_init(void)
610{
611 int result;
612
613 /* register this driver with the USB subsystem */
614 result = usb_register(&keyspan_driver);
615 if (result)
616 err("usb_register failed. Error number %d\n", result);
617
618 return result;
619}
620
621static void __exit usb_keyspan_exit(void)
622{
623 /* deregister this driver with the USB subsystem */
624 usb_deregister(&keyspan_driver);
625}
626
627module_init(usb_keyspan_init);
628module_exit(usb_keyspan_exit);
629
630MODULE_DEVICE_TABLE(usb, keyspan_table);
631MODULE_AUTHOR(DRIVER_AUTHOR);
632MODULE_DESCRIPTION(DRIVER_DESC);
633MODULE_LICENSE(DRIVER_LICENSE);
diff --git a/drivers/usb/media/Makefile b/drivers/usb/media/Makefile
index 2b76df7005fe..d83adffa925f 100644
--- a/drivers/usb/media/Makefile
+++ b/drivers/usb/media/Makefile
@@ -2,7 +2,7 @@
2# Makefile for USB Media drivers 2# Makefile for USB Media drivers
3# 3#
4 4
5sn9c102-objs := sn9c102_core.o sn9c102_hv7131d.o sn9c102_mi0343.o sn9c102_pas106b.o sn9c102_pas202bcb.o sn9c102_tas5110c1b.o sn9c102_tas5130d1b.o 5sn9c102-objs := sn9c102_core.o sn9c102_hv7131d.o sn9c102_mi0343.o sn9c102_ov7630.o sn9c102_pas106b.o sn9c102_pas202bcb.o sn9c102_tas5110c1b.o sn9c102_tas5130d1b.o
6 6
7obj-$(CONFIG_USB_DABUSB) += dabusb.o 7obj-$(CONFIG_USB_DABUSB) += dabusb.o
8obj-$(CONFIG_USB_DSBR) += dsbr100.o 8obj-$(CONFIG_USB_DSBR) += dsbr100.o
diff --git a/drivers/usb/media/sn9c102.h b/drivers/usb/media/sn9c102.h
index 8b8a4c8743f8..e5cea0e2eb57 100644
--- a/drivers/usb/media/sn9c102.h
+++ b/drivers/usb/media/sn9c102.h
@@ -56,7 +56,7 @@
56#define SN9C102_MODULE_AUTHOR "(C) 2004-2005 Luca Risolia" 56#define SN9C102_MODULE_AUTHOR "(C) 2004-2005 Luca Risolia"
57#define SN9C102_AUTHOR_EMAIL "<luca.risolia@studio.unibo.it>" 57#define SN9C102_AUTHOR_EMAIL "<luca.risolia@studio.unibo.it>"
58#define SN9C102_MODULE_LICENSE "GPL" 58#define SN9C102_MODULE_LICENSE "GPL"
59#define SN9C102_MODULE_VERSION "1:1.24" 59#define SN9C102_MODULE_VERSION "1:1.24a"
60#define SN9C102_MODULE_VERSION_CODE KERNEL_VERSION(1, 0, 24) 60#define SN9C102_MODULE_VERSION_CODE KERNEL_VERSION(1, 0, 24)
61 61
62enum sn9c102_bridge { 62enum sn9c102_bridge {
diff --git a/drivers/usb/media/sn9c102_core.c b/drivers/usb/media/sn9c102_core.c
index 31d57400d5be..cf8cfbabefde 100644
--- a/drivers/usb/media/sn9c102_core.c
+++ b/drivers/usb/media/sn9c102_core.c
@@ -429,7 +429,7 @@ sn9c102_i2c_try_read(struct sn9c102_device* cam,
429} 429}
430 430
431 431
432static int 432int
433sn9c102_i2c_try_write(struct sn9c102_device* cam, 433sn9c102_i2c_try_write(struct sn9c102_device* cam,
434 struct sn9c102_sensor* sensor, u8 address, u8 value) 434 struct sn9c102_sensor* sensor, u8 address, u8 value)
435{ 435{
diff --git a/drivers/usb/media/sn9c102_ov7630.c b/drivers/usb/media/sn9c102_ov7630.c
new file mode 100644
index 000000000000..d27c5aedeaf8
--- /dev/null
+++ b/drivers/usb/media/sn9c102_ov7630.c
@@ -0,0 +1,394 @@
1/***************************************************************************
2 * Plug-in for OV7630 image sensor connected to the SN9C10x PC Camera *
3 * Controllers *
4 * *
5 * Copyright (C) 2005 by Luca Risolia <luca.risolia@studio.unibo.it> *
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the Free Software *
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
20 ***************************************************************************/
21
22#include "sn9c102_sensor.h"
23
24
25static struct sn9c102_sensor ov7630;
26
27
28static int ov7630_init(struct sn9c102_device* cam)
29{
30 int err = 0;
31
32 err += sn9c102_write_reg(cam, 0x00, 0x14);
33 err += sn9c102_write_reg(cam, 0x60, 0x17);
34 err += sn9c102_write_reg(cam, 0x0f, 0x18);
35 err += sn9c102_write_reg(cam, 0x50, 0x19);
36
37 err += sn9c102_i2c_write(cam, 0x12, 0x8d);
38 err += sn9c102_i2c_write(cam, 0x11, 0x00);
39 err += sn9c102_i2c_write(cam, 0x15, 0x34);
40 err += sn9c102_i2c_write(cam, 0x16, 0x03);
41 err += sn9c102_i2c_write(cam, 0x17, 0x1c);
42 err += sn9c102_i2c_write(cam, 0x18, 0xbd);
43 err += sn9c102_i2c_write(cam, 0x19, 0x06);
44 err += sn9c102_i2c_write(cam, 0x1a, 0xf6);
45 err += sn9c102_i2c_write(cam, 0x1b, 0x04);
46 err += sn9c102_i2c_write(cam, 0x20, 0x44);
47 err += sn9c102_i2c_write(cam, 0x23, 0xee);
48 err += sn9c102_i2c_write(cam, 0x26, 0xa0);
49 err += sn9c102_i2c_write(cam, 0x27, 0x9a);
50 err += sn9c102_i2c_write(cam, 0x28, 0x20);
51 err += sn9c102_i2c_write(cam, 0x29, 0x30);
52 err += sn9c102_i2c_write(cam, 0x2f, 0x3d);
53 err += sn9c102_i2c_write(cam, 0x30, 0x24);
54 err += sn9c102_i2c_write(cam, 0x32, 0x86);
55 err += sn9c102_i2c_write(cam, 0x60, 0xa9);
56 err += sn9c102_i2c_write(cam, 0x61, 0x42);
57 err += sn9c102_i2c_write(cam, 0x65, 0x00);
58 err += sn9c102_i2c_write(cam, 0x69, 0x38);
59 err += sn9c102_i2c_write(cam, 0x6f, 0x88);
60 err += sn9c102_i2c_write(cam, 0x70, 0x0b);
61 err += sn9c102_i2c_write(cam, 0x71, 0x00);
62 err += sn9c102_i2c_write(cam, 0x74, 0x21);
63 err += sn9c102_i2c_write(cam, 0x7d, 0xf7);
64
65 return err;
66}
67
68
69static int ov7630_set_ctrl(struct sn9c102_device* cam,
70 const struct v4l2_control* ctrl)
71{
72 int err = 0;
73
74 switch (ctrl->id) {
75 case V4L2_CID_EXPOSURE:
76 err += sn9c102_i2c_write(cam, 0x10, ctrl->value >> 2);
77 err += sn9c102_i2c_write(cam, 0x76, ctrl->value & 0x03);
78 break;
79 case V4L2_CID_RED_BALANCE:
80 err += sn9c102_i2c_write(cam, 0x02, ctrl->value);
81 break;
82 case V4L2_CID_BLUE_BALANCE:
83 err += sn9c102_i2c_write(cam, 0x03, ctrl->value);
84 break;
85 case V4L2_CID_GAIN:
86 err += sn9c102_i2c_write(cam, 0x00, ctrl->value);
87 break;
88 case V4L2_CID_CONTRAST:
89 err += ctrl->value ? sn9c102_i2c_write(cam, 0x05,
90 (ctrl->value-1) | 0x20)
91 : sn9c102_i2c_write(cam, 0x05, 0x00);
92 break;
93 case V4L2_CID_BRIGHTNESS:
94 err += sn9c102_i2c_write(cam, 0x06, ctrl->value);
95 break;
96 case V4L2_CID_SATURATION:
97 err += sn9c102_i2c_write(cam, 0x03, ctrl->value << 4);
98 break;
99 case V4L2_CID_HUE:
100 err += ctrl->value ? sn9c102_i2c_write(cam, 0x04,
101 (ctrl->value-1) | 0x20)
102 : sn9c102_i2c_write(cam, 0x04, 0x00);
103 break;
104 case V4L2_CID_DO_WHITE_BALANCE:
105 err += sn9c102_i2c_write(cam, 0x0c, ctrl->value);
106 break;
107 case V4L2_CID_WHITENESS:
108 err += sn9c102_i2c_write(cam, 0x0d, ctrl->value);
109 break;
110 case V4L2_CID_AUTO_WHITE_BALANCE:
111 err += sn9c102_i2c_write(cam, 0x12, (ctrl->value << 2) | 0x09);
112 break;
113 case V4L2_CID_AUTOGAIN:
114 err += sn9c102_i2c_write(cam, 0x13, ctrl->value);
115 break;
116 case V4L2_CID_VFLIP:
117 err += sn9c102_i2c_write(cam, 0x75, 0x0e | (ctrl->value << 7));
118 break;
119 case V4L2_CID_BLACK_LEVEL:
120 err += sn9c102_i2c_write(cam, 0x25, ctrl->value);
121 break;
122 case SN9C102_V4L2_CID_BRIGHT_LEVEL:
123 err += sn9c102_i2c_write(cam, 0x24, ctrl->value);
124 break;
125 case SN9C102_V4L2_CID_GAMMA:
126 err += sn9c102_i2c_write(cam, 0x14, (ctrl->value << 2) | 0x80);
127 break;
128 case SN9C102_V4L2_CID_BAND_FILTER:
129 err += sn9c102_i2c_write(cam, 0x2d, ctrl->value << 2);
130 break;
131 default:
132 return -EINVAL;
133 }
134
135 return err ? -EIO : 0;
136}
137
138
139static int ov7630_set_crop(struct sn9c102_device* cam,
140 const struct v4l2_rect* rect)
141{
142 struct sn9c102_sensor* s = &ov7630;
143 int err = 0;
144 u8 v_start = (u8)(rect->top - s->cropcap.bounds.top) + 1;
145
146 err += sn9c102_write_reg(cam, v_start, 0x13);
147
148 return err;
149}
150
151
152static int ov7630_set_pix_format(struct sn9c102_device* cam,
153 const struct v4l2_pix_format* pix)
154{
155 int err = 0;
156
157 if (pix->pixelformat == V4L2_PIX_FMT_SN9C10X)
158 err += sn9c102_write_reg(cam, 0x20, 0x19);
159 else
160 err += sn9c102_write_reg(cam, 0x50, 0x19);
161
162 return err;
163}
164
165
166static struct sn9c102_sensor ov7630 = {
167 .name = "OV7630",
168 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>",
169 .sysfs_ops = SN9C102_I2C_WRITE,
170 .frequency = SN9C102_I2C_100KHZ,
171 .interface = SN9C102_I2C_2WIRES,
172 .i2c_slave_id = 0x21,
173 .init = &ov7630_init,
174 .qctrl = {
175 {
176 .id = V4L2_CID_GAIN,
177 .type = V4L2_CTRL_TYPE_INTEGER,
178 .name = "global gain",
179 .minimum = 0x00,
180 .maximum = 0x3f,
181 .step = 0x01,
182 .default_value = 0x14,
183 .flags = 0,
184 },
185 {
186 .id = V4L2_CID_HUE,
187 .type = V4L2_CTRL_TYPE_INTEGER,
188 .name = "hue",
189 .minimum = 0x00,
190 .maximum = 0x1f+1,
191 .step = 0x01,
192 .default_value = 0x00,
193 .flags = 0,
194 },
195 {
196 .id = V4L2_CID_SATURATION,
197 .type = V4L2_CTRL_TYPE_INTEGER,
198 .name = "saturation",
199 .minimum = 0x00,
200 .maximum = 0x0f,
201 .step = 0x01,
202 .default_value = 0x08,
203 .flags = 0,
204 },
205 {
206 .id = V4L2_CID_CONTRAST,
207 .type = V4L2_CTRL_TYPE_INTEGER,
208 .name = "contrast",
209 .minimum = 0x00,
210 .maximum = 0x1f+1,
211 .step = 0x01,
212 .default_value = 0x00,
213 .flags = 0,
214 },
215 {
216 .id = V4L2_CID_EXPOSURE,
217 .type = V4L2_CTRL_TYPE_INTEGER,
218 .name = "exposure",
219 .minimum = 0x000,
220 .maximum = 0x3ff,
221 .step = 0x001,
222 .default_value = 0x83<<2,
223 .flags = 0,
224 },
225 {
226 .id = V4L2_CID_RED_BALANCE,
227 .type = V4L2_CTRL_TYPE_INTEGER,
228 .name = "red balance",
229 .minimum = 0x00,
230 .maximum = 0xff,
231 .step = 0x01,
232 .default_value = 0x3a,
233 .flags = 0,
234 },
235 {
236 .id = V4L2_CID_BLUE_BALANCE,
237 .type = V4L2_CTRL_TYPE_INTEGER,
238 .name = "blue balance",
239 .minimum = 0x00,
240 .maximum = 0xff,
241 .step = 0x01,
242 .default_value = 0x77,
243 .flags = 0,
244 },
245 {
246 .id = V4L2_CID_BRIGHTNESS,
247 .type = V4L2_CTRL_TYPE_INTEGER,
248 .name = "brightness",
249 .minimum = 0x00,
250 .maximum = 0xff,
251 .step = 0x01,
252 .default_value = 0xa0,
253 .flags = 0,
254 },
255 {
256 .id = V4L2_CID_DO_WHITE_BALANCE,
257 .type = V4L2_CTRL_TYPE_INTEGER,
258 .name = "white balance background: blue",
259 .minimum = 0x00,
260 .maximum = 0x3f,
261 .step = 0x01,
262 .default_value = 0x20,
263 .flags = 0,
264 },
265 {
266 .id = V4L2_CID_WHITENESS,
267 .type = V4L2_CTRL_TYPE_INTEGER,
268 .name = "white balance background: red",
269 .minimum = 0x00,
270 .maximum = 0x3f,
271 .step = 0x01,
272 .default_value = 0x20,
273 .flags = 0,
274 },
275 {
276 .id = V4L2_CID_AUTO_WHITE_BALANCE,
277 .type = V4L2_CTRL_TYPE_BOOLEAN,
278 .name = "auto white balance",
279 .minimum = 0x00,
280 .maximum = 0x01,
281 .step = 0x01,
282 .default_value = 0x01,
283 .flags = 0,
284 },
285 {
286 .id = V4L2_CID_AUTOGAIN,
287 .type = V4L2_CTRL_TYPE_INTEGER,
288 .name = "gain & exposure mode",
289 .minimum = 0x00,
290 .maximum = 0x03,
291 .step = 0x01,
292 .default_value = 0x00,
293 .flags = 0,
294 },
295 {
296 .id = V4L2_CID_VFLIP,
297 .type = V4L2_CTRL_TYPE_BOOLEAN,
298 .name = "vertical flip",
299 .minimum = 0x00,
300 .maximum = 0x01,
301 .step = 0x01,
302 .default_value = 0x01,
303 .flags = 0,
304 },
305 {
306 .id = V4L2_CID_BLACK_LEVEL,
307 .type = V4L2_CTRL_TYPE_INTEGER,
308 .name = "black pixel ratio",
309 .minimum = 0x01,
310 .maximum = 0x9a,
311 .step = 0x01,
312 .default_value = 0x8a,
313 .flags = 0,
314 },
315 {
316 .id = SN9C102_V4L2_CID_BRIGHT_LEVEL,
317 .type = V4L2_CTRL_TYPE_INTEGER,
318 .name = "bright pixel ratio",
319 .minimum = 0x01,
320 .maximum = 0x9a,
321 .step = 0x01,
322 .default_value = 0x10,
323 .flags = 0,
324 },
325 {
326 .id = SN9C102_V4L2_CID_BAND_FILTER,
327 .type = V4L2_CTRL_TYPE_BOOLEAN,
328 .name = "band filter",
329 .minimum = 0x00,
330 .maximum = 0x01,
331 .step = 0x01,
332 .default_value = 0x00,
333 .flags = 0,
334 },
335 {
336 .id = SN9C102_V4L2_CID_GAMMA,
337 .type = V4L2_CTRL_TYPE_BOOLEAN,
338 .name = "rgb gamma",
339 .minimum = 0x00,
340 .maximum = 0x01,
341 .step = 0x01,
342 .default_value = 0x00,
343 .flags = 0,
344 },
345 },
346 .set_ctrl = &ov7630_set_ctrl,
347 .cropcap = {
348 .bounds = {
349 .left = 0,
350 .top = 0,
351 .width = 640,
352 .height = 480,
353 },
354 .defrect = {
355 .left = 0,
356 .top = 0,
357 .width = 640,
358 .height = 480,
359 },
360 },
361 .set_crop = &ov7630_set_crop,
362 .pix_format = {
363 .width = 640,
364 .height = 480,
365 .pixelformat = V4L2_PIX_FMT_SBGGR8,
366 .priv = 8,
367 },
368 .set_pix_format = &ov7630_set_pix_format
369};
370
371
372int sn9c102_probe_ov7630(struct sn9c102_device* cam)
373{
374 int err = 0;
375
376 sn9c102_attach_sensor(cam, &ov7630);
377
378 if (le16_to_cpu(ov7630.usbdev->descriptor.idProduct) != 0x608f &&
379 le16_to_cpu(ov7630.usbdev->descriptor.idProduct) != 0x602c)
380 return -ENODEV;
381
382 err += sn9c102_write_reg(cam, 0x01, 0x01);
383 err += sn9c102_write_reg(cam, 0x00, 0x01);
384 err += sn9c102_write_reg(cam, 0x28, 0x17);
385
386 if (err)
387 return -EIO;
388
389 err += sn9c102_i2c_write(cam, 0x0b, 0);
390 if (err)
391 return -ENODEV;
392
393 return 0;
394}
diff --git a/drivers/usb/media/sn9c102_sensor.h b/drivers/usb/media/sn9c102_sensor.h
index 6a7adebcb4bf..a45166c3488c 100644
--- a/drivers/usb/media/sn9c102_sensor.h
+++ b/drivers/usb/media/sn9c102_sensor.h
@@ -64,6 +64,7 @@ struct sn9c102_sensor;
64*/ 64*/
65extern int sn9c102_probe_hv7131d(struct sn9c102_device* cam); 65extern int sn9c102_probe_hv7131d(struct sn9c102_device* cam);
66extern int sn9c102_probe_mi0343(struct sn9c102_device* cam); 66extern int sn9c102_probe_mi0343(struct sn9c102_device* cam);
67extern int sn9c102_probe_ov7630(struct sn9c102_device* cam);
67extern int sn9c102_probe_pas106b(struct sn9c102_device* cam); 68extern int sn9c102_probe_pas106b(struct sn9c102_device* cam);
68extern int sn9c102_probe_pas202bcb(struct sn9c102_device* cam); 69extern int sn9c102_probe_pas202bcb(struct sn9c102_device* cam);
69extern int sn9c102_probe_tas5110c1b(struct sn9c102_device* cam); 70extern int sn9c102_probe_tas5110c1b(struct sn9c102_device* cam);
@@ -80,6 +81,7 @@ static int (*sn9c102_sensor_table[])(struct sn9c102_device*) = { \
80 &sn9c102_probe_pas106b, /* strong detection based on SENSOR ids */ \ 81 &sn9c102_probe_pas106b, /* strong detection based on SENSOR ids */ \
81 &sn9c102_probe_pas202bcb, /* strong detection based on SENSOR ids */ \ 82 &sn9c102_probe_pas202bcb, /* strong detection based on SENSOR ids */ \
82 &sn9c102_probe_hv7131d, /* strong detection based on SENSOR ids */ \ 83 &sn9c102_probe_hv7131d, /* strong detection based on SENSOR ids */ \
84 &sn9c102_probe_ov7630, /* detection mostly based on USB pid/vid */ \
83 &sn9c102_probe_tas5110c1b, /* detection based on USB pid/vid */ \ 85 &sn9c102_probe_tas5110c1b, /* detection based on USB pid/vid */ \
84 &sn9c102_probe_tas5130d1b, /* detection based on USB pid/vid */ \ 86 &sn9c102_probe_tas5130d1b, /* detection based on USB pid/vid */ \
85 NULL, \ 87 NULL, \
@@ -103,7 +105,8 @@ static const struct usb_device_id sn9c102_id_table[] = { \
103 { USB_DEVICE(0x0c45, 0x6029), }, /* PAS106B */ \ 105 { USB_DEVICE(0x0c45, 0x6029), }, /* PAS106B */ \
104 { USB_DEVICE(0x0c45, 0x602a), }, /* HV7131D */ \ 106 { USB_DEVICE(0x0c45, 0x602a), }, /* HV7131D */ \
105 { USB_DEVICE(0x0c45, 0x602b), }, /* MI-0343 */ \ 107 { USB_DEVICE(0x0c45, 0x602b), }, /* MI-0343 */ \
106 { USB_DEVICE(0x0c45, 0x602c), }, /* OV7620 */ \ 108 { USB_DEVICE(0x0c45, 0x602c), }, /* OV7630 */ \
109 { USB_DEVICE(0x0c45, 0x602d), }, \
107 { USB_DEVICE(0x0c45, 0x6030), }, /* MI03x */ \ 110 { USB_DEVICE(0x0c45, 0x6030), }, /* MI03x */ \
108 { USB_DEVICE(0x0c45, 0x6080), }, \ 111 { USB_DEVICE(0x0c45, 0x6080), }, \
109 { USB_DEVICE(0x0c45, 0x6082), }, /* MI0343 and MI0360 */ \ 112 { USB_DEVICE(0x0c45, 0x6082), }, /* MI0343 and MI0360 */ \
@@ -145,6 +148,8 @@ static const struct usb_device_id sn9c102_id_table[] = { \
145*/ 148*/
146 149
147/* The "try" I2C I/O versions are used when probing the sensor */ 150/* The "try" I2C I/O versions are used when probing the sensor */
151extern int sn9c102_i2c_try_write(struct sn9c102_device*,struct sn9c102_sensor*,
152 u8 address, u8 value);
148extern int sn9c102_i2c_try_read(struct sn9c102_device*,struct sn9c102_sensor*, 153extern int sn9c102_i2c_try_read(struct sn9c102_device*,struct sn9c102_sensor*,
149 u8 address); 154 u8 address);
150 155
@@ -201,6 +206,8 @@ enum sn9c102_i2c_interface {
201 SN9C102_I2C_3WIRES, 206 SN9C102_I2C_3WIRES,
202}; 207};
203 208
209#define SN9C102_MAX_CTRLS V4L2_CID_LASTP1-V4L2_CID_BASE+10
210
204struct sn9c102_sensor { 211struct sn9c102_sensor {
205 char name[32], /* sensor name */ 212 char name[32], /* sensor name */
206 maintainer[64]; /* name of the mantainer <email> */ 213 maintainer[64]; /* name of the mantainer <email> */
@@ -243,7 +250,7 @@ struct sn9c102_sensor {
243 sensor according to the default configuration structures below. 250 sensor according to the default configuration structures below.
244 */ 251 */
245 252
246 struct v4l2_queryctrl qctrl[V4L2_CID_LASTP1-V4L2_CID_BASE]; 253 struct v4l2_queryctrl qctrl[SN9C102_MAX_CTRLS];
247 /* 254 /*
248 Optional list of default controls, defined as indicated in the 255 Optional list of default controls, defined as indicated in the
249 V4L2 API. Menu type controls are not handled by this interface. 256 V4L2 API. Menu type controls are not handled by this interface.
@@ -356,7 +363,7 @@ struct sn9c102_sensor {
356 core module to store successfully updated values of the above 363 core module to store successfully updated values of the above
357 settings, for rollbacks..etc..in case of errors during atomic I/O 364 settings, for rollbacks..etc..in case of errors during atomic I/O
358 */ 365 */
359 struct v4l2_queryctrl _qctrl[V4L2_CID_LASTP1-V4L2_CID_BASE]; 366 struct v4l2_queryctrl _qctrl[SN9C102_MAX_CTRLS];
360 struct v4l2_rect _rect; 367 struct v4l2_rect _rect;
361}; 368};
362 369
@@ -367,5 +374,8 @@ struct sn9c102_sensor {
367#define SN9C102_V4L2_CID_GREEN_BALANCE V4L2_CID_PRIVATE_BASE + 1 374#define SN9C102_V4L2_CID_GREEN_BALANCE V4L2_CID_PRIVATE_BASE + 1
368#define SN9C102_V4L2_CID_RESET_LEVEL V4L2_CID_PRIVATE_BASE + 2 375#define SN9C102_V4L2_CID_RESET_LEVEL V4L2_CID_PRIVATE_BASE + 2
369#define SN9C102_V4L2_CID_PIXEL_BIAS_VOLTAGE V4L2_CID_PRIVATE_BASE + 3 376#define SN9C102_V4L2_CID_PIXEL_BIAS_VOLTAGE V4L2_CID_PRIVATE_BASE + 3
377#define SN9C102_V4L2_CID_GAMMA V4L2_CID_PRIVATE_BASE + 4
378#define SN9C102_V4L2_CID_BAND_FILTER V4L2_CID_PRIVATE_BASE + 5
379#define SN9C102_V4L2_CID_BRIGHT_LEVEL V4L2_CID_PRIVATE_BASE + 6
370 380
371#endif /* _SN9C102_SENSOR_H_ */ 381#endif /* _SN9C102_SENSOR_H_ */
diff --git a/drivers/usb/media/sn9c102_tas5110c1b.c b/drivers/usb/media/sn9c102_tas5110c1b.c
index 690d62192273..8775999b5aff 100644
--- a/drivers/usb/media/sn9c102_tas5110c1b.c
+++ b/drivers/usb/media/sn9c102_tas5110c1b.c
@@ -24,8 +24,6 @@
24 24
25static struct sn9c102_sensor tas5110c1b; 25static struct sn9c102_sensor tas5110c1b;
26 26
27static struct v4l2_control tas5110c1b_gain;
28
29 27
30static int tas5110c1b_init(struct sn9c102_device* cam) 28static int tas5110c1b_init(struct sn9c102_device* cam)
31{ 29{
@@ -46,21 +44,6 @@ static int tas5110c1b_init(struct sn9c102_device* cam)
46} 44}
47 45
48 46
49static int tas5110c1b_get_ctrl(struct sn9c102_device* cam,
50 struct v4l2_control* ctrl)
51{
52 switch (ctrl->id) {
53 case V4L2_CID_GAIN:
54 ctrl->value = tas5110c1b_gain.value;
55 break;
56 default:
57 return -EINVAL;
58 }
59
60 return 0;
61}
62
63
64static int tas5110c1b_set_ctrl(struct sn9c102_device* cam, 47static int tas5110c1b_set_ctrl(struct sn9c102_device* cam,
65 const struct v4l2_control* ctrl) 48 const struct v4l2_control* ctrl)
66{ 49{
@@ -68,8 +51,7 @@ static int tas5110c1b_set_ctrl(struct sn9c102_device* cam,
68 51
69 switch (ctrl->id) { 52 switch (ctrl->id) {
70 case V4L2_CID_GAIN: 53 case V4L2_CID_GAIN:
71 if (!(err += sn9c102_i2c_write(cam, 0x20, 0xf6 - ctrl->value))) 54 err += sn9c102_i2c_write(cam, 0x20, 0xf6 - ctrl->value);
72 tas5110c1b_gain.value = ctrl->value;
73 break; 55 break;
74 default: 56 default:
75 return -EINVAL; 57 return -EINVAL;
@@ -147,7 +129,6 @@ static struct sn9c102_sensor tas5110c1b = {
147 .height = 288, 129 .height = 288,
148 }, 130 },
149 }, 131 },
150 .get_ctrl = &tas5110c1b_get_ctrl,
151 .set_crop = &tas5110c1b_set_crop, 132 .set_crop = &tas5110c1b_set_crop,
152 .pix_format = { 133 .pix_format = {
153 .width = 352, 134 .width = 352,
diff --git a/drivers/usb/media/sn9c102_tas5130d1b.c b/drivers/usb/media/sn9c102_tas5130d1b.c
index b378e941bbe8..927eafdd8c73 100644
--- a/drivers/usb/media/sn9c102_tas5130d1b.c
+++ b/drivers/usb/media/sn9c102_tas5130d1b.c
@@ -24,8 +24,6 @@
24 24
25static struct sn9c102_sensor tas5130d1b; 25static struct sn9c102_sensor tas5130d1b;
26 26
27static struct v4l2_control tas5130d1b_gain, tas5130d1b_exposure;
28
29 27
30static int tas5130d1b_init(struct sn9c102_device* cam) 28static int tas5130d1b_init(struct sn9c102_device* cam)
31{ 29{
@@ -44,24 +42,6 @@ static int tas5130d1b_init(struct sn9c102_device* cam)
44} 42}
45 43
46 44
47static int tas5130d1b_get_ctrl(struct sn9c102_device* cam,
48 struct v4l2_control* ctrl)
49{
50 switch (ctrl->id) {
51 case V4L2_CID_GAIN:
52 ctrl->value = tas5130d1b_gain.value;
53 break;
54 case V4L2_CID_EXPOSURE:
55 ctrl->value = tas5130d1b_exposure.value;
56 break;
57 default:
58 return -EINVAL;
59 }
60
61 return 0;
62}
63
64
65static int tas5130d1b_set_ctrl(struct sn9c102_device* cam, 45static int tas5130d1b_set_ctrl(struct sn9c102_device* cam,
66 const struct v4l2_control* ctrl) 46 const struct v4l2_control* ctrl)
67{ 47{
@@ -69,12 +49,10 @@ static int tas5130d1b_set_ctrl(struct sn9c102_device* cam,
69 49
70 switch (ctrl->id) { 50 switch (ctrl->id) {
71 case V4L2_CID_GAIN: 51 case V4L2_CID_GAIN:
72 if (!(err += sn9c102_i2c_write(cam, 0x20, 0xf6 - ctrl->value))) 52 err += sn9c102_i2c_write(cam, 0x20, 0xf6 - ctrl->value);
73 tas5130d1b_gain.value = ctrl->value;
74 break; 53 break;
75 case V4L2_CID_EXPOSURE: 54 case V4L2_CID_EXPOSURE:
76 if (!(err += sn9c102_i2c_write(cam, 0x40, 0x47 - ctrl->value))) 55 err += sn9c102_i2c_write(cam, 0x40, 0x47 - ctrl->value);
77 tas5130d1b_exposure.value = ctrl->value;
78 break; 56 break;
79 default: 57 default:
80 return -EINVAL; 58 return -EINVAL;
@@ -147,7 +125,6 @@ static struct sn9c102_sensor tas5130d1b = {
147 .flags = 0, 125 .flags = 0,
148 }, 126 },
149 }, 127 },
150 .get_ctrl = &tas5130d1b_get_ctrl,
151 .set_ctrl = &tas5130d1b_set_ctrl, 128 .set_ctrl = &tas5130d1b_set_ctrl,
152 .cropcap = { 129 .cropcap = {
153 .bounds = { 130 .bounds = {
diff --git a/drivers/usb/misc/Kconfig b/drivers/usb/misc/Kconfig
index 3a896954b3a9..6649531fa824 100644
--- a/drivers/usb/misc/Kconfig
+++ b/drivers/usb/misc/Kconfig
@@ -139,6 +139,16 @@ config USB_IDMOUSE
139 139
140source "drivers/usb/misc/sisusbvga/Kconfig" 140source "drivers/usb/misc/sisusbvga/Kconfig"
141 141
142config USB_LD
143 tristate "USB LD driver"
144 depends on USB && EXPERIMENTAL
145 help
146 This driver is for generic USB devices that use interrupt transfers,
147 like LD Didactic's USB devices.
148
149 To compile this driver as a module, choose M here: the
150 module will be called ldusb.
151
142config USB_TEST 152config USB_TEST
143 tristate "USB testing driver (DEVELOPMENT)" 153 tristate "USB testing driver (DEVELOPMENT)"
144 depends on USB && USB_DEVICEFS && EXPERIMENTAL 154 depends on USB && USB_DEVICEFS && EXPERIMENTAL
diff --git a/drivers/usb/misc/Makefile b/drivers/usb/misc/Makefile
index 4a3814cbd48d..862e40a83689 100644
--- a/drivers/usb/misc/Makefile
+++ b/drivers/usb/misc/Makefile
@@ -9,6 +9,7 @@ obj-$(CONFIG_USB_EMI26) += emi26.o
9obj-$(CONFIG_USB_EMI62) += emi62.o 9obj-$(CONFIG_USB_EMI62) += emi62.o
10obj-$(CONFIG_USB_IDMOUSE) += idmouse.o 10obj-$(CONFIG_USB_IDMOUSE) += idmouse.o
11obj-$(CONFIG_USB_LCD) += usblcd.o 11obj-$(CONFIG_USB_LCD) += usblcd.o
12obj-$(CONFIG_USB_LD) += ldusb.o
12obj-$(CONFIG_USB_LED) += usbled.o 13obj-$(CONFIG_USB_LED) += usbled.o
13obj-$(CONFIG_USB_LEGOTOWER) += legousbtower.o 14obj-$(CONFIG_USB_LEGOTOWER) += legousbtower.o
14obj-$(CONFIG_USB_PHIDGETKIT) += phidgetkit.o 15obj-$(CONFIG_USB_PHIDGETKIT) += phidgetkit.o
diff --git a/drivers/usb/misc/ldusb.c b/drivers/usb/misc/ldusb.c
new file mode 100644
index 000000000000..66ec88354b93
--- /dev/null
+++ b/drivers/usb/misc/ldusb.c
@@ -0,0 +1,794 @@
1/**
2 * Generic USB driver for report based interrupt in/out devices
3 * like LD Didactic's USB devices. LD Didactic's USB devices are
4 * HID devices which do not use HID report definitons (they use
5 * raw interrupt in and our reports only for communication).
6 *
7 * This driver uses a ring buffer for time critical reading of
8 * interrupt in reports and provides read and write methods for
9 * raw interrupt reports (similar to the Windows HID driver).
10 * Devices based on the book USB COMPLETE by Jan Axelson may need
11 * such a compatibility to the Windows HID driver.
12 *
13 * Copyright (C) 2005 Michael Hund <mhund@ld-didactic.de>
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License as
17 * published by the Free Software Foundation; either version 2 of
18 * the License, or (at your option) any later version.
19 *
20 * Derived from Lego USB Tower driver
21 * Copyright (C) 2003 David Glance <advidgsf@sourceforge.net>
22 * 2001-2004 Juergen Stuber <starblue@users.sourceforge.net>
23 *
24 * V0.1 (mh) Initial version
25 * V0.11 (mh) Added raw support for HID 1.0 devices (no interrupt out endpoint)
26 */
27
28#include <linux/config.h>
29#include <linux/kernel.h>
30#include <linux/errno.h>
31#include <linux/init.h>
32#include <linux/slab.h>
33#include <linux/module.h>
34
35#include <asm/uaccess.h>
36#include <linux/input.h>
37#include <linux/usb.h>
38#include <linux/poll.h>
39
40/* Define these values to match your devices */
41#define USB_VENDOR_ID_LD 0x0f11 /* USB Vendor ID of LD Didactic GmbH */
42#define USB_DEVICE_ID_CASSY 0x1000 /* USB Product ID for all CASSY-S modules */
43#define USB_DEVICE_ID_POCKETCASSY 0x1010 /* USB Product ID for Pocket-CASSY */
44#define USB_DEVICE_ID_MOBILECASSY 0x1020 /* USB Product ID for Mobile-CASSY */
45#define USB_DEVICE_ID_JWM 0x1080 /* USB Product ID for Joule and Wattmeter */
46#define USB_DEVICE_ID_DMMP 0x1081 /* USB Product ID for Digital Multimeter P (reserved) */
47#define USB_DEVICE_ID_UMIP 0x1090 /* USB Product ID for UMI P */
48#define USB_DEVICE_ID_VIDEOCOM 0x1200 /* USB Product ID for VideoCom */
49#define USB_DEVICE_ID_COM3LAB 0x2000 /* USB Product ID for COM3LAB */
50#define USB_DEVICE_ID_TELEPORT 0x2010 /* USB Product ID for Terminal Adapter */
51#define USB_DEVICE_ID_NETWORKANALYSER 0x2020 /* USB Product ID for Network Analyser */
52#define USB_DEVICE_ID_POWERCONTROL 0x2030 /* USB Product ID for Controlling device for Power Electronics */
53
54#define USB_VENDOR_ID_VERNIER 0x08f7
55#define USB_DEVICE_ID_VERNIER_LABPRO 0x0001
56#define USB_DEVICE_ID_VERNIER_GOTEMP 0x0002
57#define USB_DEVICE_ID_VERNIER_SKIP 0x0003
58#define USB_DEVICE_ID_VERNIER_CYCLOPS 0x0004
59
60
61#ifdef CONFIG_USB_DYNAMIC_MINORS
62#define USB_LD_MINOR_BASE 0
63#else
64#define USB_LD_MINOR_BASE 176
65#endif
66
67/* table of devices that work with this driver */
68static struct usb_device_id ld_usb_table [] = {
69 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_CASSY) },
70 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_POCKETCASSY) },
71 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_MOBILECASSY) },
72 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_JWM) },
73 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_DMMP) },
74 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_UMIP) },
75 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_VIDEOCOM) },
76 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_COM3LAB) },
77 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_TELEPORT) },
78 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_NETWORKANALYSER) },
79 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_POWERCONTROL) },
80 { USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LABPRO) },
81 { USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP) },
82 { USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP) },
83 { USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS) },
84 { } /* Terminating entry */
85};
86MODULE_DEVICE_TABLE(usb, ld_usb_table);
87MODULE_VERSION("V0.11");
88MODULE_AUTHOR("Michael Hund <mhund@ld-didactic.de>");
89MODULE_DESCRIPTION("LD USB Driver");
90MODULE_LICENSE("GPL");
91MODULE_SUPPORTED_DEVICE("LD USB Devices");
92
93#ifdef CONFIG_USB_DEBUG
94 static int debug = 1;
95#else
96 static int debug = 0;
97#endif
98
99/* Use our own dbg macro */
100#define dbg_info(dev, format, arg...) do { if (debug) dev_info(dev , format , ## arg); } while (0)
101
102/* Module parameters */
103module_param(debug, int, S_IRUGO | S_IWUSR);
104MODULE_PARM_DESC(debug, "Debug enabled or not");
105
106/* All interrupt in transfers are collected in a ring buffer to
107 * avoid racing conditions and get better performance of the driver.
108 */
109static int ring_buffer_size = 128;
110module_param(ring_buffer_size, int, 0);
111MODULE_PARM_DESC(ring_buffer_size, "Read ring buffer size in reports");
112
113/* The write_buffer can contain more than one interrupt out transfer.
114 */
115static int write_buffer_size = 10;
116module_param(write_buffer_size, int, 0);
117MODULE_PARM_DESC(write_buffer_size, "Write buffer size in reports");
118
119/* As of kernel version 2.6.4 ehci-hcd uses an
120 * "only one interrupt transfer per frame" shortcut
121 * to simplify the scheduling of periodic transfers.
122 * This conflicts with our standard 1ms intervals for in and out URBs.
123 * We use default intervals of 2ms for in and 2ms for out transfers,
124 * which should be fast enough.
125 * Increase the interval to allow more devices that do interrupt transfers,
126 * or set to 1 to use the standard interval from the endpoint descriptors.
127 */
128static int min_interrupt_in_interval = 2;
129module_param(min_interrupt_in_interval, int, 0);
130MODULE_PARM_DESC(min_interrupt_in_interval, "Minimum interrupt in interval in ms");
131
132static int min_interrupt_out_interval = 2;
133module_param(min_interrupt_out_interval, int, 0);
134MODULE_PARM_DESC(min_interrupt_out_interval, "Minimum interrupt out interval in ms");
135
136/* Structure to hold all of our device specific stuff */
137struct ld_usb {
138 struct semaphore sem; /* locks this structure */
139 struct usb_interface* intf; /* save off the usb interface pointer */
140
141 int open_count; /* number of times this port has been opened */
142
143 char* ring_buffer;
144 unsigned int ring_head;
145 unsigned int ring_tail;
146
147 wait_queue_head_t read_wait;
148 wait_queue_head_t write_wait;
149
150 char* interrupt_in_buffer;
151 struct usb_endpoint_descriptor* interrupt_in_endpoint;
152 struct urb* interrupt_in_urb;
153 int interrupt_in_interval;
154 size_t interrupt_in_endpoint_size;
155 int interrupt_in_running;
156 int interrupt_in_done;
157
158 char* interrupt_out_buffer;
159 struct usb_endpoint_descriptor* interrupt_out_endpoint;
160 struct urb* interrupt_out_urb;
161 int interrupt_out_interval;
162 size_t interrupt_out_endpoint_size;
163 int interrupt_out_busy;
164};
165
166/* prevent races between open() and disconnect() */
167static DECLARE_MUTEX(disconnect_sem);
168
169static struct usb_driver ld_usb_driver;
170
171/**
172 * ld_usb_abort_transfers
173 * aborts transfers and frees associated data structures
174 */
175static void ld_usb_abort_transfers(struct ld_usb *dev)
176{
177 /* shutdown transfer */
178 if (dev->interrupt_in_running) {
179 dev->interrupt_in_running = 0;
180 if (dev->intf)
181 usb_kill_urb(dev->interrupt_in_urb);
182 }
183 if (dev->interrupt_out_busy)
184 if (dev->intf)
185 usb_kill_urb(dev->interrupt_out_urb);
186}
187
188/**
189 * ld_usb_delete
190 */
191static void ld_usb_delete(struct ld_usb *dev)
192{
193 ld_usb_abort_transfers(dev);
194
195 /* free data structures */
196 usb_free_urb(dev->interrupt_in_urb);
197 usb_free_urb(dev->interrupt_out_urb);
198 kfree(dev->ring_buffer);
199 kfree(dev->interrupt_in_buffer);
200 kfree(dev->interrupt_out_buffer);
201 kfree(dev);
202}
203
204/**
205 * ld_usb_interrupt_in_callback
206 */
207static void ld_usb_interrupt_in_callback(struct urb *urb, struct pt_regs *regs)
208{
209 struct ld_usb *dev = urb->context;
210 size_t *actual_buffer;
211 unsigned int next_ring_head;
212 int retval;
213
214 if (urb->status) {
215 if (urb->status == -ENOENT ||
216 urb->status == -ECONNRESET ||
217 urb->status == -ESHUTDOWN) {
218 goto exit;
219 } else {
220 dbg_info(&dev->intf->dev, "%s: nonzero status received: %d\n",
221 __FUNCTION__, urb->status);
222 goto resubmit; /* maybe we can recover */
223 }
224 }
225
226 if (urb->actual_length > 0) {
227 next_ring_head = (dev->ring_head+1) % ring_buffer_size;
228 if (next_ring_head != dev->ring_tail) {
229 actual_buffer = (size_t*)(dev->ring_buffer + dev->ring_head*(sizeof(size_t)+dev->interrupt_in_endpoint_size));
230 /* actual_buffer gets urb->actual_length + interrupt_in_buffer */
231 *actual_buffer = urb->actual_length;
232 memcpy(actual_buffer+1, dev->interrupt_in_buffer, urb->actual_length);
233 dev->ring_head = next_ring_head;
234 dbg_info(&dev->intf->dev, "%s: received %d bytes\n",
235 __FUNCTION__, urb->actual_length);
236 } else
237 dev_warn(&dev->intf->dev,
238 "Ring buffer overflow, %d bytes dropped\n",
239 urb->actual_length);
240 }
241
242resubmit:
243 /* resubmit if we're still running */
244 if (dev->interrupt_in_running && dev->intf) {
245 retval = usb_submit_urb(dev->interrupt_in_urb, GFP_ATOMIC);
246 if (retval)
247 dev_err(&dev->intf->dev,
248 "usb_submit_urb failed (%d)\n", retval);
249 }
250
251exit:
252 dev->interrupt_in_done = 1;
253 wake_up_interruptible(&dev->read_wait);
254}
255
256/**
257 * ld_usb_interrupt_out_callback
258 */
259static void ld_usb_interrupt_out_callback(struct urb *urb, struct pt_regs *regs)
260{
261 struct ld_usb *dev = urb->context;
262
263 /* sync/async unlink faults aren't errors */
264 if (urb->status && !(urb->status == -ENOENT ||
265 urb->status == -ECONNRESET ||
266 urb->status == -ESHUTDOWN))
267 dbg_info(&dev->intf->dev,
268 "%s - nonzero write interrupt status received: %d\n",
269 __FUNCTION__, urb->status);
270
271 dev->interrupt_out_busy = 0;
272 wake_up_interruptible(&dev->write_wait);
273}
274
275/**
276 * ld_usb_open
277 */
278static int ld_usb_open(struct inode *inode, struct file *file)
279{
280 struct ld_usb *dev;
281 int subminor;
282 int retval = 0;
283 struct usb_interface *interface;
284
285 nonseekable_open(inode, file);
286 subminor = iminor(inode);
287
288 down(&disconnect_sem);
289
290 interface = usb_find_interface(&ld_usb_driver, subminor);
291
292 if (!interface) {
293 err("%s - error, can't find device for minor %d\n",
294 __FUNCTION__, subminor);
295 retval = -ENODEV;
296 goto unlock_disconnect_exit;
297 }
298
299 dev = usb_get_intfdata(interface);
300
301 if (!dev) {
302 retval = -ENODEV;
303 goto unlock_disconnect_exit;
304 }
305
306 /* lock this device */
307 if (down_interruptible(&dev->sem)) {
308 retval = -ERESTARTSYS;
309 goto unlock_disconnect_exit;
310 }
311
312 /* allow opening only once */
313 if (dev->open_count) {
314 retval = -EBUSY;
315 goto unlock_exit;
316 }
317 dev->open_count = 1;
318
319 /* initialize in direction */
320 dev->ring_head = 0;
321 dev->ring_tail = 0;
322 usb_fill_int_urb(dev->interrupt_in_urb,
323 interface_to_usbdev(interface),
324 usb_rcvintpipe(interface_to_usbdev(interface),
325 dev->interrupt_in_endpoint->bEndpointAddress),
326 dev->interrupt_in_buffer,
327 dev->interrupt_in_endpoint_size,
328 ld_usb_interrupt_in_callback,
329 dev,
330 dev->interrupt_in_interval);
331
332 dev->interrupt_in_running = 1;
333 dev->interrupt_in_done = 0;
334
335 retval = usb_submit_urb(dev->interrupt_in_urb, GFP_KERNEL);
336 if (retval) {
337 dev_err(&interface->dev, "Couldn't submit interrupt_in_urb %d\n", retval);
338 dev->interrupt_in_running = 0;
339 dev->open_count = 0;
340 goto unlock_exit;
341 }
342
343 /* save device in the file's private structure */
344 file->private_data = dev;
345
346unlock_exit:
347 up(&dev->sem);
348
349unlock_disconnect_exit:
350 up(&disconnect_sem);
351
352 return retval;
353}
354
355/**
356 * ld_usb_release
357 */
358static int ld_usb_release(struct inode *inode, struct file *file)
359{
360 struct ld_usb *dev;
361 int retval = 0;
362
363 dev = file->private_data;
364
365 if (dev == NULL) {
366 retval = -ENODEV;
367 goto exit;
368 }
369
370 if (down_interruptible(&dev->sem)) {
371 retval = -ERESTARTSYS;
372 goto exit;
373 }
374
375 if (dev->open_count != 1) {
376 retval = -ENODEV;
377 goto unlock_exit;
378 }
379 if (dev->intf == NULL) {
380 /* the device was unplugged before the file was released */
381 up(&dev->sem);
382 /* unlock here as ld_usb_delete frees dev */
383 ld_usb_delete(dev);
384 goto exit;
385 }
386
387 /* wait until write transfer is finished */
388 if (dev->interrupt_out_busy)
389 wait_event_interruptible_timeout(dev->write_wait, !dev->interrupt_out_busy, 2 * HZ);
390 ld_usb_abort_transfers(dev);
391 dev->open_count = 0;
392
393unlock_exit:
394 up(&dev->sem);
395
396exit:
397 return retval;
398}
399
400/**
401 * ld_usb_poll
402 */
403static unsigned int ld_usb_poll(struct file *file, poll_table *wait)
404{
405 struct ld_usb *dev;
406 unsigned int mask = 0;
407
408 dev = file->private_data;
409
410 poll_wait(file, &dev->read_wait, wait);
411 poll_wait(file, &dev->write_wait, wait);
412
413 if (dev->ring_head != dev->ring_tail)
414 mask |= POLLIN | POLLRDNORM;
415 if (!dev->interrupt_out_busy)
416 mask |= POLLOUT | POLLWRNORM;
417
418 return mask;
419}
420
421/**
422 * ld_usb_read
423 */
424static ssize_t ld_usb_read(struct file *file, char __user *buffer, size_t count,
425 loff_t *ppos)
426{
427 struct ld_usb *dev;
428 size_t *actual_buffer;
429 size_t bytes_to_read;
430 int retval = 0;
431
432 dev = file->private_data;
433
434 /* verify that we actually have some data to read */
435 if (count == 0)
436 goto exit;
437
438 /* lock this object */
439 if (down_interruptible(&dev->sem)) {
440 retval = -ERESTARTSYS;
441 goto exit;
442 }
443
444 /* verify that the device wasn't unplugged */
445 if (dev->intf == NULL) {
446 retval = -ENODEV;
447 err("No device or device unplugged %d\n", retval);
448 goto unlock_exit;
449 }
450
451 /* wait for data */
452 if (dev->ring_head == dev->ring_tail) {
453 if (file->f_flags & O_NONBLOCK) {
454 retval = -EAGAIN;
455 goto unlock_exit;
456 }
457 retval = wait_event_interruptible(dev->read_wait, dev->interrupt_in_done);
458 if (retval < 0)
459 goto unlock_exit;
460 }
461
462 /* actual_buffer contains actual_length + interrupt_in_buffer */
463 actual_buffer = (size_t*)(dev->ring_buffer + dev->ring_tail*(sizeof(size_t)+dev->interrupt_in_endpoint_size));
464 bytes_to_read = min(count, *actual_buffer);
465 if (bytes_to_read < *actual_buffer)
466 dev_warn(&dev->intf->dev, "Read buffer overflow, %d bytes dropped\n",
467 *actual_buffer-bytes_to_read);
468
469 /* copy one interrupt_in_buffer from ring_buffer into userspace */
470 if (copy_to_user(buffer, actual_buffer+1, bytes_to_read)) {
471 retval = -EFAULT;
472 goto unlock_exit;
473 }
474 dev->ring_tail = (dev->ring_tail+1) % ring_buffer_size;
475
476 retval = bytes_to_read;
477
478unlock_exit:
479 /* unlock the device */
480 up(&dev->sem);
481
482exit:
483 return retval;
484}
485
486/**
487 * ld_usb_write
488 */
489static ssize_t ld_usb_write(struct file *file, const char __user *buffer,
490 size_t count, loff_t *ppos)
491{
492 struct ld_usb *dev;
493 size_t bytes_to_write;
494 int retval = 0;
495
496 dev = file->private_data;
497
498 /* verify that we actually have some data to write */
499 if (count == 0)
500 goto exit;
501
502 /* lock this object */
503 if (down_interruptible(&dev->sem)) {
504 retval = -ERESTARTSYS;
505 goto exit;
506 }
507
508 /* verify that the device wasn't unplugged */
509 if (dev->intf == NULL) {
510 retval = -ENODEV;
511 err("No device or device unplugged %d\n", retval);
512 goto unlock_exit;
513 }
514
515 /* wait until previous transfer is finished */
516 if (dev->interrupt_out_busy) {
517 if (file->f_flags & O_NONBLOCK) {
518 retval = -EAGAIN;
519 goto unlock_exit;
520 }
521 retval = wait_event_interruptible(dev->write_wait, !dev->interrupt_out_busy);
522 if (retval < 0) {
523 goto unlock_exit;
524 }
525 }
526
527 /* write the data into interrupt_out_buffer from userspace */
528 bytes_to_write = min(count, write_buffer_size*dev->interrupt_out_endpoint_size);
529 if (bytes_to_write < count)
530 dev_warn(&dev->intf->dev, "Write buffer overflow, %d bytes dropped\n",count-bytes_to_write);
531 dbg_info(&dev->intf->dev, "%s: count = %d, bytes_to_write = %d\n", __FUNCTION__, count, bytes_to_write);
532
533 if (copy_from_user(dev->interrupt_out_buffer, buffer, bytes_to_write)) {
534 retval = -EFAULT;
535 goto unlock_exit;
536 }
537
538 if (dev->interrupt_out_endpoint == NULL) {
539 /* try HID_REQ_SET_REPORT=9 on control_endpoint instead of interrupt_out_endpoint */
540 retval = usb_control_msg(interface_to_usbdev(dev->intf),
541 usb_sndctrlpipe(interface_to_usbdev(dev->intf), 0),
542 9,
543 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
544 1 << 8, 0,
545 dev->interrupt_out_buffer,
546 bytes_to_write,
547 USB_CTRL_SET_TIMEOUT * HZ);
548 if (retval < 0)
549 err("Couldn't submit HID_REQ_SET_REPORT %d\n", retval);
550 goto unlock_exit;
551 }
552
553 /* send off the urb */
554 usb_fill_int_urb(dev->interrupt_out_urb,
555 interface_to_usbdev(dev->intf),
556 usb_sndintpipe(interface_to_usbdev(dev->intf),
557 dev->interrupt_out_endpoint->bEndpointAddress),
558 dev->interrupt_out_buffer,
559 bytes_to_write,
560 ld_usb_interrupt_out_callback,
561 dev,
562 dev->interrupt_out_interval);
563
564 dev->interrupt_out_busy = 1;
565 wmb();
566
567 retval = usb_submit_urb(dev->interrupt_out_urb, GFP_KERNEL);
568 if (retval) {
569 dev->interrupt_out_busy = 0;
570 err("Couldn't submit interrupt_out_urb %d\n", retval);
571 goto unlock_exit;
572 }
573 retval = bytes_to_write;
574
575unlock_exit:
576 /* unlock the device */
577 up(&dev->sem);
578
579exit:
580 return retval;
581}
582
583/* file operations needed when we register this driver */
584static struct file_operations ld_usb_fops = {
585 .owner = THIS_MODULE,
586 .read = ld_usb_read,
587 .write = ld_usb_write,
588 .open = ld_usb_open,
589 .release = ld_usb_release,
590 .poll = ld_usb_poll,
591};
592
593/*
594 * usb class driver info in order to get a minor number from the usb core,
595 * and to have the device registered with devfs and the driver core
596 */
597static struct usb_class_driver ld_usb_class = {
598 .name = "ldusb%d",
599 .fops = &ld_usb_fops,
600 .minor_base = USB_LD_MINOR_BASE,
601};
602
603/**
604 * ld_usb_probe
605 *
606 * Called by the usb core when a new device is connected that it thinks
607 * this driver might be interested in.
608 */
609static int ld_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
610{
611 struct usb_device *udev = interface_to_usbdev(intf);
612 struct ld_usb *dev = NULL;
613 struct usb_host_interface *iface_desc;
614 struct usb_endpoint_descriptor *endpoint;
615 char *buffer;
616 int i;
617 int retval = -ENOMEM;
618
619 /* allocate memory for our device state and intialize it */
620
621 dev = kmalloc(sizeof(*dev), GFP_KERNEL);
622 if (dev == NULL) {
623 dev_err(&intf->dev, "Out of memory\n");
624 goto exit;
625 }
626 memset(dev, 0x00, sizeof(*dev));
627 init_MUTEX(&dev->sem);
628 dev->intf = intf;
629 init_waitqueue_head(&dev->read_wait);
630 init_waitqueue_head(&dev->write_wait);
631
632 /* workaround for early firmware versions on fast computers */
633 if ((le16_to_cpu(udev->descriptor.idVendor) == USB_VENDOR_ID_LD) &&
634 ((le16_to_cpu(udev->descriptor.idProduct) == USB_DEVICE_ID_CASSY) ||
635 (le16_to_cpu(udev->descriptor.idProduct) == USB_DEVICE_ID_COM3LAB)) &&
636 (le16_to_cpu(udev->descriptor.bcdDevice) <= 0x103)) {
637 buffer = kmalloc(256, GFP_KERNEL);
638 /* usb_string makes SETUP+STALL to leave always ControlReadLoop */
639 usb_string(udev, 255, buffer, 256);
640 kfree(buffer);
641 }
642
643 iface_desc = intf->cur_altsetting;
644
645 /* set up the endpoint information */
646 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
647 endpoint = &iface_desc->endpoint[i].desc;
648
649 if (((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN) &&
650 ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT)) {
651 dev->interrupt_in_endpoint = endpoint;
652 }
653
654 if (((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT) &&
655 ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT)) {
656 dev->interrupt_out_endpoint = endpoint;
657 }
658 }
659 if (dev->interrupt_in_endpoint == NULL) {
660 dev_err(&intf->dev, "Interrupt in endpoint not found\n");
661 goto error;
662 }
663 if (dev->interrupt_out_endpoint == NULL)
664 dev_warn(&intf->dev, "Interrupt out endpoint not found (using control endpoint instead)\n");
665
666 dev->interrupt_in_endpoint_size = le16_to_cpu(dev->interrupt_in_endpoint->wMaxPacketSize);
667 dev->ring_buffer = kmalloc(ring_buffer_size*(sizeof(size_t)+dev->interrupt_in_endpoint_size), GFP_KERNEL);
668 if (!dev->ring_buffer) {
669 dev_err(&intf->dev, "Couldn't allocate ring_buffer\n");
670 goto error;
671 }
672 dev->interrupt_in_buffer = kmalloc(dev->interrupt_in_endpoint_size, GFP_KERNEL);
673 if (!dev->interrupt_in_buffer) {
674 dev_err(&intf->dev, "Couldn't allocate interrupt_in_buffer\n");
675 goto error;
676 }
677 dev->interrupt_in_urb = usb_alloc_urb(0, GFP_KERNEL);
678 if (!dev->interrupt_in_urb) {
679 dev_err(&intf->dev, "Couldn't allocate interrupt_in_urb\n");
680 goto error;
681 }
682 dev->interrupt_out_endpoint_size = dev->interrupt_out_endpoint ? le16_to_cpu(dev->interrupt_out_endpoint->wMaxPacketSize) :
683 udev->descriptor.bMaxPacketSize0;
684 dev->interrupt_out_buffer = kmalloc(write_buffer_size*dev->interrupt_out_endpoint_size, GFP_KERNEL);
685 if (!dev->interrupt_out_buffer) {
686 dev_err(&intf->dev, "Couldn't allocate interrupt_out_buffer\n");
687 goto error;
688 }
689 dev->interrupt_out_urb = usb_alloc_urb(0, GFP_KERNEL);
690 if (!dev->interrupt_out_urb) {
691 dev_err(&intf->dev, "Couldn't allocate interrupt_out_urb\n");
692 goto error;
693 }
694 dev->interrupt_in_interval = min_interrupt_in_interval > dev->interrupt_in_endpoint->bInterval ? min_interrupt_in_interval : dev->interrupt_in_endpoint->bInterval;
695 if (dev->interrupt_out_endpoint)
696 dev->interrupt_out_interval = min_interrupt_out_interval > dev->interrupt_out_endpoint->bInterval ? min_interrupt_out_interval : dev->interrupt_out_endpoint->bInterval;
697
698 /* we can register the device now, as it is ready */
699 usb_set_intfdata(intf, dev);
700
701 retval = usb_register_dev(intf, &ld_usb_class);
702 if (retval) {
703 /* something prevented us from registering this driver */
704 dev_err(&intf->dev, "Not able to get a minor for this device.\n");
705 usb_set_intfdata(intf, NULL);
706 goto error;
707 }
708
709 /* let the user know what node this device is now attached to */
710 dev_info(&intf->dev, "LD USB Device #%d now attached to major %d minor %d\n",
711 (intf->minor - USB_LD_MINOR_BASE), USB_MAJOR, intf->minor);
712
713exit:
714 return retval;
715
716error:
717 ld_usb_delete(dev);
718
719 return retval;
720}
721
722/**
723 * ld_usb_disconnect
724 *
725 * Called by the usb core when the device is removed from the system.
726 */
727static void ld_usb_disconnect(struct usb_interface *intf)
728{
729 struct ld_usb *dev;
730 int minor;
731
732 down(&disconnect_sem);
733
734 dev = usb_get_intfdata(intf);
735 usb_set_intfdata(intf, NULL);
736
737 down(&dev->sem);
738
739 minor = intf->minor;
740
741 /* give back our minor */
742 usb_deregister_dev(intf, &ld_usb_class);
743
744 /* if the device is not opened, then we clean up right now */
745 if (!dev->open_count) {
746 up(&dev->sem);
747 ld_usb_delete(dev);
748 } else {
749 dev->intf = NULL;
750 up(&dev->sem);
751 }
752
753 up(&disconnect_sem);
754
755 dev_info(&intf->dev, "LD USB Device #%d now disconnected\n",
756 (minor - USB_LD_MINOR_BASE));
757}
758
759/* usb specific object needed to register this driver with the usb subsystem */
760static struct usb_driver ld_usb_driver = {
761 .owner = THIS_MODULE,
762 .name = "ldusb",
763 .probe = ld_usb_probe,
764 .disconnect = ld_usb_disconnect,
765 .id_table = ld_usb_table,
766};
767
768/**
769 * ld_usb_init
770 */
771static int __init ld_usb_init(void)
772{
773 int retval;
774
775 /* register this driver with the USB subsystem */
776 retval = usb_register(&ld_usb_driver);
777 if (retval)
778 err("usb_register failed for the "__FILE__" driver. Error number %d\n", retval);
779
780 return retval;
781}
782
783/**
784 * ld_usb_exit
785 */
786static void __exit ld_usb_exit(void)
787{
788 /* deregister this driver with the USB subsystem */
789 usb_deregister(&ld_usb_driver);
790}
791
792module_init(ld_usb_init);
793module_exit(ld_usb_exit);
794
diff --git a/drivers/usb/mon/mon_text.c b/drivers/usb/mon/mon_text.c
index 755a4570477f..26266b30028e 100644
--- a/drivers/usb/mon/mon_text.c
+++ b/drivers/usb/mon/mon_text.c
@@ -19,11 +19,16 @@
19#define DATA_MAX 32 19#define DATA_MAX 32
20 20
21/* 21/*
22 * Defined by USB 2.0 clause 9.3, table 9.2.
23 */
24#define SETUP_MAX 8
25
26/*
22 * This limit exists to prevent OOMs when the user process stops reading. 27 * This limit exists to prevent OOMs when the user process stops reading.
23 */ 28 */
24#define EVENT_MAX 25 29#define EVENT_MAX 25
25 30
26#define PRINTF_DFL 120 31#define PRINTF_DFL 130
27 32
28struct mon_event_text { 33struct mon_event_text {
29 struct list_head e_link; 34 struct list_head e_link;
@@ -33,7 +38,9 @@ struct mon_event_text {
33 unsigned int tstamp; 38 unsigned int tstamp;
34 int length; /* Depends on type: xfer length or act length */ 39 int length; /* Depends on type: xfer length or act length */
35 int status; 40 int status;
41 char setup_flag;
36 char data_flag; 42 char data_flag;
43 unsigned char setup[SETUP_MAX];
37 unsigned char data[DATA_MAX]; 44 unsigned char data[DATA_MAX];
38}; 45};
39 46
@@ -64,6 +71,22 @@ static void mon_text_dtor(void *, kmem_cache_t *, unsigned long);
64 * This is called with the whole mon_bus locked, so no additional lock. 71 * This is called with the whole mon_bus locked, so no additional lock.
65 */ 72 */
66 73
74static inline char mon_text_get_setup(struct mon_event_text *ep,
75 struct urb *urb, char ev_type)
76{
77
78 if (!usb_pipecontrol(urb->pipe) || ev_type != 'S')
79 return '-';
80
81 if (urb->transfer_flags & URB_NO_SETUP_DMA_MAP)
82 return 'D';
83 if (urb->setup_packet == NULL)
84 return 'Z'; /* '0' would be not as pretty. */
85
86 memcpy(ep->setup, urb->setup_packet, SETUP_MAX);
87 return 0;
88}
89
67static inline char mon_text_get_data(struct mon_event_text *ep, struct urb *urb, 90static inline char mon_text_get_data(struct mon_event_text *ep, struct urb *urb,
68 int len, char ev_type) 91 int len, char ev_type)
69{ 92{
@@ -90,7 +113,6 @@ static inline char mon_text_get_data(struct mon_event_text *ep, struct urb *urb,
90 113
91 /* 114 /*
92 * Bulk is easy to shortcut reliably. 115 * Bulk is easy to shortcut reliably.
93 * XXX Control needs setup packet taken.
94 * XXX Other pipe types need consideration. Currently, we overdo it 116 * XXX Other pipe types need consideration. Currently, we overdo it
95 * and collect garbage for them: better more than less. 117 * and collect garbage for them: better more than less.
96 */ 118 */
@@ -144,6 +166,7 @@ static void mon_text_event(struct mon_reader_text *rp, struct urb *urb,
144 /* Collecting status makes debugging sense for submits, too */ 166 /* Collecting status makes debugging sense for submits, too */
145 ep->status = urb->status; 167 ep->status = urb->status;
146 168
169 ep->setup_flag = mon_text_get_setup(ep, urb, ev_type);
147 ep->data_flag = mon_text_get_data(ep, urb, ep->length, ev_type); 170 ep->data_flag = mon_text_get_data(ep, urb, ep->length, ev_type);
148 171
149 rp->nevents++; 172 rp->nevents++;
@@ -299,10 +322,25 @@ static ssize_t mon_text_read(struct file *file, char __user *buf,
299 default: /* PIPE_BULK */ utype = 'B'; 322 default: /* PIPE_BULK */ utype = 'B';
300 } 323 }
301 cnt += snprintf(pbuf + cnt, limit - cnt, 324 cnt += snprintf(pbuf + cnt, limit - cnt,
302 "%lx %u %c %c%c:%03u:%02u %d %d", 325 "%lx %u %c %c%c:%03u:%02u",
303 ep->id, ep->tstamp, ep->type, 326 ep->id, ep->tstamp, ep->type,
304 utype, udir, usb_pipedevice(ep->pipe), usb_pipeendpoint(ep->pipe), 327 utype, udir, usb_pipedevice(ep->pipe), usb_pipeendpoint(ep->pipe));
305 ep->status, ep->length); 328
329 if (ep->setup_flag == 0) { /* Setup packet is present and captured */
330 cnt += snprintf(pbuf + cnt, limit - cnt,
331 " s %02x %02x %04x %04x %04x",
332 ep->setup[0],
333 ep->setup[1],
334 (ep->setup[3] << 8) | ep->setup[2],
335 (ep->setup[5] << 8) | ep->setup[4],
336 (ep->setup[7] << 8) | ep->setup[6]);
337 } else if (ep->setup_flag != '-') { /* Unable to capture setup packet */
338 cnt += snprintf(pbuf + cnt, limit - cnt,
339 " %c __ __ ____ ____ ____", ep->setup_flag);
340 } else { /* No setup for this kind of URB */
341 cnt += snprintf(pbuf + cnt, limit - cnt, " %d", ep->status);
342 }
343 cnt += snprintf(pbuf + cnt, limit - cnt, " %d", ep->length);
306 344
307 if ((data_len = ep->length) > 0) { 345 if ((data_len = ep->length) > 0) {
308 if (ep->data_flag == 0) { 346 if (ep->data_flag == 0) {
diff --git a/drivers/usb/net/kaweth.c b/drivers/usb/net/kaweth.c
index fd6ff4cb2c62..7ffa99b9760f 100644
--- a/drivers/usb/net/kaweth.c
+++ b/drivers/usb/net/kaweth.c
@@ -477,7 +477,7 @@ static int kaweth_reset(struct kaweth_device *kaweth)
477} 477}
478 478
479static void kaweth_usb_receive(struct urb *, struct pt_regs *regs); 479static void kaweth_usb_receive(struct urb *, struct pt_regs *regs);
480static int kaweth_resubmit_rx_urb(struct kaweth_device *, int); 480static int kaweth_resubmit_rx_urb(struct kaweth_device *, unsigned);
481 481
482/**************************************************************** 482/****************************************************************
483 int_callback 483 int_callback
@@ -550,7 +550,7 @@ static void kaweth_resubmit_tl(void *d)
550 * kaweth_resubmit_rx_urb 550 * kaweth_resubmit_rx_urb
551 ****************************************************************/ 551 ****************************************************************/
552static int kaweth_resubmit_rx_urb(struct kaweth_device *kaweth, 552static int kaweth_resubmit_rx_urb(struct kaweth_device *kaweth,
553 int mem_flags) 553 unsigned mem_flags)
554{ 554{
555 int result; 555 int result;
556 556
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index d882fa3ad19a..0b03ddab53d9 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -264,16 +264,26 @@
264/* 264/*
265 * Version Information 265 * Version Information
266 */ 266 */
267#define DRIVER_VERSION "v1.4.2" 267#define DRIVER_VERSION "v1.4.3"
268#define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Bill Ryder <bryder@sgi.com>, Kuba Ober <kuba@mareimbrium.org>" 268#define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Bill Ryder <bryder@sgi.com>, Kuba Ober <kuba@mareimbrium.org>"
269#define DRIVER_DESC "USB FTDI Serial Converters Driver" 269#define DRIVER_DESC "USB FTDI Serial Converters Driver"
270 270
271static int debug; 271static int debug;
272 272
273static struct usb_device_id id_table_sio [] = { 273/* struct ftdi_sio_quirk is used by devices requiring special attention. */
274 { USB_DEVICE(FTDI_VID, FTDI_SIO_PID) }, 274struct ftdi_sio_quirk {
275 { USB_DEVICE(MOBILITY_VID, MOBILITY_USB_SERIAL_PID) }, 275 void (*setup)(struct usb_serial *); /* Special settings during startup. */
276 { } /* Terminating entry */ 276};
277
278static void ftdi_USB_UIRT_setup (struct usb_serial *serial);
279static void ftdi_HE_TIRA1_setup (struct usb_serial *serial);
280
281static struct ftdi_sio_quirk ftdi_USB_UIRT_quirk = {
282 .setup = ftdi_USB_UIRT_setup,
283};
284
285static struct ftdi_sio_quirk ftdi_HE_TIRA1_quirk = {
286 .setup = ftdi_HE_TIRA1_setup,
277}; 287};
278 288
279/* 289/*
@@ -288,237 +298,11 @@ static struct usb_device_id id_table_sio [] = {
288 * the bcdDevice value is used to differentiate FT232BM and FT245BM from 298 * the bcdDevice value is used to differentiate FT232BM and FT245BM from
289 * the earlier FT8U232AM and FT8U232BM. For now, include all known VID/PID 299 * the earlier FT8U232AM and FT8U232BM. For now, include all known VID/PID
290 * combinations in both tables. 300 * combinations in both tables.
291 * FIXME: perhaps bcdDevice can also identify 12MHz devices, but I don't know 301 * FIXME: perhaps bcdDevice can also identify 12MHz FT8U232AM devices,
292 * if those ever went into mass production. [Ian Abbott] 302 * but I don't know if those ever went into mass production. [Ian Abbott]
293 */ 303 */
294 304
295 305
296static struct usb_device_id id_table_8U232AM [] = {
297 { USB_DEVICE_VER(FTDI_VID, FTDI_IRTRANS_PID, 0, 0x3ff) },
298 { USB_DEVICE_VER(FTDI_VID, FTDI_8U232AM_PID, 0, 0x3ff) },
299 { USB_DEVICE_VER(FTDI_VID, FTDI_8U232AM_ALT_PID, 0, 0x3ff) },
300 { USB_DEVICE_VER(FTDI_VID, FTDI_RELAIS_PID, 0, 0x3ff) },
301 { USB_DEVICE(INTERBIOMETRICS_VID, INTERBIOMETRICS_IOBOARD_PID) },
302 { USB_DEVICE(INTERBIOMETRICS_VID, INTERBIOMETRICS_MINI_IOBOARD_PID) },
303 { USB_DEVICE_VER(FTDI_NF_RIC_VID, FTDI_NF_RIC_PID, 0, 0x3ff) },
304 { USB_DEVICE_VER(FTDI_VID, FTDI_XF_632_PID, 0, 0x3ff) },
305 { USB_DEVICE_VER(FTDI_VID, FTDI_XF_634_PID, 0, 0x3ff) },
306 { USB_DEVICE_VER(FTDI_VID, FTDI_XF_547_PID, 0, 0x3ff) },
307 { USB_DEVICE_VER(FTDI_VID, FTDI_XF_633_PID, 0, 0x3ff) },
308 { USB_DEVICE_VER(FTDI_VID, FTDI_XF_631_PID, 0, 0x3ff) },
309 { USB_DEVICE_VER(FTDI_VID, FTDI_XF_635_PID, 0, 0x3ff) },
310 { USB_DEVICE_VER(FTDI_VID, FTDI_XF_640_PID, 0, 0x3ff) },
311 { USB_DEVICE_VER(FTDI_VID, FTDI_XF_642_PID, 0, 0x3ff) },
312 { USB_DEVICE_VER(FTDI_VID, FTDI_VNHCPCUSB_D_PID, 0, 0x3ff) },
313 { USB_DEVICE_VER(FTDI_VID, FTDI_DSS20_PID, 0, 0x3ff) },
314 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2101_PID, 0, 0x3ff) },
315 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2102_PID, 0, 0x3ff) },
316 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2103_PID, 0, 0x3ff) },
317 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2104_PID, 0, 0x3ff) },
318 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2201_1_PID, 0, 0x3ff) },
319 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2201_2_PID, 0, 0x3ff) },
320 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2202_1_PID, 0, 0x3ff) },
321 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2202_2_PID, 0, 0x3ff) },
322 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2203_1_PID, 0, 0x3ff) },
323 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2203_2_PID, 0, 0x3ff) },
324 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2401_1_PID, 0, 0x3ff) },
325 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2401_2_PID, 0, 0x3ff) },
326 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2401_3_PID, 0, 0x3ff) },
327 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2401_4_PID, 0, 0x3ff) },
328 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2402_1_PID, 0, 0x3ff) },
329 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2402_2_PID, 0, 0x3ff) },
330 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2402_3_PID, 0, 0x3ff) },
331 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2402_4_PID, 0, 0x3ff) },
332 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2403_1_PID, 0, 0x3ff) },
333 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2403_2_PID, 0, 0x3ff) },
334 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2403_3_PID, 0, 0x3ff) },
335 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2403_4_PID, 0, 0x3ff) },
336 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2801_1_PID, 0, 0x3ff) },
337 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2801_2_PID, 0, 0x3ff) },
338 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2801_3_PID, 0, 0x3ff) },
339 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2801_4_PID, 0, 0x3ff) },
340 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2801_5_PID, 0, 0x3ff) },
341 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2801_6_PID, 0, 0x3ff) },
342 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2801_7_PID, 0, 0x3ff) },
343 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2801_8_PID, 0, 0x3ff) },
344 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2802_1_PID, 0, 0x3ff) },
345 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2802_2_PID, 0, 0x3ff) },
346 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2802_3_PID, 0, 0x3ff) },
347 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2802_4_PID, 0, 0x3ff) },
348 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2802_5_PID, 0, 0x3ff) },
349 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2802_6_PID, 0, 0x3ff) },
350 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2802_7_PID, 0, 0x3ff) },
351 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2802_8_PID, 0, 0x3ff) },
352 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2803_1_PID, 0, 0x3ff) },
353 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2803_2_PID, 0, 0x3ff) },
354 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2803_3_PID, 0, 0x3ff) },
355 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2803_4_PID, 0, 0x3ff) },
356 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2803_5_PID, 0, 0x3ff) },
357 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2803_6_PID, 0, 0x3ff) },
358 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2803_7_PID, 0, 0x3ff) },
359 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2803_8_PID, 0, 0x3ff) },
360 { USB_DEVICE_VER(IDTECH_VID, IDTECH_IDT1221U_PID, 0, 0x3ff) },
361 { USB_DEVICE_VER(OCT_VID, OCT_US101_PID, 0, 0x3ff) },
362 { USB_DEVICE_VER(FTDI_VID, PROTEGO_SPECIAL_1, 0, 0x3ff) },
363 { USB_DEVICE_VER(FTDI_VID, PROTEGO_R2X0, 0, 0x3ff) },
364 { USB_DEVICE_VER(FTDI_VID, PROTEGO_SPECIAL_3, 0, 0x3ff) },
365 { USB_DEVICE_VER(FTDI_VID, PROTEGO_SPECIAL_4, 0, 0x3ff) },
366 { USB_DEVICE_VER(FTDI_VID, FTDI_ELV_UO100_PID, 0, 0x3ff) },
367 { USB_DEVICE_VER(FTDI_VID, FTDI_ELV_UM100_PID, 0, 0x3ff) },
368 { USB_DEVICE_VER(FTDI_VID, INSIDE_ACCESSO, 0, 0x3ff) },
369 { USB_DEVICE_VER(INTREPID_VID, INTREPID_VALUECAN_PID, 0, 0x3ff) },
370 { USB_DEVICE_VER(INTREPID_VID, INTREPID_NEOVI_PID, 0, 0x3ff) },
371 { USB_DEVICE_VER(FALCOM_VID, FALCOM_TWIST_PID, 0, 0x3ff) },
372 { USB_DEVICE_VER(FTDI_VID, FTDI_SUUNTO_SPORTS_PID, 0, 0x3ff) },
373 { USB_DEVICE_VER(FTDI_VID, FTDI_RM_CANVIEW_PID, 0, 0x3ff) },
374 { USB_DEVICE_VER(BANDB_VID, BANDB_USOTL4_PID, 0, 0x3ff) },
375 { USB_DEVICE_VER(BANDB_VID, BANDB_USTL4_PID, 0, 0x3ff) },
376 { USB_DEVICE_VER(BANDB_VID, BANDB_USO9ML2_PID, 0, 0x3ff) },
377 { USB_DEVICE_VER(FTDI_VID, EVER_ECO_PRO_CDS, 0, 0x3ff) },
378 { USB_DEVICE_VER(FTDI_VID, FTDI_4N_GALAXY_DE_0_PID, 0, 0x3ff) },
379 { USB_DEVICE_VER(FTDI_VID, FTDI_4N_GALAXY_DE_1_PID, 0, 0x3ff) },
380 { USB_DEVICE_VER(FTDI_VID, FTDI_4N_GALAXY_DE_2_PID, 0, 0x3ff) },
381 { } /* Terminating entry */
382};
383
384
385static struct usb_device_id id_table_FT232BM [] = {
386 { USB_DEVICE_VER(FTDI_VID, FTDI_IRTRANS_PID, 0x400, 0xffff) },
387 { USB_DEVICE_VER(FTDI_VID, FTDI_8U232AM_PID, 0x400, 0xffff) },
388 { USB_DEVICE_VER(FTDI_VID, FTDI_8U232AM_ALT_PID, 0x400, 0xffff) },
389 { USB_DEVICE_VER(FTDI_VID, FTDI_RELAIS_PID, 0x400, 0xffff) },
390 { USB_DEVICE_VER(FTDI_NF_RIC_VID, FTDI_NF_RIC_PID, 0x400, 0xffff) },
391 { USB_DEVICE_VER(FTDI_VID, FTDI_XF_632_PID, 0x400, 0xffff) },
392 { USB_DEVICE_VER(FTDI_VID, FTDI_XF_634_PID, 0x400, 0xffff) },
393 { USB_DEVICE_VER(FTDI_VID, FTDI_XF_547_PID, 0x400, 0xffff) },
394 { USB_DEVICE_VER(FTDI_VID, FTDI_XF_633_PID, 0x400, 0xffff) },
395 { USB_DEVICE_VER(FTDI_VID, FTDI_XF_631_PID, 0x400, 0xffff) },
396 { USB_DEVICE_VER(FTDI_VID, FTDI_XF_635_PID, 0x400, 0xffff) },
397 { USB_DEVICE_VER(FTDI_VID, FTDI_XF_640_PID, 0x400, 0xffff) },
398 { USB_DEVICE_VER(FTDI_VID, FTDI_XF_642_PID, 0x400, 0xffff) },
399 { USB_DEVICE_VER(FTDI_VID, FTDI_VNHCPCUSB_D_PID, 0x400, 0xffff) },
400 { USB_DEVICE_VER(FTDI_VID, FTDI_DSS20_PID, 0x400, 0xffff) },
401 { USB_DEVICE_VER(FTDI_VID, FTDI_MTXORB_0_PID, 0x400, 0xffff) },
402 { USB_DEVICE_VER(FTDI_VID, FTDI_MTXORB_1_PID, 0x400, 0xffff) },
403 { USB_DEVICE_VER(FTDI_VID, FTDI_MTXORB_2_PID, 0x400, 0xffff) },
404 { USB_DEVICE_VER(FTDI_VID, FTDI_MTXORB_3_PID, 0x400, 0xffff) },
405 { USB_DEVICE_VER(FTDI_VID, FTDI_MTXORB_4_PID, 0x400, 0xffff) },
406 { USB_DEVICE_VER(FTDI_VID, FTDI_MTXORB_5_PID, 0x400, 0xffff) },
407 { USB_DEVICE_VER(FTDI_VID, FTDI_MTXORB_6_PID, 0x400, 0xffff) },
408 { USB_DEVICE_VER(FTDI_VID, FTDI_PERLE_ULTRAPORT_PID, 0x400, 0xffff) },
409 { USB_DEVICE_VER(FTDI_VID, FTDI_PIEGROUP_PID, 0x400, 0xffff) },
410 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2101_PID, 0x400, 0xffff) },
411 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2102_PID, 0x400, 0xffff) },
412 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2103_PID, 0x400, 0xffff) },
413 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2104_PID, 0x400, 0xffff) },
414 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2201_1_PID, 0x400, 0xffff) },
415 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2201_2_PID, 0x400, 0xffff) },
416 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2202_1_PID, 0x400, 0xffff) },
417 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2202_2_PID, 0x400, 0xffff) },
418 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2203_1_PID, 0x400, 0xffff) },
419 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2203_2_PID, 0x400, 0xffff) },
420 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2401_1_PID, 0x400, 0xffff) },
421 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2401_2_PID, 0x400, 0xffff) },
422 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2401_3_PID, 0x400, 0xffff) },
423 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2401_4_PID, 0x400, 0xffff) },
424 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2402_1_PID, 0x400, 0xffff) },
425 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2402_2_PID, 0x400, 0xffff) },
426 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2402_3_PID, 0x400, 0xffff) },
427 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2402_4_PID, 0x400, 0xffff) },
428 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2403_1_PID, 0x400, 0xffff) },
429 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2403_2_PID, 0x400, 0xffff) },
430 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2403_3_PID, 0x400, 0xffff) },
431 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2403_4_PID, 0x400, 0xffff) },
432 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2801_1_PID, 0x400, 0xffff) },
433 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2801_2_PID, 0x400, 0xffff) },
434 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2801_3_PID, 0x400, 0xffff) },
435 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2801_4_PID, 0x400, 0xffff) },
436 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2801_5_PID, 0x400, 0xffff) },
437 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2801_6_PID, 0x400, 0xffff) },
438 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2801_7_PID, 0x400, 0xffff) },
439 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2801_8_PID, 0x400, 0xffff) },
440 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2802_1_PID, 0x400, 0xffff) },
441 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2802_2_PID, 0x400, 0xffff) },
442 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2802_3_PID, 0x400, 0xffff) },
443 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2802_4_PID, 0x400, 0xffff) },
444 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2802_5_PID, 0x400, 0xffff) },
445 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2802_6_PID, 0x400, 0xffff) },
446 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2802_7_PID, 0x400, 0xffff) },
447 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2802_8_PID, 0x400, 0xffff) },
448 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2803_1_PID, 0x400, 0xffff) },
449 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2803_2_PID, 0x400, 0xffff) },
450 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2803_3_PID, 0x400, 0xffff) },
451 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2803_4_PID, 0x400, 0xffff) },
452 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2803_5_PID, 0x400, 0xffff) },
453 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2803_6_PID, 0x400, 0xffff) },
454 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2803_7_PID, 0x400, 0xffff) },
455 { USB_DEVICE_VER(SEALEVEL_VID, SEALEVEL_2803_8_PID, 0x400, 0xffff) },
456 { USB_DEVICE_VER(IDTECH_VID, IDTECH_IDT1221U_PID, 0x400, 0xffff) },
457 { USB_DEVICE_VER(OCT_VID, OCT_US101_PID, 0x400, 0xffff) },
458 { USB_DEVICE_VER(FTDI_VID, PROTEGO_SPECIAL_1, 0x400, 0xffff) },
459 { USB_DEVICE_VER(FTDI_VID, PROTEGO_R2X0, 0x400, 0xffff) },
460 { USB_DEVICE_VER(FTDI_VID, PROTEGO_SPECIAL_3, 0x400, 0xffff) },
461 { USB_DEVICE_VER(FTDI_VID, PROTEGO_SPECIAL_4, 0x400, 0xffff) },
462 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E808_PID, 0x400, 0xffff) },
463 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E809_PID, 0x400, 0xffff) },
464 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E80A_PID, 0x400, 0xffff) },
465 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E80B_PID, 0x400, 0xffff) },
466 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E80C_PID, 0x400, 0xffff) },
467 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E80D_PID, 0x400, 0xffff) },
468 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E80E_PID, 0x400, 0xffff) },
469 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E80F_PID, 0x400, 0xffff) },
470 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E888_PID, 0x400, 0xffff) },
471 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E889_PID, 0x400, 0xffff) },
472 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E88A_PID, 0x400, 0xffff) },
473 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E88B_PID, 0x400, 0xffff) },
474 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E88C_PID, 0x400, 0xffff) },
475 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E88D_PID, 0x400, 0xffff) },
476 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E88E_PID, 0x400, 0xffff) },
477 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E88F_PID, 0x400, 0xffff) },
478 { USB_DEVICE_VER(FTDI_VID, FTDI_ELV_UO100_PID, 0x400, 0xffff) },
479 { USB_DEVICE_VER(FTDI_VID, FTDI_ELV_UM100_PID, 0x400, 0xffff) },
480 { USB_DEVICE_VER(FTDI_VID, LINX_SDMUSBQSS_PID, 0x400, 0xffff) },
481 { USB_DEVICE_VER(FTDI_VID, LINX_MASTERDEVEL2_PID, 0x400, 0xffff) },
482 { USB_DEVICE_VER(FTDI_VID, LINX_FUTURE_0_PID, 0x400, 0xffff) },
483 { USB_DEVICE_VER(FTDI_VID, LINX_FUTURE_1_PID, 0x400, 0xffff) },
484 { USB_DEVICE_VER(FTDI_VID, LINX_FUTURE_2_PID, 0x400, 0xffff) },
485 { USB_DEVICE(FTDI_VID, FTDI_CCSICDU20_0_PID) },
486 { USB_DEVICE(FTDI_VID, FTDI_CCSICDU40_1_PID) },
487 { USB_DEVICE_VER(FTDI_VID, INSIDE_ACCESSO, 0x400, 0xffff) },
488 { USB_DEVICE_VER(INTREPID_VID, INTREPID_VALUECAN_PID, 0x400, 0xffff) },
489 { USB_DEVICE_VER(INTREPID_VID, INTREPID_NEOVI_PID, 0x400, 0xffff) },
490 { USB_DEVICE_VER(FALCOM_VID, FALCOM_TWIST_PID, 0x400, 0xffff) },
491 { USB_DEVICE_VER(FTDI_VID, FTDI_SUUNTO_SPORTS_PID, 0x400, 0xffff) },
492 { USB_DEVICE_VER(FTDI_VID, FTDI_RM_CANVIEW_PID, 0x400, 0xffff) },
493 { USB_DEVICE_VER(BANDB_VID, BANDB_USOTL4_PID, 0x400, 0xffff) },
494 { USB_DEVICE_VER(BANDB_VID, BANDB_USTL4_PID, 0x400, 0xffff) },
495 { USB_DEVICE_VER(BANDB_VID, BANDB_USO9ML2_PID, 0x400, 0xffff) },
496 { USB_DEVICE_VER(FTDI_VID, EVER_ECO_PRO_CDS, 0x400, 0xffff) },
497 { USB_DEVICE_VER(FTDI_VID, FTDI_4N_GALAXY_DE_0_PID, 0x400, 0xffff) },
498 { USB_DEVICE_VER(FTDI_VID, FTDI_4N_GALAXY_DE_1_PID, 0x400, 0xffff) },
499 { USB_DEVICE_VER(FTDI_VID, FTDI_4N_GALAXY_DE_2_PID, 0x400, 0xffff) },
500 { USB_DEVICE_VER(FTDI_VID, FTDI_ACTIVE_ROBOTS_PID, 0x400, 0xffff) },
501 { } /* Terminating entry */
502};
503
504
505static struct usb_device_id id_table_USB_UIRT [] = {
506 { USB_DEVICE(FTDI_VID, FTDI_USB_UIRT_PID) },
507 { } /* Terminating entry */
508};
509
510
511static struct usb_device_id id_table_HE_TIRA1 [] = {
512 { USB_DEVICE_VER(FTDI_VID, FTDI_HE_TIRA1_PID, 0x400, 0xffff) },
513 { } /* Terminating entry */
514};
515
516
517static struct usb_device_id id_table_FT2232C[] = {
518 { USB_DEVICE(FTDI_VID, FTDI_8U2232C_PID) },
519 { } /* Terminating entry */
520};
521
522 306
523static struct usb_device_id id_table_combined [] = { 307static struct usb_device_id id_table_combined [] = {
524 { USB_DEVICE(FTDI_VID, FTDI_IRTRANS_PID) }, 308 { USB_DEVICE(FTDI_VID, FTDI_IRTRANS_PID) },
@@ -540,14 +324,14 @@ static struct usb_device_id id_table_combined [] = {
540 { USB_DEVICE(FTDI_VID, FTDI_DSS20_PID) }, 324 { USB_DEVICE(FTDI_VID, FTDI_DSS20_PID) },
541 { USB_DEVICE(FTDI_NF_RIC_VID, FTDI_NF_RIC_PID) }, 325 { USB_DEVICE(FTDI_NF_RIC_VID, FTDI_NF_RIC_PID) },
542 { USB_DEVICE(FTDI_VID, FTDI_VNHCPCUSB_D_PID) }, 326 { USB_DEVICE(FTDI_VID, FTDI_VNHCPCUSB_D_PID) },
543 { USB_DEVICE_VER(FTDI_VID, FTDI_MTXORB_0_PID, 0x400, 0xffff) }, 327 { USB_DEVICE(FTDI_VID, FTDI_MTXORB_0_PID) },
544 { USB_DEVICE_VER(FTDI_VID, FTDI_MTXORB_1_PID, 0x400, 0xffff) }, 328 { USB_DEVICE(FTDI_VID, FTDI_MTXORB_1_PID) },
545 { USB_DEVICE_VER(FTDI_VID, FTDI_MTXORB_2_PID, 0x400, 0xffff) }, 329 { USB_DEVICE(FTDI_VID, FTDI_MTXORB_2_PID) },
546 { USB_DEVICE_VER(FTDI_VID, FTDI_MTXORB_3_PID, 0x400, 0xffff) }, 330 { USB_DEVICE(FTDI_VID, FTDI_MTXORB_3_PID) },
547 { USB_DEVICE_VER(FTDI_VID, FTDI_MTXORB_4_PID, 0x400, 0xffff) }, 331 { USB_DEVICE(FTDI_VID, FTDI_MTXORB_4_PID) },
548 { USB_DEVICE_VER(FTDI_VID, FTDI_MTXORB_5_PID, 0x400, 0xffff) }, 332 { USB_DEVICE(FTDI_VID, FTDI_MTXORB_5_PID) },
549 { USB_DEVICE_VER(FTDI_VID, FTDI_MTXORB_6_PID, 0x400, 0xffff) }, 333 { USB_DEVICE(FTDI_VID, FTDI_MTXORB_6_PID) },
550 { USB_DEVICE_VER(FTDI_VID, FTDI_PERLE_ULTRAPORT_PID, 0x400, 0xffff) }, 334 { USB_DEVICE(FTDI_VID, FTDI_PERLE_ULTRAPORT_PID) },
551 { USB_DEVICE(FTDI_VID, FTDI_PIEGROUP_PID) }, 335 { USB_DEVICE(FTDI_VID, FTDI_PIEGROUP_PID) },
552 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2101_PID) }, 336 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2101_PID) },
553 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2102_PID) }, 337 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2102_PID) },
@@ -597,35 +381,37 @@ static struct usb_device_id id_table_combined [] = {
597 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2803_8_PID) }, 381 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2803_8_PID) },
598 { USB_DEVICE(IDTECH_VID, IDTECH_IDT1221U_PID) }, 382 { USB_DEVICE(IDTECH_VID, IDTECH_IDT1221U_PID) },
599 { USB_DEVICE(OCT_VID, OCT_US101_PID) }, 383 { USB_DEVICE(OCT_VID, OCT_US101_PID) },
600 { USB_DEVICE_VER(FTDI_VID, FTDI_HE_TIRA1_PID, 0x400, 0xffff) }, 384 { USB_DEVICE(FTDI_VID, FTDI_HE_TIRA1_PID),
601 { USB_DEVICE(FTDI_VID, FTDI_USB_UIRT_PID) }, 385 .driver_info = (kernel_ulong_t)&ftdi_HE_TIRA1_quirk },
386 { USB_DEVICE(FTDI_VID, FTDI_USB_UIRT_PID),
387 .driver_info = (kernel_ulong_t)&ftdi_USB_UIRT_quirk },
602 { USB_DEVICE(FTDI_VID, PROTEGO_SPECIAL_1) }, 388 { USB_DEVICE(FTDI_VID, PROTEGO_SPECIAL_1) },
603 { USB_DEVICE(FTDI_VID, PROTEGO_R2X0) }, 389 { USB_DEVICE(FTDI_VID, PROTEGO_R2X0) },
604 { USB_DEVICE(FTDI_VID, PROTEGO_SPECIAL_3) }, 390 { USB_DEVICE(FTDI_VID, PROTEGO_SPECIAL_3) },
605 { USB_DEVICE(FTDI_VID, PROTEGO_SPECIAL_4) }, 391 { USB_DEVICE(FTDI_VID, PROTEGO_SPECIAL_4) },
606 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E808_PID, 0x400, 0xffff) }, 392 { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E808_PID) },
607 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E809_PID, 0x400, 0xffff) }, 393 { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E809_PID) },
608 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E80A_PID, 0x400, 0xffff) }, 394 { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E80A_PID) },
609 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E80B_PID, 0x400, 0xffff) }, 395 { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E80B_PID) },
610 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E80C_PID, 0x400, 0xffff) }, 396 { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E80C_PID) },
611 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E80D_PID, 0x400, 0xffff) }, 397 { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E80D_PID) },
612 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E80E_PID, 0x400, 0xffff) }, 398 { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E80E_PID) },
613 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E80F_PID, 0x400, 0xffff) }, 399 { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E80F_PID) },
614 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E888_PID, 0x400, 0xffff) }, 400 { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E888_PID) },
615 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E889_PID, 0x400, 0xffff) }, 401 { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E889_PID) },
616 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E88A_PID, 0x400, 0xffff) }, 402 { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E88A_PID) },
617 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E88B_PID, 0x400, 0xffff) }, 403 { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E88B_PID) },
618 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E88C_PID, 0x400, 0xffff) }, 404 { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E88C_PID) },
619 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E88D_PID, 0x400, 0xffff) }, 405 { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E88D_PID) },
620 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E88E_PID, 0x400, 0xffff) }, 406 { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E88E_PID) },
621 { USB_DEVICE_VER(FTDI_VID, FTDI_GUDEADS_E88F_PID, 0x400, 0xffff) }, 407 { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E88F_PID) },
622 { USB_DEVICE(FTDI_VID, FTDI_ELV_UO100_PID) }, 408 { USB_DEVICE(FTDI_VID, FTDI_ELV_UO100_PID) },
623 { USB_DEVICE(FTDI_VID, FTDI_ELV_UM100_PID) }, 409 { USB_DEVICE(FTDI_VID, FTDI_ELV_UM100_PID) },
624 { USB_DEVICE_VER(FTDI_VID, LINX_SDMUSBQSS_PID, 0x400, 0xffff) }, 410 { USB_DEVICE(FTDI_VID, LINX_SDMUSBQSS_PID) },
625 { USB_DEVICE_VER(FTDI_VID, LINX_MASTERDEVEL2_PID, 0x400, 0xffff) }, 411 { USB_DEVICE(FTDI_VID, LINX_MASTERDEVEL2_PID) },
626 { USB_DEVICE_VER(FTDI_VID, LINX_FUTURE_0_PID, 0x400, 0xffff) }, 412 { USB_DEVICE(FTDI_VID, LINX_FUTURE_0_PID) },
627 { USB_DEVICE_VER(FTDI_VID, LINX_FUTURE_1_PID, 0x400, 0xffff) }, 413 { USB_DEVICE(FTDI_VID, LINX_FUTURE_1_PID) },
628 { USB_DEVICE_VER(FTDI_VID, LINX_FUTURE_2_PID, 0x400, 0xffff) }, 414 { USB_DEVICE(FTDI_VID, LINX_FUTURE_2_PID) },
629 { USB_DEVICE(FTDI_VID, FTDI_CCSICDU20_0_PID) }, 415 { USB_DEVICE(FTDI_VID, FTDI_CCSICDU20_0_PID) },
630 { USB_DEVICE(FTDI_VID, FTDI_CCSICDU40_1_PID) }, 416 { USB_DEVICE(FTDI_VID, FTDI_CCSICDU40_1_PID) },
631 { USB_DEVICE(FTDI_VID, INSIDE_ACCESSO) }, 417 { USB_DEVICE(FTDI_VID, INSIDE_ACCESSO) },
@@ -642,7 +428,7 @@ static struct usb_device_id id_table_combined [] = {
642 { USB_DEVICE(FTDI_VID, FTDI_4N_GALAXY_DE_1_PID) }, 428 { USB_DEVICE(FTDI_VID, FTDI_4N_GALAXY_DE_1_PID) },
643 { USB_DEVICE(FTDI_VID, FTDI_4N_GALAXY_DE_2_PID) }, 429 { USB_DEVICE(FTDI_VID, FTDI_4N_GALAXY_DE_2_PID) },
644 { USB_DEVICE(MOBILITY_VID, MOBILITY_USB_SERIAL_PID) }, 430 { USB_DEVICE(MOBILITY_VID, MOBILITY_USB_SERIAL_PID) },
645 { USB_DEVICE_VER(FTDI_VID, FTDI_ACTIVE_ROBOTS_PID, 0x400, 0xffff) }, 431 { USB_DEVICE(FTDI_VID, FTDI_ACTIVE_ROBOTS_PID) },
646 { } /* Terminating entry */ 432 { } /* Terminating entry */
647}; 433};
648 434
@@ -705,12 +491,8 @@ struct ftdi_private {
705 ASYNC_SPD_CUST | ASYNC_SPD_SHI | ASYNC_SPD_WARP ) 491 ASYNC_SPD_CUST | ASYNC_SPD_SHI | ASYNC_SPD_WARP )
706 492
707/* function prototypes for a FTDI serial converter */ 493/* function prototypes for a FTDI serial converter */
708static int ftdi_SIO_startup (struct usb_serial *serial); 494static int ftdi_sio_probe (struct usb_serial *serial, const struct usb_device_id *id);
709static int ftdi_8U232AM_startup (struct usb_serial *serial); 495static int ftdi_sio_attach (struct usb_serial *serial);
710static int ftdi_FT232BM_startup (struct usb_serial *serial);
711static int ftdi_FT2232C_startup (struct usb_serial *serial);
712static int ftdi_USB_UIRT_startup (struct usb_serial *serial);
713static int ftdi_HE_TIRA1_startup (struct usb_serial *serial);
714static void ftdi_shutdown (struct usb_serial *serial); 496static void ftdi_shutdown (struct usb_serial *serial);
715static int ftdi_open (struct usb_serial_port *port, struct file *filp); 497static int ftdi_open (struct usb_serial_port *port, struct file *filp);
716static void ftdi_close (struct usb_serial_port *port, struct file *filp); 498static void ftdi_close (struct usb_serial_port *port, struct file *filp);
@@ -733,14 +515,16 @@ static unsigned short int ftdi_232am_baud_to_divisor (int baud);
733static __u32 ftdi_232bm_baud_base_to_divisor (int baud, int base); 515static __u32 ftdi_232bm_baud_base_to_divisor (int baud, int base);
734static __u32 ftdi_232bm_baud_to_divisor (int baud); 516static __u32 ftdi_232bm_baud_to_divisor (int baud);
735 517
736static struct usb_serial_device_type ftdi_SIO_device = { 518static struct usb_serial_device_type ftdi_sio_device = {
737 .owner = THIS_MODULE, 519 .owner = THIS_MODULE,
738 .name = "FTDI SIO", 520 .name = "FTDI USB Serial Device",
739 .id_table = id_table_sio, 521 .short_name = "ftdi_sio",
522 .id_table = id_table_combined,
740 .num_interrupt_in = 0, 523 .num_interrupt_in = 0,
741 .num_bulk_in = 1, 524 .num_bulk_in = 1,
742 .num_bulk_out = 1, 525 .num_bulk_out = 1,
743 .num_ports = 1, 526 .num_ports = 1,
527 .probe = ftdi_sio_probe,
744 .open = ftdi_open, 528 .open = ftdi_open,
745 .close = ftdi_close, 529 .close = ftdi_close,
746 .throttle = ftdi_throttle, 530 .throttle = ftdi_throttle,
@@ -755,143 +539,10 @@ static struct usb_serial_device_type ftdi_SIO_device = {
755 .ioctl = ftdi_ioctl, 539 .ioctl = ftdi_ioctl,
756 .set_termios = ftdi_set_termios, 540 .set_termios = ftdi_set_termios,
757 .break_ctl = ftdi_break_ctl, 541 .break_ctl = ftdi_break_ctl,
758 .attach = ftdi_SIO_startup, 542 .attach = ftdi_sio_attach,
759 .shutdown = ftdi_shutdown, 543 .shutdown = ftdi_shutdown,
760}; 544};
761 545
762static struct usb_serial_device_type ftdi_8U232AM_device = {
763 .owner = THIS_MODULE,
764 .name = "FTDI 8U232AM Compatible",
765 .id_table = id_table_8U232AM,
766 .num_interrupt_in = 0,
767 .num_bulk_in = 1,
768 .num_bulk_out = 1,
769 .num_ports = 1,
770 .open = ftdi_open,
771 .close = ftdi_close,
772 .throttle = ftdi_throttle,
773 .unthrottle = ftdi_unthrottle,
774 .write = ftdi_write,
775 .write_room = ftdi_write_room,
776 .chars_in_buffer = ftdi_chars_in_buffer,
777 .read_bulk_callback = ftdi_read_bulk_callback,
778 .write_bulk_callback = ftdi_write_bulk_callback,
779 .tiocmget = ftdi_tiocmget,
780 .tiocmset = ftdi_tiocmset,
781 .ioctl = ftdi_ioctl,
782 .set_termios = ftdi_set_termios,
783 .break_ctl = ftdi_break_ctl,
784 .attach = ftdi_8U232AM_startup,
785 .shutdown = ftdi_shutdown,
786};
787
788static struct usb_serial_device_type ftdi_FT232BM_device = {
789 .owner = THIS_MODULE,
790 .name = "FTDI FT232BM Compatible",
791 .id_table = id_table_FT232BM,
792 .num_interrupt_in = 0,
793 .num_bulk_in = 1,
794 .num_bulk_out = 1,
795 .num_ports = 1,
796 .open = ftdi_open,
797 .close = ftdi_close,
798 .throttle = ftdi_throttle,
799 .unthrottle = ftdi_unthrottle,
800 .write = ftdi_write,
801 .write_room = ftdi_write_room,
802 .chars_in_buffer = ftdi_chars_in_buffer,
803 .read_bulk_callback = ftdi_read_bulk_callback,
804 .write_bulk_callback = ftdi_write_bulk_callback,
805 .tiocmget = ftdi_tiocmget,
806 .tiocmset = ftdi_tiocmset,
807 .ioctl = ftdi_ioctl,
808 .set_termios = ftdi_set_termios,
809 .break_ctl = ftdi_break_ctl,
810 .attach = ftdi_FT232BM_startup,
811 .shutdown = ftdi_shutdown,
812};
813
814static struct usb_serial_device_type ftdi_FT2232C_device = {
815 .owner = THIS_MODULE,
816 .name = "FTDI FT2232C Compatible",
817 .id_table = id_table_FT2232C,
818 .num_interrupt_in = 0,
819 .num_bulk_in = 1,
820 .num_bulk_out = 1,
821 .num_ports = 1,
822 .open = ftdi_open,
823 .close = ftdi_close,
824 .throttle = ftdi_throttle,
825 .unthrottle = ftdi_unthrottle,
826 .write = ftdi_write,
827 .write_room = ftdi_write_room,
828 .chars_in_buffer = ftdi_chars_in_buffer,
829 .read_bulk_callback = ftdi_read_bulk_callback,
830 .write_bulk_callback = ftdi_write_bulk_callback,
831 .tiocmget = ftdi_tiocmget,
832 .tiocmset = ftdi_tiocmset,
833 .ioctl = ftdi_ioctl,
834 .set_termios = ftdi_set_termios,
835 .break_ctl = ftdi_break_ctl,
836 .attach = ftdi_FT2232C_startup,
837 .shutdown = ftdi_shutdown,
838};
839
840static struct usb_serial_device_type ftdi_USB_UIRT_device = {
841 .owner = THIS_MODULE,
842 .name = "USB-UIRT Infrared Tranceiver",
843 .id_table = id_table_USB_UIRT,
844 .num_interrupt_in = 0,
845 .num_bulk_in = 1,
846 .num_bulk_out = 1,
847 .num_ports = 1,
848 .open = ftdi_open,
849 .close = ftdi_close,
850 .throttle = ftdi_throttle,
851 .unthrottle = ftdi_unthrottle,
852 .write = ftdi_write,
853 .write_room = ftdi_write_room,
854 .chars_in_buffer = ftdi_chars_in_buffer,
855 .read_bulk_callback = ftdi_read_bulk_callback,
856 .write_bulk_callback = ftdi_write_bulk_callback,
857 .tiocmget = ftdi_tiocmget,
858 .tiocmset = ftdi_tiocmset,
859 .ioctl = ftdi_ioctl,
860 .set_termios = ftdi_set_termios,
861 .break_ctl = ftdi_break_ctl,
862 .attach = ftdi_USB_UIRT_startup,
863 .shutdown = ftdi_shutdown,
864};
865
866/* The TIRA1 is based on a FT232BM which requires a fixed baud rate of 100000
867 * and which requires RTS-CTS to be enabled. */
868static struct usb_serial_device_type ftdi_HE_TIRA1_device = {
869 .owner = THIS_MODULE,
870 .name = "Home-Electronics TIRA-1 IR Transceiver",
871 .id_table = id_table_HE_TIRA1,
872 .num_interrupt_in = 0,
873 .num_bulk_in = 1,
874 .num_bulk_out = 1,
875 .num_ports = 1,
876 .open = ftdi_open,
877 .close = ftdi_close,
878 .throttle = ftdi_throttle,
879 .unthrottle = ftdi_unthrottle,
880 .write = ftdi_write,
881 .write_room = ftdi_write_room,
882 .chars_in_buffer = ftdi_chars_in_buffer,
883 .read_bulk_callback = ftdi_read_bulk_callback,
884 .write_bulk_callback = ftdi_write_bulk_callback,
885 .tiocmget = ftdi_tiocmget,
886 .tiocmset = ftdi_tiocmset,
887 .ioctl = ftdi_ioctl,
888 .set_termios = ftdi_set_termios,
889 .break_ctl = ftdi_break_ctl,
890 .attach = ftdi_HE_TIRA1_startup,
891 .shutdown = ftdi_shutdown,
892};
893
894
895 546
896#define WDR_TIMEOUT 5000 /* default urb timeout */ 547#define WDR_TIMEOUT 5000 /* default urb timeout */
897 548
@@ -1212,6 +863,59 @@ check_and_exit:
1212} /* set_serial_info */ 863} /* set_serial_info */
1213 864
1214 865
866/* Determine type of FTDI chip based on USB config and descriptor. */
867static void ftdi_determine_type(struct usb_serial_port *port)
868{
869 struct ftdi_private *priv = usb_get_serial_port_data(port);
870 struct usb_serial *serial = port->serial;
871 struct usb_device *udev = serial->dev;
872 unsigned version;
873 unsigned interfaces;
874
875 /* Assume it is not the original SIO device for now. */
876 priv->baud_base = 48000000 / 16;
877 priv->write_offset = 0;
878
879 version = le16_to_cpu(udev->descriptor.bcdDevice);
880 interfaces = udev->actconfig->desc.bNumInterfaces;
881 dbg("%s: bcdDevice = 0x%x, bNumInterfaces = %u", __FUNCTION__,
882 version, interfaces);
883 if (interfaces > 1) {
884 int inter;
885
886 /* Multiple interfaces. Assume FT2232C. */
887 priv->chip_type = FT2232C;
888 /* Determine interface code. */
889 inter = serial->interface->altsetting->desc.bInterfaceNumber;
890 if (inter == 0) {
891 priv->interface = PIT_SIOA;
892 } else {
893 priv->interface = PIT_SIOB;
894 }
895 /* BM-type devices have a bug where bcdDevice gets set
896 * to 0x200 when iSerialNumber is 0. */
897 if (version < 0x500) {
898 dbg("%s: something fishy - bcdDevice too low for multi-interface device",
899 __FUNCTION__);
900 }
901 } else if (version < 0x200) {
902 /* Old device. Assume its the original SIO. */
903 priv->chip_type = SIO;
904 priv->baud_base = 12000000 / 16;
905 priv->write_offset = 1;
906 } else if (version < 0x400) {
907 /* Assume its an FT8U232AM (or FT8U245AM) */
908 /* (It might be a BM because of the iSerialNumber bug,
909 * but it will still work as an AM device.) */
910 priv->chip_type = FT8U232AM;
911 } else {
912 /* Assume its an FT232BM (or FT245BM) */
913 priv->chip_type = FT232BM;
914 }
915 info("Detected %s", ftdi_chip_name[priv->chip_type]);
916}
917
918
1215/* 919/*
1216 * *************************************************************************** 920 * ***************************************************************************
1217 * Sysfs Attribute 921 * Sysfs Attribute
@@ -1355,12 +1059,20 @@ static void remove_sysfs_attrs(struct usb_serial *serial)
1355 * *************************************************************************** 1059 * ***************************************************************************
1356 */ 1060 */
1357 1061
1358/* Common startup subroutine */ 1062/* Probe function to check for special devices */
1359/* Called from ftdi_SIO_startup, etc. */ 1063static int ftdi_sio_probe (struct usb_serial *serial, const struct usb_device_id *id)
1360static int ftdi_common_startup (struct usb_serial *serial) 1064{
1065 usb_set_serial_data(serial, (void *)id->driver_info);
1066
1067 return (0);
1068}
1069
1070/* attach subroutine */
1071static int ftdi_sio_attach (struct usb_serial *serial)
1361{ 1072{
1362 struct usb_serial_port *port = serial->port[0]; 1073 struct usb_serial_port *port = serial->port[0];
1363 struct ftdi_private *priv; 1074 struct ftdi_private *priv;
1075 struct ftdi_sio_quirk *quirk;
1364 1076
1365 dbg("%s",__FUNCTION__); 1077 dbg("%s",__FUNCTION__);
1366 1078
@@ -1400,150 +1112,49 @@ static int ftdi_common_startup (struct usb_serial *serial)
1400 port->bulk_out_buffer = NULL; 1112 port->bulk_out_buffer = NULL;
1401 1113
1402 usb_set_serial_port_data(serial->port[0], priv); 1114 usb_set_serial_port_data(serial->port[0], priv);
1403
1404 return (0);
1405}
1406
1407
1408/* Startup for the SIO chip */
1409/* Called from usbserial:serial_probe */
1410static int ftdi_SIO_startup (struct usb_serial *serial)
1411{
1412 struct ftdi_private *priv;
1413 int err;
1414
1415 dbg("%s",__FUNCTION__);
1416
1417 err = ftdi_common_startup(serial);
1418 if (err){
1419 return (err);
1420 }
1421
1422 priv = usb_get_serial_port_data(serial->port[0]);
1423 priv->chip_type = SIO;
1424 priv->baud_base = 12000000 / 16;
1425 priv->write_offset = 1;
1426
1427 return (0);
1428}
1429
1430/* Startup for the 8U232AM chip */
1431/* Called from usbserial:serial_probe */
1432static int ftdi_8U232AM_startup (struct usb_serial *serial)
1433{ /* ftdi_8U232AM_startup */
1434 struct ftdi_private *priv;
1435 int err;
1436
1437 dbg("%s",__FUNCTION__);
1438 err = ftdi_common_startup(serial);
1439 if (err){
1440 return (err);
1441 }
1442 1115
1443 priv = usb_get_serial_port_data(serial->port[0]); 1116 ftdi_determine_type (serial->port[0]);
1444 priv->chip_type = FT8U232AM;
1445 priv->baud_base = 48000000 / 2; /* Would be / 16, but FTDI supports 0.125, 0.25 and 0.5 divisor fractions! */
1446
1447 create_sysfs_attrs(serial); 1117 create_sysfs_attrs(serial);
1448
1449 return (0);
1450} /* ftdi_8U232AM_startup */
1451 1118
1452/* Startup for the FT232BM chip */ 1119 /* Check for device requiring special set up. */
1453/* Called from usbserial:serial_probe */ 1120 quirk = (struct ftdi_sio_quirk *)usb_get_serial_data(serial);
1454static int ftdi_FT232BM_startup (struct usb_serial *serial) 1121 if (quirk && quirk->setup) {
1455{ /* ftdi_FT232BM_startup */ 1122 quirk->setup(serial);
1456 struct ftdi_private *priv;
1457 int err;
1458
1459 dbg("%s",__FUNCTION__);
1460 err = ftdi_common_startup(serial);
1461 if (err){
1462 return (err);
1463 } 1123 }
1464
1465 priv = usb_get_serial_port_data(serial->port[0]);
1466 priv->chip_type = FT232BM;
1467 priv->baud_base = 48000000 / 2; /* Would be / 16, but FT232BM supports multiple of 0.125 divisor fractions! */
1468 1124
1469 create_sysfs_attrs(serial);
1470
1471 return (0); 1125 return (0);
1472} /* ftdi_FT232BM_startup */ 1126} /* ftdi_sio_attach */
1473
1474/* Startup for the FT2232C chip */
1475/* Called from usbserial:serial_probe */
1476static int ftdi_FT2232C_startup (struct usb_serial *serial)
1477{ /* ftdi_FT2232C_startup */
1478 struct ftdi_private *priv;
1479 int err;
1480 int inter;
1481
1482 dbg("%s",__FUNCTION__);
1483 err = ftdi_common_startup(serial);
1484 if (err){
1485 return (err);
1486 }
1487 1127
1488 priv = usb_get_serial_port_data(serial->port[0]);
1489 priv->chip_type = FT2232C;
1490 inter = serial->interface->altsetting->desc.bInterfaceNumber;
1491 1128
1492 if (inter) { 1129/* Setup for the USB-UIRT device, which requires hardwired
1493 priv->interface = PIT_SIOB; 1130 * baudrate (38400 gets mapped to 312500) */
1494 }
1495 else {
1496 priv->interface = PIT_SIOA;
1497 }
1498 priv->baud_base = 48000000 / 2; /* Would be / 16, but FT2232C supports multiple of 0.125 divisor fractions! */
1499
1500 create_sysfs_attrs(serial);
1501
1502 return (0);
1503} /* ftdi_FT2232C_startup */
1504
1505/* Startup for the USB-UIRT device, which requires hardwired baudrate (38400 gets mapped to 312500) */
1506/* Called from usbserial:serial_probe */ 1131/* Called from usbserial:serial_probe */
1507static int ftdi_USB_UIRT_startup (struct usb_serial *serial) 1132static void ftdi_USB_UIRT_setup (struct usb_serial *serial)
1508{ /* ftdi_USB_UIRT_startup */ 1133{
1509 struct ftdi_private *priv; 1134 struct ftdi_private *priv;
1510 int err;
1511 1135
1512 dbg("%s",__FUNCTION__); 1136 dbg("%s",__FUNCTION__);
1513 err = ftdi_8U232AM_startup(serial);
1514 if (err){
1515 return (err);
1516 }
1517 1137
1518 priv = usb_get_serial_port_data(serial->port[0]); 1138 priv = usb_get_serial_port_data(serial->port[0]);
1519 priv->flags |= ASYNC_SPD_CUST; 1139 priv->flags |= ASYNC_SPD_CUST;
1520 priv->custom_divisor = 77; 1140 priv->custom_divisor = 77;
1521 priv->force_baud = B38400; 1141 priv->force_baud = B38400;
1522 1142} /* ftdi_USB_UIRT_setup */
1523 return (0);
1524} /* ftdi_USB_UIRT_startup */
1525 1143
1526/* Startup for the HE-TIRA1 device, which requires hardwired 1144/* Setup for the HE-TIRA1 device, which requires hardwired
1527 * baudrate (38400 gets mapped to 100000) */ 1145 * baudrate (38400 gets mapped to 100000) and RTS-CTS enabled. */
1528static int ftdi_HE_TIRA1_startup (struct usb_serial *serial) 1146static void ftdi_HE_TIRA1_setup (struct usb_serial *serial)
1529{ /* ftdi_HE_TIRA1_startup */ 1147{
1530 struct ftdi_private *priv; 1148 struct ftdi_private *priv;
1531 int err;
1532 1149
1533 dbg("%s",__FUNCTION__); 1150 dbg("%s",__FUNCTION__);
1534 err = ftdi_FT232BM_startup(serial);
1535 if (err){
1536 return (err);
1537 }
1538 1151
1539 priv = usb_get_serial_port_data(serial->port[0]); 1152 priv = usb_get_serial_port_data(serial->port[0]);
1540 priv->flags |= ASYNC_SPD_CUST; 1153 priv->flags |= ASYNC_SPD_CUST;
1541 priv->custom_divisor = 240; 1154 priv->custom_divisor = 240;
1542 priv->force_baud = B38400; 1155 priv->force_baud = B38400;
1543 priv->force_rtscts = 1; 1156 priv->force_rtscts = 1;
1544 1157} /* ftdi_HE_TIRA1_setup */
1545 return (0);
1546} /* ftdi_HE_TIRA1_startup */
1547 1158
1548 1159
1549/* ftdi_shutdown is called from usbserial:usb_serial_disconnect 1160/* ftdi_shutdown is called from usbserial:usb_serial_disconnect
@@ -2367,60 +1978,11 @@ static int ftdi_ioctl (struct usb_serial_port *port, struct file * file, unsigne
2367{ 1978{
2368 struct ftdi_private *priv = usb_get_serial_port_data(port); 1979 struct ftdi_private *priv = usb_get_serial_port_data(port);
2369 1980
2370 int ret, mask;
2371
2372 dbg("%s cmd 0x%04x", __FUNCTION__, cmd); 1981 dbg("%s cmd 0x%04x", __FUNCTION__, cmd);
2373 1982
2374 /* Based on code from acm.c and others */ 1983 /* Based on code from acm.c and others */
2375 switch (cmd) { 1984 switch (cmd) {
2376 1985
2377 case TIOCMBIS: /* turns on (Sets) the lines as specified by the mask */
2378 dbg("%s TIOCMBIS", __FUNCTION__);
2379 if (get_user(mask, (unsigned long __user *) arg))
2380 return -EFAULT;
2381 if (mask & TIOCM_DTR){
2382 if ((ret = set_dtr(port, HIGH)) < 0) {
2383 err("Urb to set DTR failed");
2384 return(ret);
2385 }
2386 }
2387 if (mask & TIOCM_RTS) {
2388 if ((ret = set_rts(port, HIGH)) < 0){
2389 err("Urb to set RTS failed");
2390 return(ret);
2391 }
2392 }
2393 return(0);
2394 break;
2395
2396 case TIOCMBIC: /* turns off (Clears) the lines as specified by the mask */
2397 dbg("%s TIOCMBIC", __FUNCTION__);
2398 if (get_user(mask, (unsigned long __user *) arg))
2399 return -EFAULT;
2400 if (mask & TIOCM_DTR){
2401 if ((ret = set_dtr(port, LOW)) < 0){
2402 err("Urb to unset DTR failed");
2403 return(ret);
2404 }
2405 }
2406 if (mask & TIOCM_RTS) {
2407 if ((ret = set_rts(port, LOW)) < 0){
2408 err("Urb to unset RTS failed");
2409 return(ret);
2410 }
2411 }
2412 return(0);
2413 break;
2414
2415 /*
2416 * I had originally implemented TCSET{A,S}{,F,W} and
2417 * TCGET{A,S} here separately, however when testing I
2418 * found that the higher layers actually do the termios
2419 * conversions themselves and pass the call onto
2420 * ftdi_sio_set_termios.
2421 *
2422 */
2423
2424 case TIOCGSERIAL: /* gets serial port data */ 1986 case TIOCGSERIAL: /* gets serial port data */
2425 return get_serial_info(port, (struct serial_struct __user *) arg); 1987 return get_serial_info(port, (struct serial_struct __user *) arg);
2426 1988
@@ -2516,24 +2078,9 @@ static int __init ftdi_init (void)
2516 int retval; 2078 int retval;
2517 2079
2518 dbg("%s", __FUNCTION__); 2080 dbg("%s", __FUNCTION__);
2519 retval = usb_serial_register(&ftdi_SIO_device); 2081 retval = usb_serial_register(&ftdi_sio_device);
2520 if (retval)
2521 goto failed_SIO_register;
2522 retval = usb_serial_register(&ftdi_8U232AM_device);
2523 if (retval)
2524 goto failed_8U232AM_register;
2525 retval = usb_serial_register(&ftdi_FT232BM_device);
2526 if (retval)
2527 goto failed_FT232BM_register;
2528 retval = usb_serial_register(&ftdi_FT2232C_device);
2529 if (retval)
2530 goto failed_FT2232C_register;
2531 retval = usb_serial_register(&ftdi_USB_UIRT_device);
2532 if (retval)
2533 goto failed_USB_UIRT_register;
2534 retval = usb_serial_register(&ftdi_HE_TIRA1_device);
2535 if (retval) 2082 if (retval)
2536 goto failed_HE_TIRA1_register; 2083 goto failed_sio_register;
2537 retval = usb_register(&ftdi_driver); 2084 retval = usb_register(&ftdi_driver);
2538 if (retval) 2085 if (retval)
2539 goto failed_usb_register; 2086 goto failed_usb_register;
@@ -2541,18 +2088,8 @@ static int __init ftdi_init (void)
2541 info(DRIVER_VERSION ":" DRIVER_DESC); 2088 info(DRIVER_VERSION ":" DRIVER_DESC);
2542 return 0; 2089 return 0;
2543failed_usb_register: 2090failed_usb_register:
2544 usb_serial_deregister(&ftdi_HE_TIRA1_device); 2091 usb_serial_deregister(&ftdi_sio_device);
2545failed_HE_TIRA1_register: 2092failed_sio_register:
2546 usb_serial_deregister(&ftdi_USB_UIRT_device);
2547failed_USB_UIRT_register:
2548 usb_serial_deregister(&ftdi_FT2232C_device);
2549failed_FT2232C_register:
2550 usb_serial_deregister(&ftdi_FT232BM_device);
2551failed_FT232BM_register:
2552 usb_serial_deregister(&ftdi_8U232AM_device);
2553failed_8U232AM_register:
2554 usb_serial_deregister(&ftdi_SIO_device);
2555failed_SIO_register:
2556 return retval; 2093 return retval;
2557} 2094}
2558 2095
@@ -2563,12 +2100,7 @@ static void __exit ftdi_exit (void)
2563 dbg("%s", __FUNCTION__); 2100 dbg("%s", __FUNCTION__);
2564 2101
2565 usb_deregister (&ftdi_driver); 2102 usb_deregister (&ftdi_driver);
2566 usb_serial_deregister (&ftdi_HE_TIRA1_device); 2103 usb_serial_deregister (&ftdi_sio_device);
2567 usb_serial_deregister (&ftdi_USB_UIRT_device);
2568 usb_serial_deregister (&ftdi_FT2232C_device);
2569 usb_serial_deregister (&ftdi_FT232BM_device);
2570 usb_serial_deregister (&ftdi_8U232AM_device);
2571 usb_serial_deregister (&ftdi_SIO_device);
2572 2104
2573} 2105}
2574 2106
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h
index 9fcc7bd1fbe4..bd0ab3039bdd 100644
--- a/drivers/usb/storage/unusual_devs.h
+++ b/drivers/usb/storage/unusual_devs.h
@@ -697,7 +697,7 @@ UNUSUAL_DEV( 0x07af, 0x0004, 0x0100, 0x0133,
697UNUSUAL_DEV( 0x07af, 0x0005, 0x0100, 0x0100, 697UNUSUAL_DEV( 0x07af, 0x0005, 0x0100, 0x0100,
698 "Microtech", 698 "Microtech",
699 "USB-SCSI-HD50", 699 "USB-SCSI-HD50",
700 US_SC_SCSI, US_PR_BULK, usb_stor_euscsi_init, 700 US_SC_DEVICE, US_PR_DEVICE, usb_stor_euscsi_init,
701 US_FL_SCM_MULT_TARG ), 701 US_FL_SCM_MULT_TARG ),
702 702
703#ifdef CONFIG_USB_STORAGE_DPCM 703#ifdef CONFIG_USB_STORAGE_DPCM
diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c
index 312cf3220f12..8a9c42822502 100644
--- a/drivers/w1/w1.c
+++ b/drivers/w1/w1.c
@@ -516,6 +516,7 @@ static void w1_slave_found(unsigned long data, u64 rn)
516 struct w1_reg_num *tmp; 516 struct w1_reg_num *tmp;
517 int family_found = 0; 517 int family_found = 0;
518 struct w1_master *dev; 518 struct w1_master *dev;
519 u64 rn_le = cpu_to_le64(rn);
519 520
520 dev = w1_search_master(data); 521 dev = w1_search_master(data);
521 if (!dev) { 522 if (!dev) {
@@ -544,10 +545,8 @@ static void w1_slave_found(unsigned long data, u64 rn)
544 slave_count++; 545 slave_count++;
545 } 546 }
546 547
547 rn = cpu_to_le64(rn);
548
549 if (slave_count == dev->slave_count && 548 if (slave_count == dev->slave_count &&
550 rn && ((le64_to_cpu(rn) >> 56) & 0xff) == w1_calc_crc8((u8 *)&rn, 7)) { 549 rn && ((rn >> 56) & 0xff) == w1_calc_crc8((u8 *)&rn_le, 7)) {
551 w1_attach_slave_device(dev, tmp); 550 w1_attach_slave_device(dev, tmp);
552 } 551 }
553 552
diff --git a/fs/Kconfig b/fs/Kconfig
index f93fd41b025d..5d0c4be43dba 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -359,6 +359,19 @@ config ROMFS_FS
359 If you don't know whether you need it, then you don't need it: 359 If you don't know whether you need it, then you don't need it:
360 answer N. 360 answer N.
361 361
362config INOTIFY
363 bool "Inotify file change notification support"
364 default y
365 ---help---
366 Say Y here to enable inotify support and the /dev/inotify character
367 device. Inotify is a file change notification system and a
368 replacement for dnotify. Inotify fixes numerous shortcomings in
369 dnotify and introduces several new features. It allows monitoring
370 of both files and directories via a single open fd. Multiple file
371 events are supported.
372
373 If unsure, say Y.
374
362config QUOTA 375config QUOTA
363 bool "Quota support" 376 bool "Quota support"
364 help 377 help
diff --git a/fs/Makefile b/fs/Makefile
index 20edcf28bfd2..cf95eb894fd5 100644
--- a/fs/Makefile
+++ b/fs/Makefile
@@ -12,6 +12,7 @@ obj-y := open.o read_write.o file_table.o buffer.o bio.o super.o \
12 seq_file.o xattr.o libfs.o fs-writeback.o mpage.o direct-io.o \ 12 seq_file.o xattr.o libfs.o fs-writeback.o mpage.o direct-io.o \
13 ioprio.o 13 ioprio.o
14 14
15obj-$(CONFIG_INOTIFY) += inotify.o
15obj-$(CONFIG_EPOLL) += eventpoll.o 16obj-$(CONFIG_EPOLL) += eventpoll.o
16obj-$(CONFIG_COMPAT) += compat.o 17obj-$(CONFIG_COMPAT) += compat.o
17 18
diff --git a/fs/attr.c b/fs/attr.c
index c3c76fe78346..b1796fb9e524 100644
--- a/fs/attr.c
+++ b/fs/attr.c
@@ -10,7 +10,7 @@
10#include <linux/mm.h> 10#include <linux/mm.h>
11#include <linux/string.h> 11#include <linux/string.h>
12#include <linux/smp_lock.h> 12#include <linux/smp_lock.h>
13#include <linux/dnotify.h> 13#include <linux/fsnotify.h>
14#include <linux/fcntl.h> 14#include <linux/fcntl.h>
15#include <linux/quotaops.h> 15#include <linux/quotaops.h>
16#include <linux/security.h> 16#include <linux/security.h>
@@ -107,31 +107,8 @@ int inode_setattr(struct inode * inode, struct iattr * attr)
107out: 107out:
108 return error; 108 return error;
109} 109}
110
111EXPORT_SYMBOL(inode_setattr); 110EXPORT_SYMBOL(inode_setattr);
112 111
113int setattr_mask(unsigned int ia_valid)
114{
115 unsigned long dn_mask = 0;
116
117 if (ia_valid & ATTR_UID)
118 dn_mask |= DN_ATTRIB;
119 if (ia_valid & ATTR_GID)
120 dn_mask |= DN_ATTRIB;
121 if (ia_valid & ATTR_SIZE)
122 dn_mask |= DN_MODIFY;
123 /* both times implies a utime(s) call */
124 if ((ia_valid & (ATTR_ATIME|ATTR_MTIME)) == (ATTR_ATIME|ATTR_MTIME))
125 dn_mask |= DN_ATTRIB;
126 else if (ia_valid & ATTR_ATIME)
127 dn_mask |= DN_ACCESS;
128 else if (ia_valid & ATTR_MTIME)
129 dn_mask |= DN_MODIFY;
130 if (ia_valid & ATTR_MODE)
131 dn_mask |= DN_ATTRIB;
132 return dn_mask;
133}
134
135int notify_change(struct dentry * dentry, struct iattr * attr) 112int notify_change(struct dentry * dentry, struct iattr * attr)
136{ 113{
137 struct inode *inode = dentry->d_inode; 114 struct inode *inode = dentry->d_inode;
@@ -197,11 +174,9 @@ int notify_change(struct dentry * dentry, struct iattr * attr)
197 if (ia_valid & ATTR_SIZE) 174 if (ia_valid & ATTR_SIZE)
198 up_write(&dentry->d_inode->i_alloc_sem); 175 up_write(&dentry->d_inode->i_alloc_sem);
199 176
200 if (!error) { 177 if (!error)
201 unsigned long dn_mask = setattr_mask(ia_valid); 178 fsnotify_change(dentry, ia_valid);
202 if (dn_mask) 179
203 dnotify_parent(dentry, dn_mask);
204 }
205 return error; 180 return error;
206} 181}
207 182
diff --git a/fs/char_dev.c b/fs/char_dev.c
index a69a5d8a406f..3b1b1eefdbb0 100644
--- a/fs/char_dev.c
+++ b/fs/char_dev.c
@@ -277,8 +277,9 @@ static struct kobject *cdev_get(struct cdev *p)
277void cdev_put(struct cdev *p) 277void cdev_put(struct cdev *p)
278{ 278{
279 if (p) { 279 if (p) {
280 struct module *owner = p->owner;
280 kobject_put(&p->kobj); 281 kobject_put(&p->kobj);
281 module_put(p->owner); 282 module_put(owner);
282 } 283 }
283} 284}
284 285
diff --git a/fs/compat.c b/fs/compat.c
index 728cd8365384..6b06b6bae35e 100644
--- a/fs/compat.c
+++ b/fs/compat.c
@@ -37,7 +37,7 @@
37#include <linux/ctype.h> 37#include <linux/ctype.h>
38#include <linux/module.h> 38#include <linux/module.h>
39#include <linux/dirent.h> 39#include <linux/dirent.h>
40#include <linux/dnotify.h> 40#include <linux/fsnotify.h>
41#include <linux/highuid.h> 41#include <linux/highuid.h>
42#include <linux/sunrpc/svc.h> 42#include <linux/sunrpc/svc.h>
43#include <linux/nfsd/nfsd.h> 43#include <linux/nfsd/nfsd.h>
@@ -1307,9 +1307,13 @@ static ssize_t compat_do_readv_writev(int type, struct file *file,
1307out: 1307out:
1308 if (iov != iovstack) 1308 if (iov != iovstack)
1309 kfree(iov); 1309 kfree(iov);
1310 if ((ret + (type == READ)) > 0) 1310 if ((ret + (type == READ)) > 0) {
1311 dnotify_parent(file->f_dentry, 1311 struct dentry *dentry = file->f_dentry;
1312 (type == READ) ? DN_ACCESS : DN_MODIFY); 1312 if (type == READ)
1313 fsnotify_access(dentry);
1314 else
1315 fsnotify_modify(dentry);
1316 }
1313 return ret; 1317 return ret;
1314} 1318}
1315 1319
diff --git a/fs/exec.c b/fs/exec.c
index 48871917d363..222ab1c572d8 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -642,6 +642,18 @@ static inline int de_thread(struct task_struct *tsk)
642 count = 2; 642 count = 2;
643 if (thread_group_leader(current)) 643 if (thread_group_leader(current))
644 count = 1; 644 count = 1;
645 else {
646 /*
647 * The SIGALRM timer survives the exec, but needs to point
648 * at us as the new group leader now. We have a race with
649 * a timer firing now getting the old leader, so we need to
650 * synchronize with any firing (by calling del_timer_sync)
651 * before we can safely let the old group leader die.
652 */
653 sig->real_timer.data = (unsigned long)current;
654 if (del_timer_sync(&sig->real_timer))
655 add_timer(&sig->real_timer);
656 }
645 while (atomic_read(&sig->count) > count) { 657 while (atomic_read(&sig->count) > count) {
646 sig->group_exit_task = current; 658 sig->group_exit_task = current;
647 sig->notify_count = count; 659 sig->notify_count = count;
diff --git a/fs/ext2/ext2.h b/fs/ext2/ext2.h
index eed521d22cf0..e977f8566d14 100644
--- a/fs/ext2/ext2.h
+++ b/fs/ext2/ext2.h
@@ -2,6 +2,15 @@
2#include <linux/ext2_fs.h> 2#include <linux/ext2_fs.h>
3 3
4/* 4/*
5 * ext2 mount options
6 */
7struct ext2_mount_options {
8 unsigned long s_mount_opt;
9 uid_t s_resuid;
10 gid_t s_resgid;
11};
12
13/*
5 * second extended file system inode data in memory 14 * second extended file system inode data in memory
6 */ 15 */
7struct ext2_inode_info { 16struct ext2_inode_info {
diff --git a/fs/ext2/super.c b/fs/ext2/super.c
index 876e391f2871..dcfe331dc4c4 100644
--- a/fs/ext2/super.c
+++ b/fs/ext2/super.c
@@ -936,12 +936,23 @@ static int ext2_remount (struct super_block * sb, int * flags, char * data)
936 struct ext2_sb_info * sbi = EXT2_SB(sb); 936 struct ext2_sb_info * sbi = EXT2_SB(sb);
937 struct ext2_super_block * es; 937 struct ext2_super_block * es;
938 unsigned long old_mount_opt = sbi->s_mount_opt; 938 unsigned long old_mount_opt = sbi->s_mount_opt;
939 struct ext2_mount_options old_opts;
940 unsigned long old_sb_flags;
941 int err;
942
943 /* Store the old options */
944 old_sb_flags = sb->s_flags;
945 old_opts.s_mount_opt = sbi->s_mount_opt;
946 old_opts.s_resuid = sbi->s_resuid;
947 old_opts.s_resgid = sbi->s_resgid;
939 948
940 /* 949 /*
941 * Allow the "check" option to be passed as a remount option. 950 * Allow the "check" option to be passed as a remount option.
942 */ 951 */
943 if (!parse_options (data, sbi)) 952 if (!parse_options (data, sbi)) {
944 return -EINVAL; 953 err = -EINVAL;
954 goto restore_opts;
955 }
945 956
946 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) | 957 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
947 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0); 958 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
@@ -971,7 +982,8 @@ static int ext2_remount (struct super_block * sb, int * flags, char * data)
971 printk("EXT2-fs: %s: couldn't remount RDWR because of " 982 printk("EXT2-fs: %s: couldn't remount RDWR because of "
972 "unsupported optional features (%x).\n", 983 "unsupported optional features (%x).\n",
973 sb->s_id, le32_to_cpu(ret)); 984 sb->s_id, le32_to_cpu(ret));
974 return -EROFS; 985 err = -EROFS;
986 goto restore_opts;
975 } 987 }
976 /* 988 /*
977 * Mounting a RDONLY partition read-write, so reread and 989 * Mounting a RDONLY partition read-write, so reread and
@@ -984,6 +996,12 @@ static int ext2_remount (struct super_block * sb, int * flags, char * data)
984 } 996 }
985 ext2_sync_super(sb, es); 997 ext2_sync_super(sb, es);
986 return 0; 998 return 0;
999restore_opts:
1000 sbi->s_mount_opt = old_opts.s_mount_opt;
1001 sbi->s_resuid = old_opts.s_resuid;
1002 sbi->s_resgid = old_opts.s_resgid;
1003 sb->s_flags = old_sb_flags;
1004 return err;
987} 1005}
988 1006
989static int ext2_statfs (struct super_block * sb, struct kstatfs * buf) 1007static int ext2_statfs (struct super_block * sb, struct kstatfs * buf)
diff --git a/fs/ext3/super.c b/fs/ext3/super.c
index a6d1779d7de4..3c3c6e399fb3 100644
--- a/fs/ext3/super.c
+++ b/fs/ext3/super.c
@@ -890,7 +890,10 @@ clear_qf_name:
890 "quota turned on.\n"); 890 "quota turned on.\n");
891 return 0; 891 return 0;
892 } 892 }
893 kfree(sbi->s_qf_names[qtype]); 893 /*
894 * The space will be released later when all options
895 * are confirmed to be correct
896 */
894 sbi->s_qf_names[qtype] = NULL; 897 sbi->s_qf_names[qtype] = NULL;
895 break; 898 break;
896 case Opt_jqfmt_vfsold: 899 case Opt_jqfmt_vfsold:
@@ -939,7 +942,7 @@ clear_qf_name:
939 case Opt_ignore: 942 case Opt_ignore:
940 break; 943 break;
941 case Opt_resize: 944 case Opt_resize:
942 if (!n_blocks_count) { 945 if (!is_remount) {
943 printk("EXT3-fs: resize option only available " 946 printk("EXT3-fs: resize option only available "
944 "for remount\n"); 947 "for remount\n");
945 return 0; 948 return 0;
@@ -2109,14 +2112,33 @@ static int ext3_remount (struct super_block * sb, int * flags, char * data)
2109{ 2112{
2110 struct ext3_super_block * es; 2113 struct ext3_super_block * es;
2111 struct ext3_sb_info *sbi = EXT3_SB(sb); 2114 struct ext3_sb_info *sbi = EXT3_SB(sb);
2112 unsigned long tmp;
2113 unsigned long n_blocks_count = 0; 2115 unsigned long n_blocks_count = 0;
2116 unsigned long old_sb_flags;
2117 struct ext3_mount_options old_opts;
2118 int err;
2119#ifdef CONFIG_QUOTA
2120 int i;
2121#endif
2122
2123 /* Store the original options */
2124 old_sb_flags = sb->s_flags;
2125 old_opts.s_mount_opt = sbi->s_mount_opt;
2126 old_opts.s_resuid = sbi->s_resuid;
2127 old_opts.s_resgid = sbi->s_resgid;
2128 old_opts.s_commit_interval = sbi->s_commit_interval;
2129#ifdef CONFIG_QUOTA
2130 old_opts.s_jquota_fmt = sbi->s_jquota_fmt;
2131 for (i = 0; i < MAXQUOTAS; i++)
2132 old_opts.s_qf_names[i] = sbi->s_qf_names[i];
2133#endif
2114 2134
2115 /* 2135 /*
2116 * Allow the "check" option to be passed as a remount option. 2136 * Allow the "check" option to be passed as a remount option.
2117 */ 2137 */
2118 if (!parse_options(data, sb, &tmp, &n_blocks_count, 1)) 2138 if (!parse_options(data, sb, NULL, &n_blocks_count, 1)) {
2119 return -EINVAL; 2139 err = -EINVAL;
2140 goto restore_opts;
2141 }
2120 2142
2121 if (sbi->s_mount_opt & EXT3_MOUNT_ABORT) 2143 if (sbi->s_mount_opt & EXT3_MOUNT_ABORT)
2122 ext3_abort(sb, __FUNCTION__, "Abort forced by user"); 2144 ext3_abort(sb, __FUNCTION__, "Abort forced by user");
@@ -2130,8 +2152,10 @@ static int ext3_remount (struct super_block * sb, int * flags, char * data)
2130 2152
2131 if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY) || 2153 if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY) ||
2132 n_blocks_count > le32_to_cpu(es->s_blocks_count)) { 2154 n_blocks_count > le32_to_cpu(es->s_blocks_count)) {
2133 if (sbi->s_mount_opt & EXT3_MOUNT_ABORT) 2155 if (sbi->s_mount_opt & EXT3_MOUNT_ABORT) {
2134 return -EROFS; 2156 err = -EROFS;
2157 goto restore_opts;
2158 }
2135 2159
2136 if (*flags & MS_RDONLY) { 2160 if (*flags & MS_RDONLY) {
2137 /* 2161 /*
@@ -2158,7 +2182,8 @@ static int ext3_remount (struct super_block * sb, int * flags, char * data)
2158 "remount RDWR because of unsupported " 2182 "remount RDWR because of unsupported "
2159 "optional features (%x).\n", 2183 "optional features (%x).\n",
2160 sb->s_id, le32_to_cpu(ret)); 2184 sb->s_id, le32_to_cpu(ret));
2161 return -EROFS; 2185 err = -EROFS;
2186 goto restore_opts;
2162 } 2187 }
2163 /* 2188 /*
2164 * Mounting a RDONLY partition read-write, so reread 2189 * Mounting a RDONLY partition read-write, so reread
@@ -2168,13 +2193,38 @@ static int ext3_remount (struct super_block * sb, int * flags, char * data)
2168 */ 2193 */
2169 ext3_clear_journal_err(sb, es); 2194 ext3_clear_journal_err(sb, es);
2170 sbi->s_mount_state = le16_to_cpu(es->s_state); 2195 sbi->s_mount_state = le16_to_cpu(es->s_state);
2171 if ((ret = ext3_group_extend(sb, es, n_blocks_count))) 2196 if ((ret = ext3_group_extend(sb, es, n_blocks_count))) {
2172 return ret; 2197 err = ret;
2198 goto restore_opts;
2199 }
2173 if (!ext3_setup_super (sb, es, 0)) 2200 if (!ext3_setup_super (sb, es, 0))
2174 sb->s_flags &= ~MS_RDONLY; 2201 sb->s_flags &= ~MS_RDONLY;
2175 } 2202 }
2176 } 2203 }
2204#ifdef CONFIG_QUOTA
2205 /* Release old quota file names */
2206 for (i = 0; i < MAXQUOTAS; i++)
2207 if (old_opts.s_qf_names[i] &&
2208 old_opts.s_qf_names[i] != sbi->s_qf_names[i])
2209 kfree(old_opts.s_qf_names[i]);
2210#endif
2177 return 0; 2211 return 0;
2212restore_opts:
2213 sb->s_flags = old_sb_flags;
2214 sbi->s_mount_opt = old_opts.s_mount_opt;
2215 sbi->s_resuid = old_opts.s_resuid;
2216 sbi->s_resgid = old_opts.s_resgid;
2217 sbi->s_commit_interval = old_opts.s_commit_interval;
2218#ifdef CONFIG_QUOTA
2219 sbi->s_jquota_fmt = old_opts.s_jquota_fmt;
2220 for (i = 0; i < MAXQUOTAS; i++) {
2221 if (sbi->s_qf_names[i] &&
2222 old_opts.s_qf_names[i] != sbi->s_qf_names[i])
2223 kfree(sbi->s_qf_names[i]);
2224 sbi->s_qf_names[i] = old_opts.s_qf_names[i];
2225 }
2226#endif
2227 return err;
2178} 2228}
2179 2229
2180static int ext3_statfs (struct super_block * sb, struct kstatfs * buf) 2230static int ext3_statfs (struct super_block * sb, struct kstatfs * buf)
diff --git a/fs/file_table.c b/fs/file_table.c
index fa7849fae134..1d3de78e6bc9 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -16,6 +16,7 @@
16#include <linux/eventpoll.h> 16#include <linux/eventpoll.h>
17#include <linux/mount.h> 17#include <linux/mount.h>
18#include <linux/cdev.h> 18#include <linux/cdev.h>
19#include <linux/fsnotify.h>
19 20
20/* sysctl tunables... */ 21/* sysctl tunables... */
21struct files_stat_struct files_stat = { 22struct files_stat_struct files_stat = {
@@ -126,6 +127,8 @@ void fastcall __fput(struct file *file)
126 struct inode *inode = dentry->d_inode; 127 struct inode *inode = dentry->d_inode;
127 128
128 might_sleep(); 129 might_sleep();
130
131 fsnotify_close(file);
129 /* 132 /*
130 * The function eventpoll_release() should be the first called 133 * The function eventpoll_release() should be the first called
131 * in the file cleanup chain. 134 * in the file cleanup chain.
diff --git a/fs/inode.c b/fs/inode.c
index 6d695037a0a3..96364fae0844 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -21,6 +21,7 @@
21#include <linux/pagemap.h> 21#include <linux/pagemap.h>
22#include <linux/cdev.h> 22#include <linux/cdev.h>
23#include <linux/bootmem.h> 23#include <linux/bootmem.h>
24#include <linux/inotify.h>
24 25
25/* 26/*
26 * This is needed for the following functions: 27 * This is needed for the following functions:
@@ -202,6 +203,10 @@ void inode_init_once(struct inode *inode)
202 INIT_LIST_HEAD(&inode->i_data.i_mmap_nonlinear); 203 INIT_LIST_HEAD(&inode->i_data.i_mmap_nonlinear);
203 spin_lock_init(&inode->i_lock); 204 spin_lock_init(&inode->i_lock);
204 i_size_ordered_init(inode); 205 i_size_ordered_init(inode);
206#ifdef CONFIG_INOTIFY
207 INIT_LIST_HEAD(&inode->inotify_watches);
208 sema_init(&inode->inotify_sem, 1);
209#endif
205} 210}
206 211
207EXPORT_SYMBOL(inode_init_once); 212EXPORT_SYMBOL(inode_init_once);
@@ -282,6 +287,13 @@ static void dispose_list(struct list_head *head)
282 if (inode->i_data.nrpages) 287 if (inode->i_data.nrpages)
283 truncate_inode_pages(&inode->i_data, 0); 288 truncate_inode_pages(&inode->i_data, 0);
284 clear_inode(inode); 289 clear_inode(inode);
290
291 spin_lock(&inode_lock);
292 hlist_del_init(&inode->i_hash);
293 list_del_init(&inode->i_sb_list);
294 spin_unlock(&inode_lock);
295
296 wake_up_inode(inode);
285 destroy_inode(inode); 297 destroy_inode(inode);
286 nr_disposed++; 298 nr_disposed++;
287 } 299 }
@@ -317,8 +329,6 @@ static int invalidate_list(struct list_head *head, struct list_head *dispose)
317 inode = list_entry(tmp, struct inode, i_sb_list); 329 inode = list_entry(tmp, struct inode, i_sb_list);
318 invalidate_inode_buffers(inode); 330 invalidate_inode_buffers(inode);
319 if (!atomic_read(&inode->i_count)) { 331 if (!atomic_read(&inode->i_count)) {
320 hlist_del_init(&inode->i_hash);
321 list_del(&inode->i_sb_list);
322 list_move(&inode->i_list, dispose); 332 list_move(&inode->i_list, dispose);
323 inode->i_state |= I_FREEING; 333 inode->i_state |= I_FREEING;
324 count++; 334 count++;
@@ -346,6 +356,7 @@ int invalidate_inodes(struct super_block * sb)
346 356
347 down(&iprune_sem); 357 down(&iprune_sem);
348 spin_lock(&inode_lock); 358 spin_lock(&inode_lock);
359 inotify_unmount_inodes(&sb->s_inodes);
349 busy = invalidate_list(&sb->s_inodes, &throw_away); 360 busy = invalidate_list(&sb->s_inodes, &throw_away);
350 spin_unlock(&inode_lock); 361 spin_unlock(&inode_lock);
351 362
@@ -439,8 +450,6 @@ static void prune_icache(int nr_to_scan)
439 if (!can_unuse(inode)) 450 if (!can_unuse(inode))
440 continue; 451 continue;
441 } 452 }
442 hlist_del_init(&inode->i_hash);
443 list_del_init(&inode->i_sb_list);
444 list_move(&inode->i_list, &freeable); 453 list_move(&inode->i_list, &freeable);
445 inode->i_state |= I_FREEING; 454 inode->i_state |= I_FREEING;
446 nr_pruned++; 455 nr_pruned++;
@@ -1244,29 +1253,21 @@ int inode_wait(void *word)
1244} 1253}
1245 1254
1246/* 1255/*
1247 * If we try to find an inode in the inode hash while it is being deleted, we 1256 * If we try to find an inode in the inode hash while it is being
1248 * have to wait until the filesystem completes its deletion before reporting 1257 * deleted, we have to wait until the filesystem completes its
1249 * that it isn't found. This is because iget will immediately call 1258 * deletion before reporting that it isn't found. This function waits
1250 * ->read_inode, and we want to be sure that evidence of the deletion is found 1259 * until the deletion _might_ have completed. Callers are responsible
1251 * by ->read_inode. 1260 * to recheck inode state.
1261 *
1262 * It doesn't matter if I_LOCK is not set initially, a call to
1263 * wake_up_inode() after removing from the hash list will DTRT.
1264 *
1252 * This is called with inode_lock held. 1265 * This is called with inode_lock held.
1253 */ 1266 */
1254static void __wait_on_freeing_inode(struct inode *inode) 1267static void __wait_on_freeing_inode(struct inode *inode)
1255{ 1268{
1256 wait_queue_head_t *wq; 1269 wait_queue_head_t *wq;
1257 DEFINE_WAIT_BIT(wait, &inode->i_state, __I_LOCK); 1270 DEFINE_WAIT_BIT(wait, &inode->i_state, __I_LOCK);
1258
1259 /*
1260 * I_FREEING and I_CLEAR are cleared in process context under
1261 * inode_lock, so we have to give the tasks who would clear them
1262 * a chance to run and acquire inode_lock.
1263 */
1264 if (!(inode->i_state & I_LOCK)) {
1265 spin_unlock(&inode_lock);
1266 yield();
1267 spin_lock(&inode_lock);
1268 return;
1269 }
1270 wq = bit_waitqueue(&inode->i_state, __I_LOCK); 1271 wq = bit_waitqueue(&inode->i_state, __I_LOCK);
1271 prepare_to_wait(wq, &wait.wait, TASK_UNINTERRUPTIBLE); 1272 prepare_to_wait(wq, &wait.wait, TASK_UNINTERRUPTIBLE);
1272 spin_unlock(&inode_lock); 1273 spin_unlock(&inode_lock);
diff --git a/fs/inotify.c b/fs/inotify.c
new file mode 100644
index 000000000000..54757be888b6
--- /dev/null
+++ b/fs/inotify.c
@@ -0,0 +1,1037 @@
1/*
2 * fs/inotify.c - inode-based file event notifications
3 *
4 * Authors:
5 * John McCutchan <ttb@tentacle.dhs.org>
6 * Robert Love <rml@novell.com>
7 *
8 * Copyright (C) 2005 John McCutchan
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2, or (at your option) any
13 * later version.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 */
20
21#include <linux/module.h>
22#include <linux/kernel.h>
23#include <linux/sched.h>
24#include <linux/spinlock.h>
25#include <linux/idr.h>
26#include <linux/slab.h>
27#include <linux/fs.h>
28#include <linux/file.h>
29#include <linux/mount.h>
30#include <linux/namei.h>
31#include <linux/poll.h>
32#include <linux/init.h>
33#include <linux/list.h>
34#include <linux/writeback.h>
35#include <linux/inotify.h>
36
37#include <asm/ioctls.h>
38
39static atomic_t inotify_cookie;
40
41static kmem_cache_t *watch_cachep;
42static kmem_cache_t *event_cachep;
43
44static struct vfsmount *inotify_mnt;
45
46/* these are configurable via /proc/sys/fs/inotify/ */
47int inotify_max_user_instances;
48int inotify_max_user_watches;
49int inotify_max_queued_events;
50
51/*
52 * Lock ordering:
53 *
54 * dentry->d_lock (used to keep d_move() away from dentry->d_parent)
55 * iprune_sem (synchronize shrink_icache_memory())
56 * inode_lock (protects the super_block->s_inodes list)
57 * inode->inotify_sem (protects inode->inotify_watches and watches->i_list)
58 * inotify_dev->sem (protects inotify_device and watches->d_list)
59 */
60
61/*
62 * Lifetimes of the three main data structures--inotify_device, inode, and
63 * inotify_watch--are managed by reference count.
64 *
65 * inotify_device: Lifetime is from open until release. Additional references
66 * can bump the count via get_inotify_dev() and drop the count via
67 * put_inotify_dev().
68 *
69 * inotify_watch: Lifetime is from create_watch() to destory_watch().
70 * Additional references can bump the count via get_inotify_watch() and drop
71 * the count via put_inotify_watch().
72 *
73 * inode: Pinned so long as the inode is associated with a watch, from
74 * create_watch() to put_inotify_watch().
75 */
76
77/*
78 * struct inotify_device - represents an open instance of an inotify device
79 *
80 * This structure is protected by the semaphore 'sem'.
81 */
82struct inotify_device {
83 wait_queue_head_t wq; /* wait queue for i/o */
84 struct idr idr; /* idr mapping wd -> watch */
85 struct semaphore sem; /* protects this bad boy */
86 struct list_head events; /* list of queued events */
87 struct list_head watches; /* list of watches */
88 atomic_t count; /* reference count */
89 struct user_struct *user; /* user who opened this dev */
90 unsigned int queue_size; /* size of the queue (bytes) */
91 unsigned int event_count; /* number of pending events */
92 unsigned int max_events; /* maximum number of events */
93};
94
95/*
96 * struct inotify_kernel_event - An inotify event, originating from a watch and
97 * queued for user-space. A list of these is attached to each instance of the
98 * device. In read(), this list is walked and all events that can fit in the
99 * buffer are returned.
100 *
101 * Protected by dev->sem of the device in which we are queued.
102 */
103struct inotify_kernel_event {
104 struct inotify_event event; /* the user-space event */
105 struct list_head list; /* entry in inotify_device's list */
106 char *name; /* filename, if any */
107};
108
109/*
110 * struct inotify_watch - represents a watch request on a specific inode
111 *
112 * d_list is protected by dev->sem of the associated watch->dev.
113 * i_list and mask are protected by inode->inotify_sem of the associated inode.
114 * dev, inode, and wd are never written to once the watch is created.
115 */
116struct inotify_watch {
117 struct list_head d_list; /* entry in inotify_device's list */
118 struct list_head i_list; /* entry in inode's list */
119 atomic_t count; /* reference count */
120 struct inotify_device *dev; /* associated device */
121 struct inode *inode; /* associated inode */
122 s32 wd; /* watch descriptor */
123 u32 mask; /* event mask for this watch */
124};
125
126#ifdef CONFIG_SYSCTL
127
128#include <linux/sysctl.h>
129
130static int zero;
131
132ctl_table inotify_table[] = {
133 {
134 .ctl_name = INOTIFY_MAX_USER_INSTANCES,
135 .procname = "max_user_instances",
136 .data = &inotify_max_user_instances,
137 .maxlen = sizeof(int),
138 .mode = 0644,
139 .proc_handler = &proc_dointvec_minmax,
140 .strategy = &sysctl_intvec,
141 .extra1 = &zero,
142 },
143 {
144 .ctl_name = INOTIFY_MAX_USER_WATCHES,
145 .procname = "max_user_watches",
146 .data = &inotify_max_user_watches,
147 .maxlen = sizeof(int),
148 .mode = 0644,
149 .proc_handler = &proc_dointvec_minmax,
150 .strategy = &sysctl_intvec,
151 .extra1 = &zero,
152 },
153 {
154 .ctl_name = INOTIFY_MAX_QUEUED_EVENTS,
155 .procname = "max_queued_events",
156 .data = &inotify_max_queued_events,
157 .maxlen = sizeof(int),
158 .mode = 0644,
159 .proc_handler = &proc_dointvec_minmax,
160 .strategy = &sysctl_intvec,
161 .extra1 = &zero
162 },
163 { .ctl_name = 0 }
164};
165#endif /* CONFIG_SYSCTL */
166
167static inline void get_inotify_dev(struct inotify_device *dev)
168{
169 atomic_inc(&dev->count);
170}
171
172static inline void put_inotify_dev(struct inotify_device *dev)
173{
174 if (atomic_dec_and_test(&dev->count)) {
175 atomic_dec(&dev->user->inotify_devs);
176 free_uid(dev->user);
177 kfree(dev);
178 }
179}
180
181static inline void get_inotify_watch(struct inotify_watch *watch)
182{
183 atomic_inc(&watch->count);
184}
185
186/*
187 * put_inotify_watch - decrements the ref count on a given watch. cleans up
188 * the watch and its references if the count reaches zero.
189 */
190static inline void put_inotify_watch(struct inotify_watch *watch)
191{
192 if (atomic_dec_and_test(&watch->count)) {
193 put_inotify_dev(watch->dev);
194 iput(watch->inode);
195 kmem_cache_free(watch_cachep, watch);
196 }
197}
198
199/*
200 * kernel_event - create a new kernel event with the given parameters
201 *
202 * This function can sleep.
203 */
204static struct inotify_kernel_event * kernel_event(s32 wd, u32 mask, u32 cookie,
205 const char *name)
206{
207 struct inotify_kernel_event *kevent;
208
209 kevent = kmem_cache_alloc(event_cachep, GFP_KERNEL);
210 if (unlikely(!kevent))
211 return NULL;
212
213 /* we hand this out to user-space, so zero it just in case */
214 memset(&kevent->event, 0, sizeof(struct inotify_event));
215
216 kevent->event.wd = wd;
217 kevent->event.mask = mask;
218 kevent->event.cookie = cookie;
219
220 INIT_LIST_HEAD(&kevent->list);
221
222 if (name) {
223 size_t len, rem, event_size = sizeof(struct inotify_event);
224
225 /*
226 * We need to pad the filename so as to properly align an
227 * array of inotify_event structures. Because the structure is
228 * small and the common case is a small filename, we just round
229 * up to the next multiple of the structure's sizeof. This is
230 * simple and safe for all architectures.
231 */
232 len = strlen(name) + 1;
233 rem = event_size - len;
234 if (len > event_size) {
235 rem = event_size - (len % event_size);
236 if (len % event_size == 0)
237 rem = 0;
238 }
239
240 kevent->name = kmalloc(len + rem, GFP_KERNEL);
241 if (unlikely(!kevent->name)) {
242 kmem_cache_free(event_cachep, kevent);
243 return NULL;
244 }
245 memcpy(kevent->name, name, len);
246 if (rem)
247 memset(kevent->name + len, 0, rem);
248 kevent->event.len = len + rem;
249 } else {
250 kevent->event.len = 0;
251 kevent->name = NULL;
252 }
253
254 return kevent;
255}
256
257/*
258 * inotify_dev_get_event - return the next event in the given dev's queue
259 *
260 * Caller must hold dev->sem.
261 */
262static inline struct inotify_kernel_event *
263inotify_dev_get_event(struct inotify_device *dev)
264{
265 return list_entry(dev->events.next, struct inotify_kernel_event, list);
266}
267
268/*
269 * inotify_dev_queue_event - add a new event to the given device
270 *
271 * Caller must hold dev->sem. Can sleep (calls kernel_event()).
272 */
273static void inotify_dev_queue_event(struct inotify_device *dev,
274 struct inotify_watch *watch, u32 mask,
275 u32 cookie, const char *name)
276{
277 struct inotify_kernel_event *kevent, *last;
278
279 /* coalescing: drop this event if it is a dupe of the previous */
280 last = inotify_dev_get_event(dev);
281 if (last && last->event.mask == mask && last->event.wd == watch->wd &&
282 last->event.cookie == cookie) {
283 const char *lastname = last->name;
284
285 if (!name && !lastname)
286 return;
287 if (name && lastname && !strcmp(lastname, name))
288 return;
289 }
290
291 /* the queue overflowed and we already sent the Q_OVERFLOW event */
292 if (unlikely(dev->event_count > dev->max_events))
293 return;
294
295 /* if the queue overflows, we need to notify user space */
296 if (unlikely(dev->event_count == dev->max_events))
297 kevent = kernel_event(-1, IN_Q_OVERFLOW, cookie, NULL);
298 else
299 kevent = kernel_event(watch->wd, mask, cookie, name);
300
301 if (unlikely(!kevent))
302 return;
303
304 /* queue the event and wake up anyone waiting */
305 dev->event_count++;
306 dev->queue_size += sizeof(struct inotify_event) + kevent->event.len;
307 list_add_tail(&kevent->list, &dev->events);
308 wake_up_interruptible(&dev->wq);
309}
310
311/*
312 * remove_kevent - cleans up and ultimately frees the given kevent
313 *
314 * Caller must hold dev->sem.
315 */
316static void remove_kevent(struct inotify_device *dev,
317 struct inotify_kernel_event *kevent)
318{
319 list_del(&kevent->list);
320
321 dev->event_count--;
322 dev->queue_size -= sizeof(struct inotify_event) + kevent->event.len;
323
324 kfree(kevent->name);
325 kmem_cache_free(event_cachep, kevent);
326}
327
328/*
329 * inotify_dev_event_dequeue - destroy an event on the given device
330 *
331 * Caller must hold dev->sem.
332 */
333static void inotify_dev_event_dequeue(struct inotify_device *dev)
334{
335 if (!list_empty(&dev->events)) {
336 struct inotify_kernel_event *kevent;
337 kevent = inotify_dev_get_event(dev);
338 remove_kevent(dev, kevent);
339 }
340}
341
342/*
343 * inotify_dev_get_wd - returns the next WD for use by the given dev
344 *
345 * Callers must hold dev->sem. This function can sleep.
346 */
347static int inotify_dev_get_wd(struct inotify_device *dev,
348 struct inotify_watch *watch)
349{
350 int ret;
351
352 do {
353 if (unlikely(!idr_pre_get(&dev->idr, GFP_KERNEL)))
354 return -ENOSPC;
355 ret = idr_get_new(&dev->idr, watch, &watch->wd);
356 } while (ret == -EAGAIN);
357
358 return ret;
359}
360
361/*
362 * find_inode - resolve a user-given path to a specific inode and return a nd
363 */
364static int find_inode(const char __user *dirname, struct nameidata *nd)
365{
366 int error;
367
368 error = __user_walk(dirname, LOOKUP_FOLLOW, nd);
369 if (error)
370 return error;
371 /* you can only watch an inode if you have read permissions on it */
372 error = permission(nd->dentry->d_inode, MAY_READ, NULL);
373 if (error)
374 path_release (nd);
375 return error;
376}
377
378/*
379 * create_watch - creates a watch on the given device.
380 *
381 * Callers must hold dev->sem. Calls inotify_dev_get_wd() so may sleep.
382 * Both 'dev' and 'inode' (by way of nameidata) need to be pinned.
383 */
384static struct inotify_watch *create_watch(struct inotify_device *dev,
385 u32 mask, struct inode *inode)
386{
387 struct inotify_watch *watch;
388 int ret;
389
390 if (atomic_read(&dev->user->inotify_watches) >= inotify_max_user_watches)
391 return ERR_PTR(-ENOSPC);
392
393 watch = kmem_cache_alloc(watch_cachep, GFP_KERNEL);
394 if (unlikely(!watch))
395 return ERR_PTR(-ENOMEM);
396
397 ret = inotify_dev_get_wd(dev, watch);
398 if (unlikely(ret)) {
399 kmem_cache_free(watch_cachep, watch);
400 return ERR_PTR(ret);
401 }
402
403 watch->mask = mask;
404 atomic_set(&watch->count, 0);
405 INIT_LIST_HEAD(&watch->d_list);
406 INIT_LIST_HEAD(&watch->i_list);
407
408 /* save a reference to device and bump the count to make it official */
409 get_inotify_dev(dev);
410 watch->dev = dev;
411
412 /*
413 * Save a reference to the inode and bump the ref count to make it
414 * official. We hold a reference to nameidata, which makes this safe.
415 */
416 watch->inode = igrab(inode);
417
418 /* bump our own count, corresponding to our entry in dev->watches */
419 get_inotify_watch(watch);
420
421 atomic_inc(&dev->user->inotify_watches);
422
423 return watch;
424}
425
426/*
427 * inotify_find_dev - find the watch associated with the given inode and dev
428 *
429 * Callers must hold inode->inotify_sem.
430 */
431static struct inotify_watch *inode_find_dev(struct inode *inode,
432 struct inotify_device *dev)
433{
434 struct inotify_watch *watch;
435
436 list_for_each_entry(watch, &inode->inotify_watches, i_list) {
437 if (watch->dev == dev)
438 return watch;
439 }
440
441 return NULL;
442}
443
444/*
445 * remove_watch_no_event - remove_watch() without the IN_IGNORED event.
446 */
447static void remove_watch_no_event(struct inotify_watch *watch,
448 struct inotify_device *dev)
449{
450 list_del(&watch->i_list);
451 list_del(&watch->d_list);
452
453 atomic_dec(&dev->user->inotify_watches);
454 idr_remove(&dev->idr, watch->wd);
455 put_inotify_watch(watch);
456}
457
458/*
459 * remove_watch - Remove a watch from both the device and the inode. Sends
460 * the IN_IGNORED event to the given device signifying that the inode is no
461 * longer watched.
462 *
463 * Callers must hold both inode->inotify_sem and dev->sem. We drop a
464 * reference to the inode before returning.
465 *
466 * The inode is not iput() so as to remain atomic. If the inode needs to be
467 * iput(), the call returns one. Otherwise, it returns zero.
468 */
469static void remove_watch(struct inotify_watch *watch,struct inotify_device *dev)
470{
471 inotify_dev_queue_event(dev, watch, IN_IGNORED, 0, NULL);
472 remove_watch_no_event(watch, dev);
473}
474
475/*
476 * inotify_inode_watched - returns nonzero if there are watches on this inode
477 * and zero otherwise. We call this lockless, we do not care if we race.
478 */
479static inline int inotify_inode_watched(struct inode *inode)
480{
481 return !list_empty(&inode->inotify_watches);
482}
483
484/* Kernel API */
485
486/**
487 * inotify_inode_queue_event - queue an event to all watches on this inode
488 * @inode: inode event is originating from
489 * @mask: event mask describing this event
490 * @cookie: cookie for synchronization, or zero
491 * @name: filename, if any
492 */
493void inotify_inode_queue_event(struct inode *inode, u32 mask, u32 cookie,
494 const char *name)
495{
496 struct inotify_watch *watch, *next;
497
498 if (!inotify_inode_watched(inode))
499 return;
500
501 down(&inode->inotify_sem);
502 list_for_each_entry_safe(watch, next, &inode->inotify_watches, i_list) {
503 u32 watch_mask = watch->mask;
504 if (watch_mask & mask) {
505 struct inotify_device *dev = watch->dev;
506 get_inotify_watch(watch);
507 down(&dev->sem);
508 inotify_dev_queue_event(dev, watch, mask, cookie, name);
509 if (watch_mask & IN_ONESHOT)
510 remove_watch_no_event(watch, dev);
511 up(&dev->sem);
512 put_inotify_watch(watch);
513 }
514 }
515 up(&inode->inotify_sem);
516}
517EXPORT_SYMBOL_GPL(inotify_inode_queue_event);
518
519/**
520 * inotify_dentry_parent_queue_event - queue an event to a dentry's parent
521 * @dentry: the dentry in question, we queue against this dentry's parent
522 * @mask: event mask describing this event
523 * @cookie: cookie for synchronization, or zero
524 * @name: filename, if any
525 */
526void inotify_dentry_parent_queue_event(struct dentry *dentry, u32 mask,
527 u32 cookie, const char *name)
528{
529 struct dentry *parent;
530 struct inode *inode;
531
532 spin_lock(&dentry->d_lock);
533 parent = dentry->d_parent;
534 inode = parent->d_inode;
535
536 if (inotify_inode_watched(inode)) {
537 dget(parent);
538 spin_unlock(&dentry->d_lock);
539 inotify_inode_queue_event(inode, mask, cookie, name);
540 dput(parent);
541 } else
542 spin_unlock(&dentry->d_lock);
543}
544EXPORT_SYMBOL_GPL(inotify_dentry_parent_queue_event);
545
546/**
547 * inotify_get_cookie - return a unique cookie for use in synchronizing events.
548 */
549u32 inotify_get_cookie(void)
550{
551 return atomic_inc_return(&inotify_cookie);
552}
553EXPORT_SYMBOL_GPL(inotify_get_cookie);
554
555/**
556 * inotify_unmount_inodes - an sb is unmounting. handle any watched inodes.
557 * @list: list of inodes being unmounted (sb->s_inodes)
558 *
559 * Called with inode_lock held, protecting the unmounting super block's list
560 * of inodes, and with iprune_sem held, keeping shrink_icache_memory() at bay.
561 * We temporarily drop inode_lock, however, and CAN block.
562 */
563void inotify_unmount_inodes(struct list_head *list)
564{
565 struct inode *inode, *next_i, *need_iput = NULL;
566
567 list_for_each_entry_safe(inode, next_i, list, i_sb_list) {
568 struct inotify_watch *watch, *next_w;
569 struct inode *need_iput_tmp;
570 struct list_head *watches;
571
572 /*
573 * If i_count is zero, the inode cannot have any watches and
574 * doing an __iget/iput with MS_ACTIVE clear would actually
575 * evict all inodes with zero i_count from icache which is
576 * unnecessarily violent and may in fact be illegal to do.
577 */
578 if (!atomic_read(&inode->i_count))
579 continue;
580
581 /*
582 * We cannot __iget() an inode in state I_CLEAR, I_FREEING, or
583 * I_WILL_FREE which is fine because by that point the inode
584 * cannot have any associated watches.
585 */
586 if (inode->i_state & (I_CLEAR | I_FREEING | I_WILL_FREE))
587 continue;
588
589 need_iput_tmp = need_iput;
590 need_iput = NULL;
591 /* In case the remove_watch() drops a reference. */
592 if (inode != need_iput_tmp)
593 __iget(inode);
594 else
595 need_iput_tmp = NULL;
596 /* In case the dropping of a reference would nuke next_i. */
597 if ((&next_i->i_sb_list != list) &&
598 atomic_read(&next_i->i_count) &&
599 !(next_i->i_state & (I_CLEAR | I_FREEING |
600 I_WILL_FREE))) {
601 __iget(next_i);
602 need_iput = next_i;
603 }
604
605 /*
606 * We can safely drop inode_lock here because we hold
607 * references on both inode and next_i. Also no new inodes
608 * will be added since the umount has begun. Finally,
609 * iprune_sem keeps shrink_icache_memory() away.
610 */
611 spin_unlock(&inode_lock);
612
613 if (need_iput_tmp)
614 iput(need_iput_tmp);
615
616 /* for each watch, send IN_UNMOUNT and then remove it */
617 down(&inode->inotify_sem);
618 watches = &inode->inotify_watches;
619 list_for_each_entry_safe(watch, next_w, watches, i_list) {
620 struct inotify_device *dev = watch->dev;
621 down(&dev->sem);
622 inotify_dev_queue_event(dev, watch, IN_UNMOUNT,0,NULL);
623 remove_watch(watch, dev);
624 up(&dev->sem);
625 }
626 up(&inode->inotify_sem);
627 iput(inode);
628
629 spin_lock(&inode_lock);
630 }
631}
632EXPORT_SYMBOL_GPL(inotify_unmount_inodes);
633
634/**
635 * inotify_inode_is_dead - an inode has been deleted, cleanup any watches
636 * @inode: inode that is about to be removed
637 */
638void inotify_inode_is_dead(struct inode *inode)
639{
640 struct inotify_watch *watch, *next;
641
642 down(&inode->inotify_sem);
643 list_for_each_entry_safe(watch, next, &inode->inotify_watches, i_list) {
644 struct inotify_device *dev = watch->dev;
645 down(&dev->sem);
646 remove_watch(watch, dev);
647 up(&dev->sem);
648 }
649 up(&inode->inotify_sem);
650}
651EXPORT_SYMBOL_GPL(inotify_inode_is_dead);
652
653/* Device Interface */
654
655static unsigned int inotify_poll(struct file *file, poll_table *wait)
656{
657 struct inotify_device *dev = file->private_data;
658 int ret = 0;
659
660 poll_wait(file, &dev->wq, wait);
661 down(&dev->sem);
662 if (!list_empty(&dev->events))
663 ret = POLLIN | POLLRDNORM;
664 up(&dev->sem);
665
666 return ret;
667}
668
669static ssize_t inotify_read(struct file *file, char __user *buf,
670 size_t count, loff_t *pos)
671{
672 size_t event_size = sizeof (struct inotify_event);
673 struct inotify_device *dev;
674 char __user *start;
675 int ret;
676 DEFINE_WAIT(wait);
677
678 start = buf;
679 dev = file->private_data;
680
681 while (1) {
682 int events;
683
684 prepare_to_wait(&dev->wq, &wait, TASK_INTERRUPTIBLE);
685
686 down(&dev->sem);
687 events = !list_empty(&dev->events);
688 up(&dev->sem);
689 if (events) {
690 ret = 0;
691 break;
692 }
693
694 if (file->f_flags & O_NONBLOCK) {
695 ret = -EAGAIN;
696 break;
697 }
698
699 if (signal_pending(current)) {
700 ret = -EINTR;
701 break;
702 }
703
704 schedule();
705 }
706
707 finish_wait(&dev->wq, &wait);
708 if (ret)
709 return ret;
710
711 down(&dev->sem);
712 while (1) {
713 struct inotify_kernel_event *kevent;
714
715 ret = buf - start;
716 if (list_empty(&dev->events))
717 break;
718
719 kevent = inotify_dev_get_event(dev);
720 if (event_size + kevent->event.len > count)
721 break;
722
723 if (copy_to_user(buf, &kevent->event, event_size)) {
724 ret = -EFAULT;
725 break;
726 }
727 buf += event_size;
728 count -= event_size;
729
730 if (kevent->name) {
731 if (copy_to_user(buf, kevent->name, kevent->event.len)){
732 ret = -EFAULT;
733 break;
734 }
735 buf += kevent->event.len;
736 count -= kevent->event.len;
737 }
738
739 remove_kevent(dev, kevent);
740 }
741 up(&dev->sem);
742
743 return ret;
744}
745
746static int inotify_release(struct inode *ignored, struct file *file)
747{
748 struct inotify_device *dev = file->private_data;
749
750 /*
751 * Destroy all of the watches on this device. Unfortunately, not very
752 * pretty. We cannot do a simple iteration over the list, because we
753 * do not know the inode until we iterate to the watch. But we need to
754 * hold inode->inotify_sem before dev->sem. The following works.
755 */
756 while (1) {
757 struct inotify_watch *watch;
758 struct list_head *watches;
759 struct inode *inode;
760
761 down(&dev->sem);
762 watches = &dev->watches;
763 if (list_empty(watches)) {
764 up(&dev->sem);
765 break;
766 }
767 watch = list_entry(watches->next, struct inotify_watch, d_list);
768 get_inotify_watch(watch);
769 up(&dev->sem);
770
771 inode = watch->inode;
772 down(&inode->inotify_sem);
773 down(&dev->sem);
774 remove_watch_no_event(watch, dev);
775 up(&dev->sem);
776 up(&inode->inotify_sem);
777 put_inotify_watch(watch);
778 }
779
780 /* destroy all of the events on this device */
781 down(&dev->sem);
782 while (!list_empty(&dev->events))
783 inotify_dev_event_dequeue(dev);
784 up(&dev->sem);
785
786 /* free this device: the put matching the get in inotify_open() */
787 put_inotify_dev(dev);
788
789 return 0;
790}
791
792/*
793 * inotify_ignore - handle the INOTIFY_IGNORE ioctl, asking that a given wd be
794 * removed from the device.
795 *
796 * Can sleep.
797 */
798static int inotify_ignore(struct inotify_device *dev, s32 wd)
799{
800 struct inotify_watch *watch;
801 struct inode *inode;
802
803 down(&dev->sem);
804 watch = idr_find(&dev->idr, wd);
805 if (unlikely(!watch)) {
806 up(&dev->sem);
807 return -EINVAL;
808 }
809 get_inotify_watch(watch);
810 inode = watch->inode;
811 up(&dev->sem);
812
813 down(&inode->inotify_sem);
814 down(&dev->sem);
815
816 /* make sure that we did not race */
817 watch = idr_find(&dev->idr, wd);
818 if (likely(watch))
819 remove_watch(watch, dev);
820
821 up(&dev->sem);
822 up(&inode->inotify_sem);
823 put_inotify_watch(watch);
824
825 return 0;
826}
827
828static long inotify_ioctl(struct file *file, unsigned int cmd,
829 unsigned long arg)
830{
831 struct inotify_device *dev;
832 void __user *p;
833 int ret = -ENOTTY;
834
835 dev = file->private_data;
836 p = (void __user *) arg;
837
838 switch (cmd) {
839 case FIONREAD:
840 ret = put_user(dev->queue_size, (int __user *) p);
841 break;
842 }
843
844 return ret;
845}
846
847static struct file_operations inotify_fops = {
848 .poll = inotify_poll,
849 .read = inotify_read,
850 .release = inotify_release,
851 .unlocked_ioctl = inotify_ioctl,
852 .compat_ioctl = inotify_ioctl,
853};
854
855asmlinkage long sys_inotify_init(void)
856{
857 struct inotify_device *dev;
858 struct user_struct *user;
859 int ret = -ENOTTY;
860 int fd;
861 struct file *filp;
862
863 fd = get_unused_fd();
864 if (fd < 0) {
865 ret = fd;
866 goto out;
867 }
868
869 filp = get_empty_filp();
870 if (!filp) {
871 put_unused_fd(fd);
872 ret = -ENFILE;
873 goto out;
874 }
875 filp->f_op = &inotify_fops;
876 filp->f_vfsmnt = mntget(inotify_mnt);
877 filp->f_dentry = dget(inotify_mnt->mnt_root);
878 filp->f_mapping = filp->f_dentry->d_inode->i_mapping;
879 filp->f_mode = FMODE_READ;
880 filp->f_flags = O_RDONLY;
881
882 user = get_uid(current->user);
883
884 if (unlikely(atomic_read(&user->inotify_devs) >= inotify_max_user_instances)) {
885 ret = -EMFILE;
886 goto out_err;
887 }
888
889 dev = kmalloc(sizeof(struct inotify_device), GFP_KERNEL);
890 if (unlikely(!dev)) {
891 ret = -ENOMEM;
892 goto out_err;
893 }
894
895 idr_init(&dev->idr);
896 INIT_LIST_HEAD(&dev->events);
897 INIT_LIST_HEAD(&dev->watches);
898 init_waitqueue_head(&dev->wq);
899 sema_init(&dev->sem, 1);
900 dev->event_count = 0;
901 dev->queue_size = 0;
902 dev->max_events = inotify_max_queued_events;
903 dev->user = user;
904 atomic_set(&dev->count, 0);
905
906 get_inotify_dev(dev);
907 atomic_inc(&user->inotify_devs);
908
909 filp->private_data = dev;
910 fd_install (fd, filp);
911 return fd;
912out_err:
913 put_unused_fd (fd);
914 put_filp (filp);
915 free_uid(user);
916out:
917 return ret;
918}
919
920asmlinkage long sys_inotify_add_watch(int fd, const char *path, u32 mask)
921{
922 struct inotify_watch *watch, *old;
923 struct inode *inode;
924 struct inotify_device *dev;
925 struct nameidata nd;
926 struct file *filp;
927 int ret;
928
929 filp = fget(fd);
930 if (!filp)
931 return -EBADF;
932
933 dev = filp->private_data;
934
935 ret = find_inode((const char __user*) path, &nd);
936 if (ret)
937 goto fput_and_out;
938
939 /* Held in place by reference in nd */
940 inode = nd.dentry->d_inode;
941
942 down(&inode->inotify_sem);
943 down(&dev->sem);
944
945 /* don't let user-space set invalid bits: we don't want flags set */
946 mask &= IN_ALL_EVENTS;
947 if (!mask) {
948 ret = -EINVAL;
949 goto out;
950 }
951
952 /*
953 * Handle the case of re-adding a watch on an (inode,dev) pair that we
954 * are already watching. We just update the mask and return its wd.
955 */
956 old = inode_find_dev(inode, dev);
957 if (unlikely(old)) {
958 old->mask = mask;
959 ret = old->wd;
960 goto out;
961 }
962
963 watch = create_watch(dev, mask, inode);
964 if (unlikely(IS_ERR(watch))) {
965 ret = PTR_ERR(watch);
966 goto out;
967 }
968
969 /* Add the watch to the device's and the inode's list */
970 list_add(&watch->d_list, &dev->watches);
971 list_add(&watch->i_list, &inode->inotify_watches);
972 ret = watch->wd;
973out:
974 path_release (&nd);
975 up(&dev->sem);
976 up(&inode->inotify_sem);
977fput_and_out:
978 fput(filp);
979 return ret;
980}
981
982asmlinkage long sys_inotify_rm_watch(int fd, u32 wd)
983{
984 struct file *filp;
985 struct inotify_device *dev;
986 int ret;
987
988 filp = fget(fd);
989 if (!filp)
990 return -EBADF;
991 dev = filp->private_data;
992 ret = inotify_ignore(dev, wd);
993 fput(filp);
994
995 return ret;
996}
997
998static struct super_block *
999inotify_get_sb(struct file_system_type *fs_type, int flags,
1000 const char *dev_name, void *data)
1001{
1002 return get_sb_pseudo(fs_type, "inotify", NULL, 0xBAD1DEA);
1003}
1004
1005static struct file_system_type inotify_fs_type = {
1006 .name = "inotifyfs",
1007 .get_sb = inotify_get_sb,
1008 .kill_sb = kill_anon_super,
1009};
1010
1011/*
1012 * inotify_init - Our initialization function. Note that we cannnot return
1013 * error because we have compiled-in VFS hooks. So an (unlikely) failure here
1014 * must result in panic().
1015 */
1016static int __init inotify_init(void)
1017{
1018 register_filesystem(&inotify_fs_type);
1019 inotify_mnt = kern_mount(&inotify_fs_type);
1020
1021 inotify_max_queued_events = 8192;
1022 inotify_max_user_instances = 8;
1023 inotify_max_user_watches = 8192;
1024
1025 atomic_set(&inotify_cookie, 0);
1026
1027 watch_cachep = kmem_cache_create("inotify_watch_cache",
1028 sizeof(struct inotify_watch),
1029 0, SLAB_PANIC, NULL, NULL);
1030 event_cachep = kmem_cache_create("inotify_event_cache",
1031 sizeof(struct inotify_kernel_event),
1032 0, SLAB_PANIC, NULL, NULL);
1033
1034 return 0;
1035}
1036
1037module_init(inotify_init);
diff --git a/fs/jfs/jfs_dmap.c b/fs/jfs/jfs_dmap.c
index cced2fed9d0f..0732f206ca60 100644
--- a/fs/jfs/jfs_dmap.c
+++ b/fs/jfs/jfs_dmap.c
@@ -26,36 +26,6 @@
26#include "jfs_debug.h" 26#include "jfs_debug.h"
27 27
28/* 28/*
29 * Debug code for double-checking block map
30 */
31/* #define _JFS_DEBUG_DMAP 1 */
32
33#ifdef _JFS_DEBUG_DMAP
34#define DBINITMAP(size,ipbmap,results) \
35 DBinitmap(size,ipbmap,results)
36#define DBALLOC(dbmap,mapsize,blkno,nblocks) \
37 DBAlloc(dbmap,mapsize,blkno,nblocks)
38#define DBFREE(dbmap,mapsize,blkno,nblocks) \
39 DBFree(dbmap,mapsize,blkno,nblocks)
40#define DBALLOCCK(dbmap,mapsize,blkno,nblocks) \
41 DBAllocCK(dbmap,mapsize,blkno,nblocks)
42#define DBFREECK(dbmap,mapsize,blkno,nblocks) \
43 DBFreeCK(dbmap,mapsize,blkno,nblocks)
44
45static void DBinitmap(s64, struct inode *, u32 **);
46static void DBAlloc(uint *, s64, s64, s64);
47static void DBFree(uint *, s64, s64, s64);
48static void DBAllocCK(uint *, s64, s64, s64);
49static void DBFreeCK(uint *, s64, s64, s64);
50#else
51#define DBINITMAP(size,ipbmap,results)
52#define DBALLOC(dbmap, mapsize, blkno, nblocks)
53#define DBFREE(dbmap, mapsize, blkno, nblocks)
54#define DBALLOCCK(dbmap, mapsize, blkno, nblocks)
55#define DBFREECK(dbmap, mapsize, blkno, nblocks)
56#endif /* _JFS_DEBUG_DMAP */
57
58/*
59 * SERIALIZATION of the Block Allocation Map. 29 * SERIALIZATION of the Block Allocation Map.
60 * 30 *
61 * the working state of the block allocation map is accessed in 31 * the working state of the block allocation map is accessed in
@@ -242,7 +212,6 @@ int dbMount(struct inode *ipbmap)
242 JFS_SBI(ipbmap->i_sb)->bmap = bmp; 212 JFS_SBI(ipbmap->i_sb)->bmap = bmp;
243 213
244 memset(bmp->db_active, 0, sizeof(bmp->db_active)); 214 memset(bmp->db_active, 0, sizeof(bmp->db_active));
245 DBINITMAP(bmp->db_mapsize, ipbmap, &bmp->db_DBmap);
246 215
247 /* 216 /*
248 * allocate/initialize the bmap lock 217 * allocate/initialize the bmap lock
@@ -407,16 +376,12 @@ int dbFree(struct inode *ip, s64 blkno, s64 nblocks)
407 */ 376 */
408 nb = min(rem, BPERDMAP - (blkno & (BPERDMAP - 1))); 377 nb = min(rem, BPERDMAP - (blkno & (BPERDMAP - 1)));
409 378
410 DBALLOCCK(bmp->db_DBmap, bmp->db_mapsize, blkno, nb);
411
412 /* free the blocks. */ 379 /* free the blocks. */
413 if ((rc = dbFreeDmap(bmp, dp, blkno, nb))) { 380 if ((rc = dbFreeDmap(bmp, dp, blkno, nb))) {
414 release_metapage(mp); 381 release_metapage(mp);
415 IREAD_UNLOCK(ipbmap); 382 IREAD_UNLOCK(ipbmap);
416 return (rc); 383 return (rc);
417 } 384 }
418
419 DBFREE(bmp->db_DBmap, bmp->db_mapsize, blkno, nb);
420 } 385 }
421 386
422 /* write the last buffer. */ 387 /* write the last buffer. */
@@ -775,10 +740,6 @@ int dbAlloc(struct inode *ip, s64 hint, s64 nblocks, s64 * results)
775 IWRITE_LOCK(ipbmap); 740 IWRITE_LOCK(ipbmap);
776 741
777 rc = dbAllocAny(bmp, nblocks, l2nb, results); 742 rc = dbAllocAny(bmp, nblocks, l2nb, results);
778 if (rc == 0) {
779 DBALLOC(bmp->db_DBmap, bmp->db_mapsize, *results,
780 nblocks);
781 }
782 743
783 goto write_unlock; 744 goto write_unlock;
784 } 745 }
@@ -836,8 +797,6 @@ int dbAlloc(struct inode *ip, s64 hint, s64 nblocks, s64 * results)
836 != -ENOSPC) { 797 != -ENOSPC) {
837 if (rc == 0) { 798 if (rc == 0) {
838 *results = blkno; 799 *results = blkno;
839 DBALLOC(bmp->db_DBmap, bmp->db_mapsize,
840 *results, nblocks);
841 mark_metapage_dirty(mp); 800 mark_metapage_dirty(mp);
842 } 801 }
843 802
@@ -863,11 +822,8 @@ int dbAlloc(struct inode *ip, s64 hint, s64 nblocks, s64 * results)
863 if ((rc = 822 if ((rc =
864 dbAllocNear(bmp, dp, blkno, (int) nblocks, l2nb, results)) 823 dbAllocNear(bmp, dp, blkno, (int) nblocks, l2nb, results))
865 != -ENOSPC) { 824 != -ENOSPC) {
866 if (rc == 0) { 825 if (rc == 0)
867 DBALLOC(bmp->db_DBmap, bmp->db_mapsize,
868 *results, nblocks);
869 mark_metapage_dirty(mp); 826 mark_metapage_dirty(mp);
870 }
871 827
872 release_metapage(mp); 828 release_metapage(mp);
873 goto read_unlock; 829 goto read_unlock;
@@ -878,11 +834,8 @@ int dbAlloc(struct inode *ip, s64 hint, s64 nblocks, s64 * results)
878 */ 834 */
879 if ((rc = dbAllocDmapLev(bmp, dp, (int) nblocks, l2nb, results)) 835 if ((rc = dbAllocDmapLev(bmp, dp, (int) nblocks, l2nb, results))
880 != -ENOSPC) { 836 != -ENOSPC) {
881 if (rc == 0) { 837 if (rc == 0)
882 DBALLOC(bmp->db_DBmap, bmp->db_mapsize,
883 *results, nblocks);
884 mark_metapage_dirty(mp); 838 mark_metapage_dirty(mp);
885 }
886 839
887 release_metapage(mp); 840 release_metapage(mp);
888 goto read_unlock; 841 goto read_unlock;
@@ -896,13 +849,9 @@ int dbAlloc(struct inode *ip, s64 hint, s64 nblocks, s64 * results)
896 * the same allocation group as the hint. 849 * the same allocation group as the hint.
897 */ 850 */
898 IWRITE_LOCK(ipbmap); 851 IWRITE_LOCK(ipbmap);
899 if ((rc = dbAllocAG(bmp, agno, nblocks, l2nb, results)) 852 if ((rc = dbAllocAG(bmp, agno, nblocks, l2nb, results)) != -ENOSPC)
900 != -ENOSPC) {
901 if (rc == 0)
902 DBALLOC(bmp->db_DBmap, bmp->db_mapsize,
903 *results, nblocks);
904 goto write_unlock; 853 goto write_unlock;
905 } 854
906 IWRITE_UNLOCK(ipbmap); 855 IWRITE_UNLOCK(ipbmap);
907 856
908 857
@@ -918,9 +867,6 @@ int dbAlloc(struct inode *ip, s64 hint, s64 nblocks, s64 * results)
918 */ 867 */
919 if ((rc = dbAllocAG(bmp, agno, nblocks, l2nb, results)) == -ENOSPC) 868 if ((rc = dbAllocAG(bmp, agno, nblocks, l2nb, results)) == -ENOSPC)
920 rc = dbAllocAny(bmp, nblocks, l2nb, results); 869 rc = dbAllocAny(bmp, nblocks, l2nb, results);
921 if (rc == 0) {
922 DBALLOC(bmp->db_DBmap, bmp->db_mapsize, *results, nblocks);
923 }
924 870
925 write_unlock: 871 write_unlock:
926 IWRITE_UNLOCK(ipbmap); 872 IWRITE_UNLOCK(ipbmap);
@@ -992,10 +938,9 @@ int dbAllocExact(struct inode *ip, s64 blkno, int nblocks)
992 938
993 IREAD_UNLOCK(ipbmap); 939 IREAD_UNLOCK(ipbmap);
994 940
995 if (rc == 0) { 941 if (rc == 0)
996 DBALLOC(bmp->db_DBmap, bmp->db_mapsize, blkno, nblocks);
997 mark_metapage_dirty(mp); 942 mark_metapage_dirty(mp);
998 } 943
999 release_metapage(mp); 944 release_metapage(mp);
1000 945
1001 return (rc); 946 return (rc);
@@ -1144,7 +1089,6 @@ static int dbExtend(struct inode *ip, s64 blkno, s64 nblocks, s64 addnblocks)
1144 return -EIO; 1089 return -EIO;
1145 } 1090 }
1146 1091
1147 DBALLOCCK(bmp->db_DBmap, bmp->db_mapsize, blkno, nblocks);
1148 dp = (struct dmap *) mp->data; 1092 dp = (struct dmap *) mp->data;
1149 1093
1150 /* try to allocate the blocks immediately following the 1094 /* try to allocate the blocks immediately following the
@@ -1155,11 +1099,9 @@ static int dbExtend(struct inode *ip, s64 blkno, s64 nblocks, s64 addnblocks)
1155 IREAD_UNLOCK(ipbmap); 1099 IREAD_UNLOCK(ipbmap);
1156 1100
1157 /* were we successful ? */ 1101 /* were we successful ? */
1158 if (rc == 0) { 1102 if (rc == 0)
1159 DBALLOC(bmp->db_DBmap, bmp->db_mapsize, extblkno,
1160 addnblocks);
1161 write_metapage(mp); 1103 write_metapage(mp);
1162 } else 1104 else
1163 /* we were not successful */ 1105 /* we were not successful */
1164 release_metapage(mp); 1106 release_metapage(mp);
1165 1107
@@ -3185,16 +3127,12 @@ int dbAllocBottomUp(struct inode *ip, s64 blkno, s64 nblocks)
3185 */ 3127 */
3186 nb = min(rem, BPERDMAP - (blkno & (BPERDMAP - 1))); 3128 nb = min(rem, BPERDMAP - (blkno & (BPERDMAP - 1)));
3187 3129
3188 DBFREECK(bmp->db_DBmap, bmp->db_mapsize, blkno, nb);
3189
3190 /* allocate the blocks. */ 3130 /* allocate the blocks. */
3191 if ((rc = dbAllocDmapBU(bmp, dp, blkno, nb))) { 3131 if ((rc = dbAllocDmapBU(bmp, dp, blkno, nb))) {
3192 release_metapage(mp); 3132 release_metapage(mp);
3193 IREAD_UNLOCK(ipbmap); 3133 IREAD_UNLOCK(ipbmap);
3194 return (rc); 3134 return (rc);
3195 } 3135 }
3196
3197 DBALLOC(bmp->db_DBmap, bmp->db_mapsize, blkno, nb);
3198 } 3136 }
3199 3137
3200 /* write the last buffer. */ 3138 /* write the last buffer. */
@@ -4041,223 +3979,3 @@ s64 dbMapFileSizeToMapSize(struct inode * ipbmap)
4041 3979
4042 return (nblocks); 3980 return (nblocks);
4043} 3981}
4044
4045
4046#ifdef _JFS_DEBUG_DMAP
4047/*
4048 * DBinitmap()
4049 */
4050static void DBinitmap(s64 size, struct inode *ipbmap, u32 ** results)
4051{
4052 int npages;
4053 u32 *dbmap, *d;
4054 int n;
4055 s64 lblkno, cur_block;
4056 struct dmap *dp;
4057 struct metapage *mp;
4058
4059 npages = size / 32768;
4060 npages += (size % 32768) ? 1 : 0;
4061
4062 dbmap = (u32 *) xmalloc(npages * 4096, L2PSIZE, kernel_heap);
4063 if (dbmap == NULL)
4064 BUG(); /* Not robust since this is only unused debug code */
4065
4066 for (n = 0, d = dbmap; n < npages; n++, d += 1024)
4067 bzero(d, 4096);
4068
4069 /* Need to initialize from disk map pages
4070 */
4071 for (d = dbmap, cur_block = 0; cur_block < size;
4072 cur_block += BPERDMAP, d += LPERDMAP) {
4073 lblkno = BLKTODMAP(cur_block,
4074 JFS_SBI(ipbmap->i_sb)->bmap->
4075 db_l2nbperpage);
4076 mp = read_metapage(ipbmap, lblkno, PSIZE, 0);
4077 if (mp == NULL) {
4078 jfs_error(ipbmap->i_sb,
4079 "DBinitmap: could not read disk map page");
4080 continue;
4081 }
4082 dp = (struct dmap *) mp->data;
4083
4084 for (n = 0; n < LPERDMAP; n++)
4085 d[n] = le32_to_cpu(dp->wmap[n]);
4086
4087 release_metapage(mp);
4088 }
4089
4090 *results = dbmap;
4091}
4092
4093
4094/*
4095 * DBAlloc()
4096 */
4097void DBAlloc(uint * dbmap, s64 mapsize, s64 blkno, s64 nblocks)
4098{
4099 int word, nb, bitno;
4100 u32 mask;
4101
4102 assert(blkno > 0 && blkno < mapsize);
4103 assert(nblocks > 0 && nblocks <= mapsize);
4104
4105 assert(blkno + nblocks <= mapsize);
4106
4107 dbmap += (blkno / 32);
4108 while (nblocks > 0) {
4109 bitno = blkno & (32 - 1);
4110 nb = min(nblocks, 32 - bitno);
4111
4112 mask = (0xffffffff << (32 - nb) >> bitno);
4113 assert((mask & *dbmap) == 0);
4114 *dbmap |= mask;
4115
4116 dbmap++;
4117 blkno += nb;
4118 nblocks -= nb;
4119 }
4120}
4121
4122
4123/*
4124 * DBFree()
4125 */
4126static void DBFree(uint * dbmap, s64 mapsize, s64 blkno, s64 nblocks)
4127{
4128 int word, nb, bitno;
4129 u32 mask;
4130
4131 assert(blkno > 0 && blkno < mapsize);
4132 assert(nblocks > 0 && nblocks <= mapsize);
4133
4134 assert(blkno + nblocks <= mapsize);
4135
4136 dbmap += (blkno / 32);
4137 while (nblocks > 0) {
4138 bitno = blkno & (32 - 1);
4139 nb = min(nblocks, 32 - bitno);
4140
4141 mask = (0xffffffff << (32 - nb) >> bitno);
4142 assert((mask & *dbmap) == mask);
4143 *dbmap &= ~mask;
4144
4145 dbmap++;
4146 blkno += nb;
4147 nblocks -= nb;
4148 }
4149}
4150
4151
4152/*
4153 * DBAllocCK()
4154 */
4155static void DBAllocCK(uint * dbmap, s64 mapsize, s64 blkno, s64 nblocks)
4156{
4157 int word, nb, bitno;
4158 u32 mask;
4159
4160 assert(blkno > 0 && blkno < mapsize);
4161 assert(nblocks > 0 && nblocks <= mapsize);
4162
4163 assert(blkno + nblocks <= mapsize);
4164
4165 dbmap += (blkno / 32);
4166 while (nblocks > 0) {
4167 bitno = blkno & (32 - 1);
4168 nb = min(nblocks, 32 - bitno);
4169
4170 mask = (0xffffffff << (32 - nb) >> bitno);
4171 assert((mask & *dbmap) == mask);
4172
4173 dbmap++;
4174 blkno += nb;
4175 nblocks -= nb;
4176 }
4177}
4178
4179
4180/*
4181 * DBFreeCK()
4182 */
4183static void DBFreeCK(uint * dbmap, s64 mapsize, s64 blkno, s64 nblocks)
4184{
4185 int word, nb, bitno;
4186 u32 mask;
4187
4188 assert(blkno > 0 && blkno < mapsize);
4189 assert(nblocks > 0 && nblocks <= mapsize);
4190
4191 assert(blkno + nblocks <= mapsize);
4192
4193 dbmap += (blkno / 32);
4194 while (nblocks > 0) {
4195 bitno = blkno & (32 - 1);
4196 nb = min(nblocks, 32 - bitno);
4197
4198 mask = (0xffffffff << (32 - nb) >> bitno);
4199 assert((mask & *dbmap) == 0);
4200
4201 dbmap++;
4202 blkno += nb;
4203 nblocks -= nb;
4204 }
4205}
4206
4207
4208/*
4209 * dbPrtMap()
4210 */
4211static void dbPrtMap(struct bmap * bmp)
4212{
4213 printk(" mapsize: %d%d\n", bmp->db_mapsize);
4214 printk(" nfree: %d%d\n", bmp->db_nfree);
4215 printk(" numag: %d\n", bmp->db_numag);
4216 printk(" agsize: %d%d\n", bmp->db_agsize);
4217 printk(" agl2size: %d\n", bmp->db_agl2size);
4218 printk(" agwidth: %d\n", bmp->db_agwidth);
4219 printk(" agstart: %d\n", bmp->db_agstart);
4220 printk(" agheigth: %d\n", bmp->db_agheigth);
4221 printk(" aglevel: %d\n", bmp->db_aglevel);
4222 printk(" maxlevel: %d\n", bmp->db_maxlevel);
4223 printk(" maxag: %d\n", bmp->db_maxag);
4224 printk(" agpref: %d\n", bmp->db_agpref);
4225 printk(" l2nbppg: %d\n", bmp->db_l2nbperpage);
4226}
4227
4228
4229/*
4230 * dbPrtCtl()
4231 */
4232static void dbPrtCtl(struct dmapctl * dcp)
4233{
4234 int i, j, n;
4235
4236 printk(" height: %08x\n", le32_to_cpu(dcp->height));
4237 printk(" leafidx: %08x\n", le32_to_cpu(dcp->leafidx));
4238 printk(" budmin: %08x\n", dcp->budmin);
4239 printk(" nleafs: %08x\n", le32_to_cpu(dcp->nleafs));
4240 printk(" l2nleafs: %08x\n", le32_to_cpu(dcp->l2nleafs));
4241
4242 printk("\n Tree:\n");
4243 for (i = 0; i < CTLLEAFIND; i += 8) {
4244 n = min(8, CTLLEAFIND - i);
4245
4246 for (j = 0; j < n; j++)
4247 printf(" [%03x]: %02x", i + j,
4248 (char) dcp->stree[i + j]);
4249 printf("\n");
4250 }
4251
4252 printk("\n Tree Leaves:\n");
4253 for (i = 0; i < LPERCTL; i += 8) {
4254 n = min(8, LPERCTL - i);
4255
4256 for (j = 0; j < n; j++)
4257 printf(" [%03x]: %02x",
4258 i + j,
4259 (char) dcp->stree[i + j + CTLLEAFIND]);
4260 printf("\n");
4261 }
4262}
4263#endif /* _JFS_DEBUG_DMAP */
diff --git a/fs/jfs/jfs_dtree.c b/fs/jfs/jfs_dtree.c
index 8676aee3ae48..73b5fc7eda80 100644
--- a/fs/jfs/jfs_dtree.c
+++ b/fs/jfs/jfs_dtree.c
@@ -4554,202 +4554,3 @@ int dtModify(tid_t tid, struct inode *ip,
4554 4554
4555 return 0; 4555 return 0;
4556} 4556}
4557
4558#ifdef _JFS_DEBUG_DTREE
4559/*
4560 * dtDisplayTree()
4561 *
4562 * function: traverse forward
4563 */
4564int dtDisplayTree(struct inode *ip)
4565{
4566 int rc;
4567 struct metapage *mp;
4568 dtpage_t *p;
4569 s64 bn, pbn;
4570 int index, lastindex, v, h;
4571 pxd_t *xd;
4572 struct btstack btstack;
4573 struct btframe *btsp;
4574 struct btframe *parent;
4575 u8 *stbl;
4576 int psize = 256;
4577
4578 printk("display B+-tree.\n");
4579
4580 /* clear stack */
4581 btsp = btstack.stack;
4582
4583 /*
4584 * start with root
4585 *
4586 * root resides in the inode
4587 */
4588 bn = 0;
4589 v = h = 0;
4590
4591 /*
4592 * first access of each page:
4593 */
4594 newPage:
4595 DT_GETPAGE(ip, bn, mp, psize, p, rc);
4596 if (rc)
4597 return rc;
4598
4599 /* process entries forward from first index */
4600 index = 0;
4601 lastindex = p->header.nextindex - 1;
4602
4603 if (p->header.flag & BT_INTERNAL) {
4604 /*
4605 * first access of each internal page
4606 */
4607 printf("internal page ");
4608 dtDisplayPage(ip, bn, p);
4609
4610 goto getChild;
4611 } else { /* (p->header.flag & BT_LEAF) */
4612
4613 /*
4614 * first access of each leaf page
4615 */
4616 printf("leaf page ");
4617 dtDisplayPage(ip, bn, p);
4618
4619 /*
4620 * process leaf page entries
4621 *
4622 for ( ; index <= lastindex; index++)
4623 {
4624 }
4625 */
4626
4627 /* unpin the leaf page */
4628 DT_PUTPAGE(mp);
4629 }
4630
4631 /*
4632 * go back up to the parent page
4633 */
4634 getParent:
4635 /* pop/restore parent entry for the current child page */
4636 if ((parent = (btsp == btstack.stack ? NULL : --btsp)) == NULL)
4637 /* current page must have been root */
4638 return;
4639
4640 /*
4641 * parent page scan completed
4642 */
4643 if ((index = parent->index) == (lastindex = parent->lastindex)) {
4644 /* go back up to the parent page */
4645 goto getParent;
4646 }
4647
4648 /*
4649 * parent page has entries remaining
4650 */
4651 /* get back the parent page */
4652 bn = parent->bn;
4653 /* v = parent->level; */
4654 DT_GETPAGE(ip, bn, mp, PSIZE, p, rc);
4655 if (rc)
4656 return rc;
4657
4658 /* get next parent entry */
4659 index++;
4660
4661 /*
4662 * internal page: go down to child page of current entry
4663 */
4664 getChild:
4665 /* push/save current parent entry for the child page */
4666 btsp->bn = pbn = bn;
4667 btsp->index = index;
4668 btsp->lastindex = lastindex;
4669 /* btsp->level = v; */
4670 /* btsp->node = h; */
4671 ++btsp;
4672
4673 /* get current entry for the child page */
4674 stbl = DT_GETSTBL(p);
4675 xd = (pxd_t *) & p->slot[stbl[index]];
4676
4677 /*
4678 * first access of each internal entry:
4679 */
4680
4681 /* get child page */
4682 bn = addressPXD(xd);
4683 psize = lengthPXD(xd) << ip->i_ipmnt->i_l2bsize;
4684
4685 printk("traverse down 0x%Lx[%d]->0x%Lx\n", pbn, index, bn);
4686 v++;
4687 h = index;
4688
4689 /* release parent page */
4690 DT_PUTPAGE(mp);
4691
4692 /* process the child page */
4693 goto newPage;
4694}
4695
4696
4697/*
4698 * dtDisplayPage()
4699 *
4700 * function: display page
4701 */
4702int dtDisplayPage(struct inode *ip, s64 bn, dtpage_t * p)
4703{
4704 int rc;
4705 struct metapage *mp;
4706 struct ldtentry *lh;
4707 struct idtentry *ih;
4708 pxd_t *xd;
4709 int i, j;
4710 u8 *stbl;
4711 wchar_t name[JFS_NAME_MAX + 1];
4712 struct component_name key = { 0, name };
4713 int freepage = 0;
4714
4715 if (p == NULL) {
4716 freepage = 1;
4717 DT_GETPAGE(ip, bn, mp, PSIZE, p, rc);
4718 if (rc)
4719 return rc;
4720 }
4721
4722 /* display page control */
4723 printk("bn:0x%Lx flag:0x%08x nextindex:%d\n",
4724 bn, p->header.flag, p->header.nextindex);
4725
4726 /* display entries */
4727 stbl = DT_GETSTBL(p);
4728 for (i = 0, j = 1; i < p->header.nextindex; i++, j++) {
4729 dtGetKey(p, i, &key, JFS_SBI(ip->i_sb)->mntflag);
4730 key.name[key.namlen] = '\0';
4731 if (p->header.flag & BT_LEAF) {
4732 lh = (struct ldtentry *) & p->slot[stbl[i]];
4733 printf("\t[%d] %s:%d", i, key.name,
4734 le32_to_cpu(lh->inumber));
4735 } else {
4736 ih = (struct idtentry *) & p->slot[stbl[i]];
4737 xd = (pxd_t *) ih;
4738 bn = addressPXD(xd);
4739 printf("\t[%d] %s:0x%Lx", i, key.name, bn);
4740 }
4741
4742 if (j == 4) {
4743 printf("\n");
4744 j = 0;
4745 }
4746 }
4747
4748 printf("\n");
4749
4750 if (freepage)
4751 DT_PUTPAGE(mp);
4752
4753 return 0;
4754}
4755#endif /* _JFS_DEBUG_DTREE */
diff --git a/fs/jfs/jfs_dtree.h b/fs/jfs/jfs_dtree.h
index 273a80130c9d..13e4fdf07724 100644
--- a/fs/jfs/jfs_dtree.h
+++ b/fs/jfs/jfs_dtree.h
@@ -269,11 +269,4 @@ extern int dtModify(tid_t tid, struct inode *ip, struct component_name * key,
269 ino_t * orig_ino, ino_t new_ino, int flag); 269 ino_t * orig_ino, ino_t new_ino, int flag);
270 270
271extern int jfs_readdir(struct file *filp, void *dirent, filldir_t filldir); 271extern int jfs_readdir(struct file *filp, void *dirent, filldir_t filldir);
272
273#ifdef _JFS_DEBUG_DTREE
274extern int dtDisplayTree(struct inode *ip);
275
276extern int dtDisplayPage(struct inode *ip, s64 bn, dtpage_t * p);
277#endif /* _JFS_DEBUG_DTREE */
278
279#endif /* !_H_JFS_DTREE */ 272#endif /* !_H_JFS_DTREE */
diff --git a/fs/jfs/jfs_imap.c b/fs/jfs/jfs_imap.c
index 971af2977eff..4021d46da7e3 100644
--- a/fs/jfs/jfs_imap.c
+++ b/fs/jfs/jfs_imap.c
@@ -87,25 +87,6 @@ static int copy_from_dinode(struct dinode *, struct inode *);
87static void copy_to_dinode(struct dinode *, struct inode *); 87static void copy_to_dinode(struct dinode *, struct inode *);
88 88
89/* 89/*
90 * debug code for double-checking inode map
91 */
92/* #define _JFS_DEBUG_IMAP 1 */
93
94#ifdef _JFS_DEBUG_IMAP
95#define DBG_DIINIT(imap) DBGdiInit(imap)
96#define DBG_DIALLOC(imap, ino) DBGdiAlloc(imap, ino)
97#define DBG_DIFREE(imap, ino) DBGdiFree(imap, ino)
98
99static void *DBGdiInit(struct inomap * imap);
100static void DBGdiAlloc(struct inomap * imap, ino_t ino);
101static void DBGdiFree(struct inomap * imap, ino_t ino);
102#else
103#define DBG_DIINIT(imap)
104#define DBG_DIALLOC(imap, ino)
105#define DBG_DIFREE(imap, ino)
106#endif /* _JFS_DEBUG_IMAP */
107
108/*
109 * NAME: diMount() 90 * NAME: diMount()
110 * 91 *
111 * FUNCTION: initialize the incore inode map control structures for 92 * FUNCTION: initialize the incore inode map control structures for
@@ -188,8 +169,6 @@ int diMount(struct inode *ipimap)
188 imap->im_ipimap = ipimap; 169 imap->im_ipimap = ipimap;
189 JFS_IP(ipimap)->i_imap = imap; 170 JFS_IP(ipimap)->i_imap = imap;
190 171
191// DBG_DIINIT(imap);
192
193 return (0); 172 return (0);
194} 173}
195 174
@@ -1043,7 +1022,6 @@ int diFree(struct inode *ip)
1043 /* update the bitmap. 1022 /* update the bitmap.
1044 */ 1023 */
1045 iagp->wmap[extno] = cpu_to_le32(bitmap); 1024 iagp->wmap[extno] = cpu_to_le32(bitmap);
1046 DBG_DIFREE(imap, inum);
1047 1025
1048 /* update the free inode counts at the iag, ag and 1026 /* update the free inode counts at the iag, ag and
1049 * map level. 1027 * map level.
@@ -1231,7 +1209,6 @@ int diFree(struct inode *ip)
1231 jfs_error(ip->i_sb, "diFree: the pmap does not show inode free"); 1209 jfs_error(ip->i_sb, "diFree: the pmap does not show inode free");
1232 } 1210 }
1233 iagp->wmap[extno] = 0; 1211 iagp->wmap[extno] = 0;
1234 DBG_DIFREE(imap, inum);
1235 PXDlength(&iagp->inoext[extno], 0); 1212 PXDlength(&iagp->inoext[extno], 0);
1236 PXDaddress(&iagp->inoext[extno], 0); 1213 PXDaddress(&iagp->inoext[extno], 0);
1237 1214
@@ -1350,7 +1327,6 @@ diInitInode(struct inode *ip, int iagno, int ino, int extno, struct iag * iagp)
1350 struct jfs_inode_info *jfs_ip = JFS_IP(ip); 1327 struct jfs_inode_info *jfs_ip = JFS_IP(ip);
1351 1328
1352 ip->i_ino = (iagno << L2INOSPERIAG) + ino; 1329 ip->i_ino = (iagno << L2INOSPERIAG) + ino;
1353 DBG_DIALLOC(JFS_IP(ipimap)->i_imap, ip->i_ino);
1354 jfs_ip->ixpxd = iagp->inoext[extno]; 1330 jfs_ip->ixpxd = iagp->inoext[extno];
1355 jfs_ip->agno = BLKTOAG(le64_to_cpu(iagp->agstart), sbi); 1331 jfs_ip->agno = BLKTOAG(le64_to_cpu(iagp->agstart), sbi);
1356 jfs_ip->active_ag = -1; 1332 jfs_ip->active_ag = -1;
@@ -3185,84 +3161,3 @@ static void copy_to_dinode(struct dinode * dip, struct inode *ip)
3185 if (S_ISCHR(ip->i_mode) || S_ISBLK(ip->i_mode)) 3161 if (S_ISCHR(ip->i_mode) || S_ISBLK(ip->i_mode))
3186 dip->di_rdev = cpu_to_le32(jfs_ip->dev); 3162 dip->di_rdev = cpu_to_le32(jfs_ip->dev);
3187} 3163}
3188
3189#ifdef _JFS_DEBUG_IMAP
3190/*
3191 * DBGdiInit()
3192 */
3193static void *DBGdiInit(struct inomap * imap)
3194{
3195 u32 *dimap;
3196 int size;
3197 size = 64 * 1024;
3198 if ((dimap = (u32 *) xmalloc(size, L2PSIZE, kernel_heap)) == NULL)
3199 assert(0);
3200 bzero((void *) dimap, size);
3201 imap->im_DBGdimap = dimap;
3202}
3203
3204/*
3205 * DBGdiAlloc()
3206 */
3207static void DBGdiAlloc(struct inomap * imap, ino_t ino)
3208{
3209 u32 *dimap = imap->im_DBGdimap;
3210 int w, b;
3211 u32 m;
3212 w = ino >> 5;
3213 b = ino & 31;
3214 m = 0x80000000 >> b;
3215 assert(w < 64 * 256);
3216 if (dimap[w] & m) {
3217 printk("DEBUG diAlloc: duplicate alloc ino:0x%x\n", ino);
3218 }
3219 dimap[w] |= m;
3220}
3221
3222/*
3223 * DBGdiFree()
3224 */
3225static void DBGdiFree(struct inomap * imap, ino_t ino)
3226{
3227 u32 *dimap = imap->im_DBGdimap;
3228 int w, b;
3229 u32 m;
3230 w = ino >> 5;
3231 b = ino & 31;
3232 m = 0x80000000 >> b;
3233 assert(w < 64 * 256);
3234 if ((dimap[w] & m) == 0) {
3235 printk("DEBUG diFree: duplicate free ino:0x%x\n", ino);
3236 }
3237 dimap[w] &= ~m;
3238}
3239
3240static void dump_cp(struct inomap * ipimap, char *function, int line)
3241{
3242 printk("\n* ********* *\nControl Page %s %d\n", function, line);
3243 printk("FreeIAG %d\tNextIAG %d\n", ipimap->im_freeiag,
3244 ipimap->im_nextiag);
3245 printk("NumInos %d\tNumFree %d\n",
3246 atomic_read(&ipimap->im_numinos),
3247 atomic_read(&ipimap->im_numfree));
3248 printk("AG InoFree %d\tAG ExtFree %d\n",
3249 ipimap->im_agctl[0].inofree, ipimap->im_agctl[0].extfree);
3250 printk("AG NumInos %d\tAG NumFree %d\n",
3251 ipimap->im_agctl[0].numinos, ipimap->im_agctl[0].numfree);
3252}
3253
3254static void dump_iag(struct iag * iag, char *function, int line)
3255{
3256 printk("\n* ********* *\nIAG %s %d\n", function, line);
3257 printk("IagNum %d\tIAG Free %d\n", le32_to_cpu(iag->iagnum),
3258 le32_to_cpu(iag->iagfree));
3259 printk("InoFreeFwd %d\tInoFreeBack %d\n",
3260 le32_to_cpu(iag->inofreefwd),
3261 le32_to_cpu(iag->inofreeback));
3262 printk("ExtFreeFwd %d\tExtFreeBack %d\n",
3263 le32_to_cpu(iag->extfreefwd),
3264 le32_to_cpu(iag->extfreeback));
3265 printk("NFreeInos %d\tNFreeExts %d\n", le32_to_cpu(iag->nfreeinos),
3266 le32_to_cpu(iag->nfreeexts));
3267}
3268#endif /* _JFS_DEBUG_IMAP */
diff --git a/fs/jfs/jfs_unicode.c b/fs/jfs/jfs_unicode.c
index b32208aad550..f327decfb155 100644
--- a/fs/jfs/jfs_unicode.c
+++ b/fs/jfs/jfs_unicode.c
@@ -51,8 +51,9 @@ int jfs_strfromUCS_le(char *to, const __le16 * from,
51 } 51 }
52 } else { 52 } else {
53 for (i = 0; (i < len) && from[i]; i++) { 53 for (i = 0; (i < len) && from[i]; i++) {
54 if (le16_to_cpu(from[i]) & 0xff00) { 54 if (unlikely(le16_to_cpu(from[i]) & 0xff00)) {
55 if (warn) { 55 to[i] = '?';
56 if (unlikely(warn)) {
56 warn--; 57 warn--;
57 warn_again--; 58 warn_again--;
58 printk(KERN_ERR 59 printk(KERN_ERR
@@ -61,7 +62,7 @@ int jfs_strfromUCS_le(char *to, const __le16 * from,
61 printk(KERN_ERR 62 printk(KERN_ERR
62 "mount with iocharset=utf8 to access\n"); 63 "mount with iocharset=utf8 to access\n");
63 } 64 }
64 to[i] = '?'; 65
65 } 66 }
66 else 67 else
67 to[i] = (char) (le16_to_cpu(from[i])); 68 to[i] = (char) (le16_to_cpu(from[i]));
diff --git a/fs/jfs/jfs_xtree.c b/fs/jfs/jfs_xtree.c
index 31b34db4519e..a7fe2f2b969f 100644
--- a/fs/jfs/jfs_xtree.c
+++ b/fs/jfs/jfs_xtree.c
@@ -135,14 +135,6 @@ static int xtSearchNode(struct inode *ip,
135static int xtRelink(tid_t tid, struct inode *ip, xtpage_t * fp); 135static int xtRelink(tid_t tid, struct inode *ip, xtpage_t * fp);
136#endif /* _STILL_TO_PORT */ 136#endif /* _STILL_TO_PORT */
137 137
138/* External references */
139
140/*
141 * debug control
142 */
143/* #define _JFS_DEBUG_XTREE 1 */
144
145
146/* 138/*
147 * xtLookup() 139 * xtLookup()
148 * 140 *
@@ -4140,338 +4132,6 @@ s64 xtTruncate_pmap(tid_t tid, struct inode *ip, s64 committed_size)
4140 return 0; 4132 return 0;
4141} 4133}
4142 4134
4143
4144#ifdef _JFS_DEBUG_XTREE
4145/*
4146 * xtDisplayTree()
4147 *
4148 * function: traverse forward
4149 */
4150int xtDisplayTree(struct inode *ip)
4151{
4152 int rc = 0;
4153 struct metapage *mp;
4154 xtpage_t *p;
4155 s64 bn, pbn;
4156 int index, lastindex, v, h;
4157 xad_t *xad;
4158 struct btstack btstack;
4159 struct btframe *btsp;
4160 struct btframe *parent;
4161
4162 printk("display B+-tree.\n");
4163
4164 /* clear stack */
4165 btsp = btstack.stack;
4166
4167 /*
4168 * start with root
4169 *
4170 * root resides in the inode
4171 */
4172 bn = 0;
4173 v = h = 0;
4174
4175 /*
4176 * first access of each page:
4177 */
4178 getPage:
4179 XT_GETPAGE(ip, bn, mp, PSIZE, p, rc);
4180 if (rc)
4181 return rc;
4182
4183 /* process entries forward from first index */
4184 index = XTENTRYSTART;
4185 lastindex = le16_to_cpu(p->header.nextindex) - 1;
4186
4187 if (p->header.flag & BT_INTERNAL) {
4188 /*
4189 * first access of each internal page
4190 */
4191 goto getChild;
4192 } else { /* (p->header.flag & BT_LEAF) */
4193
4194 /*
4195 * first access of each leaf page
4196 */
4197 printf("leaf page ");
4198 xtDisplayPage(ip, bn, p);
4199
4200 /* unpin the leaf page */
4201 XT_PUTPAGE(mp);
4202 }
4203
4204 /*
4205 * go back up to the parent page
4206 */
4207 getParent:
4208 /* pop/restore parent entry for the current child page */
4209 if ((parent = (btsp == btstack.stack ? NULL : --btsp)) == NULL)
4210 /* current page must have been root */
4211 return;
4212
4213 /*
4214 * parent page scan completed
4215 */
4216 if ((index = parent->index) == (lastindex = parent->lastindex)) {
4217 /* go back up to the parent page */
4218 goto getParent;
4219 }
4220
4221 /*
4222 * parent page has entries remaining
4223 */
4224 /* get back the parent page */
4225 bn = parent->bn;
4226 /* v = parent->level; */
4227 XT_GETPAGE(ip, bn, mp, PSIZE, p, rc);
4228 if (rc)
4229 return rc;
4230
4231 /* get next parent entry */
4232 index++;
4233
4234 /*
4235 * internal page: go down to child page of current entry
4236 */
4237 getChild:
4238 /* push/save current parent entry for the child page */
4239 btsp->bn = pbn = bn;
4240 btsp->index = index;
4241 btsp->lastindex = lastindex;
4242 /* btsp->level = v; */
4243 /* btsp->node = h; */
4244 ++btsp;
4245
4246 /* get child page */
4247 xad = &p->xad[index];
4248 bn = addressXAD(xad);
4249
4250 /*
4251 * first access of each internal entry:
4252 */
4253 /* release parent page */
4254 XT_PUTPAGE(mp);
4255
4256 printk("traverse down 0x%lx[%d]->0x%lx\n", (ulong) pbn, index,
4257 (ulong) bn);
4258 v++;
4259 h = index;
4260
4261 /* process the child page */
4262 goto getPage;
4263}
4264
4265
4266/*
4267 * xtDisplayPage()
4268 *
4269 * function: display page
4270 */
4271int xtDisplayPage(struct inode *ip, s64 bn, xtpage_t * p)
4272{
4273 int rc = 0;
4274 xad_t *xad;
4275 s64 xaddr, xoff;
4276 int xlen, i, j;
4277
4278 /* display page control */
4279 printf("bn:0x%lx flag:0x%x nextindex:%d\n",
4280 (ulong) bn, p->header.flag,
4281 le16_to_cpu(p->header.nextindex));
4282
4283 /* display entries */
4284 xad = &p->xad[XTENTRYSTART];
4285 for (i = XTENTRYSTART, j = 1; i < le16_to_cpu(p->header.nextindex);
4286 i++, xad++, j++) {
4287 xoff = offsetXAD(xad);
4288 xaddr = addressXAD(xad);
4289 xlen = lengthXAD(xad);
4290 printf("\t[%d] 0x%lx:0x%lx(0x%x)", i, (ulong) xoff,
4291 (ulong) xaddr, xlen);
4292
4293 if (j == 4) {
4294 printf("\n");
4295 j = 0;
4296 }
4297 }
4298
4299 printf("\n");
4300}
4301#endif /* _JFS_DEBUG_XTREE */
4302
4303
4304#ifdef _JFS_WIP
4305/*
4306 * xtGather()
4307 *
4308 * function:
4309 * traverse for allocation acquiring tlock at commit time
4310 * (vs at the time of update) logging backward top down
4311 *
4312 * note:
4313 * problem - establishing that all new allocation have been
4314 * processed both for append and random write in sparse file
4315 * at the current entry at the current subtree root page
4316 *
4317 */
4318int xtGather(btree_t *t)
4319{
4320 int rc = 0;
4321 xtpage_t *p;
4322 u64 bn;
4323 int index;
4324 btentry_t *e;
4325 struct btstack btstack;
4326 struct btsf *parent;
4327
4328 /* clear stack */
4329 BT_CLR(&btstack);
4330
4331 /*
4332 * start with root
4333 *
4334 * root resides in the inode
4335 */
4336 bn = 0;
4337 XT_GETPAGE(ip, bn, mp, PSIZE, p, rc);
4338 if (rc)
4339 return rc;
4340
4341 /* new root is NOT pointed by a new entry
4342 if (p->header.flag & NEW)
4343 allocate new page lock;
4344 write a NEWPAGE log;
4345 */
4346
4347 dopage:
4348 /*
4349 * first access of each page:
4350 */
4351 /* process entries backward from last index */
4352 index = le16_to_cpu(p->header.nextindex) - 1;
4353
4354 if (p->header.flag & BT_LEAF) {
4355 /*
4356 * first access of each leaf page
4357 */
4358 /* process leaf page entries backward */
4359 for (; index >= XTENTRYSTART; index--) {
4360 e = &p->xad[index];
4361 /*
4362 * if newpage, log NEWPAGE.
4363 *
4364 if (e->flag & XAD_NEW) {
4365 nfound =+ entry->length;
4366 update current page lock for the entry;
4367 newpage(entry);
4368 *
4369 * if moved, log move.
4370 *
4371 } else if (e->flag & XAD_MOVED) {
4372 reset flag;
4373 update current page lock for the entry;
4374 }
4375 */
4376 }
4377
4378 /* unpin the leaf page */
4379 XT_PUTPAGE(mp);
4380
4381 /*
4382 * go back up to the parent page
4383 */
4384 getParent:
4385 /* restore parent entry for the current child page */
4386 if ((parent = BT_POP(&btstack)) == NULL)
4387 /* current page must have been root */
4388 return 0;
4389
4390 if ((index = parent->index) == XTENTRYSTART) {
4391 /*
4392 * parent page scan completed
4393 */
4394 /* go back up to the parent page */
4395 goto getParent;
4396 } else {
4397 /*
4398 * parent page has entries remaining
4399 */
4400 /* get back the parent page */
4401 bn = parent->bn;
4402 XT_GETPAGE(ip, bn, mp, PSIZE, p, rc);
4403 if (rc)
4404 return -EIO;
4405
4406 /* first subroot page which
4407 * covers all new allocated blocks
4408 * itself not new/modified.
4409 * (if modified from split of descendent,
4410 * go down path of split page)
4411
4412 if (nfound == nnew &&
4413 !(p->header.flag & (NEW | MOD)))
4414 exit scan;
4415 */
4416
4417 /* process parent page entries backward */
4418 index--;
4419 }
4420 } else {
4421 /*
4422 * first access of each internal page
4423 */
4424 }
4425
4426 /*
4427 * internal page: go down to child page of current entry
4428 */
4429
4430 /* save current parent entry for the child page */
4431 BT_PUSH(&btstack, bn, index);
4432
4433 /* get current entry for the child page */
4434 e = &p->xad[index];
4435
4436 /*
4437 * first access of each internal entry:
4438 */
4439 /*
4440 * if new entry, log btree_tnewentry.
4441 *
4442 if (e->flag & XAD_NEW)
4443 update parent page lock for the entry;
4444 */
4445
4446 /* release parent page */
4447 XT_PUTPAGE(mp);
4448
4449 /* get child page */
4450 bn = e->bn;
4451 XT_GETPAGE(ip, bn, mp, PSIZE, p, rc);
4452 if (rc)
4453 return rc;
4454
4455 /*
4456 * first access of each non-root page:
4457 */
4458 /*
4459 * if new, log btree_newpage.
4460 *
4461 if (p->header.flag & NEW)
4462 allocate new page lock;
4463 write a NEWPAGE log (next, prev);
4464 */
4465
4466 /* process the child page */
4467 goto dopage;
4468
4469 out:
4470 return 0;
4471}
4472#endif /* _JFS_WIP */
4473
4474
4475#ifdef CONFIG_JFS_STATISTICS 4135#ifdef CONFIG_JFS_STATISTICS
4476int jfs_xtstat_read(char *buffer, char **start, off_t offset, int length, 4136int jfs_xtstat_read(char *buffer, char **start, off_t offset, int length,
4477 int *eof, void *data) 4137 int *eof, void *data)
diff --git a/fs/jfs/jfs_xtree.h b/fs/jfs/jfs_xtree.h
index a69784254fe7..af668a80b40f 100644
--- a/fs/jfs/jfs_xtree.h
+++ b/fs/jfs/jfs_xtree.h
@@ -131,10 +131,4 @@ extern int xtRelocate(tid_t tid, struct inode *ip,
131extern int xtAppend(tid_t tid, 131extern int xtAppend(tid_t tid,
132 struct inode *ip, int xflag, s64 xoff, int maxblocks, 132 struct inode *ip, int xflag, s64 xoff, int maxblocks,
133 int *xlenp, s64 * xaddrp, int flag); 133 int *xlenp, s64 * xaddrp, int flag);
134
135#ifdef _JFS_DEBUG_XTREE
136extern int xtDisplayTree(struct inode *ip);
137extern int xtDisplayPage(struct inode *ip, s64 bn, xtpage_t * p);
138#endif /* _JFS_DEBUG_XTREE */
139
140#endif /* !_H_JFS_XTREE */ 134#endif /* !_H_JFS_XTREE */
diff --git a/fs/jfs/xattr.c b/fs/jfs/xattr.c
index ee438d429d45..554ec739e49b 100644
--- a/fs/jfs/xattr.c
+++ b/fs/jfs/xattr.c
@@ -781,7 +781,7 @@ static int can_set_xattr(struct inode *inode, const char *name,
781 if (IS_RDONLY(inode)) 781 if (IS_RDONLY(inode))
782 return -EROFS; 782 return -EROFS;
783 783
784 if (IS_IMMUTABLE(inode) || IS_APPEND(inode) || S_ISLNK(inode->i_mode)) 784 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
785 return -EPERM; 785 return -EPERM;
786 786
787 if(strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN) == 0) 787 if(strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN) == 0)
@@ -790,12 +790,12 @@ static int can_set_xattr(struct inode *inode, const char *name,
790 */ 790 */
791 return can_set_system_xattr(inode, name, value, value_len); 791 return can_set_system_xattr(inode, name, value, value_len);
792 792
793 if(strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) != 0) 793 if(strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) == 0)
794 return (capable(CAP_SYS_ADMIN) ? 0 : -EPERM); 794 return (capable(CAP_SYS_ADMIN) ? 0 : -EPERM);
795 795
796#ifdef CONFIG_JFS_SECURITY 796#ifdef CONFIG_JFS_SECURITY
797 if (strncmp(name, XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN) 797 if (strncmp(name, XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN)
798 != 0) 798 == 0)
799 return 0; /* Leave it to the security module */ 799 return 0; /* Leave it to the security module */
800#endif 800#endif
801 801
diff --git a/fs/namei.c b/fs/namei.c
index 1d93cb4f7c5f..02a824cd3c5c 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -21,7 +21,7 @@
21#include <linux/namei.h> 21#include <linux/namei.h>
22#include <linux/quotaops.h> 22#include <linux/quotaops.h>
23#include <linux/pagemap.h> 23#include <linux/pagemap.h>
24#include <linux/dnotify.h> 24#include <linux/fsnotify.h>
25#include <linux/smp_lock.h> 25#include <linux/smp_lock.h>
26#include <linux/personality.h> 26#include <linux/personality.h>
27#include <linux/security.h> 27#include <linux/security.h>
@@ -1312,7 +1312,7 @@ int vfs_create(struct inode *dir, struct dentry *dentry, int mode,
1312 DQUOT_INIT(dir); 1312 DQUOT_INIT(dir);
1313 error = dir->i_op->create(dir, dentry, mode, nd); 1313 error = dir->i_op->create(dir, dentry, mode, nd);
1314 if (!error) { 1314 if (!error) {
1315 inode_dir_notify(dir, DN_CREATE); 1315 fsnotify_create(dir, dentry->d_name.name);
1316 security_inode_post_create(dir, dentry, mode); 1316 security_inode_post_create(dir, dentry, mode);
1317 } 1317 }
1318 return error; 1318 return error;
@@ -1637,7 +1637,7 @@ int vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
1637 DQUOT_INIT(dir); 1637 DQUOT_INIT(dir);
1638 error = dir->i_op->mknod(dir, dentry, mode, dev); 1638 error = dir->i_op->mknod(dir, dentry, mode, dev);
1639 if (!error) { 1639 if (!error) {
1640 inode_dir_notify(dir, DN_CREATE); 1640 fsnotify_create(dir, dentry->d_name.name);
1641 security_inode_post_mknod(dir, dentry, mode, dev); 1641 security_inode_post_mknod(dir, dentry, mode, dev);
1642 } 1642 }
1643 return error; 1643 return error;
@@ -1710,7 +1710,7 @@ int vfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
1710 DQUOT_INIT(dir); 1710 DQUOT_INIT(dir);
1711 error = dir->i_op->mkdir(dir, dentry, mode); 1711 error = dir->i_op->mkdir(dir, dentry, mode);
1712 if (!error) { 1712 if (!error) {
1713 inode_dir_notify(dir, DN_CREATE); 1713 fsnotify_mkdir(dir, dentry->d_name.name);
1714 security_inode_post_mkdir(dir,dentry, mode); 1714 security_inode_post_mkdir(dir,dentry, mode);
1715 } 1715 }
1716 return error; 1716 return error;
@@ -1801,7 +1801,7 @@ int vfs_rmdir(struct inode *dir, struct dentry *dentry)
1801 } 1801 }
1802 up(&dentry->d_inode->i_sem); 1802 up(&dentry->d_inode->i_sem);
1803 if (!error) { 1803 if (!error) {
1804 inode_dir_notify(dir, DN_DELETE); 1804 fsnotify_rmdir(dentry, dentry->d_inode, dir);
1805 d_delete(dentry); 1805 d_delete(dentry);
1806 } 1806 }
1807 dput(dentry); 1807 dput(dentry);
@@ -1874,9 +1874,10 @@ int vfs_unlink(struct inode *dir, struct dentry *dentry)
1874 1874
1875 /* We don't d_delete() NFS sillyrenamed files--they still exist. */ 1875 /* We don't d_delete() NFS sillyrenamed files--they still exist. */
1876 if (!error && !(dentry->d_flags & DCACHE_NFSFS_RENAMED)) { 1876 if (!error && !(dentry->d_flags & DCACHE_NFSFS_RENAMED)) {
1877 fsnotify_unlink(dentry, dir);
1877 d_delete(dentry); 1878 d_delete(dentry);
1878 inode_dir_notify(dir, DN_DELETE);
1879 } 1879 }
1880
1880 return error; 1881 return error;
1881} 1882}
1882 1883
@@ -1950,7 +1951,7 @@ int vfs_symlink(struct inode *dir, struct dentry *dentry, const char *oldname, i
1950 DQUOT_INIT(dir); 1951 DQUOT_INIT(dir);
1951 error = dir->i_op->symlink(dir, dentry, oldname); 1952 error = dir->i_op->symlink(dir, dentry, oldname);
1952 if (!error) { 1953 if (!error) {
1953 inode_dir_notify(dir, DN_CREATE); 1954 fsnotify_create(dir, dentry->d_name.name);
1954 security_inode_post_symlink(dir, dentry, oldname); 1955 security_inode_post_symlink(dir, dentry, oldname);
1955 } 1956 }
1956 return error; 1957 return error;
@@ -2023,7 +2024,7 @@ int vfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_de
2023 error = dir->i_op->link(old_dentry, dir, new_dentry); 2024 error = dir->i_op->link(old_dentry, dir, new_dentry);
2024 up(&old_dentry->d_inode->i_sem); 2025 up(&old_dentry->d_inode->i_sem);
2025 if (!error) { 2026 if (!error) {
2026 inode_dir_notify(dir, DN_CREATE); 2027 fsnotify_create(dir, new_dentry->d_name.name);
2027 security_inode_post_link(old_dentry, dir, new_dentry); 2028 security_inode_post_link(old_dentry, dir, new_dentry);
2028 } 2029 }
2029 return error; 2030 return error;
@@ -2187,6 +2188,7 @@ int vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
2187{ 2188{
2188 int error; 2189 int error;
2189 int is_dir = S_ISDIR(old_dentry->d_inode->i_mode); 2190 int is_dir = S_ISDIR(old_dentry->d_inode->i_mode);
2191 const char *old_name;
2190 2192
2191 if (old_dentry->d_inode == new_dentry->d_inode) 2193 if (old_dentry->d_inode == new_dentry->d_inode)
2192 return 0; 2194 return 0;
@@ -2208,18 +2210,18 @@ int vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
2208 DQUOT_INIT(old_dir); 2210 DQUOT_INIT(old_dir);
2209 DQUOT_INIT(new_dir); 2211 DQUOT_INIT(new_dir);
2210 2212
2213 old_name = fsnotify_oldname_init(old_dentry->d_name.name);
2214
2211 if (is_dir) 2215 if (is_dir)
2212 error = vfs_rename_dir(old_dir,old_dentry,new_dir,new_dentry); 2216 error = vfs_rename_dir(old_dir,old_dentry,new_dir,new_dentry);
2213 else 2217 else
2214 error = vfs_rename_other(old_dir,old_dentry,new_dir,new_dentry); 2218 error = vfs_rename_other(old_dir,old_dentry,new_dir,new_dentry);
2215 if (!error) { 2219 if (!error) {
2216 if (old_dir == new_dir) 2220 const char *new_name = old_dentry->d_name.name;
2217 inode_dir_notify(old_dir, DN_RENAME); 2221 fsnotify_move(old_dir, new_dir, old_name, new_name, is_dir);
2218 else {
2219 inode_dir_notify(old_dir, DN_DELETE);
2220 inode_dir_notify(new_dir, DN_CREATE);
2221 }
2222 } 2222 }
2223 fsnotify_oldname_free(old_name);
2224
2223 return error; 2225 return error;
2224} 2226}
2225 2227
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index 5e0bf3917607..4f2cd3d27566 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -45,7 +45,7 @@
45#endif /* CONFIG_NFSD_V3 */ 45#endif /* CONFIG_NFSD_V3 */
46#include <linux/nfsd/nfsfh.h> 46#include <linux/nfsd/nfsfh.h>
47#include <linux/quotaops.h> 47#include <linux/quotaops.h>
48#include <linux/dnotify.h> 48#include <linux/fsnotify.h>
49#include <linux/posix_acl.h> 49#include <linux/posix_acl.h>
50#include <linux/posix_acl_xattr.h> 50#include <linux/posix_acl_xattr.h>
51#ifdef CONFIG_NFSD_V4 51#ifdef CONFIG_NFSD_V4
@@ -860,7 +860,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
860 nfsdstats.io_read += err; 860 nfsdstats.io_read += err;
861 *count = err; 861 *count = err;
862 err = 0; 862 err = 0;
863 dnotify_parent(file->f_dentry, DN_ACCESS); 863 fsnotify_access(file->f_dentry);
864 } else 864 } else
865 err = nfserrno(err); 865 err = nfserrno(err);
866out: 866out:
@@ -916,7 +916,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
916 set_fs(oldfs); 916 set_fs(oldfs);
917 if (err >= 0) { 917 if (err >= 0) {
918 nfsdstats.io_write += cnt; 918 nfsdstats.io_write += cnt;
919 dnotify_parent(file->f_dentry, DN_MODIFY); 919 fsnotify_modify(file->f_dentry);
920 } 920 }
921 921
922 /* clear setuid/setgid flag after write */ 922 /* clear setuid/setgid flag after write */
diff --git a/fs/open.c b/fs/open.c
index 3f4a4286fdc4..32bf05e2996d 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -10,7 +10,7 @@
10#include <linux/file.h> 10#include <linux/file.h>
11#include <linux/smp_lock.h> 11#include <linux/smp_lock.h>
12#include <linux/quotaops.h> 12#include <linux/quotaops.h>
13#include <linux/dnotify.h> 13#include <linux/fsnotify.h>
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/tty.h> 16#include <linux/tty.h>
@@ -951,6 +951,7 @@ asmlinkage long sys_open(const char __user * filename, int flags, int mode)
951 put_unused_fd(fd); 951 put_unused_fd(fd);
952 fd = PTR_ERR(f); 952 fd = PTR_ERR(f);
953 } else { 953 } else {
954 fsnotify_open(f->f_dentry);
954 fd_install(fd, f); 955 fd_install(fd, f);
955 } 956 }
956 } 957 }
diff --git a/fs/read_write.c b/fs/read_write.c
index 9292f5fa4d62..563abd09b5c8 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -10,7 +10,7 @@
10#include <linux/file.h> 10#include <linux/file.h>
11#include <linux/uio.h> 11#include <linux/uio.h>
12#include <linux/smp_lock.h> 12#include <linux/smp_lock.h>
13#include <linux/dnotify.h> 13#include <linux/fsnotify.h>
14#include <linux/security.h> 14#include <linux/security.h>
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/syscalls.h> 16#include <linux/syscalls.h>
@@ -252,7 +252,7 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
252 else 252 else
253 ret = do_sync_read(file, buf, count, pos); 253 ret = do_sync_read(file, buf, count, pos);
254 if (ret > 0) { 254 if (ret > 0) {
255 dnotify_parent(file->f_dentry, DN_ACCESS); 255 fsnotify_access(file->f_dentry);
256 current->rchar += ret; 256 current->rchar += ret;
257 } 257 }
258 current->syscr++; 258 current->syscr++;
@@ -303,7 +303,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
303 else 303 else
304 ret = do_sync_write(file, buf, count, pos); 304 ret = do_sync_write(file, buf, count, pos);
305 if (ret > 0) { 305 if (ret > 0) {
306 dnotify_parent(file->f_dentry, DN_MODIFY); 306 fsnotify_modify(file->f_dentry);
307 current->wchar += ret; 307 current->wchar += ret;
308 } 308 }
309 current->syscw++; 309 current->syscw++;
@@ -539,9 +539,12 @@ static ssize_t do_readv_writev(int type, struct file *file,
539out: 539out:
540 if (iov != iovstack) 540 if (iov != iovstack)
541 kfree(iov); 541 kfree(iov);
542 if ((ret + (type == READ)) > 0) 542 if ((ret + (type == READ)) > 0) {
543 dnotify_parent(file->f_dentry, 543 if (type == READ)
544 (type == READ) ? DN_ACCESS : DN_MODIFY); 544 fsnotify_access(file->f_dentry);
545 else
546 fsnotify_modify(file->f_dentry);
547 }
545 return ret; 548 return ret;
546Efault: 549Efault:
547 ret = -EFAULT; 550 ret = -EFAULT;
diff --git a/fs/reiserfs/bitmap.c b/fs/reiserfs/bitmap.c
index 49c479c9454a..909f71e9a30f 100644
--- a/fs/reiserfs/bitmap.c
+++ b/fs/reiserfs/bitmap.c
@@ -46,1125 +46,1221 @@
46#define TEST_OPTION(optname, s) \ 46#define TEST_OPTION(optname, s) \
47 test_bit(_ALLOC_ ## optname , &SB_ALLOC_OPTS(s)) 47 test_bit(_ALLOC_ ## optname , &SB_ALLOC_OPTS(s))
48 48
49static inline void get_bit_address (struct super_block * s, 49static inline void get_bit_address(struct super_block *s,
50 b_blocknr_t block, int * bmap_nr, int * offset) 50 b_blocknr_t block, int *bmap_nr, int *offset)
51{ 51{
52 /* It is in the bitmap block number equal to the block 52 /* It is in the bitmap block number equal to the block
53 * number divided by the number of bits in a block. */ 53 * number divided by the number of bits in a block. */
54 *bmap_nr = block / (s->s_blocksize << 3); 54 *bmap_nr = block / (s->s_blocksize << 3);
55 /* Within that bitmap block it is located at bit offset *offset. */ 55 /* Within that bitmap block it is located at bit offset *offset. */
56 *offset = block & ((s->s_blocksize << 3) - 1 ); 56 *offset = block & ((s->s_blocksize << 3) - 1);
57 return; 57 return;
58} 58}
59 59
60#ifdef CONFIG_REISERFS_CHECK 60#ifdef CONFIG_REISERFS_CHECK
61int is_reusable (struct super_block * s, b_blocknr_t block, int bit_value) 61int is_reusable(struct super_block *s, b_blocknr_t block, int bit_value)
62{ 62{
63 int i, j; 63 int i, j;
64 64
65 if (block == 0 || block >= SB_BLOCK_COUNT (s)) { 65 if (block == 0 || block >= SB_BLOCK_COUNT(s)) {
66 reiserfs_warning (s, "vs-4010: is_reusable: block number is out of range %lu (%u)", 66 reiserfs_warning(s,
67 block, SB_BLOCK_COUNT (s)); 67 "vs-4010: is_reusable: block number is out of range %lu (%u)",
68 return 0; 68 block, SB_BLOCK_COUNT(s));
69 } 69 return 0;
70
71 /* it can't be one of the bitmap blocks */
72 for (i = 0; i < SB_BMAP_NR (s); i ++)
73 if (block == SB_AP_BITMAP (s)[i].bh->b_blocknr) {
74 reiserfs_warning (s, "vs: 4020: is_reusable: "
75 "bitmap block %lu(%u) can't be freed or reused",
76 block, SB_BMAP_NR (s));
77 return 0;
78 } 70 }
79
80 get_bit_address (s, block, &i, &j);
81 71
82 if (i >= SB_BMAP_NR (s)) { 72 /* it can't be one of the bitmap blocks */
83 reiserfs_warning (s, "vs-4030: is_reusable: there is no so many bitmap blocks: " 73 for (i = 0; i < SB_BMAP_NR(s); i++)
84 "block=%lu, bitmap_nr=%d", block, i); 74 if (block == SB_AP_BITMAP(s)[i].bh->b_blocknr) {
85 return 0; 75 reiserfs_warning(s, "vs: 4020: is_reusable: "
86 } 76 "bitmap block %lu(%u) can't be freed or reused",
77 block, SB_BMAP_NR(s));
78 return 0;
79 }
87 80
88 if ((bit_value == 0 && 81 get_bit_address(s, block, &i, &j);
89 reiserfs_test_le_bit(j, SB_AP_BITMAP(s)[i].bh->b_data)) ||
90 (bit_value == 1 &&
91 reiserfs_test_le_bit(j, SB_AP_BITMAP (s)[i].bh->b_data) == 0)) {
92 reiserfs_warning (s, "vs-4040: is_reusable: corresponding bit of block %lu does not "
93 "match required value (i==%d, j==%d) test_bit==%d",
94 block, i, j, reiserfs_test_le_bit (j, SB_AP_BITMAP (s)[i].bh->b_data));
95 82
96 return 0; 83 if (i >= SB_BMAP_NR(s)) {
97 } 84 reiserfs_warning(s,
85 "vs-4030: is_reusable: there is no so many bitmap blocks: "
86 "block=%lu, bitmap_nr=%d", block, i);
87 return 0;
88 }
98 89
99 if (bit_value == 0 && block == SB_ROOT_BLOCK (s)) { 90 if ((bit_value == 0 &&
100 reiserfs_warning (s, "vs-4050: is_reusable: this is root block (%u), " 91 reiserfs_test_le_bit(j, SB_AP_BITMAP(s)[i].bh->b_data)) ||
101 "it must be busy", SB_ROOT_BLOCK (s)); 92 (bit_value == 1 &&
102 return 0; 93 reiserfs_test_le_bit(j, SB_AP_BITMAP(s)[i].bh->b_data) == 0)) {
103 } 94 reiserfs_warning(s,
95 "vs-4040: is_reusable: corresponding bit of block %lu does not "
96 "match required value (i==%d, j==%d) test_bit==%d",
97 block, i, j, reiserfs_test_le_bit(j,
98 SB_AP_BITMAP
99 (s)[i].bh->
100 b_data));
101
102 return 0;
103 }
104 104
105 return 1; 105 if (bit_value == 0 && block == SB_ROOT_BLOCK(s)) {
106 reiserfs_warning(s,
107 "vs-4050: is_reusable: this is root block (%u), "
108 "it must be busy", SB_ROOT_BLOCK(s));
109 return 0;
110 }
111
112 return 1;
106} 113}
107#endif /* CONFIG_REISERFS_CHECK */ 114#endif /* CONFIG_REISERFS_CHECK */
108 115
109/* searches in journal structures for a given block number (bmap, off). If block 116/* searches in journal structures for a given block number (bmap, off). If block
110 is found in reiserfs journal it suggests next free block candidate to test. */ 117 is found in reiserfs journal it suggests next free block candidate to test. */
111static inline int is_block_in_journal (struct super_block * s, int bmap, int 118static inline int is_block_in_journal(struct super_block *s, int bmap, int
112off, int *next) 119 off, int *next)
113{ 120{
114 b_blocknr_t tmp; 121 b_blocknr_t tmp;
115 122
116 if (reiserfs_in_journal (s, bmap, off, 1, &tmp)) { 123 if (reiserfs_in_journal(s, bmap, off, 1, &tmp)) {
117 if (tmp) { /* hint supplied */ 124 if (tmp) { /* hint supplied */
118 *next = tmp; 125 *next = tmp;
119 PROC_INFO_INC( s, scan_bitmap.in_journal_hint ); 126 PROC_INFO_INC(s, scan_bitmap.in_journal_hint);
120 } else { 127 } else {
121 (*next) = off + 1; /* inc offset to avoid looping. */ 128 (*next) = off + 1; /* inc offset to avoid looping. */
122 PROC_INFO_INC( s, scan_bitmap.in_journal_nohint ); 129 PROC_INFO_INC(s, scan_bitmap.in_journal_nohint);
130 }
131 PROC_INFO_INC(s, scan_bitmap.retry);
132 return 1;
123 } 133 }
124 PROC_INFO_INC( s, scan_bitmap.retry ); 134 return 0;
125 return 1;
126 }
127 return 0;
128} 135}
129 136
130/* it searches for a window of zero bits with given minimum and maximum lengths in one bitmap 137/* it searches for a window of zero bits with given minimum and maximum lengths in one bitmap
131 * block; */ 138 * block; */
132static int scan_bitmap_block (struct reiserfs_transaction_handle *th, 139static int scan_bitmap_block(struct reiserfs_transaction_handle *th,
133 int bmap_n, int *beg, int boundary, int min, int max, int unfm) 140 int bmap_n, int *beg, int boundary, int min,
141 int max, int unfm)
134{ 142{
135 struct super_block *s = th->t_super; 143 struct super_block *s = th->t_super;
136 struct reiserfs_bitmap_info *bi=&SB_AP_BITMAP(s)[bmap_n]; 144 struct reiserfs_bitmap_info *bi = &SB_AP_BITMAP(s)[bmap_n];
137 int end, next; 145 int end, next;
138 int org = *beg; 146 int org = *beg;
139 147
140 BUG_ON (!th->t_trans_id); 148 BUG_ON(!th->t_trans_id);
141 149
142 RFALSE(bmap_n >= SB_BMAP_NR (s), "Bitmap %d is out of range (0..%d)",bmap_n, SB_BMAP_NR (s) - 1); 150 RFALSE(bmap_n >= SB_BMAP_NR(s), "Bitmap %d is out of range (0..%d)",
143 PROC_INFO_INC( s, scan_bitmap.bmap ); 151 bmap_n, SB_BMAP_NR(s) - 1);
152 PROC_INFO_INC(s, scan_bitmap.bmap);
144/* this is unclear and lacks comments, explain how journal bitmaps 153/* this is unclear and lacks comments, explain how journal bitmaps
145 work here for the reader. Convey a sense of the design here. What 154 work here for the reader. Convey a sense of the design here. What
146 is a window? */ 155 is a window? */
147/* - I mean `a window of zero bits' as in description of this function - Zam. */ 156/* - I mean `a window of zero bits' as in description of this function - Zam. */
148
149 if ( !bi ) {
150 reiserfs_warning (s, "NULL bitmap info pointer for bitmap %d", bmap_n);
151 return 0;
152 }
153 if (buffer_locked (bi->bh)) {
154 PROC_INFO_INC( s, scan_bitmap.wait );
155 __wait_on_buffer (bi->bh);
156 }
157
158 while (1) {
159 cont:
160 if (bi->free_count < min)
161 return 0; // No free blocks in this bitmap
162
163 /* search for a first zero bit -- beggining of a window */
164 *beg = reiserfs_find_next_zero_le_bit
165 ((unsigned long*)(bi->bh->b_data), boundary, *beg);
166
167 if (*beg + min > boundary) { /* search for a zero bit fails or the rest of bitmap block
168 * cannot contain a zero window of minimum size */
169 return 0;
170 }
171 157
172 if (unfm && is_block_in_journal(s,bmap_n, *beg, beg)) 158 if (!bi) {
173 continue; 159 reiserfs_warning(s, "NULL bitmap info pointer for bitmap %d",
174 /* first zero bit found; we check next bits */ 160 bmap_n);
175 for (end = *beg + 1;; end ++) { 161 return 0;
176 if (end >= *beg + max || end >= boundary || reiserfs_test_le_bit (end, bi->bh->b_data)) { 162 }
177 next = end; 163 if (buffer_locked(bi->bh)) {
178 break; 164 PROC_INFO_INC(s, scan_bitmap.wait);
179 } 165 __wait_on_buffer(bi->bh);
180 /* finding the other end of zero bit window requires looking into journal structures (in
181 * case of searching for free blocks for unformatted nodes) */
182 if (unfm && is_block_in_journal(s, bmap_n, end, &next))
183 break;
184 } 166 }
185 167
186 /* now (*beg) points to beginning of zero bits window, 168 while (1) {
187 * (end) points to one bit after the window end */ 169 cont:
188 if (end - *beg >= min) { /* it seems we have found window of proper size */ 170 if (bi->free_count < min)
189 int i; 171 return 0; // No free blocks in this bitmap
190 reiserfs_prepare_for_journal (s, bi->bh, 1); 172
191 /* try to set all blocks used checking are they still free */ 173 /* search for a first zero bit -- beggining of a window */
192 for (i = *beg; i < end; i++) { 174 *beg = reiserfs_find_next_zero_le_bit
193 /* It seems that we should not check in journal again. */ 175 ((unsigned long *)(bi->bh->b_data), boundary, *beg);
194 if (reiserfs_test_and_set_le_bit (i, bi->bh->b_data)) { 176
195 /* bit was set by another process 177 if (*beg + min > boundary) { /* search for a zero bit fails or the rest of bitmap block
196 * while we slept in prepare_for_journal() */ 178 * cannot contain a zero window of minimum size */
197 PROC_INFO_INC( s, scan_bitmap.stolen ); 179 return 0;
198 if (i >= *beg + min) { /* we can continue with smaller set of allocated blocks,
199 * if length of this set is more or equal to `min' */
200 end = i;
201 break;
202 }
203 /* otherwise we clear all bit were set ... */
204 while (--i >= *beg)
205 reiserfs_test_and_clear_le_bit (i, bi->bh->b_data);
206 reiserfs_restore_prepared_buffer (s, bi->bh);
207 *beg = org;
208 /* ... and search again in current block from beginning */
209 goto cont;
210 } 180 }
211 }
212 bi->free_count -= (end - *beg);
213 journal_mark_dirty (th, s, bi->bh);
214 181
215 /* free block count calculation */ 182 if (unfm && is_block_in_journal(s, bmap_n, *beg, beg))
216 reiserfs_prepare_for_journal (s, SB_BUFFER_WITH_SB(s), 1); 183 continue;
217 PUT_SB_FREE_BLOCKS(s, SB_FREE_BLOCKS(s) - (end - *beg)); 184 /* first zero bit found; we check next bits */
218 journal_mark_dirty (th, s, SB_BUFFER_WITH_SB(s)); 185 for (end = *beg + 1;; end++) {
186 if (end >= *beg + max || end >= boundary
187 || reiserfs_test_le_bit(end, bi->bh->b_data)) {
188 next = end;
189 break;
190 }
191 /* finding the other end of zero bit window requires looking into journal structures (in
192 * case of searching for free blocks for unformatted nodes) */
193 if (unfm && is_block_in_journal(s, bmap_n, end, &next))
194 break;
195 }
219 196
220 return end - (*beg); 197 /* now (*beg) points to beginning of zero bits window,
221 } else { 198 * (end) points to one bit after the window end */
222 *beg = next; 199 if (end - *beg >= min) { /* it seems we have found window of proper size */
200 int i;
201 reiserfs_prepare_for_journal(s, bi->bh, 1);
202 /* try to set all blocks used checking are they still free */
203 for (i = *beg; i < end; i++) {
204 /* It seems that we should not check in journal again. */
205 if (reiserfs_test_and_set_le_bit
206 (i, bi->bh->b_data)) {
207 /* bit was set by another process
208 * while we slept in prepare_for_journal() */
209 PROC_INFO_INC(s, scan_bitmap.stolen);
210 if (i >= *beg + min) { /* we can continue with smaller set of allocated blocks,
211 * if length of this set is more or equal to `min' */
212 end = i;
213 break;
214 }
215 /* otherwise we clear all bit were set ... */
216 while (--i >= *beg)
217 reiserfs_test_and_clear_le_bit
218 (i, bi->bh->b_data);
219 reiserfs_restore_prepared_buffer(s,
220 bi->
221 bh);
222 *beg = org;
223 /* ... and search again in current block from beginning */
224 goto cont;
225 }
226 }
227 bi->free_count -= (end - *beg);
228 journal_mark_dirty(th, s, bi->bh);
229
230 /* free block count calculation */
231 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s),
232 1);
233 PUT_SB_FREE_BLOCKS(s, SB_FREE_BLOCKS(s) - (end - *beg));
234 journal_mark_dirty(th, s, SB_BUFFER_WITH_SB(s));
235
236 return end - (*beg);
237 } else {
238 *beg = next;
239 }
223 } 240 }
224 }
225} 241}
226 242
227static int bmap_hash_id(struct super_block *s, u32 id) { 243static int bmap_hash_id(struct super_block *s, u32 id)
228 char * hash_in = NULL; 244{
229 unsigned long hash; 245 char *hash_in = NULL;
230 unsigned bm; 246 unsigned long hash;
231 247 unsigned bm;
232 if (id <= 2) { 248
233 bm = 1; 249 if (id <= 2) {
234 } else { 250 bm = 1;
235 hash_in = (char *)(&id); 251 } else {
236 hash = keyed_hash(hash_in, 4); 252 hash_in = (char *)(&id);
237 bm = hash % SB_BMAP_NR(s); 253 hash = keyed_hash(hash_in, 4);
238 if (!bm) 254 bm = hash % SB_BMAP_NR(s);
239 bm = 1; 255 if (!bm)
240 } 256 bm = 1;
241 /* this can only be true when SB_BMAP_NR = 1 */ 257 }
242 if (bm >= SB_BMAP_NR(s)) 258 /* this can only be true when SB_BMAP_NR = 1 */
243 bm = 0; 259 if (bm >= SB_BMAP_NR(s))
244 return bm; 260 bm = 0;
261 return bm;
245} 262}
246 263
247/* 264/*
248 * hashes the id and then returns > 0 if the block group for the 265 * hashes the id and then returns > 0 if the block group for the
249 * corresponding hash is full 266 * corresponding hash is full
250 */ 267 */
251static inline int block_group_used(struct super_block *s, u32 id) { 268static inline int block_group_used(struct super_block *s, u32 id)
252 int bm; 269{
253 bm = bmap_hash_id(s, id); 270 int bm;
254 if (SB_AP_BITMAP(s)[bm].free_count > ((s->s_blocksize << 3) * 60 / 100) ) { 271 bm = bmap_hash_id(s, id);
255 return 0; 272 if (SB_AP_BITMAP(s)[bm].free_count > ((s->s_blocksize << 3) * 60 / 100)) {
256 } 273 return 0;
257 return 1; 274 }
275 return 1;
258} 276}
259 277
260/* 278/*
261 * the packing is returned in disk byte order 279 * the packing is returned in disk byte order
262 */ 280 */
263__le32 reiserfs_choose_packing(struct inode *dir) 281__le32 reiserfs_choose_packing(struct inode * dir)
264{ 282{
265 __le32 packing; 283 __le32 packing;
266 if (TEST_OPTION(packing_groups, dir->i_sb)) { 284 if (TEST_OPTION(packing_groups, dir->i_sb)) {
267 u32 parent_dir = le32_to_cpu(INODE_PKEY(dir)->k_dir_id); 285 u32 parent_dir = le32_to_cpu(INODE_PKEY(dir)->k_dir_id);
268 /* 286 /*
269 * some versions of reiserfsck expect packing locality 1 to be 287 * some versions of reiserfsck expect packing locality 1 to be
270 * special 288 * special
271 */ 289 */
272 if (parent_dir == 1 || block_group_used(dir->i_sb,parent_dir)) 290 if (parent_dir == 1 || block_group_used(dir->i_sb, parent_dir))
273 packing = INODE_PKEY(dir)->k_objectid; 291 packing = INODE_PKEY(dir)->k_objectid;
274 else 292 else
275 packing = INODE_PKEY(dir)->k_dir_id; 293 packing = INODE_PKEY(dir)->k_dir_id;
276 } else 294 } else
277 packing = INODE_PKEY(dir)->k_objectid; 295 packing = INODE_PKEY(dir)->k_objectid;
278 return packing; 296 return packing;
279} 297}
280 298
281/* Tries to find contiguous zero bit window (given size) in given region of 299/* Tries to find contiguous zero bit window (given size) in given region of
282 * bitmap and place new blocks there. Returns number of allocated blocks. */ 300 * bitmap and place new blocks there. Returns number of allocated blocks. */
283static int scan_bitmap (struct reiserfs_transaction_handle *th, 301static int scan_bitmap(struct reiserfs_transaction_handle *th,
284 b_blocknr_t *start, b_blocknr_t finish, 302 b_blocknr_t * start, b_blocknr_t finish,
285 int min, int max, int unfm, unsigned long file_block) 303 int min, int max, int unfm, unsigned long file_block)
286{ 304{
287 int nr_allocated=0; 305 int nr_allocated = 0;
288 struct super_block * s = th->t_super; 306 struct super_block *s = th->t_super;
289 /* find every bm and bmap and bmap_nr in this file, and change them all to bitmap_blocknr 307 /* find every bm and bmap and bmap_nr in this file, and change them all to bitmap_blocknr
290 * - Hans, it is not a block number - Zam. */ 308 * - Hans, it is not a block number - Zam. */
291 309
292 int bm, off; 310 int bm, off;
293 int end_bm, end_off; 311 int end_bm, end_off;
294 int off_max = s->s_blocksize << 3; 312 int off_max = s->s_blocksize << 3;
295 313
296 BUG_ON (!th->t_trans_id); 314 BUG_ON(!th->t_trans_id);
297 315
298 PROC_INFO_INC( s, scan_bitmap.call ); 316 PROC_INFO_INC(s, scan_bitmap.call);
299 if ( SB_FREE_BLOCKS(s) <= 0) 317 if (SB_FREE_BLOCKS(s) <= 0)
300 return 0; // No point in looking for more free blocks 318 return 0; // No point in looking for more free blocks
301 319
302 get_bit_address (s, *start, &bm, &off); 320 get_bit_address(s, *start, &bm, &off);
303 get_bit_address (s, finish, &end_bm, &end_off); 321 get_bit_address(s, finish, &end_bm, &end_off);
304 if (bm > SB_BMAP_NR(s)) 322 if (bm > SB_BMAP_NR(s))
305 return 0; 323 return 0;
306 if (end_bm > SB_BMAP_NR(s)) 324 if (end_bm > SB_BMAP_NR(s))
307 end_bm = SB_BMAP_NR(s); 325 end_bm = SB_BMAP_NR(s);
308 326
309 /* When the bitmap is more than 10% free, anyone can allocate. 327 /* When the bitmap is more than 10% free, anyone can allocate.
310 * When it's less than 10% free, only files that already use the 328 * When it's less than 10% free, only files that already use the
311 * bitmap are allowed. Once we pass 80% full, this restriction 329 * bitmap are allowed. Once we pass 80% full, this restriction
312 * is lifted. 330 * is lifted.
313 * 331 *
314 * We do this so that files that grow later still have space close to 332 * We do this so that files that grow later still have space close to
315 * their original allocation. This improves locality, and presumably 333 * their original allocation. This improves locality, and presumably
316 * performance as a result. 334 * performance as a result.
317 * 335 *
318 * This is only an allocation policy and does not make up for getting a 336 * This is only an allocation policy and does not make up for getting a
319 * bad hint. Decent hinting must be implemented for this to work well. 337 * bad hint. Decent hinting must be implemented for this to work well.
320 */ 338 */
321 if ( TEST_OPTION(skip_busy, s) && SB_FREE_BLOCKS(s) > SB_BLOCK_COUNT(s)/20 ) { 339 if (TEST_OPTION(skip_busy, s)
322 for (;bm < end_bm; bm++, off = 0) { 340 && SB_FREE_BLOCKS(s) > SB_BLOCK_COUNT(s) / 20) {
323 if ( ( off && (!unfm || (file_block != 0))) || SB_AP_BITMAP(s)[bm].free_count > (s->s_blocksize << 3) / 10 ) 341 for (; bm < end_bm; bm++, off = 0) {
324 nr_allocated = scan_bitmap_block(th, bm, &off, off_max, min, max, unfm); 342 if ((off && (!unfm || (file_block != 0)))
325 if (nr_allocated) 343 || SB_AP_BITMAP(s)[bm].free_count >
326 goto ret; 344 (s->s_blocksize << 3) / 10)
327 } 345 nr_allocated =
328 /* we know from above that start is a reasonable number */ 346 scan_bitmap_block(th, bm, &off, off_max,
329 get_bit_address (s, *start, &bm, &off); 347 min, max, unfm);
330 } 348 if (nr_allocated)
331 349 goto ret;
332 for (;bm < end_bm; bm++, off = 0) { 350 }
333 nr_allocated = scan_bitmap_block(th, bm, &off, off_max, min, max, unfm); 351 /* we know from above that start is a reasonable number */
334 if (nr_allocated) 352 get_bit_address(s, *start, &bm, &off);
335 goto ret; 353 }
336 } 354
337 355 for (; bm < end_bm; bm++, off = 0) {
338 nr_allocated = scan_bitmap_block(th, bm, &off, end_off + 1, min, max, unfm); 356 nr_allocated =
339 357 scan_bitmap_block(th, bm, &off, off_max, min, max, unfm);
340 ret: 358 if (nr_allocated)
341 *start = bm * off_max + off; 359 goto ret;
342 return nr_allocated; 360 }
361
362 nr_allocated =
363 scan_bitmap_block(th, bm, &off, end_off + 1, min, max, unfm);
364
365 ret:
366 *start = bm * off_max + off;
367 return nr_allocated;
343 368
344} 369}
345 370
346static void _reiserfs_free_block (struct reiserfs_transaction_handle *th, 371static void _reiserfs_free_block(struct reiserfs_transaction_handle *th,
347 struct inode *inode, b_blocknr_t block, 372 struct inode *inode, b_blocknr_t block,
348 int for_unformatted) 373 int for_unformatted)
349{ 374{
350 struct super_block * s = th->t_super; 375 struct super_block *s = th->t_super;
351 struct reiserfs_super_block * rs; 376 struct reiserfs_super_block *rs;
352 struct buffer_head * sbh; 377 struct buffer_head *sbh;
353 struct reiserfs_bitmap_info *apbi; 378 struct reiserfs_bitmap_info *apbi;
354 int nr, offset; 379 int nr, offset;
355 380
356 BUG_ON (!th->t_trans_id); 381 BUG_ON(!th->t_trans_id);
357 382
358 PROC_INFO_INC( s, free_block ); 383 PROC_INFO_INC(s, free_block);
359 384
360 rs = SB_DISK_SUPER_BLOCK (s); 385 rs = SB_DISK_SUPER_BLOCK(s);
361 sbh = SB_BUFFER_WITH_SB (s); 386 sbh = SB_BUFFER_WITH_SB(s);
362 apbi = SB_AP_BITMAP(s); 387 apbi = SB_AP_BITMAP(s);
363 388
364 get_bit_address (s, block, &nr, &offset); 389 get_bit_address(s, block, &nr, &offset);
365 390
366 if (nr >= sb_bmap_nr (rs)) { 391 if (nr >= sb_bmap_nr(rs)) {
367 reiserfs_warning (s, "vs-4075: reiserfs_free_block: " 392 reiserfs_warning(s, "vs-4075: reiserfs_free_block: "
368 "block %lu is out of range on %s", 393 "block %lu is out of range on %s",
369 block, reiserfs_bdevname (s)); 394 block, reiserfs_bdevname(s));
370 return; 395 return;
371 } 396 }
372 397
373 reiserfs_prepare_for_journal(s, apbi[nr].bh, 1 ) ; 398 reiserfs_prepare_for_journal(s, apbi[nr].bh, 1);
374 399
375 /* clear bit for the given block in bit map */ 400 /* clear bit for the given block in bit map */
376 if (!reiserfs_test_and_clear_le_bit (offset, apbi[nr].bh->b_data)) { 401 if (!reiserfs_test_and_clear_le_bit(offset, apbi[nr].bh->b_data)) {
377 reiserfs_warning (s, "vs-4080: reiserfs_free_block: " 402 reiserfs_warning(s, "vs-4080: reiserfs_free_block: "
378 "free_block (%s:%lu)[dev:blocknr]: bit already cleared", 403 "free_block (%s:%lu)[dev:blocknr]: bit already cleared",
379 reiserfs_bdevname (s), block); 404 reiserfs_bdevname(s), block);
380 } 405 }
381 apbi[nr].free_count ++; 406 apbi[nr].free_count++;
382 journal_mark_dirty (th, s, apbi[nr].bh); 407 journal_mark_dirty(th, s, apbi[nr].bh);
383 408
384 reiserfs_prepare_for_journal(s, sbh, 1) ; 409 reiserfs_prepare_for_journal(s, sbh, 1);
385 /* update super block */ 410 /* update super block */
386 set_sb_free_blocks( rs, sb_free_blocks(rs) + 1 ); 411 set_sb_free_blocks(rs, sb_free_blocks(rs) + 1);
387 412
388 journal_mark_dirty (th, s, sbh); 413 journal_mark_dirty(th, s, sbh);
389 if (for_unformatted) 414 if (for_unformatted)
390 DQUOT_FREE_BLOCK_NODIRTY(inode, 1); 415 DQUOT_FREE_BLOCK_NODIRTY(inode, 1);
391} 416}
392 417
393void reiserfs_free_block (struct reiserfs_transaction_handle *th, 418void reiserfs_free_block(struct reiserfs_transaction_handle *th,
394 struct inode *inode, b_blocknr_t block, 419 struct inode *inode, b_blocknr_t block,
395 int for_unformatted) 420 int for_unformatted)
396{ 421{
397 struct super_block * s = th->t_super; 422 struct super_block *s = th->t_super;
398 423
399 BUG_ON (!th->t_trans_id); 424 BUG_ON(!th->t_trans_id);
400 425
401 RFALSE(!s, "vs-4061: trying to free block on nonexistent device"); 426 RFALSE(!s, "vs-4061: trying to free block on nonexistent device");
402 RFALSE(is_reusable (s, block, 1) == 0, "vs-4071: can not free such block"); 427 RFALSE(is_reusable(s, block, 1) == 0,
403 /* mark it before we clear it, just in case */ 428 "vs-4071: can not free such block");
404 journal_mark_freed(th, s, block) ; 429 /* mark it before we clear it, just in case */
405 _reiserfs_free_block(th, inode, block, for_unformatted) ; 430 journal_mark_freed(th, s, block);
431 _reiserfs_free_block(th, inode, block, for_unformatted);
406} 432}
407 433
408/* preallocated blocks don't need to be run through journal_mark_freed */ 434/* preallocated blocks don't need to be run through journal_mark_freed */
409static void reiserfs_free_prealloc_block (struct reiserfs_transaction_handle *th, 435static void reiserfs_free_prealloc_block(struct reiserfs_transaction_handle *th,
410 struct inode *inode, b_blocknr_t block) { 436 struct inode *inode, b_blocknr_t block)
411 RFALSE(!th->t_super, "vs-4060: trying to free block on nonexistent device"); 437{
412 RFALSE(is_reusable (th->t_super, block, 1) == 0, "vs-4070: can not free such block"); 438 RFALSE(!th->t_super,
413 BUG_ON (!th->t_trans_id); 439 "vs-4060: trying to free block on nonexistent device");
414 _reiserfs_free_block(th, inode, block, 1) ; 440 RFALSE(is_reusable(th->t_super, block, 1) == 0,
441 "vs-4070: can not free such block");
442 BUG_ON(!th->t_trans_id);
443 _reiserfs_free_block(th, inode, block, 1);
415} 444}
416 445
417static void __discard_prealloc (struct reiserfs_transaction_handle * th, 446static void __discard_prealloc(struct reiserfs_transaction_handle *th,
418 struct reiserfs_inode_info *ei) 447 struct reiserfs_inode_info *ei)
419{ 448{
420 unsigned long save = ei->i_prealloc_block ; 449 unsigned long save = ei->i_prealloc_block;
421 int dirty = 0; 450 int dirty = 0;
422 struct inode *inode = &ei->vfs_inode; 451 struct inode *inode = &ei->vfs_inode;
423 BUG_ON (!th->t_trans_id); 452 BUG_ON(!th->t_trans_id);
424#ifdef CONFIG_REISERFS_CHECK 453#ifdef CONFIG_REISERFS_CHECK
425 if (ei->i_prealloc_count < 0) 454 if (ei->i_prealloc_count < 0)
426 reiserfs_warning (th->t_super, "zam-4001:%s: inode has negative prealloc blocks count.", __FUNCTION__ ); 455 reiserfs_warning(th->t_super,
456 "zam-4001:%s: inode has negative prealloc blocks count.",
457 __FUNCTION__);
427#endif 458#endif
428 while (ei->i_prealloc_count > 0) { 459 while (ei->i_prealloc_count > 0) {
429 reiserfs_free_prealloc_block(th, inode, ei->i_prealloc_block); 460 reiserfs_free_prealloc_block(th, inode, ei->i_prealloc_block);
430 ei->i_prealloc_block++; 461 ei->i_prealloc_block++;
431 ei->i_prealloc_count --; 462 ei->i_prealloc_count--;
432 dirty = 1; 463 dirty = 1;
433 } 464 }
434 if (dirty) 465 if (dirty)
435 reiserfs_update_sd(th, inode); 466 reiserfs_update_sd(th, inode);
436 ei->i_prealloc_block = save; 467 ei->i_prealloc_block = save;
437 list_del_init(&(ei->i_prealloc_list)); 468 list_del_init(&(ei->i_prealloc_list));
438} 469}
439 470
440/* FIXME: It should be inline function */ 471/* FIXME: It should be inline function */
441void reiserfs_discard_prealloc (struct reiserfs_transaction_handle *th, 472void reiserfs_discard_prealloc(struct reiserfs_transaction_handle *th,
442 struct inode *inode) 473 struct inode *inode)
443{ 474{
444 struct reiserfs_inode_info *ei = REISERFS_I(inode); 475 struct reiserfs_inode_info *ei = REISERFS_I(inode);
445 BUG_ON (!th->t_trans_id); 476 BUG_ON(!th->t_trans_id);
446 if (ei->i_prealloc_count) 477 if (ei->i_prealloc_count)
447 __discard_prealloc(th, ei); 478 __discard_prealloc(th, ei);
448} 479}
449 480
450void reiserfs_discard_all_prealloc (struct reiserfs_transaction_handle *th) 481void reiserfs_discard_all_prealloc(struct reiserfs_transaction_handle *th)
451{ 482{
452 struct list_head * plist = &SB_JOURNAL(th->t_super)->j_prealloc_list; 483 struct list_head *plist = &SB_JOURNAL(th->t_super)->j_prealloc_list;
453 484
454 BUG_ON (!th->t_trans_id); 485 BUG_ON(!th->t_trans_id);
455 486
456 while (!list_empty(plist)) { 487 while (!list_empty(plist)) {
457 struct reiserfs_inode_info *ei; 488 struct reiserfs_inode_info *ei;
458 ei = list_entry(plist->next, struct reiserfs_inode_info, i_prealloc_list); 489 ei = list_entry(plist->next, struct reiserfs_inode_info,
490 i_prealloc_list);
459#ifdef CONFIG_REISERFS_CHECK 491#ifdef CONFIG_REISERFS_CHECK
460 if (!ei->i_prealloc_count) { 492 if (!ei->i_prealloc_count) {
461 reiserfs_warning (th->t_super, "zam-4001:%s: inode is in prealloc list but has no preallocated blocks.", __FUNCTION__); 493 reiserfs_warning(th->t_super,
462 } 494 "zam-4001:%s: inode is in prealloc list but has no preallocated blocks.",
495 __FUNCTION__);
496 }
463#endif 497#endif
464 __discard_prealloc(th, ei); 498 __discard_prealloc(th, ei);
465 } 499 }
466} 500}
467 501
468void reiserfs_init_alloc_options (struct super_block *s) 502void reiserfs_init_alloc_options(struct super_block *s)
469{ 503{
470 set_bit (_ALLOC_skip_busy, &SB_ALLOC_OPTS(s)); 504 set_bit(_ALLOC_skip_busy, &SB_ALLOC_OPTS(s));
471 set_bit (_ALLOC_dirid_groups, &SB_ALLOC_OPTS(s)); 505 set_bit(_ALLOC_dirid_groups, &SB_ALLOC_OPTS(s));
472 set_bit (_ALLOC_packing_groups, &SB_ALLOC_OPTS(s)); 506 set_bit(_ALLOC_packing_groups, &SB_ALLOC_OPTS(s));
473} 507}
474 508
475/* block allocator related options are parsed here */ 509/* block allocator related options are parsed here */
476int reiserfs_parse_alloc_options(struct super_block * s, char * options) 510int reiserfs_parse_alloc_options(struct super_block *s, char *options)
477{ 511{
478 char * this_char, * value; 512 char *this_char, *value;
479 513
480 REISERFS_SB(s)->s_alloc_options.bits = 0; /* clear default settings */ 514 REISERFS_SB(s)->s_alloc_options.bits = 0; /* clear default settings */
481 515
482 while ( (this_char = strsep (&options, ":")) != NULL ) { 516 while ((this_char = strsep(&options, ":")) != NULL) {
483 if ((value = strchr (this_char, '=')) != NULL) 517 if ((value = strchr(this_char, '=')) != NULL)
484 *value++ = 0; 518 *value++ = 0;
485 519
486 if (!strcmp(this_char, "concentrating_formatted_nodes")) { 520 if (!strcmp(this_char, "concentrating_formatted_nodes")) {
487 int temp; 521 int temp;
488 SET_OPTION(concentrating_formatted_nodes); 522 SET_OPTION(concentrating_formatted_nodes);
489 temp = (value && *value) ? simple_strtoul (value, &value, 0) : 10; 523 temp = (value
490 if (temp <= 0 || temp > 100) { 524 && *value) ? simple_strtoul(value, &value,
491 REISERFS_SB(s)->s_alloc_options.border = 10; 525 0) : 10;
492 } else { 526 if (temp <= 0 || temp > 100) {
493 REISERFS_SB(s)->s_alloc_options.border = 100 / temp; 527 REISERFS_SB(s)->s_alloc_options.border = 10;
494 } 528 } else {
495 continue; 529 REISERFS_SB(s)->s_alloc_options.border =
496 } 530 100 / temp;
497 if (!strcmp(this_char, "displacing_large_files")) { 531 }
498 SET_OPTION(displacing_large_files); 532 continue;
499 REISERFS_SB(s)->s_alloc_options.large_file_size = 533 }
500 (value && *value) ? simple_strtoul (value, &value, 0) : 16; 534 if (!strcmp(this_char, "displacing_large_files")) {
501 continue; 535 SET_OPTION(displacing_large_files);
502 } 536 REISERFS_SB(s)->s_alloc_options.large_file_size =
503 if (!strcmp(this_char, "displacing_new_packing_localities")) { 537 (value
504 SET_OPTION(displacing_new_packing_localities); 538 && *value) ? simple_strtoul(value, &value, 0) : 16;
505 continue; 539 continue;
506 }; 540 }
507 541 if (!strcmp(this_char, "displacing_new_packing_localities")) {
508 if (!strcmp(this_char, "old_hashed_relocation")) { 542 SET_OPTION(displacing_new_packing_localities);
509 SET_OPTION(old_hashed_relocation); 543 continue;
510 continue; 544 };
511 } 545
546 if (!strcmp(this_char, "old_hashed_relocation")) {
547 SET_OPTION(old_hashed_relocation);
548 continue;
549 }
512 550
513 if (!strcmp(this_char, "new_hashed_relocation")) { 551 if (!strcmp(this_char, "new_hashed_relocation")) {
514 SET_OPTION(new_hashed_relocation); 552 SET_OPTION(new_hashed_relocation);
515 continue; 553 continue;
516 } 554 }
517 555
518 if (!strcmp(this_char, "dirid_groups")) { 556 if (!strcmp(this_char, "dirid_groups")) {
519 SET_OPTION(dirid_groups); 557 SET_OPTION(dirid_groups);
520 continue; 558 continue;
521 } 559 }
522 if (!strcmp(this_char, "oid_groups")) { 560 if (!strcmp(this_char, "oid_groups")) {
523 SET_OPTION(oid_groups); 561 SET_OPTION(oid_groups);
524 continue; 562 continue;
525 } 563 }
526 if (!strcmp(this_char, "packing_groups")) { 564 if (!strcmp(this_char, "packing_groups")) {
527 SET_OPTION(packing_groups); 565 SET_OPTION(packing_groups);
528 continue; 566 continue;
529 } 567 }
530 if (!strcmp(this_char, "hashed_formatted_nodes")) { 568 if (!strcmp(this_char, "hashed_formatted_nodes")) {
531 SET_OPTION(hashed_formatted_nodes); 569 SET_OPTION(hashed_formatted_nodes);
532 continue; 570 continue;
533 } 571 }
534 572
535 if (!strcmp(this_char, "skip_busy")) { 573 if (!strcmp(this_char, "skip_busy")) {
536 SET_OPTION(skip_busy); 574 SET_OPTION(skip_busy);
537 continue; 575 continue;
538 } 576 }
539 577
540 if (!strcmp(this_char, "hundredth_slices")) { 578 if (!strcmp(this_char, "hundredth_slices")) {
541 SET_OPTION(hundredth_slices); 579 SET_OPTION(hundredth_slices);
542 continue; 580 continue;
543 } 581 }
544 582
545 if (!strcmp(this_char, "old_way")) { 583 if (!strcmp(this_char, "old_way")) {
546 SET_OPTION(old_way); 584 SET_OPTION(old_way);
547 continue; 585 continue;
548 } 586 }
549 587
550 if (!strcmp(this_char, "displace_based_on_dirid")) { 588 if (!strcmp(this_char, "displace_based_on_dirid")) {
551 SET_OPTION(displace_based_on_dirid); 589 SET_OPTION(displace_based_on_dirid);
552 continue; 590 continue;
553 } 591 }
554 592
555 if (!strcmp(this_char, "preallocmin")) { 593 if (!strcmp(this_char, "preallocmin")) {
556 REISERFS_SB(s)->s_alloc_options.preallocmin = 594 REISERFS_SB(s)->s_alloc_options.preallocmin =
557 (value && *value) ? simple_strtoul (value, &value, 0) : 4; 595 (value
558 continue; 596 && *value) ? simple_strtoul(value, &value, 0) : 4;
559 } 597 continue;
598 }
599
600 if (!strcmp(this_char, "preallocsize")) {
601 REISERFS_SB(s)->s_alloc_options.preallocsize =
602 (value
603 && *value) ? simple_strtoul(value, &value,
604 0) :
605 PREALLOCATION_SIZE;
606 continue;
607 }
560 608
561 if (!strcmp(this_char, "preallocsize")) { 609 reiserfs_warning(s, "zam-4001: %s : unknown option - %s",
562 REISERFS_SB(s)->s_alloc_options.preallocsize = 610 __FUNCTION__, this_char);
563 (value && *value) ? simple_strtoul (value, &value, 0) : PREALLOCATION_SIZE; 611 return 1;
564 continue;
565 } 612 }
566 613
567 reiserfs_warning (s, "zam-4001: %s : unknown option - %s", 614 reiserfs_warning(s, "allocator options = [%08x]\n", SB_ALLOC_OPTS(s));
568 __FUNCTION__ , this_char); 615 return 0;
569 return 1;
570 }
571
572 reiserfs_warning (s, "allocator options = [%08x]\n", SB_ALLOC_OPTS(s));
573 return 0;
574} 616}
575 617
576static inline void new_hashed_relocation (reiserfs_blocknr_hint_t * hint) 618static inline void new_hashed_relocation(reiserfs_blocknr_hint_t * hint)
577{ 619{
578 char * hash_in; 620 char *hash_in;
579 if (hint->formatted_node) { 621 if (hint->formatted_node) {
580 hash_in = (char*)&hint->key.k_dir_id; 622 hash_in = (char *)&hint->key.k_dir_id;
581 } else { 623 } else {
582 if (!hint->inode) { 624 if (!hint->inode) {
583 //hint->search_start = hint->beg; 625 //hint->search_start = hint->beg;
584 hash_in = (char*)&hint->key.k_dir_id; 626 hash_in = (char *)&hint->key.k_dir_id;
585 } else 627 } else
586 if ( TEST_OPTION(displace_based_on_dirid, hint->th->t_super)) 628 if (TEST_OPTION(displace_based_on_dirid, hint->th->t_super))
587 hash_in = (char *)(&INODE_PKEY(hint->inode)->k_dir_id); 629 hash_in = (char *)(&INODE_PKEY(hint->inode)->k_dir_id);
588 else 630 else
589 hash_in = (char *)(&INODE_PKEY(hint->inode)->k_objectid); 631 hash_in =
590 } 632 (char *)(&INODE_PKEY(hint->inode)->k_objectid);
633 }
591 634
592 hint->search_start = hint->beg + keyed_hash(hash_in, 4) % (hint->end - hint->beg); 635 hint->search_start =
636 hint->beg + keyed_hash(hash_in, 4) % (hint->end - hint->beg);
593} 637}
594 638
595/* 639/*
596 * Relocation based on dirid, hashing them into a given bitmap block 640 * Relocation based on dirid, hashing them into a given bitmap block
597 * files. Formatted nodes are unaffected, a seperate policy covers them 641 * files. Formatted nodes are unaffected, a seperate policy covers them
598 */ 642 */
599static void 643static void dirid_groups(reiserfs_blocknr_hint_t * hint)
600dirid_groups (reiserfs_blocknr_hint_t *hint)
601{ 644{
602 unsigned long hash; 645 unsigned long hash;
603 __u32 dirid = 0; 646 __u32 dirid = 0;
604 int bm = 0; 647 int bm = 0;
605 struct super_block *sb = hint->th->t_super; 648 struct super_block *sb = hint->th->t_super;
606 if (hint->inode)
607 dirid = le32_to_cpu(INODE_PKEY(hint->inode)->k_dir_id);
608 else if (hint->formatted_node)
609 dirid = hint->key.k_dir_id;
610
611 if (dirid) {
612 bm = bmap_hash_id(sb, dirid);
613 hash = bm * (sb->s_blocksize << 3);
614 /* give a portion of the block group to metadata */
615 if (hint->inode) 649 if (hint->inode)
616 hash += sb->s_blocksize/2; 650 dirid = le32_to_cpu(INODE_PKEY(hint->inode)->k_dir_id);
617 hint->search_start = hash; 651 else if (hint->formatted_node)
618 } 652 dirid = hint->key.k_dir_id;
653
654 if (dirid) {
655 bm = bmap_hash_id(sb, dirid);
656 hash = bm * (sb->s_blocksize << 3);
657 /* give a portion of the block group to metadata */
658 if (hint->inode)
659 hash += sb->s_blocksize / 2;
660 hint->search_start = hash;
661 }
619} 662}
620 663
621/* 664/*
622 * Relocation based on oid, hashing them into a given bitmap block 665 * Relocation based on oid, hashing them into a given bitmap block
623 * files. Formatted nodes are unaffected, a seperate policy covers them 666 * files. Formatted nodes are unaffected, a seperate policy covers them
624 */ 667 */
625static void 668static void oid_groups(reiserfs_blocknr_hint_t * hint)
626oid_groups (reiserfs_blocknr_hint_t *hint)
627{ 669{
628 if (hint->inode) { 670 if (hint->inode) {
629 unsigned long hash; 671 unsigned long hash;
630 __u32 oid; 672 __u32 oid;
631 __u32 dirid; 673 __u32 dirid;
632 int bm; 674 int bm;
633 675
634 dirid = le32_to_cpu(INODE_PKEY(hint->inode)->k_dir_id); 676 dirid = le32_to_cpu(INODE_PKEY(hint->inode)->k_dir_id);
635 677
636 /* keep the root dir and it's first set of subdirs close to 678 /* keep the root dir and it's first set of subdirs close to
637 * the start of the disk 679 * the start of the disk
638 */ 680 */
639 if (dirid <= 2) 681 if (dirid <= 2)
640 hash = (hint->inode->i_sb->s_blocksize << 3); 682 hash = (hint->inode->i_sb->s_blocksize << 3);
641 else { 683 else {
642 oid = le32_to_cpu(INODE_PKEY(hint->inode)->k_objectid); 684 oid = le32_to_cpu(INODE_PKEY(hint->inode)->k_objectid);
643 bm = bmap_hash_id(hint->inode->i_sb, oid); 685 bm = bmap_hash_id(hint->inode->i_sb, oid);
644 hash = bm * (hint->inode->i_sb->s_blocksize << 3); 686 hash = bm * (hint->inode->i_sb->s_blocksize << 3);
687 }
688 hint->search_start = hash;
645 } 689 }
646 hint->search_start = hash;
647 }
648} 690}
649 691
650/* returns 1 if it finds an indirect item and gets valid hint info 692/* returns 1 if it finds an indirect item and gets valid hint info
651 * from it, otherwise 0 693 * from it, otherwise 0
652 */ 694 */
653static int get_left_neighbor(reiserfs_blocknr_hint_t *hint) 695static int get_left_neighbor(reiserfs_blocknr_hint_t * hint)
654{ 696{
655 struct path * path; 697 struct path *path;
656 struct buffer_head * bh; 698 struct buffer_head *bh;
657 struct item_head * ih; 699 struct item_head *ih;
658 int pos_in_item; 700 int pos_in_item;
659 __le32 * item; 701 __le32 *item;
660 int ret = 0; 702 int ret = 0;
661 703
662 if (!hint->path) /* reiserfs code can call this function w/o pointer to path 704 if (!hint->path) /* reiserfs code can call this function w/o pointer to path
663 * structure supplied; then we rely on supplied search_start */ 705 * structure supplied; then we rely on supplied search_start */
664 return 0; 706 return 0;
665 707
666 path = hint->path; 708 path = hint->path;
667 bh = get_last_bh(path); 709 bh = get_last_bh(path);
668 RFALSE( !bh, "green-4002: Illegal path specified to get_left_neighbor"); 710 RFALSE(!bh, "green-4002: Illegal path specified to get_left_neighbor");
669 ih = get_ih(path); 711 ih = get_ih(path);
670 pos_in_item = path->pos_in_item; 712 pos_in_item = path->pos_in_item;
671 item = get_item (path); 713 item = get_item(path);
672 714
673 hint->search_start = bh->b_blocknr; 715 hint->search_start = bh->b_blocknr;
674 716
675 if (!hint->formatted_node && is_indirect_le_ih (ih)) { 717 if (!hint->formatted_node && is_indirect_le_ih(ih)) {
676 /* for indirect item: go to left and look for the first non-hole entry 718 /* for indirect item: go to left and look for the first non-hole entry
677 in the indirect item */ 719 in the indirect item */
678 if (pos_in_item == I_UNFM_NUM (ih)) 720 if (pos_in_item == I_UNFM_NUM(ih))
679 pos_in_item--; 721 pos_in_item--;
680// pos_in_item = I_UNFM_NUM (ih) - 1; 722// pos_in_item = I_UNFM_NUM (ih) - 1;
681 while (pos_in_item >= 0) { 723 while (pos_in_item >= 0) {
682 int t=get_block_num(item,pos_in_item); 724 int t = get_block_num(item, pos_in_item);
683 if (t) { 725 if (t) {
684 hint->search_start = t; 726 hint->search_start = t;
685 ret = 1; 727 ret = 1;
686 break; 728 break;
687 } 729 }
688 pos_in_item --; 730 pos_in_item--;
731 }
689 } 732 }
690 }
691 733
692 /* does result value fit into specified region? */ 734 /* does result value fit into specified region? */
693 return ret; 735 return ret;
694} 736}
695 737
696/* should be, if formatted node, then try to put on first part of the device 738/* should be, if formatted node, then try to put on first part of the device
697 specified as number of percent with mount option device, else try to put 739 specified as number of percent with mount option device, else try to put
698 on last of device. This is not to say it is good code to do so, 740 on last of device. This is not to say it is good code to do so,
699 but the effect should be measured. */ 741 but the effect should be measured. */
700static inline void set_border_in_hint(struct super_block *s, reiserfs_blocknr_hint_t *hint) 742static inline void set_border_in_hint(struct super_block *s,
743 reiserfs_blocknr_hint_t * hint)
701{ 744{
702 b_blocknr_t border = SB_BLOCK_COUNT(s) / REISERFS_SB(s)->s_alloc_options.border; 745 b_blocknr_t border =
746 SB_BLOCK_COUNT(s) / REISERFS_SB(s)->s_alloc_options.border;
703 747
704 if (hint->formatted_node) 748 if (hint->formatted_node)
705 hint->end = border - 1; 749 hint->end = border - 1;
706 else 750 else
707 hint->beg = border; 751 hint->beg = border;
708} 752}
709 753
710static inline void displace_large_file(reiserfs_blocknr_hint_t *hint) 754static inline void displace_large_file(reiserfs_blocknr_hint_t * hint)
711{ 755{
712 if ( TEST_OPTION(displace_based_on_dirid, hint->th->t_super)) 756 if (TEST_OPTION(displace_based_on_dirid, hint->th->t_super))
713 hint->search_start = hint->beg + keyed_hash((char *)(&INODE_PKEY(hint->inode)->k_dir_id), 4) % (hint->end - hint->beg); 757 hint->search_start =
714 else 758 hint->beg +
715 hint->search_start = hint->beg + keyed_hash((char *)(&INODE_PKEY(hint->inode)->k_objectid), 4) % (hint->end - hint->beg); 759 keyed_hash((char *)(&INODE_PKEY(hint->inode)->k_dir_id),
760 4) % (hint->end - hint->beg);
761 else
762 hint->search_start =
763 hint->beg +
764 keyed_hash((char *)(&INODE_PKEY(hint->inode)->k_objectid),
765 4) % (hint->end - hint->beg);
716} 766}
717 767
718static inline void hash_formatted_node(reiserfs_blocknr_hint_t *hint) 768static inline void hash_formatted_node(reiserfs_blocknr_hint_t * hint)
719{ 769{
720 char * hash_in; 770 char *hash_in;
721 771
722 if (!hint->inode) 772 if (!hint->inode)
723 hash_in = (char*)&hint->key.k_dir_id; 773 hash_in = (char *)&hint->key.k_dir_id;
724 else if ( TEST_OPTION(displace_based_on_dirid, hint->th->t_super)) 774 else if (TEST_OPTION(displace_based_on_dirid, hint->th->t_super))
725 hash_in = (char *)(&INODE_PKEY(hint->inode)->k_dir_id); 775 hash_in = (char *)(&INODE_PKEY(hint->inode)->k_dir_id);
726 else 776 else
727 hash_in = (char *)(&INODE_PKEY(hint->inode)->k_objectid); 777 hash_in = (char *)(&INODE_PKEY(hint->inode)->k_objectid);
728 778
729 hint->search_start = hint->beg + keyed_hash(hash_in, 4) % (hint->end - hint->beg); 779 hint->search_start =
780 hint->beg + keyed_hash(hash_in, 4) % (hint->end - hint->beg);
730} 781}
731 782
732static inline int this_blocknr_allocation_would_make_it_a_large_file(reiserfs_blocknr_hint_t *hint) 783static inline int
784this_blocknr_allocation_would_make_it_a_large_file(reiserfs_blocknr_hint_t *
785 hint)
733{ 786{
734 return hint->block == REISERFS_SB(hint->th->t_super)->s_alloc_options.large_file_size; 787 return hint->block ==
788 REISERFS_SB(hint->th->t_super)->s_alloc_options.large_file_size;
735} 789}
736 790
737#ifdef DISPLACE_NEW_PACKING_LOCALITIES 791#ifdef DISPLACE_NEW_PACKING_LOCALITIES
738static inline void displace_new_packing_locality (reiserfs_blocknr_hint_t *hint) 792static inline void displace_new_packing_locality(reiserfs_blocknr_hint_t * hint)
739{ 793{
740 struct in_core_key * key = &hint->key; 794 struct in_core_key *key = &hint->key;
741 795
742 hint->th->displace_new_blocks = 0; 796 hint->th->displace_new_blocks = 0;
743 hint->search_start = hint->beg + keyed_hash((char*)(&key->k_objectid),4) % (hint->end - hint->beg); 797 hint->search_start =
798 hint->beg + keyed_hash((char *)(&key->k_objectid),
799 4) % (hint->end - hint->beg);
744} 800}
745 #endif 801#endif
746 802
747static inline int old_hashed_relocation (reiserfs_blocknr_hint_t * hint) 803static inline int old_hashed_relocation(reiserfs_blocknr_hint_t * hint)
748{ 804{
749 b_blocknr_t border; 805 b_blocknr_t border;
750 u32 hash_in; 806 u32 hash_in;
751
752 if (hint->formatted_node || hint->inode == NULL) {
753 return 0;
754 }
755 807
756 hash_in = le32_to_cpu((INODE_PKEY(hint->inode))->k_dir_id); 808 if (hint->formatted_node || hint->inode == NULL) {
757 border = hint->beg + (u32) keyed_hash(((char *) (&hash_in)), 4) % (hint->end - hint->beg - 1); 809 return 0;
758 if (border > hint->search_start) 810 }
759 hint->search_start = border;
760 811
761 return 1; 812 hash_in = le32_to_cpu((INODE_PKEY(hint->inode))->k_dir_id);
762 } 813 border =
763 814 hint->beg + (u32) keyed_hash(((char *)(&hash_in)),
764static inline int old_way (reiserfs_blocknr_hint_t * hint) 815 4) % (hint->end - hint->beg - 1);
765{ 816 if (border > hint->search_start)
766 b_blocknr_t border; 817 hint->search_start = border;
767
768 if (hint->formatted_node || hint->inode == NULL) {
769 return 0;
770 }
771
772 border = hint->beg + le32_to_cpu(INODE_PKEY(hint->inode)->k_dir_id) % (hint->end - hint->beg);
773 if (border > hint->search_start)
774 hint->search_start = border;
775 818
776 return 1; 819 return 1;
777} 820}
778 821
779static inline void hundredth_slices (reiserfs_blocknr_hint_t * hint) 822static inline int old_way(reiserfs_blocknr_hint_t * hint)
780{ 823{
781 struct in_core_key * key = &hint->key; 824 b_blocknr_t border;
782 b_blocknr_t slice_start; 825
826 if (hint->formatted_node || hint->inode == NULL) {
827 return 0;
828 }
829
830 border =
831 hint->beg +
832 le32_to_cpu(INODE_PKEY(hint->inode)->k_dir_id) % (hint->end -
833 hint->beg);
834 if (border > hint->search_start)
835 hint->search_start = border;
783 836
784 slice_start = (keyed_hash((char*)(&key->k_dir_id),4) % 100) * (hint->end / 100); 837 return 1;
785 if ( slice_start > hint->search_start || slice_start + (hint->end / 100) <= hint->search_start) { 838}
786 hint->search_start = slice_start; 839
787 } 840static inline void hundredth_slices(reiserfs_blocknr_hint_t * hint)
841{
842 struct in_core_key *key = &hint->key;
843 b_blocknr_t slice_start;
844
845 slice_start =
846 (keyed_hash((char *)(&key->k_dir_id), 4) % 100) * (hint->end / 100);
847 if (slice_start > hint->search_start
848 || slice_start + (hint->end / 100) <= hint->search_start) {
849 hint->search_start = slice_start;
850 }
788} 851}
789 852
790static void determine_search_start(reiserfs_blocknr_hint_t *hint, 853static void determine_search_start(reiserfs_blocknr_hint_t * hint,
791 int amount_needed) 854 int amount_needed)
792{ 855{
793 struct super_block *s = hint->th->t_super; 856 struct super_block *s = hint->th->t_super;
794 int unfm_hint; 857 int unfm_hint;
795 858
796 hint->beg = 0; 859 hint->beg = 0;
797 hint->end = SB_BLOCK_COUNT(s) - 1; 860 hint->end = SB_BLOCK_COUNT(s) - 1;
798 861
799 /* This is former border algorithm. Now with tunable border offset */ 862 /* This is former border algorithm. Now with tunable border offset */
800 if (concentrating_formatted_nodes(s)) 863 if (concentrating_formatted_nodes(s))
801 set_border_in_hint(s, hint); 864 set_border_in_hint(s, hint);
802 865
803#ifdef DISPLACE_NEW_PACKING_LOCALITIES 866#ifdef DISPLACE_NEW_PACKING_LOCALITIES
804 /* whenever we create a new directory, we displace it. At first we will 867 /* whenever we create a new directory, we displace it. At first we will
805 hash for location, later we might look for a moderately empty place for 868 hash for location, later we might look for a moderately empty place for
806 it */ 869 it */
807 if (displacing_new_packing_localities(s) 870 if (displacing_new_packing_localities(s)
808 && hint->th->displace_new_blocks) { 871 && hint->th->displace_new_blocks) {
809 displace_new_packing_locality(hint); 872 displace_new_packing_locality(hint);
810 873
811 /* we do not continue determine_search_start, 874 /* we do not continue determine_search_start,
812 * if new packing locality is being displaced */ 875 * if new packing locality is being displaced */
813 return; 876 return;
814 } 877 }
815#endif 878#endif
816
817 /* all persons should feel encouraged to add more special cases here and
818 * test them */
819 879
820 if (displacing_large_files(s) && !hint->formatted_node 880 /* all persons should feel encouraged to add more special cases here and
821 && this_blocknr_allocation_would_make_it_a_large_file(hint)) { 881 * test them */
822 displace_large_file(hint);
823 return;
824 }
825
826 /* if none of our special cases is relevant, use the left neighbor in the
827 tree order of the new node we are allocating for */
828 if (hint->formatted_node && TEST_OPTION(hashed_formatted_nodes,s)) {
829 hash_formatted_node(hint);
830 return;
831 }
832 882
833 unfm_hint = get_left_neighbor(hint); 883 if (displacing_large_files(s) && !hint->formatted_node
884 && this_blocknr_allocation_would_make_it_a_large_file(hint)) {
885 displace_large_file(hint);
886 return;
887 }
834 888
835 /* Mimic old block allocator behaviour, that is if VFS allowed for preallocation, 889 /* if none of our special cases is relevant, use the left neighbor in the
836 new blocks are displaced based on directory ID. Also, if suggested search_start 890 tree order of the new node we are allocating for */
837 is less than last preallocated block, we start searching from it, assuming that 891 if (hint->formatted_node && TEST_OPTION(hashed_formatted_nodes, s)) {
838 HDD dataflow is faster in forward direction */ 892 hash_formatted_node(hint);
839 if ( TEST_OPTION(old_way, s)) { 893 return;
840 if (!hint->formatted_node) { 894 }
841 if ( !reiserfs_hashed_relocation(s))
842 old_way(hint);
843 else if (!reiserfs_no_unhashed_relocation(s))
844 old_hashed_relocation(hint);
845 895
846 if ( hint->inode && hint->search_start < REISERFS_I(hint->inode)->i_prealloc_block) 896 unfm_hint = get_left_neighbor(hint);
847 hint->search_start = REISERFS_I(hint->inode)->i_prealloc_block; 897
898 /* Mimic old block allocator behaviour, that is if VFS allowed for preallocation,
899 new blocks are displaced based on directory ID. Also, if suggested search_start
900 is less than last preallocated block, we start searching from it, assuming that
901 HDD dataflow is faster in forward direction */
902 if (TEST_OPTION(old_way, s)) {
903 if (!hint->formatted_node) {
904 if (!reiserfs_hashed_relocation(s))
905 old_way(hint);
906 else if (!reiserfs_no_unhashed_relocation(s))
907 old_hashed_relocation(hint);
908
909 if (hint->inode
910 && hint->search_start <
911 REISERFS_I(hint->inode)->i_prealloc_block)
912 hint->search_start =
913 REISERFS_I(hint->inode)->i_prealloc_block;
914 }
915 return;
848 } 916 }
849 return;
850 }
851 917
852 /* This is an approach proposed by Hans */ 918 /* This is an approach proposed by Hans */
853 if ( TEST_OPTION(hundredth_slices, s) && ! (displacing_large_files(s) && !hint->formatted_node)) { 919 if (TEST_OPTION(hundredth_slices, s)
854 hundredth_slices(hint); 920 && !(displacing_large_files(s) && !hint->formatted_node)) {
855 return; 921 hundredth_slices(hint);
856 } 922 return;
857 923 }
858 /* old_hashed_relocation only works on unformatted */
859 if (!unfm_hint && !hint->formatted_node &&
860 TEST_OPTION(old_hashed_relocation, s))
861 {
862 old_hashed_relocation(hint);
863 }
864 /* new_hashed_relocation works with both formatted/unformatted nodes */
865 if ((!unfm_hint || hint->formatted_node) &&
866 TEST_OPTION(new_hashed_relocation, s))
867 {
868 new_hashed_relocation(hint);
869 }
870 /* dirid grouping works only on unformatted nodes */
871 if (!unfm_hint && !hint->formatted_node && TEST_OPTION(dirid_groups,s))
872 {
873 dirid_groups(hint);
874 }
875 924
925 /* old_hashed_relocation only works on unformatted */
926 if (!unfm_hint && !hint->formatted_node &&
927 TEST_OPTION(old_hashed_relocation, s)) {
928 old_hashed_relocation(hint);
929 }
930 /* new_hashed_relocation works with both formatted/unformatted nodes */
931 if ((!unfm_hint || hint->formatted_node) &&
932 TEST_OPTION(new_hashed_relocation, s)) {
933 new_hashed_relocation(hint);
934 }
935 /* dirid grouping works only on unformatted nodes */
936 if (!unfm_hint && !hint->formatted_node && TEST_OPTION(dirid_groups, s)) {
937 dirid_groups(hint);
938 }
876#ifdef DISPLACE_NEW_PACKING_LOCALITIES 939#ifdef DISPLACE_NEW_PACKING_LOCALITIES
877 if (hint->formatted_node && TEST_OPTION(dirid_groups,s)) 940 if (hint->formatted_node && TEST_OPTION(dirid_groups, s)) {
878 { 941 dirid_groups(hint);
879 dirid_groups(hint); 942 }
880 }
881#endif 943#endif
882 944
883 /* oid grouping works only on unformatted nodes */ 945 /* oid grouping works only on unformatted nodes */
884 if (!unfm_hint && !hint->formatted_node && TEST_OPTION(oid_groups,s)) 946 if (!unfm_hint && !hint->formatted_node && TEST_OPTION(oid_groups, s)) {
885 { 947 oid_groups(hint);
886 oid_groups(hint); 948 }
887 } 949 return;
888 return;
889} 950}
890 951
891static int determine_prealloc_size(reiserfs_blocknr_hint_t * hint) 952static int determine_prealloc_size(reiserfs_blocknr_hint_t * hint)
892{ 953{
893 /* make minimum size a mount option and benchmark both ways */ 954 /* make minimum size a mount option and benchmark both ways */
894 /* we preallocate blocks only for regular files, specific size */ 955 /* we preallocate blocks only for regular files, specific size */
895 /* benchmark preallocating always and see what happens */ 956 /* benchmark preallocating always and see what happens */
896 957
897 hint->prealloc_size = 0; 958 hint->prealloc_size = 0;
898 959
899 if (!hint->formatted_node && hint->preallocate) { 960 if (!hint->formatted_node && hint->preallocate) {
900 if (S_ISREG(hint->inode->i_mode) 961 if (S_ISREG(hint->inode->i_mode)
901 && hint->inode->i_size >= REISERFS_SB(hint->th->t_super)->s_alloc_options.preallocmin * hint->inode->i_sb->s_blocksize) 962 && hint->inode->i_size >=
902 hint->prealloc_size = REISERFS_SB(hint->th->t_super)->s_alloc_options.preallocsize - 1; 963 REISERFS_SB(hint->th->t_super)->s_alloc_options.
903 } 964 preallocmin * hint->inode->i_sb->s_blocksize)
904 return CARRY_ON; 965 hint->prealloc_size =
966 REISERFS_SB(hint->th->t_super)->s_alloc_options.
967 preallocsize - 1;
968 }
969 return CARRY_ON;
905} 970}
906 971
907/* XXX I know it could be merged with upper-level function; 972/* XXX I know it could be merged with upper-level function;
908 but may be result function would be too complex. */ 973 but may be result function would be too complex. */
909static inline int allocate_without_wrapping_disk (reiserfs_blocknr_hint_t * hint, 974static inline int allocate_without_wrapping_disk(reiserfs_blocknr_hint_t * hint,
910 b_blocknr_t * new_blocknrs, 975 b_blocknr_t * new_blocknrs,
911 b_blocknr_t start, b_blocknr_t finish, 976 b_blocknr_t start,
912 int min, 977 b_blocknr_t finish, int min,
913 int amount_needed, int prealloc_size) 978 int amount_needed,
979 int prealloc_size)
914{ 980{
915 int rest = amount_needed; 981 int rest = amount_needed;
916 int nr_allocated; 982 int nr_allocated;
917 983
918 while (rest > 0 && start <= finish) { 984 while (rest > 0 && start <= finish) {
919 nr_allocated = scan_bitmap (hint->th, &start, finish, min, 985 nr_allocated = scan_bitmap(hint->th, &start, finish, min,
920 rest + prealloc_size, !hint->formatted_node, 986 rest + prealloc_size,
921 hint->block); 987 !hint->formatted_node, hint->block);
922 988
923 if (nr_allocated == 0) /* no new blocks allocated, return */ 989 if (nr_allocated == 0) /* no new blocks allocated, return */
924 break; 990 break;
925 991
926 /* fill free_blocknrs array first */ 992 /* fill free_blocknrs array first */
927 while (rest > 0 && nr_allocated > 0) { 993 while (rest > 0 && nr_allocated > 0) {
928 * new_blocknrs ++ = start ++; 994 *new_blocknrs++ = start++;
929 rest --; nr_allocated --; 995 rest--;
930 } 996 nr_allocated--;
997 }
931 998
932 /* do we have something to fill prealloc. array also ? */ 999 /* do we have something to fill prealloc. array also ? */
933 if (nr_allocated > 0) { 1000 if (nr_allocated > 0) {
934 /* it means prealloc_size was greater that 0 and we do preallocation */ 1001 /* it means prealloc_size was greater that 0 and we do preallocation */
935 list_add(&REISERFS_I(hint->inode)->i_prealloc_list, 1002 list_add(&REISERFS_I(hint->inode)->i_prealloc_list,
936 &SB_JOURNAL(hint->th->t_super)->j_prealloc_list); 1003 &SB_JOURNAL(hint->th->t_super)->
937 REISERFS_I(hint->inode)->i_prealloc_block = start; 1004 j_prealloc_list);
938 REISERFS_I(hint->inode)->i_prealloc_count = nr_allocated; 1005 REISERFS_I(hint->inode)->i_prealloc_block = start;
939 break; 1006 REISERFS_I(hint->inode)->i_prealloc_count =
1007 nr_allocated;
1008 break;
1009 }
940 } 1010 }
941 }
942 1011
943 return (amount_needed - rest); 1012 return (amount_needed - rest);
944} 1013}
945 1014
946static inline int blocknrs_and_prealloc_arrays_from_search_start 1015static inline int blocknrs_and_prealloc_arrays_from_search_start
947 (reiserfs_blocknr_hint_t *hint, b_blocknr_t *new_blocknrs, int amount_needed) 1016 (reiserfs_blocknr_hint_t * hint, b_blocknr_t * new_blocknrs,
948{ 1017 int amount_needed) {
949 struct super_block *s = hint->th->t_super; 1018 struct super_block *s = hint->th->t_super;
950 b_blocknr_t start = hint->search_start; 1019 b_blocknr_t start = hint->search_start;
951 b_blocknr_t finish = SB_BLOCK_COUNT(s) - 1; 1020 b_blocknr_t finish = SB_BLOCK_COUNT(s) - 1;
952 int passno = 0; 1021 int passno = 0;
953 int nr_allocated = 0; 1022 int nr_allocated = 0;
954 int bigalloc = 0; 1023 int bigalloc = 0;
955 1024
956 determine_prealloc_size(hint); 1025 determine_prealloc_size(hint);
957 if (!hint->formatted_node) { 1026 if (!hint->formatted_node) {
958 int quota_ret; 1027 int quota_ret;
959#ifdef REISERQUOTA_DEBUG 1028#ifdef REISERQUOTA_DEBUG
960 reiserfs_debug (s, REISERFS_DEBUG_CODE, "reiserquota: allocating %d blocks id=%u", amount_needed, hint->inode->i_uid); 1029 reiserfs_debug(s, REISERFS_DEBUG_CODE,
1030 "reiserquota: allocating %d blocks id=%u",
1031 amount_needed, hint->inode->i_uid);
961#endif 1032#endif
962 quota_ret = DQUOT_ALLOC_BLOCK_NODIRTY(hint->inode, amount_needed); 1033 quota_ret =
963 if (quota_ret) /* Quota exceeded? */ 1034 DQUOT_ALLOC_BLOCK_NODIRTY(hint->inode, amount_needed);
964 return QUOTA_EXCEEDED; 1035 if (quota_ret) /* Quota exceeded? */
965 if (hint->preallocate && hint->prealloc_size ) { 1036 return QUOTA_EXCEEDED;
1037 if (hint->preallocate && hint->prealloc_size) {
966#ifdef REISERQUOTA_DEBUG 1038#ifdef REISERQUOTA_DEBUG
967 reiserfs_debug (s, REISERFS_DEBUG_CODE, "reiserquota: allocating (prealloc) %d blocks id=%u", hint->prealloc_size, hint->inode->i_uid); 1039 reiserfs_debug(s, REISERFS_DEBUG_CODE,
1040 "reiserquota: allocating (prealloc) %d blocks id=%u",
1041 hint->prealloc_size, hint->inode->i_uid);
968#endif 1042#endif
969 quota_ret = DQUOT_PREALLOC_BLOCK_NODIRTY(hint->inode, hint->prealloc_size); 1043 quota_ret =
970 if (quota_ret) 1044 DQUOT_PREALLOC_BLOCK_NODIRTY(hint->inode,
971 hint->preallocate=hint->prealloc_size=0; 1045 hint->prealloc_size);
1046 if (quota_ret)
1047 hint->preallocate = hint->prealloc_size = 0;
1048 }
1049 /* for unformatted nodes, force large allocations */
1050 bigalloc = amount_needed;
972 } 1051 }
973 /* for unformatted nodes, force large allocations */
974 bigalloc = amount_needed;
975 }
976 1052
977 do { 1053 do {
978 /* in bigalloc mode, nr_allocated should stay zero until 1054 /* in bigalloc mode, nr_allocated should stay zero until
979 * the entire allocation is filled 1055 * the entire allocation is filled
980 */ 1056 */
981 if (unlikely(bigalloc && nr_allocated)) { 1057 if (unlikely(bigalloc && nr_allocated)) {
982 reiserfs_warning(s, "bigalloc is %d, nr_allocated %d\n", 1058 reiserfs_warning(s, "bigalloc is %d, nr_allocated %d\n",
983 bigalloc, nr_allocated); 1059 bigalloc, nr_allocated);
984 /* reset things to a sane value */ 1060 /* reset things to a sane value */
985 bigalloc = amount_needed - nr_allocated; 1061 bigalloc = amount_needed - nr_allocated;
986 } 1062 }
987 /* 1063 /*
988 * try pass 0 and pass 1 looking for a nice big 1064 * try pass 0 and pass 1 looking for a nice big
989 * contiguous allocation. Then reset and look 1065 * contiguous allocation. Then reset and look
990 * for anything you can find. 1066 * for anything you can find.
991 */ 1067 */
992 if (passno == 2 && bigalloc) { 1068 if (passno == 2 && bigalloc) {
993 passno = 0; 1069 passno = 0;
994 bigalloc = 0; 1070 bigalloc = 0;
995 } 1071 }
996 switch (passno++) { 1072 switch (passno++) {
997 case 0: /* Search from hint->search_start to end of disk */ 1073 case 0: /* Search from hint->search_start to end of disk */
998 start = hint->search_start; 1074 start = hint->search_start;
999 finish = SB_BLOCK_COUNT(s) - 1; 1075 finish = SB_BLOCK_COUNT(s) - 1;
1000 break; 1076 break;
1001 case 1: /* Search from hint->beg to hint->search_start */ 1077 case 1: /* Search from hint->beg to hint->search_start */
1002 start = hint->beg; 1078 start = hint->beg;
1003 finish = hint->search_start; 1079 finish = hint->search_start;
1004 break; 1080 break;
1005 case 2: /* Last chance: Search from 0 to hint->beg */ 1081 case 2: /* Last chance: Search from 0 to hint->beg */
1006 start = 0; 1082 start = 0;
1007 finish = hint->beg; 1083 finish = hint->beg;
1008 break; 1084 break;
1009 default: /* We've tried searching everywhere, not enough space */ 1085 default: /* We've tried searching everywhere, not enough space */
1010 /* Free the blocks */ 1086 /* Free the blocks */
1011 if (!hint->formatted_node) { 1087 if (!hint->formatted_node) {
1012#ifdef REISERQUOTA_DEBUG 1088#ifdef REISERQUOTA_DEBUG
1013 reiserfs_debug (s, REISERFS_DEBUG_CODE, "reiserquota: freeing (nospace) %d blocks id=%u", amount_needed + hint->prealloc_size - nr_allocated, hint->inode->i_uid); 1089 reiserfs_debug(s, REISERFS_DEBUG_CODE,
1090 "reiserquota: freeing (nospace) %d blocks id=%u",
1091 amount_needed +
1092 hint->prealloc_size -
1093 nr_allocated,
1094 hint->inode->i_uid);
1014#endif 1095#endif
1015 DQUOT_FREE_BLOCK_NODIRTY(hint->inode, amount_needed + hint->prealloc_size - nr_allocated); /* Free not allocated blocks */ 1096 DQUOT_FREE_BLOCK_NODIRTY(hint->inode, amount_needed + hint->prealloc_size - nr_allocated); /* Free not allocated blocks */
1016 } 1097 }
1017 while (nr_allocated --) 1098 while (nr_allocated--)
1018 reiserfs_free_block(hint->th, hint->inode, new_blocknrs[nr_allocated], !hint->formatted_node); 1099 reiserfs_free_block(hint->th, hint->inode,
1019 1100 new_blocknrs[nr_allocated],
1020 return NO_DISK_SPACE; 1101 !hint->formatted_node);
1021 } 1102
1022 } while ((nr_allocated += allocate_without_wrapping_disk (hint, 1103 return NO_DISK_SPACE;
1023 new_blocknrs + nr_allocated, start, finish, 1104 }
1024 bigalloc ? bigalloc : 1, 1105 } while ((nr_allocated += allocate_without_wrapping_disk(hint,
1025 amount_needed - nr_allocated, 1106 new_blocknrs +
1026 hint->prealloc_size)) 1107 nr_allocated,
1027 < amount_needed); 1108 start, finish,
1028 if ( !hint->formatted_node && 1109 bigalloc ?
1029 amount_needed + hint->prealloc_size > 1110 bigalloc : 1,
1030 nr_allocated + REISERFS_I(hint->inode)->i_prealloc_count) { 1111 amount_needed -
1031 /* Some of preallocation blocks were not allocated */ 1112 nr_allocated,
1113 hint->
1114 prealloc_size))
1115 < amount_needed);
1116 if (!hint->formatted_node &&
1117 amount_needed + hint->prealloc_size >
1118 nr_allocated + REISERFS_I(hint->inode)->i_prealloc_count) {
1119 /* Some of preallocation blocks were not allocated */
1032#ifdef REISERQUOTA_DEBUG 1120#ifdef REISERQUOTA_DEBUG
1033 reiserfs_debug (s, REISERFS_DEBUG_CODE, "reiserquota: freeing (failed prealloc) %d blocks id=%u", amount_needed + hint->prealloc_size - nr_allocated - REISERFS_I(hint->inode)->i_prealloc_count, hint->inode->i_uid); 1121 reiserfs_debug(s, REISERFS_DEBUG_CODE,
1122 "reiserquota: freeing (failed prealloc) %d blocks id=%u",
1123 amount_needed + hint->prealloc_size -
1124 nr_allocated -
1125 REISERFS_I(hint->inode)->i_prealloc_count,
1126 hint->inode->i_uid);
1034#endif 1127#endif
1035 DQUOT_FREE_BLOCK_NODIRTY(hint->inode, amount_needed + 1128 DQUOT_FREE_BLOCK_NODIRTY(hint->inode, amount_needed +
1036 hint->prealloc_size - nr_allocated - 1129 hint->prealloc_size - nr_allocated -
1037 REISERFS_I(hint->inode)->i_prealloc_count); 1130 REISERFS_I(hint->inode)->
1038 } 1131 i_prealloc_count);
1132 }
1039 1133
1040 return CARRY_ON; 1134 return CARRY_ON;
1041} 1135}
1042 1136
1043/* grab new blocknrs from preallocated list */ 1137/* grab new blocknrs from preallocated list */
1044/* return amount still needed after using them */ 1138/* return amount still needed after using them */
1045static int use_preallocated_list_if_available (reiserfs_blocknr_hint_t *hint, 1139static int use_preallocated_list_if_available(reiserfs_blocknr_hint_t * hint,
1046 b_blocknr_t *new_blocknrs, int amount_needed) 1140 b_blocknr_t * new_blocknrs,
1141 int amount_needed)
1047{ 1142{
1048 struct inode * inode = hint->inode; 1143 struct inode *inode = hint->inode;
1049 1144
1050 if (REISERFS_I(inode)->i_prealloc_count > 0) { 1145 if (REISERFS_I(inode)->i_prealloc_count > 0) {
1051 while (amount_needed) { 1146 while (amount_needed) {
1052 1147
1053 *new_blocknrs ++ = REISERFS_I(inode)->i_prealloc_block ++; 1148 *new_blocknrs++ = REISERFS_I(inode)->i_prealloc_block++;
1054 REISERFS_I(inode)->i_prealloc_count --; 1149 REISERFS_I(inode)->i_prealloc_count--;
1055 1150
1056 amount_needed --; 1151 amount_needed--;
1057 1152
1058 if (REISERFS_I(inode)->i_prealloc_count <= 0) { 1153 if (REISERFS_I(inode)->i_prealloc_count <= 0) {
1059 list_del(&REISERFS_I(inode)->i_prealloc_list); 1154 list_del(&REISERFS_I(inode)->i_prealloc_list);
1060 break; 1155 break;
1061 } 1156 }
1157 }
1062 } 1158 }
1063 } 1159 /* return amount still needed after using preallocated blocks */
1064 /* return amount still needed after using preallocated blocks */ 1160 return amount_needed;
1065 return amount_needed;
1066} 1161}
1067 1162
1068int reiserfs_allocate_blocknrs(reiserfs_blocknr_hint_t *hint, 1163int reiserfs_allocate_blocknrs(reiserfs_blocknr_hint_t * hint, b_blocknr_t * new_blocknrs, int amount_needed, int reserved_by_us /* Amount of blocks we have
1069 b_blocknr_t * new_blocknrs, int amount_needed, 1164 already reserved */ )
1070 int reserved_by_us /* Amount of blocks we have
1071 already reserved */)
1072{ 1165{
1073 int initial_amount_needed = amount_needed; 1166 int initial_amount_needed = amount_needed;
1074 int ret; 1167 int ret;
1075 struct super_block *s = hint->th->t_super; 1168 struct super_block *s = hint->th->t_super;
1076 1169
1077 /* Check if there is enough space, taking into account reserved space */ 1170 /* Check if there is enough space, taking into account reserved space */
1078 if ( SB_FREE_BLOCKS(s) - REISERFS_SB(s)->reserved_blocks < 1171 if (SB_FREE_BLOCKS(s) - REISERFS_SB(s)->reserved_blocks <
1079 amount_needed - reserved_by_us) 1172 amount_needed - reserved_by_us)
1080 return NO_DISK_SPACE; 1173 return NO_DISK_SPACE;
1081 /* should this be if !hint->inode && hint->preallocate? */ 1174 /* should this be if !hint->inode && hint->preallocate? */
1082 /* do you mean hint->formatted_node can be removed ? - Zam */ 1175 /* do you mean hint->formatted_node can be removed ? - Zam */
1083 /* hint->formatted_node cannot be removed because we try to access 1176 /* hint->formatted_node cannot be removed because we try to access
1084 inode information here, and there is often no inode assotiated with 1177 inode information here, and there is often no inode assotiated with
1085 metadata allocations - green */ 1178 metadata allocations - green */
1086 1179
1087 if (!hint->formatted_node && hint->preallocate) { 1180 if (!hint->formatted_node && hint->preallocate) {
1088 amount_needed = use_preallocated_list_if_available 1181 amount_needed = use_preallocated_list_if_available
1182 (hint, new_blocknrs, amount_needed);
1183 if (amount_needed == 0) /* all blocknrs we need we got from
1184 prealloc. list */
1185 return CARRY_ON;
1186 new_blocknrs += (initial_amount_needed - amount_needed);
1187 }
1188
1189 /* find search start and save it in hint structure */
1190 determine_search_start(hint, amount_needed);
1191 if (hint->search_start >= SB_BLOCK_COUNT(s))
1192 hint->search_start = SB_BLOCK_COUNT(s) - 1;
1193
1194 /* allocation itself; fill new_blocknrs and preallocation arrays */
1195 ret = blocknrs_and_prealloc_arrays_from_search_start
1089 (hint, new_blocknrs, amount_needed); 1196 (hint, new_blocknrs, amount_needed);
1090 if (amount_needed == 0) /* all blocknrs we need we got from 1197
1091 prealloc. list */ 1198 /* we used prealloc. list to fill (partially) new_blocknrs array. If final allocation fails we
1092 return CARRY_ON; 1199 * need to return blocks back to prealloc. list or just free them. -- Zam (I chose second
1093 new_blocknrs += (initial_amount_needed - amount_needed); 1200 * variant) */
1094 } 1201
1095 1202 if (ret != CARRY_ON) {
1096 /* find search start and save it in hint structure */ 1203 while (amount_needed++ < initial_amount_needed) {
1097 determine_search_start(hint, amount_needed); 1204 reiserfs_free_block(hint->th, hint->inode,
1098 if (hint->search_start >= SB_BLOCK_COUNT(s)) 1205 *(--new_blocknrs), 1);
1099 hint->search_start = SB_BLOCK_COUNT(s) - 1; 1206 }
1100
1101 /* allocation itself; fill new_blocknrs and preallocation arrays */
1102 ret = blocknrs_and_prealloc_arrays_from_search_start
1103 (hint, new_blocknrs, amount_needed);
1104
1105 /* we used prealloc. list to fill (partially) new_blocknrs array. If final allocation fails we
1106 * need to return blocks back to prealloc. list or just free them. -- Zam (I chose second
1107 * variant) */
1108
1109 if (ret != CARRY_ON) {
1110 while (amount_needed ++ < initial_amount_needed) {
1111 reiserfs_free_block(hint->th, hint->inode, *(--new_blocknrs), 1);
1112 } 1207 }
1113 } 1208 return ret;
1114 return ret;
1115} 1209}
1116 1210
1117/* These 2 functions are here to provide blocks reservation to the rest of kernel */ 1211/* These 2 functions are here to provide blocks reservation to the rest of kernel */
1118/* Reserve @blocks amount of blocks in fs pointed by @sb. Caller must make sure 1212/* Reserve @blocks amount of blocks in fs pointed by @sb. Caller must make sure
1119 there are actually this much blocks on the FS available */ 1213 there are actually this much blocks on the FS available */
1120void reiserfs_claim_blocks_to_be_allocated( 1214void reiserfs_claim_blocks_to_be_allocated(struct super_block *sb, /* super block of
1121 struct super_block *sb, /* super block of 1215 filesystem where
1122 filesystem where 1216 blocks should be
1123 blocks should be 1217 reserved */
1124 reserved */ 1218 int blocks /* How much to reserve */
1125 int blocks /* How much to reserve */ 1219 )
1126 )
1127{ 1220{
1128 1221
1129 /* Fast case, if reservation is zero - exit immediately. */ 1222 /* Fast case, if reservation is zero - exit immediately. */
1130 if ( !blocks ) 1223 if (!blocks)
1131 return; 1224 return;
1132 1225
1133 spin_lock(&REISERFS_SB(sb)->bitmap_lock); 1226 spin_lock(&REISERFS_SB(sb)->bitmap_lock);
1134 REISERFS_SB(sb)->reserved_blocks += blocks; 1227 REISERFS_SB(sb)->reserved_blocks += blocks;
1135 spin_unlock(&REISERFS_SB(sb)->bitmap_lock); 1228 spin_unlock(&REISERFS_SB(sb)->bitmap_lock);
1136} 1229}
1137 1230
1138/* Unreserve @blocks amount of blocks in fs pointed by @sb */ 1231/* Unreserve @blocks amount of blocks in fs pointed by @sb */
1139void reiserfs_release_claimed_blocks( 1232void reiserfs_release_claimed_blocks(struct super_block *sb, /* super block of
1140 struct super_block *sb, /* super block of 1233 filesystem where
1141 filesystem where 1234 blocks should be
1142 blocks should be 1235 reserved */
1143 reserved */ 1236 int blocks /* How much to unreserve */
1144 int blocks /* How much to unreserve */ 1237 )
1145 )
1146{ 1238{
1147 1239
1148 /* Fast case, if unreservation is zero - exit immediately. */ 1240 /* Fast case, if unreservation is zero - exit immediately. */
1149 if ( !blocks ) 1241 if (!blocks)
1150 return; 1242 return;
1151 1243
1152 spin_lock(&REISERFS_SB(sb)->bitmap_lock); 1244 spin_lock(&REISERFS_SB(sb)->bitmap_lock);
1153 REISERFS_SB(sb)->reserved_blocks -= blocks; 1245 REISERFS_SB(sb)->reserved_blocks -= blocks;
1154 spin_unlock(&REISERFS_SB(sb)->bitmap_lock); 1246 spin_unlock(&REISERFS_SB(sb)->bitmap_lock);
1155 RFALSE( REISERFS_SB(sb)->reserved_blocks < 0, "amount of blocks reserved became zero?"); 1247 RFALSE(REISERFS_SB(sb)->reserved_blocks < 0,
1248 "amount of blocks reserved became zero?");
1156} 1249}
1157 1250
1158/* This function estimates how much pages we will be able to write to FS 1251/* This function estimates how much pages we will be able to write to FS
1159 used for reiserfs_file_write() purposes for now. */ 1252 used for reiserfs_file_write() purposes for now. */
1160int reiserfs_can_fit_pages ( struct super_block *sb /* superblock of filesystem 1253int reiserfs_can_fit_pages(struct super_block *sb /* superblock of filesystem
1161 to estimate space */ ) 1254 to estimate space */ )
1162{ 1255{
1163 int space; 1256 int space;
1164 1257
1165 spin_lock(&REISERFS_SB(sb)->bitmap_lock); 1258 spin_lock(&REISERFS_SB(sb)->bitmap_lock);
1166 space = (SB_FREE_BLOCKS(sb) - REISERFS_SB(sb)->reserved_blocks) >> ( PAGE_CACHE_SHIFT - sb->s_blocksize_bits); 1259 space =
1260 (SB_FREE_BLOCKS(sb) -
1261 REISERFS_SB(sb)->reserved_blocks) >> (PAGE_CACHE_SHIFT -
1262 sb->s_blocksize_bits);
1167 spin_unlock(&REISERFS_SB(sb)->bitmap_lock); 1263 spin_unlock(&REISERFS_SB(sb)->bitmap_lock);
1168 1264
1169 return space>0?space:0; 1265 return space > 0 ? space : 0;
1170} 1266}
diff --git a/fs/reiserfs/dir.c b/fs/reiserfs/dir.c
index fbde4b01a325..9dd71e807034 100644
--- a/fs/reiserfs/dir.c
+++ b/fs/reiserfs/dir.c
@@ -12,264 +12,286 @@
12#include <linux/buffer_head.h> 12#include <linux/buffer_head.h>
13#include <asm/uaccess.h> 13#include <asm/uaccess.h>
14 14
15extern struct reiserfs_key MIN_KEY; 15extern struct reiserfs_key MIN_KEY;
16 16
17static int reiserfs_readdir (struct file *, void *, filldir_t); 17static int reiserfs_readdir(struct file *, void *, filldir_t);
18static int reiserfs_dir_fsync(struct file *filp, struct dentry *dentry, int datasync) ; 18static int reiserfs_dir_fsync(struct file *filp, struct dentry *dentry,
19 int datasync);
19 20
20struct file_operations reiserfs_dir_operations = { 21struct file_operations reiserfs_dir_operations = {
21 .read = generic_read_dir, 22 .read = generic_read_dir,
22 .readdir = reiserfs_readdir, 23 .readdir = reiserfs_readdir,
23 .fsync = reiserfs_dir_fsync, 24 .fsync = reiserfs_dir_fsync,
24 .ioctl = reiserfs_ioctl, 25 .ioctl = reiserfs_ioctl,
25}; 26};
26 27
27static int reiserfs_dir_fsync(struct file *filp, struct dentry *dentry, int datasync) { 28static int reiserfs_dir_fsync(struct file *filp, struct dentry *dentry,
28 struct inode *inode = dentry->d_inode; 29 int datasync)
29 int err; 30{
30 reiserfs_write_lock(inode->i_sb); 31 struct inode *inode = dentry->d_inode;
31 err = reiserfs_commit_for_inode(inode) ; 32 int err;
32 reiserfs_write_unlock(inode->i_sb) ; 33 reiserfs_write_lock(inode->i_sb);
33 if (err < 0) 34 err = reiserfs_commit_for_inode(inode);
34 return err; 35 reiserfs_write_unlock(inode->i_sb);
35 return 0; 36 if (err < 0)
37 return err;
38 return 0;
36} 39}
37 40
38
39#define store_ih(where,what) copy_item_head (where, what) 41#define store_ih(where,what) copy_item_head (where, what)
40 42
41// 43//
42static int reiserfs_readdir (struct file * filp, void * dirent, filldir_t filldir) 44static int reiserfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
43{ 45{
44 struct inode *inode = filp->f_dentry->d_inode; 46 struct inode *inode = filp->f_dentry->d_inode;
45 struct cpu_key pos_key; /* key of current position in the directory (key of directory entry) */ 47 struct cpu_key pos_key; /* key of current position in the directory (key of directory entry) */
46 INITIALIZE_PATH (path_to_entry); 48 INITIALIZE_PATH(path_to_entry);
47 struct buffer_head * bh; 49 struct buffer_head *bh;
48 int item_num, entry_num; 50 int item_num, entry_num;
49 const struct reiserfs_key * rkey; 51 const struct reiserfs_key *rkey;
50 struct item_head * ih, tmp_ih; 52 struct item_head *ih, tmp_ih;
51 int search_res; 53 int search_res;
52 char * local_buf; 54 char *local_buf;
53 loff_t next_pos; 55 loff_t next_pos;
54 char small_buf[32] ; /* avoid kmalloc if we can */ 56 char small_buf[32]; /* avoid kmalloc if we can */
55 struct reiserfs_dir_entry de; 57 struct reiserfs_dir_entry de;
56 int ret = 0; 58 int ret = 0;
57 59
58 reiserfs_write_lock(inode->i_sb); 60 reiserfs_write_lock(inode->i_sb);
59 61
60 reiserfs_check_lock_depth(inode->i_sb, "readdir") ; 62 reiserfs_check_lock_depth(inode->i_sb, "readdir");
61 63
62 /* form key for search the next directory entry using f_pos field of 64 /* form key for search the next directory entry using f_pos field of
63 file structure */ 65 file structure */
64 make_cpu_key (&pos_key, inode, (filp->f_pos) ? (filp->f_pos) : DOT_OFFSET, 66 make_cpu_key(&pos_key, inode,
65 TYPE_DIRENTRY, 3); 67 (filp->f_pos) ? (filp->f_pos) : DOT_OFFSET, TYPE_DIRENTRY,
66 next_pos = cpu_key_k_offset (&pos_key); 68 3);
67 69 next_pos = cpu_key_k_offset(&pos_key);
68 /* reiserfs_warning (inode->i_sb, "reiserfs_readdir 1: f_pos = %Ld", filp->f_pos);*/ 70
69 71 /* reiserfs_warning (inode->i_sb, "reiserfs_readdir 1: f_pos = %Ld", filp->f_pos); */
70 path_to_entry.reada = PATH_READA; 72
71 while (1) { 73 path_to_entry.reada = PATH_READA;
72 research: 74 while (1) {
73 /* search the directory item, containing entry with specified key */ 75 research:
74 search_res = search_by_entry_key (inode->i_sb, &pos_key, &path_to_entry, &de); 76 /* search the directory item, containing entry with specified key */
75 if (search_res == IO_ERROR) { 77 search_res =
76 // FIXME: we could just skip part of directory which could 78 search_by_entry_key(inode->i_sb, &pos_key, &path_to_entry,
77 // not be read 79 &de);
78 ret = -EIO; 80 if (search_res == IO_ERROR) {
79 goto out; 81 // FIXME: we could just skip part of directory which could
80 } 82 // not be read
81 entry_num = de.de_entry_num; 83 ret = -EIO;
82 bh = de.de_bh;
83 item_num = de.de_item_num;
84 ih = de.de_ih;
85 store_ih (&tmp_ih, ih);
86
87 /* we must have found item, that is item of this directory, */
88 RFALSE( COMP_SHORT_KEYS (&(ih->ih_key), &pos_key),
89 "vs-9000: found item %h does not match to dir we readdir %K",
90 ih, &pos_key);
91 RFALSE( item_num > B_NR_ITEMS (bh) - 1,
92 "vs-9005 item_num == %d, item amount == %d",
93 item_num, B_NR_ITEMS (bh));
94
95 /* and entry must be not more than number of entries in the item */
96 RFALSE( I_ENTRY_COUNT (ih) < entry_num,
97 "vs-9010: entry number is too big %d (%d)",
98 entry_num, I_ENTRY_COUNT (ih));
99
100 if (search_res == POSITION_FOUND || entry_num < I_ENTRY_COUNT (ih)) {
101 /* go through all entries in the directory item beginning from the entry, that has been found */
102 struct reiserfs_de_head * deh = B_I_DEH (bh, ih) + entry_num;
103
104 for (; entry_num < I_ENTRY_COUNT (ih); entry_num ++, deh ++) {
105 int d_reclen;
106 char * d_name;
107 off_t d_off;
108 ino_t d_ino;
109
110 if (!de_visible (deh))
111 /* it is hidden entry */
112 continue;
113 d_reclen = entry_length (bh, ih, entry_num);
114 d_name = B_I_DEH_ENTRY_FILE_NAME (bh, ih, deh);
115 if (!d_name[d_reclen - 1])
116 d_reclen = strlen (d_name);
117
118 if (d_reclen > REISERFS_MAX_NAME(inode->i_sb->s_blocksize)){
119 /* too big to send back to VFS */
120 continue ;
121 }
122
123 /* Ignore the .reiserfs_priv entry */
124 if (reiserfs_xattrs (inode->i_sb) &&
125 !old_format_only(inode->i_sb) &&
126 filp->f_dentry == inode->i_sb->s_root &&
127 REISERFS_SB(inode->i_sb)->priv_root &&
128 REISERFS_SB(inode->i_sb)->priv_root->d_inode &&
129 deh_objectid(deh) == le32_to_cpu (INODE_PKEY(REISERFS_SB(inode->i_sb)->priv_root->d_inode)->k_objectid)) {
130 continue;
131 }
132
133 d_off = deh_offset (deh);
134 filp->f_pos = d_off ;
135 d_ino = deh_objectid (deh);
136 if (d_reclen <= 32) {
137 local_buf = small_buf ;
138 } else {
139 local_buf = reiserfs_kmalloc(d_reclen, GFP_NOFS, inode->i_sb) ;
140 if (!local_buf) {
141 pathrelse (&path_to_entry);
142 ret = -ENOMEM ;
143 goto out; 84 goto out;
144 }
145 if (item_moved (&tmp_ih, &path_to_entry)) {
146 reiserfs_kfree(local_buf, d_reclen, inode->i_sb) ;
147 goto research;
148 }
149 }
150 // Note, that we copy name to user space via temporary
151 // buffer (local_buf) because filldir will block if
152 // user space buffer is swapped out. At that time
153 // entry can move to somewhere else
154 memcpy (local_buf, d_name, d_reclen);
155 if (filldir (dirent, local_buf, d_reclen, d_off, d_ino,
156 DT_UNKNOWN) < 0) {
157 if (local_buf != small_buf) {
158 reiserfs_kfree(local_buf, d_reclen, inode->i_sb) ;
159 }
160 goto end;
161 } 85 }
162 if (local_buf != small_buf) { 86 entry_num = de.de_entry_num;
163 reiserfs_kfree(local_buf, d_reclen, inode->i_sb) ; 87 bh = de.de_bh;
88 item_num = de.de_item_num;
89 ih = de.de_ih;
90 store_ih(&tmp_ih, ih);
91
92 /* we must have found item, that is item of this directory, */
93 RFALSE(COMP_SHORT_KEYS(&(ih->ih_key), &pos_key),
94 "vs-9000: found item %h does not match to dir we readdir %K",
95 ih, &pos_key);
96 RFALSE(item_num > B_NR_ITEMS(bh) - 1,
97 "vs-9005 item_num == %d, item amount == %d",
98 item_num, B_NR_ITEMS(bh));
99
100 /* and entry must be not more than number of entries in the item */
101 RFALSE(I_ENTRY_COUNT(ih) < entry_num,
102 "vs-9010: entry number is too big %d (%d)",
103 entry_num, I_ENTRY_COUNT(ih));
104
105 if (search_res == POSITION_FOUND
106 || entry_num < I_ENTRY_COUNT(ih)) {
107 /* go through all entries in the directory item beginning from the entry, that has been found */
108 struct reiserfs_de_head *deh =
109 B_I_DEH(bh, ih) + entry_num;
110
111 for (; entry_num < I_ENTRY_COUNT(ih);
112 entry_num++, deh++) {
113 int d_reclen;
114 char *d_name;
115 off_t d_off;
116 ino_t d_ino;
117
118 if (!de_visible(deh))
119 /* it is hidden entry */
120 continue;
121 d_reclen = entry_length(bh, ih, entry_num);
122 d_name = B_I_DEH_ENTRY_FILE_NAME(bh, ih, deh);
123 if (!d_name[d_reclen - 1])
124 d_reclen = strlen(d_name);
125
126 if (d_reclen >
127 REISERFS_MAX_NAME(inode->i_sb->
128 s_blocksize)) {
129 /* too big to send back to VFS */
130 continue;
131 }
132
133 /* Ignore the .reiserfs_priv entry */
134 if (reiserfs_xattrs(inode->i_sb) &&
135 !old_format_only(inode->i_sb) &&
136 filp->f_dentry == inode->i_sb->s_root &&
137 REISERFS_SB(inode->i_sb)->priv_root &&
138 REISERFS_SB(inode->i_sb)->priv_root->d_inode
139 && deh_objectid(deh) ==
140 le32_to_cpu(INODE_PKEY
141 (REISERFS_SB(inode->i_sb)->
142 priv_root->d_inode)->
143 k_objectid)) {
144 continue;
145 }
146
147 d_off = deh_offset(deh);
148 filp->f_pos = d_off;
149 d_ino = deh_objectid(deh);
150 if (d_reclen <= 32) {
151 local_buf = small_buf;
152 } else {
153 local_buf =
154 reiserfs_kmalloc(d_reclen, GFP_NOFS,
155 inode->i_sb);
156 if (!local_buf) {
157 pathrelse(&path_to_entry);
158 ret = -ENOMEM;
159 goto out;
160 }
161 if (item_moved(&tmp_ih, &path_to_entry)) {
162 reiserfs_kfree(local_buf,
163 d_reclen,
164 inode->i_sb);
165 goto research;
166 }
167 }
168 // Note, that we copy name to user space via temporary
169 // buffer (local_buf) because filldir will block if
170 // user space buffer is swapped out. At that time
171 // entry can move to somewhere else
172 memcpy(local_buf, d_name, d_reclen);
173 if (filldir
174 (dirent, local_buf, d_reclen, d_off, d_ino,
175 DT_UNKNOWN) < 0) {
176 if (local_buf != small_buf) {
177 reiserfs_kfree(local_buf,
178 d_reclen,
179 inode->i_sb);
180 }
181 goto end;
182 }
183 if (local_buf != small_buf) {
184 reiserfs_kfree(local_buf, d_reclen,
185 inode->i_sb);
186 }
187 // next entry should be looked for with such offset
188 next_pos = deh_offset(deh) + 1;
189
190 if (item_moved(&tmp_ih, &path_to_entry)) {
191 goto research;
192 }
193 } /* for */
164 } 194 }
165 195
166 // next entry should be looked for with such offset 196 if (item_num != B_NR_ITEMS(bh) - 1)
167 next_pos = deh_offset (deh) + 1; 197 // end of directory has been reached
198 goto end;
199
200 /* item we went through is last item of node. Using right
201 delimiting key check is it directory end */
202 rkey = get_rkey(&path_to_entry, inode->i_sb);
203 if (!comp_le_keys(rkey, &MIN_KEY)) {
204 /* set pos_key to key, that is the smallest and greater
205 that key of the last entry in the item */
206 set_cpu_key_k_offset(&pos_key, next_pos);
207 continue;
208 }
168 209
169 if (item_moved (&tmp_ih, &path_to_entry)) { 210 if (COMP_SHORT_KEYS(rkey, &pos_key)) {
170 goto research; 211 // end of directory has been reached
212 goto end;
171 } 213 }
172 } /* for */ 214
173 } 215 /* directory continues in the right neighboring block */
174 216 set_cpu_key_k_offset(&pos_key,
175 if (item_num != B_NR_ITEMS (bh) - 1) 217 le_key_k_offset(KEY_FORMAT_3_5, rkey));
176 // end of directory has been reached 218
177 goto end; 219 } /* while */
178 220
179 /* item we went through is last item of node. Using right 221 end:
180 delimiting key check is it directory end */ 222 filp->f_pos = next_pos;
181 rkey = get_rkey (&path_to_entry, inode->i_sb); 223 pathrelse(&path_to_entry);
182 if (! comp_le_keys (rkey, &MIN_KEY)) { 224 reiserfs_check_path(&path_to_entry);
183 /* set pos_key to key, that is the smallest and greater 225 out:
184 that key of the last entry in the item */ 226 reiserfs_write_unlock(inode->i_sb);
185 set_cpu_key_k_offset (&pos_key, next_pos); 227 return ret;
186 continue;
187 }
188
189 if ( COMP_SHORT_KEYS (rkey, &pos_key)) {
190 // end of directory has been reached
191 goto end;
192 }
193
194 /* directory continues in the right neighboring block */
195 set_cpu_key_k_offset (&pos_key, le_key_k_offset (KEY_FORMAT_3_5, rkey));
196
197 } /* while */
198
199
200 end:
201 filp->f_pos = next_pos;
202 pathrelse (&path_to_entry);
203 reiserfs_check_path(&path_to_entry) ;
204 out:
205 reiserfs_write_unlock(inode->i_sb);
206 return ret;
207} 228}
208 229
209/* compose directory item containing "." and ".." entries (entries are 230/* compose directory item containing "." and ".." entries (entries are
210 not aligned to 4 byte boundary) */ 231 not aligned to 4 byte boundary) */
211/* the last four params are LE */ 232/* the last four params are LE */
212void make_empty_dir_item_v1 (char * body, __le32 dirid, __le32 objid, 233void make_empty_dir_item_v1(char *body, __le32 dirid, __le32 objid,
213 __le32 par_dirid, __le32 par_objid) 234 __le32 par_dirid, __le32 par_objid)
214{ 235{
215 struct reiserfs_de_head * deh; 236 struct reiserfs_de_head *deh;
216 237
217 memset (body, 0, EMPTY_DIR_SIZE_V1); 238 memset(body, 0, EMPTY_DIR_SIZE_V1);
218 deh = (struct reiserfs_de_head *)body; 239 deh = (struct reiserfs_de_head *)body;
219 240
220 /* direntry header of "." */ 241 /* direntry header of "." */
221 put_deh_offset( &(deh[0]), DOT_OFFSET ); 242 put_deh_offset(&(deh[0]), DOT_OFFSET);
222 /* these two are from make_le_item_head, and are are LE */ 243 /* these two are from make_le_item_head, and are are LE */
223 deh[0].deh_dir_id = dirid; 244 deh[0].deh_dir_id = dirid;
224 deh[0].deh_objectid = objid; 245 deh[0].deh_objectid = objid;
225 deh[0].deh_state = 0; /* Endian safe if 0 */ 246 deh[0].deh_state = 0; /* Endian safe if 0 */
226 put_deh_location( &(deh[0]), EMPTY_DIR_SIZE_V1 - strlen( "." )); 247 put_deh_location(&(deh[0]), EMPTY_DIR_SIZE_V1 - strlen("."));
227 mark_de_visible(&(deh[0])); 248 mark_de_visible(&(deh[0]));
228 249
229 /* direntry header of ".." */ 250 /* direntry header of ".." */
230 put_deh_offset( &(deh[1]), DOT_DOT_OFFSET); 251 put_deh_offset(&(deh[1]), DOT_DOT_OFFSET);
231 /* key of ".." for the root directory */ 252 /* key of ".." for the root directory */
232 /* these two are from the inode, and are are LE */ 253 /* these two are from the inode, and are are LE */
233 deh[1].deh_dir_id = par_dirid; 254 deh[1].deh_dir_id = par_dirid;
234 deh[1].deh_objectid = par_objid; 255 deh[1].deh_objectid = par_objid;
235 deh[1].deh_state = 0; /* Endian safe if 0 */ 256 deh[1].deh_state = 0; /* Endian safe if 0 */
236 put_deh_location( &(deh[1]), deh_location( &(deh[0]) ) - strlen( ".." ) ); 257 put_deh_location(&(deh[1]), deh_location(&(deh[0])) - strlen(".."));
237 mark_de_visible(&(deh[1])); 258 mark_de_visible(&(deh[1]));
238 259
239 /* copy ".." and "." */ 260 /* copy ".." and "." */
240 memcpy (body + deh_location( &(deh[0]) ), ".", 1); 261 memcpy(body + deh_location(&(deh[0])), ".", 1);
241 memcpy (body + deh_location( &(deh[1]) ), "..", 2); 262 memcpy(body + deh_location(&(deh[1])), "..", 2);
242} 263}
243 264
244/* compose directory item containing "." and ".." entries */ 265/* compose directory item containing "." and ".." entries */
245void make_empty_dir_item (char * body, __le32 dirid, __le32 objid, 266void make_empty_dir_item(char *body, __le32 dirid, __le32 objid,
246 __le32 par_dirid, __le32 par_objid) 267 __le32 par_dirid, __le32 par_objid)
247{ 268{
248 struct reiserfs_de_head * deh; 269 struct reiserfs_de_head *deh;
249 270
250 memset (body, 0, EMPTY_DIR_SIZE); 271 memset(body, 0, EMPTY_DIR_SIZE);
251 deh = (struct reiserfs_de_head *)body; 272 deh = (struct reiserfs_de_head *)body;
252 273
253 /* direntry header of "." */ 274 /* direntry header of "." */
254 put_deh_offset( &(deh[0]), DOT_OFFSET ); 275 put_deh_offset(&(deh[0]), DOT_OFFSET);
255 /* these two are from make_le_item_head, and are are LE */ 276 /* these two are from make_le_item_head, and are are LE */
256 deh[0].deh_dir_id = dirid; 277 deh[0].deh_dir_id = dirid;
257 deh[0].deh_objectid = objid; 278 deh[0].deh_objectid = objid;
258 deh[0].deh_state = 0; /* Endian safe if 0 */ 279 deh[0].deh_state = 0; /* Endian safe if 0 */
259 put_deh_location( &(deh[0]), EMPTY_DIR_SIZE - ROUND_UP( strlen( "." ) ) ); 280 put_deh_location(&(deh[0]), EMPTY_DIR_SIZE - ROUND_UP(strlen(".")));
260 mark_de_visible(&(deh[0])); 281 mark_de_visible(&(deh[0]));
261 282
262 /* direntry header of ".." */ 283 /* direntry header of ".." */
263 put_deh_offset( &(deh[1]), DOT_DOT_OFFSET ); 284 put_deh_offset(&(deh[1]), DOT_DOT_OFFSET);
264 /* key of ".." for the root directory */ 285 /* key of ".." for the root directory */
265 /* these two are from the inode, and are are LE */ 286 /* these two are from the inode, and are are LE */
266 deh[1].deh_dir_id = par_dirid; 287 deh[1].deh_dir_id = par_dirid;
267 deh[1].deh_objectid = par_objid; 288 deh[1].deh_objectid = par_objid;
268 deh[1].deh_state = 0; /* Endian safe if 0 */ 289 deh[1].deh_state = 0; /* Endian safe if 0 */
269 put_deh_location( &(deh[1]), deh_location( &(deh[0])) - ROUND_UP( strlen( ".." ) ) ); 290 put_deh_location(&(deh[1]),
270 mark_de_visible(&(deh[1])); 291 deh_location(&(deh[0])) - ROUND_UP(strlen("..")));
271 292 mark_de_visible(&(deh[1]));
272 /* copy ".." and "." */ 293
273 memcpy (body + deh_location( &(deh[0]) ), ".", 1); 294 /* copy ".." and "." */
274 memcpy (body + deh_location( &(deh[1]) ), "..", 2); 295 memcpy(body + deh_location(&(deh[0])), ".", 1);
296 memcpy(body + deh_location(&(deh[1])), "..", 2);
275} 297}
diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
index 2118db2896c7..b2264ba3cc56 100644
--- a/fs/reiserfs/do_balan.c
+++ b/fs/reiserfs/do_balan.c
@@ -8,7 +8,6 @@
8/* balance the tree according to the analysis made before, */ 8/* balance the tree according to the analysis made before, */
9/* and using buffers obtained after all above. */ 9/* and using buffers obtained after all above. */
10 10
11
12/** 11/**
13 ** balance_leaf_when_delete 12 ** balance_leaf_when_delete
14 ** balance_leaf 13 ** balance_leaf
@@ -24,23 +23,22 @@
24 23
25#ifdef CONFIG_REISERFS_CHECK 24#ifdef CONFIG_REISERFS_CHECK
26 25
27struct tree_balance * cur_tb = NULL; /* detects whether more than one 26struct tree_balance *cur_tb = NULL; /* detects whether more than one
28 copy of tb exists as a means 27 copy of tb exists as a means
29 of checking whether schedule 28 of checking whether schedule
30 is interrupting do_balance */ 29 is interrupting do_balance */
31#endif 30#endif
32 31
33inline void do_balance_mark_leaf_dirty (struct tree_balance * tb, 32inline void do_balance_mark_leaf_dirty(struct tree_balance *tb,
34 struct buffer_head * bh, int flag) 33 struct buffer_head *bh, int flag)
35{ 34{
36 journal_mark_dirty(tb->transaction_handle, 35 journal_mark_dirty(tb->transaction_handle,
37 tb->transaction_handle->t_super, bh) ; 36 tb->transaction_handle->t_super, bh);
38} 37}
39 38
40#define do_balance_mark_internal_dirty do_balance_mark_leaf_dirty 39#define do_balance_mark_internal_dirty do_balance_mark_leaf_dirty
41#define do_balance_mark_sb_dirty do_balance_mark_leaf_dirty 40#define do_balance_mark_sb_dirty do_balance_mark_leaf_dirty
42 41
43
44/* summary: 42/* summary:
45 if deleting something ( tb->insert_size[0] < 0 ) 43 if deleting something ( tb->insert_size[0] < 0 )
46 return(balance_leaf_when_delete()); (flag d handled here) 44 return(balance_leaf_when_delete()); (flag d handled here)
@@ -64,8 +62,6 @@ be performed by do_balance.
64 62
65-Hans */ 63-Hans */
66 64
67
68
69/* Balance leaf node in case of delete or cut: insert_size[0] < 0 65/* Balance leaf node in case of delete or cut: insert_size[0] < 0
70 * 66 *
71 * lnum, rnum can have values >= -1 67 * lnum, rnum can have values >= -1
@@ -73,1384 +69,1933 @@ be performed by do_balance.
73 * 0 means that nothing should be done with the neighbor 69 * 0 means that nothing should be done with the neighbor
74 * >0 means to shift entirely or partly the specified number of items to the neighbor 70 * >0 means to shift entirely or partly the specified number of items to the neighbor
75 */ 71 */
76static int balance_leaf_when_delete (struct tree_balance * tb, int flag) 72static int balance_leaf_when_delete(struct tree_balance *tb, int flag)
77{ 73{
78 struct buffer_head * tbS0 = PATH_PLAST_BUFFER (tb->tb_path); 74 struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
79 int item_pos = PATH_LAST_POSITION (tb->tb_path); 75 int item_pos = PATH_LAST_POSITION(tb->tb_path);
80 int pos_in_item = tb->tb_path->pos_in_item; 76 int pos_in_item = tb->tb_path->pos_in_item;
81 struct buffer_info bi; 77 struct buffer_info bi;
82 int n; 78 int n;
83 struct item_head * ih; 79 struct item_head *ih;
84 80
85 RFALSE( tb->FR[0] && B_LEVEL (tb->FR[0]) != DISK_LEAF_NODE_LEVEL + 1, 81 RFALSE(tb->FR[0] && B_LEVEL(tb->FR[0]) != DISK_LEAF_NODE_LEVEL + 1,
86 "vs- 12000: level: wrong FR %z", tb->FR[0]); 82 "vs- 12000: level: wrong FR %z", tb->FR[0]);
87 RFALSE( tb->blknum[0] > 1, 83 RFALSE(tb->blknum[0] > 1,
88 "PAP-12005: tb->blknum == %d, can not be > 1", tb->blknum[0]); 84 "PAP-12005: tb->blknum == %d, can not be > 1", tb->blknum[0]);
89 RFALSE( ! tb->blknum[0] && ! PATH_H_PPARENT(tb->tb_path, 0), 85 RFALSE(!tb->blknum[0] && !PATH_H_PPARENT(tb->tb_path, 0),
90 "PAP-12010: tree can not be empty"); 86 "PAP-12010: tree can not be empty");
91 87
92 ih = B_N_PITEM_HEAD (tbS0, item_pos); 88 ih = B_N_PITEM_HEAD(tbS0, item_pos);
93 89
94 /* Delete or truncate the item */ 90 /* Delete or truncate the item */
95 91
96 switch (flag) { 92 switch (flag) {
97 case M_DELETE: /* delete item in S[0] */ 93 case M_DELETE: /* delete item in S[0] */
94
95 RFALSE(ih_item_len(ih) + IH_SIZE != -tb->insert_size[0],
96 "vs-12013: mode Delete, insert size %d, ih to be deleted %h",
97 -tb->insert_size[0], ih);
98
99 bi.tb = tb;
100 bi.bi_bh = tbS0;
101 bi.bi_parent = PATH_H_PPARENT(tb->tb_path, 0);
102 bi.bi_position = PATH_H_POSITION(tb->tb_path, 1);
103 leaf_delete_items(&bi, 0, item_pos, 1, -1);
104
105 if (!item_pos && tb->CFL[0]) {
106 if (B_NR_ITEMS(tbS0)) {
107 replace_key(tb, tb->CFL[0], tb->lkey[0], tbS0,
108 0);
109 } else {
110 if (!PATH_H_POSITION(tb->tb_path, 1))
111 replace_key(tb, tb->CFL[0], tb->lkey[0],
112 PATH_H_PPARENT(tb->tb_path,
113 0), 0);
114 }
115 }
98 116
99 RFALSE( ih_item_len(ih) + IH_SIZE != -tb->insert_size[0], 117 RFALSE(!item_pos && !tb->CFL[0],
100 "vs-12013: mode Delete, insert size %d, ih to be deleted %h", 118 "PAP-12020: tb->CFL[0]==%p, tb->L[0]==%p", tb->CFL[0],
101 -tb->insert_size [0], ih); 119 tb->L[0]);
102 120
103 bi.tb = tb; 121 break;
104 bi.bi_bh = tbS0; 122
105 bi.bi_parent = PATH_H_PPARENT (tb->tb_path, 0); 123 case M_CUT:{ /* cut item in S[0] */
106 bi.bi_position = PATH_H_POSITION (tb->tb_path, 1); 124 bi.tb = tb;
107 leaf_delete_items (&bi, 0, item_pos, 1, -1); 125 bi.bi_bh = tbS0;
108 126 bi.bi_parent = PATH_H_PPARENT(tb->tb_path, 0);
109 if ( ! item_pos && tb->CFL[0] ) { 127 bi.bi_position = PATH_H_POSITION(tb->tb_path, 1);
110 if ( B_NR_ITEMS(tbS0) ) { 128 if (is_direntry_le_ih(ih)) {
111 replace_key(tb, tb->CFL[0],tb->lkey[0],tbS0,0); 129
112 } 130 /* UFS unlink semantics are such that you can only delete one directory entry at a time. */
113 else { 131 /* when we cut a directory tb->insert_size[0] means number of entries to be cut (always 1) */
114 if ( ! PATH_H_POSITION (tb->tb_path, 1) ) 132 tb->insert_size[0] = -1;
115 replace_key(tb, tb->CFL[0],tb->lkey[0],PATH_H_PPARENT(tb->tb_path, 0),0); 133 leaf_cut_from_buffer(&bi, item_pos, pos_in_item,
116 } 134 -tb->insert_size[0]);
117 } 135
118 136 RFALSE(!item_pos && !pos_in_item && !tb->CFL[0],
119 RFALSE( ! item_pos && !tb->CFL[0], 137 "PAP-12030: can not change delimiting key. CFL[0]=%p",
120 "PAP-12020: tb->CFL[0]==%p, tb->L[0]==%p", tb->CFL[0], tb->L[0]); 138 tb->CFL[0]);
121 139
122 break; 140 if (!item_pos && !pos_in_item && tb->CFL[0]) {
123 141 replace_key(tb, tb->CFL[0], tb->lkey[0],
124 case M_CUT: { /* cut item in S[0] */ 142 tbS0, 0);
125 bi.tb = tb; 143 }
126 bi.bi_bh = tbS0; 144 } else {
127 bi.bi_parent = PATH_H_PPARENT (tb->tb_path, 0); 145 leaf_cut_from_buffer(&bi, item_pos, pos_in_item,
128 bi.bi_position = PATH_H_POSITION (tb->tb_path, 1); 146 -tb->insert_size[0]);
129 if (is_direntry_le_ih (ih)) { 147
130 148 RFALSE(!ih_item_len(ih),
131 /* UFS unlink semantics are such that you can only delete one directory entry at a time. */ 149 "PAP-12035: cut must leave non-zero dynamic length of item");
132 /* when we cut a directory tb->insert_size[0] means number of entries to be cut (always 1) */ 150 }
133 tb->insert_size[0] = -1; 151 break;
134 leaf_cut_from_buffer (&bi, item_pos, pos_in_item, -tb->insert_size[0]);
135
136 RFALSE( ! item_pos && ! pos_in_item && ! tb->CFL[0],
137 "PAP-12030: can not change delimiting key. CFL[0]=%p",
138 tb->CFL[0]);
139
140 if ( ! item_pos && ! pos_in_item && tb->CFL[0] ) {
141 replace_key(tb, tb->CFL[0],tb->lkey[0],tbS0,0);
142 }
143 } else {
144 leaf_cut_from_buffer (&bi, item_pos, pos_in_item, -tb->insert_size[0]);
145
146 RFALSE( ! ih_item_len(ih),
147 "PAP-12035: cut must leave non-zero dynamic length of item");
148 }
149 break;
150 }
151
152 default:
153 print_cur_tb ("12040");
154 reiserfs_panic (tb->tb_sb, "PAP-12040: balance_leaf_when_delete: unexpectable mode: %s(%d)",
155 (flag == M_PASTE) ? "PASTE" : ((flag == M_INSERT) ? "INSERT" : "UNKNOWN"), flag);
156 }
157
158 /* the rule is that no shifting occurs unless by shifting a node can be freed */
159 n = B_NR_ITEMS(tbS0);
160 if ( tb->lnum[0] ) /* L[0] takes part in balancing */
161 {
162 if ( tb->lnum[0] == -1 ) /* L[0] must be joined with S[0] */
163 {
164 if ( tb->rnum[0] == -1 ) /* R[0] must be also joined with S[0] */
165 {
166 if ( tb->FR[0] == PATH_H_PPARENT(tb->tb_path, 0) )
167 {
168 /* all contents of all the 3 buffers will be in L[0] */
169 if ( PATH_H_POSITION (tb->tb_path, 1) == 0 && 1 < B_NR_ITEMS(tb->FR[0]) )
170 replace_key(tb, tb->CFL[0],tb->lkey[0],tb->FR[0],1);
171
172 leaf_move_items (LEAF_FROM_S_TO_L, tb, n, -1, NULL);
173 leaf_move_items (LEAF_FROM_R_TO_L, tb, B_NR_ITEMS(tb->R[0]), -1, NULL);
174
175 reiserfs_invalidate_buffer (tb, tbS0);
176 reiserfs_invalidate_buffer (tb, tb->R[0]);
177
178 return 0;
179 } 152 }
180 /* all contents of all the 3 buffers will be in R[0] */
181 leaf_move_items (LEAF_FROM_S_TO_R, tb, n, -1, NULL);
182 leaf_move_items (LEAF_FROM_L_TO_R, tb, B_NR_ITEMS(tb->L[0]), -1, NULL);
183 153
184 /* right_delimiting_key is correct in R[0] */ 154 default:
185 replace_key(tb, tb->CFR[0],tb->rkey[0],tb->R[0],0); 155 print_cur_tb("12040");
156 reiserfs_panic(tb->tb_sb,
157 "PAP-12040: balance_leaf_when_delete: unexpectable mode: %s(%d)",
158 (flag ==
159 M_PASTE) ? "PASTE" : ((flag ==
160 M_INSERT) ? "INSERT" :
161 "UNKNOWN"), flag);
162 }
186 163
187 reiserfs_invalidate_buffer (tb, tbS0); 164 /* the rule is that no shifting occurs unless by shifting a node can be freed */
188 reiserfs_invalidate_buffer (tb, tb->L[0]); 165 n = B_NR_ITEMS(tbS0);
166 if (tb->lnum[0]) { /* L[0] takes part in balancing */
167 if (tb->lnum[0] == -1) { /* L[0] must be joined with S[0] */
168 if (tb->rnum[0] == -1) { /* R[0] must be also joined with S[0] */
169 if (tb->FR[0] == PATH_H_PPARENT(tb->tb_path, 0)) {
170 /* all contents of all the 3 buffers will be in L[0] */
171 if (PATH_H_POSITION(tb->tb_path, 1) == 0
172 && 1 < B_NR_ITEMS(tb->FR[0]))
173 replace_key(tb, tb->CFL[0],
174 tb->lkey[0],
175 tb->FR[0], 1);
176
177 leaf_move_items(LEAF_FROM_S_TO_L, tb, n,
178 -1, NULL);
179 leaf_move_items(LEAF_FROM_R_TO_L, tb,
180 B_NR_ITEMS(tb->R[0]),
181 -1, NULL);
182
183 reiserfs_invalidate_buffer(tb, tbS0);
184 reiserfs_invalidate_buffer(tb,
185 tb->R[0]);
186
187 return 0;
188 }
189 /* all contents of all the 3 buffers will be in R[0] */
190 leaf_move_items(LEAF_FROM_S_TO_R, tb, n, -1,
191 NULL);
192 leaf_move_items(LEAF_FROM_L_TO_R, tb,
193 B_NR_ITEMS(tb->L[0]), -1, NULL);
194
195 /* right_delimiting_key is correct in R[0] */
196 replace_key(tb, tb->CFR[0], tb->rkey[0],
197 tb->R[0], 0);
189 198
190 return -1; 199 reiserfs_invalidate_buffer(tb, tbS0);
191 } 200 reiserfs_invalidate_buffer(tb, tb->L[0]);
192 201
193 RFALSE( tb->rnum[0] != 0, 202 return -1;
194 "PAP-12045: rnum must be 0 (%d)", tb->rnum[0]); 203 }
195 /* all contents of L[0] and S[0] will be in L[0] */
196 leaf_shift_left(tb, n, -1);
197 204
198 reiserfs_invalidate_buffer (tb, tbS0); 205 RFALSE(tb->rnum[0] != 0,
206 "PAP-12045: rnum must be 0 (%d)", tb->rnum[0]);
207 /* all contents of L[0] and S[0] will be in L[0] */
208 leaf_shift_left(tb, n, -1);
199 209
200 return 0; 210 reiserfs_invalidate_buffer(tb, tbS0);
211
212 return 0;
213 }
214 /* a part of contents of S[0] will be in L[0] and the rest part of S[0] will be in R[0] */
215
216 RFALSE((tb->lnum[0] + tb->rnum[0] < n) ||
217 (tb->lnum[0] + tb->rnum[0] > n + 1),
218 "PAP-12050: rnum(%d) and lnum(%d) and item number(%d) in S[0] are not consistent",
219 tb->rnum[0], tb->lnum[0], n);
220 RFALSE((tb->lnum[0] + tb->rnum[0] == n) &&
221 (tb->lbytes != -1 || tb->rbytes != -1),
222 "PAP-12055: bad rbytes (%d)/lbytes (%d) parameters when items are not split",
223 tb->rbytes, tb->lbytes);
224 RFALSE((tb->lnum[0] + tb->rnum[0] == n + 1) &&
225 (tb->lbytes < 1 || tb->rbytes != -1),
226 "PAP-12060: bad rbytes (%d)/lbytes (%d) parameters when items are split",
227 tb->rbytes, tb->lbytes);
228
229 leaf_shift_left(tb, tb->lnum[0], tb->lbytes);
230 leaf_shift_right(tb, tb->rnum[0], tb->rbytes);
231
232 reiserfs_invalidate_buffer(tb, tbS0);
233
234 return 0;
201 } 235 }
202 /* a part of contents of S[0] will be in L[0] and the rest part of S[0] will be in R[0] */
203
204 RFALSE( ( tb->lnum[0] + tb->rnum[0] < n ) ||
205 ( tb->lnum[0] + tb->rnum[0] > n+1 ),
206 "PAP-12050: rnum(%d) and lnum(%d) and item number(%d) in S[0] are not consistent",
207 tb->rnum[0], tb->lnum[0], n);
208 RFALSE( ( tb->lnum[0] + tb->rnum[0] == n ) &&
209 (tb->lbytes != -1 || tb->rbytes != -1),
210 "PAP-12055: bad rbytes (%d)/lbytes (%d) parameters when items are not split",
211 tb->rbytes, tb->lbytes);
212 RFALSE( ( tb->lnum[0] + tb->rnum[0] == n + 1 ) &&
213 (tb->lbytes < 1 || tb->rbytes != -1),
214 "PAP-12060: bad rbytes (%d)/lbytes (%d) parameters when items are split",
215 tb->rbytes, tb->lbytes);
216
217 leaf_shift_left (tb, tb->lnum[0], tb->lbytes);
218 leaf_shift_right(tb, tb->rnum[0], tb->rbytes);
219
220 reiserfs_invalidate_buffer (tb, tbS0);
221 236
222 return 0; 237 if (tb->rnum[0] == -1) {
223 } 238 /* all contents of R[0] and S[0] will be in R[0] */
239 leaf_shift_right(tb, n, -1);
240 reiserfs_invalidate_buffer(tb, tbS0);
241 return 0;
242 }
224 243
225 if ( tb->rnum[0] == -1 ) { 244 RFALSE(tb->rnum[0],
226 /* all contents of R[0] and S[0] will be in R[0] */ 245 "PAP-12065: bad rnum parameter must be 0 (%d)", tb->rnum[0]);
227 leaf_shift_right(tb, n, -1);
228 reiserfs_invalidate_buffer (tb, tbS0);
229 return 0; 246 return 0;
230 }
231
232 RFALSE( tb->rnum[0],
233 "PAP-12065: bad rnum parameter must be 0 (%d)", tb->rnum[0]);
234 return 0;
235} 247}
236 248
237 249static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item header of inserted item (this is on little endian) */
238static int balance_leaf (struct tree_balance * tb, 250 const char *body, /* body of inserted item or bytes to paste */
239 struct item_head * ih, /* item header of inserted item (this is on little endian) */ 251 int flag, /* i - insert, d - delete, c - cut, p - paste
240 const char * body, /* body of inserted item or bytes to paste */ 252 (see comment to do_balance) */
241 int flag, /* i - insert, d - delete, c - cut, p - paste 253 struct item_head *insert_key, /* in our processing of one level we sometimes determine what
242 (see comment to do_balance) */ 254 must be inserted into the next higher level. This insertion
243 struct item_head * insert_key, /* in our processing of one level we sometimes determine what 255 consists of a key or two keys and their corresponding
244 must be inserted into the next higher level. This insertion 256 pointers */
245 consists of a key or two keys and their corresponding 257 struct buffer_head **insert_ptr /* inserted node-ptrs for the next level */
246 pointers */
247 struct buffer_head ** insert_ptr /* inserted node-ptrs for the next level */
248 ) 258 )
249{ 259{
250 struct buffer_head * tbS0 = PATH_PLAST_BUFFER (tb->tb_path); 260 struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
251 int item_pos = PATH_LAST_POSITION (tb->tb_path); /* index into the array of item headers in S[0] 261 int item_pos = PATH_LAST_POSITION(tb->tb_path); /* index into the array of item headers in S[0]
252 of the affected item */ 262 of the affected item */
253 struct buffer_info bi; 263 struct buffer_info bi;
254 struct buffer_head *S_new[2]; /* new nodes allocated to hold what could not fit into S */ 264 struct buffer_head *S_new[2]; /* new nodes allocated to hold what could not fit into S */
255 int snum[2]; /* number of items that will be placed 265 int snum[2]; /* number of items that will be placed
256 into S_new (includes partially shifted 266 into S_new (includes partially shifted
257 items) */ 267 items) */
258 int sbytes[2]; /* if an item is partially shifted into S_new then 268 int sbytes[2]; /* if an item is partially shifted into S_new then
259 if it is a directory item 269 if it is a directory item
260 it is the number of entries from the item that are shifted into S_new 270 it is the number of entries from the item that are shifted into S_new
261 else 271 else
262 it is the number of bytes from the item that are shifted into S_new 272 it is the number of bytes from the item that are shifted into S_new
263 */ 273 */
264 int n, i; 274 int n, i;
265 int ret_val; 275 int ret_val;
266 int pos_in_item; 276 int pos_in_item;
267 int zeros_num; 277 int zeros_num;
268 278
269 PROC_INFO_INC( tb -> tb_sb, balance_at[ 0 ] ); 279 PROC_INFO_INC(tb->tb_sb, balance_at[0]);
270 280
271 /* Make balance in case insert_size[0] < 0 */ 281 /* Make balance in case insert_size[0] < 0 */
272 if ( tb->insert_size[0] < 0 ) 282 if (tb->insert_size[0] < 0)
273 return balance_leaf_when_delete (tb, flag); 283 return balance_leaf_when_delete(tb, flag);
274 284
275 zeros_num = 0; 285 zeros_num = 0;
276 if (flag == M_INSERT && body == 0) 286 if (flag == M_INSERT && body == 0)
277 zeros_num = ih_item_len( ih ); 287 zeros_num = ih_item_len(ih);
278 288
279 pos_in_item = tb->tb_path->pos_in_item; 289 pos_in_item = tb->tb_path->pos_in_item;
280 /* for indirect item pos_in_item is measured in unformatted node 290 /* for indirect item pos_in_item is measured in unformatted node
281 pointers. Recalculate to bytes */ 291 pointers. Recalculate to bytes */
282 if (flag != M_INSERT && is_indirect_le_ih (B_N_PITEM_HEAD (tbS0, item_pos))) 292 if (flag != M_INSERT
283 pos_in_item *= UNFM_P_SIZE; 293 && is_indirect_le_ih(B_N_PITEM_HEAD(tbS0, item_pos)))
284 294 pos_in_item *= UNFM_P_SIZE;
285 if ( tb->lnum[0] > 0 ) { 295
286 /* Shift lnum[0] items from S[0] to the left neighbor L[0] */ 296 if (tb->lnum[0] > 0) {
287 if ( item_pos < tb->lnum[0] ) { 297 /* Shift lnum[0] items from S[0] to the left neighbor L[0] */
288 /* new item or it part falls to L[0], shift it too */ 298 if (item_pos < tb->lnum[0]) {
289 n = B_NR_ITEMS(tb->L[0]); 299 /* new item or it part falls to L[0], shift it too */
290 300 n = B_NR_ITEMS(tb->L[0]);
291 switch (flag) { 301
292 case M_INSERT: /* insert item into L[0] */ 302 switch (flag) {
293 303 case M_INSERT: /* insert item into L[0] */
294 if ( item_pos == tb->lnum[0] - 1 && tb->lbytes != -1 ) { 304
295 /* part of new item falls into L[0] */ 305 if (item_pos == tb->lnum[0] - 1
296 int new_item_len; 306 && tb->lbytes != -1) {
297 int version; 307 /* part of new item falls into L[0] */
298 308 int new_item_len;
299 ret_val = leaf_shift_left (tb, tb->lnum[0]-1, -1); 309 int version;
300 310
301 /* Calculate item length to insert to S[0] */ 311 ret_val =
302 new_item_len = ih_item_len(ih) - tb->lbytes; 312 leaf_shift_left(tb, tb->lnum[0] - 1,
303 /* Calculate and check item length to insert to L[0] */ 313 -1);
304 put_ih_item_len(ih, ih_item_len(ih) - new_item_len ); 314
305 315 /* Calculate item length to insert to S[0] */
306 RFALSE( ih_item_len(ih) <= 0, 316 new_item_len =
307 "PAP-12080: there is nothing to insert into L[0]: ih_item_len=%d", 317 ih_item_len(ih) - tb->lbytes;
308 ih_item_len(ih)); 318 /* Calculate and check item length to insert to L[0] */
309 319 put_ih_item_len(ih,
310 /* Insert new item into L[0] */ 320 ih_item_len(ih) -
311 bi.tb = tb; 321 new_item_len);
312 bi.bi_bh = tb->L[0]; 322
313 bi.bi_parent = tb->FL[0]; 323 RFALSE(ih_item_len(ih) <= 0,
314 bi.bi_position = get_left_neighbor_position (tb, 0); 324 "PAP-12080: there is nothing to insert into L[0]: ih_item_len=%d",
315 leaf_insert_into_buf (&bi, n + item_pos - ret_val, ih, body, 325 ih_item_len(ih));
316 zeros_num > ih_item_len(ih) ? ih_item_len(ih) : zeros_num); 326
317 327 /* Insert new item into L[0] */
318 version = ih_version (ih); 328 bi.tb = tb;
319 329 bi.bi_bh = tb->L[0];
320 /* Calculate key component, item length and body to insert into S[0] */ 330 bi.bi_parent = tb->FL[0];
321 set_le_ih_k_offset( ih, le_ih_k_offset( ih ) + (tb->lbytes << (is_indirect_le_ih(ih)?tb->tb_sb->s_blocksize_bits - UNFM_P_SHIFT:0)) ); 331 bi.bi_position =
322 332 get_left_neighbor_position(tb, 0);
323 put_ih_item_len( ih, new_item_len ); 333 leaf_insert_into_buf(&bi,
324 if ( tb->lbytes > zeros_num ) { 334 n + item_pos -
325 body += (tb->lbytes - zeros_num); 335 ret_val, ih, body,
326 zeros_num = 0; 336 zeros_num >
327 } 337 ih_item_len(ih) ?
328 else 338 ih_item_len(ih) :
329 zeros_num -= tb->lbytes; 339 zeros_num);
330 340
331 RFALSE( ih_item_len(ih) <= 0, 341 version = ih_version(ih);
332 "PAP-12085: there is nothing to insert into S[0]: ih_item_len=%d", 342
333 ih_item_len(ih)); 343 /* Calculate key component, item length and body to insert into S[0] */
334 } else { 344 set_le_ih_k_offset(ih,
335 /* new item in whole falls into L[0] */ 345 le_ih_k_offset(ih) +
336 /* Shift lnum[0]-1 items to L[0] */ 346 (tb->
337 ret_val = leaf_shift_left(tb, tb->lnum[0]-1, tb->lbytes); 347 lbytes <<
338 /* Insert new item into L[0] */ 348 (is_indirect_le_ih
339 bi.tb = tb; 349 (ih) ? tb->tb_sb->
340 bi.bi_bh = tb->L[0]; 350 s_blocksize_bits -
341 bi.bi_parent = tb->FL[0]; 351 UNFM_P_SHIFT :
342 bi.bi_position = get_left_neighbor_position (tb, 0); 352 0)));
343 leaf_insert_into_buf (&bi, n + item_pos - ret_val, ih, body, zeros_num); 353
344 tb->insert_size[0] = 0; 354 put_ih_item_len(ih, new_item_len);
345 zeros_num = 0; 355 if (tb->lbytes > zeros_num) {
346 } 356 body +=
347 break; 357 (tb->lbytes - zeros_num);
348 358 zeros_num = 0;
349 case M_PASTE: /* append item in L[0] */ 359 } else
350 360 zeros_num -= tb->lbytes;
351 if ( item_pos == tb->lnum[0] - 1 && tb->lbytes != -1 ) { 361
352 /* we must shift the part of the appended item */ 362 RFALSE(ih_item_len(ih) <= 0,
353 if ( is_direntry_le_ih (B_N_PITEM_HEAD (tbS0, item_pos))) { 363 "PAP-12085: there is nothing to insert into S[0]: ih_item_len=%d",
354 364 ih_item_len(ih));
355 RFALSE( zeros_num, 365 } else {
356 "PAP-12090: invalid parameter in case of a directory"); 366 /* new item in whole falls into L[0] */
357 /* directory item */ 367 /* Shift lnum[0]-1 items to L[0] */
358 if ( tb->lbytes > pos_in_item ) { 368 ret_val =
359 /* new directory entry falls into L[0] */ 369 leaf_shift_left(tb, tb->lnum[0] - 1,
360 struct item_head * pasted; 370 tb->lbytes);
361 int l_pos_in_item = pos_in_item; 371 /* Insert new item into L[0] */
362 372 bi.tb = tb;
363 /* Shift lnum[0] - 1 items in whole. Shift lbytes - 1 entries from given directory item */ 373 bi.bi_bh = tb->L[0];
364 ret_val = leaf_shift_left(tb, tb->lnum[0], tb->lbytes - 1); 374 bi.bi_parent = tb->FL[0];
365 if ( ret_val && ! item_pos ) { 375 bi.bi_position =
366 pasted = B_N_PITEM_HEAD(tb->L[0],B_NR_ITEMS(tb->L[0])-1); 376 get_left_neighbor_position(tb, 0);
367 l_pos_in_item += I_ENTRY_COUNT(pasted) - (tb->lbytes-1); 377 leaf_insert_into_buf(&bi,
368 } 378 n + item_pos -
369 379 ret_val, ih, body,
370 /* Append given directory entry to directory item */ 380 zeros_num);
371 bi.tb = tb; 381 tb->insert_size[0] = 0;
372 bi.bi_bh = tb->L[0]; 382 zeros_num = 0;
373 bi.bi_parent = tb->FL[0];
374 bi.bi_position = get_left_neighbor_position (tb, 0);
375 leaf_paste_in_buffer (&bi, n + item_pos - ret_val, l_pos_in_item,
376 tb->insert_size[0], body, zeros_num);
377
378 /* previous string prepared space for pasting new entry, following string pastes this entry */
379
380 /* when we have merge directory item, pos_in_item has been changed too */
381
382 /* paste new directory entry. 1 is entry number */
383 leaf_paste_entries (bi.bi_bh, n + item_pos - ret_val, l_pos_in_item, 1,
384 (struct reiserfs_de_head *)body,
385 body + DEH_SIZE, tb->insert_size[0]
386 );
387 tb->insert_size[0] = 0;
388 } else {
389 /* new directory item doesn't fall into L[0] */
390 /* Shift lnum[0]-1 items in whole. Shift lbytes directory entries from directory item number lnum[0] */
391 leaf_shift_left (tb, tb->lnum[0], tb->lbytes);
392 }
393 /* Calculate new position to append in item body */
394 pos_in_item -= tb->lbytes;
395 }
396 else {
397 /* regular object */
398 RFALSE( tb->lbytes <= 0,
399 "PAP-12095: there is nothing to shift to L[0]. lbytes=%d",
400 tb->lbytes);
401 RFALSE( pos_in_item != ih_item_len(B_N_PITEM_HEAD(tbS0, item_pos)),
402 "PAP-12100: incorrect position to paste: item_len=%d, pos_in_item=%d",
403 ih_item_len(B_N_PITEM_HEAD(tbS0,item_pos)), pos_in_item);
404
405 if ( tb->lbytes >= pos_in_item ) {
406 /* appended item will be in L[0] in whole */
407 int l_n;
408
409 /* this bytes number must be appended to the last item of L[h] */
410 l_n = tb->lbytes - pos_in_item;
411
412 /* Calculate new insert_size[0] */
413 tb->insert_size[0] -= l_n;
414
415 RFALSE( tb->insert_size[0] <= 0,
416 "PAP-12105: there is nothing to paste into L[0]. insert_size=%d",
417 tb->insert_size[0]);
418 ret_val = leaf_shift_left(tb,tb->lnum[0],
419 ih_item_len(B_N_PITEM_HEAD(tbS0,item_pos)));
420 /* Append to body of item in L[0] */
421 bi.tb = tb;
422 bi.bi_bh = tb->L[0];
423 bi.bi_parent = tb->FL[0];
424 bi.bi_position = get_left_neighbor_position (tb, 0);
425 leaf_paste_in_buffer(
426 &bi,n + item_pos - ret_val,
427 ih_item_len( B_N_PITEM_HEAD(tb->L[0],n+item_pos-ret_val)),
428 l_n,body, zeros_num > l_n ? l_n : zeros_num
429 );
430 /* 0-th item in S0 can be only of DIRECT type when l_n != 0*/
431 {
432 int version;
433 int temp_l = l_n;
434
435 RFALSE (ih_item_len (B_N_PITEM_HEAD (tbS0, 0)),
436 "PAP-12106: item length must be 0");
437 RFALSE (comp_short_le_keys (B_N_PKEY (tbS0, 0),
438 B_N_PKEY (tb->L[0],
439 n + item_pos - ret_val)),
440 "PAP-12107: items must be of the same file");
441 if (is_indirect_le_ih(B_N_PITEM_HEAD (tb->L[0],
442 n + item_pos - ret_val))) {
443 temp_l = l_n << (tb->tb_sb->s_blocksize_bits - UNFM_P_SHIFT);
444 } 383 }
445 /* update key of first item in S0 */ 384 break;
446 version = ih_version (B_N_PITEM_HEAD (tbS0, 0)); 385
447 set_le_key_k_offset (version, B_N_PKEY (tbS0, 0), 386 case M_PASTE: /* append item in L[0] */
448 le_key_k_offset (version, B_N_PKEY (tbS0, 0)) + temp_l); 387
449 /* update left delimiting key */ 388 if (item_pos == tb->lnum[0] - 1
450 set_le_key_k_offset (version, B_N_PDELIM_KEY(tb->CFL[0],tb->lkey[0]), 389 && tb->lbytes != -1) {
451 le_key_k_offset (version, B_N_PDELIM_KEY(tb->CFL[0],tb->lkey[0])) + temp_l); 390 /* we must shift the part of the appended item */
452 } 391 if (is_direntry_le_ih
453 392 (B_N_PITEM_HEAD(tbS0, item_pos))) {
454 /* Calculate new body, position in item and insert_size[0] */ 393
455 if ( l_n > zeros_num ) { 394 RFALSE(zeros_num,
456 body += (l_n - zeros_num); 395 "PAP-12090: invalid parameter in case of a directory");
457 zeros_num = 0; 396 /* directory item */
458 } 397 if (tb->lbytes > pos_in_item) {
459 else 398 /* new directory entry falls into L[0] */
460 zeros_num -= l_n; 399 struct item_head
461 pos_in_item = 0; 400 *pasted;
462 401 int l_pos_in_item =
463 RFALSE( comp_short_le_keys 402 pos_in_item;
464 (B_N_PKEY(tbS0,0), 403
465 B_N_PKEY(tb->L[0],B_NR_ITEMS(tb->L[0])-1)) || 404 /* Shift lnum[0] - 1 items in whole. Shift lbytes - 1 entries from given directory item */
466 405 ret_val =
467 !op_is_left_mergeable 406 leaf_shift_left(tb,
468 (B_N_PKEY (tbS0, 0), tbS0->b_size) || 407 tb->
469 !op_is_left_mergeable 408 lnum
470 (B_N_PDELIM_KEY(tb->CFL[0],tb->lkey[0]), 409 [0],
471 tbS0->b_size), 410 tb->
472 "PAP-12120: item must be merge-able with left neighboring item"); 411 lbytes
473 } 412 -
474 else /* only part of the appended item will be in L[0] */ 413 1);
475 { 414 if (ret_val
476 /* Calculate position in item for append in S[0] */ 415 && !item_pos) {
477 pos_in_item -= tb->lbytes; 416 pasted =
478 417 B_N_PITEM_HEAD
479 RFALSE( pos_in_item <= 0, 418 (tb->L[0],
480 "PAP-12125: no place for paste. pos_in_item=%d", pos_in_item); 419 B_NR_ITEMS
481 420 (tb->
482 /* Shift lnum[0] - 1 items in whole. Shift lbytes - 1 byte from item number lnum[0] */ 421 L[0]) -
483 leaf_shift_left(tb,tb->lnum[0],tb->lbytes); 422 1);
484 } 423 l_pos_in_item +=
485 } 424 I_ENTRY_COUNT
486 } 425 (pasted) -
487 else /* appended item will be in L[0] in whole */ 426 (tb->
488 { 427 lbytes -
489 struct item_head * pasted; 428 1);
490 429 }
491 if ( ! item_pos && op_is_left_mergeable (B_N_PKEY (tbS0, 0), tbS0->b_size) ) 430
492 { /* if we paste into first item of S[0] and it is left mergable */ 431 /* Append given directory entry to directory item */
493 /* then increment pos_in_item by the size of the last item in L[0] */ 432 bi.tb = tb;
494 pasted = B_N_PITEM_HEAD(tb->L[0],n-1); 433 bi.bi_bh = tb->L[0];
495 if ( is_direntry_le_ih (pasted) ) 434 bi.bi_parent =
496 pos_in_item += ih_entry_count(pasted); 435 tb->FL[0];
497 else 436 bi.bi_position =
498 pos_in_item += ih_item_len(pasted); 437 get_left_neighbor_position
438 (tb, 0);
439 leaf_paste_in_buffer
440 (&bi,
441 n + item_pos -
442 ret_val,
443 l_pos_in_item,
444 tb->insert_size[0],
445 body, zeros_num);
446
447 /* previous string prepared space for pasting new entry, following string pastes this entry */
448
449 /* when we have merge directory item, pos_in_item has been changed too */
450
451 /* paste new directory entry. 1 is entry number */
452 leaf_paste_entries(bi.
453 bi_bh,
454 n +
455 item_pos
456 -
457 ret_val,
458 l_pos_in_item,
459 1,
460 (struct
461 reiserfs_de_head
462 *)
463 body,
464 body
465 +
466 DEH_SIZE,
467 tb->
468 insert_size
469 [0]
470 );
471 tb->insert_size[0] = 0;
472 } else {
473 /* new directory item doesn't fall into L[0] */
474 /* Shift lnum[0]-1 items in whole. Shift lbytes directory entries from directory item number lnum[0] */
475 leaf_shift_left(tb,
476 tb->
477 lnum[0],
478 tb->
479 lbytes);
480 }
481 /* Calculate new position to append in item body */
482 pos_in_item -= tb->lbytes;
483 } else {
484 /* regular object */
485 RFALSE(tb->lbytes <= 0,
486 "PAP-12095: there is nothing to shift to L[0]. lbytes=%d",
487 tb->lbytes);
488 RFALSE(pos_in_item !=
489 ih_item_len
490 (B_N_PITEM_HEAD
491 (tbS0, item_pos)),
492 "PAP-12100: incorrect position to paste: item_len=%d, pos_in_item=%d",
493 ih_item_len
494 (B_N_PITEM_HEAD
495 (tbS0, item_pos)),
496 pos_in_item);
497
498 if (tb->lbytes >= pos_in_item) {
499 /* appended item will be in L[0] in whole */
500 int l_n;
501
502 /* this bytes number must be appended to the last item of L[h] */
503 l_n =
504 tb->lbytes -
505 pos_in_item;
506
507 /* Calculate new insert_size[0] */
508 tb->insert_size[0] -=
509 l_n;
510
511 RFALSE(tb->
512 insert_size[0] <=
513 0,
514 "PAP-12105: there is nothing to paste into L[0]. insert_size=%d",
515 tb->
516 insert_size[0]);
517 ret_val =
518 leaf_shift_left(tb,
519 tb->
520 lnum
521 [0],
522 ih_item_len
523 (B_N_PITEM_HEAD
524 (tbS0,
525 item_pos)));
526 /* Append to body of item in L[0] */
527 bi.tb = tb;
528 bi.bi_bh = tb->L[0];
529 bi.bi_parent =
530 tb->FL[0];
531 bi.bi_position =
532 get_left_neighbor_position
533 (tb, 0);
534 leaf_paste_in_buffer
535 (&bi,
536 n + item_pos -
537 ret_val,
538 ih_item_len
539 (B_N_PITEM_HEAD
540 (tb->L[0],
541 n + item_pos -
542 ret_val)), l_n,
543 body,
544 zeros_num >
545 l_n ? l_n :
546 zeros_num);
547 /* 0-th item in S0 can be only of DIRECT type when l_n != 0 */
548 {
549 int version;
550 int temp_l =
551 l_n;
552
553 RFALSE
554 (ih_item_len
555 (B_N_PITEM_HEAD
556 (tbS0,
557 0)),
558 "PAP-12106: item length must be 0");
559 RFALSE
560 (comp_short_le_keys
561 (B_N_PKEY
562 (tbS0, 0),
563 B_N_PKEY
564 (tb->L[0],
565 n +
566 item_pos
567 -
568 ret_val)),
569 "PAP-12107: items must be of the same file");
570 if (is_indirect_le_ih(B_N_PITEM_HEAD(tb->L[0], n + item_pos - ret_val))) {
571 temp_l =
572 l_n
573 <<
574 (tb->
575 tb_sb->
576 s_blocksize_bits
577 -
578 UNFM_P_SHIFT);
579 }
580 /* update key of first item in S0 */
581 version =
582 ih_version
583 (B_N_PITEM_HEAD
584 (tbS0, 0));
585 set_le_key_k_offset
586 (version,
587 B_N_PKEY
588 (tbS0, 0),
589 le_key_k_offset
590 (version,
591 B_N_PKEY
592 (tbS0,
593 0)) +
594 temp_l);
595 /* update left delimiting key */
596 set_le_key_k_offset
597 (version,
598 B_N_PDELIM_KEY
599 (tb->
600 CFL[0],
601 tb->
602 lkey[0]),
603 le_key_k_offset
604 (version,
605 B_N_PDELIM_KEY
606 (tb->
607 CFL[0],
608 tb->
609 lkey[0]))
610 + temp_l);
611 }
612
613 /* Calculate new body, position in item and insert_size[0] */
614 if (l_n > zeros_num) {
615 body +=
616 (l_n -
617 zeros_num);
618 zeros_num = 0;
619 } else
620 zeros_num -=
621 l_n;
622 pos_in_item = 0;
623
624 RFALSE
625 (comp_short_le_keys
626 (B_N_PKEY(tbS0, 0),
627 B_N_PKEY(tb->L[0],
628 B_NR_ITEMS
629 (tb->
630 L[0]) -
631 1))
632 ||
633 !op_is_left_mergeable
634 (B_N_PKEY(tbS0, 0),
635 tbS0->b_size)
636 ||
637 !op_is_left_mergeable
638 (B_N_PDELIM_KEY
639 (tb->CFL[0],
640 tb->lkey[0]),
641 tbS0->b_size),
642 "PAP-12120: item must be merge-able with left neighboring item");
643 } else { /* only part of the appended item will be in L[0] */
644
645 /* Calculate position in item for append in S[0] */
646 pos_in_item -=
647 tb->lbytes;
648
649 RFALSE(pos_in_item <= 0,
650 "PAP-12125: no place for paste. pos_in_item=%d",
651 pos_in_item);
652
653 /* Shift lnum[0] - 1 items in whole. Shift lbytes - 1 byte from item number lnum[0] */
654 leaf_shift_left(tb,
655 tb->
656 lnum[0],
657 tb->
658 lbytes);
659 }
660 }
661 } else { /* appended item will be in L[0] in whole */
662
663 struct item_head *pasted;
664
665 if (!item_pos && op_is_left_mergeable(B_N_PKEY(tbS0, 0), tbS0->b_size)) { /* if we paste into first item of S[0] and it is left mergable */
666 /* then increment pos_in_item by the size of the last item in L[0] */
667 pasted =
668 B_N_PITEM_HEAD(tb->L[0],
669 n - 1);
670 if (is_direntry_le_ih(pasted))
671 pos_in_item +=
672 ih_entry_count
673 (pasted);
674 else
675 pos_in_item +=
676 ih_item_len(pasted);
677 }
678
679 /* Shift lnum[0] - 1 items in whole. Shift lbytes - 1 byte from item number lnum[0] */
680 ret_val =
681 leaf_shift_left(tb, tb->lnum[0],
682 tb->lbytes);
683 /* Append to body of item in L[0] */
684 bi.tb = tb;
685 bi.bi_bh = tb->L[0];
686 bi.bi_parent = tb->FL[0];
687 bi.bi_position =
688 get_left_neighbor_position(tb, 0);
689 leaf_paste_in_buffer(&bi,
690 n + item_pos -
691 ret_val,
692 pos_in_item,
693 tb->insert_size[0],
694 body, zeros_num);
695
696 /* if appended item is directory, paste entry */
697 pasted =
698 B_N_PITEM_HEAD(tb->L[0],
699 n + item_pos -
700 ret_val);
701 if (is_direntry_le_ih(pasted))
702 leaf_paste_entries(bi.bi_bh,
703 n +
704 item_pos -
705 ret_val,
706 pos_in_item,
707 1,
708 (struct
709 reiserfs_de_head
710 *)body,
711 body +
712 DEH_SIZE,
713 tb->
714 insert_size
715 [0]
716 );
717 /* if appended item is indirect item, put unformatted node into un list */
718 if (is_indirect_le_ih(pasted))
719 set_ih_free_space(pasted, 0);
720 tb->insert_size[0] = 0;
721 zeros_num = 0;
722 }
723 break;
724 default: /* cases d and t */
725 reiserfs_panic(tb->tb_sb,
726 "PAP-12130: balance_leaf: lnum > 0: unexpectable mode: %s(%d)",
727 (flag ==
728 M_DELETE) ? "DELETE" : ((flag ==
729 M_CUT)
730 ? "CUT"
731 :
732 "UNKNOWN"),
733 flag);
499 } 734 }
500 735 } else {
501 /* Shift lnum[0] - 1 items in whole. Shift lbytes - 1 byte from item number lnum[0] */ 736 /* new item doesn't fall into L[0] */
502 ret_val = leaf_shift_left(tb,tb->lnum[0],tb->lbytes); 737 leaf_shift_left(tb, tb->lnum[0], tb->lbytes);
503 /* Append to body of item in L[0] */
504 bi.tb = tb;
505 bi.bi_bh = tb->L[0];
506 bi.bi_parent = tb->FL[0];
507 bi.bi_position = get_left_neighbor_position (tb, 0);
508 leaf_paste_in_buffer (&bi, n + item_pos - ret_val, pos_in_item, tb->insert_size[0],
509 body, zeros_num);
510
511 /* if appended item is directory, paste entry */
512 pasted = B_N_PITEM_HEAD (tb->L[0], n + item_pos - ret_val);
513 if (is_direntry_le_ih (pasted))
514 leaf_paste_entries (
515 bi.bi_bh, n + item_pos - ret_val, pos_in_item, 1,
516 (struct reiserfs_de_head *)body, body + DEH_SIZE, tb->insert_size[0]
517 );
518 /* if appended item is indirect item, put unformatted node into un list */
519 if (is_indirect_le_ih (pasted))
520 set_ih_free_space (pasted, 0);
521 tb->insert_size[0] = 0;
522 zeros_num = 0;
523 } 738 }
524 break;
525 default: /* cases d and t */
526 reiserfs_panic (tb->tb_sb, "PAP-12130: balance_leaf: lnum > 0: unexpectable mode: %s(%d)",
527 (flag == M_DELETE) ? "DELETE" : ((flag == M_CUT) ? "CUT" : "UNKNOWN"), flag);
528 }
529 } else {
530 /* new item doesn't fall into L[0] */
531 leaf_shift_left(tb,tb->lnum[0],tb->lbytes);
532 } 739 }
533 } /* tb->lnum[0] > 0 */
534 740
535 /* Calculate new item position */ 741 /* tb->lnum[0] > 0 */
536 item_pos -= ( tb->lnum[0] - (( tb->lbytes != -1 ) ? 1 : 0)); 742 /* Calculate new item position */
537 743 item_pos -= (tb->lnum[0] - ((tb->lbytes != -1) ? 1 : 0));
538 if ( tb->rnum[0] > 0 ) { 744
539 /* shift rnum[0] items from S[0] to the right neighbor R[0] */ 745 if (tb->rnum[0] > 0) {
540 n = B_NR_ITEMS(tbS0); 746 /* shift rnum[0] items from S[0] to the right neighbor R[0] */
541 switch ( flag ) { 747 n = B_NR_ITEMS(tbS0);
542 748 switch (flag) {
543 case M_INSERT: /* insert item */ 749
544 if ( n - tb->rnum[0] < item_pos ) 750 case M_INSERT: /* insert item */
545 { /* new item or its part falls to R[0] */ 751 if (n - tb->rnum[0] < item_pos) { /* new item or its part falls to R[0] */
546 if ( item_pos == n - tb->rnum[0] + 1 && tb->rbytes != -1 ) 752 if (item_pos == n - tb->rnum[0] + 1 && tb->rbytes != -1) { /* part of new item falls into R[0] */
547 { /* part of new item falls into R[0] */ 753 loff_t old_key_comp, old_len,
548 loff_t old_key_comp, old_len, r_zeros_number; 754 r_zeros_number;
549 const char * r_body; 755 const char *r_body;
550 int version; 756 int version;
551 loff_t offset; 757 loff_t offset;
552 758
553 leaf_shift_right(tb,tb->rnum[0]-1,-1); 759 leaf_shift_right(tb, tb->rnum[0] - 1,
554 760 -1);
555 version = ih_version(ih); 761
556 /* Remember key component and item length */ 762 version = ih_version(ih);
557 old_key_comp = le_ih_k_offset( ih ); 763 /* Remember key component and item length */
558 old_len = ih_item_len(ih); 764 old_key_comp = le_ih_k_offset(ih);
559 765 old_len = ih_item_len(ih);
560 /* Calculate key component and item length to insert into R[0] */ 766
561 offset = le_ih_k_offset( ih ) + ((old_len - tb->rbytes )<<(is_indirect_le_ih(ih)?tb->tb_sb->s_blocksize_bits - UNFM_P_SHIFT:0)); 767 /* Calculate key component and item length to insert into R[0] */
562 set_le_ih_k_offset( ih, offset ); 768 offset =
563 put_ih_item_len( ih, tb->rbytes); 769 le_ih_k_offset(ih) +
564 /* Insert part of the item into R[0] */ 770 ((old_len -
565 bi.tb = tb; 771 tb->
566 bi.bi_bh = tb->R[0]; 772 rbytes) << (is_indirect_le_ih(ih)
567 bi.bi_parent = tb->FR[0]; 773 ? tb->tb_sb->
568 bi.bi_position = get_right_neighbor_position (tb, 0); 774 s_blocksize_bits -
569 if ( (old_len - tb->rbytes) > zeros_num ) { 775 UNFM_P_SHIFT : 0));
570 r_zeros_number = 0; 776 set_le_ih_k_offset(ih, offset);
571 r_body = body + (old_len - tb->rbytes) - zeros_num; 777 put_ih_item_len(ih, tb->rbytes);
572 } 778 /* Insert part of the item into R[0] */
573 else { 779 bi.tb = tb;
574 r_body = body; 780 bi.bi_bh = tb->R[0];
575 r_zeros_number = zeros_num - (old_len - tb->rbytes); 781 bi.bi_parent = tb->FR[0];
576 zeros_num -= r_zeros_number; 782 bi.bi_position =
577 } 783 get_right_neighbor_position(tb, 0);
578 784 if ((old_len - tb->rbytes) > zeros_num) {
579 leaf_insert_into_buf (&bi, 0, ih, r_body, r_zeros_number); 785 r_zeros_number = 0;
580 786 r_body =
581 /* Replace right delimiting key by first key in R[0] */ 787 body + (old_len -
582 replace_key(tb, tb->CFR[0],tb->rkey[0],tb->R[0],0); 788 tb->rbytes) -
583 789 zeros_num;
584 /* Calculate key component and item length to insert into S[0] */ 790 } else {
585 set_le_ih_k_offset( ih, old_key_comp ); 791 r_body = body;
586 put_ih_item_len( ih, old_len - tb->rbytes ); 792 r_zeros_number =
587 793 zeros_num - (old_len -
588 tb->insert_size[0] -= tb->rbytes; 794 tb->rbytes);
795 zeros_num -= r_zeros_number;
796 }
797
798 leaf_insert_into_buf(&bi, 0, ih, r_body,
799 r_zeros_number);
800
801 /* Replace right delimiting key by first key in R[0] */
802 replace_key(tb, tb->CFR[0], tb->rkey[0],
803 tb->R[0], 0);
804
805 /* Calculate key component and item length to insert into S[0] */
806 set_le_ih_k_offset(ih, old_key_comp);
807 put_ih_item_len(ih,
808 old_len - tb->rbytes);
809
810 tb->insert_size[0] -= tb->rbytes;
811
812 } else { /* whole new item falls into R[0] */
813
814 /* Shift rnum[0]-1 items to R[0] */
815 ret_val =
816 leaf_shift_right(tb,
817 tb->rnum[0] - 1,
818 tb->rbytes);
819 /* Insert new item into R[0] */
820 bi.tb = tb;
821 bi.bi_bh = tb->R[0];
822 bi.bi_parent = tb->FR[0];
823 bi.bi_position =
824 get_right_neighbor_position(tb, 0);
825 leaf_insert_into_buf(&bi,
826 item_pos - n +
827 tb->rnum[0] - 1,
828 ih, body,
829 zeros_num);
830
831 if (item_pos - n + tb->rnum[0] - 1 == 0) {
832 replace_key(tb, tb->CFR[0],
833 tb->rkey[0],
834 tb->R[0], 0);
835
836 }
837 zeros_num = tb->insert_size[0] = 0;
838 }
839 } else { /* new item or part of it doesn't fall into R[0] */
589 840
590 } 841 leaf_shift_right(tb, tb->rnum[0], tb->rbytes);
591 else /* whole new item falls into R[0] */
592 {
593 /* Shift rnum[0]-1 items to R[0] */
594 ret_val = leaf_shift_right(tb,tb->rnum[0]-1,tb->rbytes);
595 /* Insert new item into R[0] */
596 bi.tb = tb;
597 bi.bi_bh = tb->R[0];
598 bi.bi_parent = tb->FR[0];
599 bi.bi_position = get_right_neighbor_position (tb, 0);
600 leaf_insert_into_buf (&bi, item_pos - n + tb->rnum[0] - 1, ih, body, zeros_num);
601
602 if ( item_pos - n + tb->rnum[0] - 1 == 0 ) {
603 replace_key(tb, tb->CFR[0],tb->rkey[0],tb->R[0],0);
604
605 }
606 zeros_num = tb->insert_size[0] = 0;
607 }
608 }
609 else /* new item or part of it doesn't fall into R[0] */
610 {
611 leaf_shift_right(tb,tb->rnum[0],tb->rbytes);
612 }
613 break;
614
615 case M_PASTE: /* append item */
616
617 if ( n - tb->rnum[0] <= item_pos ) /* pasted item or part of it falls to R[0] */
618 {
619 if ( item_pos == n - tb->rnum[0] && tb->rbytes != -1 )
620 { /* we must shift the part of the appended item */
621 if ( is_direntry_le_ih (B_N_PITEM_HEAD(tbS0, item_pos)))
622 { /* we append to directory item */
623 int entry_count;
624
625 RFALSE( zeros_num,
626 "PAP-12145: invalid parameter in case of a directory");
627 entry_count = I_ENTRY_COUNT(B_N_PITEM_HEAD(tbS0, item_pos));
628 if ( entry_count - tb->rbytes < pos_in_item )
629 /* new directory entry falls into R[0] */
630 {
631 int paste_entry_position;
632
633 RFALSE( tb->rbytes - 1 >= entry_count ||
634 ! tb->insert_size[0],
635 "PAP-12150: no enough of entries to shift to R[0]: rbytes=%d, entry_count=%d",
636 tb->rbytes, entry_count);
637 /* Shift rnum[0]-1 items in whole. Shift rbytes-1 directory entries from directory item number rnum[0] */
638 leaf_shift_right(tb,tb->rnum[0],tb->rbytes - 1);
639 /* Paste given directory entry to directory item */
640 paste_entry_position = pos_in_item - entry_count + tb->rbytes - 1;
641 bi.tb = tb;
642 bi.bi_bh = tb->R[0];
643 bi.bi_parent = tb->FR[0];
644 bi.bi_position = get_right_neighbor_position (tb, 0);
645 leaf_paste_in_buffer (&bi, 0, paste_entry_position,
646 tb->insert_size[0],body,zeros_num);
647 /* paste entry */
648 leaf_paste_entries (
649 bi.bi_bh, 0, paste_entry_position, 1, (struct reiserfs_de_head *)body,
650 body + DEH_SIZE, tb->insert_size[0]
651 );
652
653 if ( paste_entry_position == 0 ) {
654 /* change delimiting keys */
655 replace_key(tb, tb->CFR[0],tb->rkey[0],tb->R[0],0);
656 }
657
658 tb->insert_size[0] = 0;
659 pos_in_item++;
660 }
661 else /* new directory entry doesn't fall into R[0] */
662 {
663 leaf_shift_right(tb,tb->rnum[0],tb->rbytes);
664 }
665 }
666 else /* regular object */
667 {
668 int n_shift, n_rem, r_zeros_number;
669 const char * r_body;
670
671 /* Calculate number of bytes which must be shifted from appended item */
672 if ( (n_shift = tb->rbytes - tb->insert_size[0]) < 0 )
673 n_shift = 0;
674
675 RFALSE(pos_in_item != ih_item_len(B_N_PITEM_HEAD (tbS0, item_pos)),
676 "PAP-12155: invalid position to paste. ih_item_len=%d, pos_in_item=%d",
677 pos_in_item, ih_item_len( B_N_PITEM_HEAD(tbS0,item_pos)));
678
679 leaf_shift_right(tb,tb->rnum[0],n_shift);
680 /* Calculate number of bytes which must remain in body after appending to R[0] */
681 if ( (n_rem = tb->insert_size[0] - tb->rbytes) < 0 )
682 n_rem = 0;
683
684 {
685 int version;
686 unsigned long temp_rem = n_rem;
687
688 version = ih_version (B_N_PITEM_HEAD (tb->R[0],0));
689 if (is_indirect_le_key(version,B_N_PKEY(tb->R[0],0))){
690 temp_rem = n_rem << (tb->tb_sb->s_blocksize_bits -
691 UNFM_P_SHIFT);
692 }
693 set_le_key_k_offset (version, B_N_PKEY(tb->R[0],0),
694 le_key_k_offset (version, B_N_PKEY(tb->R[0],0)) + temp_rem);
695 set_le_key_k_offset (version, B_N_PDELIM_KEY(tb->CFR[0],tb->rkey[0]),
696 le_key_k_offset (version, B_N_PDELIM_KEY(tb->CFR[0],tb->rkey[0])) + temp_rem);
697 } 842 }
843 break;
844
845 case M_PASTE: /* append item */
846
847 if (n - tb->rnum[0] <= item_pos) { /* pasted item or part of it falls to R[0] */
848 if (item_pos == n - tb->rnum[0] && tb->rbytes != -1) { /* we must shift the part of the appended item */
849 if (is_direntry_le_ih(B_N_PITEM_HEAD(tbS0, item_pos))) { /* we append to directory item */
850 int entry_count;
851
852 RFALSE(zeros_num,
853 "PAP-12145: invalid parameter in case of a directory");
854 entry_count =
855 I_ENTRY_COUNT(B_N_PITEM_HEAD
856 (tbS0,
857 item_pos));
858 if (entry_count - tb->rbytes <
859 pos_in_item)
860 /* new directory entry falls into R[0] */
861 {
862 int paste_entry_position;
863
864 RFALSE(tb->rbytes - 1 >=
865 entry_count
866 || !tb->
867 insert_size[0],
868 "PAP-12150: no enough of entries to shift to R[0]: rbytes=%d, entry_count=%d",
869 tb->rbytes,
870 entry_count);
871 /* Shift rnum[0]-1 items in whole. Shift rbytes-1 directory entries from directory item number rnum[0] */
872 leaf_shift_right(tb,
873 tb->
874 rnum
875 [0],
876 tb->
877 rbytes
878 - 1);
879 /* Paste given directory entry to directory item */
880 paste_entry_position =
881 pos_in_item -
882 entry_count +
883 tb->rbytes - 1;
884 bi.tb = tb;
885 bi.bi_bh = tb->R[0];
886 bi.bi_parent =
887 tb->FR[0];
888 bi.bi_position =
889 get_right_neighbor_position
890 (tb, 0);
891 leaf_paste_in_buffer
892 (&bi, 0,
893 paste_entry_position,
894 tb->insert_size[0],
895 body, zeros_num);
896 /* paste entry */
897 leaf_paste_entries(bi.
898 bi_bh,
899 0,
900 paste_entry_position,
901 1,
902 (struct
903 reiserfs_de_head
904 *)
905 body,
906 body
907 +
908 DEH_SIZE,
909 tb->
910 insert_size
911 [0]
912 );
913
914 if (paste_entry_position
915 == 0) {
916 /* change delimiting keys */
917 replace_key(tb,
918 tb->
919 CFR
920 [0],
921 tb->
922 rkey
923 [0],
924 tb->
925 R
926 [0],
927 0);
928 }
929
930 tb->insert_size[0] = 0;
931 pos_in_item++;
932 } else { /* new directory entry doesn't fall into R[0] */
933
934 leaf_shift_right(tb,
935 tb->
936 rnum
937 [0],
938 tb->
939 rbytes);
940 }
941 } else { /* regular object */
942
943 int n_shift, n_rem,
944 r_zeros_number;
945 const char *r_body;
946
947 /* Calculate number of bytes which must be shifted from appended item */
948 if ((n_shift =
949 tb->rbytes -
950 tb->insert_size[0]) < 0)
951 n_shift = 0;
952
953 RFALSE(pos_in_item !=
954 ih_item_len
955 (B_N_PITEM_HEAD
956 (tbS0, item_pos)),
957 "PAP-12155: invalid position to paste. ih_item_len=%d, pos_in_item=%d",
958 pos_in_item,
959 ih_item_len
960 (B_N_PITEM_HEAD
961 (tbS0, item_pos)));
962
963 leaf_shift_right(tb,
964 tb->rnum[0],
965 n_shift);
966 /* Calculate number of bytes which must remain in body after appending to R[0] */
967 if ((n_rem =
968 tb->insert_size[0] -
969 tb->rbytes) < 0)
970 n_rem = 0;
971
972 {
973 int version;
974 unsigned long temp_rem =
975 n_rem;
976
977 version =
978 ih_version
979 (B_N_PITEM_HEAD
980 (tb->R[0], 0));
981 if (is_indirect_le_key
982 (version,
983 B_N_PKEY(tb->R[0],
984 0))) {
985 temp_rem =
986 n_rem <<
987 (tb->tb_sb->
988 s_blocksize_bits
989 -
990 UNFM_P_SHIFT);
991 }
992 set_le_key_k_offset
993 (version,
994 B_N_PKEY(tb->R[0],
995 0),
996 le_key_k_offset
997 (version,
998 B_N_PKEY(tb->R[0],
999 0)) +
1000 temp_rem);
1001 set_le_key_k_offset
1002 (version,
1003 B_N_PDELIM_KEY(tb->
1004 CFR
1005 [0],
1006 tb->
1007 rkey
1008 [0]),
1009 le_key_k_offset
1010 (version,
1011 B_N_PDELIM_KEY
1012 (tb->CFR[0],
1013 tb->rkey[0])) +
1014 temp_rem);
1015 }
698/* k_offset (B_N_PKEY(tb->R[0],0)) += n_rem; 1016/* k_offset (B_N_PKEY(tb->R[0],0)) += n_rem;
699 k_offset (B_N_PDELIM_KEY(tb->CFR[0],tb->rkey[0])) += n_rem;*/ 1017 k_offset (B_N_PDELIM_KEY(tb->CFR[0],tb->rkey[0])) += n_rem;*/
700 do_balance_mark_internal_dirty (tb, tb->CFR[0], 0); 1018 do_balance_mark_internal_dirty
701 1019 (tb, tb->CFR[0], 0);
702 /* Append part of body into R[0] */ 1020
703 bi.tb = tb; 1021 /* Append part of body into R[0] */
704 bi.bi_bh = tb->R[0]; 1022 bi.tb = tb;
705 bi.bi_parent = tb->FR[0]; 1023 bi.bi_bh = tb->R[0];
706 bi.bi_position = get_right_neighbor_position (tb, 0); 1024 bi.bi_parent = tb->FR[0];
707 if ( n_rem > zeros_num ) { 1025 bi.bi_position =
708 r_zeros_number = 0; 1026 get_right_neighbor_position
709 r_body = body + n_rem - zeros_num; 1027 (tb, 0);
710 } 1028 if (n_rem > zeros_num) {
711 else { 1029 r_zeros_number = 0;
712 r_body = body; 1030 r_body =
713 r_zeros_number = zeros_num - n_rem; 1031 body + n_rem -
714 zeros_num -= r_zeros_number; 1032 zeros_num;
715 } 1033 } else {
716 1034 r_body = body;
717 leaf_paste_in_buffer(&bi, 0, n_shift, tb->insert_size[0] - n_rem, r_body, r_zeros_number); 1035 r_zeros_number =
718 1036 zeros_num - n_rem;
719 if (is_indirect_le_ih (B_N_PITEM_HEAD(tb->R[0],0))) { 1037 zeros_num -=
1038 r_zeros_number;
1039 }
1040
1041 leaf_paste_in_buffer(&bi, 0,
1042 n_shift,
1043 tb->
1044 insert_size
1045 [0] -
1046 n_rem,
1047 r_body,
1048 r_zeros_number);
1049
1050 if (is_indirect_le_ih
1051 (B_N_PITEM_HEAD
1052 (tb->R[0], 0))) {
720#if 0 1053#if 0
721 RFALSE( n_rem, 1054 RFALSE(n_rem,
722 "PAP-12160: paste more than one unformatted node pointer"); 1055 "PAP-12160: paste more than one unformatted node pointer");
723#endif 1056#endif
724 set_ih_free_space (B_N_PITEM_HEAD(tb->R[0],0), 0); 1057 set_ih_free_space
725 } 1058 (B_N_PITEM_HEAD
726 tb->insert_size[0] = n_rem; 1059 (tb->R[0], 0), 0);
727 if ( ! n_rem ) 1060 }
728 pos_in_item ++; 1061 tb->insert_size[0] = n_rem;
729 } 1062 if (!n_rem)
730 } 1063 pos_in_item++;
731 else /* pasted item in whole falls into R[0] */ 1064 }
732 { 1065 } else { /* pasted item in whole falls into R[0] */
733 struct item_head * pasted; 1066
1067 struct item_head *pasted;
1068
1069 ret_val =
1070 leaf_shift_right(tb, tb->rnum[0],
1071 tb->rbytes);
1072 /* append item in R[0] */
1073 if (pos_in_item >= 0) {
1074 bi.tb = tb;
1075 bi.bi_bh = tb->R[0];
1076 bi.bi_parent = tb->FR[0];
1077 bi.bi_position =
1078 get_right_neighbor_position
1079 (tb, 0);
1080 leaf_paste_in_buffer(&bi,
1081 item_pos -
1082 n +
1083 tb->
1084 rnum[0],
1085 pos_in_item,
1086 tb->
1087 insert_size
1088 [0], body,
1089 zeros_num);
1090 }
1091
1092 /* paste new entry, if item is directory item */
1093 pasted =
1094 B_N_PITEM_HEAD(tb->R[0],
1095 item_pos - n +
1096 tb->rnum[0]);
1097 if (is_direntry_le_ih(pasted)
1098 && pos_in_item >= 0) {
1099 leaf_paste_entries(bi.bi_bh,
1100 item_pos -
1101 n +
1102 tb->rnum[0],
1103 pos_in_item,
1104 1,
1105 (struct
1106 reiserfs_de_head
1107 *)body,
1108 body +
1109 DEH_SIZE,
1110 tb->
1111 insert_size
1112 [0]
1113 );
1114 if (!pos_in_item) {
1115
1116 RFALSE(item_pos - n +
1117 tb->rnum[0],
1118 "PAP-12165: directory item must be first item of node when pasting is in 0th position");
1119
1120 /* update delimiting keys */
1121 replace_key(tb,
1122 tb->CFR[0],
1123 tb->rkey[0],
1124 tb->R[0],
1125 0);
1126 }
1127 }
1128
1129 if (is_indirect_le_ih(pasted))
1130 set_ih_free_space(pasted, 0);
1131 zeros_num = tb->insert_size[0] = 0;
1132 }
1133 } else { /* new item doesn't fall into R[0] */
734 1134
735 ret_val = leaf_shift_right(tb,tb->rnum[0],tb->rbytes); 1135 leaf_shift_right(tb, tb->rnum[0], tb->rbytes);
736 /* append item in R[0] */
737 if ( pos_in_item >= 0 ) {
738 bi.tb = tb;
739 bi.bi_bh = tb->R[0];
740 bi.bi_parent = tb->FR[0];
741 bi.bi_position = get_right_neighbor_position (tb, 0);
742 leaf_paste_in_buffer(&bi,item_pos - n + tb->rnum[0], pos_in_item,
743 tb->insert_size[0],body, zeros_num);
744 }
745
746 /* paste new entry, if item is directory item */
747 pasted = B_N_PITEM_HEAD(tb->R[0], item_pos - n + tb->rnum[0]);
748 if (is_direntry_le_ih (pasted) && pos_in_item >= 0 ) {
749 leaf_paste_entries (
750 bi.bi_bh, item_pos - n + tb->rnum[0], pos_in_item, 1,
751 (struct reiserfs_de_head *)body, body + DEH_SIZE, tb->insert_size[0]
752 );
753 if ( ! pos_in_item ) {
754
755 RFALSE( item_pos - n + tb->rnum[0],
756 "PAP-12165: directory item must be first item of node when pasting is in 0th position");
757
758 /* update delimiting keys */
759 replace_key(tb, tb->CFR[0],tb->rkey[0],tb->R[0],0);
760 } 1136 }
761 } 1137 break;
762 1138 default: /* cases d and t */
763 if (is_indirect_le_ih (pasted)) 1139 reiserfs_panic(tb->tb_sb,
764 set_ih_free_space (pasted, 0); 1140 "PAP-12175: balance_leaf: rnum > 0: unexpectable mode: %s(%d)",
765 zeros_num = tb->insert_size[0] = 0; 1141 (flag ==
1142 M_DELETE) ? "DELETE" : ((flag ==
1143 M_CUT) ? "CUT"
1144 : "UNKNOWN"),
1145 flag);
766 } 1146 }
767 }
768 else /* new item doesn't fall into R[0] */
769 {
770 leaf_shift_right(tb,tb->rnum[0],tb->rbytes);
771 }
772 break;
773 default: /* cases d and t */
774 reiserfs_panic (tb->tb_sb, "PAP-12175: balance_leaf: rnum > 0: unexpectable mode: %s(%d)",
775 (flag == M_DELETE) ? "DELETE" : ((flag == M_CUT) ? "CUT" : "UNKNOWN"), flag);
776 }
777
778 } /* tb->rnum[0] > 0 */
779
780
781 RFALSE( tb->blknum[0] > 3,
782 "PAP-12180: blknum can not be %d. It must be <= 3", tb->blknum[0]);
783 RFALSE( tb->blknum[0] < 0,
784 "PAP-12185: blknum can not be %d. It must be >= 0", tb->blknum[0]);
785
786 /* if while adding to a node we discover that it is possible to split
787 it in two, and merge the left part into the left neighbor and the
788 right part into the right neighbor, eliminating the node */
789 if ( tb->blknum[0] == 0 ) { /* node S[0] is empty now */
790
791 RFALSE( ! tb->lnum[0] || ! tb->rnum[0],
792 "PAP-12190: lnum and rnum must not be zero");
793 /* if insertion was done before 0-th position in R[0], right
794 delimiting key of the tb->L[0]'s and left delimiting key are
795 not set correctly */
796 if (tb->CFL[0]) {
797 if (!tb->CFR[0])
798 reiserfs_panic (tb->tb_sb, "vs-12195: balance_leaf: CFR not initialized");
799 copy_key (B_N_PDELIM_KEY (tb->CFL[0], tb->lkey[0]), B_N_PDELIM_KEY (tb->CFR[0], tb->rkey[0]));
800 do_balance_mark_internal_dirty (tb, tb->CFL[0], 0);
801 }
802
803 reiserfs_invalidate_buffer(tb,tbS0);
804 return 0;
805 }
806
807
808 /* Fill new nodes that appear in place of S[0] */
809 1147
810 /* I am told that this copying is because we need an array to enable 1148 }
811 the looping code. -Hans */
812 snum[0] = tb->s1num,
813 snum[1] = tb->s2num;
814 sbytes[0] = tb->s1bytes;
815 sbytes[1] = tb->s2bytes;
816 for( i = tb->blknum[0] - 2; i >= 0; i-- ) {
817
818 RFALSE( !snum[i], "PAP-12200: snum[%d] == %d. Must be > 0", i, snum[i]);
819 1149
820 /* here we shift from S to S_new nodes */ 1150 /* tb->rnum[0] > 0 */
1151 RFALSE(tb->blknum[0] > 3,
1152 "PAP-12180: blknum can not be %d. It must be <= 3",
1153 tb->blknum[0]);
1154 RFALSE(tb->blknum[0] < 0,
1155 "PAP-12185: blknum can not be %d. It must be >= 0",
1156 tb->blknum[0]);
1157
1158 /* if while adding to a node we discover that it is possible to split
1159 it in two, and merge the left part into the left neighbor and the
1160 right part into the right neighbor, eliminating the node */
1161 if (tb->blknum[0] == 0) { /* node S[0] is empty now */
1162
1163 RFALSE(!tb->lnum[0] || !tb->rnum[0],
1164 "PAP-12190: lnum and rnum must not be zero");
1165 /* if insertion was done before 0-th position in R[0], right
1166 delimiting key of the tb->L[0]'s and left delimiting key are
1167 not set correctly */
1168 if (tb->CFL[0]) {
1169 if (!tb->CFR[0])
1170 reiserfs_panic(tb->tb_sb,
1171 "vs-12195: balance_leaf: CFR not initialized");
1172 copy_key(B_N_PDELIM_KEY(tb->CFL[0], tb->lkey[0]),
1173 B_N_PDELIM_KEY(tb->CFR[0], tb->rkey[0]));
1174 do_balance_mark_internal_dirty(tb, tb->CFL[0], 0);
1175 }
821 1176
822 S_new[i] = get_FEB(tb); 1177 reiserfs_invalidate_buffer(tb, tbS0);
1178 return 0;
1179 }
823 1180
824 /* initialized block type and tree level */ 1181 /* Fill new nodes that appear in place of S[0] */
825 set_blkh_level( B_BLK_HEAD(S_new[i]), DISK_LEAF_NODE_LEVEL ); 1182
1183 /* I am told that this copying is because we need an array to enable
1184 the looping code. -Hans */
1185 snum[0] = tb->s1num, snum[1] = tb->s2num;
1186 sbytes[0] = tb->s1bytes;
1187 sbytes[1] = tb->s2bytes;
1188 for (i = tb->blknum[0] - 2; i >= 0; i--) {
1189
1190 RFALSE(!snum[i], "PAP-12200: snum[%d] == %d. Must be > 0", i,
1191 snum[i]);
1192
1193 /* here we shift from S to S_new nodes */
1194
1195 S_new[i] = get_FEB(tb);
1196
1197 /* initialized block type and tree level */
1198 set_blkh_level(B_BLK_HEAD(S_new[i]), DISK_LEAF_NODE_LEVEL);
1199
1200 n = B_NR_ITEMS(tbS0);
1201
1202 switch (flag) {
1203 case M_INSERT: /* insert item */
1204
1205 if (n - snum[i] < item_pos) { /* new item or it's part falls to first new node S_new[i] */
1206 if (item_pos == n - snum[i] + 1 && sbytes[i] != -1) { /* part of new item falls into S_new[i] */
1207 int old_key_comp, old_len,
1208 r_zeros_number;
1209 const char *r_body;
1210 int version;
1211
1212 /* Move snum[i]-1 items from S[0] to S_new[i] */
1213 leaf_move_items(LEAF_FROM_S_TO_SNEW, tb,
1214 snum[i] - 1, -1,
1215 S_new[i]);
1216 /* Remember key component and item length */
1217 version = ih_version(ih);
1218 old_key_comp = le_ih_k_offset(ih);
1219 old_len = ih_item_len(ih);
1220
1221 /* Calculate key component and item length to insert into S_new[i] */
1222 set_le_ih_k_offset(ih,
1223 le_ih_k_offset(ih) +
1224 ((old_len -
1225 sbytes[i]) <<
1226 (is_indirect_le_ih
1227 (ih) ? tb->tb_sb->
1228 s_blocksize_bits -
1229 UNFM_P_SHIFT :
1230 0)));
1231
1232 put_ih_item_len(ih, sbytes[i]);
1233
1234 /* Insert part of the item into S_new[i] before 0-th item */
1235 bi.tb = tb;
1236 bi.bi_bh = S_new[i];
1237 bi.bi_parent = NULL;
1238 bi.bi_position = 0;
1239
1240 if ((old_len - sbytes[i]) > zeros_num) {
1241 r_zeros_number = 0;
1242 r_body =
1243 body + (old_len -
1244 sbytes[i]) -
1245 zeros_num;
1246 } else {
1247 r_body = body;
1248 r_zeros_number =
1249 zeros_num - (old_len -
1250 sbytes[i]);
1251 zeros_num -= r_zeros_number;
1252 }
1253
1254 leaf_insert_into_buf(&bi, 0, ih, r_body,
1255 r_zeros_number);
1256
1257 /* Calculate key component and item length to insert into S[i] */
1258 set_le_ih_k_offset(ih, old_key_comp);
1259 put_ih_item_len(ih,
1260 old_len - sbytes[i]);
1261 tb->insert_size[0] -= sbytes[i];
1262 } else { /* whole new item falls into S_new[i] */
1263
1264 /* Shift snum[0] - 1 items to S_new[i] (sbytes[i] of split item) */
1265 leaf_move_items(LEAF_FROM_S_TO_SNEW, tb,
1266 snum[i] - 1, sbytes[i],
1267 S_new[i]);
1268
1269 /* Insert new item into S_new[i] */
1270 bi.tb = tb;
1271 bi.bi_bh = S_new[i];
1272 bi.bi_parent = NULL;
1273 bi.bi_position = 0;
1274 leaf_insert_into_buf(&bi,
1275 item_pos - n +
1276 snum[i] - 1, ih,
1277 body, zeros_num);
1278
1279 zeros_num = tb->insert_size[0] = 0;
1280 }
1281 }
826 1282
1283 else { /* new item or it part don't falls into S_new[i] */
827 1284
828 n = B_NR_ITEMS(tbS0); 1285 leaf_move_items(LEAF_FROM_S_TO_SNEW, tb,
829 1286 snum[i], sbytes[i], S_new[i]);
830 switch (flag) {
831 case M_INSERT: /* insert item */
832
833 if ( n - snum[i] < item_pos )
834 { /* new item or it's part falls to first new node S_new[i]*/
835 if ( item_pos == n - snum[i] + 1 && sbytes[i] != -1 )
836 { /* part of new item falls into S_new[i] */
837 int old_key_comp, old_len, r_zeros_number;
838 const char * r_body;
839 int version;
840
841 /* Move snum[i]-1 items from S[0] to S_new[i] */
842 leaf_move_items (LEAF_FROM_S_TO_SNEW, tb, snum[i] - 1, -1, S_new[i]);
843 /* Remember key component and item length */
844 version = ih_version (ih);
845 old_key_comp = le_ih_k_offset( ih );
846 old_len = ih_item_len(ih);
847
848 /* Calculate key component and item length to insert into S_new[i] */
849 set_le_ih_k_offset( ih,
850 le_ih_k_offset(ih) + ((old_len - sbytes[i] )<<(is_indirect_le_ih(ih)?tb->tb_sb->s_blocksize_bits - UNFM_P_SHIFT:0)) );
851
852 put_ih_item_len( ih, sbytes[i] );
853
854 /* Insert part of the item into S_new[i] before 0-th item */
855 bi.tb = tb;
856 bi.bi_bh = S_new[i];
857 bi.bi_parent = NULL;
858 bi.bi_position = 0;
859
860 if ( (old_len - sbytes[i]) > zeros_num ) {
861 r_zeros_number = 0;
862 r_body = body + (old_len - sbytes[i]) - zeros_num;
863 }
864 else {
865 r_body = body;
866 r_zeros_number = zeros_num - (old_len - sbytes[i]);
867 zeros_num -= r_zeros_number;
868 }
869
870 leaf_insert_into_buf (&bi, 0, ih, r_body, r_zeros_number);
871
872 /* Calculate key component and item length to insert into S[i] */
873 set_le_ih_k_offset( ih, old_key_comp );
874 put_ih_item_len( ih, old_len - sbytes[i] );
875 tb->insert_size[0] -= sbytes[i];
876 }
877 else /* whole new item falls into S_new[i] */
878 {
879 /* Shift snum[0] - 1 items to S_new[i] (sbytes[i] of split item) */
880 leaf_move_items (LEAF_FROM_S_TO_SNEW, tb, snum[i] - 1, sbytes[i], S_new[i]);
881
882 /* Insert new item into S_new[i] */
883 bi.tb = tb;
884 bi.bi_bh = S_new[i];
885 bi.bi_parent = NULL;
886 bi.bi_position = 0;
887 leaf_insert_into_buf (&bi, item_pos - n + snum[i] - 1, ih, body, zeros_num);
888
889 zeros_num = tb->insert_size[0] = 0;
890 }
891 }
892
893 else /* new item or it part don't falls into S_new[i] */
894 {
895 leaf_move_items (LEAF_FROM_S_TO_SNEW, tb, snum[i], sbytes[i], S_new[i]);
896 }
897 break;
898
899 case M_PASTE: /* append item */
900
901 if ( n - snum[i] <= item_pos ) /* pasted item or part if it falls to S_new[i] */
902 {
903 if ( item_pos == n - snum[i] && sbytes[i] != -1 )
904 { /* we must shift part of the appended item */
905 struct item_head * aux_ih;
906
907 RFALSE( ih, "PAP-12210: ih must be 0");
908
909 if ( is_direntry_le_ih (aux_ih = B_N_PITEM_HEAD(tbS0,item_pos))) {
910 /* we append to directory item */
911
912 int entry_count;
913
914 entry_count = ih_entry_count(aux_ih);
915
916 if ( entry_count - sbytes[i] < pos_in_item && pos_in_item <= entry_count ) {
917 /* new directory entry falls into S_new[i] */
918
919 RFALSE( ! tb->insert_size[0],
920 "PAP-12215: insert_size is already 0");
921 RFALSE( sbytes[i] - 1 >= entry_count,
922 "PAP-12220: there are no so much entries (%d), only %d",
923 sbytes[i] - 1, entry_count);
924
925 /* Shift snum[i]-1 items in whole. Shift sbytes[i] directory entries from directory item number snum[i] */
926 leaf_move_items (LEAF_FROM_S_TO_SNEW, tb, snum[i], sbytes[i]-1, S_new[i]);
927 /* Paste given directory entry to directory item */
928 bi.tb = tb;
929 bi.bi_bh = S_new[i];
930 bi.bi_parent = NULL;
931 bi.bi_position = 0;
932 leaf_paste_in_buffer (&bi, 0, pos_in_item - entry_count + sbytes[i] - 1,
933 tb->insert_size[0], body,zeros_num);
934 /* paste new directory entry */
935 leaf_paste_entries (
936 bi.bi_bh, 0, pos_in_item - entry_count + sbytes[i] - 1,
937 1, (struct reiserfs_de_head *)body, body + DEH_SIZE,
938 tb->insert_size[0]
939 );
940 tb->insert_size[0] = 0;
941 pos_in_item++;
942 } else { /* new directory entry doesn't fall into S_new[i] */
943 leaf_move_items (LEAF_FROM_S_TO_SNEW, tb, snum[i], sbytes[i], S_new[i]);
944 } 1287 }
945 } 1288 break;
946 else /* regular object */ 1289
947 { 1290 case M_PASTE: /* append item */
948 int n_shift, n_rem, r_zeros_number; 1291
949 const char * r_body; 1292 if (n - snum[i] <= item_pos) { /* pasted item or part if it falls to S_new[i] */
950 1293 if (item_pos == n - snum[i] && sbytes[i] != -1) { /* we must shift part of the appended item */
951 RFALSE( pos_in_item != ih_item_len(B_N_PITEM_HEAD(tbS0,item_pos)) || 1294 struct item_head *aux_ih;
952 tb->insert_size[0] <= 0, 1295
953 "PAP-12225: item too short or insert_size <= 0"); 1296 RFALSE(ih, "PAP-12210: ih must be 0");
954 1297
955 /* Calculate number of bytes which must be shifted from appended item */ 1298 if (is_direntry_le_ih
956 n_shift = sbytes[i] - tb->insert_size[0]; 1299 (aux_ih =
957 if ( n_shift < 0 ) 1300 B_N_PITEM_HEAD(tbS0, item_pos))) {
958 n_shift = 0; 1301 /* we append to directory item */
959 leaf_move_items (LEAF_FROM_S_TO_SNEW, tb, snum[i], n_shift, S_new[i]); 1302
960 1303 int entry_count;
961 /* Calculate number of bytes which must remain in body after append to S_new[i] */ 1304
962 n_rem = tb->insert_size[0] - sbytes[i]; 1305 entry_count =
963 if ( n_rem < 0 ) 1306 ih_entry_count(aux_ih);
964 n_rem = 0; 1307
965 /* Append part of body into S_new[0] */ 1308 if (entry_count - sbytes[i] <
966 bi.tb = tb; 1309 pos_in_item
967 bi.bi_bh = S_new[i]; 1310 && pos_in_item <=
968 bi.bi_parent = NULL; 1311 entry_count) {
969 bi.bi_position = 0; 1312 /* new directory entry falls into S_new[i] */
1313
1314 RFALSE(!tb->
1315 insert_size[0],
1316 "PAP-12215: insert_size is already 0");
1317 RFALSE(sbytes[i] - 1 >=
1318 entry_count,
1319 "PAP-12220: there are no so much entries (%d), only %d",
1320 sbytes[i] - 1,
1321 entry_count);
1322
1323 /* Shift snum[i]-1 items in whole. Shift sbytes[i] directory entries from directory item number snum[i] */
1324 leaf_move_items
1325 (LEAF_FROM_S_TO_SNEW,
1326 tb, snum[i],
1327 sbytes[i] - 1,
1328 S_new[i]);
1329 /* Paste given directory entry to directory item */
1330 bi.tb = tb;
1331 bi.bi_bh = S_new[i];
1332 bi.bi_parent = NULL;
1333 bi.bi_position = 0;
1334 leaf_paste_in_buffer
1335 (&bi, 0,
1336 pos_in_item -
1337 entry_count +
1338 sbytes[i] - 1,
1339 tb->insert_size[0],
1340 body, zeros_num);
1341 /* paste new directory entry */
1342 leaf_paste_entries(bi.
1343 bi_bh,
1344 0,
1345 pos_in_item
1346 -
1347 entry_count
1348 +
1349 sbytes
1350 [i] -
1351 1, 1,
1352 (struct
1353 reiserfs_de_head
1354 *)
1355 body,
1356 body
1357 +
1358 DEH_SIZE,
1359 tb->
1360 insert_size
1361 [0]
1362 );
1363 tb->insert_size[0] = 0;
1364 pos_in_item++;
1365 } else { /* new directory entry doesn't fall into S_new[i] */
1366 leaf_move_items
1367 (LEAF_FROM_S_TO_SNEW,
1368 tb, snum[i],
1369 sbytes[i],
1370 S_new[i]);
1371 }
1372 } else { /* regular object */
1373
1374 int n_shift, n_rem,
1375 r_zeros_number;
1376 const char *r_body;
1377
1378 RFALSE(pos_in_item !=
1379 ih_item_len
1380 (B_N_PITEM_HEAD
1381 (tbS0, item_pos))
1382 || tb->insert_size[0] <=
1383 0,
1384 "PAP-12225: item too short or insert_size <= 0");
1385
1386 /* Calculate number of bytes which must be shifted from appended item */
1387 n_shift =
1388 sbytes[i] -
1389 tb->insert_size[0];
1390 if (n_shift < 0)
1391 n_shift = 0;
1392 leaf_move_items
1393 (LEAF_FROM_S_TO_SNEW, tb,
1394 snum[i], n_shift,
1395 S_new[i]);
1396
1397 /* Calculate number of bytes which must remain in body after append to S_new[i] */
1398 n_rem =
1399 tb->insert_size[0] -
1400 sbytes[i];
1401 if (n_rem < 0)
1402 n_rem = 0;
1403 /* Append part of body into S_new[0] */
1404 bi.tb = tb;
1405 bi.bi_bh = S_new[i];
1406 bi.bi_parent = NULL;
1407 bi.bi_position = 0;
1408
1409 if (n_rem > zeros_num) {
1410 r_zeros_number = 0;
1411 r_body =
1412 body + n_rem -
1413 zeros_num;
1414 } else {
1415 r_body = body;
1416 r_zeros_number =
1417 zeros_num - n_rem;
1418 zeros_num -=
1419 r_zeros_number;
1420 }
1421
1422 leaf_paste_in_buffer(&bi, 0,
1423 n_shift,
1424 tb->
1425 insert_size
1426 [0] -
1427 n_rem,
1428 r_body,
1429 r_zeros_number);
1430 {
1431 struct item_head *tmp;
1432
1433 tmp =
1434 B_N_PITEM_HEAD(S_new
1435 [i],
1436 0);
1437 if (is_indirect_le_ih
1438 (tmp)) {
1439 set_ih_free_space
1440 (tmp, 0);
1441 set_le_ih_k_offset
1442 (tmp,
1443 le_ih_k_offset
1444 (tmp) +
1445 (n_rem <<
1446 (tb->
1447 tb_sb->
1448 s_blocksize_bits
1449 -
1450 UNFM_P_SHIFT)));
1451 } else {
1452 set_le_ih_k_offset
1453 (tmp,
1454 le_ih_k_offset
1455 (tmp) +
1456 n_rem);
1457 }
1458 }
1459
1460 tb->insert_size[0] = n_rem;
1461 if (!n_rem)
1462 pos_in_item++;
1463 }
1464 } else
1465 /* item falls wholly into S_new[i] */
1466 {
1467 int ret_val;
1468 struct item_head *pasted;
970 1469
971 if ( n_rem > zeros_num ) { 1470#ifdef CONFIG_REISERFS_CHECK
972 r_zeros_number = 0; 1471 struct item_head *ih =
973 r_body = body + n_rem - zeros_num; 1472 B_N_PITEM_HEAD(tbS0, item_pos);
974 } 1473
975 else { 1474 if (!is_direntry_le_ih(ih)
976 r_body = body; 1475 && (pos_in_item != ih_item_len(ih)
977 r_zeros_number = zeros_num - n_rem; 1476 || tb->insert_size[0] <= 0))
978 zeros_num -= r_zeros_number; 1477 reiserfs_panic(tb->tb_sb,
1478 "PAP-12235: balance_leaf: pos_in_item must be equal to ih_item_len");
1479#endif /* CONFIG_REISERFS_CHECK */
1480
1481 ret_val =
1482 leaf_move_items(LEAF_FROM_S_TO_SNEW,
1483 tb, snum[i],
1484 sbytes[i],
1485 S_new[i]);
1486
1487 RFALSE(ret_val,
1488 "PAP-12240: unexpected value returned by leaf_move_items (%d)",
1489 ret_val);
1490
1491 /* paste into item */
1492 bi.tb = tb;
1493 bi.bi_bh = S_new[i];
1494 bi.bi_parent = NULL;
1495 bi.bi_position = 0;
1496 leaf_paste_in_buffer(&bi,
1497 item_pos - n +
1498 snum[i],
1499 pos_in_item,
1500 tb->insert_size[0],
1501 body, zeros_num);
1502
1503 pasted =
1504 B_N_PITEM_HEAD(S_new[i],
1505 item_pos - n +
1506 snum[i]);
1507 if (is_direntry_le_ih(pasted)) {
1508 leaf_paste_entries(bi.bi_bh,
1509 item_pos -
1510 n + snum[i],
1511 pos_in_item,
1512 1,
1513 (struct
1514 reiserfs_de_head
1515 *)body,
1516 body +
1517 DEH_SIZE,
1518 tb->
1519 insert_size
1520 [0]
1521 );
1522 }
1523
1524 /* if we paste to indirect item update ih_free_space */
1525 if (is_indirect_le_ih(pasted))
1526 set_ih_free_space(pasted, 0);
1527 zeros_num = tb->insert_size[0] = 0;
1528 }
979 } 1529 }
980 1530
981 leaf_paste_in_buffer(&bi, 0, n_shift, tb->insert_size[0]-n_rem, r_body,r_zeros_number); 1531 else { /* pasted item doesn't fall into S_new[i] */
982 {
983 struct item_head * tmp;
984
985 tmp = B_N_PITEM_HEAD(S_new[i],0);
986 if (is_indirect_le_ih (tmp)) {
987 set_ih_free_space (tmp, 0);
988 set_le_ih_k_offset( tmp, le_ih_k_offset(tmp) +
989 (n_rem << (tb->tb_sb->s_blocksize_bits - UNFM_P_SHIFT)));
990 } else {
991 set_le_ih_k_offset( tmp, le_ih_k_offset(tmp) +
992 n_rem );
993 }
994 }
995 1532
996 tb->insert_size[0] = n_rem; 1533 leaf_move_items(LEAF_FROM_S_TO_SNEW, tb,
997 if ( ! n_rem ) 1534 snum[i], sbytes[i], S_new[i]);
998 pos_in_item++; 1535 }
999 } 1536 break;
1537 default: /* cases d and t */
1538 reiserfs_panic(tb->tb_sb,
1539 "PAP-12245: balance_leaf: blknum > 2: unexpectable mode: %s(%d)",
1540 (flag ==
1541 M_DELETE) ? "DELETE" : ((flag ==
1542 M_CUT) ? "CUT"
1543 : "UNKNOWN"),
1544 flag);
1000 } 1545 }
1001 else
1002 /* item falls wholly into S_new[i] */
1003 {
1004 int ret_val;
1005 struct item_head * pasted;
1006 1546
1007#ifdef CONFIG_REISERFS_CHECK 1547 memcpy(insert_key + i, B_N_PKEY(S_new[i], 0), KEY_SIZE);
1008 struct item_head * ih = B_N_PITEM_HEAD(tbS0,item_pos); 1548 insert_ptr[i] = S_new[i];
1009 1549
1010 if ( ! is_direntry_le_ih(ih) && (pos_in_item != ih_item_len(ih) || 1550 RFALSE(!buffer_journaled(S_new[i])
1011 tb->insert_size[0] <= 0) ) 1551 || buffer_journal_dirty(S_new[i])
1012 reiserfs_panic (tb->tb_sb, "PAP-12235: balance_leaf: pos_in_item must be equal to ih_item_len"); 1552 || buffer_dirty(S_new[i]), "PAP-12247: S_new[%d] : (%b)",
1013#endif /* CONFIG_REISERFS_CHECK */ 1553 i, S_new[i]);
1014
1015 ret_val = leaf_move_items (LEAF_FROM_S_TO_SNEW, tb, snum[i], sbytes[i], S_new[i]);
1016
1017 RFALSE( ret_val,
1018 "PAP-12240: unexpected value returned by leaf_move_items (%d)",
1019 ret_val);
1020
1021 /* paste into item */
1022 bi.tb = tb;
1023 bi.bi_bh = S_new[i];
1024 bi.bi_parent = NULL;
1025 bi.bi_position = 0;
1026 leaf_paste_in_buffer(&bi, item_pos - n + snum[i], pos_in_item, tb->insert_size[0], body, zeros_num);
1027
1028 pasted = B_N_PITEM_HEAD(S_new[i], item_pos - n + snum[i]);
1029 if (is_direntry_le_ih (pasted))
1030 {
1031 leaf_paste_entries (
1032 bi.bi_bh, item_pos - n + snum[i], pos_in_item, 1,
1033 (struct reiserfs_de_head *)body, body + DEH_SIZE, tb->insert_size[0]
1034 );
1035 }
1036
1037 /* if we paste to indirect item update ih_free_space */
1038 if (is_indirect_le_ih (pasted))
1039 set_ih_free_space (pasted, 0);
1040 zeros_num = tb->insert_size[0] = 0;
1041 }
1042 }
1043
1044 else /* pasted item doesn't fall into S_new[i] */
1045 {
1046 leaf_move_items (LEAF_FROM_S_TO_SNEW, tb, snum[i], sbytes[i], S_new[i]);
1047 }
1048 break;
1049 default: /* cases d and t */
1050 reiserfs_panic (tb->tb_sb, "PAP-12245: balance_leaf: blknum > 2: unexpectable mode: %s(%d)",
1051 (flag == M_DELETE) ? "DELETE" : ((flag == M_CUT) ? "CUT" : "UNKNOWN"), flag);
1052 } 1554 }
1053 1555
1054 memcpy (insert_key + i,B_N_PKEY(S_new[i],0),KEY_SIZE); 1556 /* if the affected item was not wholly shifted then we perform all necessary operations on that part or whole of the
1055 insert_ptr[i] = S_new[i]; 1557 affected item which remains in S */
1056 1558 if (0 <= item_pos && item_pos < tb->s0num) { /* if we must insert or append into buffer S[0] */
1057 RFALSE (!buffer_journaled (S_new [i]) || buffer_journal_dirty (S_new [i]) || 1559
1058 buffer_dirty (S_new [i]), 1560 switch (flag) {
1059 "PAP-12247: S_new[%d] : (%b)", i, S_new[i]); 1561 case M_INSERT: /* insert item into S[0] */
1060 } 1562 bi.tb = tb;
1061 1563 bi.bi_bh = tbS0;
1062 /* if the affected item was not wholly shifted then we perform all necessary operations on that part or whole of the 1564 bi.bi_parent = PATH_H_PPARENT(tb->tb_path, 0);
1063 affected item which remains in S */ 1565 bi.bi_position = PATH_H_POSITION(tb->tb_path, 1);
1064 if ( 0 <= item_pos && item_pos < tb->s0num ) 1566 leaf_insert_into_buf(&bi, item_pos, ih, body,
1065 { /* if we must insert or append into buffer S[0] */ 1567 zeros_num);
1066 1568
1067 switch (flag) 1569 /* If we insert the first key change the delimiting key */
1068 { 1570 if (item_pos == 0) {
1069 case M_INSERT: /* insert item into S[0] */ 1571 if (tb->CFL[0]) /* can be 0 in reiserfsck */
1070 bi.tb = tb; 1572 replace_key(tb, tb->CFL[0], tb->lkey[0],
1071 bi.bi_bh = tbS0; 1573 tbS0, 0);
1072 bi.bi_parent = PATH_H_PPARENT (tb->tb_path, 0);
1073 bi.bi_position = PATH_H_POSITION (tb->tb_path, 1);
1074 leaf_insert_into_buf (&bi, item_pos, ih, body, zeros_num);
1075
1076 /* If we insert the first key change the delimiting key */
1077 if( item_pos == 0 ) {
1078 if (tb->CFL[0]) /* can be 0 in reiserfsck */
1079 replace_key(tb, tb->CFL[0], tb->lkey[0],tbS0,0);
1080
1081 }
1082 break;
1083
1084 case M_PASTE: { /* append item in S[0] */
1085 struct item_head * pasted;
1086
1087 pasted = B_N_PITEM_HEAD (tbS0, item_pos);
1088 /* when directory, may be new entry already pasted */
1089 if (is_direntry_le_ih (pasted)) {
1090 if ( pos_in_item >= 0 &&
1091 pos_in_item <= ih_entry_count(pasted) ) {
1092
1093 RFALSE( ! tb->insert_size[0],
1094 "PAP-12260: insert_size is 0 already");
1095
1096 /* prepare space */
1097 bi.tb = tb;
1098 bi.bi_bh = tbS0;
1099 bi.bi_parent = PATH_H_PPARENT (tb->tb_path, 0);
1100 bi.bi_position = PATH_H_POSITION (tb->tb_path, 1);
1101 leaf_paste_in_buffer(&bi, item_pos, pos_in_item, tb->insert_size[0], body, zeros_num);
1102
1103 /* paste entry */
1104 leaf_paste_entries (
1105 bi.bi_bh, item_pos, pos_in_item, 1, (struct reiserfs_de_head *)body,
1106 body + DEH_SIZE, tb->insert_size[0]
1107 );
1108 if ( ! item_pos && ! pos_in_item ) {
1109 RFALSE( !tb->CFL[0] || !tb->L[0],
1110 "PAP-12270: CFL[0]/L[0] must be specified");
1111 if (tb->CFL[0]) {
1112 replace_key(tb, tb->CFL[0], tb->lkey[0],tbS0,0);
1113 1574
1114 } 1575 }
1115 } 1576 break;
1116 tb->insert_size[0] = 0; 1577
1117 } 1578 case M_PASTE:{ /* append item in S[0] */
1118 } else { /* regular object */ 1579 struct item_head *pasted;
1119 if ( pos_in_item == ih_item_len(pasted) ) { 1580
1120 1581 pasted = B_N_PITEM_HEAD(tbS0, item_pos);
1121 RFALSE( tb->insert_size[0] <= 0, 1582 /* when directory, may be new entry already pasted */
1122 "PAP-12275: insert size must not be %d", 1583 if (is_direntry_le_ih(pasted)) {
1123 tb->insert_size[0]); 1584 if (pos_in_item >= 0 &&
1124 bi.tb = tb; 1585 pos_in_item <=
1125 bi.bi_bh = tbS0; 1586 ih_entry_count(pasted)) {
1126 bi.bi_parent = PATH_H_PPARENT (tb->tb_path, 0); 1587
1127 bi.bi_position = PATH_H_POSITION (tb->tb_path, 1); 1588 RFALSE(!tb->insert_size[0],
1128 leaf_paste_in_buffer (&bi, item_pos, pos_in_item, tb->insert_size[0], body, zeros_num); 1589 "PAP-12260: insert_size is 0 already");
1129 1590
1130 if (is_indirect_le_ih (pasted)) { 1591 /* prepare space */
1592 bi.tb = tb;
1593 bi.bi_bh = tbS0;
1594 bi.bi_parent =
1595 PATH_H_PPARENT(tb->tb_path,
1596 0);
1597 bi.bi_position =
1598 PATH_H_POSITION(tb->tb_path,
1599 1);
1600 leaf_paste_in_buffer(&bi,
1601 item_pos,
1602 pos_in_item,
1603 tb->
1604 insert_size
1605 [0], body,
1606 zeros_num);
1607
1608 /* paste entry */
1609 leaf_paste_entries(bi.bi_bh,
1610 item_pos,
1611 pos_in_item,
1612 1,
1613 (struct
1614 reiserfs_de_head
1615 *)body,
1616 body +
1617 DEH_SIZE,
1618 tb->
1619 insert_size
1620 [0]
1621 );
1622 if (!item_pos && !pos_in_item) {
1623 RFALSE(!tb->CFL[0]
1624 || !tb->L[0],
1625 "PAP-12270: CFL[0]/L[0] must be specified");
1626 if (tb->CFL[0]) {
1627 replace_key(tb,
1628 tb->
1629 CFL
1630 [0],
1631 tb->
1632 lkey
1633 [0],
1634 tbS0,
1635 0);
1636
1637 }
1638 }
1639 tb->insert_size[0] = 0;
1640 }
1641 } else { /* regular object */
1642 if (pos_in_item == ih_item_len(pasted)) {
1643
1644 RFALSE(tb->insert_size[0] <= 0,
1645 "PAP-12275: insert size must not be %d",
1646 tb->insert_size[0]);
1647 bi.tb = tb;
1648 bi.bi_bh = tbS0;
1649 bi.bi_parent =
1650 PATH_H_PPARENT(tb->tb_path,
1651 0);
1652 bi.bi_position =
1653 PATH_H_POSITION(tb->tb_path,
1654 1);
1655 leaf_paste_in_buffer(&bi,
1656 item_pos,
1657 pos_in_item,
1658 tb->
1659 insert_size
1660 [0], body,
1661 zeros_num);
1662
1663 if (is_indirect_le_ih(pasted)) {
1131#if 0 1664#if 0
1132 RFALSE( tb->insert_size[0] != UNFM_P_SIZE, 1665 RFALSE(tb->
1133 "PAP-12280: insert_size for indirect item must be %d, not %d", 1666 insert_size[0] !=
1134 UNFM_P_SIZE, tb->insert_size[0]); 1667 UNFM_P_SIZE,
1668 "PAP-12280: insert_size for indirect item must be %d, not %d",
1669 UNFM_P_SIZE,
1670 tb->
1671 insert_size[0]);
1135#endif 1672#endif
1136 set_ih_free_space (pasted, 0); 1673 set_ih_free_space
1137 } 1674 (pasted, 0);
1138 tb->insert_size[0] = 0; 1675 }
1139 } 1676 tb->insert_size[0] = 0;
1140 1677 }
1141#ifdef CONFIG_REISERFS_CHECK 1678#ifdef CONFIG_REISERFS_CHECK
1142 else { 1679 else {
1143 if ( tb->insert_size[0] ) { 1680 if (tb->insert_size[0]) {
1144 print_cur_tb ("12285"); 1681 print_cur_tb("12285");
1145 reiserfs_panic (tb->tb_sb, "PAP-12285: balance_leaf: insert_size must be 0 (%d)", tb->insert_size[0]); 1682 reiserfs_panic(tb->
1146 } 1683 tb_sb,
1684 "PAP-12285: balance_leaf: insert_size must be 0 (%d)",
1685 tb->
1686 insert_size
1687 [0]);
1688 }
1689 }
1690#endif /* CONFIG_REISERFS_CHECK */
1691
1692 }
1693 } /* case M_PASTE: */
1147 } 1694 }
1148#endif /* CONFIG_REISERFS_CHECK */
1149
1150 }
1151 } /* case M_PASTE: */
1152 } 1695 }
1153 }
1154
1155#ifdef CONFIG_REISERFS_CHECK 1696#ifdef CONFIG_REISERFS_CHECK
1156 if ( flag == M_PASTE && tb->insert_size[0] ) { 1697 if (flag == M_PASTE && tb->insert_size[0]) {
1157 print_cur_tb ("12290"); 1698 print_cur_tb("12290");
1158 reiserfs_panic (tb->tb_sb, "PAP-12290: balance_leaf: insert_size is still not 0 (%d)", tb->insert_size[0]); 1699 reiserfs_panic(tb->tb_sb,
1159 } 1700 "PAP-12290: balance_leaf: insert_size is still not 0 (%d)",
1160#endif /* CONFIG_REISERFS_CHECK */ 1701 tb->insert_size[0]);
1161 1702 }
1162 return 0; 1703#endif /* CONFIG_REISERFS_CHECK */
1163} /* Leaf level of the tree is balanced (end of balance_leaf) */
1164
1165 1704
1705 return 0;
1706} /* Leaf level of the tree is balanced (end of balance_leaf) */
1166 1707
1167/* Make empty node */ 1708/* Make empty node */
1168void make_empty_node (struct buffer_info * bi) 1709void make_empty_node(struct buffer_info *bi)
1169{ 1710{
1170 struct block_head * blkh; 1711 struct block_head *blkh;
1171 1712
1172 RFALSE( bi->bi_bh == NULL, "PAP-12295: pointer to the buffer is NULL"); 1713 RFALSE(bi->bi_bh == NULL, "PAP-12295: pointer to the buffer is NULL");
1173 1714
1174 blkh = B_BLK_HEAD(bi->bi_bh); 1715 blkh = B_BLK_HEAD(bi->bi_bh);
1175 set_blkh_nr_item( blkh, 0 ); 1716 set_blkh_nr_item(blkh, 0);
1176 set_blkh_free_space( blkh, MAX_CHILD_SIZE(bi->bi_bh) ); 1717 set_blkh_free_space(blkh, MAX_CHILD_SIZE(bi->bi_bh));
1177 1718
1178 if (bi->bi_parent) 1719 if (bi->bi_parent)
1179 B_N_CHILD (bi->bi_parent, bi->bi_position)->dc_size = 0; /* Endian safe if 0 */ 1720 B_N_CHILD(bi->bi_parent, bi->bi_position)->dc_size = 0; /* Endian safe if 0 */
1180} 1721}
1181 1722
1182
1183/* Get first empty buffer */ 1723/* Get first empty buffer */
1184struct buffer_head * get_FEB (struct tree_balance * tb) 1724struct buffer_head *get_FEB(struct tree_balance *tb)
1185{ 1725{
1186 int i; 1726 int i;
1187 struct buffer_head * first_b; 1727 struct buffer_head *first_b;
1188 struct buffer_info bi; 1728 struct buffer_info bi;
1189
1190 for (i = 0; i < MAX_FEB_SIZE; i ++)
1191 if (tb->FEB[i] != 0)
1192 break;
1193
1194 if (i == MAX_FEB_SIZE)
1195 reiserfs_panic(tb->tb_sb, "vs-12300: get_FEB: FEB list is empty");
1196
1197 bi.tb = tb;
1198 bi.bi_bh = first_b = tb->FEB[i];
1199 bi.bi_parent = NULL;
1200 bi.bi_position = 0;
1201 make_empty_node (&bi);
1202 set_buffer_uptodate(first_b);
1203 tb->FEB[i] = NULL;
1204 tb->used[i] = first_b;
1205
1206 return(first_b);
1207}
1208 1729
1730 for (i = 0; i < MAX_FEB_SIZE; i++)
1731 if (tb->FEB[i] != 0)
1732 break;
1733
1734 if (i == MAX_FEB_SIZE)
1735 reiserfs_panic(tb->tb_sb,
1736 "vs-12300: get_FEB: FEB list is empty");
1737
1738 bi.tb = tb;
1739 bi.bi_bh = first_b = tb->FEB[i];
1740 bi.bi_parent = NULL;
1741 bi.bi_position = 0;
1742 make_empty_node(&bi);
1743 set_buffer_uptodate(first_b);
1744 tb->FEB[i] = NULL;
1745 tb->used[i] = first_b;
1746
1747 return (first_b);
1748}
1209 1749
1210/* This is now used because reiserfs_free_block has to be able to 1750/* This is now used because reiserfs_free_block has to be able to
1211** schedule. 1751** schedule.
1212*/ 1752*/
1213static void store_thrown (struct tree_balance * tb, struct buffer_head * bh) 1753static void store_thrown(struct tree_balance *tb, struct buffer_head *bh)
1214{ 1754{
1215 int i; 1755 int i;
1216 1756
1217 if (buffer_dirty (bh)) 1757 if (buffer_dirty(bh))
1218 reiserfs_warning (tb->tb_sb, "store_thrown deals with dirty buffer"); 1758 reiserfs_warning(tb->tb_sb,
1219 for (i = 0; i < sizeof (tb->thrown)/sizeof (tb->thrown[0]); i ++) 1759 "store_thrown deals with dirty buffer");
1220 if (!tb->thrown[i]) { 1760 for (i = 0; i < sizeof(tb->thrown) / sizeof(tb->thrown[0]); i++)
1221 tb->thrown[i] = bh; 1761 if (!tb->thrown[i]) {
1222 get_bh(bh) ; /* free_thrown puts this */ 1762 tb->thrown[i] = bh;
1223 return; 1763 get_bh(bh); /* free_thrown puts this */
1224 } 1764 return;
1225 reiserfs_warning (tb->tb_sb, "store_thrown: too many thrown buffers"); 1765 }
1766 reiserfs_warning(tb->tb_sb, "store_thrown: too many thrown buffers");
1226} 1767}
1227 1768
1228static void free_thrown(struct tree_balance *tb) { 1769static void free_thrown(struct tree_balance *tb)
1229 int i ; 1770{
1230 b_blocknr_t blocknr ; 1771 int i;
1231 for (i = 0; i < sizeof (tb->thrown)/sizeof (tb->thrown[0]); i++) { 1772 b_blocknr_t blocknr;
1232 if (tb->thrown[i]) { 1773 for (i = 0; i < sizeof(tb->thrown) / sizeof(tb->thrown[0]); i++) {
1233 blocknr = tb->thrown[i]->b_blocknr ; 1774 if (tb->thrown[i]) {
1234 if (buffer_dirty (tb->thrown[i])) 1775 blocknr = tb->thrown[i]->b_blocknr;
1235 reiserfs_warning (tb->tb_sb, 1776 if (buffer_dirty(tb->thrown[i]))
1236 "free_thrown deals with dirty buffer %d", 1777 reiserfs_warning(tb->tb_sb,
1237 blocknr); 1778 "free_thrown deals with dirty buffer %d",
1238 brelse(tb->thrown[i]) ; /* incremented in store_thrown */ 1779 blocknr);
1239 reiserfs_free_block (tb->transaction_handle, NULL, blocknr, 0); 1780 brelse(tb->thrown[i]); /* incremented in store_thrown */
1781 reiserfs_free_block(tb->transaction_handle, NULL,
1782 blocknr, 0);
1783 }
1240 } 1784 }
1241 }
1242} 1785}
1243 1786
1244void reiserfs_invalidate_buffer (struct tree_balance * tb, struct buffer_head * bh) 1787void reiserfs_invalidate_buffer(struct tree_balance *tb, struct buffer_head *bh)
1245{ 1788{
1246 struct block_head *blkh; 1789 struct block_head *blkh;
1247 blkh = B_BLK_HEAD(bh); 1790 blkh = B_BLK_HEAD(bh);
1248 set_blkh_level( blkh, FREE_LEVEL ); 1791 set_blkh_level(blkh, FREE_LEVEL);
1249 set_blkh_nr_item( blkh, 0 ); 1792 set_blkh_nr_item(blkh, 0);
1250 1793
1251 clear_buffer_dirty(bh); 1794 clear_buffer_dirty(bh);
1252 store_thrown (tb, bh); 1795 store_thrown(tb, bh);
1253} 1796}
1254 1797
1255/* Replace n_dest'th key in buffer dest by n_src'th key of buffer src.*/ 1798/* Replace n_dest'th key in buffer dest by n_src'th key of buffer src.*/
1256void replace_key (struct tree_balance * tb, struct buffer_head * dest, int n_dest, 1799void replace_key(struct tree_balance *tb, struct buffer_head *dest, int n_dest,
1257 struct buffer_head * src, int n_src) 1800 struct buffer_head *src, int n_src)
1258{ 1801{
1259 1802
1260 RFALSE( dest == NULL || src == NULL, 1803 RFALSE(dest == NULL || src == NULL,
1261 "vs-12305: source or destination buffer is 0 (src=%p, dest=%p)", 1804 "vs-12305: source or destination buffer is 0 (src=%p, dest=%p)",
1262 src, dest); 1805 src, dest);
1263 RFALSE( ! B_IS_KEYS_LEVEL (dest), 1806 RFALSE(!B_IS_KEYS_LEVEL(dest),
1264 "vs-12310: invalid level (%z) for destination buffer. dest must be leaf", 1807 "vs-12310: invalid level (%z) for destination buffer. dest must be leaf",
1265 dest); 1808 dest);
1266 RFALSE( n_dest < 0 || n_src < 0, 1809 RFALSE(n_dest < 0 || n_src < 0,
1267 "vs-12315: src(%d) or dest(%d) key number < 0", n_src, n_dest); 1810 "vs-12315: src(%d) or dest(%d) key number < 0", n_src, n_dest);
1268 RFALSE( n_dest >= B_NR_ITEMS(dest) || n_src >= B_NR_ITEMS(src), 1811 RFALSE(n_dest >= B_NR_ITEMS(dest) || n_src >= B_NR_ITEMS(src),
1269 "vs-12320: src(%d(%d)) or dest(%d(%d)) key number is too big", 1812 "vs-12320: src(%d(%d)) or dest(%d(%d)) key number is too big",
1270 n_src, B_NR_ITEMS(src), n_dest, B_NR_ITEMS(dest)); 1813 n_src, B_NR_ITEMS(src), n_dest, B_NR_ITEMS(dest));
1271 1814
1272 if (B_IS_ITEMS_LEVEL (src)) 1815 if (B_IS_ITEMS_LEVEL(src))
1273 /* source buffer contains leaf node */ 1816 /* source buffer contains leaf node */
1274 memcpy (B_N_PDELIM_KEY(dest,n_dest), B_N_PITEM_HEAD(src,n_src), KEY_SIZE); 1817 memcpy(B_N_PDELIM_KEY(dest, n_dest), B_N_PITEM_HEAD(src, n_src),
1275 else 1818 KEY_SIZE);
1276 memcpy (B_N_PDELIM_KEY(dest,n_dest), B_N_PDELIM_KEY(src,n_src), KEY_SIZE); 1819 else
1277 1820 memcpy(B_N_PDELIM_KEY(dest, n_dest), B_N_PDELIM_KEY(src, n_src),
1278 do_balance_mark_internal_dirty (tb, dest, 0); 1821 KEY_SIZE);
1822
1823 do_balance_mark_internal_dirty(tb, dest, 0);
1279} 1824}
1280 1825
1281 1826int get_left_neighbor_position(struct tree_balance *tb, int h)
1282int get_left_neighbor_position (
1283 struct tree_balance * tb,
1284 int h
1285 )
1286{ 1827{
1287 int Sh_position = PATH_H_POSITION (tb->tb_path, h + 1); 1828 int Sh_position = PATH_H_POSITION(tb->tb_path, h + 1);
1288 1829
1289 RFALSE( PATH_H_PPARENT (tb->tb_path, h) == 0 || tb->FL[h] == 0, 1830 RFALSE(PATH_H_PPARENT(tb->tb_path, h) == 0 || tb->FL[h] == 0,
1290 "vs-12325: FL[%d](%p) or F[%d](%p) does not exist", 1831 "vs-12325: FL[%d](%p) or F[%d](%p) does not exist",
1291 h, tb->FL[h], h, PATH_H_PPARENT (tb->tb_path, h)); 1832 h, tb->FL[h], h, PATH_H_PPARENT(tb->tb_path, h));
1292 1833
1293 if (Sh_position == 0) 1834 if (Sh_position == 0)
1294 return B_NR_ITEMS (tb->FL[h]); 1835 return B_NR_ITEMS(tb->FL[h]);
1295 else 1836 else
1296 return Sh_position - 1; 1837 return Sh_position - 1;
1297} 1838}
1298 1839
1299 1840int get_right_neighbor_position(struct tree_balance *tb, int h)
1300int get_right_neighbor_position (struct tree_balance * tb, int h)
1301{ 1841{
1302 int Sh_position = PATH_H_POSITION (tb->tb_path, h + 1); 1842 int Sh_position = PATH_H_POSITION(tb->tb_path, h + 1);
1303 1843
1304 RFALSE( PATH_H_PPARENT (tb->tb_path, h) == 0 || tb->FR[h] == 0, 1844 RFALSE(PATH_H_PPARENT(tb->tb_path, h) == 0 || tb->FR[h] == 0,
1305 "vs-12330: F[%d](%p) or FR[%d](%p) does not exist", 1845 "vs-12330: F[%d](%p) or FR[%d](%p) does not exist",
1306 h, PATH_H_PPARENT (tb->tb_path, h), h, tb->FR[h]); 1846 h, PATH_H_PPARENT(tb->tb_path, h), h, tb->FR[h]);
1307 1847
1308 if (Sh_position == B_NR_ITEMS (PATH_H_PPARENT (tb->tb_path, h))) 1848 if (Sh_position == B_NR_ITEMS(PATH_H_PPARENT(tb->tb_path, h)))
1309 return 0; 1849 return 0;
1310 else 1850 else
1311 return Sh_position + 1; 1851 return Sh_position + 1;
1312} 1852}
1313 1853
1314
1315#ifdef CONFIG_REISERFS_CHECK 1854#ifdef CONFIG_REISERFS_CHECK
1316 1855
1317int is_reusable (struct super_block * s, b_blocknr_t block, int bit_value); 1856int is_reusable(struct super_block *s, b_blocknr_t block, int bit_value);
1318static void check_internal_node (struct super_block * s, struct buffer_head * bh, char * mes) 1857static void check_internal_node(struct super_block *s, struct buffer_head *bh,
1858 char *mes)
1319{ 1859{
1320 struct disk_child * dc; 1860 struct disk_child *dc;
1321 int i; 1861 int i;
1322
1323 RFALSE( !bh, "PAP-12336: bh == 0");
1324
1325 if (!bh || !B_IS_IN_TREE (bh))
1326 return;
1327
1328 RFALSE( !buffer_dirty (bh) &&
1329 !(buffer_journaled(bh) || buffer_journal_dirty(bh)),
1330 "PAP-12337: buffer (%b) must be dirty", bh);
1331 dc = B_N_CHILD (bh, 0);
1332
1333 for (i = 0; i <= B_NR_ITEMS (bh); i ++, dc ++) {
1334 if (!is_reusable (s, dc_block_number(dc), 1) ) {
1335 print_cur_tb (mes);
1336 reiserfs_panic (s, "PAP-12338: check_internal_node: invalid child pointer %y in %b", dc, bh);
1337 }
1338 }
1339}
1340 1862
1863 RFALSE(!bh, "PAP-12336: bh == 0");
1341 1864
1342static int locked_or_not_in_tree (struct buffer_head * bh, char * which) 1865 if (!bh || !B_IS_IN_TREE(bh))
1343{ 1866 return;
1344 if ( (!buffer_journal_prepared (bh) && buffer_locked (bh)) ||
1345 !B_IS_IN_TREE (bh) ) {
1346 reiserfs_warning (NULL, "vs-12339: locked_or_not_in_tree: %s (%b)",
1347 which, bh);
1348 return 1;
1349 }
1350 return 0;
1351}
1352 1867
1868 RFALSE(!buffer_dirty(bh) &&
1869 !(buffer_journaled(bh) || buffer_journal_dirty(bh)),
1870 "PAP-12337: buffer (%b) must be dirty", bh);
1871 dc = B_N_CHILD(bh, 0);
1353 1872
1354static int check_before_balancing (struct tree_balance * tb) 1873 for (i = 0; i <= B_NR_ITEMS(bh); i++, dc++) {
1355{ 1874 if (!is_reusable(s, dc_block_number(dc), 1)) {
1356 int retval = 0; 1875 print_cur_tb(mes);
1357 1876 reiserfs_panic(s,
1358 if ( cur_tb ) { 1877 "PAP-12338: check_internal_node: invalid child pointer %y in %b",
1359 reiserfs_panic (tb->tb_sb, "vs-12335: check_before_balancing: " 1878 dc, bh);
1360 "suspect that schedule occurred based on cur_tb not being null at this point in code. " 1879 }
1361 "do_balance cannot properly handle schedule occurring while it runs."); 1880 }
1362 }
1363
1364 /* double check that buffers that we will modify are unlocked. (fix_nodes should already have
1365 prepped all of these for us). */
1366 if ( tb->lnum[0] ) {
1367 retval |= locked_or_not_in_tree (tb->L[0], "L[0]");
1368 retval |= locked_or_not_in_tree (tb->FL[0], "FL[0]");
1369 retval |= locked_or_not_in_tree (tb->CFL[0], "CFL[0]");
1370 check_leaf (tb->L[0]);
1371 }
1372 if ( tb->rnum[0] ) {
1373 retval |= locked_or_not_in_tree (tb->R[0], "R[0]");
1374 retval |= locked_or_not_in_tree (tb->FR[0], "FR[0]");
1375 retval |= locked_or_not_in_tree (tb->CFR[0], "CFR[0]");
1376 check_leaf (tb->R[0]);
1377 }
1378 retval |= locked_or_not_in_tree (PATH_PLAST_BUFFER (tb->tb_path), "S[0]");
1379 check_leaf (PATH_PLAST_BUFFER (tb->tb_path));
1380
1381 return retval;
1382} 1881}
1383 1882
1883static int locked_or_not_in_tree(struct buffer_head *bh, char *which)
1884{
1885 if ((!buffer_journal_prepared(bh) && buffer_locked(bh)) ||
1886 !B_IS_IN_TREE(bh)) {
1887 reiserfs_warning(NULL,
1888 "vs-12339: locked_or_not_in_tree: %s (%b)",
1889 which, bh);
1890 return 1;
1891 }
1892 return 0;
1893}
1384 1894
1385static void check_after_balance_leaf (struct tree_balance * tb) 1895static int check_before_balancing(struct tree_balance *tb)
1386{ 1896{
1387 if (tb->lnum[0]) { 1897 int retval = 0;
1388 if (B_FREE_SPACE (tb->L[0]) != 1898
1389 MAX_CHILD_SIZE (tb->L[0]) - dc_size(B_N_CHILD (tb->FL[0], get_left_neighbor_position (tb, 0)))) { 1899 if (cur_tb) {
1390 print_cur_tb ("12221"); 1900 reiserfs_panic(tb->tb_sb, "vs-12335: check_before_balancing: "
1391 reiserfs_panic (tb->tb_sb, "PAP-12355: check_after_balance_leaf: shift to left was incorrect"); 1901 "suspect that schedule occurred based on cur_tb not being null at this point in code. "
1902 "do_balance cannot properly handle schedule occurring while it runs.");
1392 } 1903 }
1393 } 1904
1394 if (tb->rnum[0]) { 1905 /* double check that buffers that we will modify are unlocked. (fix_nodes should already have
1395 if (B_FREE_SPACE (tb->R[0]) != 1906 prepped all of these for us). */
1396 MAX_CHILD_SIZE (tb->R[0]) - dc_size(B_N_CHILD (tb->FR[0], get_right_neighbor_position (tb, 0)))) { 1907 if (tb->lnum[0]) {
1397 print_cur_tb ("12222"); 1908 retval |= locked_or_not_in_tree(tb->L[0], "L[0]");
1398 reiserfs_panic (tb->tb_sb, "PAP-12360: check_after_balance_leaf: shift to right was incorrect"); 1909 retval |= locked_or_not_in_tree(tb->FL[0], "FL[0]");
1910 retval |= locked_or_not_in_tree(tb->CFL[0], "CFL[0]");
1911 check_leaf(tb->L[0]);
1399 } 1912 }
1400 } 1913 if (tb->rnum[0]) {
1401 if (PATH_H_PBUFFER(tb->tb_path,1) && 1914 retval |= locked_or_not_in_tree(tb->R[0], "R[0]");
1402 (B_FREE_SPACE (PATH_H_PBUFFER(tb->tb_path,0)) != 1915 retval |= locked_or_not_in_tree(tb->FR[0], "FR[0]");
1403 (MAX_CHILD_SIZE (PATH_H_PBUFFER(tb->tb_path,0)) - 1916 retval |= locked_or_not_in_tree(tb->CFR[0], "CFR[0]");
1404 dc_size(B_N_CHILD (PATH_H_PBUFFER(tb->tb_path,1), 1917 check_leaf(tb->R[0]);
1405 PATH_H_POSITION (tb->tb_path, 1)))) )) { 1918 }
1406 int left = B_FREE_SPACE (PATH_H_PBUFFER(tb->tb_path,0)); 1919 retval |= locked_or_not_in_tree(PATH_PLAST_BUFFER(tb->tb_path), "S[0]");
1407 int right = (MAX_CHILD_SIZE (PATH_H_PBUFFER(tb->tb_path,0)) - 1920 check_leaf(PATH_PLAST_BUFFER(tb->tb_path));
1408 dc_size(B_N_CHILD (PATH_H_PBUFFER(tb->tb_path,1),
1409 PATH_H_POSITION (tb->tb_path, 1))));
1410 print_cur_tb ("12223");
1411 reiserfs_warning (tb->tb_sb,
1412 "B_FREE_SPACE (PATH_H_PBUFFER(tb->tb_path,0)) = %d; "
1413 "MAX_CHILD_SIZE (%d) - dc_size( %y, %d ) [%d] = %d",
1414 left,
1415 MAX_CHILD_SIZE (PATH_H_PBUFFER(tb->tb_path,0)),
1416 PATH_H_PBUFFER(tb->tb_path,1),
1417 PATH_H_POSITION (tb->tb_path, 1),
1418 dc_size(B_N_CHILD (PATH_H_PBUFFER(tb->tb_path,1), PATH_H_POSITION (tb->tb_path, 1 )) ),
1419 right );
1420 reiserfs_panic (tb->tb_sb, "PAP-12365: check_after_balance_leaf: S is incorrect");
1421 }
1422}
1423 1921
1922 return retval;
1923}
1424 1924
1425static void check_leaf_level (struct tree_balance * tb) 1925static void check_after_balance_leaf(struct tree_balance *tb)
1426{ 1926{
1427 check_leaf (tb->L[0]); 1927 if (tb->lnum[0]) {
1428 check_leaf (tb->R[0]); 1928 if (B_FREE_SPACE(tb->L[0]) !=
1429 check_leaf (PATH_PLAST_BUFFER (tb->tb_path)); 1929 MAX_CHILD_SIZE(tb->L[0]) -
1930 dc_size(B_N_CHILD
1931 (tb->FL[0], get_left_neighbor_position(tb, 0)))) {
1932 print_cur_tb("12221");
1933 reiserfs_panic(tb->tb_sb,
1934 "PAP-12355: check_after_balance_leaf: shift to left was incorrect");
1935 }
1936 }
1937 if (tb->rnum[0]) {
1938 if (B_FREE_SPACE(tb->R[0]) !=
1939 MAX_CHILD_SIZE(tb->R[0]) -
1940 dc_size(B_N_CHILD
1941 (tb->FR[0], get_right_neighbor_position(tb, 0)))) {
1942 print_cur_tb("12222");
1943 reiserfs_panic(tb->tb_sb,
1944 "PAP-12360: check_after_balance_leaf: shift to right was incorrect");
1945 }
1946 }
1947 if (PATH_H_PBUFFER(tb->tb_path, 1) &&
1948 (B_FREE_SPACE(PATH_H_PBUFFER(tb->tb_path, 0)) !=
1949 (MAX_CHILD_SIZE(PATH_H_PBUFFER(tb->tb_path, 0)) -
1950 dc_size(B_N_CHILD(PATH_H_PBUFFER(tb->tb_path, 1),
1951 PATH_H_POSITION(tb->tb_path, 1)))))) {
1952 int left = B_FREE_SPACE(PATH_H_PBUFFER(tb->tb_path, 0));
1953 int right = (MAX_CHILD_SIZE(PATH_H_PBUFFER(tb->tb_path, 0)) -
1954 dc_size(B_N_CHILD(PATH_H_PBUFFER(tb->tb_path, 1),
1955 PATH_H_POSITION(tb->tb_path,
1956 1))));
1957 print_cur_tb("12223");
1958 reiserfs_warning(tb->tb_sb,
1959 "B_FREE_SPACE (PATH_H_PBUFFER(tb->tb_path,0)) = %d; "
1960 "MAX_CHILD_SIZE (%d) - dc_size( %y, %d ) [%d] = %d",
1961 left,
1962 MAX_CHILD_SIZE(PATH_H_PBUFFER(tb->tb_path, 0)),
1963 PATH_H_PBUFFER(tb->tb_path, 1),
1964 PATH_H_POSITION(tb->tb_path, 1),
1965 dc_size(B_N_CHILD
1966 (PATH_H_PBUFFER(tb->tb_path, 1),
1967 PATH_H_POSITION(tb->tb_path, 1))),
1968 right);
1969 reiserfs_panic(tb->tb_sb,
1970 "PAP-12365: check_after_balance_leaf: S is incorrect");
1971 }
1430} 1972}
1431 1973
1432static void check_internal_levels (struct tree_balance * tb) 1974static void check_leaf_level(struct tree_balance *tb)
1433{ 1975{
1434 int h; 1976 check_leaf(tb->L[0]);
1977 check_leaf(tb->R[0]);
1978 check_leaf(PATH_PLAST_BUFFER(tb->tb_path));
1979}
1435 1980
1436 /* check all internal nodes */ 1981static void check_internal_levels(struct tree_balance *tb)
1437 for (h = 1; tb->insert_size[h]; h ++) { 1982{
1438 check_internal_node (tb->tb_sb, PATH_H_PBUFFER (tb->tb_path, h), "BAD BUFFER ON PATH"); 1983 int h;
1439 if (tb->lnum[h]) 1984
1440 check_internal_node (tb->tb_sb, tb->L[h], "BAD L"); 1985 /* check all internal nodes */
1441 if (tb->rnum[h]) 1986 for (h = 1; tb->insert_size[h]; h++) {
1442 check_internal_node (tb->tb_sb, tb->R[h], "BAD R"); 1987 check_internal_node(tb->tb_sb, PATH_H_PBUFFER(tb->tb_path, h),
1443 } 1988 "BAD BUFFER ON PATH");
1989 if (tb->lnum[h])
1990 check_internal_node(tb->tb_sb, tb->L[h], "BAD L");
1991 if (tb->rnum[h])
1992 check_internal_node(tb->tb_sb, tb->R[h], "BAD R");
1993 }
1444 1994
1445} 1995}
1446 1996
1447#endif 1997#endif
1448 1998
1449
1450
1451
1452
1453
1454/* Now we have all of the buffers that must be used in balancing of 1999/* Now we have all of the buffers that must be used in balancing of
1455 the tree. We rely on the assumption that schedule() will not occur 2000 the tree. We rely on the assumption that schedule() will not occur
1456 while do_balance works. ( Only interrupt handlers are acceptable.) 2001 while do_balance works. ( Only interrupt handlers are acceptable.)
@@ -1484,114 +2029,109 @@ static void check_internal_levels (struct tree_balance * tb)
1484 2029
1485*/ 2030*/
1486 2031
1487static inline void do_balance_starts (struct tree_balance *tb) 2032static inline void do_balance_starts(struct tree_balance *tb)
1488{ 2033{
1489 /* use print_cur_tb() to see initial state of struct 2034 /* use print_cur_tb() to see initial state of struct
1490 tree_balance */ 2035 tree_balance */
1491 2036
1492 /* store_print_tb (tb); */ 2037 /* store_print_tb (tb); */
1493 2038
1494 /* do not delete, just comment it out */ 2039 /* do not delete, just comment it out */
1495/* print_tb(flag, PATH_LAST_POSITION(tb->tb_path), tb->tb_path->pos_in_item, tb, 2040/* print_tb(flag, PATH_LAST_POSITION(tb->tb_path), tb->tb_path->pos_in_item, tb,
1496 "check");*/ 2041 "check");*/
1497 RFALSE( check_before_balancing (tb), "PAP-12340: locked buffers in TB"); 2042 RFALSE(check_before_balancing(tb), "PAP-12340: locked buffers in TB");
1498#ifdef CONFIG_REISERFS_CHECK 2043#ifdef CONFIG_REISERFS_CHECK
1499 cur_tb = tb; 2044 cur_tb = tb;
1500#endif 2045#endif
1501} 2046}
1502 2047
1503 2048static inline void do_balance_completed(struct tree_balance *tb)
1504static inline void do_balance_completed (struct tree_balance * tb)
1505{ 2049{
1506 2050
1507#ifdef CONFIG_REISERFS_CHECK 2051#ifdef CONFIG_REISERFS_CHECK
1508 check_leaf_level (tb); 2052 check_leaf_level(tb);
1509 check_internal_levels (tb); 2053 check_internal_levels(tb);
1510 cur_tb = NULL; 2054 cur_tb = NULL;
1511#endif 2055#endif
1512 2056
1513 /* reiserfs_free_block is no longer schedule safe. So, we need to 2057 /* reiserfs_free_block is no longer schedule safe. So, we need to
1514 ** put the buffers we want freed on the thrown list during do_balance, 2058 ** put the buffers we want freed on the thrown list during do_balance,
1515 ** and then free them now 2059 ** and then free them now
1516 */ 2060 */
1517
1518 REISERFS_SB(tb->tb_sb)->s_do_balance ++;
1519 2061
2062 REISERFS_SB(tb->tb_sb)->s_do_balance++;
1520 2063
1521 /* release all nodes hold to perform the balancing */ 2064 /* release all nodes hold to perform the balancing */
1522 unfix_nodes(tb); 2065 unfix_nodes(tb);
1523 2066
1524 free_thrown(tb) ; 2067 free_thrown(tb);
1525} 2068}
1526 2069
2070void do_balance(struct tree_balance *tb, /* tree_balance structure */
2071 struct item_head *ih, /* item header of inserted item */
2072 const char *body, /* body of inserted item or bytes to paste */
2073 int flag)
2074{ /* i - insert, d - delete
2075 c - cut, p - paste
2076
2077 Cut means delete part of an item
2078 (includes removing an entry from a
2079 directory).
2080
2081 Delete means delete whole item.
2082
2083 Insert means add a new item into the
2084 tree.
2085
2086 Paste means to append to the end of an
2087 existing file or to insert a directory
2088 entry. */
2089 int child_pos, /* position of a child node in its parent */
2090 h; /* level of the tree being processed */
2091 struct item_head insert_key[2]; /* in our processing of one level
2092 we sometimes determine what
2093 must be inserted into the next
2094 higher level. This insertion
2095 consists of a key or two keys
2096 and their corresponding
2097 pointers */
2098 struct buffer_head *insert_ptr[2]; /* inserted node-ptrs for the next
2099 level */
2100
2101 tb->tb_mode = flag;
2102 tb->need_balance_dirty = 0;
2103
2104 if (FILESYSTEM_CHANGED_TB(tb)) {
2105 reiserfs_panic(tb->tb_sb,
2106 "clm-6000: do_balance, fs generation has changed\n");
2107 }
2108 /* if we have no real work to do */
2109 if (!tb->insert_size[0]) {
2110 reiserfs_warning(tb->tb_sb,
2111 "PAP-12350: do_balance: insert_size == 0, mode == %c",
2112 flag);
2113 unfix_nodes(tb);
2114 return;
2115 }
1527 2116
2117 atomic_inc(&(fs_generation(tb->tb_sb)));
2118 do_balance_starts(tb);
1528 2119
1529
1530
1531void do_balance (struct tree_balance * tb, /* tree_balance structure */
1532 struct item_head * ih, /* item header of inserted item */
1533 const char * body, /* body of inserted item or bytes to paste */
1534 int flag) /* i - insert, d - delete
1535 c - cut, p - paste
1536
1537 Cut means delete part of an item
1538 (includes removing an entry from a
1539 directory).
1540
1541 Delete means delete whole item.
1542
1543 Insert means add a new item into the
1544 tree.
1545
1546 Paste means to append to the end of an
1547 existing file or to insert a directory
1548 entry. */
1549{
1550 int child_pos, /* position of a child node in its parent */
1551 h; /* level of the tree being processed */
1552 struct item_head insert_key[2]; /* in our processing of one level
1553 we sometimes determine what
1554 must be inserted into the next
1555 higher level. This insertion
1556 consists of a key or two keys
1557 and their corresponding
1558 pointers */
1559 struct buffer_head *insert_ptr[2]; /* inserted node-ptrs for the next
1560 level */
1561
1562 tb->tb_mode = flag;
1563 tb->need_balance_dirty = 0;
1564
1565 if (FILESYSTEM_CHANGED_TB(tb)) {
1566 reiserfs_panic(tb->tb_sb, "clm-6000: do_balance, fs generation has changed\n") ;
1567 }
1568 /* if we have no real work to do */
1569 if ( ! tb->insert_size[0] ) {
1570 reiserfs_warning (tb->tb_sb,
1571 "PAP-12350: do_balance: insert_size == 0, mode == %c",
1572 flag);
1573 unfix_nodes(tb);
1574 return;
1575 }
1576
1577 atomic_inc (&(fs_generation (tb->tb_sb)));
1578 do_balance_starts (tb);
1579
1580 /* balance leaf returns 0 except if combining L R and S into 2120 /* balance leaf returns 0 except if combining L R and S into
1581 one node. see balance_internal() for explanation of this 2121 one node. see balance_internal() for explanation of this
1582 line of code.*/ 2122 line of code. */
1583 child_pos = PATH_H_B_ITEM_ORDER (tb->tb_path, 0) + 2123 child_pos = PATH_H_B_ITEM_ORDER(tb->tb_path, 0) +
1584 balance_leaf (tb, ih, body, flag, insert_key, insert_ptr); 2124 balance_leaf(tb, ih, body, flag, insert_key, insert_ptr);
1585 2125
1586#ifdef CONFIG_REISERFS_CHECK 2126#ifdef CONFIG_REISERFS_CHECK
1587 check_after_balance_leaf (tb); 2127 check_after_balance_leaf(tb);
1588#endif 2128#endif
1589 2129
1590 /* Balance internal level of the tree. */ 2130 /* Balance internal level of the tree. */
1591 for ( h = 1; h < MAX_HEIGHT && tb->insert_size[h]; h++ ) 2131 for (h = 1; h < MAX_HEIGHT && tb->insert_size[h]; h++)
1592 child_pos = balance_internal (tb, h, child_pos, insert_key, insert_ptr); 2132 child_pos =
1593 2133 balance_internal(tb, h, child_pos, insert_key, insert_ptr);
1594 2134
1595 do_balance_completed (tb); 2135 do_balance_completed(tb);
1596 2136
1597} 2137}
diff --git a/fs/reiserfs/file.c b/fs/reiserfs/file.c
index 12e91209544e..c9f178fb494f 100644
--- a/fs/reiserfs/file.c
+++ b/fs/reiserfs/file.c
@@ -2,7 +2,6 @@
2 * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README 2 * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
3 */ 3 */
4 4
5
6#include <linux/time.h> 5#include <linux/time.h>
7#include <linux/reiserfs_fs.h> 6#include <linux/reiserfs_fs.h>
8#include <linux/reiserfs_acl.h> 7#include <linux/reiserfs_acl.h>
@@ -31,82 +30,84 @@
31** We use reiserfs_truncate_file to pack the tail, since it already has 30** We use reiserfs_truncate_file to pack the tail, since it already has
32** all the conditions coded. 31** all the conditions coded.
33*/ 32*/
34static int reiserfs_file_release (struct inode * inode, struct file * filp) 33static int reiserfs_file_release(struct inode *inode, struct file *filp)
35{ 34{
36 35
37 struct reiserfs_transaction_handle th ; 36 struct reiserfs_transaction_handle th;
38 int err; 37 int err;
39 int jbegin_failure = 0; 38 int jbegin_failure = 0;
40 39
41 if (!S_ISREG (inode->i_mode)) 40 if (!S_ISREG(inode->i_mode))
42 BUG (); 41 BUG();
43 42
44 /* fast out for when nothing needs to be done */ 43 /* fast out for when nothing needs to be done */
45 if ((atomic_read(&inode->i_count) > 1 || 44 if ((atomic_read(&inode->i_count) > 1 ||
46 !(REISERFS_I(inode)->i_flags & i_pack_on_close_mask) || 45 !(REISERFS_I(inode)->i_flags & i_pack_on_close_mask) ||
47 !tail_has_to_be_packed(inode)) && 46 !tail_has_to_be_packed(inode)) &&
48 REISERFS_I(inode)->i_prealloc_count <= 0) { 47 REISERFS_I(inode)->i_prealloc_count <= 0) {
49 return 0; 48 return 0;
50 } 49 }
51
52 reiserfs_write_lock(inode->i_sb);
53 down (&inode->i_sem);
54 /* freeing preallocation only involves relogging blocks that
55 * are already in the current transaction. preallocation gets
56 * freed at the end of each transaction, so it is impossible for
57 * us to log any additional blocks (including quota blocks)
58 */
59 err = journal_begin(&th, inode->i_sb, 1);
60 if (err) {
61 /* uh oh, we can't allow the inode to go away while there
62 * is still preallocation blocks pending. Try to join the
63 * aborted transaction
64 */
65 jbegin_failure = err;
66 err = journal_join_abort(&th, inode->i_sb, 1);
67 50
51 reiserfs_write_lock(inode->i_sb);
52 down(&inode->i_sem);
53 /* freeing preallocation only involves relogging blocks that
54 * are already in the current transaction. preallocation gets
55 * freed at the end of each transaction, so it is impossible for
56 * us to log any additional blocks (including quota blocks)
57 */
58 err = journal_begin(&th, inode->i_sb, 1);
68 if (err) { 59 if (err) {
69 /* hmpf, our choices here aren't good. We can pin the inode 60 /* uh oh, we can't allow the inode to go away while there
70 * which will disallow unmount from every happening, we can 61 * is still preallocation blocks pending. Try to join the
71 * do nothing, which will corrupt random memory on unmount, 62 * aborted transaction
72 * or we can forcibly remove the file from the preallocation 63 */
73 * list, which will leak blocks on disk. Lets pin the inode 64 jbegin_failure = err;
74 * and let the admin know what is going on. 65 err = journal_join_abort(&th, inode->i_sb, 1);
75 */ 66
76 igrab(inode); 67 if (err) {
77 reiserfs_warning(inode->i_sb, "pinning inode %lu because the " 68 /* hmpf, our choices here aren't good. We can pin the inode
78 "preallocation can't be freed"); 69 * which will disallow unmount from every happening, we can
79 goto out; 70 * do nothing, which will corrupt random memory on unmount,
71 * or we can forcibly remove the file from the preallocation
72 * list, which will leak blocks on disk. Lets pin the inode
73 * and let the admin know what is going on.
74 */
75 igrab(inode);
76 reiserfs_warning(inode->i_sb,
77 "pinning inode %lu because the "
78 "preallocation can't be freed");
79 goto out;
80 }
80 } 81 }
81 } 82 reiserfs_update_inode_transaction(inode);
82 reiserfs_update_inode_transaction(inode) ;
83 83
84#ifdef REISERFS_PREALLOCATE 84#ifdef REISERFS_PREALLOCATE
85 reiserfs_discard_prealloc (&th, inode); 85 reiserfs_discard_prealloc(&th, inode);
86#endif 86#endif
87 err = journal_end(&th, inode->i_sb, 1); 87 err = journal_end(&th, inode->i_sb, 1);
88 88
89 /* copy back the error code from journal_begin */ 89 /* copy back the error code from journal_begin */
90 if (!err) 90 if (!err)
91 err = jbegin_failure; 91 err = jbegin_failure;
92 92
93 if (!err && atomic_read(&inode->i_count) <= 1 && 93 if (!err && atomic_read(&inode->i_count) <= 1 &&
94 (REISERFS_I(inode)->i_flags & i_pack_on_close_mask) && 94 (REISERFS_I(inode)->i_flags & i_pack_on_close_mask) &&
95 tail_has_to_be_packed (inode)) { 95 tail_has_to_be_packed(inode)) {
96 /* if regular file is released by last holder and it has been 96 /* if regular file is released by last holder and it has been
97 appended (we append by unformatted node only) or its direct 97 appended (we append by unformatted node only) or its direct
98 item(s) had to be converted, then it may have to be 98 item(s) had to be converted, then it may have to be
99 indirect2direct converted */ 99 indirect2direct converted */
100 err = reiserfs_truncate_file(inode, 0) ; 100 err = reiserfs_truncate_file(inode, 0);
101 } 101 }
102out: 102 out:
103 up (&inode->i_sem); 103 up(&inode->i_sem);
104 reiserfs_write_unlock(inode->i_sb); 104 reiserfs_write_unlock(inode->i_sb);
105 return err; 105 return err;
106} 106}
107 107
108static void reiserfs_vfs_truncate_file(struct inode *inode) { 108static void reiserfs_vfs_truncate_file(struct inode *inode)
109 reiserfs_truncate_file(inode, 1) ; 109{
110 reiserfs_truncate_file(inode, 1);
110} 111}
111 112
112/* Sync a reiserfs file. */ 113/* Sync a reiserfs file. */
@@ -116,26 +117,24 @@ static void reiserfs_vfs_truncate_file(struct inode *inode) {
116 * be removed... 117 * be removed...
117 */ 118 */
118 119
119static int reiserfs_sync_file( 120static int reiserfs_sync_file(struct file *p_s_filp,
120 struct file * p_s_filp, 121 struct dentry *p_s_dentry, int datasync)
121 struct dentry * p_s_dentry, 122{
122 int datasync 123 struct inode *p_s_inode = p_s_dentry->d_inode;
123 ) { 124 int n_err;
124 struct inode * p_s_inode = p_s_dentry->d_inode; 125 int barrier_done;
125 int n_err; 126
126 int barrier_done; 127 if (!S_ISREG(p_s_inode->i_mode))
127 128 BUG();
128 if (!S_ISREG(p_s_inode->i_mode)) 129 n_err = sync_mapping_buffers(p_s_inode->i_mapping);
129 BUG (); 130 reiserfs_write_lock(p_s_inode->i_sb);
130 n_err = sync_mapping_buffers(p_s_inode->i_mapping) ; 131 barrier_done = reiserfs_commit_for_inode(p_s_inode);
131 reiserfs_write_lock(p_s_inode->i_sb); 132 reiserfs_write_unlock(p_s_inode->i_sb);
132 barrier_done = reiserfs_commit_for_inode(p_s_inode); 133 if (barrier_done != 1)
133 reiserfs_write_unlock(p_s_inode->i_sb); 134 blkdev_issue_flush(p_s_inode->i_sb->s_bdev, NULL);
134 if (barrier_done != 1) 135 if (barrier_done < 0)
135 blkdev_issue_flush(p_s_inode->i_sb->s_bdev, NULL); 136 return barrier_done;
136 if (barrier_done < 0) 137 return (n_err < 0) ? -EIO : 0;
137 return barrier_done;
138 return ( n_err < 0 ) ? -EIO : 0;
139} 138}
140 139
141/* I really do not want to play with memory shortage right now, so 140/* I really do not want to play with memory shortage right now, so
@@ -147,700 +146,797 @@ static int reiserfs_sync_file(
147/* Allocates blocks for a file to fulfil write request. 146/* Allocates blocks for a file to fulfil write request.
148 Maps all unmapped but prepared pages from the list. 147 Maps all unmapped but prepared pages from the list.
149 Updates metadata with newly allocated blocknumbers as needed */ 148 Updates metadata with newly allocated blocknumbers as needed */
150static int reiserfs_allocate_blocks_for_region( 149static int reiserfs_allocate_blocks_for_region(struct reiserfs_transaction_handle *th, struct inode *inode, /* Inode we work with */
151 struct reiserfs_transaction_handle *th, 150 loff_t pos, /* Writing position */
152 struct inode *inode, /* Inode we work with */ 151 int num_pages, /* number of pages write going
153 loff_t pos, /* Writing position */ 152 to touch */
154 int num_pages, /* number of pages write going 153 int write_bytes, /* amount of bytes to write */
155 to touch */ 154 struct page **prepared_pages, /* array of
156 int write_bytes, /* amount of bytes to write */ 155 prepared pages
157 struct page **prepared_pages, /* array of 156 */
158 prepared pages 157 int blocks_to_allocate /* Amount of blocks we
159 */ 158 need to allocate to
160 int blocks_to_allocate /* Amount of blocks we 159 fit the data into file
161 need to allocate to 160 */
162 fit the data into file 161 )
163 */
164 )
165{ 162{
166 struct cpu_key key; // cpu key of item that we are going to deal with 163 struct cpu_key key; // cpu key of item that we are going to deal with
167 struct item_head *ih; // pointer to item head that we are going to deal with 164 struct item_head *ih; // pointer to item head that we are going to deal with
168 struct buffer_head *bh; // Buffer head that contains items that we are going to deal with 165 struct buffer_head *bh; // Buffer head that contains items that we are going to deal with
169 __le32 * item; // pointer to item we are going to deal with 166 __le32 *item; // pointer to item we are going to deal with
170 INITIALIZE_PATH(path); // path to item, that we are going to deal with. 167 INITIALIZE_PATH(path); // path to item, that we are going to deal with.
171 b_blocknr_t *allocated_blocks; // Pointer to a place where allocated blocknumbers would be stored. 168 b_blocknr_t *allocated_blocks; // Pointer to a place where allocated blocknumbers would be stored.
172 reiserfs_blocknr_hint_t hint; // hint structure for block allocator. 169 reiserfs_blocknr_hint_t hint; // hint structure for block allocator.
173 size_t res; // return value of various functions that we call. 170 size_t res; // return value of various functions that we call.
174 int curr_block; // current block used to keep track of unmapped blocks. 171 int curr_block; // current block used to keep track of unmapped blocks.
175 int i; // loop counter 172 int i; // loop counter
176 int itempos; // position in item 173 int itempos; // position in item
177 unsigned int from = (pos & (PAGE_CACHE_SIZE - 1)); // writing position in 174 unsigned int from = (pos & (PAGE_CACHE_SIZE - 1)); // writing position in
178 // first page 175 // first page
179 unsigned int to = ((pos + write_bytes - 1) & (PAGE_CACHE_SIZE - 1)) + 1; /* last modified byte offset in last page */ 176 unsigned int to = ((pos + write_bytes - 1) & (PAGE_CACHE_SIZE - 1)) + 1; /* last modified byte offset in last page */
180 __u64 hole_size ; // amount of blocks for a file hole, if it needed to be created. 177 __u64 hole_size; // amount of blocks for a file hole, if it needed to be created.
181 int modifying_this_item = 0; // Flag for items traversal code to keep track 178 int modifying_this_item = 0; // Flag for items traversal code to keep track
182 // of the fact that we already prepared 179 // of the fact that we already prepared
183 // current block for journal 180 // current block for journal
184 int will_prealloc = 0; 181 int will_prealloc = 0;
185 RFALSE(!blocks_to_allocate, "green-9004: tried to allocate zero blocks?"); 182 RFALSE(!blocks_to_allocate,
186 183 "green-9004: tried to allocate zero blocks?");
187 /* only preallocate if this is a small write */ 184
188 if (REISERFS_I(inode)->i_prealloc_count || 185 /* only preallocate if this is a small write */
189 (!(write_bytes & (inode->i_sb->s_blocksize -1)) && 186 if (REISERFS_I(inode)->i_prealloc_count ||
190 blocks_to_allocate < 187 (!(write_bytes & (inode->i_sb->s_blocksize - 1)) &&
191 REISERFS_SB(inode->i_sb)->s_alloc_options.preallocsize)) 188 blocks_to_allocate <
192 will_prealloc = REISERFS_SB(inode->i_sb)->s_alloc_options.preallocsize; 189 REISERFS_SB(inode->i_sb)->s_alloc_options.preallocsize))
193 190 will_prealloc =
194 allocated_blocks = kmalloc((blocks_to_allocate + will_prealloc) * 191 REISERFS_SB(inode->i_sb)->s_alloc_options.preallocsize;
195 sizeof(b_blocknr_t), GFP_NOFS); 192
196 193 allocated_blocks = kmalloc((blocks_to_allocate + will_prealloc) *
197 /* First we compose a key to point at the writing position, we want to do 194 sizeof(b_blocknr_t), GFP_NOFS);
198 that outside of any locking region. */ 195
199 make_cpu_key (&key, inode, pos+1, TYPE_ANY, 3/*key length*/); 196 /* First we compose a key to point at the writing position, we want to do
200 197 that outside of any locking region. */
201 /* If we came here, it means we absolutely need to open a transaction, 198 make_cpu_key(&key, inode, pos + 1, TYPE_ANY, 3 /*key length */ );
202 since we need to allocate some blocks */ 199
203 reiserfs_write_lock(inode->i_sb); // Journaling stuff and we need that. 200 /* If we came here, it means we absolutely need to open a transaction,
204 res = journal_begin(th, inode->i_sb, JOURNAL_PER_BALANCE_CNT * 3 + 1 + 2 * REISERFS_QUOTA_TRANS_BLOCKS(inode->i_sb)); // Wish I know if this number enough 201 since we need to allocate some blocks */
205 if (res) 202 reiserfs_write_lock(inode->i_sb); // Journaling stuff and we need that.
206 goto error_exit; 203 res = journal_begin(th, inode->i_sb, JOURNAL_PER_BALANCE_CNT * 3 + 1 + 2 * REISERFS_QUOTA_TRANS_BLOCKS(inode->i_sb)); // Wish I know if this number enough
207 reiserfs_update_inode_transaction(inode) ; 204 if (res)
208
209 /* Look for the in-tree position of our write, need path for block allocator */
210 res = search_for_position_by_key(inode->i_sb, &key, &path);
211 if ( res == IO_ERROR ) {
212 res = -EIO;
213 goto error_exit;
214 }
215
216 /* Allocate blocks */
217 /* First fill in "hint" structure for block allocator */
218 hint.th = th; // transaction handle.
219 hint.path = &path; // Path, so that block allocator can determine packing locality or whatever it needs to determine.
220 hint.inode = inode; // Inode is needed by block allocator too.
221 hint.search_start = 0; // We have no hint on where to search free blocks for block allocator.
222 hint.key = key.on_disk_key; // on disk key of file.
223 hint.block = inode->i_blocks>>(inode->i_sb->s_blocksize_bits-9); // Number of disk blocks this file occupies already.
224 hint.formatted_node = 0; // We are allocating blocks for unformatted node.
225 hint.preallocate = will_prealloc;
226
227 /* Call block allocator to allocate blocks */
228 res = reiserfs_allocate_blocknrs(&hint, allocated_blocks, blocks_to_allocate, blocks_to_allocate);
229 if ( res != CARRY_ON ) {
230 if ( res == NO_DISK_SPACE ) {
231 /* We flush the transaction in case of no space. This way some
232 blocks might become free */
233 SB_JOURNAL(inode->i_sb)->j_must_wait = 1;
234 res = restart_transaction(th, inode, &path);
235 if (res)
236 goto error_exit;
237
238 /* We might have scheduled, so search again */
239 res = search_for_position_by_key(inode->i_sb, &key, &path);
240 if ( res == IO_ERROR ) {
241 res = -EIO;
242 goto error_exit; 205 goto error_exit;
243 } 206 reiserfs_update_inode_transaction(inode);
244 207
245 /* update changed info for hint structure. */ 208 /* Look for the in-tree position of our write, need path for block allocator */
246 res = reiserfs_allocate_blocknrs(&hint, allocated_blocks, blocks_to_allocate, blocks_to_allocate); 209 res = search_for_position_by_key(inode->i_sb, &key, &path);
247 if ( res != CARRY_ON ) { 210 if (res == IO_ERROR) {
248 res = -ENOSPC; 211 res = -EIO;
249 pathrelse(&path);
250 goto error_exit; 212 goto error_exit;
251 }
252 } else {
253 res = -ENOSPC;
254 pathrelse(&path);
255 goto error_exit;
256 } 213 }
257 }
258 214
259#ifdef __BIG_ENDIAN 215 /* Allocate blocks */
260 // Too bad, I have not found any way to convert a given region from 216 /* First fill in "hint" structure for block allocator */
261 // cpu format to little endian format 217 hint.th = th; // transaction handle.
262 { 218 hint.path = &path; // Path, so that block allocator can determine packing locality or whatever it needs to determine.
263 int i; 219 hint.inode = inode; // Inode is needed by block allocator too.
264 for ( i = 0; i < blocks_to_allocate ; i++) 220 hint.search_start = 0; // We have no hint on where to search free blocks for block allocator.
265 allocated_blocks[i]=cpu_to_le32(allocated_blocks[i]); 221 hint.key = key.on_disk_key; // on disk key of file.
266 } 222 hint.block = inode->i_blocks >> (inode->i_sb->s_blocksize_bits - 9); // Number of disk blocks this file occupies already.
267#endif 223 hint.formatted_node = 0; // We are allocating blocks for unformatted node.
268 224 hint.preallocate = will_prealloc;
269 /* Blocks allocating well might have scheduled and tree might have changed, 225
270 let's search the tree again */ 226 /* Call block allocator to allocate blocks */
271 /* find where in the tree our write should go */ 227 res =
272 res = search_for_position_by_key(inode->i_sb, &key, &path); 228 reiserfs_allocate_blocknrs(&hint, allocated_blocks,
273 if ( res == IO_ERROR ) { 229 blocks_to_allocate, blocks_to_allocate);
274 res = -EIO; 230 if (res != CARRY_ON) {
275 goto error_exit_free_blocks; 231 if (res == NO_DISK_SPACE) {
276 } 232 /* We flush the transaction in case of no space. This way some
277 233 blocks might become free */
278 bh = get_last_bh( &path ); // Get a bufferhead for last element in path. 234 SB_JOURNAL(inode->i_sb)->j_must_wait = 1;
279 ih = get_ih( &path ); // Get a pointer to last item head in path. 235 res = restart_transaction(th, inode, &path);
280 item = get_item( &path ); // Get a pointer to last item in path 236 if (res)
281 237 goto error_exit;
282 /* Let's see what we have found */ 238
283 if ( res != POSITION_FOUND ) { /* position not found, this means that we 239 /* We might have scheduled, so search again */
284 might need to append file with holes 240 res =
285 first */ 241 search_for_position_by_key(inode->i_sb, &key,
286 // Since we are writing past the file's end, we need to find out if 242 &path);
287 // there is a hole that needs to be inserted before our writing 243 if (res == IO_ERROR) {
288 // position, and how many blocks it is going to cover (we need to 244 res = -EIO;
289 // populate pointers to file blocks representing the hole with zeros) 245 goto error_exit;
246 }
290 247
248 /* update changed info for hint structure. */
249 res =
250 reiserfs_allocate_blocknrs(&hint, allocated_blocks,
251 blocks_to_allocate,
252 blocks_to_allocate);
253 if (res != CARRY_ON) {
254 res = -ENOSPC;
255 pathrelse(&path);
256 goto error_exit;
257 }
258 } else {
259 res = -ENOSPC;
260 pathrelse(&path);
261 goto error_exit;
262 }
263 }
264#ifdef __BIG_ENDIAN
265 // Too bad, I have not found any way to convert a given region from
266 // cpu format to little endian format
291 { 267 {
292 int item_offset = 1; 268 int i;
293 /* 269 for (i = 0; i < blocks_to_allocate; i++)
294 * if ih is stat data, its offset is 0 and we don't want to 270 allocated_blocks[i] = cpu_to_le32(allocated_blocks[i]);
295 * add 1 to pos in the hole_size calculation
296 */
297 if (is_statdata_le_ih(ih))
298 item_offset = 0;
299 hole_size = (pos + item_offset -
300 (le_key_k_offset( get_inode_item_key_version(inode),
301 &(ih->ih_key)) +
302 op_bytes_number(ih, inode->i_sb->s_blocksize))) >>
303 inode->i_sb->s_blocksize_bits;
304 } 271 }
272#endif
305 273
306 if ( hole_size > 0 ) { 274 /* Blocks allocating well might have scheduled and tree might have changed,
307 int to_paste = min_t(__u64, hole_size, MAX_ITEM_LEN(inode->i_sb->s_blocksize)/UNFM_P_SIZE ); // How much data to insert first time. 275 let's search the tree again */
308 /* area filled with zeroes, to supply as list of zero blocknumbers 276 /* find where in the tree our write should go */
309 We allocate it outside of loop just in case loop would spin for 277 res = search_for_position_by_key(inode->i_sb, &key, &path);
310 several iterations. */ 278 if (res == IO_ERROR) {
311 char *zeros = kmalloc(to_paste*UNFM_P_SIZE, GFP_ATOMIC); // We cannot insert more than MAX_ITEM_LEN bytes anyway. 279 res = -EIO;
312 if ( !zeros ) {
313 res = -ENOMEM;
314 goto error_exit_free_blocks; 280 goto error_exit_free_blocks;
315 } 281 }
316 memset ( zeros, 0, to_paste*UNFM_P_SIZE); 282
317 do { 283 bh = get_last_bh(&path); // Get a bufferhead for last element in path.
318 to_paste = min_t(__u64, hole_size, MAX_ITEM_LEN(inode->i_sb->s_blocksize)/UNFM_P_SIZE ); 284 ih = get_ih(&path); // Get a pointer to last item head in path.
319 if ( is_indirect_le_ih(ih) ) { 285 item = get_item(&path); // Get a pointer to last item in path
320 /* Ok, there is existing indirect item already. Need to append it */ 286
321 /* Calculate position past inserted item */ 287 /* Let's see what we have found */
322 make_cpu_key( &key, inode, le_key_k_offset( get_inode_item_key_version(inode), &(ih->ih_key)) + op_bytes_number(ih, inode->i_sb->s_blocksize), TYPE_INDIRECT, 3); 288 if (res != POSITION_FOUND) { /* position not found, this means that we
323 res = reiserfs_paste_into_item( th, &path, &key, inode, (char *)zeros, UNFM_P_SIZE*to_paste); 289 might need to append file with holes
324 if ( res ) { 290 first */
325 kfree(zeros); 291 // Since we are writing past the file's end, we need to find out if
326 goto error_exit_free_blocks; 292 // there is a hole that needs to be inserted before our writing
327 } 293 // position, and how many blocks it is going to cover (we need to
328 } else if ( is_statdata_le_ih(ih) ) { 294 // populate pointers to file blocks representing the hole with zeros)
329 /* No existing item, create it */ 295
330 /* item head for new item */ 296 {
331 struct item_head ins_ih; 297 int item_offset = 1;
332 298 /*
333 /* create a key for our new item */ 299 * if ih is stat data, its offset is 0 and we don't want to
334 make_cpu_key( &key, inode, 1, TYPE_INDIRECT, 3); 300 * add 1 to pos in the hole_size calculation
335 301 */
336 /* Create new item head for our new item */ 302 if (is_statdata_le_ih(ih))
337 make_le_item_head (&ins_ih, &key, key.version, 1, 303 item_offset = 0;
338 TYPE_INDIRECT, to_paste*UNFM_P_SIZE, 304 hole_size = (pos + item_offset -
339 0 /* free space */); 305 (le_key_k_offset
340 306 (get_inode_item_key_version(inode),
341 /* Find where such item should live in the tree */ 307 &(ih->ih_key)) + op_bytes_number(ih,
342 res = search_item (inode->i_sb, &key, &path); 308 inode->
343 if ( res != ITEM_NOT_FOUND ) { 309 i_sb->
344 /* item should not exist, otherwise we have error */ 310 s_blocksize)))
345 if ( res != -ENOSPC ) { 311 >> inode->i_sb->s_blocksize_bits;
346 reiserfs_warning (inode->i_sb, 312 }
347 "green-9008: search_by_key (%K) returned %d", 313
348 &key, res); 314 if (hole_size > 0) {
315 int to_paste = min_t(__u64, hole_size, MAX_ITEM_LEN(inode->i_sb->s_blocksize) / UNFM_P_SIZE); // How much data to insert first time.
316 /* area filled with zeroes, to supply as list of zero blocknumbers
317 We allocate it outside of loop just in case loop would spin for
318 several iterations. */
319 char *zeros = kmalloc(to_paste * UNFM_P_SIZE, GFP_ATOMIC); // We cannot insert more than MAX_ITEM_LEN bytes anyway.
320 if (!zeros) {
321 res = -ENOMEM;
322 goto error_exit_free_blocks;
349 } 323 }
350 res = -EIO; 324 memset(zeros, 0, to_paste * UNFM_P_SIZE);
351 kfree(zeros); 325 do {
352 goto error_exit_free_blocks; 326 to_paste =
353 } 327 min_t(__u64, hole_size,
354 res = reiserfs_insert_item( th, &path, &key, &ins_ih, inode, (char *)zeros); 328 MAX_ITEM_LEN(inode->i_sb->
355 } else { 329 s_blocksize) /
356 reiserfs_panic(inode->i_sb, "green-9011: Unexpected key type %K\n", &key); 330 UNFM_P_SIZE);
331 if (is_indirect_le_ih(ih)) {
332 /* Ok, there is existing indirect item already. Need to append it */
333 /* Calculate position past inserted item */
334 make_cpu_key(&key, inode,
335 le_key_k_offset
336 (get_inode_item_key_version
337 (inode),
338 &(ih->ih_key)) +
339 op_bytes_number(ih,
340 inode->
341 i_sb->
342 s_blocksize),
343 TYPE_INDIRECT, 3);
344 res =
345 reiserfs_paste_into_item(th, &path,
346 &key,
347 inode,
348 (char *)
349 zeros,
350 UNFM_P_SIZE
351 *
352 to_paste);
353 if (res) {
354 kfree(zeros);
355 goto error_exit_free_blocks;
356 }
357 } else if (is_statdata_le_ih(ih)) {
358 /* No existing item, create it */
359 /* item head for new item */
360 struct item_head ins_ih;
361
362 /* create a key for our new item */
363 make_cpu_key(&key, inode, 1,
364 TYPE_INDIRECT, 3);
365
366 /* Create new item head for our new item */
367 make_le_item_head(&ins_ih, &key,
368 key.version, 1,
369 TYPE_INDIRECT,
370 to_paste *
371 UNFM_P_SIZE,
372 0 /* free space */ );
373
374 /* Find where such item should live in the tree */
375 res =
376 search_item(inode->i_sb, &key,
377 &path);
378 if (res != ITEM_NOT_FOUND) {
379 /* item should not exist, otherwise we have error */
380 if (res != -ENOSPC) {
381 reiserfs_warning(inode->
382 i_sb,
383 "green-9008: search_by_key (%K) returned %d",
384 &key,
385 res);
386 }
387 res = -EIO;
388 kfree(zeros);
389 goto error_exit_free_blocks;
390 }
391 res =
392 reiserfs_insert_item(th, &path,
393 &key, &ins_ih,
394 inode,
395 (char *)zeros);
396 } else {
397 reiserfs_panic(inode->i_sb,
398 "green-9011: Unexpected key type %K\n",
399 &key);
400 }
401 if (res) {
402 kfree(zeros);
403 goto error_exit_free_blocks;
404 }
405 /* Now we want to check if transaction is too full, and if it is
406 we restart it. This will also free the path. */
407 if (journal_transaction_should_end
408 (th, th->t_blocks_allocated)) {
409 res =
410 restart_transaction(th, inode,
411 &path);
412 if (res) {
413 pathrelse(&path);
414 kfree(zeros);
415 goto error_exit;
416 }
417 }
418
419 /* Well, need to recalculate path and stuff */
420 set_cpu_key_k_offset(&key,
421 cpu_key_k_offset(&key) +
422 (to_paste << inode->
423 i_blkbits));
424 res =
425 search_for_position_by_key(inode->i_sb,
426 &key, &path);
427 if (res == IO_ERROR) {
428 res = -EIO;
429 kfree(zeros);
430 goto error_exit_free_blocks;
431 }
432 bh = get_last_bh(&path);
433 ih = get_ih(&path);
434 item = get_item(&path);
435 hole_size -= to_paste;
436 } while (hole_size);
437 kfree(zeros);
357 } 438 }
358 if ( res ) { 439 }
359 kfree(zeros); 440 // Go through existing indirect items first
360 goto error_exit_free_blocks; 441 // replace all zeroes with blocknumbers from list
442 // Note that if no corresponding item was found, by previous search,
443 // it means there are no existing in-tree representation for file area
444 // we are going to overwrite, so there is nothing to scan through for holes.
445 for (curr_block = 0, itempos = path.pos_in_item;
446 curr_block < blocks_to_allocate && res == POSITION_FOUND;) {
447 retry:
448
449 if (itempos >= ih_item_len(ih) / UNFM_P_SIZE) {
450 /* We run out of data in this indirect item, let's look for another
451 one. */
452 /* First if we are already modifying current item, log it */
453 if (modifying_this_item) {
454 journal_mark_dirty(th, inode->i_sb, bh);
455 modifying_this_item = 0;
456 }
457 /* Then set the key to look for a new indirect item (offset of old
458 item is added to old item length */
459 set_cpu_key_k_offset(&key,
460 le_key_k_offset
461 (get_inode_item_key_version(inode),
462 &(ih->ih_key)) +
463 op_bytes_number(ih,
464 inode->i_sb->
465 s_blocksize));
466 /* Search ofor position of new key in the tree. */
467 res =
468 search_for_position_by_key(inode->i_sb, &key,
469 &path);
470 if (res == IO_ERROR) {
471 res = -EIO;
472 goto error_exit_free_blocks;
473 }
474 bh = get_last_bh(&path);
475 ih = get_ih(&path);
476 item = get_item(&path);
477 itempos = path.pos_in_item;
478 continue; // loop to check all kinds of conditions and so on.
361 } 479 }
362 /* Now we want to check if transaction is too full, and if it is 480 /* Ok, we have correct position in item now, so let's see if it is
363 we restart it. This will also free the path. */ 481 representing file hole (blocknumber is zero) and fill it if needed */
364 if (journal_transaction_should_end(th, th->t_blocks_allocated)) { 482 if (!item[itempos]) {
365 res = restart_transaction(th, inode, &path); 483 /* Ok, a hole. Now we need to check if we already prepared this
366 if (res) { 484 block to be journaled */
367 pathrelse (&path); 485 while (!modifying_this_item) { // loop until succeed
368 kfree(zeros); 486 /* Well, this item is not journaled yet, so we must prepare
369 goto error_exit; 487 it for journal first, before we can change it */
370 } 488 struct item_head tmp_ih; // We copy item head of found item,
371 } 489 // here to detect if fs changed under
372 490 // us while we were preparing for
373 /* Well, need to recalculate path and stuff */ 491 // journal.
374 set_cpu_key_k_offset( &key, cpu_key_k_offset(&key) + (to_paste << inode->i_blkbits)); 492 int fs_gen; // We store fs generation here to find if someone
375 res = search_for_position_by_key(inode->i_sb, &key, &path); 493 // changes fs under our feet
376 if ( res == IO_ERROR ) { 494
377 res = -EIO; 495 copy_item_head(&tmp_ih, ih); // Remember itemhead
378 kfree(zeros); 496 fs_gen = get_generation(inode->i_sb); // remember fs generation
379 goto error_exit_free_blocks; 497 reiserfs_prepare_for_journal(inode->i_sb, bh, 1); // Prepare a buffer within which indirect item is stored for changing.
498 if (fs_changed(fs_gen, inode->i_sb)
499 && item_moved(&tmp_ih, &path)) {
500 // Sigh, fs was changed under us, we need to look for new
501 // location of item we are working with
502
503 /* unmark prepaerd area as journaled and search for it's
504 new position */
505 reiserfs_restore_prepared_buffer(inode->
506 i_sb,
507 bh);
508 res =
509 search_for_position_by_key(inode->
510 i_sb,
511 &key,
512 &path);
513 if (res == IO_ERROR) {
514 res = -EIO;
515 goto error_exit_free_blocks;
516 }
517 bh = get_last_bh(&path);
518 ih = get_ih(&path);
519 item = get_item(&path);
520 itempos = path.pos_in_item;
521 goto retry;
522 }
523 modifying_this_item = 1;
524 }
525 item[itempos] = allocated_blocks[curr_block]; // Assign new block
526 curr_block++;
380 } 527 }
381 bh=get_last_bh(&path); 528 itempos++;
382 ih=get_ih(&path);
383 item = get_item(&path);
384 hole_size -= to_paste;
385 } while ( hole_size );
386 kfree(zeros);
387 } 529 }
388 } 530
389 531 if (modifying_this_item) { // We need to log last-accessed block, if it
390 // Go through existing indirect items first 532 // was modified, but not logged yet.
391 // replace all zeroes with blocknumbers from list 533 journal_mark_dirty(th, inode->i_sb, bh);
392 // Note that if no corresponding item was found, by previous search,
393 // it means there are no existing in-tree representation for file area
394 // we are going to overwrite, so there is nothing to scan through for holes.
395 for ( curr_block = 0, itempos = path.pos_in_item ; curr_block < blocks_to_allocate && res == POSITION_FOUND ; ) {
396retry:
397
398 if ( itempos >= ih_item_len(ih)/UNFM_P_SIZE ) {
399 /* We run out of data in this indirect item, let's look for another
400 one. */
401 /* First if we are already modifying current item, log it */
402 if ( modifying_this_item ) {
403 journal_mark_dirty (th, inode->i_sb, bh);
404 modifying_this_item = 0;
405 }
406 /* Then set the key to look for a new indirect item (offset of old
407 item is added to old item length */
408 set_cpu_key_k_offset( &key, le_key_k_offset( get_inode_item_key_version(inode), &(ih->ih_key)) + op_bytes_number(ih, inode->i_sb->s_blocksize));
409 /* Search ofor position of new key in the tree. */
410 res = search_for_position_by_key(inode->i_sb, &key, &path);
411 if ( res == IO_ERROR) {
412 res = -EIO;
413 goto error_exit_free_blocks;
414 }
415 bh=get_last_bh(&path);
416 ih=get_ih(&path);
417 item = get_item(&path);
418 itempos = path.pos_in_item;
419 continue; // loop to check all kinds of conditions and so on.
420 } 534 }
421 /* Ok, we have correct position in item now, so let's see if it is 535
422 representing file hole (blocknumber is zero) and fill it if needed */ 536 if (curr_block < blocks_to_allocate) {
423 if ( !item[itempos] ) { 537 // Oh, well need to append to indirect item, or to create indirect item
424 /* Ok, a hole. Now we need to check if we already prepared this 538 // if there weren't any
425 block to be journaled */ 539 if (is_indirect_le_ih(ih)) {
426 while ( !modifying_this_item ) { // loop until succeed 540 // Existing indirect item - append. First calculate key for append
427 /* Well, this item is not journaled yet, so we must prepare 541 // position. We do not need to recalculate path as it should
428 it for journal first, before we can change it */ 542 // already point to correct place.
429 struct item_head tmp_ih; // We copy item head of found item, 543 make_cpu_key(&key, inode,
430 // here to detect if fs changed under 544 le_key_k_offset(get_inode_item_key_version
431 // us while we were preparing for 545 (inode),
432 // journal. 546 &(ih->ih_key)) +
433 int fs_gen; // We store fs generation here to find if someone 547 op_bytes_number(ih,
434 // changes fs under our feet 548 inode->i_sb->s_blocksize),
435 549 TYPE_INDIRECT, 3);
436 copy_item_head (&tmp_ih, ih); // Remember itemhead 550 res =
437 fs_gen = get_generation (inode->i_sb); // remember fs generation 551 reiserfs_paste_into_item(th, &path, &key, inode,
438 reiserfs_prepare_for_journal(inode->i_sb, bh, 1); // Prepare a buffer within which indirect item is stored for changing. 552 (char *)(allocated_blocks +
439 if (fs_changed (fs_gen, inode->i_sb) && item_moved (&tmp_ih, &path)) { 553 curr_block),
440 // Sigh, fs was changed under us, we need to look for new 554 UNFM_P_SIZE *
441 // location of item we are working with 555 (blocks_to_allocate -
442 556 curr_block));
443 /* unmark prepaerd area as journaled and search for it's 557 if (res) {
444 new position */ 558 goto error_exit_free_blocks;
445 reiserfs_restore_prepared_buffer(inode->i_sb, bh); 559 }
446 res = search_for_position_by_key(inode->i_sb, &key, &path); 560 } else if (is_statdata_le_ih(ih)) {
447 if ( res == IO_ERROR) { 561 // Last found item was statdata. That means we need to create indirect item.
448 res = -EIO; 562 struct item_head ins_ih; /* itemhead for new item */
449 goto error_exit_free_blocks; 563
450 } 564 /* create a key for our new item */
451 bh=get_last_bh(&path); 565 make_cpu_key(&key, inode, 1, TYPE_INDIRECT, 3); // Position one,
452 ih=get_ih(&path); 566 // because that's
453 item = get_item(&path); 567 // where first
454 itempos = path.pos_in_item; 568 // indirect item
455 goto retry; 569 // begins
570 /* Create new item head for our new item */
571 make_le_item_head(&ins_ih, &key, key.version, 1,
572 TYPE_INDIRECT,
573 (blocks_to_allocate -
574 curr_block) * UNFM_P_SIZE,
575 0 /* free space */ );
576 /* Find where such item should live in the tree */
577 res = search_item(inode->i_sb, &key, &path);
578 if (res != ITEM_NOT_FOUND) {
579 /* Well, if we have found such item already, or some error
580 occured, we need to warn user and return error */
581 if (res != -ENOSPC) {
582 reiserfs_warning(inode->i_sb,
583 "green-9009: search_by_key (%K) "
584 "returned %d", &key,
585 res);
586 }
587 res = -EIO;
588 goto error_exit_free_blocks;
589 }
590 /* Insert item into the tree with the data as its body */
591 res =
592 reiserfs_insert_item(th, &path, &key, &ins_ih,
593 inode,
594 (char *)(allocated_blocks +
595 curr_block));
596 } else {
597 reiserfs_panic(inode->i_sb,
598 "green-9010: unexpected item type for key %K\n",
599 &key);
456 } 600 }
457 modifying_this_item = 1;
458 }
459 item[itempos] = allocated_blocks[curr_block]; // Assign new block
460 curr_block++;
461 } 601 }
462 itempos++; 602 // the caller is responsible for closing the transaction
463 } 603 // unless we return an error, they are also responsible for logging
464 604 // the inode.
465 if ( modifying_this_item ) { // We need to log last-accessed block, if it 605 //
466 // was modified, but not logged yet. 606 pathrelse(&path);
467 journal_mark_dirty (th, inode->i_sb, bh); 607 /*
468 } 608 * cleanup prellocation from previous writes
469 609 * if this is a partial block write
470 if ( curr_block < blocks_to_allocate ) { 610 */
471 // Oh, well need to append to indirect item, or to create indirect item 611 if (write_bytes & (inode->i_sb->s_blocksize - 1))
472 // if there weren't any 612 reiserfs_discard_prealloc(th, inode);
473 if ( is_indirect_le_ih(ih) ) { 613 reiserfs_write_unlock(inode->i_sb);
474 // Existing indirect item - append. First calculate key for append 614
475 // position. We do not need to recalculate path as it should 615 // go through all the pages/buffers and map the buffers to newly allocated
476 // already point to correct place. 616 // blocks (so that system knows where to write these pages later).
477 make_cpu_key( &key, inode, le_key_k_offset( get_inode_item_key_version(inode), &(ih->ih_key)) + op_bytes_number(ih, inode->i_sb->s_blocksize), TYPE_INDIRECT, 3); 617 curr_block = 0;
478 res = reiserfs_paste_into_item( th, &path, &key, inode, (char *)(allocated_blocks+curr_block), UNFM_P_SIZE*(blocks_to_allocate-curr_block)); 618 for (i = 0; i < num_pages; i++) {
479 if ( res ) { 619 struct page *page = prepared_pages[i]; //current page
480 goto error_exit_free_blocks; 620 struct buffer_head *head = page_buffers(page); // first buffer for a page
481 } 621 int block_start, block_end; // in-page offsets for buffers.
482 } else if (is_statdata_le_ih(ih) ) { 622
483 // Last found item was statdata. That means we need to create indirect item. 623 if (!page_buffers(page))
484 struct item_head ins_ih; /* itemhead for new item */ 624 reiserfs_panic(inode->i_sb,
485 625 "green-9005: No buffers for prepared page???");
486 /* create a key for our new item */ 626
487 make_cpu_key( &key, inode, 1, TYPE_INDIRECT, 3); // Position one, 627 /* For each buffer in page */
488 // because that's 628 for (bh = head, block_start = 0; bh != head || !block_start;
489 // where first 629 block_start = block_end, bh = bh->b_this_page) {
490 // indirect item 630 if (!bh)
491 // begins 631 reiserfs_panic(inode->i_sb,
492 /* Create new item head for our new item */ 632 "green-9006: Allocated but absent buffer for a page?");
493 make_le_item_head (&ins_ih, &key, key.version, 1, TYPE_INDIRECT, 633 block_end = block_start + inode->i_sb->s_blocksize;
494 (blocks_to_allocate-curr_block)*UNFM_P_SIZE, 634 if (i == 0 && block_end <= from)
495 0 /* free space */); 635 /* if this buffer is before requested data to map, skip it */
496 /* Find where such item should live in the tree */ 636 continue;
497 res = search_item (inode->i_sb, &key, &path); 637 if (i == num_pages - 1 && block_start >= to)
498 if ( res != ITEM_NOT_FOUND ) { 638 /* If this buffer is after requested data to map, abort
499 /* Well, if we have found such item already, or some error 639 processing of current page */
500 occured, we need to warn user and return error */ 640 break;
501 if ( res != -ENOSPC ) { 641
502 reiserfs_warning (inode->i_sb, 642 if (!buffer_mapped(bh)) { // Ok, unmapped buffer, need to map it
503 "green-9009: search_by_key (%K) " 643 map_bh(bh, inode->i_sb,
504 "returned %d", &key, res); 644 le32_to_cpu(allocated_blocks
645 [curr_block]));
646 curr_block++;
647 set_buffer_new(bh);
648 }
505 } 649 }
506 res = -EIO;
507 goto error_exit_free_blocks;
508 }
509 /* Insert item into the tree with the data as its body */
510 res = reiserfs_insert_item( th, &path, &key, &ins_ih, inode, (char *)(allocated_blocks+curr_block));
511 } else {
512 reiserfs_panic(inode->i_sb, "green-9010: unexpected item type for key %K\n",&key);
513 }
514 }
515
516 // the caller is responsible for closing the transaction
517 // unless we return an error, they are also responsible for logging
518 // the inode.
519 //
520 pathrelse(&path);
521 /*
522 * cleanup prellocation from previous writes
523 * if this is a partial block write
524 */
525 if (write_bytes & (inode->i_sb->s_blocksize -1))
526 reiserfs_discard_prealloc(th, inode);
527 reiserfs_write_unlock(inode->i_sb);
528
529 // go through all the pages/buffers and map the buffers to newly allocated
530 // blocks (so that system knows where to write these pages later).
531 curr_block = 0;
532 for ( i = 0; i < num_pages ; i++ ) {
533 struct page *page=prepared_pages[i]; //current page
534 struct buffer_head *head = page_buffers(page);// first buffer for a page
535 int block_start, block_end; // in-page offsets for buffers.
536
537 if (!page_buffers(page))
538 reiserfs_panic(inode->i_sb, "green-9005: No buffers for prepared page???");
539
540 /* For each buffer in page */
541 for(bh = head, block_start = 0; bh != head || !block_start;
542 block_start=block_end, bh = bh->b_this_page) {
543 if (!bh)
544 reiserfs_panic(inode->i_sb, "green-9006: Allocated but absent buffer for a page?");
545 block_end = block_start+inode->i_sb->s_blocksize;
546 if (i == 0 && block_end <= from )
547 /* if this buffer is before requested data to map, skip it */
548 continue;
549 if (i == num_pages - 1 && block_start >= to)
550 /* If this buffer is after requested data to map, abort
551 processing of current page */
552 break;
553
554 if ( !buffer_mapped(bh) ) { // Ok, unmapped buffer, need to map it
555 map_bh( bh, inode->i_sb, le32_to_cpu(allocated_blocks[curr_block]));
556 curr_block++;
557 set_buffer_new(bh);
558 }
559 } 650 }
560 }
561 651
562 RFALSE( curr_block > blocks_to_allocate, "green-9007: Used too many blocks? weird"); 652 RFALSE(curr_block > blocks_to_allocate,
653 "green-9007: Used too many blocks? weird");
563 654
564 kfree(allocated_blocks); 655 kfree(allocated_blocks);
565 return 0; 656 return 0;
566 657
567// Need to deal with transaction here. 658// Need to deal with transaction here.
568error_exit_free_blocks: 659 error_exit_free_blocks:
569 pathrelse(&path); 660 pathrelse(&path);
570 // free blocks 661 // free blocks
571 for( i = 0; i < blocks_to_allocate; i++ ) 662 for (i = 0; i < blocks_to_allocate; i++)
572 reiserfs_free_block(th, inode, le32_to_cpu(allocated_blocks[i]), 1); 663 reiserfs_free_block(th, inode, le32_to_cpu(allocated_blocks[i]),
573 664 1);
574error_exit: 665
575 if (th->t_trans_id) { 666 error_exit:
576 int err; 667 if (th->t_trans_id) {
577 // update any changes we made to blk count 668 int err;
578 reiserfs_update_sd(th, inode); 669 // update any changes we made to blk count
579 err = journal_end(th, inode->i_sb, JOURNAL_PER_BALANCE_CNT * 3 + 1 + 2 * REISERFS_QUOTA_TRANS_BLOCKS(inode->i_sb)); 670 reiserfs_update_sd(th, inode);
580 if (err) 671 err =
581 res = err; 672 journal_end(th, inode->i_sb,
582 } 673 JOURNAL_PER_BALANCE_CNT * 3 + 1 +
583 reiserfs_write_unlock(inode->i_sb); 674 2 * REISERFS_QUOTA_TRANS_BLOCKS(inode->i_sb));
584 kfree(allocated_blocks); 675 if (err)
585 676 res = err;
586 return res; 677 }
678 reiserfs_write_unlock(inode->i_sb);
679 kfree(allocated_blocks);
680
681 return res;
587} 682}
588 683
589/* Unlock pages prepared by reiserfs_prepare_file_region_for_write */ 684/* Unlock pages prepared by reiserfs_prepare_file_region_for_write */
590static void reiserfs_unprepare_pages(struct page **prepared_pages, /* list of locked pages */ 685static void reiserfs_unprepare_pages(struct page **prepared_pages, /* list of locked pages */
591 size_t num_pages /* amount of pages */) { 686 size_t num_pages /* amount of pages */ )
592 int i; // loop counter 687{
688 int i; // loop counter
593 689
594 for (i=0; i < num_pages ; i++) { 690 for (i = 0; i < num_pages; i++) {
595 struct page *page = prepared_pages[i]; 691 struct page *page = prepared_pages[i];
596 692
597 try_to_free_buffers(page); 693 try_to_free_buffers(page);
598 unlock_page(page); 694 unlock_page(page);
599 page_cache_release(page); 695 page_cache_release(page);
600 } 696 }
601} 697}
602 698
603/* This function will copy data from userspace to specified pages within 699/* This function will copy data from userspace to specified pages within
604 supplied byte range */ 700 supplied byte range */
605static int reiserfs_copy_from_user_to_file_region( 701static int reiserfs_copy_from_user_to_file_region(loff_t pos, /* In-file position */
606 loff_t pos, /* In-file position */ 702 int num_pages, /* Number of pages affected */
607 int num_pages, /* Number of pages affected */ 703 int write_bytes, /* Amount of bytes to write */
608 int write_bytes, /* Amount of bytes to write */ 704 struct page **prepared_pages, /* pointer to
609 struct page **prepared_pages, /* pointer to 705 array to
610 array to 706 prepared pages
611 prepared pages 707 */
612 */ 708 const char __user * buf /* Pointer to user-supplied
613 const char __user *buf /* Pointer to user-supplied 709 data */
614 data*/ 710 )
615 )
616{ 711{
617 long page_fault=0; // status of copy_from_user. 712 long page_fault = 0; // status of copy_from_user.
618 int i; // loop counter. 713 int i; // loop counter.
619 int offset; // offset in page 714 int offset; // offset in page
620 715
621 for ( i = 0, offset = (pos & (PAGE_CACHE_SIZE-1)); i < num_pages ; i++,offset=0) { 716 for (i = 0, offset = (pos & (PAGE_CACHE_SIZE - 1)); i < num_pages;
622 size_t count = min_t(size_t,PAGE_CACHE_SIZE-offset,write_bytes); // How much of bytes to write to this page 717 i++, offset = 0) {
623 struct page *page=prepared_pages[i]; // Current page we process. 718 size_t count = min_t(size_t, PAGE_CACHE_SIZE - offset, write_bytes); // How much of bytes to write to this page
624 719 struct page *page = prepared_pages[i]; // Current page we process.
625 fault_in_pages_readable( buf, count); 720
626 721 fault_in_pages_readable(buf, count);
627 /* Copy data from userspace to the current page */ 722
628 kmap(page); 723 /* Copy data from userspace to the current page */
629 page_fault = __copy_from_user(page_address(page)+offset, buf, count); // Copy the data. 724 kmap(page);
630 /* Flush processor's dcache for this page */ 725 page_fault = __copy_from_user(page_address(page) + offset, buf, count); // Copy the data.
631 flush_dcache_page(page); 726 /* Flush processor's dcache for this page */
632 kunmap(page); 727 flush_dcache_page(page);
633 buf+=count; 728 kunmap(page);
634 write_bytes-=count; 729 buf += count;
635 730 write_bytes -= count;
636 if (page_fault) 731
637 break; // Was there a fault? abort. 732 if (page_fault)
638 } 733 break; // Was there a fault? abort.
639 734 }
640 return page_fault?-EFAULT:0; 735
736 return page_fault ? -EFAULT : 0;
641} 737}
642 738
643/* taken fs/buffer.c:__block_commit_write */ 739/* taken fs/buffer.c:__block_commit_write */
644int reiserfs_commit_page(struct inode *inode, struct page *page, 740int reiserfs_commit_page(struct inode *inode, struct page *page,
645 unsigned from, unsigned to) 741 unsigned from, unsigned to)
646{ 742{
647 unsigned block_start, block_end; 743 unsigned block_start, block_end;
648 int partial = 0; 744 int partial = 0;
649 unsigned blocksize; 745 unsigned blocksize;
650 struct buffer_head *bh, *head; 746 struct buffer_head *bh, *head;
651 unsigned long i_size_index = inode->i_size >> PAGE_CACHE_SHIFT; 747 unsigned long i_size_index = inode->i_size >> PAGE_CACHE_SHIFT;
652 int new; 748 int new;
653 int logit = reiserfs_file_data_log(inode); 749 int logit = reiserfs_file_data_log(inode);
654 struct super_block *s = inode->i_sb; 750 struct super_block *s = inode->i_sb;
655 int bh_per_page = PAGE_CACHE_SIZE / s->s_blocksize; 751 int bh_per_page = PAGE_CACHE_SIZE / s->s_blocksize;
656 struct reiserfs_transaction_handle th; 752 struct reiserfs_transaction_handle th;
657 int ret = 0; 753 int ret = 0;
658 754
659 th.t_trans_id = 0; 755 th.t_trans_id = 0;
660 blocksize = 1 << inode->i_blkbits; 756 blocksize = 1 << inode->i_blkbits;
661 757
662 if (logit) { 758 if (logit) {
663 reiserfs_write_lock(s); 759 reiserfs_write_lock(s);
664 ret = journal_begin(&th, s, bh_per_page + 1); 760 ret = journal_begin(&th, s, bh_per_page + 1);
665 if (ret) 761 if (ret)
666 goto drop_write_lock; 762 goto drop_write_lock;
667 reiserfs_update_inode_transaction(inode); 763 reiserfs_update_inode_transaction(inode);
668 } 764 }
669 for(bh = head = page_buffers(page), block_start = 0; 765 for (bh = head = page_buffers(page), block_start = 0;
670 bh != head || !block_start; 766 bh != head || !block_start;
671 block_start=block_end, bh = bh->b_this_page) 767 block_start = block_end, bh = bh->b_this_page) {
672 { 768
673 769 new = buffer_new(bh);
674 new = buffer_new(bh); 770 clear_buffer_new(bh);
675 clear_buffer_new(bh); 771 block_end = block_start + blocksize;
676 block_end = block_start + blocksize; 772 if (block_end <= from || block_start >= to) {
677 if (block_end <= from || block_start >= to) { 773 if (!buffer_uptodate(bh))
678 if (!buffer_uptodate(bh)) 774 partial = 1;
679 partial = 1; 775 } else {
680 } else { 776 set_buffer_uptodate(bh);
681 set_buffer_uptodate(bh); 777 if (logit) {
682 if (logit) { 778 reiserfs_prepare_for_journal(s, bh, 1);
683 reiserfs_prepare_for_journal(s, bh, 1); 779 journal_mark_dirty(&th, s, bh);
684 journal_mark_dirty(&th, s, bh); 780 } else if (!buffer_dirty(bh)) {
685 } else if (!buffer_dirty(bh)) { 781 mark_buffer_dirty(bh);
686 mark_buffer_dirty(bh); 782 /* do data=ordered on any page past the end
687 /* do data=ordered on any page past the end 783 * of file and any buffer marked BH_New.
688 * of file and any buffer marked BH_New. 784 */
689 */ 785 if (reiserfs_data_ordered(inode->i_sb) &&
690 if (reiserfs_data_ordered(inode->i_sb) && 786 (new || page->index >= i_size_index)) {
691 (new || page->index >= i_size_index)) { 787 reiserfs_add_ordered_list(inode, bh);
692 reiserfs_add_ordered_list(inode, bh); 788 }
693 } 789 }
694 } 790 }
695 } 791 }
696 } 792 if (logit) {
697 if (logit) { 793 ret = journal_end(&th, s, bh_per_page + 1);
698 ret = journal_end(&th, s, bh_per_page + 1); 794 drop_write_lock:
699drop_write_lock: 795 reiserfs_write_unlock(s);
700 reiserfs_write_unlock(s); 796 }
701 } 797 /*
702 /* 798 * If this is a partial write which happened to make all buffers
703 * If this is a partial write which happened to make all buffers 799 * uptodate then we can optimize away a bogus readpage() for
704 * uptodate then we can optimize away a bogus readpage() for 800 * the next read(). Here we 'discover' whether the page went
705 * the next read(). Here we 'discover' whether the page went 801 * uptodate as a result of this (potentially partial) write.
706 * uptodate as a result of this (potentially partial) write. 802 */
707 */ 803 if (!partial)
708 if (!partial) 804 SetPageUptodate(page);
709 SetPageUptodate(page); 805 return ret;
710 return ret;
711} 806}
712 807
713
714/* Submit pages for write. This was separated from actual file copying 808/* Submit pages for write. This was separated from actual file copying
715 because we might want to allocate block numbers in-between. 809 because we might want to allocate block numbers in-between.
716 This function assumes that caller will adjust file size to correct value. */ 810 This function assumes that caller will adjust file size to correct value. */
717static int reiserfs_submit_file_region_for_write( 811static int reiserfs_submit_file_region_for_write(struct reiserfs_transaction_handle *th, struct inode *inode, loff_t pos, /* Writing position offset */
718 struct reiserfs_transaction_handle *th, 812 size_t num_pages, /* Number of pages to write */
719 struct inode *inode, 813 size_t write_bytes, /* number of bytes to write */
720 loff_t pos, /* Writing position offset */ 814 struct page **prepared_pages /* list of pages */
721 size_t num_pages, /* Number of pages to write */ 815 )
722 size_t write_bytes, /* number of bytes to write */
723 struct page **prepared_pages /* list of pages */
724 )
725{ 816{
726 int status; // return status of block_commit_write. 817 int status; // return status of block_commit_write.
727 int retval = 0; // Return value we are going to return. 818 int retval = 0; // Return value we are going to return.
728 int i; // loop counter 819 int i; // loop counter
729 int offset; // Writing offset in page. 820 int offset; // Writing offset in page.
730 int orig_write_bytes = write_bytes; 821 int orig_write_bytes = write_bytes;
731 int sd_update = 0; 822 int sd_update = 0;
732 823
733 for ( i = 0, offset = (pos & (PAGE_CACHE_SIZE-1)); i < num_pages ; i++,offset=0) { 824 for (i = 0, offset = (pos & (PAGE_CACHE_SIZE - 1)); i < num_pages;
734 int count = min_t(int,PAGE_CACHE_SIZE-offset,write_bytes); // How much of bytes to write to this page 825 i++, offset = 0) {
735 struct page *page=prepared_pages[i]; // Current page we process. 826 int count = min_t(int, PAGE_CACHE_SIZE - offset, write_bytes); // How much of bytes to write to this page
736 827 struct page *page = prepared_pages[i]; // Current page we process.
737 status = reiserfs_commit_page(inode, page, offset, offset+count); 828
738 if ( status ) 829 status =
739 retval = status; // To not overcomplicate matters We are going to 830 reiserfs_commit_page(inode, page, offset, offset + count);
740 // submit all the pages even if there was error. 831 if (status)
741 // we only remember error status to report it on 832 retval = status; // To not overcomplicate matters We are going to
742 // exit. 833 // submit all the pages even if there was error.
743 write_bytes-=count; 834 // we only remember error status to report it on
744 } 835 // exit.
745 /* now that we've gotten all the ordered buffers marked dirty, 836 write_bytes -= count;
746 * we can safely update i_size and close any running transaction 837 }
747 */ 838 /* now that we've gotten all the ordered buffers marked dirty,
748 if ( pos + orig_write_bytes > inode->i_size) { 839 * we can safely update i_size and close any running transaction
749 inode->i_size = pos + orig_write_bytes; // Set new size 840 */
750 /* If the file have grown so much that tail packing is no 841 if (pos + orig_write_bytes > inode->i_size) {
751 * longer possible, reset "need to pack" flag */ 842 inode->i_size = pos + orig_write_bytes; // Set new size
752 if ( (have_large_tails (inode->i_sb) && 843 /* If the file have grown so much that tail packing is no
753 inode->i_size > i_block_size (inode)*4) || 844 * longer possible, reset "need to pack" flag */
754 (have_small_tails (inode->i_sb) && 845 if ((have_large_tails(inode->i_sb) &&
755 inode->i_size > i_block_size(inode)) ) 846 inode->i_size > i_block_size(inode) * 4) ||
756 REISERFS_I(inode)->i_flags &= ~i_pack_on_close_mask ; 847 (have_small_tails(inode->i_sb) &&
757 else if ( (have_large_tails (inode->i_sb) && 848 inode->i_size > i_block_size(inode)))
758 inode->i_size < i_block_size (inode)*4) || 849 REISERFS_I(inode)->i_flags &= ~i_pack_on_close_mask;
759 (have_small_tails (inode->i_sb) && 850 else if ((have_large_tails(inode->i_sb) &&
760 inode->i_size < i_block_size(inode)) ) 851 inode->i_size < i_block_size(inode) * 4) ||
761 REISERFS_I(inode)->i_flags |= i_pack_on_close_mask ; 852 (have_small_tails(inode->i_sb) &&
762 853 inode->i_size < i_block_size(inode)))
854 REISERFS_I(inode)->i_flags |= i_pack_on_close_mask;
855
856 if (th->t_trans_id) {
857 reiserfs_write_lock(inode->i_sb);
858 reiserfs_update_sd(th, inode); // And update on-disk metadata
859 reiserfs_write_unlock(inode->i_sb);
860 } else
861 inode->i_sb->s_op->dirty_inode(inode);
862
863 sd_update = 1;
864 }
763 if (th->t_trans_id) { 865 if (th->t_trans_id) {
764 reiserfs_write_lock(inode->i_sb); 866 reiserfs_write_lock(inode->i_sb);
765 reiserfs_update_sd(th, inode); // And update on-disk metadata 867 if (!sd_update)
766 reiserfs_write_unlock(inode->i_sb); 868 reiserfs_update_sd(th, inode);
767 } else 869 status = journal_end(th, th->t_super, th->t_blocks_allocated);
768 inode->i_sb->s_op->dirty_inode(inode); 870 if (status)
871 retval = status;
872 reiserfs_write_unlock(inode->i_sb);
873 }
874 th->t_trans_id = 0;
769 875
770 sd_update = 1; 876 /*
771 } 877 * we have to unlock the pages after updating i_size, otherwise
772 if (th->t_trans_id) { 878 * we race with writepage
773 reiserfs_write_lock(inode->i_sb); 879 */
774 if (!sd_update) 880 for (i = 0; i < num_pages; i++) {
775 reiserfs_update_sd(th, inode); 881 struct page *page = prepared_pages[i];
776 status = journal_end(th, th->t_super, th->t_blocks_allocated); 882 unlock_page(page);
777 if (status) 883 mark_page_accessed(page);
778 retval = status; 884 page_cache_release(page);
779 reiserfs_write_unlock(inode->i_sb); 885 }
780 } 886 return retval;
781 th->t_trans_id = 0;
782
783 /*
784 * we have to unlock the pages after updating i_size, otherwise
785 * we race with writepage
786 */
787 for ( i = 0; i < num_pages ; i++) {
788 struct page *page=prepared_pages[i];
789 unlock_page(page);
790 mark_page_accessed(page);
791 page_cache_release(page);
792 }
793 return retval;
794} 887}
795 888
796/* Look if passed writing region is going to touch file's tail 889/* Look if passed writing region is going to touch file's tail
797 (if it is present). And if it is, convert the tail to unformatted node */ 890 (if it is present). And if it is, convert the tail to unformatted node */
798static int reiserfs_check_for_tail_and_convert( struct inode *inode, /* inode to deal with */ 891static int reiserfs_check_for_tail_and_convert(struct inode *inode, /* inode to deal with */
799 loff_t pos, /* Writing position */ 892 loff_t pos, /* Writing position */
800 int write_bytes /* amount of bytes to write */ 893 int write_bytes /* amount of bytes to write */
801 ) 894 )
802{ 895{
803 INITIALIZE_PATH(path); // needed for search_for_position 896 INITIALIZE_PATH(path); // needed for search_for_position
804 struct cpu_key key; // Key that would represent last touched writing byte. 897 struct cpu_key key; // Key that would represent last touched writing byte.
805 struct item_head *ih; // item header of found block; 898 struct item_head *ih; // item header of found block;
806 int res; // Return value of various functions we call. 899 int res; // Return value of various functions we call.
807 int cont_expand_offset; // We will put offset for generic_cont_expand here 900 int cont_expand_offset; // We will put offset for generic_cont_expand here
808 // This can be int just because tails are created 901 // This can be int just because tails are created
809 // only for small files. 902 // only for small files.
810 903
811/* this embodies a dependency on a particular tail policy */ 904/* this embodies a dependency on a particular tail policy */
812 if ( inode->i_size >= inode->i_sb->s_blocksize*4 ) { 905 if (inode->i_size >= inode->i_sb->s_blocksize * 4) {
813 /* such a big files do not have tails, so we won't bother ourselves 906 /* such a big files do not have tails, so we won't bother ourselves
814 to look for tails, simply return */ 907 to look for tails, simply return */
815 return 0; 908 return 0;
816 } 909 }
817
818 reiserfs_write_lock(inode->i_sb);
819 /* find the item containing the last byte to be written, or if
820 * writing past the end of the file then the last item of the
821 * file (and then we check its type). */
822 make_cpu_key (&key, inode, pos+write_bytes+1, TYPE_ANY, 3/*key length*/);
823 res = search_for_position_by_key(inode->i_sb, &key, &path);
824 if ( res == IO_ERROR ) {
825 reiserfs_write_unlock(inode->i_sb);
826 return -EIO;
827 }
828 ih = get_ih(&path);
829 res = 0;
830 if ( is_direct_le_ih(ih) ) {
831 /* Ok, closest item is file tail (tails are stored in "direct"
832 * items), so we need to unpack it. */
833 /* To not overcomplicate matters, we just call generic_cont_expand
834 which will in turn call other stuff and finally will boil down to
835 reiserfs_get_block() that would do necessary conversion. */
836 cont_expand_offset = le_key_k_offset(get_inode_item_key_version(inode), &(ih->ih_key));
837 pathrelse(&path);
838 res = generic_cont_expand( inode, cont_expand_offset);
839 } else
840 pathrelse(&path);
841 910
842 reiserfs_write_unlock(inode->i_sb); 911 reiserfs_write_lock(inode->i_sb);
843 return res; 912 /* find the item containing the last byte to be written, or if
913 * writing past the end of the file then the last item of the
914 * file (and then we check its type). */
915 make_cpu_key(&key, inode, pos + write_bytes + 1, TYPE_ANY,
916 3 /*key length */ );
917 res = search_for_position_by_key(inode->i_sb, &key, &path);
918 if (res == IO_ERROR) {
919 reiserfs_write_unlock(inode->i_sb);
920 return -EIO;
921 }
922 ih = get_ih(&path);
923 res = 0;
924 if (is_direct_le_ih(ih)) {
925 /* Ok, closest item is file tail (tails are stored in "direct"
926 * items), so we need to unpack it. */
927 /* To not overcomplicate matters, we just call generic_cont_expand
928 which will in turn call other stuff and finally will boil down to
929 reiserfs_get_block() that would do necessary conversion. */
930 cont_expand_offset =
931 le_key_k_offset(get_inode_item_key_version(inode),
932 &(ih->ih_key));
933 pathrelse(&path);
934 res = generic_cont_expand(inode, cont_expand_offset);
935 } else
936 pathrelse(&path);
937
938 reiserfs_write_unlock(inode->i_sb);
939 return res;
844} 940}
845 941
846/* This function locks pages starting from @pos for @inode. 942/* This function locks pages starting from @pos for @inode.
@@ -851,275 +947,296 @@ static int reiserfs_check_for_tail_and_convert( struct inode *inode, /* inode to
851 append), it is zeroed, then. 947 append), it is zeroed, then.
852 Returns number of unallocated blocks that should be allocated to cover 948 Returns number of unallocated blocks that should be allocated to cover
853 new file data.*/ 949 new file data.*/
854static int reiserfs_prepare_file_region_for_write( 950static int reiserfs_prepare_file_region_for_write(struct inode *inode
855 struct inode *inode /* Inode of the file */, 951 /* Inode of the file */ ,
856 loff_t pos, /* position in the file */ 952 loff_t pos, /* position in the file */
857 size_t num_pages, /* number of pages to 953 size_t num_pages, /* number of pages to
858 prepare */ 954 prepare */
859 size_t write_bytes, /* Amount of bytes to be 955 size_t write_bytes, /* Amount of bytes to be
860 overwritten from 956 overwritten from
861 @pos */ 957 @pos */
862 struct page **prepared_pages /* pointer to array 958 struct page **prepared_pages /* pointer to array
863 where to store 959 where to store
864 prepared pages */ 960 prepared pages */
865 ) 961 )
866{ 962{
867 int res=0; // Return values of different functions we call. 963 int res = 0; // Return values of different functions we call.
868 unsigned long index = pos >> PAGE_CACHE_SHIFT; // Offset in file in pages. 964 unsigned long index = pos >> PAGE_CACHE_SHIFT; // Offset in file in pages.
869 int from = (pos & (PAGE_CACHE_SIZE - 1)); // Writing offset in first page 965 int from = (pos & (PAGE_CACHE_SIZE - 1)); // Writing offset in first page
870 int to = ((pos + write_bytes - 1) & (PAGE_CACHE_SIZE - 1)) + 1; 966 int to = ((pos + write_bytes - 1) & (PAGE_CACHE_SIZE - 1)) + 1;
871 /* offset of last modified byte in last 967 /* offset of last modified byte in last
872 page */ 968 page */
873 struct address_space *mapping = inode->i_mapping; // Pages are mapped here. 969 struct address_space *mapping = inode->i_mapping; // Pages are mapped here.
874 int i; // Simple counter 970 int i; // Simple counter
875 int blocks = 0; /* Return value (blocks that should be allocated) */ 971 int blocks = 0; /* Return value (blocks that should be allocated) */
876 struct buffer_head *bh, *head; // Current bufferhead and first bufferhead 972 struct buffer_head *bh, *head; // Current bufferhead and first bufferhead
877 // of a page. 973 // of a page.
878 unsigned block_start, block_end; // Starting and ending offsets of current 974 unsigned block_start, block_end; // Starting and ending offsets of current
879 // buffer in the page. 975 // buffer in the page.
880 struct buffer_head *wait[2], **wait_bh=wait; // Buffers for page, if 976 struct buffer_head *wait[2], **wait_bh = wait; // Buffers for page, if
881 // Page appeared to be not up 977 // Page appeared to be not up
882 // to date. Note how we have 978 // to date. Note how we have
883 // at most 2 buffers, this is 979 // at most 2 buffers, this is
884 // because we at most may 980 // because we at most may
885 // partially overwrite two 981 // partially overwrite two
886 // buffers for one page. One at // the beginning of write area 982 // buffers for one page. One at // the beginning of write area
887 // and one at the end. 983 // and one at the end.
888 // Everything inthe middle gets // overwritten totally. 984 // Everything inthe middle gets // overwritten totally.
889 985
890 struct cpu_key key; // cpu key of item that we are going to deal with 986 struct cpu_key key; // cpu key of item that we are going to deal with
891 struct item_head *ih = NULL; // pointer to item head that we are going to deal with 987 struct item_head *ih = NULL; // pointer to item head that we are going to deal with
892 struct buffer_head *itembuf=NULL; // Buffer head that contains items that we are going to deal with 988 struct buffer_head *itembuf = NULL; // Buffer head that contains items that we are going to deal with
893 INITIALIZE_PATH(path); // path to item, that we are going to deal with. 989 INITIALIZE_PATH(path); // path to item, that we are going to deal with.
894 __le32 * item=NULL; // pointer to item we are going to deal with 990 __le32 *item = NULL; // pointer to item we are going to deal with
895 int item_pos=-1; /* Position in indirect item */ 991 int item_pos = -1; /* Position in indirect item */
896 992
897 993 if (num_pages < 1) {
898 if ( num_pages < 1 ) { 994 reiserfs_warning(inode->i_sb,
899 reiserfs_warning (inode->i_sb, 995 "green-9001: reiserfs_prepare_file_region_for_write "
900 "green-9001: reiserfs_prepare_file_region_for_write " 996 "called with zero number of pages to process");
901 "called with zero number of pages to process"); 997 return -EFAULT;
902 return -EFAULT;
903 }
904
905 /* We have 2 loops for pages. In first loop we grab and lock the pages, so
906 that nobody would touch these until we release the pages. Then
907 we'd start to deal with mapping buffers to blocks. */
908 for ( i = 0; i < num_pages; i++) {
909 prepared_pages[i] = grab_cache_page(mapping, index + i); // locks the page
910 if ( !prepared_pages[i]) {
911 res = -ENOMEM;
912 goto failed_page_grabbing;
913 }
914 if (!page_has_buffers(prepared_pages[i]))
915 create_empty_buffers(prepared_pages[i], inode->i_sb->s_blocksize, 0);
916 }
917
918 /* Let's count amount of blocks for a case where all the blocks
919 overwritten are new (we will substract already allocated blocks later)*/
920 if ( num_pages > 2 )
921 /* These are full-overwritten pages so we count all the blocks in
922 these pages are counted as needed to be allocated */
923 blocks = (num_pages - 2) << (PAGE_CACHE_SHIFT - inode->i_blkbits);
924
925 /* count blocks needed for first page (possibly partially written) */
926 blocks += ((PAGE_CACHE_SIZE - from) >> inode->i_blkbits) +
927 !!(from & (inode->i_sb->s_blocksize-1)); /* roundup */
928
929 /* Now we account for last page. If last page == first page (we
930 overwrite only one page), we substract all the blocks past the
931 last writing position in a page out of already calculated number
932 of blocks */
933 blocks += ((num_pages > 1) << (PAGE_CACHE_SHIFT-inode->i_blkbits)) -
934 ((PAGE_CACHE_SIZE - to) >> inode->i_blkbits);
935 /* Note how we do not roundup here since partial blocks still
936 should be allocated */
937
938 /* Now if all the write area lies past the file end, no point in
939 maping blocks, since there is none, so we just zero out remaining
940 parts of first and last pages in write area (if needed) */
941 if ( (pos & ~((loff_t)PAGE_CACHE_SIZE - 1)) > inode->i_size ) {
942 if ( from != 0 ) {/* First page needs to be partially zeroed */
943 char *kaddr = kmap_atomic(prepared_pages[0], KM_USER0);
944 memset(kaddr, 0, from);
945 kunmap_atomic( kaddr, KM_USER0);
946 }
947 if ( to != PAGE_CACHE_SIZE ) { /* Last page needs to be partially zeroed */
948 char *kaddr = kmap_atomic(prepared_pages[num_pages-1], KM_USER0);
949 memset(kaddr+to, 0, PAGE_CACHE_SIZE - to);
950 kunmap_atomic( kaddr, KM_USER0);
951 } 998 }
952 999
953 /* Since all blocks are new - use already calculated value */ 1000 /* We have 2 loops for pages. In first loop we grab and lock the pages, so
954 return blocks; 1001 that nobody would touch these until we release the pages. Then
955 } 1002 we'd start to deal with mapping buffers to blocks. */
956 1003 for (i = 0; i < num_pages; i++) {
957 /* Well, since we write somewhere into the middle of a file, there is 1004 prepared_pages[i] = grab_cache_page(mapping, index + i); // locks the page
958 possibility we are writing over some already allocated blocks, so 1005 if (!prepared_pages[i]) {
959 let's map these blocks and substract number of such blocks out of blocks 1006 res = -ENOMEM;
960 we need to allocate (calculated above) */ 1007 goto failed_page_grabbing;
961 /* Mask write position to start on blocksize, we do it out of the
962 loop for performance reasons */
963 pos &= ~((loff_t) inode->i_sb->s_blocksize - 1);
964 /* Set cpu key to the starting position in a file (on left block boundary)*/
965 make_cpu_key (&key, inode, 1 + ((pos) & ~((loff_t) inode->i_sb->s_blocksize - 1)), TYPE_ANY, 3/*key length*/);
966
967 reiserfs_write_lock(inode->i_sb); // We need that for at least search_by_key()
968 for ( i = 0; i < num_pages ; i++ ) {
969
970 head = page_buffers(prepared_pages[i]);
971 /* For each buffer in the page */
972 for(bh = head, block_start = 0; bh != head || !block_start;
973 block_start=block_end, bh = bh->b_this_page) {
974 if (!bh)
975 reiserfs_panic(inode->i_sb, "green-9002: Allocated but absent buffer for a page?");
976 /* Find where this buffer ends */
977 block_end = block_start+inode->i_sb->s_blocksize;
978 if (i == 0 && block_end <= from )
979 /* if this buffer is before requested data to map, skip it*/
980 continue;
981
982 if (i == num_pages - 1 && block_start >= to) {
983 /* If this buffer is after requested data to map, abort
984 processing of current page */
985 break;
986 } 1008 }
1009 if (!page_has_buffers(prepared_pages[i]))
1010 create_empty_buffers(prepared_pages[i],
1011 inode->i_sb->s_blocksize, 0);
1012 }
987 1013
988 if ( buffer_mapped(bh) && bh->b_blocknr !=0 ) { 1014 /* Let's count amount of blocks for a case where all the blocks
989 /* This is optimisation for a case where buffer is mapped 1015 overwritten are new (we will substract already allocated blocks later) */
990 and have blocknumber assigned. In case significant amount 1016 if (num_pages > 2)
991 of such buffers are present, we may avoid some amount 1017 /* These are full-overwritten pages so we count all the blocks in
992 of search_by_key calls. 1018 these pages are counted as needed to be allocated */
993 Probably it would be possible to move parts of this code 1019 blocks =
994 out of BKL, but I afraid that would overcomplicate code 1020 (num_pages - 2) << (PAGE_CACHE_SHIFT - inode->i_blkbits);
995 without any noticeable benefit. 1021
996 */ 1022 /* count blocks needed for first page (possibly partially written) */
997 item_pos++; 1023 blocks += ((PAGE_CACHE_SIZE - from) >> inode->i_blkbits) + !!(from & (inode->i_sb->s_blocksize - 1)); /* roundup */
998 /* Update the key */ 1024
999 set_cpu_key_k_offset( &key, cpu_key_k_offset(&key) + inode->i_sb->s_blocksize); 1025 /* Now we account for last page. If last page == first page (we
1000 blocks--; // Decrease the amount of blocks that need to be 1026 overwrite only one page), we substract all the blocks past the
1001 // allocated 1027 last writing position in a page out of already calculated number
1002 continue; // Go to the next buffer 1028 of blocks */
1029 blocks += ((num_pages > 1) << (PAGE_CACHE_SHIFT - inode->i_blkbits)) -
1030 ((PAGE_CACHE_SIZE - to) >> inode->i_blkbits);
1031 /* Note how we do not roundup here since partial blocks still
1032 should be allocated */
1033
1034 /* Now if all the write area lies past the file end, no point in
1035 maping blocks, since there is none, so we just zero out remaining
1036 parts of first and last pages in write area (if needed) */
1037 if ((pos & ~((loff_t) PAGE_CACHE_SIZE - 1)) > inode->i_size) {
1038 if (from != 0) { /* First page needs to be partially zeroed */
1039 char *kaddr = kmap_atomic(prepared_pages[0], KM_USER0);
1040 memset(kaddr, 0, from);
1041 kunmap_atomic(kaddr, KM_USER0);
1042 }
1043 if (to != PAGE_CACHE_SIZE) { /* Last page needs to be partially zeroed */
1044 char *kaddr =
1045 kmap_atomic(prepared_pages[num_pages - 1],
1046 KM_USER0);
1047 memset(kaddr + to, 0, PAGE_CACHE_SIZE - to);
1048 kunmap_atomic(kaddr, KM_USER0);
1003 } 1049 }
1004 1050
1005 if ( !itembuf || /* if first iteration */ 1051 /* Since all blocks are new - use already calculated value */
1006 item_pos >= ih_item_len(ih)/UNFM_P_SIZE) 1052 return blocks;
1007 { /* or if we progressed past the 1053 }
1008 current unformatted_item */ 1054
1009 /* Try to find next item */ 1055 /* Well, since we write somewhere into the middle of a file, there is
1010 res = search_for_position_by_key(inode->i_sb, &key, &path); 1056 possibility we are writing over some already allocated blocks, so
1011 /* Abort if no more items */ 1057 let's map these blocks and substract number of such blocks out of blocks
1012 if ( res != POSITION_FOUND ) { 1058 we need to allocate (calculated above) */
1013 /* make sure later loops don't use this item */ 1059 /* Mask write position to start on blocksize, we do it out of the
1014 itembuf = NULL; 1060 loop for performance reasons */
1015 item = NULL; 1061 pos &= ~((loff_t) inode->i_sb->s_blocksize - 1);
1016 break; 1062 /* Set cpu key to the starting position in a file (on left block boundary) */
1063 make_cpu_key(&key, inode,
1064 1 + ((pos) & ~((loff_t) inode->i_sb->s_blocksize - 1)),
1065 TYPE_ANY, 3 /*key length */ );
1066
1067 reiserfs_write_lock(inode->i_sb); // We need that for at least search_by_key()
1068 for (i = 0; i < num_pages; i++) {
1069
1070 head = page_buffers(prepared_pages[i]);
1071 /* For each buffer in the page */
1072 for (bh = head, block_start = 0; bh != head || !block_start;
1073 block_start = block_end, bh = bh->b_this_page) {
1074 if (!bh)
1075 reiserfs_panic(inode->i_sb,
1076 "green-9002: Allocated but absent buffer for a page?");
1077 /* Find where this buffer ends */
1078 block_end = block_start + inode->i_sb->s_blocksize;
1079 if (i == 0 && block_end <= from)
1080 /* if this buffer is before requested data to map, skip it */
1081 continue;
1082
1083 if (i == num_pages - 1 && block_start >= to) {
1084 /* If this buffer is after requested data to map, abort
1085 processing of current page */
1086 break;
1017 } 1087 }
1018 1088
1019 /* Update information about current indirect item */ 1089 if (buffer_mapped(bh) && bh->b_blocknr != 0) {
1020 itembuf = get_last_bh( &path ); 1090 /* This is optimisation for a case where buffer is mapped
1021 ih = get_ih( &path ); 1091 and have blocknumber assigned. In case significant amount
1022 item = get_item( &path ); 1092 of such buffers are present, we may avoid some amount
1023 item_pos = path.pos_in_item; 1093 of search_by_key calls.
1094 Probably it would be possible to move parts of this code
1095 out of BKL, but I afraid that would overcomplicate code
1096 without any noticeable benefit.
1097 */
1098 item_pos++;
1099 /* Update the key */
1100 set_cpu_key_k_offset(&key,
1101 cpu_key_k_offset(&key) +
1102 inode->i_sb->s_blocksize);
1103 blocks--; // Decrease the amount of blocks that need to be
1104 // allocated
1105 continue; // Go to the next buffer
1106 }
1024 1107
1025 RFALSE( !is_indirect_le_ih (ih), "green-9003: indirect item expected"); 1108 if (!itembuf || /* if first iteration */
1026 } 1109 item_pos >= ih_item_len(ih) / UNFM_P_SIZE) { /* or if we progressed past the
1110 current unformatted_item */
1111 /* Try to find next item */
1112 res =
1113 search_for_position_by_key(inode->i_sb,
1114 &key, &path);
1115 /* Abort if no more items */
1116 if (res != POSITION_FOUND) {
1117 /* make sure later loops don't use this item */
1118 itembuf = NULL;
1119 item = NULL;
1120 break;
1121 }
1122
1123 /* Update information about current indirect item */
1124 itembuf = get_last_bh(&path);
1125 ih = get_ih(&path);
1126 item = get_item(&path);
1127 item_pos = path.pos_in_item;
1128
1129 RFALSE(!is_indirect_le_ih(ih),
1130 "green-9003: indirect item expected");
1131 }
1027 1132
1028 /* See if there is some block associated with the file 1133 /* See if there is some block associated with the file
1029 at that position, map the buffer to this block */ 1134 at that position, map the buffer to this block */
1030 if ( get_block_num(item,item_pos) ) { 1135 if (get_block_num(item, item_pos)) {
1031 map_bh(bh, inode->i_sb, get_block_num(item,item_pos)); 1136 map_bh(bh, inode->i_sb,
1032 blocks--; // Decrease the amount of blocks that need to be 1137 get_block_num(item, item_pos));
1033 // allocated 1138 blocks--; // Decrease the amount of blocks that need to be
1139 // allocated
1140 }
1141 item_pos++;
1142 /* Update the key */
1143 set_cpu_key_k_offset(&key,
1144 cpu_key_k_offset(&key) +
1145 inode->i_sb->s_blocksize);
1034 } 1146 }
1035 item_pos++;
1036 /* Update the key */
1037 set_cpu_key_k_offset( &key, cpu_key_k_offset(&key) + inode->i_sb->s_blocksize);
1038 } 1147 }
1039 } 1148 pathrelse(&path); // Free the path
1040 pathrelse(&path); // Free the path 1149 reiserfs_write_unlock(inode->i_sb);
1041 reiserfs_write_unlock(inode->i_sb);
1042 1150
1043 /* Now zero out unmappend buffers for the first and last pages of 1151 /* Now zero out unmappend buffers for the first and last pages of
1044 write area or issue read requests if page is mapped. */ 1152 write area or issue read requests if page is mapped. */
1045 /* First page, see if it is not uptodate */ 1153 /* First page, see if it is not uptodate */
1046 if ( !PageUptodate(prepared_pages[0]) ) { 1154 if (!PageUptodate(prepared_pages[0])) {
1047 head = page_buffers(prepared_pages[0]); 1155 head = page_buffers(prepared_pages[0]);
1048 1156
1049 /* For each buffer in page */ 1157 /* For each buffer in page */
1050 for(bh = head, block_start = 0; bh != head || !block_start; 1158 for (bh = head, block_start = 0; bh != head || !block_start;
1051 block_start=block_end, bh = bh->b_this_page) { 1159 block_start = block_end, bh = bh->b_this_page) {
1052 1160
1053 if (!bh) 1161 if (!bh)
1054 reiserfs_panic(inode->i_sb, "green-9002: Allocated but absent buffer for a page?"); 1162 reiserfs_panic(inode->i_sb,
1055 /* Find where this buffer ends */ 1163 "green-9002: Allocated but absent buffer for a page?");
1056 block_end = block_start+inode->i_sb->s_blocksize; 1164 /* Find where this buffer ends */
1057 if ( block_end <= from ) 1165 block_end = block_start + inode->i_sb->s_blocksize;
1058 /* if this buffer is before requested data to map, skip it*/ 1166 if (block_end <= from)
1059 continue; 1167 /* if this buffer is before requested data to map, skip it */
1060 if ( block_start < from ) { /* Aha, our partial buffer */ 1168 continue;
1061 if ( buffer_mapped(bh) ) { /* If it is mapped, we need to 1169 if (block_start < from) { /* Aha, our partial buffer */
1062 issue READ request for it to 1170 if (buffer_mapped(bh)) { /* If it is mapped, we need to
1063 not loose data */ 1171 issue READ request for it to
1064 ll_rw_block(READ, 1, &bh); 1172 not loose data */
1065 *wait_bh++=bh; 1173 ll_rw_block(READ, 1, &bh);
1066 } else { /* Not mapped, zero it */ 1174 *wait_bh++ = bh;
1067 char *kaddr = kmap_atomic(prepared_pages[0], KM_USER0); 1175 } else { /* Not mapped, zero it */
1068 memset(kaddr+block_start, 0, from-block_start); 1176 char *kaddr =
1069 kunmap_atomic( kaddr, KM_USER0); 1177 kmap_atomic(prepared_pages[0],
1070 set_buffer_uptodate(bh); 1178 KM_USER0);
1071 } 1179 memset(kaddr + block_start, 0,
1180 from - block_start);
1181 kunmap_atomic(kaddr, KM_USER0);
1182 set_buffer_uptodate(bh);
1183 }
1184 }
1072 } 1185 }
1073 }
1074 } 1186 }
1075 1187
1076 /* Last page, see if it is not uptodate, or if the last page is past the end of the file. */ 1188 /* Last page, see if it is not uptodate, or if the last page is past the end of the file. */
1077 if ( !PageUptodate(prepared_pages[num_pages-1]) || 1189 if (!PageUptodate(prepared_pages[num_pages - 1]) ||
1078 ((pos+write_bytes)>>PAGE_CACHE_SHIFT) > (inode->i_size>>PAGE_CACHE_SHIFT) ) { 1190 ((pos + write_bytes) >> PAGE_CACHE_SHIFT) >
1079 head = page_buffers(prepared_pages[num_pages-1]); 1191 (inode->i_size >> PAGE_CACHE_SHIFT)) {
1080 1192 head = page_buffers(prepared_pages[num_pages - 1]);
1081 /* for each buffer in page */ 1193
1082 for(bh = head, block_start = 0; bh != head || !block_start; 1194 /* for each buffer in page */
1083 block_start=block_end, bh = bh->b_this_page) { 1195 for (bh = head, block_start = 0; bh != head || !block_start;
1084 1196 block_start = block_end, bh = bh->b_this_page) {
1085 if (!bh) 1197
1086 reiserfs_panic(inode->i_sb, "green-9002: Allocated but absent buffer for a page?"); 1198 if (!bh)
1087 /* Find where this buffer ends */ 1199 reiserfs_panic(inode->i_sb,
1088 block_end = block_start+inode->i_sb->s_blocksize; 1200 "green-9002: Allocated but absent buffer for a page?");
1089 if ( block_start >= to ) 1201 /* Find where this buffer ends */
1090 /* if this buffer is after requested data to map, skip it*/ 1202 block_end = block_start + inode->i_sb->s_blocksize;
1091 break; 1203 if (block_start >= to)
1092 if ( block_end > to ) { /* Aha, our partial buffer */ 1204 /* if this buffer is after requested data to map, skip it */
1093 if ( buffer_mapped(bh) ) { /* If it is mapped, we need to 1205 break;
1094 issue READ request for it to 1206 if (block_end > to) { /* Aha, our partial buffer */
1095 not loose data */ 1207 if (buffer_mapped(bh)) { /* If it is mapped, we need to
1096 ll_rw_block(READ, 1, &bh); 1208 issue READ request for it to
1097 *wait_bh++=bh; 1209 not loose data */
1098 } else { /* Not mapped, zero it */ 1210 ll_rw_block(READ, 1, &bh);
1099 char *kaddr = kmap_atomic(prepared_pages[num_pages-1], KM_USER0); 1211 *wait_bh++ = bh;
1100 memset(kaddr+to, 0, block_end-to); 1212 } else { /* Not mapped, zero it */
1101 kunmap_atomic( kaddr, KM_USER0); 1213 char *kaddr =
1102 set_buffer_uptodate(bh); 1214 kmap_atomic(prepared_pages
1103 } 1215 [num_pages - 1],
1216 KM_USER0);
1217 memset(kaddr + to, 0, block_end - to);
1218 kunmap_atomic(kaddr, KM_USER0);
1219 set_buffer_uptodate(bh);
1220 }
1221 }
1104 } 1222 }
1105 }
1106 } 1223 }
1107 1224
1108 /* Wait for read requests we made to happen, if necessary */ 1225 /* Wait for read requests we made to happen, if necessary */
1109 while(wait_bh > wait) { 1226 while (wait_bh > wait) {
1110 wait_on_buffer(*--wait_bh); 1227 wait_on_buffer(*--wait_bh);
1111 if (!buffer_uptodate(*wait_bh)) { 1228 if (!buffer_uptodate(*wait_bh)) {
1112 res = -EIO; 1229 res = -EIO;
1113 goto failed_read; 1230 goto failed_read;
1231 }
1114 } 1232 }
1115 } 1233
1116 1234 return blocks;
1117 return blocks; 1235 failed_page_grabbing:
1118failed_page_grabbing: 1236 num_pages = i;
1119 num_pages = i; 1237 failed_read:
1120failed_read: 1238 reiserfs_unprepare_pages(prepared_pages, num_pages);
1121 reiserfs_unprepare_pages(prepared_pages, num_pages); 1239 return res;
1122 return res;
1123} 1240}
1124 1241
1125/* Write @count bytes at position @ppos in a file indicated by @file 1242/* Write @count bytes at position @ppos in a file indicated by @file
@@ -1148,262 +1265,305 @@ failed_read:
1148 Future Features: providing search_by_key with hints. 1265 Future Features: providing search_by_key with hints.
1149 1266
1150*/ 1267*/
1151static ssize_t reiserfs_file_write( struct file *file, /* the file we are going to write into */ 1268static ssize_t reiserfs_file_write(struct file *file, /* the file we are going to write into */
1152 const char __user *buf, /* pointer to user supplied data 1269 const char __user * buf, /* pointer to user supplied data
1153(in userspace) */ 1270 (in userspace) */
1154 size_t count, /* amount of bytes to write */ 1271 size_t count, /* amount of bytes to write */
1155 loff_t *ppos /* pointer to position in file that we start writing at. Should be updated to 1272 loff_t * ppos /* pointer to position in file that we start writing at. Should be updated to
1156 * new current position before returning. */ ) 1273 * new current position before returning. */
1274 )
1157{ 1275{
1158 size_t already_written = 0; // Number of bytes already written to the file. 1276 size_t already_written = 0; // Number of bytes already written to the file.
1159 loff_t pos; // Current position in the file. 1277 loff_t pos; // Current position in the file.
1160 ssize_t res; // return value of various functions that we call. 1278 ssize_t res; // return value of various functions that we call.
1161 int err = 0; 1279 int err = 0;
1162 struct inode *inode = file->f_dentry->d_inode; // Inode of the file that we are writing to. 1280 struct inode *inode = file->f_dentry->d_inode; // Inode of the file that we are writing to.
1163 /* To simplify coding at this time, we store 1281 /* To simplify coding at this time, we store
1164 locked pages in array for now */ 1282 locked pages in array for now */
1165 struct page * prepared_pages[REISERFS_WRITE_PAGES_AT_A_TIME]; 1283 struct page *prepared_pages[REISERFS_WRITE_PAGES_AT_A_TIME];
1166 struct reiserfs_transaction_handle th; 1284 struct reiserfs_transaction_handle th;
1167 th.t_trans_id = 0; 1285 th.t_trans_id = 0;
1168 1286
1169 if ( file->f_flags & O_DIRECT) { // Direct IO needs treatment 1287 if (file->f_flags & O_DIRECT) { // Direct IO needs treatment
1170 ssize_t result, after_file_end = 0; 1288 ssize_t result, after_file_end = 0;
1171 if ( (*ppos + count >= inode->i_size) || (file->f_flags & O_APPEND) ) { 1289 if ((*ppos + count >= inode->i_size)
1172 /* If we are appending a file, we need to put this savelink in here. 1290 || (file->f_flags & O_APPEND)) {
1173 If we will crash while doing direct io, finish_unfinished will 1291 /* If we are appending a file, we need to put this savelink in here.
1174 cut the garbage from the file end. */ 1292 If we will crash while doing direct io, finish_unfinished will
1175 reiserfs_write_lock(inode->i_sb); 1293 cut the garbage from the file end. */
1176 err = journal_begin(&th, inode->i_sb, JOURNAL_PER_BALANCE_CNT ); 1294 reiserfs_write_lock(inode->i_sb);
1177 if (err) { 1295 err =
1178 reiserfs_write_unlock (inode->i_sb); 1296 journal_begin(&th, inode->i_sb,
1179 return err; 1297 JOURNAL_PER_BALANCE_CNT);
1180 } 1298 if (err) {
1181 reiserfs_update_inode_transaction(inode); 1299 reiserfs_write_unlock(inode->i_sb);
1182 add_save_link (&th, inode, 1 /* Truncate */); 1300 return err;
1183 after_file_end = 1; 1301 }
1184 err = journal_end(&th, inode->i_sb, JOURNAL_PER_BALANCE_CNT ); 1302 reiserfs_update_inode_transaction(inode);
1185 reiserfs_write_unlock(inode->i_sb); 1303 add_save_link(&th, inode, 1 /* Truncate */ );
1186 if (err) 1304 after_file_end = 1;
1187 return err; 1305 err =
1188 } 1306 journal_end(&th, inode->i_sb,
1189 result = generic_file_write(file, buf, count, ppos); 1307 JOURNAL_PER_BALANCE_CNT);
1190 1308 reiserfs_write_unlock(inode->i_sb);
1191 if ( after_file_end ) { /* Now update i_size and remove the savelink */ 1309 if (err)
1192 struct reiserfs_transaction_handle th; 1310 return err;
1193 reiserfs_write_lock(inode->i_sb); 1311 }
1194 err = journal_begin(&th, inode->i_sb, 1); 1312 result = generic_file_write(file, buf, count, ppos);
1195 if (err) { 1313
1196 reiserfs_write_unlock (inode->i_sb); 1314 if (after_file_end) { /* Now update i_size and remove the savelink */
1197 return err; 1315 struct reiserfs_transaction_handle th;
1198 } 1316 reiserfs_write_lock(inode->i_sb);
1199 reiserfs_update_inode_transaction(inode); 1317 err = journal_begin(&th, inode->i_sb, 1);
1200 reiserfs_update_sd(&th, inode); 1318 if (err) {
1201 err = journal_end(&th, inode->i_sb, 1); 1319 reiserfs_write_unlock(inode->i_sb);
1202 if (err) { 1320 return err;
1203 reiserfs_write_unlock (inode->i_sb); 1321 }
1204 return err; 1322 reiserfs_update_inode_transaction(inode);
1205 } 1323 reiserfs_update_sd(&th, inode);
1206 err = remove_save_link (inode, 1/* truncate */); 1324 err = journal_end(&th, inode->i_sb, 1);
1207 reiserfs_write_unlock(inode->i_sb); 1325 if (err) {
1208 if (err) 1326 reiserfs_write_unlock(inode->i_sb);
1209 return err; 1327 return err;
1210 } 1328 }
1211 1329 err = remove_save_link(inode, 1 /* truncate */ );
1212 return result; 1330 reiserfs_write_unlock(inode->i_sb);
1213 } 1331 if (err)
1214 1332 return err;
1215 if ( unlikely((ssize_t) count < 0 )) 1333 }
1216 return -EINVAL;
1217
1218 if (unlikely(!access_ok(VERIFY_READ, buf, count)))
1219 return -EFAULT;
1220
1221 down(&inode->i_sem); // locks the entire file for just us
1222
1223 pos = *ppos;
1224
1225 /* Check if we can write to specified region of file, file
1226 is not overly big and this kind of stuff. Adjust pos and
1227 count, if needed */
1228 res = generic_write_checks(file, &pos, &count, 0);
1229 if (res)
1230 goto out;
1231
1232 if ( count == 0 )
1233 goto out;
1234
1235 res = remove_suid(file->f_dentry);
1236 if (res)
1237 goto out;
1238
1239 inode_update_time(inode, 1); /* Both mtime and ctime */
1240
1241 // Ok, we are done with all the checks.
1242 1334
1243 // Now we should start real work 1335 return result;
1336 }
1244 1337
1245 /* If we are going to write past the file's packed tail or if we are going 1338 if (unlikely((ssize_t) count < 0))
1246 to overwrite part of the tail, we need that tail to be converted into 1339 return -EINVAL;
1247 unformatted node */ 1340
1248 res = reiserfs_check_for_tail_and_convert( inode, pos, count); 1341 if (unlikely(!access_ok(VERIFY_READ, buf, count)))
1249 if (res) 1342 return -EFAULT;
1250 goto out; 1343
1344 down(&inode->i_sem); // locks the entire file for just us
1345
1346 pos = *ppos;
1347
1348 /* Check if we can write to specified region of file, file
1349 is not overly big and this kind of stuff. Adjust pos and
1350 count, if needed */
1351 res = generic_write_checks(file, &pos, &count, 0);
1352 if (res)
1353 goto out;
1354
1355 if (count == 0)
1356 goto out;
1357
1358 res = remove_suid(file->f_dentry);
1359 if (res)
1360 goto out;
1361
1362 inode_update_time(inode, 1); /* Both mtime and ctime */
1363
1364 // Ok, we are done with all the checks.
1365
1366 // Now we should start real work
1367
1368 /* If we are going to write past the file's packed tail or if we are going
1369 to overwrite part of the tail, we need that tail to be converted into
1370 unformatted node */
1371 res = reiserfs_check_for_tail_and_convert(inode, pos, count);
1372 if (res)
1373 goto out;
1374
1375 while (count > 0) {
1376 /* This is the main loop in which we running until some error occures
1377 or until we write all of the data. */
1378 size_t num_pages; /* amount of pages we are going to write this iteration */
1379 size_t write_bytes; /* amount of bytes to write during this iteration */
1380 size_t blocks_to_allocate; /* how much blocks we need to allocate for this iteration */
1381
1382 /* (pos & (PAGE_CACHE_SIZE-1)) is an idiom for offset into a page of pos */
1383 num_pages = !!((pos + count) & (PAGE_CACHE_SIZE - 1)) + /* round up partial
1384 pages */
1385 ((count +
1386 (pos & (PAGE_CACHE_SIZE - 1))) >> PAGE_CACHE_SHIFT);
1387 /* convert size to amount of
1388 pages */
1389 reiserfs_write_lock(inode->i_sb);
1390 if (num_pages > REISERFS_WRITE_PAGES_AT_A_TIME
1391 || num_pages > reiserfs_can_fit_pages(inode->i_sb)) {
1392 /* If we were asked to write more data than we want to or if there
1393 is not that much space, then we shorten amount of data to write
1394 for this iteration. */
1395 num_pages =
1396 min_t(size_t, REISERFS_WRITE_PAGES_AT_A_TIME,
1397 reiserfs_can_fit_pages(inode->i_sb));
1398 /* Also we should not forget to set size in bytes accordingly */
1399 write_bytes = (num_pages << PAGE_CACHE_SHIFT) -
1400 (pos & (PAGE_CACHE_SIZE - 1));
1401 /* If position is not on the
1402 start of the page, we need
1403 to substract the offset
1404 within page */
1405 } else
1406 write_bytes = count;
1407
1408 /* reserve the blocks to be allocated later, so that later on
1409 we still have the space to write the blocks to */
1410 reiserfs_claim_blocks_to_be_allocated(inode->i_sb,
1411 num_pages <<
1412 (PAGE_CACHE_SHIFT -
1413 inode->i_blkbits));
1414 reiserfs_write_unlock(inode->i_sb);
1415
1416 if (!num_pages) { /* If we do not have enough space even for a single page... */
1417 if (pos >
1418 inode->i_size + inode->i_sb->s_blocksize -
1419 (pos & (inode->i_sb->s_blocksize - 1))) {
1420 res = -ENOSPC;
1421 break; // In case we are writing past the end of the last file block, break.
1422 }
1423 // Otherwise we are possibly overwriting the file, so
1424 // let's set write size to be equal or less than blocksize.
1425 // This way we get it correctly for file holes.
1426 // But overwriting files on absolutelly full volumes would not
1427 // be very efficient. Well, people are not supposed to fill
1428 // 100% of disk space anyway.
1429 write_bytes =
1430 min_t(size_t, count,
1431 inode->i_sb->s_blocksize -
1432 (pos & (inode->i_sb->s_blocksize - 1)));
1433 num_pages = 1;
1434 // No blocks were claimed before, so do it now.
1435 reiserfs_claim_blocks_to_be_allocated(inode->i_sb,
1436 1 <<
1437 (PAGE_CACHE_SHIFT
1438 -
1439 inode->
1440 i_blkbits));
1441 }
1251 1442
1252 while ( count > 0) { 1443 /* Prepare for writing into the region, read in all the
1253 /* This is the main loop in which we running until some error occures 1444 partially overwritten pages, if needed. And lock the pages,
1254 or until we write all of the data. */ 1445 so that nobody else can access these until we are done.
1255 size_t num_pages;/* amount of pages we are going to write this iteration */ 1446 We get number of actual blocks needed as a result. */
1256 size_t write_bytes; /* amount of bytes to write during this iteration */ 1447 blocks_to_allocate =
1257 size_t blocks_to_allocate; /* how much blocks we need to allocate for this iteration */ 1448 reiserfs_prepare_file_region_for_write(inode, pos,
1258 1449 num_pages,
1259 /* (pos & (PAGE_CACHE_SIZE-1)) is an idiom for offset into a page of pos*/ 1450 write_bytes,
1260 num_pages = !!((pos+count) & (PAGE_CACHE_SIZE - 1)) + /* round up partial 1451 prepared_pages);
1261 pages */ 1452 if (blocks_to_allocate < 0) {
1262 ((count + (pos & (PAGE_CACHE_SIZE-1))) >> PAGE_CACHE_SHIFT); 1453 res = blocks_to_allocate;
1263 /* convert size to amount of 1454 reiserfs_release_claimed_blocks(inode->i_sb,
1264 pages */ 1455 num_pages <<
1265 reiserfs_write_lock(inode->i_sb); 1456 (PAGE_CACHE_SHIFT -
1266 if ( num_pages > REISERFS_WRITE_PAGES_AT_A_TIME 1457 inode->i_blkbits));
1267 || num_pages > reiserfs_can_fit_pages(inode->i_sb) ) { 1458 break;
1268 /* If we were asked to write more data than we want to or if there 1459 }
1269 is not that much space, then we shorten amount of data to write
1270 for this iteration. */
1271 num_pages = min_t(size_t, REISERFS_WRITE_PAGES_AT_A_TIME, reiserfs_can_fit_pages(inode->i_sb));
1272 /* Also we should not forget to set size in bytes accordingly */
1273 write_bytes = (num_pages << PAGE_CACHE_SHIFT) -
1274 (pos & (PAGE_CACHE_SIZE-1));
1275 /* If position is not on the
1276 start of the page, we need
1277 to substract the offset
1278 within page */
1279 } else
1280 write_bytes = count;
1281 1460
1282 /* reserve the blocks to be allocated later, so that later on 1461 /* First we correct our estimate of how many blocks we need */
1283 we still have the space to write the blocks to */ 1462 reiserfs_release_claimed_blocks(inode->i_sb,
1284 reiserfs_claim_blocks_to_be_allocated(inode->i_sb, num_pages << (PAGE_CACHE_SHIFT - inode->i_blkbits)); 1463 (num_pages <<
1285 reiserfs_write_unlock(inode->i_sb); 1464 (PAGE_CACHE_SHIFT -
1465 inode->i_sb->
1466 s_blocksize_bits)) -
1467 blocks_to_allocate);
1468
1469 if (blocks_to_allocate > 0) { /*We only allocate blocks if we need to */
1470 /* Fill in all the possible holes and append the file if needed */
1471 res =
1472 reiserfs_allocate_blocks_for_region(&th, inode, pos,
1473 num_pages,
1474 write_bytes,
1475 prepared_pages,
1476 blocks_to_allocate);
1477 }
1286 1478
1287 if ( !num_pages ) { /* If we do not have enough space even for a single page... */ 1479 /* well, we have allocated the blocks, so it is time to free
1288 if ( pos > inode->i_size+inode->i_sb->s_blocksize-(pos & (inode->i_sb->s_blocksize-1))) { 1480 the reservation we made earlier. */
1289 res = -ENOSPC; 1481 reiserfs_release_claimed_blocks(inode->i_sb,
1290 break; // In case we are writing past the end of the last file block, break. 1482 blocks_to_allocate);
1291 } 1483 if (res) {
1292 // Otherwise we are possibly overwriting the file, so 1484 reiserfs_unprepare_pages(prepared_pages, num_pages);
1293 // let's set write size to be equal or less than blocksize. 1485 break;
1294 // This way we get it correctly for file holes. 1486 }
1295 // But overwriting files on absolutelly full volumes would not
1296 // be very efficient. Well, people are not supposed to fill
1297 // 100% of disk space anyway.
1298 write_bytes = min_t(size_t, count, inode->i_sb->s_blocksize - (pos & (inode->i_sb->s_blocksize - 1)));
1299 num_pages = 1;
1300 // No blocks were claimed before, so do it now.
1301 reiserfs_claim_blocks_to_be_allocated(inode->i_sb, 1 << (PAGE_CACHE_SHIFT - inode->i_blkbits));
1302 }
1303 1487
1304 /* Prepare for writing into the region, read in all the 1488/* NOTE that allocating blocks and filling blocks can be done in reverse order
1305 partially overwritten pages, if needed. And lock the pages, 1489 and probably we would do that just to get rid of garbage in files after a
1306 so that nobody else can access these until we are done. 1490 crash */
1307 We get number of actual blocks needed as a result.*/
1308 blocks_to_allocate = reiserfs_prepare_file_region_for_write(inode, pos, num_pages, write_bytes, prepared_pages);
1309 if ( blocks_to_allocate < 0 ) {
1310 res = blocks_to_allocate;
1311 reiserfs_release_claimed_blocks(inode->i_sb, num_pages << (PAGE_CACHE_SHIFT - inode->i_blkbits));
1312 break;
1313 }
1314 1491
1315 /* First we correct our estimate of how many blocks we need */ 1492 /* Copy data from user-supplied buffer to file's pages */
1316 reiserfs_release_claimed_blocks(inode->i_sb, (num_pages << (PAGE_CACHE_SHIFT - inode->i_sb->s_blocksize_bits)) - blocks_to_allocate ); 1493 res =
1494 reiserfs_copy_from_user_to_file_region(pos, num_pages,
1495 write_bytes,
1496 prepared_pages, buf);
1497 if (res) {
1498 reiserfs_unprepare_pages(prepared_pages, num_pages);
1499 break;
1500 }
1317 1501
1318 if ( blocks_to_allocate > 0) {/*We only allocate blocks if we need to*/ 1502 /* Send the pages to disk and unlock them. */
1319 /* Fill in all the possible holes and append the file if needed */ 1503 res =
1320 res = reiserfs_allocate_blocks_for_region(&th, inode, pos, num_pages, write_bytes, prepared_pages, blocks_to_allocate); 1504 reiserfs_submit_file_region_for_write(&th, inode, pos,
1505 num_pages,
1506 write_bytes,
1507 prepared_pages);
1508 if (res)
1509 break;
1510
1511 already_written += write_bytes;
1512 buf += write_bytes;
1513 *ppos = pos += write_bytes;
1514 count -= write_bytes;
1515 balance_dirty_pages_ratelimited(inode->i_mapping);
1321 } 1516 }
1322 1517
1323 /* well, we have allocated the blocks, so it is time to free 1518 /* this is only true on error */
1324 the reservation we made earlier. */ 1519 if (th.t_trans_id) {
1325 reiserfs_release_claimed_blocks(inode->i_sb, blocks_to_allocate); 1520 reiserfs_write_lock(inode->i_sb);
1326 if ( res ) { 1521 err = journal_end(&th, th.t_super, th.t_blocks_allocated);
1327 reiserfs_unprepare_pages(prepared_pages, num_pages); 1522 reiserfs_write_unlock(inode->i_sb);
1328 break; 1523 if (err) {
1524 res = err;
1525 goto out;
1526 }
1329 } 1527 }
1330 1528
1331/* NOTE that allocating blocks and filling blocks can be done in reverse order 1529 if ((file->f_flags & O_SYNC) || IS_SYNC(inode))
1332 and probably we would do that just to get rid of garbage in files after a 1530 res =
1333 crash */ 1531 generic_osync_inode(inode, file->f_mapping,
1532 OSYNC_METADATA | OSYNC_DATA);
1334 1533
1335 /* Copy data from user-supplied buffer to file's pages */ 1534 up(&inode->i_sem);
1336 res = reiserfs_copy_from_user_to_file_region(pos, num_pages, write_bytes, prepared_pages, buf); 1535 reiserfs_async_progress_wait(inode->i_sb);
1337 if ( res ) { 1536 return (already_written != 0) ? already_written : res;
1338 reiserfs_unprepare_pages(prepared_pages, num_pages);
1339 break;
1340 }
1341 1537
1342 /* Send the pages to disk and unlock them. */ 1538 out:
1343 res = reiserfs_submit_file_region_for_write(&th, inode, pos, num_pages, 1539 up(&inode->i_sem); // unlock the file on exit.
1344 write_bytes,prepared_pages); 1540 return res;
1345 if ( res )
1346 break;
1347
1348 already_written += write_bytes;
1349 buf += write_bytes;
1350 *ppos = pos += write_bytes;
1351 count -= write_bytes;
1352 balance_dirty_pages_ratelimited(inode->i_mapping);
1353 }
1354
1355 /* this is only true on error */
1356 if (th.t_trans_id) {
1357 reiserfs_write_lock(inode->i_sb);
1358 err = journal_end(&th, th.t_super, th.t_blocks_allocated);
1359 reiserfs_write_unlock(inode->i_sb);
1360 if (err) {
1361 res = err;
1362 goto out;
1363 }
1364 }
1365
1366 if ((file->f_flags & O_SYNC) || IS_SYNC(inode))
1367 res = generic_osync_inode(inode, file->f_mapping, OSYNC_METADATA|OSYNC_DATA);
1368
1369 up(&inode->i_sem);
1370 reiserfs_async_progress_wait(inode->i_sb);
1371 return (already_written != 0)?already_written:res;
1372
1373out:
1374 up(&inode->i_sem); // unlock the file on exit.
1375 return res;
1376} 1541}
1377 1542
1378static ssize_t reiserfs_aio_write(struct kiocb *iocb, const char __user *buf, 1543static ssize_t reiserfs_aio_write(struct kiocb *iocb, const char __user * buf,
1379 size_t count, loff_t pos) 1544 size_t count, loff_t pos)
1380{ 1545{
1381 return generic_file_aio_write(iocb, buf, count, pos); 1546 return generic_file_aio_write(iocb, buf, count, pos);
1382} 1547}
1383 1548
1384
1385
1386struct file_operations reiserfs_file_operations = { 1549struct file_operations reiserfs_file_operations = {
1387 .read = generic_file_read, 1550 .read = generic_file_read,
1388 .write = reiserfs_file_write, 1551 .write = reiserfs_file_write,
1389 .ioctl = reiserfs_ioctl, 1552 .ioctl = reiserfs_ioctl,
1390 .mmap = generic_file_mmap, 1553 .mmap = generic_file_mmap,
1391 .release = reiserfs_file_release, 1554 .release = reiserfs_file_release,
1392 .fsync = reiserfs_sync_file, 1555 .fsync = reiserfs_sync_file,
1393 .sendfile = generic_file_sendfile, 1556 .sendfile = generic_file_sendfile,
1394 .aio_read = generic_file_aio_read, 1557 .aio_read = generic_file_aio_read,
1395 .aio_write = reiserfs_aio_write, 1558 .aio_write = reiserfs_aio_write,
1396}; 1559};
1397 1560
1398 1561struct inode_operations reiserfs_file_inode_operations = {
1399struct inode_operations reiserfs_file_inode_operations = { 1562 .truncate = reiserfs_vfs_truncate_file,
1400 .truncate = reiserfs_vfs_truncate_file, 1563 .setattr = reiserfs_setattr,
1401 .setattr = reiserfs_setattr, 1564 .setxattr = reiserfs_setxattr,
1402 .setxattr = reiserfs_setxattr, 1565 .getxattr = reiserfs_getxattr,
1403 .getxattr = reiserfs_getxattr, 1566 .listxattr = reiserfs_listxattr,
1404 .listxattr = reiserfs_listxattr, 1567 .removexattr = reiserfs_removexattr,
1405 .removexattr = reiserfs_removexattr, 1568 .permission = reiserfs_permission,
1406 .permission = reiserfs_permission,
1407}; 1569};
1408
1409
diff --git a/fs/reiserfs/fix_node.c b/fs/reiserfs/fix_node.c
index e4f64be9e15b..2706e2adffab 100644
--- a/fs/reiserfs/fix_node.c
+++ b/fs/reiserfs/fix_node.c
@@ -34,14 +34,12 @@
34 ** 34 **
35 **/ 35 **/
36 36
37
38#include <linux/config.h> 37#include <linux/config.h>
39#include <linux/time.h> 38#include <linux/time.h>
40#include <linux/string.h> 39#include <linux/string.h>
41#include <linux/reiserfs_fs.h> 40#include <linux/reiserfs_fs.h>
42#include <linux/buffer_head.h> 41#include <linux/buffer_head.h>
43 42
44
45/* To make any changes in the tree we find a node, that contains item 43/* To make any changes in the tree we find a node, that contains item
46 to be changed/deleted or position in the node we insert a new item 44 to be changed/deleted or position in the node we insert a new item
47 to. We call this node S. To do balancing we need to decide what we 45 to. We call this node S. To do balancing we need to decide what we
@@ -56,490 +54,522 @@
56 have to have if we do not any shiftings, if we shift to left/right 54 have to have if we do not any shiftings, if we shift to left/right
57 neighbor or to both. */ 55 neighbor or to both. */
58 56
59
60/* taking item number in virtual node, returns number of item, that it has in source buffer */ 57/* taking item number in virtual node, returns number of item, that it has in source buffer */
61static inline int old_item_num (int new_num, int affected_item_num, int mode) 58static inline int old_item_num(int new_num, int affected_item_num, int mode)
62{ 59{
63 if (mode == M_PASTE || mode == M_CUT || new_num < affected_item_num) 60 if (mode == M_PASTE || mode == M_CUT || new_num < affected_item_num)
64 return new_num; 61 return new_num;
65 62
66 if (mode == M_INSERT) { 63 if (mode == M_INSERT) {
67 64
68 RFALSE( new_num == 0, 65 RFALSE(new_num == 0,
69 "vs-8005: for INSERT mode and item number of inserted item"); 66 "vs-8005: for INSERT mode and item number of inserted item");
70 67
71 return new_num - 1; 68 return new_num - 1;
72 } 69 }
73 70
74 RFALSE( mode != M_DELETE, 71 RFALSE(mode != M_DELETE,
75 "vs-8010: old_item_num: mode must be M_DELETE (mode = \'%c\'", mode); 72 "vs-8010: old_item_num: mode must be M_DELETE (mode = \'%c\'",
76 /* delete mode */ 73 mode);
77 return new_num + 1; 74 /* delete mode */
75 return new_num + 1;
78} 76}
79 77
80static void create_virtual_node (struct tree_balance * tb, int h) 78static void create_virtual_node(struct tree_balance *tb, int h)
81{ 79{
82 struct item_head * ih; 80 struct item_head *ih;
83 struct virtual_node * vn = tb->tb_vn; 81 struct virtual_node *vn = tb->tb_vn;
84 int new_num; 82 int new_num;
85 struct buffer_head * Sh; /* this comes from tb->S[h] */ 83 struct buffer_head *Sh; /* this comes from tb->S[h] */
86 84
87 Sh = PATH_H_PBUFFER (tb->tb_path, h); 85 Sh = PATH_H_PBUFFER(tb->tb_path, h);
88 86
89 /* size of changed node */ 87 /* size of changed node */
90 vn->vn_size = MAX_CHILD_SIZE (Sh) - B_FREE_SPACE (Sh) + tb->insert_size[h]; 88 vn->vn_size =
89 MAX_CHILD_SIZE(Sh) - B_FREE_SPACE(Sh) + tb->insert_size[h];
91 90
92 /* for internal nodes array if virtual items is not created */ 91 /* for internal nodes array if virtual items is not created */
93 if (h) { 92 if (h) {
94 vn->vn_nr_item = (vn->vn_size - DC_SIZE) / (DC_SIZE + KEY_SIZE); 93 vn->vn_nr_item = (vn->vn_size - DC_SIZE) / (DC_SIZE + KEY_SIZE);
95 return; 94 return;
96 }
97
98 /* number of items in virtual node */
99 vn->vn_nr_item = B_NR_ITEMS (Sh) + ((vn->vn_mode == M_INSERT)? 1 : 0) - ((vn->vn_mode == M_DELETE)? 1 : 0);
100
101 /* first virtual item */
102 vn->vn_vi = (struct virtual_item *)(tb->tb_vn + 1);
103 memset (vn->vn_vi, 0, vn->vn_nr_item * sizeof (struct virtual_item));
104 vn->vn_free_ptr += vn->vn_nr_item * sizeof (struct virtual_item);
105
106
107 /* first item in the node */
108 ih = B_N_PITEM_HEAD (Sh, 0);
109
110 /* define the mergeability for 0-th item (if it is not being deleted) */
111 if (op_is_left_mergeable (&(ih->ih_key), Sh->b_size) && (vn->vn_mode != M_DELETE || vn->vn_affected_item_num))
112 vn->vn_vi[0].vi_type |= VI_TYPE_LEFT_MERGEABLE;
113
114 /* go through all items those remain in the virtual node (except for the new (inserted) one) */
115 for (new_num = 0; new_num < vn->vn_nr_item; new_num ++) {
116 int j;
117 struct virtual_item * vi = vn->vn_vi + new_num;
118 int is_affected = ((new_num != vn->vn_affected_item_num) ? 0 : 1);
119
120
121 if (is_affected && vn->vn_mode == M_INSERT)
122 continue;
123
124 /* get item number in source node */
125 j = old_item_num (new_num, vn->vn_affected_item_num, vn->vn_mode);
126
127 vi->vi_item_len += ih_item_len(ih + j) + IH_SIZE;
128 vi->vi_ih = ih + j;
129 vi->vi_item = B_I_PITEM (Sh, ih + j);
130 vi->vi_uarea = vn->vn_free_ptr;
131
132 // FIXME: there is no check, that item operation did not
133 // consume too much memory
134 vn->vn_free_ptr += op_create_vi (vn, vi, is_affected, tb->insert_size [0]);
135 if (tb->vn_buf + tb->vn_buf_size < vn->vn_free_ptr)
136 reiserfs_panic (tb->tb_sb, "vs-8030: create_virtual_node: "
137 "virtual node space consumed");
138
139 if (!is_affected)
140 /* this is not being changed */
141 continue;
142
143 if (vn->vn_mode == M_PASTE || vn->vn_mode == M_CUT) {
144 vn->vn_vi[new_num].vi_item_len += tb->insert_size[0];
145 vi->vi_new_data = vn->vn_data; // pointer to data which is going to be pasted
146 } 95 }
147 }
148
149
150 /* virtual inserted item is not defined yet */
151 if (vn->vn_mode == M_INSERT) {
152 struct virtual_item * vi = vn->vn_vi + vn->vn_affected_item_num;
153
154 RFALSE( vn->vn_ins_ih == 0,
155 "vs-8040: item header of inserted item is not specified");
156 vi->vi_item_len = tb->insert_size[0];
157 vi->vi_ih = vn->vn_ins_ih;
158 vi->vi_item = vn->vn_data;
159 vi->vi_uarea = vn->vn_free_ptr;
160
161 op_create_vi (vn, vi, 0/*not pasted or cut*/, tb->insert_size [0]);
162 }
163
164 /* set right merge flag we take right delimiting key and check whether it is a mergeable item */
165 if (tb->CFR[0]) {
166 struct reiserfs_key * key;
167
168 key = B_N_PDELIM_KEY (tb->CFR[0], tb->rkey[0]);
169 if (op_is_left_mergeable (key, Sh->b_size) && (vn->vn_mode != M_DELETE ||
170 vn->vn_affected_item_num != B_NR_ITEMS (Sh) - 1))
171 vn->vn_vi[vn->vn_nr_item-1].vi_type |= VI_TYPE_RIGHT_MERGEABLE;
172 96
173#ifdef CONFIG_REISERFS_CHECK 97 /* number of items in virtual node */
174 if (op_is_left_mergeable (key, Sh->b_size) && 98 vn->vn_nr_item =
175 !(vn->vn_mode != M_DELETE || vn->vn_affected_item_num != B_NR_ITEMS (Sh) - 1) ) { 99 B_NR_ITEMS(Sh) + ((vn->vn_mode == M_INSERT) ? 1 : 0) -
176 /* we delete last item and it could be merged with right neighbor's first item */ 100 ((vn->vn_mode == M_DELETE) ? 1 : 0);
177 if (!(B_NR_ITEMS (Sh) == 1 && is_direntry_le_ih (B_N_PITEM_HEAD (Sh, 0)) && 101
178 I_ENTRY_COUNT (B_N_PITEM_HEAD (Sh, 0)) == 1)) { 102 /* first virtual item */
179 /* node contains more than 1 item, or item is not directory item, or this item contains more than 1 entry */ 103 vn->vn_vi = (struct virtual_item *)(tb->tb_vn + 1);
180 print_block (Sh, 0, -1, -1); 104 memset(vn->vn_vi, 0, vn->vn_nr_item * sizeof(struct virtual_item));
181 reiserfs_panic (tb->tb_sb, "vs-8045: create_virtual_node: rdkey %k, affected item==%d (mode==%c) Must be %c", 105 vn->vn_free_ptr += vn->vn_nr_item * sizeof(struct virtual_item);
182 key, vn->vn_affected_item_num, vn->vn_mode, M_DELETE); 106
183 } else 107 /* first item in the node */
184 /* we can delete directory item, that has only one directory entry in it */ 108 ih = B_N_PITEM_HEAD(Sh, 0);
185 ; 109
110 /* define the mergeability for 0-th item (if it is not being deleted) */
111 if (op_is_left_mergeable(&(ih->ih_key), Sh->b_size)
112 && (vn->vn_mode != M_DELETE || vn->vn_affected_item_num))
113 vn->vn_vi[0].vi_type |= VI_TYPE_LEFT_MERGEABLE;
114
115 /* go through all items those remain in the virtual node (except for the new (inserted) one) */
116 for (new_num = 0; new_num < vn->vn_nr_item; new_num++) {
117 int j;
118 struct virtual_item *vi = vn->vn_vi + new_num;
119 int is_affected =
120 ((new_num != vn->vn_affected_item_num) ? 0 : 1);
121
122 if (is_affected && vn->vn_mode == M_INSERT)
123 continue;
124
125 /* get item number in source node */
126 j = old_item_num(new_num, vn->vn_affected_item_num,
127 vn->vn_mode);
128
129 vi->vi_item_len += ih_item_len(ih + j) + IH_SIZE;
130 vi->vi_ih = ih + j;
131 vi->vi_item = B_I_PITEM(Sh, ih + j);
132 vi->vi_uarea = vn->vn_free_ptr;
133
134 // FIXME: there is no check, that item operation did not
135 // consume too much memory
136 vn->vn_free_ptr +=
137 op_create_vi(vn, vi, is_affected, tb->insert_size[0]);
138 if (tb->vn_buf + tb->vn_buf_size < vn->vn_free_ptr)
139 reiserfs_panic(tb->tb_sb,
140 "vs-8030: create_virtual_node: "
141 "virtual node space consumed");
142
143 if (!is_affected)
144 /* this is not being changed */
145 continue;
146
147 if (vn->vn_mode == M_PASTE || vn->vn_mode == M_CUT) {
148 vn->vn_vi[new_num].vi_item_len += tb->insert_size[0];
149 vi->vi_new_data = vn->vn_data; // pointer to data which is going to be pasted
150 }
186 } 151 }
152
153 /* virtual inserted item is not defined yet */
154 if (vn->vn_mode == M_INSERT) {
155 struct virtual_item *vi = vn->vn_vi + vn->vn_affected_item_num;
156
157 RFALSE(vn->vn_ins_ih == 0,
158 "vs-8040: item header of inserted item is not specified");
159 vi->vi_item_len = tb->insert_size[0];
160 vi->vi_ih = vn->vn_ins_ih;
161 vi->vi_item = vn->vn_data;
162 vi->vi_uarea = vn->vn_free_ptr;
163
164 op_create_vi(vn, vi, 0 /*not pasted or cut */ ,
165 tb->insert_size[0]);
166 }
167
168 /* set right merge flag we take right delimiting key and check whether it is a mergeable item */
169 if (tb->CFR[0]) {
170 struct reiserfs_key *key;
171
172 key = B_N_PDELIM_KEY(tb->CFR[0], tb->rkey[0]);
173 if (op_is_left_mergeable(key, Sh->b_size)
174 && (vn->vn_mode != M_DELETE
175 || vn->vn_affected_item_num != B_NR_ITEMS(Sh) - 1))
176 vn->vn_vi[vn->vn_nr_item - 1].vi_type |=
177 VI_TYPE_RIGHT_MERGEABLE;
178
179#ifdef CONFIG_REISERFS_CHECK
180 if (op_is_left_mergeable(key, Sh->b_size) &&
181 !(vn->vn_mode != M_DELETE
182 || vn->vn_affected_item_num != B_NR_ITEMS(Sh) - 1)) {
183 /* we delete last item and it could be merged with right neighbor's first item */
184 if (!
185 (B_NR_ITEMS(Sh) == 1
186 && is_direntry_le_ih(B_N_PITEM_HEAD(Sh, 0))
187 && I_ENTRY_COUNT(B_N_PITEM_HEAD(Sh, 0)) == 1)) {
188 /* node contains more than 1 item, or item is not directory item, or this item contains more than 1 entry */
189 print_block(Sh, 0, -1, -1);
190 reiserfs_panic(tb->tb_sb,
191 "vs-8045: create_virtual_node: rdkey %k, affected item==%d (mode==%c) Must be %c",
192 key, vn->vn_affected_item_num,
193 vn->vn_mode, M_DELETE);
194 } else
195 /* we can delete directory item, that has only one directory entry in it */
196 ;
197 }
187#endif 198#endif
188
189 }
190}
191 199
200 }
201}
192 202
193/* using virtual node check, how many items can be shifted to left 203/* using virtual node check, how many items can be shifted to left
194 neighbor */ 204 neighbor */
195static void check_left (struct tree_balance * tb, int h, int cur_free) 205static void check_left(struct tree_balance *tb, int h, int cur_free)
196{ 206{
197 int i; 207 int i;
198 struct virtual_node * vn = tb->tb_vn; 208 struct virtual_node *vn = tb->tb_vn;
199 struct virtual_item * vi; 209 struct virtual_item *vi;
200 int d_size, ih_size; 210 int d_size, ih_size;
201 211
202 RFALSE( cur_free < 0, "vs-8050: cur_free (%d) < 0", cur_free); 212 RFALSE(cur_free < 0, "vs-8050: cur_free (%d) < 0", cur_free);
203 213
204 /* internal level */ 214 /* internal level */
205 if (h > 0) { 215 if (h > 0) {
206 tb->lnum[h] = cur_free / (DC_SIZE + KEY_SIZE); 216 tb->lnum[h] = cur_free / (DC_SIZE + KEY_SIZE);
207 return; 217 return;
208 } 218 }
209 219
210 /* leaf level */ 220 /* leaf level */
211 221
212 if (!cur_free || !vn->vn_nr_item) { 222 if (!cur_free || !vn->vn_nr_item) {
213 /* no free space or nothing to move */ 223 /* no free space or nothing to move */
214 tb->lnum[h] = 0; 224 tb->lnum[h] = 0;
215 tb->lbytes = -1; 225 tb->lbytes = -1;
216 return; 226 return;
217 } 227 }
218 228
219 RFALSE( !PATH_H_PPARENT (tb->tb_path, 0), 229 RFALSE(!PATH_H_PPARENT(tb->tb_path, 0),
220 "vs-8055: parent does not exist or invalid"); 230 "vs-8055: parent does not exist or invalid");
221 231
222 vi = vn->vn_vi; 232 vi = vn->vn_vi;
223 if ((unsigned int)cur_free >= (vn->vn_size - ((vi->vi_type & VI_TYPE_LEFT_MERGEABLE) ? IH_SIZE : 0))) { 233 if ((unsigned int)cur_free >=
224 /* all contents of S[0] fits into L[0] */ 234 (vn->vn_size -
235 ((vi->vi_type & VI_TYPE_LEFT_MERGEABLE) ? IH_SIZE : 0))) {
236 /* all contents of S[0] fits into L[0] */
225 237
226 RFALSE( vn->vn_mode == M_INSERT || vn->vn_mode == M_PASTE, 238 RFALSE(vn->vn_mode == M_INSERT || vn->vn_mode == M_PASTE,
227 "vs-8055: invalid mode or balance condition failed"); 239 "vs-8055: invalid mode or balance condition failed");
228 240
229 tb->lnum[0] = vn->vn_nr_item; 241 tb->lnum[0] = vn->vn_nr_item;
230 tb->lbytes = -1; 242 tb->lbytes = -1;
231 return; 243 return;
232 }
233
234
235 d_size = 0, ih_size = IH_SIZE;
236
237 /* first item may be merge with last item in left neighbor */
238 if (vi->vi_type & VI_TYPE_LEFT_MERGEABLE)
239 d_size = -((int)IH_SIZE), ih_size = 0;
240
241 tb->lnum[0] = 0;
242 for (i = 0; i < vn->vn_nr_item; i ++, ih_size = IH_SIZE, d_size = 0, vi ++) {
243 d_size += vi->vi_item_len;
244 if (cur_free >= d_size) {
245 /* the item can be shifted entirely */
246 cur_free -= d_size;
247 tb->lnum[0] ++;
248 continue;
249 } 244 }
250 245
251 /* the item cannot be shifted entirely, try to split it */ 246 d_size = 0, ih_size = IH_SIZE;
252 /* check whether L[0] can hold ih and at least one byte of the item body */ 247
253 if (cur_free <= ih_size) { 248 /* first item may be merge with last item in left neighbor */
254 /* cannot shift even a part of the current item */ 249 if (vi->vi_type & VI_TYPE_LEFT_MERGEABLE)
255 tb->lbytes = -1; 250 d_size = -((int)IH_SIZE), ih_size = 0;
256 return; 251
252 tb->lnum[0] = 0;
253 for (i = 0; i < vn->vn_nr_item;
254 i++, ih_size = IH_SIZE, d_size = 0, vi++) {
255 d_size += vi->vi_item_len;
256 if (cur_free >= d_size) {
257 /* the item can be shifted entirely */
258 cur_free -= d_size;
259 tb->lnum[0]++;
260 continue;
261 }
262
263 /* the item cannot be shifted entirely, try to split it */
264 /* check whether L[0] can hold ih and at least one byte of the item body */
265 if (cur_free <= ih_size) {
266 /* cannot shift even a part of the current item */
267 tb->lbytes = -1;
268 return;
269 }
270 cur_free -= ih_size;
271
272 tb->lbytes = op_check_left(vi, cur_free, 0, 0);
273 if (tb->lbytes != -1)
274 /* count partially shifted item */
275 tb->lnum[0]++;
276
277 break;
257 } 278 }
258 cur_free -= ih_size;
259
260 tb->lbytes = op_check_left (vi, cur_free, 0, 0);
261 if (tb->lbytes != -1)
262 /* count partially shifted item */
263 tb->lnum[0] ++;
264
265 break;
266 }
267
268 return;
269}
270 279
280 return;
281}
271 282
272/* using virtual node check, how many items can be shifted to right 283/* using virtual node check, how many items can be shifted to right
273 neighbor */ 284 neighbor */
274static void check_right (struct tree_balance * tb, int h, int cur_free) 285static void check_right(struct tree_balance *tb, int h, int cur_free)
275{ 286{
276 int i; 287 int i;
277 struct virtual_node * vn = tb->tb_vn; 288 struct virtual_node *vn = tb->tb_vn;
278 struct virtual_item * vi; 289 struct virtual_item *vi;
279 int d_size, ih_size; 290 int d_size, ih_size;
280 291
281 RFALSE( cur_free < 0, "vs-8070: cur_free < 0"); 292 RFALSE(cur_free < 0, "vs-8070: cur_free < 0");
282 293
283 /* internal level */ 294 /* internal level */
284 if (h > 0) { 295 if (h > 0) {
285 tb->rnum[h] = cur_free / (DC_SIZE + KEY_SIZE); 296 tb->rnum[h] = cur_free / (DC_SIZE + KEY_SIZE);
286 return; 297 return;
287 }
288
289 /* leaf level */
290
291 if (!cur_free || !vn->vn_nr_item) {
292 /* no free space */
293 tb->rnum[h] = 0;
294 tb->rbytes = -1;
295 return;
296 }
297
298 RFALSE( !PATH_H_PPARENT (tb->tb_path, 0),
299 "vs-8075: parent does not exist or invalid");
300
301 vi = vn->vn_vi + vn->vn_nr_item - 1;
302 if ((unsigned int)cur_free >= (vn->vn_size - ((vi->vi_type & VI_TYPE_RIGHT_MERGEABLE) ? IH_SIZE : 0))) {
303 /* all contents of S[0] fits into R[0] */
304
305 RFALSE( vn->vn_mode == M_INSERT || vn->vn_mode == M_PASTE,
306 "vs-8080: invalid mode or balance condition failed");
307
308 tb->rnum[h] = vn->vn_nr_item;
309 tb->rbytes = -1;
310 return;
311 }
312
313 d_size = 0, ih_size = IH_SIZE;
314
315 /* last item may be merge with first item in right neighbor */
316 if (vi->vi_type & VI_TYPE_RIGHT_MERGEABLE)
317 d_size = -(int)IH_SIZE, ih_size = 0;
318
319 tb->rnum[0] = 0;
320 for (i = vn->vn_nr_item - 1; i >= 0; i --, d_size = 0, ih_size = IH_SIZE, vi --) {
321 d_size += vi->vi_item_len;
322 if (cur_free >= d_size) {
323 /* the item can be shifted entirely */
324 cur_free -= d_size;
325 tb->rnum[0] ++;
326 continue;
327 } 298 }
328 299
329 /* check whether R[0] can hold ih and at least one byte of the item body */ 300 /* leaf level */
330 if ( cur_free <= ih_size ) { /* cannot shift even a part of the current item */ 301
331 tb->rbytes = -1; 302 if (!cur_free || !vn->vn_nr_item) {
332 return; 303 /* no free space */
304 tb->rnum[h] = 0;
305 tb->rbytes = -1;
306 return;
333 } 307 }
334
335 /* R[0] can hold the header of the item and at least one byte of its body */
336 cur_free -= ih_size; /* cur_free is still > 0 */
337
338 tb->rbytes = op_check_right (vi, cur_free);
339 if (tb->rbytes != -1)
340 /* count partially shifted item */
341 tb->rnum[0] ++;
342
343 break;
344 }
345
346 return;
347}
348 308
309 RFALSE(!PATH_H_PPARENT(tb->tb_path, 0),
310 "vs-8075: parent does not exist or invalid");
311
312 vi = vn->vn_vi + vn->vn_nr_item - 1;
313 if ((unsigned int)cur_free >=
314 (vn->vn_size -
315 ((vi->vi_type & VI_TYPE_RIGHT_MERGEABLE) ? IH_SIZE : 0))) {
316 /* all contents of S[0] fits into R[0] */
317
318 RFALSE(vn->vn_mode == M_INSERT || vn->vn_mode == M_PASTE,
319 "vs-8080: invalid mode or balance condition failed");
320
321 tb->rnum[h] = vn->vn_nr_item;
322 tb->rbytes = -1;
323 return;
324 }
325
326 d_size = 0, ih_size = IH_SIZE;
327
328 /* last item may be merge with first item in right neighbor */
329 if (vi->vi_type & VI_TYPE_RIGHT_MERGEABLE)
330 d_size = -(int)IH_SIZE, ih_size = 0;
331
332 tb->rnum[0] = 0;
333 for (i = vn->vn_nr_item - 1; i >= 0;
334 i--, d_size = 0, ih_size = IH_SIZE, vi--) {
335 d_size += vi->vi_item_len;
336 if (cur_free >= d_size) {
337 /* the item can be shifted entirely */
338 cur_free -= d_size;
339 tb->rnum[0]++;
340 continue;
341 }
342
343 /* check whether R[0] can hold ih and at least one byte of the item body */
344 if (cur_free <= ih_size) { /* cannot shift even a part of the current item */
345 tb->rbytes = -1;
346 return;
347 }
348
349 /* R[0] can hold the header of the item and at least one byte of its body */
350 cur_free -= ih_size; /* cur_free is still > 0 */
351
352 tb->rbytes = op_check_right(vi, cur_free);
353 if (tb->rbytes != -1)
354 /* count partially shifted item */
355 tb->rnum[0]++;
356
357 break;
358 }
359
360 return;
361}
349 362
350/* 363/*
351 * from - number of items, which are shifted to left neighbor entirely 364 * from - number of items, which are shifted to left neighbor entirely
352 * to - number of item, which are shifted to right neighbor entirely 365 * to - number of item, which are shifted to right neighbor entirely
353 * from_bytes - number of bytes of boundary item (or directory entries) which are shifted to left neighbor 366 * from_bytes - number of bytes of boundary item (or directory entries) which are shifted to left neighbor
354 * to_bytes - number of bytes of boundary item (or directory entries) which are shifted to right neighbor */ 367 * to_bytes - number of bytes of boundary item (or directory entries) which are shifted to right neighbor */
355static int get_num_ver (int mode, struct tree_balance * tb, int h, 368static int get_num_ver(int mode, struct tree_balance *tb, int h,
356 int from, int from_bytes, 369 int from, int from_bytes,
357 int to, int to_bytes, 370 int to, int to_bytes, short *snum012, int flow)
358 short * snum012, int flow
359 )
360{ 371{
361 int i; 372 int i;
362 int cur_free; 373 int cur_free;
363 // int bytes; 374 // int bytes;
364 int units; 375 int units;
365 struct virtual_node * vn = tb->tb_vn; 376 struct virtual_node *vn = tb->tb_vn;
366 // struct virtual_item * vi; 377 // struct virtual_item * vi;
367 378
368 int total_node_size, max_node_size, current_item_size; 379 int total_node_size, max_node_size, current_item_size;
369 int needed_nodes; 380 int needed_nodes;
370 int start_item, /* position of item we start filling node from */ 381 int start_item, /* position of item we start filling node from */
371 end_item, /* position of item we finish filling node by */ 382 end_item, /* position of item we finish filling node by */
372 start_bytes,/* number of first bytes (entries for directory) of start_item-th item 383 start_bytes, /* number of first bytes (entries for directory) of start_item-th item
373 we do not include into node that is being filled */ 384 we do not include into node that is being filled */
374 end_bytes; /* number of last bytes (entries for directory) of end_item-th item 385 end_bytes; /* number of last bytes (entries for directory) of end_item-th item
375 we do node include into node that is being filled */ 386 we do node include into node that is being filled */
376 int split_item_positions[2]; /* these are positions in virtual item of 387 int split_item_positions[2]; /* these are positions in virtual item of
377 items, that are split between S[0] and 388 items, that are split between S[0] and
378 S1new and S1new and S2new */ 389 S1new and S1new and S2new */
379 390
380 split_item_positions[0] = -1; 391 split_item_positions[0] = -1;
381 split_item_positions[1] = -1; 392 split_item_positions[1] = -1;
382 393
383 /* We only create additional nodes if we are in insert or paste mode 394 /* We only create additional nodes if we are in insert or paste mode
384 or we are in replace mode at the internal level. If h is 0 and 395 or we are in replace mode at the internal level. If h is 0 and
385 the mode is M_REPLACE then in fix_nodes we change the mode to 396 the mode is M_REPLACE then in fix_nodes we change the mode to
386 paste or insert before we get here in the code. */ 397 paste or insert before we get here in the code. */
387 RFALSE( tb->insert_size[h] < 0 || (mode != M_INSERT && mode != M_PASTE), 398 RFALSE(tb->insert_size[h] < 0 || (mode != M_INSERT && mode != M_PASTE),
388 "vs-8100: insert_size < 0 in overflow"); 399 "vs-8100: insert_size < 0 in overflow");
389 400
390 max_node_size = MAX_CHILD_SIZE (PATH_H_PBUFFER (tb->tb_path, h)); 401 max_node_size = MAX_CHILD_SIZE(PATH_H_PBUFFER(tb->tb_path, h));
391 402
392 /* snum012 [0-2] - number of items, that lay 403 /* snum012 [0-2] - number of items, that lay
393 to S[0], first new node and second new node */ 404 to S[0], first new node and second new node */
394 snum012[3] = -1; /* s1bytes */ 405 snum012[3] = -1; /* s1bytes */
395 snum012[4] = -1; /* s2bytes */ 406 snum012[4] = -1; /* s2bytes */
396 407
397 /* internal level */ 408 /* internal level */
398 if (h > 0) { 409 if (h > 0) {
399 i = ((to - from) * (KEY_SIZE + DC_SIZE) + DC_SIZE); 410 i = ((to - from) * (KEY_SIZE + DC_SIZE) + DC_SIZE);
400 if (i == max_node_size) 411 if (i == max_node_size)
401 return 1; 412 return 1;
402 return (i / max_node_size + 1); 413 return (i / max_node_size + 1);
403 }
404
405 /* leaf level */
406 needed_nodes = 1;
407 total_node_size = 0;
408 cur_free = max_node_size;
409
410 // start from 'from'-th item
411 start_item = from;
412 // skip its first 'start_bytes' units
413 start_bytes = ((from_bytes != -1) ? from_bytes : 0);
414
415 // last included item is the 'end_item'-th one
416 end_item = vn->vn_nr_item - to - 1;
417 // do not count last 'end_bytes' units of 'end_item'-th item
418 end_bytes = (to_bytes != -1) ? to_bytes : 0;
419
420 /* go through all item beginning from the start_item-th item and ending by
421 the end_item-th item. Do not count first 'start_bytes' units of
422 'start_item'-th item and last 'end_bytes' of 'end_item'-th item */
423
424 for (i = start_item; i <= end_item; i ++) {
425 struct virtual_item * vi = vn->vn_vi + i;
426 int skip_from_end = ((i == end_item) ? end_bytes : 0);
427
428 RFALSE( needed_nodes > 3, "vs-8105: too many nodes are needed");
429
430 /* get size of current item */
431 current_item_size = vi->vi_item_len;
432
433 /* do not take in calculation head part (from_bytes) of from-th item */
434 current_item_size -= op_part_size (vi, 0/*from start*/, start_bytes);
435
436 /* do not take in calculation tail part of last item */
437 current_item_size -= op_part_size (vi, 1/*from end*/, skip_from_end);
438
439 /* if item fits into current node entierly */
440 if (total_node_size + current_item_size <= max_node_size) {
441 snum012[needed_nodes - 1] ++;
442 total_node_size += current_item_size;
443 start_bytes = 0;
444 continue;
445 } 414 }
446 415
447 if (current_item_size > max_node_size) { 416 /* leaf level */
448 /* virtual item length is longer, than max size of item in 417 needed_nodes = 1;
449 a node. It is impossible for direct item */ 418 total_node_size = 0;
450 RFALSE( is_direct_le_ih (vi->vi_ih), 419 cur_free = max_node_size;
451 "vs-8110: " 420
452 "direct item length is %d. It can not be longer than %d", 421 // start from 'from'-th item
453 current_item_size, max_node_size); 422 start_item = from;
454 /* we will try to split it */ 423 // skip its first 'start_bytes' units
455 flow = 1; 424 start_bytes = ((from_bytes != -1) ? from_bytes : 0);
425
426 // last included item is the 'end_item'-th one
427 end_item = vn->vn_nr_item - to - 1;
428 // do not count last 'end_bytes' units of 'end_item'-th item
429 end_bytes = (to_bytes != -1) ? to_bytes : 0;
430
431 /* go through all item beginning from the start_item-th item and ending by
432 the end_item-th item. Do not count first 'start_bytes' units of
433 'start_item'-th item and last 'end_bytes' of 'end_item'-th item */
434
435 for (i = start_item; i <= end_item; i++) {
436 struct virtual_item *vi = vn->vn_vi + i;
437 int skip_from_end = ((i == end_item) ? end_bytes : 0);
438
439 RFALSE(needed_nodes > 3, "vs-8105: too many nodes are needed");
440
441 /* get size of current item */
442 current_item_size = vi->vi_item_len;
443
444 /* do not take in calculation head part (from_bytes) of from-th item */
445 current_item_size -=
446 op_part_size(vi, 0 /*from start */ , start_bytes);
447
448 /* do not take in calculation tail part of last item */
449 current_item_size -=
450 op_part_size(vi, 1 /*from end */ , skip_from_end);
451
452 /* if item fits into current node entierly */
453 if (total_node_size + current_item_size <= max_node_size) {
454 snum012[needed_nodes - 1]++;
455 total_node_size += current_item_size;
456 start_bytes = 0;
457 continue;
458 }
459
460 if (current_item_size > max_node_size) {
461 /* virtual item length is longer, than max size of item in
462 a node. It is impossible for direct item */
463 RFALSE(is_direct_le_ih(vi->vi_ih),
464 "vs-8110: "
465 "direct item length is %d. It can not be longer than %d",
466 current_item_size, max_node_size);
467 /* we will try to split it */
468 flow = 1;
469 }
470
471 if (!flow) {
472 /* as we do not split items, take new node and continue */
473 needed_nodes++;
474 i--;
475 total_node_size = 0;
476 continue;
477 }
478 // calculate number of item units which fit into node being
479 // filled
480 {
481 int free_space;
482
483 free_space = max_node_size - total_node_size - IH_SIZE;
484 units =
485 op_check_left(vi, free_space, start_bytes,
486 skip_from_end);
487 if (units == -1) {
488 /* nothing fits into current node, take new node and continue */
489 needed_nodes++, i--, total_node_size = 0;
490 continue;
491 }
492 }
493
494 /* something fits into the current node */
495 //if (snum012[3] != -1 || needed_nodes != 1)
496 // reiserfs_panic (tb->tb_sb, "vs-8115: get_num_ver: too many nodes required");
497 //snum012[needed_nodes - 1 + 3] = op_unit_num (vi) - start_bytes - units;
498 start_bytes += units;
499 snum012[needed_nodes - 1 + 3] = units;
500
501 if (needed_nodes > 2)
502 reiserfs_warning(tb->tb_sb, "vs-8111: get_num_ver: "
503 "split_item_position is out of boundary");
504 snum012[needed_nodes - 1]++;
505 split_item_positions[needed_nodes - 1] = i;
506 needed_nodes++;
507 /* continue from the same item with start_bytes != -1 */
508 start_item = i;
509 i--;
510 total_node_size = 0;
456 } 511 }
457 512
458 if (!flow) { 513 // sum012[4] (if it is not -1) contains number of units of which
459 /* as we do not split items, take new node and continue */ 514 // are to be in S1new, snum012[3] - to be in S0. They are supposed
460 needed_nodes ++; i --; total_node_size = 0; 515 // to be S1bytes and S2bytes correspondingly, so recalculate
461 continue; 516 if (snum012[4] > 0) {
517 int split_item_num;
518 int bytes_to_r, bytes_to_l;
519 int bytes_to_S1new;
520
521 split_item_num = split_item_positions[1];
522 bytes_to_l =
523 ((from == split_item_num
524 && from_bytes != -1) ? from_bytes : 0);
525 bytes_to_r =
526 ((end_item == split_item_num
527 && end_bytes != -1) ? end_bytes : 0);
528 bytes_to_S1new =
529 ((split_item_positions[0] ==
530 split_item_positions[1]) ? snum012[3] : 0);
531
532 // s2bytes
533 snum012[4] =
534 op_unit_num(&vn->vn_vi[split_item_num]) - snum012[4] -
535 bytes_to_r - bytes_to_l - bytes_to_S1new;
536
537 if (vn->vn_vi[split_item_num].vi_index != TYPE_DIRENTRY &&
538 vn->vn_vi[split_item_num].vi_index != TYPE_INDIRECT)
539 reiserfs_warning(tb->tb_sb, "vs-8115: get_num_ver: not "
540 "directory or indirect item");
462 } 541 }
463 542
464 // calculate number of item units which fit into node being 543 /* now we know S2bytes, calculate S1bytes */
465 // filled 544 if (snum012[3] > 0) {
466 { 545 int split_item_num;
467 int free_space; 546 int bytes_to_r, bytes_to_l;
468 547 int bytes_to_S2new;
469 free_space = max_node_size - total_node_size - IH_SIZE; 548
470 units = op_check_left (vi, free_space, start_bytes, skip_from_end); 549 split_item_num = split_item_positions[0];
471 if (units == -1) { 550 bytes_to_l =
472 /* nothing fits into current node, take new node and continue */ 551 ((from == split_item_num
473 needed_nodes ++, i--, total_node_size = 0; 552 && from_bytes != -1) ? from_bytes : 0);
474 continue; 553 bytes_to_r =
475 } 554 ((end_item == split_item_num
555 && end_bytes != -1) ? end_bytes : 0);
556 bytes_to_S2new =
557 ((split_item_positions[0] == split_item_positions[1]
558 && snum012[4] != -1) ? snum012[4] : 0);
559
560 // s1bytes
561 snum012[3] =
562 op_unit_num(&vn->vn_vi[split_item_num]) - snum012[3] -
563 bytes_to_r - bytes_to_l - bytes_to_S2new;
476 } 564 }
477 565
478 /* something fits into the current node */ 566 return needed_nodes;
479 //if (snum012[3] != -1 || needed_nodes != 1)
480 // reiserfs_panic (tb->tb_sb, "vs-8115: get_num_ver: too many nodes required");
481 //snum012[needed_nodes - 1 + 3] = op_unit_num (vi) - start_bytes - units;
482 start_bytes += units;
483 snum012[needed_nodes - 1 + 3] = units;
484
485 if (needed_nodes > 2)
486 reiserfs_warning (tb->tb_sb, "vs-8111: get_num_ver: "
487 "split_item_position is out of boundary");
488 snum012[needed_nodes - 1] ++;
489 split_item_positions[needed_nodes - 1] = i;
490 needed_nodes ++;
491 /* continue from the same item with start_bytes != -1 */
492 start_item = i;
493 i --;
494 total_node_size = 0;
495 }
496
497 // sum012[4] (if it is not -1) contains number of units of which
498 // are to be in S1new, snum012[3] - to be in S0. They are supposed
499 // to be S1bytes and S2bytes correspondingly, so recalculate
500 if (snum012[4] > 0) {
501 int split_item_num;
502 int bytes_to_r, bytes_to_l;
503 int bytes_to_S1new;
504
505 split_item_num = split_item_positions[1];
506 bytes_to_l = ((from == split_item_num && from_bytes != -1) ? from_bytes : 0);
507 bytes_to_r = ((end_item == split_item_num && end_bytes != -1) ? end_bytes : 0);
508 bytes_to_S1new = ((split_item_positions[0] == split_item_positions[1]) ? snum012[3] : 0);
509
510 // s2bytes
511 snum012[4] = op_unit_num (&vn->vn_vi[split_item_num]) - snum012[4] - bytes_to_r - bytes_to_l - bytes_to_S1new;
512
513 if (vn->vn_vi[split_item_num].vi_index != TYPE_DIRENTRY &&
514 vn->vn_vi[split_item_num].vi_index != TYPE_INDIRECT)
515 reiserfs_warning (tb->tb_sb, "vs-8115: get_num_ver: not "
516 "directory or indirect item");
517 }
518
519 /* now we know S2bytes, calculate S1bytes */
520 if (snum012[3] > 0) {
521 int split_item_num;
522 int bytes_to_r, bytes_to_l;
523 int bytes_to_S2new;
524
525 split_item_num = split_item_positions[0];
526 bytes_to_l = ((from == split_item_num && from_bytes != -1) ? from_bytes : 0);
527 bytes_to_r = ((end_item == split_item_num && end_bytes != -1) ? end_bytes : 0);
528 bytes_to_S2new = ((split_item_positions[0] == split_item_positions[1] && snum012[4] != -1) ? snum012[4] : 0);
529
530 // s1bytes
531 snum012[3] = op_unit_num (&vn->vn_vi[split_item_num]) - snum012[3] - bytes_to_r - bytes_to_l - bytes_to_S2new;
532 }
533
534 return needed_nodes;
535} 567}
536 568
537
538#ifdef CONFIG_REISERFS_CHECK 569#ifdef CONFIG_REISERFS_CHECK
539extern struct tree_balance * cur_tb; 570extern struct tree_balance *cur_tb;
540#endif 571#endif
541 572
542
543/* Set parameters for balancing. 573/* Set parameters for balancing.
544 * Performs write of results of analysis of balancing into structure tb, 574 * Performs write of results of analysis of balancing into structure tb,
545 * where it will later be used by the functions that actually do the balancing. 575 * where it will later be used by the functions that actually do the balancing.
@@ -557,131 +587,130 @@ extern struct tree_balance * cur_tb;
557 * s1bytes number of bytes which flow to the first new node when S[0] splits (this number is contained in s012 array) 587 * s1bytes number of bytes which flow to the first new node when S[0] splits (this number is contained in s012 array)
558 */ 588 */
559 589
560static void set_parameters (struct tree_balance * tb, int h, int lnum, 590static void set_parameters(struct tree_balance *tb, int h, int lnum,
561 int rnum, int blk_num, short * s012, int lb, int rb) 591 int rnum, int blk_num, short *s012, int lb, int rb)
562{ 592{
563 593
564 tb->lnum[h] = lnum; 594 tb->lnum[h] = lnum;
565 tb->rnum[h] = rnum; 595 tb->rnum[h] = rnum;
566 tb->blknum[h] = blk_num; 596 tb->blknum[h] = blk_num;
567 597
568 if (h == 0) 598 if (h == 0) { /* only for leaf level */
569 { /* only for leaf level */ 599 if (s012 != NULL) {
570 if (s012 != NULL) 600 tb->s0num = *s012++,
571 { 601 tb->s1num = *s012++, tb->s2num = *s012++;
572 tb->s0num = * s012 ++, 602 tb->s1bytes = *s012++;
573 tb->s1num = * s012 ++, 603 tb->s2bytes = *s012;
574 tb->s2num = * s012 ++; 604 }
575 tb->s1bytes = * s012 ++; 605 tb->lbytes = lb;
576 tb->s2bytes = * s012; 606 tb->rbytes = rb;
577 } 607 }
578 tb->lbytes = lb; 608 PROC_INFO_ADD(tb->tb_sb, lnum[h], lnum);
579 tb->rbytes = rb; 609 PROC_INFO_ADD(tb->tb_sb, rnum[h], rnum);
580 }
581 PROC_INFO_ADD( tb -> tb_sb, lnum[ h ], lnum );
582 PROC_INFO_ADD( tb -> tb_sb, rnum[ h ], rnum );
583
584 PROC_INFO_ADD( tb -> tb_sb, lbytes[ h ], lb );
585 PROC_INFO_ADD( tb -> tb_sb, rbytes[ h ], rb );
586}
587
588 610
611 PROC_INFO_ADD(tb->tb_sb, lbytes[h], lb);
612 PROC_INFO_ADD(tb->tb_sb, rbytes[h], rb);
613}
589 614
590/* check, does node disappear if we shift tb->lnum[0] items to left 615/* check, does node disappear if we shift tb->lnum[0] items to left
591 neighbor and tb->rnum[0] to the right one. */ 616 neighbor and tb->rnum[0] to the right one. */
592static int is_leaf_removable (struct tree_balance * tb) 617static int is_leaf_removable(struct tree_balance *tb)
593{ 618{
594 struct virtual_node * vn = tb->tb_vn; 619 struct virtual_node *vn = tb->tb_vn;
595 int to_left, to_right; 620 int to_left, to_right;
596 int size; 621 int size;
597 int remain_items; 622 int remain_items;
598 623
599 /* number of items, that will be shifted to left (right) neighbor 624 /* number of items, that will be shifted to left (right) neighbor
600 entirely */ 625 entirely */
601 to_left = tb->lnum[0] - ((tb->lbytes != -1) ? 1 : 0); 626 to_left = tb->lnum[0] - ((tb->lbytes != -1) ? 1 : 0);
602 to_right = tb->rnum[0] - ((tb->rbytes != -1) ? 1 : 0); 627 to_right = tb->rnum[0] - ((tb->rbytes != -1) ? 1 : 0);
603 remain_items = vn->vn_nr_item; 628 remain_items = vn->vn_nr_item;
604 629
605 /* how many items remain in S[0] after shiftings to neighbors */ 630 /* how many items remain in S[0] after shiftings to neighbors */
606 remain_items -= (to_left + to_right); 631 remain_items -= (to_left + to_right);
607 632
608 if (remain_items < 1) { 633 if (remain_items < 1) {
609 /* all content of node can be shifted to neighbors */ 634 /* all content of node can be shifted to neighbors */
610 set_parameters (tb, 0, to_left, vn->vn_nr_item - to_left, 0, NULL, -1, -1); 635 set_parameters(tb, 0, to_left, vn->vn_nr_item - to_left, 0,
611 return 1; 636 NULL, -1, -1);
612 } 637 return 1;
613 638 }
614 if (remain_items > 1 || tb->lbytes == -1 || tb->rbytes == -1)
615 /* S[0] is not removable */
616 return 0;
617
618 /* check, whether we can divide 1 remaining item between neighbors */
619
620 /* get size of remaining item (in item units) */
621 size = op_unit_num (&(vn->vn_vi[to_left]));
622
623 if (tb->lbytes + tb->rbytes >= size) {
624 set_parameters (tb, 0, to_left + 1, to_right + 1, 0, NULL, tb->lbytes, -1);
625 return 1;
626 }
627
628 return 0;
629}
630 639
640 if (remain_items > 1 || tb->lbytes == -1 || tb->rbytes == -1)
641 /* S[0] is not removable */
642 return 0;
643
644 /* check, whether we can divide 1 remaining item between neighbors */
645
646 /* get size of remaining item (in item units) */
647 size = op_unit_num(&(vn->vn_vi[to_left]));
648
649 if (tb->lbytes + tb->rbytes >= size) {
650 set_parameters(tb, 0, to_left + 1, to_right + 1, 0, NULL,
651 tb->lbytes, -1);
652 return 1;
653 }
654
655 return 0;
656}
631 657
632/* check whether L, S, R can be joined in one node */ 658/* check whether L, S, R can be joined in one node */
633static int are_leaves_removable (struct tree_balance * tb, int lfree, int rfree) 659static int are_leaves_removable(struct tree_balance *tb, int lfree, int rfree)
634{ 660{
635 struct virtual_node * vn = tb->tb_vn; 661 struct virtual_node *vn = tb->tb_vn;
636 int ih_size; 662 int ih_size;
637 struct buffer_head *S0; 663 struct buffer_head *S0;
638 664
639 S0 = PATH_H_PBUFFER (tb->tb_path, 0); 665 S0 = PATH_H_PBUFFER(tb->tb_path, 0);
640 666
641 ih_size = 0; 667 ih_size = 0;
642 if (vn->vn_nr_item) { 668 if (vn->vn_nr_item) {
643 if (vn->vn_vi[0].vi_type & VI_TYPE_LEFT_MERGEABLE) 669 if (vn->vn_vi[0].vi_type & VI_TYPE_LEFT_MERGEABLE)
644 ih_size += IH_SIZE; 670 ih_size += IH_SIZE;
645 671
646 if (vn->vn_vi[vn->vn_nr_item-1].vi_type & VI_TYPE_RIGHT_MERGEABLE) 672 if (vn->vn_vi[vn->vn_nr_item - 1].
647 ih_size += IH_SIZE; 673 vi_type & VI_TYPE_RIGHT_MERGEABLE)
648 } else { 674 ih_size += IH_SIZE;
649 /* there was only one item and it will be deleted */ 675 } else {
650 struct item_head * ih; 676 /* there was only one item and it will be deleted */
651 677 struct item_head *ih;
652 RFALSE( B_NR_ITEMS (S0) != 1, 678
653 "vs-8125: item number must be 1: it is %d", B_NR_ITEMS(S0)); 679 RFALSE(B_NR_ITEMS(S0) != 1,
654 680 "vs-8125: item number must be 1: it is %d",
655 ih = B_N_PITEM_HEAD (S0, 0); 681 B_NR_ITEMS(S0));
656 if (tb->CFR[0] && !comp_short_le_keys (&(ih->ih_key), B_N_PDELIM_KEY (tb->CFR[0], tb->rkey[0]))) 682
657 if (is_direntry_le_ih (ih)) { 683 ih = B_N_PITEM_HEAD(S0, 0);
658 /* Directory must be in correct state here: that is 684 if (tb->CFR[0]
659 somewhere at the left side should exist first directory 685 && !comp_short_le_keys(&(ih->ih_key),
660 item. But the item being deleted can not be that first 686 B_N_PDELIM_KEY(tb->CFR[0],
661 one because its right neighbor is item of the same 687 tb->rkey[0])))
662 directory. (But first item always gets deleted in last 688 if (is_direntry_le_ih(ih)) {
663 turn). So, neighbors of deleted item can be merged, so 689 /* Directory must be in correct state here: that is
664 we can save ih_size */ 690 somewhere at the left side should exist first directory
665 ih_size = IH_SIZE; 691 item. But the item being deleted can not be that first
666 692 one because its right neighbor is item of the same
667 /* we might check that left neighbor exists and is of the 693 directory. (But first item always gets deleted in last
668 same directory */ 694 turn). So, neighbors of deleted item can be merged, so
669 RFALSE(le_ih_k_offset (ih) == DOT_OFFSET, 695 we can save ih_size */
670 "vs-8130: first directory item can not be removed until directory is not empty"); 696 ih_size = IH_SIZE;
671 } 697
672 698 /* we might check that left neighbor exists and is of the
673 } 699 same directory */
674 700 RFALSE(le_ih_k_offset(ih) == DOT_OFFSET,
675 if (MAX_CHILD_SIZE (S0) + vn->vn_size <= rfree + lfree + ih_size) { 701 "vs-8130: first directory item can not be removed until directory is not empty");
676 set_parameters (tb, 0, -1, -1, -1, NULL, -1, -1); 702 }
677 PROC_INFO_INC( tb -> tb_sb, leaves_removable );
678 return 1;
679 }
680 return 0;
681
682}
683 703
704 }
705
706 if (MAX_CHILD_SIZE(S0) + vn->vn_size <= rfree + lfree + ih_size) {
707 set_parameters(tb, 0, -1, -1, -1, NULL, -1, -1);
708 PROC_INFO_INC(tb->tb_sb, leaves_removable);
709 return 1;
710 }
711 return 0;
684 712
713}
685 714
686/* when we do not split item, lnum and rnum are numbers of entire items */ 715/* when we do not split item, lnum and rnum are numbers of entire items */
687#define SET_PAR_SHIFT_LEFT \ 716#define SET_PAR_SHIFT_LEFT \
@@ -704,7 +733,6 @@ else \
704 -1, -1);\ 733 -1, -1);\
705} 734}
706 735
707
708#define SET_PAR_SHIFT_RIGHT \ 736#define SET_PAR_SHIFT_RIGHT \
709if (h)\ 737if (h)\
710{\ 738{\
@@ -724,214 +752,199 @@ else \
724 -1, -1);\ 752 -1, -1);\
725} 753}
726 754
727 755static void free_buffers_in_tb(struct tree_balance *p_s_tb)
728static void free_buffers_in_tb ( 756{
729 struct tree_balance * p_s_tb 757 int n_counter;
730 ) { 758
731 int n_counter; 759 decrement_counters_in_path(p_s_tb->tb_path);
732 760
733 decrement_counters_in_path(p_s_tb->tb_path); 761 for (n_counter = 0; n_counter < MAX_HEIGHT; n_counter++) {
734 762 decrement_bcount(p_s_tb->L[n_counter]);
735 for ( n_counter = 0; n_counter < MAX_HEIGHT; n_counter++ ) { 763 p_s_tb->L[n_counter] = NULL;
736 decrement_bcount(p_s_tb->L[n_counter]); 764 decrement_bcount(p_s_tb->R[n_counter]);
737 p_s_tb->L[n_counter] = NULL; 765 p_s_tb->R[n_counter] = NULL;
738 decrement_bcount(p_s_tb->R[n_counter]); 766 decrement_bcount(p_s_tb->FL[n_counter]);
739 p_s_tb->R[n_counter] = NULL; 767 p_s_tb->FL[n_counter] = NULL;
740 decrement_bcount(p_s_tb->FL[n_counter]); 768 decrement_bcount(p_s_tb->FR[n_counter]);
741 p_s_tb->FL[n_counter] = NULL; 769 p_s_tb->FR[n_counter] = NULL;
742 decrement_bcount(p_s_tb->FR[n_counter]); 770 decrement_bcount(p_s_tb->CFL[n_counter]);
743 p_s_tb->FR[n_counter] = NULL; 771 p_s_tb->CFL[n_counter] = NULL;
744 decrement_bcount(p_s_tb->CFL[n_counter]); 772 decrement_bcount(p_s_tb->CFR[n_counter]);
745 p_s_tb->CFL[n_counter] = NULL; 773 p_s_tb->CFR[n_counter] = NULL;
746 decrement_bcount(p_s_tb->CFR[n_counter]); 774 }
747 p_s_tb->CFR[n_counter] = NULL;
748 }
749} 775}
750 776
751
752/* Get new buffers for storing new nodes that are created while balancing. 777/* Get new buffers for storing new nodes that are created while balancing.
753 * Returns: SCHEDULE_OCCURRED - schedule occurred while the function worked; 778 * Returns: SCHEDULE_OCCURRED - schedule occurred while the function worked;
754 * CARRY_ON - schedule didn't occur while the function worked; 779 * CARRY_ON - schedule didn't occur while the function worked;
755 * NO_DISK_SPACE - no disk space. 780 * NO_DISK_SPACE - no disk space.
756 */ 781 */
757/* The function is NOT SCHEDULE-SAFE! */ 782/* The function is NOT SCHEDULE-SAFE! */
758static int get_empty_nodes( 783static int get_empty_nodes(struct tree_balance *p_s_tb, int n_h)
759 struct tree_balance * p_s_tb, 784{
760 int n_h 785 struct buffer_head *p_s_new_bh,
761 ) { 786 *p_s_Sh = PATH_H_PBUFFER(p_s_tb->tb_path, n_h);
762 struct buffer_head * p_s_new_bh, 787 b_blocknr_t *p_n_blocknr, a_n_blocknrs[MAX_AMOUNT_NEEDED] = { 0, };
763 * p_s_Sh = PATH_H_PBUFFER (p_s_tb->tb_path, n_h); 788 int n_counter, n_number_of_freeblk, n_amount_needed, /* number of needed empty blocks */
764 b_blocknr_t * p_n_blocknr, 789 n_retval = CARRY_ON;
765 a_n_blocknrs[MAX_AMOUNT_NEEDED] = {0, }; 790 struct super_block *p_s_sb = p_s_tb->tb_sb;
766 int n_counter, 791
767 n_number_of_freeblk, 792 /* number_of_freeblk is the number of empty blocks which have been
768 n_amount_needed,/* number of needed empty blocks */ 793 acquired for use by the balancing algorithm minus the number of
769 n_retval = CARRY_ON; 794 empty blocks used in the previous levels of the analysis,
770 struct super_block * p_s_sb = p_s_tb->tb_sb; 795 number_of_freeblk = tb->cur_blknum can be non-zero if a schedule occurs
771 796 after empty blocks are acquired, and the balancing analysis is
772 797 then restarted, amount_needed is the number needed by this level
773 /* number_of_freeblk is the number of empty blocks which have been 798 (n_h) of the balancing analysis.
774 acquired for use by the balancing algorithm minus the number of 799
775 empty blocks used in the previous levels of the analysis, 800 Note that for systems with many processes writing, it would be
776 number_of_freeblk = tb->cur_blknum can be non-zero if a schedule occurs 801 more layout optimal to calculate the total number needed by all
777 after empty blocks are acquired, and the balancing analysis is 802 levels and then to run reiserfs_new_blocks to get all of them at once. */
778 then restarted, amount_needed is the number needed by this level 803
779 (n_h) of the balancing analysis. 804 /* Initiate number_of_freeblk to the amount acquired prior to the restart of
780 805 the analysis or 0 if not restarted, then subtract the amount needed
781 Note that for systems with many processes writing, it would be 806 by all of the levels of the tree below n_h. */
782 more layout optimal to calculate the total number needed by all 807 /* blknum includes S[n_h], so we subtract 1 in this calculation */
783 levels and then to run reiserfs_new_blocks to get all of them at once. */ 808 for (n_counter = 0, n_number_of_freeblk = p_s_tb->cur_blknum;
784 809 n_counter < n_h; n_counter++)
785 /* Initiate number_of_freeblk to the amount acquired prior to the restart of 810 n_number_of_freeblk -=
786 the analysis or 0 if not restarted, then subtract the amount needed 811 (p_s_tb->blknum[n_counter]) ? (p_s_tb->blknum[n_counter] -
787 by all of the levels of the tree below n_h. */ 812 1) : 0;
788 /* blknum includes S[n_h], so we subtract 1 in this calculation */ 813
789 for ( n_counter = 0, n_number_of_freeblk = p_s_tb->cur_blknum; n_counter < n_h; n_counter++ ) 814 /* Allocate missing empty blocks. */
790 n_number_of_freeblk -= ( p_s_tb->blknum[n_counter] ) ? (p_s_tb->blknum[n_counter] - 1) : 0; 815 /* if p_s_Sh == 0 then we are getting a new root */
791 816 n_amount_needed = (p_s_Sh) ? (p_s_tb->blknum[n_h] - 1) : 1;
792 /* Allocate missing empty blocks. */ 817 /* Amount_needed = the amount that we need more than the amount that we have. */
793 /* if p_s_Sh == 0 then we are getting a new root */ 818 if (n_amount_needed > n_number_of_freeblk)
794 n_amount_needed = ( p_s_Sh ) ? (p_s_tb->blknum[n_h] - 1) : 1; 819 n_amount_needed -= n_number_of_freeblk;
795 /* Amount_needed = the amount that we need more than the amount that we have. */ 820 else /* If we have enough already then there is nothing to do. */
796 if ( n_amount_needed > n_number_of_freeblk ) 821 return CARRY_ON;
797 n_amount_needed -= n_number_of_freeblk; 822
798 else /* If we have enough already then there is nothing to do. */ 823 /* No need to check quota - is not allocated for blocks used for formatted nodes */
799 return CARRY_ON; 824 if (reiserfs_new_form_blocknrs(p_s_tb, a_n_blocknrs,
800 825 n_amount_needed) == NO_DISK_SPACE)
801 /* No need to check quota - is not allocated for blocks used for formatted nodes */ 826 return NO_DISK_SPACE;
802 if (reiserfs_new_form_blocknrs (p_s_tb, a_n_blocknrs, 827
803 n_amount_needed) == NO_DISK_SPACE) 828 /* for each blocknumber we just got, get a buffer and stick it on FEB */
804 return NO_DISK_SPACE; 829 for (p_n_blocknr = a_n_blocknrs, n_counter = 0;
805 830 n_counter < n_amount_needed; p_n_blocknr++, n_counter++) {
806 /* for each blocknumber we just got, get a buffer and stick it on FEB */ 831
807 for ( p_n_blocknr = a_n_blocknrs, n_counter = 0; n_counter < n_amount_needed; 832 RFALSE(!*p_n_blocknr,
808 p_n_blocknr++, n_counter++ ) { 833 "PAP-8135: reiserfs_new_blocknrs failed when got new blocks");
809 834
810 RFALSE( ! *p_n_blocknr, 835 p_s_new_bh = sb_getblk(p_s_sb, *p_n_blocknr);
811 "PAP-8135: reiserfs_new_blocknrs failed when got new blocks"); 836 RFALSE(buffer_dirty(p_s_new_bh) ||
812 837 buffer_journaled(p_s_new_bh) ||
813 p_s_new_bh = sb_getblk(p_s_sb, *p_n_blocknr); 838 buffer_journal_dirty(p_s_new_bh),
814 RFALSE (buffer_dirty (p_s_new_bh) || 839 "PAP-8140: journlaled or dirty buffer %b for the new block",
815 buffer_journaled (p_s_new_bh) || 840 p_s_new_bh);
816 buffer_journal_dirty (p_s_new_bh), 841
817 "PAP-8140: journlaled or dirty buffer %b for the new block", 842 /* Put empty buffers into the array. */
818 p_s_new_bh); 843 RFALSE(p_s_tb->FEB[p_s_tb->cur_blknum],
819 844 "PAP-8141: busy slot for new buffer");
820 /* Put empty buffers into the array. */ 845
821 RFALSE (p_s_tb->FEB[p_s_tb->cur_blknum], 846 set_buffer_journal_new(p_s_new_bh);
822 "PAP-8141: busy slot for new buffer"); 847 p_s_tb->FEB[p_s_tb->cur_blknum++] = p_s_new_bh;
823 848 }
824 set_buffer_journal_new (p_s_new_bh); 849
825 p_s_tb->FEB[p_s_tb->cur_blknum++] = p_s_new_bh; 850 if (n_retval == CARRY_ON && FILESYSTEM_CHANGED_TB(p_s_tb))
826 } 851 n_retval = REPEAT_SEARCH;
827
828 if ( n_retval == CARRY_ON && FILESYSTEM_CHANGED_TB (p_s_tb) )
829 n_retval = REPEAT_SEARCH ;
830
831 return n_retval;
832}
833 852
853 return n_retval;
854}
834 855
835/* Get free space of the left neighbor, which is stored in the parent 856/* Get free space of the left neighbor, which is stored in the parent
836 * node of the left neighbor. */ 857 * node of the left neighbor. */
837static int get_lfree (struct tree_balance * tb, int h) 858static int get_lfree(struct tree_balance *tb, int h)
838{ 859{
839 struct buffer_head * l, * f; 860 struct buffer_head *l, *f;
840 int order; 861 int order;
841 862
842 if ((f = PATH_H_PPARENT (tb->tb_path, h)) == 0 || (l = tb->FL[h]) == 0) 863 if ((f = PATH_H_PPARENT(tb->tb_path, h)) == 0 || (l = tb->FL[h]) == 0)
843 return 0; 864 return 0;
844 865
845 if (f == l) 866 if (f == l)
846 order = PATH_H_B_ITEM_ORDER (tb->tb_path, h) - 1; 867 order = PATH_H_B_ITEM_ORDER(tb->tb_path, h) - 1;
847 else { 868 else {
848 order = B_NR_ITEMS (l); 869 order = B_NR_ITEMS(l);
849 f = l; 870 f = l;
850 } 871 }
851 872
852 return (MAX_CHILD_SIZE(f) - dc_size(B_N_CHILD(f,order))); 873 return (MAX_CHILD_SIZE(f) - dc_size(B_N_CHILD(f, order)));
853} 874}
854 875
855
856/* Get free space of the right neighbor, 876/* Get free space of the right neighbor,
857 * which is stored in the parent node of the right neighbor. 877 * which is stored in the parent node of the right neighbor.
858 */ 878 */
859static int get_rfree (struct tree_balance * tb, int h) 879static int get_rfree(struct tree_balance *tb, int h)
860{ 880{
861 struct buffer_head * r, * f; 881 struct buffer_head *r, *f;
862 int order; 882 int order;
863 883
864 if ((f = PATH_H_PPARENT (tb->tb_path, h)) == 0 || (r = tb->FR[h]) == 0) 884 if ((f = PATH_H_PPARENT(tb->tb_path, h)) == 0 || (r = tb->FR[h]) == 0)
865 return 0; 885 return 0;
866 886
867 if (f == r) 887 if (f == r)
868 order = PATH_H_B_ITEM_ORDER (tb->tb_path, h) + 1; 888 order = PATH_H_B_ITEM_ORDER(tb->tb_path, h) + 1;
869 else { 889 else {
870 order = 0; 890 order = 0;
871 f = r; 891 f = r;
872 } 892 }
873 893
874 return (MAX_CHILD_SIZE(f) - dc_size( B_N_CHILD(f,order))); 894 return (MAX_CHILD_SIZE(f) - dc_size(B_N_CHILD(f, order)));
875 895
876} 896}
877 897
878
879/* Check whether left neighbor is in memory. */ 898/* Check whether left neighbor is in memory. */
880static int is_left_neighbor_in_cache( 899static int is_left_neighbor_in_cache(struct tree_balance *p_s_tb, int n_h)
881 struct tree_balance * p_s_tb, 900{
882 int n_h 901 struct buffer_head *p_s_father, *left;
883 ) { 902 struct super_block *p_s_sb = p_s_tb->tb_sb;
884 struct buffer_head * p_s_father, * left; 903 b_blocknr_t n_left_neighbor_blocknr;
885 struct super_block * p_s_sb = p_s_tb->tb_sb; 904 int n_left_neighbor_position;
886 b_blocknr_t n_left_neighbor_blocknr; 905
887 int n_left_neighbor_position; 906 if (!p_s_tb->FL[n_h]) /* Father of the left neighbor does not exist. */
888 907 return 0;
889 if ( ! p_s_tb->FL[n_h] ) /* Father of the left neighbor does not exist. */ 908
890 return 0; 909 /* Calculate father of the node to be balanced. */
891 910 p_s_father = PATH_H_PBUFFER(p_s_tb->tb_path, n_h + 1);
892 /* Calculate father of the node to be balanced. */ 911
893 p_s_father = PATH_H_PBUFFER(p_s_tb->tb_path, n_h + 1); 912 RFALSE(!p_s_father ||
894 913 !B_IS_IN_TREE(p_s_father) ||
895 RFALSE( ! p_s_father || 914 !B_IS_IN_TREE(p_s_tb->FL[n_h]) ||
896 ! B_IS_IN_TREE (p_s_father) || 915 !buffer_uptodate(p_s_father) ||
897 ! B_IS_IN_TREE (p_s_tb->FL[n_h]) || 916 !buffer_uptodate(p_s_tb->FL[n_h]),
898 ! buffer_uptodate (p_s_father) || 917 "vs-8165: F[h] (%b) or FL[h] (%b) is invalid",
899 ! buffer_uptodate (p_s_tb->FL[n_h]), 918 p_s_father, p_s_tb->FL[n_h]);
900 "vs-8165: F[h] (%b) or FL[h] (%b) is invalid", 919
901 p_s_father, p_s_tb->FL[n_h]); 920 /* Get position of the pointer to the left neighbor into the left father. */
902 921 n_left_neighbor_position = (p_s_father == p_s_tb->FL[n_h]) ?
903 922 p_s_tb->lkey[n_h] : B_NR_ITEMS(p_s_tb->FL[n_h]);
904 /* Get position of the pointer to the left neighbor into the left father. */ 923 /* Get left neighbor block number. */
905 n_left_neighbor_position = ( p_s_father == p_s_tb->FL[n_h] ) ? 924 n_left_neighbor_blocknr =
906 p_s_tb->lkey[n_h] : B_NR_ITEMS (p_s_tb->FL[n_h]); 925 B_N_CHILD_NUM(p_s_tb->FL[n_h], n_left_neighbor_position);
907 /* Get left neighbor block number. */ 926 /* Look for the left neighbor in the cache. */
908 n_left_neighbor_blocknr = B_N_CHILD_NUM(p_s_tb->FL[n_h], n_left_neighbor_position); 927 if ((left = sb_find_get_block(p_s_sb, n_left_neighbor_blocknr))) {
909 /* Look for the left neighbor in the cache. */ 928
910 if ( (left = sb_find_get_block(p_s_sb, n_left_neighbor_blocknr)) ) { 929 RFALSE(buffer_uptodate(left) && !B_IS_IN_TREE(left),
911 930 "vs-8170: left neighbor (%b %z) is not in the tree",
912 RFALSE( buffer_uptodate (left) && ! B_IS_IN_TREE(left), 931 left, left);
913 "vs-8170: left neighbor (%b %z) is not in the tree", left, left); 932 put_bh(left);
914 put_bh(left) ; 933 return 1;
915 return 1; 934 }
916 }
917
918 return 0;
919}
920 935
936 return 0;
937}
921 938
922#define LEFT_PARENTS 'l' 939#define LEFT_PARENTS 'l'
923#define RIGHT_PARENTS 'r' 940#define RIGHT_PARENTS 'r'
924 941
925 942static void decrement_key(struct cpu_key *p_s_key)
926static void decrement_key (struct cpu_key * p_s_key)
927{ 943{
928 // call item specific function for this key 944 // call item specific function for this key
929 item_ops[cpu_key_k_type (p_s_key)]->decrement_key (p_s_key); 945 item_ops[cpu_key_k_type(p_s_key)]->decrement_key(p_s_key);
930} 946}
931 947
932
933
934
935/* Calculate far left/right parent of the left/right neighbor of the current node, that 948/* Calculate far left/right parent of the left/right neighbor of the current node, that
936 * is calculate the left/right (FL[h]/FR[h]) neighbor of the parent F[h]. 949 * is calculate the left/right (FL[h]/FR[h]) neighbor of the parent F[h].
937 * Calculate left/right common parent of the current node and L[h]/R[h]. 950 * Calculate left/right common parent of the current node and L[h]/R[h].
@@ -940,111 +953,121 @@ static void decrement_key (struct cpu_key * p_s_key)
940 SCHEDULE_OCCURRED - schedule occurred while the function worked; 953 SCHEDULE_OCCURRED - schedule occurred while the function worked;
941 * CARRY_ON - schedule didn't occur while the function worked; 954 * CARRY_ON - schedule didn't occur while the function worked;
942 */ 955 */
943static int get_far_parent (struct tree_balance * p_s_tb, 956static int get_far_parent(struct tree_balance *p_s_tb,
944 int n_h, 957 int n_h,
945 struct buffer_head ** pp_s_father, 958 struct buffer_head **pp_s_father,
946 struct buffer_head ** pp_s_com_father, 959 struct buffer_head **pp_s_com_father, char c_lr_par)
947 char c_lr_par)
948{ 960{
949 struct buffer_head * p_s_parent; 961 struct buffer_head *p_s_parent;
950 INITIALIZE_PATH (s_path_to_neighbor_father); 962 INITIALIZE_PATH(s_path_to_neighbor_father);
951 struct path * p_s_path = p_s_tb->tb_path; 963 struct path *p_s_path = p_s_tb->tb_path;
952 struct cpu_key s_lr_father_key; 964 struct cpu_key s_lr_father_key;
953 int n_counter, 965 int n_counter,
954 n_position = INT_MAX, 966 n_position = INT_MAX,
955 n_first_last_position = 0, 967 n_first_last_position = 0,
956 n_path_offset = PATH_H_PATH_OFFSET(p_s_path, n_h); 968 n_path_offset = PATH_H_PATH_OFFSET(p_s_path, n_h);
957 969
958 /* Starting from F[n_h] go upwards in the tree, and look for the common 970 /* Starting from F[n_h] go upwards in the tree, and look for the common
959 ancestor of F[n_h], and its neighbor l/r, that should be obtained. */ 971 ancestor of F[n_h], and its neighbor l/r, that should be obtained. */
960 972
961 n_counter = n_path_offset; 973 n_counter = n_path_offset;
962 974
963 RFALSE( n_counter < FIRST_PATH_ELEMENT_OFFSET, 975 RFALSE(n_counter < FIRST_PATH_ELEMENT_OFFSET,
964 "PAP-8180: invalid path length"); 976 "PAP-8180: invalid path length");
965 977
966 978 for (; n_counter > FIRST_PATH_ELEMENT_OFFSET; n_counter--) {
967 for ( ; n_counter > FIRST_PATH_ELEMENT_OFFSET; n_counter-- ) { 979 /* Check whether parent of the current buffer in the path is really parent in the tree. */
968 /* Check whether parent of the current buffer in the path is really parent in the tree. */ 980 if (!B_IS_IN_TREE
969 if ( ! B_IS_IN_TREE(p_s_parent = PATH_OFFSET_PBUFFER(p_s_path, n_counter - 1)) ) 981 (p_s_parent = PATH_OFFSET_PBUFFER(p_s_path, n_counter - 1)))
970 return REPEAT_SEARCH; 982 return REPEAT_SEARCH;
971 /* Check whether position in the parent is correct. */ 983 /* Check whether position in the parent is correct. */
972 if ( (n_position = PATH_OFFSET_POSITION(p_s_path, n_counter - 1)) > B_NR_ITEMS(p_s_parent) ) 984 if ((n_position =
973 return REPEAT_SEARCH; 985 PATH_OFFSET_POSITION(p_s_path,
974 /* Check whether parent at the path really points to the child. */ 986 n_counter - 1)) >
975 if ( B_N_CHILD_NUM(p_s_parent, n_position) != 987 B_NR_ITEMS(p_s_parent))
976 PATH_OFFSET_PBUFFER(p_s_path, n_counter)->b_blocknr ) 988 return REPEAT_SEARCH;
977 return REPEAT_SEARCH; 989 /* Check whether parent at the path really points to the child. */
978 /* Return delimiting key if position in the parent is not equal to first/last one. */ 990 if (B_N_CHILD_NUM(p_s_parent, n_position) !=
979 if ( c_lr_par == RIGHT_PARENTS ) 991 PATH_OFFSET_PBUFFER(p_s_path, n_counter)->b_blocknr)
980 n_first_last_position = B_NR_ITEMS (p_s_parent); 992 return REPEAT_SEARCH;
981 if ( n_position != n_first_last_position ) { 993 /* Return delimiting key if position in the parent is not equal to first/last one. */
982 *pp_s_com_father = p_s_parent; 994 if (c_lr_par == RIGHT_PARENTS)
983 get_bh(*pp_s_com_father) ; 995 n_first_last_position = B_NR_ITEMS(p_s_parent);
984 /*(*pp_s_com_father = p_s_parent)->b_count++;*/ 996 if (n_position != n_first_last_position) {
985 break; 997 *pp_s_com_father = p_s_parent;
998 get_bh(*pp_s_com_father);
999 /*(*pp_s_com_father = p_s_parent)->b_count++; */
1000 break;
1001 }
986 } 1002 }
987 } 1003
988 1004 /* if we are in the root of the tree, then there is no common father */
989 /* if we are in the root of the tree, then there is no common father */ 1005 if (n_counter == FIRST_PATH_ELEMENT_OFFSET) {
990 if ( n_counter == FIRST_PATH_ELEMENT_OFFSET ) { 1006 /* Check whether first buffer in the path is the root of the tree. */
991 /* Check whether first buffer in the path is the root of the tree. */ 1007 if (PATH_OFFSET_PBUFFER
992 if ( PATH_OFFSET_PBUFFER(p_s_tb->tb_path, FIRST_PATH_ELEMENT_OFFSET)->b_blocknr == 1008 (p_s_tb->tb_path,
993 SB_ROOT_BLOCK (p_s_tb->tb_sb) ) { 1009 FIRST_PATH_ELEMENT_OFFSET)->b_blocknr ==
994 *pp_s_father = *pp_s_com_father = NULL; 1010 SB_ROOT_BLOCK(p_s_tb->tb_sb)) {
995 return CARRY_ON; 1011 *pp_s_father = *pp_s_com_father = NULL;
1012 return CARRY_ON;
1013 }
1014 return REPEAT_SEARCH;
996 } 1015 }
997 return REPEAT_SEARCH;
998 }
999 1016
1000 RFALSE( B_LEVEL (*pp_s_com_father) <= DISK_LEAF_NODE_LEVEL, 1017 RFALSE(B_LEVEL(*pp_s_com_father) <= DISK_LEAF_NODE_LEVEL,
1001 "PAP-8185: (%b %z) level too small", 1018 "PAP-8185: (%b %z) level too small",
1002 *pp_s_com_father, *pp_s_com_father); 1019 *pp_s_com_father, *pp_s_com_father);
1003 1020
1004 /* Check whether the common parent is locked. */ 1021 /* Check whether the common parent is locked. */
1005 1022
1006 if ( buffer_locked (*pp_s_com_father) ) { 1023 if (buffer_locked(*pp_s_com_father)) {
1007 __wait_on_buffer(*pp_s_com_father); 1024 __wait_on_buffer(*pp_s_com_father);
1008 if ( FILESYSTEM_CHANGED_TB (p_s_tb) ) { 1025 if (FILESYSTEM_CHANGED_TB(p_s_tb)) {
1009 decrement_bcount(*pp_s_com_father); 1026 decrement_bcount(*pp_s_com_father);
1010 return REPEAT_SEARCH; 1027 return REPEAT_SEARCH;
1028 }
1011 } 1029 }
1012 }
1013
1014 /* So, we got common parent of the current node and its left/right neighbor.
1015 Now we are geting the parent of the left/right neighbor. */
1016 1030
1017 /* Form key to get parent of the left/right neighbor. */ 1031 /* So, we got common parent of the current node and its left/right neighbor.
1018 le_key2cpu_key (&s_lr_father_key, B_N_PDELIM_KEY(*pp_s_com_father, ( c_lr_par == LEFT_PARENTS ) ? 1032 Now we are geting the parent of the left/right neighbor. */
1019 (p_s_tb->lkey[n_h - 1] = n_position - 1) : (p_s_tb->rkey[n_h - 1] = n_position)));
1020 1033
1034 /* Form key to get parent of the left/right neighbor. */
1035 le_key2cpu_key(&s_lr_father_key,
1036 B_N_PDELIM_KEY(*pp_s_com_father,
1037 (c_lr_par ==
1038 LEFT_PARENTS) ? (p_s_tb->lkey[n_h - 1] =
1039 n_position -
1040 1) : (p_s_tb->rkey[n_h -
1041 1] =
1042 n_position)));
1021 1043
1022 if ( c_lr_par == LEFT_PARENTS ) 1044 if (c_lr_par == LEFT_PARENTS)
1023 decrement_key(&s_lr_father_key); 1045 decrement_key(&s_lr_father_key);
1024 1046
1025 if (search_by_key(p_s_tb->tb_sb, &s_lr_father_key, &s_path_to_neighbor_father, n_h + 1) == IO_ERROR) 1047 if (search_by_key
1026 // path is released 1048 (p_s_tb->tb_sb, &s_lr_father_key, &s_path_to_neighbor_father,
1027 return IO_ERROR; 1049 n_h + 1) == IO_ERROR)
1050 // path is released
1051 return IO_ERROR;
1028 1052
1029 if ( FILESYSTEM_CHANGED_TB (p_s_tb) ) { 1053 if (FILESYSTEM_CHANGED_TB(p_s_tb)) {
1030 decrement_counters_in_path(&s_path_to_neighbor_father); 1054 decrement_counters_in_path(&s_path_to_neighbor_father);
1031 decrement_bcount(*pp_s_com_father); 1055 decrement_bcount(*pp_s_com_father);
1032 return REPEAT_SEARCH; 1056 return REPEAT_SEARCH;
1033 } 1057 }
1034 1058
1035 *pp_s_father = PATH_PLAST_BUFFER(&s_path_to_neighbor_father); 1059 *pp_s_father = PATH_PLAST_BUFFER(&s_path_to_neighbor_father);
1036 1060
1037 RFALSE( B_LEVEL (*pp_s_father) != n_h + 1, 1061 RFALSE(B_LEVEL(*pp_s_father) != n_h + 1,
1038 "PAP-8190: (%b %z) level too small", *pp_s_father, *pp_s_father); 1062 "PAP-8190: (%b %z) level too small", *pp_s_father, *pp_s_father);
1039 RFALSE( s_path_to_neighbor_father.path_length < FIRST_PATH_ELEMENT_OFFSET, 1063 RFALSE(s_path_to_neighbor_father.path_length <
1040 "PAP-8192: path length is too small"); 1064 FIRST_PATH_ELEMENT_OFFSET, "PAP-8192: path length is too small");
1041 1065
1042 s_path_to_neighbor_father.path_length--; 1066 s_path_to_neighbor_father.path_length--;
1043 decrement_counters_in_path(&s_path_to_neighbor_father); 1067 decrement_counters_in_path(&s_path_to_neighbor_father);
1044 return CARRY_ON; 1068 return CARRY_ON;
1045} 1069}
1046 1070
1047
1048/* Get parents of neighbors of node in the path(S[n_path_offset]) and common parents of 1071/* Get parents of neighbors of node in the path(S[n_path_offset]) and common parents of
1049 * S[n_path_offset] and L[n_path_offset]/R[n_path_offset]: F[n_path_offset], FL[n_path_offset], 1072 * S[n_path_offset] and L[n_path_offset]/R[n_path_offset]: F[n_path_offset], FL[n_path_offset],
1050 * FR[n_path_offset], CFL[n_path_offset], CFR[n_path_offset]. 1073 * FR[n_path_offset], CFL[n_path_offset], CFR[n_path_offset].
@@ -1052,122 +1075,127 @@ static int get_far_parent (struct tree_balance * p_s_tb,
1052 * Returns: SCHEDULE_OCCURRED - schedule occurred while the function worked; 1075 * Returns: SCHEDULE_OCCURRED - schedule occurred while the function worked;
1053 * CARRY_ON - schedule didn't occur while the function worked; 1076 * CARRY_ON - schedule didn't occur while the function worked;
1054 */ 1077 */
1055static int get_parents (struct tree_balance * p_s_tb, int n_h) 1078static int get_parents(struct tree_balance *p_s_tb, int n_h)
1056{ 1079{
1057 struct path * p_s_path = p_s_tb->tb_path; 1080 struct path *p_s_path = p_s_tb->tb_path;
1058 int n_position, 1081 int n_position,
1059 n_ret_value, 1082 n_ret_value,
1060 n_path_offset = PATH_H_PATH_OFFSET(p_s_tb->tb_path, n_h); 1083 n_path_offset = PATH_H_PATH_OFFSET(p_s_tb->tb_path, n_h);
1061 struct buffer_head * p_s_curf, 1084 struct buffer_head *p_s_curf, *p_s_curcf;
1062 * p_s_curcf; 1085
1063 1086 /* Current node is the root of the tree or will be root of the tree */
1064 /* Current node is the root of the tree or will be root of the tree */ 1087 if (n_path_offset <= FIRST_PATH_ELEMENT_OFFSET) {
1065 if ( n_path_offset <= FIRST_PATH_ELEMENT_OFFSET ) { 1088 /* The root can not have parents.
1066 /* The root can not have parents. 1089 Release nodes which previously were obtained as parents of the current node neighbors. */
1067 Release nodes which previously were obtained as parents of the current node neighbors. */ 1090 decrement_bcount(p_s_tb->FL[n_h]);
1091 decrement_bcount(p_s_tb->CFL[n_h]);
1092 decrement_bcount(p_s_tb->FR[n_h]);
1093 decrement_bcount(p_s_tb->CFR[n_h]);
1094 p_s_tb->FL[n_h] = p_s_tb->CFL[n_h] = p_s_tb->FR[n_h] =
1095 p_s_tb->CFR[n_h] = NULL;
1096 return CARRY_ON;
1097 }
1098
1099 /* Get parent FL[n_path_offset] of L[n_path_offset]. */
1100 if ((n_position = PATH_OFFSET_POSITION(p_s_path, n_path_offset - 1))) {
1101 /* Current node is not the first child of its parent. */
1102 /*(p_s_curf = p_s_curcf = PATH_OFFSET_PBUFFER(p_s_path, n_path_offset - 1))->b_count += 2; */
1103 p_s_curf = p_s_curcf =
1104 PATH_OFFSET_PBUFFER(p_s_path, n_path_offset - 1);
1105 get_bh(p_s_curf);
1106 get_bh(p_s_curf);
1107 p_s_tb->lkey[n_h] = n_position - 1;
1108 } else {
1109 /* Calculate current parent of L[n_path_offset], which is the left neighbor of the current node.
1110 Calculate current common parent of L[n_path_offset] and the current node. Note that
1111 CFL[n_path_offset] not equal FL[n_path_offset] and CFL[n_path_offset] not equal F[n_path_offset].
1112 Calculate lkey[n_path_offset]. */
1113 if ((n_ret_value = get_far_parent(p_s_tb, n_h + 1, &p_s_curf,
1114 &p_s_curcf,
1115 LEFT_PARENTS)) != CARRY_ON)
1116 return n_ret_value;
1117 }
1118
1068 decrement_bcount(p_s_tb->FL[n_h]); 1119 decrement_bcount(p_s_tb->FL[n_h]);
1120 p_s_tb->FL[n_h] = p_s_curf; /* New initialization of FL[n_h]. */
1069 decrement_bcount(p_s_tb->CFL[n_h]); 1121 decrement_bcount(p_s_tb->CFL[n_h]);
1070 decrement_bcount(p_s_tb->FR[n_h]); 1122 p_s_tb->CFL[n_h] = p_s_curcf; /* New initialization of CFL[n_h]. */
1071 decrement_bcount(p_s_tb->CFR[n_h]); 1123
1072 p_s_tb->FL[n_h] = p_s_tb->CFL[n_h] = p_s_tb->FR[n_h] = p_s_tb->CFR[n_h] = NULL; 1124 RFALSE((p_s_curf && !B_IS_IN_TREE(p_s_curf)) ||
1073 return CARRY_ON; 1125 (p_s_curcf && !B_IS_IN_TREE(p_s_curcf)),
1074 } 1126 "PAP-8195: FL (%b) or CFL (%b) is invalid", p_s_curf, p_s_curcf);
1075
1076 /* Get parent FL[n_path_offset] of L[n_path_offset]. */
1077 if ( (n_position = PATH_OFFSET_POSITION(p_s_path, n_path_offset - 1)) ) {
1078 /* Current node is not the first child of its parent. */
1079 /*(p_s_curf = p_s_curcf = PATH_OFFSET_PBUFFER(p_s_path, n_path_offset - 1))->b_count += 2;*/
1080 p_s_curf = p_s_curcf = PATH_OFFSET_PBUFFER(p_s_path, n_path_offset - 1);
1081 get_bh(p_s_curf) ;
1082 get_bh(p_s_curf) ;
1083 p_s_tb->lkey[n_h] = n_position - 1;
1084 }
1085 else {
1086 /* Calculate current parent of L[n_path_offset], which is the left neighbor of the current node.
1087 Calculate current common parent of L[n_path_offset] and the current node. Note that
1088 CFL[n_path_offset] not equal FL[n_path_offset] and CFL[n_path_offset] not equal F[n_path_offset].
1089 Calculate lkey[n_path_offset]. */
1090 if ( (n_ret_value = get_far_parent(p_s_tb, n_h + 1, &p_s_curf,
1091 &p_s_curcf, LEFT_PARENTS)) != CARRY_ON )
1092 return n_ret_value;
1093 }
1094
1095 decrement_bcount(p_s_tb->FL[n_h]);
1096 p_s_tb->FL[n_h] = p_s_curf; /* New initialization of FL[n_h]. */
1097 decrement_bcount(p_s_tb->CFL[n_h]);
1098 p_s_tb->CFL[n_h] = p_s_curcf; /* New initialization of CFL[n_h]. */
1099
1100 RFALSE( (p_s_curf && !B_IS_IN_TREE (p_s_curf)) ||
1101 (p_s_curcf && !B_IS_IN_TREE (p_s_curcf)),
1102 "PAP-8195: FL (%b) or CFL (%b) is invalid", p_s_curf, p_s_curcf);
1103 1127
1104/* Get parent FR[n_h] of R[n_h]. */ 1128/* Get parent FR[n_h] of R[n_h]. */
1105 1129
1106/* Current node is the last child of F[n_h]. FR[n_h] != F[n_h]. */ 1130/* Current node is the last child of F[n_h]. FR[n_h] != F[n_h]. */
1107 if ( n_position == B_NR_ITEMS (PATH_H_PBUFFER(p_s_path, n_h + 1)) ) { 1131 if (n_position == B_NR_ITEMS(PATH_H_PBUFFER(p_s_path, n_h + 1))) {
1108/* Calculate current parent of R[n_h], which is the right neighbor of F[n_h]. 1132/* Calculate current parent of R[n_h], which is the right neighbor of F[n_h].
1109 Calculate current common parent of R[n_h] and current node. Note that CFR[n_h] 1133 Calculate current common parent of R[n_h] and current node. Note that CFR[n_h]
1110 not equal FR[n_path_offset] and CFR[n_h] not equal F[n_h]. */ 1134 not equal FR[n_path_offset] and CFR[n_h] not equal F[n_h]. */
1111 if ( (n_ret_value = get_far_parent(p_s_tb, n_h + 1, &p_s_curf, &p_s_curcf, RIGHT_PARENTS)) != CARRY_ON ) 1135 if ((n_ret_value =
1112 return n_ret_value; 1136 get_far_parent(p_s_tb, n_h + 1, &p_s_curf, &p_s_curcf,
1113 } 1137 RIGHT_PARENTS)) != CARRY_ON)
1114 else { 1138 return n_ret_value;
1139 } else {
1115/* Current node is not the last child of its parent F[n_h]. */ 1140/* Current node is not the last child of its parent F[n_h]. */
1116 /*(p_s_curf = p_s_curcf = PATH_OFFSET_PBUFFER(p_s_path, n_path_offset - 1))->b_count += 2;*/ 1141 /*(p_s_curf = p_s_curcf = PATH_OFFSET_PBUFFER(p_s_path, n_path_offset - 1))->b_count += 2; */
1117 p_s_curf = p_s_curcf = PATH_OFFSET_PBUFFER(p_s_path, n_path_offset - 1); 1142 p_s_curf = p_s_curcf =
1118 get_bh(p_s_curf) ; 1143 PATH_OFFSET_PBUFFER(p_s_path, n_path_offset - 1);
1119 get_bh(p_s_curf) ; 1144 get_bh(p_s_curf);
1120 p_s_tb->rkey[n_h] = n_position; 1145 get_bh(p_s_curf);
1121 } 1146 p_s_tb->rkey[n_h] = n_position;
1122 1147 }
1123 decrement_bcount(p_s_tb->FR[n_h]);
1124 p_s_tb->FR[n_h] = p_s_curf; /* New initialization of FR[n_path_offset]. */
1125
1126 decrement_bcount(p_s_tb->CFR[n_h]);
1127 p_s_tb->CFR[n_h] = p_s_curcf; /* New initialization of CFR[n_path_offset]. */
1128
1129 RFALSE( (p_s_curf && !B_IS_IN_TREE (p_s_curf)) ||
1130 (p_s_curcf && !B_IS_IN_TREE (p_s_curcf)),
1131 "PAP-8205: FR (%b) or CFR (%b) is invalid", p_s_curf, p_s_curcf);
1132
1133 return CARRY_ON;
1134}
1135 1148
1149 decrement_bcount(p_s_tb->FR[n_h]);
1150 p_s_tb->FR[n_h] = p_s_curf; /* New initialization of FR[n_path_offset]. */
1151
1152 decrement_bcount(p_s_tb->CFR[n_h]);
1153 p_s_tb->CFR[n_h] = p_s_curcf; /* New initialization of CFR[n_path_offset]. */
1154
1155 RFALSE((p_s_curf && !B_IS_IN_TREE(p_s_curf)) ||
1156 (p_s_curcf && !B_IS_IN_TREE(p_s_curcf)),
1157 "PAP-8205: FR (%b) or CFR (%b) is invalid", p_s_curf, p_s_curcf);
1158
1159 return CARRY_ON;
1160}
1136 1161
1137/* it is possible to remove node as result of shiftings to 1162/* it is possible to remove node as result of shiftings to
1138 neighbors even when we insert or paste item. */ 1163 neighbors even when we insert or paste item. */
1139static inline int can_node_be_removed (int mode, int lfree, int sfree, int rfree, struct tree_balance * tb, int h) 1164static inline int can_node_be_removed(int mode, int lfree, int sfree, int rfree,
1165 struct tree_balance *tb, int h)
1140{ 1166{
1141 struct buffer_head * Sh = PATH_H_PBUFFER (tb->tb_path, h); 1167 struct buffer_head *Sh = PATH_H_PBUFFER(tb->tb_path, h);
1142 int levbytes = tb->insert_size[h]; 1168 int levbytes = tb->insert_size[h];
1143 struct item_head * ih; 1169 struct item_head *ih;
1144 struct reiserfs_key * r_key = NULL; 1170 struct reiserfs_key *r_key = NULL;
1145 1171
1146 ih = B_N_PITEM_HEAD (Sh, 0); 1172 ih = B_N_PITEM_HEAD(Sh, 0);
1147 if ( tb->CFR[h] ) 1173 if (tb->CFR[h])
1148 r_key = B_N_PDELIM_KEY(tb->CFR[h],tb->rkey[h]); 1174 r_key = B_N_PDELIM_KEY(tb->CFR[h], tb->rkey[h]);
1149 1175
1150 if ( 1176 if (lfree + rfree + sfree < MAX_CHILD_SIZE(Sh) + levbytes
1151 lfree + rfree + sfree < MAX_CHILD_SIZE(Sh) + levbytes 1177 /* shifting may merge items which might save space */
1152 /* shifting may merge items which might save space */ 1178 -
1153 - (( ! h && op_is_left_mergeable (&(ih->ih_key), Sh->b_size) ) ? IH_SIZE : 0) 1179 ((!h
1154 - (( ! h && r_key && op_is_left_mergeable (r_key, Sh->b_size) ) ? IH_SIZE : 0) 1180 && op_is_left_mergeable(&(ih->ih_key), Sh->b_size)) ? IH_SIZE : 0)
1155 + (( h ) ? KEY_SIZE : 0)) 1181 -
1156 { 1182 ((!h && r_key
1157 /* node can not be removed */ 1183 && op_is_left_mergeable(r_key, Sh->b_size)) ? IH_SIZE : 0)
1158 if (sfree >= levbytes ) { /* new item fits into node S[h] without any shifting */ 1184 + ((h) ? KEY_SIZE : 0)) {
1159 if ( ! h ) 1185 /* node can not be removed */
1160 tb->s0num = B_NR_ITEMS(Sh) + ((mode == M_INSERT ) ? 1 : 0); 1186 if (sfree >= levbytes) { /* new item fits into node S[h] without any shifting */
1161 set_parameters (tb, h, 0, 0, 1, NULL, -1, -1); 1187 if (!h)
1162 return NO_BALANCING_NEEDED; 1188 tb->s0num =
1189 B_NR_ITEMS(Sh) +
1190 ((mode == M_INSERT) ? 1 : 0);
1191 set_parameters(tb, h, 0, 0, 1, NULL, -1, -1);
1192 return NO_BALANCING_NEEDED;
1193 }
1163 } 1194 }
1164 } 1195 PROC_INFO_INC(tb->tb_sb, can_node_be_removed[h]);
1165 PROC_INFO_INC( tb -> tb_sb, can_node_be_removed[ h ] ); 1196 return !NO_BALANCING_NEEDED;
1166 return !NO_BALANCING_NEEDED;
1167} 1197}
1168 1198
1169
1170
1171/* Check whether current node S[h] is balanced when increasing its size by 1199/* Check whether current node S[h] is balanced when increasing its size by
1172 * Inserting or Pasting. 1200 * Inserting or Pasting.
1173 * Calculate parameters for balancing for current level h. 1201 * Calculate parameters for balancing for current level h.
@@ -1182,154 +1210,157 @@ static inline int can_node_be_removed (int mode, int lfree, int sfree, int rfree
1182 * -2 - no disk space. 1210 * -2 - no disk space.
1183 */ 1211 */
1184/* ip means Inserting or Pasting */ 1212/* ip means Inserting or Pasting */
1185static int ip_check_balance (struct tree_balance * tb, int h) 1213static int ip_check_balance(struct tree_balance *tb, int h)
1186{ 1214{
1187 struct virtual_node * vn = tb->tb_vn; 1215 struct virtual_node *vn = tb->tb_vn;
1188 int levbytes, /* Number of bytes that must be inserted into (value 1216 int levbytes, /* Number of bytes that must be inserted into (value
1189 is negative if bytes are deleted) buffer which 1217 is negative if bytes are deleted) buffer which
1190 contains node being balanced. The mnemonic is 1218 contains node being balanced. The mnemonic is
1191 that the attempted change in node space used level 1219 that the attempted change in node space used level
1192 is levbytes bytes. */ 1220 is levbytes bytes. */
1193 n_ret_value; 1221 n_ret_value;
1194 1222
1195 int lfree, sfree, rfree /* free space in L, S and R */; 1223 int lfree, sfree, rfree /* free space in L, S and R */ ;
1196 1224
1197 /* nver is short for number of vertixes, and lnver is the number if 1225 /* nver is short for number of vertixes, and lnver is the number if
1198 we shift to the left, rnver is the number if we shift to the 1226 we shift to the left, rnver is the number if we shift to the
1199 right, and lrnver is the number if we shift in both directions. 1227 right, and lrnver is the number if we shift in both directions.
1200 The goal is to minimize first the number of vertixes, and second, 1228 The goal is to minimize first the number of vertixes, and second,
1201 the number of vertixes whose contents are changed by shifting, 1229 the number of vertixes whose contents are changed by shifting,
1202 and third the number of uncached vertixes whose contents are 1230 and third the number of uncached vertixes whose contents are
1203 changed by shifting and must be read from disk. */ 1231 changed by shifting and must be read from disk. */
1204 int nver, lnver, rnver, lrnver; 1232 int nver, lnver, rnver, lrnver;
1205 1233
1206 /* used at leaf level only, S0 = S[0] is the node being balanced, 1234 /* used at leaf level only, S0 = S[0] is the node being balanced,
1207 sInum [ I = 0,1,2 ] is the number of items that will 1235 sInum [ I = 0,1,2 ] is the number of items that will
1208 remain in node SI after balancing. S1 and S2 are new 1236 remain in node SI after balancing. S1 and S2 are new
1209 nodes that might be created. */ 1237 nodes that might be created. */
1210 1238
1211 /* we perform 8 calls to get_num_ver(). For each call we calculate five parameters. 1239 /* we perform 8 calls to get_num_ver(). For each call we calculate five parameters.
1212 where 4th parameter is s1bytes and 5th - s2bytes 1240 where 4th parameter is s1bytes and 5th - s2bytes
1213 */ 1241 */
1214 short snum012[40] = {0,}; /* s0num, s1num, s2num for 8 cases 1242 short snum012[40] = { 0, }; /* s0num, s1num, s2num for 8 cases
1215 0,1 - do not shift and do not shift but bottle 1243 0,1 - do not shift and do not shift but bottle
1216 2 - shift only whole item to left 1244 2 - shift only whole item to left
1217 3 - shift to left and bottle as much as possible 1245 3 - shift to left and bottle as much as possible
1218 4,5 - shift to right (whole items and as much as possible 1246 4,5 - shift to right (whole items and as much as possible
1219 6,7 - shift to both directions (whole items and as much as possible) 1247 6,7 - shift to both directions (whole items and as much as possible)
1220 */ 1248 */
1221 1249
1222 /* Sh is the node whose balance is currently being checked */ 1250 /* Sh is the node whose balance is currently being checked */
1223 struct buffer_head * Sh; 1251 struct buffer_head *Sh;
1224 1252
1225 Sh = PATH_H_PBUFFER (tb->tb_path, h); 1253 Sh = PATH_H_PBUFFER(tb->tb_path, h);
1226 levbytes = tb->insert_size[h]; 1254 levbytes = tb->insert_size[h];
1227 1255
1228 /* Calculate balance parameters for creating new root. */ 1256 /* Calculate balance parameters for creating new root. */
1229 if ( ! Sh ) { 1257 if (!Sh) {
1230 if ( ! h ) 1258 if (!h)
1231 reiserfs_panic (tb->tb_sb, "vs-8210: ip_check_balance: S[0] can not be 0"); 1259 reiserfs_panic(tb->tb_sb,
1232 switch ( n_ret_value = get_empty_nodes (tb, h) ) { 1260 "vs-8210: ip_check_balance: S[0] can not be 0");
1233 case CARRY_ON: 1261 switch (n_ret_value = get_empty_nodes(tb, h)) {
1234 set_parameters (tb, h, 0, 0, 1, NULL, -1, -1); 1262 case CARRY_ON:
1235 return NO_BALANCING_NEEDED; /* no balancing for higher levels needed */ 1263 set_parameters(tb, h, 0, 0, 1, NULL, -1, -1);
1236 1264 return NO_BALANCING_NEEDED; /* no balancing for higher levels needed */
1237 case NO_DISK_SPACE: 1265
1238 case REPEAT_SEARCH: 1266 case NO_DISK_SPACE:
1239 return n_ret_value; 1267 case REPEAT_SEARCH:
1240 default: 1268 return n_ret_value;
1241 reiserfs_panic(tb->tb_sb, "vs-8215: ip_check_balance: incorrect return value of get_empty_nodes"); 1269 default:
1270 reiserfs_panic(tb->tb_sb,
1271 "vs-8215: ip_check_balance: incorrect return value of get_empty_nodes");
1272 }
1242 } 1273 }
1243 }
1244
1245 if ( (n_ret_value = get_parents (tb, h)) != CARRY_ON ) /* get parents of S[h] neighbors. */
1246 return n_ret_value;
1247
1248 sfree = B_FREE_SPACE (Sh);
1249
1250 /* get free space of neighbors */
1251 rfree = get_rfree (tb, h);
1252 lfree = get_lfree (tb, h);
1253
1254 if (can_node_be_removed (vn->vn_mode, lfree, sfree, rfree, tb, h) == NO_BALANCING_NEEDED)
1255 /* and new item fits into node S[h] without any shifting */
1256 return NO_BALANCING_NEEDED;
1257
1258 create_virtual_node (tb, h);
1259
1260 /*
1261 determine maximal number of items we can shift to the left neighbor (in tb structure)
1262 and the maximal number of bytes that can flow to the left neighbor
1263 from the left most liquid item that cannot be shifted from S[0] entirely (returned value)
1264 */
1265 check_left (tb, h, lfree);
1266
1267 /*
1268 determine maximal number of items we can shift to the right neighbor (in tb structure)
1269 and the maximal number of bytes that can flow to the right neighbor
1270 from the right most liquid item that cannot be shifted from S[0] entirely (returned value)
1271 */
1272 check_right (tb, h, rfree);
1273
1274
1275 /* all contents of internal node S[h] can be moved into its
1276 neighbors, S[h] will be removed after balancing */
1277 if (h && (tb->rnum[h] + tb->lnum[h] >= vn->vn_nr_item + 1)) {
1278 int to_r;
1279
1280 /* Since we are working on internal nodes, and our internal
1281 nodes have fixed size entries, then we can balance by the
1282 number of items rather than the space they consume. In this
1283 routine we set the left node equal to the right node,
1284 allowing a difference of less than or equal to 1 child
1285 pointer. */
1286 to_r = ((MAX_NR_KEY(Sh)<<1)+2-tb->lnum[h]-tb->rnum[h]+vn->vn_nr_item+1)/2 -
1287 (MAX_NR_KEY(Sh) + 1 - tb->rnum[h]);
1288 set_parameters (tb, h, vn->vn_nr_item + 1 - to_r, to_r, 0, NULL, -1, -1);
1289 return CARRY_ON;
1290 }
1291
1292 /* this checks balance condition, that any two neighboring nodes can not fit in one node */
1293 RFALSE( h &&
1294 ( tb->lnum[h] >= vn->vn_nr_item + 1 ||
1295 tb->rnum[h] >= vn->vn_nr_item + 1),
1296 "vs-8220: tree is not balanced on internal level");
1297 RFALSE( ! h && ((tb->lnum[h] >= vn->vn_nr_item && (tb->lbytes == -1)) ||
1298 (tb->rnum[h] >= vn->vn_nr_item && (tb->rbytes == -1)) ),
1299 "vs-8225: tree is not balanced on leaf level");
1300
1301 /* all contents of S[0] can be moved into its neighbors
1302 S[0] will be removed after balancing. */
1303 if (!h && is_leaf_removable (tb))
1304 return CARRY_ON;
1305 1274
1275 if ((n_ret_value = get_parents(tb, h)) != CARRY_ON) /* get parents of S[h] neighbors. */
1276 return n_ret_value;
1306 1277
1307 /* why do we perform this check here rather than earlier?? 1278 sfree = B_FREE_SPACE(Sh);
1308 Answer: we can win 1 node in some cases above. Moreover we 1279
1309 checked it above, when we checked, that S[0] is not removable 1280 /* get free space of neighbors */
1310 in principle */ 1281 rfree = get_rfree(tb, h);
1311 if (sfree >= levbytes) { /* new item fits into node S[h] without any shifting */ 1282 lfree = get_lfree(tb, h);
1312 if ( ! h ) 1283
1313 tb->s0num = vn->vn_nr_item; 1284 if (can_node_be_removed(vn->vn_mode, lfree, sfree, rfree, tb, h) ==
1314 set_parameters (tb, h, 0, 0, 1, NULL, -1, -1); 1285 NO_BALANCING_NEEDED)
1315 return NO_BALANCING_NEEDED; 1286 /* and new item fits into node S[h] without any shifting */
1316 } 1287 return NO_BALANCING_NEEDED;
1317 1288
1289 create_virtual_node(tb, h);
1318 1290
1319 { 1291 /*
1320 int lpar, rpar, nset, lset, rset, lrset; 1292 determine maximal number of items we can shift to the left neighbor (in tb structure)
1321 /* 1293 and the maximal number of bytes that can flow to the left neighbor
1322 * regular overflowing of the node 1294 from the left most liquid item that cannot be shifted from S[0] entirely (returned value)
1323 */ 1295 */
1296 check_left(tb, h, lfree);
1324 1297
1325 /* get_num_ver works in 2 modes (FLOW & NO_FLOW) 1298 /*
1326 lpar, rpar - number of items we can shift to left/right neighbor (including splitting item) 1299 determine maximal number of items we can shift to the right neighbor (in tb structure)
1327 nset, lset, rset, lrset - shows, whether flowing items give better packing 1300 and the maximal number of bytes that can flow to the right neighbor
1328 */ 1301 from the right most liquid item that cannot be shifted from S[0] entirely (returned value)
1302 */
1303 check_right(tb, h, rfree);
1304
1305 /* all contents of internal node S[h] can be moved into its
1306 neighbors, S[h] will be removed after balancing */
1307 if (h && (tb->rnum[h] + tb->lnum[h] >= vn->vn_nr_item + 1)) {
1308 int to_r;
1309
1310 /* Since we are working on internal nodes, and our internal
1311 nodes have fixed size entries, then we can balance by the
1312 number of items rather than the space they consume. In this
1313 routine we set the left node equal to the right node,
1314 allowing a difference of less than or equal to 1 child
1315 pointer. */
1316 to_r =
1317 ((MAX_NR_KEY(Sh) << 1) + 2 - tb->lnum[h] - tb->rnum[h] +
1318 vn->vn_nr_item + 1) / 2 - (MAX_NR_KEY(Sh) + 1 -
1319 tb->rnum[h]);
1320 set_parameters(tb, h, vn->vn_nr_item + 1 - to_r, to_r, 0, NULL,
1321 -1, -1);
1322 return CARRY_ON;
1323 }
1324
1325 /* this checks balance condition, that any two neighboring nodes can not fit in one node */
1326 RFALSE(h &&
1327 (tb->lnum[h] >= vn->vn_nr_item + 1 ||
1328 tb->rnum[h] >= vn->vn_nr_item + 1),
1329 "vs-8220: tree is not balanced on internal level");
1330 RFALSE(!h && ((tb->lnum[h] >= vn->vn_nr_item && (tb->lbytes == -1)) ||
1331 (tb->rnum[h] >= vn->vn_nr_item && (tb->rbytes == -1))),
1332 "vs-8225: tree is not balanced on leaf level");
1333
1334 /* all contents of S[0] can be moved into its neighbors
1335 S[0] will be removed after balancing. */
1336 if (!h && is_leaf_removable(tb))
1337 return CARRY_ON;
1338
1339 /* why do we perform this check here rather than earlier??
1340 Answer: we can win 1 node in some cases above. Moreover we
1341 checked it above, when we checked, that S[0] is not removable
1342 in principle */
1343 if (sfree >= levbytes) { /* new item fits into node S[h] without any shifting */
1344 if (!h)
1345 tb->s0num = vn->vn_nr_item;
1346 set_parameters(tb, h, 0, 0, 1, NULL, -1, -1);
1347 return NO_BALANCING_NEEDED;
1348 }
1349
1350 {
1351 int lpar, rpar, nset, lset, rset, lrset;
1352 /*
1353 * regular overflowing of the node
1354 */
1355
1356 /* get_num_ver works in 2 modes (FLOW & NO_FLOW)
1357 lpar, rpar - number of items we can shift to left/right neighbor (including splitting item)
1358 nset, lset, rset, lrset - shows, whether flowing items give better packing
1359 */
1329#define FLOW 1 1360#define FLOW 1
1330#define NO_FLOW 0 /* do not any splitting */ 1361#define NO_FLOW 0 /* do not any splitting */
1331 1362
1332 /* we choose one the following */ 1363 /* we choose one the following */
1333#define NOTHING_SHIFT_NO_FLOW 0 1364#define NOTHING_SHIFT_NO_FLOW 0
1334#define NOTHING_SHIFT_FLOW 5 1365#define NOTHING_SHIFT_FLOW 5
1335#define LEFT_SHIFT_NO_FLOW 10 1366#define LEFT_SHIFT_NO_FLOW 10
@@ -1339,164 +1370,173 @@ static int ip_check_balance (struct tree_balance * tb, int h)
1339#define LR_SHIFT_NO_FLOW 30 1370#define LR_SHIFT_NO_FLOW 30
1340#define LR_SHIFT_FLOW 35 1371#define LR_SHIFT_FLOW 35
1341 1372
1373 lpar = tb->lnum[h];
1374 rpar = tb->rnum[h];
1375
1376 /* calculate number of blocks S[h] must be split into when
1377 nothing is shifted to the neighbors,
1378 as well as number of items in each part of the split node (s012 numbers),
1379 and number of bytes (s1bytes) of the shared drop which flow to S1 if any */
1380 nset = NOTHING_SHIFT_NO_FLOW;
1381 nver = get_num_ver(vn->vn_mode, tb, h,
1382 0, -1, h ? vn->vn_nr_item : 0, -1,
1383 snum012, NO_FLOW);
1384
1385 if (!h) {
1386 int nver1;
1387
1388 /* note, that in this case we try to bottle between S[0] and S1 (S1 - the first new node) */
1389 nver1 = get_num_ver(vn->vn_mode, tb, h,
1390 0, -1, 0, -1,
1391 snum012 + NOTHING_SHIFT_FLOW, FLOW);
1392 if (nver > nver1)
1393 nset = NOTHING_SHIFT_FLOW, nver = nver1;
1394 }
1342 1395
1343 lpar = tb->lnum[h]; 1396 /* calculate number of blocks S[h] must be split into when
1344 rpar = tb->rnum[h]; 1397 l_shift_num first items and l_shift_bytes of the right most
1345 1398 liquid item to be shifted are shifted to the left neighbor,
1346 1399 as well as number of items in each part of the splitted node (s012 numbers),
1347 /* calculate number of blocks S[h] must be split into when 1400 and number of bytes (s1bytes) of the shared drop which flow to S1 if any
1348 nothing is shifted to the neighbors, 1401 */
1349 as well as number of items in each part of the split node (s012 numbers), 1402 lset = LEFT_SHIFT_NO_FLOW;
1350 and number of bytes (s1bytes) of the shared drop which flow to S1 if any */ 1403 lnver = get_num_ver(vn->vn_mode, tb, h,
1351 nset = NOTHING_SHIFT_NO_FLOW; 1404 lpar - ((h || tb->lbytes == -1) ? 0 : 1),
1352 nver = get_num_ver (vn->vn_mode, tb, h, 1405 -1, h ? vn->vn_nr_item : 0, -1,
1353 0, -1, h?vn->vn_nr_item:0, -1, 1406 snum012 + LEFT_SHIFT_NO_FLOW, NO_FLOW);
1354 snum012, NO_FLOW); 1407 if (!h) {
1355 1408 int lnver1;
1356 if (!h) 1409
1357 { 1410 lnver1 = get_num_ver(vn->vn_mode, tb, h,
1358 int nver1; 1411 lpar -
1359 1412 ((tb->lbytes != -1) ? 1 : 0),
1360 /* note, that in this case we try to bottle between S[0] and S1 (S1 - the first new node) */ 1413 tb->lbytes, 0, -1,
1361 nver1 = get_num_ver (vn->vn_mode, tb, h, 1414 snum012 + LEFT_SHIFT_FLOW, FLOW);
1362 0, -1, 0, -1, 1415 if (lnver > lnver1)
1363 snum012 + NOTHING_SHIFT_FLOW, FLOW); 1416 lset = LEFT_SHIFT_FLOW, lnver = lnver1;
1364 if (nver > nver1) 1417 }
1365 nset = NOTHING_SHIFT_FLOW, nver = nver1;
1366 }
1367
1368
1369 /* calculate number of blocks S[h] must be split into when
1370 l_shift_num first items and l_shift_bytes of the right most
1371 liquid item to be shifted are shifted to the left neighbor,
1372 as well as number of items in each part of the splitted node (s012 numbers),
1373 and number of bytes (s1bytes) of the shared drop which flow to S1 if any
1374 */
1375 lset = LEFT_SHIFT_NO_FLOW;
1376 lnver = get_num_ver (vn->vn_mode, tb, h,
1377 lpar - (( h || tb->lbytes == -1 ) ? 0 : 1), -1, h ? vn->vn_nr_item:0, -1,
1378 snum012 + LEFT_SHIFT_NO_FLOW, NO_FLOW);
1379 if (!h)
1380 {
1381 int lnver1;
1382
1383 lnver1 = get_num_ver (vn->vn_mode, tb, h,
1384 lpar - ((tb->lbytes != -1) ? 1 : 0), tb->lbytes, 0, -1,
1385 snum012 + LEFT_SHIFT_FLOW, FLOW);
1386 if (lnver > lnver1)
1387 lset = LEFT_SHIFT_FLOW, lnver = lnver1;
1388 }
1389
1390
1391 /* calculate number of blocks S[h] must be split into when
1392 r_shift_num first items and r_shift_bytes of the left most
1393 liquid item to be shifted are shifted to the right neighbor,
1394 as well as number of items in each part of the splitted node (s012 numbers),
1395 and number of bytes (s1bytes) of the shared drop which flow to S1 if any
1396 */
1397 rset = RIGHT_SHIFT_NO_FLOW;
1398 rnver = get_num_ver (vn->vn_mode, tb, h,
1399 0, -1, h ? (vn->vn_nr_item-rpar) : (rpar - (( tb->rbytes != -1 ) ? 1 : 0)), -1,
1400 snum012 + RIGHT_SHIFT_NO_FLOW, NO_FLOW);
1401 if (!h)
1402 {
1403 int rnver1;
1404
1405 rnver1 = get_num_ver (vn->vn_mode, tb, h,
1406 0, -1, (rpar - ((tb->rbytes != -1) ? 1 : 0)), tb->rbytes,
1407 snum012 + RIGHT_SHIFT_FLOW, FLOW);
1408
1409 if (rnver > rnver1)
1410 rset = RIGHT_SHIFT_FLOW, rnver = rnver1;
1411 }
1412
1413
1414 /* calculate number of blocks S[h] must be split into when
1415 items are shifted in both directions,
1416 as well as number of items in each part of the splitted node (s012 numbers),
1417 and number of bytes (s1bytes) of the shared drop which flow to S1 if any
1418 */
1419 lrset = LR_SHIFT_NO_FLOW;
1420 lrnver = get_num_ver (vn->vn_mode, tb, h,
1421 lpar - ((h || tb->lbytes == -1) ? 0 : 1), -1, h ? (vn->vn_nr_item-rpar):(rpar - ((tb->rbytes != -1) ? 1 : 0)), -1,
1422 snum012 + LR_SHIFT_NO_FLOW, NO_FLOW);
1423 if (!h)
1424 {
1425 int lrnver1;
1426
1427 lrnver1 = get_num_ver (vn->vn_mode, tb, h,
1428 lpar - ((tb->lbytes != -1) ? 1 : 0), tb->lbytes, (rpar - ((tb->rbytes != -1) ? 1 : 0)), tb->rbytes,
1429 snum012 + LR_SHIFT_FLOW, FLOW);
1430 if (lrnver > lrnver1)
1431 lrset = LR_SHIFT_FLOW, lrnver = lrnver1;
1432 }
1433
1434
1435 1418
1436 /* Our general shifting strategy is: 1419 /* calculate number of blocks S[h] must be split into when
1437 1) to minimized number of new nodes; 1420 r_shift_num first items and r_shift_bytes of the left most
1438 2) to minimized number of neighbors involved in shifting; 1421 liquid item to be shifted are shifted to the right neighbor,
1439 3) to minimized number of disk reads; */ 1422 as well as number of items in each part of the splitted node (s012 numbers),
1423 and number of bytes (s1bytes) of the shared drop which flow to S1 if any
1424 */
1425 rset = RIGHT_SHIFT_NO_FLOW;
1426 rnver = get_num_ver(vn->vn_mode, tb, h,
1427 0, -1,
1428 h ? (vn->vn_nr_item - rpar) : (rpar -
1429 ((tb->
1430 rbytes !=
1431 -1) ? 1 :
1432 0)), -1,
1433 snum012 + RIGHT_SHIFT_NO_FLOW, NO_FLOW);
1434 if (!h) {
1435 int rnver1;
1436
1437 rnver1 = get_num_ver(vn->vn_mode, tb, h,
1438 0, -1,
1439 (rpar -
1440 ((tb->rbytes != -1) ? 1 : 0)),
1441 tb->rbytes,
1442 snum012 + RIGHT_SHIFT_FLOW, FLOW);
1443
1444 if (rnver > rnver1)
1445 rset = RIGHT_SHIFT_FLOW, rnver = rnver1;
1446 }
1440 1447
1441 /* we can win TWO or ONE nodes by shifting in both directions */ 1448 /* calculate number of blocks S[h] must be split into when
1442 if (lrnver < lnver && lrnver < rnver) 1449 items are shifted in both directions,
1443 { 1450 as well as number of items in each part of the splitted node (s012 numbers),
1444 RFALSE( h && 1451 and number of bytes (s1bytes) of the shared drop which flow to S1 if any
1445 (tb->lnum[h] != 1 || 1452 */
1446 tb->rnum[h] != 1 || 1453 lrset = LR_SHIFT_NO_FLOW;
1447 lrnver != 1 || rnver != 2 || lnver != 2 || h != 1), 1454 lrnver = get_num_ver(vn->vn_mode, tb, h,
1448 "vs-8230: bad h"); 1455 lpar - ((h || tb->lbytes == -1) ? 0 : 1),
1449 if (lrset == LR_SHIFT_FLOW) 1456 -1,
1450 set_parameters (tb, h, tb->lnum[h], tb->rnum[h], lrnver, snum012 + lrset, 1457 h ? (vn->vn_nr_item - rpar) : (rpar -
1451 tb->lbytes, tb->rbytes); 1458 ((tb->
1452 else 1459 rbytes !=
1453 set_parameters (tb, h, tb->lnum[h] - ((tb->lbytes == -1) ? 0 : 1), 1460 -1) ? 1 :
1454 tb->rnum[h] - ((tb->rbytes == -1) ? 0 : 1), lrnver, snum012 + lrset, -1, -1); 1461 0)), -1,
1455 1462 snum012 + LR_SHIFT_NO_FLOW, NO_FLOW);
1456 return CARRY_ON; 1463 if (!h) {
1457 } 1464 int lrnver1;
1465
1466 lrnver1 = get_num_ver(vn->vn_mode, tb, h,
1467 lpar -
1468 ((tb->lbytes != -1) ? 1 : 0),
1469 tb->lbytes,
1470 (rpar -
1471 ((tb->rbytes != -1) ? 1 : 0)),
1472 tb->rbytes,
1473 snum012 + LR_SHIFT_FLOW, FLOW);
1474 if (lrnver > lrnver1)
1475 lrset = LR_SHIFT_FLOW, lrnver = lrnver1;
1476 }
1458 1477
1459 /* if shifting doesn't lead to better packing then don't shift */ 1478 /* Our general shifting strategy is:
1460 if (nver == lrnver) 1479 1) to minimized number of new nodes;
1461 { 1480 2) to minimized number of neighbors involved in shifting;
1462 set_parameters (tb, h, 0, 0, nver, snum012 + nset, -1, -1); 1481 3) to minimized number of disk reads; */
1463 return CARRY_ON; 1482
1464 } 1483 /* we can win TWO or ONE nodes by shifting in both directions */
1484 if (lrnver < lnver && lrnver < rnver) {
1485 RFALSE(h &&
1486 (tb->lnum[h] != 1 ||
1487 tb->rnum[h] != 1 ||
1488 lrnver != 1 || rnver != 2 || lnver != 2
1489 || h != 1), "vs-8230: bad h");
1490 if (lrset == LR_SHIFT_FLOW)
1491 set_parameters(tb, h, tb->lnum[h], tb->rnum[h],
1492 lrnver, snum012 + lrset,
1493 tb->lbytes, tb->rbytes);
1494 else
1495 set_parameters(tb, h,
1496 tb->lnum[h] -
1497 ((tb->lbytes == -1) ? 0 : 1),
1498 tb->rnum[h] -
1499 ((tb->rbytes == -1) ? 0 : 1),
1500 lrnver, snum012 + lrset, -1, -1);
1501
1502 return CARRY_ON;
1503 }
1465 1504
1505 /* if shifting doesn't lead to better packing then don't shift */
1506 if (nver == lrnver) {
1507 set_parameters(tb, h, 0, 0, nver, snum012 + nset, -1,
1508 -1);
1509 return CARRY_ON;
1510 }
1466 1511
1467 /* now we know that for better packing shifting in only one 1512 /* now we know that for better packing shifting in only one
1468 direction either to the left or to the right is required */ 1513 direction either to the left or to the right is required */
1469 1514
1470 /* if shifting to the left is better than shifting to the right */ 1515 /* if shifting to the left is better than shifting to the right */
1471 if (lnver < rnver) 1516 if (lnver < rnver) {
1472 { 1517 SET_PAR_SHIFT_LEFT;
1473 SET_PAR_SHIFT_LEFT; 1518 return CARRY_ON;
1474 return CARRY_ON; 1519 }
1475 }
1476 1520
1477 /* if shifting to the right is better than shifting to the left */ 1521 /* if shifting to the right is better than shifting to the left */
1478 if (lnver > rnver) 1522 if (lnver > rnver) {
1479 { 1523 SET_PAR_SHIFT_RIGHT;
1480 SET_PAR_SHIFT_RIGHT; 1524 return CARRY_ON;
1481 return CARRY_ON; 1525 }
1482 }
1483 1526
1527 /* now shifting in either direction gives the same number
1528 of nodes and we can make use of the cached neighbors */
1529 if (is_left_neighbor_in_cache(tb, h)) {
1530 SET_PAR_SHIFT_LEFT;
1531 return CARRY_ON;
1532 }
1484 1533
1485 /* now shifting in either direction gives the same number 1534 /* shift to the right independently on whether the right neighbor in cache or not */
1486 of nodes and we can make use of the cached neighbors */ 1535 SET_PAR_SHIFT_RIGHT;
1487 if (is_left_neighbor_in_cache (tb,h)) 1536 return CARRY_ON;
1488 {
1489 SET_PAR_SHIFT_LEFT;
1490 return CARRY_ON;
1491 } 1537 }
1492
1493 /* shift to the right independently on whether the right neighbor in cache or not */
1494 SET_PAR_SHIFT_RIGHT;
1495 return CARRY_ON;
1496 }
1497} 1538}
1498 1539
1499
1500/* Check whether current node S[h] is balanced when Decreasing its size by 1540/* Check whether current node S[h] is balanced when Decreasing its size by
1501 * Deleting or Cutting for INTERNAL node of S+tree. 1541 * Deleting or Cutting for INTERNAL node of S+tree.
1502 * Calculate parameters for balancing for current level h. 1542 * Calculate parameters for balancing for current level h.
@@ -1513,157 +1553,173 @@ static int ip_check_balance (struct tree_balance * tb, int h)
1513 * Note: Items of internal nodes have fixed size, so the balance condition for 1553 * Note: Items of internal nodes have fixed size, so the balance condition for
1514 * the internal part of S+tree is as for the B-trees. 1554 * the internal part of S+tree is as for the B-trees.
1515 */ 1555 */
1516static int dc_check_balance_internal (struct tree_balance * tb, int h) 1556static int dc_check_balance_internal(struct tree_balance *tb, int h)
1517{ 1557{
1518 struct virtual_node * vn = tb->tb_vn; 1558 struct virtual_node *vn = tb->tb_vn;
1519 1559
1520 /* Sh is the node whose balance is currently being checked, 1560 /* Sh is the node whose balance is currently being checked,
1521 and Fh is its father. */ 1561 and Fh is its father. */
1522 struct buffer_head * Sh, * Fh; 1562 struct buffer_head *Sh, *Fh;
1523 int maxsize, 1563 int maxsize, n_ret_value;
1524 n_ret_value; 1564 int lfree, rfree /* free space in L and R */ ;
1525 int lfree, rfree /* free space in L and R */;
1526 1565
1527 Sh = PATH_H_PBUFFER (tb->tb_path, h); 1566 Sh = PATH_H_PBUFFER(tb->tb_path, h);
1528 Fh = PATH_H_PPARENT (tb->tb_path, h); 1567 Fh = PATH_H_PPARENT(tb->tb_path, h);
1529 1568
1530 maxsize = MAX_CHILD_SIZE(Sh); 1569 maxsize = MAX_CHILD_SIZE(Sh);
1531 1570
1532/* using tb->insert_size[h], which is negative in this case, create_virtual_node calculates: */ 1571/* using tb->insert_size[h], which is negative in this case, create_virtual_node calculates: */
1533/* new_nr_item = number of items node would have if operation is */ 1572/* new_nr_item = number of items node would have if operation is */
1534/* performed without balancing (new_nr_item); */ 1573/* performed without balancing (new_nr_item); */
1535 create_virtual_node (tb, h); 1574 create_virtual_node(tb, h);
1536 1575
1537 if ( ! Fh ) 1576 if (!Fh) { /* S[h] is the root. */
1538 { /* S[h] is the root. */ 1577 if (vn->vn_nr_item > 0) {
1539 if ( vn->vn_nr_item > 0 ) 1578 set_parameters(tb, h, 0, 0, 1, NULL, -1, -1);
1540 { 1579 return NO_BALANCING_NEEDED; /* no balancing for higher levels needed */
1541 set_parameters (tb, h, 0, 0, 1, NULL, -1, -1); 1580 }
1542 return NO_BALANCING_NEEDED; /* no balancing for higher levels needed */ 1581 /* new_nr_item == 0.
1582 * Current root will be deleted resulting in
1583 * decrementing the tree height. */
1584 set_parameters(tb, h, 0, 0, 0, NULL, -1, -1);
1585 return CARRY_ON;
1586 }
1587
1588 if ((n_ret_value = get_parents(tb, h)) != CARRY_ON)
1589 return n_ret_value;
1590
1591 /* get free space of neighbors */
1592 rfree = get_rfree(tb, h);
1593 lfree = get_lfree(tb, h);
1594
1595 /* determine maximal number of items we can fit into neighbors */
1596 check_left(tb, h, lfree);
1597 check_right(tb, h, rfree);
1598
1599 if (vn->vn_nr_item >= MIN_NR_KEY(Sh)) { /* Balance condition for the internal node is valid.
1600 * In this case we balance only if it leads to better packing. */
1601 if (vn->vn_nr_item == MIN_NR_KEY(Sh)) { /* Here we join S[h] with one of its neighbors,
1602 * which is impossible with greater values of new_nr_item. */
1603 if (tb->lnum[h] >= vn->vn_nr_item + 1) {
1604 /* All contents of S[h] can be moved to L[h]. */
1605 int n;
1606 int order_L;
1607
1608 order_L =
1609 ((n =
1610 PATH_H_B_ITEM_ORDER(tb->tb_path,
1611 h)) ==
1612 0) ? B_NR_ITEMS(tb->FL[h]) : n - 1;
1613 n = dc_size(B_N_CHILD(tb->FL[h], order_L)) /
1614 (DC_SIZE + KEY_SIZE);
1615 set_parameters(tb, h, -n - 1, 0, 0, NULL, -1,
1616 -1);
1617 return CARRY_ON;
1618 }
1619
1620 if (tb->rnum[h] >= vn->vn_nr_item + 1) {
1621 /* All contents of S[h] can be moved to R[h]. */
1622 int n;
1623 int order_R;
1624
1625 order_R =
1626 ((n =
1627 PATH_H_B_ITEM_ORDER(tb->tb_path,
1628 h)) ==
1629 B_NR_ITEMS(Fh)) ? 0 : n + 1;
1630 n = dc_size(B_N_CHILD(tb->FR[h], order_R)) /
1631 (DC_SIZE + KEY_SIZE);
1632 set_parameters(tb, h, 0, -n - 1, 0, NULL, -1,
1633 -1);
1634 return CARRY_ON;
1635 }
1636 }
1637
1638 if (tb->rnum[h] + tb->lnum[h] >= vn->vn_nr_item + 1) {
1639 /* All contents of S[h] can be moved to the neighbors (L[h] & R[h]). */
1640 int to_r;
1641
1642 to_r =
1643 ((MAX_NR_KEY(Sh) << 1) + 2 - tb->lnum[h] -
1644 tb->rnum[h] + vn->vn_nr_item + 1) / 2 -
1645 (MAX_NR_KEY(Sh) + 1 - tb->rnum[h]);
1646 set_parameters(tb, h, vn->vn_nr_item + 1 - to_r, to_r,
1647 0, NULL, -1, -1);
1648 return CARRY_ON;
1649 }
1650
1651 /* Balancing does not lead to better packing. */
1652 set_parameters(tb, h, 0, 0, 1, NULL, -1, -1);
1653 return NO_BALANCING_NEEDED;
1543 } 1654 }
1544 /* new_nr_item == 0. 1655
1545 * Current root will be deleted resulting in 1656 /* Current node contain insufficient number of items. Balancing is required. */
1546 * decrementing the tree height. */ 1657 /* Check whether we can merge S[h] with left neighbor. */
1547 set_parameters (tb, h, 0, 0, 0, NULL, -1, -1); 1658 if (tb->lnum[h] >= vn->vn_nr_item + 1)
1548 return CARRY_ON; 1659 if (is_left_neighbor_in_cache(tb, h)
1549 } 1660 || tb->rnum[h] < vn->vn_nr_item + 1 || !tb->FR[h]) {
1550 1661 int n;
1551 if ( (n_ret_value = get_parents(tb,h)) != CARRY_ON ) 1662 int order_L;
1552 return n_ret_value; 1663
1553 1664 order_L =
1554 1665 ((n =
1555 /* get free space of neighbors */ 1666 PATH_H_B_ITEM_ORDER(tb->tb_path,
1556 rfree = get_rfree (tb, h); 1667 h)) ==
1557 lfree = get_lfree (tb, h); 1668 0) ? B_NR_ITEMS(tb->FL[h]) : n - 1;
1558 1669 n = dc_size(B_N_CHILD(tb->FL[h], order_L)) / (DC_SIZE +
1559 /* determine maximal number of items we can fit into neighbors */ 1670 KEY_SIZE);
1560 check_left (tb, h, lfree); 1671 set_parameters(tb, h, -n - 1, 0, 0, NULL, -1, -1);
1561 check_right (tb, h, rfree); 1672 return CARRY_ON;
1562 1673 }
1563 1674
1564 if ( vn->vn_nr_item >= MIN_NR_KEY(Sh) ) 1675 /* Check whether we can merge S[h] with right neighbor. */
1565 { /* Balance condition for the internal node is valid. 1676 if (tb->rnum[h] >= vn->vn_nr_item + 1) {
1566 * In this case we balance only if it leads to better packing. */ 1677 int n;
1567 if ( vn->vn_nr_item == MIN_NR_KEY(Sh) ) 1678 int order_R;
1568 { /* Here we join S[h] with one of its neighbors, 1679
1569 * which is impossible with greater values of new_nr_item. */ 1680 order_R =
1570 if ( tb->lnum[h] >= vn->vn_nr_item + 1 ) 1681 ((n =
1571 { 1682 PATH_H_B_ITEM_ORDER(tb->tb_path,
1572 /* All contents of S[h] can be moved to L[h]. */ 1683 h)) == B_NR_ITEMS(Fh)) ? 0 : (n + 1);
1573 int n; 1684 n = dc_size(B_N_CHILD(tb->FR[h], order_R)) / (DC_SIZE +
1574 int order_L; 1685 KEY_SIZE);
1575 1686 set_parameters(tb, h, 0, -n - 1, 0, NULL, -1, -1);
1576 order_L = ((n=PATH_H_B_ITEM_ORDER(tb->tb_path, h))==0) ? B_NR_ITEMS(tb->FL[h]) : n - 1; 1687 return CARRY_ON;
1577 n = dc_size(B_N_CHILD(tb->FL[h],order_L)) / (DC_SIZE + KEY_SIZE);
1578 set_parameters (tb, h, -n-1, 0, 0, NULL, -1, -1);
1579 return CARRY_ON;
1580 }
1581
1582 if ( tb->rnum[h] >= vn->vn_nr_item + 1 )
1583 {
1584 /* All contents of S[h] can be moved to R[h]. */
1585 int n;
1586 int order_R;
1587
1588 order_R = ((n=PATH_H_B_ITEM_ORDER(tb->tb_path, h))==B_NR_ITEMS(Fh)) ? 0 : n + 1;
1589 n = dc_size(B_N_CHILD(tb->FR[h],order_R)) / (DC_SIZE + KEY_SIZE);
1590 set_parameters (tb, h, 0, -n-1, 0, NULL, -1, -1);
1591 return CARRY_ON;
1592 }
1593 } 1688 }
1594 1689
1595 if (tb->rnum[h] + tb->lnum[h] >= vn->vn_nr_item + 1) 1690 /* All contents of S[h] can be moved to the neighbors (L[h] & R[h]). */
1596 { 1691 if (tb->rnum[h] + tb->lnum[h] >= vn->vn_nr_item + 1) {
1597 /* All contents of S[h] can be moved to the neighbors (L[h] & R[h]). */ 1692 int to_r;
1598 int to_r; 1693
1694 to_r =
1695 ((MAX_NR_KEY(Sh) << 1) + 2 - tb->lnum[h] - tb->rnum[h] +
1696 vn->vn_nr_item + 1) / 2 - (MAX_NR_KEY(Sh) + 1 -
1697 tb->rnum[h]);
1698 set_parameters(tb, h, vn->vn_nr_item + 1 - to_r, to_r, 0, NULL,
1699 -1, -1);
1700 return CARRY_ON;
1701 }
1599 1702
1600 to_r = ((MAX_NR_KEY(Sh)<<1)+2-tb->lnum[h]-tb->rnum[h]+vn->vn_nr_item+1)/2 - 1703 /* For internal nodes try to borrow item from a neighbor */
1601 (MAX_NR_KEY(Sh) + 1 - tb->rnum[h]); 1704 RFALSE(!tb->FL[h] && !tb->FR[h], "vs-8235: trying to borrow for root");
1602 set_parameters (tb, h, vn->vn_nr_item + 1 - to_r, to_r, 0, NULL, -1, -1); 1705
1603 return CARRY_ON; 1706 /* Borrow one or two items from caching neighbor */
1707 if (is_left_neighbor_in_cache(tb, h) || !tb->FR[h]) {
1708 int from_l;
1709
1710 from_l =
1711 (MAX_NR_KEY(Sh) + 1 - tb->lnum[h] + vn->vn_nr_item +
1712 1) / 2 - (vn->vn_nr_item + 1);
1713 set_parameters(tb, h, -from_l, 0, 1, NULL, -1, -1);
1714 return CARRY_ON;
1604 } 1715 }
1605 1716
1606 /* Balancing does not lead to better packing. */ 1717 set_parameters(tb, h, 0,
1607 set_parameters (tb, h, 0, 0, 1, NULL, -1, -1); 1718 -((MAX_NR_KEY(Sh) + 1 - tb->rnum[h] + vn->vn_nr_item +
1608 return NO_BALANCING_NEEDED; 1719 1) / 2 - (vn->vn_nr_item + 1)), 1, NULL, -1, -1);
1609 }
1610
1611 /* Current node contain insufficient number of items. Balancing is required. */
1612 /* Check whether we can merge S[h] with left neighbor. */
1613 if (tb->lnum[h] >= vn->vn_nr_item + 1)
1614 if (is_left_neighbor_in_cache (tb,h) || tb->rnum[h] < vn->vn_nr_item + 1 || !tb->FR[h])
1615 {
1616 int n;
1617 int order_L;
1618
1619 order_L = ((n=PATH_H_B_ITEM_ORDER(tb->tb_path, h))==0) ? B_NR_ITEMS(tb->FL[h]) : n - 1;
1620 n = dc_size(B_N_CHILD(tb->FL[h],order_L)) / (DC_SIZE + KEY_SIZE);
1621 set_parameters (tb, h, -n-1, 0, 0, NULL, -1, -1);
1622 return CARRY_ON; 1720 return CARRY_ON;
1623 }
1624
1625 /* Check whether we can merge S[h] with right neighbor. */
1626 if (tb->rnum[h] >= vn->vn_nr_item + 1)
1627 {
1628 int n;
1629 int order_R;
1630
1631 order_R = ((n=PATH_H_B_ITEM_ORDER(tb->tb_path, h))==B_NR_ITEMS(Fh)) ? 0 : (n + 1);
1632 n = dc_size(B_N_CHILD(tb->FR[h],order_R)) / (DC_SIZE + KEY_SIZE);
1633 set_parameters (tb, h, 0, -n-1, 0, NULL, -1, -1);
1634 return CARRY_ON;
1635 }
1636
1637 /* All contents of S[h] can be moved to the neighbors (L[h] & R[h]). */
1638 if (tb->rnum[h] + tb->lnum[h] >= vn->vn_nr_item + 1)
1639 {
1640 int to_r;
1641
1642 to_r = ((MAX_NR_KEY(Sh)<<1)+2-tb->lnum[h]-tb->rnum[h]+vn->vn_nr_item+1)/2 -
1643 (MAX_NR_KEY(Sh) + 1 - tb->rnum[h]);
1644 set_parameters (tb, h, vn->vn_nr_item + 1 - to_r, to_r, 0, NULL, -1, -1);
1645 return CARRY_ON;
1646 }
1647
1648 /* For internal nodes try to borrow item from a neighbor */
1649 RFALSE( !tb->FL[h] && !tb->FR[h], "vs-8235: trying to borrow for root");
1650
1651 /* Borrow one or two items from caching neighbor */
1652 if (is_left_neighbor_in_cache (tb,h) || !tb->FR[h])
1653 {
1654 int from_l;
1655
1656 from_l = (MAX_NR_KEY(Sh) + 1 - tb->lnum[h] + vn->vn_nr_item + 1) / 2 - (vn->vn_nr_item + 1);
1657 set_parameters (tb, h, -from_l, 0, 1, NULL, -1, -1);
1658 return CARRY_ON;
1659 }
1660
1661 set_parameters (tb, h, 0, -((MAX_NR_KEY(Sh)+1-tb->rnum[h]+vn->vn_nr_item+1)/2-(vn->vn_nr_item+1)), 1,
1662 NULL, -1, -1);
1663 return CARRY_ON;
1664} 1721}
1665 1722
1666
1667/* Check whether current node S[h] is balanced when Decreasing its size by 1723/* Check whether current node S[h] is balanced when Decreasing its size by
1668 * Deleting or Truncating for LEAF node of S+tree. 1724 * Deleting or Truncating for LEAF node of S+tree.
1669 * Calculate parameters for balancing for current level h. 1725 * Calculate parameters for balancing for current level h.
@@ -1677,90 +1733,86 @@ static int dc_check_balance_internal (struct tree_balance * tb, int h)
1677 * -1 - no balancing for higher levels needed; 1733 * -1 - no balancing for higher levels needed;
1678 * -2 - no disk space. 1734 * -2 - no disk space.
1679 */ 1735 */
1680static int dc_check_balance_leaf (struct tree_balance * tb, int h) 1736static int dc_check_balance_leaf(struct tree_balance *tb, int h)
1681{ 1737{
1682 struct virtual_node * vn = tb->tb_vn; 1738 struct virtual_node *vn = tb->tb_vn;
1683 1739
1684 /* Number of bytes that must be deleted from 1740 /* Number of bytes that must be deleted from
1685 (value is negative if bytes are deleted) buffer which 1741 (value is negative if bytes are deleted) buffer which
1686 contains node being balanced. The mnemonic is that the 1742 contains node being balanced. The mnemonic is that the
1687 attempted change in node space used level is levbytes bytes. */ 1743 attempted change in node space used level is levbytes bytes. */
1688 int levbytes; 1744 int levbytes;
1689 /* the maximal item size */ 1745 /* the maximal item size */
1690 int maxsize, 1746 int maxsize, n_ret_value;
1691 n_ret_value; 1747 /* S0 is the node whose balance is currently being checked,
1692 /* S0 is the node whose balance is currently being checked, 1748 and F0 is its father. */
1693 and F0 is its father. */ 1749 struct buffer_head *S0, *F0;
1694 struct buffer_head * S0, * F0; 1750 int lfree, rfree /* free space in L and R */ ;
1695 int lfree, rfree /* free space in L and R */; 1751
1696 1752 S0 = PATH_H_PBUFFER(tb->tb_path, 0);
1697 S0 = PATH_H_PBUFFER (tb->tb_path, 0); 1753 F0 = PATH_H_PPARENT(tb->tb_path, 0);
1698 F0 = PATH_H_PPARENT (tb->tb_path, 0);
1699
1700 levbytes = tb->insert_size[h];
1701
1702 maxsize = MAX_CHILD_SIZE(S0); /* maximal possible size of an item */
1703
1704 if ( ! F0 )
1705 { /* S[0] is the root now. */
1706
1707 RFALSE( -levbytes >= maxsize - B_FREE_SPACE (S0),
1708 "vs-8240: attempt to create empty buffer tree");
1709
1710 set_parameters (tb, h, 0, 0, 1, NULL, -1, -1);
1711 return NO_BALANCING_NEEDED;
1712 }
1713
1714 if ( (n_ret_value = get_parents(tb,h)) != CARRY_ON )
1715 return n_ret_value;
1716
1717 /* get free space of neighbors */
1718 rfree = get_rfree (tb, h);
1719 lfree = get_lfree (tb, h);
1720
1721 create_virtual_node (tb, h);
1722
1723 /* if 3 leaves can be merge to one, set parameters and return */
1724 if (are_leaves_removable (tb, lfree, rfree))
1725 return CARRY_ON;
1726
1727 /* determine maximal number of items we can shift to the left/right neighbor
1728 and the maximal number of bytes that can flow to the left/right neighbor
1729 from the left/right most liquid item that cannot be shifted from S[0] entirely
1730 */
1731 check_left (tb, h, lfree);
1732 check_right (tb, h, rfree);
1733
1734 /* check whether we can merge S with left neighbor. */
1735 if (tb->lnum[0] >= vn->vn_nr_item && tb->lbytes == -1)
1736 if (is_left_neighbor_in_cache (tb,h) ||
1737 ((tb->rnum[0] - ((tb->rbytes == -1) ? 0 : 1)) < vn->vn_nr_item) || /* S can not be merged with R */
1738 !tb->FR[h]) {
1739
1740 RFALSE( !tb->FL[h], "vs-8245: dc_check_balance_leaf: FL[h] must exist");
1741
1742 /* set parameter to merge S[0] with its left neighbor */
1743 set_parameters (tb, h, -1, 0, 0, NULL, -1, -1);
1744 return CARRY_ON;
1745 }
1746
1747 /* check whether we can merge S[0] with right neighbor. */
1748 if (tb->rnum[0] >= vn->vn_nr_item && tb->rbytes == -1) {
1749 set_parameters (tb, h, 0, -1, 0, NULL, -1, -1);
1750 return CARRY_ON;
1751 }
1752
1753 /* All contents of S[0] can be moved to the neighbors (L[0] & R[0]). Set parameters and return */
1754 if (is_leaf_removable (tb))
1755 return CARRY_ON;
1756
1757 /* Balancing is not required. */
1758 tb->s0num = vn->vn_nr_item;
1759 set_parameters (tb, h, 0, 0, 1, NULL, -1, -1);
1760 return NO_BALANCING_NEEDED;
1761}
1762 1754
1755 levbytes = tb->insert_size[h];
1763 1756
1757 maxsize = MAX_CHILD_SIZE(S0); /* maximal possible size of an item */
1758
1759 if (!F0) { /* S[0] is the root now. */
1760
1761 RFALSE(-levbytes >= maxsize - B_FREE_SPACE(S0),
1762 "vs-8240: attempt to create empty buffer tree");
1763
1764 set_parameters(tb, h, 0, 0, 1, NULL, -1, -1);
1765 return NO_BALANCING_NEEDED;
1766 }
1767
1768 if ((n_ret_value = get_parents(tb, h)) != CARRY_ON)
1769 return n_ret_value;
1770
1771 /* get free space of neighbors */
1772 rfree = get_rfree(tb, h);
1773 lfree = get_lfree(tb, h);
1774
1775 create_virtual_node(tb, h);
1776
1777 /* if 3 leaves can be merge to one, set parameters and return */
1778 if (are_leaves_removable(tb, lfree, rfree))
1779 return CARRY_ON;
1780
1781 /* determine maximal number of items we can shift to the left/right neighbor
1782 and the maximal number of bytes that can flow to the left/right neighbor
1783 from the left/right most liquid item that cannot be shifted from S[0] entirely
1784 */
1785 check_left(tb, h, lfree);
1786 check_right(tb, h, rfree);
1787
1788 /* check whether we can merge S with left neighbor. */
1789 if (tb->lnum[0] >= vn->vn_nr_item && tb->lbytes == -1)
1790 if (is_left_neighbor_in_cache(tb, h) || ((tb->rnum[0] - ((tb->rbytes == -1) ? 0 : 1)) < vn->vn_nr_item) || /* S can not be merged with R */
1791 !tb->FR[h]) {
1792
1793 RFALSE(!tb->FL[h],
1794 "vs-8245: dc_check_balance_leaf: FL[h] must exist");
1795
1796 /* set parameter to merge S[0] with its left neighbor */
1797 set_parameters(tb, h, -1, 0, 0, NULL, -1, -1);
1798 return CARRY_ON;
1799 }
1800
1801 /* check whether we can merge S[0] with right neighbor. */
1802 if (tb->rnum[0] >= vn->vn_nr_item && tb->rbytes == -1) {
1803 set_parameters(tb, h, 0, -1, 0, NULL, -1, -1);
1804 return CARRY_ON;
1805 }
1806
1807 /* All contents of S[0] can be moved to the neighbors (L[0] & R[0]). Set parameters and return */
1808 if (is_leaf_removable(tb))
1809 return CARRY_ON;
1810
1811 /* Balancing is not required. */
1812 tb->s0num = vn->vn_nr_item;
1813 set_parameters(tb, h, 0, 0, 1, NULL, -1, -1);
1814 return NO_BALANCING_NEEDED;
1815}
1764 1816
1765/* Check whether current node S[h] is balanced when Decreasing its size by 1817/* Check whether current node S[h] is balanced when Decreasing its size by
1766 * Deleting or Cutting. 1818 * Deleting or Cutting.
@@ -1775,18 +1827,17 @@ static int dc_check_balance_leaf (struct tree_balance * tb, int h)
1775 * -1 - no balancing for higher levels needed; 1827 * -1 - no balancing for higher levels needed;
1776 * -2 - no disk space. 1828 * -2 - no disk space.
1777 */ 1829 */
1778static int dc_check_balance (struct tree_balance * tb, int h) 1830static int dc_check_balance(struct tree_balance *tb, int h)
1779{ 1831{
1780 RFALSE( ! (PATH_H_PBUFFER (tb->tb_path, h)), "vs-8250: S is not initialized"); 1832 RFALSE(!(PATH_H_PBUFFER(tb->tb_path, h)),
1833 "vs-8250: S is not initialized");
1781 1834
1782 if ( h ) 1835 if (h)
1783 return dc_check_balance_internal (tb, h); 1836 return dc_check_balance_internal(tb, h);
1784 else 1837 else
1785 return dc_check_balance_leaf (tb, h); 1838 return dc_check_balance_leaf(tb, h);
1786} 1839}
1787 1840
1788
1789
1790/* Check whether current node S[h] is balanced. 1841/* Check whether current node S[h] is balanced.
1791 * Calculate parameters for balancing for current level h. 1842 * Calculate parameters for balancing for current level h.
1792 * Parameters: 1843 * Parameters:
@@ -1805,83 +1856,80 @@ static int dc_check_balance (struct tree_balance * tb, int h)
1805 * -1 - no balancing for higher levels needed; 1856 * -1 - no balancing for higher levels needed;
1806 * -2 - no disk space. 1857 * -2 - no disk space.
1807 */ 1858 */
1808static int check_balance (int mode, 1859static int check_balance(int mode,
1809 struct tree_balance * tb, 1860 struct tree_balance *tb,
1810 int h, 1861 int h,
1811 int inum, 1862 int inum,
1812 int pos_in_item, 1863 int pos_in_item,
1813 struct item_head * ins_ih, 1864 struct item_head *ins_ih, const void *data)
1814 const void * data
1815 )
1816{ 1865{
1817 struct virtual_node * vn; 1866 struct virtual_node *vn;
1818 1867
1819 vn = tb->tb_vn = (struct virtual_node *)(tb->vn_buf); 1868 vn = tb->tb_vn = (struct virtual_node *)(tb->vn_buf);
1820 vn->vn_free_ptr = (char *)(tb->tb_vn + 1); 1869 vn->vn_free_ptr = (char *)(tb->tb_vn + 1);
1821 vn->vn_mode = mode; 1870 vn->vn_mode = mode;
1822 vn->vn_affected_item_num = inum; 1871 vn->vn_affected_item_num = inum;
1823 vn->vn_pos_in_item = pos_in_item; 1872 vn->vn_pos_in_item = pos_in_item;
1824 vn->vn_ins_ih = ins_ih; 1873 vn->vn_ins_ih = ins_ih;
1825 vn->vn_data = data; 1874 vn->vn_data = data;
1826 1875
1827 RFALSE( mode == M_INSERT && !vn->vn_ins_ih, 1876 RFALSE(mode == M_INSERT && !vn->vn_ins_ih,
1828 "vs-8255: ins_ih can not be 0 in insert mode"); 1877 "vs-8255: ins_ih can not be 0 in insert mode");
1829 1878
1830 if ( tb->insert_size[h] > 0 ) 1879 if (tb->insert_size[h] > 0)
1831 /* Calculate balance parameters when size of node is increasing. */ 1880 /* Calculate balance parameters when size of node is increasing. */
1832 return ip_check_balance (tb, h); 1881 return ip_check_balance(tb, h);
1833 1882
1834 /* Calculate balance parameters when size of node is decreasing. */ 1883 /* Calculate balance parameters when size of node is decreasing. */
1835 return dc_check_balance (tb, h); 1884 return dc_check_balance(tb, h);
1836} 1885}
1837 1886
1887/* Check whether parent at the path is the really parent of the current node.*/
1888static int get_direct_parent(struct tree_balance *p_s_tb, int n_h)
1889{
1890 struct buffer_head *p_s_bh;
1891 struct path *p_s_path = p_s_tb->tb_path;
1892 int n_position,
1893 n_path_offset = PATH_H_PATH_OFFSET(p_s_tb->tb_path, n_h);
1894
1895 /* We are in the root or in the new root. */
1896 if (n_path_offset <= FIRST_PATH_ELEMENT_OFFSET) {
1897
1898 RFALSE(n_path_offset < FIRST_PATH_ELEMENT_OFFSET - 1,
1899 "PAP-8260: invalid offset in the path");
1900
1901 if (PATH_OFFSET_PBUFFER(p_s_path, FIRST_PATH_ELEMENT_OFFSET)->
1902 b_blocknr == SB_ROOT_BLOCK(p_s_tb->tb_sb)) {
1903 /* Root is not changed. */
1904 PATH_OFFSET_PBUFFER(p_s_path, n_path_offset - 1) = NULL;
1905 PATH_OFFSET_POSITION(p_s_path, n_path_offset - 1) = 0;
1906 return CARRY_ON;
1907 }
1908 return REPEAT_SEARCH; /* Root is changed and we must recalculate the path. */
1909 }
1910
1911 if (!B_IS_IN_TREE
1912 (p_s_bh = PATH_OFFSET_PBUFFER(p_s_path, n_path_offset - 1)))
1913 return REPEAT_SEARCH; /* Parent in the path is not in the tree. */
1838 1914
1915 if ((n_position =
1916 PATH_OFFSET_POSITION(p_s_path,
1917 n_path_offset - 1)) > B_NR_ITEMS(p_s_bh))
1918 return REPEAT_SEARCH;
1839 1919
1840/* Check whether parent at the path is the really parent of the current node.*/ 1920 if (B_N_CHILD_NUM(p_s_bh, n_position) !=
1841static int get_direct_parent( 1921 PATH_OFFSET_PBUFFER(p_s_path, n_path_offset)->b_blocknr)
1842 struct tree_balance * p_s_tb, 1922 /* Parent in the path is not parent of the current node in the tree. */
1843 int n_h 1923 return REPEAT_SEARCH;
1844 ) { 1924
1845 struct buffer_head * p_s_bh; 1925 if (buffer_locked(p_s_bh)) {
1846 struct path * p_s_path = p_s_tb->tb_path; 1926 __wait_on_buffer(p_s_bh);
1847 int n_position, 1927 if (FILESYSTEM_CHANGED_TB(p_s_tb))
1848 n_path_offset = PATH_H_PATH_OFFSET(p_s_tb->tb_path, n_h); 1928 return REPEAT_SEARCH;
1849
1850 /* We are in the root or in the new root. */
1851 if ( n_path_offset <= FIRST_PATH_ELEMENT_OFFSET ) {
1852
1853 RFALSE( n_path_offset < FIRST_PATH_ELEMENT_OFFSET - 1,
1854 "PAP-8260: invalid offset in the path");
1855
1856 if ( PATH_OFFSET_PBUFFER(p_s_path, FIRST_PATH_ELEMENT_OFFSET)->b_blocknr ==
1857 SB_ROOT_BLOCK (p_s_tb->tb_sb) ) {
1858 /* Root is not changed. */
1859 PATH_OFFSET_PBUFFER(p_s_path, n_path_offset - 1) = NULL;
1860 PATH_OFFSET_POSITION(p_s_path, n_path_offset - 1) = 0;
1861 return CARRY_ON;
1862 } 1929 }
1863 return REPEAT_SEARCH; /* Root is changed and we must recalculate the path. */
1864 }
1865
1866 if ( ! B_IS_IN_TREE(p_s_bh = PATH_OFFSET_PBUFFER(p_s_path, n_path_offset - 1)) )
1867 return REPEAT_SEARCH; /* Parent in the path is not in the tree. */
1868
1869 if ( (n_position = PATH_OFFSET_POSITION(p_s_path, n_path_offset - 1)) > B_NR_ITEMS(p_s_bh) )
1870 return REPEAT_SEARCH;
1871
1872 if ( B_N_CHILD_NUM(p_s_bh, n_position) != PATH_OFFSET_PBUFFER(p_s_path, n_path_offset)->b_blocknr )
1873 /* Parent in the path is not parent of the current node in the tree. */
1874 return REPEAT_SEARCH;
1875
1876 if ( buffer_locked(p_s_bh) ) {
1877 __wait_on_buffer(p_s_bh);
1878 if ( FILESYSTEM_CHANGED_TB (p_s_tb) )
1879 return REPEAT_SEARCH;
1880 }
1881
1882 return CARRY_ON; /* Parent in the path is unlocked and really parent of the current node. */
1883}
1884 1930
1931 return CARRY_ON; /* Parent in the path is unlocked and really parent of the current node. */
1932}
1885 1933
1886/* Using lnum[n_h] and rnum[n_h] we should determine what neighbors 1934/* Using lnum[n_h] and rnum[n_h] we should determine what neighbors
1887 * of S[n_h] we 1935 * of S[n_h] we
@@ -1889,356 +1937,401 @@ static int get_direct_parent(
1889 * Returns: SCHEDULE_OCCURRED - schedule occurred while the function worked; 1937 * Returns: SCHEDULE_OCCURRED - schedule occurred while the function worked;
1890 * CARRY_ON - schedule didn't occur while the function worked; 1938 * CARRY_ON - schedule didn't occur while the function worked;
1891 */ 1939 */
1892static int get_neighbors( 1940static int get_neighbors(struct tree_balance *p_s_tb, int n_h)
1893 struct tree_balance * p_s_tb, 1941{
1894 int n_h 1942 int n_child_position,
1895 ) { 1943 n_path_offset = PATH_H_PATH_OFFSET(p_s_tb->tb_path, n_h + 1);
1896 int n_child_position, 1944 unsigned long n_son_number;
1897 n_path_offset = PATH_H_PATH_OFFSET(p_s_tb->tb_path, n_h + 1); 1945 struct super_block *p_s_sb = p_s_tb->tb_sb;
1898 unsigned long n_son_number; 1946 struct buffer_head *p_s_bh;
1899 struct super_block * p_s_sb = p_s_tb->tb_sb; 1947
1900 struct buffer_head * p_s_bh; 1948 PROC_INFO_INC(p_s_sb, get_neighbors[n_h]);
1901 1949
1902 1950 if (p_s_tb->lnum[n_h]) {
1903 PROC_INFO_INC( p_s_sb, get_neighbors[ n_h ] ); 1951 /* We need left neighbor to balance S[n_h]. */
1904 1952 PROC_INFO_INC(p_s_sb, need_l_neighbor[n_h]);
1905 if ( p_s_tb->lnum[n_h] ) { 1953 p_s_bh = PATH_OFFSET_PBUFFER(p_s_tb->tb_path, n_path_offset);
1906 /* We need left neighbor to balance S[n_h]. */ 1954
1907 PROC_INFO_INC( p_s_sb, need_l_neighbor[ n_h ] ); 1955 RFALSE(p_s_bh == p_s_tb->FL[n_h] &&
1908 p_s_bh = PATH_OFFSET_PBUFFER(p_s_tb->tb_path, n_path_offset); 1956 !PATH_OFFSET_POSITION(p_s_tb->tb_path, n_path_offset),
1909 1957 "PAP-8270: invalid position in the parent");
1910 RFALSE( p_s_bh == p_s_tb->FL[n_h] && 1958
1911 ! PATH_OFFSET_POSITION(p_s_tb->tb_path, n_path_offset), 1959 n_child_position =
1912 "PAP-8270: invalid position in the parent"); 1960 (p_s_bh ==
1913 1961 p_s_tb->FL[n_h]) ? p_s_tb->lkey[n_h] : B_NR_ITEMS(p_s_tb->
1914 n_child_position = ( p_s_bh == p_s_tb->FL[n_h] ) ? p_s_tb->lkey[n_h] : B_NR_ITEMS (p_s_tb->FL[n_h]); 1962 FL[n_h]);
1915 n_son_number = B_N_CHILD_NUM(p_s_tb->FL[n_h], n_child_position); 1963 n_son_number = B_N_CHILD_NUM(p_s_tb->FL[n_h], n_child_position);
1916 p_s_bh = sb_bread(p_s_sb, n_son_number); 1964 p_s_bh = sb_bread(p_s_sb, n_son_number);
1917 if (!p_s_bh) 1965 if (!p_s_bh)
1918 return IO_ERROR; 1966 return IO_ERROR;
1919 if ( FILESYSTEM_CHANGED_TB (p_s_tb) ) { 1967 if (FILESYSTEM_CHANGED_TB(p_s_tb)) {
1920 decrement_bcount(p_s_bh); 1968 decrement_bcount(p_s_bh);
1921 PROC_INFO_INC( p_s_sb, get_neighbors_restart[ n_h ] ); 1969 PROC_INFO_INC(p_s_sb, get_neighbors_restart[n_h]);
1922 return REPEAT_SEARCH; 1970 return REPEAT_SEARCH;
1971 }
1972
1973 RFALSE(!B_IS_IN_TREE(p_s_tb->FL[n_h]) ||
1974 n_child_position > B_NR_ITEMS(p_s_tb->FL[n_h]) ||
1975 B_N_CHILD_NUM(p_s_tb->FL[n_h], n_child_position) !=
1976 p_s_bh->b_blocknr, "PAP-8275: invalid parent");
1977 RFALSE(!B_IS_IN_TREE(p_s_bh), "PAP-8280: invalid child");
1978 RFALSE(!n_h &&
1979 B_FREE_SPACE(p_s_bh) !=
1980 MAX_CHILD_SIZE(p_s_bh) -
1981 dc_size(B_N_CHILD(p_s_tb->FL[0], n_child_position)),
1982 "PAP-8290: invalid child size of left neighbor");
1983
1984 decrement_bcount(p_s_tb->L[n_h]);
1985 p_s_tb->L[n_h] = p_s_bh;
1923 } 1986 }
1924 1987
1925 RFALSE( ! B_IS_IN_TREE(p_s_tb->FL[n_h]) || 1988 if (p_s_tb->rnum[n_h]) { /* We need right neighbor to balance S[n_path_offset]. */
1926 n_child_position > B_NR_ITEMS(p_s_tb->FL[n_h]) || 1989 PROC_INFO_INC(p_s_sb, need_r_neighbor[n_h]);
1927 B_N_CHILD_NUM(p_s_tb->FL[n_h], n_child_position) != 1990 p_s_bh = PATH_OFFSET_PBUFFER(p_s_tb->tb_path, n_path_offset);
1928 p_s_bh->b_blocknr, "PAP-8275: invalid parent"); 1991
1929 RFALSE( ! B_IS_IN_TREE(p_s_bh), "PAP-8280: invalid child"); 1992 RFALSE(p_s_bh == p_s_tb->FR[n_h] &&
1930 RFALSE( ! n_h && 1993 PATH_OFFSET_POSITION(p_s_tb->tb_path,
1931 B_FREE_SPACE (p_s_bh) != MAX_CHILD_SIZE (p_s_bh) - dc_size(B_N_CHILD (p_s_tb->FL[0],n_child_position)), 1994 n_path_offset) >=
1932 "PAP-8290: invalid child size of left neighbor"); 1995 B_NR_ITEMS(p_s_bh),
1933 1996 "PAP-8295: invalid position in the parent");
1934 decrement_bcount(p_s_tb->L[n_h]); 1997
1935 p_s_tb->L[n_h] = p_s_bh; 1998 n_child_position =
1936 } 1999 (p_s_bh == p_s_tb->FR[n_h]) ? p_s_tb->rkey[n_h] + 1 : 0;
1937 2000 n_son_number = B_N_CHILD_NUM(p_s_tb->FR[n_h], n_child_position);
1938 2001 p_s_bh = sb_bread(p_s_sb, n_son_number);
1939 if ( p_s_tb->rnum[n_h] ) { /* We need right neighbor to balance S[n_path_offset]. */ 2002 if (!p_s_bh)
1940 PROC_INFO_INC( p_s_sb, need_r_neighbor[ n_h ] ); 2003 return IO_ERROR;
1941 p_s_bh = PATH_OFFSET_PBUFFER(p_s_tb->tb_path, n_path_offset); 2004 if (FILESYSTEM_CHANGED_TB(p_s_tb)) {
1942 2005 decrement_bcount(p_s_bh);
1943 RFALSE( p_s_bh == p_s_tb->FR[n_h] && 2006 PROC_INFO_INC(p_s_sb, get_neighbors_restart[n_h]);
1944 PATH_OFFSET_POSITION(p_s_tb->tb_path, n_path_offset) >= B_NR_ITEMS(p_s_bh), 2007 return REPEAT_SEARCH;
1945 "PAP-8295: invalid position in the parent"); 2008 }
1946 2009 decrement_bcount(p_s_tb->R[n_h]);
1947 n_child_position = ( p_s_bh == p_s_tb->FR[n_h] ) ? p_s_tb->rkey[n_h] + 1 : 0; 2010 p_s_tb->R[n_h] = p_s_bh;
1948 n_son_number = B_N_CHILD_NUM(p_s_tb->FR[n_h], n_child_position); 2011
1949 p_s_bh = sb_bread(p_s_sb, n_son_number); 2012 RFALSE(!n_h
1950 if (!p_s_bh) 2013 && B_FREE_SPACE(p_s_bh) !=
1951 return IO_ERROR; 2014 MAX_CHILD_SIZE(p_s_bh) -
1952 if ( FILESYSTEM_CHANGED_TB (p_s_tb) ) { 2015 dc_size(B_N_CHILD(p_s_tb->FR[0], n_child_position)),
1953 decrement_bcount(p_s_bh); 2016 "PAP-8300: invalid child size of right neighbor (%d != %d - %d)",
1954 PROC_INFO_INC( p_s_sb, get_neighbors_restart[ n_h ] ); 2017 B_FREE_SPACE(p_s_bh), MAX_CHILD_SIZE(p_s_bh),
1955 return REPEAT_SEARCH; 2018 dc_size(B_N_CHILD(p_s_tb->FR[0], n_child_position)));
2019
1956 } 2020 }
1957 decrement_bcount(p_s_tb->R[n_h]); 2021 return CARRY_ON;
1958 p_s_tb->R[n_h] = p_s_bh;
1959
1960 RFALSE( ! n_h && B_FREE_SPACE (p_s_bh) != MAX_CHILD_SIZE (p_s_bh) - dc_size(B_N_CHILD (p_s_tb->FR[0],n_child_position)),
1961 "PAP-8300: invalid child size of right neighbor (%d != %d - %d)",
1962 B_FREE_SPACE (p_s_bh), MAX_CHILD_SIZE (p_s_bh),
1963 dc_size(B_N_CHILD (p_s_tb->FR[0],n_child_position)));
1964
1965 }
1966 return CARRY_ON;
1967} 2022}
1968 2023
1969#ifdef CONFIG_REISERFS_CHECK 2024#ifdef CONFIG_REISERFS_CHECK
1970void * reiserfs_kmalloc (size_t size, int flags, struct super_block * s) 2025void *reiserfs_kmalloc(size_t size, int flags, struct super_block *s)
1971{ 2026{
1972 void * vp; 2027 void *vp;
1973 static size_t malloced; 2028 static size_t malloced;
1974 2029
1975 2030 vp = kmalloc(size, flags);
1976 vp = kmalloc (size, flags); 2031 if (vp) {
1977 if (vp) { 2032 REISERFS_SB(s)->s_kmallocs += size;
1978 REISERFS_SB(s)->s_kmallocs += size; 2033 if (REISERFS_SB(s)->s_kmallocs > malloced + 200000) {
1979 if (REISERFS_SB(s)->s_kmallocs > malloced + 200000) { 2034 reiserfs_warning(s,
1980 reiserfs_warning (s, 2035 "vs-8301: reiserfs_kmalloc: allocated memory %d",
1981 "vs-8301: reiserfs_kmalloc: allocated memory %d", 2036 REISERFS_SB(s)->s_kmallocs);
1982 REISERFS_SB(s)->s_kmallocs); 2037 malloced = REISERFS_SB(s)->s_kmallocs;
1983 malloced = REISERFS_SB(s)->s_kmallocs; 2038 }
1984 } 2039 }
1985 } 2040 return vp;
1986 return vp;
1987} 2041}
1988 2042
1989void reiserfs_kfree (const void * vp, size_t size, struct super_block * s) 2043void reiserfs_kfree(const void *vp, size_t size, struct super_block *s)
1990{ 2044{
1991 kfree (vp); 2045 kfree(vp);
1992 2046
1993 REISERFS_SB(s)->s_kmallocs -= size; 2047 REISERFS_SB(s)->s_kmallocs -= size;
1994 if (REISERFS_SB(s)->s_kmallocs < 0) 2048 if (REISERFS_SB(s)->s_kmallocs < 0)
1995 reiserfs_warning (s, "vs-8302: reiserfs_kfree: allocated memory %d", 2049 reiserfs_warning(s,
1996 REISERFS_SB(s)->s_kmallocs); 2050 "vs-8302: reiserfs_kfree: allocated memory %d",
2051 REISERFS_SB(s)->s_kmallocs);
1997 2052
1998} 2053}
1999#endif 2054#endif
2000 2055
2001 2056static int get_virtual_node_size(struct super_block *sb, struct buffer_head *bh)
2002static int get_virtual_node_size (struct super_block * sb, struct buffer_head * bh)
2003{ 2057{
2004 int max_num_of_items; 2058 int max_num_of_items;
2005 int max_num_of_entries; 2059 int max_num_of_entries;
2006 unsigned long blocksize = sb->s_blocksize; 2060 unsigned long blocksize = sb->s_blocksize;
2007 2061
2008#define MIN_NAME_LEN 1 2062#define MIN_NAME_LEN 1
2009 2063
2010 max_num_of_items = (blocksize - BLKH_SIZE) / (IH_SIZE + MIN_ITEM_LEN); 2064 max_num_of_items = (blocksize - BLKH_SIZE) / (IH_SIZE + MIN_ITEM_LEN);
2011 max_num_of_entries = (blocksize - BLKH_SIZE - IH_SIZE) / 2065 max_num_of_entries = (blocksize - BLKH_SIZE - IH_SIZE) /
2012 (DEH_SIZE + MIN_NAME_LEN); 2066 (DEH_SIZE + MIN_NAME_LEN);
2013 2067
2014 return sizeof(struct virtual_node) + 2068 return sizeof(struct virtual_node) +
2015 max(max_num_of_items * sizeof (struct virtual_item), 2069 max(max_num_of_items * sizeof(struct virtual_item),
2016 sizeof (struct virtual_item) + sizeof(struct direntry_uarea) + 2070 sizeof(struct virtual_item) + sizeof(struct direntry_uarea) +
2017 (max_num_of_entries - 1) * sizeof (__u16)); 2071 (max_num_of_entries - 1) * sizeof(__u16));
2018} 2072}
2019 2073
2020
2021
2022/* maybe we should fail balancing we are going to perform when kmalloc 2074/* maybe we should fail balancing we are going to perform when kmalloc
2023 fails several times. But now it will loop until kmalloc gets 2075 fails several times. But now it will loop until kmalloc gets
2024 required memory */ 2076 required memory */
2025static int get_mem_for_virtual_node (struct tree_balance * tb) 2077static int get_mem_for_virtual_node(struct tree_balance *tb)
2026{ 2078{
2027 int check_fs = 0; 2079 int check_fs = 0;
2028 int size; 2080 int size;
2029 char * buf; 2081 char *buf;
2030 2082
2031 size = get_virtual_node_size (tb->tb_sb, PATH_PLAST_BUFFER (tb->tb_path)); 2083 size = get_virtual_node_size(tb->tb_sb, PATH_PLAST_BUFFER(tb->tb_path));
2032 2084
2033 if (size > tb->vn_buf_size) { 2085 if (size > tb->vn_buf_size) {
2034 /* we have to allocate more memory for virtual node */ 2086 /* we have to allocate more memory for virtual node */
2035 if (tb->vn_buf) { 2087 if (tb->vn_buf) {
2036 /* free memory allocated before */ 2088 /* free memory allocated before */
2037 reiserfs_kfree (tb->vn_buf, tb->vn_buf_size, tb->tb_sb); 2089 reiserfs_kfree(tb->vn_buf, tb->vn_buf_size, tb->tb_sb);
2038 /* this is not needed if kfree is atomic */ 2090 /* this is not needed if kfree is atomic */
2039 check_fs = 1; 2091 check_fs = 1;
2040 } 2092 }
2041 2093
2042 /* virtual node requires now more memory */ 2094 /* virtual node requires now more memory */
2043 tb->vn_buf_size = size; 2095 tb->vn_buf_size = size;
2044 2096
2045 /* get memory for virtual item */ 2097 /* get memory for virtual item */
2046 buf = reiserfs_kmalloc(size, GFP_ATOMIC | __GFP_NOWARN, tb->tb_sb); 2098 buf =
2047 if ( ! buf ) { 2099 reiserfs_kmalloc(size, GFP_ATOMIC | __GFP_NOWARN,
2048 /* getting memory with GFP_KERNEL priority may involve 2100 tb->tb_sb);
2049 balancing now (due to indirect_to_direct conversion on 2101 if (!buf) {
2050 dcache shrinking). So, release path and collected 2102 /* getting memory with GFP_KERNEL priority may involve
2051 resources here */ 2103 balancing now (due to indirect_to_direct conversion on
2052 free_buffers_in_tb (tb); 2104 dcache shrinking). So, release path and collected
2053 buf = reiserfs_kmalloc(size, GFP_NOFS, tb->tb_sb); 2105 resources here */
2054 if ( !buf ) { 2106 free_buffers_in_tb(tb);
2107 buf = reiserfs_kmalloc(size, GFP_NOFS, tb->tb_sb);
2108 if (!buf) {
2055#ifdef CONFIG_REISERFS_CHECK 2109#ifdef CONFIG_REISERFS_CHECK
2056 reiserfs_warning (tb->tb_sb, 2110 reiserfs_warning(tb->tb_sb,
2057 "vs-8345: get_mem_for_virtual_node: " 2111 "vs-8345: get_mem_for_virtual_node: "
2058 "kmalloc failed. reiserfs kmalloced %d bytes", 2112 "kmalloc failed. reiserfs kmalloced %d bytes",
2059 REISERFS_SB(tb->tb_sb)->s_kmallocs); 2113 REISERFS_SB(tb->tb_sb)->
2114 s_kmallocs);
2060#endif 2115#endif
2061 tb->vn_buf_size = 0; 2116 tb->vn_buf_size = 0;
2062 } 2117 }
2063 tb->vn_buf = buf; 2118 tb->vn_buf = buf;
2064 schedule() ; 2119 schedule();
2065 return REPEAT_SEARCH; 2120 return REPEAT_SEARCH;
2066 } 2121 }
2067 2122
2068 tb->vn_buf = buf; 2123 tb->vn_buf = buf;
2069 } 2124 }
2070 2125
2071 if ( check_fs && FILESYSTEM_CHANGED_TB (tb) ) 2126 if (check_fs && FILESYSTEM_CHANGED_TB(tb))
2072 return REPEAT_SEARCH; 2127 return REPEAT_SEARCH;
2073 2128
2074 return CARRY_ON; 2129 return CARRY_ON;
2075} 2130}
2076 2131
2077
2078#ifdef CONFIG_REISERFS_CHECK 2132#ifdef CONFIG_REISERFS_CHECK
2079static void tb_buffer_sanity_check (struct super_block * p_s_sb, 2133static void tb_buffer_sanity_check(struct super_block *p_s_sb,
2080 struct buffer_head * p_s_bh, 2134 struct buffer_head *p_s_bh,
2081 const char *descr, int level) { 2135 const char *descr, int level)
2082 if (p_s_bh) {
2083 if (atomic_read (&(p_s_bh->b_count)) <= 0) {
2084
2085 reiserfs_panic (p_s_sb, "jmacd-1: tb_buffer_sanity_check(): negative or zero reference counter for buffer %s[%d] (%b)\n", descr, level, p_s_bh);
2086 }
2087
2088 if ( ! buffer_uptodate (p_s_bh) ) {
2089 reiserfs_panic (p_s_sb, "jmacd-2: tb_buffer_sanity_check(): buffer is not up to date %s[%d] (%b)\n", descr, level, p_s_bh);
2090 }
2091
2092 if ( ! B_IS_IN_TREE (p_s_bh) ) {
2093 reiserfs_panic (p_s_sb, "jmacd-3: tb_buffer_sanity_check(): buffer is not in tree %s[%d] (%b)\n", descr, level, p_s_bh);
2094 }
2095
2096 if (p_s_bh->b_bdev != p_s_sb->s_bdev) {
2097 reiserfs_panic (p_s_sb, "jmacd-4: tb_buffer_sanity_check(): buffer has wrong device %s[%d] (%b)\n", descr, level, p_s_bh);
2098 }
2099
2100 if (p_s_bh->b_size != p_s_sb->s_blocksize) {
2101 reiserfs_panic (p_s_sb, "jmacd-5: tb_buffer_sanity_check(): buffer has wrong blocksize %s[%d] (%b)\n", descr, level, p_s_bh);
2102 }
2103
2104 if (p_s_bh->b_blocknr > SB_BLOCK_COUNT(p_s_sb)) {
2105 reiserfs_panic (p_s_sb, "jmacd-6: tb_buffer_sanity_check(): buffer block number too high %s[%d] (%b)\n", descr, level, p_s_bh);
2106 }
2107 }
2108}
2109#else
2110static void tb_buffer_sanity_check (struct super_block * p_s_sb,
2111 struct buffer_head * p_s_bh,
2112 const char *descr, int level)
2113{;}
2114#endif
2115
2116static int clear_all_dirty_bits(struct super_block *s,
2117 struct buffer_head *bh) {
2118 return reiserfs_prepare_for_journal(s, bh, 0) ;
2119}
2120
2121static int wait_tb_buffers_until_unlocked (struct tree_balance * p_s_tb)
2122{ 2136{
2123 struct buffer_head * locked; 2137 if (p_s_bh) {
2124#ifdef CONFIG_REISERFS_CHECK 2138 if (atomic_read(&(p_s_bh->b_count)) <= 0) {
2125 int repeat_counter = 0;
2126#endif
2127 int i;
2128 2139
2129 do { 2140 reiserfs_panic(p_s_sb,
2130 2141 "jmacd-1: tb_buffer_sanity_check(): negative or zero reference counter for buffer %s[%d] (%b)\n",
2131 locked = NULL; 2142 descr, level, p_s_bh);
2132
2133 for ( i = p_s_tb->tb_path->path_length; !locked && i > ILLEGAL_PATH_ELEMENT_OFFSET; i-- ) {
2134 if ( PATH_OFFSET_PBUFFER (p_s_tb->tb_path, i) ) {
2135 /* if I understand correctly, we can only be sure the last buffer
2136 ** in the path is in the tree --clm
2137 */
2138#ifdef CONFIG_REISERFS_CHECK
2139 if (PATH_PLAST_BUFFER(p_s_tb->tb_path) ==
2140 PATH_OFFSET_PBUFFER(p_s_tb->tb_path, i)) {
2141 tb_buffer_sanity_check (p_s_tb->tb_sb,
2142 PATH_OFFSET_PBUFFER (p_s_tb->tb_path, i),
2143 "S",
2144 p_s_tb->tb_path->path_length - i);
2145 } 2143 }
2146#endif
2147 if (!clear_all_dirty_bits(p_s_tb->tb_sb,
2148 PATH_OFFSET_PBUFFER (p_s_tb->tb_path, i)))
2149 {
2150 locked = PATH_OFFSET_PBUFFER (p_s_tb->tb_path, i);
2151 }
2152 }
2153 }
2154 2144
2155 for ( i = 0; !locked && i < MAX_HEIGHT && p_s_tb->insert_size[i]; i++ ) { 2145 if (!buffer_uptodate(p_s_bh)) {
2146 reiserfs_panic(p_s_sb,
2147 "jmacd-2: tb_buffer_sanity_check(): buffer is not up to date %s[%d] (%b)\n",
2148 descr, level, p_s_bh);
2149 }
2156 2150
2157 if (p_s_tb->lnum[i] ) { 2151 if (!B_IS_IN_TREE(p_s_bh)) {
2152 reiserfs_panic(p_s_sb,
2153 "jmacd-3: tb_buffer_sanity_check(): buffer is not in tree %s[%d] (%b)\n",
2154 descr, level, p_s_bh);
2155 }
2158 2156
2159 if ( p_s_tb->L[i] ) { 2157 if (p_s_bh->b_bdev != p_s_sb->s_bdev) {
2160 tb_buffer_sanity_check (p_s_tb->tb_sb, p_s_tb->L[i], "L", i); 2158 reiserfs_panic(p_s_sb,
2161 if (!clear_all_dirty_bits(p_s_tb->tb_sb, p_s_tb->L[i])) 2159 "jmacd-4: tb_buffer_sanity_check(): buffer has wrong device %s[%d] (%b)\n",
2162 locked = p_s_tb->L[i]; 2160 descr, level, p_s_bh);
2163 } 2161 }
2164 2162
2165 if ( !locked && p_s_tb->FL[i] ) { 2163 if (p_s_bh->b_size != p_s_sb->s_blocksize) {
2166 tb_buffer_sanity_check (p_s_tb->tb_sb, p_s_tb->FL[i], "FL", i); 2164 reiserfs_panic(p_s_sb,
2167 if (!clear_all_dirty_bits(p_s_tb->tb_sb, p_s_tb->FL[i])) 2165 "jmacd-5: tb_buffer_sanity_check(): buffer has wrong blocksize %s[%d] (%b)\n",
2168 locked = p_s_tb->FL[i]; 2166 descr, level, p_s_bh);
2169 } 2167 }
2170 2168
2171 if ( !locked && p_s_tb->CFL[i] ) { 2169 if (p_s_bh->b_blocknr > SB_BLOCK_COUNT(p_s_sb)) {
2172 tb_buffer_sanity_check (p_s_tb->tb_sb, p_s_tb->CFL[i], "CFL", i); 2170 reiserfs_panic(p_s_sb,
2173 if (!clear_all_dirty_bits(p_s_tb->tb_sb, p_s_tb->CFL[i])) 2171 "jmacd-6: tb_buffer_sanity_check(): buffer block number too high %s[%d] (%b)\n",
2174 locked = p_s_tb->CFL[i]; 2172 descr, level, p_s_bh);
2175 } 2173 }
2174 }
2175}
2176#else
2177static void tb_buffer_sanity_check(struct super_block *p_s_sb,
2178 struct buffer_head *p_s_bh,
2179 const char *descr, int level)
2180{;
2181}
2182#endif
2176 2183
2177 } 2184static int clear_all_dirty_bits(struct super_block *s, struct buffer_head *bh)
2185{
2186 return reiserfs_prepare_for_journal(s, bh, 0);
2187}
2178 2188
2179 if ( !locked && (p_s_tb->rnum[i]) ) { 2189static int wait_tb_buffers_until_unlocked(struct tree_balance *p_s_tb)
2190{
2191 struct buffer_head *locked;
2192#ifdef CONFIG_REISERFS_CHECK
2193 int repeat_counter = 0;
2194#endif
2195 int i;
2180 2196
2181 if ( p_s_tb->R[i] ) { 2197 do {
2182 tb_buffer_sanity_check (p_s_tb->tb_sb, p_s_tb->R[i], "R", i);
2183 if (!clear_all_dirty_bits(p_s_tb->tb_sb, p_s_tb->R[i]))
2184 locked = p_s_tb->R[i];
2185 }
2186 2198
2187 2199 locked = NULL;
2188 if ( !locked && p_s_tb->FR[i] ) { 2200
2189 tb_buffer_sanity_check (p_s_tb->tb_sb, p_s_tb->FR[i], "FR", i); 2201 for (i = p_s_tb->tb_path->path_length;
2190 if (!clear_all_dirty_bits(p_s_tb->tb_sb, p_s_tb->FR[i])) 2202 !locked && i > ILLEGAL_PATH_ELEMENT_OFFSET; i--) {
2191 locked = p_s_tb->FR[i]; 2203 if (PATH_OFFSET_PBUFFER(p_s_tb->tb_path, i)) {
2204 /* if I understand correctly, we can only be sure the last buffer
2205 ** in the path is in the tree --clm
2206 */
2207#ifdef CONFIG_REISERFS_CHECK
2208 if (PATH_PLAST_BUFFER(p_s_tb->tb_path) ==
2209 PATH_OFFSET_PBUFFER(p_s_tb->tb_path, i)) {
2210 tb_buffer_sanity_check(p_s_tb->tb_sb,
2211 PATH_OFFSET_PBUFFER
2212 (p_s_tb->tb_path,
2213 i), "S",
2214 p_s_tb->tb_path->
2215 path_length - i);
2216 }
2217#endif
2218 if (!clear_all_dirty_bits(p_s_tb->tb_sb,
2219 PATH_OFFSET_PBUFFER
2220 (p_s_tb->tb_path,
2221 i))) {
2222 locked =
2223 PATH_OFFSET_PBUFFER(p_s_tb->tb_path,
2224 i);
2225 }
2226 }
2192 } 2227 }
2193 2228
2194 if ( !locked && p_s_tb->CFR[i] ) { 2229 for (i = 0; !locked && i < MAX_HEIGHT && p_s_tb->insert_size[i];
2195 tb_buffer_sanity_check (p_s_tb->tb_sb, p_s_tb->CFR[i], "CFR", i); 2230 i++) {
2196 if (!clear_all_dirty_bits(p_s_tb->tb_sb, p_s_tb->CFR[i])) 2231
2197 locked = p_s_tb->CFR[i]; 2232 if (p_s_tb->lnum[i]) {
2233
2234 if (p_s_tb->L[i]) {
2235 tb_buffer_sanity_check(p_s_tb->tb_sb,
2236 p_s_tb->L[i],
2237 "L", i);
2238 if (!clear_all_dirty_bits
2239 (p_s_tb->tb_sb, p_s_tb->L[i]))
2240 locked = p_s_tb->L[i];
2241 }
2242
2243 if (!locked && p_s_tb->FL[i]) {
2244 tb_buffer_sanity_check(p_s_tb->tb_sb,
2245 p_s_tb->FL[i],
2246 "FL", i);
2247 if (!clear_all_dirty_bits
2248 (p_s_tb->tb_sb, p_s_tb->FL[i]))
2249 locked = p_s_tb->FL[i];
2250 }
2251
2252 if (!locked && p_s_tb->CFL[i]) {
2253 tb_buffer_sanity_check(p_s_tb->tb_sb,
2254 p_s_tb->CFL[i],
2255 "CFL", i);
2256 if (!clear_all_dirty_bits
2257 (p_s_tb->tb_sb, p_s_tb->CFL[i]))
2258 locked = p_s_tb->CFL[i];
2259 }
2260
2261 }
2262
2263 if (!locked && (p_s_tb->rnum[i])) {
2264
2265 if (p_s_tb->R[i]) {
2266 tb_buffer_sanity_check(p_s_tb->tb_sb,
2267 p_s_tb->R[i],
2268 "R", i);
2269 if (!clear_all_dirty_bits
2270 (p_s_tb->tb_sb, p_s_tb->R[i]))
2271 locked = p_s_tb->R[i];
2272 }
2273
2274 if (!locked && p_s_tb->FR[i]) {
2275 tb_buffer_sanity_check(p_s_tb->tb_sb,
2276 p_s_tb->FR[i],
2277 "FR", i);
2278 if (!clear_all_dirty_bits
2279 (p_s_tb->tb_sb, p_s_tb->FR[i]))
2280 locked = p_s_tb->FR[i];
2281 }
2282
2283 if (!locked && p_s_tb->CFR[i]) {
2284 tb_buffer_sanity_check(p_s_tb->tb_sb,
2285 p_s_tb->CFR[i],
2286 "CFR", i);
2287 if (!clear_all_dirty_bits
2288 (p_s_tb->tb_sb, p_s_tb->CFR[i]))
2289 locked = p_s_tb->CFR[i];
2290 }
2291 }
2292 }
2293 /* as far as I can tell, this is not required. The FEB list seems
2294 ** to be full of newly allocated nodes, which will never be locked,
2295 ** dirty, or anything else.
2296 ** To be safe, I'm putting in the checks and waits in. For the moment,
2297 ** they are needed to keep the code in journal.c from complaining
2298 ** about the buffer. That code is inside CONFIG_REISERFS_CHECK as well.
2299 ** --clm
2300 */
2301 for (i = 0; !locked && i < MAX_FEB_SIZE; i++) {
2302 if (p_s_tb->FEB[i]) {
2303 if (!clear_all_dirty_bits
2304 (p_s_tb->tb_sb, p_s_tb->FEB[i]))
2305 locked = p_s_tb->FEB[i];
2306 }
2198 } 2307 }
2199 }
2200 }
2201 /* as far as I can tell, this is not required. The FEB list seems
2202 ** to be full of newly allocated nodes, which will never be locked,
2203 ** dirty, or anything else.
2204 ** To be safe, I'm putting in the checks and waits in. For the moment,
2205 ** they are needed to keep the code in journal.c from complaining
2206 ** about the buffer. That code is inside CONFIG_REISERFS_CHECK as well.
2207 ** --clm
2208 */
2209 for ( i = 0; !locked && i < MAX_FEB_SIZE; i++ ) {
2210 if ( p_s_tb->FEB[i] ) {
2211 if (!clear_all_dirty_bits(p_s_tb->tb_sb, p_s_tb->FEB[i]))
2212 locked = p_s_tb->FEB[i] ;
2213 }
2214 }
2215 2308
2216 if (locked) { 2309 if (locked) {
2217#ifdef CONFIG_REISERFS_CHECK 2310#ifdef CONFIG_REISERFS_CHECK
2218 repeat_counter++; 2311 repeat_counter++;
2219 if ( (repeat_counter % 10000) == 0) { 2312 if ((repeat_counter % 10000) == 0) {
2220 reiserfs_warning (p_s_tb->tb_sb, 2313 reiserfs_warning(p_s_tb->tb_sb,
2221 "wait_tb_buffers_until_released(): too many " 2314 "wait_tb_buffers_until_released(): too many "
2222 "iterations waiting for buffer to unlock " 2315 "iterations waiting for buffer to unlock "
2223 "(%b)", locked); 2316 "(%b)", locked);
2224 2317
2225 /* Don't loop forever. Try to recover from possible error. */ 2318 /* Don't loop forever. Try to recover from possible error. */
2226 2319
2227 return ( FILESYSTEM_CHANGED_TB (p_s_tb) ) ? REPEAT_SEARCH : CARRY_ON; 2320 return (FILESYSTEM_CHANGED_TB(p_s_tb)) ?
2228 } 2321 REPEAT_SEARCH : CARRY_ON;
2322 }
2229#endif 2323#endif
2230 __wait_on_buffer (locked); 2324 __wait_on_buffer(locked);
2231 if ( FILESYSTEM_CHANGED_TB (p_s_tb) ) { 2325 if (FILESYSTEM_CHANGED_TB(p_s_tb)) {
2232 return REPEAT_SEARCH; 2326 return REPEAT_SEARCH;
2233 } 2327 }
2234 } 2328 }
2235 2329
2236 } while (locked); 2330 } while (locked);
2237 2331
2238 return CARRY_ON; 2332 return CARRY_ON;
2239} 2333}
2240 2334
2241
2242/* Prepare for balancing, that is 2335/* Prepare for balancing, that is
2243 * get all necessary parents, and neighbors; 2336 * get all necessary parents, and neighbors;
2244 * analyze what and where should be moved; 2337 * analyze what and where should be moved;
@@ -2267,252 +2360,266 @@ static int wait_tb_buffers_until_unlocked (struct tree_balance * p_s_tb)
2267 * -1 - if no_disk_space 2360 * -1 - if no_disk_space
2268 */ 2361 */
2269 2362
2363int fix_nodes(int n_op_mode, struct tree_balance *p_s_tb, struct item_head *p_s_ins_ih, // item head of item being inserted
2364 const void *data // inserted item or data to be pasted
2365 )
2366{
2367 int n_ret_value, n_h, n_item_num = PATH_LAST_POSITION(p_s_tb->tb_path);
2368 int n_pos_in_item;
2270 2369
2271int fix_nodes (int n_op_mode, 2370 /* we set wait_tb_buffers_run when we have to restore any dirty bits cleared
2272 struct tree_balance * p_s_tb, 2371 ** during wait_tb_buffers_run
2273 struct item_head * p_s_ins_ih, // item head of item being inserted 2372 */
2274 const void * data // inserted item or data to be pasted 2373 int wait_tb_buffers_run = 0;
2275 ) { 2374 struct buffer_head *p_s_tbS0 = PATH_PLAST_BUFFER(p_s_tb->tb_path);
2276 int n_ret_value,
2277 n_h,
2278 n_item_num = PATH_LAST_POSITION(p_s_tb->tb_path);
2279 int n_pos_in_item;
2280
2281 /* we set wait_tb_buffers_run when we have to restore any dirty bits cleared
2282 ** during wait_tb_buffers_run
2283 */
2284 int wait_tb_buffers_run = 0 ;
2285 struct buffer_head * p_s_tbS0 = PATH_PLAST_BUFFER(p_s_tb->tb_path);
2286
2287 ++ REISERFS_SB(p_s_tb -> tb_sb) -> s_fix_nodes;
2288
2289 n_pos_in_item = p_s_tb->tb_path->pos_in_item;
2290
2291
2292 p_s_tb->fs_gen = get_generation (p_s_tb->tb_sb);
2293
2294 /* we prepare and log the super here so it will already be in the
2295 ** transaction when do_balance needs to change it.
2296 ** This way do_balance won't have to schedule when trying to prepare
2297 ** the super for logging
2298 */
2299 reiserfs_prepare_for_journal(p_s_tb->tb_sb,
2300 SB_BUFFER_WITH_SB(p_s_tb->tb_sb), 1) ;
2301 journal_mark_dirty(p_s_tb->transaction_handle, p_s_tb->tb_sb,
2302 SB_BUFFER_WITH_SB(p_s_tb->tb_sb)) ;
2303 if ( FILESYSTEM_CHANGED_TB (p_s_tb) )
2304 return REPEAT_SEARCH;
2305
2306 /* if it possible in indirect_to_direct conversion */
2307 if (buffer_locked (p_s_tbS0)) {
2308 __wait_on_buffer (p_s_tbS0);
2309 if ( FILESYSTEM_CHANGED_TB (p_s_tb) )
2310 return REPEAT_SEARCH;
2311 }
2312 2375
2313#ifdef CONFIG_REISERFS_CHECK 2376 ++REISERFS_SB(p_s_tb->tb_sb)->s_fix_nodes;
2314 if ( cur_tb ) { 2377
2315 print_cur_tb ("fix_nodes"); 2378 n_pos_in_item = p_s_tb->tb_path->pos_in_item;
2316 reiserfs_panic(p_s_tb->tb_sb,"PAP-8305: fix_nodes: there is pending do_balance"); 2379
2317 } 2380 p_s_tb->fs_gen = get_generation(p_s_tb->tb_sb);
2318
2319 if (!buffer_uptodate (p_s_tbS0) || !B_IS_IN_TREE (p_s_tbS0)) {
2320 reiserfs_panic (p_s_tb->tb_sb, "PAP-8320: fix_nodes: S[0] (%b %z) is not uptodate "
2321 "at the beginning of fix_nodes or not in tree (mode %c)", p_s_tbS0, p_s_tbS0, n_op_mode);
2322 }
2323
2324 /* Check parameters. */
2325 switch (n_op_mode) {
2326 case M_INSERT:
2327 if ( n_item_num <= 0 || n_item_num > B_NR_ITEMS(p_s_tbS0) )
2328 reiserfs_panic(p_s_tb->tb_sb,"PAP-8330: fix_nodes: Incorrect item number %d (in S0 - %d) in case of insert",
2329 n_item_num, B_NR_ITEMS(p_s_tbS0));
2330 break;
2331 case M_PASTE:
2332 case M_DELETE:
2333 case M_CUT:
2334 if ( n_item_num < 0 || n_item_num >= B_NR_ITEMS(p_s_tbS0) ) {
2335 print_block (p_s_tbS0, 0, -1, -1);
2336 reiserfs_panic(p_s_tb->tb_sb,"PAP-8335: fix_nodes: Incorrect item number(%d); mode = %c insert_size = %d\n", n_item_num, n_op_mode, p_s_tb->insert_size[0]);
2337 }
2338 break;
2339 default:
2340 reiserfs_panic(p_s_tb->tb_sb,"PAP-8340: fix_nodes: Incorrect mode of operation");
2341 }
2342#endif
2343 2381
2344 if (get_mem_for_virtual_node (p_s_tb) == REPEAT_SEARCH) 2382 /* we prepare and log the super here so it will already be in the
2345 // FIXME: maybe -ENOMEM when tb->vn_buf == 0? Now just repeat 2383 ** transaction when do_balance needs to change it.
2346 return REPEAT_SEARCH; 2384 ** This way do_balance won't have to schedule when trying to prepare
2385 ** the super for logging
2386 */
2387 reiserfs_prepare_for_journal(p_s_tb->tb_sb,
2388 SB_BUFFER_WITH_SB(p_s_tb->tb_sb), 1);
2389 journal_mark_dirty(p_s_tb->transaction_handle, p_s_tb->tb_sb,
2390 SB_BUFFER_WITH_SB(p_s_tb->tb_sb));
2391 if (FILESYSTEM_CHANGED_TB(p_s_tb))
2392 return REPEAT_SEARCH;
2347 2393
2394 /* if it possible in indirect_to_direct conversion */
2395 if (buffer_locked(p_s_tbS0)) {
2396 __wait_on_buffer(p_s_tbS0);
2397 if (FILESYSTEM_CHANGED_TB(p_s_tb))
2398 return REPEAT_SEARCH;
2399 }
2400#ifdef CONFIG_REISERFS_CHECK
2401 if (cur_tb) {
2402 print_cur_tb("fix_nodes");
2403 reiserfs_panic(p_s_tb->tb_sb,
2404 "PAP-8305: fix_nodes: there is pending do_balance");
2405 }
2348 2406
2349 /* Starting from the leaf level; for all levels n_h of the tree. */ 2407 if (!buffer_uptodate(p_s_tbS0) || !B_IS_IN_TREE(p_s_tbS0)) {
2350 for ( n_h = 0; n_h < MAX_HEIGHT && p_s_tb->insert_size[n_h]; n_h++ ) { 2408 reiserfs_panic(p_s_tb->tb_sb,
2351 if ( (n_ret_value = get_direct_parent(p_s_tb, n_h)) != CARRY_ON ) { 2409 "PAP-8320: fix_nodes: S[0] (%b %z) is not uptodate "
2352 goto repeat; 2410 "at the beginning of fix_nodes or not in tree (mode %c)",
2411 p_s_tbS0, p_s_tbS0, n_op_mode);
2353 } 2412 }
2354 2413
2355 if ( (n_ret_value = check_balance (n_op_mode, p_s_tb, n_h, n_item_num, 2414 /* Check parameters. */
2356 n_pos_in_item, p_s_ins_ih, data)) != CARRY_ON ) { 2415 switch (n_op_mode) {
2357 if ( n_ret_value == NO_BALANCING_NEEDED ) { 2416 case M_INSERT:
2358 /* No balancing for higher levels needed. */ 2417 if (n_item_num <= 0 || n_item_num > B_NR_ITEMS(p_s_tbS0))
2359 if ( (n_ret_value = get_neighbors(p_s_tb, n_h)) != CARRY_ON ) { 2418 reiserfs_panic(p_s_tb->tb_sb,
2360 goto repeat; 2419 "PAP-8330: fix_nodes: Incorrect item number %d (in S0 - %d) in case of insert",
2420 n_item_num, B_NR_ITEMS(p_s_tbS0));
2421 break;
2422 case M_PASTE:
2423 case M_DELETE:
2424 case M_CUT:
2425 if (n_item_num < 0 || n_item_num >= B_NR_ITEMS(p_s_tbS0)) {
2426 print_block(p_s_tbS0, 0, -1, -1);
2427 reiserfs_panic(p_s_tb->tb_sb,
2428 "PAP-8335: fix_nodes: Incorrect item number(%d); mode = %c insert_size = %d\n",
2429 n_item_num, n_op_mode,
2430 p_s_tb->insert_size[0]);
2361 } 2431 }
2362 if ( n_h != MAX_HEIGHT - 1 )
2363 p_s_tb->insert_size[n_h + 1] = 0;
2364 /* ok, analysis and resource gathering are complete */
2365 break; 2432 break;
2366 } 2433 default:
2367 goto repeat; 2434 reiserfs_panic(p_s_tb->tb_sb,
2435 "PAP-8340: fix_nodes: Incorrect mode of operation");
2368 } 2436 }
2437#endif
2369 2438
2370 if ( (n_ret_value = get_neighbors(p_s_tb, n_h)) != CARRY_ON ) { 2439 if (get_mem_for_virtual_node(p_s_tb) == REPEAT_SEARCH)
2371 goto repeat; 2440 // FIXME: maybe -ENOMEM when tb->vn_buf == 0? Now just repeat
2372 } 2441 return REPEAT_SEARCH;
2373 2442
2374 if ( (n_ret_value = get_empty_nodes(p_s_tb, n_h)) != CARRY_ON ) { 2443 /* Starting from the leaf level; for all levels n_h of the tree. */
2375 goto repeat; /* No disk space, or schedule occurred and 2444 for (n_h = 0; n_h < MAX_HEIGHT && p_s_tb->insert_size[n_h]; n_h++) {
2376 analysis may be invalid and needs to be redone. */ 2445 if ((n_ret_value = get_direct_parent(p_s_tb, n_h)) != CARRY_ON) {
2377 } 2446 goto repeat;
2378 2447 }
2379 if ( ! PATH_H_PBUFFER(p_s_tb->tb_path, n_h) ) {
2380 /* We have a positive insert size but no nodes exist on this
2381 level, this means that we are creating a new root. */
2382 2448
2383 RFALSE( p_s_tb->blknum[n_h] != 1, 2449 if ((n_ret_value =
2384 "PAP-8350: creating new empty root"); 2450 check_balance(n_op_mode, p_s_tb, n_h, n_item_num,
2451 n_pos_in_item, p_s_ins_ih,
2452 data)) != CARRY_ON) {
2453 if (n_ret_value == NO_BALANCING_NEEDED) {
2454 /* No balancing for higher levels needed. */
2455 if ((n_ret_value =
2456 get_neighbors(p_s_tb, n_h)) != CARRY_ON) {
2457 goto repeat;
2458 }
2459 if (n_h != MAX_HEIGHT - 1)
2460 p_s_tb->insert_size[n_h + 1] = 0;
2461 /* ok, analysis and resource gathering are complete */
2462 break;
2463 }
2464 goto repeat;
2465 }
2385 2466
2386 if ( n_h < MAX_HEIGHT - 1 ) 2467 if ((n_ret_value = get_neighbors(p_s_tb, n_h)) != CARRY_ON) {
2387 p_s_tb->insert_size[n_h + 1] = 0; 2468 goto repeat;
2388 }
2389 else
2390 if ( ! PATH_H_PBUFFER(p_s_tb->tb_path, n_h + 1) ) {
2391 if ( p_s_tb->blknum[n_h] > 1 ) {
2392 /* The tree needs to be grown, so this node S[n_h]
2393 which is the root node is split into two nodes,
2394 and a new node (S[n_h+1]) will be created to
2395 become the root node. */
2396
2397 RFALSE( n_h == MAX_HEIGHT - 1,
2398 "PAP-8355: attempt to create too high of a tree");
2399
2400 p_s_tb->insert_size[n_h + 1] = (DC_SIZE + KEY_SIZE) * (p_s_tb->blknum[n_h] - 1) + DC_SIZE;
2401 } 2469 }
2402 else 2470
2403 if ( n_h < MAX_HEIGHT - 1 ) 2471 if ((n_ret_value = get_empty_nodes(p_s_tb, n_h)) != CARRY_ON) {
2404 p_s_tb->insert_size[n_h + 1] = 0; 2472 goto repeat; /* No disk space, or schedule occurred and
2405 } 2473 analysis may be invalid and needs to be redone. */
2406 else 2474 }
2407 p_s_tb->insert_size[n_h + 1] = (DC_SIZE + KEY_SIZE) * (p_s_tb->blknum[n_h] - 1); 2475
2408 } 2476 if (!PATH_H_PBUFFER(p_s_tb->tb_path, n_h)) {
2409 2477 /* We have a positive insert size but no nodes exist on this
2410 if ((n_ret_value = wait_tb_buffers_until_unlocked (p_s_tb)) == CARRY_ON) { 2478 level, this means that we are creating a new root. */
2411 if (FILESYSTEM_CHANGED_TB(p_s_tb)) { 2479
2412 wait_tb_buffers_run = 1 ; 2480 RFALSE(p_s_tb->blknum[n_h] != 1,
2413 n_ret_value = REPEAT_SEARCH ; 2481 "PAP-8350: creating new empty root");
2414 goto repeat; 2482
2415 } else { 2483 if (n_h < MAX_HEIGHT - 1)
2416 return CARRY_ON; 2484 p_s_tb->insert_size[n_h + 1] = 0;
2485 } else if (!PATH_H_PBUFFER(p_s_tb->tb_path, n_h + 1)) {
2486 if (p_s_tb->blknum[n_h] > 1) {
2487 /* The tree needs to be grown, so this node S[n_h]
2488 which is the root node is split into two nodes,
2489 and a new node (S[n_h+1]) will be created to
2490 become the root node. */
2491
2492 RFALSE(n_h == MAX_HEIGHT - 1,
2493 "PAP-8355: attempt to create too high of a tree");
2494
2495 p_s_tb->insert_size[n_h + 1] =
2496 (DC_SIZE +
2497 KEY_SIZE) * (p_s_tb->blknum[n_h] - 1) +
2498 DC_SIZE;
2499 } else if (n_h < MAX_HEIGHT - 1)
2500 p_s_tb->insert_size[n_h + 1] = 0;
2501 } else
2502 p_s_tb->insert_size[n_h + 1] =
2503 (DC_SIZE + KEY_SIZE) * (p_s_tb->blknum[n_h] - 1);
2417 } 2504 }
2418 } else {
2419 wait_tb_buffers_run = 1 ;
2420 goto repeat;
2421 }
2422
2423 repeat:
2424 // fix_nodes was unable to perform its calculation due to
2425 // filesystem got changed under us, lack of free disk space or i/o
2426 // failure. If the first is the case - the search will be
2427 // repeated. For now - free all resources acquired so far except
2428 // for the new allocated nodes
2429 {
2430 int i;
2431 2505
2432 /* Release path buffers. */ 2506 if ((n_ret_value = wait_tb_buffers_until_unlocked(p_s_tb)) == CARRY_ON) {
2433 if (wait_tb_buffers_run) { 2507 if (FILESYSTEM_CHANGED_TB(p_s_tb)) {
2434 pathrelse_and_restore(p_s_tb->tb_sb, p_s_tb->tb_path) ; 2508 wait_tb_buffers_run = 1;
2509 n_ret_value = REPEAT_SEARCH;
2510 goto repeat;
2511 } else {
2512 return CARRY_ON;
2513 }
2435 } else { 2514 } else {
2436 pathrelse (p_s_tb->tb_path); 2515 wait_tb_buffers_run = 1;
2437 } 2516 goto repeat;
2438 /* brelse all resources collected for balancing */
2439 for ( i = 0; i < MAX_HEIGHT; i++ ) {
2440 if (wait_tb_buffers_run) {
2441 reiserfs_restore_prepared_buffer(p_s_tb->tb_sb, p_s_tb->L[i]);
2442 reiserfs_restore_prepared_buffer(p_s_tb->tb_sb, p_s_tb->R[i]);
2443 reiserfs_restore_prepared_buffer(p_s_tb->tb_sb, p_s_tb->FL[i]);
2444 reiserfs_restore_prepared_buffer(p_s_tb->tb_sb, p_s_tb->FR[i]);
2445 reiserfs_restore_prepared_buffer(p_s_tb->tb_sb, p_s_tb->CFL[i]);
2446 reiserfs_restore_prepared_buffer(p_s_tb->tb_sb, p_s_tb->CFR[i]);
2447 }
2448
2449 brelse (p_s_tb->L[i]);p_s_tb->L[i] = NULL;
2450 brelse (p_s_tb->R[i]);p_s_tb->R[i] = NULL;
2451 brelse (p_s_tb->FL[i]);p_s_tb->FL[i] = NULL;
2452 brelse (p_s_tb->FR[i]);p_s_tb->FR[i] = NULL;
2453 brelse (p_s_tb->CFL[i]);p_s_tb->CFL[i] = NULL;
2454 brelse (p_s_tb->CFR[i]);p_s_tb->CFR[i] = NULL;
2455 } 2517 }
2456 2518
2457 if (wait_tb_buffers_run) { 2519 repeat:
2458 for ( i = 0; i < MAX_FEB_SIZE; i++ ) { 2520 // fix_nodes was unable to perform its calculation due to
2459 if ( p_s_tb->FEB[i] ) { 2521 // filesystem got changed under us, lack of free disk space or i/o
2460 reiserfs_restore_prepared_buffer(p_s_tb->tb_sb, 2522 // failure. If the first is the case - the search will be
2461 p_s_tb->FEB[i]) ; 2523 // repeated. For now - free all resources acquired so far except
2524 // for the new allocated nodes
2525 {
2526 int i;
2527
2528 /* Release path buffers. */
2529 if (wait_tb_buffers_run) {
2530 pathrelse_and_restore(p_s_tb->tb_sb, p_s_tb->tb_path);
2531 } else {
2532 pathrelse(p_s_tb->tb_path);
2533 }
2534 /* brelse all resources collected for balancing */
2535 for (i = 0; i < MAX_HEIGHT; i++) {
2536 if (wait_tb_buffers_run) {
2537 reiserfs_restore_prepared_buffer(p_s_tb->tb_sb,
2538 p_s_tb->L[i]);
2539 reiserfs_restore_prepared_buffer(p_s_tb->tb_sb,
2540 p_s_tb->R[i]);
2541 reiserfs_restore_prepared_buffer(p_s_tb->tb_sb,
2542 p_s_tb->FL[i]);
2543 reiserfs_restore_prepared_buffer(p_s_tb->tb_sb,
2544 p_s_tb->FR[i]);
2545 reiserfs_restore_prepared_buffer(p_s_tb->tb_sb,
2546 p_s_tb->
2547 CFL[i]);
2548 reiserfs_restore_prepared_buffer(p_s_tb->tb_sb,
2549 p_s_tb->
2550 CFR[i]);
2551 }
2552
2553 brelse(p_s_tb->L[i]);
2554 p_s_tb->L[i] = NULL;
2555 brelse(p_s_tb->R[i]);
2556 p_s_tb->R[i] = NULL;
2557 brelse(p_s_tb->FL[i]);
2558 p_s_tb->FL[i] = NULL;
2559 brelse(p_s_tb->FR[i]);
2560 p_s_tb->FR[i] = NULL;
2561 brelse(p_s_tb->CFL[i]);
2562 p_s_tb->CFL[i] = NULL;
2563 brelse(p_s_tb->CFR[i]);
2564 p_s_tb->CFR[i] = NULL;
2565 }
2566
2567 if (wait_tb_buffers_run) {
2568 for (i = 0; i < MAX_FEB_SIZE; i++) {
2569 if (p_s_tb->FEB[i]) {
2570 reiserfs_restore_prepared_buffer
2571 (p_s_tb->tb_sb, p_s_tb->FEB[i]);
2572 }
2573 }
2462 } 2574 }
2463 } 2575 return n_ret_value;
2464 } 2576 }
2465 return n_ret_value;
2466 }
2467 2577
2468} 2578}
2469 2579
2470
2471/* Anatoly will probably forgive me renaming p_s_tb to tb. I just 2580/* Anatoly will probably forgive me renaming p_s_tb to tb. I just
2472 wanted to make lines shorter */ 2581 wanted to make lines shorter */
2473void unfix_nodes (struct tree_balance * tb) 2582void unfix_nodes(struct tree_balance *tb)
2474{ 2583{
2475 int i; 2584 int i;
2476
2477 /* Release path buffers. */
2478 pathrelse_and_restore (tb->tb_sb, tb->tb_path);
2479
2480 /* brelse all resources collected for balancing */
2481 for ( i = 0; i < MAX_HEIGHT; i++ ) {
2482 reiserfs_restore_prepared_buffer (tb->tb_sb, tb->L[i]);
2483 reiserfs_restore_prepared_buffer (tb->tb_sb, tb->R[i]);
2484 reiserfs_restore_prepared_buffer (tb->tb_sb, tb->FL[i]);
2485 reiserfs_restore_prepared_buffer (tb->tb_sb, tb->FR[i]);
2486 reiserfs_restore_prepared_buffer (tb->tb_sb, tb->CFL[i]);
2487 reiserfs_restore_prepared_buffer (tb->tb_sb, tb->CFR[i]);
2488
2489 brelse (tb->L[i]);
2490 brelse (tb->R[i]);
2491 brelse (tb->FL[i]);
2492 brelse (tb->FR[i]);
2493 brelse (tb->CFL[i]);
2494 brelse (tb->CFR[i]);
2495 }
2496
2497 /* deal with list of allocated (used and unused) nodes */
2498 for ( i = 0; i < MAX_FEB_SIZE; i++ ) {
2499 if ( tb->FEB[i] ) {
2500 b_blocknr_t blocknr = tb->FEB[i]->b_blocknr ;
2501 /* de-allocated block which was not used by balancing and
2502 bforget about buffer for it */
2503 brelse (tb->FEB[i]);
2504 reiserfs_free_block (tb->transaction_handle, NULL, blocknr, 0);
2505 }
2506 if (tb->used[i]) {
2507 /* release used as new nodes including a new root */
2508 brelse (tb->used[i]);
2509 }
2510 }
2511 2585
2512 if (tb->vn_buf) 2586 /* Release path buffers. */
2513 reiserfs_kfree (tb->vn_buf, tb->vn_buf_size, tb->tb_sb); 2587 pathrelse_and_restore(tb->tb_sb, tb->tb_path);
2514 2588
2515} 2589 /* brelse all resources collected for balancing */
2590 for (i = 0; i < MAX_HEIGHT; i++) {
2591 reiserfs_restore_prepared_buffer(tb->tb_sb, tb->L[i]);
2592 reiserfs_restore_prepared_buffer(tb->tb_sb, tb->R[i]);
2593 reiserfs_restore_prepared_buffer(tb->tb_sb, tb->FL[i]);
2594 reiserfs_restore_prepared_buffer(tb->tb_sb, tb->FR[i]);
2595 reiserfs_restore_prepared_buffer(tb->tb_sb, tb->CFL[i]);
2596 reiserfs_restore_prepared_buffer(tb->tb_sb, tb->CFR[i]);
2597
2598 brelse(tb->L[i]);
2599 brelse(tb->R[i]);
2600 brelse(tb->FL[i]);
2601 brelse(tb->FR[i]);
2602 brelse(tb->CFL[i]);
2603 brelse(tb->CFR[i]);
2604 }
2516 2605
2606 /* deal with list of allocated (used and unused) nodes */
2607 for (i = 0; i < MAX_FEB_SIZE; i++) {
2608 if (tb->FEB[i]) {
2609 b_blocknr_t blocknr = tb->FEB[i]->b_blocknr;
2610 /* de-allocated block which was not used by balancing and
2611 bforget about buffer for it */
2612 brelse(tb->FEB[i]);
2613 reiserfs_free_block(tb->transaction_handle, NULL,
2614 blocknr, 0);
2615 }
2616 if (tb->used[i]) {
2617 /* release used as new nodes including a new root */
2618 brelse(tb->used[i]);
2619 }
2620 }
2517 2621
2622 if (tb->vn_buf)
2623 reiserfs_kfree(tb->vn_buf, tb->vn_buf_size, tb->tb_sb);
2518 2624
2625}
diff --git a/fs/reiserfs/hashes.c b/fs/reiserfs/hashes.c
index 08d0508c2d39..37c1306eb9b7 100644
--- a/fs/reiserfs/hashes.c
+++ b/fs/reiserfs/hashes.c
@@ -22,7 +22,6 @@
22#include <asm/types.h> 22#include <asm/types.h>
23#include <asm/bug.h> 23#include <asm/bug.h>
24 24
25
26#define DELTA 0x9E3779B9 25#define DELTA 0x9E3779B9
27#define FULLROUNDS 10 /* 32 is overkill, 16 is strong crypto */ 26#define FULLROUNDS 10 /* 32 is overkill, 16 is strong crypto */
28#define PARTROUNDS 6 /* 6 gets complete mixing */ 27#define PARTROUNDS 6 /* 6 gets complete mixing */
@@ -48,105 +47,75 @@
48 h1 += b1; \ 47 h1 += b1; \
49 } while(0) 48 } while(0)
50 49
51
52u32 keyed_hash(const signed char *msg, int len) 50u32 keyed_hash(const signed char *msg, int len)
53{ 51{
54 u32 k[] = { 0x9464a485, 0x542e1a94, 0x3e846bff, 0xb75bcfc3}; 52 u32 k[] = { 0x9464a485, 0x542e1a94, 0x3e846bff, 0xb75bcfc3 };
55 53
56 u32 h0 = k[0], h1 = k[1]; 54 u32 h0 = k[0], h1 = k[1];
57 u32 a, b, c, d; 55 u32 a, b, c, d;
58 u32 pad; 56 u32 pad;
59 int i; 57 int i;
60
61 // assert(len >= 0 && len < 256);
62 58
63 pad = (u32)len | ((u32)len << 8); 59 // assert(len >= 0 && len < 256);
60
61 pad = (u32) len | ((u32) len << 8);
64 pad |= pad << 16; 62 pad |= pad << 16;
65 63
66 while(len >= 16) 64 while (len >= 16) {
67 { 65 a = (u32) msg[0] |
68 a = (u32)msg[ 0] | 66 (u32) msg[1] << 8 | (u32) msg[2] << 16 | (u32) msg[3] << 24;
69 (u32)msg[ 1] << 8 | 67 b = (u32) msg[4] |
70 (u32)msg[ 2] << 16| 68 (u32) msg[5] << 8 | (u32) msg[6] << 16 | (u32) msg[7] << 24;
71 (u32)msg[ 3] << 24; 69 c = (u32) msg[8] |
72 b = (u32)msg[ 4] | 70 (u32) msg[9] << 8 |
73 (u32)msg[ 5] << 8 | 71 (u32) msg[10] << 16 | (u32) msg[11] << 24;
74 (u32)msg[ 6] << 16| 72 d = (u32) msg[12] |
75 (u32)msg[ 7] << 24; 73 (u32) msg[13] << 8 |
76 c = (u32)msg[ 8] | 74 (u32) msg[14] << 16 | (u32) msg[15] << 24;
77 (u32)msg[ 9] << 8 | 75
78 (u32)msg[10] << 16|
79 (u32)msg[11] << 24;
80 d = (u32)msg[12] |
81 (u32)msg[13] << 8 |
82 (u32)msg[14] << 16|
83 (u32)msg[15] << 24;
84
85 TEACORE(PARTROUNDS); 76 TEACORE(PARTROUNDS);
86 77
87 len -= 16; 78 len -= 16;
88 msg += 16; 79 msg += 16;
89 } 80 }
90 81
91 if (len >= 12) 82 if (len >= 12) {
92 { 83 a = (u32) msg[0] |
93 a = (u32)msg[ 0] | 84 (u32) msg[1] << 8 | (u32) msg[2] << 16 | (u32) msg[3] << 24;
94 (u32)msg[ 1] << 8 | 85 b = (u32) msg[4] |
95 (u32)msg[ 2] << 16| 86 (u32) msg[5] << 8 | (u32) msg[6] << 16 | (u32) msg[7] << 24;
96 (u32)msg[ 3] << 24; 87 c = (u32) msg[8] |
97 b = (u32)msg[ 4] | 88 (u32) msg[9] << 8 |
98 (u32)msg[ 5] << 8 | 89 (u32) msg[10] << 16 | (u32) msg[11] << 24;
99 (u32)msg[ 6] << 16|
100 (u32)msg[ 7] << 24;
101 c = (u32)msg[ 8] |
102 (u32)msg[ 9] << 8 |
103 (u32)msg[10] << 16|
104 (u32)msg[11] << 24;
105 90
106 d = pad; 91 d = pad;
107 for(i = 12; i < len; i++) 92 for (i = 12; i < len; i++) {
108 {
109 d <<= 8; 93 d <<= 8;
110 d |= msg[i]; 94 d |= msg[i];
111 } 95 }
112 } 96 } else if (len >= 8) {
113 else if (len >= 8) 97 a = (u32) msg[0] |
114 { 98 (u32) msg[1] << 8 | (u32) msg[2] << 16 | (u32) msg[3] << 24;
115 a = (u32)msg[ 0] | 99 b = (u32) msg[4] |
116 (u32)msg[ 1] << 8 | 100 (u32) msg[5] << 8 | (u32) msg[6] << 16 | (u32) msg[7] << 24;
117 (u32)msg[ 2] << 16|
118 (u32)msg[ 3] << 24;
119 b = (u32)msg[ 4] |
120 (u32)msg[ 5] << 8 |
121 (u32)msg[ 6] << 16|
122 (u32)msg[ 7] << 24;
123 101
124 c = d = pad; 102 c = d = pad;
125 for(i = 8; i < len; i++) 103 for (i = 8; i < len; i++) {
126 {
127 c <<= 8; 104 c <<= 8;
128 c |= msg[i]; 105 c |= msg[i];
129 } 106 }
130 } 107 } else if (len >= 4) {
131 else if (len >= 4) 108 a = (u32) msg[0] |
132 { 109 (u32) msg[1] << 8 | (u32) msg[2] << 16 | (u32) msg[3] << 24;
133 a = (u32)msg[ 0] |
134 (u32)msg[ 1] << 8 |
135 (u32)msg[ 2] << 16|
136 (u32)msg[ 3] << 24;
137 110
138 b = c = d = pad; 111 b = c = d = pad;
139 for(i = 4; i < len; i++) 112 for (i = 4; i < len; i++) {
140 {
141 b <<= 8; 113 b <<= 8;
142 b |= msg[i]; 114 b |= msg[i];
143 } 115 }
144 } 116 } else {
145 else
146 {
147 a = b = c = d = pad; 117 a = b = c = d = pad;
148 for(i = 0; i < len; i++) 118 for (i = 0; i < len; i++) {
149 {
150 a <<= 8; 119 a <<= 8;
151 a |= msg[i]; 120 a |= msg[i];
152 } 121 }
@@ -155,55 +124,59 @@ u32 keyed_hash(const signed char *msg, int len)
155 TEACORE(FULLROUNDS); 124 TEACORE(FULLROUNDS);
156 125
157/* return 0;*/ 126/* return 0;*/
158 return h0^h1; 127 return h0 ^ h1;
159} 128}
160 129
161/* What follows in this file is copyright 2000 by Hans Reiser, and the 130/* What follows in this file is copyright 2000 by Hans Reiser, and the
162 * licensing of what follows is governed by reiserfs/README */ 131 * licensing of what follows is governed by reiserfs/README */
163 132
164u32 yura_hash (const signed char *msg, int len) 133u32 yura_hash(const signed char *msg, int len)
165{ 134{
166 int j, pow; 135 int j, pow;
167 u32 a, c; 136 u32 a, c;
168 int i; 137 int i;
169 138
170 for (pow=1,i=1; i < len; i++) pow = pow * 10; 139 for (pow = 1, i = 1; i < len; i++)
171 140 pow = pow * 10;
172 if (len == 1) 141
173 a = msg[0]-48; 142 if (len == 1)
174 else 143 a = msg[0] - 48;
175 a = (msg[0] - 48) * pow; 144 else
176 145 a = (msg[0] - 48) * pow;
177 for (i=1; i < len; i++) { 146
178 c = msg[i] - 48; 147 for (i = 1; i < len; i++) {
179 for (pow=1,j=i; j < len-1; j++) pow = pow * 10; 148 c = msg[i] - 48;
180 a = a + c * pow; 149 for (pow = 1, j = i; j < len - 1; j++)
181 } 150 pow = pow * 10;
182 151 a = a + c * pow;
183 for (; i < 40; i++) { 152 }
184 c = '0' - 48; 153
185 for (pow=1,j=i; j < len-1; j++) pow = pow * 10; 154 for (; i < 40; i++) {
186 a = a + c * pow; 155 c = '0' - 48;
187 } 156 for (pow = 1, j = i; j < len - 1; j++)
188 157 pow = pow * 10;
189 for (; i < 256; i++) { 158 a = a + c * pow;
190 c = i; 159 }
191 for (pow=1,j=i; j < len-1; j++) pow = pow * 10; 160
192 a = a + c * pow; 161 for (; i < 256; i++) {
193 } 162 c = i;
194 163 for (pow = 1, j = i; j < len - 1; j++)
195 a = a << 7; 164 pow = pow * 10;
196 return a; 165 a = a + c * pow;
166 }
167
168 a = a << 7;
169 return a;
197} 170}
198 171
199u32 r5_hash (const signed char *msg, int len) 172u32 r5_hash(const signed char *msg, int len)
200{ 173{
201 u32 a=0; 174 u32 a = 0;
202 while(*msg) { 175 while (*msg) {
203 a += *msg << 4; 176 a += *msg << 4;
204 a += *msg >> 4; 177 a += *msg >> 4;
205 a *= 11; 178 a *= 11;
206 msg++; 179 msg++;
207 } 180 }
208 return a; 181 return a;
209} 182}
diff --git a/fs/reiserfs/ibalance.c b/fs/reiserfs/ibalance.c
index a362125da0d8..6c5a726fd34b 100644
--- a/fs/reiserfs/ibalance.c
+++ b/fs/reiserfs/ibalance.c
@@ -10,13 +10,8 @@
10#include <linux/buffer_head.h> 10#include <linux/buffer_head.h>
11 11
12/* this is one and only function that is used outside (do_balance.c) */ 12/* this is one and only function that is used outside (do_balance.c) */
13int balance_internal ( 13int balance_internal(struct tree_balance *,
14 struct tree_balance * , 14 int, int, struct item_head *, struct buffer_head **);
15 int,
16 int,
17 struct item_head * ,
18 struct buffer_head **
19 );
20 15
21/* modes of internal_shift_left, internal_shift_right and internal_insert_childs */ 16/* modes of internal_shift_left, internal_shift_right and internal_insert_childs */
22#define INTERNAL_SHIFT_FROM_S_TO_L 0 17#define INTERNAL_SHIFT_FROM_S_TO_L 0
@@ -27,464 +22,474 @@ int balance_internal (
27#define INTERNAL_INSERT_TO_L 5 22#define INTERNAL_INSERT_TO_L 5
28#define INTERNAL_INSERT_TO_R 6 23#define INTERNAL_INSERT_TO_R 6
29 24
30static void internal_define_dest_src_infos ( 25static void internal_define_dest_src_infos(int shift_mode,
31 int shift_mode, 26 struct tree_balance *tb,
32 struct tree_balance * tb, 27 int h,
33 int h, 28 struct buffer_info *dest_bi,
34 struct buffer_info * dest_bi, 29 struct buffer_info *src_bi,
35 struct buffer_info * src_bi, 30 int *d_key, struct buffer_head **cf)
36 int * d_key,
37 struct buffer_head ** cf
38 )
39{ 31{
40 memset (dest_bi, 0, sizeof (struct buffer_info)); 32 memset(dest_bi, 0, sizeof(struct buffer_info));
41 memset (src_bi, 0, sizeof (struct buffer_info)); 33 memset(src_bi, 0, sizeof(struct buffer_info));
42 /* define dest, src, dest parent, dest position */ 34 /* define dest, src, dest parent, dest position */
43 switch (shift_mode) { 35 switch (shift_mode) {
44 case INTERNAL_SHIFT_FROM_S_TO_L: /* used in internal_shift_left */ 36 case INTERNAL_SHIFT_FROM_S_TO_L: /* used in internal_shift_left */
45 src_bi->tb = tb; 37 src_bi->tb = tb;
46 src_bi->bi_bh = PATH_H_PBUFFER (tb->tb_path, h); 38 src_bi->bi_bh = PATH_H_PBUFFER(tb->tb_path, h);
47 src_bi->bi_parent = PATH_H_PPARENT (tb->tb_path, h); 39 src_bi->bi_parent = PATH_H_PPARENT(tb->tb_path, h);
48 src_bi->bi_position = PATH_H_POSITION (tb->tb_path, h + 1); 40 src_bi->bi_position = PATH_H_POSITION(tb->tb_path, h + 1);
49 dest_bi->tb = tb; 41 dest_bi->tb = tb;
50 dest_bi->bi_bh = tb->L[h]; 42 dest_bi->bi_bh = tb->L[h];
51 dest_bi->bi_parent = tb->FL[h]; 43 dest_bi->bi_parent = tb->FL[h];
52 dest_bi->bi_position = get_left_neighbor_position (tb, h); 44 dest_bi->bi_position = get_left_neighbor_position(tb, h);
53 *d_key = tb->lkey[h]; 45 *d_key = tb->lkey[h];
54 *cf = tb->CFL[h]; 46 *cf = tb->CFL[h];
55 break; 47 break;
56 case INTERNAL_SHIFT_FROM_L_TO_S: 48 case INTERNAL_SHIFT_FROM_L_TO_S:
57 src_bi->tb = tb; 49 src_bi->tb = tb;
58 src_bi->bi_bh = tb->L[h]; 50 src_bi->bi_bh = tb->L[h];
59 src_bi->bi_parent = tb->FL[h]; 51 src_bi->bi_parent = tb->FL[h];
60 src_bi->bi_position = get_left_neighbor_position (tb, h); 52 src_bi->bi_position = get_left_neighbor_position(tb, h);
61 dest_bi->tb = tb; 53 dest_bi->tb = tb;
62 dest_bi->bi_bh = PATH_H_PBUFFER (tb->tb_path, h); 54 dest_bi->bi_bh = PATH_H_PBUFFER(tb->tb_path, h);
63 dest_bi->bi_parent = PATH_H_PPARENT (tb->tb_path, h); 55 dest_bi->bi_parent = PATH_H_PPARENT(tb->tb_path, h);
64 dest_bi->bi_position = PATH_H_POSITION (tb->tb_path, h + 1); /* dest position is analog of dest->b_item_order */ 56 dest_bi->bi_position = PATH_H_POSITION(tb->tb_path, h + 1); /* dest position is analog of dest->b_item_order */
65 *d_key = tb->lkey[h]; 57 *d_key = tb->lkey[h];
66 *cf = tb->CFL[h]; 58 *cf = tb->CFL[h];
67 break; 59 break;
68 60
69 case INTERNAL_SHIFT_FROM_R_TO_S: /* used in internal_shift_left */ 61 case INTERNAL_SHIFT_FROM_R_TO_S: /* used in internal_shift_left */
70 src_bi->tb = tb; 62 src_bi->tb = tb;
71 src_bi->bi_bh = tb->R[h]; 63 src_bi->bi_bh = tb->R[h];
72 src_bi->bi_parent = tb->FR[h]; 64 src_bi->bi_parent = tb->FR[h];
73 src_bi->bi_position = get_right_neighbor_position (tb, h); 65 src_bi->bi_position = get_right_neighbor_position(tb, h);
74 dest_bi->tb = tb; 66 dest_bi->tb = tb;
75 dest_bi->bi_bh = PATH_H_PBUFFER (tb->tb_path, h); 67 dest_bi->bi_bh = PATH_H_PBUFFER(tb->tb_path, h);
76 dest_bi->bi_parent = PATH_H_PPARENT (tb->tb_path, h); 68 dest_bi->bi_parent = PATH_H_PPARENT(tb->tb_path, h);
77 dest_bi->bi_position = PATH_H_POSITION (tb->tb_path, h + 1); 69 dest_bi->bi_position = PATH_H_POSITION(tb->tb_path, h + 1);
78 *d_key = tb->rkey[h]; 70 *d_key = tb->rkey[h];
79 *cf = tb->CFR[h]; 71 *cf = tb->CFR[h];
80 break; 72 break;
81 73
82 case INTERNAL_SHIFT_FROM_S_TO_R: 74 case INTERNAL_SHIFT_FROM_S_TO_R:
83 src_bi->tb = tb; 75 src_bi->tb = tb;
84 src_bi->bi_bh = PATH_H_PBUFFER (tb->tb_path, h); 76 src_bi->bi_bh = PATH_H_PBUFFER(tb->tb_path, h);
85 src_bi->bi_parent = PATH_H_PPARENT (tb->tb_path, h); 77 src_bi->bi_parent = PATH_H_PPARENT(tb->tb_path, h);
86 src_bi->bi_position = PATH_H_POSITION (tb->tb_path, h + 1); 78 src_bi->bi_position = PATH_H_POSITION(tb->tb_path, h + 1);
87 dest_bi->tb = tb; 79 dest_bi->tb = tb;
88 dest_bi->bi_bh = tb->R[h]; 80 dest_bi->bi_bh = tb->R[h];
89 dest_bi->bi_parent = tb->FR[h]; 81 dest_bi->bi_parent = tb->FR[h];
90 dest_bi->bi_position = get_right_neighbor_position (tb, h); 82 dest_bi->bi_position = get_right_neighbor_position(tb, h);
91 *d_key = tb->rkey[h]; 83 *d_key = tb->rkey[h];
92 *cf = tb->CFR[h]; 84 *cf = tb->CFR[h];
93 break; 85 break;
94 86
95 case INTERNAL_INSERT_TO_L: 87 case INTERNAL_INSERT_TO_L:
96 dest_bi->tb = tb; 88 dest_bi->tb = tb;
97 dest_bi->bi_bh = tb->L[h]; 89 dest_bi->bi_bh = tb->L[h];
98 dest_bi->bi_parent = tb->FL[h]; 90 dest_bi->bi_parent = tb->FL[h];
99 dest_bi->bi_position = get_left_neighbor_position (tb, h); 91 dest_bi->bi_position = get_left_neighbor_position(tb, h);
100 break; 92 break;
101 93
102 case INTERNAL_INSERT_TO_S: 94 case INTERNAL_INSERT_TO_S:
103 dest_bi->tb = tb; 95 dest_bi->tb = tb;
104 dest_bi->bi_bh = PATH_H_PBUFFER (tb->tb_path, h); 96 dest_bi->bi_bh = PATH_H_PBUFFER(tb->tb_path, h);
105 dest_bi->bi_parent = PATH_H_PPARENT (tb->tb_path, h); 97 dest_bi->bi_parent = PATH_H_PPARENT(tb->tb_path, h);
106 dest_bi->bi_position = PATH_H_POSITION (tb->tb_path, h + 1); 98 dest_bi->bi_position = PATH_H_POSITION(tb->tb_path, h + 1);
107 break; 99 break;
108 100
109 case INTERNAL_INSERT_TO_R: 101 case INTERNAL_INSERT_TO_R:
110 dest_bi->tb = tb; 102 dest_bi->tb = tb;
111 dest_bi->bi_bh = tb->R[h]; 103 dest_bi->bi_bh = tb->R[h];
112 dest_bi->bi_parent = tb->FR[h]; 104 dest_bi->bi_parent = tb->FR[h];
113 dest_bi->bi_position = get_right_neighbor_position (tb, h); 105 dest_bi->bi_position = get_right_neighbor_position(tb, h);
114 break; 106 break;
115 107
116 default: 108 default:
117 reiserfs_panic (tb->tb_sb, "internal_define_dest_src_infos: shift type is unknown (%d)", shift_mode); 109 reiserfs_panic(tb->tb_sb,
118 } 110 "internal_define_dest_src_infos: shift type is unknown (%d)",
111 shift_mode);
112 }
119} 113}
120 114
121
122
123/* Insert count node pointers into buffer cur before position to + 1. 115/* Insert count node pointers into buffer cur before position to + 1.
124 * Insert count items into buffer cur before position to. 116 * Insert count items into buffer cur before position to.
125 * Items and node pointers are specified by inserted and bh respectively. 117 * Items and node pointers are specified by inserted and bh respectively.
126 */ 118 */
127static void internal_insert_childs (struct buffer_info * cur_bi, 119static void internal_insert_childs(struct buffer_info *cur_bi,
128 int to, int count, 120 int to, int count,
129 struct item_head * inserted, 121 struct item_head *inserted,
130 struct buffer_head ** bh 122 struct buffer_head **bh)
131 )
132{ 123{
133 struct buffer_head * cur = cur_bi->bi_bh; 124 struct buffer_head *cur = cur_bi->bi_bh;
134 struct block_head * blkh; 125 struct block_head *blkh;
135 int nr; 126 int nr;
136 struct reiserfs_key * ih; 127 struct reiserfs_key *ih;
137 struct disk_child new_dc[2]; 128 struct disk_child new_dc[2];
138 struct disk_child * dc; 129 struct disk_child *dc;
139 int i; 130 int i;
140 131
141 if (count <= 0) 132 if (count <= 0)
142 return; 133 return;
143 134
144 blkh = B_BLK_HEAD(cur); 135 blkh = B_BLK_HEAD(cur);
145 nr = blkh_nr_item(blkh); 136 nr = blkh_nr_item(blkh);
146 137
147 RFALSE( count > 2, 138 RFALSE(count > 2, "too many children (%d) are to be inserted", count);
148 "too many children (%d) are to be inserted", count); 139 RFALSE(B_FREE_SPACE(cur) < count * (KEY_SIZE + DC_SIZE),
149 RFALSE( B_FREE_SPACE (cur) < count * (KEY_SIZE + DC_SIZE), 140 "no enough free space (%d), needed %d bytes",
150 "no enough free space (%d), needed %d bytes", 141 B_FREE_SPACE(cur), count * (KEY_SIZE + DC_SIZE));
151 B_FREE_SPACE (cur), count * (KEY_SIZE + DC_SIZE)); 142
152 143 /* prepare space for count disk_child */
153 /* prepare space for count disk_child */ 144 dc = B_N_CHILD(cur, to + 1);
154 dc = B_N_CHILD(cur,to+1); 145
155 146 memmove(dc + count, dc, (nr + 1 - (to + 1)) * DC_SIZE);
156 memmove (dc + count, dc, (nr+1-(to+1)) * DC_SIZE); 147
157 148 /* copy to_be_insert disk children */
158 /* copy to_be_insert disk children */ 149 for (i = 0; i < count; i++) {
159 for (i = 0; i < count; i ++) { 150 put_dc_size(&(new_dc[i]),
160 put_dc_size( &(new_dc[i]), MAX_CHILD_SIZE(bh[i]) - B_FREE_SPACE(bh[i])); 151 MAX_CHILD_SIZE(bh[i]) - B_FREE_SPACE(bh[i]));
161 put_dc_block_number( &(new_dc[i]), bh[i]->b_blocknr ); 152 put_dc_block_number(&(new_dc[i]), bh[i]->b_blocknr);
162 } 153 }
163 memcpy (dc, new_dc, DC_SIZE * count); 154 memcpy(dc, new_dc, DC_SIZE * count);
164 155
165 156 /* prepare space for count items */
166 /* prepare space for count items */ 157 ih = B_N_PDELIM_KEY(cur, ((to == -1) ? 0 : to));
167 ih = B_N_PDELIM_KEY (cur, ((to == -1) ? 0 : to)); 158
168 159 memmove(ih + count, ih,
169 memmove (ih + count, ih, (nr - to) * KEY_SIZE + (nr + 1 + count) * DC_SIZE); 160 (nr - to) * KEY_SIZE + (nr + 1 + count) * DC_SIZE);
170 161
171 /* copy item headers (keys) */ 162 /* copy item headers (keys) */
172 memcpy (ih, inserted, KEY_SIZE); 163 memcpy(ih, inserted, KEY_SIZE);
173 if ( count > 1 ) 164 if (count > 1)
174 memcpy (ih + 1, inserted + 1, KEY_SIZE); 165 memcpy(ih + 1, inserted + 1, KEY_SIZE);
175 166
176 /* sizes, item number */ 167 /* sizes, item number */
177 set_blkh_nr_item( blkh, blkh_nr_item(blkh) + count ); 168 set_blkh_nr_item(blkh, blkh_nr_item(blkh) + count);
178 set_blkh_free_space( blkh, 169 set_blkh_free_space(blkh,
179 blkh_free_space(blkh) - count * (DC_SIZE + KEY_SIZE ) ); 170 blkh_free_space(blkh) - count * (DC_SIZE +
180 171 KEY_SIZE));
181 do_balance_mark_internal_dirty (cur_bi->tb, cur,0); 172
182 173 do_balance_mark_internal_dirty(cur_bi->tb, cur, 0);
183 /*&&&&&&&&&&&&&&&&&&&&&&&&*/ 174
184 check_internal (cur); 175 /*&&&&&&&&&&&&&&&&&&&&&&&& */
185 /*&&&&&&&&&&&&&&&&&&&&&&&&*/ 176 check_internal(cur);
186 177 /*&&&&&&&&&&&&&&&&&&&&&&&& */
187 if (cur_bi->bi_parent) { 178
188 struct disk_child *t_dc = B_N_CHILD (cur_bi->bi_parent,cur_bi->bi_position); 179 if (cur_bi->bi_parent) {
189 put_dc_size( t_dc, dc_size(t_dc) + (count * (DC_SIZE + KEY_SIZE))); 180 struct disk_child *t_dc =
190 do_balance_mark_internal_dirty(cur_bi->tb, cur_bi->bi_parent, 0); 181 B_N_CHILD(cur_bi->bi_parent, cur_bi->bi_position);
191 182 put_dc_size(t_dc,
192 /*&&&&&&&&&&&&&&&&&&&&&&&&*/ 183 dc_size(t_dc) + (count * (DC_SIZE + KEY_SIZE)));
193 check_internal (cur_bi->bi_parent); 184 do_balance_mark_internal_dirty(cur_bi->tb, cur_bi->bi_parent,
194 /*&&&&&&&&&&&&&&&&&&&&&&&&*/ 185 0);
195 } 186
187 /*&&&&&&&&&&&&&&&&&&&&&&&& */
188 check_internal(cur_bi->bi_parent);
189 /*&&&&&&&&&&&&&&&&&&&&&&&& */
190 }
196 191
197} 192}
198 193
199
200/* Delete del_num items and node pointers from buffer cur starting from * 194/* Delete del_num items and node pointers from buffer cur starting from *
201 * the first_i'th item and first_p'th pointers respectively. */ 195 * the first_i'th item and first_p'th pointers respectively. */
202static void internal_delete_pointers_items ( 196static void internal_delete_pointers_items(struct buffer_info *cur_bi,
203 struct buffer_info * cur_bi, 197 int first_p,
204 int first_p, 198 int first_i, int del_num)
205 int first_i,
206 int del_num
207 )
208{ 199{
209 struct buffer_head * cur = cur_bi->bi_bh; 200 struct buffer_head *cur = cur_bi->bi_bh;
210 int nr; 201 int nr;
211 struct block_head * blkh; 202 struct block_head *blkh;
212 struct reiserfs_key * key; 203 struct reiserfs_key *key;
213 struct disk_child * dc; 204 struct disk_child *dc;
214 205
215 RFALSE( cur == NULL, "buffer is 0"); 206 RFALSE(cur == NULL, "buffer is 0");
216 RFALSE( del_num < 0, 207 RFALSE(del_num < 0,
217 "negative number of items (%d) can not be deleted", del_num); 208 "negative number of items (%d) can not be deleted", del_num);
218 RFALSE( first_p < 0 || first_p + del_num > B_NR_ITEMS (cur) + 1 || first_i < 0, 209 RFALSE(first_p < 0 || first_p + del_num > B_NR_ITEMS(cur) + 1
219 "first pointer order (%d) < 0 or " 210 || first_i < 0,
220 "no so many pointers (%d), only (%d) or " 211 "first pointer order (%d) < 0 or "
221 "first key order %d < 0", first_p, 212 "no so many pointers (%d), only (%d) or "
222 first_p + del_num, B_NR_ITEMS (cur) + 1, first_i); 213 "first key order %d < 0", first_p, first_p + del_num,
223 if ( del_num == 0 ) 214 B_NR_ITEMS(cur) + 1, first_i);
224 return; 215 if (del_num == 0)
225 216 return;
226 blkh = B_BLK_HEAD(cur); 217
227 nr = blkh_nr_item(blkh); 218 blkh = B_BLK_HEAD(cur);
228 219 nr = blkh_nr_item(blkh);
229 if ( first_p == 0 && del_num == nr + 1 ) { 220
230 RFALSE( first_i != 0, "1st deleted key must have order 0, not %d", first_i); 221 if (first_p == 0 && del_num == nr + 1) {
231 make_empty_node (cur_bi); 222 RFALSE(first_i != 0,
232 return; 223 "1st deleted key must have order 0, not %d", first_i);
233 } 224 make_empty_node(cur_bi);
234 225 return;
235 RFALSE( first_i + del_num > B_NR_ITEMS (cur), 226 }
236 "first_i = %d del_num = %d "
237 "no so many keys (%d) in the node (%b)(%z)",
238 first_i, del_num, first_i + del_num, cur, cur);
239
240
241 /* deleting */
242 dc = B_N_CHILD (cur, first_p);
243
244 memmove (dc, dc + del_num, (nr + 1 - first_p - del_num) * DC_SIZE);
245 key = B_N_PDELIM_KEY (cur, first_i);
246 memmove (key, key + del_num, (nr - first_i - del_num) * KEY_SIZE + (nr + 1 - del_num) * DC_SIZE);
247
248
249 /* sizes, item number */
250 set_blkh_nr_item( blkh, blkh_nr_item(blkh) - del_num );
251 set_blkh_free_space( blkh,
252 blkh_free_space(blkh) + (del_num * (KEY_SIZE + DC_SIZE) ) );
253
254 do_balance_mark_internal_dirty (cur_bi->tb, cur, 0);
255 /*&&&&&&&&&&&&&&&&&&&&&&&*/
256 check_internal (cur);
257 /*&&&&&&&&&&&&&&&&&&&&&&&*/
258
259 if (cur_bi->bi_parent) {
260 struct disk_child *t_dc;
261 t_dc = B_N_CHILD (cur_bi->bi_parent, cur_bi->bi_position);
262 put_dc_size( t_dc, dc_size(t_dc) - (del_num * (KEY_SIZE + DC_SIZE) ) );
263
264 do_balance_mark_internal_dirty (cur_bi->tb, cur_bi->bi_parent,0);
265 /*&&&&&&&&&&&&&&&&&&&&&&&&*/
266 check_internal (cur_bi->bi_parent);
267 /*&&&&&&&&&&&&&&&&&&&&&&&&*/
268 }
269}
270 227
228 RFALSE(first_i + del_num > B_NR_ITEMS(cur),
229 "first_i = %d del_num = %d "
230 "no so many keys (%d) in the node (%b)(%z)",
231 first_i, del_num, first_i + del_num, cur, cur);
232
233 /* deleting */
234 dc = B_N_CHILD(cur, first_p);
235
236 memmove(dc, dc + del_num, (nr + 1 - first_p - del_num) * DC_SIZE);
237 key = B_N_PDELIM_KEY(cur, first_i);
238 memmove(key, key + del_num,
239 (nr - first_i - del_num) * KEY_SIZE + (nr + 1 -
240 del_num) * DC_SIZE);
241
242 /* sizes, item number */
243 set_blkh_nr_item(blkh, blkh_nr_item(blkh) - del_num);
244 set_blkh_free_space(blkh,
245 blkh_free_space(blkh) +
246 (del_num * (KEY_SIZE + DC_SIZE)));
247
248 do_balance_mark_internal_dirty(cur_bi->tb, cur, 0);
249 /*&&&&&&&&&&&&&&&&&&&&&&& */
250 check_internal(cur);
251 /*&&&&&&&&&&&&&&&&&&&&&&& */
252
253 if (cur_bi->bi_parent) {
254 struct disk_child *t_dc;
255 t_dc = B_N_CHILD(cur_bi->bi_parent, cur_bi->bi_position);
256 put_dc_size(t_dc,
257 dc_size(t_dc) - (del_num * (KEY_SIZE + DC_SIZE)));
258
259 do_balance_mark_internal_dirty(cur_bi->tb, cur_bi->bi_parent,
260 0);
261 /*&&&&&&&&&&&&&&&&&&&&&&&& */
262 check_internal(cur_bi->bi_parent);
263 /*&&&&&&&&&&&&&&&&&&&&&&&& */
264 }
265}
271 266
272/* delete n node pointers and items starting from given position */ 267/* delete n node pointers and items starting from given position */
273static void internal_delete_childs (struct buffer_info * cur_bi, 268static void internal_delete_childs(struct buffer_info *cur_bi, int from, int n)
274 int from, int n)
275{ 269{
276 int i_from; 270 int i_from;
277 271
278 i_from = (from == 0) ? from : from - 1; 272 i_from = (from == 0) ? from : from - 1;
279 273
280 /* delete n pointers starting from `from' position in CUR; 274 /* delete n pointers starting from `from' position in CUR;
281 delete n keys starting from 'i_from' position in CUR; 275 delete n keys starting from 'i_from' position in CUR;
282 */ 276 */
283 internal_delete_pointers_items (cur_bi, from, i_from, n); 277 internal_delete_pointers_items(cur_bi, from, i_from, n);
284} 278}
285 279
286
287/* copy cpy_num node pointers and cpy_num - 1 items from buffer src to buffer dest 280/* copy cpy_num node pointers and cpy_num - 1 items from buffer src to buffer dest
288* last_first == FIRST_TO_LAST means, that we copy first items from src to tail of dest 281* last_first == FIRST_TO_LAST means, that we copy first items from src to tail of dest
289 * last_first == LAST_TO_FIRST means, that we copy last items from src to head of dest 282 * last_first == LAST_TO_FIRST means, that we copy last items from src to head of dest
290 */ 283 */
291static void internal_copy_pointers_items ( 284static void internal_copy_pointers_items(struct buffer_info *dest_bi,
292 struct buffer_info * dest_bi, 285 struct buffer_head *src,
293 struct buffer_head * src, 286 int last_first, int cpy_num)
294 int last_first, int cpy_num
295 )
296{ 287{
297 /* ATTENTION! Number of node pointers in DEST is equal to number of items in DEST * 288 /* ATTENTION! Number of node pointers in DEST is equal to number of items in DEST *
298 * as delimiting key have already inserted to buffer dest.*/ 289 * as delimiting key have already inserted to buffer dest.*/
299 struct buffer_head * dest = dest_bi->bi_bh; 290 struct buffer_head *dest = dest_bi->bi_bh;
300 int nr_dest, nr_src; 291 int nr_dest, nr_src;
301 int dest_order, src_order; 292 int dest_order, src_order;
302 struct block_head * blkh; 293 struct block_head *blkh;
303 struct reiserfs_key * key; 294 struct reiserfs_key *key;
304 struct disk_child * dc; 295 struct disk_child *dc;
305 296
306 nr_src = B_NR_ITEMS (src); 297 nr_src = B_NR_ITEMS(src);
307 298
308 RFALSE( dest == NULL || src == NULL, 299 RFALSE(dest == NULL || src == NULL,
309 "src (%p) or dest (%p) buffer is 0", src, dest); 300 "src (%p) or dest (%p) buffer is 0", src, dest);
310 RFALSE( last_first != FIRST_TO_LAST && last_first != LAST_TO_FIRST, 301 RFALSE(last_first != FIRST_TO_LAST && last_first != LAST_TO_FIRST,
311 "invalid last_first parameter (%d)", last_first); 302 "invalid last_first parameter (%d)", last_first);
312 RFALSE( nr_src < cpy_num - 1, 303 RFALSE(nr_src < cpy_num - 1,
313 "no so many items (%d) in src (%d)", cpy_num, nr_src); 304 "no so many items (%d) in src (%d)", cpy_num, nr_src);
314 RFALSE( cpy_num < 0, "cpy_num less than 0 (%d)", cpy_num); 305 RFALSE(cpy_num < 0, "cpy_num less than 0 (%d)", cpy_num);
315 RFALSE( cpy_num - 1 + B_NR_ITEMS(dest) > (int)MAX_NR_KEY(dest), 306 RFALSE(cpy_num - 1 + B_NR_ITEMS(dest) > (int)MAX_NR_KEY(dest),
316 "cpy_num (%d) + item number in dest (%d) can not be > MAX_NR_KEY(%d)", 307 "cpy_num (%d) + item number in dest (%d) can not be > MAX_NR_KEY(%d)",
317 cpy_num, B_NR_ITEMS(dest), MAX_NR_KEY(dest)); 308 cpy_num, B_NR_ITEMS(dest), MAX_NR_KEY(dest));
318 309
319 if ( cpy_num == 0 ) 310 if (cpy_num == 0)
320 return; 311 return;
321 312
322 /* coping */ 313 /* coping */
323 blkh = B_BLK_HEAD(dest); 314 blkh = B_BLK_HEAD(dest);
324 nr_dest = blkh_nr_item(blkh); 315 nr_dest = blkh_nr_item(blkh);
325 316
326 /*dest_order = (last_first == LAST_TO_FIRST) ? 0 : nr_dest;*/ 317 /*dest_order = (last_first == LAST_TO_FIRST) ? 0 : nr_dest; */
327 /*src_order = (last_first == LAST_TO_FIRST) ? (nr_src - cpy_num + 1) : 0;*/ 318 /*src_order = (last_first == LAST_TO_FIRST) ? (nr_src - cpy_num + 1) : 0; */
328 (last_first == LAST_TO_FIRST) ? (dest_order = 0, src_order = nr_src - cpy_num + 1) : 319 (last_first == LAST_TO_FIRST) ? (dest_order = 0, src_order =
329 (dest_order = nr_dest, src_order = 0); 320 nr_src - cpy_num + 1) : (dest_order =
321 nr_dest,
322 src_order =
323 0);
330 324
331 /* prepare space for cpy_num pointers */ 325 /* prepare space for cpy_num pointers */
332 dc = B_N_CHILD (dest, dest_order); 326 dc = B_N_CHILD(dest, dest_order);
333 327
334 memmove (dc + cpy_num, dc, (nr_dest - dest_order) * DC_SIZE); 328 memmove(dc + cpy_num, dc, (nr_dest - dest_order) * DC_SIZE);
335 329
336 /* insert pointers */ 330 /* insert pointers */
337 memcpy (dc, B_N_CHILD (src, src_order), DC_SIZE * cpy_num); 331 memcpy(dc, B_N_CHILD(src, src_order), DC_SIZE * cpy_num);
338 332
339 333 /* prepare space for cpy_num - 1 item headers */
340 /* prepare space for cpy_num - 1 item headers */ 334 key = B_N_PDELIM_KEY(dest, dest_order);
341 key = B_N_PDELIM_KEY(dest, dest_order); 335 memmove(key + cpy_num - 1, key,
342 memmove (key + cpy_num - 1, key, 336 KEY_SIZE * (nr_dest - dest_order) + DC_SIZE * (nr_dest +
343 KEY_SIZE * (nr_dest - dest_order) + DC_SIZE * (nr_dest + cpy_num)); 337 cpy_num));
344 338
345 339 /* insert headers */
346 /* insert headers */ 340 memcpy(key, B_N_PDELIM_KEY(src, src_order), KEY_SIZE * (cpy_num - 1));
347 memcpy (key, B_N_PDELIM_KEY (src, src_order), KEY_SIZE * (cpy_num - 1)); 341
348 342 /* sizes, item number */
349 /* sizes, item number */ 343 set_blkh_nr_item(blkh, blkh_nr_item(blkh) + (cpy_num - 1));
350 set_blkh_nr_item( blkh, blkh_nr_item(blkh) + (cpy_num - 1 ) ); 344 set_blkh_free_space(blkh,
351 set_blkh_free_space( blkh, 345 blkh_free_space(blkh) - (KEY_SIZE * (cpy_num - 1) +
352 blkh_free_space(blkh) - (KEY_SIZE * (cpy_num - 1) + DC_SIZE * cpy_num ) ); 346 DC_SIZE * cpy_num));
353 347
354 do_balance_mark_internal_dirty (dest_bi->tb, dest, 0); 348 do_balance_mark_internal_dirty(dest_bi->tb, dest, 0);
355 349
356 /*&&&&&&&&&&&&&&&&&&&&&&&&*/ 350 /*&&&&&&&&&&&&&&&&&&&&&&&& */
357 check_internal (dest); 351 check_internal(dest);
358 /*&&&&&&&&&&&&&&&&&&&&&&&&*/ 352 /*&&&&&&&&&&&&&&&&&&&&&&&& */
359 353
360 if (dest_bi->bi_parent) { 354 if (dest_bi->bi_parent) {
361 struct disk_child *t_dc; 355 struct disk_child *t_dc;
362 t_dc = B_N_CHILD(dest_bi->bi_parent,dest_bi->bi_position); 356 t_dc = B_N_CHILD(dest_bi->bi_parent, dest_bi->bi_position);
363 put_dc_size( t_dc, dc_size(t_dc) + (KEY_SIZE * (cpy_num - 1) + DC_SIZE * cpy_num) ); 357 put_dc_size(t_dc,
364 358 dc_size(t_dc) + (KEY_SIZE * (cpy_num - 1) +
365 do_balance_mark_internal_dirty (dest_bi->tb, dest_bi->bi_parent,0); 359 DC_SIZE * cpy_num));
366 /*&&&&&&&&&&&&&&&&&&&&&&&&*/ 360
367 check_internal (dest_bi->bi_parent); 361 do_balance_mark_internal_dirty(dest_bi->tb, dest_bi->bi_parent,
368 /*&&&&&&&&&&&&&&&&&&&&&&&&*/ 362 0);
369 } 363 /*&&&&&&&&&&&&&&&&&&&&&&&& */
364 check_internal(dest_bi->bi_parent);
365 /*&&&&&&&&&&&&&&&&&&&&&&&& */
366 }
370 367
371} 368}
372 369
373
374/* Copy cpy_num node pointers and cpy_num - 1 items from buffer src to buffer dest. 370/* Copy cpy_num node pointers and cpy_num - 1 items from buffer src to buffer dest.
375 * Delete cpy_num - del_par items and node pointers from buffer src. 371 * Delete cpy_num - del_par items and node pointers from buffer src.
376 * last_first == FIRST_TO_LAST means, that we copy/delete first items from src. 372 * last_first == FIRST_TO_LAST means, that we copy/delete first items from src.
377 * last_first == LAST_TO_FIRST means, that we copy/delete last items from src. 373 * last_first == LAST_TO_FIRST means, that we copy/delete last items from src.
378 */ 374 */
379static void internal_move_pointers_items (struct buffer_info * dest_bi, 375static void internal_move_pointers_items(struct buffer_info *dest_bi,
380 struct buffer_info * src_bi, 376 struct buffer_info *src_bi,
381 int last_first, int cpy_num, int del_par) 377 int last_first, int cpy_num,
378 int del_par)
382{ 379{
383 int first_pointer; 380 int first_pointer;
384 int first_item; 381 int first_item;
385 382
386 internal_copy_pointers_items (dest_bi, src_bi->bi_bh, last_first, cpy_num); 383 internal_copy_pointers_items(dest_bi, src_bi->bi_bh, last_first,
387 384 cpy_num);
388 if (last_first == FIRST_TO_LAST) { /* shift_left occurs */ 385
389 first_pointer = 0; 386 if (last_first == FIRST_TO_LAST) { /* shift_left occurs */
390 first_item = 0; 387 first_pointer = 0;
391 /* delete cpy_num - del_par pointers and keys starting for pointers with first_pointer, 388 first_item = 0;
392 for key - with first_item */ 389 /* delete cpy_num - del_par pointers and keys starting for pointers with first_pointer,
393 internal_delete_pointers_items (src_bi, first_pointer, first_item, cpy_num - del_par); 390 for key - with first_item */
394 } else { /* shift_right occurs */ 391 internal_delete_pointers_items(src_bi, first_pointer,
395 int i, j; 392 first_item, cpy_num - del_par);
396 393 } else { /* shift_right occurs */
397 i = ( cpy_num - del_par == ( j = B_NR_ITEMS(src_bi->bi_bh)) + 1 ) ? 0 : j - cpy_num + del_par; 394 int i, j;
398 395
399 internal_delete_pointers_items (src_bi, j + 1 - cpy_num + del_par, i, cpy_num - del_par); 396 i = (cpy_num - del_par ==
400 } 397 (j =
398 B_NR_ITEMS(src_bi->bi_bh)) + 1) ? 0 : j - cpy_num +
399 del_par;
400
401 internal_delete_pointers_items(src_bi,
402 j + 1 - cpy_num + del_par, i,
403 cpy_num - del_par);
404 }
401} 405}
402 406
403/* Insert n_src'th key of buffer src before n_dest'th key of buffer dest. */ 407/* Insert n_src'th key of buffer src before n_dest'th key of buffer dest. */
404static void internal_insert_key (struct buffer_info * dest_bi, 408static void internal_insert_key(struct buffer_info *dest_bi, int dest_position_before, /* insert key before key with n_dest number */
405 int dest_position_before, /* insert key before key with n_dest number */ 409 struct buffer_head *src, int src_position)
406 struct buffer_head * src,
407 int src_position)
408{ 410{
409 struct buffer_head * dest = dest_bi->bi_bh; 411 struct buffer_head *dest = dest_bi->bi_bh;
410 int nr; 412 int nr;
411 struct block_head * blkh; 413 struct block_head *blkh;
412 struct reiserfs_key * key; 414 struct reiserfs_key *key;
413 415
414 RFALSE( dest == NULL || src == NULL, 416 RFALSE(dest == NULL || src == NULL,
415 "source(%p) or dest(%p) buffer is 0", src, dest); 417 "source(%p) or dest(%p) buffer is 0", src, dest);
416 RFALSE( dest_position_before < 0 || src_position < 0, 418 RFALSE(dest_position_before < 0 || src_position < 0,
417 "source(%d) or dest(%d) key number less than 0", 419 "source(%d) or dest(%d) key number less than 0",
418 src_position, dest_position_before); 420 src_position, dest_position_before);
419 RFALSE( dest_position_before > B_NR_ITEMS (dest) || 421 RFALSE(dest_position_before > B_NR_ITEMS(dest) ||
420 src_position >= B_NR_ITEMS(src), 422 src_position >= B_NR_ITEMS(src),
421 "invalid position in dest (%d (key number %d)) or in src (%d (key number %d))", 423 "invalid position in dest (%d (key number %d)) or in src (%d (key number %d))",
422 dest_position_before, B_NR_ITEMS (dest), 424 dest_position_before, B_NR_ITEMS(dest),
423 src_position, B_NR_ITEMS(src)); 425 src_position, B_NR_ITEMS(src));
424 RFALSE( B_FREE_SPACE (dest) < KEY_SIZE, 426 RFALSE(B_FREE_SPACE(dest) < KEY_SIZE,
425 "no enough free space (%d) in dest buffer", B_FREE_SPACE (dest)); 427 "no enough free space (%d) in dest buffer", B_FREE_SPACE(dest));
426 428
427 blkh = B_BLK_HEAD(dest); 429 blkh = B_BLK_HEAD(dest);
428 nr = blkh_nr_item(blkh); 430 nr = blkh_nr_item(blkh);
429 431
430 /* prepare space for inserting key */ 432 /* prepare space for inserting key */
431 key = B_N_PDELIM_KEY (dest, dest_position_before); 433 key = B_N_PDELIM_KEY(dest, dest_position_before);
432 memmove (key + 1, key, (nr - dest_position_before) * KEY_SIZE + (nr + 1) * DC_SIZE); 434 memmove(key + 1, key,
433 435 (nr - dest_position_before) * KEY_SIZE + (nr + 1) * DC_SIZE);
434 /* insert key */ 436
435 memcpy (key, B_N_PDELIM_KEY(src, src_position), KEY_SIZE); 437 /* insert key */
436 438 memcpy(key, B_N_PDELIM_KEY(src, src_position), KEY_SIZE);
437 /* Change dirt, free space, item number fields. */ 439
438 440 /* Change dirt, free space, item number fields. */
439 set_blkh_nr_item( blkh, blkh_nr_item(blkh) + 1 ); 441
440 set_blkh_free_space( blkh, blkh_free_space(blkh) - KEY_SIZE ); 442 set_blkh_nr_item(blkh, blkh_nr_item(blkh) + 1);
441 443 set_blkh_free_space(blkh, blkh_free_space(blkh) - KEY_SIZE);
442 do_balance_mark_internal_dirty (dest_bi->tb, dest, 0); 444
443 445 do_balance_mark_internal_dirty(dest_bi->tb, dest, 0);
444 if (dest_bi->bi_parent) { 446
445 struct disk_child *t_dc; 447 if (dest_bi->bi_parent) {
446 t_dc = B_N_CHILD(dest_bi->bi_parent,dest_bi->bi_position); 448 struct disk_child *t_dc;
447 put_dc_size( t_dc, dc_size(t_dc) + KEY_SIZE ); 449 t_dc = B_N_CHILD(dest_bi->bi_parent, dest_bi->bi_position);
448 450 put_dc_size(t_dc, dc_size(t_dc) + KEY_SIZE);
449 do_balance_mark_internal_dirty (dest_bi->tb, dest_bi->bi_parent,0); 451
450 } 452 do_balance_mark_internal_dirty(dest_bi->tb, dest_bi->bi_parent,
453 0);
454 }
451} 455}
452 456
453
454
455/* Insert d_key'th (delimiting) key from buffer cfl to tail of dest. 457/* Insert d_key'th (delimiting) key from buffer cfl to tail of dest.
456 * Copy pointer_amount node pointers and pointer_amount - 1 items from buffer src to buffer dest. 458 * Copy pointer_amount node pointers and pointer_amount - 1 items from buffer src to buffer dest.
457 * Replace d_key'th key in buffer cfl. 459 * Replace d_key'th key in buffer cfl.
458 * Delete pointer_amount items and node pointers from buffer src. 460 * Delete pointer_amount items and node pointers from buffer src.
459 */ 461 */
460/* this can be invoked both to shift from S to L and from R to S */ 462/* this can be invoked both to shift from S to L and from R to S */
461static void internal_shift_left ( 463static void internal_shift_left(int mode, /* INTERNAL_FROM_S_TO_L | INTERNAL_FROM_R_TO_S */
462 int mode, /* INTERNAL_FROM_S_TO_L | INTERNAL_FROM_R_TO_S */ 464 struct tree_balance *tb,
463 struct tree_balance * tb, 465 int h, int pointer_amount)
464 int h,
465 int pointer_amount
466 )
467{ 466{
468 struct buffer_info dest_bi, src_bi; 467 struct buffer_info dest_bi, src_bi;
469 struct buffer_head * cf; 468 struct buffer_head *cf;
470 int d_key_position; 469 int d_key_position;
471 470
472 internal_define_dest_src_infos (mode, tb, h, &dest_bi, &src_bi, &d_key_position, &cf); 471 internal_define_dest_src_infos(mode, tb, h, &dest_bi, &src_bi,
473 472 &d_key_position, &cf);
474 /*printk("pointer_amount = %d\n",pointer_amount);*/ 473
475 474 /*printk("pointer_amount = %d\n",pointer_amount); */
476 if (pointer_amount) { 475
477 /* insert delimiting key from common father of dest and src to node dest into position B_NR_ITEM(dest) */ 476 if (pointer_amount) {
478 internal_insert_key (&dest_bi, B_NR_ITEMS(dest_bi.bi_bh), cf, d_key_position); 477 /* insert delimiting key from common father of dest and src to node dest into position B_NR_ITEM(dest) */
479 478 internal_insert_key(&dest_bi, B_NR_ITEMS(dest_bi.bi_bh), cf,
480 if (B_NR_ITEMS(src_bi.bi_bh) == pointer_amount - 1) { 479 d_key_position);
481 if (src_bi.bi_position/*src->b_item_order*/ == 0) 480
482 replace_key (tb, cf, d_key_position, src_bi.bi_parent/*src->b_parent*/, 0); 481 if (B_NR_ITEMS(src_bi.bi_bh) == pointer_amount - 1) {
483 } else 482 if (src_bi.bi_position /*src->b_item_order */ == 0)
484 replace_key (tb, cf, d_key_position, src_bi.bi_bh, pointer_amount - 1); 483 replace_key(tb, cf, d_key_position,
485 } 484 src_bi.
486 /* last parameter is del_parameter */ 485 bi_parent /*src->b_parent */ , 0);
487 internal_move_pointers_items (&dest_bi, &src_bi, FIRST_TO_LAST, pointer_amount, 0); 486 } else
487 replace_key(tb, cf, d_key_position, src_bi.bi_bh,
488 pointer_amount - 1);
489 }
490 /* last parameter is del_parameter */
491 internal_move_pointers_items(&dest_bi, &src_bi, FIRST_TO_LAST,
492 pointer_amount, 0);
488 493
489} 494}
490 495
@@ -493,67 +498,66 @@ static void internal_shift_left (
493 * Delete n - 1 items and node pointers from buffer S[h]. 498 * Delete n - 1 items and node pointers from buffer S[h].
494 */ 499 */
495/* it always shifts from S[h] to L[h] */ 500/* it always shifts from S[h] to L[h] */
496static void internal_shift1_left ( 501static void internal_shift1_left(struct tree_balance *tb,
497 struct tree_balance * tb, 502 int h, int pointer_amount)
498 int h,
499 int pointer_amount
500 )
501{ 503{
502 struct buffer_info dest_bi, src_bi; 504 struct buffer_info dest_bi, src_bi;
503 struct buffer_head * cf; 505 struct buffer_head *cf;
504 int d_key_position; 506 int d_key_position;
505 507
506 internal_define_dest_src_infos (INTERNAL_SHIFT_FROM_S_TO_L, tb, h, &dest_bi, &src_bi, &d_key_position, &cf); 508 internal_define_dest_src_infos(INTERNAL_SHIFT_FROM_S_TO_L, tb, h,
509 &dest_bi, &src_bi, &d_key_position, &cf);
507 510
508 if ( pointer_amount > 0 ) /* insert lkey[h]-th key from CFL[h] to left neighbor L[h] */ 511 if (pointer_amount > 0) /* insert lkey[h]-th key from CFL[h] to left neighbor L[h] */
509 internal_insert_key (&dest_bi, B_NR_ITEMS(dest_bi.bi_bh), cf, d_key_position); 512 internal_insert_key(&dest_bi, B_NR_ITEMS(dest_bi.bi_bh), cf,
510 /* internal_insert_key (tb->L[h], B_NR_ITEM(tb->L[h]), tb->CFL[h], tb->lkey[h]);*/ 513 d_key_position);
514 /* internal_insert_key (tb->L[h], B_NR_ITEM(tb->L[h]), tb->CFL[h], tb->lkey[h]); */
511 515
512 /* last parameter is del_parameter */ 516 /* last parameter is del_parameter */
513 internal_move_pointers_items (&dest_bi, &src_bi, FIRST_TO_LAST, pointer_amount, 1); 517 internal_move_pointers_items(&dest_bi, &src_bi, FIRST_TO_LAST,
514 /* internal_move_pointers_items (tb->L[h], tb->S[h], FIRST_TO_LAST, pointer_amount, 1);*/ 518 pointer_amount, 1);
519 /* internal_move_pointers_items (tb->L[h], tb->S[h], FIRST_TO_LAST, pointer_amount, 1); */
515} 520}
516 521
517
518/* Insert d_key'th (delimiting) key from buffer cfr to head of dest. 522/* Insert d_key'th (delimiting) key from buffer cfr to head of dest.
519 * Copy n node pointers and n - 1 items from buffer src to buffer dest. 523 * Copy n node pointers and n - 1 items from buffer src to buffer dest.
520 * Replace d_key'th key in buffer cfr. 524 * Replace d_key'th key in buffer cfr.
521 * Delete n items and node pointers from buffer src. 525 * Delete n items and node pointers from buffer src.
522 */ 526 */
523static void internal_shift_right ( 527static void internal_shift_right(int mode, /* INTERNAL_FROM_S_TO_R | INTERNAL_FROM_L_TO_S */
524 int mode, /* INTERNAL_FROM_S_TO_R | INTERNAL_FROM_L_TO_S */ 528 struct tree_balance *tb,
525 struct tree_balance * tb, 529 int h, int pointer_amount)
526 int h,
527 int pointer_amount
528 )
529{ 530{
530 struct buffer_info dest_bi, src_bi; 531 struct buffer_info dest_bi, src_bi;
531 struct buffer_head * cf; 532 struct buffer_head *cf;
532 int d_key_position; 533 int d_key_position;
533 int nr; 534 int nr;
534 535
535 536 internal_define_dest_src_infos(mode, tb, h, &dest_bi, &src_bi,
536 internal_define_dest_src_infos (mode, tb, h, &dest_bi, &src_bi, &d_key_position, &cf); 537 &d_key_position, &cf);
537 538
538 nr = B_NR_ITEMS (src_bi.bi_bh); 539 nr = B_NR_ITEMS(src_bi.bi_bh);
539 540
540 if (pointer_amount > 0) { 541 if (pointer_amount > 0) {
541 /* insert delimiting key from common father of dest and src to dest node into position 0 */ 542 /* insert delimiting key from common father of dest and src to dest node into position 0 */
542 internal_insert_key (&dest_bi, 0, cf, d_key_position); 543 internal_insert_key(&dest_bi, 0, cf, d_key_position);
543 if (nr == pointer_amount - 1) { 544 if (nr == pointer_amount - 1) {
544 RFALSE( src_bi.bi_bh != PATH_H_PBUFFER (tb->tb_path, h)/*tb->S[h]*/ || 545 RFALSE(src_bi.bi_bh != PATH_H_PBUFFER(tb->tb_path, h) /*tb->S[h] */ ||
545 dest_bi.bi_bh != tb->R[h], 546 dest_bi.bi_bh != tb->R[h],
546 "src (%p) must be == tb->S[h](%p) when it disappears", 547 "src (%p) must be == tb->S[h](%p) when it disappears",
547 src_bi.bi_bh, PATH_H_PBUFFER (tb->tb_path, h)); 548 src_bi.bi_bh, PATH_H_PBUFFER(tb->tb_path, h));
548 /* when S[h] disappers replace left delemiting key as well */ 549 /* when S[h] disappers replace left delemiting key as well */
549 if (tb->CFL[h]) 550 if (tb->CFL[h])
550 replace_key (tb, cf, d_key_position, tb->CFL[h], tb->lkey[h]); 551 replace_key(tb, cf, d_key_position, tb->CFL[h],
551 } else 552 tb->lkey[h]);
552 replace_key (tb, cf, d_key_position, src_bi.bi_bh, nr - pointer_amount); 553 } else
553 } 554 replace_key(tb, cf, d_key_position, src_bi.bi_bh,
554 555 nr - pointer_amount);
555 /* last parameter is del_parameter */ 556 }
556 internal_move_pointers_items (&dest_bi, &src_bi, LAST_TO_FIRST, pointer_amount, 0); 557
558 /* last parameter is del_parameter */
559 internal_move_pointers_items(&dest_bi, &src_bi, LAST_TO_FIRST,
560 pointer_amount, 0);
557} 561}
558 562
559/* Insert delimiting key to R[h]. 563/* Insert delimiting key to R[h].
@@ -561,498 +565,526 @@ static void internal_shift_right (
561 * Delete n - 1 items and node pointers from buffer S[h]. 565 * Delete n - 1 items and node pointers from buffer S[h].
562 */ 566 */
563/* it always shift from S[h] to R[h] */ 567/* it always shift from S[h] to R[h] */
564static void internal_shift1_right ( 568static void internal_shift1_right(struct tree_balance *tb,
565 struct tree_balance * tb, 569 int h, int pointer_amount)
566 int h,
567 int pointer_amount
568 )
569{ 570{
570 struct buffer_info dest_bi, src_bi; 571 struct buffer_info dest_bi, src_bi;
571 struct buffer_head * cf; 572 struct buffer_head *cf;
572 int d_key_position; 573 int d_key_position;
573 574
574 internal_define_dest_src_infos (INTERNAL_SHIFT_FROM_S_TO_R, tb, h, &dest_bi, &src_bi, &d_key_position, &cf); 575 internal_define_dest_src_infos(INTERNAL_SHIFT_FROM_S_TO_R, tb, h,
575 576 &dest_bi, &src_bi, &d_key_position, &cf);
576 if (pointer_amount > 0) /* insert rkey from CFR[h] to right neighbor R[h] */ 577
577 internal_insert_key (&dest_bi, 0, cf, d_key_position); 578 if (pointer_amount > 0) /* insert rkey from CFR[h] to right neighbor R[h] */
578 /* internal_insert_key (tb->R[h], 0, tb->CFR[h], tb->rkey[h]);*/ 579 internal_insert_key(&dest_bi, 0, cf, d_key_position);
579 580 /* internal_insert_key (tb->R[h], 0, tb->CFR[h], tb->rkey[h]); */
580 /* last parameter is del_parameter */
581 internal_move_pointers_items (&dest_bi, &src_bi, LAST_TO_FIRST, pointer_amount, 1);
582 /* internal_move_pointers_items (tb->R[h], tb->S[h], LAST_TO_FIRST, pointer_amount, 1);*/
583}
584 581
582 /* last parameter is del_parameter */
583 internal_move_pointers_items(&dest_bi, &src_bi, LAST_TO_FIRST,
584 pointer_amount, 1);
585 /* internal_move_pointers_items (tb->R[h], tb->S[h], LAST_TO_FIRST, pointer_amount, 1); */
586}
585 587
586/* Delete insert_num node pointers together with their left items 588/* Delete insert_num node pointers together with their left items
587 * and balance current node.*/ 589 * and balance current node.*/
588static void balance_internal_when_delete (struct tree_balance * tb, 590static void balance_internal_when_delete(struct tree_balance *tb,
589 int h, int child_pos) 591 int h, int child_pos)
590{ 592{
591 int insert_num; 593 int insert_num;
592 int n; 594 int n;
593 struct buffer_head * tbSh = PATH_H_PBUFFER (tb->tb_path, h); 595 struct buffer_head *tbSh = PATH_H_PBUFFER(tb->tb_path, h);
594 struct buffer_info bi; 596 struct buffer_info bi;
595 597
596 insert_num = tb->insert_size[h] / ((int)(DC_SIZE + KEY_SIZE)); 598 insert_num = tb->insert_size[h] / ((int)(DC_SIZE + KEY_SIZE));
597 599
598 /* delete child-node-pointer(s) together with their left item(s) */ 600 /* delete child-node-pointer(s) together with their left item(s) */
599 bi.tb = tb; 601 bi.tb = tb;
600 bi.bi_bh = tbSh; 602 bi.bi_bh = tbSh;
601 bi.bi_parent = PATH_H_PPARENT (tb->tb_path, h); 603 bi.bi_parent = PATH_H_PPARENT(tb->tb_path, h);
602 bi.bi_position = PATH_H_POSITION (tb->tb_path, h + 1); 604 bi.bi_position = PATH_H_POSITION(tb->tb_path, h + 1);
603 605
604 internal_delete_childs (&bi, child_pos, -insert_num); 606 internal_delete_childs(&bi, child_pos, -insert_num);
605 607
606 RFALSE( tb->blknum[h] > 1, 608 RFALSE(tb->blknum[h] > 1,
607 "tb->blknum[%d]=%d when insert_size < 0", h, tb->blknum[h]); 609 "tb->blknum[%d]=%d when insert_size < 0", h, tb->blknum[h]);
608 610
609 n = B_NR_ITEMS(tbSh); 611 n = B_NR_ITEMS(tbSh);
610 612
611 if ( tb->lnum[h] == 0 && tb->rnum[h] == 0 ) { 613 if (tb->lnum[h] == 0 && tb->rnum[h] == 0) {
612 if ( tb->blknum[h] == 0 ) { 614 if (tb->blknum[h] == 0) {
613 /* node S[h] (root of the tree) is empty now */ 615 /* node S[h] (root of the tree) is empty now */
614 struct buffer_head *new_root; 616 struct buffer_head *new_root;
615 617
616 RFALSE( n || B_FREE_SPACE (tbSh) != MAX_CHILD_SIZE(tbSh) - DC_SIZE, 618 RFALSE(n
617 "buffer must have only 0 keys (%d)", n); 619 || B_FREE_SPACE(tbSh) !=
618 RFALSE( bi.bi_parent, "root has parent (%p)", bi.bi_parent); 620 MAX_CHILD_SIZE(tbSh) - DC_SIZE,
619 621 "buffer must have only 0 keys (%d)", n);
620 /* choose a new root */ 622 RFALSE(bi.bi_parent, "root has parent (%p)",
621 if ( ! tb->L[h-1] || ! B_NR_ITEMS(tb->L[h-1]) ) 623 bi.bi_parent);
622 new_root = tb->R[h-1]; 624
623 else 625 /* choose a new root */
624 new_root = tb->L[h-1]; 626 if (!tb->L[h - 1] || !B_NR_ITEMS(tb->L[h - 1]))
625 /* switch super block's tree root block number to the new value */ 627 new_root = tb->R[h - 1];
626 PUT_SB_ROOT_BLOCK( tb->tb_sb, new_root->b_blocknr ); 628 else
627 //REISERFS_SB(tb->tb_sb)->s_rs->s_tree_height --; 629 new_root = tb->L[h - 1];
628 PUT_SB_TREE_HEIGHT( tb->tb_sb, SB_TREE_HEIGHT(tb->tb_sb) - 1 ); 630 /* switch super block's tree root block number to the new value */
629 631 PUT_SB_ROOT_BLOCK(tb->tb_sb, new_root->b_blocknr);
630 do_balance_mark_sb_dirty (tb, REISERFS_SB(tb->tb_sb)->s_sbh, 1); 632 //REISERFS_SB(tb->tb_sb)->s_rs->s_tree_height --;
631 /*&&&&&&&&&&&&&&&&&&&&&&*/ 633 PUT_SB_TREE_HEIGHT(tb->tb_sb,
632 if (h > 1) 634 SB_TREE_HEIGHT(tb->tb_sb) - 1);
633 /* use check_internal if new root is an internal node */ 635
634 check_internal (new_root); 636 do_balance_mark_sb_dirty(tb,
635 /*&&&&&&&&&&&&&&&&&&&&&&*/ 637 REISERFS_SB(tb->tb_sb)->s_sbh,
636 638 1);
637 /* do what is needed for buffer thrown from tree */ 639 /*&&&&&&&&&&&&&&&&&&&&&& */
638 reiserfs_invalidate_buffer(tb, tbSh); 640 if (h > 1)
639 return; 641 /* use check_internal if new root is an internal node */
642 check_internal(new_root);
643 /*&&&&&&&&&&&&&&&&&&&&&& */
644
645 /* do what is needed for buffer thrown from tree */
646 reiserfs_invalidate_buffer(tb, tbSh);
647 return;
648 }
649 return;
650 }
651
652 if (tb->L[h] && tb->lnum[h] == -B_NR_ITEMS(tb->L[h]) - 1) { /* join S[h] with L[h] */
653
654 RFALSE(tb->rnum[h] != 0,
655 "invalid tb->rnum[%d]==%d when joining S[h] with L[h]",
656 h, tb->rnum[h]);
657
658 internal_shift_left(INTERNAL_SHIFT_FROM_S_TO_L, tb, h, n + 1);
659 reiserfs_invalidate_buffer(tb, tbSh);
660
661 return;
662 }
663
664 if (tb->R[h] && tb->rnum[h] == -B_NR_ITEMS(tb->R[h]) - 1) { /* join S[h] with R[h] */
665 RFALSE(tb->lnum[h] != 0,
666 "invalid tb->lnum[%d]==%d when joining S[h] with R[h]",
667 h, tb->lnum[h]);
668
669 internal_shift_right(INTERNAL_SHIFT_FROM_S_TO_R, tb, h, n + 1);
670
671 reiserfs_invalidate_buffer(tb, tbSh);
672 return;
640 } 673 }
641 return;
642 }
643
644 if ( tb->L[h] && tb->lnum[h] == -B_NR_ITEMS(tb->L[h]) - 1 ) { /* join S[h] with L[h] */
645
646 RFALSE( tb->rnum[h] != 0,
647 "invalid tb->rnum[%d]==%d when joining S[h] with L[h]",
648 h, tb->rnum[h]);
649
650 internal_shift_left (INTERNAL_SHIFT_FROM_S_TO_L, tb, h, n + 1);
651 reiserfs_invalidate_buffer(tb, tbSh);
652
653 return;
654 }
655
656 if ( tb->R[h] && tb->rnum[h] == -B_NR_ITEMS(tb->R[h]) - 1 ) { /* join S[h] with R[h] */
657 RFALSE( tb->lnum[h] != 0,
658 "invalid tb->lnum[%d]==%d when joining S[h] with R[h]",
659 h, tb->lnum[h]);
660
661 internal_shift_right (INTERNAL_SHIFT_FROM_S_TO_R, tb, h, n + 1);
662
663 reiserfs_invalidate_buffer(tb,tbSh);
664 return;
665 }
666
667 if ( tb->lnum[h] < 0 ) { /* borrow from left neighbor L[h] */
668 RFALSE( tb->rnum[h] != 0,
669 "wrong tb->rnum[%d]==%d when borrow from L[h]", h, tb->rnum[h]);
670 /*internal_shift_right (tb, h, tb->L[h], tb->CFL[h], tb->lkey[h], tb->S[h], -tb->lnum[h]);*/
671 internal_shift_right (INTERNAL_SHIFT_FROM_L_TO_S, tb, h, -tb->lnum[h]);
672 return;
673 }
674
675 if ( tb->rnum[h] < 0 ) { /* borrow from right neighbor R[h] */
676 RFALSE( tb->lnum[h] != 0,
677 "invalid tb->lnum[%d]==%d when borrow from R[h]",
678 h, tb->lnum[h]);
679 internal_shift_left (INTERNAL_SHIFT_FROM_R_TO_S, tb, h, -tb->rnum[h]);/*tb->S[h], tb->CFR[h], tb->rkey[h], tb->R[h], -tb->rnum[h]);*/
680 return;
681 }
682
683 if ( tb->lnum[h] > 0 ) { /* split S[h] into two parts and put them into neighbors */
684 RFALSE( tb->rnum[h] == 0 || tb->lnum[h] + tb->rnum[h] != n + 1,
685 "invalid tb->lnum[%d]==%d or tb->rnum[%d]==%d when S[h](item number == %d) is split between them",
686 h, tb->lnum[h], h, tb->rnum[h], n);
687
688 internal_shift_left (INTERNAL_SHIFT_FROM_S_TO_L, tb, h, tb->lnum[h]);/*tb->L[h], tb->CFL[h], tb->lkey[h], tb->S[h], tb->lnum[h]);*/
689 internal_shift_right (INTERNAL_SHIFT_FROM_S_TO_R, tb, h, tb->rnum[h]);
690
691 reiserfs_invalidate_buffer (tb, tbSh);
692
693 return;
694 }
695 reiserfs_panic (tb->tb_sb, "balance_internal_when_delete: unexpected tb->lnum[%d]==%d or tb->rnum[%d]==%d",
696 h, tb->lnum[h], h, tb->rnum[h]);
697}
698 674
675 if (tb->lnum[h] < 0) { /* borrow from left neighbor L[h] */
676 RFALSE(tb->rnum[h] != 0,
677 "wrong tb->rnum[%d]==%d when borrow from L[h]", h,
678 tb->rnum[h]);
679 /*internal_shift_right (tb, h, tb->L[h], tb->CFL[h], tb->lkey[h], tb->S[h], -tb->lnum[h]); */
680 internal_shift_right(INTERNAL_SHIFT_FROM_L_TO_S, tb, h,
681 -tb->lnum[h]);
682 return;
683 }
684
685 if (tb->rnum[h] < 0) { /* borrow from right neighbor R[h] */
686 RFALSE(tb->lnum[h] != 0,
687 "invalid tb->lnum[%d]==%d when borrow from R[h]",
688 h, tb->lnum[h]);
689 internal_shift_left(INTERNAL_SHIFT_FROM_R_TO_S, tb, h, -tb->rnum[h]); /*tb->S[h], tb->CFR[h], tb->rkey[h], tb->R[h], -tb->rnum[h]); */
690 return;
691 }
692
693 if (tb->lnum[h] > 0) { /* split S[h] into two parts and put them into neighbors */
694 RFALSE(tb->rnum[h] == 0 || tb->lnum[h] + tb->rnum[h] != n + 1,
695 "invalid tb->lnum[%d]==%d or tb->rnum[%d]==%d when S[h](item number == %d) is split between them",
696 h, tb->lnum[h], h, tb->rnum[h], n);
697
698 internal_shift_left(INTERNAL_SHIFT_FROM_S_TO_L, tb, h, tb->lnum[h]); /*tb->L[h], tb->CFL[h], tb->lkey[h], tb->S[h], tb->lnum[h]); */
699 internal_shift_right(INTERNAL_SHIFT_FROM_S_TO_R, tb, h,
700 tb->rnum[h]);
701
702 reiserfs_invalidate_buffer(tb, tbSh);
703
704 return;
705 }
706 reiserfs_panic(tb->tb_sb,
707 "balance_internal_when_delete: unexpected tb->lnum[%d]==%d or tb->rnum[%d]==%d",
708 h, tb->lnum[h], h, tb->rnum[h]);
709}
699 710
700/* Replace delimiting key of buffers L[h] and S[h] by the given key.*/ 711/* Replace delimiting key of buffers L[h] and S[h] by the given key.*/
701static void replace_lkey ( 712static void replace_lkey(struct tree_balance *tb, int h, struct item_head *key)
702 struct tree_balance * tb,
703 int h,
704 struct item_head * key
705 )
706{ 713{
707 RFALSE( tb->L[h] == NULL || tb->CFL[h] == NULL, 714 RFALSE(tb->L[h] == NULL || tb->CFL[h] == NULL,
708 "L[h](%p) and CFL[h](%p) must exist in replace_lkey", 715 "L[h](%p) and CFL[h](%p) must exist in replace_lkey",
709 tb->L[h], tb->CFL[h]); 716 tb->L[h], tb->CFL[h]);
710 717
711 if (B_NR_ITEMS(PATH_H_PBUFFER(tb->tb_path, h)) == 0) 718 if (B_NR_ITEMS(PATH_H_PBUFFER(tb->tb_path, h)) == 0)
712 return; 719 return;
713 720
714 memcpy (B_N_PDELIM_KEY(tb->CFL[h],tb->lkey[h]), key, KEY_SIZE); 721 memcpy(B_N_PDELIM_KEY(tb->CFL[h], tb->lkey[h]), key, KEY_SIZE);
715 722
716 do_balance_mark_internal_dirty (tb, tb->CFL[h],0); 723 do_balance_mark_internal_dirty(tb, tb->CFL[h], 0);
717} 724}
718 725
719
720/* Replace delimiting key of buffers S[h] and R[h] by the given key.*/ 726/* Replace delimiting key of buffers S[h] and R[h] by the given key.*/
721static void replace_rkey ( 727static void replace_rkey(struct tree_balance *tb, int h, struct item_head *key)
722 struct tree_balance * tb,
723 int h,
724 struct item_head * key
725 )
726{ 728{
727 RFALSE( tb->R[h] == NULL || tb->CFR[h] == NULL, 729 RFALSE(tb->R[h] == NULL || tb->CFR[h] == NULL,
728 "R[h](%p) and CFR[h](%p) must exist in replace_rkey", 730 "R[h](%p) and CFR[h](%p) must exist in replace_rkey",
729 tb->R[h], tb->CFR[h]); 731 tb->R[h], tb->CFR[h]);
730 RFALSE( B_NR_ITEMS(tb->R[h]) == 0, 732 RFALSE(B_NR_ITEMS(tb->R[h]) == 0,
731 "R[h] can not be empty if it exists (item number=%d)", 733 "R[h] can not be empty if it exists (item number=%d)",
732 B_NR_ITEMS(tb->R[h])); 734 B_NR_ITEMS(tb->R[h]));
733 735
734 memcpy (B_N_PDELIM_KEY(tb->CFR[h],tb->rkey[h]), key, KEY_SIZE); 736 memcpy(B_N_PDELIM_KEY(tb->CFR[h], tb->rkey[h]), key, KEY_SIZE);
735 737
736 do_balance_mark_internal_dirty (tb, tb->CFR[h], 0); 738 do_balance_mark_internal_dirty(tb, tb->CFR[h], 0);
737} 739}
738 740
739 741int balance_internal(struct tree_balance *tb, /* tree_balance structure */
740int balance_internal (struct tree_balance * tb, /* tree_balance structure */ 742 int h, /* level of the tree */
741 int h, /* level of the tree */ 743 int child_pos, struct item_head *insert_key, /* key for insertion on higher level */
742 int child_pos, 744 struct buffer_head **insert_ptr /* node for insertion on higher level */
743 struct item_head * insert_key, /* key for insertion on higher level */
744 struct buffer_head ** insert_ptr /* node for insertion on higher level*/
745 ) 745 )
746 /* if inserting/pasting 746 /* if inserting/pasting
747 { 747 {
748 child_pos is the position of the node-pointer in S[h] that * 748 child_pos is the position of the node-pointer in S[h] that *
749 pointed to S[h-1] before balancing of the h-1 level; * 749 pointed to S[h-1] before balancing of the h-1 level; *
750 this means that new pointers and items must be inserted AFTER * 750 this means that new pointers and items must be inserted AFTER *
751 child_pos 751 child_pos
752 } 752 }
753 else 753 else
754 { 754 {
755 it is the position of the leftmost pointer that must be deleted (together with 755 it is the position of the leftmost pointer that must be deleted (together with
756 its corresponding key to the left of the pointer) 756 its corresponding key to the left of the pointer)
757 as a result of the previous level's balancing. 757 as a result of the previous level's balancing.
758 } 758 }
759*/ 759 */
760{ 760{
761 struct buffer_head * tbSh = PATH_H_PBUFFER (tb->tb_path, h); 761 struct buffer_head *tbSh = PATH_H_PBUFFER(tb->tb_path, h);
762 struct buffer_info bi; 762 struct buffer_info bi;
763 int order; /* we return this: it is 0 if there is no S[h], else it is tb->S[h]->b_item_order */ 763 int order; /* we return this: it is 0 if there is no S[h], else it is tb->S[h]->b_item_order */
764 int insert_num, n, k; 764 int insert_num, n, k;
765 struct buffer_head * S_new; 765 struct buffer_head *S_new;
766 struct item_head new_insert_key; 766 struct item_head new_insert_key;
767 struct buffer_head * new_insert_ptr = NULL; 767 struct buffer_head *new_insert_ptr = NULL;
768 struct item_head * new_insert_key_addr = insert_key; 768 struct item_head *new_insert_key_addr = insert_key;
769 769
770 RFALSE( h < 1, "h (%d) can not be < 1 on internal level", h); 770 RFALSE(h < 1, "h (%d) can not be < 1 on internal level", h);
771 771
772 PROC_INFO_INC( tb -> tb_sb, balance_at[ h ] ); 772 PROC_INFO_INC(tb->tb_sb, balance_at[h]);
773 773
774 order = ( tbSh ) ? PATH_H_POSITION (tb->tb_path, h + 1)/*tb->S[h]->b_item_order*/ : 0; 774 order =
775 775 (tbSh) ? PATH_H_POSITION(tb->tb_path,
776 /* Using insert_size[h] calculate the number insert_num of items 776 h + 1) /*tb->S[h]->b_item_order */ : 0;
777 that must be inserted to or deleted from S[h]. */ 777
778 insert_num = tb->insert_size[h]/((int)(KEY_SIZE + DC_SIZE)); 778 /* Using insert_size[h] calculate the number insert_num of items
779 779 that must be inserted to or deleted from S[h]. */
780 /* Check whether insert_num is proper **/ 780 insert_num = tb->insert_size[h] / ((int)(KEY_SIZE + DC_SIZE));
781 RFALSE( insert_num < -2 || insert_num > 2, 781
782 "incorrect number of items inserted to the internal node (%d)", 782 /* Check whether insert_num is proper * */
783 insert_num); 783 RFALSE(insert_num < -2 || insert_num > 2,
784 RFALSE( h > 1 && (insert_num > 1 || insert_num < -1), 784 "incorrect number of items inserted to the internal node (%d)",
785 "incorrect number of items (%d) inserted to the internal node on a level (h=%d) higher than last internal level", 785 insert_num);
786 insert_num, h); 786 RFALSE(h > 1 && (insert_num > 1 || insert_num < -1),
787 787 "incorrect number of items (%d) inserted to the internal node on a level (h=%d) higher than last internal level",
788 /* Make balance in case insert_num < 0 */ 788 insert_num, h);
789 if ( insert_num < 0 ) { 789
790 balance_internal_when_delete (tb, h, child_pos); 790 /* Make balance in case insert_num < 0 */
791 return order; 791 if (insert_num < 0) {
792 } 792 balance_internal_when_delete(tb, h, child_pos);
793 793 return order;
794 k = 0;
795 if ( tb->lnum[h] > 0 ) {
796 /* shift lnum[h] items from S[h] to the left neighbor L[h].
797 check how many of new items fall into L[h] or CFL[h] after
798 shifting */
799 n = B_NR_ITEMS (tb->L[h]); /* number of items in L[h] */
800 if ( tb->lnum[h] <= child_pos ) {
801 /* new items don't fall into L[h] or CFL[h] */
802 internal_shift_left (INTERNAL_SHIFT_FROM_S_TO_L, tb, h, tb->lnum[h]);
803 /*internal_shift_left (tb->L[h],tb->CFL[h],tb->lkey[h],tbSh,tb->lnum[h]);*/
804 child_pos -= tb->lnum[h];
805 } else if ( tb->lnum[h] > child_pos + insert_num ) {
806 /* all new items fall into L[h] */
807 internal_shift_left (INTERNAL_SHIFT_FROM_S_TO_L, tb, h, tb->lnum[h] - insert_num);
808 /* internal_shift_left(tb->L[h],tb->CFL[h],tb->lkey[h],tbSh,
809 tb->lnum[h]-insert_num);
810 */
811 /* insert insert_num keys and node-pointers into L[h] */
812 bi.tb = tb;
813 bi.bi_bh = tb->L[h];
814 bi.bi_parent = tb->FL[h];
815 bi.bi_position = get_left_neighbor_position (tb, h);
816 internal_insert_childs (&bi,/*tb->L[h], tb->S[h-1]->b_next*/ n + child_pos + 1,
817 insert_num,insert_key,insert_ptr);
818
819 insert_num = 0;
820 } else {
821 struct disk_child * dc;
822
823 /* some items fall into L[h] or CFL[h], but some don't fall */
824 internal_shift1_left(tb,h,child_pos+1);
825 /* calculate number of new items that fall into L[h] */
826 k = tb->lnum[h] - child_pos - 1;
827 bi.tb = tb;
828 bi.bi_bh = tb->L[h];
829 bi.bi_parent = tb->FL[h];
830 bi.bi_position = get_left_neighbor_position (tb, h);
831 internal_insert_childs (&bi,/*tb->L[h], tb->S[h-1]->b_next,*/ n + child_pos + 1,k,
832 insert_key,insert_ptr);
833
834 replace_lkey(tb,h,insert_key + k);
835
836 /* replace the first node-ptr in S[h] by node-ptr to insert_ptr[k] */
837 dc = B_N_CHILD(tbSh, 0);
838 put_dc_size( dc, MAX_CHILD_SIZE(insert_ptr[k]) - B_FREE_SPACE (insert_ptr[k]));
839 put_dc_block_number( dc, insert_ptr[k]->b_blocknr );
840
841 do_balance_mark_internal_dirty (tb, tbSh, 0);
842
843 k++;
844 insert_key += k;
845 insert_ptr += k;
846 insert_num -= k;
847 child_pos = 0;
848 } 794 }
849 } /* tb->lnum[h] > 0 */
850
851 if ( tb->rnum[h] > 0 ) {
852 /*shift rnum[h] items from S[h] to the right neighbor R[h]*/
853 /* check how many of new items fall into R or CFR after shifting */
854 n = B_NR_ITEMS (tbSh); /* number of items in S[h] */
855 if ( n - tb->rnum[h] >= child_pos )
856 /* new items fall into S[h] */
857 /*internal_shift_right(tb,h,tbSh,tb->CFR[h],tb->rkey[h],tb->R[h],tb->rnum[h]);*/
858 internal_shift_right (INTERNAL_SHIFT_FROM_S_TO_R, tb, h, tb->rnum[h]);
859 else
860 if ( n + insert_num - tb->rnum[h] < child_pos )
861 {
862 /* all new items fall into R[h] */
863 /*internal_shift_right(tb,h,tbSh,tb->CFR[h],tb->rkey[h],tb->R[h],
864 tb->rnum[h] - insert_num);*/
865 internal_shift_right (INTERNAL_SHIFT_FROM_S_TO_R, tb, h, tb->rnum[h] - insert_num);
866
867 /* insert insert_num keys and node-pointers into R[h] */
868 bi.tb = tb;
869 bi.bi_bh = tb->R[h];
870 bi.bi_parent = tb->FR[h];
871 bi.bi_position = get_right_neighbor_position (tb, h);
872 internal_insert_childs (&bi, /*tb->R[h],tb->S[h-1]->b_next*/ child_pos - n - insert_num + tb->rnum[h] - 1,
873 insert_num,insert_key,insert_ptr);
874 insert_num = 0;
875 }
876 else
877 {
878 struct disk_child * dc;
879
880 /* one of the items falls into CFR[h] */
881 internal_shift1_right(tb,h,n - child_pos + 1);
882 /* calculate number of new items that fall into R[h] */
883 k = tb->rnum[h] - n + child_pos - 1;
884 bi.tb = tb;
885 bi.bi_bh = tb->R[h];
886 bi.bi_parent = tb->FR[h];
887 bi.bi_position = get_right_neighbor_position (tb, h);
888 internal_insert_childs (&bi, /*tb->R[h], tb->R[h]->b_child,*/ 0, k, insert_key + 1, insert_ptr + 1);
889 795
890 replace_rkey(tb,h,insert_key + insert_num - k - 1); 796 k = 0;
797 if (tb->lnum[h] > 0) {
798 /* shift lnum[h] items from S[h] to the left neighbor L[h].
799 check how many of new items fall into L[h] or CFL[h] after
800 shifting */
801 n = B_NR_ITEMS(tb->L[h]); /* number of items in L[h] */
802 if (tb->lnum[h] <= child_pos) {
803 /* new items don't fall into L[h] or CFL[h] */
804 internal_shift_left(INTERNAL_SHIFT_FROM_S_TO_L, tb, h,
805 tb->lnum[h]);
806 /*internal_shift_left (tb->L[h],tb->CFL[h],tb->lkey[h],tbSh,tb->lnum[h]); */
807 child_pos -= tb->lnum[h];
808 } else if (tb->lnum[h] > child_pos + insert_num) {
809 /* all new items fall into L[h] */
810 internal_shift_left(INTERNAL_SHIFT_FROM_S_TO_L, tb, h,
811 tb->lnum[h] - insert_num);
812 /* internal_shift_left(tb->L[h],tb->CFL[h],tb->lkey[h],tbSh,
813 tb->lnum[h]-insert_num);
814 */
815 /* insert insert_num keys and node-pointers into L[h] */
816 bi.tb = tb;
817 bi.bi_bh = tb->L[h];
818 bi.bi_parent = tb->FL[h];
819 bi.bi_position = get_left_neighbor_position(tb, h);
820 internal_insert_childs(&bi,
821 /*tb->L[h], tb->S[h-1]->b_next */
822 n + child_pos + 1,
823 insert_num, insert_key,
824 insert_ptr);
825
826 insert_num = 0;
827 } else {
828 struct disk_child *dc;
829
830 /* some items fall into L[h] or CFL[h], but some don't fall */
831 internal_shift1_left(tb, h, child_pos + 1);
832 /* calculate number of new items that fall into L[h] */
833 k = tb->lnum[h] - child_pos - 1;
834 bi.tb = tb;
835 bi.bi_bh = tb->L[h];
836 bi.bi_parent = tb->FL[h];
837 bi.bi_position = get_left_neighbor_position(tb, h);
838 internal_insert_childs(&bi,
839 /*tb->L[h], tb->S[h-1]->b_next, */
840 n + child_pos + 1, k,
841 insert_key, insert_ptr);
842
843 replace_lkey(tb, h, insert_key + k);
844
845 /* replace the first node-ptr in S[h] by node-ptr to insert_ptr[k] */
846 dc = B_N_CHILD(tbSh, 0);
847 put_dc_size(dc,
848 MAX_CHILD_SIZE(insert_ptr[k]) -
849 B_FREE_SPACE(insert_ptr[k]));
850 put_dc_block_number(dc, insert_ptr[k]->b_blocknr);
851
852 do_balance_mark_internal_dirty(tb, tbSh, 0);
853
854 k++;
855 insert_key += k;
856 insert_ptr += k;
857 insert_num -= k;
858 child_pos = 0;
859 }
860 }
861 /* tb->lnum[h] > 0 */
862 if (tb->rnum[h] > 0) {
863 /*shift rnum[h] items from S[h] to the right neighbor R[h] */
864 /* check how many of new items fall into R or CFR after shifting */
865 n = B_NR_ITEMS(tbSh); /* number of items in S[h] */
866 if (n - tb->rnum[h] >= child_pos)
867 /* new items fall into S[h] */
868 /*internal_shift_right(tb,h,tbSh,tb->CFR[h],tb->rkey[h],tb->R[h],tb->rnum[h]); */
869 internal_shift_right(INTERNAL_SHIFT_FROM_S_TO_R, tb, h,
870 tb->rnum[h]);
871 else if (n + insert_num - tb->rnum[h] < child_pos) {
872 /* all new items fall into R[h] */
873 /*internal_shift_right(tb,h,tbSh,tb->CFR[h],tb->rkey[h],tb->R[h],
874 tb->rnum[h] - insert_num); */
875 internal_shift_right(INTERNAL_SHIFT_FROM_S_TO_R, tb, h,
876 tb->rnum[h] - insert_num);
877
878 /* insert insert_num keys and node-pointers into R[h] */
879 bi.tb = tb;
880 bi.bi_bh = tb->R[h];
881 bi.bi_parent = tb->FR[h];
882 bi.bi_position = get_right_neighbor_position(tb, h);
883 internal_insert_childs(&bi,
884 /*tb->R[h],tb->S[h-1]->b_next */
885 child_pos - n - insert_num +
886 tb->rnum[h] - 1,
887 insert_num, insert_key,
888 insert_ptr);
889 insert_num = 0;
890 } else {
891 struct disk_child *dc;
892
893 /* one of the items falls into CFR[h] */
894 internal_shift1_right(tb, h, n - child_pos + 1);
895 /* calculate number of new items that fall into R[h] */
896 k = tb->rnum[h] - n + child_pos - 1;
897 bi.tb = tb;
898 bi.bi_bh = tb->R[h];
899 bi.bi_parent = tb->FR[h];
900 bi.bi_position = get_right_neighbor_position(tb, h);
901 internal_insert_childs(&bi,
902 /*tb->R[h], tb->R[h]->b_child, */
903 0, k, insert_key + 1,
904 insert_ptr + 1);
905
906 replace_rkey(tb, h, insert_key + insert_num - k - 1);
907
908 /* replace the first node-ptr in R[h] by node-ptr insert_ptr[insert_num-k-1] */
909 dc = B_N_CHILD(tb->R[h], 0);
910 put_dc_size(dc,
911 MAX_CHILD_SIZE(insert_ptr
912 [insert_num - k - 1]) -
913 B_FREE_SPACE(insert_ptr
914 [insert_num - k - 1]));
915 put_dc_block_number(dc,
916 insert_ptr[insert_num - k -
917 1]->b_blocknr);
918
919 do_balance_mark_internal_dirty(tb, tb->R[h], 0);
920
921 insert_num -= (k + 1);
922 }
923 }
891 924
892 /* replace the first node-ptr in R[h] by node-ptr insert_ptr[insert_num-k-1]*/ 925 /** Fill new node that appears instead of S[h] **/
893 dc = B_N_CHILD(tb->R[h], 0); 926 RFALSE(tb->blknum[h] > 2, "blknum can not be > 2 for internal level");
894 put_dc_size( dc, MAX_CHILD_SIZE(insert_ptr[insert_num-k-1]) - 927 RFALSE(tb->blknum[h] < 0, "blknum can not be < 0");
895 B_FREE_SPACE (insert_ptr[insert_num-k-1]));
896 put_dc_block_number( dc, insert_ptr[insert_num-k-1]->b_blocknr );
897 928
898 do_balance_mark_internal_dirty (tb, tb->R[h],0); 929 if (!tb->blknum[h]) { /* node S[h] is empty now */
930 RFALSE(!tbSh, "S[h] is equal NULL");
899 931
900 insert_num -= (k + 1); 932 /* do what is needed for buffer thrown from tree */
901 } 933 reiserfs_invalidate_buffer(tb, tbSh);
902 } 934 return order;
935 }
903 936
904 /** Fill new node that appears instead of S[h] **/ 937 if (!tbSh) {
905 RFALSE( tb->blknum[h] > 2, "blknum can not be > 2 for internal level"); 938 /* create new root */
906 RFALSE( tb->blknum[h] < 0, "blknum can not be < 0"); 939 struct disk_child *dc;
940 struct buffer_head *tbSh_1 = PATH_H_PBUFFER(tb->tb_path, h - 1);
941 struct block_head *blkh;
907 942
908 if ( ! tb->blknum[h] ) 943 if (tb->blknum[h] != 1)
909 { /* node S[h] is empty now */ 944 reiserfs_panic(NULL,
910 RFALSE( ! tbSh, "S[h] is equal NULL"); 945 "balance_internal: One new node required for creating the new root");
946 /* S[h] = empty buffer from the list FEB. */
947 tbSh = get_FEB(tb);
948 blkh = B_BLK_HEAD(tbSh);
949 set_blkh_level(blkh, h + 1);
911 950
912 /* do what is needed for buffer thrown from tree */ 951 /* Put the unique node-pointer to S[h] that points to S[h-1]. */
913 reiserfs_invalidate_buffer(tb,tbSh); 952
914 return order; 953 dc = B_N_CHILD(tbSh, 0);
915 } 954 put_dc_block_number(dc, tbSh_1->b_blocknr);
916 955 put_dc_size(dc,
917 if ( ! tbSh ) { 956 (MAX_CHILD_SIZE(tbSh_1) - B_FREE_SPACE(tbSh_1)));
918 /* create new root */ 957
919 struct disk_child * dc; 958 tb->insert_size[h] -= DC_SIZE;
920 struct buffer_head * tbSh_1 = PATH_H_PBUFFER (tb->tb_path, h - 1); 959 set_blkh_free_space(blkh, blkh_free_space(blkh) - DC_SIZE);
921 struct block_head * blkh;
922
923
924 if ( tb->blknum[h] != 1 )
925 reiserfs_panic(NULL, "balance_internal: One new node required for creating the new root");
926 /* S[h] = empty buffer from the list FEB. */
927 tbSh = get_FEB (tb);
928 blkh = B_BLK_HEAD(tbSh);
929 set_blkh_level( blkh, h + 1 );
930
931 /* Put the unique node-pointer to S[h] that points to S[h-1]. */
932
933 dc = B_N_CHILD(tbSh, 0);
934 put_dc_block_number( dc, tbSh_1->b_blocknr );
935 put_dc_size( dc, (MAX_CHILD_SIZE (tbSh_1) - B_FREE_SPACE (tbSh_1)));
936
937 tb->insert_size[h] -= DC_SIZE;
938 set_blkh_free_space( blkh, blkh_free_space(blkh) - DC_SIZE );
939
940 do_balance_mark_internal_dirty (tb, tbSh, 0);
941
942 /*&&&&&&&&&&&&&&&&&&&&&&&&*/
943 check_internal (tbSh);
944 /*&&&&&&&&&&&&&&&&&&&&&&&&*/
945
946 /* put new root into path structure */
947 PATH_OFFSET_PBUFFER(tb->tb_path, ILLEGAL_PATH_ELEMENT_OFFSET) = tbSh;
948
949 /* Change root in structure super block. */
950 PUT_SB_ROOT_BLOCK( tb->tb_sb, tbSh->b_blocknr );
951 PUT_SB_TREE_HEIGHT( tb->tb_sb, SB_TREE_HEIGHT(tb->tb_sb) + 1 );
952 do_balance_mark_sb_dirty (tb, REISERFS_SB(tb->tb_sb)->s_sbh, 1);
953 }
954
955 if ( tb->blknum[h] == 2 ) {
956 int snum;
957 struct buffer_info dest_bi, src_bi;
958 960
961 do_balance_mark_internal_dirty(tb, tbSh, 0);
959 962
960 /* S_new = free buffer from list FEB */ 963 /*&&&&&&&&&&&&&&&&&&&&&&&& */
961 S_new = get_FEB(tb); 964 check_internal(tbSh);
962 965 /*&&&&&&&&&&&&&&&&&&&&&&&& */
963 set_blkh_level( B_BLK_HEAD(S_new), h + 1 ); 966
964 967 /* put new root into path structure */
965 dest_bi.tb = tb; 968 PATH_OFFSET_PBUFFER(tb->tb_path, ILLEGAL_PATH_ELEMENT_OFFSET) =
966 dest_bi.bi_bh = S_new; 969 tbSh;
967 dest_bi.bi_parent = NULL; 970
968 dest_bi.bi_position = 0; 971 /* Change root in structure super block. */
969 src_bi.tb = tb; 972 PUT_SB_ROOT_BLOCK(tb->tb_sb, tbSh->b_blocknr);
970 src_bi.bi_bh = tbSh; 973 PUT_SB_TREE_HEIGHT(tb->tb_sb, SB_TREE_HEIGHT(tb->tb_sb) + 1);
971 src_bi.bi_parent = PATH_H_PPARENT (tb->tb_path, h); 974 do_balance_mark_sb_dirty(tb, REISERFS_SB(tb->tb_sb)->s_sbh, 1);
972 src_bi.bi_position = PATH_H_POSITION (tb->tb_path, h + 1);
973
974 n = B_NR_ITEMS (tbSh); /* number of items in S[h] */
975 snum = (insert_num + n + 1)/2;
976 if ( n - snum >= child_pos ) {
977 /* new items don't fall into S_new */
978 /* store the delimiting key for the next level */
979 /* new_insert_key = (n - snum)'th key in S[h] */
980 memcpy (&new_insert_key,B_N_PDELIM_KEY(tbSh,n - snum),
981 KEY_SIZE);
982 /* last parameter is del_par */
983 internal_move_pointers_items (&dest_bi, &src_bi, LAST_TO_FIRST, snum, 0);
984 /* internal_move_pointers_items(S_new, tbSh, LAST_TO_FIRST, snum, 0);*/
985 } else if ( n + insert_num - snum < child_pos ) {
986 /* all new items fall into S_new */
987 /* store the delimiting key for the next level */
988 /* new_insert_key = (n + insert_item - snum)'th key in S[h] */
989 memcpy(&new_insert_key,B_N_PDELIM_KEY(tbSh,n + insert_num - snum),
990 KEY_SIZE);
991 /* last parameter is del_par */
992 internal_move_pointers_items (&dest_bi, &src_bi, LAST_TO_FIRST, snum - insert_num, 0);
993 /* internal_move_pointers_items(S_new,tbSh,1,snum - insert_num,0);*/
994
995 /* insert insert_num keys and node-pointers into S_new */
996 internal_insert_childs (&dest_bi, /*S_new,tb->S[h-1]->b_next,*/child_pos - n - insert_num + snum - 1,
997 insert_num,insert_key,insert_ptr);
998
999 insert_num = 0;
1000 } else {
1001 struct disk_child * dc;
1002
1003 /* some items fall into S_new, but some don't fall */
1004 /* last parameter is del_par */
1005 internal_move_pointers_items (&dest_bi, &src_bi, LAST_TO_FIRST, n - child_pos + 1, 1);
1006 /* internal_move_pointers_items(S_new,tbSh,1,n - child_pos + 1,1);*/
1007 /* calculate number of new items that fall into S_new */
1008 k = snum - n + child_pos - 1;
1009
1010 internal_insert_childs (&dest_bi, /*S_new,*/ 0, k, insert_key + 1, insert_ptr+1);
1011
1012 /* new_insert_key = insert_key[insert_num - k - 1] */
1013 memcpy(&new_insert_key,insert_key + insert_num - k - 1,
1014 KEY_SIZE);
1015 /* replace first node-ptr in S_new by node-ptr to insert_ptr[insert_num-k-1] */
1016
1017 dc = B_N_CHILD(S_new,0);
1018 put_dc_size( dc, (MAX_CHILD_SIZE(insert_ptr[insert_num-k-1]) -
1019 B_FREE_SPACE(insert_ptr[insert_num-k-1])) );
1020 put_dc_block_number( dc, insert_ptr[insert_num-k-1]->b_blocknr );
1021
1022 do_balance_mark_internal_dirty (tb, S_new,0);
1023
1024 insert_num -= (k + 1);
1025 } 975 }
1026 /* new_insert_ptr = node_pointer to S_new */ 976
1027 new_insert_ptr = S_new; 977 if (tb->blknum[h] == 2) {
1028 978 int snum;
1029 RFALSE (!buffer_journaled(S_new) || buffer_journal_dirty(S_new) || 979 struct buffer_info dest_bi, src_bi;
1030 buffer_dirty (S_new), 980
1031 "cm-00001: bad S_new (%b)", S_new); 981 /* S_new = free buffer from list FEB */
1032 982 S_new = get_FEB(tb);
1033 // S_new is released in unfix_nodes 983
1034 } 984 set_blkh_level(B_BLK_HEAD(S_new), h + 1);
1035 985
1036 n = B_NR_ITEMS (tbSh); /*number of items in S[h] */ 986 dest_bi.tb = tb;
1037 987 dest_bi.bi_bh = S_new;
1038 if ( 0 <= child_pos && child_pos <= n && insert_num > 0 ) { 988 dest_bi.bi_parent = NULL;
1039 bi.tb = tb; 989 dest_bi.bi_position = 0;
1040 bi.bi_bh = tbSh; 990 src_bi.tb = tb;
1041 bi.bi_parent = PATH_H_PPARENT (tb->tb_path, h); 991 src_bi.bi_bh = tbSh;
1042 bi.bi_position = PATH_H_POSITION (tb->tb_path, h + 1); 992 src_bi.bi_parent = PATH_H_PPARENT(tb->tb_path, h);
1043 internal_insert_childs ( 993 src_bi.bi_position = PATH_H_POSITION(tb->tb_path, h + 1);
1044 &bi,/*tbSh,*/ 994
1045 /* ( tb->S[h-1]->b_parent == tb->S[h] ) ? tb->S[h-1]->b_next : tb->S[h]->b_child->b_next,*/ 995 n = B_NR_ITEMS(tbSh); /* number of items in S[h] */
1046 child_pos,insert_num,insert_key,insert_ptr 996 snum = (insert_num + n + 1) / 2;
1047 ); 997 if (n - snum >= child_pos) {
998 /* new items don't fall into S_new */
999 /* store the delimiting key for the next level */
1000 /* new_insert_key = (n - snum)'th key in S[h] */
1001 memcpy(&new_insert_key, B_N_PDELIM_KEY(tbSh, n - snum),
1002 KEY_SIZE);
1003 /* last parameter is del_par */
1004 internal_move_pointers_items(&dest_bi, &src_bi,
1005 LAST_TO_FIRST, snum, 0);
1006 /* internal_move_pointers_items(S_new, tbSh, LAST_TO_FIRST, snum, 0); */
1007 } else if (n + insert_num - snum < child_pos) {
1008 /* all new items fall into S_new */
1009 /* store the delimiting key for the next level */
1010 /* new_insert_key = (n + insert_item - snum)'th key in S[h] */
1011 memcpy(&new_insert_key,
1012 B_N_PDELIM_KEY(tbSh, n + insert_num - snum),
1013 KEY_SIZE);
1014 /* last parameter is del_par */
1015 internal_move_pointers_items(&dest_bi, &src_bi,
1016 LAST_TO_FIRST,
1017 snum - insert_num, 0);
1018 /* internal_move_pointers_items(S_new,tbSh,1,snum - insert_num,0); */
1019
1020 /* insert insert_num keys and node-pointers into S_new */
1021 internal_insert_childs(&dest_bi,
1022 /*S_new,tb->S[h-1]->b_next, */
1023 child_pos - n - insert_num +
1024 snum - 1,
1025 insert_num, insert_key,
1026 insert_ptr);
1027
1028 insert_num = 0;
1029 } else {
1030 struct disk_child *dc;
1031
1032 /* some items fall into S_new, but some don't fall */
1033 /* last parameter is del_par */
1034 internal_move_pointers_items(&dest_bi, &src_bi,
1035 LAST_TO_FIRST,
1036 n - child_pos + 1, 1);
1037 /* internal_move_pointers_items(S_new,tbSh,1,n - child_pos + 1,1); */
1038 /* calculate number of new items that fall into S_new */
1039 k = snum - n + child_pos - 1;
1040
1041 internal_insert_childs(&dest_bi, /*S_new, */ 0, k,
1042 insert_key + 1, insert_ptr + 1);
1043
1044 /* new_insert_key = insert_key[insert_num - k - 1] */
1045 memcpy(&new_insert_key, insert_key + insert_num - k - 1,
1046 KEY_SIZE);
1047 /* replace first node-ptr in S_new by node-ptr to insert_ptr[insert_num-k-1] */
1048
1049 dc = B_N_CHILD(S_new, 0);
1050 put_dc_size(dc,
1051 (MAX_CHILD_SIZE
1052 (insert_ptr[insert_num - k - 1]) -
1053 B_FREE_SPACE(insert_ptr
1054 [insert_num - k - 1])));
1055 put_dc_block_number(dc,
1056 insert_ptr[insert_num - k -
1057 1]->b_blocknr);
1058
1059 do_balance_mark_internal_dirty(tb, S_new, 0);
1060
1061 insert_num -= (k + 1);
1062 }
1063 /* new_insert_ptr = node_pointer to S_new */
1064 new_insert_ptr = S_new;
1065
1066 RFALSE(!buffer_journaled(S_new) || buffer_journal_dirty(S_new)
1067 || buffer_dirty(S_new), "cm-00001: bad S_new (%b)",
1068 S_new);
1069
1070 // S_new is released in unfix_nodes
1048 } 1071 }
1049 1072
1073 n = B_NR_ITEMS(tbSh); /*number of items in S[h] */
1050 1074
1051 memcpy (new_insert_key_addr,&new_insert_key,KEY_SIZE); 1075 if (0 <= child_pos && child_pos <= n && insert_num > 0) {
1076 bi.tb = tb;
1077 bi.bi_bh = tbSh;
1078 bi.bi_parent = PATH_H_PPARENT(tb->tb_path, h);
1079 bi.bi_position = PATH_H_POSITION(tb->tb_path, h + 1);
1080 internal_insert_childs(&bi, /*tbSh, */
1081 /* ( tb->S[h-1]->b_parent == tb->S[h] ) ? tb->S[h-1]->b_next : tb->S[h]->b_child->b_next, */
1082 child_pos, insert_num, insert_key,
1083 insert_ptr);
1084 }
1085
1086 memcpy(new_insert_key_addr, &new_insert_key, KEY_SIZE);
1052 insert_ptr[0] = new_insert_ptr; 1087 insert_ptr[0] = new_insert_ptr;
1053 1088
1054 return order; 1089 return order;
1055 } 1090}
1056
1057
1058
diff --git a/fs/reiserfs/inode.c b/fs/reiserfs/inode.c
index 289d864fe731..1aaf2c7d44e6 100644
--- a/fs/reiserfs/inode.c
+++ b/fs/reiserfs/inode.c
@@ -18,107 +18,109 @@
18#include <linux/writeback.h> 18#include <linux/writeback.h>
19#include <linux/quotaops.h> 19#include <linux/quotaops.h>
20 20
21extern int reiserfs_default_io_size; /* default io size devuned in super.c */ 21extern int reiserfs_default_io_size; /* default io size devuned in super.c */
22 22
23static int reiserfs_commit_write(struct file *f, struct page *page, 23static int reiserfs_commit_write(struct file *f, struct page *page,
24 unsigned from, unsigned to); 24 unsigned from, unsigned to);
25static int reiserfs_prepare_write(struct file *f, struct page *page, 25static int reiserfs_prepare_write(struct file *f, struct page *page,
26 unsigned from, unsigned to); 26 unsigned from, unsigned to);
27 27
28void reiserfs_delete_inode (struct inode * inode) 28void reiserfs_delete_inode(struct inode *inode)
29{ 29{
30 /* We need blocks for transaction + (user+group) quota update (possibly delete) */ 30 /* We need blocks for transaction + (user+group) quota update (possibly delete) */
31 int jbegin_count = JOURNAL_PER_BALANCE_CNT * 2 + 2 * REISERFS_QUOTA_INIT_BLOCKS(inode->i_sb); 31 int jbegin_count =
32 struct reiserfs_transaction_handle th ; 32 JOURNAL_PER_BALANCE_CNT * 2 +
33 33 2 * REISERFS_QUOTA_INIT_BLOCKS(inode->i_sb);
34 reiserfs_write_lock(inode->i_sb); 34 struct reiserfs_transaction_handle th;
35 35
36 /* The = 0 happens when we abort creating a new inode for some reason like lack of space.. */ 36 reiserfs_write_lock(inode->i_sb);
37 if (!(inode->i_state & I_NEW) && INODE_PKEY(inode)->k_objectid != 0) { /* also handles bad_inode case */
38 down (&inode->i_sem);
39 37
40 reiserfs_delete_xattrs (inode); 38 /* The = 0 happens when we abort creating a new inode for some reason like lack of space.. */
39 if (!(inode->i_state & I_NEW) && INODE_PKEY(inode)->k_objectid != 0) { /* also handles bad_inode case */
40 down(&inode->i_sem);
41 41
42 if (journal_begin(&th, inode->i_sb, jbegin_count)) { 42 reiserfs_delete_xattrs(inode);
43 up (&inode->i_sem);
44 goto out;
45 }
46 reiserfs_update_inode_transaction(inode) ;
47 43
48 if (reiserfs_delete_object (&th, inode)) { 44 if (journal_begin(&th, inode->i_sb, jbegin_count)) {
49 up (&inode->i_sem); 45 up(&inode->i_sem);
50 goto out; 46 goto out;
51 } 47 }
48 reiserfs_update_inode_transaction(inode);
52 49
53 /* Do quota update inside a transaction for journaled quotas. We must do that 50 if (reiserfs_delete_object(&th, inode)) {
54 * after delete_object so that quota updates go into the same transaction as 51 up(&inode->i_sem);
55 * stat data deletion */ 52 goto out;
56 DQUOT_FREE_INODE(inode); 53 }
57 54
58 if (journal_end(&th, inode->i_sb, jbegin_count)) { 55 /* Do quota update inside a transaction for journaled quotas. We must do that
59 up (&inode->i_sem); 56 * after delete_object so that quota updates go into the same transaction as
60 goto out; 57 * stat data deletion */
61 } 58 DQUOT_FREE_INODE(inode);
59
60 if (journal_end(&th, inode->i_sb, jbegin_count)) {
61 up(&inode->i_sem);
62 goto out;
63 }
62 64
63 up (&inode->i_sem); 65 up(&inode->i_sem);
64 66
65 /* all items of file are deleted, so we can remove "save" link */ 67 /* all items of file are deleted, so we can remove "save" link */
66 remove_save_link (inode, 0/* not truncate */); /* we can't do anything 68 remove_save_link(inode, 0 /* not truncate */ ); /* we can't do anything
67 * about an error here */ 69 * about an error here */
68 } else { 70 } else {
69 /* no object items are in the tree */ 71 /* no object items are in the tree */
70 ; 72 ;
71 } 73 }
72out: 74 out:
73 clear_inode (inode); /* note this must go after the journal_end to prevent deadlock */ 75 clear_inode(inode); /* note this must go after the journal_end to prevent deadlock */
74 inode->i_blocks = 0; 76 inode->i_blocks = 0;
75 reiserfs_write_unlock(inode->i_sb); 77 reiserfs_write_unlock(inode->i_sb);
76} 78}
77 79
78static void _make_cpu_key (struct cpu_key * key, int version, __u32 dirid, __u32 objectid, 80static void _make_cpu_key(struct cpu_key *key, int version, __u32 dirid,
79 loff_t offset, int type, int length ) 81 __u32 objectid, loff_t offset, int type, int length)
80{ 82{
81 key->version = version; 83 key->version = version;
82 84
83 key->on_disk_key.k_dir_id = dirid; 85 key->on_disk_key.k_dir_id = dirid;
84 key->on_disk_key.k_objectid = objectid; 86 key->on_disk_key.k_objectid = objectid;
85 set_cpu_key_k_offset (key, offset); 87 set_cpu_key_k_offset(key, offset);
86 set_cpu_key_k_type (key, type); 88 set_cpu_key_k_type(key, type);
87 key->key_length = length; 89 key->key_length = length;
88} 90}
89 91
90
91/* take base of inode_key (it comes from inode always) (dirid, objectid) and version from an inode, set 92/* take base of inode_key (it comes from inode always) (dirid, objectid) and version from an inode, set
92 offset and type of key */ 93 offset and type of key */
93void make_cpu_key (struct cpu_key * key, struct inode * inode, loff_t offset, 94void make_cpu_key(struct cpu_key *key, struct inode *inode, loff_t offset,
94 int type, int length ) 95 int type, int length)
95{ 96{
96 _make_cpu_key (key, get_inode_item_key_version (inode), le32_to_cpu (INODE_PKEY (inode)->k_dir_id), 97 _make_cpu_key(key, get_inode_item_key_version(inode),
97 le32_to_cpu (INODE_PKEY (inode)->k_objectid), 98 le32_to_cpu(INODE_PKEY(inode)->k_dir_id),
98 offset, type, length); 99 le32_to_cpu(INODE_PKEY(inode)->k_objectid), offset, type,
100 length);
99} 101}
100 102
101
102// 103//
103// when key is 0, do not set version and short key 104// when key is 0, do not set version and short key
104// 105//
105inline void make_le_item_head (struct item_head * ih, const struct cpu_key * key, 106inline void make_le_item_head(struct item_head *ih, const struct cpu_key *key,
106 int version, 107 int version,
107 loff_t offset, int type, int length, 108 loff_t offset, int type, int length,
108 int entry_count/*or ih_free_space*/) 109 int entry_count /*or ih_free_space */ )
109{ 110{
110 if (key) { 111 if (key) {
111 ih->ih_key.k_dir_id = cpu_to_le32 (key->on_disk_key.k_dir_id); 112 ih->ih_key.k_dir_id = cpu_to_le32(key->on_disk_key.k_dir_id);
112 ih->ih_key.k_objectid = cpu_to_le32 (key->on_disk_key.k_objectid); 113 ih->ih_key.k_objectid =
113 } 114 cpu_to_le32(key->on_disk_key.k_objectid);
114 put_ih_version( ih, version ); 115 }
115 set_le_ih_k_offset (ih, offset); 116 put_ih_version(ih, version);
116 set_le_ih_k_type (ih, type); 117 set_le_ih_k_offset(ih, offset);
117 put_ih_item_len( ih, length ); 118 set_le_ih_k_type(ih, type);
118 /* set_ih_free_space (ih, 0);*/ 119 put_ih_item_len(ih, length);
119 // for directory items it is entry count, for directs and stat 120 /* set_ih_free_space (ih, 0); */
120 // datas - 0xffff, for indirects - 0 121 // for directory items it is entry count, for directs and stat
121 put_ih_entry_count( ih, entry_count ); 122 // datas - 0xffff, for indirects - 0
123 put_ih_entry_count(ih, entry_count);
122} 124}
123 125
124// 126//
@@ -153,84 +155,84 @@ inline void make_le_item_head (struct item_head * ih, const struct cpu_key * key
153** to be unmapped, so that block_prepare_write will correctly call 155** to be unmapped, so that block_prepare_write will correctly call
154** reiserfs_get_block to convert the tail into an unformatted node 156** reiserfs_get_block to convert the tail into an unformatted node
155*/ 157*/
156static inline void fix_tail_page_for_writing(struct page *page) { 158static inline void fix_tail_page_for_writing(struct page *page)
157 struct buffer_head *head, *next, *bh ; 159{
158 160 struct buffer_head *head, *next, *bh;
159 if (page && page_has_buffers(page)) { 161
160 head = page_buffers(page) ; 162 if (page && page_has_buffers(page)) {
161 bh = head ; 163 head = page_buffers(page);
162 do { 164 bh = head;
163 next = bh->b_this_page ; 165 do {
164 if (buffer_mapped(bh) && bh->b_blocknr == 0) { 166 next = bh->b_this_page;
165 reiserfs_unmap_buffer(bh) ; 167 if (buffer_mapped(bh) && bh->b_blocknr == 0) {
166 } 168 reiserfs_unmap_buffer(bh);
167 bh = next ; 169 }
168 } while (bh != head) ; 170 bh = next;
169 } 171 } while (bh != head);
172 }
170} 173}
171 174
172/* reiserfs_get_block does not need to allocate a block only if it has been 175/* reiserfs_get_block does not need to allocate a block only if it has been
173 done already or non-hole position has been found in the indirect item */ 176 done already or non-hole position has been found in the indirect item */
174static inline int allocation_needed (int retval, b_blocknr_t allocated, 177static inline int allocation_needed(int retval, b_blocknr_t allocated,
175 struct item_head * ih, 178 struct item_head *ih,
176 __le32 * item, int pos_in_item) 179 __le32 * item, int pos_in_item)
177{ 180{
178 if (allocated) 181 if (allocated)
179 return 0; 182 return 0;
180 if (retval == POSITION_FOUND && is_indirect_le_ih (ih) && 183 if (retval == POSITION_FOUND && is_indirect_le_ih(ih) &&
181 get_block_num(item, pos_in_item)) 184 get_block_num(item, pos_in_item))
182 return 0; 185 return 0;
183 return 1; 186 return 1;
184} 187}
185 188
186static inline int indirect_item_found (int retval, struct item_head * ih) 189static inline int indirect_item_found(int retval, struct item_head *ih)
187{ 190{
188 return (retval == POSITION_FOUND) && is_indirect_le_ih (ih); 191 return (retval == POSITION_FOUND) && is_indirect_le_ih(ih);
189} 192}
190 193
191 194static inline void set_block_dev_mapped(struct buffer_head *bh,
192static inline void set_block_dev_mapped (struct buffer_head * bh, 195 b_blocknr_t block, struct inode *inode)
193 b_blocknr_t block, struct inode * inode)
194{ 196{
195 map_bh(bh, inode->i_sb, block); 197 map_bh(bh, inode->i_sb, block);
196} 198}
197 199
198
199// 200//
200// files which were created in the earlier version can not be longer, 201// files which were created in the earlier version can not be longer,
201// than 2 gb 202// than 2 gb
202// 203//
203static int file_capable (struct inode * inode, long block) 204static int file_capable(struct inode *inode, long block)
204{ 205{
205 if (get_inode_item_key_version (inode) != KEY_FORMAT_3_5 || // it is new file. 206 if (get_inode_item_key_version(inode) != KEY_FORMAT_3_5 || // it is new file.
206 block < (1 << (31 - inode->i_sb->s_blocksize_bits))) // old file, but 'block' is inside of 2gb 207 block < (1 << (31 - inode->i_sb->s_blocksize_bits))) // old file, but 'block' is inside of 2gb
207 return 1; 208 return 1;
208 209
209 return 0; 210 return 0;
210} 211}
211 212
212/*static*/ int restart_transaction(struct reiserfs_transaction_handle *th, 213/*static*/ int restart_transaction(struct reiserfs_transaction_handle *th,
213 struct inode *inode, struct path *path) { 214 struct inode *inode, struct path *path)
214 struct super_block *s = th->t_super ; 215{
215 int len = th->t_blocks_allocated ; 216 struct super_block *s = th->t_super;
216 int err; 217 int len = th->t_blocks_allocated;
217 218 int err;
218 BUG_ON (!th->t_trans_id); 219
219 BUG_ON (!th->t_refcount); 220 BUG_ON(!th->t_trans_id);
220 221 BUG_ON(!th->t_refcount);
221 /* we cannot restart while nested */ 222
222 if (th->t_refcount > 1) { 223 /* we cannot restart while nested */
223 return 0 ; 224 if (th->t_refcount > 1) {
224 } 225 return 0;
225 pathrelse(path) ; 226 }
226 reiserfs_update_sd(th, inode) ; 227 pathrelse(path);
227 err = journal_end(th, s, len) ; 228 reiserfs_update_sd(th, inode);
228 if (!err) { 229 err = journal_end(th, s, len);
229 err = journal_begin(th, s, JOURNAL_PER_BALANCE_CNT * 6) ; 230 if (!err) {
230 if (!err) 231 err = journal_begin(th, s, JOURNAL_PER_BALANCE_CNT * 6);
231 reiserfs_update_inode_transaction(inode) ; 232 if (!err)
232 } 233 reiserfs_update_inode_transaction(inode);
233 return err; 234 }
235 return err;
234} 236}
235 237
236// it is called by get_block when create == 0. Returns block number 238// it is called by get_block when create == 0. Returns block number
@@ -241,190 +243,192 @@ static int file_capable (struct inode * inode, long block)
241// Please improve the english/clarity in the comment above, as it is 243// Please improve the english/clarity in the comment above, as it is
242// hard to understand. 244// hard to understand.
243 245
244static int _get_block_create_0 (struct inode * inode, long block, 246static int _get_block_create_0(struct inode *inode, long block,
245 struct buffer_head * bh_result, 247 struct buffer_head *bh_result, int args)
246 int args)
247{ 248{
248 INITIALIZE_PATH (path); 249 INITIALIZE_PATH(path);
249 struct cpu_key key; 250 struct cpu_key key;
250 struct buffer_head * bh; 251 struct buffer_head *bh;
251 struct item_head * ih, tmp_ih; 252 struct item_head *ih, tmp_ih;
252 int fs_gen ; 253 int fs_gen;
253 int blocknr; 254 int blocknr;
254 char * p = NULL; 255 char *p = NULL;
255 int chars; 256 int chars;
256 int ret ; 257 int ret;
257 int result ; 258 int result;
258 int done = 0 ; 259 int done = 0;
259 unsigned long offset ; 260 unsigned long offset;
260 261
261 // prepare the key to look for the 'block'-th block of file 262 // prepare the key to look for the 'block'-th block of file
262 make_cpu_key (&key, inode, 263 make_cpu_key(&key, inode,
263 (loff_t)block * inode->i_sb->s_blocksize + 1, TYPE_ANY, 3); 264 (loff_t) block * inode->i_sb->s_blocksize + 1, TYPE_ANY,
264 265 3);
265research: 266
266 result = search_for_position_by_key (inode->i_sb, &key, &path) ; 267 research:
267 if (result != POSITION_FOUND) { 268 result = search_for_position_by_key(inode->i_sb, &key, &path);
268 pathrelse (&path); 269 if (result != POSITION_FOUND) {
269 if (p) 270 pathrelse(&path);
270 kunmap(bh_result->b_page) ; 271 if (p)
271 if (result == IO_ERROR) 272 kunmap(bh_result->b_page);
272 return -EIO; 273 if (result == IO_ERROR)
273 // We do not return -ENOENT if there is a hole but page is uptodate, because it means 274 return -EIO;
274 // That there is some MMAPED data associated with it that is yet to be written to disk. 275 // We do not return -ENOENT if there is a hole but page is uptodate, because it means
275 if ((args & GET_BLOCK_NO_HOLE) && !PageUptodate(bh_result->b_page) ) { 276 // That there is some MMAPED data associated with it that is yet to be written to disk.
276 return -ENOENT ; 277 if ((args & GET_BLOCK_NO_HOLE)
277 } 278 && !PageUptodate(bh_result->b_page)) {
278 return 0 ; 279 return -ENOENT;
279 } 280 }
280 281 return 0;
281 // 282 }
282 bh = get_last_bh (&path); 283 //
283 ih = get_ih (&path); 284 bh = get_last_bh(&path);
284 if (is_indirect_le_ih (ih)) { 285 ih = get_ih(&path);
285 __le32 * ind_item = (__le32 *)B_I_PITEM (bh, ih); 286 if (is_indirect_le_ih(ih)) {
286 287 __le32 *ind_item = (__le32 *) B_I_PITEM(bh, ih);
287 /* FIXME: here we could cache indirect item or part of it in 288
288 the inode to avoid search_by_key in case of subsequent 289 /* FIXME: here we could cache indirect item or part of it in
289 access to file */ 290 the inode to avoid search_by_key in case of subsequent
290 blocknr = get_block_num(ind_item, path.pos_in_item) ; 291 access to file */
291 ret = 0 ; 292 blocknr = get_block_num(ind_item, path.pos_in_item);
292 if (blocknr) { 293 ret = 0;
293 map_bh(bh_result, inode->i_sb, blocknr); 294 if (blocknr) {
294 if (path.pos_in_item == ((ih_item_len(ih) / UNFM_P_SIZE) - 1)) { 295 map_bh(bh_result, inode->i_sb, blocknr);
295 set_buffer_boundary(bh_result); 296 if (path.pos_in_item ==
296 } 297 ((ih_item_len(ih) / UNFM_P_SIZE) - 1)) {
297 } else 298 set_buffer_boundary(bh_result);
298 // We do not return -ENOENT if there is a hole but page is uptodate, because it means 299 }
299 // That there is some MMAPED data associated with it that is yet to be written to disk. 300 } else
300 if ((args & GET_BLOCK_NO_HOLE) && !PageUptodate(bh_result->b_page) ) { 301 // We do not return -ENOENT if there is a hole but page is uptodate, because it means
301 ret = -ENOENT ; 302 // That there is some MMAPED data associated with it that is yet to be written to disk.
302 } 303 if ((args & GET_BLOCK_NO_HOLE)
303 304 && !PageUptodate(bh_result->b_page)) {
304 pathrelse (&path); 305 ret = -ENOENT;
305 if (p) 306 }
306 kunmap(bh_result->b_page) ; 307
307 return ret ; 308 pathrelse(&path);
308 } 309 if (p)
309 310 kunmap(bh_result->b_page);
310 // requested data are in direct item(s) 311 return ret;
311 if (!(args & GET_BLOCK_READ_DIRECT)) { 312 }
312 // we are called by bmap. FIXME: we can not map block of file 313 // requested data are in direct item(s)
313 // when it is stored in direct item(s) 314 if (!(args & GET_BLOCK_READ_DIRECT)) {
314 pathrelse (&path); 315 // we are called by bmap. FIXME: we can not map block of file
315 if (p) 316 // when it is stored in direct item(s)
316 kunmap(bh_result->b_page) ; 317 pathrelse(&path);
317 return -ENOENT; 318 if (p)
318 } 319 kunmap(bh_result->b_page);
319 320 return -ENOENT;
320 /* if we've got a direct item, and the buffer or page was uptodate, 321 }
321 ** we don't want to pull data off disk again. skip to the 322
322 ** end, where we map the buffer and return 323 /* if we've got a direct item, and the buffer or page was uptodate,
323 */ 324 ** we don't want to pull data off disk again. skip to the
324 if (buffer_uptodate(bh_result)) { 325 ** end, where we map the buffer and return
325 goto finished ; 326 */
326 } else 327 if (buffer_uptodate(bh_result)) {
327 /* 328 goto finished;
328 ** grab_tail_page can trigger calls to reiserfs_get_block on up to date 329 } else
329 ** pages without any buffers. If the page is up to date, we don't want 330 /*
330 ** read old data off disk. Set the up to date bit on the buffer instead 331 ** grab_tail_page can trigger calls to reiserfs_get_block on up to date
331 ** and jump to the end 332 ** pages without any buffers. If the page is up to date, we don't want
332 */ 333 ** read old data off disk. Set the up to date bit on the buffer instead
333 if (!bh_result->b_page || PageUptodate(bh_result->b_page)) { 334 ** and jump to the end
335 */
336 if (!bh_result->b_page || PageUptodate(bh_result->b_page)) {
334 set_buffer_uptodate(bh_result); 337 set_buffer_uptodate(bh_result);
335 goto finished ; 338 goto finished;
336 } 339 }
337 340 // read file tail into part of page
338 // read file tail into part of page 341 offset = (cpu_key_k_offset(&key) - 1) & (PAGE_CACHE_SIZE - 1);
339 offset = (cpu_key_k_offset(&key) - 1) & (PAGE_CACHE_SIZE - 1) ; 342 fs_gen = get_generation(inode->i_sb);
340 fs_gen = get_generation(inode->i_sb) ; 343 copy_item_head(&tmp_ih, ih);
341 copy_item_head (&tmp_ih, ih); 344
342 345 /* we only want to kmap if we are reading the tail into the page.
343 /* we only want to kmap if we are reading the tail into the page. 346 ** this is not the common case, so we don't kmap until we are
344 ** this is not the common case, so we don't kmap until we are 347 ** sure we need to. But, this means the item might move if
345 ** sure we need to. But, this means the item might move if 348 ** kmap schedules
346 ** kmap schedules 349 */
347 */ 350 if (!p) {
348 if (!p) { 351 p = (char *)kmap(bh_result->b_page);
349 p = (char *)kmap(bh_result->b_page) ; 352 if (fs_changed(fs_gen, inode->i_sb)
350 if (fs_changed (fs_gen, inode->i_sb) && item_moved (&tmp_ih, &path)) { 353 && item_moved(&tmp_ih, &path)) {
351 goto research; 354 goto research;
352 } 355 }
353 } 356 }
354 p += offset ; 357 p += offset;
355 memset (p, 0, inode->i_sb->s_blocksize); 358 memset(p, 0, inode->i_sb->s_blocksize);
356 do { 359 do {
357 if (!is_direct_le_ih (ih)) { 360 if (!is_direct_le_ih(ih)) {
358 BUG (); 361 BUG();
359 } 362 }
360 /* make sure we don't read more bytes than actually exist in 363 /* make sure we don't read more bytes than actually exist in
361 ** the file. This can happen in odd cases where i_size isn't 364 ** the file. This can happen in odd cases where i_size isn't
362 ** correct, and when direct item padding results in a few 365 ** correct, and when direct item padding results in a few
363 ** extra bytes at the end of the direct item 366 ** extra bytes at the end of the direct item
364 */ 367 */
365 if ((le_ih_k_offset(ih) + path.pos_in_item) > inode->i_size) 368 if ((le_ih_k_offset(ih) + path.pos_in_item) > inode->i_size)
366 break ; 369 break;
367 if ((le_ih_k_offset(ih) - 1 + ih_item_len(ih)) > inode->i_size) { 370 if ((le_ih_k_offset(ih) - 1 + ih_item_len(ih)) > inode->i_size) {
368 chars = inode->i_size - (le_ih_k_offset(ih) - 1) - path.pos_in_item; 371 chars =
369 done = 1 ; 372 inode->i_size - (le_ih_k_offset(ih) - 1) -
370 } else { 373 path.pos_in_item;
371 chars = ih_item_len(ih) - path.pos_in_item; 374 done = 1;
372 } 375 } else {
373 memcpy (p, B_I_PITEM (bh, ih) + path.pos_in_item, chars); 376 chars = ih_item_len(ih) - path.pos_in_item;
374 377 }
375 if (done) 378 memcpy(p, B_I_PITEM(bh, ih) + path.pos_in_item, chars);
376 break ; 379
377 380 if (done)
378 p += chars; 381 break;
379 382
380 if (PATH_LAST_POSITION (&path) != (B_NR_ITEMS (bh) - 1)) 383 p += chars;
381 // we done, if read direct item is not the last item of 384
382 // node FIXME: we could try to check right delimiting key 385 if (PATH_LAST_POSITION(&path) != (B_NR_ITEMS(bh) - 1))
383 // to see whether direct item continues in the right 386 // we done, if read direct item is not the last item of
384 // neighbor or rely on i_size 387 // node FIXME: we could try to check right delimiting key
385 break; 388 // to see whether direct item continues in the right
386 389 // neighbor or rely on i_size
387 // update key to look for the next piece 390 break;
388 set_cpu_key_k_offset (&key, cpu_key_k_offset (&key) + chars); 391
389 result = search_for_position_by_key (inode->i_sb, &key, &path); 392 // update key to look for the next piece
390 if (result != POSITION_FOUND) 393 set_cpu_key_k_offset(&key, cpu_key_k_offset(&key) + chars);
391 // i/o error most likely 394 result = search_for_position_by_key(inode->i_sb, &key, &path);
392 break; 395 if (result != POSITION_FOUND)
393 bh = get_last_bh (&path); 396 // i/o error most likely
394 ih = get_ih (&path); 397 break;
395 } while (1); 398 bh = get_last_bh(&path);
396 399 ih = get_ih(&path);
397 flush_dcache_page(bh_result->b_page) ; 400 } while (1);
398 kunmap(bh_result->b_page) ; 401
399 402 flush_dcache_page(bh_result->b_page);
400finished: 403 kunmap(bh_result->b_page);
401 pathrelse (&path); 404
402 405 finished:
403 if (result == IO_ERROR) 406 pathrelse(&path);
404 return -EIO; 407
405 408 if (result == IO_ERROR)
406 /* this buffer has valid data, but isn't valid for io. mapping it to 409 return -EIO;
407 * block #0 tells the rest of reiserfs it just has a tail in it
408 */
409 map_bh(bh_result, inode->i_sb, 0);
410 set_buffer_uptodate (bh_result);
411 return 0;
412}
413 410
411 /* this buffer has valid data, but isn't valid for io. mapping it to
412 * block #0 tells the rest of reiserfs it just has a tail in it
413 */
414 map_bh(bh_result, inode->i_sb, 0);
415 set_buffer_uptodate(bh_result);
416 return 0;
417}
414 418
415// this is called to create file map. So, _get_block_create_0 will not 419// this is called to create file map. So, _get_block_create_0 will not
416// read direct item 420// read direct item
417static int reiserfs_bmap (struct inode * inode, sector_t block, 421static int reiserfs_bmap(struct inode *inode, sector_t block,
418 struct buffer_head * bh_result, int create) 422 struct buffer_head *bh_result, int create)
419{ 423{
420 if (!file_capable (inode, block)) 424 if (!file_capable(inode, block))
421 return -EFBIG; 425 return -EFBIG;
422 426
423 reiserfs_write_lock(inode->i_sb); 427 reiserfs_write_lock(inode->i_sb);
424 /* do not read the direct item */ 428 /* do not read the direct item */
425 _get_block_create_0 (inode, block, bh_result, 0) ; 429 _get_block_create_0(inode, block, bh_result, 0);
426 reiserfs_write_unlock(inode->i_sb); 430 reiserfs_write_unlock(inode->i_sb);
427 return 0; 431 return 0;
428} 432}
429 433
430/* special version of get_block that is only used by grab_tail_page right 434/* special version of get_block that is only used by grab_tail_page right
@@ -444,9 +448,11 @@ static int reiserfs_bmap (struct inode * inode, sector_t block,
444** don't want to send create == GET_BLOCK_NO_HOLE to reiserfs_get_block, 448** don't want to send create == GET_BLOCK_NO_HOLE to reiserfs_get_block,
445** don't use this function. 449** don't use this function.
446*/ 450*/
447static int reiserfs_get_block_create_0 (struct inode * inode, sector_t block, 451static int reiserfs_get_block_create_0(struct inode *inode, sector_t block,
448 struct buffer_head * bh_result, int create) { 452 struct buffer_head *bh_result,
449 return reiserfs_get_block(inode, block, bh_result, GET_BLOCK_NO_HOLE) ; 453 int create)
454{
455 return reiserfs_get_block(inode, block, bh_result, GET_BLOCK_NO_HOLE);
450} 456}
451 457
452/* This is special helper for reiserfs_get_block in case we are executing 458/* This is special helper for reiserfs_get_block in case we are executing
@@ -457,43 +463,42 @@ static int reiserfs_get_blocks_direct_io(struct inode *inode,
457 struct buffer_head *bh_result, 463 struct buffer_head *bh_result,
458 int create) 464 int create)
459{ 465{
460 int ret ; 466 int ret;
461 467
462 bh_result->b_page = NULL; 468 bh_result->b_page = NULL;
463
464 /* We set the b_size before reiserfs_get_block call since it is
465 referenced in convert_tail_for_hole() that may be called from
466 reiserfs_get_block() */
467 bh_result->b_size = (1 << inode->i_blkbits);
468
469 ret = reiserfs_get_block(inode, iblock, bh_result,
470 create | GET_BLOCK_NO_DANGLE) ;
471 if (ret)
472 goto out;
473
474 /* don't allow direct io onto tail pages */
475 if (buffer_mapped(bh_result) && bh_result->b_blocknr == 0) {
476 /* make sure future calls to the direct io funcs for this offset
477 ** in the file fail by unmapping the buffer
478 */
479 clear_buffer_mapped(bh_result);
480 ret = -EINVAL ;
481 }
482 /* Possible unpacked tail. Flush the data before pages have
483 disappeared */
484 if (REISERFS_I(inode)->i_flags & i_pack_on_close_mask) {
485 int err;
486 lock_kernel();
487 err = reiserfs_commit_for_inode(inode);
488 REISERFS_I(inode)->i_flags &= ~i_pack_on_close_mask;
489 unlock_kernel();
490 if (err < 0)
491 ret = err;
492 }
493out:
494 return ret ;
495}
496 469
470 /* We set the b_size before reiserfs_get_block call since it is
471 referenced in convert_tail_for_hole() that may be called from
472 reiserfs_get_block() */
473 bh_result->b_size = (1 << inode->i_blkbits);
474
475 ret = reiserfs_get_block(inode, iblock, bh_result,
476 create | GET_BLOCK_NO_DANGLE);
477 if (ret)
478 goto out;
479
480 /* don't allow direct io onto tail pages */
481 if (buffer_mapped(bh_result) && bh_result->b_blocknr == 0) {
482 /* make sure future calls to the direct io funcs for this offset
483 ** in the file fail by unmapping the buffer
484 */
485 clear_buffer_mapped(bh_result);
486 ret = -EINVAL;
487 }
488 /* Possible unpacked tail. Flush the data before pages have
489 disappeared */
490 if (REISERFS_I(inode)->i_flags & i_pack_on_close_mask) {
491 int err;
492 lock_kernel();
493 err = reiserfs_commit_for_inode(inode);
494 REISERFS_I(inode)->i_flags &= ~i_pack_on_close_mask;
495 unlock_kernel();
496 if (err < 0)
497 ret = err;
498 }
499 out:
500 return ret;
501}
497 502
498/* 503/*
499** helper function for when reiserfs_get_block is called for a hole 504** helper function for when reiserfs_get_block is called for a hole
@@ -505,490 +510,547 @@ out:
505** you should not be in a transaction, or have any paths held when you 510** you should not be in a transaction, or have any paths held when you
506** call this. 511** call this.
507*/ 512*/
508static int convert_tail_for_hole(struct inode *inode, 513static int convert_tail_for_hole(struct inode *inode,
509 struct buffer_head *bh_result, 514 struct buffer_head *bh_result,
510 loff_t tail_offset) { 515 loff_t tail_offset)
511 unsigned long index ; 516{
512 unsigned long tail_end ; 517 unsigned long index;
513 unsigned long tail_start ; 518 unsigned long tail_end;
514 struct page * tail_page ; 519 unsigned long tail_start;
515 struct page * hole_page = bh_result->b_page ; 520 struct page *tail_page;
516 int retval = 0 ; 521 struct page *hole_page = bh_result->b_page;
517 522 int retval = 0;
518 if ((tail_offset & (bh_result->b_size - 1)) != 1) 523
519 return -EIO ; 524 if ((tail_offset & (bh_result->b_size - 1)) != 1)
520 525 return -EIO;
521 /* always try to read until the end of the block */ 526
522 tail_start = tail_offset & (PAGE_CACHE_SIZE - 1) ; 527 /* always try to read until the end of the block */
523 tail_end = (tail_start | (bh_result->b_size - 1)) + 1 ; 528 tail_start = tail_offset & (PAGE_CACHE_SIZE - 1);
524 529 tail_end = (tail_start | (bh_result->b_size - 1)) + 1;
525 index = tail_offset >> PAGE_CACHE_SHIFT ; 530
526 /* hole_page can be zero in case of direct_io, we are sure 531 index = tail_offset >> PAGE_CACHE_SHIFT;
527 that we cannot get here if we write with O_DIRECT into 532 /* hole_page can be zero in case of direct_io, we are sure
528 tail page */ 533 that we cannot get here if we write with O_DIRECT into
529 if (!hole_page || index != hole_page->index) { 534 tail page */
530 tail_page = grab_cache_page(inode->i_mapping, index) ; 535 if (!hole_page || index != hole_page->index) {
531 retval = -ENOMEM; 536 tail_page = grab_cache_page(inode->i_mapping, index);
532 if (!tail_page) { 537 retval = -ENOMEM;
533 goto out ; 538 if (!tail_page) {
534 } 539 goto out;
535 } else { 540 }
536 tail_page = hole_page ; 541 } else {
537 } 542 tail_page = hole_page;
538 543 }
539 /* we don't have to make sure the conversion did not happen while 544
540 ** we were locking the page because anyone that could convert 545 /* we don't have to make sure the conversion did not happen while
541 ** must first take i_sem. 546 ** we were locking the page because anyone that could convert
542 ** 547 ** must first take i_sem.
543 ** We must fix the tail page for writing because it might have buffers 548 **
544 ** that are mapped, but have a block number of 0. This indicates tail 549 ** We must fix the tail page for writing because it might have buffers
545 ** data that has been read directly into the page, and block_prepare_write 550 ** that are mapped, but have a block number of 0. This indicates tail
546 ** won't trigger a get_block in this case. 551 ** data that has been read directly into the page, and block_prepare_write
547 */ 552 ** won't trigger a get_block in this case.
548 fix_tail_page_for_writing(tail_page) ; 553 */
549 retval = reiserfs_prepare_write(NULL, tail_page, tail_start, tail_end); 554 fix_tail_page_for_writing(tail_page);
550 if (retval) 555 retval = reiserfs_prepare_write(NULL, tail_page, tail_start, tail_end);
551 goto unlock ; 556 if (retval)
552 557 goto unlock;
553 /* tail conversion might change the data in the page */ 558
554 flush_dcache_page(tail_page) ; 559 /* tail conversion might change the data in the page */
555 560 flush_dcache_page(tail_page);
556 retval = reiserfs_commit_write(NULL, tail_page, tail_start, tail_end) ; 561
557 562 retval = reiserfs_commit_write(NULL, tail_page, tail_start, tail_end);
558unlock: 563
559 if (tail_page != hole_page) { 564 unlock:
560 unlock_page(tail_page) ; 565 if (tail_page != hole_page) {
561 page_cache_release(tail_page) ; 566 unlock_page(tail_page);
562 } 567 page_cache_release(tail_page);
563out: 568 }
564 return retval ; 569 out:
570 return retval;
565} 571}
566 572
567static inline int _allocate_block(struct reiserfs_transaction_handle *th, 573static inline int _allocate_block(struct reiserfs_transaction_handle *th,
568 long block, 574 long block,
569 struct inode *inode, 575 struct inode *inode,
570 b_blocknr_t *allocated_block_nr, 576 b_blocknr_t * allocated_block_nr,
571 struct path * path, 577 struct path *path, int flags)
572 int flags) { 578{
573 BUG_ON (!th->t_trans_id); 579 BUG_ON(!th->t_trans_id);
574 580
575#ifdef REISERFS_PREALLOCATE 581#ifdef REISERFS_PREALLOCATE
576 if (!(flags & GET_BLOCK_NO_ISEM)) { 582 if (!(flags & GET_BLOCK_NO_ISEM)) {
577 return reiserfs_new_unf_blocknrs2(th, inode, allocated_block_nr, path, block); 583 return reiserfs_new_unf_blocknrs2(th, inode, allocated_block_nr,
578 } 584 path, block);
585 }
579#endif 586#endif
580 return reiserfs_new_unf_blocknrs (th, inode, allocated_block_nr, path, block); 587 return reiserfs_new_unf_blocknrs(th, inode, allocated_block_nr, path,
588 block);
581} 589}
582 590
583int reiserfs_get_block (struct inode * inode, sector_t block, 591int reiserfs_get_block(struct inode *inode, sector_t block,
584 struct buffer_head * bh_result, int create) 592 struct buffer_head *bh_result, int create)
585{ 593{
586 int repeat, retval = 0; 594 int repeat, retval = 0;
587 b_blocknr_t allocated_block_nr = 0;// b_blocknr_t is (unsigned) 32 bit int 595 b_blocknr_t allocated_block_nr = 0; // b_blocknr_t is (unsigned) 32 bit int
588 INITIALIZE_PATH(path); 596 INITIALIZE_PATH(path);
589 int pos_in_item; 597 int pos_in_item;
590 struct cpu_key key; 598 struct cpu_key key;
591 struct buffer_head * bh, * unbh = NULL; 599 struct buffer_head *bh, *unbh = NULL;
592 struct item_head * ih, tmp_ih; 600 struct item_head *ih, tmp_ih;
593 __le32 * item; 601 __le32 *item;
594 int done; 602 int done;
595 int fs_gen; 603 int fs_gen;
596 struct reiserfs_transaction_handle *th = NULL; 604 struct reiserfs_transaction_handle *th = NULL;
597 /* space reserved in transaction batch: 605 /* space reserved in transaction batch:
598 . 3 balancings in direct->indirect conversion 606 . 3 balancings in direct->indirect conversion
599 . 1 block involved into reiserfs_update_sd() 607 . 1 block involved into reiserfs_update_sd()
600 XXX in practically impossible worst case direct2indirect() 608 XXX in practically impossible worst case direct2indirect()
601 can incur (much) more than 3 balancings. 609 can incur (much) more than 3 balancings.
602 quota update for user, group */ 610 quota update for user, group */
603 int jbegin_count = JOURNAL_PER_BALANCE_CNT * 3 + 1 + 2 * REISERFS_QUOTA_TRANS_BLOCKS(inode->i_sb); 611 int jbegin_count =
604 int version; 612 JOURNAL_PER_BALANCE_CNT * 3 + 1 +
605 int dangle = 1; 613 2 * REISERFS_QUOTA_TRANS_BLOCKS(inode->i_sb);
606 loff_t new_offset = (((loff_t)block) << inode->i_sb->s_blocksize_bits) + 1 ; 614 int version;
607 615 int dangle = 1;
608 /* bad.... */ 616 loff_t new_offset =
609 reiserfs_write_lock(inode->i_sb); 617 (((loff_t) block) << inode->i_sb->s_blocksize_bits) + 1;
610 version = get_inode_item_key_version (inode); 618
611 619 /* bad.... */
612 if (block < 0) { 620 reiserfs_write_lock(inode->i_sb);
613 reiserfs_write_unlock(inode->i_sb); 621 version = get_inode_item_key_version(inode);
614 return -EIO;
615 }
616 622
617 if (!file_capable (inode, block)) { 623 if (block < 0) {
618 reiserfs_write_unlock(inode->i_sb); 624 reiserfs_write_unlock(inode->i_sb);
619 return -EFBIG; 625 return -EIO;
620 } 626 }
621
622 /* if !create, we aren't changing the FS, so we don't need to
623 ** log anything, so we don't need to start a transaction
624 */
625 if (!(create & GET_BLOCK_CREATE)) {
626 int ret ;
627 /* find number of block-th logical block of the file */
628 ret = _get_block_create_0 (inode, block, bh_result,
629 create | GET_BLOCK_READ_DIRECT) ;
630 reiserfs_write_unlock(inode->i_sb);
631 return ret;
632 }
633 /*
634 * if we're already in a transaction, make sure to close
635 * any new transactions we start in this func
636 */
637 if ((create & GET_BLOCK_NO_DANGLE) ||
638 reiserfs_transaction_running(inode->i_sb))
639 dangle = 0;
640
641 /* If file is of such a size, that it might have a tail and tails are enabled
642 ** we should mark it as possibly needing tail packing on close
643 */
644 if ( (have_large_tails (inode->i_sb) && inode->i_size < i_block_size (inode)*4) ||
645 (have_small_tails (inode->i_sb) && inode->i_size < i_block_size(inode)) )
646 REISERFS_I(inode)->i_flags |= i_pack_on_close_mask ;
647
648 /* set the key of the first byte in the 'block'-th block of file */
649 make_cpu_key (&key, inode, new_offset,
650 TYPE_ANY, 3/*key length*/);
651 if ((new_offset + inode->i_sb->s_blocksize - 1) > inode->i_size) {
652start_trans:
653 th = reiserfs_persistent_transaction(inode->i_sb, jbegin_count);
654 if (!th) {
655 retval = -ENOMEM;
656 goto failure;
657 }
658 reiserfs_update_inode_transaction(inode) ;
659 }
660 research:
661
662 retval = search_for_position_by_key (inode->i_sb, &key, &path);
663 if (retval == IO_ERROR) {
664 retval = -EIO;
665 goto failure;
666 }
667
668 bh = get_last_bh (&path);
669 ih = get_ih (&path);
670 item = get_item (&path);
671 pos_in_item = path.pos_in_item;
672
673 fs_gen = get_generation (inode->i_sb);
674 copy_item_head (&tmp_ih, ih);
675
676 if (allocation_needed (retval, allocated_block_nr, ih, item, pos_in_item)) {
677 /* we have to allocate block for the unformatted node */
678 if (!th) {
679 pathrelse(&path) ;
680 goto start_trans;
681 }
682
683 repeat = _allocate_block(th, block, inode, &allocated_block_nr, &path, create);
684
685 if (repeat == NO_DISK_SPACE || repeat == QUOTA_EXCEEDED) {
686 /* restart the transaction to give the journal a chance to free
687 ** some blocks. releases the path, so we have to go back to
688 ** research if we succeed on the second try
689 */
690 SB_JOURNAL(inode->i_sb)->j_next_async_flush = 1;
691 retval = restart_transaction(th, inode, &path) ;
692 if (retval)
693 goto failure;
694 repeat = _allocate_block(th, block, inode, &allocated_block_nr, NULL, create);
695
696 if (repeat != NO_DISK_SPACE && repeat != QUOTA_EXCEEDED) {
697 goto research ;
698 }
699 if (repeat == QUOTA_EXCEEDED)
700 retval = -EDQUOT;
701 else
702 retval = -ENOSPC;
703 goto failure;
704 }
705
706 if (fs_changed (fs_gen, inode->i_sb) && item_moved (&tmp_ih, &path)) {
707 goto research;
708 }
709 }
710
711 if (indirect_item_found (retval, ih)) {
712 b_blocknr_t unfm_ptr;
713 /* 'block'-th block is in the file already (there is
714 corresponding cell in some indirect item). But it may be
715 zero unformatted node pointer (hole) */
716 unfm_ptr = get_block_num (item, pos_in_item);
717 if (unfm_ptr == 0) {
718 /* use allocated block to plug the hole */
719 reiserfs_prepare_for_journal(inode->i_sb, bh, 1) ;
720 if (fs_changed (fs_gen, inode->i_sb) && item_moved (&tmp_ih, &path)) {
721 reiserfs_restore_prepared_buffer(inode->i_sb, bh) ;
722 goto research;
723 }
724 set_buffer_new(bh_result);
725 if (buffer_dirty(bh_result) && reiserfs_data_ordered(inode->i_sb))
726 reiserfs_add_ordered_list(inode, bh_result);
727 put_block_num(item, pos_in_item, allocated_block_nr) ;
728 unfm_ptr = allocated_block_nr;
729 journal_mark_dirty (th, inode->i_sb, bh);
730 reiserfs_update_sd(th, inode) ;
731 }
732 set_block_dev_mapped(bh_result, unfm_ptr, inode);
733 pathrelse (&path);
734 retval = 0;
735 if (!dangle && th)
736 retval = reiserfs_end_persistent_transaction(th);
737 627
738 reiserfs_write_unlock(inode->i_sb); 628 if (!file_capable(inode, block)) {
739 629 reiserfs_write_unlock(inode->i_sb);
740 /* the item was found, so new blocks were not added to the file 630 return -EFBIG;
741 ** there is no need to make sure the inode is updated with this 631 }
742 ** transaction 632
743 */ 633 /* if !create, we aren't changing the FS, so we don't need to
744 return retval; 634 ** log anything, so we don't need to start a transaction
745 } 635 */
746 636 if (!(create & GET_BLOCK_CREATE)) {
747 if (!th) { 637 int ret;
748 pathrelse(&path) ; 638 /* find number of block-th logical block of the file */
749 goto start_trans; 639 ret = _get_block_create_0(inode, block, bh_result,
750 } 640 create | GET_BLOCK_READ_DIRECT);
751 641 reiserfs_write_unlock(inode->i_sb);
752 /* desired position is not found or is in the direct item. We have 642 return ret;
753 to append file with holes up to 'block'-th block converting 643 }
754 direct items to indirect one if necessary */ 644 /*
755 done = 0; 645 * if we're already in a transaction, make sure to close
756 do { 646 * any new transactions we start in this func
757 if (is_statdata_le_ih (ih)) { 647 */
758 __le32 unp = 0; 648 if ((create & GET_BLOCK_NO_DANGLE) ||
759 struct cpu_key tmp_key; 649 reiserfs_transaction_running(inode->i_sb))
760 650 dangle = 0;
761 /* indirect item has to be inserted */ 651
762 make_le_item_head (&tmp_ih, &key, version, 1, TYPE_INDIRECT, 652 /* If file is of such a size, that it might have a tail and tails are enabled
763 UNFM_P_SIZE, 0/* free_space */); 653 ** we should mark it as possibly needing tail packing on close
764 654 */
765 if (cpu_key_k_offset (&key) == 1) { 655 if ((have_large_tails(inode->i_sb)
766 /* we are going to add 'block'-th block to the file. Use 656 && inode->i_size < i_block_size(inode) * 4)
767 allocated block for that */ 657 || (have_small_tails(inode->i_sb)
768 unp = cpu_to_le32 (allocated_block_nr); 658 && inode->i_size < i_block_size(inode)))
769 set_block_dev_mapped (bh_result, allocated_block_nr, inode); 659 REISERFS_I(inode)->i_flags |= i_pack_on_close_mask;
770 set_buffer_new(bh_result); 660
771 done = 1; 661 /* set the key of the first byte in the 'block'-th block of file */
772 } 662 make_cpu_key(&key, inode, new_offset, TYPE_ANY, 3 /*key length */ );
773 tmp_key = key; // ;) 663 if ((new_offset + inode->i_sb->s_blocksize - 1) > inode->i_size) {
774 set_cpu_key_k_offset (&tmp_key, 1); 664 start_trans:
775 PATH_LAST_POSITION(&path) ++; 665 th = reiserfs_persistent_transaction(inode->i_sb, jbegin_count);
776 666 if (!th) {
777 retval = reiserfs_insert_item (th, &path, &tmp_key, &tmp_ih, inode, (char *)&unp); 667 retval = -ENOMEM;
778 if (retval) {
779 reiserfs_free_block (th, inode, allocated_block_nr, 1);
780 goto failure; // retval == -ENOSPC, -EDQUOT or -EIO or -EEXIST
781 }
782 //mark_tail_converted (inode);
783 } else if (is_direct_le_ih (ih)) {
784 /* direct item has to be converted */
785 loff_t tail_offset;
786
787 tail_offset = ((le_ih_k_offset (ih) - 1) & ~(inode->i_sb->s_blocksize - 1)) + 1;
788 if (tail_offset == cpu_key_k_offset (&key)) {
789 /* direct item we just found fits into block we have
790 to map. Convert it into unformatted node: use
791 bh_result for the conversion */
792 set_block_dev_mapped (bh_result, allocated_block_nr, inode);
793 unbh = bh_result;
794 done = 1;
795 } else {
796 /* we have to padd file tail stored in direct item(s)
797 up to block size and convert it to unformatted
798 node. FIXME: this should also get into page cache */
799
800 pathrelse(&path) ;
801 /*
802 * ugly, but we can only end the transaction if
803 * we aren't nested
804 */
805 BUG_ON (!th->t_refcount);
806 if (th->t_refcount == 1) {
807 retval = reiserfs_end_persistent_transaction(th);
808 th = NULL;
809 if (retval)
810 goto failure; 668 goto failure;
811 } 669 }
670 reiserfs_update_inode_transaction(inode);
671 }
672 research:
812 673
813 retval = convert_tail_for_hole(inode, bh_result, tail_offset) ; 674 retval = search_for_position_by_key(inode->i_sb, &key, &path);
814 if (retval) {
815 if ( retval != -ENOSPC )
816 reiserfs_warning (inode->i_sb, "clm-6004: convert tail failed inode %lu, error %d", inode->i_ino, retval) ;
817 if (allocated_block_nr) {
818 /* the bitmap, the super, and the stat data == 3 */
819 if (!th)
820 th = reiserfs_persistent_transaction(inode->i_sb,3);
821 if (th)
822 reiserfs_free_block (th,inode,allocated_block_nr,1);
823 }
824 goto failure ;
825 }
826 goto research ;
827 }
828 retval = direct2indirect (th, inode, &path, unbh, tail_offset);
829 if (retval) {
830 reiserfs_unmap_buffer(unbh);
831 reiserfs_free_block (th, inode, allocated_block_nr, 1);
832 goto failure;
833 }
834 /* it is important the set_buffer_uptodate is done after
835 ** the direct2indirect. The buffer might contain valid
836 ** data newer than the data on disk (read by readpage, changed,
837 ** and then sent here by writepage). direct2indirect needs
838 ** to know if unbh was already up to date, so it can decide
839 ** if the data in unbh needs to be replaced with data from
840 ** the disk
841 */
842 set_buffer_uptodate (unbh);
843
844 /* unbh->b_page == NULL in case of DIRECT_IO request, this means
845 buffer will disappear shortly, so it should not be added to
846 */
847 if ( unbh->b_page ) {
848 /* we've converted the tail, so we must
849 ** flush unbh before the transaction commits
850 */
851 reiserfs_add_tail_list(inode, unbh) ;
852
853 /* mark it dirty now to prevent commit_write from adding
854 ** this buffer to the inode's dirty buffer list
855 */
856 /*
857 * AKPM: changed __mark_buffer_dirty to mark_buffer_dirty().
858 * It's still atomic, but it sets the page dirty too,
859 * which makes it eligible for writeback at any time by the
860 * VM (which was also the case with __mark_buffer_dirty())
861 */
862 mark_buffer_dirty(unbh) ;
863 }
864 } else {
865 /* append indirect item with holes if needed, when appending
866 pointer to 'block'-th block use block, which is already
867 allocated */
868 struct cpu_key tmp_key;
869 unp_t unf_single=0; // We use this in case we need to allocate only
870 // one block which is a fastpath
871 unp_t *un;
872 __u64 max_to_insert=MAX_ITEM_LEN(inode->i_sb->s_blocksize)/UNFM_P_SIZE;
873 __u64 blocks_needed;
874
875 RFALSE( pos_in_item != ih_item_len(ih) / UNFM_P_SIZE,
876 "vs-804: invalid position for append");
877 /* indirect item has to be appended, set up key of that position */
878 make_cpu_key (&tmp_key, inode,
879 le_key_k_offset (version, &(ih->ih_key)) + op_bytes_number (ih, inode->i_sb->s_blocksize),
880 //pos_in_item * inode->i_sb->s_blocksize,
881 TYPE_INDIRECT, 3);// key type is unimportant
882
883 blocks_needed = 1 + ((cpu_key_k_offset (&key) - cpu_key_k_offset (&tmp_key)) >> inode->i_sb->s_blocksize_bits);
884 RFALSE( blocks_needed < 0, "green-805: invalid offset");
885
886 if ( blocks_needed == 1 ) {
887 un = &unf_single;
888 } else {
889 un=kmalloc( min(blocks_needed,max_to_insert)*UNFM_P_SIZE,
890 GFP_ATOMIC); // We need to avoid scheduling.
891 if ( !un) {
892 un = &unf_single;
893 blocks_needed = 1;
894 max_to_insert = 0;
895 } else
896 memset(un, 0, UNFM_P_SIZE * min(blocks_needed,max_to_insert));
897 }
898 if ( blocks_needed <= max_to_insert) {
899 /* we are going to add target block to the file. Use allocated
900 block for that */
901 un[blocks_needed-1] = cpu_to_le32 (allocated_block_nr);
902 set_block_dev_mapped (bh_result, allocated_block_nr, inode);
903 set_buffer_new(bh_result);
904 done = 1;
905 } else {
906 /* paste hole to the indirect item */
907 /* If kmalloc failed, max_to_insert becomes zero and it means we
908 only have space for one block */
909 blocks_needed=max_to_insert?max_to_insert:1;
910 }
911 retval = reiserfs_paste_into_item (th, &path, &tmp_key, inode, (char *)un, UNFM_P_SIZE * blocks_needed);
912
913 if (blocks_needed != 1)
914 kfree(un);
915
916 if (retval) {
917 reiserfs_free_block (th, inode, allocated_block_nr, 1);
918 goto failure;
919 }
920 if (!done) {
921 /* We need to mark new file size in case this function will be
922 interrupted/aborted later on. And we may do this only for
923 holes. */
924 inode->i_size += inode->i_sb->s_blocksize * blocks_needed;
925 }
926 }
927
928 if (done == 1)
929 break;
930
931 /* this loop could log more blocks than we had originally asked
932 ** for. So, we have to allow the transaction to end if it is
933 ** too big or too full. Update the inode so things are
934 ** consistent if we crash before the function returns
935 **
936 ** release the path so that anybody waiting on the path before
937 ** ending their transaction will be able to continue.
938 */
939 if (journal_transaction_should_end(th, th->t_blocks_allocated)) {
940 retval = restart_transaction(th, inode, &path) ;
941 if (retval)
942 goto failure;
943 }
944 /* inserting indirect pointers for a hole can take a
945 ** long time. reschedule if needed
946 */
947 cond_resched();
948
949 retval = search_for_position_by_key (inode->i_sb, &key, &path);
950 if (retval == IO_ERROR) { 675 if (retval == IO_ERROR) {
951 retval = -EIO; 676 retval = -EIO;
952 goto failure; 677 goto failure;
953 } 678 }
954 if (retval == POSITION_FOUND) { 679
955 reiserfs_warning (inode->i_sb, "vs-825: reiserfs_get_block: " 680 bh = get_last_bh(&path);
956 "%K should not be found", &key); 681 ih = get_ih(&path);
957 retval = -EEXIST; 682 item = get_item(&path);
958 if (allocated_block_nr)
959 reiserfs_free_block (th, inode, allocated_block_nr, 1);
960 pathrelse(&path) ;
961 goto failure;
962 }
963 bh = get_last_bh (&path);
964 ih = get_ih (&path);
965 item = get_item (&path);
966 pos_in_item = path.pos_in_item; 683 pos_in_item = path.pos_in_item;
967 } while (1);
968 684
685 fs_gen = get_generation(inode->i_sb);
686 copy_item_head(&tmp_ih, ih);
687
688 if (allocation_needed
689 (retval, allocated_block_nr, ih, item, pos_in_item)) {
690 /* we have to allocate block for the unformatted node */
691 if (!th) {
692 pathrelse(&path);
693 goto start_trans;
694 }
695
696 repeat =
697 _allocate_block(th, block, inode, &allocated_block_nr,
698 &path, create);
699
700 if (repeat == NO_DISK_SPACE || repeat == QUOTA_EXCEEDED) {
701 /* restart the transaction to give the journal a chance to free
702 ** some blocks. releases the path, so we have to go back to
703 ** research if we succeed on the second try
704 */
705 SB_JOURNAL(inode->i_sb)->j_next_async_flush = 1;
706 retval = restart_transaction(th, inode, &path);
707 if (retval)
708 goto failure;
709 repeat =
710 _allocate_block(th, block, inode,
711 &allocated_block_nr, NULL, create);
712
713 if (repeat != NO_DISK_SPACE && repeat != QUOTA_EXCEEDED) {
714 goto research;
715 }
716 if (repeat == QUOTA_EXCEEDED)
717 retval = -EDQUOT;
718 else
719 retval = -ENOSPC;
720 goto failure;
721 }
722
723 if (fs_changed(fs_gen, inode->i_sb)
724 && item_moved(&tmp_ih, &path)) {
725 goto research;
726 }
727 }
728
729 if (indirect_item_found(retval, ih)) {
730 b_blocknr_t unfm_ptr;
731 /* 'block'-th block is in the file already (there is
732 corresponding cell in some indirect item). But it may be
733 zero unformatted node pointer (hole) */
734 unfm_ptr = get_block_num(item, pos_in_item);
735 if (unfm_ptr == 0) {
736 /* use allocated block to plug the hole */
737 reiserfs_prepare_for_journal(inode->i_sb, bh, 1);
738 if (fs_changed(fs_gen, inode->i_sb)
739 && item_moved(&tmp_ih, &path)) {
740 reiserfs_restore_prepared_buffer(inode->i_sb,
741 bh);
742 goto research;
743 }
744 set_buffer_new(bh_result);
745 if (buffer_dirty(bh_result)
746 && reiserfs_data_ordered(inode->i_sb))
747 reiserfs_add_ordered_list(inode, bh_result);
748 put_block_num(item, pos_in_item, allocated_block_nr);
749 unfm_ptr = allocated_block_nr;
750 journal_mark_dirty(th, inode->i_sb, bh);
751 reiserfs_update_sd(th, inode);
752 }
753 set_block_dev_mapped(bh_result, unfm_ptr, inode);
754 pathrelse(&path);
755 retval = 0;
756 if (!dangle && th)
757 retval = reiserfs_end_persistent_transaction(th);
758
759 reiserfs_write_unlock(inode->i_sb);
760
761 /* the item was found, so new blocks were not added to the file
762 ** there is no need to make sure the inode is updated with this
763 ** transaction
764 */
765 return retval;
766 }
767
768 if (!th) {
769 pathrelse(&path);
770 goto start_trans;
771 }
772
773 /* desired position is not found or is in the direct item. We have
774 to append file with holes up to 'block'-th block converting
775 direct items to indirect one if necessary */
776 done = 0;
777 do {
778 if (is_statdata_le_ih(ih)) {
779 __le32 unp = 0;
780 struct cpu_key tmp_key;
781
782 /* indirect item has to be inserted */
783 make_le_item_head(&tmp_ih, &key, version, 1,
784 TYPE_INDIRECT, UNFM_P_SIZE,
785 0 /* free_space */ );
786
787 if (cpu_key_k_offset(&key) == 1) {
788 /* we are going to add 'block'-th block to the file. Use
789 allocated block for that */
790 unp = cpu_to_le32(allocated_block_nr);
791 set_block_dev_mapped(bh_result,
792 allocated_block_nr, inode);
793 set_buffer_new(bh_result);
794 done = 1;
795 }
796 tmp_key = key; // ;)
797 set_cpu_key_k_offset(&tmp_key, 1);
798 PATH_LAST_POSITION(&path)++;
799
800 retval =
801 reiserfs_insert_item(th, &path, &tmp_key, &tmp_ih,
802 inode, (char *)&unp);
803 if (retval) {
804 reiserfs_free_block(th, inode,
805 allocated_block_nr, 1);
806 goto failure; // retval == -ENOSPC, -EDQUOT or -EIO or -EEXIST
807 }
808 //mark_tail_converted (inode);
809 } else if (is_direct_le_ih(ih)) {
810 /* direct item has to be converted */
811 loff_t tail_offset;
812
813 tail_offset =
814 ((le_ih_k_offset(ih) -
815 1) & ~(inode->i_sb->s_blocksize - 1)) + 1;
816 if (tail_offset == cpu_key_k_offset(&key)) {
817 /* direct item we just found fits into block we have
818 to map. Convert it into unformatted node: use
819 bh_result for the conversion */
820 set_block_dev_mapped(bh_result,
821 allocated_block_nr, inode);
822 unbh = bh_result;
823 done = 1;
824 } else {
825 /* we have to padd file tail stored in direct item(s)
826 up to block size and convert it to unformatted
827 node. FIXME: this should also get into page cache */
828
829 pathrelse(&path);
830 /*
831 * ugly, but we can only end the transaction if
832 * we aren't nested
833 */
834 BUG_ON(!th->t_refcount);
835 if (th->t_refcount == 1) {
836 retval =
837 reiserfs_end_persistent_transaction
838 (th);
839 th = NULL;
840 if (retval)
841 goto failure;
842 }
843
844 retval =
845 convert_tail_for_hole(inode, bh_result,
846 tail_offset);
847 if (retval) {
848 if (retval != -ENOSPC)
849 reiserfs_warning(inode->i_sb,
850 "clm-6004: convert tail failed inode %lu, error %d",
851 inode->i_ino,
852 retval);
853 if (allocated_block_nr) {
854 /* the bitmap, the super, and the stat data == 3 */
855 if (!th)
856 th = reiserfs_persistent_transaction(inode->i_sb, 3);
857 if (th)
858 reiserfs_free_block(th,
859 inode,
860 allocated_block_nr,
861 1);
862 }
863 goto failure;
864 }
865 goto research;
866 }
867 retval =
868 direct2indirect(th, inode, &path, unbh,
869 tail_offset);
870 if (retval) {
871 reiserfs_unmap_buffer(unbh);
872 reiserfs_free_block(th, inode,
873 allocated_block_nr, 1);
874 goto failure;
875 }
876 /* it is important the set_buffer_uptodate is done after
877 ** the direct2indirect. The buffer might contain valid
878 ** data newer than the data on disk (read by readpage, changed,
879 ** and then sent here by writepage). direct2indirect needs
880 ** to know if unbh was already up to date, so it can decide
881 ** if the data in unbh needs to be replaced with data from
882 ** the disk
883 */
884 set_buffer_uptodate(unbh);
885
886 /* unbh->b_page == NULL in case of DIRECT_IO request, this means
887 buffer will disappear shortly, so it should not be added to
888 */
889 if (unbh->b_page) {
890 /* we've converted the tail, so we must
891 ** flush unbh before the transaction commits
892 */
893 reiserfs_add_tail_list(inode, unbh);
894
895 /* mark it dirty now to prevent commit_write from adding
896 ** this buffer to the inode's dirty buffer list
897 */
898 /*
899 * AKPM: changed __mark_buffer_dirty to mark_buffer_dirty().
900 * It's still atomic, but it sets the page dirty too,
901 * which makes it eligible for writeback at any time by the
902 * VM (which was also the case with __mark_buffer_dirty())
903 */
904 mark_buffer_dirty(unbh);
905 }
906 } else {
907 /* append indirect item with holes if needed, when appending
908 pointer to 'block'-th block use block, which is already
909 allocated */
910 struct cpu_key tmp_key;
911 unp_t unf_single = 0; // We use this in case we need to allocate only
912 // one block which is a fastpath
913 unp_t *un;
914 __u64 max_to_insert =
915 MAX_ITEM_LEN(inode->i_sb->s_blocksize) /
916 UNFM_P_SIZE;
917 __u64 blocks_needed;
918
919 RFALSE(pos_in_item != ih_item_len(ih) / UNFM_P_SIZE,
920 "vs-804: invalid position for append");
921 /* indirect item has to be appended, set up key of that position */
922 make_cpu_key(&tmp_key, inode,
923 le_key_k_offset(version,
924 &(ih->ih_key)) +
925 op_bytes_number(ih,
926 inode->i_sb->s_blocksize),
927 //pos_in_item * inode->i_sb->s_blocksize,
928 TYPE_INDIRECT, 3); // key type is unimportant
929
930 blocks_needed =
931 1 +
932 ((cpu_key_k_offset(&key) -
933 cpu_key_k_offset(&tmp_key)) >> inode->i_sb->
934 s_blocksize_bits);
935 RFALSE(blocks_needed < 0, "green-805: invalid offset");
936
937 if (blocks_needed == 1) {
938 un = &unf_single;
939 } else {
940 un = kmalloc(min(blocks_needed, max_to_insert) * UNFM_P_SIZE, GFP_ATOMIC); // We need to avoid scheduling.
941 if (!un) {
942 un = &unf_single;
943 blocks_needed = 1;
944 max_to_insert = 0;
945 } else
946 memset(un, 0,
947 UNFM_P_SIZE * min(blocks_needed,
948 max_to_insert));
949 }
950 if (blocks_needed <= max_to_insert) {
951 /* we are going to add target block to the file. Use allocated
952 block for that */
953 un[blocks_needed - 1] =
954 cpu_to_le32(allocated_block_nr);
955 set_block_dev_mapped(bh_result,
956 allocated_block_nr, inode);
957 set_buffer_new(bh_result);
958 done = 1;
959 } else {
960 /* paste hole to the indirect item */
961 /* If kmalloc failed, max_to_insert becomes zero and it means we
962 only have space for one block */
963 blocks_needed =
964 max_to_insert ? max_to_insert : 1;
965 }
966 retval =
967 reiserfs_paste_into_item(th, &path, &tmp_key, inode,
968 (char *)un,
969 UNFM_P_SIZE *
970 blocks_needed);
971
972 if (blocks_needed != 1)
973 kfree(un);
974
975 if (retval) {
976 reiserfs_free_block(th, inode,
977 allocated_block_nr, 1);
978 goto failure;
979 }
980 if (!done) {
981 /* We need to mark new file size in case this function will be
982 interrupted/aborted later on. And we may do this only for
983 holes. */
984 inode->i_size +=
985 inode->i_sb->s_blocksize * blocks_needed;
986 }
987 }
969 988
970 retval = 0; 989 if (done == 1)
990 break;
971 991
972 failure: 992 /* this loop could log more blocks than we had originally asked
973 if (th && (!dangle || (retval && !th->t_trans_id))) { 993 ** for. So, we have to allow the transaction to end if it is
974 int err; 994 ** too big or too full. Update the inode so things are
975 if (th->t_trans_id) 995 ** consistent if we crash before the function returns
976 reiserfs_update_sd(th, inode); 996 **
977 err = reiserfs_end_persistent_transaction(th); 997 ** release the path so that anybody waiting on the path before
978 if (err) 998 ** ending their transaction will be able to continue.
979 retval = err; 999 */
980 } 1000 if (journal_transaction_should_end(th, th->t_blocks_allocated)) {
1001 retval = restart_transaction(th, inode, &path);
1002 if (retval)
1003 goto failure;
1004 }
1005 /* inserting indirect pointers for a hole can take a
1006 ** long time. reschedule if needed
1007 */
1008 cond_resched();
981 1009
982 reiserfs_write_unlock(inode->i_sb); 1010 retval = search_for_position_by_key(inode->i_sb, &key, &path);
983 reiserfs_check_path(&path) ; 1011 if (retval == IO_ERROR) {
984 return retval; 1012 retval = -EIO;
1013 goto failure;
1014 }
1015 if (retval == POSITION_FOUND) {
1016 reiserfs_warning(inode->i_sb,
1017 "vs-825: reiserfs_get_block: "
1018 "%K should not be found", &key);
1019 retval = -EEXIST;
1020 if (allocated_block_nr)
1021 reiserfs_free_block(th, inode,
1022 allocated_block_nr, 1);
1023 pathrelse(&path);
1024 goto failure;
1025 }
1026 bh = get_last_bh(&path);
1027 ih = get_ih(&path);
1028 item = get_item(&path);
1029 pos_in_item = path.pos_in_item;
1030 } while (1);
1031
1032 retval = 0;
1033
1034 failure:
1035 if (th && (!dangle || (retval && !th->t_trans_id))) {
1036 int err;
1037 if (th->t_trans_id)
1038 reiserfs_update_sd(th, inode);
1039 err = reiserfs_end_persistent_transaction(th);
1040 if (err)
1041 retval = err;
1042 }
1043
1044 reiserfs_write_unlock(inode->i_sb);
1045 reiserfs_check_path(&path);
1046 return retval;
985} 1047}
986 1048
987static int 1049static int
988reiserfs_readpages(struct file *file, struct address_space *mapping, 1050reiserfs_readpages(struct file *file, struct address_space *mapping,
989 struct list_head *pages, unsigned nr_pages) 1051 struct list_head *pages, unsigned nr_pages)
990{ 1052{
991 return mpage_readpages(mapping, pages, nr_pages, reiserfs_get_block); 1053 return mpage_readpages(mapping, pages, nr_pages, reiserfs_get_block);
992} 1054}
993 1055
994/* Compute real number of used bytes by file 1056/* Compute real number of used bytes by file
@@ -996,51 +1058,56 @@ reiserfs_readpages(struct file *file, struct address_space *mapping,
996 */ 1058 */
997static int real_space_diff(struct inode *inode, int sd_size) 1059static int real_space_diff(struct inode *inode, int sd_size)
998{ 1060{
999 int bytes; 1061 int bytes;
1000 loff_t blocksize = inode->i_sb->s_blocksize ; 1062 loff_t blocksize = inode->i_sb->s_blocksize;
1001 1063
1002 if (S_ISLNK(inode->i_mode) || S_ISDIR(inode->i_mode)) 1064 if (S_ISLNK(inode->i_mode) || S_ISDIR(inode->i_mode))
1003 return sd_size ; 1065 return sd_size;
1004 1066
1005 /* End of file is also in full block with indirect reference, so round 1067 /* End of file is also in full block with indirect reference, so round
1006 ** up to the next block. 1068 ** up to the next block.
1007 ** 1069 **
1008 ** there is just no way to know if the tail is actually packed 1070 ** there is just no way to know if the tail is actually packed
1009 ** on the file, so we have to assume it isn't. When we pack the 1071 ** on the file, so we have to assume it isn't. When we pack the
1010 ** tail, we add 4 bytes to pretend there really is an unformatted 1072 ** tail, we add 4 bytes to pretend there really is an unformatted
1011 ** node pointer 1073 ** node pointer
1012 */ 1074 */
1013 bytes = ((inode->i_size + (blocksize-1)) >> inode->i_sb->s_blocksize_bits) * UNFM_P_SIZE + sd_size; 1075 bytes =
1014 return bytes ; 1076 ((inode->i_size +
1077 (blocksize - 1)) >> inode->i_sb->s_blocksize_bits) * UNFM_P_SIZE +
1078 sd_size;
1079 return bytes;
1015} 1080}
1016 1081
1017static inline loff_t to_real_used_space(struct inode *inode, ulong blocks, 1082static inline loff_t to_real_used_space(struct inode *inode, ulong blocks,
1018 int sd_size) 1083 int sd_size)
1019{ 1084{
1020 if (S_ISLNK(inode->i_mode) || S_ISDIR(inode->i_mode)) { 1085 if (S_ISLNK(inode->i_mode) || S_ISDIR(inode->i_mode)) {
1021 return inode->i_size + (loff_t)(real_space_diff(inode, sd_size)) ; 1086 return inode->i_size +
1022 } 1087 (loff_t) (real_space_diff(inode, sd_size));
1023 return ((loff_t)real_space_diff(inode, sd_size)) + (((loff_t)blocks) << 9); 1088 }
1089 return ((loff_t) real_space_diff(inode, sd_size)) +
1090 (((loff_t) blocks) << 9);
1024} 1091}
1025 1092
1026/* Compute number of blocks used by file in ReiserFS counting */ 1093/* Compute number of blocks used by file in ReiserFS counting */
1027static inline ulong to_fake_used_blocks(struct inode *inode, int sd_size) 1094static inline ulong to_fake_used_blocks(struct inode *inode, int sd_size)
1028{ 1095{
1029 loff_t bytes = inode_get_bytes(inode) ; 1096 loff_t bytes = inode_get_bytes(inode);
1030 loff_t real_space = real_space_diff(inode, sd_size) ; 1097 loff_t real_space = real_space_diff(inode, sd_size);
1031 1098
1032 /* keeps fsck and non-quota versions of reiserfs happy */ 1099 /* keeps fsck and non-quota versions of reiserfs happy */
1033 if (S_ISLNK(inode->i_mode) || S_ISDIR(inode->i_mode)) { 1100 if (S_ISLNK(inode->i_mode) || S_ISDIR(inode->i_mode)) {
1034 bytes += (loff_t)511 ; 1101 bytes += (loff_t) 511;
1035 } 1102 }
1036 1103
1037 /* files from before the quota patch might i_blocks such that 1104 /* files from before the quota patch might i_blocks such that
1038 ** bytes < real_space. Deal with that here to prevent it from 1105 ** bytes < real_space. Deal with that here to prevent it from
1039 ** going negative. 1106 ** going negative.
1040 */ 1107 */
1041 if (bytes < real_space) 1108 if (bytes < real_space)
1042 return 0 ; 1109 return 0;
1043 return (bytes - real_space) >> 9; 1110 return (bytes - real_space) >> 9;
1044} 1111}
1045 1112
1046// 1113//
@@ -1051,263 +1118,269 @@ static inline ulong to_fake_used_blocks(struct inode *inode, int sd_size)
1051// 1118//
1052 1119
1053// called by read_locked_inode 1120// called by read_locked_inode
1054static void init_inode (struct inode * inode, struct path * path) 1121static void init_inode(struct inode *inode, struct path *path)
1055{ 1122{
1056 struct buffer_head * bh; 1123 struct buffer_head *bh;
1057 struct item_head * ih; 1124 struct item_head *ih;
1058 __u32 rdev; 1125 __u32 rdev;
1059 //int version = ITEM_VERSION_1; 1126 //int version = ITEM_VERSION_1;
1060 1127
1061 bh = PATH_PLAST_BUFFER (path); 1128 bh = PATH_PLAST_BUFFER(path);
1062 ih = PATH_PITEM_HEAD (path); 1129 ih = PATH_PITEM_HEAD(path);
1063 1130
1064 1131 copy_key(INODE_PKEY(inode), &(ih->ih_key));
1065 copy_key (INODE_PKEY (inode), &(ih->ih_key)); 1132 inode->i_blksize = reiserfs_default_io_size;
1066 inode->i_blksize = reiserfs_default_io_size; 1133
1067 1134 INIT_LIST_HEAD(&(REISERFS_I(inode)->i_prealloc_list));
1068 INIT_LIST_HEAD(&(REISERFS_I(inode)->i_prealloc_list )); 1135 REISERFS_I(inode)->i_flags = 0;
1069 REISERFS_I(inode)->i_flags = 0; 1136 REISERFS_I(inode)->i_prealloc_block = 0;
1070 REISERFS_I(inode)->i_prealloc_block = 0; 1137 REISERFS_I(inode)->i_prealloc_count = 0;
1071 REISERFS_I(inode)->i_prealloc_count = 0; 1138 REISERFS_I(inode)->i_trans_id = 0;
1072 REISERFS_I(inode)->i_trans_id = 0; 1139 REISERFS_I(inode)->i_jl = NULL;
1073 REISERFS_I(inode)->i_jl = NULL; 1140 REISERFS_I(inode)->i_acl_access = NULL;
1074 REISERFS_I(inode)->i_acl_access = NULL; 1141 REISERFS_I(inode)->i_acl_default = NULL;
1075 REISERFS_I(inode)->i_acl_default = NULL; 1142 init_rwsem(&REISERFS_I(inode)->xattr_sem);
1076 init_rwsem (&REISERFS_I(inode)->xattr_sem); 1143
1077 1144 if (stat_data_v1(ih)) {
1078 if (stat_data_v1 (ih)) { 1145 struct stat_data_v1 *sd =
1079 struct stat_data_v1 * sd = (struct stat_data_v1 *)B_I_PITEM (bh, ih); 1146 (struct stat_data_v1 *)B_I_PITEM(bh, ih);
1080 unsigned long blocks; 1147 unsigned long blocks;
1081 1148
1082 set_inode_item_key_version (inode, KEY_FORMAT_3_5); 1149 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
1083 set_inode_sd_version (inode, STAT_DATA_V1); 1150 set_inode_sd_version(inode, STAT_DATA_V1);
1084 inode->i_mode = sd_v1_mode(sd); 1151 inode->i_mode = sd_v1_mode(sd);
1085 inode->i_nlink = sd_v1_nlink(sd); 1152 inode->i_nlink = sd_v1_nlink(sd);
1086 inode->i_uid = sd_v1_uid(sd); 1153 inode->i_uid = sd_v1_uid(sd);
1087 inode->i_gid = sd_v1_gid(sd); 1154 inode->i_gid = sd_v1_gid(sd);
1088 inode->i_size = sd_v1_size(sd); 1155 inode->i_size = sd_v1_size(sd);
1089 inode->i_atime.tv_sec = sd_v1_atime(sd); 1156 inode->i_atime.tv_sec = sd_v1_atime(sd);
1090 inode->i_mtime.tv_sec = sd_v1_mtime(sd); 1157 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
1091 inode->i_ctime.tv_sec = sd_v1_ctime(sd); 1158 inode->i_ctime.tv_sec = sd_v1_ctime(sd);
1092 inode->i_atime.tv_nsec = 0; 1159 inode->i_atime.tv_nsec = 0;
1093 inode->i_ctime.tv_nsec = 0; 1160 inode->i_ctime.tv_nsec = 0;
1094 inode->i_mtime.tv_nsec = 0; 1161 inode->i_mtime.tv_nsec = 0;
1095 1162
1096 inode->i_blocks = sd_v1_blocks(sd); 1163 inode->i_blocks = sd_v1_blocks(sd);
1097 inode->i_generation = le32_to_cpu (INODE_PKEY (inode)->k_dir_id); 1164 inode->i_generation = le32_to_cpu(INODE_PKEY(inode)->k_dir_id);
1098 blocks = (inode->i_size + 511) >> 9; 1165 blocks = (inode->i_size + 511) >> 9;
1099 blocks = _ROUND_UP (blocks, inode->i_sb->s_blocksize >> 9); 1166 blocks = _ROUND_UP(blocks, inode->i_sb->s_blocksize >> 9);
1100 if (inode->i_blocks > blocks) { 1167 if (inode->i_blocks > blocks) {
1101 // there was a bug in <=3.5.23 when i_blocks could take negative 1168 // there was a bug in <=3.5.23 when i_blocks could take negative
1102 // values. Starting from 3.5.17 this value could even be stored in 1169 // values. Starting from 3.5.17 this value could even be stored in
1103 // stat data. For such files we set i_blocks based on file 1170 // stat data. For such files we set i_blocks based on file
1104 // size. Just 2 notes: this can be wrong for sparce files. On-disk value will be 1171 // size. Just 2 notes: this can be wrong for sparce files. On-disk value will be
1105 // only updated if file's inode will ever change 1172 // only updated if file's inode will ever change
1106 inode->i_blocks = blocks; 1173 inode->i_blocks = blocks;
1107 } 1174 }
1108
1109 rdev = sd_v1_rdev(sd);
1110 REISERFS_I(inode)->i_first_direct_byte = sd_v1_first_direct_byte(sd);
1111 /* an early bug in the quota code can give us an odd number for the
1112 ** block count. This is incorrect, fix it here.
1113 */
1114 if (inode->i_blocks & 1) {
1115 inode->i_blocks++ ;
1116 }
1117 inode_set_bytes(inode, to_real_used_space(inode, inode->i_blocks,
1118 SD_V1_SIZE));
1119 /* nopack is initially zero for v1 objects. For v2 objects,
1120 nopack is initialised from sd_attrs */
1121 REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
1122 } else {
1123 // new stat data found, but object may have old items
1124 // (directories and symlinks)
1125 struct stat_data * sd = (struct stat_data *)B_I_PITEM (bh, ih);
1126
1127 inode->i_mode = sd_v2_mode(sd);
1128 inode->i_nlink = sd_v2_nlink(sd);
1129 inode->i_uid = sd_v2_uid(sd);
1130 inode->i_size = sd_v2_size(sd);
1131 inode->i_gid = sd_v2_gid(sd);
1132 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
1133 inode->i_atime.tv_sec = sd_v2_atime(sd);
1134 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
1135 inode->i_ctime.tv_nsec = 0;
1136 inode->i_mtime.tv_nsec = 0;
1137 inode->i_atime.tv_nsec = 0;
1138 inode->i_blocks = sd_v2_blocks(sd);
1139 rdev = sd_v2_rdev(sd);
1140 if( S_ISCHR( inode -> i_mode ) || S_ISBLK( inode -> i_mode ) )
1141 inode->i_generation = le32_to_cpu (INODE_PKEY (inode)->k_dir_id);
1142 else
1143 inode->i_generation = sd_v2_generation(sd);
1144 1175
1145 if (S_ISDIR (inode->i_mode) || S_ISLNK (inode->i_mode)) 1176 rdev = sd_v1_rdev(sd);
1146 set_inode_item_key_version (inode, KEY_FORMAT_3_5); 1177 REISERFS_I(inode)->i_first_direct_byte =
1147 else 1178 sd_v1_first_direct_byte(sd);
1148 set_inode_item_key_version (inode, KEY_FORMAT_3_6); 1179 /* an early bug in the quota code can give us an odd number for the
1149 REISERFS_I(inode)->i_first_direct_byte = 0; 1180 ** block count. This is incorrect, fix it here.
1150 set_inode_sd_version (inode, STAT_DATA_V2); 1181 */
1151 inode_set_bytes(inode, to_real_used_space(inode, inode->i_blocks, 1182 if (inode->i_blocks & 1) {
1152 SD_V2_SIZE)); 1183 inode->i_blocks++;
1153 /* read persistent inode attributes from sd and initalise 1184 }
1154 generic inode flags from them */ 1185 inode_set_bytes(inode,
1155 REISERFS_I(inode)->i_attrs = sd_v2_attrs( sd ); 1186 to_real_used_space(inode, inode->i_blocks,
1156 sd_attrs_to_i_attrs( sd_v2_attrs( sd ), inode ); 1187 SD_V1_SIZE));
1157 } 1188 /* nopack is initially zero for v1 objects. For v2 objects,
1158 1189 nopack is initialised from sd_attrs */
1159 pathrelse (path); 1190 REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
1160 if (S_ISREG (inode->i_mode)) { 1191 } else {
1161 inode->i_op = &reiserfs_file_inode_operations; 1192 // new stat data found, but object may have old items
1162 inode->i_fop = &reiserfs_file_operations; 1193 // (directories and symlinks)
1163 inode->i_mapping->a_ops = &reiserfs_address_space_operations ; 1194 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
1164 } else if (S_ISDIR (inode->i_mode)) { 1195
1165 inode->i_op = &reiserfs_dir_inode_operations; 1196 inode->i_mode = sd_v2_mode(sd);
1166 inode->i_fop = &reiserfs_dir_operations; 1197 inode->i_nlink = sd_v2_nlink(sd);
1167 } else if (S_ISLNK (inode->i_mode)) { 1198 inode->i_uid = sd_v2_uid(sd);
1168 inode->i_op = &reiserfs_symlink_inode_operations; 1199 inode->i_size = sd_v2_size(sd);
1169 inode->i_mapping->a_ops = &reiserfs_address_space_operations; 1200 inode->i_gid = sd_v2_gid(sd);
1170 } else { 1201 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
1171 inode->i_blocks = 0; 1202 inode->i_atime.tv_sec = sd_v2_atime(sd);
1172 inode->i_op = &reiserfs_special_inode_operations; 1203 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
1173 init_special_inode(inode, inode->i_mode, new_decode_dev(rdev)); 1204 inode->i_ctime.tv_nsec = 0;
1174 } 1205 inode->i_mtime.tv_nsec = 0;
1175} 1206 inode->i_atime.tv_nsec = 0;
1207 inode->i_blocks = sd_v2_blocks(sd);
1208 rdev = sd_v2_rdev(sd);
1209 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
1210 inode->i_generation =
1211 le32_to_cpu(INODE_PKEY(inode)->k_dir_id);
1212 else
1213 inode->i_generation = sd_v2_generation(sd);
1176 1214
1215 if (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode))
1216 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
1217 else
1218 set_inode_item_key_version(inode, KEY_FORMAT_3_6);
1219 REISERFS_I(inode)->i_first_direct_byte = 0;
1220 set_inode_sd_version(inode, STAT_DATA_V2);
1221 inode_set_bytes(inode,
1222 to_real_used_space(inode, inode->i_blocks,
1223 SD_V2_SIZE));
1224 /* read persistent inode attributes from sd and initalise
1225 generic inode flags from them */
1226 REISERFS_I(inode)->i_attrs = sd_v2_attrs(sd);
1227 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
1228 }
1229
1230 pathrelse(path);
1231 if (S_ISREG(inode->i_mode)) {
1232 inode->i_op = &reiserfs_file_inode_operations;
1233 inode->i_fop = &reiserfs_file_operations;
1234 inode->i_mapping->a_ops = &reiserfs_address_space_operations;
1235 } else if (S_ISDIR(inode->i_mode)) {
1236 inode->i_op = &reiserfs_dir_inode_operations;
1237 inode->i_fop = &reiserfs_dir_operations;
1238 } else if (S_ISLNK(inode->i_mode)) {
1239 inode->i_op = &reiserfs_symlink_inode_operations;
1240 inode->i_mapping->a_ops = &reiserfs_address_space_operations;
1241 } else {
1242 inode->i_blocks = 0;
1243 inode->i_op = &reiserfs_special_inode_operations;
1244 init_special_inode(inode, inode->i_mode, new_decode_dev(rdev));
1245 }
1246}
1177 1247
1178// update new stat data with inode fields 1248// update new stat data with inode fields
1179static void inode2sd (void * sd, struct inode * inode, loff_t size) 1249static void inode2sd(void *sd, struct inode *inode, loff_t size)
1180{ 1250{
1181 struct stat_data * sd_v2 = (struct stat_data *)sd; 1251 struct stat_data *sd_v2 = (struct stat_data *)sd;
1182 __u16 flags; 1252 __u16 flags;
1183 1253
1184 set_sd_v2_mode(sd_v2, inode->i_mode ); 1254 set_sd_v2_mode(sd_v2, inode->i_mode);
1185 set_sd_v2_nlink(sd_v2, inode->i_nlink ); 1255 set_sd_v2_nlink(sd_v2, inode->i_nlink);
1186 set_sd_v2_uid(sd_v2, inode->i_uid ); 1256 set_sd_v2_uid(sd_v2, inode->i_uid);
1187 set_sd_v2_size(sd_v2, size ); 1257 set_sd_v2_size(sd_v2, size);
1188 set_sd_v2_gid(sd_v2, inode->i_gid ); 1258 set_sd_v2_gid(sd_v2, inode->i_gid);
1189 set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec ); 1259 set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
1190 set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec ); 1260 set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
1191 set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec ); 1261 set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
1192 set_sd_v2_blocks(sd_v2, to_fake_used_blocks(inode, SD_V2_SIZE)); 1262 set_sd_v2_blocks(sd_v2, to_fake_used_blocks(inode, SD_V2_SIZE));
1193 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) 1263 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
1194 set_sd_v2_rdev(sd_v2, new_encode_dev(inode->i_rdev)); 1264 set_sd_v2_rdev(sd_v2, new_encode_dev(inode->i_rdev));
1195 else 1265 else
1196 set_sd_v2_generation(sd_v2, inode->i_generation); 1266 set_sd_v2_generation(sd_v2, inode->i_generation);
1197 flags = REISERFS_I(inode)->i_attrs; 1267 flags = REISERFS_I(inode)->i_attrs;
1198 i_attrs_to_sd_attrs( inode, &flags ); 1268 i_attrs_to_sd_attrs(inode, &flags);
1199 set_sd_v2_attrs( sd_v2, flags ); 1269 set_sd_v2_attrs(sd_v2, flags);
1200} 1270}
1201 1271
1202
1203// used to copy inode's fields to old stat data 1272// used to copy inode's fields to old stat data
1204static void inode2sd_v1 (void * sd, struct inode * inode, loff_t size) 1273static void inode2sd_v1(void *sd, struct inode *inode, loff_t size)
1205{ 1274{
1206 struct stat_data_v1 * sd_v1 = (struct stat_data_v1 *)sd; 1275 struct stat_data_v1 *sd_v1 = (struct stat_data_v1 *)sd;
1207 1276
1208 set_sd_v1_mode(sd_v1, inode->i_mode ); 1277 set_sd_v1_mode(sd_v1, inode->i_mode);
1209 set_sd_v1_uid(sd_v1, inode->i_uid ); 1278 set_sd_v1_uid(sd_v1, inode->i_uid);
1210 set_sd_v1_gid(sd_v1, inode->i_gid ); 1279 set_sd_v1_gid(sd_v1, inode->i_gid);
1211 set_sd_v1_nlink(sd_v1, inode->i_nlink ); 1280 set_sd_v1_nlink(sd_v1, inode->i_nlink);
1212 set_sd_v1_size(sd_v1, size ); 1281 set_sd_v1_size(sd_v1, size);
1213 set_sd_v1_atime(sd_v1, inode->i_atime.tv_sec ); 1282 set_sd_v1_atime(sd_v1, inode->i_atime.tv_sec);
1214 set_sd_v1_ctime(sd_v1, inode->i_ctime.tv_sec ); 1283 set_sd_v1_ctime(sd_v1, inode->i_ctime.tv_sec);
1215 set_sd_v1_mtime(sd_v1, inode->i_mtime.tv_sec ); 1284 set_sd_v1_mtime(sd_v1, inode->i_mtime.tv_sec);
1216 1285
1217 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) 1286 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
1218 set_sd_v1_rdev(sd_v1, new_encode_dev(inode->i_rdev)); 1287 set_sd_v1_rdev(sd_v1, new_encode_dev(inode->i_rdev));
1219 else 1288 else
1220 set_sd_v1_blocks(sd_v1, to_fake_used_blocks(inode, SD_V1_SIZE)); 1289 set_sd_v1_blocks(sd_v1, to_fake_used_blocks(inode, SD_V1_SIZE));
1221
1222 // Sigh. i_first_direct_byte is back
1223 set_sd_v1_first_direct_byte(sd_v1, REISERFS_I(inode)->i_first_direct_byte);
1224}
1225 1290
1291 // Sigh. i_first_direct_byte is back
1292 set_sd_v1_first_direct_byte(sd_v1,
1293 REISERFS_I(inode)->i_first_direct_byte);
1294}
1226 1295
1227/* NOTE, you must prepare the buffer head before sending it here, 1296/* NOTE, you must prepare the buffer head before sending it here,
1228** and then log it after the call 1297** and then log it after the call
1229*/ 1298*/
1230static void update_stat_data (struct path * path, struct inode * inode, 1299static void update_stat_data(struct path *path, struct inode *inode,
1231 loff_t size) 1300 loff_t size)
1232{ 1301{
1233 struct buffer_head * bh; 1302 struct buffer_head *bh;
1234 struct item_head * ih; 1303 struct item_head *ih;
1235 1304
1236 bh = PATH_PLAST_BUFFER (path); 1305 bh = PATH_PLAST_BUFFER(path);
1237 ih = PATH_PITEM_HEAD (path); 1306 ih = PATH_PITEM_HEAD(path);
1238 1307
1239 if (!is_statdata_le_ih (ih)) 1308 if (!is_statdata_le_ih(ih))
1240 reiserfs_panic (inode->i_sb, "vs-13065: update_stat_data: key %k, found item %h", 1309 reiserfs_panic(inode->i_sb,
1241 INODE_PKEY (inode), ih); 1310 "vs-13065: update_stat_data: key %k, found item %h",
1242 1311 INODE_PKEY(inode), ih);
1243 if (stat_data_v1 (ih)) { 1312
1244 // path points to old stat data 1313 if (stat_data_v1(ih)) {
1245 inode2sd_v1 (B_I_PITEM (bh, ih), inode, size); 1314 // path points to old stat data
1246 } else { 1315 inode2sd_v1(B_I_PITEM(bh, ih), inode, size);
1247 inode2sd (B_I_PITEM (bh, ih), inode, size); 1316 } else {
1248 } 1317 inode2sd(B_I_PITEM(bh, ih), inode, size);
1249 1318 }
1250 return;
1251}
1252 1319
1320 return;
1321}
1253 1322
1254void reiserfs_update_sd_size (struct reiserfs_transaction_handle *th, 1323void reiserfs_update_sd_size(struct reiserfs_transaction_handle *th,
1255 struct inode * inode, loff_t size) 1324 struct inode *inode, loff_t size)
1256{ 1325{
1257 struct cpu_key key; 1326 struct cpu_key key;
1258 INITIALIZE_PATH(path); 1327 INITIALIZE_PATH(path);
1259 struct buffer_head *bh ; 1328 struct buffer_head *bh;
1260 int fs_gen ; 1329 int fs_gen;
1261 struct item_head *ih, tmp_ih ; 1330 struct item_head *ih, tmp_ih;
1262 int retval; 1331 int retval;
1263 1332
1264 BUG_ON (!th->t_trans_id); 1333 BUG_ON(!th->t_trans_id);
1265 1334
1266 make_cpu_key (&key, inode, SD_OFFSET, TYPE_STAT_DATA, 3);//key type is unimportant 1335 make_cpu_key(&key, inode, SD_OFFSET, TYPE_STAT_DATA, 3); //key type is unimportant
1267 1336
1268 for(;;) { 1337 for (;;) {
1269 int pos; 1338 int pos;
1270 /* look for the object's stat data */ 1339 /* look for the object's stat data */
1271 retval = search_item (inode->i_sb, &key, &path); 1340 retval = search_item(inode->i_sb, &key, &path);
1272 if (retval == IO_ERROR) { 1341 if (retval == IO_ERROR) {
1273 reiserfs_warning (inode->i_sb, "vs-13050: reiserfs_update_sd: " 1342 reiserfs_warning(inode->i_sb,
1274 "i/o failure occurred trying to update %K stat data", 1343 "vs-13050: reiserfs_update_sd: "
1275 &key); 1344 "i/o failure occurred trying to update %K stat data",
1276 return; 1345 &key);
1277 } 1346 return;
1278 if (retval == ITEM_NOT_FOUND) { 1347 }
1279 pos = PATH_LAST_POSITION (&path); 1348 if (retval == ITEM_NOT_FOUND) {
1280 pathrelse(&path) ; 1349 pos = PATH_LAST_POSITION(&path);
1281 if (inode->i_nlink == 0) { 1350 pathrelse(&path);
1282 /*reiserfs_warning (inode->i_sb, "vs-13050: reiserfs_update_sd: i_nlink == 0, stat data not found");*/ 1351 if (inode->i_nlink == 0) {
1283 return; 1352 /*reiserfs_warning (inode->i_sb, "vs-13050: reiserfs_update_sd: i_nlink == 0, stat data not found"); */
1284 } 1353 return;
1285 reiserfs_warning (inode->i_sb, "vs-13060: reiserfs_update_sd: " 1354 }
1286 "stat data of object %k (nlink == %d) not found (pos %d)", 1355 reiserfs_warning(inode->i_sb,
1287 INODE_PKEY (inode), inode->i_nlink, pos); 1356 "vs-13060: reiserfs_update_sd: "
1288 reiserfs_check_path(&path) ; 1357 "stat data of object %k (nlink == %d) not found (pos %d)",
1289 return; 1358 INODE_PKEY(inode), inode->i_nlink,
1290 } 1359 pos);
1291 1360 reiserfs_check_path(&path);
1292 /* sigh, prepare_for_journal might schedule. When it schedules the 1361 return;
1293 ** FS might change. We have to detect that, and loop back to the 1362 }
1294 ** search if the stat data item has moved 1363
1295 */ 1364 /* sigh, prepare_for_journal might schedule. When it schedules the
1296 bh = get_last_bh(&path) ; 1365 ** FS might change. We have to detect that, and loop back to the
1297 ih = get_ih(&path) ; 1366 ** search if the stat data item has moved
1298 copy_item_head (&tmp_ih, ih); 1367 */
1299 fs_gen = get_generation (inode->i_sb); 1368 bh = get_last_bh(&path);
1300 reiserfs_prepare_for_journal(inode->i_sb, bh, 1) ; 1369 ih = get_ih(&path);
1301 if (fs_changed (fs_gen, inode->i_sb) && item_moved(&tmp_ih, &path)) { 1370 copy_item_head(&tmp_ih, ih);
1302 reiserfs_restore_prepared_buffer(inode->i_sb, bh) ; 1371 fs_gen = get_generation(inode->i_sb);
1303 continue ; /* Stat_data item has been moved after scheduling. */ 1372 reiserfs_prepare_for_journal(inode->i_sb, bh, 1);
1304 } 1373 if (fs_changed(fs_gen, inode->i_sb)
1305 break; 1374 && item_moved(&tmp_ih, &path)) {
1306 } 1375 reiserfs_restore_prepared_buffer(inode->i_sb, bh);
1307 update_stat_data (&path, inode, size); 1376 continue; /* Stat_data item has been moved after scheduling. */
1308 journal_mark_dirty(th, th->t_super, bh) ; 1377 }
1309 pathrelse (&path); 1378 break;
1310 return; 1379 }
1380 update_stat_data(&path, inode, size);
1381 journal_mark_dirty(th, th->t_super, bh);
1382 pathrelse(&path);
1383 return;
1311} 1384}
1312 1385
1313/* reiserfs_read_locked_inode is called to read the inode off disk, and it 1386/* reiserfs_read_locked_inode is called to read the inode off disk, and it
@@ -1316,9 +1389,10 @@ void reiserfs_update_sd_size (struct reiserfs_transaction_handle *th,
1316** corresponding iput might try to delete whatever object the inode last 1389** corresponding iput might try to delete whatever object the inode last
1317** represented. 1390** represented.
1318*/ 1391*/
1319static void reiserfs_make_bad_inode(struct inode *inode) { 1392static void reiserfs_make_bad_inode(struct inode *inode)
1320 memset(INODE_PKEY(inode), 0, KEY_SIZE); 1393{
1321 make_bad_inode(inode); 1394 memset(INODE_PKEY(inode), 0, KEY_SIZE);
1395 make_bad_inode(inode);
1322} 1396}
1323 1397
1324// 1398//
@@ -1326,77 +1400,79 @@ static void reiserfs_make_bad_inode(struct inode *inode) {
1326// evolved as the prototype did 1400// evolved as the prototype did
1327// 1401//
1328 1402
1329int reiserfs_init_locked_inode (struct inode * inode, void *p) 1403int reiserfs_init_locked_inode(struct inode *inode, void *p)
1330{ 1404{
1331 struct reiserfs_iget_args *args = (struct reiserfs_iget_args *)p ; 1405 struct reiserfs_iget_args *args = (struct reiserfs_iget_args *)p;
1332 inode->i_ino = args->objectid; 1406 inode->i_ino = args->objectid;
1333 INODE_PKEY(inode)->k_dir_id = cpu_to_le32(args->dirid); 1407 INODE_PKEY(inode)->k_dir_id = cpu_to_le32(args->dirid);
1334 return 0; 1408 return 0;
1335} 1409}
1336 1410
1337/* looks for stat data in the tree, and fills up the fields of in-core 1411/* looks for stat data in the tree, and fills up the fields of in-core
1338 inode stat data fields */ 1412 inode stat data fields */
1339void reiserfs_read_locked_inode (struct inode * inode, struct reiserfs_iget_args *args) 1413void reiserfs_read_locked_inode(struct inode *inode,
1414 struct reiserfs_iget_args *args)
1340{ 1415{
1341 INITIALIZE_PATH (path_to_sd); 1416 INITIALIZE_PATH(path_to_sd);
1342 struct cpu_key key; 1417 struct cpu_key key;
1343 unsigned long dirino; 1418 unsigned long dirino;
1344 int retval; 1419 int retval;
1345 1420
1346 dirino = args->dirid ; 1421 dirino = args->dirid;
1347 1422
1348 /* set version 1, version 2 could be used too, because stat data 1423 /* set version 1, version 2 could be used too, because stat data
1349 key is the same in both versions */ 1424 key is the same in both versions */
1350 key.version = KEY_FORMAT_3_5; 1425 key.version = KEY_FORMAT_3_5;
1351 key.on_disk_key.k_dir_id = dirino; 1426 key.on_disk_key.k_dir_id = dirino;
1352 key.on_disk_key.k_objectid = inode->i_ino; 1427 key.on_disk_key.k_objectid = inode->i_ino;
1353 key.on_disk_key.k_offset = 0; 1428 key.on_disk_key.k_offset = 0;
1354 key.on_disk_key.k_type = 0; 1429 key.on_disk_key.k_type = 0;
1355 1430
1356 /* look for the object's stat data */ 1431 /* look for the object's stat data */
1357 retval = search_item (inode->i_sb, &key, &path_to_sd); 1432 retval = search_item(inode->i_sb, &key, &path_to_sd);
1358 if (retval == IO_ERROR) { 1433 if (retval == IO_ERROR) {
1359 reiserfs_warning (inode->i_sb, "vs-13070: reiserfs_read_locked_inode: " 1434 reiserfs_warning(inode->i_sb,
1360 "i/o failure occurred trying to find stat data of %K", 1435 "vs-13070: reiserfs_read_locked_inode: "
1361 &key); 1436 "i/o failure occurred trying to find stat data of %K",
1362 reiserfs_make_bad_inode(inode) ; 1437 &key);
1363 return; 1438 reiserfs_make_bad_inode(inode);
1364 } 1439 return;
1365 if (retval != ITEM_FOUND) { 1440 }
1366 /* a stale NFS handle can trigger this without it being an error */ 1441 if (retval != ITEM_FOUND) {
1367 pathrelse (&path_to_sd); 1442 /* a stale NFS handle can trigger this without it being an error */
1368 reiserfs_make_bad_inode(inode) ; 1443 pathrelse(&path_to_sd);
1369 inode->i_nlink = 0; 1444 reiserfs_make_bad_inode(inode);
1370 return; 1445 inode->i_nlink = 0;
1371 } 1446 return;
1372 1447 }
1373 init_inode (inode, &path_to_sd); 1448
1374 1449 init_inode(inode, &path_to_sd);
1375 /* It is possible that knfsd is trying to access inode of a file 1450
1376 that is being removed from the disk by some other thread. As we 1451 /* It is possible that knfsd is trying to access inode of a file
1377 update sd on unlink all that is required is to check for nlink 1452 that is being removed from the disk by some other thread. As we
1378 here. This bug was first found by Sizif when debugging 1453 update sd on unlink all that is required is to check for nlink
1379 SquidNG/Butterfly, forgotten, and found again after Philippe 1454 here. This bug was first found by Sizif when debugging
1380 Gramoulle <philippe.gramoulle@mmania.com> reproduced it. 1455 SquidNG/Butterfly, forgotten, and found again after Philippe
1381 1456 Gramoulle <philippe.gramoulle@mmania.com> reproduced it.
1382 More logical fix would require changes in fs/inode.c:iput() to 1457
1383 remove inode from hash-table _after_ fs cleaned disk stuff up and 1458 More logical fix would require changes in fs/inode.c:iput() to
1384 in iget() to return NULL if I_FREEING inode is found in 1459 remove inode from hash-table _after_ fs cleaned disk stuff up and
1385 hash-table. */ 1460 in iget() to return NULL if I_FREEING inode is found in
1386 /* Currently there is one place where it's ok to meet inode with 1461 hash-table. */
1387 nlink==0: processing of open-unlinked and half-truncated files 1462 /* Currently there is one place where it's ok to meet inode with
1388 during mount (fs/reiserfs/super.c:finish_unfinished()). */ 1463 nlink==0: processing of open-unlinked and half-truncated files
1389 if( ( inode -> i_nlink == 0 ) && 1464 during mount (fs/reiserfs/super.c:finish_unfinished()). */
1390 ! REISERFS_SB(inode -> i_sb) -> s_is_unlinked_ok ) { 1465 if ((inode->i_nlink == 0) &&
1391 reiserfs_warning (inode->i_sb, 1466 !REISERFS_SB(inode->i_sb)->s_is_unlinked_ok) {
1392 "vs-13075: reiserfs_read_locked_inode: " 1467 reiserfs_warning(inode->i_sb,
1393 "dead inode read from disk %K. " 1468 "vs-13075: reiserfs_read_locked_inode: "
1394 "This is likely to be race with knfsd. Ignore", 1469 "dead inode read from disk %K. "
1395 &key ); 1470 "This is likely to be race with knfsd. Ignore",
1396 reiserfs_make_bad_inode( inode ); 1471 &key);
1397 } 1472 reiserfs_make_bad_inode(inode);
1398 1473 }
1399 reiserfs_check_path(&path_to_sd) ; /* init inode should be relsing */ 1474
1475 reiserfs_check_path(&path_to_sd); /* init inode should be relsing */
1400 1476
1401} 1477}
1402 1478
@@ -1412,140 +1488,148 @@ void reiserfs_read_locked_inode (struct inode * inode, struct reiserfs_iget_args
1412 * inode numbers (objectids) are distinguished by parent directory ids. 1488 * inode numbers (objectids) are distinguished by parent directory ids.
1413 * 1489 *
1414 */ 1490 */
1415int reiserfs_find_actor( struct inode *inode, void *opaque ) 1491int reiserfs_find_actor(struct inode *inode, void *opaque)
1416{ 1492{
1417 struct reiserfs_iget_args *args; 1493 struct reiserfs_iget_args *args;
1418 1494
1419 args = opaque; 1495 args = opaque;
1420 /* args is already in CPU order */ 1496 /* args is already in CPU order */
1421 return (inode->i_ino == args->objectid) && 1497 return (inode->i_ino == args->objectid) &&
1422 (le32_to_cpu(INODE_PKEY(inode)->k_dir_id) == args->dirid); 1498 (le32_to_cpu(INODE_PKEY(inode)->k_dir_id) == args->dirid);
1423} 1499}
1424 1500
1425struct inode * reiserfs_iget (struct super_block * s, const struct cpu_key * key) 1501struct inode *reiserfs_iget(struct super_block *s, const struct cpu_key *key)
1426{ 1502{
1427 struct inode * inode; 1503 struct inode *inode;
1428 struct reiserfs_iget_args args ; 1504 struct reiserfs_iget_args args;
1429 1505
1430 args.objectid = key->on_disk_key.k_objectid ; 1506 args.objectid = key->on_disk_key.k_objectid;
1431 args.dirid = key->on_disk_key.k_dir_id ; 1507 args.dirid = key->on_disk_key.k_dir_id;
1432 inode = iget5_locked (s, key->on_disk_key.k_objectid, 1508 inode = iget5_locked(s, key->on_disk_key.k_objectid,
1433 reiserfs_find_actor, reiserfs_init_locked_inode, (void *)(&args)); 1509 reiserfs_find_actor, reiserfs_init_locked_inode,
1434 if (!inode) 1510 (void *)(&args));
1435 return ERR_PTR(-ENOMEM) ; 1511 if (!inode)
1436 1512 return ERR_PTR(-ENOMEM);
1437 if (inode->i_state & I_NEW) { 1513
1438 reiserfs_read_locked_inode(inode, &args); 1514 if (inode->i_state & I_NEW) {
1439 unlock_new_inode(inode); 1515 reiserfs_read_locked_inode(inode, &args);
1440 } 1516 unlock_new_inode(inode);
1441 1517 }
1442 if (comp_short_keys (INODE_PKEY (inode), key) || is_bad_inode (inode)) { 1518
1443 /* either due to i/o error or a stale NFS handle */ 1519 if (comp_short_keys(INODE_PKEY(inode), key) || is_bad_inode(inode)) {
1444 iput (inode); 1520 /* either due to i/o error or a stale NFS handle */
1445 inode = NULL; 1521 iput(inode);
1446 } 1522 inode = NULL;
1447 return inode; 1523 }
1524 return inode;
1448} 1525}
1449 1526
1450struct dentry *reiserfs_get_dentry(struct super_block *sb, void *vobjp) 1527struct dentry *reiserfs_get_dentry(struct super_block *sb, void *vobjp)
1451{ 1528{
1452 __u32 *data = vobjp; 1529 __u32 *data = vobjp;
1453 struct cpu_key key ; 1530 struct cpu_key key;
1454 struct dentry *result; 1531 struct dentry *result;
1455 struct inode *inode; 1532 struct inode *inode;
1456 1533
1457 key.on_disk_key.k_objectid = data[0] ; 1534 key.on_disk_key.k_objectid = data[0];
1458 key.on_disk_key.k_dir_id = data[1] ; 1535 key.on_disk_key.k_dir_id = data[1];
1459 reiserfs_write_lock(sb); 1536 reiserfs_write_lock(sb);
1460 inode = reiserfs_iget(sb, &key) ; 1537 inode = reiserfs_iget(sb, &key);
1461 if (inode && !IS_ERR(inode) && data[2] != 0 && 1538 if (inode && !IS_ERR(inode) && data[2] != 0 &&
1462 data[2] != inode->i_generation) { 1539 data[2] != inode->i_generation) {
1463 iput(inode) ; 1540 iput(inode);
1464 inode = NULL ; 1541 inode = NULL;
1465 } 1542 }
1466 reiserfs_write_unlock(sb); 1543 reiserfs_write_unlock(sb);
1467 if (!inode) 1544 if (!inode)
1468 inode = ERR_PTR(-ESTALE); 1545 inode = ERR_PTR(-ESTALE);
1469 if (IS_ERR(inode)) 1546 if (IS_ERR(inode))
1470 return ERR_PTR(PTR_ERR(inode)); 1547 return ERR_PTR(PTR_ERR(inode));
1471 result = d_alloc_anon(inode); 1548 result = d_alloc_anon(inode);
1472 if (!result) { 1549 if (!result) {
1473 iput(inode); 1550 iput(inode);
1474 return ERR_PTR(-ENOMEM); 1551 return ERR_PTR(-ENOMEM);
1475 } 1552 }
1476 return result; 1553 return result;
1477} 1554}
1478 1555
1479struct dentry *reiserfs_decode_fh(struct super_block *sb, __u32 *data, 1556struct dentry *reiserfs_decode_fh(struct super_block *sb, __u32 * data,
1480 int len, int fhtype, 1557 int len, int fhtype,
1481 int (*acceptable)(void *contect, struct dentry *de), 1558 int (*acceptable) (void *contect,
1482 void *context) { 1559 struct dentry * de),
1483 __u32 obj[3], parent[3]; 1560 void *context)
1484 1561{
1485 /* fhtype happens to reflect the number of u32s encoded. 1562 __u32 obj[3], parent[3];
1486 * due to a bug in earlier code, fhtype might indicate there 1563
1487 * are more u32s then actually fitted. 1564 /* fhtype happens to reflect the number of u32s encoded.
1488 * so if fhtype seems to be more than len, reduce fhtype. 1565 * due to a bug in earlier code, fhtype might indicate there
1489 * Valid types are: 1566 * are more u32s then actually fitted.
1490 * 2 - objectid + dir_id - legacy support 1567 * so if fhtype seems to be more than len, reduce fhtype.
1491 * 3 - objectid + dir_id + generation 1568 * Valid types are:
1492 * 4 - objectid + dir_id + objectid and dirid of parent - legacy 1569 * 2 - objectid + dir_id - legacy support
1493 * 5 - objectid + dir_id + generation + objectid and dirid of parent 1570 * 3 - objectid + dir_id + generation
1494 * 6 - as above plus generation of directory 1571 * 4 - objectid + dir_id + objectid and dirid of parent - legacy
1495 * 6 does not fit in NFSv2 handles 1572 * 5 - objectid + dir_id + generation + objectid and dirid of parent
1496 */ 1573 * 6 - as above plus generation of directory
1497 if (fhtype > len) { 1574 * 6 does not fit in NFSv2 handles
1498 if (fhtype != 6 || len != 5) 1575 */
1499 reiserfs_warning (sb, "nfsd/reiserfs, fhtype=%d, len=%d - odd", 1576 if (fhtype > len) {
1500 fhtype, len); 1577 if (fhtype != 6 || len != 5)
1501 fhtype = 5; 1578 reiserfs_warning(sb,
1502 } 1579 "nfsd/reiserfs, fhtype=%d, len=%d - odd",
1503 1580 fhtype, len);
1504 obj[0] = data[0]; 1581 fhtype = 5;
1505 obj[1] = data[1]; 1582 }
1506 if (fhtype == 3 || fhtype >= 5) 1583
1507 obj[2] = data[2]; 1584 obj[0] = data[0];
1508 else obj[2] = 0; /* generation number */ 1585 obj[1] = data[1];
1509 1586 if (fhtype == 3 || fhtype >= 5)
1510 if (fhtype >= 4) { 1587 obj[2] = data[2];
1511 parent[0] = data[fhtype>=5?3:2] ; 1588 else
1512 parent[1] = data[fhtype>=5?4:3] ; 1589 obj[2] = 0; /* generation number */
1513 if (fhtype == 6)
1514 parent[2] = data[5];
1515 else parent[2] = 0;
1516 }
1517 return sb->s_export_op->find_exported_dentry(sb, obj, fhtype < 4 ? NULL : parent,
1518 acceptable, context);
1519}
1520 1590
1521int reiserfs_encode_fh(struct dentry *dentry, __u32 *data, int *lenp, int need_parent) { 1591 if (fhtype >= 4) {
1522 struct inode *inode = dentry->d_inode ; 1592 parent[0] = data[fhtype >= 5 ? 3 : 2];
1523 int maxlen = *lenp; 1593 parent[1] = data[fhtype >= 5 ? 4 : 3];
1524 1594 if (fhtype == 6)
1525 if (maxlen < 3) 1595 parent[2] = data[5];
1526 return 255 ; 1596 else
1527 1597 parent[2] = 0;
1528 data[0] = inode->i_ino ; 1598 }
1529 data[1] = le32_to_cpu(INODE_PKEY (inode)->k_dir_id) ; 1599 return sb->s_export_op->find_exported_dentry(sb, obj,
1530 data[2] = inode->i_generation ; 1600 fhtype < 4 ? NULL : parent,
1531 *lenp = 3 ; 1601 acceptable, context);
1532 /* no room for directory info? return what we've stored so far */
1533 if (maxlen < 5 || ! need_parent)
1534 return 3 ;
1535
1536 spin_lock(&dentry->d_lock);
1537 inode = dentry->d_parent->d_inode ;
1538 data[3] = inode->i_ino ;
1539 data[4] = le32_to_cpu(INODE_PKEY (inode)->k_dir_id) ;
1540 *lenp = 5 ;
1541 if (maxlen >= 6) {
1542 data[5] = inode->i_generation ;
1543 *lenp = 6 ;
1544 }
1545 spin_unlock(&dentry->d_lock);
1546 return *lenp ;
1547} 1602}
1548 1603
1604int reiserfs_encode_fh(struct dentry *dentry, __u32 * data, int *lenp,
1605 int need_parent)
1606{
1607 struct inode *inode = dentry->d_inode;
1608 int maxlen = *lenp;
1609
1610 if (maxlen < 3)
1611 return 255;
1612
1613 data[0] = inode->i_ino;
1614 data[1] = le32_to_cpu(INODE_PKEY(inode)->k_dir_id);
1615 data[2] = inode->i_generation;
1616 *lenp = 3;
1617 /* no room for directory info? return what we've stored so far */
1618 if (maxlen < 5 || !need_parent)
1619 return 3;
1620
1621 spin_lock(&dentry->d_lock);
1622 inode = dentry->d_parent->d_inode;
1623 data[3] = inode->i_ino;
1624 data[4] = le32_to_cpu(INODE_PKEY(inode)->k_dir_id);
1625 *lenp = 5;
1626 if (maxlen >= 6) {
1627 data[5] = inode->i_generation;
1628 *lenp = 6;
1629 }
1630 spin_unlock(&dentry->d_lock);
1631 return *lenp;
1632}
1549 1633
1550/* looks for stat data, then copies fields to it, marks the buffer 1634/* looks for stat data, then copies fields to it, marks the buffer
1551 containing stat data as dirty */ 1635 containing stat data as dirty */
@@ -1554,120 +1638,127 @@ int reiserfs_encode_fh(struct dentry *dentry, __u32 *data, int *lenp, int need_p
1554** to properly mark inodes for datasync and such, but only actually 1638** to properly mark inodes for datasync and such, but only actually
1555** does something when called for a synchronous update. 1639** does something when called for a synchronous update.
1556*/ 1640*/
1557int reiserfs_write_inode (struct inode * inode, int do_sync) { 1641int reiserfs_write_inode(struct inode *inode, int do_sync)
1558 struct reiserfs_transaction_handle th ; 1642{
1559 int jbegin_count = 1 ; 1643 struct reiserfs_transaction_handle th;
1560 1644 int jbegin_count = 1;
1561 if (inode->i_sb->s_flags & MS_RDONLY) 1645
1562 return -EROFS; 1646 if (inode->i_sb->s_flags & MS_RDONLY)
1563 /* memory pressure can sometimes initiate write_inode calls with sync == 1, 1647 return -EROFS;
1564 ** these cases are just when the system needs ram, not when the 1648 /* memory pressure can sometimes initiate write_inode calls with sync == 1,
1565 ** inode needs to reach disk for safety, and they can safely be 1649 ** these cases are just when the system needs ram, not when the
1566 ** ignored because the altered inode has already been logged. 1650 ** inode needs to reach disk for safety, and they can safely be
1567 */ 1651 ** ignored because the altered inode has already been logged.
1568 if (do_sync && !(current->flags & PF_MEMALLOC)) { 1652 */
1569 reiserfs_write_lock(inode->i_sb); 1653 if (do_sync && !(current->flags & PF_MEMALLOC)) {
1570 if (!journal_begin(&th, inode->i_sb, jbegin_count)) { 1654 reiserfs_write_lock(inode->i_sb);
1571 reiserfs_update_sd (&th, inode); 1655 if (!journal_begin(&th, inode->i_sb, jbegin_count)) {
1572 journal_end_sync(&th, inode->i_sb, jbegin_count) ; 1656 reiserfs_update_sd(&th, inode);
1573 } 1657 journal_end_sync(&th, inode->i_sb, jbegin_count);
1574 reiserfs_write_unlock(inode->i_sb); 1658 }
1575 } 1659 reiserfs_write_unlock(inode->i_sb);
1576 return 0; 1660 }
1661 return 0;
1577} 1662}
1578 1663
1579/* stat data of new object is inserted already, this inserts the item 1664/* stat data of new object is inserted already, this inserts the item
1580 containing "." and ".." entries */ 1665 containing "." and ".." entries */
1581static int reiserfs_new_directory (struct reiserfs_transaction_handle *th, 1666static int reiserfs_new_directory(struct reiserfs_transaction_handle *th,
1582 struct inode *inode, 1667 struct inode *inode,
1583 struct item_head * ih, struct path * path, 1668 struct item_head *ih, struct path *path,
1584 struct inode * dir) 1669 struct inode *dir)
1585{ 1670{
1586 struct super_block * sb = th->t_super; 1671 struct super_block *sb = th->t_super;
1587 char empty_dir [EMPTY_DIR_SIZE]; 1672 char empty_dir[EMPTY_DIR_SIZE];
1588 char * body = empty_dir; 1673 char *body = empty_dir;
1589 struct cpu_key key; 1674 struct cpu_key key;
1590 int retval; 1675 int retval;
1591 1676
1592 BUG_ON (!th->t_trans_id); 1677 BUG_ON(!th->t_trans_id);
1593 1678
1594 _make_cpu_key (&key, KEY_FORMAT_3_5, le32_to_cpu (ih->ih_key.k_dir_id), 1679 _make_cpu_key(&key, KEY_FORMAT_3_5, le32_to_cpu(ih->ih_key.k_dir_id),
1595 le32_to_cpu (ih->ih_key.k_objectid), DOT_OFFSET, TYPE_DIRENTRY, 3/*key length*/); 1680 le32_to_cpu(ih->ih_key.k_objectid), DOT_OFFSET,
1596 1681 TYPE_DIRENTRY, 3 /*key length */ );
1597 /* compose item head for new item. Directories consist of items of 1682
1598 old type (ITEM_VERSION_1). Do not set key (second arg is 0), it 1683 /* compose item head for new item. Directories consist of items of
1599 is done by reiserfs_new_inode */ 1684 old type (ITEM_VERSION_1). Do not set key (second arg is 0), it
1600 if (old_format_only (sb)) { 1685 is done by reiserfs_new_inode */
1601 make_le_item_head (ih, NULL, KEY_FORMAT_3_5, DOT_OFFSET, TYPE_DIRENTRY, EMPTY_DIR_SIZE_V1, 2); 1686 if (old_format_only(sb)) {
1602 1687 make_le_item_head(ih, NULL, KEY_FORMAT_3_5, DOT_OFFSET,
1603 make_empty_dir_item_v1 (body, ih->ih_key.k_dir_id, ih->ih_key.k_objectid, 1688 TYPE_DIRENTRY, EMPTY_DIR_SIZE_V1, 2);
1604 INODE_PKEY (dir)->k_dir_id, 1689
1605 INODE_PKEY (dir)->k_objectid ); 1690 make_empty_dir_item_v1(body, ih->ih_key.k_dir_id,
1606 } else { 1691 ih->ih_key.k_objectid,
1607 make_le_item_head (ih, NULL, KEY_FORMAT_3_5, DOT_OFFSET, TYPE_DIRENTRY, EMPTY_DIR_SIZE, 2); 1692 INODE_PKEY(dir)->k_dir_id,
1608 1693 INODE_PKEY(dir)->k_objectid);
1609 make_empty_dir_item (body, ih->ih_key.k_dir_id, ih->ih_key.k_objectid, 1694 } else {
1610 INODE_PKEY (dir)->k_dir_id, 1695 make_le_item_head(ih, NULL, KEY_FORMAT_3_5, DOT_OFFSET,
1611 INODE_PKEY (dir)->k_objectid ); 1696 TYPE_DIRENTRY, EMPTY_DIR_SIZE, 2);
1612 } 1697
1613 1698 make_empty_dir_item(body, ih->ih_key.k_dir_id,
1614 /* look for place in the tree for new item */ 1699 ih->ih_key.k_objectid,
1615 retval = search_item (sb, &key, path); 1700 INODE_PKEY(dir)->k_dir_id,
1616 if (retval == IO_ERROR) { 1701 INODE_PKEY(dir)->k_objectid);
1617 reiserfs_warning (sb, "vs-13080: reiserfs_new_directory: " 1702 }
1618 "i/o failure occurred creating new directory"); 1703
1619 return -EIO; 1704 /* look for place in the tree for new item */
1620 } 1705 retval = search_item(sb, &key, path);
1621 if (retval == ITEM_FOUND) { 1706 if (retval == IO_ERROR) {
1622 pathrelse (path); 1707 reiserfs_warning(sb, "vs-13080: reiserfs_new_directory: "
1623 reiserfs_warning (sb, "vs-13070: reiserfs_new_directory: " 1708 "i/o failure occurred creating new directory");
1624 "object with this key exists (%k)", &(ih->ih_key)); 1709 return -EIO;
1625 return -EEXIST; 1710 }
1626 } 1711 if (retval == ITEM_FOUND) {
1627 1712 pathrelse(path);
1628 /* insert item, that is empty directory item */ 1713 reiserfs_warning(sb, "vs-13070: reiserfs_new_directory: "
1629 return reiserfs_insert_item (th, path, &key, ih, inode, body); 1714 "object with this key exists (%k)",
1630} 1715 &(ih->ih_key));
1716 return -EEXIST;
1717 }
1631 1718
1719 /* insert item, that is empty directory item */
1720 return reiserfs_insert_item(th, path, &key, ih, inode, body);
1721}
1632 1722
1633/* stat data of object has been inserted, this inserts the item 1723/* stat data of object has been inserted, this inserts the item
1634 containing the body of symlink */ 1724 containing the body of symlink */
1635static int reiserfs_new_symlink (struct reiserfs_transaction_handle *th, 1725static int reiserfs_new_symlink(struct reiserfs_transaction_handle *th, struct inode *inode, /* Inode of symlink */
1636 struct inode *inode, /* Inode of symlink */ 1726 struct item_head *ih,
1637 struct item_head * ih, 1727 struct path *path, const char *symname,
1638 struct path * path, const char * symname, int item_len) 1728 int item_len)
1639{ 1729{
1640 struct super_block * sb = th->t_super; 1730 struct super_block *sb = th->t_super;
1641 struct cpu_key key; 1731 struct cpu_key key;
1642 int retval; 1732 int retval;
1643 1733
1644 BUG_ON (!th->t_trans_id); 1734 BUG_ON(!th->t_trans_id);
1645 1735
1646 _make_cpu_key (&key, KEY_FORMAT_3_5, 1736 _make_cpu_key(&key, KEY_FORMAT_3_5,
1647 le32_to_cpu (ih->ih_key.k_dir_id), 1737 le32_to_cpu(ih->ih_key.k_dir_id),
1648 le32_to_cpu (ih->ih_key.k_objectid), 1738 le32_to_cpu(ih->ih_key.k_objectid),
1649 1, TYPE_DIRECT, 3/*key length*/); 1739 1, TYPE_DIRECT, 3 /*key length */ );
1650 1740
1651 make_le_item_head (ih, NULL, KEY_FORMAT_3_5, 1, TYPE_DIRECT, item_len, 0/*free_space*/); 1741 make_le_item_head(ih, NULL, KEY_FORMAT_3_5, 1, TYPE_DIRECT, item_len,
1652 1742 0 /*free_space */ );
1653 /* look for place in the tree for new item */ 1743
1654 retval = search_item (sb, &key, path); 1744 /* look for place in the tree for new item */
1655 if (retval == IO_ERROR) { 1745 retval = search_item(sb, &key, path);
1656 reiserfs_warning (sb, "vs-13080: reiserfs_new_symlinik: " 1746 if (retval == IO_ERROR) {
1657 "i/o failure occurred creating new symlink"); 1747 reiserfs_warning(sb, "vs-13080: reiserfs_new_symlinik: "
1658 return -EIO; 1748 "i/o failure occurred creating new symlink");
1659 } 1749 return -EIO;
1660 if (retval == ITEM_FOUND) { 1750 }
1661 pathrelse (path); 1751 if (retval == ITEM_FOUND) {
1662 reiserfs_warning (sb, "vs-13080: reiserfs_new_symlink: " 1752 pathrelse(path);
1663 "object with this key exists (%k)", &(ih->ih_key)); 1753 reiserfs_warning(sb, "vs-13080: reiserfs_new_symlink: "
1664 return -EEXIST; 1754 "object with this key exists (%k)",
1665 } 1755 &(ih->ih_key));
1666 1756 return -EEXIST;
1667 /* insert item, that is body of symlink */ 1757 }
1668 return reiserfs_insert_item (th, path, &key, ih, inode, symname);
1669}
1670 1758
1759 /* insert item, that is body of symlink */
1760 return reiserfs_insert_item(th, path, &key, ih, inode, symname);
1761}
1671 1762
1672/* inserts the stat data into the tree, and then calls 1763/* inserts the stat data into the tree, and then calls
1673 reiserfs_new_directory (to insert ".", ".." item if new object is 1764 reiserfs_new_directory (to insert ".", ".." item if new object is
@@ -1678,213 +1769,219 @@ static int reiserfs_new_symlink (struct reiserfs_transaction_handle *th,
1678 non-zero due to an error, we have to drop the quota previously allocated 1769 non-zero due to an error, we have to drop the quota previously allocated
1679 for the fresh inode. This can only be done outside a transaction, so 1770 for the fresh inode. This can only be done outside a transaction, so
1680 if we return non-zero, we also end the transaction. */ 1771 if we return non-zero, we also end the transaction. */
1681int reiserfs_new_inode (struct reiserfs_transaction_handle *th, 1772int reiserfs_new_inode(struct reiserfs_transaction_handle *th,
1682 struct inode * dir, int mode, 1773 struct inode *dir, int mode, const char *symname,
1683 const char * symname, 1774 /* 0 for regular, EMTRY_DIR_SIZE for dirs,
1684 /* 0 for regular, EMTRY_DIR_SIZE for dirs, 1775 strlen (symname) for symlinks) */
1685 strlen (symname) for symlinks)*/ 1776 loff_t i_size, struct dentry *dentry,
1686 loff_t i_size, struct dentry *dentry, 1777 struct inode *inode)
1687 struct inode *inode)
1688{ 1778{
1689 struct super_block * sb; 1779 struct super_block *sb;
1690 INITIALIZE_PATH (path_to_key); 1780 INITIALIZE_PATH(path_to_key);
1691 struct cpu_key key; 1781 struct cpu_key key;
1692 struct item_head ih; 1782 struct item_head ih;
1693 struct stat_data sd; 1783 struct stat_data sd;
1694 int retval; 1784 int retval;
1695 int err; 1785 int err;
1696 1786
1697 BUG_ON (!th->t_trans_id); 1787 BUG_ON(!th->t_trans_id);
1698 1788
1699 if (DQUOT_ALLOC_INODE(inode)) { 1789 if (DQUOT_ALLOC_INODE(inode)) {
1700 err = -EDQUOT; 1790 err = -EDQUOT;
1701 goto out_end_trans; 1791 goto out_end_trans;
1702 } 1792 }
1703 if (!dir || !dir->i_nlink) { 1793 if (!dir || !dir->i_nlink) {
1704 err = -EPERM; 1794 err = -EPERM;
1705 goto out_bad_inode; 1795 goto out_bad_inode;
1706 } 1796 }
1707 1797
1708 sb = dir->i_sb; 1798 sb = dir->i_sb;
1709 1799
1710 /* item head of new item */ 1800 /* item head of new item */
1711 ih.ih_key.k_dir_id = reiserfs_choose_packing(dir); 1801 ih.ih_key.k_dir_id = reiserfs_choose_packing(dir);
1712 ih.ih_key.k_objectid = cpu_to_le32 (reiserfs_get_unused_objectid (th)); 1802 ih.ih_key.k_objectid = cpu_to_le32(reiserfs_get_unused_objectid(th));
1713 if (!ih.ih_key.k_objectid) { 1803 if (!ih.ih_key.k_objectid) {
1714 err = -ENOMEM; 1804 err = -ENOMEM;
1715 goto out_bad_inode ; 1805 goto out_bad_inode;
1716 } 1806 }
1717 if (old_format_only (sb)) 1807 if (old_format_only(sb))
1718 /* not a perfect generation count, as object ids can be reused, but 1808 /* not a perfect generation count, as object ids can be reused, but
1719 ** this is as good as reiserfs can do right now. 1809 ** this is as good as reiserfs can do right now.
1720 ** note that the private part of inode isn't filled in yet, we have 1810 ** note that the private part of inode isn't filled in yet, we have
1721 ** to use the directory. 1811 ** to use the directory.
1722 */ 1812 */
1723 inode->i_generation = le32_to_cpu (INODE_PKEY (dir)->k_objectid); 1813 inode->i_generation = le32_to_cpu(INODE_PKEY(dir)->k_objectid);
1724 else 1814 else
1725#if defined( USE_INODE_GENERATION_COUNTER ) 1815#if defined( USE_INODE_GENERATION_COUNTER )
1726 inode->i_generation = le32_to_cpu(REISERFS_SB(sb)->s_rs->s_inode_generation); 1816 inode->i_generation =
1817 le32_to_cpu(REISERFS_SB(sb)->s_rs->s_inode_generation);
1727#else 1818#else
1728 inode->i_generation = ++event; 1819 inode->i_generation = ++event;
1729#endif 1820#endif
1730 1821
1731 /* fill stat data */ 1822 /* fill stat data */
1732 inode->i_nlink = (S_ISDIR (mode) ? 2 : 1); 1823 inode->i_nlink = (S_ISDIR(mode) ? 2 : 1);
1733 1824
1734 /* uid and gid must already be set by the caller for quota init */ 1825 /* uid and gid must already be set by the caller for quota init */
1735 1826
1736 /* symlink cannot be immutable or append only, right? */ 1827 /* symlink cannot be immutable or append only, right? */
1737 if( S_ISLNK( inode -> i_mode ) ) 1828 if (S_ISLNK(inode->i_mode))
1738 inode -> i_flags &= ~ ( S_IMMUTABLE | S_APPEND ); 1829 inode->i_flags &= ~(S_IMMUTABLE | S_APPEND);
1739 1830
1740 inode->i_mtime = inode->i_atime = inode->i_ctime = 1831 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME_SEC;
1741 CURRENT_TIME_SEC; 1832 inode->i_size = i_size;
1742 inode->i_size = i_size; 1833 inode->i_blocks = 0;
1743 inode->i_blocks = 0; 1834 inode->i_bytes = 0;
1744 inode->i_bytes = 0; 1835 REISERFS_I(inode)->i_first_direct_byte = S_ISLNK(mode) ? 1 :
1745 REISERFS_I(inode)->i_first_direct_byte = S_ISLNK(mode) ? 1 : 1836 U32_MAX /*NO_BYTES_IN_DIRECT_ITEM */ ;
1746 U32_MAX/*NO_BYTES_IN_DIRECT_ITEM*/; 1837
1747 1838 INIT_LIST_HEAD(&(REISERFS_I(inode)->i_prealloc_list));
1748 INIT_LIST_HEAD(&(REISERFS_I(inode)->i_prealloc_list )); 1839 REISERFS_I(inode)->i_flags = 0;
1749 REISERFS_I(inode)->i_flags = 0; 1840 REISERFS_I(inode)->i_prealloc_block = 0;
1750 REISERFS_I(inode)->i_prealloc_block = 0; 1841 REISERFS_I(inode)->i_prealloc_count = 0;
1751 REISERFS_I(inode)->i_prealloc_count = 0; 1842 REISERFS_I(inode)->i_trans_id = 0;
1752 REISERFS_I(inode)->i_trans_id = 0; 1843 REISERFS_I(inode)->i_jl = NULL;
1753 REISERFS_I(inode)->i_jl = NULL; 1844 REISERFS_I(inode)->i_attrs =
1754 REISERFS_I(inode)->i_attrs = 1845 REISERFS_I(dir)->i_attrs & REISERFS_INHERIT_MASK;
1755 REISERFS_I(dir)->i_attrs & REISERFS_INHERIT_MASK; 1846 sd_attrs_to_i_attrs(REISERFS_I(inode)->i_attrs, inode);
1756 sd_attrs_to_i_attrs( REISERFS_I(inode) -> i_attrs, inode ); 1847 REISERFS_I(inode)->i_acl_access = NULL;
1757 REISERFS_I(inode)->i_acl_access = NULL; 1848 REISERFS_I(inode)->i_acl_default = NULL;
1758 REISERFS_I(inode)->i_acl_default = NULL; 1849 init_rwsem(&REISERFS_I(inode)->xattr_sem);
1759 init_rwsem (&REISERFS_I(inode)->xattr_sem); 1850
1760 1851 if (old_format_only(sb))
1761 if (old_format_only (sb)) 1852 make_le_item_head(&ih, NULL, KEY_FORMAT_3_5, SD_OFFSET,
1762 make_le_item_head (&ih, NULL, KEY_FORMAT_3_5, SD_OFFSET, TYPE_STAT_DATA, SD_V1_SIZE, MAX_US_INT); 1853 TYPE_STAT_DATA, SD_V1_SIZE, MAX_US_INT);
1763 else 1854 else
1764 make_le_item_head (&ih, NULL, KEY_FORMAT_3_6, SD_OFFSET, TYPE_STAT_DATA, SD_SIZE, MAX_US_INT); 1855 make_le_item_head(&ih, NULL, KEY_FORMAT_3_6, SD_OFFSET,
1765 1856 TYPE_STAT_DATA, SD_SIZE, MAX_US_INT);
1766 /* key to search for correct place for new stat data */ 1857
1767 _make_cpu_key (&key, KEY_FORMAT_3_6, le32_to_cpu (ih.ih_key.k_dir_id), 1858 /* key to search for correct place for new stat data */
1768 le32_to_cpu (ih.ih_key.k_objectid), SD_OFFSET, TYPE_STAT_DATA, 3/*key length*/); 1859 _make_cpu_key(&key, KEY_FORMAT_3_6, le32_to_cpu(ih.ih_key.k_dir_id),
1769 1860 le32_to_cpu(ih.ih_key.k_objectid), SD_OFFSET,
1770 /* find proper place for inserting of stat data */ 1861 TYPE_STAT_DATA, 3 /*key length */ );
1771 retval = search_item (sb, &key, &path_to_key); 1862
1772 if (retval == IO_ERROR) { 1863 /* find proper place for inserting of stat data */
1773 err = -EIO; 1864 retval = search_item(sb, &key, &path_to_key);
1774 goto out_bad_inode; 1865 if (retval == IO_ERROR) {
1775 } 1866 err = -EIO;
1776 if (retval == ITEM_FOUND) { 1867 goto out_bad_inode;
1777 pathrelse (&path_to_key); 1868 }
1778 err = -EEXIST; 1869 if (retval == ITEM_FOUND) {
1779 goto out_bad_inode; 1870 pathrelse(&path_to_key);
1780 } 1871 err = -EEXIST;
1781 if (old_format_only (sb)) { 1872 goto out_bad_inode;
1782 if (inode->i_uid & ~0xffff || inode->i_gid & ~0xffff) { 1873 }
1783 pathrelse (&path_to_key); 1874 if (old_format_only(sb)) {
1784 /* i_uid or i_gid is too big to be stored in stat data v3.5 */ 1875 if (inode->i_uid & ~0xffff || inode->i_gid & ~0xffff) {
1785 err = -EINVAL; 1876 pathrelse(&path_to_key);
1786 goto out_bad_inode; 1877 /* i_uid or i_gid is too big to be stored in stat data v3.5 */
1787 } 1878 err = -EINVAL;
1788 inode2sd_v1 (&sd, inode, inode->i_size); 1879 goto out_bad_inode;
1789 } else { 1880 }
1790 inode2sd (&sd, inode, inode->i_size); 1881 inode2sd_v1(&sd, inode, inode->i_size);
1791 } 1882 } else {
1792 // these do not go to on-disk stat data 1883 inode2sd(&sd, inode, inode->i_size);
1793 inode->i_ino = le32_to_cpu (ih.ih_key.k_objectid); 1884 }
1794 inode->i_blksize = reiserfs_default_io_size; 1885 // these do not go to on-disk stat data
1795 1886 inode->i_ino = le32_to_cpu(ih.ih_key.k_objectid);
1796 // store in in-core inode the key of stat data and version all 1887 inode->i_blksize = reiserfs_default_io_size;
1797 // object items will have (directory items will have old offset 1888
1798 // format, other new objects will consist of new items) 1889 // store in in-core inode the key of stat data and version all
1799 memcpy (INODE_PKEY (inode), &(ih.ih_key), KEY_SIZE); 1890 // object items will have (directory items will have old offset
1800 if (old_format_only (sb) || S_ISDIR(mode) || S_ISLNK(mode)) 1891 // format, other new objects will consist of new items)
1801 set_inode_item_key_version (inode, KEY_FORMAT_3_5); 1892 memcpy(INODE_PKEY(inode), &(ih.ih_key), KEY_SIZE);
1802 else 1893 if (old_format_only(sb) || S_ISDIR(mode) || S_ISLNK(mode))
1803 set_inode_item_key_version (inode, KEY_FORMAT_3_6); 1894 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
1804 if (old_format_only (sb)) 1895 else
1805 set_inode_sd_version (inode, STAT_DATA_V1); 1896 set_inode_item_key_version(inode, KEY_FORMAT_3_6);
1806 else 1897 if (old_format_only(sb))
1807 set_inode_sd_version (inode, STAT_DATA_V2); 1898 set_inode_sd_version(inode, STAT_DATA_V1);
1808 1899 else
1809 /* insert the stat data into the tree */ 1900 set_inode_sd_version(inode, STAT_DATA_V2);
1901
1902 /* insert the stat data into the tree */
1810#ifdef DISPLACE_NEW_PACKING_LOCALITIES 1903#ifdef DISPLACE_NEW_PACKING_LOCALITIES
1811 if (REISERFS_I(dir)->new_packing_locality) 1904 if (REISERFS_I(dir)->new_packing_locality)
1812 th->displace_new_blocks = 1; 1905 th->displace_new_blocks = 1;
1813#endif 1906#endif
1814 retval = reiserfs_insert_item (th, &path_to_key, &key, &ih, inode, (char *)(&sd)); 1907 retval =
1815 if (retval) { 1908 reiserfs_insert_item(th, &path_to_key, &key, &ih, inode,
1816 err = retval; 1909 (char *)(&sd));
1817 reiserfs_check_path(&path_to_key) ; 1910 if (retval) {
1818 goto out_bad_inode; 1911 err = retval;
1819 } 1912 reiserfs_check_path(&path_to_key);
1820 1913 goto out_bad_inode;
1914 }
1821#ifdef DISPLACE_NEW_PACKING_LOCALITIES 1915#ifdef DISPLACE_NEW_PACKING_LOCALITIES
1822 if (!th->displace_new_blocks) 1916 if (!th->displace_new_blocks)
1823 REISERFS_I(dir)->new_packing_locality = 0; 1917 REISERFS_I(dir)->new_packing_locality = 0;
1824#endif 1918#endif
1825 if (S_ISDIR(mode)) { 1919 if (S_ISDIR(mode)) {
1826 /* insert item with "." and ".." */ 1920 /* insert item with "." and ".." */
1827 retval = reiserfs_new_directory (th, inode, &ih, &path_to_key, dir); 1921 retval =
1828 } 1922 reiserfs_new_directory(th, inode, &ih, &path_to_key, dir);
1829 1923 }
1830 if (S_ISLNK(mode)) { 1924
1831 /* insert body of symlink */ 1925 if (S_ISLNK(mode)) {
1832 if (!old_format_only (sb)) 1926 /* insert body of symlink */
1833 i_size = ROUND_UP(i_size); 1927 if (!old_format_only(sb))
1834 retval = reiserfs_new_symlink (th, inode, &ih, &path_to_key, symname, i_size); 1928 i_size = ROUND_UP(i_size);
1835 } 1929 retval =
1836 if (retval) { 1930 reiserfs_new_symlink(th, inode, &ih, &path_to_key, symname,
1837 err = retval; 1931 i_size);
1838 reiserfs_check_path(&path_to_key) ; 1932 }
1839 journal_end(th, th->t_super, th->t_blocks_allocated); 1933 if (retval) {
1840 goto out_inserted_sd; 1934 err = retval;
1841 } 1935 reiserfs_check_path(&path_to_key);
1842 1936 journal_end(th, th->t_super, th->t_blocks_allocated);
1843 /* XXX CHECK THIS */ 1937 goto out_inserted_sd;
1844 if (reiserfs_posixacl (inode->i_sb)) { 1938 }
1845 retval = reiserfs_inherit_default_acl (dir, dentry, inode); 1939
1846 if (retval) { 1940 /* XXX CHECK THIS */
1847 err = retval; 1941 if (reiserfs_posixacl(inode->i_sb)) {
1848 reiserfs_check_path(&path_to_key) ; 1942 retval = reiserfs_inherit_default_acl(dir, dentry, inode);
1849 journal_end(th, th->t_super, th->t_blocks_allocated); 1943 if (retval) {
1850 goto out_inserted_sd; 1944 err = retval;
1851 } 1945 reiserfs_check_path(&path_to_key);
1852 } else if (inode->i_sb->s_flags & MS_POSIXACL) { 1946 journal_end(th, th->t_super, th->t_blocks_allocated);
1853 reiserfs_warning (inode->i_sb, "ACLs aren't enabled in the fs, " 1947 goto out_inserted_sd;
1854 "but vfs thinks they are!"); 1948 }
1855 } else if (is_reiserfs_priv_object (dir)) { 1949 } else if (inode->i_sb->s_flags & MS_POSIXACL) {
1856 reiserfs_mark_inode_private (inode); 1950 reiserfs_warning(inode->i_sb, "ACLs aren't enabled in the fs, "
1857 } 1951 "but vfs thinks they are!");
1858 1952 } else if (is_reiserfs_priv_object(dir)) {
1859 insert_inode_hash (inode); 1953 reiserfs_mark_inode_private(inode);
1860 reiserfs_update_sd(th, inode); 1954 }
1861 reiserfs_check_path(&path_to_key) ; 1955
1862 1956 insert_inode_hash(inode);
1863 return 0; 1957 reiserfs_update_sd(th, inode);
1958 reiserfs_check_path(&path_to_key);
1959
1960 return 0;
1864 1961
1865/* it looks like you can easily compress these two goto targets into 1962/* it looks like you can easily compress these two goto targets into
1866 * one. Keeping it like this doesn't actually hurt anything, and they 1963 * one. Keeping it like this doesn't actually hurt anything, and they
1867 * are place holders for what the quota code actually needs. 1964 * are place holders for what the quota code actually needs.
1868 */ 1965 */
1869out_bad_inode: 1966 out_bad_inode:
1870 /* Invalidate the object, nothing was inserted yet */ 1967 /* Invalidate the object, nothing was inserted yet */
1871 INODE_PKEY(inode)->k_objectid = 0; 1968 INODE_PKEY(inode)->k_objectid = 0;
1872 1969
1873 /* Quota change must be inside a transaction for journaling */ 1970 /* Quota change must be inside a transaction for journaling */
1874 DQUOT_FREE_INODE(inode); 1971 DQUOT_FREE_INODE(inode);
1875 1972
1876out_end_trans: 1973 out_end_trans:
1877 journal_end(th, th->t_super, th->t_blocks_allocated) ; 1974 journal_end(th, th->t_super, th->t_blocks_allocated);
1878 /* Drop can be outside and it needs more credits so it's better to have it outside */ 1975 /* Drop can be outside and it needs more credits so it's better to have it outside */
1879 DQUOT_DROP(inode); 1976 DQUOT_DROP(inode);
1880 inode->i_flags |= S_NOQUOTA; 1977 inode->i_flags |= S_NOQUOTA;
1881 make_bad_inode(inode); 1978 make_bad_inode(inode);
1882 1979
1883out_inserted_sd: 1980 out_inserted_sd:
1884 inode->i_nlink = 0; 1981 inode->i_nlink = 0;
1885 th->t_trans_id = 0; /* so the caller can't use this handle later */ 1982 th->t_trans_id = 0; /* so the caller can't use this handle later */
1886 iput(inode); 1983 iput(inode);
1887 return err; 1984 return err;
1888} 1985}
1889 1986
1890/* 1987/*
@@ -1900,77 +1997,78 @@ out_inserted_sd:
1900** 1997**
1901** on failure, nonzero is returned, page_result and bh_result are untouched. 1998** on failure, nonzero is returned, page_result and bh_result are untouched.
1902*/ 1999*/
1903static int grab_tail_page(struct inode *p_s_inode, 2000static int grab_tail_page(struct inode *p_s_inode,
1904 struct page **page_result, 2001 struct page **page_result,
1905 struct buffer_head **bh_result) { 2002 struct buffer_head **bh_result)
1906 2003{
1907 /* we want the page with the last byte in the file, 2004
1908 ** not the page that will hold the next byte for appending 2005 /* we want the page with the last byte in the file,
1909 */ 2006 ** not the page that will hold the next byte for appending
1910 unsigned long index = (p_s_inode->i_size-1) >> PAGE_CACHE_SHIFT ; 2007 */
1911 unsigned long pos = 0 ; 2008 unsigned long index = (p_s_inode->i_size - 1) >> PAGE_CACHE_SHIFT;
1912 unsigned long start = 0 ; 2009 unsigned long pos = 0;
1913 unsigned long blocksize = p_s_inode->i_sb->s_blocksize ; 2010 unsigned long start = 0;
1914 unsigned long offset = (p_s_inode->i_size) & (PAGE_CACHE_SIZE - 1) ; 2011 unsigned long blocksize = p_s_inode->i_sb->s_blocksize;
1915 struct buffer_head *bh ; 2012 unsigned long offset = (p_s_inode->i_size) & (PAGE_CACHE_SIZE - 1);
1916 struct buffer_head *head ; 2013 struct buffer_head *bh;
1917 struct page * page ; 2014 struct buffer_head *head;
1918 int error ; 2015 struct page *page;
1919 2016 int error;
1920 /* we know that we are only called with inode->i_size > 0. 2017
1921 ** we also know that a file tail can never be as big as a block 2018 /* we know that we are only called with inode->i_size > 0.
1922 ** If i_size % blocksize == 0, our file is currently block aligned 2019 ** we also know that a file tail can never be as big as a block
1923 ** and it won't need converting or zeroing after a truncate. 2020 ** If i_size % blocksize == 0, our file is currently block aligned
1924 */ 2021 ** and it won't need converting or zeroing after a truncate.
1925 if ((offset & (blocksize - 1)) == 0) { 2022 */
1926 return -ENOENT ; 2023 if ((offset & (blocksize - 1)) == 0) {
1927 } 2024 return -ENOENT;
1928 page = grab_cache_page(p_s_inode->i_mapping, index) ; 2025 }
1929 error = -ENOMEM ; 2026 page = grab_cache_page(p_s_inode->i_mapping, index);
1930 if (!page) { 2027 error = -ENOMEM;
1931 goto out ; 2028 if (!page) {
1932 } 2029 goto out;
1933 /* start within the page of the last block in the file */ 2030 }
1934 start = (offset / blocksize) * blocksize ; 2031 /* start within the page of the last block in the file */
1935 2032 start = (offset / blocksize) * blocksize;
1936 error = block_prepare_write(page, start, offset, 2033
1937 reiserfs_get_block_create_0) ; 2034 error = block_prepare_write(page, start, offset,
1938 if (error) 2035 reiserfs_get_block_create_0);
1939 goto unlock ; 2036 if (error)
1940 2037 goto unlock;
1941 head = page_buffers(page) ; 2038
1942 bh = head; 2039 head = page_buffers(page);
1943 do { 2040 bh = head;
1944 if (pos >= start) { 2041 do {
1945 break ; 2042 if (pos >= start) {
1946 } 2043 break;
1947 bh = bh->b_this_page ; 2044 }
1948 pos += blocksize ; 2045 bh = bh->b_this_page;
1949 } while(bh != head) ; 2046 pos += blocksize;
1950 2047 } while (bh != head);
1951 if (!buffer_uptodate(bh)) { 2048
1952 /* note, this should never happen, prepare_write should 2049 if (!buffer_uptodate(bh)) {
1953 ** be taking care of this for us. If the buffer isn't up to date, 2050 /* note, this should never happen, prepare_write should
1954 ** I've screwed up the code to find the buffer, or the code to 2051 ** be taking care of this for us. If the buffer isn't up to date,
1955 ** call prepare_write 2052 ** I've screwed up the code to find the buffer, or the code to
1956 */ 2053 ** call prepare_write
1957 reiserfs_warning (p_s_inode->i_sb, 2054 */
1958 "clm-6000: error reading block %lu on dev %s", 2055 reiserfs_warning(p_s_inode->i_sb,
1959 bh->b_blocknr, 2056 "clm-6000: error reading block %lu on dev %s",
1960 reiserfs_bdevname (p_s_inode->i_sb)) ; 2057 bh->b_blocknr,
1961 error = -EIO ; 2058 reiserfs_bdevname(p_s_inode->i_sb));
1962 goto unlock ; 2059 error = -EIO;
1963 } 2060 goto unlock;
1964 *bh_result = bh ; 2061 }
1965 *page_result = page ; 2062 *bh_result = bh;
1966 2063 *page_result = page;
1967out: 2064
1968 return error ; 2065 out:
1969 2066 return error;
1970unlock: 2067
1971 unlock_page(page) ; 2068 unlock:
1972 page_cache_release(page) ; 2069 unlock_page(page);
1973 return error ; 2070 page_cache_release(page);
2071 return error;
1974} 2072}
1975 2073
1976/* 2074/*
@@ -1979,235 +2077,247 @@ unlock:
1979** 2077**
1980** some code taken from block_truncate_page 2078** some code taken from block_truncate_page
1981*/ 2079*/
1982int reiserfs_truncate_file(struct inode *p_s_inode, int update_timestamps) { 2080int reiserfs_truncate_file(struct inode *p_s_inode, int update_timestamps)
1983 struct reiserfs_transaction_handle th ; 2081{
1984 /* we want the offset for the first byte after the end of the file */ 2082 struct reiserfs_transaction_handle th;
1985 unsigned long offset = p_s_inode->i_size & (PAGE_CACHE_SIZE - 1) ; 2083 /* we want the offset for the first byte after the end of the file */
1986 unsigned blocksize = p_s_inode->i_sb->s_blocksize ; 2084 unsigned long offset = p_s_inode->i_size & (PAGE_CACHE_SIZE - 1);
1987 unsigned length ; 2085 unsigned blocksize = p_s_inode->i_sb->s_blocksize;
1988 struct page *page = NULL ; 2086 unsigned length;
1989 int error ; 2087 struct page *page = NULL;
1990 struct buffer_head *bh = NULL ; 2088 int error;
1991 2089 struct buffer_head *bh = NULL;
1992 reiserfs_write_lock(p_s_inode->i_sb); 2090
1993 2091 reiserfs_write_lock(p_s_inode->i_sb);
1994 if (p_s_inode->i_size > 0) { 2092
1995 if ((error = grab_tail_page(p_s_inode, &page, &bh))) { 2093 if (p_s_inode->i_size > 0) {
1996 // -ENOENT means we truncated past the end of the file, 2094 if ((error = grab_tail_page(p_s_inode, &page, &bh))) {
1997 // and get_block_create_0 could not find a block to read in, 2095 // -ENOENT means we truncated past the end of the file,
1998 // which is ok. 2096 // and get_block_create_0 could not find a block to read in,
1999 if (error != -ENOENT) 2097 // which is ok.
2000 reiserfs_warning (p_s_inode->i_sb, 2098 if (error != -ENOENT)
2001 "clm-6001: grab_tail_page failed %d", 2099 reiserfs_warning(p_s_inode->i_sb,
2002 error); 2100 "clm-6001: grab_tail_page failed %d",
2003 page = NULL ; 2101 error);
2004 bh = NULL ; 2102 page = NULL;
2005 } 2103 bh = NULL;
2006 } 2104 }
2007 2105 }
2008 /* so, if page != NULL, we have a buffer head for the offset at
2009 ** the end of the file. if the bh is mapped, and bh->b_blocknr != 0,
2010 ** then we have an unformatted node. Otherwise, we have a direct item,
2011 ** and no zeroing is required on disk. We zero after the truncate,
2012 ** because the truncate might pack the item anyway
2013 ** (it will unmap bh if it packs).
2014 */
2015 /* it is enough to reserve space in transaction for 2 balancings:
2016 one for "save" link adding and another for the first
2017 cut_from_item. 1 is for update_sd */
2018 error = journal_begin (&th, p_s_inode->i_sb,
2019 JOURNAL_PER_BALANCE_CNT * 2 + 1);
2020 if (error)
2021 goto out;
2022 reiserfs_update_inode_transaction(p_s_inode) ;
2023 if (update_timestamps)
2024 /* we are doing real truncate: if the system crashes before the last
2025 transaction of truncating gets committed - on reboot the file
2026 either appears truncated properly or not truncated at all */
2027 add_save_link (&th, p_s_inode, 1);
2028 error = reiserfs_do_truncate (&th, p_s_inode, page, update_timestamps) ;
2029 if (error)
2030 goto out;
2031 error = journal_end (&th, p_s_inode->i_sb, JOURNAL_PER_BALANCE_CNT * 2 + 1);
2032 if (error)
2033 goto out;
2034
2035 if (update_timestamps) {
2036 error = remove_save_link (p_s_inode, 1/* truncate */);
2037 if (error)
2038 goto out;
2039 }
2040
2041 if (page) {
2042 length = offset & (blocksize - 1) ;
2043 /* if we are not on a block boundary */
2044 if (length) {
2045 char *kaddr;
2046
2047 length = blocksize - length ;
2048 kaddr = kmap_atomic(page, KM_USER0) ;
2049 memset(kaddr + offset, 0, length) ;
2050 flush_dcache_page(page) ;
2051 kunmap_atomic(kaddr, KM_USER0) ;
2052 if (buffer_mapped(bh) && bh->b_blocknr != 0) {
2053 mark_buffer_dirty(bh) ;
2054 }
2055 }
2056 unlock_page(page) ;
2057 page_cache_release(page) ;
2058 }
2059
2060 reiserfs_write_unlock(p_s_inode->i_sb);
2061 return 0;
2062out:
2063 if (page) {
2064 unlock_page (page);
2065 page_cache_release (page);
2066 }
2067 reiserfs_write_unlock(p_s_inode->i_sb);
2068 return error;
2069}
2070 2106
2071static int map_block_for_writepage(struct inode *inode, 2107 /* so, if page != NULL, we have a buffer head for the offset at
2072 struct buffer_head *bh_result, 2108 ** the end of the file. if the bh is mapped, and bh->b_blocknr != 0,
2073 unsigned long block) { 2109 ** then we have an unformatted node. Otherwise, we have a direct item,
2074 struct reiserfs_transaction_handle th ; 2110 ** and no zeroing is required on disk. We zero after the truncate,
2075 int fs_gen ; 2111 ** because the truncate might pack the item anyway
2076 struct item_head tmp_ih ; 2112 ** (it will unmap bh if it packs).
2077 struct item_head *ih ;
2078 struct buffer_head *bh ;
2079 __le32 *item ;
2080 struct cpu_key key ;
2081 INITIALIZE_PATH(path) ;
2082 int pos_in_item ;
2083 int jbegin_count = JOURNAL_PER_BALANCE_CNT ;
2084 loff_t byte_offset = (block << inode->i_sb->s_blocksize_bits) + 1 ;
2085 int retval ;
2086 int use_get_block = 0 ;
2087 int bytes_copied = 0 ;
2088 int copy_size ;
2089 int trans_running = 0;
2090
2091 /* catch places below that try to log something without starting a trans */
2092 th.t_trans_id = 0;
2093
2094 if (!buffer_uptodate(bh_result)) {
2095 return -EIO;
2096 }
2097
2098 kmap(bh_result->b_page) ;
2099start_over:
2100 reiserfs_write_lock(inode->i_sb);
2101 make_cpu_key(&key, inode, byte_offset, TYPE_ANY, 3) ;
2102
2103research:
2104 retval = search_for_position_by_key(inode->i_sb, &key, &path) ;
2105 if (retval != POSITION_FOUND) {
2106 use_get_block = 1;
2107 goto out ;
2108 }
2109
2110 bh = get_last_bh(&path) ;
2111 ih = get_ih(&path) ;
2112 item = get_item(&path) ;
2113 pos_in_item = path.pos_in_item ;
2114
2115 /* we've found an unformatted node */
2116 if (indirect_item_found(retval, ih)) {
2117 if (bytes_copied > 0) {
2118 reiserfs_warning (inode->i_sb, "clm-6002: bytes_copied %d",
2119 bytes_copied) ;
2120 }
2121 if (!get_block_num(item, pos_in_item)) {
2122 /* crap, we are writing to a hole */
2123 use_get_block = 1;
2124 goto out ;
2125 }
2126 set_block_dev_mapped(bh_result, get_block_num(item,pos_in_item),inode);
2127 } else if (is_direct_le_ih(ih)) {
2128 char *p ;
2129 p = page_address(bh_result->b_page) ;
2130 p += (byte_offset -1) & (PAGE_CACHE_SIZE - 1) ;
2131 copy_size = ih_item_len(ih) - pos_in_item;
2132
2133 fs_gen = get_generation(inode->i_sb) ;
2134 copy_item_head(&tmp_ih, ih) ;
2135
2136 if (!trans_running) {
2137 /* vs-3050 is gone, no need to drop the path */
2138 retval = journal_begin(&th, inode->i_sb, jbegin_count) ;
2139 if (retval)
2140 goto out;
2141 reiserfs_update_inode_transaction(inode) ;
2142 trans_running = 1;
2143 if (fs_changed(fs_gen, inode->i_sb) && item_moved(&tmp_ih, &path)) {
2144 reiserfs_restore_prepared_buffer(inode->i_sb, bh) ;
2145 goto research;
2146 }
2147 }
2148
2149 reiserfs_prepare_for_journal(inode->i_sb, bh, 1) ;
2150
2151 if (fs_changed (fs_gen, inode->i_sb) && item_moved (&tmp_ih, &path)) {
2152 reiserfs_restore_prepared_buffer(inode->i_sb, bh) ;
2153 goto research;
2154 }
2155
2156 memcpy( B_I_PITEM(bh, ih) + pos_in_item, p + bytes_copied, copy_size) ;
2157
2158 journal_mark_dirty(&th, inode->i_sb, bh) ;
2159 bytes_copied += copy_size ;
2160 set_block_dev_mapped(bh_result, 0, inode);
2161
2162 /* are there still bytes left? */
2163 if (bytes_copied < bh_result->b_size &&
2164 (byte_offset + bytes_copied) < inode->i_size) {
2165 set_cpu_key_k_offset(&key, cpu_key_k_offset(&key) + copy_size) ;
2166 goto research ;
2167 }
2168 } else {
2169 reiserfs_warning (inode->i_sb,
2170 "clm-6003: bad item inode %lu, device %s",
2171 inode->i_ino, reiserfs_bdevname (inode->i_sb)) ;
2172 retval = -EIO ;
2173 goto out ;
2174 }
2175 retval = 0 ;
2176
2177out:
2178 pathrelse(&path) ;
2179 if (trans_running) {
2180 int err = journal_end(&th, inode->i_sb, jbegin_count) ;
2181 if (err)
2182 retval = err;
2183 trans_running = 0;
2184 }
2185 reiserfs_write_unlock(inode->i_sb);
2186
2187 /* this is where we fill in holes in the file. */
2188 if (use_get_block) {
2189 retval = reiserfs_get_block(inode, block, bh_result,
2190 GET_BLOCK_CREATE | GET_BLOCK_NO_ISEM |
2191 GET_BLOCK_NO_DANGLE);
2192 if (!retval) {
2193 if (!buffer_mapped(bh_result) || bh_result->b_blocknr == 0) {
2194 /* get_block failed to find a mapped unformatted node. */
2195 use_get_block = 0 ;
2196 goto start_over ;
2197 }
2198 }
2199 }
2200 kunmap(bh_result->b_page) ;
2201
2202 if (!retval && buffer_mapped(bh_result) && bh_result->b_blocknr == 0) {
2203 /* we've copied data from the page into the direct item, so the
2204 * buffer in the page is now clean, mark it to reflect that.
2205 */ 2113 */
2206 lock_buffer(bh_result); 2114 /* it is enough to reserve space in transaction for 2 balancings:
2207 clear_buffer_dirty(bh_result); 2115 one for "save" link adding and another for the first
2208 unlock_buffer(bh_result); 2116 cut_from_item. 1 is for update_sd */
2209 } 2117 error = journal_begin(&th, p_s_inode->i_sb,
2210 return retval ; 2118 JOURNAL_PER_BALANCE_CNT * 2 + 1);
2119 if (error)
2120 goto out;
2121 reiserfs_update_inode_transaction(p_s_inode);
2122 if (update_timestamps)
2123 /* we are doing real truncate: if the system crashes before the last
2124 transaction of truncating gets committed - on reboot the file
2125 either appears truncated properly or not truncated at all */
2126 add_save_link(&th, p_s_inode, 1);
2127 error = reiserfs_do_truncate(&th, p_s_inode, page, update_timestamps);
2128 if (error)
2129 goto out;
2130 error =
2131 journal_end(&th, p_s_inode->i_sb, JOURNAL_PER_BALANCE_CNT * 2 + 1);
2132 if (error)
2133 goto out;
2134
2135 if (update_timestamps) {
2136 error = remove_save_link(p_s_inode, 1 /* truncate */ );
2137 if (error)
2138 goto out;
2139 }
2140
2141 if (page) {
2142 length = offset & (blocksize - 1);
2143 /* if we are not on a block boundary */
2144 if (length) {
2145 char *kaddr;
2146
2147 length = blocksize - length;
2148 kaddr = kmap_atomic(page, KM_USER0);
2149 memset(kaddr + offset, 0, length);
2150 flush_dcache_page(page);
2151 kunmap_atomic(kaddr, KM_USER0);
2152 if (buffer_mapped(bh) && bh->b_blocknr != 0) {
2153 mark_buffer_dirty(bh);
2154 }
2155 }
2156 unlock_page(page);
2157 page_cache_release(page);
2158 }
2159
2160 reiserfs_write_unlock(p_s_inode->i_sb);
2161 return 0;
2162 out:
2163 if (page) {
2164 unlock_page(page);
2165 page_cache_release(page);
2166 }
2167 reiserfs_write_unlock(p_s_inode->i_sb);
2168 return error;
2169}
2170
2171static int map_block_for_writepage(struct inode *inode,
2172 struct buffer_head *bh_result,
2173 unsigned long block)
2174{
2175 struct reiserfs_transaction_handle th;
2176 int fs_gen;
2177 struct item_head tmp_ih;
2178 struct item_head *ih;
2179 struct buffer_head *bh;
2180 __le32 *item;
2181 struct cpu_key key;
2182 INITIALIZE_PATH(path);
2183 int pos_in_item;
2184 int jbegin_count = JOURNAL_PER_BALANCE_CNT;
2185 loff_t byte_offset = (block << inode->i_sb->s_blocksize_bits) + 1;
2186 int retval;
2187 int use_get_block = 0;
2188 int bytes_copied = 0;
2189 int copy_size;
2190 int trans_running = 0;
2191
2192 /* catch places below that try to log something without starting a trans */
2193 th.t_trans_id = 0;
2194
2195 if (!buffer_uptodate(bh_result)) {
2196 return -EIO;
2197 }
2198
2199 kmap(bh_result->b_page);
2200 start_over:
2201 reiserfs_write_lock(inode->i_sb);
2202 make_cpu_key(&key, inode, byte_offset, TYPE_ANY, 3);
2203
2204 research:
2205 retval = search_for_position_by_key(inode->i_sb, &key, &path);
2206 if (retval != POSITION_FOUND) {
2207 use_get_block = 1;
2208 goto out;
2209 }
2210
2211 bh = get_last_bh(&path);
2212 ih = get_ih(&path);
2213 item = get_item(&path);
2214 pos_in_item = path.pos_in_item;
2215
2216 /* we've found an unformatted node */
2217 if (indirect_item_found(retval, ih)) {
2218 if (bytes_copied > 0) {
2219 reiserfs_warning(inode->i_sb,
2220 "clm-6002: bytes_copied %d",
2221 bytes_copied);
2222 }
2223 if (!get_block_num(item, pos_in_item)) {
2224 /* crap, we are writing to a hole */
2225 use_get_block = 1;
2226 goto out;
2227 }
2228 set_block_dev_mapped(bh_result,
2229 get_block_num(item, pos_in_item), inode);
2230 } else if (is_direct_le_ih(ih)) {
2231 char *p;
2232 p = page_address(bh_result->b_page);
2233 p += (byte_offset - 1) & (PAGE_CACHE_SIZE - 1);
2234 copy_size = ih_item_len(ih) - pos_in_item;
2235
2236 fs_gen = get_generation(inode->i_sb);
2237 copy_item_head(&tmp_ih, ih);
2238
2239 if (!trans_running) {
2240 /* vs-3050 is gone, no need to drop the path */
2241 retval = journal_begin(&th, inode->i_sb, jbegin_count);
2242 if (retval)
2243 goto out;
2244 reiserfs_update_inode_transaction(inode);
2245 trans_running = 1;
2246 if (fs_changed(fs_gen, inode->i_sb)
2247 && item_moved(&tmp_ih, &path)) {
2248 reiserfs_restore_prepared_buffer(inode->i_sb,
2249 bh);
2250 goto research;
2251 }
2252 }
2253
2254 reiserfs_prepare_for_journal(inode->i_sb, bh, 1);
2255
2256 if (fs_changed(fs_gen, inode->i_sb)
2257 && item_moved(&tmp_ih, &path)) {
2258 reiserfs_restore_prepared_buffer(inode->i_sb, bh);
2259 goto research;
2260 }
2261
2262 memcpy(B_I_PITEM(bh, ih) + pos_in_item, p + bytes_copied,
2263 copy_size);
2264
2265 journal_mark_dirty(&th, inode->i_sb, bh);
2266 bytes_copied += copy_size;
2267 set_block_dev_mapped(bh_result, 0, inode);
2268
2269 /* are there still bytes left? */
2270 if (bytes_copied < bh_result->b_size &&
2271 (byte_offset + bytes_copied) < inode->i_size) {
2272 set_cpu_key_k_offset(&key,
2273 cpu_key_k_offset(&key) +
2274 copy_size);
2275 goto research;
2276 }
2277 } else {
2278 reiserfs_warning(inode->i_sb,
2279 "clm-6003: bad item inode %lu, device %s",
2280 inode->i_ino, reiserfs_bdevname(inode->i_sb));
2281 retval = -EIO;
2282 goto out;
2283 }
2284 retval = 0;
2285
2286 out:
2287 pathrelse(&path);
2288 if (trans_running) {
2289 int err = journal_end(&th, inode->i_sb, jbegin_count);
2290 if (err)
2291 retval = err;
2292 trans_running = 0;
2293 }
2294 reiserfs_write_unlock(inode->i_sb);
2295
2296 /* this is where we fill in holes in the file. */
2297 if (use_get_block) {
2298 retval = reiserfs_get_block(inode, block, bh_result,
2299 GET_BLOCK_CREATE | GET_BLOCK_NO_ISEM
2300 | GET_BLOCK_NO_DANGLE);
2301 if (!retval) {
2302 if (!buffer_mapped(bh_result)
2303 || bh_result->b_blocknr == 0) {
2304 /* get_block failed to find a mapped unformatted node. */
2305 use_get_block = 0;
2306 goto start_over;
2307 }
2308 }
2309 }
2310 kunmap(bh_result->b_page);
2311
2312 if (!retval && buffer_mapped(bh_result) && bh_result->b_blocknr == 0) {
2313 /* we've copied data from the page into the direct item, so the
2314 * buffer in the page is now clean, mark it to reflect that.
2315 */
2316 lock_buffer(bh_result);
2317 clear_buffer_dirty(bh_result);
2318 unlock_buffer(bh_result);
2319 }
2320 return retval;
2211} 2321}
2212 2322
2213/* 2323/*
@@ -2215,383 +2325,390 @@ out:
2215 * start/recovery path as __block_write_full_page, along with special 2325 * start/recovery path as __block_write_full_page, along with special
2216 * code to handle reiserfs tails. 2326 * code to handle reiserfs tails.
2217 */ 2327 */
2218static int reiserfs_write_full_page(struct page *page, struct writeback_control *wbc) { 2328static int reiserfs_write_full_page(struct page *page,
2219 struct inode *inode = page->mapping->host ; 2329 struct writeback_control *wbc)
2220 unsigned long end_index = inode->i_size >> PAGE_CACHE_SHIFT ; 2330{
2221 int error = 0; 2331 struct inode *inode = page->mapping->host;
2222 unsigned long block ; 2332 unsigned long end_index = inode->i_size >> PAGE_CACHE_SHIFT;
2223 struct buffer_head *head, *bh; 2333 int error = 0;
2224 int partial = 0 ; 2334 unsigned long block;
2225 int nr = 0; 2335 struct buffer_head *head, *bh;
2226 int checked = PageChecked(page); 2336 int partial = 0;
2227 struct reiserfs_transaction_handle th; 2337 int nr = 0;
2228 struct super_block *s = inode->i_sb; 2338 int checked = PageChecked(page);
2229 int bh_per_page = PAGE_CACHE_SIZE / s->s_blocksize; 2339 struct reiserfs_transaction_handle th;
2230 th.t_trans_id = 0; 2340 struct super_block *s = inode->i_sb;
2231 2341 int bh_per_page = PAGE_CACHE_SIZE / s->s_blocksize;
2232 /* The page dirty bit is cleared before writepage is called, which 2342 th.t_trans_id = 0;
2233 * means we have to tell create_empty_buffers to make dirty buffers 2343
2234 * The page really should be up to date at this point, so tossing 2344 /* The page dirty bit is cleared before writepage is called, which
2235 * in the BH_Uptodate is just a sanity check. 2345 * means we have to tell create_empty_buffers to make dirty buffers
2236 */ 2346 * The page really should be up to date at this point, so tossing
2237 if (!page_has_buffers(page)) { 2347 * in the BH_Uptodate is just a sanity check.
2238 create_empty_buffers(page, s->s_blocksize, 2348 */
2239 (1 << BH_Dirty) | (1 << BH_Uptodate)); 2349 if (!page_has_buffers(page)) {
2240 } 2350 create_empty_buffers(page, s->s_blocksize,
2241 head = page_buffers(page) ; 2351 (1 << BH_Dirty) | (1 << BH_Uptodate));
2242 2352 }
2243 /* last page in the file, zero out any contents past the 2353 head = page_buffers(page);
2244 ** last byte in the file
2245 */
2246 if (page->index >= end_index) {
2247 char *kaddr;
2248 unsigned last_offset;
2249
2250 last_offset = inode->i_size & (PAGE_CACHE_SIZE - 1) ;
2251 /* no file contents in this page */
2252 if (page->index >= end_index + 1 || !last_offset) {
2253 unlock_page(page);
2254 return 0;
2255 }
2256 kaddr = kmap_atomic(page, KM_USER0);
2257 memset(kaddr + last_offset, 0, PAGE_CACHE_SIZE-last_offset) ;
2258 flush_dcache_page(page) ;
2259 kunmap_atomic(kaddr, KM_USER0) ;
2260 }
2261 bh = head ;
2262 block = page->index << (PAGE_CACHE_SHIFT - s->s_blocksize_bits) ;
2263 /* first map all the buffers, logging any direct items we find */
2264 do {
2265 if ((checked || buffer_dirty(bh)) && (!buffer_mapped(bh) ||
2266 (buffer_mapped(bh) && bh->b_blocknr == 0))) {
2267 /* not mapped yet, or it points to a direct item, search
2268 * the btree for the mapping info, and log any direct
2269 * items found
2270 */
2271 if ((error = map_block_for_writepage(inode, bh, block))) {
2272 goto fail ;
2273 }
2274 }
2275 bh = bh->b_this_page;
2276 block++;
2277 } while(bh != head) ;
2278
2279 /*
2280 * we start the transaction after map_block_for_writepage,
2281 * because it can create holes in the file (an unbounded operation).
2282 * starting it here, we can make a reliable estimate for how many
2283 * blocks we're going to log
2284 */
2285 if (checked) {
2286 ClearPageChecked(page);
2287 reiserfs_write_lock(s);
2288 error = journal_begin(&th, s, bh_per_page + 1);
2289 if (error) {
2290 reiserfs_write_unlock(s);
2291 goto fail;
2292 }
2293 reiserfs_update_inode_transaction(inode);
2294 }
2295 /* now go through and lock any dirty buffers on the page */
2296 do {
2297 get_bh(bh);
2298 if (!buffer_mapped(bh))
2299 continue;
2300 if (buffer_mapped(bh) && bh->b_blocknr == 0)
2301 continue;
2302 2354
2303 if (checked) { 2355 /* last page in the file, zero out any contents past the
2304 reiserfs_prepare_for_journal(s, bh, 1); 2356 ** last byte in the file
2305 journal_mark_dirty(&th, s, bh); 2357 */
2306 continue; 2358 if (page->index >= end_index) {
2359 char *kaddr;
2360 unsigned last_offset;
2361
2362 last_offset = inode->i_size & (PAGE_CACHE_SIZE - 1);
2363 /* no file contents in this page */
2364 if (page->index >= end_index + 1 || !last_offset) {
2365 unlock_page(page);
2366 return 0;
2367 }
2368 kaddr = kmap_atomic(page, KM_USER0);
2369 memset(kaddr + last_offset, 0, PAGE_CACHE_SIZE - last_offset);
2370 flush_dcache_page(page);
2371 kunmap_atomic(kaddr, KM_USER0);
2307 } 2372 }
2308 /* from this point on, we know the buffer is mapped to a 2373 bh = head;
2309 * real block and not a direct item 2374 block = page->index << (PAGE_CACHE_SHIFT - s->s_blocksize_bits);
2375 /* first map all the buffers, logging any direct items we find */
2376 do {
2377 if ((checked || buffer_dirty(bh)) && (!buffer_mapped(bh) ||
2378 (buffer_mapped(bh)
2379 && bh->b_blocknr ==
2380 0))) {
2381 /* not mapped yet, or it points to a direct item, search
2382 * the btree for the mapping info, and log any direct
2383 * items found
2384 */
2385 if ((error = map_block_for_writepage(inode, bh, block))) {
2386 goto fail;
2387 }
2388 }
2389 bh = bh->b_this_page;
2390 block++;
2391 } while (bh != head);
2392
2393 /*
2394 * we start the transaction after map_block_for_writepage,
2395 * because it can create holes in the file (an unbounded operation).
2396 * starting it here, we can make a reliable estimate for how many
2397 * blocks we're going to log
2310 */ 2398 */
2311 if (wbc->sync_mode != WB_SYNC_NONE || !wbc->nonblocking) { 2399 if (checked) {
2312 lock_buffer(bh); 2400 ClearPageChecked(page);
2313 } else { 2401 reiserfs_write_lock(s);
2314 if (test_set_buffer_locked(bh)) { 2402 error = journal_begin(&th, s, bh_per_page + 1);
2315 redirty_page_for_writepage(wbc, page); 2403 if (error) {
2316 continue; 2404 reiserfs_write_unlock(s);
2317 } 2405 goto fail;
2406 }
2407 reiserfs_update_inode_transaction(inode);
2318 } 2408 }
2319 if (test_clear_buffer_dirty(bh)) { 2409 /* now go through and lock any dirty buffers on the page */
2320 mark_buffer_async_write(bh); 2410 do {
2321 } else { 2411 get_bh(bh);
2322 unlock_buffer(bh); 2412 if (!buffer_mapped(bh))
2413 continue;
2414 if (buffer_mapped(bh) && bh->b_blocknr == 0)
2415 continue;
2416
2417 if (checked) {
2418 reiserfs_prepare_for_journal(s, bh, 1);
2419 journal_mark_dirty(&th, s, bh);
2420 continue;
2421 }
2422 /* from this point on, we know the buffer is mapped to a
2423 * real block and not a direct item
2424 */
2425 if (wbc->sync_mode != WB_SYNC_NONE || !wbc->nonblocking) {
2426 lock_buffer(bh);
2427 } else {
2428 if (test_set_buffer_locked(bh)) {
2429 redirty_page_for_writepage(wbc, page);
2430 continue;
2431 }
2432 }
2433 if (test_clear_buffer_dirty(bh)) {
2434 mark_buffer_async_write(bh);
2435 } else {
2436 unlock_buffer(bh);
2437 }
2438 } while ((bh = bh->b_this_page) != head);
2439
2440 if (checked) {
2441 error = journal_end(&th, s, bh_per_page + 1);
2442 reiserfs_write_unlock(s);
2443 if (error)
2444 goto fail;
2323 } 2445 }
2324 } while((bh = bh->b_this_page) != head); 2446 BUG_ON(PageWriteback(page));
2447 set_page_writeback(page);
2448 unlock_page(page);
2325 2449
2326 if (checked) { 2450 /*
2327 error = journal_end(&th, s, bh_per_page + 1); 2451 * since any buffer might be the only dirty buffer on the page,
2328 reiserfs_write_unlock(s); 2452 * the first submit_bh can bring the page out of writeback.
2329 if (error) 2453 * be careful with the buffers.
2330 goto fail;
2331 }
2332 BUG_ON(PageWriteback(page));
2333 set_page_writeback(page);
2334 unlock_page(page);
2335
2336 /*
2337 * since any buffer might be the only dirty buffer on the page,
2338 * the first submit_bh can bring the page out of writeback.
2339 * be careful with the buffers.
2340 */
2341 do {
2342 struct buffer_head *next = bh->b_this_page;
2343 if (buffer_async_write(bh)) {
2344 submit_bh(WRITE, bh);
2345 nr++;
2346 }
2347 put_bh(bh);
2348 bh = next;
2349 } while(bh != head);
2350
2351 error = 0;
2352done:
2353 if (nr == 0) {
2354 /*
2355 * if this page only had a direct item, it is very possible for
2356 * no io to be required without there being an error. Or,
2357 * someone else could have locked them and sent them down the
2358 * pipe without locking the page
2359 */ 2454 */
2360 bh = head ;
2361 do { 2455 do {
2362 if (!buffer_uptodate(bh)) { 2456 struct buffer_head *next = bh->b_this_page;
2363 partial = 1; 2457 if (buffer_async_write(bh)) {
2364 break; 2458 submit_bh(WRITE, bh);
2365 } 2459 nr++;
2366 bh = bh->b_this_page; 2460 }
2367 } while(bh != head); 2461 put_bh(bh);
2368 if (!partial) 2462 bh = next;
2369 SetPageUptodate(page); 2463 } while (bh != head);
2370 end_page_writeback(page);
2371 }
2372 return error;
2373
2374fail:
2375 /* catches various errors, we need to make sure any valid dirty blocks
2376 * get to the media. The page is currently locked and not marked for
2377 * writeback
2378 */
2379 ClearPageUptodate(page);
2380 bh = head;
2381 do {
2382 get_bh(bh);
2383 if (buffer_mapped(bh) && buffer_dirty(bh) && bh->b_blocknr) {
2384 lock_buffer(bh);
2385 mark_buffer_async_write(bh);
2386 } else {
2387 /*
2388 * clear any dirty bits that might have come from getting
2389 * attached to a dirty page
2390 */
2391 clear_buffer_dirty(bh);
2392 }
2393 bh = bh->b_this_page;
2394 } while(bh != head);
2395 SetPageError(page);
2396 BUG_ON(PageWriteback(page));
2397 set_page_writeback(page);
2398 unlock_page(page);
2399 do {
2400 struct buffer_head *next = bh->b_this_page;
2401 if (buffer_async_write(bh)) {
2402 clear_buffer_dirty(bh);
2403 submit_bh(WRITE, bh);
2404 nr++;
2405 }
2406 put_bh(bh);
2407 bh = next;
2408 } while(bh != head);
2409 goto done;
2410}
2411 2464
2465 error = 0;
2466 done:
2467 if (nr == 0) {
2468 /*
2469 * if this page only had a direct item, it is very possible for
2470 * no io to be required without there being an error. Or,
2471 * someone else could have locked them and sent them down the
2472 * pipe without locking the page
2473 */
2474 bh = head;
2475 do {
2476 if (!buffer_uptodate(bh)) {
2477 partial = 1;
2478 break;
2479 }
2480 bh = bh->b_this_page;
2481 } while (bh != head);
2482 if (!partial)
2483 SetPageUptodate(page);
2484 end_page_writeback(page);
2485 }
2486 return error;
2412 2487
2413static int reiserfs_readpage (struct file *f, struct page * page) 2488 fail:
2414{ 2489 /* catches various errors, we need to make sure any valid dirty blocks
2415 return block_read_full_page (page, reiserfs_get_block); 2490 * get to the media. The page is currently locked and not marked for
2491 * writeback
2492 */
2493 ClearPageUptodate(page);
2494 bh = head;
2495 do {
2496 get_bh(bh);
2497 if (buffer_mapped(bh) && buffer_dirty(bh) && bh->b_blocknr) {
2498 lock_buffer(bh);
2499 mark_buffer_async_write(bh);
2500 } else {
2501 /*
2502 * clear any dirty bits that might have come from getting
2503 * attached to a dirty page
2504 */
2505 clear_buffer_dirty(bh);
2506 }
2507 bh = bh->b_this_page;
2508 } while (bh != head);
2509 SetPageError(page);
2510 BUG_ON(PageWriteback(page));
2511 set_page_writeback(page);
2512 unlock_page(page);
2513 do {
2514 struct buffer_head *next = bh->b_this_page;
2515 if (buffer_async_write(bh)) {
2516 clear_buffer_dirty(bh);
2517 submit_bh(WRITE, bh);
2518 nr++;
2519 }
2520 put_bh(bh);
2521 bh = next;
2522 } while (bh != head);
2523 goto done;
2416} 2524}
2417 2525
2526static int reiserfs_readpage(struct file *f, struct page *page)
2527{
2528 return block_read_full_page(page, reiserfs_get_block);
2529}
2418 2530
2419static int reiserfs_writepage (struct page * page, struct writeback_control *wbc) 2531static int reiserfs_writepage(struct page *page, struct writeback_control *wbc)
2420{ 2532{
2421 struct inode *inode = page->mapping->host ; 2533 struct inode *inode = page->mapping->host;
2422 reiserfs_wait_on_write_block(inode->i_sb) ; 2534 reiserfs_wait_on_write_block(inode->i_sb);
2423 return reiserfs_write_full_page(page, wbc) ; 2535 return reiserfs_write_full_page(page, wbc);
2424} 2536}
2425 2537
2426static int reiserfs_prepare_write(struct file *f, struct page *page, 2538static int reiserfs_prepare_write(struct file *f, struct page *page,
2427 unsigned from, unsigned to) { 2539 unsigned from, unsigned to)
2428 struct inode *inode = page->mapping->host ; 2540{
2429 int ret; 2541 struct inode *inode = page->mapping->host;
2430 int old_ref = 0; 2542 int ret;
2431 2543 int old_ref = 0;
2432 reiserfs_wait_on_write_block(inode->i_sb) ; 2544
2433 fix_tail_page_for_writing(page) ; 2545 reiserfs_wait_on_write_block(inode->i_sb);
2434 if (reiserfs_transaction_running(inode->i_sb)) { 2546 fix_tail_page_for_writing(page);
2435 struct reiserfs_transaction_handle *th; 2547 if (reiserfs_transaction_running(inode->i_sb)) {
2436 th = (struct reiserfs_transaction_handle *)current->journal_info; 2548 struct reiserfs_transaction_handle *th;
2437 BUG_ON (!th->t_refcount); 2549 th = (struct reiserfs_transaction_handle *)current->
2438 BUG_ON (!th->t_trans_id); 2550 journal_info;
2439 old_ref = th->t_refcount; 2551 BUG_ON(!th->t_refcount);
2440 th->t_refcount++; 2552 BUG_ON(!th->t_trans_id);
2441 } 2553 old_ref = th->t_refcount;
2442 2554 th->t_refcount++;
2443 ret = block_prepare_write(page, from, to, reiserfs_get_block) ;
2444 if (ret && reiserfs_transaction_running(inode->i_sb)) {
2445 struct reiserfs_transaction_handle *th = current->journal_info;
2446 /* this gets a little ugly. If reiserfs_get_block returned an
2447 * error and left a transacstion running, we've got to close it,
2448 * and we've got to free handle if it was a persistent transaction.
2449 *
2450 * But, if we had nested into an existing transaction, we need
2451 * to just drop the ref count on the handle.
2452 *
2453 * If old_ref == 0, the transaction is from reiserfs_get_block,
2454 * and it was a persistent trans. Otherwise, it was nested above.
2455 */
2456 if (th->t_refcount > old_ref) {
2457 if (old_ref)
2458 th->t_refcount--;
2459 else {
2460 int err;
2461 reiserfs_write_lock(inode->i_sb);
2462 err = reiserfs_end_persistent_transaction(th);
2463 reiserfs_write_unlock(inode->i_sb);
2464 if (err)
2465 ret = err;
2466 }
2467 } 2555 }
2468 }
2469 return ret;
2470 2556
2471} 2557 ret = block_prepare_write(page, from, to, reiserfs_get_block);
2558 if (ret && reiserfs_transaction_running(inode->i_sb)) {
2559 struct reiserfs_transaction_handle *th = current->journal_info;
2560 /* this gets a little ugly. If reiserfs_get_block returned an
2561 * error and left a transacstion running, we've got to close it,
2562 * and we've got to free handle if it was a persistent transaction.
2563 *
2564 * But, if we had nested into an existing transaction, we need
2565 * to just drop the ref count on the handle.
2566 *
2567 * If old_ref == 0, the transaction is from reiserfs_get_block,
2568 * and it was a persistent trans. Otherwise, it was nested above.
2569 */
2570 if (th->t_refcount > old_ref) {
2571 if (old_ref)
2572 th->t_refcount--;
2573 else {
2574 int err;
2575 reiserfs_write_lock(inode->i_sb);
2576 err = reiserfs_end_persistent_transaction(th);
2577 reiserfs_write_unlock(inode->i_sb);
2578 if (err)
2579 ret = err;
2580 }
2581 }
2582 }
2583 return ret;
2472 2584
2585}
2473 2586
2474static sector_t reiserfs_aop_bmap(struct address_space *as, sector_t block) { 2587static sector_t reiserfs_aop_bmap(struct address_space *as, sector_t block)
2475 return generic_block_bmap(as, block, reiserfs_bmap) ; 2588{
2589 return generic_block_bmap(as, block, reiserfs_bmap);
2476} 2590}
2477 2591
2478static int reiserfs_commit_write(struct file *f, struct page *page, 2592static int reiserfs_commit_write(struct file *f, struct page *page,
2479 unsigned from, unsigned to) { 2593 unsigned from, unsigned to)
2480 struct inode *inode = page->mapping->host ; 2594{
2481 loff_t pos = ((loff_t)page->index << PAGE_CACHE_SHIFT) + to; 2595 struct inode *inode = page->mapping->host;
2482 int ret = 0; 2596 loff_t pos = ((loff_t) page->index << PAGE_CACHE_SHIFT) + to;
2483 int update_sd = 0; 2597 int ret = 0;
2484 struct reiserfs_transaction_handle *th = NULL; 2598 int update_sd = 0;
2485 2599 struct reiserfs_transaction_handle *th = NULL;
2486 reiserfs_wait_on_write_block(inode->i_sb) ; 2600
2487 if (reiserfs_transaction_running(inode->i_sb)) { 2601 reiserfs_wait_on_write_block(inode->i_sb);
2488 th = current->journal_info; 2602 if (reiserfs_transaction_running(inode->i_sb)) {
2489 } 2603 th = current->journal_info;
2490 reiserfs_commit_page(inode, page, from, to); 2604 }
2491 2605 reiserfs_commit_page(inode, page, from, to);
2492 /* generic_commit_write does this for us, but does not update the
2493 ** transaction tracking stuff when the size changes. So, we have
2494 ** to do the i_size updates here.
2495 */
2496 if (pos > inode->i_size) {
2497 struct reiserfs_transaction_handle myth ;
2498 reiserfs_write_lock(inode->i_sb);
2499 /* If the file have grown beyond the border where it
2500 can have a tail, unmark it as needing a tail
2501 packing */
2502 if ( (have_large_tails (inode->i_sb) && inode->i_size > i_block_size (inode)*4) ||
2503 (have_small_tails (inode->i_sb) && inode->i_size > i_block_size(inode)) )
2504 REISERFS_I(inode)->i_flags &= ~i_pack_on_close_mask ;
2505
2506 ret = journal_begin(&myth, inode->i_sb, 1) ;
2507 if (ret) {
2508 reiserfs_write_unlock(inode->i_sb);
2509 goto journal_error;
2510 }
2511 reiserfs_update_inode_transaction(inode) ;
2512 inode->i_size = pos ;
2513 reiserfs_update_sd(&myth, inode) ;
2514 update_sd = 1;
2515 ret = journal_end(&myth, inode->i_sb, 1) ;
2516 reiserfs_write_unlock(inode->i_sb);
2517 if (ret)
2518 goto journal_error;
2519 }
2520 if (th) {
2521 reiserfs_write_lock(inode->i_sb);
2522 if (!update_sd)
2523 reiserfs_update_sd(th, inode) ;
2524 ret = reiserfs_end_persistent_transaction(th);
2525 reiserfs_write_unlock(inode->i_sb);
2526 if (ret)
2527 goto out;
2528 }
2529
2530 /* we test for O_SYNC here so we can commit the transaction
2531 ** for any packed tails the file might have had
2532 */
2533 if (f && (f->f_flags & O_SYNC)) {
2534 reiserfs_write_lock(inode->i_sb);
2535 ret = reiserfs_commit_for_inode(inode) ;
2536 reiserfs_write_unlock(inode->i_sb);
2537 }
2538out:
2539 return ret ;
2540 2606
2541journal_error: 2607 /* generic_commit_write does this for us, but does not update the
2542 if (th) { 2608 ** transaction tracking stuff when the size changes. So, we have
2543 reiserfs_write_lock(inode->i_sb); 2609 ** to do the i_size updates here.
2544 if (!update_sd) 2610 */
2545 reiserfs_update_sd(th, inode) ; 2611 if (pos > inode->i_size) {
2546 ret = reiserfs_end_persistent_transaction(th); 2612 struct reiserfs_transaction_handle myth;
2547 reiserfs_write_unlock(inode->i_sb); 2613 reiserfs_write_lock(inode->i_sb);
2548 } 2614 /* If the file have grown beyond the border where it
2615 can have a tail, unmark it as needing a tail
2616 packing */
2617 if ((have_large_tails(inode->i_sb)
2618 && inode->i_size > i_block_size(inode) * 4)
2619 || (have_small_tails(inode->i_sb)
2620 && inode->i_size > i_block_size(inode)))
2621 REISERFS_I(inode)->i_flags &= ~i_pack_on_close_mask;
2622
2623 ret = journal_begin(&myth, inode->i_sb, 1);
2624 if (ret) {
2625 reiserfs_write_unlock(inode->i_sb);
2626 goto journal_error;
2627 }
2628 reiserfs_update_inode_transaction(inode);
2629 inode->i_size = pos;
2630 reiserfs_update_sd(&myth, inode);
2631 update_sd = 1;
2632 ret = journal_end(&myth, inode->i_sb, 1);
2633 reiserfs_write_unlock(inode->i_sb);
2634 if (ret)
2635 goto journal_error;
2636 }
2637 if (th) {
2638 reiserfs_write_lock(inode->i_sb);
2639 if (!update_sd)
2640 reiserfs_update_sd(th, inode);
2641 ret = reiserfs_end_persistent_transaction(th);
2642 reiserfs_write_unlock(inode->i_sb);
2643 if (ret)
2644 goto out;
2645 }
2646
2647 /* we test for O_SYNC here so we can commit the transaction
2648 ** for any packed tails the file might have had
2649 */
2650 if (f && (f->f_flags & O_SYNC)) {
2651 reiserfs_write_lock(inode->i_sb);
2652 ret = reiserfs_commit_for_inode(inode);
2653 reiserfs_write_unlock(inode->i_sb);
2654 }
2655 out:
2656 return ret;
2549 2657
2550 return ret; 2658 journal_error:
2659 if (th) {
2660 reiserfs_write_lock(inode->i_sb);
2661 if (!update_sd)
2662 reiserfs_update_sd(th, inode);
2663 ret = reiserfs_end_persistent_transaction(th);
2664 reiserfs_write_unlock(inode->i_sb);
2665 }
2666
2667 return ret;
2551} 2668}
2552 2669
2553void sd_attrs_to_i_attrs( __u16 sd_attrs, struct inode *inode ) 2670void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode)
2554{ 2671{
2555 if( reiserfs_attrs( inode -> i_sb ) ) { 2672 if (reiserfs_attrs(inode->i_sb)) {
2556 if( sd_attrs & REISERFS_SYNC_FL ) 2673 if (sd_attrs & REISERFS_SYNC_FL)
2557 inode -> i_flags |= S_SYNC; 2674 inode->i_flags |= S_SYNC;
2558 else 2675 else
2559 inode -> i_flags &= ~S_SYNC; 2676 inode->i_flags &= ~S_SYNC;
2560 if( sd_attrs & REISERFS_IMMUTABLE_FL ) 2677 if (sd_attrs & REISERFS_IMMUTABLE_FL)
2561 inode -> i_flags |= S_IMMUTABLE; 2678 inode->i_flags |= S_IMMUTABLE;
2562 else 2679 else
2563 inode -> i_flags &= ~S_IMMUTABLE; 2680 inode->i_flags &= ~S_IMMUTABLE;
2564 if( sd_attrs & REISERFS_APPEND_FL ) 2681 if (sd_attrs & REISERFS_APPEND_FL)
2565 inode -> i_flags |= S_APPEND; 2682 inode->i_flags |= S_APPEND;
2566 else 2683 else
2567 inode -> i_flags &= ~S_APPEND; 2684 inode->i_flags &= ~S_APPEND;
2568 if( sd_attrs & REISERFS_NOATIME_FL ) 2685 if (sd_attrs & REISERFS_NOATIME_FL)
2569 inode -> i_flags |= S_NOATIME; 2686 inode->i_flags |= S_NOATIME;
2570 else 2687 else
2571 inode -> i_flags &= ~S_NOATIME; 2688 inode->i_flags &= ~S_NOATIME;
2572 if( sd_attrs & REISERFS_NOTAIL_FL ) 2689 if (sd_attrs & REISERFS_NOTAIL_FL)
2573 REISERFS_I(inode)->i_flags |= i_nopack_mask; 2690 REISERFS_I(inode)->i_flags |= i_nopack_mask;
2574 else 2691 else
2575 REISERFS_I(inode)->i_flags &= ~i_nopack_mask; 2692 REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
2576 } 2693 }
2577} 2694}
2578 2695
2579void i_attrs_to_sd_attrs( struct inode *inode, __u16 *sd_attrs ) 2696void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs)
2580{ 2697{
2581 if( reiserfs_attrs( inode -> i_sb ) ) { 2698 if (reiserfs_attrs(inode->i_sb)) {
2582 if( inode -> i_flags & S_IMMUTABLE ) 2699 if (inode->i_flags & S_IMMUTABLE)
2583 *sd_attrs |= REISERFS_IMMUTABLE_FL; 2700 *sd_attrs |= REISERFS_IMMUTABLE_FL;
2584 else 2701 else
2585 *sd_attrs &= ~REISERFS_IMMUTABLE_FL; 2702 *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
2586 if( inode -> i_flags & S_SYNC ) 2703 if (inode->i_flags & S_SYNC)
2587 *sd_attrs |= REISERFS_SYNC_FL; 2704 *sd_attrs |= REISERFS_SYNC_FL;
2588 else 2705 else
2589 *sd_attrs &= ~REISERFS_SYNC_FL; 2706 *sd_attrs &= ~REISERFS_SYNC_FL;
2590 if( inode -> i_flags & S_NOATIME ) 2707 if (inode->i_flags & S_NOATIME)
2591 *sd_attrs |= REISERFS_NOATIME_FL; 2708 *sd_attrs |= REISERFS_NOATIME_FL;
2592 else 2709 else
2593 *sd_attrs &= ~REISERFS_NOATIME_FL; 2710 *sd_attrs &= ~REISERFS_NOATIME_FL;
2594 if( REISERFS_I(inode)->i_flags & i_nopack_mask ) 2711 if (REISERFS_I(inode)->i_flags & i_nopack_mask)
2595 *sd_attrs |= REISERFS_NOTAIL_FL; 2712 *sd_attrs |= REISERFS_NOTAIL_FL;
2596 else 2713 else
2597 *sd_attrs &= ~REISERFS_NOTAIL_FL; 2714 *sd_attrs &= ~REISERFS_NOTAIL_FL;
@@ -2603,106 +2720,107 @@ void i_attrs_to_sd_attrs( struct inode *inode, __u16 *sd_attrs )
2603*/ 2720*/
2604static int invalidatepage_can_drop(struct inode *inode, struct buffer_head *bh) 2721static int invalidatepage_can_drop(struct inode *inode, struct buffer_head *bh)
2605{ 2722{
2606 int ret = 1 ; 2723 int ret = 1;
2607 struct reiserfs_journal *j = SB_JOURNAL(inode->i_sb) ; 2724 struct reiserfs_journal *j = SB_JOURNAL(inode->i_sb);
2608 2725
2609 spin_lock(&j->j_dirty_buffers_lock) ; 2726 spin_lock(&j->j_dirty_buffers_lock);
2610 if (!buffer_mapped(bh)) { 2727 if (!buffer_mapped(bh)) {
2611 goto free_jh; 2728 goto free_jh;
2612 } 2729 }
2613 /* the page is locked, and the only places that log a data buffer 2730 /* the page is locked, and the only places that log a data buffer
2614 * also lock the page. 2731 * also lock the page.
2615 */
2616 if (reiserfs_file_data_log(inode)) {
2617 /*
2618 * very conservative, leave the buffer pinned if
2619 * anyone might need it.
2620 */
2621 if (buffer_journaled(bh) || buffer_journal_dirty(bh)) {
2622 ret = 0 ;
2623 }
2624 } else
2625 if (buffer_dirty(bh) || buffer_locked(bh)) {
2626 struct reiserfs_journal_list *jl;
2627 struct reiserfs_jh *jh = bh->b_private;
2628
2629 /* why is this safe?
2630 * reiserfs_setattr updates i_size in the on disk
2631 * stat data before allowing vmtruncate to be called.
2632 *
2633 * If buffer was put onto the ordered list for this
2634 * transaction, we know for sure either this transaction
2635 * or an older one already has updated i_size on disk,
2636 * and this ordered data won't be referenced in the file
2637 * if we crash.
2638 *
2639 * if the buffer was put onto the ordered list for an older
2640 * transaction, we need to leave it around
2641 */ 2732 */
2642 if (jh && (jl = jh->jl) && jl != SB_JOURNAL(inode->i_sb)->j_current_jl) 2733 if (reiserfs_file_data_log(inode)) {
2643 ret = 0; 2734 /*
2644 } 2735 * very conservative, leave the buffer pinned if
2645free_jh: 2736 * anyone might need it.
2646 if (ret && bh->b_private) { 2737 */
2647 reiserfs_free_jh(bh); 2738 if (buffer_journaled(bh) || buffer_journal_dirty(bh)) {
2648 } 2739 ret = 0;
2649 spin_unlock(&j->j_dirty_buffers_lock) ; 2740 }
2650 return ret ; 2741 } else if (buffer_dirty(bh) || buffer_locked(bh)) {
2742 struct reiserfs_journal_list *jl;
2743 struct reiserfs_jh *jh = bh->b_private;
2744
2745 /* why is this safe?
2746 * reiserfs_setattr updates i_size in the on disk
2747 * stat data before allowing vmtruncate to be called.
2748 *
2749 * If buffer was put onto the ordered list for this
2750 * transaction, we know for sure either this transaction
2751 * or an older one already has updated i_size on disk,
2752 * and this ordered data won't be referenced in the file
2753 * if we crash.
2754 *
2755 * if the buffer was put onto the ordered list for an older
2756 * transaction, we need to leave it around
2757 */
2758 if (jh && (jl = jh->jl)
2759 && jl != SB_JOURNAL(inode->i_sb)->j_current_jl)
2760 ret = 0;
2761 }
2762 free_jh:
2763 if (ret && bh->b_private) {
2764 reiserfs_free_jh(bh);
2765 }
2766 spin_unlock(&j->j_dirty_buffers_lock);
2767 return ret;
2651} 2768}
2652 2769
2653/* clm -- taken from fs/buffer.c:block_invalidate_page */ 2770/* clm -- taken from fs/buffer.c:block_invalidate_page */
2654static int reiserfs_invalidatepage(struct page *page, unsigned long offset) 2771static int reiserfs_invalidatepage(struct page *page, unsigned long offset)
2655{ 2772{
2656 struct buffer_head *head, *bh, *next; 2773 struct buffer_head *head, *bh, *next;
2657 struct inode *inode = page->mapping->host; 2774 struct inode *inode = page->mapping->host;
2658 unsigned int curr_off = 0; 2775 unsigned int curr_off = 0;
2659 int ret = 1; 2776 int ret = 1;
2660 2777
2661 BUG_ON(!PageLocked(page)); 2778 BUG_ON(!PageLocked(page));
2662 2779
2663 if (offset == 0) 2780 if (offset == 0)
2664 ClearPageChecked(page); 2781 ClearPageChecked(page);
2665 2782
2666 if (!page_has_buffers(page)) 2783 if (!page_has_buffers(page))
2667 goto out; 2784 goto out;
2785
2786 head = page_buffers(page);
2787 bh = head;
2788 do {
2789 unsigned int next_off = curr_off + bh->b_size;
2790 next = bh->b_this_page;
2668 2791
2669 head = page_buffers(page); 2792 /*
2670 bh = head; 2793 * is this block fully invalidated?
2671 do { 2794 */
2672 unsigned int next_off = curr_off + bh->b_size; 2795 if (offset <= curr_off) {
2673 next = bh->b_this_page; 2796 if (invalidatepage_can_drop(inode, bh))
2797 reiserfs_unmap_buffer(bh);
2798 else
2799 ret = 0;
2800 }
2801 curr_off = next_off;
2802 bh = next;
2803 } while (bh != head);
2674 2804
2675 /* 2805 /*
2676 * is this block fully invalidated? 2806 * We release buffers only if the entire page is being invalidated.
2807 * The get_block cached value has been unconditionally invalidated,
2808 * so real IO is not possible anymore.
2677 */ 2809 */
2678 if (offset <= curr_off) { 2810 if (!offset && ret)
2679 if (invalidatepage_can_drop(inode, bh)) 2811 ret = try_to_release_page(page, 0);
2680 reiserfs_unmap_buffer(bh); 2812 out:
2681 else 2813 return ret;
2682 ret = 0;
2683 }
2684 curr_off = next_off;
2685 bh = next;
2686 } while (bh != head);
2687
2688 /*
2689 * We release buffers only if the entire page is being invalidated.
2690 * The get_block cached value has been unconditionally invalidated,
2691 * so real IO is not possible anymore.
2692 */
2693 if (!offset && ret)
2694 ret = try_to_release_page(page, 0);
2695out:
2696 return ret;
2697} 2814}
2698 2815
2699static int reiserfs_set_page_dirty(struct page *page) { 2816static int reiserfs_set_page_dirty(struct page *page)
2700 struct inode *inode = page->mapping->host; 2817{
2701 if (reiserfs_file_data_log(inode)) { 2818 struct inode *inode = page->mapping->host;
2702 SetPageChecked(page); 2819 if (reiserfs_file_data_log(inode)) {
2703 return __set_page_dirty_nobuffers(page); 2820 SetPageChecked(page);
2704 } 2821 return __set_page_dirty_nobuffers(page);
2705 return __set_page_dirty_buffers(page); 2822 }
2823 return __set_page_dirty_buffers(page);
2706} 2824}
2707 2825
2708/* 2826/*
@@ -2716,143 +2834,152 @@ static int reiserfs_set_page_dirty(struct page *page) {
2716 */ 2834 */
2717static int reiserfs_releasepage(struct page *page, int unused_gfp_flags) 2835static int reiserfs_releasepage(struct page *page, int unused_gfp_flags)
2718{ 2836{
2719 struct inode *inode = page->mapping->host ; 2837 struct inode *inode = page->mapping->host;
2720 struct reiserfs_journal *j = SB_JOURNAL(inode->i_sb) ; 2838 struct reiserfs_journal *j = SB_JOURNAL(inode->i_sb);
2721 struct buffer_head *head ; 2839 struct buffer_head *head;
2722 struct buffer_head *bh ; 2840 struct buffer_head *bh;
2723 int ret = 1 ; 2841 int ret = 1;
2724 2842
2725 WARN_ON(PageChecked(page)); 2843 WARN_ON(PageChecked(page));
2726 spin_lock(&j->j_dirty_buffers_lock) ; 2844 spin_lock(&j->j_dirty_buffers_lock);
2727 head = page_buffers(page) ; 2845 head = page_buffers(page);
2728 bh = head ; 2846 bh = head;
2729 do { 2847 do {
2730 if (bh->b_private) { 2848 if (bh->b_private) {
2731 if (!buffer_dirty(bh) && !buffer_locked(bh)) { 2849 if (!buffer_dirty(bh) && !buffer_locked(bh)) {
2732 reiserfs_free_jh(bh); 2850 reiserfs_free_jh(bh);
2733 } else { 2851 } else {
2734 ret = 0 ; 2852 ret = 0;
2735 break ; 2853 break;
2736 } 2854 }
2737 } 2855 }
2738 bh = bh->b_this_page ; 2856 bh = bh->b_this_page;
2739 } while (bh != head) ; 2857 } while (bh != head);
2740 if (ret) 2858 if (ret)
2741 ret = try_to_free_buffers(page) ; 2859 ret = try_to_free_buffers(page);
2742 spin_unlock(&j->j_dirty_buffers_lock) ; 2860 spin_unlock(&j->j_dirty_buffers_lock);
2743 return ret ; 2861 return ret;
2744} 2862}
2745 2863
2746/* We thank Mingming Cao for helping us understand in great detail what 2864/* We thank Mingming Cao for helping us understand in great detail what
2747 to do in this section of the code. */ 2865 to do in this section of the code. */
2748static ssize_t reiserfs_direct_IO(int rw, struct kiocb *iocb, 2866static ssize_t reiserfs_direct_IO(int rw, struct kiocb *iocb,
2749 const struct iovec *iov, loff_t offset, unsigned long nr_segs) 2867 const struct iovec *iov, loff_t offset,
2868 unsigned long nr_segs)
2750{ 2869{
2751 struct file *file = iocb->ki_filp; 2870 struct file *file = iocb->ki_filp;
2752 struct inode *inode = file->f_mapping->host; 2871 struct inode *inode = file->f_mapping->host;
2753 2872
2754 return blockdev_direct_IO(rw, iocb, inode, inode->i_sb->s_bdev, iov, 2873 return blockdev_direct_IO(rw, iocb, inode, inode->i_sb->s_bdev, iov,
2755 offset, nr_segs, reiserfs_get_blocks_direct_io, NULL); 2874 offset, nr_segs,
2875 reiserfs_get_blocks_direct_io, NULL);
2756} 2876}
2757 2877
2758int reiserfs_setattr(struct dentry *dentry, struct iattr *attr) { 2878int reiserfs_setattr(struct dentry *dentry, struct iattr *attr)
2759 struct inode *inode = dentry->d_inode ; 2879{
2760 int error ; 2880 struct inode *inode = dentry->d_inode;
2761 unsigned int ia_valid = attr->ia_valid; 2881 int error;
2762 reiserfs_write_lock(inode->i_sb); 2882 unsigned int ia_valid = attr->ia_valid;
2763 if (attr->ia_valid & ATTR_SIZE) { 2883 reiserfs_write_lock(inode->i_sb);
2764 /* version 2 items will be caught by the s_maxbytes check 2884 if (attr->ia_valid & ATTR_SIZE) {
2765 ** done for us in vmtruncate 2885 /* version 2 items will be caught by the s_maxbytes check
2766 */ 2886 ** done for us in vmtruncate
2767 if (get_inode_item_key_version(inode) == KEY_FORMAT_3_5 && 2887 */
2768 attr->ia_size > MAX_NON_LFS) { 2888 if (get_inode_item_key_version(inode) == KEY_FORMAT_3_5 &&
2769 error = -EFBIG ; 2889 attr->ia_size > MAX_NON_LFS) {
2770 goto out; 2890 error = -EFBIG;
2771 } 2891 goto out;
2772 /* fill in hole pointers in the expanding truncate case. */ 2892 }
2773 if (attr->ia_size > inode->i_size) { 2893 /* fill in hole pointers in the expanding truncate case. */
2774 error = generic_cont_expand(inode, attr->ia_size) ; 2894 if (attr->ia_size > inode->i_size) {
2775 if (REISERFS_I(inode)->i_prealloc_count > 0) { 2895 error = generic_cont_expand(inode, attr->ia_size);
2776 int err; 2896 if (REISERFS_I(inode)->i_prealloc_count > 0) {
2777 struct reiserfs_transaction_handle th ; 2897 int err;
2778 /* we're changing at most 2 bitmaps, inode + super */ 2898 struct reiserfs_transaction_handle th;
2779 err = journal_begin(&th, inode->i_sb, 4) ; 2899 /* we're changing at most 2 bitmaps, inode + super */
2780 if (!err) { 2900 err = journal_begin(&th, inode->i_sb, 4);
2781 reiserfs_discard_prealloc (&th, inode); 2901 if (!err) {
2782 err = journal_end(&th, inode->i_sb, 4) ; 2902 reiserfs_discard_prealloc(&th, inode);
2903 err = journal_end(&th, inode->i_sb, 4);
2904 }
2905 if (err)
2906 error = err;
2907 }
2908 if (error)
2909 goto out;
2783 } 2910 }
2784 if (err)
2785 error = err;
2786 }
2787 if (error)
2788 goto out;
2789 } 2911 }
2790 }
2791 2912
2792 if ((((attr->ia_valid & ATTR_UID) && (attr->ia_uid & ~0xffff)) || 2913 if ((((attr->ia_valid & ATTR_UID) && (attr->ia_uid & ~0xffff)) ||
2793 ((attr->ia_valid & ATTR_GID) && (attr->ia_gid & ~0xffff))) && 2914 ((attr->ia_valid & ATTR_GID) && (attr->ia_gid & ~0xffff))) &&
2794 (get_inode_sd_version (inode) == STAT_DATA_V1)) { 2915 (get_inode_sd_version(inode) == STAT_DATA_V1)) {
2795 /* stat data of format v3.5 has 16 bit uid and gid */ 2916 /* stat data of format v3.5 has 16 bit uid and gid */
2796 error = -EINVAL; 2917 error = -EINVAL;
2797 goto out; 2918 goto out;
2798 } 2919 }
2799
2800 error = inode_change_ok(inode, attr) ;
2801 if (!error) {
2802 if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
2803 (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
2804 error = reiserfs_chown_xattrs (inode, attr);
2805
2806 if (!error) {
2807 struct reiserfs_transaction_handle th;
2808 int jbegin_count = 2*(REISERFS_QUOTA_INIT_BLOCKS(inode->i_sb)+REISERFS_QUOTA_DEL_BLOCKS(inode->i_sb))+2;
2809
2810 /* (user+group)*(old+new) structure - we count quota info and , inode write (sb, inode) */
2811 error = journal_begin(&th, inode->i_sb, jbegin_count);
2812 if (error)
2813 goto out;
2814 error = DQUOT_TRANSFER(inode, attr) ? -EDQUOT : 0;
2815 if (error) {
2816 journal_end(&th, inode->i_sb, jbegin_count);
2817 goto out;
2818 }
2819 /* Update corresponding info in inode so that everything is in
2820 * one transaction */
2821 if (attr->ia_valid & ATTR_UID)
2822 inode->i_uid = attr->ia_uid;
2823 if (attr->ia_valid & ATTR_GID)
2824 inode->i_gid = attr->ia_gid;
2825 mark_inode_dirty(inode);
2826 error = journal_end(&th, inode->i_sb, jbegin_count);
2827 }
2828 }
2829 if (!error)
2830 error = inode_setattr(inode, attr) ;
2831 }
2832 2920
2921 error = inode_change_ok(inode, attr);
2922 if (!error) {
2923 if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
2924 (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
2925 error = reiserfs_chown_xattrs(inode, attr);
2926
2927 if (!error) {
2928 struct reiserfs_transaction_handle th;
2929 int jbegin_count =
2930 2 *
2931 (REISERFS_QUOTA_INIT_BLOCKS(inode->i_sb) +
2932 REISERFS_QUOTA_DEL_BLOCKS(inode->i_sb)) +
2933 2;
2934
2935 /* (user+group)*(old+new) structure - we count quota info and , inode write (sb, inode) */
2936 error =
2937 journal_begin(&th, inode->i_sb,
2938 jbegin_count);
2939 if (error)
2940 goto out;
2941 error =
2942 DQUOT_TRANSFER(inode, attr) ? -EDQUOT : 0;
2943 if (error) {
2944 journal_end(&th, inode->i_sb,
2945 jbegin_count);
2946 goto out;
2947 }
2948 /* Update corresponding info in inode so that everything is in
2949 * one transaction */
2950 if (attr->ia_valid & ATTR_UID)
2951 inode->i_uid = attr->ia_uid;
2952 if (attr->ia_valid & ATTR_GID)
2953 inode->i_gid = attr->ia_gid;
2954 mark_inode_dirty(inode);
2955 error =
2956 journal_end(&th, inode->i_sb, jbegin_count);
2957 }
2958 }
2959 if (!error)
2960 error = inode_setattr(inode, attr);
2961 }
2833 2962
2834 if (!error && reiserfs_posixacl (inode->i_sb)) { 2963 if (!error && reiserfs_posixacl(inode->i_sb)) {
2835 if (attr->ia_valid & ATTR_MODE) 2964 if (attr->ia_valid & ATTR_MODE)
2836 error = reiserfs_acl_chmod (inode); 2965 error = reiserfs_acl_chmod(inode);
2837 } 2966 }
2838 2967
2839out: 2968 out:
2840 reiserfs_write_unlock(inode->i_sb); 2969 reiserfs_write_unlock(inode->i_sb);
2841 return error ; 2970 return error;
2842} 2971}
2843 2972
2844
2845
2846struct address_space_operations reiserfs_address_space_operations = { 2973struct address_space_operations reiserfs_address_space_operations = {
2847 .writepage = reiserfs_writepage, 2974 .writepage = reiserfs_writepage,
2848 .readpage = reiserfs_readpage, 2975 .readpage = reiserfs_readpage,
2849 .readpages = reiserfs_readpages, 2976 .readpages = reiserfs_readpages,
2850 .releasepage = reiserfs_releasepage, 2977 .releasepage = reiserfs_releasepage,
2851 .invalidatepage = reiserfs_invalidatepage, 2978 .invalidatepage = reiserfs_invalidatepage,
2852 .sync_page = block_sync_page, 2979 .sync_page = block_sync_page,
2853 .prepare_write = reiserfs_prepare_write, 2980 .prepare_write = reiserfs_prepare_write,
2854 .commit_write = reiserfs_commit_write, 2981 .commit_write = reiserfs_commit_write,
2855 .bmap = reiserfs_aop_bmap, 2982 .bmap = reiserfs_aop_bmap,
2856 .direct_IO = reiserfs_direct_IO, 2983 .direct_IO = reiserfs_direct_IO,
2857 .set_page_dirty = reiserfs_set_page_dirty, 2984 .set_page_dirty = reiserfs_set_page_dirty,
2858} ; 2985};
diff --git a/fs/reiserfs/ioctl.c b/fs/reiserfs/ioctl.c
index 76caedf737f2..81fc00285f60 100644
--- a/fs/reiserfs/ioctl.c
+++ b/fs/reiserfs/ioctl.c
@@ -9,7 +9,7 @@
9#include <linux/pagemap.h> 9#include <linux/pagemap.h>
10#include <linux/smp_lock.h> 10#include <linux/smp_lock.h>
11 11
12static int reiserfs_unpack (struct inode * inode, struct file * filp); 12static int reiserfs_unpack(struct inode *inode, struct file *filp);
13 13
14/* 14/*
15** reiserfs_ioctl - handler for ioctl for inode 15** reiserfs_ioctl - handler for ioctl for inode
@@ -19,69 +19,72 @@ static int reiserfs_unpack (struct inode * inode, struct file * filp);
19** 2) REISERFS_IOC_[GS]ETFLAGS, REISERFS_IOC_[GS]ETVERSION 19** 2) REISERFS_IOC_[GS]ETFLAGS, REISERFS_IOC_[GS]ETVERSION
20** 3) That's all for a while ... 20** 3) That's all for a while ...
21*/ 21*/
22int reiserfs_ioctl (struct inode * inode, struct file * filp, unsigned int cmd, 22int reiserfs_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
23 unsigned long arg) 23 unsigned long arg)
24{ 24{
25 unsigned int flags; 25 unsigned int flags;
26 26
27 switch (cmd) { 27 switch (cmd) {
28 case REISERFS_IOC_UNPACK: 28 case REISERFS_IOC_UNPACK:
29 if( S_ISREG( inode -> i_mode ) ) { 29 if (S_ISREG(inode->i_mode)) {
30 if (arg) 30 if (arg)
31 return reiserfs_unpack (inode, filp); 31 return reiserfs_unpack(inode, filp);
32 else 32 else
33 return 0; 33 return 0;
34 } else 34 } else
35 return -ENOTTY; 35 return -ENOTTY;
36 /* following two cases are taken from fs/ext2/ioctl.c by Remy 36 /* following two cases are taken from fs/ext2/ioctl.c by Remy
37 Card (card@masi.ibp.fr) */ 37 Card (card@masi.ibp.fr) */
38 case REISERFS_IOC_GETFLAGS: 38 case REISERFS_IOC_GETFLAGS:
39 if (!reiserfs_attrs (inode->i_sb)) 39 if (!reiserfs_attrs(inode->i_sb))
40 return -ENOTTY; 40 return -ENOTTY;
41 41
42 flags = REISERFS_I(inode) -> i_attrs; 42 flags = REISERFS_I(inode)->i_attrs;
43 i_attrs_to_sd_attrs( inode, ( __u16 * ) &flags ); 43 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
44 return put_user(flags, (int __user *) arg); 44 return put_user(flags, (int __user *)arg);
45 case REISERFS_IOC_SETFLAGS: { 45 case REISERFS_IOC_SETFLAGS:{
46 if (!reiserfs_attrs (inode->i_sb)) 46 if (!reiserfs_attrs(inode->i_sb))
47 return -ENOTTY; 47 return -ENOTTY;
48 48
49 if (IS_RDONLY(inode)) 49 if (IS_RDONLY(inode))
50 return -EROFS; 50 return -EROFS;
51 51
52 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER)) 52 if ((current->fsuid != inode->i_uid)
53 return -EPERM; 53 && !capable(CAP_FOWNER))
54 return -EPERM;
54 55
55 if (get_user(flags, (int __user *) arg)) 56 if (get_user(flags, (int __user *)arg))
56 return -EFAULT; 57 return -EFAULT;
57 58
58 if ( ( ( flags ^ REISERFS_I(inode) -> i_attrs) & ( REISERFS_IMMUTABLE_FL | REISERFS_APPEND_FL)) && 59 if (((flags ^ REISERFS_I(inode)->
59 !capable( CAP_LINUX_IMMUTABLE ) ) 60 i_attrs) & (REISERFS_IMMUTABLE_FL |
60 return -EPERM; 61 REISERFS_APPEND_FL))
61 62 && !capable(CAP_LINUX_IMMUTABLE))
62 if( ( flags & REISERFS_NOTAIL_FL ) && 63 return -EPERM;
63 S_ISREG( inode -> i_mode ) ) { 64
65 if ((flags & REISERFS_NOTAIL_FL) &&
66 S_ISREG(inode->i_mode)) {
64 int result; 67 int result;
65 68
66 result = reiserfs_unpack( inode, filp ); 69 result = reiserfs_unpack(inode, filp);
67 if( result ) 70 if (result)
68 return result; 71 return result;
72 }
73 sd_attrs_to_i_attrs(flags, inode);
74 REISERFS_I(inode)->i_attrs = flags;
75 inode->i_ctime = CURRENT_TIME_SEC;
76 mark_inode_dirty(inode);
77 return 0;
69 } 78 }
70 sd_attrs_to_i_attrs( flags, inode );
71 REISERFS_I(inode) -> i_attrs = flags;
72 inode->i_ctime = CURRENT_TIME_SEC;
73 mark_inode_dirty(inode);
74 return 0;
75 }
76 case REISERFS_IOC_GETVERSION: 79 case REISERFS_IOC_GETVERSION:
77 return put_user(inode->i_generation, (int __user *) arg); 80 return put_user(inode->i_generation, (int __user *)arg);
78 case REISERFS_IOC_SETVERSION: 81 case REISERFS_IOC_SETVERSION:
79 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER)) 82 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
80 return -EPERM; 83 return -EPERM;
81 if (IS_RDONLY(inode)) 84 if (IS_RDONLY(inode))
82 return -EROFS; 85 return -EROFS;
83 if (get_user(inode->i_generation, (int __user *) arg)) 86 if (get_user(inode->i_generation, (int __user *)arg))
84 return -EFAULT; 87 return -EFAULT;
85 inode->i_ctime = CURRENT_TIME_SEC; 88 inode->i_ctime = CURRENT_TIME_SEC;
86 mark_inode_dirty(inode); 89 mark_inode_dirty(inode);
87 return 0; 90 return 0;
@@ -95,63 +98,65 @@ int reiserfs_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
95** Function try to convert tail from direct item into indirect. 98** Function try to convert tail from direct item into indirect.
96** It set up nopack attribute in the REISERFS_I(inode)->nopack 99** It set up nopack attribute in the REISERFS_I(inode)->nopack
97*/ 100*/
98static int reiserfs_unpack (struct inode * inode, struct file * filp) 101static int reiserfs_unpack(struct inode *inode, struct file *filp)
99{ 102{
100 int retval = 0; 103 int retval = 0;
101 int index ; 104 int index;
102 struct page *page ; 105 struct page *page;
103 struct address_space *mapping ; 106 struct address_space *mapping;
104 unsigned long write_from ; 107 unsigned long write_from;
105 unsigned long blocksize = inode->i_sb->s_blocksize ; 108 unsigned long blocksize = inode->i_sb->s_blocksize;
106 109
107 if (inode->i_size == 0) { 110 if (inode->i_size == 0) {
108 REISERFS_I(inode)->i_flags |= i_nopack_mask; 111 REISERFS_I(inode)->i_flags |= i_nopack_mask;
109 return 0 ; 112 return 0;
110 } 113 }
111 /* ioctl already done */ 114 /* ioctl already done */
112 if (REISERFS_I(inode)->i_flags & i_nopack_mask) { 115 if (REISERFS_I(inode)->i_flags & i_nopack_mask) {
113 return 0 ; 116 return 0;
114 } 117 }
115 reiserfs_write_lock(inode->i_sb); 118 reiserfs_write_lock(inode->i_sb);
116 119
117 /* we need to make sure nobody is changing the file size beneath 120 /* we need to make sure nobody is changing the file size beneath
118 ** us 121 ** us
119 */ 122 */
120 down(&inode->i_sem) ; 123 down(&inode->i_sem);
121 124
122 write_from = inode->i_size & (blocksize - 1) ; 125 write_from = inode->i_size & (blocksize - 1);
123 /* if we are on a block boundary, we are already unpacked. */ 126 /* if we are on a block boundary, we are already unpacked. */
124 if ( write_from == 0) { 127 if (write_from == 0) {
128 REISERFS_I(inode)->i_flags |= i_nopack_mask;
129 goto out;
130 }
131
132 /* we unpack by finding the page with the tail, and calling
133 ** reiserfs_prepare_write on that page. This will force a
134 ** reiserfs_get_block to unpack the tail for us.
135 */
136 index = inode->i_size >> PAGE_CACHE_SHIFT;
137 mapping = inode->i_mapping;
138 page = grab_cache_page(mapping, index);
139 retval = -ENOMEM;
140 if (!page) {
141 goto out;
142 }
143 retval =
144 mapping->a_ops->prepare_write(NULL, page, write_from, write_from);
145 if (retval)
146 goto out_unlock;
147
148 /* conversion can change page contents, must flush */
149 flush_dcache_page(page);
150 retval =
151 mapping->a_ops->commit_write(NULL, page, write_from, write_from);
125 REISERFS_I(inode)->i_flags |= i_nopack_mask; 152 REISERFS_I(inode)->i_flags |= i_nopack_mask;
126 goto out ; 153
127 } 154 out_unlock:
128 155 unlock_page(page);
129 /* we unpack by finding the page with the tail, and calling 156 page_cache_release(page);
130 ** reiserfs_prepare_write on that page. This will force a 157
131 ** reiserfs_get_block to unpack the tail for us. 158 out:
132 */ 159 up(&inode->i_sem);
133 index = inode->i_size >> PAGE_CACHE_SHIFT ; 160 reiserfs_write_unlock(inode->i_sb);
134 mapping = inode->i_mapping ; 161 return retval;
135 page = grab_cache_page(mapping, index) ;
136 retval = -ENOMEM;
137 if (!page) {
138 goto out ;
139 }
140 retval = mapping->a_ops->prepare_write(NULL, page, write_from, write_from) ;
141 if (retval)
142 goto out_unlock ;
143
144 /* conversion can change page contents, must flush */
145 flush_dcache_page(page) ;
146 retval = mapping->a_ops->commit_write(NULL, page, write_from, write_from) ;
147 REISERFS_I(inode)->i_flags |= i_nopack_mask;
148
149out_unlock:
150 unlock_page(page) ;
151 page_cache_release(page) ;
152
153out:
154 up(&inode->i_sem) ;
155 reiserfs_write_unlock(inode->i_sb);
156 return retval;
157} 162}
diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
index 0ce33db1acdf..e237cd668e5b 100644
--- a/fs/reiserfs/item_ops.c
+++ b/fs/reiserfs/item_ops.c
@@ -14,776 +14,741 @@
14////////////////////////////////////////////////////////////////////////////// 14//////////////////////////////////////////////////////////////////////////////
15// stat data functions 15// stat data functions
16// 16//
17static int sd_bytes_number (struct item_head * ih, int block_size) 17static int sd_bytes_number(struct item_head *ih, int block_size)
18{ 18{
19 return 0; 19 return 0;
20} 20}
21 21
22static void sd_decrement_key (struct cpu_key * key) 22static void sd_decrement_key(struct cpu_key *key)
23{ 23{
24 key->on_disk_key.k_objectid --; 24 key->on_disk_key.k_objectid--;
25 set_cpu_key_k_type (key, TYPE_ANY); 25 set_cpu_key_k_type(key, TYPE_ANY);
26 set_cpu_key_k_offset(key, (loff_t)(-1)); 26 set_cpu_key_k_offset(key, (loff_t) (-1));
27} 27}
28 28
29static int sd_is_left_mergeable (struct reiserfs_key * key, unsigned long bsize) 29static int sd_is_left_mergeable(struct reiserfs_key *key, unsigned long bsize)
30{ 30{
31 return 0; 31 return 0;
32} 32}
33 33
34 34static char *print_time(time_t t)
35
36static char * print_time (time_t t)
37{ 35{
38 static char timebuf[256]; 36 static char timebuf[256];
39 37
40 sprintf (timebuf, "%ld", t); 38 sprintf(timebuf, "%ld", t);
41 return timebuf; 39 return timebuf;
42} 40}
43 41
44 42static void sd_print_item(struct item_head *ih, char *item)
45static void sd_print_item (struct item_head * ih, char * item)
46{ 43{
47 printk ("\tmode | size | nlinks | first direct | mtime\n"); 44 printk("\tmode | size | nlinks | first direct | mtime\n");
48 if (stat_data_v1 (ih)) { 45 if (stat_data_v1(ih)) {
49 struct stat_data_v1 * sd = (struct stat_data_v1 *)item; 46 struct stat_data_v1 *sd = (struct stat_data_v1 *)item;
50 47
51 printk ("\t0%-6o | %6u | %2u | %d | %s\n", sd_v1_mode(sd), 48 printk("\t0%-6o | %6u | %2u | %d | %s\n", sd_v1_mode(sd),
52 sd_v1_size(sd), sd_v1_nlink(sd), sd_v1_first_direct_byte(sd), 49 sd_v1_size(sd), sd_v1_nlink(sd),
53 print_time( sd_v1_mtime(sd) ) ); 50 sd_v1_first_direct_byte(sd),
54 } else { 51 print_time(sd_v1_mtime(sd)));
55 struct stat_data * sd = (struct stat_data *)item; 52 } else {
53 struct stat_data *sd = (struct stat_data *)item;
56 54
57 printk ("\t0%-6o | %6Lu | %2u | %d | %s\n", sd_v2_mode(sd), 55 printk("\t0%-6o | %6Lu | %2u | %d | %s\n", sd_v2_mode(sd),
58 (unsigned long long)sd_v2_size(sd), sd_v2_nlink(sd), 56 (unsigned long long)sd_v2_size(sd), sd_v2_nlink(sd),
59 sd_v2_rdev(sd), print_time(sd_v2_mtime(sd))); 57 sd_v2_rdev(sd), print_time(sd_v2_mtime(sd)));
60 } 58 }
61} 59}
62 60
63static void sd_check_item (struct item_head * ih, char * item) 61static void sd_check_item(struct item_head *ih, char *item)
64{ 62{
65 // FIXME: type something here! 63 // FIXME: type something here!
66} 64}
67 65
68 66static int sd_create_vi(struct virtual_node *vn,
69static int sd_create_vi (struct virtual_node * vn, 67 struct virtual_item *vi,
70 struct virtual_item * vi, 68 int is_affected, int insert_size)
71 int is_affected,
72 int insert_size)
73{ 69{
74 vi->vi_index = TYPE_STAT_DATA; 70 vi->vi_index = TYPE_STAT_DATA;
75 //vi->vi_type |= VI_TYPE_STAT_DATA;// not needed? 71 //vi->vi_type |= VI_TYPE_STAT_DATA;// not needed?
76 return 0; 72 return 0;
77} 73}
78 74
79 75static int sd_check_left(struct virtual_item *vi, int free,
80static int sd_check_left (struct virtual_item * vi, int free, 76 int start_skip, int end_skip)
81 int start_skip, int end_skip)
82{ 77{
83 if (start_skip || end_skip) 78 if (start_skip || end_skip)
84 BUG (); 79 BUG();
85 return -1; 80 return -1;
86} 81}
87 82
88 83static int sd_check_right(struct virtual_item *vi, int free)
89static int sd_check_right (struct virtual_item * vi, int free)
90{ 84{
91 return -1; 85 return -1;
92} 86}
93 87
94static int sd_part_size (struct virtual_item * vi, int first, int count) 88static int sd_part_size(struct virtual_item *vi, int first, int count)
95{ 89{
96 if (count) 90 if (count)
97 BUG (); 91 BUG();
98 return 0; 92 return 0;
99} 93}
100 94
101static int sd_unit_num (struct virtual_item * vi) 95static int sd_unit_num(struct virtual_item *vi)
102{ 96{
103 return vi->vi_item_len - IH_SIZE; 97 return vi->vi_item_len - IH_SIZE;
104} 98}
105 99
106 100static void sd_print_vi(struct virtual_item *vi)
107static void sd_print_vi (struct virtual_item * vi)
108{ 101{
109 reiserfs_warning (NULL, "STATDATA, index %d, type 0x%x, %h", 102 reiserfs_warning(NULL, "STATDATA, index %d, type 0x%x, %h",
110 vi->vi_index, vi->vi_type, vi->vi_ih); 103 vi->vi_index, vi->vi_type, vi->vi_ih);
111} 104}
112 105
113static struct item_operations stat_data_ops = { 106static struct item_operations stat_data_ops = {
114 .bytes_number = sd_bytes_number, 107 .bytes_number = sd_bytes_number,
115 .decrement_key = sd_decrement_key, 108 .decrement_key = sd_decrement_key,
116 .is_left_mergeable = sd_is_left_mergeable, 109 .is_left_mergeable = sd_is_left_mergeable,
117 .print_item = sd_print_item, 110 .print_item = sd_print_item,
118 .check_item = sd_check_item, 111 .check_item = sd_check_item,
119 112
120 .create_vi = sd_create_vi, 113 .create_vi = sd_create_vi,
121 .check_left = sd_check_left, 114 .check_left = sd_check_left,
122 .check_right = sd_check_right, 115 .check_right = sd_check_right,
123 .part_size = sd_part_size, 116 .part_size = sd_part_size,
124 .unit_num = sd_unit_num, 117 .unit_num = sd_unit_num,
125 .print_vi = sd_print_vi 118 .print_vi = sd_print_vi
126}; 119};
127 120
128
129
130////////////////////////////////////////////////////////////////////////////// 121//////////////////////////////////////////////////////////////////////////////
131// direct item functions 122// direct item functions
132// 123//
133static int direct_bytes_number (struct item_head * ih, int block_size) 124static int direct_bytes_number(struct item_head *ih, int block_size)
134{ 125{
135 return ih_item_len(ih); 126 return ih_item_len(ih);
136} 127}
137 128
138
139// FIXME: this should probably switch to indirect as well 129// FIXME: this should probably switch to indirect as well
140static void direct_decrement_key (struct cpu_key * key) 130static void direct_decrement_key(struct cpu_key *key)
141{ 131{
142 cpu_key_k_offset_dec (key); 132 cpu_key_k_offset_dec(key);
143 if (cpu_key_k_offset (key) == 0) 133 if (cpu_key_k_offset(key) == 0)
144 set_cpu_key_k_type (key, TYPE_STAT_DATA); 134 set_cpu_key_k_type(key, TYPE_STAT_DATA);
145} 135}
146 136
147 137static int direct_is_left_mergeable(struct reiserfs_key *key,
148static int direct_is_left_mergeable (struct reiserfs_key * key, unsigned long bsize) 138 unsigned long bsize)
149{ 139{
150 int version = le_key_version (key); 140 int version = le_key_version(key);
151 return ((le_key_k_offset (version, key) & (bsize - 1)) != 1); 141 return ((le_key_k_offset(version, key) & (bsize - 1)) != 1);
152} 142}
153 143
154 144static void direct_print_item(struct item_head *ih, char *item)
155static void direct_print_item (struct item_head * ih, char * item)
156{ 145{
157 int j = 0; 146 int j = 0;
158 147
159// return; 148// return;
160 printk ("\""); 149 printk("\"");
161 while (j < ih_item_len(ih)) 150 while (j < ih_item_len(ih))
162 printk ("%c", item[j++]); 151 printk("%c", item[j++]);
163 printk ("\"\n"); 152 printk("\"\n");
164} 153}
165 154
166 155static void direct_check_item(struct item_head *ih, char *item)
167static void direct_check_item (struct item_head * ih, char * item)
168{ 156{
169 // FIXME: type something here! 157 // FIXME: type something here!
170} 158}
171 159
172 160static int direct_create_vi(struct virtual_node *vn,
173static int direct_create_vi (struct virtual_node * vn, 161 struct virtual_item *vi,
174 struct virtual_item * vi, 162 int is_affected, int insert_size)
175 int is_affected,
176 int insert_size)
177{ 163{
178 vi->vi_index = TYPE_DIRECT; 164 vi->vi_index = TYPE_DIRECT;
179 //vi->vi_type |= VI_TYPE_DIRECT; 165 //vi->vi_type |= VI_TYPE_DIRECT;
180 return 0; 166 return 0;
181} 167}
182 168
183static int direct_check_left (struct virtual_item * vi, int free, 169static int direct_check_left(struct virtual_item *vi, int free,
184 int start_skip, int end_skip) 170 int start_skip, int end_skip)
185{ 171{
186 int bytes; 172 int bytes;
187 173
188 bytes = free - free % 8; 174 bytes = free - free % 8;
189 return bytes ?: -1; 175 return bytes ? : -1;
190} 176}
191 177
192 178static int direct_check_right(struct virtual_item *vi, int free)
193static int direct_check_right (struct virtual_item * vi, int free)
194{ 179{
195 return direct_check_left (vi, free, 0, 0); 180 return direct_check_left(vi, free, 0, 0);
196} 181}
197 182
198static int direct_part_size (struct virtual_item * vi, int first, int count) 183static int direct_part_size(struct virtual_item *vi, int first, int count)
199{ 184{
200 return count; 185 return count;
201} 186}
202 187
203 188static int direct_unit_num(struct virtual_item *vi)
204static int direct_unit_num (struct virtual_item * vi)
205{ 189{
206 return vi->vi_item_len - IH_SIZE; 190 return vi->vi_item_len - IH_SIZE;
207} 191}
208 192
209 193static void direct_print_vi(struct virtual_item *vi)
210static void direct_print_vi (struct virtual_item * vi)
211{ 194{
212 reiserfs_warning (NULL, "DIRECT, index %d, type 0x%x, %h", 195 reiserfs_warning(NULL, "DIRECT, index %d, type 0x%x, %h",
213 vi->vi_index, vi->vi_type, vi->vi_ih); 196 vi->vi_index, vi->vi_type, vi->vi_ih);
214} 197}
215 198
216static struct item_operations direct_ops = { 199static struct item_operations direct_ops = {
217 .bytes_number = direct_bytes_number, 200 .bytes_number = direct_bytes_number,
218 .decrement_key = direct_decrement_key, 201 .decrement_key = direct_decrement_key,
219 .is_left_mergeable = direct_is_left_mergeable, 202 .is_left_mergeable = direct_is_left_mergeable,
220 .print_item = direct_print_item, 203 .print_item = direct_print_item,
221 .check_item = direct_check_item, 204 .check_item = direct_check_item,
222 205
223 .create_vi = direct_create_vi, 206 .create_vi = direct_create_vi,
224 .check_left = direct_check_left, 207 .check_left = direct_check_left,
225 .check_right = direct_check_right, 208 .check_right = direct_check_right,
226 .part_size = direct_part_size, 209 .part_size = direct_part_size,
227 .unit_num = direct_unit_num, 210 .unit_num = direct_unit_num,
228 .print_vi = direct_print_vi 211 .print_vi = direct_print_vi
229}; 212};
230 213
231
232
233////////////////////////////////////////////////////////////////////////////// 214//////////////////////////////////////////////////////////////////////////////
234// indirect item functions 215// indirect item functions
235// 216//
236 217
237static int indirect_bytes_number (struct item_head * ih, int block_size) 218static int indirect_bytes_number(struct item_head *ih, int block_size)
238{ 219{
239 return ih_item_len(ih) / UNFM_P_SIZE * block_size; //- get_ih_free_space (ih); 220 return ih_item_len(ih) / UNFM_P_SIZE * block_size; //- get_ih_free_space (ih);
240} 221}
241 222
242
243// decrease offset, if it becomes 0, change type to stat data 223// decrease offset, if it becomes 0, change type to stat data
244static void indirect_decrement_key (struct cpu_key * key) 224static void indirect_decrement_key(struct cpu_key *key)
245{ 225{
246 cpu_key_k_offset_dec (key); 226 cpu_key_k_offset_dec(key);
247 if (cpu_key_k_offset (key) == 0) 227 if (cpu_key_k_offset(key) == 0)
248 set_cpu_key_k_type (key, TYPE_STAT_DATA); 228 set_cpu_key_k_type(key, TYPE_STAT_DATA);
249} 229}
250 230
251
252// if it is not first item of the body, then it is mergeable 231// if it is not first item of the body, then it is mergeable
253static int indirect_is_left_mergeable (struct reiserfs_key * key, unsigned long bsize) 232static int indirect_is_left_mergeable(struct reiserfs_key *key,
233 unsigned long bsize)
254{ 234{
255 int version = le_key_version (key); 235 int version = le_key_version(key);
256 return (le_key_k_offset (version, key) != 1); 236 return (le_key_k_offset(version, key) != 1);
257} 237}
258 238
259
260// printing of indirect item 239// printing of indirect item
261static void start_new_sequence (__u32 * start, int * len, __u32 new) 240static void start_new_sequence(__u32 * start, int *len, __u32 new)
262{ 241{
263 *start = new; 242 *start = new;
264 *len = 1; 243 *len = 1;
265} 244}
266 245
267 246static int sequence_finished(__u32 start, int *len, __u32 new)
268static int sequence_finished (__u32 start, int * len, __u32 new)
269{ 247{
270 if (start == INT_MAX) 248 if (start == INT_MAX)
271 return 1; 249 return 1;
272 250
273 if (start == 0 && new == 0) { 251 if (start == 0 && new == 0) {
274 (*len) ++; 252 (*len)++;
275 return 0; 253 return 0;
276 } 254 }
277 if (start != 0 && (start + *len) == new) { 255 if (start != 0 && (start + *len) == new) {
278 (*len) ++; 256 (*len)++;
279 return 0; 257 return 0;
280 } 258 }
281 return 1; 259 return 1;
282} 260}
283 261
284static void print_sequence (__u32 start, int len) 262static void print_sequence(__u32 start, int len)
285{ 263{
286 if (start == INT_MAX) 264 if (start == INT_MAX)
287 return; 265 return;
288 266
289 if (len == 1) 267 if (len == 1)
290 printk (" %d", start); 268 printk(" %d", start);
291 else 269 else
292 printk (" %d(%d)", start, len); 270 printk(" %d(%d)", start, len);
293} 271}
294 272
295 273static void indirect_print_item(struct item_head *ih, char *item)
296static void indirect_print_item (struct item_head * ih, char * item)
297{ 274{
298 int j; 275 int j;
299 __le32 * unp; 276 __le32 *unp;
300 __u32 prev = INT_MAX; 277 __u32 prev = INT_MAX;
301 int num; 278 int num;
302 279
303 unp = (__le32 *)item; 280 unp = (__le32 *) item;
304 281
305 if (ih_item_len(ih) % UNFM_P_SIZE) 282 if (ih_item_len(ih) % UNFM_P_SIZE)
306 reiserfs_warning (NULL, "indirect_print_item: invalid item len"); 283 reiserfs_warning(NULL, "indirect_print_item: invalid item len");
307 284
308 printk ("%d pointers\n[ ", (int)I_UNFM_NUM (ih)); 285 printk("%d pointers\n[ ", (int)I_UNFM_NUM(ih));
309 for (j = 0; j < I_UNFM_NUM (ih); j ++) { 286 for (j = 0; j < I_UNFM_NUM(ih); j++) {
310 if (sequence_finished (prev, &num, get_block_num(unp, j))) { 287 if (sequence_finished(prev, &num, get_block_num(unp, j))) {
311 print_sequence (prev, num); 288 print_sequence(prev, num);
312 start_new_sequence (&prev, &num, get_block_num(unp, j)); 289 start_new_sequence(&prev, &num, get_block_num(unp, j));
290 }
313 } 291 }
314 } 292 print_sequence(prev, num);
315 print_sequence (prev, num); 293 printk("]\n");
316 printk ("]\n");
317} 294}
318 295
319static void indirect_check_item (struct item_head * ih, char * item) 296static void indirect_check_item(struct item_head *ih, char *item)
320{ 297{
321 // FIXME: type something here! 298 // FIXME: type something here!
322} 299}
323 300
324 301static int indirect_create_vi(struct virtual_node *vn,
325static int indirect_create_vi (struct virtual_node * vn, 302 struct virtual_item *vi,
326 struct virtual_item * vi, 303 int is_affected, int insert_size)
327 int is_affected,
328 int insert_size)
329{ 304{
330 vi->vi_index = TYPE_INDIRECT; 305 vi->vi_index = TYPE_INDIRECT;
331 //vi->vi_type |= VI_TYPE_INDIRECT; 306 //vi->vi_type |= VI_TYPE_INDIRECT;
332 return 0; 307 return 0;
333} 308}
334 309
335static int indirect_check_left (struct virtual_item * vi, int free, 310static int indirect_check_left(struct virtual_item *vi, int free,
336 int start_skip, int end_skip) 311 int start_skip, int end_skip)
337{ 312{
338 int bytes; 313 int bytes;
339 314
340 bytes = free - free % UNFM_P_SIZE; 315 bytes = free - free % UNFM_P_SIZE;
341 return bytes ?: -1; 316 return bytes ? : -1;
342} 317}
343 318
344 319static int indirect_check_right(struct virtual_item *vi, int free)
345static int indirect_check_right (struct virtual_item * vi, int free)
346{ 320{
347 return indirect_check_left (vi, free, 0, 0); 321 return indirect_check_left(vi, free, 0, 0);
348} 322}
349 323
350
351
352// return size in bytes of 'units' units. If first == 0 - calculate from the head (left), otherwise - from tail (right) 324// return size in bytes of 'units' units. If first == 0 - calculate from the head (left), otherwise - from tail (right)
353static int indirect_part_size (struct virtual_item * vi, int first, int units) 325static int indirect_part_size(struct virtual_item *vi, int first, int units)
354{ 326{
355 // unit of indirect item is byte (yet) 327 // unit of indirect item is byte (yet)
356 return units; 328 return units;
357} 329}
358 330
359static int indirect_unit_num (struct virtual_item * vi) 331static int indirect_unit_num(struct virtual_item *vi)
360{ 332{
361 // unit of indirect item is byte (yet) 333 // unit of indirect item is byte (yet)
362 return vi->vi_item_len - IH_SIZE; 334 return vi->vi_item_len - IH_SIZE;
363} 335}
364 336
365static void indirect_print_vi (struct virtual_item * vi) 337static void indirect_print_vi(struct virtual_item *vi)
366{ 338{
367 reiserfs_warning (NULL, "INDIRECT, index %d, type 0x%x, %h", 339 reiserfs_warning(NULL, "INDIRECT, index %d, type 0x%x, %h",
368 vi->vi_index, vi->vi_type, vi->vi_ih); 340 vi->vi_index, vi->vi_type, vi->vi_ih);
369} 341}
370 342
371static struct item_operations indirect_ops = { 343static struct item_operations indirect_ops = {
372 .bytes_number = indirect_bytes_number, 344 .bytes_number = indirect_bytes_number,
373 .decrement_key = indirect_decrement_key, 345 .decrement_key = indirect_decrement_key,
374 .is_left_mergeable = indirect_is_left_mergeable, 346 .is_left_mergeable = indirect_is_left_mergeable,
375 .print_item = indirect_print_item, 347 .print_item = indirect_print_item,
376 .check_item = indirect_check_item, 348 .check_item = indirect_check_item,
377 349
378 .create_vi = indirect_create_vi, 350 .create_vi = indirect_create_vi,
379 .check_left = indirect_check_left, 351 .check_left = indirect_check_left,
380 .check_right = indirect_check_right, 352 .check_right = indirect_check_right,
381 .part_size = indirect_part_size, 353 .part_size = indirect_part_size,
382 .unit_num = indirect_unit_num, 354 .unit_num = indirect_unit_num,
383 .print_vi = indirect_print_vi 355 .print_vi = indirect_print_vi
384}; 356};
385 357
386
387////////////////////////////////////////////////////////////////////////////// 358//////////////////////////////////////////////////////////////////////////////
388// direntry functions 359// direntry functions
389// 360//
390 361
391 362static int direntry_bytes_number(struct item_head *ih, int block_size)
392static int direntry_bytes_number (struct item_head * ih, int block_size)
393{ 363{
394 reiserfs_warning (NULL, "vs-16090: direntry_bytes_number: " 364 reiserfs_warning(NULL, "vs-16090: direntry_bytes_number: "
395 "bytes number is asked for direntry"); 365 "bytes number is asked for direntry");
396 return 0; 366 return 0;
397}
398
399static void direntry_decrement_key (struct cpu_key * key)
400{
401 cpu_key_k_offset_dec (key);
402 if (cpu_key_k_offset (key) == 0)
403 set_cpu_key_k_type (key, TYPE_STAT_DATA);
404} 367}
405 368
406 369static void direntry_decrement_key(struct cpu_key *key)
407static int direntry_is_left_mergeable (struct reiserfs_key * key, unsigned long bsize)
408{ 370{
409 if (le32_to_cpu (key->u.k_offset_v1.k_offset) == DOT_OFFSET) 371 cpu_key_k_offset_dec(key);
410 return 0; 372 if (cpu_key_k_offset(key) == 0)
411 return 1; 373 set_cpu_key_k_type(key, TYPE_STAT_DATA);
412
413} 374}
414 375
415 376static int direntry_is_left_mergeable(struct reiserfs_key *key,
416static void direntry_print_item (struct item_head * ih, char * item) 377 unsigned long bsize)
417{ 378{
418 int i; 379 if (le32_to_cpu(key->u.k_offset_v1.k_offset) == DOT_OFFSET)
419 int namelen; 380 return 0;
420 struct reiserfs_de_head * deh; 381 return 1;
421 char * name;
422 static char namebuf [80];
423
424
425 printk ("\n # %-15s%-30s%-15s%-15s%-15s\n", "Name", "Key of pointed object", "Hash", "Gen number", "Status");
426 382
427 deh = (struct reiserfs_de_head *)item; 383}
428 384
429 for (i = 0; i < I_ENTRY_COUNT (ih); i ++, deh ++) { 385static void direntry_print_item(struct item_head *ih, char *item)
430 namelen = (i ? (deh_location(deh - 1)) : ih_item_len(ih)) - deh_location(deh); 386{
431 name = item + deh_location(deh); 387 int i;
432 if (name[namelen-1] == 0) 388 int namelen;
433 namelen = strlen (name); 389 struct reiserfs_de_head *deh;
434 namebuf[0] = '"'; 390 char *name;
435 if (namelen > sizeof (namebuf) - 3) { 391 static char namebuf[80];
436 strncpy (namebuf + 1, name, sizeof (namebuf) - 3); 392
437 namebuf[sizeof (namebuf) - 2] = '"'; 393 printk("\n # %-15s%-30s%-15s%-15s%-15s\n", "Name",
438 namebuf[sizeof (namebuf) - 1] = 0; 394 "Key of pointed object", "Hash", "Gen number", "Status");
439 } else { 395
440 memcpy (namebuf + 1, name, namelen); 396 deh = (struct reiserfs_de_head *)item;
441 namebuf[namelen + 1] = '"'; 397
442 namebuf[namelen + 2] = 0; 398 for (i = 0; i < I_ENTRY_COUNT(ih); i++, deh++) {
399 namelen =
400 (i ? (deh_location(deh - 1)) : ih_item_len(ih)) -
401 deh_location(deh);
402 name = item + deh_location(deh);
403 if (name[namelen - 1] == 0)
404 namelen = strlen(name);
405 namebuf[0] = '"';
406 if (namelen > sizeof(namebuf) - 3) {
407 strncpy(namebuf + 1, name, sizeof(namebuf) - 3);
408 namebuf[sizeof(namebuf) - 2] = '"';
409 namebuf[sizeof(namebuf) - 1] = 0;
410 } else {
411 memcpy(namebuf + 1, name, namelen);
412 namebuf[namelen + 1] = '"';
413 namebuf[namelen + 2] = 0;
414 }
415
416 printk("%d: %-15s%-15d%-15d%-15Ld%-15Ld(%s)\n",
417 i, namebuf,
418 deh_dir_id(deh), deh_objectid(deh),
419 GET_HASH_VALUE(deh_offset(deh)),
420 GET_GENERATION_NUMBER((deh_offset(deh))),
421 (de_hidden(deh)) ? "HIDDEN" : "VISIBLE");
443 } 422 }
444
445 printk ("%d: %-15s%-15d%-15d%-15Ld%-15Ld(%s)\n",
446 i, namebuf,
447 deh_dir_id(deh), deh_objectid(deh),
448 GET_HASH_VALUE (deh_offset (deh)), GET_GENERATION_NUMBER ((deh_offset (deh))),
449 (de_hidden (deh)) ? "HIDDEN" : "VISIBLE");
450 }
451} 423}
452 424
453 425static void direntry_check_item(struct item_head *ih, char *item)
454static void direntry_check_item (struct item_head * ih, char * item)
455{ 426{
456 int i; 427 int i;
457 struct reiserfs_de_head * deh; 428 struct reiserfs_de_head *deh;
458 429
459 // FIXME: type something here! 430 // FIXME: type something here!
460 deh = (struct reiserfs_de_head *)item; 431 deh = (struct reiserfs_de_head *)item;
461 for (i = 0; i < I_ENTRY_COUNT (ih); i ++, deh ++) { 432 for (i = 0; i < I_ENTRY_COUNT(ih); i++, deh++) {
462 ; 433 ;
463 } 434 }
464} 435}
465 436
466
467
468#define DIRENTRY_VI_FIRST_DIRENTRY_ITEM 1 437#define DIRENTRY_VI_FIRST_DIRENTRY_ITEM 1
469 438
470/* 439/*
471 * function returns old entry number in directory item in real node 440 * function returns old entry number in directory item in real node
472 * using new entry number in virtual item in virtual node */ 441 * using new entry number in virtual item in virtual node */
473static inline int old_entry_num (int is_affected, int virtual_entry_num, int pos_in_item, int mode) 442static inline int old_entry_num(int is_affected, int virtual_entry_num,
443 int pos_in_item, int mode)
474{ 444{
475 if ( mode == M_INSERT || mode == M_DELETE) 445 if (mode == M_INSERT || mode == M_DELETE)
476 return virtual_entry_num; 446 return virtual_entry_num;
477
478 if (!is_affected)
479 /* cut or paste is applied to another item */
480 return virtual_entry_num;
481
482 if (virtual_entry_num < pos_in_item)
483 return virtual_entry_num;
484 447
485 if (mode == M_CUT) 448 if (!is_affected)
486 return virtual_entry_num + 1; 449 /* cut or paste is applied to another item */
450 return virtual_entry_num;
487 451
488 RFALSE( mode != M_PASTE || virtual_entry_num == 0, 452 if (virtual_entry_num < pos_in_item)
489 "vs-8015: old_entry_num: mode must be M_PASTE (mode = \'%c\'", mode); 453 return virtual_entry_num;
490
491 return virtual_entry_num - 1;
492}
493 454
455 if (mode == M_CUT)
456 return virtual_entry_num + 1;
494 457
458 RFALSE(mode != M_PASTE || virtual_entry_num == 0,
459 "vs-8015: old_entry_num: mode must be M_PASTE (mode = \'%c\'",
460 mode);
495 461
462 return virtual_entry_num - 1;
463}
496 464
497/* Create an array of sizes of directory entries for virtual 465/* Create an array of sizes of directory entries for virtual
498 item. Return space used by an item. FIXME: no control over 466 item. Return space used by an item. FIXME: no control over
499 consuming of space used by this item handler */ 467 consuming of space used by this item handler */
500static int direntry_create_vi (struct virtual_node * vn, 468static int direntry_create_vi(struct virtual_node *vn,
501 struct virtual_item * vi, 469 struct virtual_item *vi,
502 int is_affected, 470 int is_affected, int insert_size)
503 int insert_size) 471{
504{ 472 struct direntry_uarea *dir_u = vi->vi_uarea;
505 struct direntry_uarea * dir_u = vi->vi_uarea; 473 int i, j;
506 int i, j; 474 int size = sizeof(struct direntry_uarea);
507 int size = sizeof (struct direntry_uarea); 475 struct reiserfs_de_head *deh;
508 struct reiserfs_de_head * deh;
509
510 vi->vi_index = TYPE_DIRENTRY;
511
512 if (!(vi->vi_ih) || !vi->vi_item)
513 BUG ();
514
515
516 dir_u->flags = 0;
517 if (le_ih_k_offset (vi->vi_ih) == DOT_OFFSET)
518 dir_u->flags |= DIRENTRY_VI_FIRST_DIRENTRY_ITEM;
519
520 deh = (struct reiserfs_de_head *)(vi->vi_item);
521
522
523 /* virtual directory item have this amount of entry after */
524 dir_u->entry_count = ih_entry_count (vi->vi_ih) +
525 ((is_affected) ? ((vn->vn_mode == M_CUT) ? -1 :
526 (vn->vn_mode == M_PASTE ? 1 : 0)) : 0);
527
528 for (i = 0; i < dir_u->entry_count; i ++) {
529 j = old_entry_num (is_affected, i, vn->vn_pos_in_item, vn->vn_mode);
530 dir_u->entry_sizes[i] = (j ? deh_location( &(deh[j - 1]) ) :
531 ih_item_len (vi->vi_ih)) -
532 deh_location( &(deh[j])) + DEH_SIZE;
533 }
534
535 size += (dir_u->entry_count * sizeof (short));
536
537 /* set size of pasted entry */
538 if (is_affected && vn->vn_mode == M_PASTE)
539 dir_u->entry_sizes[vn->vn_pos_in_item] = insert_size;
540 476
477 vi->vi_index = TYPE_DIRENTRY;
478
479 if (!(vi->vi_ih) || !vi->vi_item)
480 BUG();
481
482 dir_u->flags = 0;
483 if (le_ih_k_offset(vi->vi_ih) == DOT_OFFSET)
484 dir_u->flags |= DIRENTRY_VI_FIRST_DIRENTRY_ITEM;
485
486 deh = (struct reiserfs_de_head *)(vi->vi_item);
487
488 /* virtual directory item have this amount of entry after */
489 dir_u->entry_count = ih_entry_count(vi->vi_ih) +
490 ((is_affected) ? ((vn->vn_mode == M_CUT) ? -1 :
491 (vn->vn_mode == M_PASTE ? 1 : 0)) : 0);
492
493 for (i = 0; i < dir_u->entry_count; i++) {
494 j = old_entry_num(is_affected, i, vn->vn_pos_in_item,
495 vn->vn_mode);
496 dir_u->entry_sizes[i] =
497 (j ? deh_location(&(deh[j - 1])) : ih_item_len(vi->vi_ih)) -
498 deh_location(&(deh[j])) + DEH_SIZE;
499 }
500
501 size += (dir_u->entry_count * sizeof(short));
502
503 /* set size of pasted entry */
504 if (is_affected && vn->vn_mode == M_PASTE)
505 dir_u->entry_sizes[vn->vn_pos_in_item] = insert_size;
541 506
542#ifdef CONFIG_REISERFS_CHECK 507#ifdef CONFIG_REISERFS_CHECK
543 /* compare total size of entries with item length */ 508 /* compare total size of entries with item length */
544 { 509 {
545 int k, l; 510 int k, l;
546 511
547 l = 0; 512 l = 0;
548 for (k = 0; k < dir_u->entry_count; k ++) 513 for (k = 0; k < dir_u->entry_count; k++)
549 l += dir_u->entry_sizes[k]; 514 l += dir_u->entry_sizes[k];
550 515
551 if (l + IH_SIZE != vi->vi_item_len + 516 if (l + IH_SIZE != vi->vi_item_len +
552 ((is_affected && (vn->vn_mode == M_PASTE || vn->vn_mode == M_CUT)) ? insert_size : 0) ) { 517 ((is_affected
553 reiserfs_panic (NULL, "vs-8025: set_entry_sizes: (mode==%c, insert_size==%d), invalid length of directory item", 518 && (vn->vn_mode == M_PASTE
554 vn->vn_mode, insert_size); 519 || vn->vn_mode == M_CUT)) ? insert_size : 0)) {
520 reiserfs_panic(NULL,
521 "vs-8025: set_entry_sizes: (mode==%c, insert_size==%d), invalid length of directory item",
522 vn->vn_mode, insert_size);
523 }
555 } 524 }
556 }
557#endif 525#endif
558 526
559 return size; 527 return size;
560
561 528
562} 529}
563 530
564
565// 531//
566// return number of entries which may fit into specified amount of 532// return number of entries which may fit into specified amount of
567// free space, or -1 if free space is not enough even for 1 entry 533// free space, or -1 if free space is not enough even for 1 entry
568// 534//
569static int direntry_check_left (struct virtual_item * vi, int free, 535static int direntry_check_left(struct virtual_item *vi, int free,
570 int start_skip, int end_skip) 536 int start_skip, int end_skip)
571{ 537{
572 int i; 538 int i;
573 int entries = 0; 539 int entries = 0;
574 struct direntry_uarea * dir_u = vi->vi_uarea; 540 struct direntry_uarea *dir_u = vi->vi_uarea;
575 541
576 for (i = start_skip; i < dir_u->entry_count - end_skip; i ++) { 542 for (i = start_skip; i < dir_u->entry_count - end_skip; i++) {
577 if (dir_u->entry_sizes[i] > free) 543 if (dir_u->entry_sizes[i] > free)
578 /* i-th entry doesn't fit into the remaining free space */ 544 /* i-th entry doesn't fit into the remaining free space */
579 break; 545 break;
580
581 free -= dir_u->entry_sizes[i];
582 entries ++;
583 }
584 546
585 if (entries == dir_u->entry_count) { 547 free -= dir_u->entry_sizes[i];
586 reiserfs_panic (NULL, "free space %d, entry_count %d\n", free, dir_u->entry_count); 548 entries++;
587 } 549 }
588 550
589 /* "." and ".." can not be separated from each other */ 551 if (entries == dir_u->entry_count) {
590 if (start_skip == 0 && (dir_u->flags & DIRENTRY_VI_FIRST_DIRENTRY_ITEM) && entries < 2) 552 reiserfs_panic(NULL, "free space %d, entry_count %d\n", free,
591 entries = 0; 553 dir_u->entry_count);
592 554 }
593 return entries ?: -1;
594}
595 555
556 /* "." and ".." can not be separated from each other */
557 if (start_skip == 0 && (dir_u->flags & DIRENTRY_VI_FIRST_DIRENTRY_ITEM)
558 && entries < 2)
559 entries = 0;
596 560
597static int direntry_check_right (struct virtual_item * vi, int free) 561 return entries ? : -1;
562}
563
564static int direntry_check_right(struct virtual_item *vi, int free)
598{ 565{
599 int i; 566 int i;
600 int entries = 0; 567 int entries = 0;
601 struct direntry_uarea * dir_u = vi->vi_uarea; 568 struct direntry_uarea *dir_u = vi->vi_uarea;
602
603 for (i = dir_u->entry_count - 1; i >= 0; i --) {
604 if (dir_u->entry_sizes[i] > free)
605 /* i-th entry doesn't fit into the remaining free space */
606 break;
607
608 free -= dir_u->entry_sizes[i];
609 entries ++;
610 }
611 if (entries == dir_u->entry_count)
612 BUG ();
613 569
614 /* "." and ".." can not be separated from each other */ 570 for (i = dir_u->entry_count - 1; i >= 0; i--) {
615 if ((dir_u->flags & DIRENTRY_VI_FIRST_DIRENTRY_ITEM) && entries > dir_u->entry_count - 2) 571 if (dir_u->entry_sizes[i] > free)
616 entries = dir_u->entry_count - 2; 572 /* i-th entry doesn't fit into the remaining free space */
573 break;
617 574
618 return entries ?: -1; 575 free -= dir_u->entry_sizes[i];
619} 576 entries++;
577 }
578 if (entries == dir_u->entry_count)
579 BUG();
620 580
581 /* "." and ".." can not be separated from each other */
582 if ((dir_u->flags & DIRENTRY_VI_FIRST_DIRENTRY_ITEM)
583 && entries > dir_u->entry_count - 2)
584 entries = dir_u->entry_count - 2;
585
586 return entries ? : -1;
587}
621 588
622/* sum of entry sizes between from-th and to-th entries including both edges */ 589/* sum of entry sizes between from-th and to-th entries including both edges */
623static int direntry_part_size (struct virtual_item * vi, int first, int count) 590static int direntry_part_size(struct virtual_item *vi, int first, int count)
624{ 591{
625 int i, retval; 592 int i, retval;
626 int from, to; 593 int from, to;
627 struct direntry_uarea * dir_u = vi->vi_uarea; 594 struct direntry_uarea *dir_u = vi->vi_uarea;
628
629 retval = 0;
630 if (first == 0)
631 from = 0;
632 else
633 from = dir_u->entry_count - count;
634 to = from + count - 1;
635 595
636 for (i = from; i <= to; i ++) 596 retval = 0;
637 retval += dir_u->entry_sizes[i]; 597 if (first == 0)
598 from = 0;
599 else
600 from = dir_u->entry_count - count;
601 to = from + count - 1;
638 602
639 return retval; 603 for (i = from; i <= to; i++)
640} 604 retval += dir_u->entry_sizes[i];
641 605
642static int direntry_unit_num (struct virtual_item * vi) 606 return retval;
643{
644 struct direntry_uarea * dir_u = vi->vi_uarea;
645
646 return dir_u->entry_count;
647} 607}
648 608
609static int direntry_unit_num(struct virtual_item *vi)
610{
611 struct direntry_uarea *dir_u = vi->vi_uarea;
649 612
613 return dir_u->entry_count;
614}
650 615
651static void direntry_print_vi (struct virtual_item * vi) 616static void direntry_print_vi(struct virtual_item *vi)
652{ 617{
653 int i; 618 int i;
654 struct direntry_uarea * dir_u = vi->vi_uarea; 619 struct direntry_uarea *dir_u = vi->vi_uarea;
655 620
656 reiserfs_warning (NULL, "DIRENTRY, index %d, type 0x%x, %h, flags 0x%x", 621 reiserfs_warning(NULL, "DIRENTRY, index %d, type 0x%x, %h, flags 0x%x",
657 vi->vi_index, vi->vi_type, vi->vi_ih, dir_u->flags); 622 vi->vi_index, vi->vi_type, vi->vi_ih, dir_u->flags);
658 printk ("%d entries: ", dir_u->entry_count); 623 printk("%d entries: ", dir_u->entry_count);
659 for (i = 0; i < dir_u->entry_count; i ++) 624 for (i = 0; i < dir_u->entry_count; i++)
660 printk ("%d ", dir_u->entry_sizes[i]); 625 printk("%d ", dir_u->entry_sizes[i]);
661 printk ("\n"); 626 printk("\n");
662} 627}
663 628
664static struct item_operations direntry_ops = { 629static struct item_operations direntry_ops = {
665 .bytes_number = direntry_bytes_number, 630 .bytes_number = direntry_bytes_number,
666 .decrement_key = direntry_decrement_key, 631 .decrement_key = direntry_decrement_key,
667 .is_left_mergeable = direntry_is_left_mergeable, 632 .is_left_mergeable = direntry_is_left_mergeable,
668 .print_item = direntry_print_item, 633 .print_item = direntry_print_item,
669 .check_item = direntry_check_item, 634 .check_item = direntry_check_item,
670 635
671 .create_vi = direntry_create_vi, 636 .create_vi = direntry_create_vi,
672 .check_left = direntry_check_left, 637 .check_left = direntry_check_left,
673 .check_right = direntry_check_right, 638 .check_right = direntry_check_right,
674 .part_size = direntry_part_size, 639 .part_size = direntry_part_size,
675 .unit_num = direntry_unit_num, 640 .unit_num = direntry_unit_num,
676 .print_vi = direntry_print_vi 641 .print_vi = direntry_print_vi
677}; 642};
678 643
679
680////////////////////////////////////////////////////////////////////////////// 644//////////////////////////////////////////////////////////////////////////////
681// Error catching functions to catch errors caused by incorrect item types. 645// Error catching functions to catch errors caused by incorrect item types.
682// 646//
683static int errcatch_bytes_number (struct item_head * ih, int block_size) 647static int errcatch_bytes_number(struct item_head *ih, int block_size)
684{ 648{
685 reiserfs_warning (NULL, "green-16001: Invalid item type observed, run fsck ASAP"); 649 reiserfs_warning(NULL,
686 return 0; 650 "green-16001: Invalid item type observed, run fsck ASAP");
651 return 0;
687} 652}
688 653
689static void errcatch_decrement_key (struct cpu_key * key) 654static void errcatch_decrement_key(struct cpu_key *key)
690{ 655{
691 reiserfs_warning (NULL, "green-16002: Invalid item type observed, run fsck ASAP"); 656 reiserfs_warning(NULL,
657 "green-16002: Invalid item type observed, run fsck ASAP");
692} 658}
693 659
694 660static int errcatch_is_left_mergeable(struct reiserfs_key *key,
695static int errcatch_is_left_mergeable (struct reiserfs_key * key, unsigned long bsize) 661 unsigned long bsize)
696{ 662{
697 reiserfs_warning (NULL, "green-16003: Invalid item type observed, run fsck ASAP"); 663 reiserfs_warning(NULL,
698 return 0; 664 "green-16003: Invalid item type observed, run fsck ASAP");
665 return 0;
699} 666}
700 667
701 668static void errcatch_print_item(struct item_head *ih, char *item)
702static void errcatch_print_item (struct item_head * ih, char * item)
703{ 669{
704 reiserfs_warning (NULL, "green-16004: Invalid item type observed, run fsck ASAP"); 670 reiserfs_warning(NULL,
671 "green-16004: Invalid item type observed, run fsck ASAP");
705} 672}
706 673
707 674static void errcatch_check_item(struct item_head *ih, char *item)
708static void errcatch_check_item (struct item_head * ih, char * item)
709{ 675{
710 reiserfs_warning (NULL, "green-16005: Invalid item type observed, run fsck ASAP"); 676 reiserfs_warning(NULL,
677 "green-16005: Invalid item type observed, run fsck ASAP");
711} 678}
712 679
713static int errcatch_create_vi (struct virtual_node * vn, 680static int errcatch_create_vi(struct virtual_node *vn,
714 struct virtual_item * vi, 681 struct virtual_item *vi,
715 int is_affected, 682 int is_affected, int insert_size)
716 int insert_size)
717{ 683{
718 reiserfs_warning (NULL, "green-16006: Invalid item type observed, run fsck ASAP"); 684 reiserfs_warning(NULL,
719 return 0; // We might return -1 here as well, but it won't help as create_virtual_node() from where 685 "green-16006: Invalid item type observed, run fsck ASAP");
720 // this operation is called from is of return type void. 686 return 0; // We might return -1 here as well, but it won't help as create_virtual_node() from where
687 // this operation is called from is of return type void.
721} 688}
722 689
723static int errcatch_check_left (struct virtual_item * vi, int free, 690static int errcatch_check_left(struct virtual_item *vi, int free,
724 int start_skip, int end_skip) 691 int start_skip, int end_skip)
725{ 692{
726 reiserfs_warning (NULL, "green-16007: Invalid item type observed, run fsck ASAP"); 693 reiserfs_warning(NULL,
727 return -1; 694 "green-16007: Invalid item type observed, run fsck ASAP");
695 return -1;
728} 696}
729 697
730 698static int errcatch_check_right(struct virtual_item *vi, int free)
731static int errcatch_check_right (struct virtual_item * vi, int free)
732{ 699{
733 reiserfs_warning (NULL, "green-16008: Invalid item type observed, run fsck ASAP"); 700 reiserfs_warning(NULL,
734 return -1; 701 "green-16008: Invalid item type observed, run fsck ASAP");
702 return -1;
735} 703}
736 704
737static int errcatch_part_size (struct virtual_item * vi, int first, int count) 705static int errcatch_part_size(struct virtual_item *vi, int first, int count)
738{ 706{
739 reiserfs_warning (NULL, "green-16009: Invalid item type observed, run fsck ASAP"); 707 reiserfs_warning(NULL,
740 return 0; 708 "green-16009: Invalid item type observed, run fsck ASAP");
709 return 0;
741} 710}
742 711
743static int errcatch_unit_num (struct virtual_item * vi) 712static int errcatch_unit_num(struct virtual_item *vi)
744{ 713{
745 reiserfs_warning (NULL, "green-16010: Invalid item type observed, run fsck ASAP"); 714 reiserfs_warning(NULL,
746 return 0; 715 "green-16010: Invalid item type observed, run fsck ASAP");
716 return 0;
747} 717}
748 718
749static void errcatch_print_vi (struct virtual_item * vi) 719static void errcatch_print_vi(struct virtual_item *vi)
750{ 720{
751 reiserfs_warning (NULL, "green-16011: Invalid item type observed, run fsck ASAP"); 721 reiserfs_warning(NULL,
722 "green-16011: Invalid item type observed, run fsck ASAP");
752} 723}
753 724
754static struct item_operations errcatch_ops = { 725static struct item_operations errcatch_ops = {
755 errcatch_bytes_number, 726 errcatch_bytes_number,
756 errcatch_decrement_key, 727 errcatch_decrement_key,
757 errcatch_is_left_mergeable, 728 errcatch_is_left_mergeable,
758 errcatch_print_item, 729 errcatch_print_item,
759 errcatch_check_item, 730 errcatch_check_item,
760 731
761 errcatch_create_vi, 732 errcatch_create_vi,
762 errcatch_check_left, 733 errcatch_check_left,
763 errcatch_check_right, 734 errcatch_check_right,
764 errcatch_part_size, 735 errcatch_part_size,
765 errcatch_unit_num, 736 errcatch_unit_num,
766 errcatch_print_vi 737 errcatch_print_vi
767}; 738};
768 739
769
770
771////////////////////////////////////////////////////////////////////////////// 740//////////////////////////////////////////////////////////////////////////////
772// 741//
773// 742//
774#if ! (TYPE_STAT_DATA == 0 && TYPE_INDIRECT == 1 && TYPE_DIRECT == 2 && TYPE_DIRENTRY == 3) 743#if ! (TYPE_STAT_DATA == 0 && TYPE_INDIRECT == 1 && TYPE_DIRECT == 2 && TYPE_DIRENTRY == 3)
775 do not compile 744#error Item types must use disk-format assigned values.
776#endif 745#endif
777 746
778struct item_operations * item_ops [TYPE_ANY + 1] = { 747struct item_operations *item_ops[TYPE_ANY + 1] = {
779 &stat_data_ops, 748 &stat_data_ops,
780 &indirect_ops, 749 &indirect_ops,
781 &direct_ops, 750 &direct_ops,
782 &direntry_ops, 751 &direntry_ops,
783 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 752 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
784 &errcatch_ops /* This is to catch errors with invalid type (15th entry for TYPE_ANY) */ 753 &errcatch_ops /* This is to catch errors with invalid type (15th entry for TYPE_ANY) */
785}; 754};
786
787
788
789
diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c
index d1bcf0da6728..c66c27ec4100 100644
--- a/fs/reiserfs/journal.c
+++ b/fs/reiserfs/journal.c
@@ -55,7 +55,6 @@
55#include <linux/writeback.h> 55#include <linux/writeback.h>
56#include <linux/blkdev.h> 56#include <linux/blkdev.h>
57 57
58
59/* gets a struct reiserfs_journal_list * from a list head */ 58/* gets a struct reiserfs_journal_list * from a list head */
60#define JOURNAL_LIST_ENTRY(h) (list_entry((h), struct reiserfs_journal_list, \ 59#define JOURNAL_LIST_ENTRY(h) (list_entry((h), struct reiserfs_journal_list, \
61 j_list)) 60 j_list))
@@ -69,55 +68,61 @@ static int reiserfs_mounted_fs_count;
69 68
70static struct workqueue_struct *commit_wq; 69static struct workqueue_struct *commit_wq;
71 70
72#define JOURNAL_TRANS_HALF 1018 /* must be correct to keep the desc and commit 71#define JOURNAL_TRANS_HALF 1018 /* must be correct to keep the desc and commit
73 structs at 4k */ 72 structs at 4k */
74#define BUFNR 64 /*read ahead */ 73#define BUFNR 64 /*read ahead */
75 74
76/* cnode stat bits. Move these into reiserfs_fs.h */ 75/* cnode stat bits. Move these into reiserfs_fs.h */
77 76
78#define BLOCK_FREED 2 /* this block was freed, and can't be written. */ 77#define BLOCK_FREED 2 /* this block was freed, and can't be written. */
79#define BLOCK_FREED_HOLDER 3 /* this block was freed during this transaction, and can't be written */ 78#define BLOCK_FREED_HOLDER 3 /* this block was freed during this transaction, and can't be written */
80 79
81#define BLOCK_NEEDS_FLUSH 4 /* used in flush_journal_list */ 80#define BLOCK_NEEDS_FLUSH 4 /* used in flush_journal_list */
82#define BLOCK_DIRTIED 5 81#define BLOCK_DIRTIED 5
83 82
84
85/* journal list state bits */ 83/* journal list state bits */
86#define LIST_TOUCHED 1 84#define LIST_TOUCHED 1
87#define LIST_DIRTY 2 85#define LIST_DIRTY 2
88#define LIST_COMMIT_PENDING 4 /* someone will commit this list */ 86#define LIST_COMMIT_PENDING 4 /* someone will commit this list */
89 87
90/* flags for do_journal_end */ 88/* flags for do_journal_end */
91#define FLUSH_ALL 1 /* flush commit and real blocks */ 89#define FLUSH_ALL 1 /* flush commit and real blocks */
92#define COMMIT_NOW 2 /* end and commit this transaction */ 90#define COMMIT_NOW 2 /* end and commit this transaction */
93#define WAIT 4 /* wait for the log blocks to hit the disk*/ 91#define WAIT 4 /* wait for the log blocks to hit the disk */
94 92
95static int do_journal_end(struct reiserfs_transaction_handle *,struct super_block *,unsigned long nblocks,int flags) ; 93static int do_journal_end(struct reiserfs_transaction_handle *,
96static int flush_journal_list(struct super_block *s, struct reiserfs_journal_list *jl, int flushall) ; 94 struct super_block *, unsigned long nblocks,
97static int flush_commit_list(struct super_block *s, struct reiserfs_journal_list *jl, int flushall) ; 95 int flags);
98static int can_dirty(struct reiserfs_journal_cnode *cn) ; 96static int flush_journal_list(struct super_block *s,
99static int journal_join(struct reiserfs_transaction_handle *th, struct super_block *p_s_sb, unsigned long nblocks); 97 struct reiserfs_journal_list *jl, int flushall);
100static int release_journal_dev( struct super_block *super, 98static int flush_commit_list(struct super_block *s,
101 struct reiserfs_journal *journal ); 99 struct reiserfs_journal_list *jl, int flushall);
100static int can_dirty(struct reiserfs_journal_cnode *cn);
101static int journal_join(struct reiserfs_transaction_handle *th,
102 struct super_block *p_s_sb, unsigned long nblocks);
103static int release_journal_dev(struct super_block *super,
104 struct reiserfs_journal *journal);
102static int dirty_one_transaction(struct super_block *s, 105static int dirty_one_transaction(struct super_block *s,
103 struct reiserfs_journal_list *jl); 106 struct reiserfs_journal_list *jl);
104static void flush_async_commits(void *p); 107static void flush_async_commits(void *p);
105static void queue_log_writer(struct super_block *s); 108static void queue_log_writer(struct super_block *s);
106 109
107/* values for join in do_journal_begin_r */ 110/* values for join in do_journal_begin_r */
108enum { 111enum {
109 JBEGIN_REG = 0, /* regular journal begin */ 112 JBEGIN_REG = 0, /* regular journal begin */
110 JBEGIN_JOIN = 1, /* join the running transaction if at all possible */ 113 JBEGIN_JOIN = 1, /* join the running transaction if at all possible */
111 JBEGIN_ABORT = 2, /* called from cleanup code, ignores aborted flag */ 114 JBEGIN_ABORT = 2, /* called from cleanup code, ignores aborted flag */
112}; 115};
113 116
114static int do_journal_begin_r(struct reiserfs_transaction_handle *th, 117static int do_journal_begin_r(struct reiserfs_transaction_handle *th,
115 struct super_block * p_s_sb, 118 struct super_block *p_s_sb,
116 unsigned long nblocks,int join); 119 unsigned long nblocks, int join);
117 120
118static void init_journal_hash(struct super_block *p_s_sb) { 121static void init_journal_hash(struct super_block *p_s_sb)
119 struct reiserfs_journal *journal = SB_JOURNAL (p_s_sb); 122{
120 memset(journal->j_hash_table, 0, JOURNAL_HASH_SIZE * sizeof(struct reiserfs_journal_cnode *)) ; 123 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb);
124 memset(journal->j_hash_table, 0,
125 JOURNAL_HASH_SIZE * sizeof(struct reiserfs_journal_cnode *));
121} 126}
122 127
123/* 128/*
@@ -125,149 +130,159 @@ static void init_journal_hash(struct super_block *p_s_sb) {
125** make schedule happen after I've freed a block. Look at remove_from_transaction and journal_mark_freed for 130** make schedule happen after I've freed a block. Look at remove_from_transaction and journal_mark_freed for
126** more details. 131** more details.
127*/ 132*/
128static int reiserfs_clean_and_file_buffer(struct buffer_head *bh) { 133static int reiserfs_clean_and_file_buffer(struct buffer_head *bh)
129 if (bh) { 134{
130 clear_buffer_dirty(bh); 135 if (bh) {
131 clear_buffer_journal_test(bh); 136 clear_buffer_dirty(bh);
132 } 137 clear_buffer_journal_test(bh);
133 return 0 ; 138 }
139 return 0;
134} 140}
135 141
136static void disable_barrier(struct super_block *s) 142static void disable_barrier(struct super_block *s)
137{ 143{
138 REISERFS_SB(s)->s_mount_opt &= ~(1 << REISERFS_BARRIER_FLUSH); 144 REISERFS_SB(s)->s_mount_opt &= ~(1 << REISERFS_BARRIER_FLUSH);
139 printk("reiserfs: disabling flush barriers on %s\n", reiserfs_bdevname(s)); 145 printk("reiserfs: disabling flush barriers on %s\n",
140} 146 reiserfs_bdevname(s));
141 147}
142static struct reiserfs_bitmap_node * 148
143allocate_bitmap_node(struct super_block *p_s_sb) { 149static struct reiserfs_bitmap_node *allocate_bitmap_node(struct super_block
144 struct reiserfs_bitmap_node *bn ; 150 *p_s_sb)
145 static int id; 151{
146 152 struct reiserfs_bitmap_node *bn;
147 bn = reiserfs_kmalloc(sizeof(struct reiserfs_bitmap_node), GFP_NOFS, p_s_sb) ; 153 static int id;
148 if (!bn) { 154
149 return NULL ; 155 bn = reiserfs_kmalloc(sizeof(struct reiserfs_bitmap_node), GFP_NOFS,
150 } 156 p_s_sb);
151 bn->data = reiserfs_kmalloc(p_s_sb->s_blocksize, GFP_NOFS, p_s_sb) ; 157 if (!bn) {
152 if (!bn->data) { 158 return NULL;
153 reiserfs_kfree(bn, sizeof(struct reiserfs_bitmap_node), p_s_sb) ; 159 }
154 return NULL ; 160 bn->data = reiserfs_kmalloc(p_s_sb->s_blocksize, GFP_NOFS, p_s_sb);
155 } 161 if (!bn->data) {
156 bn->id = id++ ; 162 reiserfs_kfree(bn, sizeof(struct reiserfs_bitmap_node), p_s_sb);
157 memset(bn->data, 0, p_s_sb->s_blocksize) ; 163 return NULL;
158 INIT_LIST_HEAD(&bn->list) ; 164 }
159 return bn ; 165 bn->id = id++;
160} 166 memset(bn->data, 0, p_s_sb->s_blocksize);
161 167 INIT_LIST_HEAD(&bn->list);
162static struct reiserfs_bitmap_node * 168 return bn;
163get_bitmap_node(struct super_block *p_s_sb) { 169}
164 struct reiserfs_journal *journal = SB_JOURNAL (p_s_sb); 170
165 struct reiserfs_bitmap_node *bn = NULL; 171static struct reiserfs_bitmap_node *get_bitmap_node(struct super_block *p_s_sb)
166 struct list_head *entry = journal->j_bitmap_nodes.next ; 172{
167 173 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb);
168 journal->j_used_bitmap_nodes++ ; 174 struct reiserfs_bitmap_node *bn = NULL;
169repeat: 175 struct list_head *entry = journal->j_bitmap_nodes.next;
170 176
171 if(entry != &journal->j_bitmap_nodes) { 177 journal->j_used_bitmap_nodes++;
172 bn = list_entry(entry, struct reiserfs_bitmap_node, list) ; 178 repeat:
173 list_del(entry) ; 179
174 memset(bn->data, 0, p_s_sb->s_blocksize) ; 180 if (entry != &journal->j_bitmap_nodes) {
175 journal->j_free_bitmap_nodes-- ; 181 bn = list_entry(entry, struct reiserfs_bitmap_node, list);
176 return bn ; 182 list_del(entry);
177 } 183 memset(bn->data, 0, p_s_sb->s_blocksize);
178 bn = allocate_bitmap_node(p_s_sb) ; 184 journal->j_free_bitmap_nodes--;
179 if (!bn) { 185 return bn;
180 yield(); 186 }
181 goto repeat ; 187 bn = allocate_bitmap_node(p_s_sb);
182 } 188 if (!bn) {
183 return bn ; 189 yield();
190 goto repeat;
191 }
192 return bn;
184} 193}
185static inline void free_bitmap_node(struct super_block *p_s_sb, 194static inline void free_bitmap_node(struct super_block *p_s_sb,
186 struct reiserfs_bitmap_node *bn) { 195 struct reiserfs_bitmap_node *bn)
187 struct reiserfs_journal *journal = SB_JOURNAL (p_s_sb); 196{
188 journal->j_used_bitmap_nodes-- ; 197 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb);
189 if (journal->j_free_bitmap_nodes > REISERFS_MAX_BITMAP_NODES) { 198 journal->j_used_bitmap_nodes--;
190 reiserfs_kfree(bn->data, p_s_sb->s_blocksize, p_s_sb) ; 199 if (journal->j_free_bitmap_nodes > REISERFS_MAX_BITMAP_NODES) {
191 reiserfs_kfree(bn, sizeof(struct reiserfs_bitmap_node), p_s_sb) ; 200 reiserfs_kfree(bn->data, p_s_sb->s_blocksize, p_s_sb);
192 } else { 201 reiserfs_kfree(bn, sizeof(struct reiserfs_bitmap_node), p_s_sb);
193 list_add(&bn->list, &journal->j_bitmap_nodes) ; 202 } else {
194 journal->j_free_bitmap_nodes++ ; 203 list_add(&bn->list, &journal->j_bitmap_nodes);
195 } 204 journal->j_free_bitmap_nodes++;
196} 205 }
197 206}
198static void allocate_bitmap_nodes(struct super_block *p_s_sb) { 207
199 int i ; 208static void allocate_bitmap_nodes(struct super_block *p_s_sb)
200 struct reiserfs_journal *journal = SB_JOURNAL (p_s_sb); 209{
201 struct reiserfs_bitmap_node *bn = NULL ; 210 int i;
202 for (i = 0 ; i < REISERFS_MIN_BITMAP_NODES ; i++) { 211 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb);
203 bn = allocate_bitmap_node(p_s_sb) ; 212 struct reiserfs_bitmap_node *bn = NULL;
204 if (bn) { 213 for (i = 0; i < REISERFS_MIN_BITMAP_NODES; i++) {
205 list_add(&bn->list, &journal->j_bitmap_nodes) ; 214 bn = allocate_bitmap_node(p_s_sb);
206 journal->j_free_bitmap_nodes++ ; 215 if (bn) {
207 } else { 216 list_add(&bn->list, &journal->j_bitmap_nodes);
208 break ; // this is ok, we'll try again when more are needed 217 journal->j_free_bitmap_nodes++;
209 } 218 } else {
210 } 219 break; // this is ok, we'll try again when more are needed
220 }
221 }
211} 222}
212 223
213static int set_bit_in_list_bitmap(struct super_block *p_s_sb, int block, 224static int set_bit_in_list_bitmap(struct super_block *p_s_sb, int block,
214 struct reiserfs_list_bitmap *jb) { 225 struct reiserfs_list_bitmap *jb)
215 int bmap_nr = block / (p_s_sb->s_blocksize << 3) ; 226{
216 int bit_nr = block % (p_s_sb->s_blocksize << 3) ; 227 int bmap_nr = block / (p_s_sb->s_blocksize << 3);
228 int bit_nr = block % (p_s_sb->s_blocksize << 3);
217 229
218 if (!jb->bitmaps[bmap_nr]) { 230 if (!jb->bitmaps[bmap_nr]) {
219 jb->bitmaps[bmap_nr] = get_bitmap_node(p_s_sb) ; 231 jb->bitmaps[bmap_nr] = get_bitmap_node(p_s_sb);
220 } 232 }
221 set_bit(bit_nr, (unsigned long *)jb->bitmaps[bmap_nr]->data) ; 233 set_bit(bit_nr, (unsigned long *)jb->bitmaps[bmap_nr]->data);
222 return 0 ; 234 return 0;
223} 235}
224 236
225static void cleanup_bitmap_list(struct super_block *p_s_sb, 237static void cleanup_bitmap_list(struct super_block *p_s_sb,
226 struct reiserfs_list_bitmap *jb) { 238 struct reiserfs_list_bitmap *jb)
227 int i; 239{
228 if (jb->bitmaps == NULL) 240 int i;
229 return; 241 if (jb->bitmaps == NULL)
230 242 return;
231 for (i = 0 ; i < SB_BMAP_NR(p_s_sb) ; i++) { 243
232 if (jb->bitmaps[i]) { 244 for (i = 0; i < SB_BMAP_NR(p_s_sb); i++) {
233 free_bitmap_node(p_s_sb, jb->bitmaps[i]) ; 245 if (jb->bitmaps[i]) {
234 jb->bitmaps[i] = NULL ; 246 free_bitmap_node(p_s_sb, jb->bitmaps[i]);
235 } 247 jb->bitmaps[i] = NULL;
236 } 248 }
249 }
237} 250}
238 251
239/* 252/*
240** only call this on FS unmount. 253** only call this on FS unmount.
241*/ 254*/
242static int free_list_bitmaps(struct super_block *p_s_sb, 255static int free_list_bitmaps(struct super_block *p_s_sb,
243 struct reiserfs_list_bitmap *jb_array) { 256 struct reiserfs_list_bitmap *jb_array)
244 int i ; 257{
245 struct reiserfs_list_bitmap *jb ; 258 int i;
246 for (i = 0 ; i < JOURNAL_NUM_BITMAPS ; i++) { 259 struct reiserfs_list_bitmap *jb;
247 jb = jb_array + i ; 260 for (i = 0; i < JOURNAL_NUM_BITMAPS; i++) {
248 jb->journal_list = NULL ; 261 jb = jb_array + i;
249 cleanup_bitmap_list(p_s_sb, jb) ; 262 jb->journal_list = NULL;
250 vfree(jb->bitmaps) ; 263 cleanup_bitmap_list(p_s_sb, jb);
251 jb->bitmaps = NULL ; 264 vfree(jb->bitmaps);
252 } 265 jb->bitmaps = NULL;
253 return 0; 266 }
254} 267 return 0;
255 268}
256static int free_bitmap_nodes(struct super_block *p_s_sb) { 269
257 struct reiserfs_journal *journal = SB_JOURNAL (p_s_sb); 270static int free_bitmap_nodes(struct super_block *p_s_sb)
258 struct list_head *next = journal->j_bitmap_nodes.next ; 271{
259 struct reiserfs_bitmap_node *bn ; 272 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb);
260 273 struct list_head *next = journal->j_bitmap_nodes.next;
261 while(next != &journal->j_bitmap_nodes) { 274 struct reiserfs_bitmap_node *bn;
262 bn = list_entry(next, struct reiserfs_bitmap_node, list) ; 275
263 list_del(next) ; 276 while (next != &journal->j_bitmap_nodes) {
264 reiserfs_kfree(bn->data, p_s_sb->s_blocksize, p_s_sb) ; 277 bn = list_entry(next, struct reiserfs_bitmap_node, list);
265 reiserfs_kfree(bn, sizeof(struct reiserfs_bitmap_node), p_s_sb) ; 278 list_del(next);
266 next = journal->j_bitmap_nodes.next ; 279 reiserfs_kfree(bn->data, p_s_sb->s_blocksize, p_s_sb);
267 journal->j_free_bitmap_nodes-- ; 280 reiserfs_kfree(bn, sizeof(struct reiserfs_bitmap_node), p_s_sb);
268 } 281 next = journal->j_bitmap_nodes.next;
269 282 journal->j_free_bitmap_nodes--;
270 return 0 ; 283 }
284
285 return 0;
271} 286}
272 287
273/* 288/*
@@ -275,59 +290,65 @@ static int free_bitmap_nodes(struct super_block *p_s_sb) {
275** jb_array is the array to be filled in. 290** jb_array is the array to be filled in.
276*/ 291*/
277int reiserfs_allocate_list_bitmaps(struct super_block *p_s_sb, 292int reiserfs_allocate_list_bitmaps(struct super_block *p_s_sb,
278 struct reiserfs_list_bitmap *jb_array, 293 struct reiserfs_list_bitmap *jb_array,
279 int bmap_nr) { 294 int bmap_nr)
280 int i ; 295{
281 int failed = 0 ; 296 int i;
282 struct reiserfs_list_bitmap *jb ; 297 int failed = 0;
283 int mem = bmap_nr * sizeof(struct reiserfs_bitmap_node *) ; 298 struct reiserfs_list_bitmap *jb;
284 299 int mem = bmap_nr * sizeof(struct reiserfs_bitmap_node *);
285 for (i = 0 ; i < JOURNAL_NUM_BITMAPS ; i++) { 300
286 jb = jb_array + i ; 301 for (i = 0; i < JOURNAL_NUM_BITMAPS; i++) {
287 jb->journal_list = NULL ; 302 jb = jb_array + i;
288 jb->bitmaps = vmalloc( mem ) ; 303 jb->journal_list = NULL;
289 if (!jb->bitmaps) { 304 jb->bitmaps = vmalloc(mem);
290 reiserfs_warning(p_s_sb, "clm-2000, unable to allocate bitmaps for journal lists") ; 305 if (!jb->bitmaps) {
291 failed = 1; 306 reiserfs_warning(p_s_sb,
292 break ; 307 "clm-2000, unable to allocate bitmaps for journal lists");
293 } 308 failed = 1;
294 memset(jb->bitmaps, 0, mem) ; 309 break;
295 } 310 }
296 if (failed) { 311 memset(jb->bitmaps, 0, mem);
297 free_list_bitmaps(p_s_sb, jb_array) ; 312 }
298 return -1 ; 313 if (failed) {
299 } 314 free_list_bitmaps(p_s_sb, jb_array);
300 return 0 ; 315 return -1;
316 }
317 return 0;
301} 318}
302 319
303/* 320/*
304** find an available list bitmap. If you can't find one, flush a commit list 321** find an available list bitmap. If you can't find one, flush a commit list
305** and try again 322** and try again
306*/ 323*/
307static struct reiserfs_list_bitmap * 324static struct reiserfs_list_bitmap *get_list_bitmap(struct super_block *p_s_sb,
308get_list_bitmap(struct super_block *p_s_sb, struct reiserfs_journal_list *jl) { 325 struct reiserfs_journal_list
309 int i,j ; 326 *jl)
310 struct reiserfs_journal *journal = SB_JOURNAL (p_s_sb); 327{
311 struct reiserfs_list_bitmap *jb = NULL ; 328 int i, j;
312 329 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb);
313 for (j = 0 ; j < (JOURNAL_NUM_BITMAPS * 3) ; j++) { 330 struct reiserfs_list_bitmap *jb = NULL;
314 i = journal->j_list_bitmap_index ; 331
315 journal->j_list_bitmap_index = (i + 1) % JOURNAL_NUM_BITMAPS ; 332 for (j = 0; j < (JOURNAL_NUM_BITMAPS * 3); j++) {
316 jb = journal->j_list_bitmap + i ; 333 i = journal->j_list_bitmap_index;
317 if (journal->j_list_bitmap[i].journal_list) { 334 journal->j_list_bitmap_index = (i + 1) % JOURNAL_NUM_BITMAPS;
318 flush_commit_list(p_s_sb, journal->j_list_bitmap[i].journal_list, 1) ; 335 jb = journal->j_list_bitmap + i;
319 if (!journal->j_list_bitmap[i].journal_list) { 336 if (journal->j_list_bitmap[i].journal_list) {
320 break ; 337 flush_commit_list(p_s_sb,
321 } 338 journal->j_list_bitmap[i].
322 } else { 339 journal_list, 1);
323 break ; 340 if (!journal->j_list_bitmap[i].journal_list) {
324 } 341 break;
325 } 342 }
326 if (jb->journal_list) { /* double check to make sure if flushed correctly */ 343 } else {
327 return NULL ; 344 break;
328 } 345 }
329 jb->journal_list = jl ; 346 }
330 return jb ; 347 if (jb->journal_list) { /* double check to make sure if flushed correctly */
348 return NULL;
349 }
350 jb->journal_list = jl;
351 return jb;
331} 352}
332 353
333/* 354/*
@@ -335,104 +356,114 @@ get_list_bitmap(struct super_block *p_s_sb, struct reiserfs_journal_list *jl) {
335** Uses the cnode->next and cnode->prev pointers 356** Uses the cnode->next and cnode->prev pointers
336** returns NULL on failure 357** returns NULL on failure
337*/ 358*/
338static struct reiserfs_journal_cnode *allocate_cnodes(int num_cnodes) { 359static struct reiserfs_journal_cnode *allocate_cnodes(int num_cnodes)
339 struct reiserfs_journal_cnode *head ; 360{
340 int i ; 361 struct reiserfs_journal_cnode *head;
341 if (num_cnodes <= 0) { 362 int i;
342 return NULL ; 363 if (num_cnodes <= 0) {
343 } 364 return NULL;
344 head = vmalloc(num_cnodes * sizeof(struct reiserfs_journal_cnode)) ; 365 }
345 if (!head) { 366 head = vmalloc(num_cnodes * sizeof(struct reiserfs_journal_cnode));
346 return NULL ; 367 if (!head) {
347 } 368 return NULL;
348 memset(head, 0, num_cnodes * sizeof(struct reiserfs_journal_cnode)) ; 369 }
349 head[0].prev = NULL ; 370 memset(head, 0, num_cnodes * sizeof(struct reiserfs_journal_cnode));
350 head[0].next = head + 1 ; 371 head[0].prev = NULL;
351 for (i = 1 ; i < num_cnodes; i++) { 372 head[0].next = head + 1;
352 head[i].prev = head + (i - 1) ; 373 for (i = 1; i < num_cnodes; i++) {
353 head[i].next = head + (i + 1) ; /* if last one, overwrite it after the if */ 374 head[i].prev = head + (i - 1);
354 } 375 head[i].next = head + (i + 1); /* if last one, overwrite it after the if */
355 head[num_cnodes -1].next = NULL ; 376 }
356 return head ; 377 head[num_cnodes - 1].next = NULL;
378 return head;
357} 379}
358 380
359/* 381/*
360** pulls a cnode off the free list, or returns NULL on failure 382** pulls a cnode off the free list, or returns NULL on failure
361*/ 383*/
362static struct reiserfs_journal_cnode *get_cnode(struct super_block *p_s_sb) { 384static struct reiserfs_journal_cnode *get_cnode(struct super_block *p_s_sb)
363 struct reiserfs_journal_cnode *cn ; 385{
364 struct reiserfs_journal *journal = SB_JOURNAL (p_s_sb); 386 struct reiserfs_journal_cnode *cn;
365 387 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb);
366 reiserfs_check_lock_depth(p_s_sb, "get_cnode") ; 388
367 389 reiserfs_check_lock_depth(p_s_sb, "get_cnode");
368 if (journal->j_cnode_free <= 0) { 390
369 return NULL ; 391 if (journal->j_cnode_free <= 0) {
370 } 392 return NULL;
371 journal->j_cnode_used++ ; 393 }
372 journal->j_cnode_free-- ; 394 journal->j_cnode_used++;
373 cn = journal->j_cnode_free_list ; 395 journal->j_cnode_free--;
374 if (!cn) { 396 cn = journal->j_cnode_free_list;
375 return cn ; 397 if (!cn) {
376 } 398 return cn;
377 if (cn->next) { 399 }
378 cn->next->prev = NULL ; 400 if (cn->next) {
379 } 401 cn->next->prev = NULL;
380 journal->j_cnode_free_list = cn->next ; 402 }
381 memset(cn, 0, sizeof(struct reiserfs_journal_cnode)) ; 403 journal->j_cnode_free_list = cn->next;
382 return cn ; 404 memset(cn, 0, sizeof(struct reiserfs_journal_cnode));
405 return cn;
383} 406}
384 407
385/* 408/*
386** returns a cnode to the free list 409** returns a cnode to the free list
387*/ 410*/
388static void free_cnode(struct super_block *p_s_sb, struct reiserfs_journal_cnode *cn) { 411static void free_cnode(struct super_block *p_s_sb,
389 struct reiserfs_journal *journal = SB_JOURNAL (p_s_sb); 412 struct reiserfs_journal_cnode *cn)
413{
414 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb);
390 415
391 reiserfs_check_lock_depth(p_s_sb, "free_cnode") ; 416 reiserfs_check_lock_depth(p_s_sb, "free_cnode");
392 417
393 journal->j_cnode_used-- ; 418 journal->j_cnode_used--;
394 journal->j_cnode_free++ ; 419 journal->j_cnode_free++;
395 /* memset(cn, 0, sizeof(struct reiserfs_journal_cnode)) ; */ 420 /* memset(cn, 0, sizeof(struct reiserfs_journal_cnode)) ; */
396 cn->next = journal->j_cnode_free_list ; 421 cn->next = journal->j_cnode_free_list;
397 if (journal->j_cnode_free_list) { 422 if (journal->j_cnode_free_list) {
398 journal->j_cnode_free_list->prev = cn ; 423 journal->j_cnode_free_list->prev = cn;
399 } 424 }
400 cn->prev = NULL ; /* not needed with the memset, but I might kill the memset, and forget to do this */ 425 cn->prev = NULL; /* not needed with the memset, but I might kill the memset, and forget to do this */
401 journal->j_cnode_free_list = cn ; 426 journal->j_cnode_free_list = cn;
402} 427}
403 428
404static void clear_prepared_bits(struct buffer_head *bh) { 429static void clear_prepared_bits(struct buffer_head *bh)
405 clear_buffer_journal_prepared (bh); 430{
406 clear_buffer_journal_restore_dirty (bh); 431 clear_buffer_journal_prepared(bh);
432 clear_buffer_journal_restore_dirty(bh);
407} 433}
408 434
409/* utility function to force a BUG if it is called without the big 435/* utility function to force a BUG if it is called without the big
410** kernel lock held. caller is the string printed just before calling BUG() 436** kernel lock held. caller is the string printed just before calling BUG()
411*/ 437*/
412void reiserfs_check_lock_depth(struct super_block *sb, char *caller) { 438void reiserfs_check_lock_depth(struct super_block *sb, char *caller)
439{
413#ifdef CONFIG_SMP 440#ifdef CONFIG_SMP
414 if (current->lock_depth < 0) { 441 if (current->lock_depth < 0) {
415 reiserfs_panic (sb, "%s called without kernel lock held", caller) ; 442 reiserfs_panic(sb, "%s called without kernel lock held",
416 } 443 caller);
444 }
417#else 445#else
418 ; 446 ;
419#endif 447#endif
420} 448}
421 449
422/* return a cnode with same dev, block number and size in table, or null if not found */ 450/* return a cnode with same dev, block number and size in table, or null if not found */
423static inline struct reiserfs_journal_cnode * 451static inline struct reiserfs_journal_cnode *get_journal_hash_dev(struct
424get_journal_hash_dev(struct super_block *sb, 452 super_block
425 struct reiserfs_journal_cnode **table, 453 *sb,
426 long bl) 454 struct
455 reiserfs_journal_cnode
456 **table,
457 long bl)
427{ 458{
428 struct reiserfs_journal_cnode *cn ; 459 struct reiserfs_journal_cnode *cn;
429 cn = journal_hash(table, sb, bl) ; 460 cn = journal_hash(table, sb, bl);
430 while(cn) { 461 while (cn) {
431 if (cn->blocknr == bl && cn->sb == sb) 462 if (cn->blocknr == bl && cn->sb == sb)
432 return cn ; 463 return cn;
433 cn = cn->hnext ; 464 cn = cn->hnext;
434 } 465 }
435 return (struct reiserfs_journal_cnode *)0 ; 466 return (struct reiserfs_journal_cnode *)0;
436} 467}
437 468
438/* 469/*
@@ -454,91 +485,103 @@ get_journal_hash_dev(struct super_block *sb,
454** 485**
455*/ 486*/
456int reiserfs_in_journal(struct super_block *p_s_sb, 487int reiserfs_in_journal(struct super_block *p_s_sb,
457 int bmap_nr, int bit_nr, int search_all, 488 int bmap_nr, int bit_nr, int search_all,
458 b_blocknr_t *next_zero_bit) { 489 b_blocknr_t * next_zero_bit)
459 struct reiserfs_journal *journal = SB_JOURNAL (p_s_sb); 490{
460 struct reiserfs_journal_cnode *cn ; 491 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb);
461 struct reiserfs_list_bitmap *jb ; 492 struct reiserfs_journal_cnode *cn;
462 int i ; 493 struct reiserfs_list_bitmap *jb;
463 unsigned long bl; 494 int i;
464 495 unsigned long bl;
465 *next_zero_bit = 0 ; /* always start this at zero. */ 496
466 497 *next_zero_bit = 0; /* always start this at zero. */
467 PROC_INFO_INC( p_s_sb, journal.in_journal ); 498
468 /* If we aren't doing a search_all, this is a metablock, and it will be logged before use. 499 PROC_INFO_INC(p_s_sb, journal.in_journal);
469 ** if we crash before the transaction that freed it commits, this transaction won't 500 /* If we aren't doing a search_all, this is a metablock, and it will be logged before use.
470 ** have committed either, and the block will never be written 501 ** if we crash before the transaction that freed it commits, this transaction won't
471 */ 502 ** have committed either, and the block will never be written
472 if (search_all) { 503 */
473 for (i = 0 ; i < JOURNAL_NUM_BITMAPS ; i++) { 504 if (search_all) {
474 PROC_INFO_INC( p_s_sb, journal.in_journal_bitmap ); 505 for (i = 0; i < JOURNAL_NUM_BITMAPS; i++) {
475 jb = journal->j_list_bitmap + i ; 506 PROC_INFO_INC(p_s_sb, journal.in_journal_bitmap);
476 if (jb->journal_list && jb->bitmaps[bmap_nr] && 507 jb = journal->j_list_bitmap + i;
477 test_bit(bit_nr, (unsigned long *)jb->bitmaps[bmap_nr]->data)) { 508 if (jb->journal_list && jb->bitmaps[bmap_nr] &&
478 *next_zero_bit = find_next_zero_bit((unsigned long *) 509 test_bit(bit_nr,
479 (jb->bitmaps[bmap_nr]->data), 510 (unsigned long *)jb->bitmaps[bmap_nr]->
480 p_s_sb->s_blocksize << 3, bit_nr+1) ; 511 data)) {
481 return 1 ; 512 *next_zero_bit =
482 } 513 find_next_zero_bit((unsigned long *)
483 } 514 (jb->bitmaps[bmap_nr]->
484 } 515 data),
485 516 p_s_sb->s_blocksize << 3,
486 bl = bmap_nr * (p_s_sb->s_blocksize << 3) + bit_nr; 517 bit_nr + 1);
487 /* is it in any old transactions? */ 518 return 1;
488 if (search_all && (cn = get_journal_hash_dev(p_s_sb, journal->j_list_hash_table, bl))) { 519 }
489 return 1; 520 }
490 } 521 }
491 522
492 /* is it in the current transaction. This should never happen */ 523 bl = bmap_nr * (p_s_sb->s_blocksize << 3) + bit_nr;
493 if ((cn = get_journal_hash_dev(p_s_sb, journal->j_hash_table, bl))) { 524 /* is it in any old transactions? */
494 BUG(); 525 if (search_all
495 return 1; 526 && (cn =
496 } 527 get_journal_hash_dev(p_s_sb, journal->j_list_hash_table, bl))) {
497 528 return 1;
498 PROC_INFO_INC( p_s_sb, journal.in_journal_reusable ); 529 }
499 /* safe for reuse */ 530
500 return 0 ; 531 /* is it in the current transaction. This should never happen */
532 if ((cn = get_journal_hash_dev(p_s_sb, journal->j_hash_table, bl))) {
533 BUG();
534 return 1;
535 }
536
537 PROC_INFO_INC(p_s_sb, journal.in_journal_reusable);
538 /* safe for reuse */
539 return 0;
501} 540}
502 541
503/* insert cn into table 542/* insert cn into table
504*/ 543*/
505static inline void insert_journal_hash(struct reiserfs_journal_cnode **table, struct reiserfs_journal_cnode *cn) { 544static inline void insert_journal_hash(struct reiserfs_journal_cnode **table,
506 struct reiserfs_journal_cnode *cn_orig ; 545 struct reiserfs_journal_cnode *cn)
546{
547 struct reiserfs_journal_cnode *cn_orig;
507 548
508 cn_orig = journal_hash(table, cn->sb, cn->blocknr) ; 549 cn_orig = journal_hash(table, cn->sb, cn->blocknr);
509 cn->hnext = cn_orig ; 550 cn->hnext = cn_orig;
510 cn->hprev = NULL ; 551 cn->hprev = NULL;
511 if (cn_orig) { 552 if (cn_orig) {
512 cn_orig->hprev = cn ; 553 cn_orig->hprev = cn;
513 } 554 }
514 journal_hash(table, cn->sb, cn->blocknr) = cn ; 555 journal_hash(table, cn->sb, cn->blocknr) = cn;
515} 556}
516 557
517/* lock the current transaction */ 558/* lock the current transaction */
518inline static void lock_journal(struct super_block *p_s_sb) { 559inline static void lock_journal(struct super_block *p_s_sb)
519 PROC_INFO_INC( p_s_sb, journal.lock_journal ); 560{
520 down(&SB_JOURNAL(p_s_sb)->j_lock); 561 PROC_INFO_INC(p_s_sb, journal.lock_journal);
562 down(&SB_JOURNAL(p_s_sb)->j_lock);
521} 563}
522 564
523/* unlock the current transaction */ 565/* unlock the current transaction */
524inline static void unlock_journal(struct super_block *p_s_sb) { 566inline static void unlock_journal(struct super_block *p_s_sb)
525 up(&SB_JOURNAL(p_s_sb)->j_lock); 567{
568 up(&SB_JOURNAL(p_s_sb)->j_lock);
526} 569}
527 570
528static inline void get_journal_list(struct reiserfs_journal_list *jl) 571static inline void get_journal_list(struct reiserfs_journal_list *jl)
529{ 572{
530 jl->j_refcount++; 573 jl->j_refcount++;
531} 574}
532 575
533static inline void put_journal_list(struct super_block *s, 576static inline void put_journal_list(struct super_block *s,
534 struct reiserfs_journal_list *jl) 577 struct reiserfs_journal_list *jl)
535{ 578{
536 if (jl->j_refcount < 1) { 579 if (jl->j_refcount < 1) {
537 reiserfs_panic (s, "trans id %lu, refcount at %d", jl->j_trans_id, 580 reiserfs_panic(s, "trans id %lu, refcount at %d",
538 jl->j_refcount); 581 jl->j_trans_id, jl->j_refcount);
539 } 582 }
540 if (--jl->j_refcount == 0) 583 if (--jl->j_refcount == 0)
541 reiserfs_kfree(jl, sizeof(struct reiserfs_journal_list), s); 584 reiserfs_kfree(jl, sizeof(struct reiserfs_journal_list), s);
542} 585}
543 586
544/* 587/*
@@ -546,358 +589,375 @@ static inline void put_journal_list(struct super_block *s,
546** it gets called by flush_commit_list, and cleans up any data stored about blocks freed during a 589** it gets called by flush_commit_list, and cleans up any data stored about blocks freed during a
547** transaction. 590** transaction.
548*/ 591*/
549static void cleanup_freed_for_journal_list(struct super_block *p_s_sb, struct reiserfs_journal_list *jl) { 592static void cleanup_freed_for_journal_list(struct super_block *p_s_sb,
593 struct reiserfs_journal_list *jl)
594{
550 595
551 struct reiserfs_list_bitmap *jb = jl->j_list_bitmap ; 596 struct reiserfs_list_bitmap *jb = jl->j_list_bitmap;
552 if (jb) { 597 if (jb) {
553 cleanup_bitmap_list(p_s_sb, jb) ; 598 cleanup_bitmap_list(p_s_sb, jb);
554 } 599 }
555 jl->j_list_bitmap->journal_list = NULL ; 600 jl->j_list_bitmap->journal_list = NULL;
556 jl->j_list_bitmap = NULL ; 601 jl->j_list_bitmap = NULL;
557} 602}
558 603
559static int journal_list_still_alive(struct super_block *s, 604static int journal_list_still_alive(struct super_block *s,
560 unsigned long trans_id) 605 unsigned long trans_id)
561{ 606{
562 struct reiserfs_journal *journal = SB_JOURNAL (s); 607 struct reiserfs_journal *journal = SB_JOURNAL(s);
563 struct list_head *entry = &journal->j_journal_list; 608 struct list_head *entry = &journal->j_journal_list;
564 struct reiserfs_journal_list *jl; 609 struct reiserfs_journal_list *jl;
565 610
566 if (!list_empty(entry)) { 611 if (!list_empty(entry)) {
567 jl = JOURNAL_LIST_ENTRY(entry->next); 612 jl = JOURNAL_LIST_ENTRY(entry->next);
568 if (jl->j_trans_id <= trans_id) { 613 if (jl->j_trans_id <= trans_id) {
569 return 1; 614 return 1;
570 } 615 }
571 } 616 }
572 return 0; 617 return 0;
573} 618}
574 619
575static void reiserfs_end_buffer_io_sync(struct buffer_head *bh, int uptodate) { 620static void reiserfs_end_buffer_io_sync(struct buffer_head *bh, int uptodate)
576 char b[BDEVNAME_SIZE]; 621{
577 622 char b[BDEVNAME_SIZE];
578 if (buffer_journaled(bh)) { 623
579 reiserfs_warning(NULL, "clm-2084: pinned buffer %lu:%s sent to disk", 624 if (buffer_journaled(bh)) {
580 bh->b_blocknr, bdevname(bh->b_bdev, b)) ; 625 reiserfs_warning(NULL,
581 } 626 "clm-2084: pinned buffer %lu:%s sent to disk",
582 if (uptodate) 627 bh->b_blocknr, bdevname(bh->b_bdev, b));
583 set_buffer_uptodate(bh) ; 628 }
584 else 629 if (uptodate)
585 clear_buffer_uptodate(bh) ; 630 set_buffer_uptodate(bh);
586 unlock_buffer(bh) ; 631 else
587 put_bh(bh) ; 632 clear_buffer_uptodate(bh);
588} 633 unlock_buffer(bh);
589 634 put_bh(bh);
590static void reiserfs_end_ordered_io(struct buffer_head *bh, int uptodate) { 635}
591 if (uptodate) 636
592 set_buffer_uptodate(bh) ; 637static void reiserfs_end_ordered_io(struct buffer_head *bh, int uptodate)
593 else 638{
594 clear_buffer_uptodate(bh) ; 639 if (uptodate)
595 unlock_buffer(bh) ; 640 set_buffer_uptodate(bh);
596 put_bh(bh) ; 641 else
597} 642 clear_buffer_uptodate(bh);
598 643 unlock_buffer(bh);
599static void submit_logged_buffer(struct buffer_head *bh) { 644 put_bh(bh);
600 get_bh(bh) ; 645}
601 bh->b_end_io = reiserfs_end_buffer_io_sync ; 646
602 clear_buffer_journal_new (bh); 647static void submit_logged_buffer(struct buffer_head *bh)
603 clear_buffer_dirty(bh) ; 648{
604 if (!test_clear_buffer_journal_test (bh)) 649 get_bh(bh);
605 BUG(); 650 bh->b_end_io = reiserfs_end_buffer_io_sync;
606 if (!buffer_uptodate(bh)) 651 clear_buffer_journal_new(bh);
607 BUG(); 652 clear_buffer_dirty(bh);
608 submit_bh(WRITE, bh) ; 653 if (!test_clear_buffer_journal_test(bh))
609} 654 BUG();
610 655 if (!buffer_uptodate(bh))
611static void submit_ordered_buffer(struct buffer_head *bh) { 656 BUG();
612 get_bh(bh) ; 657 submit_bh(WRITE, bh);
613 bh->b_end_io = reiserfs_end_ordered_io; 658}
614 clear_buffer_dirty(bh) ; 659
615 if (!buffer_uptodate(bh)) 660static void submit_ordered_buffer(struct buffer_head *bh)
616 BUG(); 661{
617 submit_bh(WRITE, bh) ; 662 get_bh(bh);
618} 663 bh->b_end_io = reiserfs_end_ordered_io;
619 664 clear_buffer_dirty(bh);
620static int submit_barrier_buffer(struct buffer_head *bh) { 665 if (!buffer_uptodate(bh))
621 get_bh(bh) ; 666 BUG();
622 bh->b_end_io = reiserfs_end_ordered_io; 667 submit_bh(WRITE, bh);
623 clear_buffer_dirty(bh) ; 668}
624 if (!buffer_uptodate(bh)) 669
625 BUG(); 670static int submit_barrier_buffer(struct buffer_head *bh)
626 return submit_bh(WRITE_BARRIER, bh) ; 671{
672 get_bh(bh);
673 bh->b_end_io = reiserfs_end_ordered_io;
674 clear_buffer_dirty(bh);
675 if (!buffer_uptodate(bh))
676 BUG();
677 return submit_bh(WRITE_BARRIER, bh);
627} 678}
628 679
629static void check_barrier_completion(struct super_block *s, 680static void check_barrier_completion(struct super_block *s,
630 struct buffer_head *bh) { 681 struct buffer_head *bh)
631 if (buffer_eopnotsupp(bh)) { 682{
632 clear_buffer_eopnotsupp(bh); 683 if (buffer_eopnotsupp(bh)) {
633 disable_barrier(s); 684 clear_buffer_eopnotsupp(bh);
634 set_buffer_uptodate(bh); 685 disable_barrier(s);
635 set_buffer_dirty(bh); 686 set_buffer_uptodate(bh);
636 sync_dirty_buffer(bh); 687 set_buffer_dirty(bh);
637 } 688 sync_dirty_buffer(bh);
689 }
638} 690}
639 691
640#define CHUNK_SIZE 32 692#define CHUNK_SIZE 32
641struct buffer_chunk { 693struct buffer_chunk {
642 struct buffer_head *bh[CHUNK_SIZE]; 694 struct buffer_head *bh[CHUNK_SIZE];
643 int nr; 695 int nr;
644}; 696};
645 697
646static void write_chunk(struct buffer_chunk *chunk) { 698static void write_chunk(struct buffer_chunk *chunk)
647 int i; 699{
648 get_fs_excl(); 700 int i;
649 for (i = 0; i < chunk->nr ; i++) { 701 get_fs_excl();
650 submit_logged_buffer(chunk->bh[i]) ; 702 for (i = 0; i < chunk->nr; i++) {
651 } 703 submit_logged_buffer(chunk->bh[i]);
652 chunk->nr = 0; 704 }
653 put_fs_excl(); 705 chunk->nr = 0;
706 put_fs_excl();
654} 707}
655 708
656static void write_ordered_chunk(struct buffer_chunk *chunk) { 709static void write_ordered_chunk(struct buffer_chunk *chunk)
657 int i; 710{
658 get_fs_excl(); 711 int i;
659 for (i = 0; i < chunk->nr ; i++) { 712 get_fs_excl();
660 submit_ordered_buffer(chunk->bh[i]) ; 713 for (i = 0; i < chunk->nr; i++) {
661 } 714 submit_ordered_buffer(chunk->bh[i]);
662 chunk->nr = 0; 715 }
663 put_fs_excl(); 716 chunk->nr = 0;
717 put_fs_excl();
664} 718}
665 719
666static int add_to_chunk(struct buffer_chunk *chunk, struct buffer_head *bh, 720static int add_to_chunk(struct buffer_chunk *chunk, struct buffer_head *bh,
667 spinlock_t *lock, 721 spinlock_t * lock, void (fn) (struct buffer_chunk *))
668 void (fn)(struct buffer_chunk *))
669{ 722{
670 int ret = 0; 723 int ret = 0;
671 if (chunk->nr >= CHUNK_SIZE) 724 if (chunk->nr >= CHUNK_SIZE)
672 BUG(); 725 BUG();
673 chunk->bh[chunk->nr++] = bh; 726 chunk->bh[chunk->nr++] = bh;
674 if (chunk->nr >= CHUNK_SIZE) { 727 if (chunk->nr >= CHUNK_SIZE) {
675 ret = 1; 728 ret = 1;
676 if (lock) 729 if (lock)
677 spin_unlock(lock); 730 spin_unlock(lock);
678 fn(chunk); 731 fn(chunk);
679 if (lock) 732 if (lock)
680 spin_lock(lock); 733 spin_lock(lock);
681 } 734 }
682 return ret; 735 return ret;
683} 736}
684 737
685
686static atomic_t nr_reiserfs_jh = ATOMIC_INIT(0); 738static atomic_t nr_reiserfs_jh = ATOMIC_INIT(0);
687static struct reiserfs_jh *alloc_jh(void) { 739static struct reiserfs_jh *alloc_jh(void)
688 struct reiserfs_jh *jh; 740{
689 while(1) { 741 struct reiserfs_jh *jh;
690 jh = kmalloc(sizeof(*jh), GFP_NOFS); 742 while (1) {
691 if (jh) { 743 jh = kmalloc(sizeof(*jh), GFP_NOFS);
692 atomic_inc(&nr_reiserfs_jh); 744 if (jh) {
693 return jh; 745 atomic_inc(&nr_reiserfs_jh);
746 return jh;
747 }
748 yield();
694 } 749 }
695 yield();
696 }
697} 750}
698 751
699/* 752/*
700 * we want to free the jh when the buffer has been written 753 * we want to free the jh when the buffer has been written
701 * and waited on 754 * and waited on
702 */ 755 */
703void reiserfs_free_jh(struct buffer_head *bh) { 756void reiserfs_free_jh(struct buffer_head *bh)
704 struct reiserfs_jh *jh; 757{
705 758 struct reiserfs_jh *jh;
706 jh = bh->b_private; 759
707 if (jh) { 760 jh = bh->b_private;
708 bh->b_private = NULL; 761 if (jh) {
709 jh->bh = NULL; 762 bh->b_private = NULL;
710 list_del_init(&jh->list); 763 jh->bh = NULL;
711 kfree(jh); 764 list_del_init(&jh->list);
712 if (atomic_read(&nr_reiserfs_jh) <= 0) 765 kfree(jh);
713 BUG(); 766 if (atomic_read(&nr_reiserfs_jh) <= 0)
714 atomic_dec(&nr_reiserfs_jh); 767 BUG();
715 put_bh(bh); 768 atomic_dec(&nr_reiserfs_jh);
716 } 769 put_bh(bh);
770 }
717} 771}
718 772
719static inline int __add_jh(struct reiserfs_journal *j, struct buffer_head *bh, 773static inline int __add_jh(struct reiserfs_journal *j, struct buffer_head *bh,
720 int tail) 774 int tail)
721{ 775{
722 struct reiserfs_jh *jh; 776 struct reiserfs_jh *jh;
723 777
724 if (bh->b_private) { 778 if (bh->b_private) {
725 spin_lock(&j->j_dirty_buffers_lock); 779 spin_lock(&j->j_dirty_buffers_lock);
726 if (!bh->b_private) { 780 if (!bh->b_private) {
727 spin_unlock(&j->j_dirty_buffers_lock); 781 spin_unlock(&j->j_dirty_buffers_lock);
728 goto no_jh; 782 goto no_jh;
783 }
784 jh = bh->b_private;
785 list_del_init(&jh->list);
786 } else {
787 no_jh:
788 get_bh(bh);
789 jh = alloc_jh();
790 spin_lock(&j->j_dirty_buffers_lock);
791 /* buffer must be locked for __add_jh, should be able to have
792 * two adds at the same time
793 */
794 if (bh->b_private)
795 BUG();
796 jh->bh = bh;
797 bh->b_private = jh;
729 } 798 }
730 jh = bh->b_private; 799 jh->jl = j->j_current_jl;
731 list_del_init(&jh->list); 800 if (tail)
732 } else { 801 list_add_tail(&jh->list, &jh->jl->j_tail_bh_list);
733no_jh: 802 else {
734 get_bh(bh); 803 list_add_tail(&jh->list, &jh->jl->j_bh_list);
735 jh = alloc_jh(); 804 }
736 spin_lock(&j->j_dirty_buffers_lock); 805 spin_unlock(&j->j_dirty_buffers_lock);
737 /* buffer must be locked for __add_jh, should be able to have 806 return 0;
738 * two adds at the same time
739 */
740 if (bh->b_private)
741 BUG();
742 jh->bh = bh;
743 bh->b_private = jh;
744 }
745 jh->jl = j->j_current_jl;
746 if (tail)
747 list_add_tail(&jh->list, &jh->jl->j_tail_bh_list);
748 else {
749 list_add_tail(&jh->list, &jh->jl->j_bh_list);
750 }
751 spin_unlock(&j->j_dirty_buffers_lock);
752 return 0;
753} 807}
754 808
755int reiserfs_add_tail_list(struct inode *inode, struct buffer_head *bh) { 809int reiserfs_add_tail_list(struct inode *inode, struct buffer_head *bh)
756 return __add_jh(SB_JOURNAL(inode->i_sb), bh, 1); 810{
811 return __add_jh(SB_JOURNAL(inode->i_sb), bh, 1);
757} 812}
758int reiserfs_add_ordered_list(struct inode *inode, struct buffer_head *bh) { 813int reiserfs_add_ordered_list(struct inode *inode, struct buffer_head *bh)
759 return __add_jh(SB_JOURNAL(inode->i_sb), bh, 0); 814{
815 return __add_jh(SB_JOURNAL(inode->i_sb), bh, 0);
760} 816}
761 817
762#define JH_ENTRY(l) list_entry((l), struct reiserfs_jh, list) 818#define JH_ENTRY(l) list_entry((l), struct reiserfs_jh, list)
763static int write_ordered_buffers(spinlock_t *lock, 819static int write_ordered_buffers(spinlock_t * lock,
764 struct reiserfs_journal *j, 820 struct reiserfs_journal *j,
765 struct reiserfs_journal_list *jl, 821 struct reiserfs_journal_list *jl,
766 struct list_head *list) 822 struct list_head *list)
767{ 823{
768 struct buffer_head *bh; 824 struct buffer_head *bh;
769 struct reiserfs_jh *jh; 825 struct reiserfs_jh *jh;
770 int ret = j->j_errno; 826 int ret = j->j_errno;
771 struct buffer_chunk chunk; 827 struct buffer_chunk chunk;
772 struct list_head tmp; 828 struct list_head tmp;
773 INIT_LIST_HEAD(&tmp); 829 INIT_LIST_HEAD(&tmp);
774 830
775 chunk.nr = 0; 831 chunk.nr = 0;
776 spin_lock(lock); 832 spin_lock(lock);
777 while(!list_empty(list)) { 833 while (!list_empty(list)) {
778 jh = JH_ENTRY(list->next); 834 jh = JH_ENTRY(list->next);
779 bh = jh->bh; 835 bh = jh->bh;
780 get_bh(bh); 836 get_bh(bh);
781 if (test_set_buffer_locked(bh)) { 837 if (test_set_buffer_locked(bh)) {
782 if (!buffer_dirty(bh)) { 838 if (!buffer_dirty(bh)) {
783 list_del_init(&jh->list); 839 list_del_init(&jh->list);
784 list_add(&jh->list, &tmp); 840 list_add(&jh->list, &tmp);
785 goto loop_next; 841 goto loop_next;
786 } 842 }
787 spin_unlock(lock); 843 spin_unlock(lock);
788 if (chunk.nr) 844 if (chunk.nr)
845 write_ordered_chunk(&chunk);
846 wait_on_buffer(bh);
847 cond_resched();
848 spin_lock(lock);
849 goto loop_next;
850 }
851 if (buffer_dirty(bh)) {
852 list_del_init(&jh->list);
853 list_add(&jh->list, &tmp);
854 add_to_chunk(&chunk, bh, lock, write_ordered_chunk);
855 } else {
856 reiserfs_free_jh(bh);
857 unlock_buffer(bh);
858 }
859 loop_next:
860 put_bh(bh);
861 cond_resched_lock(lock);
862 }
863 if (chunk.nr) {
864 spin_unlock(lock);
789 write_ordered_chunk(&chunk); 865 write_ordered_chunk(&chunk);
790 wait_on_buffer(bh); 866 spin_lock(lock);
791 cond_resched();
792 spin_lock(lock);
793 goto loop_next;
794 }
795 if (buffer_dirty(bh)) {
796 list_del_init(&jh->list);
797 list_add(&jh->list, &tmp);
798 add_to_chunk(&chunk, bh, lock, write_ordered_chunk);
799 } else {
800 reiserfs_free_jh(bh);
801 unlock_buffer(bh);
802 } 867 }
803loop_next: 868 while (!list_empty(&tmp)) {
804 put_bh(bh); 869 jh = JH_ENTRY(tmp.prev);
805 cond_resched_lock(lock); 870 bh = jh->bh;
806 } 871 get_bh(bh);
807 if (chunk.nr) { 872 reiserfs_free_jh(bh);
808 spin_unlock(lock); 873
809 write_ordered_chunk(&chunk); 874 if (buffer_locked(bh)) {
810 spin_lock(lock); 875 spin_unlock(lock);
811 } 876 wait_on_buffer(bh);
812 while(!list_empty(&tmp)) { 877 spin_lock(lock);
813 jh = JH_ENTRY(tmp.prev); 878 }
814 bh = jh->bh; 879 if (!buffer_uptodate(bh)) {
815 get_bh(bh); 880 ret = -EIO;
816 reiserfs_free_jh(bh); 881 }
817 882 put_bh(bh);
818 if (buffer_locked(bh)) { 883 cond_resched_lock(lock);
819 spin_unlock(lock);
820 wait_on_buffer(bh);
821 spin_lock(lock);
822 } 884 }
823 if (!buffer_uptodate(bh)) { 885 spin_unlock(lock);
824 ret = -EIO; 886 return ret;
825 } 887}
826 put_bh(bh);
827 cond_resched_lock(lock);
828 }
829 spin_unlock(lock);
830 return ret;
831}
832
833static int flush_older_commits(struct super_block *s, struct reiserfs_journal_list *jl) {
834 struct reiserfs_journal *journal = SB_JOURNAL (s);
835 struct reiserfs_journal_list *other_jl;
836 struct reiserfs_journal_list *first_jl;
837 struct list_head *entry;
838 unsigned long trans_id = jl->j_trans_id;
839 unsigned long other_trans_id;
840 unsigned long first_trans_id;
841
842find_first:
843 /*
844 * first we walk backwards to find the oldest uncommitted transation
845 */
846 first_jl = jl;
847 entry = jl->j_list.prev;
848 while(1) {
849 other_jl = JOURNAL_LIST_ENTRY(entry);
850 if (entry == &journal->j_journal_list ||
851 atomic_read(&other_jl->j_older_commits_done))
852 break;
853
854 first_jl = other_jl;
855 entry = other_jl->j_list.prev;
856 }
857
858 /* if we didn't find any older uncommitted transactions, return now */
859 if (first_jl == jl) {
860 return 0;
861 }
862
863 first_trans_id = first_jl->j_trans_id;
864 888
865 entry = &first_jl->j_list; 889static int flush_older_commits(struct super_block *s,
866 while(1) { 890 struct reiserfs_journal_list *jl)
867 other_jl = JOURNAL_LIST_ENTRY(entry); 891{
868 other_trans_id = other_jl->j_trans_id; 892 struct reiserfs_journal *journal = SB_JOURNAL(s);
893 struct reiserfs_journal_list *other_jl;
894 struct reiserfs_journal_list *first_jl;
895 struct list_head *entry;
896 unsigned long trans_id = jl->j_trans_id;
897 unsigned long other_trans_id;
898 unsigned long first_trans_id;
899
900 find_first:
901 /*
902 * first we walk backwards to find the oldest uncommitted transation
903 */
904 first_jl = jl;
905 entry = jl->j_list.prev;
906 while (1) {
907 other_jl = JOURNAL_LIST_ENTRY(entry);
908 if (entry == &journal->j_journal_list ||
909 atomic_read(&other_jl->j_older_commits_done))
910 break;
869 911
870 if (other_trans_id < trans_id) { 912 first_jl = other_jl;
871 if (atomic_read(&other_jl->j_commit_left) != 0) { 913 entry = other_jl->j_list.prev;
872 flush_commit_list(s, other_jl, 0); 914 }
873 915
874 /* list we were called with is gone, return */ 916 /* if we didn't find any older uncommitted transactions, return now */
875 if (!journal_list_still_alive(s, trans_id)) 917 if (first_jl == jl) {
876 return 1; 918 return 0;
919 }
877 920
878 /* the one we just flushed is gone, this means all 921 first_trans_id = first_jl->j_trans_id;
879 * older lists are also gone, so first_jl is no longer 922
880 * valid either. Go back to the beginning. 923 entry = &first_jl->j_list;
881 */ 924 while (1) {
882 if (!journal_list_still_alive(s, other_trans_id)) { 925 other_jl = JOURNAL_LIST_ENTRY(entry);
883 goto find_first; 926 other_trans_id = other_jl->j_trans_id;
927
928 if (other_trans_id < trans_id) {
929 if (atomic_read(&other_jl->j_commit_left) != 0) {
930 flush_commit_list(s, other_jl, 0);
931
932 /* list we were called with is gone, return */
933 if (!journal_list_still_alive(s, trans_id))
934 return 1;
935
936 /* the one we just flushed is gone, this means all
937 * older lists are also gone, so first_jl is no longer
938 * valid either. Go back to the beginning.
939 */
940 if (!journal_list_still_alive
941 (s, other_trans_id)) {
942 goto find_first;
943 }
944 }
945 entry = entry->next;
946 if (entry == &journal->j_journal_list)
947 return 0;
948 } else {
949 return 0;
884 } 950 }
885 }
886 entry = entry->next;
887 if (entry == &journal->j_journal_list)
888 return 0;
889 } else {
890 return 0;
891 } 951 }
892 } 952 return 0;
893 return 0;
894} 953}
895int reiserfs_async_progress_wait(struct super_block *s) { 954int reiserfs_async_progress_wait(struct super_block *s)
896 DEFINE_WAIT(wait); 955{
897 struct reiserfs_journal *j = SB_JOURNAL(s); 956 DEFINE_WAIT(wait);
898 if (atomic_read(&j->j_async_throttle)) 957 struct reiserfs_journal *j = SB_JOURNAL(s);
899 blk_congestion_wait(WRITE, HZ/10); 958 if (atomic_read(&j->j_async_throttle))
900 return 0; 959 blk_congestion_wait(WRITE, HZ / 10);
960 return 0;
901} 961}
902 962
903/* 963/*
@@ -907,212 +967,225 @@ int reiserfs_async_progress_wait(struct super_block *s) {
907** Before the commit block can by written, every other log block must be safely on disk 967** Before the commit block can by written, every other log block must be safely on disk
908** 968**
909*/ 969*/
910static int flush_commit_list(struct super_block *s, struct reiserfs_journal_list *jl, int flushall) { 970static int flush_commit_list(struct super_block *s,
911 int i; 971 struct reiserfs_journal_list *jl, int flushall)
912 int bn ; 972{
913 struct buffer_head *tbh = NULL ; 973 int i;
914 unsigned long trans_id = jl->j_trans_id; 974 int bn;
915 struct reiserfs_journal *journal = SB_JOURNAL (s); 975 struct buffer_head *tbh = NULL;
916 int barrier = 0; 976 unsigned long trans_id = jl->j_trans_id;
917 int retval = 0; 977 struct reiserfs_journal *journal = SB_JOURNAL(s);
918 978 int barrier = 0;
919 reiserfs_check_lock_depth(s, "flush_commit_list") ; 979 int retval = 0;
920 980
921 if (atomic_read(&jl->j_older_commits_done)) { 981 reiserfs_check_lock_depth(s, "flush_commit_list");
922 return 0 ; 982
923 } 983 if (atomic_read(&jl->j_older_commits_done)) {
924 984 return 0;
925 get_fs_excl(); 985 }
926 986
927 /* before we can put our commit blocks on disk, we have to make sure everyone older than 987 get_fs_excl();
928 ** us is on disk too 988
929 */ 989 /* before we can put our commit blocks on disk, we have to make sure everyone older than
930 BUG_ON (jl->j_len <= 0); 990 ** us is on disk too
931 BUG_ON (trans_id == journal->j_trans_id); 991 */
932 992 BUG_ON(jl->j_len <= 0);
933 get_journal_list(jl); 993 BUG_ON(trans_id == journal->j_trans_id);
934 if (flushall) { 994
935 if (flush_older_commits(s, jl) == 1) { 995 get_journal_list(jl);
936 /* list disappeared during flush_older_commits. return */ 996 if (flushall) {
937 goto put_jl; 997 if (flush_older_commits(s, jl) == 1) {
938 } 998 /* list disappeared during flush_older_commits. return */
939 } 999 goto put_jl;
940 1000 }
941 /* make sure nobody is trying to flush this one at the same time */ 1001 }
942 down(&jl->j_commit_lock); 1002
943 if (!journal_list_still_alive(s, trans_id)) { 1003 /* make sure nobody is trying to flush this one at the same time */
944 up(&jl->j_commit_lock); 1004 down(&jl->j_commit_lock);
945 goto put_jl; 1005 if (!journal_list_still_alive(s, trans_id)) {
946 } 1006 up(&jl->j_commit_lock);
947 BUG_ON (jl->j_trans_id == 0); 1007 goto put_jl;
948 1008 }
949 /* this commit is done, exit */ 1009 BUG_ON(jl->j_trans_id == 0);
950 if (atomic_read(&(jl->j_commit_left)) <= 0) { 1010
951 if (flushall) { 1011 /* this commit is done, exit */
952 atomic_set(&(jl->j_older_commits_done), 1) ; 1012 if (atomic_read(&(jl->j_commit_left)) <= 0) {
953 } 1013 if (flushall) {
954 up(&jl->j_commit_lock); 1014 atomic_set(&(jl->j_older_commits_done), 1);
955 goto put_jl; 1015 }
956 } 1016 up(&jl->j_commit_lock);
957 1017 goto put_jl;
958 if (!list_empty(&jl->j_bh_list)) { 1018 }
959 unlock_kernel(); 1019
960 write_ordered_buffers(&journal->j_dirty_buffers_lock, 1020 if (!list_empty(&jl->j_bh_list)) {
961 journal, jl, &jl->j_bh_list); 1021 unlock_kernel();
962 lock_kernel(); 1022 write_ordered_buffers(&journal->j_dirty_buffers_lock,
963 } 1023 journal, jl, &jl->j_bh_list);
964 BUG_ON (!list_empty(&jl->j_bh_list)); 1024 lock_kernel();
965 /* 1025 }
966 * for the description block and all the log blocks, submit any buffers 1026 BUG_ON(!list_empty(&jl->j_bh_list));
967 * that haven't already reached the disk 1027 /*
968 */ 1028 * for the description block and all the log blocks, submit any buffers
969 atomic_inc(&journal->j_async_throttle); 1029 * that haven't already reached the disk
970 for (i = 0 ; i < (jl->j_len + 1) ; i++) { 1030 */
971 bn = SB_ONDISK_JOURNAL_1st_BLOCK(s) + (jl->j_start+i) % 1031 atomic_inc(&journal->j_async_throttle);
972 SB_ONDISK_JOURNAL_SIZE(s); 1032 for (i = 0; i < (jl->j_len + 1); i++) {
973 tbh = journal_find_get_block(s, bn) ; 1033 bn = SB_ONDISK_JOURNAL_1st_BLOCK(s) + (jl->j_start + i) %
974 if (buffer_dirty(tbh)) /* redundant, ll_rw_block() checks */ 1034 SB_ONDISK_JOURNAL_SIZE(s);
975 ll_rw_block(WRITE, 1, &tbh) ; 1035 tbh = journal_find_get_block(s, bn);
976 put_bh(tbh) ; 1036 if (buffer_dirty(tbh)) /* redundant, ll_rw_block() checks */
977 } 1037 ll_rw_block(WRITE, 1, &tbh);
978 atomic_dec(&journal->j_async_throttle); 1038 put_bh(tbh);
979 1039 }
980 /* wait on everything written so far before writing the commit 1040 atomic_dec(&journal->j_async_throttle);
981 * if we are in barrier mode, send the commit down now 1041
982 */ 1042 /* wait on everything written so far before writing the commit
983 barrier = reiserfs_barrier_flush(s); 1043 * if we are in barrier mode, send the commit down now
984 if (barrier) { 1044 */
985 int ret; 1045 barrier = reiserfs_barrier_flush(s);
986 lock_buffer(jl->j_commit_bh); 1046 if (barrier) {
987 ret = submit_barrier_buffer(jl->j_commit_bh); 1047 int ret;
988 if (ret == -EOPNOTSUPP) { 1048 lock_buffer(jl->j_commit_bh);
989 set_buffer_uptodate(jl->j_commit_bh); 1049 ret = submit_barrier_buffer(jl->j_commit_bh);
990 disable_barrier(s); 1050 if (ret == -EOPNOTSUPP) {
991 barrier = 0; 1051 set_buffer_uptodate(jl->j_commit_bh);
992 } 1052 disable_barrier(s);
993 } 1053 barrier = 0;
994 for (i = 0 ; i < (jl->j_len + 1) ; i++) { 1054 }
995 bn = SB_ONDISK_JOURNAL_1st_BLOCK(s) + 1055 }
996 (jl->j_start + i) % SB_ONDISK_JOURNAL_SIZE(s) ; 1056 for (i = 0; i < (jl->j_len + 1); i++) {
997 tbh = journal_find_get_block(s, bn) ; 1057 bn = SB_ONDISK_JOURNAL_1st_BLOCK(s) +
998 wait_on_buffer(tbh) ; 1058 (jl->j_start + i) % SB_ONDISK_JOURNAL_SIZE(s);
999 // since we're using ll_rw_blk above, it might have skipped over 1059 tbh = journal_find_get_block(s, bn);
1000 // a locked buffer. Double check here 1060 wait_on_buffer(tbh);
1001 // 1061 // since we're using ll_rw_blk above, it might have skipped over
1002 if (buffer_dirty(tbh)) /* redundant, sync_dirty_buffer() checks */ 1062 // a locked buffer. Double check here
1003 sync_dirty_buffer(tbh); 1063 //
1004 if (unlikely (!buffer_uptodate(tbh))) { 1064 if (buffer_dirty(tbh)) /* redundant, sync_dirty_buffer() checks */
1065 sync_dirty_buffer(tbh);
1066 if (unlikely(!buffer_uptodate(tbh))) {
1005#ifdef CONFIG_REISERFS_CHECK 1067#ifdef CONFIG_REISERFS_CHECK
1006 reiserfs_warning(s, "journal-601, buffer write failed") ; 1068 reiserfs_warning(s, "journal-601, buffer write failed");
1007#endif 1069#endif
1008 retval = -EIO; 1070 retval = -EIO;
1009 } 1071 }
1010 put_bh(tbh) ; /* once for journal_find_get_block */ 1072 put_bh(tbh); /* once for journal_find_get_block */
1011 put_bh(tbh) ; /* once due to original getblk in do_journal_end */ 1073 put_bh(tbh); /* once due to original getblk in do_journal_end */
1012 atomic_dec(&(jl->j_commit_left)) ; 1074 atomic_dec(&(jl->j_commit_left));
1013 } 1075 }
1014 1076
1015 BUG_ON (atomic_read(&(jl->j_commit_left)) != 1); 1077 BUG_ON(atomic_read(&(jl->j_commit_left)) != 1);
1016 1078
1017 if (!barrier) { 1079 if (!barrier) {
1018 if (buffer_dirty(jl->j_commit_bh)) 1080 if (buffer_dirty(jl->j_commit_bh))
1019 BUG(); 1081 BUG();
1020 mark_buffer_dirty(jl->j_commit_bh) ; 1082 mark_buffer_dirty(jl->j_commit_bh);
1021 sync_dirty_buffer(jl->j_commit_bh) ; 1083 sync_dirty_buffer(jl->j_commit_bh);
1022 } else 1084 } else
1023 wait_on_buffer(jl->j_commit_bh); 1085 wait_on_buffer(jl->j_commit_bh);
1024 1086
1025 check_barrier_completion(s, jl->j_commit_bh); 1087 check_barrier_completion(s, jl->j_commit_bh);
1026 1088
1027 /* If there was a write error in the journal - we can't commit this 1089 /* If there was a write error in the journal - we can't commit this
1028 * transaction - it will be invalid and, if successful, will just end 1090 * transaction - it will be invalid and, if successful, will just end
1029 * up propogating the write error out to the filesystem. */ 1091 * up propogating the write error out to the filesystem. */
1030 if (unlikely (!buffer_uptodate(jl->j_commit_bh))) { 1092 if (unlikely(!buffer_uptodate(jl->j_commit_bh))) {
1031#ifdef CONFIG_REISERFS_CHECK 1093#ifdef CONFIG_REISERFS_CHECK
1032 reiserfs_warning(s, "journal-615: buffer write failed") ; 1094 reiserfs_warning(s, "journal-615: buffer write failed");
1033#endif 1095#endif
1034 retval = -EIO; 1096 retval = -EIO;
1035 } 1097 }
1036 bforget(jl->j_commit_bh) ; 1098 bforget(jl->j_commit_bh);
1037 if (journal->j_last_commit_id != 0 && 1099 if (journal->j_last_commit_id != 0 &&
1038 (jl->j_trans_id - journal->j_last_commit_id) != 1) { 1100 (jl->j_trans_id - journal->j_last_commit_id) != 1) {
1039 reiserfs_warning(s, "clm-2200: last commit %lu, current %lu", 1101 reiserfs_warning(s, "clm-2200: last commit %lu, current %lu",
1040 journal->j_last_commit_id, 1102 journal->j_last_commit_id, jl->j_trans_id);
1041 jl->j_trans_id); 1103 }
1042 } 1104 journal->j_last_commit_id = jl->j_trans_id;
1043 journal->j_last_commit_id = jl->j_trans_id; 1105
1044 1106 /* now, every commit block is on the disk. It is safe to allow blocks freed during this transaction to be reallocated */
1045 /* now, every commit block is on the disk. It is safe to allow blocks freed during this transaction to be reallocated */ 1107 cleanup_freed_for_journal_list(s, jl);
1046 cleanup_freed_for_journal_list(s, jl) ; 1108
1047 1109 retval = retval ? retval : journal->j_errno;
1048 retval = retval ? retval : journal->j_errno; 1110
1049 1111 /* mark the metadata dirty */
1050 /* mark the metadata dirty */ 1112 if (!retval)
1051 if (!retval) 1113 dirty_one_transaction(s, jl);
1052 dirty_one_transaction(s, jl); 1114 atomic_dec(&(jl->j_commit_left));
1053 atomic_dec(&(jl->j_commit_left)) ; 1115
1054 1116 if (flushall) {
1055 if (flushall) { 1117 atomic_set(&(jl->j_older_commits_done), 1);
1056 atomic_set(&(jl->j_older_commits_done), 1) ; 1118 }
1057 } 1119 up(&jl->j_commit_lock);
1058 up(&jl->j_commit_lock); 1120 put_jl:
1059put_jl: 1121 put_journal_list(s, jl);
1060 put_journal_list(s, jl); 1122
1061 1123 if (retval)
1062 if (retval) 1124 reiserfs_abort(s, retval, "Journal write error in %s",
1063 reiserfs_abort (s, retval, "Journal write error in %s", __FUNCTION__); 1125 __FUNCTION__);
1064 put_fs_excl(); 1126 put_fs_excl();
1065 return retval; 1127 return retval;
1066} 1128}
1067 1129
1068/* 1130/*
1069** flush_journal_list frequently needs to find a newer transaction for a given block. This does that, or 1131** flush_journal_list frequently needs to find a newer transaction for a given block. This does that, or
1070** returns NULL if it can't find anything 1132** returns NULL if it can't find anything
1071*/ 1133*/
1072static struct reiserfs_journal_list *find_newer_jl_for_cn(struct reiserfs_journal_cnode *cn) { 1134static struct reiserfs_journal_list *find_newer_jl_for_cn(struct
1073 struct super_block *sb = cn->sb; 1135 reiserfs_journal_cnode
1074 b_blocknr_t blocknr = cn->blocknr ; 1136 *cn)
1137{
1138 struct super_block *sb = cn->sb;
1139 b_blocknr_t blocknr = cn->blocknr;
1075 1140
1076 cn = cn->hprev ; 1141 cn = cn->hprev;
1077 while(cn) { 1142 while (cn) {
1078 if (cn->sb == sb && cn->blocknr == blocknr && cn->jlist) { 1143 if (cn->sb == sb && cn->blocknr == blocknr && cn->jlist) {
1079 return cn->jlist ; 1144 return cn->jlist;
1080 } 1145 }
1081 cn = cn->hprev ; 1146 cn = cn->hprev;
1082 } 1147 }
1083 return NULL ; 1148 return NULL;
1084} 1149}
1085 1150
1086static void remove_journal_hash(struct super_block *, struct reiserfs_journal_cnode **, 1151static void remove_journal_hash(struct super_block *,
1087struct reiserfs_journal_list *, unsigned long, int); 1152 struct reiserfs_journal_cnode **,
1153 struct reiserfs_journal_list *, unsigned long,
1154 int);
1088 1155
1089/* 1156/*
1090** once all the real blocks have been flushed, it is safe to remove them from the 1157** once all the real blocks have been flushed, it is safe to remove them from the
1091** journal list for this transaction. Aside from freeing the cnode, this also allows the 1158** journal list for this transaction. Aside from freeing the cnode, this also allows the
1092** block to be reallocated for data blocks if it had been deleted. 1159** block to be reallocated for data blocks if it had been deleted.
1093*/ 1160*/
1094static void remove_all_from_journal_list(struct super_block *p_s_sb, struct reiserfs_journal_list *jl, int debug) { 1161static void remove_all_from_journal_list(struct super_block *p_s_sb,
1095 struct reiserfs_journal *journal = SB_JOURNAL (p_s_sb); 1162 struct reiserfs_journal_list *jl,
1096 struct reiserfs_journal_cnode *cn, *last ; 1163 int debug)
1097 cn = jl->j_realblock ; 1164{
1098 1165 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb);
1099 /* which is better, to lock once around the whole loop, or 1166 struct reiserfs_journal_cnode *cn, *last;
1100 ** to lock for each call to remove_journal_hash? 1167 cn = jl->j_realblock;
1101 */ 1168
1102 while(cn) { 1169 /* which is better, to lock once around the whole loop, or
1103 if (cn->blocknr != 0) { 1170 ** to lock for each call to remove_journal_hash?
1104 if (debug) { 1171 */
1105 reiserfs_warning (p_s_sb, "block %u, bh is %d, state %ld", cn->blocknr, 1172 while (cn) {
1106 cn->bh ? 1: 0, cn->state) ; 1173 if (cn->blocknr != 0) {
1107 } 1174 if (debug) {
1108 cn->state = 0 ; 1175 reiserfs_warning(p_s_sb,
1109 remove_journal_hash(p_s_sb, journal->j_list_hash_table, jl, cn->blocknr, 1) ; 1176 "block %u, bh is %d, state %ld",
1110 } 1177 cn->blocknr, cn->bh ? 1 : 0,
1111 last = cn ; 1178 cn->state);
1112 cn = cn->next ; 1179 }
1113 free_cnode(p_s_sb, last) ; 1180 cn->state = 0;
1114 } 1181 remove_journal_hash(p_s_sb, journal->j_list_hash_table,
1115 jl->j_realblock = NULL ; 1182 jl, cn->blocknr, 1);
1183 }
1184 last = cn;
1185 cn = cn->next;
1186 free_cnode(p_s_sb, last);
1187 }
1188 jl->j_realblock = NULL;
1116} 1189}
1117 1190
1118/* 1191/*
@@ -1122,98 +1195,107 @@ static void remove_all_from_journal_list(struct super_block *p_s_sb, struct reis
1122** called by flush_journal_list, before it calls remove_all_from_journal_list 1195** called by flush_journal_list, before it calls remove_all_from_journal_list
1123** 1196**
1124*/ 1197*/
1125static int _update_journal_header_block(struct super_block *p_s_sb, unsigned long offset, unsigned long trans_id) { 1198static int _update_journal_header_block(struct super_block *p_s_sb,
1126 struct reiserfs_journal_header *jh ; 1199 unsigned long offset,
1127 struct reiserfs_journal *journal = SB_JOURNAL (p_s_sb); 1200 unsigned long trans_id)
1201{
1202 struct reiserfs_journal_header *jh;
1203 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb);
1128 1204
1129 if (reiserfs_is_journal_aborted (journal)) 1205 if (reiserfs_is_journal_aborted(journal))
1130 return -EIO; 1206 return -EIO;
1131 1207
1132 if (trans_id >= journal->j_last_flush_trans_id) { 1208 if (trans_id >= journal->j_last_flush_trans_id) {
1133 if (buffer_locked((journal->j_header_bh))) { 1209 if (buffer_locked((journal->j_header_bh))) {
1134 wait_on_buffer((journal->j_header_bh)) ; 1210 wait_on_buffer((journal->j_header_bh));
1135 if (unlikely (!buffer_uptodate(journal->j_header_bh))) { 1211 if (unlikely(!buffer_uptodate(journal->j_header_bh))) {
1136#ifdef CONFIG_REISERFS_CHECK 1212#ifdef CONFIG_REISERFS_CHECK
1137 reiserfs_warning (p_s_sb, "journal-699: buffer write failed") ; 1213 reiserfs_warning(p_s_sb,
1214 "journal-699: buffer write failed");
1138#endif 1215#endif
1139 return -EIO; 1216 return -EIO;
1140 } 1217 }
1141 } 1218 }
1142 journal->j_last_flush_trans_id = trans_id ; 1219 journal->j_last_flush_trans_id = trans_id;
1143 journal->j_first_unflushed_offset = offset ; 1220 journal->j_first_unflushed_offset = offset;
1144 jh = (struct reiserfs_journal_header *)(journal->j_header_bh->b_data) ; 1221 jh = (struct reiserfs_journal_header *)(journal->j_header_bh->
1145 jh->j_last_flush_trans_id = cpu_to_le32(trans_id) ; 1222 b_data);
1146 jh->j_first_unflushed_offset = cpu_to_le32(offset) ; 1223 jh->j_last_flush_trans_id = cpu_to_le32(trans_id);
1147 jh->j_mount_id = cpu_to_le32(journal->j_mount_id) ; 1224 jh->j_first_unflushed_offset = cpu_to_le32(offset);
1148 1225 jh->j_mount_id = cpu_to_le32(journal->j_mount_id);
1149 if (reiserfs_barrier_flush(p_s_sb)) { 1226
1150 int ret; 1227 if (reiserfs_barrier_flush(p_s_sb)) {
1151 lock_buffer(journal->j_header_bh); 1228 int ret;
1152 ret = submit_barrier_buffer(journal->j_header_bh); 1229 lock_buffer(journal->j_header_bh);
1153 if (ret == -EOPNOTSUPP) { 1230 ret = submit_barrier_buffer(journal->j_header_bh);
1154 set_buffer_uptodate(journal->j_header_bh); 1231 if (ret == -EOPNOTSUPP) {
1155 disable_barrier(p_s_sb); 1232 set_buffer_uptodate(journal->j_header_bh);
1156 goto sync; 1233 disable_barrier(p_s_sb);
1157 } 1234 goto sync;
1158 wait_on_buffer(journal->j_header_bh); 1235 }
1159 check_barrier_completion(p_s_sb, journal->j_header_bh); 1236 wait_on_buffer(journal->j_header_bh);
1160 } else { 1237 check_barrier_completion(p_s_sb, journal->j_header_bh);
1161sync: 1238 } else {
1162 set_buffer_dirty(journal->j_header_bh) ; 1239 sync:
1163 sync_dirty_buffer(journal->j_header_bh) ; 1240 set_buffer_dirty(journal->j_header_bh);
1164 } 1241 sync_dirty_buffer(journal->j_header_bh);
1165 if (!buffer_uptodate(journal->j_header_bh)) { 1242 }
1166 reiserfs_warning (p_s_sb, "journal-837: IO error during journal replay"); 1243 if (!buffer_uptodate(journal->j_header_bh)) {
1167 return -EIO ; 1244 reiserfs_warning(p_s_sb,
1168 } 1245 "journal-837: IO error during journal replay");
1169 } 1246 return -EIO;
1170 return 0 ; 1247 }
1171} 1248 }
1172 1249 return 0;
1173static int update_journal_header_block(struct super_block *p_s_sb,
1174 unsigned long offset,
1175 unsigned long trans_id) {
1176 return _update_journal_header_block(p_s_sb, offset, trans_id);
1177} 1250}
1251
1252static int update_journal_header_block(struct super_block *p_s_sb,
1253 unsigned long offset,
1254 unsigned long trans_id)
1255{
1256 return _update_journal_header_block(p_s_sb, offset, trans_id);
1257}
1258
1178/* 1259/*
1179** flush any and all journal lists older than you are 1260** flush any and all journal lists older than you are
1180** can only be called from flush_journal_list 1261** can only be called from flush_journal_list
1181*/ 1262*/
1182static int flush_older_journal_lists(struct super_block *p_s_sb, 1263static int flush_older_journal_lists(struct super_block *p_s_sb,
1183 struct reiserfs_journal_list *jl) 1264 struct reiserfs_journal_list *jl)
1184{ 1265{
1185 struct list_head *entry; 1266 struct list_head *entry;
1186 struct reiserfs_journal_list *other_jl ; 1267 struct reiserfs_journal_list *other_jl;
1187 struct reiserfs_journal *journal = SB_JOURNAL (p_s_sb); 1268 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb);
1188 unsigned long trans_id = jl->j_trans_id; 1269 unsigned long trans_id = jl->j_trans_id;
1189 1270
1190 /* we know we are the only ones flushing things, no extra race 1271 /* we know we are the only ones flushing things, no extra race
1191 * protection is required. 1272 * protection is required.
1192 */ 1273 */
1193restart: 1274 restart:
1194 entry = journal->j_journal_list.next; 1275 entry = journal->j_journal_list.next;
1195 /* Did we wrap? */ 1276 /* Did we wrap? */
1196 if (entry == &journal->j_journal_list) 1277 if (entry == &journal->j_journal_list)
1197 return 0; 1278 return 0;
1198 other_jl = JOURNAL_LIST_ENTRY(entry); 1279 other_jl = JOURNAL_LIST_ENTRY(entry);
1199 if (other_jl->j_trans_id < trans_id) { 1280 if (other_jl->j_trans_id < trans_id) {
1200 BUG_ON (other_jl->j_refcount <= 0); 1281 BUG_ON(other_jl->j_refcount <= 0);
1201 /* do not flush all */ 1282 /* do not flush all */
1202 flush_journal_list(p_s_sb, other_jl, 0) ; 1283 flush_journal_list(p_s_sb, other_jl, 0);
1203 1284
1204 /* other_jl is now deleted from the list */ 1285 /* other_jl is now deleted from the list */
1205 goto restart; 1286 goto restart;
1206 } 1287 }
1207 return 0 ; 1288 return 0;
1208} 1289}
1209 1290
1210static void del_from_work_list(struct super_block *s, 1291static void del_from_work_list(struct super_block *s,
1211 struct reiserfs_journal_list *jl) { 1292 struct reiserfs_journal_list *jl)
1212 struct reiserfs_journal *journal = SB_JOURNAL (s); 1293{
1213 if (!list_empty(&jl->j_working_list)) { 1294 struct reiserfs_journal *journal = SB_JOURNAL(s);
1214 list_del_init(&jl->j_working_list); 1295 if (!list_empty(&jl->j_working_list)) {
1215 journal->j_num_work_lists--; 1296 list_del_init(&jl->j_working_list);
1216 } 1297 journal->j_num_work_lists--;
1298 }
1217} 1299}
1218 1300
1219/* flush a journal list, both commit and real blocks 1301/* flush a journal list, both commit and real blocks
@@ -1225,386 +1307,407 @@ static void del_from_work_list(struct super_block *s,
1225** and the journal is locked. That means it can only be called from 1307** and the journal is locked. That means it can only be called from
1226** do_journal_end, or by journal_release 1308** do_journal_end, or by journal_release
1227*/ 1309*/
1228static int flush_journal_list(struct super_block *s, 1310static int flush_journal_list(struct super_block *s,
1229 struct reiserfs_journal_list *jl, int flushall) { 1311 struct reiserfs_journal_list *jl, int flushall)
1230 struct reiserfs_journal_list *pjl ; 1312{
1231 struct reiserfs_journal_cnode *cn, *last ; 1313 struct reiserfs_journal_list *pjl;
1232 int count ; 1314 struct reiserfs_journal_cnode *cn, *last;
1233 int was_jwait = 0 ; 1315 int count;
1234 int was_dirty = 0 ; 1316 int was_jwait = 0;
1235 struct buffer_head *saved_bh ; 1317 int was_dirty = 0;
1236 unsigned long j_len_saved = jl->j_len ; 1318 struct buffer_head *saved_bh;
1237 struct reiserfs_journal *journal = SB_JOURNAL (s); 1319 unsigned long j_len_saved = jl->j_len;
1238 int err = 0; 1320 struct reiserfs_journal *journal = SB_JOURNAL(s);
1239 1321 int err = 0;
1240 BUG_ON (j_len_saved <= 0); 1322
1241 1323 BUG_ON(j_len_saved <= 0);
1242 if (atomic_read(&journal->j_wcount) != 0) { 1324
1243 reiserfs_warning(s, "clm-2048: flush_journal_list called with wcount %d", 1325 if (atomic_read(&journal->j_wcount) != 0) {
1244 atomic_read(&journal->j_wcount)) ; 1326 reiserfs_warning(s,
1245 } 1327 "clm-2048: flush_journal_list called with wcount %d",
1246 BUG_ON (jl->j_trans_id == 0); 1328 atomic_read(&journal->j_wcount));
1247 1329 }
1248 /* if flushall == 0, the lock is already held */ 1330 BUG_ON(jl->j_trans_id == 0);
1249 if (flushall) { 1331
1250 down(&journal->j_flush_sem); 1332 /* if flushall == 0, the lock is already held */
1251 } else if (!down_trylock(&journal->j_flush_sem)) { 1333 if (flushall) {
1252 BUG(); 1334 down(&journal->j_flush_sem);
1253 } 1335 } else if (!down_trylock(&journal->j_flush_sem)) {
1254 1336 BUG();
1255 count = 0 ; 1337 }
1256 if (j_len_saved > journal->j_trans_max) { 1338
1257 reiserfs_panic(s, "journal-715: flush_journal_list, length is %lu, trans id %lu\n", j_len_saved, jl->j_trans_id); 1339 count = 0;
1258 return 0 ; 1340 if (j_len_saved > journal->j_trans_max) {
1259 } 1341 reiserfs_panic(s,
1260 1342 "journal-715: flush_journal_list, length is %lu, trans id %lu\n",
1261 get_fs_excl(); 1343 j_len_saved, jl->j_trans_id);
1262 1344 return 0;
1263 /* if all the work is already done, get out of here */ 1345 }
1264 if (atomic_read(&(jl->j_nonzerolen)) <= 0 && 1346
1265 atomic_read(&(jl->j_commit_left)) <= 0) { 1347 get_fs_excl();
1266 goto flush_older_and_return ; 1348
1267 } 1349 /* if all the work is already done, get out of here */
1268 1350 if (atomic_read(&(jl->j_nonzerolen)) <= 0 &&
1269 /* start by putting the commit list on disk. This will also flush 1351 atomic_read(&(jl->j_commit_left)) <= 0) {
1270 ** the commit lists of any olders transactions 1352 goto flush_older_and_return;
1271 */ 1353 }
1272 flush_commit_list(s, jl, 1) ; 1354
1273 1355 /* start by putting the commit list on disk. This will also flush
1274 if (!(jl->j_state & LIST_DIRTY) && !reiserfs_is_journal_aborted (journal)) 1356 ** the commit lists of any olders transactions
1275 BUG(); 1357 */
1276 1358 flush_commit_list(s, jl, 1);
1277 /* are we done now? */ 1359
1278 if (atomic_read(&(jl->j_nonzerolen)) <= 0 && 1360 if (!(jl->j_state & LIST_DIRTY)
1279 atomic_read(&(jl->j_commit_left)) <= 0) { 1361 && !reiserfs_is_journal_aborted(journal))
1280 goto flush_older_and_return ; 1362 BUG();
1281 } 1363
1282 1364 /* are we done now? */
1283 /* loop through each cnode, see if we need to write it, 1365 if (atomic_read(&(jl->j_nonzerolen)) <= 0 &&
1284 ** or wait on a more recent transaction, or just ignore it 1366 atomic_read(&(jl->j_commit_left)) <= 0) {
1285 */ 1367 goto flush_older_and_return;
1286 if (atomic_read(&(journal->j_wcount)) != 0) { 1368 }
1287 reiserfs_panic(s, "journal-844: panic journal list is flushing, wcount is not 0\n") ; 1369
1288 } 1370 /* loop through each cnode, see if we need to write it,
1289 cn = jl->j_realblock ; 1371 ** or wait on a more recent transaction, or just ignore it
1290 while(cn) { 1372 */
1291 was_jwait = 0 ; 1373 if (atomic_read(&(journal->j_wcount)) != 0) {
1292 was_dirty = 0 ; 1374 reiserfs_panic(s,
1293 saved_bh = NULL ; 1375 "journal-844: panic journal list is flushing, wcount is not 0\n");
1294 /* blocknr of 0 is no longer in the hash, ignore it */ 1376 }
1295 if (cn->blocknr == 0) { 1377 cn = jl->j_realblock;
1296 goto free_cnode ; 1378 while (cn) {
1297 } 1379 was_jwait = 0;
1298 1380 was_dirty = 0;
1299 /* This transaction failed commit. Don't write out to the disk */ 1381 saved_bh = NULL;
1300 if (!(jl->j_state & LIST_DIRTY)) 1382 /* blocknr of 0 is no longer in the hash, ignore it */
1301 goto free_cnode; 1383 if (cn->blocknr == 0) {
1302 1384 goto free_cnode;
1303 pjl = find_newer_jl_for_cn(cn) ; 1385 }
1304 /* the order is important here. We check pjl to make sure we 1386
1305 ** don't clear BH_JDirty_wait if we aren't the one writing this 1387 /* This transaction failed commit. Don't write out to the disk */
1306 ** block to disk 1388 if (!(jl->j_state & LIST_DIRTY))
1307 */ 1389 goto free_cnode;
1308 if (!pjl && cn->bh) { 1390
1309 saved_bh = cn->bh ; 1391 pjl = find_newer_jl_for_cn(cn);
1310 1392 /* the order is important here. We check pjl to make sure we
1311 /* we do this to make sure nobody releases the buffer while 1393 ** don't clear BH_JDirty_wait if we aren't the one writing this
1312 ** we are working with it 1394 ** block to disk
1313 */ 1395 */
1314 get_bh(saved_bh) ; 1396 if (!pjl && cn->bh) {
1315 1397 saved_bh = cn->bh;
1316 if (buffer_journal_dirty(saved_bh)) { 1398
1317 BUG_ON (!can_dirty (cn)); 1399 /* we do this to make sure nobody releases the buffer while
1318 was_jwait = 1 ; 1400 ** we are working with it
1319 was_dirty = 1 ; 1401 */
1320 } else if (can_dirty(cn)) { 1402 get_bh(saved_bh);
1321 /* everything with !pjl && jwait should be writable */ 1403
1322 BUG(); 1404 if (buffer_journal_dirty(saved_bh)) {
1323 } 1405 BUG_ON(!can_dirty(cn));
1324 } 1406 was_jwait = 1;
1325 1407 was_dirty = 1;
1326 /* if someone has this block in a newer transaction, just make 1408 } else if (can_dirty(cn)) {
1327 ** sure they are commited, and don't try writing it to disk 1409 /* everything with !pjl && jwait should be writable */
1328 */ 1410 BUG();
1329 if (pjl) { 1411 }
1330 if (atomic_read(&pjl->j_commit_left)) 1412 }
1331 flush_commit_list(s, pjl, 1) ; 1413
1332 goto free_cnode ; 1414 /* if someone has this block in a newer transaction, just make
1333 } 1415 ** sure they are commited, and don't try writing it to disk
1334 1416 */
1335 /* bh == NULL when the block got to disk on its own, OR, 1417 if (pjl) {
1336 ** the block got freed in a future transaction 1418 if (atomic_read(&pjl->j_commit_left))
1337 */ 1419 flush_commit_list(s, pjl, 1);
1338 if (saved_bh == NULL) { 1420 goto free_cnode;
1339 goto free_cnode ; 1421 }
1340 } 1422
1341 1423 /* bh == NULL when the block got to disk on its own, OR,
1342 /* this should never happen. kupdate_one_transaction has this list 1424 ** the block got freed in a future transaction
1343 ** locked while it works, so we should never see a buffer here that 1425 */
1344 ** is not marked JDirty_wait 1426 if (saved_bh == NULL) {
1345 */ 1427 goto free_cnode;
1346 if ((!was_jwait) && !buffer_locked(saved_bh)) { 1428 }
1347 reiserfs_warning (s, "journal-813: BAD! buffer %llu %cdirty %cjwait, " 1429
1348 "not in a newer tranasction", 1430 /* this should never happen. kupdate_one_transaction has this list
1349 (unsigned long long)saved_bh->b_blocknr, 1431 ** locked while it works, so we should never see a buffer here that
1350 was_dirty ? ' ' : '!', was_jwait ? ' ' : '!') ; 1432 ** is not marked JDirty_wait
1351 } 1433 */
1352 if (was_dirty) { 1434 if ((!was_jwait) && !buffer_locked(saved_bh)) {
1353 /* we inc again because saved_bh gets decremented at free_cnode */ 1435 reiserfs_warning(s,
1354 get_bh(saved_bh) ; 1436 "journal-813: BAD! buffer %llu %cdirty %cjwait, "
1355 set_bit(BLOCK_NEEDS_FLUSH, &cn->state) ; 1437 "not in a newer tranasction",
1356 lock_buffer(saved_bh); 1438 (unsigned long long)saved_bh->
1357 BUG_ON (cn->blocknr != saved_bh->b_blocknr); 1439 b_blocknr, was_dirty ? ' ' : '!',
1358 if (buffer_dirty(saved_bh)) 1440 was_jwait ? ' ' : '!');
1359 submit_logged_buffer(saved_bh) ; 1441 }
1360 else 1442 if (was_dirty) {
1361 unlock_buffer(saved_bh); 1443 /* we inc again because saved_bh gets decremented at free_cnode */
1362 count++ ; 1444 get_bh(saved_bh);
1363 } else { 1445 set_bit(BLOCK_NEEDS_FLUSH, &cn->state);
1364 reiserfs_warning (s, "clm-2082: Unable to flush buffer %llu in %s", 1446 lock_buffer(saved_bh);
1365 (unsigned long long)saved_bh->b_blocknr, __FUNCTION__); 1447 BUG_ON(cn->blocknr != saved_bh->b_blocknr);
1366 } 1448 if (buffer_dirty(saved_bh))
1367free_cnode: 1449 submit_logged_buffer(saved_bh);
1368 last = cn ; 1450 else
1369 cn = cn->next ; 1451 unlock_buffer(saved_bh);
1370 if (saved_bh) { 1452 count++;
1371 /* we incremented this to keep others from taking the buffer head away */ 1453 } else {
1372 put_bh(saved_bh) ; 1454 reiserfs_warning(s,
1373 if (atomic_read(&(saved_bh->b_count)) < 0) { 1455 "clm-2082: Unable to flush buffer %llu in %s",
1374 reiserfs_warning (s, "journal-945: saved_bh->b_count < 0"); 1456 (unsigned long long)saved_bh->
1375 } 1457 b_blocknr, __FUNCTION__);
1376 } 1458 }
1377 } 1459 free_cnode:
1378 if (count > 0) { 1460 last = cn;
1379 cn = jl->j_realblock ; 1461 cn = cn->next;
1380 while(cn) { 1462 if (saved_bh) {
1381 if (test_bit(BLOCK_NEEDS_FLUSH, &cn->state)) { 1463 /* we incremented this to keep others from taking the buffer head away */
1382 if (!cn->bh) { 1464 put_bh(saved_bh);
1383 reiserfs_panic(s, "journal-1011: cn->bh is NULL\n") ; 1465 if (atomic_read(&(saved_bh->b_count)) < 0) {
1384 } 1466 reiserfs_warning(s,
1385 wait_on_buffer(cn->bh) ; 1467 "journal-945: saved_bh->b_count < 0");
1386 if (!cn->bh) { 1468 }
1387 reiserfs_panic(s, "journal-1012: cn->bh is NULL\n") ; 1469 }
1388 } 1470 }
1389 if (unlikely (!buffer_uptodate(cn->bh))) { 1471 if (count > 0) {
1472 cn = jl->j_realblock;
1473 while (cn) {
1474 if (test_bit(BLOCK_NEEDS_FLUSH, &cn->state)) {
1475 if (!cn->bh) {
1476 reiserfs_panic(s,
1477 "journal-1011: cn->bh is NULL\n");
1478 }
1479 wait_on_buffer(cn->bh);
1480 if (!cn->bh) {
1481 reiserfs_panic(s,
1482 "journal-1012: cn->bh is NULL\n");
1483 }
1484 if (unlikely(!buffer_uptodate(cn->bh))) {
1390#ifdef CONFIG_REISERFS_CHECK 1485#ifdef CONFIG_REISERFS_CHECK
1391 reiserfs_warning(s, "journal-949: buffer write failed\n") ; 1486 reiserfs_warning(s,
1487 "journal-949: buffer write failed\n");
1392#endif 1488#endif
1393 err = -EIO; 1489 err = -EIO;
1394 } 1490 }
1395 /* note, we must clear the JDirty_wait bit after the up to date 1491 /* note, we must clear the JDirty_wait bit after the up to date
1396 ** check, otherwise we race against our flushpage routine 1492 ** check, otherwise we race against our flushpage routine
1397 */ 1493 */
1398 BUG_ON (!test_clear_buffer_journal_dirty (cn->bh)); 1494 BUG_ON(!test_clear_buffer_journal_dirty
1399 1495 (cn->bh));
1400 /* undo the inc from journal_mark_dirty */ 1496
1401 put_bh(cn->bh) ; 1497 /* undo the inc from journal_mark_dirty */
1402 brelse(cn->bh) ; 1498 put_bh(cn->bh);
1403 } 1499 brelse(cn->bh);
1404 cn = cn->next ; 1500 }
1405 } 1501 cn = cn->next;
1406 } 1502 }
1407 1503 }
1408 if (err) 1504
1409 reiserfs_abort (s, -EIO, "Write error while pushing transaction to disk in %s", __FUNCTION__); 1505 if (err)
1410flush_older_and_return: 1506 reiserfs_abort(s, -EIO,
1411 1507 "Write error while pushing transaction to disk in %s",
1412 1508 __FUNCTION__);
1413 /* before we can update the journal header block, we _must_ flush all 1509 flush_older_and_return:
1414 ** real blocks from all older transactions to disk. This is because 1510
1415 ** once the header block is updated, this transaction will not be 1511 /* before we can update the journal header block, we _must_ flush all
1416 ** replayed after a crash 1512 ** real blocks from all older transactions to disk. This is because
1417 */ 1513 ** once the header block is updated, this transaction will not be
1418 if (flushall) { 1514 ** replayed after a crash
1419 flush_older_journal_lists(s, jl); 1515 */
1420 } 1516 if (flushall) {
1421 1517 flush_older_journal_lists(s, jl);
1422 err = journal->j_errno; 1518 }
1423 /* before we can remove everything from the hash tables for this 1519
1424 ** transaction, we must make sure it can never be replayed 1520 err = journal->j_errno;
1425 ** 1521 /* before we can remove everything from the hash tables for this
1426 ** since we are only called from do_journal_end, we know for sure there 1522 ** transaction, we must make sure it can never be replayed
1427 ** are no allocations going on while we are flushing journal lists. So, 1523 **
1428 ** we only need to update the journal header block for the last list 1524 ** since we are only called from do_journal_end, we know for sure there
1429 ** being flushed 1525 ** are no allocations going on while we are flushing journal lists. So,
1430 */ 1526 ** we only need to update the journal header block for the last list
1431 if (!err && flushall) { 1527 ** being flushed
1432 err = update_journal_header_block(s, (jl->j_start + jl->j_len + 2) % SB_ONDISK_JOURNAL_SIZE(s), jl->j_trans_id) ; 1528 */
1433 if (err) 1529 if (!err && flushall) {
1434 reiserfs_abort (s, -EIO, "Write error while updating journal header in %s", __FUNCTION__); 1530 err =
1435 } 1531 update_journal_header_block(s,
1436 remove_all_from_journal_list(s, jl, 0) ; 1532 (jl->j_start + jl->j_len +
1437 list_del_init(&jl->j_list); 1533 2) % SB_ONDISK_JOURNAL_SIZE(s),
1438 journal->j_num_lists--; 1534 jl->j_trans_id);
1439 del_from_work_list(s, jl); 1535 if (err)
1440 1536 reiserfs_abort(s, -EIO,
1441 if (journal->j_last_flush_id != 0 && 1537 "Write error while updating journal header in %s",
1442 (jl->j_trans_id - journal->j_last_flush_id) != 1) { 1538 __FUNCTION__);
1443 reiserfs_warning(s, "clm-2201: last flush %lu, current %lu", 1539 }
1444 journal->j_last_flush_id, 1540 remove_all_from_journal_list(s, jl, 0);
1445 jl->j_trans_id); 1541 list_del_init(&jl->j_list);
1446 } 1542 journal->j_num_lists--;
1447 journal->j_last_flush_id = jl->j_trans_id; 1543 del_from_work_list(s, jl);
1448 1544
1449 /* not strictly required since we are freeing the list, but it should 1545 if (journal->j_last_flush_id != 0 &&
1450 * help find code using dead lists later on 1546 (jl->j_trans_id - journal->j_last_flush_id) != 1) {
1451 */ 1547 reiserfs_warning(s, "clm-2201: last flush %lu, current %lu",
1452 jl->j_len = 0 ; 1548 journal->j_last_flush_id, jl->j_trans_id);
1453 atomic_set(&(jl->j_nonzerolen), 0) ; 1549 }
1454 jl->j_start = 0 ; 1550 journal->j_last_flush_id = jl->j_trans_id;
1455 jl->j_realblock = NULL ; 1551
1456 jl->j_commit_bh = NULL ; 1552 /* not strictly required since we are freeing the list, but it should
1457 jl->j_trans_id = 0 ; 1553 * help find code using dead lists later on
1458 jl->j_state = 0; 1554 */
1459 put_journal_list(s, jl); 1555 jl->j_len = 0;
1460 if (flushall) 1556 atomic_set(&(jl->j_nonzerolen), 0);
1461 up(&journal->j_flush_sem); 1557 jl->j_start = 0;
1462 put_fs_excl(); 1558 jl->j_realblock = NULL;
1463 return err ; 1559 jl->j_commit_bh = NULL;
1464} 1560 jl->j_trans_id = 0;
1561 jl->j_state = 0;
1562 put_journal_list(s, jl);
1563 if (flushall)
1564 up(&journal->j_flush_sem);
1565 put_fs_excl();
1566 return err;
1567}
1465 1568
1466static int write_one_transaction(struct super_block *s, 1569static int write_one_transaction(struct super_block *s,
1467 struct reiserfs_journal_list *jl, 1570 struct reiserfs_journal_list *jl,
1468 struct buffer_chunk *chunk) 1571 struct buffer_chunk *chunk)
1469{ 1572{
1470 struct reiserfs_journal_cnode *cn; 1573 struct reiserfs_journal_cnode *cn;
1471 int ret = 0 ; 1574 int ret = 0;
1472 1575
1473 jl->j_state |= LIST_TOUCHED; 1576 jl->j_state |= LIST_TOUCHED;
1474 del_from_work_list(s, jl); 1577 del_from_work_list(s, jl);
1475 if (jl->j_len == 0 || atomic_read(&jl->j_nonzerolen) == 0) { 1578 if (jl->j_len == 0 || atomic_read(&jl->j_nonzerolen) == 0) {
1476 return 0; 1579 return 0;
1477 } 1580 }
1478 1581
1479 cn = jl->j_realblock ; 1582 cn = jl->j_realblock;
1480 while(cn) { 1583 while (cn) {
1481 /* if the blocknr == 0, this has been cleared from the hash, 1584 /* if the blocknr == 0, this has been cleared from the hash,
1482 ** skip it 1585 ** skip it
1483 */ 1586 */
1484 if (cn->blocknr == 0) { 1587 if (cn->blocknr == 0) {
1485 goto next ; 1588 goto next;
1486 } 1589 }
1487 if (cn->bh && can_dirty(cn) && buffer_dirty(cn->bh)) { 1590 if (cn->bh && can_dirty(cn) && buffer_dirty(cn->bh)) {
1488 struct buffer_head *tmp_bh; 1591 struct buffer_head *tmp_bh;
1489 /* we can race against journal_mark_freed when we try 1592 /* we can race against journal_mark_freed when we try
1490 * to lock_buffer(cn->bh), so we have to inc the buffer 1593 * to lock_buffer(cn->bh), so we have to inc the buffer
1491 * count, and recheck things after locking 1594 * count, and recheck things after locking
1492 */ 1595 */
1493 tmp_bh = cn->bh; 1596 tmp_bh = cn->bh;
1494 get_bh(tmp_bh); 1597 get_bh(tmp_bh);
1495 lock_buffer(tmp_bh); 1598 lock_buffer(tmp_bh);
1496 if (cn->bh && can_dirty(cn) && buffer_dirty(tmp_bh)) { 1599 if (cn->bh && can_dirty(cn) && buffer_dirty(tmp_bh)) {
1497 if (!buffer_journal_dirty(tmp_bh) || 1600 if (!buffer_journal_dirty(tmp_bh) ||
1498 buffer_journal_prepared(tmp_bh)) 1601 buffer_journal_prepared(tmp_bh))
1499 BUG(); 1602 BUG();
1500 add_to_chunk(chunk, tmp_bh, NULL, write_chunk); 1603 add_to_chunk(chunk, tmp_bh, NULL, write_chunk);
1501 ret++; 1604 ret++;
1502 } else { 1605 } else {
1503 /* note, cn->bh might be null now */ 1606 /* note, cn->bh might be null now */
1504 unlock_buffer(tmp_bh); 1607 unlock_buffer(tmp_bh);
1505 } 1608 }
1506 put_bh(tmp_bh); 1609 put_bh(tmp_bh);
1507 } 1610 }
1508next: 1611 next:
1509 cn = cn->next ; 1612 cn = cn->next;
1510 cond_resched(); 1613 cond_resched();
1511 } 1614 }
1512 return ret ; 1615 return ret;
1513} 1616}
1514 1617
1515/* used by flush_commit_list */ 1618/* used by flush_commit_list */
1516static int dirty_one_transaction(struct super_block *s, 1619static int dirty_one_transaction(struct super_block *s,
1517 struct reiserfs_journal_list *jl) 1620 struct reiserfs_journal_list *jl)
1518{ 1621{
1519 struct reiserfs_journal_cnode *cn; 1622 struct reiserfs_journal_cnode *cn;
1520 struct reiserfs_journal_list *pjl; 1623 struct reiserfs_journal_list *pjl;
1521 int ret = 0 ; 1624 int ret = 0;
1522 1625
1523 jl->j_state |= LIST_DIRTY; 1626 jl->j_state |= LIST_DIRTY;
1524 cn = jl->j_realblock ; 1627 cn = jl->j_realblock;
1525 while(cn) { 1628 while (cn) {
1526 /* look for a more recent transaction that logged this 1629 /* look for a more recent transaction that logged this
1527 ** buffer. Only the most recent transaction with a buffer in 1630 ** buffer. Only the most recent transaction with a buffer in
1528 ** it is allowed to send that buffer to disk 1631 ** it is allowed to send that buffer to disk
1529 */ 1632 */
1530 pjl = find_newer_jl_for_cn(cn) ; 1633 pjl = find_newer_jl_for_cn(cn);
1531 if (!pjl && cn->blocknr && cn->bh && buffer_journal_dirty(cn->bh)) 1634 if (!pjl && cn->blocknr && cn->bh
1532 { 1635 && buffer_journal_dirty(cn->bh)) {
1533 BUG_ON (!can_dirty(cn)); 1636 BUG_ON(!can_dirty(cn));
1534 /* if the buffer is prepared, it will either be logged 1637 /* if the buffer is prepared, it will either be logged
1535 * or restored. If restored, we need to make sure 1638 * or restored. If restored, we need to make sure
1536 * it actually gets marked dirty 1639 * it actually gets marked dirty
1537 */ 1640 */
1538 clear_buffer_journal_new (cn->bh); 1641 clear_buffer_journal_new(cn->bh);
1539 if (buffer_journal_prepared (cn->bh)) { 1642 if (buffer_journal_prepared(cn->bh)) {
1540 set_buffer_journal_restore_dirty (cn->bh); 1643 set_buffer_journal_restore_dirty(cn->bh);
1541 } else { 1644 } else {
1542 set_buffer_journal_test (cn->bh); 1645 set_buffer_journal_test(cn->bh);
1543 mark_buffer_dirty(cn->bh); 1646 mark_buffer_dirty(cn->bh);
1544 } 1647 }
1545 } 1648 }
1546 cn = cn->next ; 1649 cn = cn->next;
1547 } 1650 }
1548 return ret ; 1651 return ret;
1549} 1652}
1550 1653
1551static int kupdate_transactions(struct super_block *s, 1654static int kupdate_transactions(struct super_block *s,
1552 struct reiserfs_journal_list *jl, 1655 struct reiserfs_journal_list *jl,
1553 struct reiserfs_journal_list **next_jl, 1656 struct reiserfs_journal_list **next_jl,
1554 unsigned long *next_trans_id, 1657 unsigned long *next_trans_id,
1555 int num_blocks, 1658 int num_blocks, int num_trans)
1556 int num_trans) { 1659{
1557 int ret = 0; 1660 int ret = 0;
1558 int written = 0 ; 1661 int written = 0;
1559 int transactions_flushed = 0; 1662 int transactions_flushed = 0;
1560 unsigned long orig_trans_id = jl->j_trans_id; 1663 unsigned long orig_trans_id = jl->j_trans_id;
1561 struct buffer_chunk chunk; 1664 struct buffer_chunk chunk;
1562 struct list_head *entry; 1665 struct list_head *entry;
1563 struct reiserfs_journal *journal = SB_JOURNAL (s); 1666 struct reiserfs_journal *journal = SB_JOURNAL(s);
1564 chunk.nr = 0; 1667 chunk.nr = 0;
1565 1668
1566 down(&journal->j_flush_sem); 1669 down(&journal->j_flush_sem);
1567 if (!journal_list_still_alive(s, orig_trans_id)) { 1670 if (!journal_list_still_alive(s, orig_trans_id)) {
1568 goto done; 1671 goto done;
1569 } 1672 }
1570 1673
1571 /* we've got j_flush_sem held, nobody is going to delete any 1674 /* we've got j_flush_sem held, nobody is going to delete any
1572 * of these lists out from underneath us 1675 * of these lists out from underneath us
1573 */ 1676 */
1574 while((num_trans && transactions_flushed < num_trans) || 1677 while ((num_trans && transactions_flushed < num_trans) ||
1575 (!num_trans && written < num_blocks)) { 1678 (!num_trans && written < num_blocks)) {
1576 1679
1577 if (jl->j_len == 0 || (jl->j_state & LIST_TOUCHED) || 1680 if (jl->j_len == 0 || (jl->j_state & LIST_TOUCHED) ||
1578 atomic_read(&jl->j_commit_left) || !(jl->j_state & LIST_DIRTY)) 1681 atomic_read(&jl->j_commit_left)
1579 { 1682 || !(jl->j_state & LIST_DIRTY)) {
1580 del_from_work_list(s, jl); 1683 del_from_work_list(s, jl);
1581 break; 1684 break;
1582 } 1685 }
1583 ret = write_one_transaction(s, jl, &chunk); 1686 ret = write_one_transaction(s, jl, &chunk);
1584 1687
1585 if (ret < 0) 1688 if (ret < 0)
1586 goto done; 1689 goto done;
1587 transactions_flushed++; 1690 transactions_flushed++;
1588 written += ret; 1691 written += ret;
1589 entry = jl->j_list.next; 1692 entry = jl->j_list.next;
1590 1693
1591 /* did we wrap? */ 1694 /* did we wrap? */
1592 if (entry == &journal->j_journal_list) { 1695 if (entry == &journal->j_journal_list) {
1593 break; 1696 break;
1594 } 1697 }
1595 jl = JOURNAL_LIST_ENTRY(entry); 1698 jl = JOURNAL_LIST_ENTRY(entry);
1596 1699
1597 /* don't bother with older transactions */ 1700 /* don't bother with older transactions */
1598 if (jl->j_trans_id <= orig_trans_id) 1701 if (jl->j_trans_id <= orig_trans_id)
1599 break; 1702 break;
1600 } 1703 }
1601 if (chunk.nr) { 1704 if (chunk.nr) {
1602 write_chunk(&chunk); 1705 write_chunk(&chunk);
1603 } 1706 }
1604 1707
1605done: 1708 done:
1606 up(&journal->j_flush_sem); 1709 up(&journal->j_flush_sem);
1607 return ret; 1710 return ret;
1608} 1711}
1609 1712
1610/* for o_sync and fsync heavy applications, they tend to use 1713/* for o_sync and fsync heavy applications, they tend to use
@@ -1617,47 +1720,48 @@ done:
1617** list updates the header block 1720** list updates the header block
1618*/ 1721*/
1619static int flush_used_journal_lists(struct super_block *s, 1722static int flush_used_journal_lists(struct super_block *s,
1620 struct reiserfs_journal_list *jl) { 1723 struct reiserfs_journal_list *jl)
1621 unsigned long len = 0; 1724{
1622 unsigned long cur_len; 1725 unsigned long len = 0;
1623 int ret; 1726 unsigned long cur_len;
1624 int i; 1727 int ret;
1625 int limit = 256; 1728 int i;
1626 struct reiserfs_journal_list *tjl; 1729 int limit = 256;
1627 struct reiserfs_journal_list *flush_jl; 1730 struct reiserfs_journal_list *tjl;
1628 unsigned long trans_id; 1731 struct reiserfs_journal_list *flush_jl;
1629 struct reiserfs_journal *journal = SB_JOURNAL (s); 1732 unsigned long trans_id;
1630 1733 struct reiserfs_journal *journal = SB_JOURNAL(s);
1631 flush_jl = tjl = jl; 1734
1632 1735 flush_jl = tjl = jl;
1633 /* in data logging mode, try harder to flush a lot of blocks */ 1736
1634 if (reiserfs_data_log(s)) 1737 /* in data logging mode, try harder to flush a lot of blocks */
1635 limit = 1024; 1738 if (reiserfs_data_log(s))
1636 /* flush for 256 transactions or limit blocks, whichever comes first */ 1739 limit = 1024;
1637 for(i = 0 ; i < 256 && len < limit ; i++) { 1740 /* flush for 256 transactions or limit blocks, whichever comes first */
1638 if (atomic_read(&tjl->j_commit_left) || 1741 for (i = 0; i < 256 && len < limit; i++) {
1639 tjl->j_trans_id < jl->j_trans_id) { 1742 if (atomic_read(&tjl->j_commit_left) ||
1640 break; 1743 tjl->j_trans_id < jl->j_trans_id) {
1641 } 1744 break;
1642 cur_len = atomic_read(&tjl->j_nonzerolen); 1745 }
1643 if (cur_len > 0) { 1746 cur_len = atomic_read(&tjl->j_nonzerolen);
1644 tjl->j_state &= ~LIST_TOUCHED; 1747 if (cur_len > 0) {
1645 } 1748 tjl->j_state &= ~LIST_TOUCHED;
1646 len += cur_len; 1749 }
1647 flush_jl = tjl; 1750 len += cur_len;
1648 if (tjl->j_list.next == &journal->j_journal_list) 1751 flush_jl = tjl;
1649 break; 1752 if (tjl->j_list.next == &journal->j_journal_list)
1650 tjl = JOURNAL_LIST_ENTRY(tjl->j_list.next); 1753 break;
1651 } 1754 tjl = JOURNAL_LIST_ENTRY(tjl->j_list.next);
1652 /* try to find a group of blocks we can flush across all the 1755 }
1653 ** transactions, but only bother if we've actually spanned 1756 /* try to find a group of blocks we can flush across all the
1654 ** across multiple lists 1757 ** transactions, but only bother if we've actually spanned
1655 */ 1758 ** across multiple lists
1656 if (flush_jl != jl) { 1759 */
1657 ret = kupdate_transactions(s, jl, &tjl, &trans_id, len, i); 1760 if (flush_jl != jl) {
1658 } 1761 ret = kupdate_transactions(s, jl, &tjl, &trans_id, len, i);
1659 flush_journal_list(s, flush_jl, 1); 1762 }
1660 return 0; 1763 flush_journal_list(s, flush_jl, 1);
1764 return 0;
1661} 1765}
1662 1766
1663/* 1767/*
@@ -1665,207 +1769,248 @@ static int flush_used_journal_lists(struct super_block *s,
1665** only touchs the hnext and hprev pointers. 1769** only touchs the hnext and hprev pointers.
1666*/ 1770*/
1667void remove_journal_hash(struct super_block *sb, 1771void remove_journal_hash(struct super_block *sb,
1668 struct reiserfs_journal_cnode **table, 1772 struct reiserfs_journal_cnode **table,
1669 struct reiserfs_journal_list *jl, 1773 struct reiserfs_journal_list *jl,
1670 unsigned long block, int remove_freed) 1774 unsigned long block, int remove_freed)
1671{ 1775{
1672 struct reiserfs_journal_cnode *cur ; 1776 struct reiserfs_journal_cnode *cur;
1673 struct reiserfs_journal_cnode **head ; 1777 struct reiserfs_journal_cnode **head;
1674 1778
1675 head= &(journal_hash(table, sb, block)) ; 1779 head = &(journal_hash(table, sb, block));
1676 if (!head) { 1780 if (!head) {
1677 return ; 1781 return;
1678 } 1782 }
1679 cur = *head ; 1783 cur = *head;
1680 while(cur) { 1784 while (cur) {
1681 if (cur->blocknr == block && cur->sb == sb && (jl == NULL || jl == cur->jlist) && 1785 if (cur->blocknr == block && cur->sb == sb
1682 (!test_bit(BLOCK_FREED, &cur->state) || remove_freed)) { 1786 && (jl == NULL || jl == cur->jlist)
1683 if (cur->hnext) { 1787 && (!test_bit(BLOCK_FREED, &cur->state) || remove_freed)) {
1684 cur->hnext->hprev = cur->hprev ; 1788 if (cur->hnext) {
1685 } 1789 cur->hnext->hprev = cur->hprev;
1686 if (cur->hprev) { 1790 }
1687 cur->hprev->hnext = cur->hnext ; 1791 if (cur->hprev) {
1688 } else { 1792 cur->hprev->hnext = cur->hnext;
1689 *head = cur->hnext ; 1793 } else {
1690 } 1794 *head = cur->hnext;
1691 cur->blocknr = 0 ; 1795 }
1692 cur->sb = NULL ; 1796 cur->blocknr = 0;
1693 cur->state = 0 ; 1797 cur->sb = NULL;
1694 if (cur->bh && cur->jlist) /* anybody who clears the cur->bh will also dec the nonzerolen */ 1798 cur->state = 0;
1695 atomic_dec(&(cur->jlist->j_nonzerolen)) ; 1799 if (cur->bh && cur->jlist) /* anybody who clears the cur->bh will also dec the nonzerolen */
1696 cur->bh = NULL ; 1800 atomic_dec(&(cur->jlist->j_nonzerolen));
1697 cur->jlist = NULL ; 1801 cur->bh = NULL;
1698 } 1802 cur->jlist = NULL;
1699 cur = cur->hnext ; 1803 }
1700 } 1804 cur = cur->hnext;
1701} 1805 }
1702 1806}
1703static void free_journal_ram(struct super_block *p_s_sb) { 1807
1704 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb); 1808static void free_journal_ram(struct super_block *p_s_sb)
1705 reiserfs_kfree(journal->j_current_jl, 1809{
1706 sizeof(struct reiserfs_journal_list), p_s_sb); 1810 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb);
1707 journal->j_num_lists--; 1811 reiserfs_kfree(journal->j_current_jl,
1708 1812 sizeof(struct reiserfs_journal_list), p_s_sb);
1709 vfree(journal->j_cnode_free_orig) ; 1813 journal->j_num_lists--;
1710 free_list_bitmaps(p_s_sb, journal->j_list_bitmap) ; 1814
1711 free_bitmap_nodes(p_s_sb) ; /* must be after free_list_bitmaps */ 1815 vfree(journal->j_cnode_free_orig);
1712 if (journal->j_header_bh) { 1816 free_list_bitmaps(p_s_sb, journal->j_list_bitmap);
1713 brelse(journal->j_header_bh) ; 1817 free_bitmap_nodes(p_s_sb); /* must be after free_list_bitmaps */
1714 } 1818 if (journal->j_header_bh) {
1715 /* j_header_bh is on the journal dev, make sure not to release the journal 1819 brelse(journal->j_header_bh);
1716 * dev until we brelse j_header_bh 1820 }
1717 */ 1821 /* j_header_bh is on the journal dev, make sure not to release the journal
1718 release_journal_dev(p_s_sb, journal); 1822 * dev until we brelse j_header_bh
1719 vfree(journal) ; 1823 */
1824 release_journal_dev(p_s_sb, journal);
1825 vfree(journal);
1720} 1826}
1721 1827
1722/* 1828/*
1723** call on unmount. Only set error to 1 if you haven't made your way out 1829** call on unmount. Only set error to 1 if you haven't made your way out
1724** of read_super() yet. Any other caller must keep error at 0. 1830** of read_super() yet. Any other caller must keep error at 0.
1725*/ 1831*/
1726static int do_journal_release(struct reiserfs_transaction_handle *th, struct super_block *p_s_sb, int error) { 1832static int do_journal_release(struct reiserfs_transaction_handle *th,
1727 struct reiserfs_transaction_handle myth ; 1833 struct super_block *p_s_sb, int error)
1728 int flushed = 0; 1834{
1729 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb); 1835 struct reiserfs_transaction_handle myth;
1730 1836 int flushed = 0;
1731 /* we only want to flush out transactions if we were called with error == 0 1837 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb);
1732 */ 1838
1733 if (!error && !(p_s_sb->s_flags & MS_RDONLY)) { 1839 /* we only want to flush out transactions if we were called with error == 0
1734 /* end the current trans */ 1840 */
1735 BUG_ON (!th->t_trans_id); 1841 if (!error && !(p_s_sb->s_flags & MS_RDONLY)) {
1736 do_journal_end(th, p_s_sb,10, FLUSH_ALL) ; 1842 /* end the current trans */
1737 1843 BUG_ON(!th->t_trans_id);
1738 /* make sure something gets logged to force our way into the flush code */ 1844 do_journal_end(th, p_s_sb, 10, FLUSH_ALL);
1739 if (!journal_join(&myth, p_s_sb, 1)) { 1845
1740 reiserfs_prepare_for_journal(p_s_sb, SB_BUFFER_WITH_SB(p_s_sb), 1) ; 1846 /* make sure something gets logged to force our way into the flush code */
1741 journal_mark_dirty(&myth, p_s_sb, SB_BUFFER_WITH_SB(p_s_sb)) ; 1847 if (!journal_join(&myth, p_s_sb, 1)) {
1742 do_journal_end(&myth, p_s_sb,1, FLUSH_ALL) ; 1848 reiserfs_prepare_for_journal(p_s_sb,
1743 flushed = 1; 1849 SB_BUFFER_WITH_SB(p_s_sb),
1744 } 1850 1);
1745 } 1851 journal_mark_dirty(&myth, p_s_sb,
1746 1852 SB_BUFFER_WITH_SB(p_s_sb));
1747 /* this also catches errors during the do_journal_end above */ 1853 do_journal_end(&myth, p_s_sb, 1, FLUSH_ALL);
1748 if (!error && reiserfs_is_journal_aborted(journal)) { 1854 flushed = 1;
1749 memset(&myth, 0, sizeof(myth)); 1855 }
1750 if (!journal_join_abort(&myth, p_s_sb, 1)) { 1856 }
1751 reiserfs_prepare_for_journal(p_s_sb, SB_BUFFER_WITH_SB(p_s_sb), 1) ; 1857
1752 journal_mark_dirty(&myth, p_s_sb, SB_BUFFER_WITH_SB(p_s_sb)) ; 1858 /* this also catches errors during the do_journal_end above */
1753 do_journal_end(&myth, p_s_sb, 1, FLUSH_ALL) ; 1859 if (!error && reiserfs_is_journal_aborted(journal)) {
1754 } 1860 memset(&myth, 0, sizeof(myth));
1755 } 1861 if (!journal_join_abort(&myth, p_s_sb, 1)) {
1756 1862 reiserfs_prepare_for_journal(p_s_sb,
1757 reiserfs_mounted_fs_count-- ; 1863 SB_BUFFER_WITH_SB(p_s_sb),
1758 /* wait for all commits to finish */ 1864 1);
1759 cancel_delayed_work(&SB_JOURNAL(p_s_sb)->j_work); 1865 journal_mark_dirty(&myth, p_s_sb,
1760 flush_workqueue(commit_wq); 1866 SB_BUFFER_WITH_SB(p_s_sb));
1761 if (!reiserfs_mounted_fs_count) { 1867 do_journal_end(&myth, p_s_sb, 1, FLUSH_ALL);
1762 destroy_workqueue(commit_wq); 1868 }
1763 commit_wq = NULL; 1869 }
1764 } 1870
1765 1871 reiserfs_mounted_fs_count--;
1766 free_journal_ram(p_s_sb) ; 1872 /* wait for all commits to finish */
1767 1873 cancel_delayed_work(&SB_JOURNAL(p_s_sb)->j_work);
1768 return 0 ; 1874 flush_workqueue(commit_wq);
1875 if (!reiserfs_mounted_fs_count) {
1876 destroy_workqueue(commit_wq);
1877 commit_wq = NULL;
1878 }
1879
1880 free_journal_ram(p_s_sb);
1881
1882 return 0;
1769} 1883}
1770 1884
1771/* 1885/*
1772** call on unmount. flush all journal trans, release all alloc'd ram 1886** call on unmount. flush all journal trans, release all alloc'd ram
1773*/ 1887*/
1774int journal_release(struct reiserfs_transaction_handle *th, struct super_block *p_s_sb) { 1888int journal_release(struct reiserfs_transaction_handle *th,
1775 return do_journal_release(th, p_s_sb, 0) ; 1889 struct super_block *p_s_sb)
1890{
1891 return do_journal_release(th, p_s_sb, 0);
1776} 1892}
1893
1777/* 1894/*
1778** only call from an error condition inside reiserfs_read_super! 1895** only call from an error condition inside reiserfs_read_super!
1779*/ 1896*/
1780int journal_release_error(struct reiserfs_transaction_handle *th, struct super_block *p_s_sb) { 1897int journal_release_error(struct reiserfs_transaction_handle *th,
1781 return do_journal_release(th, p_s_sb, 1) ; 1898 struct super_block *p_s_sb)
1899{
1900 return do_journal_release(th, p_s_sb, 1);
1782} 1901}
1783 1902
1784/* compares description block with commit block. returns 1 if they differ, 0 if they are the same */ 1903/* compares description block with commit block. returns 1 if they differ, 0 if they are the same */
1785static int journal_compare_desc_commit(struct super_block *p_s_sb, struct reiserfs_journal_desc *desc, 1904static int journal_compare_desc_commit(struct super_block *p_s_sb,
1786 struct reiserfs_journal_commit *commit) { 1905 struct reiserfs_journal_desc *desc,
1787 if (get_commit_trans_id (commit) != get_desc_trans_id (desc) || 1906 struct reiserfs_journal_commit *commit)
1788 get_commit_trans_len (commit) != get_desc_trans_len (desc) || 1907{
1789 get_commit_trans_len (commit) > SB_JOURNAL(p_s_sb)->j_trans_max || 1908 if (get_commit_trans_id(commit) != get_desc_trans_id(desc) ||
1790 get_commit_trans_len (commit) <= 0 1909 get_commit_trans_len(commit) != get_desc_trans_len(desc) ||
1791 ) { 1910 get_commit_trans_len(commit) > SB_JOURNAL(p_s_sb)->j_trans_max ||
1792 return 1 ; 1911 get_commit_trans_len(commit) <= 0) {
1793 } 1912 return 1;
1794 return 0 ; 1913 }
1914 return 0;
1795} 1915}
1916
1796/* returns 0 if it did not find a description block 1917/* returns 0 if it did not find a description block
1797** returns -1 if it found a corrupt commit block 1918** returns -1 if it found a corrupt commit block
1798** returns 1 if both desc and commit were valid 1919** returns 1 if both desc and commit were valid
1799*/ 1920*/
1800static int journal_transaction_is_valid(struct super_block *p_s_sb, struct buffer_head *d_bh, unsigned long *oldest_invalid_trans_id, unsigned long *newest_mount_id) { 1921static int journal_transaction_is_valid(struct super_block *p_s_sb,
1801 struct reiserfs_journal_desc *desc ; 1922 struct buffer_head *d_bh,
1802 struct reiserfs_journal_commit *commit ; 1923 unsigned long *oldest_invalid_trans_id,
1803 struct buffer_head *c_bh ; 1924 unsigned long *newest_mount_id)
1804 unsigned long offset ; 1925{
1805 1926 struct reiserfs_journal_desc *desc;
1806 if (!d_bh) 1927 struct reiserfs_journal_commit *commit;
1807 return 0 ; 1928 struct buffer_head *c_bh;
1808 1929 unsigned long offset;
1809 desc = (struct reiserfs_journal_desc *)d_bh->b_data ; 1930
1810 if (get_desc_trans_len(desc) > 0 && !memcmp(get_journal_desc_magic (d_bh), JOURNAL_DESC_MAGIC, 8)) { 1931 if (!d_bh)
1811 if (oldest_invalid_trans_id && *oldest_invalid_trans_id && get_desc_trans_id(desc) > *oldest_invalid_trans_id) { 1932 return 0;
1812 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, "journal-986: transaction " 1933
1813 "is valid returning because trans_id %d is greater than " 1934 desc = (struct reiserfs_journal_desc *)d_bh->b_data;
1814 "oldest_invalid %lu", get_desc_trans_id(desc), 1935 if (get_desc_trans_len(desc) > 0
1815 *oldest_invalid_trans_id); 1936 && !memcmp(get_journal_desc_magic(d_bh), JOURNAL_DESC_MAGIC, 8)) {
1816 return 0 ; 1937 if (oldest_invalid_trans_id && *oldest_invalid_trans_id
1817 } 1938 && get_desc_trans_id(desc) > *oldest_invalid_trans_id) {
1818 if (newest_mount_id && *newest_mount_id > get_desc_mount_id (desc)) { 1939 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE,
1819 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, "journal-1087: transaction " 1940 "journal-986: transaction "
1820 "is valid returning because mount_id %d is less than " 1941 "is valid returning because trans_id %d is greater than "
1821 "newest_mount_id %lu", get_desc_mount_id (desc), 1942 "oldest_invalid %lu",
1822 *newest_mount_id) ; 1943 get_desc_trans_id(desc),
1823 return -1 ; 1944 *oldest_invalid_trans_id);
1824 } 1945 return 0;
1825 if ( get_desc_trans_len(desc) > SB_JOURNAL(p_s_sb)->j_trans_max ) { 1946 }
1826 reiserfs_warning(p_s_sb, "journal-2018: Bad transaction length %d encountered, ignoring transaction", get_desc_trans_len(desc)); 1947 if (newest_mount_id
1827 return -1 ; 1948 && *newest_mount_id > get_desc_mount_id(desc)) {
1828 } 1949 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE,
1829 offset = d_bh->b_blocknr - SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) ; 1950 "journal-1087: transaction "
1830 1951 "is valid returning because mount_id %d is less than "
1831 /* ok, we have a journal description block, lets see if the transaction was valid */ 1952 "newest_mount_id %lu",
1832 c_bh = journal_bread(p_s_sb, SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) + 1953 get_desc_mount_id(desc),
1833 ((offset + get_desc_trans_len(desc) + 1) % SB_ONDISK_JOURNAL_SIZE(p_s_sb))) ; 1954 *newest_mount_id);
1834 if (!c_bh) 1955 return -1;
1835 return 0 ; 1956 }
1836 commit = (struct reiserfs_journal_commit *)c_bh->b_data ; 1957 if (get_desc_trans_len(desc) > SB_JOURNAL(p_s_sb)->j_trans_max) {
1837 if (journal_compare_desc_commit(p_s_sb, desc, commit)) { 1958 reiserfs_warning(p_s_sb,
1838 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, 1959 "journal-2018: Bad transaction length %d encountered, ignoring transaction",
1839 "journal_transaction_is_valid, commit offset %ld had bad " 1960 get_desc_trans_len(desc));
1840 "time %d or length %d", 1961 return -1;
1841 c_bh->b_blocknr - SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb), 1962 }
1842 get_commit_trans_id (commit), 1963 offset = d_bh->b_blocknr - SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb);
1843 get_commit_trans_len(commit)); 1964
1844 brelse(c_bh) ; 1965 /* ok, we have a journal description block, lets see if the transaction was valid */
1845 if (oldest_invalid_trans_id) { 1966 c_bh =
1846 *oldest_invalid_trans_id = get_desc_trans_id(desc) ; 1967 journal_bread(p_s_sb,
1847 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, "journal-1004: " 1968 SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) +
1848 "transaction_is_valid setting oldest invalid trans_id " 1969 ((offset + get_desc_trans_len(desc) +
1849 "to %d", get_desc_trans_id(desc)) ; 1970 1) % SB_ONDISK_JOURNAL_SIZE(p_s_sb)));
1850 } 1971 if (!c_bh)
1851 return -1; 1972 return 0;
1852 } 1973 commit = (struct reiserfs_journal_commit *)c_bh->b_data;
1853 brelse(c_bh) ; 1974 if (journal_compare_desc_commit(p_s_sb, desc, commit)) {
1854 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, "journal-1006: found valid " 1975 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE,
1855 "transaction start offset %llu, len %d id %d", 1976 "journal_transaction_is_valid, commit offset %ld had bad "
1856 d_bh->b_blocknr - SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb), 1977 "time %d or length %d",
1857 get_desc_trans_len(desc), get_desc_trans_id(desc)) ; 1978 c_bh->b_blocknr -
1858 return 1 ; 1979 SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb),
1859 } else { 1980 get_commit_trans_id(commit),
1860 return 0 ; 1981 get_commit_trans_len(commit));
1861 } 1982 brelse(c_bh);
1862} 1983 if (oldest_invalid_trans_id) {
1863 1984 *oldest_invalid_trans_id =
1864static void brelse_array(struct buffer_head **heads, int num) { 1985 get_desc_trans_id(desc);
1865 int i ; 1986 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE,
1866 for (i = 0 ; i < num ; i++) { 1987 "journal-1004: "
1867 brelse(heads[i]) ; 1988 "transaction_is_valid setting oldest invalid trans_id "
1868 } 1989 "to %d",
1990 get_desc_trans_id(desc));
1991 }
1992 return -1;
1993 }
1994 brelse(c_bh);
1995 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE,
1996 "journal-1006: found valid "
1997 "transaction start offset %llu, len %d id %d",
1998 d_bh->b_blocknr -
1999 SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb),
2000 get_desc_trans_len(desc),
2001 get_desc_trans_id(desc));
2002 return 1;
2003 } else {
2004 return 0;
2005 }
2006}
2007
2008static void brelse_array(struct buffer_head **heads, int num)
2009{
2010 int i;
2011 for (i = 0; i < num; i++) {
2012 brelse(heads[i]);
2013 }
1869} 2014}
1870 2015
1871/* 2016/*
@@ -1873,149 +2018,202 @@ static void brelse_array(struct buffer_head **heads, int num) {
1873** this either reads in a replays a transaction, or returns because the transaction 2018** this either reads in a replays a transaction, or returns because the transaction
1874** is invalid, or too old. 2019** is invalid, or too old.
1875*/ 2020*/
1876static int journal_read_transaction(struct super_block *p_s_sb, unsigned long cur_dblock, unsigned long oldest_start, 2021static int journal_read_transaction(struct super_block *p_s_sb,
1877 unsigned long oldest_trans_id, unsigned long newest_mount_id) { 2022 unsigned long cur_dblock,
1878 struct reiserfs_journal *journal = SB_JOURNAL (p_s_sb); 2023 unsigned long oldest_start,
1879 struct reiserfs_journal_desc *desc ; 2024 unsigned long oldest_trans_id,
1880 struct reiserfs_journal_commit *commit ; 2025 unsigned long newest_mount_id)
1881 unsigned long trans_id = 0 ; 2026{
1882 struct buffer_head *c_bh ; 2027 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb);
1883 struct buffer_head *d_bh ; 2028 struct reiserfs_journal_desc *desc;
1884 struct buffer_head **log_blocks = NULL ; 2029 struct reiserfs_journal_commit *commit;
1885 struct buffer_head **real_blocks = NULL ; 2030 unsigned long trans_id = 0;
1886 unsigned long trans_offset ; 2031 struct buffer_head *c_bh;
1887 int i; 2032 struct buffer_head *d_bh;
1888 int trans_half; 2033 struct buffer_head **log_blocks = NULL;
1889 2034 struct buffer_head **real_blocks = NULL;
1890 d_bh = journal_bread(p_s_sb, cur_dblock) ; 2035 unsigned long trans_offset;
1891 if (!d_bh) 2036 int i;
1892 return 1 ; 2037 int trans_half;
1893 desc = (struct reiserfs_journal_desc *)d_bh->b_data ; 2038
1894 trans_offset = d_bh->b_blocknr - SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) ; 2039 d_bh = journal_bread(p_s_sb, cur_dblock);
1895 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, "journal-1037: " 2040 if (!d_bh)
1896 "journal_read_transaction, offset %llu, len %d mount_id %d", 2041 return 1;
1897 d_bh->b_blocknr - SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb), 2042 desc = (struct reiserfs_journal_desc *)d_bh->b_data;
1898 get_desc_trans_len(desc), get_desc_mount_id(desc)) ; 2043 trans_offset = d_bh->b_blocknr - SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb);
1899 if (get_desc_trans_id(desc) < oldest_trans_id) { 2044 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, "journal-1037: "
1900 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, "journal-1039: " 2045 "journal_read_transaction, offset %llu, len %d mount_id %d",
1901 "journal_read_trans skipping because %lu is too old", 2046 d_bh->b_blocknr - SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb),
1902 cur_dblock - SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb)) ; 2047 get_desc_trans_len(desc), get_desc_mount_id(desc));
1903 brelse(d_bh) ; 2048 if (get_desc_trans_id(desc) < oldest_trans_id) {
1904 return 1 ; 2049 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, "journal-1039: "
1905 } 2050 "journal_read_trans skipping because %lu is too old",
1906 if (get_desc_mount_id(desc) != newest_mount_id) { 2051 cur_dblock -
1907 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, "journal-1146: " 2052 SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb));
1908 "journal_read_trans skipping because %d is != " 2053 brelse(d_bh);
1909 "newest_mount_id %lu", get_desc_mount_id(desc), 2054 return 1;
1910 newest_mount_id) ; 2055 }
1911 brelse(d_bh) ; 2056 if (get_desc_mount_id(desc) != newest_mount_id) {
1912 return 1 ; 2057 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, "journal-1146: "
1913 } 2058 "journal_read_trans skipping because %d is != "
1914 c_bh = journal_bread(p_s_sb, SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) + 2059 "newest_mount_id %lu", get_desc_mount_id(desc),
1915 ((trans_offset + get_desc_trans_len(desc) + 1) % 2060 newest_mount_id);
1916 SB_ONDISK_JOURNAL_SIZE(p_s_sb))) ; 2061 brelse(d_bh);
1917 if (!c_bh) { 2062 return 1;
1918 brelse(d_bh) ; 2063 }
1919 return 1 ; 2064 c_bh = journal_bread(p_s_sb, SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) +
1920 } 2065 ((trans_offset + get_desc_trans_len(desc) + 1) %
1921 commit = (struct reiserfs_journal_commit *)c_bh->b_data ; 2066 SB_ONDISK_JOURNAL_SIZE(p_s_sb)));
1922 if (journal_compare_desc_commit(p_s_sb, desc, commit)) { 2067 if (!c_bh) {
1923 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, "journal_read_transaction, " 2068 brelse(d_bh);
1924 "commit offset %llu had bad time %d or length %d", 2069 return 1;
1925 c_bh->b_blocknr - SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb), 2070 }
1926 get_commit_trans_id(commit), get_commit_trans_len(commit)); 2071 commit = (struct reiserfs_journal_commit *)c_bh->b_data;
1927 brelse(c_bh) ; 2072 if (journal_compare_desc_commit(p_s_sb, desc, commit)) {
1928 brelse(d_bh) ; 2073 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE,
1929 return 1; 2074 "journal_read_transaction, "
1930 } 2075 "commit offset %llu had bad time %d or length %d",
1931 trans_id = get_desc_trans_id(desc) ; 2076 c_bh->b_blocknr -
1932 /* now we know we've got a good transaction, and it was inside the valid time ranges */ 2077 SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb),
1933 log_blocks = reiserfs_kmalloc(get_desc_trans_len(desc) * sizeof(struct buffer_head *), GFP_NOFS, p_s_sb) ; 2078 get_commit_trans_id(commit),
1934 real_blocks = reiserfs_kmalloc(get_desc_trans_len(desc) * sizeof(struct buffer_head *), GFP_NOFS, p_s_sb) ; 2079 get_commit_trans_len(commit));
1935 if (!log_blocks || !real_blocks) { 2080 brelse(c_bh);
1936 brelse(c_bh) ; 2081 brelse(d_bh);
1937 brelse(d_bh) ; 2082 return 1;
1938 reiserfs_kfree(log_blocks, get_desc_trans_len(desc) * sizeof(struct buffer_head *), p_s_sb) ; 2083 }
1939 reiserfs_kfree(real_blocks, get_desc_trans_len(desc) * sizeof(struct buffer_head *), p_s_sb) ; 2084 trans_id = get_desc_trans_id(desc);
1940 reiserfs_warning(p_s_sb, "journal-1169: kmalloc failed, unable to mount FS") ; 2085 /* now we know we've got a good transaction, and it was inside the valid time ranges */
1941 return -1 ; 2086 log_blocks =
1942 } 2087 reiserfs_kmalloc(get_desc_trans_len(desc) *
1943 /* get all the buffer heads */ 2088 sizeof(struct buffer_head *), GFP_NOFS, p_s_sb);
1944 trans_half = journal_trans_half (p_s_sb->s_blocksize) ; 2089 real_blocks =
1945 for(i = 0 ; i < get_desc_trans_len(desc) ; i++) { 2090 reiserfs_kmalloc(get_desc_trans_len(desc) *
1946 log_blocks[i] = journal_getblk(p_s_sb, SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) + (trans_offset + 1 + i) % SB_ONDISK_JOURNAL_SIZE(p_s_sb)); 2091 sizeof(struct buffer_head *), GFP_NOFS, p_s_sb);
1947 if (i < trans_half) { 2092 if (!log_blocks || !real_blocks) {
1948 real_blocks[i] = sb_getblk(p_s_sb, le32_to_cpu(desc->j_realblock[i])) ; 2093 brelse(c_bh);
1949 } else { 2094 brelse(d_bh);
1950 real_blocks[i] = sb_getblk(p_s_sb, le32_to_cpu(commit->j_realblock[i - trans_half])) ; 2095 reiserfs_kfree(log_blocks,
1951 } 2096 get_desc_trans_len(desc) *
1952 if ( real_blocks[i]->b_blocknr > SB_BLOCK_COUNT(p_s_sb) ) { 2097 sizeof(struct buffer_head *), p_s_sb);
1953 reiserfs_warning(p_s_sb, "journal-1207: REPLAY FAILURE fsck required! Block to replay is outside of filesystem"); 2098 reiserfs_kfree(real_blocks,
1954 goto abort_replay; 2099 get_desc_trans_len(desc) *
1955 } 2100 sizeof(struct buffer_head *), p_s_sb);
1956 /* make sure we don't try to replay onto log or reserved area */ 2101 reiserfs_warning(p_s_sb,
1957 if (is_block_in_log_or_reserved_area(p_s_sb, real_blocks[i]->b_blocknr)) { 2102 "journal-1169: kmalloc failed, unable to mount FS");
1958 reiserfs_warning(p_s_sb, "journal-1204: REPLAY FAILURE fsck required! Trying to replay onto a log block") ; 2103 return -1;
1959abort_replay: 2104 }
1960 brelse_array(log_blocks, i) ; 2105 /* get all the buffer heads */
1961 brelse_array(real_blocks, i) ; 2106 trans_half = journal_trans_half(p_s_sb->s_blocksize);
1962 brelse(c_bh) ; 2107 for (i = 0; i < get_desc_trans_len(desc); i++) {
1963 brelse(d_bh) ; 2108 log_blocks[i] =
1964 reiserfs_kfree(log_blocks, get_desc_trans_len(desc) * sizeof(struct buffer_head *), p_s_sb) ; 2109 journal_getblk(p_s_sb,
1965 reiserfs_kfree(real_blocks, get_desc_trans_len(desc) * sizeof(struct buffer_head *), p_s_sb) ; 2110 SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) +
1966 return -1 ; 2111 (trans_offset + 1 +
1967 } 2112 i) % SB_ONDISK_JOURNAL_SIZE(p_s_sb));
1968 } 2113 if (i < trans_half) {
1969 /* read in the log blocks, memcpy to the corresponding real block */ 2114 real_blocks[i] =
1970 ll_rw_block(READ, get_desc_trans_len(desc), log_blocks) ; 2115 sb_getblk(p_s_sb,
1971 for (i = 0 ; i < get_desc_trans_len(desc) ; i++) { 2116 le32_to_cpu(desc->j_realblock[i]));
1972 wait_on_buffer(log_blocks[i]) ; 2117 } else {
1973 if (!buffer_uptodate(log_blocks[i])) { 2118 real_blocks[i] =
1974 reiserfs_warning(p_s_sb, "journal-1212: REPLAY FAILURE fsck required! buffer write failed") ; 2119 sb_getblk(p_s_sb,
1975 brelse_array(log_blocks + i, get_desc_trans_len(desc) - i) ; 2120 le32_to_cpu(commit->
1976 brelse_array(real_blocks, get_desc_trans_len(desc)) ; 2121 j_realblock[i - trans_half]));
1977 brelse(c_bh) ; 2122 }
1978 brelse(d_bh) ; 2123 if (real_blocks[i]->b_blocknr > SB_BLOCK_COUNT(p_s_sb)) {
1979 reiserfs_kfree(log_blocks, get_desc_trans_len(desc) * sizeof(struct buffer_head *), p_s_sb) ; 2124 reiserfs_warning(p_s_sb,
1980 reiserfs_kfree(real_blocks, get_desc_trans_len(desc) * sizeof(struct buffer_head *), p_s_sb) ; 2125 "journal-1207: REPLAY FAILURE fsck required! Block to replay is outside of filesystem");
1981 return -1 ; 2126 goto abort_replay;
1982 } 2127 }
1983 memcpy(real_blocks[i]->b_data, log_blocks[i]->b_data, real_blocks[i]->b_size) ; 2128 /* make sure we don't try to replay onto log or reserved area */
1984 set_buffer_uptodate(real_blocks[i]) ; 2129 if (is_block_in_log_or_reserved_area
1985 brelse(log_blocks[i]) ; 2130 (p_s_sb, real_blocks[i]->b_blocknr)) {
1986 } 2131 reiserfs_warning(p_s_sb,
1987 /* flush out the real blocks */ 2132 "journal-1204: REPLAY FAILURE fsck required! Trying to replay onto a log block");
1988 for (i = 0 ; i < get_desc_trans_len(desc) ; i++) { 2133 abort_replay:
1989 set_buffer_dirty(real_blocks[i]) ; 2134 brelse_array(log_blocks, i);
1990 ll_rw_block(WRITE, 1, real_blocks + i) ; 2135 brelse_array(real_blocks, i);
1991 } 2136 brelse(c_bh);
1992 for (i = 0 ; i < get_desc_trans_len(desc) ; i++) { 2137 brelse(d_bh);
1993 wait_on_buffer(real_blocks[i]) ; 2138 reiserfs_kfree(log_blocks,
1994 if (!buffer_uptodate(real_blocks[i])) { 2139 get_desc_trans_len(desc) *
1995 reiserfs_warning(p_s_sb, "journal-1226: REPLAY FAILURE, fsck required! buffer write failed") ; 2140 sizeof(struct buffer_head *), p_s_sb);
1996 brelse_array(real_blocks + i, get_desc_trans_len(desc) - i) ; 2141 reiserfs_kfree(real_blocks,
1997 brelse(c_bh) ; 2142 get_desc_trans_len(desc) *
1998 brelse(d_bh) ; 2143 sizeof(struct buffer_head *), p_s_sb);
1999 reiserfs_kfree(log_blocks, get_desc_trans_len(desc) * sizeof(struct buffer_head *), p_s_sb) ; 2144 return -1;
2000 reiserfs_kfree(real_blocks, get_desc_trans_len(desc) * sizeof(struct buffer_head *), p_s_sb) ; 2145 }
2001 return -1 ; 2146 }
2002 } 2147 /* read in the log blocks, memcpy to the corresponding real block */
2003 brelse(real_blocks[i]) ; 2148 ll_rw_block(READ, get_desc_trans_len(desc), log_blocks);
2004 } 2149 for (i = 0; i < get_desc_trans_len(desc); i++) {
2005 cur_dblock = SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) + ((trans_offset + get_desc_trans_len(desc) + 2) % SB_ONDISK_JOURNAL_SIZE(p_s_sb)) ; 2150 wait_on_buffer(log_blocks[i]);
2006 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, "journal-1095: setting journal " 2151 if (!buffer_uptodate(log_blocks[i])) {
2007 "start to offset %ld", 2152 reiserfs_warning(p_s_sb,
2008 cur_dblock - SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb)) ; 2153 "journal-1212: REPLAY FAILURE fsck required! buffer write failed");
2009 2154 brelse_array(log_blocks + i,
2010 /* init starting values for the first transaction, in case this is the last transaction to be replayed. */ 2155 get_desc_trans_len(desc) - i);
2011 journal->j_start = cur_dblock - SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) ; 2156 brelse_array(real_blocks, get_desc_trans_len(desc));
2012 journal->j_last_flush_trans_id = trans_id ; 2157 brelse(c_bh);
2013 journal->j_trans_id = trans_id + 1; 2158 brelse(d_bh);
2014 brelse(c_bh) ; 2159 reiserfs_kfree(log_blocks,
2015 brelse(d_bh) ; 2160 get_desc_trans_len(desc) *
2016 reiserfs_kfree(log_blocks, le32_to_cpu(desc->j_len) * sizeof(struct buffer_head *), p_s_sb) ; 2161 sizeof(struct buffer_head *), p_s_sb);
2017 reiserfs_kfree(real_blocks, le32_to_cpu(desc->j_len) * sizeof(struct buffer_head *), p_s_sb) ; 2162 reiserfs_kfree(real_blocks,
2018 return 0 ; 2163 get_desc_trans_len(desc) *
2164 sizeof(struct buffer_head *), p_s_sb);
2165 return -1;
2166 }
2167 memcpy(real_blocks[i]->b_data, log_blocks[i]->b_data,
2168 real_blocks[i]->b_size);
2169 set_buffer_uptodate(real_blocks[i]);
2170 brelse(log_blocks[i]);
2171 }
2172 /* flush out the real blocks */
2173 for (i = 0; i < get_desc_trans_len(desc); i++) {
2174 set_buffer_dirty(real_blocks[i]);
2175 ll_rw_block(WRITE, 1, real_blocks + i);
2176 }
2177 for (i = 0; i < get_desc_trans_len(desc); i++) {
2178 wait_on_buffer(real_blocks[i]);
2179 if (!buffer_uptodate(real_blocks[i])) {
2180 reiserfs_warning(p_s_sb,
2181 "journal-1226: REPLAY FAILURE, fsck required! buffer write failed");
2182 brelse_array(real_blocks + i,
2183 get_desc_trans_len(desc) - i);
2184 brelse(c_bh);
2185 brelse(d_bh);
2186 reiserfs_kfree(log_blocks,
2187 get_desc_trans_len(desc) *
2188 sizeof(struct buffer_head *), p_s_sb);
2189 reiserfs_kfree(real_blocks,
2190 get_desc_trans_len(desc) *
2191 sizeof(struct buffer_head *), p_s_sb);
2192 return -1;
2193 }
2194 brelse(real_blocks[i]);
2195 }
2196 cur_dblock =
2197 SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) +
2198 ((trans_offset + get_desc_trans_len(desc) +
2199 2) % SB_ONDISK_JOURNAL_SIZE(p_s_sb));
2200 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE,
2201 "journal-1095: setting journal " "start to offset %ld",
2202 cur_dblock - SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb));
2203
2204 /* init starting values for the first transaction, in case this is the last transaction to be replayed. */
2205 journal->j_start = cur_dblock - SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb);
2206 journal->j_last_flush_trans_id = trans_id;
2207 journal->j_trans_id = trans_id + 1;
2208 brelse(c_bh);
2209 brelse(d_bh);
2210 reiserfs_kfree(log_blocks,
2211 le32_to_cpu(desc->j_len) * sizeof(struct buffer_head *),
2212 p_s_sb);
2213 reiserfs_kfree(real_blocks,
2214 le32_to_cpu(desc->j_len) * sizeof(struct buffer_head *),
2215 p_s_sb);
2216 return 0;
2019} 2217}
2020 2218
2021/* This function reads blocks starting from block and to max_block of bufsize 2219/* This function reads blocks starting from block and to max_block of bufsize
@@ -2024,39 +2222,39 @@ abort_replay:
2024 Right now it is only used from journal code. But later we might use it 2222 Right now it is only used from journal code. But later we might use it
2025 from other places. 2223 from other places.
2026 Note: Do not use journal_getblk/sb_getblk functions here! */ 2224 Note: Do not use journal_getblk/sb_getblk functions here! */
2027static struct buffer_head * reiserfs_breada (struct block_device *dev, int block, int bufsize, 2225static struct buffer_head *reiserfs_breada(struct block_device *dev, int block,
2028 unsigned int max_block) 2226 int bufsize, unsigned int max_block)
2029{ 2227{
2030 struct buffer_head * bhlist[BUFNR]; 2228 struct buffer_head *bhlist[BUFNR];
2031 unsigned int blocks = BUFNR; 2229 unsigned int blocks = BUFNR;
2032 struct buffer_head * bh; 2230 struct buffer_head *bh;
2033 int i, j; 2231 int i, j;
2034 2232
2035 bh = __getblk (dev, block, bufsize ); 2233 bh = __getblk(dev, block, bufsize);
2036 if (buffer_uptodate (bh)) 2234 if (buffer_uptodate(bh))
2037 return (bh); 2235 return (bh);
2038 2236
2039 if (block + BUFNR > max_block) { 2237 if (block + BUFNR > max_block) {
2040 blocks = max_block - block; 2238 blocks = max_block - block;
2041 } 2239 }
2042 bhlist[0] = bh; 2240 bhlist[0] = bh;
2043 j = 1; 2241 j = 1;
2044 for (i = 1; i < blocks; i++) { 2242 for (i = 1; i < blocks; i++) {
2045 bh = __getblk (dev, block + i, bufsize); 2243 bh = __getblk(dev, block + i, bufsize);
2046 if (buffer_uptodate (bh)) { 2244 if (buffer_uptodate(bh)) {
2047 brelse (bh); 2245 brelse(bh);
2048 break; 2246 break;
2049 } 2247 } else
2050 else bhlist[j++] = bh; 2248 bhlist[j++] = bh;
2051 } 2249 }
2052 ll_rw_block (READ, j, bhlist); 2250 ll_rw_block(READ, j, bhlist);
2053 for(i = 1; i < j; i++) 2251 for (i = 1; i < j; i++)
2054 brelse (bhlist[i]); 2252 brelse(bhlist[i]);
2055 bh = bhlist[0]; 2253 bh = bhlist[0];
2056 wait_on_buffer (bh); 2254 wait_on_buffer(bh);
2057 if (buffer_uptodate (bh)) 2255 if (buffer_uptodate(bh))
2058 return bh; 2256 return bh;
2059 brelse (bh); 2257 brelse(bh);
2060 return NULL; 2258 return NULL;
2061} 2259}
2062 2260
@@ -2069,218 +2267,250 @@ static struct buffer_head * reiserfs_breada (struct block_device *dev, int block
2069** 2267**
2070** On exit, it sets things up so the first transaction will work correctly. 2268** On exit, it sets things up so the first transaction will work correctly.
2071*/ 2269*/
2072static int journal_read(struct super_block *p_s_sb) { 2270static int journal_read(struct super_block *p_s_sb)
2073 struct reiserfs_journal *journal = SB_JOURNAL (p_s_sb); 2271{
2074 struct reiserfs_journal_desc *desc ; 2272 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb);
2075 unsigned long oldest_trans_id = 0; 2273 struct reiserfs_journal_desc *desc;
2076 unsigned long oldest_invalid_trans_id = 0 ; 2274 unsigned long oldest_trans_id = 0;
2077 time_t start ; 2275 unsigned long oldest_invalid_trans_id = 0;
2078 unsigned long oldest_start = 0; 2276 time_t start;
2079 unsigned long cur_dblock = 0 ; 2277 unsigned long oldest_start = 0;
2080 unsigned long newest_mount_id = 9 ; 2278 unsigned long cur_dblock = 0;
2081 struct buffer_head *d_bh ; 2279 unsigned long newest_mount_id = 9;
2082 struct reiserfs_journal_header *jh ; 2280 struct buffer_head *d_bh;
2083 int valid_journal_header = 0 ; 2281 struct reiserfs_journal_header *jh;
2084 int replay_count = 0 ; 2282 int valid_journal_header = 0;
2085 int continue_replay = 1 ; 2283 int replay_count = 0;
2086 int ret ; 2284 int continue_replay = 1;
2087 char b[BDEVNAME_SIZE]; 2285 int ret;
2088 2286 char b[BDEVNAME_SIZE];
2089 cur_dblock = SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) ; 2287
2090 reiserfs_info (p_s_sb, "checking transaction log (%s)\n", 2288 cur_dblock = SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb);
2091 bdevname(journal->j_dev_bd, b)); 2289 reiserfs_info(p_s_sb, "checking transaction log (%s)\n",
2092 start = get_seconds(); 2290 bdevname(journal->j_dev_bd, b));
2093 2291 start = get_seconds();
2094 /* step 1, read in the journal header block. Check the transaction it says 2292
2095 ** is the first unflushed, and if that transaction is not valid, 2293 /* step 1, read in the journal header block. Check the transaction it says
2096 ** replay is done 2294 ** is the first unflushed, and if that transaction is not valid,
2097 */ 2295 ** replay is done
2098 journal->j_header_bh = journal_bread(p_s_sb, 2296 */
2099 SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) + 2297 journal->j_header_bh = journal_bread(p_s_sb,
2100 SB_ONDISK_JOURNAL_SIZE(p_s_sb)); 2298 SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb)
2101 if (!journal->j_header_bh) { 2299 + SB_ONDISK_JOURNAL_SIZE(p_s_sb));
2102 return 1 ; 2300 if (!journal->j_header_bh) {
2103 } 2301 return 1;
2104 jh = (struct reiserfs_journal_header *)(journal->j_header_bh->b_data) ; 2302 }
2105 if (le32_to_cpu(jh->j_first_unflushed_offset) >= 0 && 2303 jh = (struct reiserfs_journal_header *)(journal->j_header_bh->b_data);
2106 le32_to_cpu(jh->j_first_unflushed_offset) < SB_ONDISK_JOURNAL_SIZE(p_s_sb) && 2304 if (le32_to_cpu(jh->j_first_unflushed_offset) >= 0 &&
2107 le32_to_cpu(jh->j_last_flush_trans_id) > 0) { 2305 le32_to_cpu(jh->j_first_unflushed_offset) <
2108 oldest_start = SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) + 2306 SB_ONDISK_JOURNAL_SIZE(p_s_sb)
2109 le32_to_cpu(jh->j_first_unflushed_offset) ; 2307 && le32_to_cpu(jh->j_last_flush_trans_id) > 0) {
2110 oldest_trans_id = le32_to_cpu(jh->j_last_flush_trans_id) + 1; 2308 oldest_start =
2111 newest_mount_id = le32_to_cpu(jh->j_mount_id); 2309 SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) +
2112 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, "journal-1153: found in " 2310 le32_to_cpu(jh->j_first_unflushed_offset);
2113 "header: first_unflushed_offset %d, last_flushed_trans_id " 2311 oldest_trans_id = le32_to_cpu(jh->j_last_flush_trans_id) + 1;
2114 "%lu", le32_to_cpu(jh->j_first_unflushed_offset), 2312 newest_mount_id = le32_to_cpu(jh->j_mount_id);
2115 le32_to_cpu(jh->j_last_flush_trans_id)) ; 2313 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE,
2116 valid_journal_header = 1 ; 2314 "journal-1153: found in "
2117 2315 "header: first_unflushed_offset %d, last_flushed_trans_id "
2118 /* now, we try to read the first unflushed offset. If it is not valid, 2316 "%lu", le32_to_cpu(jh->j_first_unflushed_offset),
2119 ** there is nothing more we can do, and it makes no sense to read 2317 le32_to_cpu(jh->j_last_flush_trans_id));
2120 ** through the whole log. 2318 valid_journal_header = 1;
2121 */ 2319
2122 d_bh = journal_bread(p_s_sb, SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) + le32_to_cpu(jh->j_first_unflushed_offset)) ; 2320 /* now, we try to read the first unflushed offset. If it is not valid,
2123 ret = journal_transaction_is_valid(p_s_sb, d_bh, NULL, NULL) ; 2321 ** there is nothing more we can do, and it makes no sense to read
2124 if (!ret) { 2322 ** through the whole log.
2125 continue_replay = 0 ; 2323 */
2126 } 2324 d_bh =
2127 brelse(d_bh) ; 2325 journal_bread(p_s_sb,
2128 goto start_log_replay; 2326 SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) +
2129 } 2327 le32_to_cpu(jh->j_first_unflushed_offset));
2130 2328 ret = journal_transaction_is_valid(p_s_sb, d_bh, NULL, NULL);
2131 if (continue_replay && bdev_read_only(p_s_sb->s_bdev)) { 2329 if (!ret) {
2132 reiserfs_warning (p_s_sb, 2330 continue_replay = 0;
2133 "clm-2076: device is readonly, unable to replay log") ; 2331 }
2134 return -1 ; 2332 brelse(d_bh);
2135 } 2333 goto start_log_replay;
2136 2334 }
2137 /* ok, there are transactions that need to be replayed. start with the first log block, find 2335
2138 ** all the valid transactions, and pick out the oldest. 2336 if (continue_replay && bdev_read_only(p_s_sb->s_bdev)) {
2139 */ 2337 reiserfs_warning(p_s_sb,
2140 while(continue_replay && cur_dblock < (SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) + SB_ONDISK_JOURNAL_SIZE(p_s_sb))) { 2338 "clm-2076: device is readonly, unable to replay log");
2141 /* Note that it is required for blocksize of primary fs device and journal 2339 return -1;
2142 device to be the same */ 2340 }
2143 d_bh = reiserfs_breada(journal->j_dev_bd, cur_dblock, p_s_sb->s_blocksize, 2341
2144 SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) + SB_ONDISK_JOURNAL_SIZE(p_s_sb)) ; 2342 /* ok, there are transactions that need to be replayed. start with the first log block, find
2145 ret = journal_transaction_is_valid(p_s_sb, d_bh, &oldest_invalid_trans_id, &newest_mount_id) ; 2343 ** all the valid transactions, and pick out the oldest.
2146 if (ret == 1) { 2344 */
2147 desc = (struct reiserfs_journal_desc *)d_bh->b_data ; 2345 while (continue_replay
2148 if (oldest_start == 0) { /* init all oldest_ values */ 2346 && cur_dblock <
2149 oldest_trans_id = get_desc_trans_id(desc) ; 2347 (SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) +
2150 oldest_start = d_bh->b_blocknr ; 2348 SB_ONDISK_JOURNAL_SIZE(p_s_sb))) {
2151 newest_mount_id = get_desc_mount_id(desc) ; 2349 /* Note that it is required for blocksize of primary fs device and journal
2152 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, "journal-1179: Setting " 2350 device to be the same */
2153 "oldest_start to offset %llu, trans_id %lu", 2351 d_bh =
2154 oldest_start - SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb), 2352 reiserfs_breada(journal->j_dev_bd, cur_dblock,
2155 oldest_trans_id) ; 2353 p_s_sb->s_blocksize,
2156 } else if (oldest_trans_id > get_desc_trans_id(desc)) { 2354 SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) +
2157 /* one we just read was older */ 2355 SB_ONDISK_JOURNAL_SIZE(p_s_sb));
2158 oldest_trans_id = get_desc_trans_id(desc) ; 2356 ret =
2159 oldest_start = d_bh->b_blocknr ; 2357 journal_transaction_is_valid(p_s_sb, d_bh,
2160 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, "journal-1180: Resetting " 2358 &oldest_invalid_trans_id,
2161 "oldest_start to offset %lu, trans_id %lu", 2359 &newest_mount_id);
2162 oldest_start - SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb), 2360 if (ret == 1) {
2163 oldest_trans_id) ; 2361 desc = (struct reiserfs_journal_desc *)d_bh->b_data;
2164 } 2362 if (oldest_start == 0) { /* init all oldest_ values */
2165 if (newest_mount_id < get_desc_mount_id(desc)) { 2363 oldest_trans_id = get_desc_trans_id(desc);
2166 newest_mount_id = get_desc_mount_id(desc) ; 2364 oldest_start = d_bh->b_blocknr;
2365 newest_mount_id = get_desc_mount_id(desc);
2366 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE,
2367 "journal-1179: Setting "
2368 "oldest_start to offset %llu, trans_id %lu",
2369 oldest_start -
2370 SB_ONDISK_JOURNAL_1st_BLOCK
2371 (p_s_sb), oldest_trans_id);
2372 } else if (oldest_trans_id > get_desc_trans_id(desc)) {
2373 /* one we just read was older */
2374 oldest_trans_id = get_desc_trans_id(desc);
2375 oldest_start = d_bh->b_blocknr;
2376 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE,
2377 "journal-1180: Resetting "
2378 "oldest_start to offset %lu, trans_id %lu",
2379 oldest_start -
2380 SB_ONDISK_JOURNAL_1st_BLOCK
2381 (p_s_sb), oldest_trans_id);
2382 }
2383 if (newest_mount_id < get_desc_mount_id(desc)) {
2384 newest_mount_id = get_desc_mount_id(desc);
2385 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE,
2386 "journal-1299: Setting "
2387 "newest_mount_id to %d",
2388 get_desc_mount_id(desc));
2389 }
2390 cur_dblock += get_desc_trans_len(desc) + 2;
2391 } else {
2392 cur_dblock++;
2393 }
2394 brelse(d_bh);
2395 }
2396
2397 start_log_replay:
2398 cur_dblock = oldest_start;
2399 if (oldest_trans_id) {
2400 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE,
2401 "journal-1206: Starting replay "
2402 "from offset %llu, trans_id %lu",
2403 cur_dblock - SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb),
2404 oldest_trans_id);
2405
2406 }
2407 replay_count = 0;
2408 while (continue_replay && oldest_trans_id > 0) {
2409 ret =
2410 journal_read_transaction(p_s_sb, cur_dblock, oldest_start,
2411 oldest_trans_id, newest_mount_id);
2412 if (ret < 0) {
2413 return ret;
2414 } else if (ret != 0) {
2415 break;
2416 }
2417 cur_dblock =
2418 SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) + journal->j_start;
2419 replay_count++;
2420 if (cur_dblock == oldest_start)
2421 break;
2422 }
2423
2424 if (oldest_trans_id == 0) {
2425 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE,
2426 "journal-1225: No valid " "transactions found");
2427 }
2428 /* j_start does not get set correctly if we don't replay any transactions.
2429 ** if we had a valid journal_header, set j_start to the first unflushed transaction value,
2430 ** copy the trans_id from the header
2431 */
2432 if (valid_journal_header && replay_count == 0) {
2433 journal->j_start = le32_to_cpu(jh->j_first_unflushed_offset);
2434 journal->j_trans_id =
2435 le32_to_cpu(jh->j_last_flush_trans_id) + 1;
2436 journal->j_last_flush_trans_id =
2437 le32_to_cpu(jh->j_last_flush_trans_id);
2438 journal->j_mount_id = le32_to_cpu(jh->j_mount_id) + 1;
2439 } else {
2440 journal->j_mount_id = newest_mount_id + 1;
2441 }
2167 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, "journal-1299: Setting " 2442 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, "journal-1299: Setting "
2168 "newest_mount_id to %d", get_desc_mount_id(desc)); 2443 "newest_mount_id to %lu", journal->j_mount_id);
2169 } 2444 journal->j_first_unflushed_offset = journal->j_start;
2170 cur_dblock += get_desc_trans_len(desc) + 2 ; 2445 if (replay_count > 0) {
2171 } else { 2446 reiserfs_info(p_s_sb,
2172 cur_dblock++ ; 2447 "replayed %d transactions in %lu seconds\n",
2173 } 2448 replay_count, get_seconds() - start);
2174 brelse(d_bh) ; 2449 }
2175 } 2450 if (!bdev_read_only(p_s_sb->s_bdev) &&
2176 2451 _update_journal_header_block(p_s_sb, journal->j_start,
2177start_log_replay: 2452 journal->j_last_flush_trans_id)) {
2178 cur_dblock = oldest_start ; 2453 /* replay failed, caller must call free_journal_ram and abort
2179 if (oldest_trans_id) { 2454 ** the mount
2180 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, "journal-1206: Starting replay " 2455 */
2181 "from offset %llu, trans_id %lu", 2456 return -1;
2182 cur_dblock - SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb), 2457 }
2183 oldest_trans_id) ; 2458 return 0;
2184
2185 }
2186 replay_count = 0 ;
2187 while(continue_replay && oldest_trans_id > 0) {
2188 ret = journal_read_transaction(p_s_sb, cur_dblock, oldest_start, oldest_trans_id, newest_mount_id) ;
2189 if (ret < 0) {
2190 return ret ;
2191 } else if (ret != 0) {
2192 break ;
2193 }
2194 cur_dblock = SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) + journal->j_start ;
2195 replay_count++ ;
2196 if (cur_dblock == oldest_start)
2197 break;
2198 }
2199
2200 if (oldest_trans_id == 0) {
2201 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, "journal-1225: No valid "
2202 "transactions found") ;
2203 }
2204 /* j_start does not get set correctly if we don't replay any transactions.
2205 ** if we had a valid journal_header, set j_start to the first unflushed transaction value,
2206 ** copy the trans_id from the header
2207 */
2208 if (valid_journal_header && replay_count == 0) {
2209 journal->j_start = le32_to_cpu(jh->j_first_unflushed_offset) ;
2210 journal->j_trans_id = le32_to_cpu(jh->j_last_flush_trans_id) + 1;
2211 journal->j_last_flush_trans_id = le32_to_cpu(jh->j_last_flush_trans_id) ;
2212 journal->j_mount_id = le32_to_cpu(jh->j_mount_id) + 1;
2213 } else {
2214 journal->j_mount_id = newest_mount_id + 1 ;
2215 }
2216 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, "journal-1299: Setting "
2217 "newest_mount_id to %lu", journal->j_mount_id) ;
2218 journal->j_first_unflushed_offset = journal->j_start ;
2219 if (replay_count > 0) {
2220 reiserfs_info (p_s_sb, "replayed %d transactions in %lu seconds\n",
2221 replay_count, get_seconds() - start) ;
2222 }
2223 if (!bdev_read_only(p_s_sb->s_bdev) &&
2224 _update_journal_header_block(p_s_sb, journal->j_start,
2225 journal->j_last_flush_trans_id))
2226 {
2227 /* replay failed, caller must call free_journal_ram and abort
2228 ** the mount
2229 */
2230 return -1 ;
2231 }
2232 return 0 ;
2233} 2459}
2234 2460
2235static struct reiserfs_journal_list *alloc_journal_list(struct super_block *s) 2461static struct reiserfs_journal_list *alloc_journal_list(struct super_block *s)
2236{ 2462{
2237 struct reiserfs_journal_list *jl; 2463 struct reiserfs_journal_list *jl;
2238retry: 2464 retry:
2239 jl = reiserfs_kmalloc(sizeof(struct reiserfs_journal_list), GFP_NOFS, s); 2465 jl = reiserfs_kmalloc(sizeof(struct reiserfs_journal_list), GFP_NOFS,
2240 if (!jl) { 2466 s);
2241 yield(); 2467 if (!jl) {
2242 goto retry; 2468 yield();
2243 } 2469 goto retry;
2244 memset(jl, 0, sizeof(*jl)); 2470 }
2245 INIT_LIST_HEAD(&jl->j_list); 2471 memset(jl, 0, sizeof(*jl));
2246 INIT_LIST_HEAD(&jl->j_working_list); 2472 INIT_LIST_HEAD(&jl->j_list);
2247 INIT_LIST_HEAD(&jl->j_tail_bh_list); 2473 INIT_LIST_HEAD(&jl->j_working_list);
2248 INIT_LIST_HEAD(&jl->j_bh_list); 2474 INIT_LIST_HEAD(&jl->j_tail_bh_list);
2249 sema_init(&jl->j_commit_lock, 1); 2475 INIT_LIST_HEAD(&jl->j_bh_list);
2250 SB_JOURNAL(s)->j_num_lists++; 2476 sema_init(&jl->j_commit_lock, 1);
2251 get_journal_list(jl); 2477 SB_JOURNAL(s)->j_num_lists++;
2252 return jl; 2478 get_journal_list(jl);
2253} 2479 return jl;
2254 2480}
2255static void journal_list_init(struct super_block *p_s_sb) { 2481
2256 SB_JOURNAL(p_s_sb)->j_current_jl = alloc_journal_list(p_s_sb); 2482static void journal_list_init(struct super_block *p_s_sb)
2257} 2483{
2258 2484 SB_JOURNAL(p_s_sb)->j_current_jl = alloc_journal_list(p_s_sb);
2259static int release_journal_dev( struct super_block *super, 2485}
2260 struct reiserfs_journal *journal ) 2486
2261{ 2487static int release_journal_dev(struct super_block *super,
2262 int result; 2488 struct reiserfs_journal *journal)
2263 2489{
2264 result = 0; 2490 int result;
2265 2491
2266 if( journal -> j_dev_file != NULL ) { 2492 result = 0;
2267 result = filp_close( journal -> j_dev_file, NULL ); 2493
2268 journal -> j_dev_file = NULL; 2494 if (journal->j_dev_file != NULL) {
2269 journal -> j_dev_bd = NULL; 2495 result = filp_close(journal->j_dev_file, NULL);
2270 } else if( journal -> j_dev_bd != NULL ) { 2496 journal->j_dev_file = NULL;
2271 result = blkdev_put( journal -> j_dev_bd ); 2497 journal->j_dev_bd = NULL;
2272 journal -> j_dev_bd = NULL; 2498 } else if (journal->j_dev_bd != NULL) {
2273 } 2499 result = blkdev_put(journal->j_dev_bd);
2274 2500 journal->j_dev_bd = NULL;
2275 if( result != 0 ) { 2501 }
2276 reiserfs_warning(super, "sh-457: release_journal_dev: Cannot release journal device: %i", result ); 2502
2277 } 2503 if (result != 0) {
2278 return result; 2504 reiserfs_warning(super,
2279} 2505 "sh-457: release_journal_dev: Cannot release journal device: %i",
2280 2506 result);
2281static int journal_init_dev( struct super_block *super, 2507 }
2282 struct reiserfs_journal *journal, 2508 return result;
2283 const char *jdev_name ) 2509}
2510
2511static int journal_init_dev(struct super_block *super,
2512 struct reiserfs_journal *journal,
2513 const char *jdev_name)
2284{ 2514{
2285 int result; 2515 int result;
2286 dev_t jdev; 2516 dev_t jdev;
@@ -2289,50 +2519,51 @@ static int journal_init_dev( struct super_block *super,
2289 2519
2290 result = 0; 2520 result = 0;
2291 2521
2292 journal -> j_dev_bd = NULL; 2522 journal->j_dev_bd = NULL;
2293 journal -> j_dev_file = NULL; 2523 journal->j_dev_file = NULL;
2294 jdev = SB_ONDISK_JOURNAL_DEVICE( super ) ? 2524 jdev = SB_ONDISK_JOURNAL_DEVICE(super) ?
2295 new_decode_dev(SB_ONDISK_JOURNAL_DEVICE(super)) : super->s_dev; 2525 new_decode_dev(SB_ONDISK_JOURNAL_DEVICE(super)) : super->s_dev;
2296 2526
2297 if (bdev_read_only(super->s_bdev)) 2527 if (bdev_read_only(super->s_bdev))
2298 blkdev_mode = FMODE_READ; 2528 blkdev_mode = FMODE_READ;
2299 2529
2300 /* there is no "jdev" option and journal is on separate device */ 2530 /* there is no "jdev" option and journal is on separate device */
2301 if( ( !jdev_name || !jdev_name[ 0 ] ) ) { 2531 if ((!jdev_name || !jdev_name[0])) {
2302 journal->j_dev_bd = open_by_devnum(jdev, blkdev_mode); 2532 journal->j_dev_bd = open_by_devnum(jdev, blkdev_mode);
2303 if (IS_ERR(journal->j_dev_bd)) { 2533 if (IS_ERR(journal->j_dev_bd)) {
2304 result = PTR_ERR(journal->j_dev_bd); 2534 result = PTR_ERR(journal->j_dev_bd);
2305 journal->j_dev_bd = NULL; 2535 journal->j_dev_bd = NULL;
2306 reiserfs_warning (super, "sh-458: journal_init_dev: " 2536 reiserfs_warning(super, "sh-458: journal_init_dev: "
2307 "cannot init journal device '%s': %i", 2537 "cannot init journal device '%s': %i",
2308 __bdevname(jdev, b), result ); 2538 __bdevname(jdev, b), result);
2309 return result; 2539 return result;
2310 } else if (jdev != super->s_dev) 2540 } else if (jdev != super->s_dev)
2311 set_blocksize(journal->j_dev_bd, super->s_blocksize); 2541 set_blocksize(journal->j_dev_bd, super->s_blocksize);
2312 return 0; 2542 return 0;
2313 } 2543 }
2314 2544
2315 journal -> j_dev_file = filp_open( jdev_name, 0, 0 ); 2545 journal->j_dev_file = filp_open(jdev_name, 0, 0);
2316 if( !IS_ERR( journal -> j_dev_file ) ) { 2546 if (!IS_ERR(journal->j_dev_file)) {
2317 struct inode *jdev_inode = journal->j_dev_file->f_mapping->host; 2547 struct inode *jdev_inode = journal->j_dev_file->f_mapping->host;
2318 if( !S_ISBLK( jdev_inode -> i_mode ) ) { 2548 if (!S_ISBLK(jdev_inode->i_mode)) {
2319 reiserfs_warning(super, "journal_init_dev: '%s' is " 2549 reiserfs_warning(super, "journal_init_dev: '%s' is "
2320 "not a block device", jdev_name ); 2550 "not a block device", jdev_name);
2321 result = -ENOTBLK; 2551 result = -ENOTBLK;
2322 release_journal_dev( super, journal ); 2552 release_journal_dev(super, journal);
2323 } else { 2553 } else {
2324 /* ok */ 2554 /* ok */
2325 journal->j_dev_bd = I_BDEV(jdev_inode); 2555 journal->j_dev_bd = I_BDEV(jdev_inode);
2326 set_blocksize(journal->j_dev_bd, super->s_blocksize); 2556 set_blocksize(journal->j_dev_bd, super->s_blocksize);
2327 reiserfs_info(super, "journal_init_dev: journal device: %s\n", 2557 reiserfs_info(super,
2558 "journal_init_dev: journal device: %s\n",
2328 bdevname(journal->j_dev_bd, b)); 2559 bdevname(journal->j_dev_bd, b));
2329 } 2560 }
2330 } else { 2561 } else {
2331 result = PTR_ERR( journal -> j_dev_file ); 2562 result = PTR_ERR(journal->j_dev_file);
2332 journal -> j_dev_file = NULL; 2563 journal->j_dev_file = NULL;
2333 reiserfs_warning (super, 2564 reiserfs_warning(super,
2334 "journal_init_dev: Cannot open '%s': %i", 2565 "journal_init_dev: Cannot open '%s': %i",
2335 jdev_name, result ); 2566 jdev_name, result);
2336 } 2567 }
2337 return result; 2568 return result;
2338} 2569}
@@ -2340,193 +2571,214 @@ static int journal_init_dev( struct super_block *super,
2340/* 2571/*
2341** must be called once on fs mount. calls journal_read for you 2572** must be called once on fs mount. calls journal_read for you
2342*/ 2573*/
2343int journal_init(struct super_block *p_s_sb, const char * j_dev_name, int old_format, unsigned int commit_max_age) { 2574int journal_init(struct super_block *p_s_sb, const char *j_dev_name,
2344 int num_cnodes = SB_ONDISK_JOURNAL_SIZE(p_s_sb) * 2 ; 2575 int old_format, unsigned int commit_max_age)
2345 struct buffer_head *bhjh; 2576{
2346 struct reiserfs_super_block * rs; 2577 int num_cnodes = SB_ONDISK_JOURNAL_SIZE(p_s_sb) * 2;
2347 struct reiserfs_journal_header *jh; 2578 struct buffer_head *bhjh;
2348 struct reiserfs_journal *journal; 2579 struct reiserfs_super_block *rs;
2349 struct reiserfs_journal_list *jl; 2580 struct reiserfs_journal_header *jh;
2350 char b[BDEVNAME_SIZE]; 2581 struct reiserfs_journal *journal;
2351 2582 struct reiserfs_journal_list *jl;
2352 journal = SB_JOURNAL(p_s_sb) = vmalloc(sizeof (struct reiserfs_journal)) ; 2583 char b[BDEVNAME_SIZE];
2353 if (!journal) { 2584
2354 reiserfs_warning (p_s_sb, "journal-1256: unable to get memory for journal structure") ; 2585 journal = SB_JOURNAL(p_s_sb) = vmalloc(sizeof(struct reiserfs_journal));
2355 return 1 ; 2586 if (!journal) {
2356 } 2587 reiserfs_warning(p_s_sb,
2357 memset(journal, 0, sizeof(struct reiserfs_journal)) ; 2588 "journal-1256: unable to get memory for journal structure");
2358 INIT_LIST_HEAD(&journal->j_bitmap_nodes) ; 2589 return 1;
2359 INIT_LIST_HEAD (&journal->j_prealloc_list); 2590 }
2360 INIT_LIST_HEAD(&journal->j_working_list); 2591 memset(journal, 0, sizeof(struct reiserfs_journal));
2361 INIT_LIST_HEAD(&journal->j_journal_list); 2592 INIT_LIST_HEAD(&journal->j_bitmap_nodes);
2362 journal->j_persistent_trans = 0; 2593 INIT_LIST_HEAD(&journal->j_prealloc_list);
2363 if (reiserfs_allocate_list_bitmaps(p_s_sb, 2594 INIT_LIST_HEAD(&journal->j_working_list);
2364 journal->j_list_bitmap, 2595 INIT_LIST_HEAD(&journal->j_journal_list);
2365 SB_BMAP_NR(p_s_sb))) 2596 journal->j_persistent_trans = 0;
2366 goto free_and_return ; 2597 if (reiserfs_allocate_list_bitmaps(p_s_sb,
2367 allocate_bitmap_nodes(p_s_sb) ; 2598 journal->j_list_bitmap,
2368 2599 SB_BMAP_NR(p_s_sb)))
2369 /* reserved for journal area support */ 2600 goto free_and_return;
2370 SB_JOURNAL_1st_RESERVED_BLOCK(p_s_sb) = (old_format ? 2601 allocate_bitmap_nodes(p_s_sb);
2371 REISERFS_OLD_DISK_OFFSET_IN_BYTES / p_s_sb->s_blocksize + 2602
2372 SB_BMAP_NR(p_s_sb) + 1 : 2603 /* reserved for journal area support */
2373 REISERFS_DISK_OFFSET_IN_BYTES / p_s_sb->s_blocksize + 2); 2604 SB_JOURNAL_1st_RESERVED_BLOCK(p_s_sb) = (old_format ?
2374 2605 REISERFS_OLD_DISK_OFFSET_IN_BYTES
2375 /* Sanity check to see is the standard journal fitting withing first bitmap 2606 / p_s_sb->s_blocksize +
2376 (actual for small blocksizes) */ 2607 SB_BMAP_NR(p_s_sb) +
2377 if ( !SB_ONDISK_JOURNAL_DEVICE( p_s_sb ) && 2608 1 :
2378 (SB_JOURNAL_1st_RESERVED_BLOCK(p_s_sb) + SB_ONDISK_JOURNAL_SIZE(p_s_sb) > p_s_sb->s_blocksize * 8) ) { 2609 REISERFS_DISK_OFFSET_IN_BYTES /
2379 reiserfs_warning (p_s_sb, "journal-1393: journal does not fit for area " 2610 p_s_sb->s_blocksize + 2);
2380 "addressed by first of bitmap blocks. It starts at " 2611
2381 "%u and its size is %u. Block size %ld", 2612 /* Sanity check to see is the standard journal fitting withing first bitmap
2382 SB_JOURNAL_1st_RESERVED_BLOCK(p_s_sb), 2613 (actual for small blocksizes) */
2383 SB_ONDISK_JOURNAL_SIZE(p_s_sb), p_s_sb->s_blocksize); 2614 if (!SB_ONDISK_JOURNAL_DEVICE(p_s_sb) &&
2384 goto free_and_return; 2615 (SB_JOURNAL_1st_RESERVED_BLOCK(p_s_sb) +
2385 } 2616 SB_ONDISK_JOURNAL_SIZE(p_s_sb) > p_s_sb->s_blocksize * 8)) {
2386 2617 reiserfs_warning(p_s_sb,
2387 if( journal_init_dev( p_s_sb, journal, j_dev_name ) != 0 ) { 2618 "journal-1393: journal does not fit for area "
2388 reiserfs_warning (p_s_sb, "sh-462: unable to initialize jornal device"); 2619 "addressed by first of bitmap blocks. It starts at "
2389 goto free_and_return; 2620 "%u and its size is %u. Block size %ld",
2390 } 2621 SB_JOURNAL_1st_RESERVED_BLOCK(p_s_sb),
2391 2622 SB_ONDISK_JOURNAL_SIZE(p_s_sb),
2392 rs = SB_DISK_SUPER_BLOCK(p_s_sb); 2623 p_s_sb->s_blocksize);
2393 2624 goto free_and_return;
2394 /* read journal header */ 2625 }
2395 bhjh = journal_bread(p_s_sb, 2626
2396 SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) + SB_ONDISK_JOURNAL_SIZE(p_s_sb)); 2627 if (journal_init_dev(p_s_sb, journal, j_dev_name) != 0) {
2397 if (!bhjh) { 2628 reiserfs_warning(p_s_sb,
2398 reiserfs_warning (p_s_sb, "sh-459: unable to read journal header"); 2629 "sh-462: unable to initialize jornal device");
2399 goto free_and_return; 2630 goto free_and_return;
2400 } 2631 }
2401 jh = (struct reiserfs_journal_header *)(bhjh->b_data); 2632
2402 2633 rs = SB_DISK_SUPER_BLOCK(p_s_sb);
2403 /* make sure that journal matches to the super block */ 2634
2404 if (is_reiserfs_jr(rs) && (le32_to_cpu(jh->jh_journal.jp_journal_magic) != sb_jp_journal_magic(rs))) { 2635 /* read journal header */
2405 reiserfs_warning (p_s_sb, "sh-460: journal header magic %x " 2636 bhjh = journal_bread(p_s_sb,
2406 "(device %s) does not match to magic found in super " 2637 SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) +
2407 "block %x", 2638 SB_ONDISK_JOURNAL_SIZE(p_s_sb));
2408 jh->jh_journal.jp_journal_magic, 2639 if (!bhjh) {
2409 bdevname( journal->j_dev_bd, b), 2640 reiserfs_warning(p_s_sb,
2410 sb_jp_journal_magic(rs)); 2641 "sh-459: unable to read journal header");
2411 brelse (bhjh); 2642 goto free_and_return;
2412 goto free_and_return; 2643 }
2413 } 2644 jh = (struct reiserfs_journal_header *)(bhjh->b_data);
2414 2645
2415 journal->j_trans_max = le32_to_cpu (jh->jh_journal.jp_journal_trans_max); 2646 /* make sure that journal matches to the super block */
2416 journal->j_max_batch = le32_to_cpu (jh->jh_journal.jp_journal_max_batch); 2647 if (is_reiserfs_jr(rs)
2417 journal->j_max_commit_age = le32_to_cpu (jh->jh_journal.jp_journal_max_commit_age); 2648 && (le32_to_cpu(jh->jh_journal.jp_journal_magic) !=
2418 journal->j_max_trans_age = JOURNAL_MAX_TRANS_AGE; 2649 sb_jp_journal_magic(rs))) {
2419 2650 reiserfs_warning(p_s_sb,
2420 if (journal->j_trans_max) { 2651 "sh-460: journal header magic %x "
2421 /* make sure these parameters are available, assign it if they are not */ 2652 "(device %s) does not match to magic found in super "
2422 __u32 initial = journal->j_trans_max; 2653 "block %x", jh->jh_journal.jp_journal_magic,
2423 __u32 ratio = 1; 2654 bdevname(journal->j_dev_bd, b),
2424 2655 sb_jp_journal_magic(rs));
2425 if (p_s_sb->s_blocksize < 4096) 2656 brelse(bhjh);
2426 ratio = 4096 / p_s_sb->s_blocksize; 2657 goto free_and_return;
2427 2658 }
2428 if (SB_ONDISK_JOURNAL_SIZE(p_s_sb)/journal->j_trans_max < JOURNAL_MIN_RATIO) 2659
2429 journal->j_trans_max = SB_ONDISK_JOURNAL_SIZE(p_s_sb) / JOURNAL_MIN_RATIO; 2660 journal->j_trans_max = le32_to_cpu(jh->jh_journal.jp_journal_trans_max);
2430 if (journal->j_trans_max > JOURNAL_TRANS_MAX_DEFAULT / ratio) 2661 journal->j_max_batch = le32_to_cpu(jh->jh_journal.jp_journal_max_batch);
2431 journal->j_trans_max = JOURNAL_TRANS_MAX_DEFAULT / ratio; 2662 journal->j_max_commit_age =
2432 if (journal->j_trans_max < JOURNAL_TRANS_MIN_DEFAULT / ratio) 2663 le32_to_cpu(jh->jh_journal.jp_journal_max_commit_age);
2433 journal->j_trans_max = JOURNAL_TRANS_MIN_DEFAULT / ratio; 2664 journal->j_max_trans_age = JOURNAL_MAX_TRANS_AGE;
2434 2665
2435 if (journal->j_trans_max != initial) 2666 if (journal->j_trans_max) {
2436 reiserfs_warning (p_s_sb, "sh-461: journal_init: wrong transaction max size (%u). Changed to %u", 2667 /* make sure these parameters are available, assign it if they are not */
2437 initial, journal->j_trans_max); 2668 __u32 initial = journal->j_trans_max;
2438 2669 __u32 ratio = 1;
2439 journal->j_max_batch = journal->j_trans_max* 2670
2440 JOURNAL_MAX_BATCH_DEFAULT/JOURNAL_TRANS_MAX_DEFAULT; 2671 if (p_s_sb->s_blocksize < 4096)
2441 } 2672 ratio = 4096 / p_s_sb->s_blocksize;
2442 2673
2443 if (!journal->j_trans_max) { 2674 if (SB_ONDISK_JOURNAL_SIZE(p_s_sb) / journal->j_trans_max <
2444 /*we have the file system was created by old version of mkreiserfs 2675 JOURNAL_MIN_RATIO)
2445 so this field contains zero value */ 2676 journal->j_trans_max =
2446 journal->j_trans_max = JOURNAL_TRANS_MAX_DEFAULT ; 2677 SB_ONDISK_JOURNAL_SIZE(p_s_sb) / JOURNAL_MIN_RATIO;
2447 journal->j_max_batch = JOURNAL_MAX_BATCH_DEFAULT ; 2678 if (journal->j_trans_max > JOURNAL_TRANS_MAX_DEFAULT / ratio)
2448 journal->j_max_commit_age = JOURNAL_MAX_COMMIT_AGE ; 2679 journal->j_trans_max =
2449 2680 JOURNAL_TRANS_MAX_DEFAULT / ratio;
2450 /* for blocksize >= 4096 - max transaction size is 1024. For block size < 4096 2681 if (journal->j_trans_max < JOURNAL_TRANS_MIN_DEFAULT / ratio)
2451 trans max size is decreased proportionally */ 2682 journal->j_trans_max =
2452 if (p_s_sb->s_blocksize < 4096) { 2683 JOURNAL_TRANS_MIN_DEFAULT / ratio;
2453 journal->j_trans_max /= (4096 / p_s_sb->s_blocksize) ; 2684
2454 journal->j_max_batch = (journal->j_trans_max) * 9 / 10 ; 2685 if (journal->j_trans_max != initial)
2455 } 2686 reiserfs_warning(p_s_sb,
2456 } 2687 "sh-461: journal_init: wrong transaction max size (%u). Changed to %u",
2457 2688 initial, journal->j_trans_max);
2458 journal->j_default_max_commit_age = journal->j_max_commit_age; 2689
2459 2690 journal->j_max_batch = journal->j_trans_max *
2460 if (commit_max_age != 0) { 2691 JOURNAL_MAX_BATCH_DEFAULT / JOURNAL_TRANS_MAX_DEFAULT;
2461 journal->j_max_commit_age = commit_max_age; 2692 }
2462 journal->j_max_trans_age = commit_max_age; 2693
2463 } 2694 if (!journal->j_trans_max) {
2464 2695 /*we have the file system was created by old version of mkreiserfs
2465 reiserfs_info (p_s_sb, "journal params: device %s, size %u, " 2696 so this field contains zero value */
2466 "journal first block %u, max trans len %u, max batch %u, " 2697 journal->j_trans_max = JOURNAL_TRANS_MAX_DEFAULT;
2467 "max commit age %u, max trans age %u\n", 2698 journal->j_max_batch = JOURNAL_MAX_BATCH_DEFAULT;
2468 bdevname( journal->j_dev_bd, b), 2699 journal->j_max_commit_age = JOURNAL_MAX_COMMIT_AGE;
2469 SB_ONDISK_JOURNAL_SIZE(p_s_sb), 2700
2470 SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb), 2701 /* for blocksize >= 4096 - max transaction size is 1024. For block size < 4096
2471 journal->j_trans_max, 2702 trans max size is decreased proportionally */
2472 journal->j_max_batch, 2703 if (p_s_sb->s_blocksize < 4096) {
2473 journal->j_max_commit_age, 2704 journal->j_trans_max /= (4096 / p_s_sb->s_blocksize);
2474 journal->j_max_trans_age); 2705 journal->j_max_batch = (journal->j_trans_max) * 9 / 10;
2475 2706 }
2476 brelse (bhjh); 2707 }
2477 2708
2478 journal->j_list_bitmap_index = 0 ; 2709 journal->j_default_max_commit_age = journal->j_max_commit_age;
2479 journal_list_init(p_s_sb) ; 2710
2480 2711 if (commit_max_age != 0) {
2481 memset(journal->j_list_hash_table, 0, JOURNAL_HASH_SIZE * sizeof(struct reiserfs_journal_cnode *)) ; 2712 journal->j_max_commit_age = commit_max_age;
2482 2713 journal->j_max_trans_age = commit_max_age;
2483 INIT_LIST_HEAD(&journal->j_dirty_buffers) ; 2714 }
2484 spin_lock_init(&journal->j_dirty_buffers_lock) ; 2715
2485 2716 reiserfs_info(p_s_sb, "journal params: device %s, size %u, "
2486 journal->j_start = 0 ; 2717 "journal first block %u, max trans len %u, max batch %u, "
2487 journal->j_len = 0 ; 2718 "max commit age %u, max trans age %u\n",
2488 journal->j_len_alloc = 0 ; 2719 bdevname(journal->j_dev_bd, b),
2489 atomic_set(&(journal->j_wcount), 0) ; 2720 SB_ONDISK_JOURNAL_SIZE(p_s_sb),
2490 atomic_set(&(journal->j_async_throttle), 0) ; 2721 SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb),
2491 journal->j_bcount = 0 ; 2722 journal->j_trans_max,
2492 journal->j_trans_start_time = 0 ; 2723 journal->j_max_batch,
2493 journal->j_last = NULL ; 2724 journal->j_max_commit_age, journal->j_max_trans_age);
2494 journal->j_first = NULL ; 2725
2495 init_waitqueue_head(&(journal->j_join_wait)) ; 2726 brelse(bhjh);
2496 sema_init(&journal->j_lock, 1); 2727
2497 sema_init(&journal->j_flush_sem, 1); 2728 journal->j_list_bitmap_index = 0;
2498 2729 journal_list_init(p_s_sb);
2499 journal->j_trans_id = 10 ; 2730
2500 journal->j_mount_id = 10 ; 2731 memset(journal->j_list_hash_table, 0,
2501 journal->j_state = 0 ; 2732 JOURNAL_HASH_SIZE * sizeof(struct reiserfs_journal_cnode *));
2502 atomic_set(&(journal->j_jlock), 0) ; 2733
2503 journal->j_cnode_free_list = allocate_cnodes(num_cnodes) ; 2734 INIT_LIST_HEAD(&journal->j_dirty_buffers);
2504 journal->j_cnode_free_orig = journal->j_cnode_free_list ; 2735 spin_lock_init(&journal->j_dirty_buffers_lock);
2505 journal->j_cnode_free = journal->j_cnode_free_list ? num_cnodes : 0 ; 2736
2506 journal->j_cnode_used = 0 ; 2737 journal->j_start = 0;
2507 journal->j_must_wait = 0 ; 2738 journal->j_len = 0;
2508 2739 journal->j_len_alloc = 0;
2509 init_journal_hash(p_s_sb) ; 2740 atomic_set(&(journal->j_wcount), 0);
2510 jl = journal->j_current_jl; 2741 atomic_set(&(journal->j_async_throttle), 0);
2511 jl->j_list_bitmap = get_list_bitmap(p_s_sb, jl); 2742 journal->j_bcount = 0;
2512 if (!jl->j_list_bitmap) { 2743 journal->j_trans_start_time = 0;
2513 reiserfs_warning(p_s_sb, "journal-2005, get_list_bitmap failed for journal list 0") ; 2744 journal->j_last = NULL;
2514 goto free_and_return; 2745 journal->j_first = NULL;
2515 } 2746 init_waitqueue_head(&(journal->j_join_wait));
2516 if (journal_read(p_s_sb) < 0) { 2747 sema_init(&journal->j_lock, 1);
2517 reiserfs_warning(p_s_sb, "Replay Failure, unable to mount") ; 2748 sema_init(&journal->j_flush_sem, 1);
2518 goto free_and_return; 2749
2519 } 2750 journal->j_trans_id = 10;
2520 2751 journal->j_mount_id = 10;
2521 reiserfs_mounted_fs_count++ ; 2752 journal->j_state = 0;
2522 if (reiserfs_mounted_fs_count <= 1) 2753 atomic_set(&(journal->j_jlock), 0);
2523 commit_wq = create_workqueue("reiserfs"); 2754 journal->j_cnode_free_list = allocate_cnodes(num_cnodes);
2524 2755 journal->j_cnode_free_orig = journal->j_cnode_free_list;
2525 INIT_WORK(&journal->j_work, flush_async_commits, p_s_sb); 2756 journal->j_cnode_free = journal->j_cnode_free_list ? num_cnodes : 0;
2526 return 0 ; 2757 journal->j_cnode_used = 0;
2527free_and_return: 2758 journal->j_must_wait = 0;
2528 free_journal_ram(p_s_sb); 2759
2529 return 1; 2760 init_journal_hash(p_s_sb);
2761 jl = journal->j_current_jl;
2762 jl->j_list_bitmap = get_list_bitmap(p_s_sb, jl);
2763 if (!jl->j_list_bitmap) {
2764 reiserfs_warning(p_s_sb,
2765 "journal-2005, get_list_bitmap failed for journal list 0");
2766 goto free_and_return;
2767 }
2768 if (journal_read(p_s_sb) < 0) {
2769 reiserfs_warning(p_s_sb, "Replay Failure, unable to mount");
2770 goto free_and_return;
2771 }
2772
2773 reiserfs_mounted_fs_count++;
2774 if (reiserfs_mounted_fs_count <= 1)
2775 commit_wq = create_workqueue("reiserfs");
2776
2777 INIT_WORK(&journal->j_work, flush_async_commits, p_s_sb);
2778 return 0;
2779 free_and_return:
2780 free_journal_ram(p_s_sb);
2781 return 1;
2530} 2782}
2531 2783
2532/* 2784/*
@@ -2534,96 +2786,102 @@ free_and_return:
2534** be used by delete to make sure they don't write more than can fit inside a single 2786** be used by delete to make sure they don't write more than can fit inside a single
2535** transaction 2787** transaction
2536*/ 2788*/
2537int journal_transaction_should_end(struct reiserfs_transaction_handle *th, int new_alloc) { 2789int journal_transaction_should_end(struct reiserfs_transaction_handle *th,
2538 struct reiserfs_journal *journal = SB_JOURNAL (th->t_super); 2790 int new_alloc)
2539 time_t now = get_seconds() ; 2791{
2540 /* cannot restart while nested */ 2792 struct reiserfs_journal *journal = SB_JOURNAL(th->t_super);
2541 BUG_ON (!th->t_trans_id); 2793 time_t now = get_seconds();
2542 if (th->t_refcount > 1) 2794 /* cannot restart while nested */
2543 return 0 ; 2795 BUG_ON(!th->t_trans_id);
2544 if ( journal->j_must_wait > 0 || 2796 if (th->t_refcount > 1)
2545 (journal->j_len_alloc + new_alloc) >= journal->j_max_batch || 2797 return 0;
2546 atomic_read(&(journal->j_jlock)) || 2798 if (journal->j_must_wait > 0 ||
2547 (now - journal->j_trans_start_time) > journal->j_max_trans_age || 2799 (journal->j_len_alloc + new_alloc) >= journal->j_max_batch ||
2548 journal->j_cnode_free < (journal->j_trans_max * 3)) { 2800 atomic_read(&(journal->j_jlock)) ||
2549 return 1 ; 2801 (now - journal->j_trans_start_time) > journal->j_max_trans_age ||
2550 } 2802 journal->j_cnode_free < (journal->j_trans_max * 3)) {
2551 return 0 ; 2803 return 1;
2804 }
2805 return 0;
2552} 2806}
2553 2807
2554/* this must be called inside a transaction, and requires the 2808/* this must be called inside a transaction, and requires the
2555** kernel_lock to be held 2809** kernel_lock to be held
2556*/ 2810*/
2557void reiserfs_block_writes(struct reiserfs_transaction_handle *th) { 2811void reiserfs_block_writes(struct reiserfs_transaction_handle *th)
2558 struct reiserfs_journal *journal = SB_JOURNAL (th->t_super); 2812{
2559 BUG_ON (!th->t_trans_id); 2813 struct reiserfs_journal *journal = SB_JOURNAL(th->t_super);
2560 journal->j_must_wait = 1 ; 2814 BUG_ON(!th->t_trans_id);
2561 set_bit(J_WRITERS_BLOCKED, &journal->j_state) ; 2815 journal->j_must_wait = 1;
2562 return ; 2816 set_bit(J_WRITERS_BLOCKED, &journal->j_state);
2817 return;
2563} 2818}
2564 2819
2565/* this must be called without a transaction started, and does not 2820/* this must be called without a transaction started, and does not
2566** require BKL 2821** require BKL
2567*/ 2822*/
2568void reiserfs_allow_writes(struct super_block *s) { 2823void reiserfs_allow_writes(struct super_block *s)
2569 struct reiserfs_journal *journal = SB_JOURNAL (s); 2824{
2570 clear_bit(J_WRITERS_BLOCKED, &journal->j_state) ; 2825 struct reiserfs_journal *journal = SB_JOURNAL(s);
2571 wake_up(&journal->j_join_wait) ; 2826 clear_bit(J_WRITERS_BLOCKED, &journal->j_state);
2827 wake_up(&journal->j_join_wait);
2572} 2828}
2573 2829
2574/* this must be called without a transaction started, and does not 2830/* this must be called without a transaction started, and does not
2575** require BKL 2831** require BKL
2576*/ 2832*/
2577void reiserfs_wait_on_write_block(struct super_block *s) { 2833void reiserfs_wait_on_write_block(struct super_block *s)
2578 struct reiserfs_journal *journal = SB_JOURNAL (s); 2834{
2579 wait_event(journal->j_join_wait, 2835 struct reiserfs_journal *journal = SB_JOURNAL(s);
2580 !test_bit(J_WRITERS_BLOCKED, &journal->j_state)) ; 2836 wait_event(journal->j_join_wait,
2581} 2837 !test_bit(J_WRITERS_BLOCKED, &journal->j_state));
2582 2838}
2583static void queue_log_writer(struct super_block *s) { 2839
2584 wait_queue_t wait; 2840static void queue_log_writer(struct super_block *s)
2585 struct reiserfs_journal *journal = SB_JOURNAL (s); 2841{
2586 set_bit(J_WRITERS_QUEUED, &journal->j_state); 2842 wait_queue_t wait;
2587 2843 struct reiserfs_journal *journal = SB_JOURNAL(s);
2588 /* 2844 set_bit(J_WRITERS_QUEUED, &journal->j_state);
2589 * we don't want to use wait_event here because 2845
2590 * we only want to wait once. 2846 /*
2591 */ 2847 * we don't want to use wait_event here because
2592 init_waitqueue_entry(&wait, current); 2848 * we only want to wait once.
2593 add_wait_queue(&journal->j_join_wait, &wait); 2849 */
2594 set_current_state(TASK_UNINTERRUPTIBLE); 2850 init_waitqueue_entry(&wait, current);
2595 if (test_bit(J_WRITERS_QUEUED, &journal->j_state)) 2851 add_wait_queue(&journal->j_join_wait, &wait);
2596 schedule();
2597 current->state = TASK_RUNNING;
2598 remove_wait_queue(&journal->j_join_wait, &wait);
2599}
2600
2601static void wake_queued_writers(struct super_block *s) {
2602 struct reiserfs_journal *journal = SB_JOURNAL (s);
2603 if (test_and_clear_bit(J_WRITERS_QUEUED, &journal->j_state))
2604 wake_up(&journal->j_join_wait);
2605}
2606
2607static void let_transaction_grow(struct super_block *sb,
2608 unsigned long trans_id)
2609{
2610 struct reiserfs_journal *journal = SB_JOURNAL (sb);
2611 unsigned long bcount = journal->j_bcount;
2612 while(1) {
2613 set_current_state(TASK_UNINTERRUPTIBLE); 2852 set_current_state(TASK_UNINTERRUPTIBLE);
2614 schedule_timeout(1); 2853 if (test_bit(J_WRITERS_QUEUED, &journal->j_state))
2615 journal->j_current_jl->j_state |= LIST_COMMIT_PENDING; 2854 schedule();
2616 while ((atomic_read(&journal->j_wcount) > 0 || 2855 current->state = TASK_RUNNING;
2617 atomic_read(&journal->j_jlock)) && 2856 remove_wait_queue(&journal->j_join_wait, &wait);
2618 journal->j_trans_id == trans_id) { 2857}
2619 queue_log_writer(sb); 2858
2859static void wake_queued_writers(struct super_block *s)
2860{
2861 struct reiserfs_journal *journal = SB_JOURNAL(s);
2862 if (test_and_clear_bit(J_WRITERS_QUEUED, &journal->j_state))
2863 wake_up(&journal->j_join_wait);
2864}
2865
2866static void let_transaction_grow(struct super_block *sb, unsigned long trans_id)
2867{
2868 struct reiserfs_journal *journal = SB_JOURNAL(sb);
2869 unsigned long bcount = journal->j_bcount;
2870 while (1) {
2871 set_current_state(TASK_UNINTERRUPTIBLE);
2872 schedule_timeout(1);
2873 journal->j_current_jl->j_state |= LIST_COMMIT_PENDING;
2874 while ((atomic_read(&journal->j_wcount) > 0 ||
2875 atomic_read(&journal->j_jlock)) &&
2876 journal->j_trans_id == trans_id) {
2877 queue_log_writer(sb);
2878 }
2879 if (journal->j_trans_id != trans_id)
2880 break;
2881 if (bcount == journal->j_bcount)
2882 break;
2883 bcount = journal->j_bcount;
2620 } 2884 }
2621 if (journal->j_trans_id != trans_id)
2622 break;
2623 if (bcount == journal->j_bcount)
2624 break;
2625 bcount = journal->j_bcount;
2626 }
2627} 2885}
2628 2886
2629/* join == true if you must join an existing transaction. 2887/* join == true if you must join an existing transaction.
@@ -2632,224 +2890,244 @@ static void let_transaction_grow(struct super_block *sb,
2632** this will block until the transaction is joinable. send the number of blocks you 2890** this will block until the transaction is joinable. send the number of blocks you
2633** expect to use in nblocks. 2891** expect to use in nblocks.
2634*/ 2892*/
2635static int do_journal_begin_r(struct reiserfs_transaction_handle *th, struct super_block * p_s_sb,unsigned long nblocks,int join) { 2893static int do_journal_begin_r(struct reiserfs_transaction_handle *th,
2636 time_t now = get_seconds() ; 2894 struct super_block *p_s_sb, unsigned long nblocks,
2637 int old_trans_id ; 2895 int join)
2638 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb); 2896{
2639 struct reiserfs_transaction_handle myth; 2897 time_t now = get_seconds();
2640 int sched_count = 0; 2898 int old_trans_id;
2641 int retval; 2899 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb);
2642 2900 struct reiserfs_transaction_handle myth;
2643 reiserfs_check_lock_depth(p_s_sb, "journal_begin") ; 2901 int sched_count = 0;
2644 if (nblocks > journal->j_trans_max) 2902 int retval;
2645 BUG(); 2903
2646 2904 reiserfs_check_lock_depth(p_s_sb, "journal_begin");
2647 PROC_INFO_INC( p_s_sb, journal.journal_being ); 2905 if (nblocks > journal->j_trans_max)
2648 /* set here for journal_join */ 2906 BUG();
2649 th->t_refcount = 1; 2907
2650 th->t_super = p_s_sb ; 2908 PROC_INFO_INC(p_s_sb, journal.journal_being);
2651 2909 /* set here for journal_join */
2652relock: 2910 th->t_refcount = 1;
2653 lock_journal(p_s_sb) ; 2911 th->t_super = p_s_sb;
2654 if (join != JBEGIN_ABORT && reiserfs_is_journal_aborted (journal)) { 2912
2655 unlock_journal (p_s_sb); 2913 relock:
2656 retval = journal->j_errno; 2914 lock_journal(p_s_sb);
2657 goto out_fail; 2915 if (join != JBEGIN_ABORT && reiserfs_is_journal_aborted(journal)) {
2658 } 2916 unlock_journal(p_s_sb);
2659 journal->j_bcount++; 2917 retval = journal->j_errno;
2660 2918 goto out_fail;
2661 if (test_bit(J_WRITERS_BLOCKED, &journal->j_state)) { 2919 }
2662 unlock_journal(p_s_sb) ; 2920 journal->j_bcount++;
2663 reiserfs_wait_on_write_block(p_s_sb) ; 2921
2664 PROC_INFO_INC( p_s_sb, journal.journal_relock_writers ); 2922 if (test_bit(J_WRITERS_BLOCKED, &journal->j_state)) {
2665 goto relock ; 2923 unlock_journal(p_s_sb);
2666 } 2924 reiserfs_wait_on_write_block(p_s_sb);
2667 now = get_seconds(); 2925 PROC_INFO_INC(p_s_sb, journal.journal_relock_writers);
2668 2926 goto relock;
2669 /* if there is no room in the journal OR 2927 }
2670 ** if this transaction is too old, and we weren't called joinable, wait for it to finish before beginning 2928 now = get_seconds();
2671 ** we don't sleep if there aren't other writers 2929
2672 */ 2930 /* if there is no room in the journal OR
2673 2931 ** if this transaction is too old, and we weren't called joinable, wait for it to finish before beginning
2674 if ( (!join && journal->j_must_wait > 0) || 2932 ** we don't sleep if there aren't other writers
2675 ( !join && (journal->j_len_alloc + nblocks + 2) >= journal->j_max_batch) || 2933 */
2676 (!join && atomic_read(&journal->j_wcount) > 0 && journal->j_trans_start_time > 0 && 2934
2677 (now - journal->j_trans_start_time) > journal->j_max_trans_age) || 2935 if ((!join && journal->j_must_wait > 0) ||
2678 (!join && atomic_read(&journal->j_jlock)) || 2936 (!join
2679 (!join && journal->j_cnode_free < (journal->j_trans_max * 3))) { 2937 && (journal->j_len_alloc + nblocks + 2) >= journal->j_max_batch)
2680 2938 || (!join && atomic_read(&journal->j_wcount) > 0
2681 old_trans_id = journal->j_trans_id; 2939 && journal->j_trans_start_time > 0
2682 unlock_journal(p_s_sb) ; /* allow others to finish this transaction */ 2940 && (now - journal->j_trans_start_time) >
2683 2941 journal->j_max_trans_age) || (!join
2684 if (!join && (journal->j_len_alloc + nblocks + 2) >= 2942 && atomic_read(&journal->j_jlock))
2685 journal->j_max_batch && 2943 || (!join && journal->j_cnode_free < (journal->j_trans_max * 3))) {
2686 ((journal->j_len + nblocks + 2) * 100) < (journal->j_len_alloc * 75)) 2944
2687 { 2945 old_trans_id = journal->j_trans_id;
2688 if (atomic_read(&journal->j_wcount) > 10) { 2946 unlock_journal(p_s_sb); /* allow others to finish this transaction */
2689 sched_count++; 2947
2690 queue_log_writer(p_s_sb); 2948 if (!join && (journal->j_len_alloc + nblocks + 2) >=
2691 goto relock; 2949 journal->j_max_batch &&
2692 } 2950 ((journal->j_len + nblocks + 2) * 100) <
2693 } 2951 (journal->j_len_alloc * 75)) {
2694 /* don't mess with joining the transaction if all we have to do is 2952 if (atomic_read(&journal->j_wcount) > 10) {
2695 * wait for someone else to do a commit 2953 sched_count++;
2696 */ 2954 queue_log_writer(p_s_sb);
2697 if (atomic_read(&journal->j_jlock)) { 2955 goto relock;
2698 while (journal->j_trans_id == old_trans_id && 2956 }
2699 atomic_read(&journal->j_jlock)) { 2957 }
2700 queue_log_writer(p_s_sb); 2958 /* don't mess with joining the transaction if all we have to do is
2701 } 2959 * wait for someone else to do a commit
2702 goto relock; 2960 */
2703 } 2961 if (atomic_read(&journal->j_jlock)) {
2704 retval = journal_join(&myth, p_s_sb, 1) ; 2962 while (journal->j_trans_id == old_trans_id &&
2705 if (retval) 2963 atomic_read(&journal->j_jlock)) {
2706 goto out_fail; 2964 queue_log_writer(p_s_sb);
2707 2965 }
2708 /* someone might have ended the transaction while we joined */ 2966 goto relock;
2709 if (old_trans_id != journal->j_trans_id) { 2967 }
2710 retval = do_journal_end(&myth, p_s_sb, 1, 0) ; 2968 retval = journal_join(&myth, p_s_sb, 1);
2711 } else { 2969 if (retval)
2712 retval = do_journal_end(&myth, p_s_sb, 1, COMMIT_NOW) ; 2970 goto out_fail;
2713 } 2971
2714 2972 /* someone might have ended the transaction while we joined */
2715 if (retval) 2973 if (old_trans_id != journal->j_trans_id) {
2716 goto out_fail; 2974 retval = do_journal_end(&myth, p_s_sb, 1, 0);
2717 2975 } else {
2718 PROC_INFO_INC( p_s_sb, journal.journal_relock_wcount ); 2976 retval = do_journal_end(&myth, p_s_sb, 1, COMMIT_NOW);
2719 goto relock ; 2977 }
2720 } 2978
2721 /* we are the first writer, set trans_id */ 2979 if (retval)
2722 if (journal->j_trans_start_time == 0) { 2980 goto out_fail;
2723 journal->j_trans_start_time = get_seconds(); 2981
2724 } 2982 PROC_INFO_INC(p_s_sb, journal.journal_relock_wcount);
2725 atomic_inc(&(journal->j_wcount)) ; 2983 goto relock;
2726 journal->j_len_alloc += nblocks ; 2984 }
2727 th->t_blocks_logged = 0 ; 2985 /* we are the first writer, set trans_id */
2728 th->t_blocks_allocated = nblocks ; 2986 if (journal->j_trans_start_time == 0) {
2729 th->t_trans_id = journal->j_trans_id ; 2987 journal->j_trans_start_time = get_seconds();
2730 unlock_journal(p_s_sb) ; 2988 }
2731 INIT_LIST_HEAD (&th->t_list); 2989 atomic_inc(&(journal->j_wcount));
2732 get_fs_excl(); 2990 journal->j_len_alloc += nblocks;
2733 return 0 ; 2991 th->t_blocks_logged = 0;
2734 2992 th->t_blocks_allocated = nblocks;
2735out_fail: 2993 th->t_trans_id = journal->j_trans_id;
2736 memset (th, 0, sizeof (*th)); 2994 unlock_journal(p_s_sb);
2737 /* Re-set th->t_super, so we can properly keep track of how many 2995 INIT_LIST_HEAD(&th->t_list);
2738 * persistent transactions there are. We need to do this so if this 2996 get_fs_excl();
2739 * call is part of a failed restart_transaction, we can free it later */ 2997 return 0;
2740 th->t_super = p_s_sb; 2998
2741 return retval; 2999 out_fail:
2742} 3000 memset(th, 0, sizeof(*th));
2743 3001 /* Re-set th->t_super, so we can properly keep track of how many
2744struct reiserfs_transaction_handle * 3002 * persistent transactions there are. We need to do this so if this
2745reiserfs_persistent_transaction(struct super_block *s, int nblocks) { 3003 * call is part of a failed restart_transaction, we can free it later */
2746 int ret ; 3004 th->t_super = p_s_sb;
2747 struct reiserfs_transaction_handle *th ; 3005 return retval;
2748 3006}
2749 /* if we're nesting into an existing transaction. It will be 3007
2750 ** persistent on its own 3008struct reiserfs_transaction_handle *reiserfs_persistent_transaction(struct
2751 */ 3009 super_block
2752 if (reiserfs_transaction_running(s)) { 3010 *s,
2753 th = current->journal_info ; 3011 int nblocks)
2754 th->t_refcount++ ; 3012{
2755 if (th->t_refcount < 2) { 3013 int ret;
2756 BUG() ; 3014 struct reiserfs_transaction_handle *th;
2757 } 3015
2758 return th ; 3016 /* if we're nesting into an existing transaction. It will be
2759 } 3017 ** persistent on its own
2760 th = reiserfs_kmalloc(sizeof(struct reiserfs_transaction_handle), GFP_NOFS, s) ; 3018 */
2761 if (!th) 3019 if (reiserfs_transaction_running(s)) {
2762 return NULL; 3020 th = current->journal_info;
2763 ret = journal_begin(th, s, nblocks) ; 3021 th->t_refcount++;
2764 if (ret) { 3022 if (th->t_refcount < 2) {
2765 reiserfs_kfree(th, sizeof(struct reiserfs_transaction_handle), s) ; 3023 BUG();
2766 return NULL; 3024 }
2767 } 3025 return th;
2768 3026 }
2769 SB_JOURNAL(s)->j_persistent_trans++; 3027 th = reiserfs_kmalloc(sizeof(struct reiserfs_transaction_handle),
2770 return th ; 3028 GFP_NOFS, s);
2771} 3029 if (!th)
2772 3030 return NULL;
2773int 3031 ret = journal_begin(th, s, nblocks);
2774reiserfs_end_persistent_transaction(struct reiserfs_transaction_handle *th) { 3032 if (ret) {
2775 struct super_block *s = th->t_super; 3033 reiserfs_kfree(th, sizeof(struct reiserfs_transaction_handle),
2776 int ret = 0; 3034 s);
2777 if (th->t_trans_id) 3035 return NULL;
2778 ret = journal_end(th, th->t_super, th->t_blocks_allocated); 3036 }
2779 else 3037
2780 ret = -EIO; 3038 SB_JOURNAL(s)->j_persistent_trans++;
2781 if (th->t_refcount == 0) { 3039 return th;
2782 SB_JOURNAL(s)->j_persistent_trans--; 3040}
2783 reiserfs_kfree(th, sizeof(struct reiserfs_transaction_handle), s) ; 3041
2784 } 3042int reiserfs_end_persistent_transaction(struct reiserfs_transaction_handle *th)
2785 return ret; 3043{
2786} 3044 struct super_block *s = th->t_super;
2787 3045 int ret = 0;
2788static int journal_join(struct reiserfs_transaction_handle *th, struct super_block *p_s_sb, unsigned long nblocks) { 3046 if (th->t_trans_id)
2789 struct reiserfs_transaction_handle *cur_th = current->journal_info; 3047 ret = journal_end(th, th->t_super, th->t_blocks_allocated);
2790 3048 else
2791 /* this keeps do_journal_end from NULLing out the current->journal_info 3049 ret = -EIO;
2792 ** pointer 3050 if (th->t_refcount == 0) {
2793 */ 3051 SB_JOURNAL(s)->j_persistent_trans--;
2794 th->t_handle_save = cur_th ; 3052 reiserfs_kfree(th, sizeof(struct reiserfs_transaction_handle),
2795 if (cur_th && cur_th->t_refcount > 1) { 3053 s);
2796 BUG() ; 3054 }
2797 } 3055 return ret;
2798 return do_journal_begin_r(th, p_s_sb, nblocks, JBEGIN_JOIN) ; 3056}
2799} 3057
2800 3058static int journal_join(struct reiserfs_transaction_handle *th,
2801int journal_join_abort(struct reiserfs_transaction_handle *th, struct super_block *p_s_sb, unsigned long nblocks) { 3059 struct super_block *p_s_sb, unsigned long nblocks)
2802 struct reiserfs_transaction_handle *cur_th = current->journal_info; 3060{
2803 3061 struct reiserfs_transaction_handle *cur_th = current->journal_info;
2804 /* this keeps do_journal_end from NULLing out the current->journal_info 3062
2805 ** pointer 3063 /* this keeps do_journal_end from NULLing out the current->journal_info
2806 */ 3064 ** pointer
2807 th->t_handle_save = cur_th ; 3065 */
2808 if (cur_th && cur_th->t_refcount > 1) { 3066 th->t_handle_save = cur_th;
2809 BUG() ; 3067 if (cur_th && cur_th->t_refcount > 1) {
2810 } 3068 BUG();
2811 return do_journal_begin_r(th, p_s_sb, nblocks, JBEGIN_ABORT) ; 3069 }
2812} 3070 return do_journal_begin_r(th, p_s_sb, nblocks, JBEGIN_JOIN);
2813 3071}
2814int journal_begin(struct reiserfs_transaction_handle *th, struct super_block * p_s_sb, unsigned long nblocks) { 3072
2815 struct reiserfs_transaction_handle *cur_th = current->journal_info ; 3073int journal_join_abort(struct reiserfs_transaction_handle *th,
2816 int ret ; 3074 struct super_block *p_s_sb, unsigned long nblocks)
2817 3075{
2818 th->t_handle_save = NULL ; 3076 struct reiserfs_transaction_handle *cur_th = current->journal_info;
2819 if (cur_th) { 3077
2820 /* we are nesting into the current transaction */ 3078 /* this keeps do_journal_end from NULLing out the current->journal_info
2821 if (cur_th->t_super == p_s_sb) { 3079 ** pointer
2822 BUG_ON (!cur_th->t_refcount); 3080 */
2823 cur_th->t_refcount++ ; 3081 th->t_handle_save = cur_th;
2824 memcpy(th, cur_th, sizeof(*th)); 3082 if (cur_th && cur_th->t_refcount > 1) {
2825 if (th->t_refcount <= 1) 3083 BUG();
2826 reiserfs_warning (p_s_sb, "BAD: refcount <= 1, but journal_info != 0"); 3084 }
2827 return 0; 3085 return do_journal_begin_r(th, p_s_sb, nblocks, JBEGIN_ABORT);
3086}
3087
3088int journal_begin(struct reiserfs_transaction_handle *th,
3089 struct super_block *p_s_sb, unsigned long nblocks)
3090{
3091 struct reiserfs_transaction_handle *cur_th = current->journal_info;
3092 int ret;
3093
3094 th->t_handle_save = NULL;
3095 if (cur_th) {
3096 /* we are nesting into the current transaction */
3097 if (cur_th->t_super == p_s_sb) {
3098 BUG_ON(!cur_th->t_refcount);
3099 cur_th->t_refcount++;
3100 memcpy(th, cur_th, sizeof(*th));
3101 if (th->t_refcount <= 1)
3102 reiserfs_warning(p_s_sb,
3103 "BAD: refcount <= 1, but journal_info != 0");
3104 return 0;
3105 } else {
3106 /* we've ended up with a handle from a different filesystem.
3107 ** save it and restore on journal_end. This should never
3108 ** really happen...
3109 */
3110 reiserfs_warning(p_s_sb,
3111 "clm-2100: nesting info a different FS");
3112 th->t_handle_save = current->journal_info;
3113 current->journal_info = th;
3114 }
2828 } else { 3115 } else {
2829 /* we've ended up with a handle from a different filesystem. 3116 current->journal_info = th;
2830 ** save it and restore on journal_end. This should never 3117 }
2831 ** really happen... 3118 ret = do_journal_begin_r(th, p_s_sb, nblocks, JBEGIN_REG);
2832 */ 3119 if (current->journal_info != th)
2833 reiserfs_warning(p_s_sb, "clm-2100: nesting info a different FS") ; 3120 BUG();
2834 th->t_handle_save = current->journal_info ;
2835 current->journal_info = th;
2836 }
2837 } else {
2838 current->journal_info = th;
2839 }
2840 ret = do_journal_begin_r(th, p_s_sb, nblocks, JBEGIN_REG) ;
2841 if (current->journal_info != th)
2842 BUG() ;
2843 3121
2844 /* I guess this boils down to being the reciprocal of clm-2100 above. 3122 /* I guess this boils down to being the reciprocal of clm-2100 above.
2845 * If do_journal_begin_r fails, we need to put it back, since journal_end 3123 * If do_journal_begin_r fails, we need to put it back, since journal_end
2846 * won't be called to do it. */ 3124 * won't be called to do it. */
2847 if (ret) 3125 if (ret)
2848 current->journal_info = th->t_handle_save; 3126 current->journal_info = th->t_handle_save;
2849 else 3127 else
2850 BUG_ON (!th->t_refcount); 3128 BUG_ON(!th->t_refcount);
2851 3129
2852 return ret ; 3130 return ret;
2853} 3131}
2854 3132
2855/* 3133/*
@@ -2861,129 +3139,140 @@ int journal_begin(struct reiserfs_transaction_handle *th, struct super_block *
2861** 3139**
2862** if j_len, is bigger than j_len_alloc, it pushes j_len_alloc to 10 + j_len. 3140** if j_len, is bigger than j_len_alloc, it pushes j_len_alloc to 10 + j_len.
2863*/ 3141*/
2864int journal_mark_dirty(struct reiserfs_transaction_handle *th, struct super_block *p_s_sb, struct buffer_head *bh) { 3142int journal_mark_dirty(struct reiserfs_transaction_handle *th,
2865 struct reiserfs_journal *journal = SB_JOURNAL (p_s_sb); 3143 struct super_block *p_s_sb, struct buffer_head *bh)
2866 struct reiserfs_journal_cnode *cn = NULL; 3144{
2867 int count_already_incd = 0 ; 3145 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb);
2868 int prepared = 0 ; 3146 struct reiserfs_journal_cnode *cn = NULL;
2869 BUG_ON (!th->t_trans_id); 3147 int count_already_incd = 0;
2870 3148 int prepared = 0;
2871 PROC_INFO_INC( p_s_sb, journal.mark_dirty ); 3149 BUG_ON(!th->t_trans_id);
2872 if (th->t_trans_id != journal->j_trans_id) { 3150
2873 reiserfs_panic(th->t_super, "journal-1577: handle trans id %ld != current trans id %ld\n", 3151 PROC_INFO_INC(p_s_sb, journal.mark_dirty);
2874 th->t_trans_id, journal->j_trans_id); 3152 if (th->t_trans_id != journal->j_trans_id) {
2875 } 3153 reiserfs_panic(th->t_super,
2876 3154 "journal-1577: handle trans id %ld != current trans id %ld\n",
2877 p_s_sb->s_dirt = 1; 3155 th->t_trans_id, journal->j_trans_id);
2878 3156 }
2879 prepared = test_clear_buffer_journal_prepared (bh); 3157
2880 clear_buffer_journal_restore_dirty (bh); 3158 p_s_sb->s_dirt = 1;
2881 /* already in this transaction, we are done */ 3159
2882 if (buffer_journaled(bh)) { 3160 prepared = test_clear_buffer_journal_prepared(bh);
2883 PROC_INFO_INC( p_s_sb, journal.mark_dirty_already ); 3161 clear_buffer_journal_restore_dirty(bh);
2884 return 0 ; 3162 /* already in this transaction, we are done */
2885 } 3163 if (buffer_journaled(bh)) {
2886 3164 PROC_INFO_INC(p_s_sb, journal.mark_dirty_already);
2887 /* this must be turned into a panic instead of a warning. We can't allow 3165 return 0;
2888 ** a dirty or journal_dirty or locked buffer to be logged, as some changes 3166 }
2889 ** could get to disk too early. NOT GOOD. 3167
2890 */ 3168 /* this must be turned into a panic instead of a warning. We can't allow
2891 if (!prepared || buffer_dirty(bh)) { 3169 ** a dirty or journal_dirty or locked buffer to be logged, as some changes
2892 reiserfs_warning (p_s_sb, "journal-1777: buffer %llu bad state " 3170 ** could get to disk too early. NOT GOOD.
2893 "%cPREPARED %cLOCKED %cDIRTY %cJDIRTY_WAIT", 3171 */
2894 (unsigned long long)bh->b_blocknr, prepared ? ' ' : '!', 3172 if (!prepared || buffer_dirty(bh)) {
2895 buffer_locked(bh) ? ' ' : '!', 3173 reiserfs_warning(p_s_sb, "journal-1777: buffer %llu bad state "
2896 buffer_dirty(bh) ? ' ' : '!', 3174 "%cPREPARED %cLOCKED %cDIRTY %cJDIRTY_WAIT",
2897 buffer_journal_dirty(bh) ? ' ' : '!') ; 3175 (unsigned long long)bh->b_blocknr,
2898 } 3176 prepared ? ' ' : '!',
2899 3177 buffer_locked(bh) ? ' ' : '!',
2900 if (atomic_read(&(journal->j_wcount)) <= 0) { 3178 buffer_dirty(bh) ? ' ' : '!',
2901 reiserfs_warning (p_s_sb, "journal-1409: journal_mark_dirty returning because j_wcount was %d", atomic_read(&(journal->j_wcount))) ; 3179 buffer_journal_dirty(bh) ? ' ' : '!');
2902 return 1 ; 3180 }
2903 } 3181
2904 /* this error means I've screwed up, and we've overflowed the transaction. 3182 if (atomic_read(&(journal->j_wcount)) <= 0) {
2905 ** Nothing can be done here, except make the FS readonly or panic. 3183 reiserfs_warning(p_s_sb,
2906 */ 3184 "journal-1409: journal_mark_dirty returning because j_wcount was %d",
2907 if (journal->j_len >= journal->j_trans_max) { 3185 atomic_read(&(journal->j_wcount)));
2908 reiserfs_panic(th->t_super, "journal-1413: journal_mark_dirty: j_len (%lu) is too big\n", journal->j_len) ; 3186 return 1;
2909 } 3187 }
2910 3188 /* this error means I've screwed up, and we've overflowed the transaction.
2911 if (buffer_journal_dirty(bh)) { 3189 ** Nothing can be done here, except make the FS readonly or panic.
2912 count_already_incd = 1 ; 3190 */
2913 PROC_INFO_INC( p_s_sb, journal.mark_dirty_notjournal ); 3191 if (journal->j_len >= journal->j_trans_max) {
2914 clear_buffer_journal_dirty (bh); 3192 reiserfs_panic(th->t_super,
2915 } 3193 "journal-1413: journal_mark_dirty: j_len (%lu) is too big\n",
2916 3194 journal->j_len);
2917 if (journal->j_len > journal->j_len_alloc) { 3195 }
2918 journal->j_len_alloc = journal->j_len + JOURNAL_PER_BALANCE_CNT ; 3196
2919 } 3197 if (buffer_journal_dirty(bh)) {
2920 3198 count_already_incd = 1;
2921 set_buffer_journaled (bh); 3199 PROC_INFO_INC(p_s_sb, journal.mark_dirty_notjournal);
2922 3200 clear_buffer_journal_dirty(bh);
2923 /* now put this guy on the end */ 3201 }
2924 if (!cn) { 3202
2925 cn = get_cnode(p_s_sb) ; 3203 if (journal->j_len > journal->j_len_alloc) {
2926 if (!cn) { 3204 journal->j_len_alloc = journal->j_len + JOURNAL_PER_BALANCE_CNT;
2927 reiserfs_panic(p_s_sb, "get_cnode failed!\n"); 3205 }
2928 } 3206
2929 3207 set_buffer_journaled(bh);
2930 if (th->t_blocks_logged == th->t_blocks_allocated) { 3208
2931 th->t_blocks_allocated += JOURNAL_PER_BALANCE_CNT ; 3209 /* now put this guy on the end */
2932 journal->j_len_alloc += JOURNAL_PER_BALANCE_CNT ; 3210 if (!cn) {
2933 } 3211 cn = get_cnode(p_s_sb);
2934 th->t_blocks_logged++ ; 3212 if (!cn) {
2935 journal->j_len++ ; 3213 reiserfs_panic(p_s_sb, "get_cnode failed!\n");
2936 3214 }
2937 cn->bh = bh ; 3215
2938 cn->blocknr = bh->b_blocknr ; 3216 if (th->t_blocks_logged == th->t_blocks_allocated) {
2939 cn->sb = p_s_sb; 3217 th->t_blocks_allocated += JOURNAL_PER_BALANCE_CNT;
2940 cn->jlist = NULL ; 3218 journal->j_len_alloc += JOURNAL_PER_BALANCE_CNT;
2941 insert_journal_hash(journal->j_hash_table, cn) ; 3219 }
2942 if (!count_already_incd) { 3220 th->t_blocks_logged++;
2943 get_bh(bh) ; 3221 journal->j_len++;
2944 } 3222
2945 } 3223 cn->bh = bh;
2946 cn->next = NULL ; 3224 cn->blocknr = bh->b_blocknr;
2947 cn->prev = journal->j_last ; 3225 cn->sb = p_s_sb;
2948 cn->bh = bh ; 3226 cn->jlist = NULL;
2949 if (journal->j_last) { 3227 insert_journal_hash(journal->j_hash_table, cn);
2950 journal->j_last->next = cn ; 3228 if (!count_already_incd) {
2951 journal->j_last = cn ; 3229 get_bh(bh);
2952 } else { 3230 }
2953 journal->j_first = cn ; 3231 }
2954 journal->j_last = cn ; 3232 cn->next = NULL;
2955 } 3233 cn->prev = journal->j_last;
2956 return 0 ; 3234 cn->bh = bh;
2957} 3235 if (journal->j_last) {
2958 3236 journal->j_last->next = cn;
2959int journal_end(struct reiserfs_transaction_handle *th, struct super_block *p_s_sb, unsigned long nblocks) { 3237 journal->j_last = cn;
2960 if (!current->journal_info && th->t_refcount > 1) 3238 } else {
2961 reiserfs_warning (p_s_sb, "REISER-NESTING: th NULL, refcount %d", 3239 journal->j_first = cn;
2962 th->t_refcount); 3240 journal->j_last = cn;
2963 3241 }
2964 if (!th->t_trans_id) { 3242 return 0;
2965 WARN_ON (1); 3243}
2966 return -EIO; 3244
2967 } 3245int journal_end(struct reiserfs_transaction_handle *th,
2968 3246 struct super_block *p_s_sb, unsigned long nblocks)
2969 th->t_refcount--; 3247{
2970 if (th->t_refcount > 0) { 3248 if (!current->journal_info && th->t_refcount > 1)
2971 struct reiserfs_transaction_handle *cur_th = current->journal_info ; 3249 reiserfs_warning(p_s_sb, "REISER-NESTING: th NULL, refcount %d",
2972 3250 th->t_refcount);
2973 /* we aren't allowed to close a nested transaction on a different 3251
2974 ** filesystem from the one in the task struct 3252 if (!th->t_trans_id) {
2975 */ 3253 WARN_ON(1);
2976 if (cur_th->t_super != th->t_super) 3254 return -EIO;
2977 BUG() ; 3255 }
2978 3256
2979 if (th != cur_th) { 3257 th->t_refcount--;
2980 memcpy(current->journal_info, th, sizeof(*th)); 3258 if (th->t_refcount > 0) {
2981 th->t_trans_id = 0; 3259 struct reiserfs_transaction_handle *cur_th =
2982 } 3260 current->journal_info;
2983 return 0; 3261
2984 } else { 3262 /* we aren't allowed to close a nested transaction on a different
2985 return do_journal_end(th, p_s_sb, nblocks, 0) ; 3263 ** filesystem from the one in the task struct
2986 } 3264 */
3265 if (cur_th->t_super != th->t_super)
3266 BUG();
3267
3268 if (th != cur_th) {
3269 memcpy(current->journal_info, th, sizeof(*th));
3270 th->t_trans_id = 0;
3271 }
3272 return 0;
3273 } else {
3274 return do_journal_end(th, p_s_sb, nblocks, 0);
3275 }
2987} 3276}
2988 3277
2989/* removes from the current transaction, relsing and descrementing any counters. 3278/* removes from the current transaction, relsing and descrementing any counters.
@@ -2993,47 +3282,51 @@ int journal_end(struct reiserfs_transaction_handle *th, struct super_block *p_s_
2993** 3282**
2994** returns 1 if it cleaned and relsed the buffer. 0 otherwise 3283** returns 1 if it cleaned and relsed the buffer. 0 otherwise
2995*/ 3284*/
2996static int remove_from_transaction(struct super_block *p_s_sb, b_blocknr_t blocknr, int already_cleaned) { 3285static int remove_from_transaction(struct super_block *p_s_sb,
2997 struct buffer_head *bh ; 3286 b_blocknr_t blocknr, int already_cleaned)
2998 struct reiserfs_journal_cnode *cn ; 3287{
2999 struct reiserfs_journal *journal = SB_JOURNAL (p_s_sb); 3288 struct buffer_head *bh;
3000 int ret = 0; 3289 struct reiserfs_journal_cnode *cn;
3001 3290 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb);
3002 cn = get_journal_hash_dev(p_s_sb, journal->j_hash_table, blocknr) ; 3291 int ret = 0;
3003 if (!cn || !cn->bh) { 3292
3004 return ret ; 3293 cn = get_journal_hash_dev(p_s_sb, journal->j_hash_table, blocknr);
3005 } 3294 if (!cn || !cn->bh) {
3006 bh = cn->bh ; 3295 return ret;
3007 if (cn->prev) { 3296 }
3008 cn->prev->next = cn->next ; 3297 bh = cn->bh;
3009 } 3298 if (cn->prev) {
3010 if (cn->next) { 3299 cn->prev->next = cn->next;
3011 cn->next->prev = cn->prev ; 3300 }
3012 } 3301 if (cn->next) {
3013 if (cn == journal->j_first) { 3302 cn->next->prev = cn->prev;
3014 journal->j_first = cn->next ; 3303 }
3015 } 3304 if (cn == journal->j_first) {
3016 if (cn == journal->j_last) { 3305 journal->j_first = cn->next;
3017 journal->j_last = cn->prev ; 3306 }
3018 } 3307 if (cn == journal->j_last) {
3019 if (bh) 3308 journal->j_last = cn->prev;
3020 remove_journal_hash(p_s_sb, journal->j_hash_table, NULL, bh->b_blocknr, 0) ; 3309 }
3021 clear_buffer_journaled (bh); /* don't log this one */ 3310 if (bh)
3022 3311 remove_journal_hash(p_s_sb, journal->j_hash_table, NULL,
3023 if (!already_cleaned) { 3312 bh->b_blocknr, 0);
3024 clear_buffer_journal_dirty (bh); 3313 clear_buffer_journaled(bh); /* don't log this one */
3025 clear_buffer_dirty(bh); 3314
3026 clear_buffer_journal_test (bh); 3315 if (!already_cleaned) {
3027 put_bh(bh) ; 3316 clear_buffer_journal_dirty(bh);
3028 if (atomic_read(&(bh->b_count)) < 0) { 3317 clear_buffer_dirty(bh);
3029 reiserfs_warning (p_s_sb, "journal-1752: remove from trans, b_count < 0"); 3318 clear_buffer_journal_test(bh);
3030 } 3319 put_bh(bh);
3031 ret = 1 ; 3320 if (atomic_read(&(bh->b_count)) < 0) {
3032 } 3321 reiserfs_warning(p_s_sb,
3033 journal->j_len-- ; 3322 "journal-1752: remove from trans, b_count < 0");
3034 journal->j_len_alloc-- ; 3323 }
3035 free_cnode(p_s_sb, cn) ; 3324 ret = 1;
3036 return ret ; 3325 }
3326 journal->j_len--;
3327 journal->j_len_alloc--;
3328 free_cnode(p_s_sb, cn);
3329 return ret;
3037} 3330}
3038 3331
3039/* 3332/*
@@ -3046,120 +3339,129 @@ static int remove_from_transaction(struct super_block *p_s_sb, b_blocknr_t block
3046** blocks for a given transaction on disk 3339** blocks for a given transaction on disk
3047** 3340**
3048*/ 3341*/
3049static int can_dirty(struct reiserfs_journal_cnode *cn) { 3342static int can_dirty(struct reiserfs_journal_cnode *cn)
3050 struct super_block *sb = cn->sb; 3343{
3051 b_blocknr_t blocknr = cn->blocknr ; 3344 struct super_block *sb = cn->sb;
3052 struct reiserfs_journal_cnode *cur = cn->hprev ; 3345 b_blocknr_t blocknr = cn->blocknr;
3053 int can_dirty = 1 ; 3346 struct reiserfs_journal_cnode *cur = cn->hprev;
3054 3347 int can_dirty = 1;
3055 /* first test hprev. These are all newer than cn, so any node here 3348
3056 ** with the same block number and dev means this node can't be sent 3349 /* first test hprev. These are all newer than cn, so any node here
3057 ** to disk right now. 3350 ** with the same block number and dev means this node can't be sent
3058 */ 3351 ** to disk right now.
3059 while(cur && can_dirty) { 3352 */
3060 if (cur->jlist && cur->bh && cur->blocknr && cur->sb == sb && 3353 while (cur && can_dirty) {
3061 cur->blocknr == blocknr) { 3354 if (cur->jlist && cur->bh && cur->blocknr && cur->sb == sb &&
3062 can_dirty = 0 ; 3355 cur->blocknr == blocknr) {
3063 } 3356 can_dirty = 0;
3064 cur = cur->hprev ; 3357 }
3065 } 3358 cur = cur->hprev;
3066 /* then test hnext. These are all older than cn. As long as they 3359 }
3067 ** are committed to the log, it is safe to write cn to disk 3360 /* then test hnext. These are all older than cn. As long as they
3068 */ 3361 ** are committed to the log, it is safe to write cn to disk
3069 cur = cn->hnext ; 3362 */
3070 while(cur && can_dirty) { 3363 cur = cn->hnext;
3071 if (cur->jlist && cur->jlist->j_len > 0 && 3364 while (cur && can_dirty) {
3072 atomic_read(&(cur->jlist->j_commit_left)) > 0 && cur->bh && 3365 if (cur->jlist && cur->jlist->j_len > 0 &&
3073 cur->blocknr && cur->sb == sb && cur->blocknr == blocknr) { 3366 atomic_read(&(cur->jlist->j_commit_left)) > 0 && cur->bh &&
3074 can_dirty = 0 ; 3367 cur->blocknr && cur->sb == sb && cur->blocknr == blocknr) {
3075 } 3368 can_dirty = 0;
3076 cur = cur->hnext ; 3369 }
3077 } 3370 cur = cur->hnext;
3078 return can_dirty ; 3371 }
3372 return can_dirty;
3079} 3373}
3080 3374
3081/* syncs the commit blocks, but does not force the real buffers to disk 3375/* syncs the commit blocks, but does not force the real buffers to disk
3082** will wait until the current transaction is done/commited before returning 3376** will wait until the current transaction is done/commited before returning
3083*/ 3377*/
3084int journal_end_sync(struct reiserfs_transaction_handle *th, struct super_block *p_s_sb, unsigned long nblocks) { 3378int journal_end_sync(struct reiserfs_transaction_handle *th,
3085 struct reiserfs_journal *journal = SB_JOURNAL (p_s_sb); 3379 struct super_block *p_s_sb, unsigned long nblocks)
3380{
3381 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb);
3086 3382
3087 BUG_ON (!th->t_trans_id); 3383 BUG_ON(!th->t_trans_id);
3088 /* you can sync while nested, very, very bad */ 3384 /* you can sync while nested, very, very bad */
3089 if (th->t_refcount > 1) { 3385 if (th->t_refcount > 1) {
3090 BUG() ; 3386 BUG();
3091 } 3387 }
3092 if (journal->j_len == 0) { 3388 if (journal->j_len == 0) {
3093 reiserfs_prepare_for_journal(p_s_sb, SB_BUFFER_WITH_SB(p_s_sb), 1) ; 3389 reiserfs_prepare_for_journal(p_s_sb, SB_BUFFER_WITH_SB(p_s_sb),
3094 journal_mark_dirty(th, p_s_sb, SB_BUFFER_WITH_SB(p_s_sb)) ; 3390 1);
3095 } 3391 journal_mark_dirty(th, p_s_sb, SB_BUFFER_WITH_SB(p_s_sb));
3096 return do_journal_end(th, p_s_sb, nblocks, COMMIT_NOW | WAIT) ; 3392 }
3393 return do_journal_end(th, p_s_sb, nblocks, COMMIT_NOW | WAIT);
3097} 3394}
3098 3395
3099/* 3396/*
3100** writeback the pending async commits to disk 3397** writeback the pending async commits to disk
3101*/ 3398*/
3102static void flush_async_commits(void *p) { 3399static void flush_async_commits(void *p)
3103 struct super_block *p_s_sb = p; 3400{
3104 struct reiserfs_journal *journal = SB_JOURNAL (p_s_sb); 3401 struct super_block *p_s_sb = p;
3105 struct reiserfs_journal_list *jl; 3402 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb);
3106 struct list_head *entry; 3403 struct reiserfs_journal_list *jl;
3107 3404 struct list_head *entry;
3108 lock_kernel(); 3405
3109 if (!list_empty(&journal->j_journal_list)) { 3406 lock_kernel();
3110 /* last entry is the youngest, commit it and you get everything */ 3407 if (!list_empty(&journal->j_journal_list)) {
3111 entry = journal->j_journal_list.prev; 3408 /* last entry is the youngest, commit it and you get everything */
3112 jl = JOURNAL_LIST_ENTRY(entry); 3409 entry = journal->j_journal_list.prev;
3113 flush_commit_list(p_s_sb, jl, 1); 3410 jl = JOURNAL_LIST_ENTRY(entry);
3114 } 3411 flush_commit_list(p_s_sb, jl, 1);
3115 unlock_kernel(); 3412 }
3116 /* 3413 unlock_kernel();
3117 * this is a little racey, but there's no harm in missing 3414 /*
3118 * the filemap_fdata_write 3415 * this is a little racey, but there's no harm in missing
3119 */ 3416 * the filemap_fdata_write
3120 if (!atomic_read(&journal->j_async_throttle) && !reiserfs_is_journal_aborted (journal)) { 3417 */
3121 atomic_inc(&journal->j_async_throttle); 3418 if (!atomic_read(&journal->j_async_throttle)
3122 filemap_fdatawrite(p_s_sb->s_bdev->bd_inode->i_mapping); 3419 && !reiserfs_is_journal_aborted(journal)) {
3123 atomic_dec(&journal->j_async_throttle); 3420 atomic_inc(&journal->j_async_throttle);
3124 } 3421 filemap_fdatawrite(p_s_sb->s_bdev->bd_inode->i_mapping);
3422 atomic_dec(&journal->j_async_throttle);
3423 }
3125} 3424}
3126 3425
3127/* 3426/*
3128** flushes any old transactions to disk 3427** flushes any old transactions to disk
3129** ends the current transaction if it is too old 3428** ends the current transaction if it is too old
3130*/ 3429*/
3131int reiserfs_flush_old_commits(struct super_block *p_s_sb) { 3430int reiserfs_flush_old_commits(struct super_block *p_s_sb)
3132 time_t now ; 3431{
3133 struct reiserfs_transaction_handle th ; 3432 time_t now;
3134 struct reiserfs_journal *journal = SB_JOURNAL (p_s_sb); 3433 struct reiserfs_transaction_handle th;
3135 3434 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb);
3136 now = get_seconds(); 3435
3137 /* safety check so we don't flush while we are replaying the log during 3436 now = get_seconds();
3138 * mount 3437 /* safety check so we don't flush while we are replaying the log during
3139 */ 3438 * mount
3140 if (list_empty(&journal->j_journal_list)) { 3439 */
3141 return 0 ; 3440 if (list_empty(&journal->j_journal_list)) {
3142 } 3441 return 0;
3143 3442 }
3144 /* check the current transaction. If there are no writers, and it is 3443
3145 * too old, finish it, and force the commit blocks to disk 3444 /* check the current transaction. If there are no writers, and it is
3146 */ 3445 * too old, finish it, and force the commit blocks to disk
3147 if (atomic_read(&journal->j_wcount) <= 0 && 3446 */
3148 journal->j_trans_start_time > 0 && 3447 if (atomic_read(&journal->j_wcount) <= 0 &&
3149 journal->j_len > 0 && 3448 journal->j_trans_start_time > 0 &&
3150 (now - journal->j_trans_start_time) > journal->j_max_trans_age) 3449 journal->j_len > 0 &&
3151 { 3450 (now - journal->j_trans_start_time) > journal->j_max_trans_age) {
3152 if (!journal_join(&th, p_s_sb, 1)) { 3451 if (!journal_join(&th, p_s_sb, 1)) {
3153 reiserfs_prepare_for_journal(p_s_sb, SB_BUFFER_WITH_SB(p_s_sb), 1) ; 3452 reiserfs_prepare_for_journal(p_s_sb,
3154 journal_mark_dirty(&th, p_s_sb, SB_BUFFER_WITH_SB(p_s_sb)) ; 3453 SB_BUFFER_WITH_SB(p_s_sb),
3155 3454 1);
3156 /* we're only being called from kreiserfsd, it makes no sense to do 3455 journal_mark_dirty(&th, p_s_sb,
3157 ** an async commit so that kreiserfsd can do it later 3456 SB_BUFFER_WITH_SB(p_s_sb));
3158 */ 3457
3159 do_journal_end(&th, p_s_sb,1, COMMIT_NOW | WAIT) ; 3458 /* we're only being called from kreiserfsd, it makes no sense to do
3160 } 3459 ** an async commit so that kreiserfsd can do it later
3161 } 3460 */
3162 return p_s_sb->s_dirt; 3461 do_journal_end(&th, p_s_sb, 1, COMMIT_NOW | WAIT);
3462 }
3463 }
3464 return p_s_sb->s_dirt;
3163} 3465}
3164 3466
3165/* 3467/*
@@ -3173,101 +3475,108 @@ int reiserfs_flush_old_commits(struct super_block *p_s_sb) {
3173** 3475**
3174** Note, we can't allow the journal_end to proceed while there are still writers in the log. 3476** Note, we can't allow the journal_end to proceed while there are still writers in the log.
3175*/ 3477*/
3176static int check_journal_end(struct reiserfs_transaction_handle *th, struct super_block * p_s_sb, 3478static int check_journal_end(struct reiserfs_transaction_handle *th,
3177 unsigned long nblocks, int flags) { 3479 struct super_block *p_s_sb, unsigned long nblocks,
3178 3480 int flags)
3179 time_t now ; 3481{
3180 int flush = flags & FLUSH_ALL ; 3482
3181 int commit_now = flags & COMMIT_NOW ; 3483 time_t now;
3182 int wait_on_commit = flags & WAIT ; 3484 int flush = flags & FLUSH_ALL;
3183 struct reiserfs_journal_list *jl; 3485 int commit_now = flags & COMMIT_NOW;
3184 struct reiserfs_journal *journal = SB_JOURNAL (p_s_sb); 3486 int wait_on_commit = flags & WAIT;
3185 3487 struct reiserfs_journal_list *jl;
3186 BUG_ON (!th->t_trans_id); 3488 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb);
3187 3489
3188 if (th->t_trans_id != journal->j_trans_id) { 3490 BUG_ON(!th->t_trans_id);
3189 reiserfs_panic(th->t_super, "journal-1577: handle trans id %ld != current trans id %ld\n", 3491
3190 th->t_trans_id, journal->j_trans_id); 3492 if (th->t_trans_id != journal->j_trans_id) {
3191 } 3493 reiserfs_panic(th->t_super,
3192 3494 "journal-1577: handle trans id %ld != current trans id %ld\n",
3193 journal->j_len_alloc -= (th->t_blocks_allocated - th->t_blocks_logged) ; 3495 th->t_trans_id, journal->j_trans_id);
3194 if (atomic_read(&(journal->j_wcount)) > 0) { /* <= 0 is allowed. unmounting might not call begin */ 3496 }
3195 atomic_dec(&(journal->j_wcount)) ; 3497
3196 } 3498 journal->j_len_alloc -= (th->t_blocks_allocated - th->t_blocks_logged);
3197 3499 if (atomic_read(&(journal->j_wcount)) > 0) { /* <= 0 is allowed. unmounting might not call begin */
3198 /* BUG, deal with case where j_len is 0, but people previously freed blocks need to be released 3500 atomic_dec(&(journal->j_wcount));
3199 ** will be dealt with by next transaction that actually writes something, but should be taken 3501 }
3200 ** care of in this trans 3502
3201 */ 3503 /* BUG, deal with case where j_len is 0, but people previously freed blocks need to be released
3202 if (journal->j_len == 0) { 3504 ** will be dealt with by next transaction that actually writes something, but should be taken
3203 BUG(); 3505 ** care of in this trans
3204 } 3506 */
3205 /* if wcount > 0, and we are called to with flush or commit_now, 3507 if (journal->j_len == 0) {
3206 ** we wait on j_join_wait. We will wake up when the last writer has 3508 BUG();
3207 ** finished the transaction, and started it on its way to the disk. 3509 }
3208 ** Then, we flush the commit or journal list, and just return 0 3510 /* if wcount > 0, and we are called to with flush or commit_now,
3209 ** because the rest of journal end was already done for this transaction. 3511 ** we wait on j_join_wait. We will wake up when the last writer has
3210 */ 3512 ** finished the transaction, and started it on its way to the disk.
3211 if (atomic_read(&(journal->j_wcount)) > 0) { 3513 ** Then, we flush the commit or journal list, and just return 0
3212 if (flush || commit_now) { 3514 ** because the rest of journal end was already done for this transaction.
3213 unsigned trans_id ; 3515 */
3214 3516 if (atomic_read(&(journal->j_wcount)) > 0) {
3215 jl = journal->j_current_jl; 3517 if (flush || commit_now) {
3216 trans_id = jl->j_trans_id; 3518 unsigned trans_id;
3217 if (wait_on_commit) 3519
3218 jl->j_state |= LIST_COMMIT_PENDING; 3520 jl = journal->j_current_jl;
3219 atomic_set(&(journal->j_jlock), 1) ; 3521 trans_id = jl->j_trans_id;
3220 if (flush) { 3522 if (wait_on_commit)
3221 journal->j_next_full_flush = 1 ; 3523 jl->j_state |= LIST_COMMIT_PENDING;
3222 } 3524 atomic_set(&(journal->j_jlock), 1);
3223 unlock_journal(p_s_sb) ; 3525 if (flush) {
3224 3526 journal->j_next_full_flush = 1;
3225 /* sleep while the current transaction is still j_jlocked */ 3527 }
3226 while(journal->j_trans_id == trans_id) { 3528 unlock_journal(p_s_sb);
3227 if (atomic_read(&journal->j_jlock)) { 3529
3228 queue_log_writer(p_s_sb); 3530 /* sleep while the current transaction is still j_jlocked */
3229 } else { 3531 while (journal->j_trans_id == trans_id) {
3230 lock_journal(p_s_sb); 3532 if (atomic_read(&journal->j_jlock)) {
3231 if (journal->j_trans_id == trans_id) { 3533 queue_log_writer(p_s_sb);
3232 atomic_set(&(journal->j_jlock), 1) ; 3534 } else {
3233 } 3535 lock_journal(p_s_sb);
3234 unlock_journal(p_s_sb); 3536 if (journal->j_trans_id == trans_id) {
3235 } 3537 atomic_set(&(journal->j_jlock),
3236 } 3538 1);
3237 if (journal->j_trans_id == trans_id) { 3539 }
3238 BUG(); 3540 unlock_journal(p_s_sb);
3239 } 3541 }
3240 if (commit_now && journal_list_still_alive(p_s_sb, trans_id) && 3542 }
3241 wait_on_commit) 3543 if (journal->j_trans_id == trans_id) {
3242 { 3544 BUG();
3243 flush_commit_list(p_s_sb, jl, 1) ; 3545 }
3244 } 3546 if (commit_now
3245 return 0 ; 3547 && journal_list_still_alive(p_s_sb, trans_id)
3246 } 3548 && wait_on_commit) {
3247 unlock_journal(p_s_sb) ; 3549 flush_commit_list(p_s_sb, jl, 1);
3248 return 0 ; 3550 }
3249 } 3551 return 0;
3250 3552 }
3251 /* deal with old transactions where we are the last writers */ 3553 unlock_journal(p_s_sb);
3252 now = get_seconds(); 3554 return 0;
3253 if ((now - journal->j_trans_start_time) > journal->j_max_trans_age) { 3555 }
3254 commit_now = 1 ; 3556
3255 journal->j_next_async_flush = 1 ; 3557 /* deal with old transactions where we are the last writers */
3256 } 3558 now = get_seconds();
3257 /* don't batch when someone is waiting on j_join_wait */ 3559 if ((now - journal->j_trans_start_time) > journal->j_max_trans_age) {
3258 /* don't batch when syncing the commit or flushing the whole trans */ 3560 commit_now = 1;
3259 if (!(journal->j_must_wait > 0) && !(atomic_read(&(journal->j_jlock))) && !flush && !commit_now && 3561 journal->j_next_async_flush = 1;
3260 (journal->j_len < journal->j_max_batch) && 3562 }
3261 journal->j_len_alloc < journal->j_max_batch && journal->j_cnode_free > (journal->j_trans_max * 3)) { 3563 /* don't batch when someone is waiting on j_join_wait */
3262 journal->j_bcount++ ; 3564 /* don't batch when syncing the commit or flushing the whole trans */
3263 unlock_journal(p_s_sb) ; 3565 if (!(journal->j_must_wait > 0) && !(atomic_read(&(journal->j_jlock)))
3264 return 0 ; 3566 && !flush && !commit_now && (journal->j_len < journal->j_max_batch)
3265 } 3567 && journal->j_len_alloc < journal->j_max_batch
3266 3568 && journal->j_cnode_free > (journal->j_trans_max * 3)) {
3267 if (journal->j_start > SB_ONDISK_JOURNAL_SIZE(p_s_sb)) { 3569 journal->j_bcount++;
3268 reiserfs_panic(p_s_sb, "journal-003: journal_end: j_start (%ld) is too high\n", journal->j_start) ; 3570 unlock_journal(p_s_sb);
3269 } 3571 return 0;
3270 return 1 ; 3572 }
3573
3574 if (journal->j_start > SB_ONDISK_JOURNAL_SIZE(p_s_sb)) {
3575 reiserfs_panic(p_s_sb,
3576 "journal-003: journal_end: j_start (%ld) is too high\n",
3577 journal->j_start);
3578 }
3579 return 1;
3271} 3580}
3272 3581
3273/* 3582/*
@@ -3284,83 +3593,95 @@ static int check_journal_end(struct reiserfs_transaction_handle *th, struct supe
3284** 3593**
3285** Then remove it from the current transaction, decrementing any counters and filing it on the clean list. 3594** Then remove it from the current transaction, decrementing any counters and filing it on the clean list.
3286*/ 3595*/
3287int journal_mark_freed(struct reiserfs_transaction_handle *th, struct super_block *p_s_sb, b_blocknr_t blocknr) { 3596int journal_mark_freed(struct reiserfs_transaction_handle *th,
3288 struct reiserfs_journal *journal = SB_JOURNAL (p_s_sb); 3597 struct super_block *p_s_sb, b_blocknr_t blocknr)
3289 struct reiserfs_journal_cnode *cn = NULL ; 3598{
3290 struct buffer_head *bh = NULL ; 3599 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb);
3291 struct reiserfs_list_bitmap *jb = NULL ; 3600 struct reiserfs_journal_cnode *cn = NULL;
3292 int cleaned = 0 ; 3601 struct buffer_head *bh = NULL;
3293 BUG_ON (!th->t_trans_id); 3602 struct reiserfs_list_bitmap *jb = NULL;
3294 3603 int cleaned = 0;
3295 cn = get_journal_hash_dev(p_s_sb, journal->j_hash_table, blocknr); 3604 BUG_ON(!th->t_trans_id);
3296 if (cn && cn->bh) { 3605
3297 bh = cn->bh ; 3606 cn = get_journal_hash_dev(p_s_sb, journal->j_hash_table, blocknr);
3298 get_bh(bh) ; 3607 if (cn && cn->bh) {
3299 } 3608 bh = cn->bh;
3300 /* if it is journal new, we just remove it from this transaction */ 3609 get_bh(bh);
3301 if (bh && buffer_journal_new(bh)) { 3610 }
3302 clear_buffer_journal_new (bh); 3611 /* if it is journal new, we just remove it from this transaction */
3303 clear_prepared_bits(bh) ; 3612 if (bh && buffer_journal_new(bh)) {
3304 reiserfs_clean_and_file_buffer(bh) ; 3613 clear_buffer_journal_new(bh);
3305 cleaned = remove_from_transaction(p_s_sb, blocknr, cleaned) ; 3614 clear_prepared_bits(bh);
3306 } else { 3615 reiserfs_clean_and_file_buffer(bh);
3307 /* set the bit for this block in the journal bitmap for this transaction */ 3616 cleaned = remove_from_transaction(p_s_sb, blocknr, cleaned);
3308 jb = journal->j_current_jl->j_list_bitmap; 3617 } else {
3309 if (!jb) { 3618 /* set the bit for this block in the journal bitmap for this transaction */
3310 reiserfs_panic(p_s_sb, "journal-1702: journal_mark_freed, journal_list_bitmap is NULL\n") ; 3619 jb = journal->j_current_jl->j_list_bitmap;
3311 } 3620 if (!jb) {
3312 set_bit_in_list_bitmap(p_s_sb, blocknr, jb) ; 3621 reiserfs_panic(p_s_sb,
3313 3622 "journal-1702: journal_mark_freed, journal_list_bitmap is NULL\n");
3314 /* Note, the entire while loop is not allowed to schedule. */ 3623 }
3315 3624 set_bit_in_list_bitmap(p_s_sb, blocknr, jb);
3316 if (bh) { 3625
3317 clear_prepared_bits(bh) ; 3626 /* Note, the entire while loop is not allowed to schedule. */
3318 reiserfs_clean_and_file_buffer(bh) ; 3627
3319 } 3628 if (bh) {
3320 cleaned = remove_from_transaction(p_s_sb, blocknr, cleaned) ; 3629 clear_prepared_bits(bh);
3321 3630 reiserfs_clean_and_file_buffer(bh);
3322 /* find all older transactions with this block, make sure they don't try to write it out */ 3631 }
3323 cn = get_journal_hash_dev(p_s_sb,journal->j_list_hash_table, blocknr) ; 3632 cleaned = remove_from_transaction(p_s_sb, blocknr, cleaned);
3324 while (cn) { 3633
3325 if (p_s_sb == cn->sb && blocknr == cn->blocknr) { 3634 /* find all older transactions with this block, make sure they don't try to write it out */
3326 set_bit(BLOCK_FREED, &cn->state) ; 3635 cn = get_journal_hash_dev(p_s_sb, journal->j_list_hash_table,
3327 if (cn->bh) { 3636 blocknr);
3328 if (!cleaned) { 3637 while (cn) {
3329 /* remove_from_transaction will brelse the buffer if it was 3638 if (p_s_sb == cn->sb && blocknr == cn->blocknr) {
3330 ** in the current trans 3639 set_bit(BLOCK_FREED, &cn->state);
3331 */ 3640 if (cn->bh) {
3332 clear_buffer_journal_dirty (cn->bh); 3641 if (!cleaned) {
3333 clear_buffer_dirty(cn->bh); 3642 /* remove_from_transaction will brelse the buffer if it was
3334 clear_buffer_journal_test(cn->bh); 3643 ** in the current trans
3335 cleaned = 1 ; 3644 */
3336 put_bh(cn->bh) ; 3645 clear_buffer_journal_dirty(cn->
3337 if (atomic_read(&(cn->bh->b_count)) < 0) { 3646 bh);
3338 reiserfs_warning (p_s_sb, "journal-2138: cn->bh->b_count < 0"); 3647 clear_buffer_dirty(cn->bh);
3339 } 3648 clear_buffer_journal_test(cn->
3340 } 3649 bh);
3341 if (cn->jlist) { /* since we are clearing the bh, we MUST dec nonzerolen */ 3650 cleaned = 1;
3342 atomic_dec(&(cn->jlist->j_nonzerolen)) ; 3651 put_bh(cn->bh);
3343 } 3652 if (atomic_read
3344 cn->bh = NULL ; 3653 (&(cn->bh->b_count)) < 0) {
3345 } 3654 reiserfs_warning(p_s_sb,
3346 } 3655 "journal-2138: cn->bh->b_count < 0");
3347 cn = cn->hnext ; 3656 }
3348 } 3657 }
3349 } 3658 if (cn->jlist) { /* since we are clearing the bh, we MUST dec nonzerolen */
3350 3659 atomic_dec(&
3351 if (bh) { 3660 (cn->jlist->
3352 put_bh(bh) ; /* get_hash grabs the buffer */ 3661 j_nonzerolen));
3353 if (atomic_read(&(bh->b_count)) < 0) { 3662 }
3354 reiserfs_warning (p_s_sb, "journal-2165: bh->b_count < 0"); 3663 cn->bh = NULL;
3355 } 3664 }
3356 } 3665 }
3357 return 0 ; 3666 cn = cn->hnext;
3358} 3667 }
3359 3668 }
3360void reiserfs_update_inode_transaction(struct inode *inode) { 3669
3361 struct reiserfs_journal *journal = SB_JOURNAL (inode->i_sb); 3670 if (bh) {
3362 REISERFS_I(inode)->i_jl = journal->j_current_jl; 3671 put_bh(bh); /* get_hash grabs the buffer */
3363 REISERFS_I(inode)->i_trans_id = journal->j_trans_id ; 3672 if (atomic_read(&(bh->b_count)) < 0) {
3673 reiserfs_warning(p_s_sb,
3674 "journal-2165: bh->b_count < 0");
3675 }
3676 }
3677 return 0;
3678}
3679
3680void reiserfs_update_inode_transaction(struct inode *inode)
3681{
3682 struct reiserfs_journal *journal = SB_JOURNAL(inode->i_sb);
3683 REISERFS_I(inode)->i_jl = journal->j_current_jl;
3684 REISERFS_I(inode)->i_trans_id = journal->j_trans_id;
3364} 3685}
3365 3686
3366/* 3687/*
@@ -3368,99 +3689,102 @@ void reiserfs_update_inode_transaction(struct inode *inode) {
3368 * if a transaction was actually committed and the barrier was done 3689 * if a transaction was actually committed and the barrier was done
3369 */ 3690 */
3370static int __commit_trans_jl(struct inode *inode, unsigned long id, 3691static int __commit_trans_jl(struct inode *inode, unsigned long id,
3371 struct reiserfs_journal_list *jl) 3692 struct reiserfs_journal_list *jl)
3372{ 3693{
3373 struct reiserfs_transaction_handle th ; 3694 struct reiserfs_transaction_handle th;
3374 struct super_block *sb = inode->i_sb ; 3695 struct super_block *sb = inode->i_sb;
3375 struct reiserfs_journal *journal = SB_JOURNAL (sb); 3696 struct reiserfs_journal *journal = SB_JOURNAL(sb);
3376 int ret = 0; 3697 int ret = 0;
3698
3699 /* is it from the current transaction, or from an unknown transaction? */
3700 if (id == journal->j_trans_id) {
3701 jl = journal->j_current_jl;
3702 /* try to let other writers come in and grow this transaction */
3703 let_transaction_grow(sb, id);
3704 if (journal->j_trans_id != id) {
3705 goto flush_commit_only;
3706 }
3377 3707
3378 /* is it from the current transaction, or from an unknown transaction? */ 3708 ret = journal_begin(&th, sb, 1);
3379 if (id == journal->j_trans_id) { 3709 if (ret)
3380 jl = journal->j_current_jl; 3710 return ret;
3381 /* try to let other writers come in and grow this transaction */ 3711
3382 let_transaction_grow(sb, id); 3712 /* someone might have ended this transaction while we joined */
3383 if (journal->j_trans_id != id) { 3713 if (journal->j_trans_id != id) {
3384 goto flush_commit_only; 3714 reiserfs_prepare_for_journal(sb, SB_BUFFER_WITH_SB(sb),
3385 } 3715 1);
3716 journal_mark_dirty(&th, sb, SB_BUFFER_WITH_SB(sb));
3717 ret = journal_end(&th, sb, 1);
3718 goto flush_commit_only;
3719 }
3386 3720
3387 ret = journal_begin(&th, sb, 1) ; 3721 ret = journal_end_sync(&th, sb, 1);
3388 if (ret) 3722 if (!ret)
3389 return ret; 3723 ret = 1;
3390 3724
3391 /* someone might have ended this transaction while we joined */ 3725 } else {
3392 if (journal->j_trans_id != id) { 3726 /* this gets tricky, we have to make sure the journal list in
3393 reiserfs_prepare_for_journal(sb, SB_BUFFER_WITH_SB(sb), 1) ; 3727 * the inode still exists. We know the list is still around
3394 journal_mark_dirty(&th, sb, SB_BUFFER_WITH_SB(sb)) ; 3728 * if we've got a larger transaction id than the oldest list
3395 ret = journal_end(&th, sb, 1) ; 3729 */
3396 goto flush_commit_only; 3730 flush_commit_only:
3731 if (journal_list_still_alive(inode->i_sb, id)) {
3732 /*
3733 * we only set ret to 1 when we know for sure
3734 * the barrier hasn't been started yet on the commit
3735 * block.
3736 */
3737 if (atomic_read(&jl->j_commit_left) > 1)
3738 ret = 1;
3739 flush_commit_list(sb, jl, 1);
3740 if (journal->j_errno)
3741 ret = journal->j_errno;
3742 }
3397 } 3743 }
3744 /* otherwise the list is gone, and long since committed */
3745 return ret;
3746}
3398 3747
3399 ret = journal_end_sync(&th, sb, 1) ; 3748int reiserfs_commit_for_inode(struct inode *inode)
3400 if (!ret) 3749{
3401 ret = 1; 3750 unsigned long id = REISERFS_I(inode)->i_trans_id;
3751 struct reiserfs_journal_list *jl = REISERFS_I(inode)->i_jl;
3402 3752
3403 } else { 3753 /* for the whole inode, assume unset id means it was
3404 /* this gets tricky, we have to make sure the journal list in 3754 * changed in the current transaction. More conservative
3405 * the inode still exists. We know the list is still around
3406 * if we've got a larger transaction id than the oldest list
3407 */ 3755 */
3408flush_commit_only: 3756 if (!id || !jl) {
3409 if (journal_list_still_alive(inode->i_sb, id)) { 3757 reiserfs_update_inode_transaction(inode);
3410 /* 3758 id = REISERFS_I(inode)->i_trans_id;
3411 * we only set ret to 1 when we know for sure 3759 /* jl will be updated in __commit_trans_jl */
3412 * the barrier hasn't been started yet on the commit 3760 }
3413 * block. 3761
3414 */ 3762 return __commit_trans_jl(inode, id, jl);
3415 if (atomic_read(&jl->j_commit_left) > 1) 3763}
3416 ret = 1; 3764
3417 flush_commit_list(sb, jl, 1) ; 3765void reiserfs_restore_prepared_buffer(struct super_block *p_s_sb,
3418 if (journal->j_errno) 3766 struct buffer_head *bh)
3419 ret = journal->j_errno; 3767{
3420 } 3768 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb);
3421 } 3769 PROC_INFO_INC(p_s_sb, journal.restore_prepared);
3422 /* otherwise the list is gone, and long since committed */ 3770 if (!bh) {
3423 return ret; 3771 return;
3424} 3772 }
3425 3773 if (test_clear_buffer_journal_restore_dirty(bh) &&
3426int reiserfs_commit_for_inode(struct inode *inode) { 3774 buffer_journal_dirty(bh)) {
3427 unsigned long id = REISERFS_I(inode)->i_trans_id; 3775 struct reiserfs_journal_cnode *cn;
3428 struct reiserfs_journal_list *jl = REISERFS_I(inode)->i_jl; 3776 cn = get_journal_hash_dev(p_s_sb,
3429 3777 journal->j_list_hash_table,
3430 /* for the whole inode, assume unset id means it was 3778 bh->b_blocknr);
3431 * changed in the current transaction. More conservative 3779 if (cn && can_dirty(cn)) {
3432 */ 3780 set_buffer_journal_test(bh);
3433 if (!id || !jl) { 3781 mark_buffer_dirty(bh);
3434 reiserfs_update_inode_transaction(inode) ; 3782 }
3435 id = REISERFS_I(inode)->i_trans_id; 3783 }
3436 /* jl will be updated in __commit_trans_jl */ 3784 clear_buffer_journal_prepared(bh);
3437 } 3785}
3438 3786
3439 return __commit_trans_jl(inode, id, jl); 3787extern struct tree_balance *cur_tb;
3440}
3441
3442void reiserfs_restore_prepared_buffer(struct super_block *p_s_sb,
3443 struct buffer_head *bh) {
3444 struct reiserfs_journal *journal = SB_JOURNAL (p_s_sb);
3445 PROC_INFO_INC( p_s_sb, journal.restore_prepared );
3446 if (!bh) {
3447 return ;
3448 }
3449 if (test_clear_buffer_journal_restore_dirty (bh) &&
3450 buffer_journal_dirty(bh)) {
3451 struct reiserfs_journal_cnode *cn;
3452 cn = get_journal_hash_dev(p_s_sb,
3453 journal->j_list_hash_table,
3454 bh->b_blocknr);
3455 if (cn && can_dirty(cn)) {
3456 set_buffer_journal_test (bh);
3457 mark_buffer_dirty(bh);
3458 }
3459 }
3460 clear_buffer_journal_prepared (bh);
3461}
3462
3463extern struct tree_balance *cur_tb ;
3464/* 3788/*
3465** before we can change a metadata block, we have to make sure it won't 3789** before we can change a metadata block, we have to make sure it won't
3466** be written to disk while we are altering it. So, we must: 3790** be written to disk while we are altering it. So, we must:
@@ -3469,39 +3793,41 @@ extern struct tree_balance *cur_tb ;
3469** 3793**
3470*/ 3794*/
3471int reiserfs_prepare_for_journal(struct super_block *p_s_sb, 3795int reiserfs_prepare_for_journal(struct super_block *p_s_sb,
3472 struct buffer_head *bh, int wait) { 3796 struct buffer_head *bh, int wait)
3473 PROC_INFO_INC( p_s_sb, journal.prepare ); 3797{
3474 3798 PROC_INFO_INC(p_s_sb, journal.prepare);
3475 if (test_set_buffer_locked(bh)) { 3799
3476 if (!wait) 3800 if (test_set_buffer_locked(bh)) {
3477 return 0; 3801 if (!wait)
3478 lock_buffer(bh); 3802 return 0;
3479 } 3803 lock_buffer(bh);
3480 set_buffer_journal_prepared (bh); 3804 }
3481 if (test_clear_buffer_dirty(bh) && buffer_journal_dirty(bh)) { 3805 set_buffer_journal_prepared(bh);
3482 clear_buffer_journal_test (bh); 3806 if (test_clear_buffer_dirty(bh) && buffer_journal_dirty(bh)) {
3483 set_buffer_journal_restore_dirty (bh); 3807 clear_buffer_journal_test(bh);
3484 } 3808 set_buffer_journal_restore_dirty(bh);
3485 unlock_buffer(bh); 3809 }
3486 return 1; 3810 unlock_buffer(bh);
3487} 3811 return 1;
3488 3812}
3489static void flush_old_journal_lists(struct super_block *s) { 3813
3490 struct reiserfs_journal *journal = SB_JOURNAL (s); 3814static void flush_old_journal_lists(struct super_block *s)
3491 struct reiserfs_journal_list *jl; 3815{
3492 struct list_head *entry; 3816 struct reiserfs_journal *journal = SB_JOURNAL(s);
3493 time_t now = get_seconds(); 3817 struct reiserfs_journal_list *jl;
3494 3818 struct list_head *entry;
3495 while(!list_empty(&journal->j_journal_list)) { 3819 time_t now = get_seconds();
3496 entry = journal->j_journal_list.next; 3820
3497 jl = JOURNAL_LIST_ENTRY(entry); 3821 while (!list_empty(&journal->j_journal_list)) {
3498 /* this check should always be run, to send old lists to disk */ 3822 entry = journal->j_journal_list.next;
3499 if (jl->j_timestamp < (now - (JOURNAL_MAX_TRANS_AGE * 4))) { 3823 jl = JOURNAL_LIST_ENTRY(entry);
3500 flush_used_journal_lists(s, jl); 3824 /* this check should always be run, to send old lists to disk */
3501 } else { 3825 if (jl->j_timestamp < (now - (JOURNAL_MAX_TRANS_AGE * 4))) {
3502 break; 3826 flush_used_journal_lists(s, jl);
3827 } else {
3828 break;
3829 }
3503 } 3830 }
3504 }
3505} 3831}
3506 3832
3507/* 3833/*
@@ -3514,375 +3840,390 @@ static void flush_old_journal_lists(struct super_block *s) {
3514** If the journal is aborted, we just clean up. Things like flushing 3840** If the journal is aborted, we just clean up. Things like flushing
3515** journal lists, etc just won't happen. 3841** journal lists, etc just won't happen.
3516*/ 3842*/
3517static int do_journal_end(struct reiserfs_transaction_handle *th, struct super_block * p_s_sb, unsigned long nblocks, 3843static int do_journal_end(struct reiserfs_transaction_handle *th,
3518 int flags) { 3844 struct super_block *p_s_sb, unsigned long nblocks,
3519 struct reiserfs_journal *journal = SB_JOURNAL (p_s_sb); 3845 int flags)
3520 struct reiserfs_journal_cnode *cn, *next, *jl_cn; 3846{
3521 struct reiserfs_journal_cnode *last_cn = NULL; 3847 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb);
3522 struct reiserfs_journal_desc *desc ; 3848 struct reiserfs_journal_cnode *cn, *next, *jl_cn;
3523 struct reiserfs_journal_commit *commit ; 3849 struct reiserfs_journal_cnode *last_cn = NULL;
3524 struct buffer_head *c_bh ; /* commit bh */ 3850 struct reiserfs_journal_desc *desc;
3525 struct buffer_head *d_bh ; /* desc bh */ 3851 struct reiserfs_journal_commit *commit;
3526 int cur_write_start = 0 ; /* start index of current log write */ 3852 struct buffer_head *c_bh; /* commit bh */
3527 int old_start ; 3853 struct buffer_head *d_bh; /* desc bh */
3528 int i ; 3854 int cur_write_start = 0; /* start index of current log write */
3529 int flush = flags & FLUSH_ALL ; 3855 int old_start;
3530 int wait_on_commit = flags & WAIT ; 3856 int i;
3531 struct reiserfs_journal_list *jl, *temp_jl; 3857 int flush = flags & FLUSH_ALL;
3532 struct list_head *entry, *safe; 3858 int wait_on_commit = flags & WAIT;
3533 unsigned long jindex; 3859 struct reiserfs_journal_list *jl, *temp_jl;
3534 unsigned long commit_trans_id; 3860 struct list_head *entry, *safe;
3535 int trans_half; 3861 unsigned long jindex;
3536 3862 unsigned long commit_trans_id;
3537 BUG_ON (th->t_refcount > 1); 3863 int trans_half;
3538 BUG_ON (!th->t_trans_id); 3864
3539 3865 BUG_ON(th->t_refcount > 1);
3540 put_fs_excl(); 3866 BUG_ON(!th->t_trans_id);
3541 current->journal_info = th->t_handle_save; 3867
3542 reiserfs_check_lock_depth(p_s_sb, "journal end"); 3868 put_fs_excl();
3543 if (journal->j_len == 0) { 3869 current->journal_info = th->t_handle_save;
3544 reiserfs_prepare_for_journal(p_s_sb, SB_BUFFER_WITH_SB(p_s_sb), 1) ; 3870 reiserfs_check_lock_depth(p_s_sb, "journal end");
3545 journal_mark_dirty(th, p_s_sb, SB_BUFFER_WITH_SB(p_s_sb)) ; 3871 if (journal->j_len == 0) {
3546 } 3872 reiserfs_prepare_for_journal(p_s_sb, SB_BUFFER_WITH_SB(p_s_sb),
3547 3873 1);
3548 lock_journal(p_s_sb) ; 3874 journal_mark_dirty(th, p_s_sb, SB_BUFFER_WITH_SB(p_s_sb));
3549 if (journal->j_next_full_flush) { 3875 }
3550 flags |= FLUSH_ALL ;
3551 flush = 1 ;
3552 }
3553 if (journal->j_next_async_flush) {
3554 flags |= COMMIT_NOW | WAIT;
3555 wait_on_commit = 1;
3556 }
3557
3558 /* check_journal_end locks the journal, and unlocks if it does not return 1
3559 ** it tells us if we should continue with the journal_end, or just return
3560 */
3561 if (!check_journal_end(th, p_s_sb, nblocks, flags)) {
3562 p_s_sb->s_dirt = 1;
3563 wake_queued_writers(p_s_sb);
3564 reiserfs_async_progress_wait(p_s_sb);
3565 goto out ;
3566 }
3567
3568 /* check_journal_end might set these, check again */
3569 if (journal->j_next_full_flush) {
3570 flush = 1 ;
3571 }
3572
3573 /*
3574 ** j must wait means we have to flush the log blocks, and the real blocks for
3575 ** this transaction
3576 */
3577 if (journal->j_must_wait > 0) {
3578 flush = 1 ;
3579 }
3580 3876
3877 lock_journal(p_s_sb);
3878 if (journal->j_next_full_flush) {
3879 flags |= FLUSH_ALL;
3880 flush = 1;
3881 }
3882 if (journal->j_next_async_flush) {
3883 flags |= COMMIT_NOW | WAIT;
3884 wait_on_commit = 1;
3885 }
3886
3887 /* check_journal_end locks the journal, and unlocks if it does not return 1
3888 ** it tells us if we should continue with the journal_end, or just return
3889 */
3890 if (!check_journal_end(th, p_s_sb, nblocks, flags)) {
3891 p_s_sb->s_dirt = 1;
3892 wake_queued_writers(p_s_sb);
3893 reiserfs_async_progress_wait(p_s_sb);
3894 goto out;
3895 }
3896
3897 /* check_journal_end might set these, check again */
3898 if (journal->j_next_full_flush) {
3899 flush = 1;
3900 }
3901
3902 /*
3903 ** j must wait means we have to flush the log blocks, and the real blocks for
3904 ** this transaction
3905 */
3906 if (journal->j_must_wait > 0) {
3907 flush = 1;
3908 }
3581#ifdef REISERFS_PREALLOCATE 3909#ifdef REISERFS_PREALLOCATE
3582 /* quota ops might need to nest, setup the journal_info pointer for them */ 3910 /* quota ops might need to nest, setup the journal_info pointer for them */
3583 current->journal_info = th ; 3911 current->journal_info = th;
3584 reiserfs_discard_all_prealloc(th); /* it should not involve new blocks into 3912 reiserfs_discard_all_prealloc(th); /* it should not involve new blocks into
3585 * the transaction */ 3913 * the transaction */
3586 current->journal_info = th->t_handle_save ; 3914 current->journal_info = th->t_handle_save;
3587#endif 3915#endif
3588 3916
3589 /* setup description block */ 3917 /* setup description block */
3590 d_bh = journal_getblk(p_s_sb, SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) + journal->j_start) ; 3918 d_bh =
3591 set_buffer_uptodate(d_bh); 3919 journal_getblk(p_s_sb,
3592 desc = (struct reiserfs_journal_desc *)(d_bh)->b_data ; 3920 SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) +
3593 memset(d_bh->b_data, 0, d_bh->b_size) ; 3921 journal->j_start);
3594 memcpy(get_journal_desc_magic (d_bh), JOURNAL_DESC_MAGIC, 8) ; 3922 set_buffer_uptodate(d_bh);
3595 set_desc_trans_id(desc, journal->j_trans_id) ; 3923 desc = (struct reiserfs_journal_desc *)(d_bh)->b_data;
3596 3924 memset(d_bh->b_data, 0, d_bh->b_size);
3597 /* setup commit block. Don't write (keep it clean too) this one until after everyone else is written */ 3925 memcpy(get_journal_desc_magic(d_bh), JOURNAL_DESC_MAGIC, 8);
3598 c_bh = journal_getblk(p_s_sb, SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) + 3926 set_desc_trans_id(desc, journal->j_trans_id);
3599 ((journal->j_start + journal->j_len + 1) % SB_ONDISK_JOURNAL_SIZE(p_s_sb))) ; 3927
3600 commit = (struct reiserfs_journal_commit *)c_bh->b_data ; 3928 /* setup commit block. Don't write (keep it clean too) this one until after everyone else is written */
3601 memset(c_bh->b_data, 0, c_bh->b_size) ; 3929 c_bh = journal_getblk(p_s_sb, SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) +
3602 set_commit_trans_id(commit, journal->j_trans_id) ; 3930 ((journal->j_start + journal->j_len +
3603 set_buffer_uptodate(c_bh) ; 3931 1) % SB_ONDISK_JOURNAL_SIZE(p_s_sb)));
3604 3932 commit = (struct reiserfs_journal_commit *)c_bh->b_data;
3605 /* init this journal list */ 3933 memset(c_bh->b_data, 0, c_bh->b_size);
3606 jl = journal->j_current_jl; 3934 set_commit_trans_id(commit, journal->j_trans_id);
3607 3935 set_buffer_uptodate(c_bh);
3608 /* we lock the commit before doing anything because 3936
3609 * we want to make sure nobody tries to run flush_commit_list until 3937 /* init this journal list */
3610 * the new transaction is fully setup, and we've already flushed the 3938 jl = journal->j_current_jl;
3611 * ordered bh list 3939
3612 */ 3940 /* we lock the commit before doing anything because
3613 down(&jl->j_commit_lock); 3941 * we want to make sure nobody tries to run flush_commit_list until
3614 3942 * the new transaction is fully setup, and we've already flushed the
3615 /* save the transaction id in case we need to commit it later */ 3943 * ordered bh list
3616 commit_trans_id = jl->j_trans_id; 3944 */
3617 3945 down(&jl->j_commit_lock);
3618 atomic_set(&jl->j_older_commits_done, 0) ; 3946
3619 jl->j_trans_id = journal->j_trans_id ; 3947 /* save the transaction id in case we need to commit it later */
3620 jl->j_timestamp = journal->j_trans_start_time ; 3948 commit_trans_id = jl->j_trans_id;
3621 jl->j_commit_bh = c_bh ; 3949
3622 jl->j_start = journal->j_start ; 3950 atomic_set(&jl->j_older_commits_done, 0);
3623 jl->j_len = journal->j_len ; 3951 jl->j_trans_id = journal->j_trans_id;
3624 atomic_set(&jl->j_nonzerolen, journal->j_len) ; 3952 jl->j_timestamp = journal->j_trans_start_time;
3625 atomic_set(&jl->j_commit_left, journal->j_len + 2); 3953 jl->j_commit_bh = c_bh;
3626 jl->j_realblock = NULL ; 3954 jl->j_start = journal->j_start;
3627 3955 jl->j_len = journal->j_len;
3628 /* The ENTIRE FOR LOOP MUST not cause schedule to occur. 3956 atomic_set(&jl->j_nonzerolen, journal->j_len);
3629 ** for each real block, add it to the journal list hash, 3957 atomic_set(&jl->j_commit_left, journal->j_len + 2);
3630 ** copy into real block index array in the commit or desc block 3958 jl->j_realblock = NULL;
3631 */ 3959
3632 trans_half = journal_trans_half(p_s_sb->s_blocksize); 3960 /* The ENTIRE FOR LOOP MUST not cause schedule to occur.
3633 for (i = 0, cn = journal->j_first ; cn ; cn = cn->next, i++) { 3961 ** for each real block, add it to the journal list hash,
3634 if (buffer_journaled (cn->bh)) { 3962 ** copy into real block index array in the commit or desc block
3635 jl_cn = get_cnode(p_s_sb) ; 3963 */
3636 if (!jl_cn) { 3964 trans_half = journal_trans_half(p_s_sb->s_blocksize);
3637 reiserfs_panic(p_s_sb, "journal-1676, get_cnode returned NULL\n") ; 3965 for (i = 0, cn = journal->j_first; cn; cn = cn->next, i++) {
3638 } 3966 if (buffer_journaled(cn->bh)) {
3639 if (i == 0) { 3967 jl_cn = get_cnode(p_s_sb);
3640 jl->j_realblock = jl_cn ; 3968 if (!jl_cn) {
3641 } 3969 reiserfs_panic(p_s_sb,
3642 jl_cn->prev = last_cn ; 3970 "journal-1676, get_cnode returned NULL\n");
3643 jl_cn->next = NULL ; 3971 }
3644 if (last_cn) { 3972 if (i == 0) {
3645 last_cn->next = jl_cn ; 3973 jl->j_realblock = jl_cn;
3646 } 3974 }
3647 last_cn = jl_cn ; 3975 jl_cn->prev = last_cn;
3648 /* make sure the block we are trying to log is not a block 3976 jl_cn->next = NULL;
3649 of journal or reserved area */ 3977 if (last_cn) {
3650 3978 last_cn->next = jl_cn;
3651 if (is_block_in_log_or_reserved_area(p_s_sb, cn->bh->b_blocknr)) { 3979 }
3652 reiserfs_panic(p_s_sb, "journal-2332: Trying to log block %lu, which is a log block\n", cn->bh->b_blocknr) ; 3980 last_cn = jl_cn;
3653 } 3981 /* make sure the block we are trying to log is not a block
3654 jl_cn->blocknr = cn->bh->b_blocknr ; 3982 of journal or reserved area */
3655 jl_cn->state = 0 ; 3983
3656 jl_cn->sb = p_s_sb; 3984 if (is_block_in_log_or_reserved_area
3657 jl_cn->bh = cn->bh ; 3985 (p_s_sb, cn->bh->b_blocknr)) {
3658 jl_cn->jlist = jl; 3986 reiserfs_panic(p_s_sb,
3659 insert_journal_hash(journal->j_list_hash_table, jl_cn) ; 3987 "journal-2332: Trying to log block %lu, which is a log block\n",
3660 if (i < trans_half) { 3988 cn->bh->b_blocknr);
3661 desc->j_realblock[i] = cpu_to_le32(cn->bh->b_blocknr) ; 3989 }
3662 } else { 3990 jl_cn->blocknr = cn->bh->b_blocknr;
3663 commit->j_realblock[i - trans_half] = cpu_to_le32(cn->bh->b_blocknr) ; 3991 jl_cn->state = 0;
3664 } 3992 jl_cn->sb = p_s_sb;
3665 } else { 3993 jl_cn->bh = cn->bh;
3666 i-- ; 3994 jl_cn->jlist = jl;
3667 } 3995 insert_journal_hash(journal->j_list_hash_table, jl_cn);
3668 } 3996 if (i < trans_half) {
3669 set_desc_trans_len(desc, journal->j_len) ; 3997 desc->j_realblock[i] =
3670 set_desc_mount_id(desc, journal->j_mount_id) ; 3998 cpu_to_le32(cn->bh->b_blocknr);
3671 set_desc_trans_id(desc, journal->j_trans_id) ; 3999 } else {
3672 set_commit_trans_len(commit, journal->j_len); 4000 commit->j_realblock[i - trans_half] =
3673 4001 cpu_to_le32(cn->bh->b_blocknr);
3674 /* special check in case all buffers in the journal were marked for not logging */ 4002 }
3675 if (journal->j_len == 0) { 4003 } else {
3676 BUG(); 4004 i--;
3677 } 4005 }
3678 4006 }
3679 /* we're about to dirty all the log blocks, mark the description block 4007 set_desc_trans_len(desc, journal->j_len);
3680 * dirty now too. Don't mark the commit block dirty until all the 4008 set_desc_mount_id(desc, journal->j_mount_id);
3681 * others are on disk 4009 set_desc_trans_id(desc, journal->j_trans_id);
3682 */ 4010 set_commit_trans_len(commit, journal->j_len);
3683 mark_buffer_dirty(d_bh); 4011
3684 4012 /* special check in case all buffers in the journal were marked for not logging */
3685 /* first data block is j_start + 1, so add one to cur_write_start wherever you use it */ 4013 if (journal->j_len == 0) {
3686 cur_write_start = journal->j_start ; 4014 BUG();
3687 cn = journal->j_first ; 4015 }
3688 jindex = 1 ; /* start at one so we don't get the desc again */ 4016
3689 while(cn) { 4017 /* we're about to dirty all the log blocks, mark the description block
3690 clear_buffer_journal_new (cn->bh); 4018 * dirty now too. Don't mark the commit block dirty until all the
3691 /* copy all the real blocks into log area. dirty log blocks */ 4019 * others are on disk
3692 if (buffer_journaled (cn->bh)) { 4020 */
3693 struct buffer_head *tmp_bh ; 4021 mark_buffer_dirty(d_bh);
3694 char *addr; 4022
3695 struct page *page; 4023 /* first data block is j_start + 1, so add one to cur_write_start wherever you use it */
3696 tmp_bh = journal_getblk(p_s_sb, SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) + 4024 cur_write_start = journal->j_start;
3697 ((cur_write_start + jindex) % SB_ONDISK_JOURNAL_SIZE(p_s_sb))) ; 4025 cn = journal->j_first;
3698 set_buffer_uptodate(tmp_bh); 4026 jindex = 1; /* start at one so we don't get the desc again */
3699 page = cn->bh->b_page; 4027 while (cn) {
3700 addr = kmap(page); 4028 clear_buffer_journal_new(cn->bh);
3701 memcpy(tmp_bh->b_data, addr + offset_in_page(cn->bh->b_data), 4029 /* copy all the real blocks into log area. dirty log blocks */
3702 cn->bh->b_size); 4030 if (buffer_journaled(cn->bh)) {
3703 kunmap(page); 4031 struct buffer_head *tmp_bh;
3704 mark_buffer_dirty(tmp_bh); 4032 char *addr;
3705 jindex++ ; 4033 struct page *page;
3706 set_buffer_journal_dirty (cn->bh); 4034 tmp_bh =
3707 clear_buffer_journaled (cn->bh); 4035 journal_getblk(p_s_sb,
3708 } else { 4036 SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) +
3709 /* JDirty cleared sometime during transaction. don't log this one */ 4037 ((cur_write_start +
3710 reiserfs_warning(p_s_sb, "journal-2048: do_journal_end: BAD, buffer in journal hash, but not JDirty!") ; 4038 jindex) %
3711 brelse(cn->bh) ; 4039 SB_ONDISK_JOURNAL_SIZE(p_s_sb)));
3712 } 4040 set_buffer_uptodate(tmp_bh);
3713 next = cn->next ; 4041 page = cn->bh->b_page;
3714 free_cnode(p_s_sb, cn) ; 4042 addr = kmap(page);
3715 cn = next ; 4043 memcpy(tmp_bh->b_data,
3716 cond_resched(); 4044 addr + offset_in_page(cn->bh->b_data),
3717 } 4045 cn->bh->b_size);
3718 4046 kunmap(page);
3719 /* we are done with both the c_bh and d_bh, but 4047 mark_buffer_dirty(tmp_bh);
3720 ** c_bh must be written after all other commit blocks, 4048 jindex++;
3721 ** so we dirty/relse c_bh in flush_commit_list, with commit_left <= 1. 4049 set_buffer_journal_dirty(cn->bh);
3722 */ 4050 clear_buffer_journaled(cn->bh);
3723 4051 } else {
3724 journal->j_current_jl = alloc_journal_list(p_s_sb); 4052 /* JDirty cleared sometime during transaction. don't log this one */
3725 4053 reiserfs_warning(p_s_sb,
3726 /* now it is safe to insert this transaction on the main list */ 4054 "journal-2048: do_journal_end: BAD, buffer in journal hash, but not JDirty!");
3727 list_add_tail(&jl->j_list, &journal->j_journal_list); 4055 brelse(cn->bh);
3728 list_add_tail(&jl->j_working_list, &journal->j_working_list); 4056 }
3729 journal->j_num_work_lists++; 4057 next = cn->next;
3730 4058 free_cnode(p_s_sb, cn);
3731 /* reset journal values for the next transaction */ 4059 cn = next;
3732 old_start = journal->j_start ; 4060 cond_resched();
3733 journal->j_start = (journal->j_start + journal->j_len + 2) % SB_ONDISK_JOURNAL_SIZE(p_s_sb); 4061 }
3734 atomic_set(&(journal->j_wcount), 0) ; 4062
3735 journal->j_bcount = 0 ; 4063 /* we are done with both the c_bh and d_bh, but
3736 journal->j_last = NULL ; 4064 ** c_bh must be written after all other commit blocks,
3737 journal->j_first = NULL ; 4065 ** so we dirty/relse c_bh in flush_commit_list, with commit_left <= 1.
3738 journal->j_len = 0 ; 4066 */
3739 journal->j_trans_start_time = 0 ; 4067
3740 journal->j_trans_id++ ; 4068 journal->j_current_jl = alloc_journal_list(p_s_sb);
3741 journal->j_current_jl->j_trans_id = journal->j_trans_id; 4069
3742 journal->j_must_wait = 0 ; 4070 /* now it is safe to insert this transaction on the main list */
3743 journal->j_len_alloc = 0 ; 4071 list_add_tail(&jl->j_list, &journal->j_journal_list);
3744 journal->j_next_full_flush = 0 ; 4072 list_add_tail(&jl->j_working_list, &journal->j_working_list);
3745 journal->j_next_async_flush = 0 ; 4073 journal->j_num_work_lists++;
3746 init_journal_hash(p_s_sb) ; 4074
3747 4075 /* reset journal values for the next transaction */
3748 // make sure reiserfs_add_jh sees the new current_jl before we 4076 old_start = journal->j_start;
3749 // write out the tails 4077 journal->j_start =
3750 smp_mb(); 4078 (journal->j_start + journal->j_len +
3751 4079 2) % SB_ONDISK_JOURNAL_SIZE(p_s_sb);
3752 /* tail conversion targets have to hit the disk before we end the 4080 atomic_set(&(journal->j_wcount), 0);
3753 * transaction. Otherwise a later transaction might repack the tail 4081 journal->j_bcount = 0;
3754 * before this transaction commits, leaving the data block unflushed and 4082 journal->j_last = NULL;
3755 * clean, if we crash before the later transaction commits, the data block 4083 journal->j_first = NULL;
3756 * is lost. 4084 journal->j_len = 0;
3757 */ 4085 journal->j_trans_start_time = 0;
3758 if (!list_empty(&jl->j_tail_bh_list)) { 4086 journal->j_trans_id++;
3759 unlock_kernel(); 4087 journal->j_current_jl->j_trans_id = journal->j_trans_id;
3760 write_ordered_buffers(&journal->j_dirty_buffers_lock, 4088 journal->j_must_wait = 0;
3761 journal, jl, &jl->j_tail_bh_list); 4089 journal->j_len_alloc = 0;
3762 lock_kernel(); 4090 journal->j_next_full_flush = 0;
3763 } 4091 journal->j_next_async_flush = 0;
3764 if (!list_empty(&jl->j_tail_bh_list)) 4092 init_journal_hash(p_s_sb);
3765 BUG(); 4093
3766 up(&jl->j_commit_lock); 4094 // make sure reiserfs_add_jh sees the new current_jl before we
3767 4095 // write out the tails
3768 /* honor the flush wishes from the caller, simple commits can 4096 smp_mb();
3769 ** be done outside the journal lock, they are done below 4097
3770 ** 4098 /* tail conversion targets have to hit the disk before we end the
3771 ** if we don't flush the commit list right now, we put it into 4099 * transaction. Otherwise a later transaction might repack the tail
3772 ** the work queue so the people waiting on the async progress work 4100 * before this transaction commits, leaving the data block unflushed and
3773 ** queue don't wait for this proc to flush journal lists and such. 4101 * clean, if we crash before the later transaction commits, the data block
3774 */ 4102 * is lost.
3775 if (flush) { 4103 */
3776 flush_commit_list(p_s_sb, jl, 1) ; 4104 if (!list_empty(&jl->j_tail_bh_list)) {
3777 flush_journal_list(p_s_sb, jl, 1) ; 4105 unlock_kernel();
3778 } else if (!(jl->j_state & LIST_COMMIT_PENDING)) 4106 write_ordered_buffers(&journal->j_dirty_buffers_lock,
3779 queue_delayed_work(commit_wq, &journal->j_work, HZ/10); 4107 journal, jl, &jl->j_tail_bh_list);
3780 4108 lock_kernel();
3781 4109 }
3782 /* if the next transaction has any chance of wrapping, flush 4110 if (!list_empty(&jl->j_tail_bh_list))
3783 ** transactions that might get overwritten. If any journal lists are very 4111 BUG();
3784 ** old flush them as well. 4112 up(&jl->j_commit_lock);
3785 */ 4113
3786first_jl: 4114 /* honor the flush wishes from the caller, simple commits can
3787 list_for_each_safe(entry, safe, &journal->j_journal_list) { 4115 ** be done outside the journal lock, they are done below
3788 temp_jl = JOURNAL_LIST_ENTRY(entry); 4116 **
3789 if (journal->j_start <= temp_jl->j_start) { 4117 ** if we don't flush the commit list right now, we put it into
3790 if ((journal->j_start + journal->j_trans_max + 1) >= 4118 ** the work queue so the people waiting on the async progress work
3791 temp_jl->j_start) 4119 ** queue don't wait for this proc to flush journal lists and such.
3792 { 4120 */
3793 flush_used_journal_lists(p_s_sb, temp_jl); 4121 if (flush) {
3794 goto first_jl; 4122 flush_commit_list(p_s_sb, jl, 1);
3795 } else if ((journal->j_start + 4123 flush_journal_list(p_s_sb, jl, 1);
3796 journal->j_trans_max + 1) < 4124 } else if (!(jl->j_state & LIST_COMMIT_PENDING))
3797 SB_ONDISK_JOURNAL_SIZE(p_s_sb)) 4125 queue_delayed_work(commit_wq, &journal->j_work, HZ / 10);
3798 { 4126
3799 /* if we don't cross into the next transaction and we don't 4127 /* if the next transaction has any chance of wrapping, flush
3800 * wrap, there is no way we can overlap any later transactions 4128 ** transactions that might get overwritten. If any journal lists are very
3801 * break now 4129 ** old flush them as well.
3802 */ 4130 */
3803 break; 4131 first_jl:
3804 } 4132 list_for_each_safe(entry, safe, &journal->j_journal_list) {
3805 } else if ((journal->j_start + 4133 temp_jl = JOURNAL_LIST_ENTRY(entry);
3806 journal->j_trans_max + 1) > 4134 if (journal->j_start <= temp_jl->j_start) {
3807 SB_ONDISK_JOURNAL_SIZE(p_s_sb)) 4135 if ((journal->j_start + journal->j_trans_max + 1) >=
3808 { 4136 temp_jl->j_start) {
3809 if (((journal->j_start + journal->j_trans_max + 1) % 4137 flush_used_journal_lists(p_s_sb, temp_jl);
3810 SB_ONDISK_JOURNAL_SIZE(p_s_sb)) >= temp_jl->j_start) 4138 goto first_jl;
3811 { 4139 } else if ((journal->j_start +
3812 flush_used_journal_lists(p_s_sb, temp_jl); 4140 journal->j_trans_max + 1) <
3813 goto first_jl; 4141 SB_ONDISK_JOURNAL_SIZE(p_s_sb)) {
3814 } else { 4142 /* if we don't cross into the next transaction and we don't
3815 /* we don't overlap anything from out start to the end of the 4143 * wrap, there is no way we can overlap any later transactions
3816 * log, and our wrapped portion doesn't overlap anything at 4144 * break now
3817 * the start of the log. We can break 4145 */
3818 */ 4146 break;
3819 break; 4147 }
3820 } 4148 } else if ((journal->j_start +
3821 } 4149 journal->j_trans_max + 1) >
3822 } 4150 SB_ONDISK_JOURNAL_SIZE(p_s_sb)) {
3823 flush_old_journal_lists(p_s_sb); 4151 if (((journal->j_start + journal->j_trans_max + 1) %
3824 4152 SB_ONDISK_JOURNAL_SIZE(p_s_sb)) >=
3825 journal->j_current_jl->j_list_bitmap = get_list_bitmap(p_s_sb, journal->j_current_jl) ; 4153 temp_jl->j_start) {
3826 4154 flush_used_journal_lists(p_s_sb, temp_jl);
3827 if (!(journal->j_current_jl->j_list_bitmap)) { 4155 goto first_jl;
3828 reiserfs_panic(p_s_sb, "journal-1996: do_journal_end, could not get a list bitmap\n") ; 4156 } else {
3829 } 4157 /* we don't overlap anything from out start to the end of the
3830 4158 * log, and our wrapped portion doesn't overlap anything at
3831 atomic_set(&(journal->j_jlock), 0) ; 4159 * the start of the log. We can break
3832 unlock_journal(p_s_sb) ; 4160 */
3833 /* wake up any body waiting to join. */ 4161 break;
3834 clear_bit(J_WRITERS_QUEUED, &journal->j_state); 4162 }
3835 wake_up(&(journal->j_join_wait)) ; 4163 }
3836 4164 }
3837 if (!flush && wait_on_commit && 4165 flush_old_journal_lists(p_s_sb);
3838 journal_list_still_alive(p_s_sb, commit_trans_id)) { 4166
3839 flush_commit_list(p_s_sb, jl, 1) ; 4167 journal->j_current_jl->j_list_bitmap =
3840 } 4168 get_list_bitmap(p_s_sb, journal->j_current_jl);
3841out: 4169
3842 reiserfs_check_lock_depth(p_s_sb, "journal end2"); 4170 if (!(journal->j_current_jl->j_list_bitmap)) {
3843 4171 reiserfs_panic(p_s_sb,
3844 memset (th, 0, sizeof (*th)); 4172 "journal-1996: do_journal_end, could not get a list bitmap\n");
3845 /* Re-set th->t_super, so we can properly keep track of how many 4173 }
3846 * persistent transactions there are. We need to do this so if this 4174
3847 * call is part of a failed restart_transaction, we can free it later */ 4175 atomic_set(&(journal->j_jlock), 0);
3848 th->t_super = p_s_sb; 4176 unlock_journal(p_s_sb);
3849 4177 /* wake up any body waiting to join. */
3850 return journal->j_errno; 4178 clear_bit(J_WRITERS_QUEUED, &journal->j_state);
3851} 4179 wake_up(&(journal->j_join_wait));
3852 4180
3853static void 4181 if (!flush && wait_on_commit &&
3854__reiserfs_journal_abort_hard (struct super_block *sb) 4182 journal_list_still_alive(p_s_sb, commit_trans_id)) {
3855{ 4183 flush_commit_list(p_s_sb, jl, 1);
3856 struct reiserfs_journal *journal = SB_JOURNAL (sb); 4184 }
3857 if (test_bit (J_ABORTED, &journal->j_state)) 4185 out:
3858 return; 4186 reiserfs_check_lock_depth(p_s_sb, "journal end2");
3859 4187
3860 printk (KERN_CRIT "REISERFS: Aborting journal for filesystem on %s\n", 4188 memset(th, 0, sizeof(*th));
3861 reiserfs_bdevname (sb)); 4189 /* Re-set th->t_super, so we can properly keep track of how many
3862 4190 * persistent transactions there are. We need to do this so if this
3863 sb->s_flags |= MS_RDONLY; 4191 * call is part of a failed restart_transaction, we can free it later */
3864 set_bit (J_ABORTED, &journal->j_state); 4192 th->t_super = p_s_sb;
4193
4194 return journal->j_errno;
4195}
4196
4197static void __reiserfs_journal_abort_hard(struct super_block *sb)
4198{
4199 struct reiserfs_journal *journal = SB_JOURNAL(sb);
4200 if (test_bit(J_ABORTED, &journal->j_state))
4201 return;
4202
4203 printk(KERN_CRIT "REISERFS: Aborting journal for filesystem on %s\n",
4204 reiserfs_bdevname(sb));
4205
4206 sb->s_flags |= MS_RDONLY;
4207 set_bit(J_ABORTED, &journal->j_state);
3865 4208
3866#ifdef CONFIG_REISERFS_CHECK 4209#ifdef CONFIG_REISERFS_CHECK
3867 dump_stack(); 4210 dump_stack();
3868#endif 4211#endif
3869} 4212}
3870 4213
3871static void 4214static void __reiserfs_journal_abort_soft(struct super_block *sb, int errno)
3872__reiserfs_journal_abort_soft (struct super_block *sb, int errno)
3873{ 4215{
3874 struct reiserfs_journal *journal = SB_JOURNAL (sb); 4216 struct reiserfs_journal *journal = SB_JOURNAL(sb);
3875 if (test_bit (J_ABORTED, &journal->j_state)) 4217 if (test_bit(J_ABORTED, &journal->j_state))
3876 return; 4218 return;
3877 4219
3878 if (!journal->j_errno) 4220 if (!journal->j_errno)
3879 journal->j_errno = errno; 4221 journal->j_errno = errno;
3880 4222
3881 __reiserfs_journal_abort_hard (sb); 4223 __reiserfs_journal_abort_hard(sb);
3882} 4224}
3883 4225
3884void 4226void reiserfs_journal_abort(struct super_block *sb, int errno)
3885reiserfs_journal_abort (struct super_block *sb, int errno)
3886{ 4227{
3887 return __reiserfs_journal_abort_soft (sb, errno); 4228 return __reiserfs_journal_abort_soft(sb, errno);
3888} 4229}
diff --git a/fs/reiserfs/lbalance.c b/fs/reiserfs/lbalance.c
index 2406608fc5cd..2533c1f64aba 100644
--- a/fs/reiserfs/lbalance.c
+++ b/fs/reiserfs/lbalance.c
@@ -21,648 +21,709 @@
21 leaf_paste_entries 21 leaf_paste_entries
22 */ 22 */
23 23
24
25/* copy copy_count entries from source directory item to dest buffer (creating new item if needed) */ 24/* copy copy_count entries from source directory item to dest buffer (creating new item if needed) */
26static void leaf_copy_dir_entries (struct buffer_info * dest_bi, struct buffer_head * source, 25static void leaf_copy_dir_entries(struct buffer_info *dest_bi,
27 int last_first, int item_num, int from, int copy_count) 26 struct buffer_head *source, int last_first,
27 int item_num, int from, int copy_count)
28{ 28{
29 struct buffer_head * dest = dest_bi->bi_bh; 29 struct buffer_head *dest = dest_bi->bi_bh;
30 int item_num_in_dest; /* either the number of target item, 30 int item_num_in_dest; /* either the number of target item,
31 or if we must create a new item, 31 or if we must create a new item,
32 the number of the item we will 32 the number of the item we will
33 create it next to */ 33 create it next to */
34 struct item_head * ih; 34 struct item_head *ih;
35 struct reiserfs_de_head * deh; 35 struct reiserfs_de_head *deh;
36 int copy_records_len; /* length of all records in item to be copied */ 36 int copy_records_len; /* length of all records in item to be copied */
37 char * records; 37 char *records;
38 38
39 ih = B_N_PITEM_HEAD (source, item_num); 39 ih = B_N_PITEM_HEAD(source, item_num);
40 40
41 RFALSE( !is_direntry_le_ih (ih), "vs-10000: item must be directory item"); 41 RFALSE(!is_direntry_le_ih(ih), "vs-10000: item must be directory item");
42 42
43 /* length of all record to be copied and first byte of the last of them */ 43 /* length of all record to be copied and first byte of the last of them */
44 deh = B_I_DEH (source, ih); 44 deh = B_I_DEH(source, ih);
45 if (copy_count) { 45 if (copy_count) {
46 copy_records_len = (from ? deh_location( &(deh[from - 1]) ) : 46 copy_records_len = (from ? deh_location(&(deh[from - 1])) :
47 ih_item_len(ih)) - deh_location( &(deh[from + copy_count - 1])); 47 ih_item_len(ih)) -
48 records = source->b_data + ih_location(ih) + 48 deh_location(&(deh[from + copy_count - 1]));
49 deh_location( &(deh[from + copy_count - 1])); 49 records =
50 } else { 50 source->b_data + ih_location(ih) +
51 copy_records_len = 0; 51 deh_location(&(deh[from + copy_count - 1]));
52 records = NULL; 52 } else {
53 } 53 copy_records_len = 0;
54 54 records = NULL;
55 /* when copy last to first, dest buffer can contain 0 items */ 55 }
56 item_num_in_dest = (last_first == LAST_TO_FIRST) ? (( B_NR_ITEMS(dest) ) ? 0 : -1) : (B_NR_ITEMS(dest) - 1); 56
57 57 /* when copy last to first, dest buffer can contain 0 items */
58 /* if there are no items in dest or the first/last item in dest is not item of the same directory */ 58 item_num_in_dest =
59 if ( (item_num_in_dest == - 1) || 59 (last_first ==
60 (last_first == FIRST_TO_LAST && le_ih_k_offset (ih) == DOT_OFFSET) || 60 LAST_TO_FIRST) ? ((B_NR_ITEMS(dest)) ? 0 : -1) : (B_NR_ITEMS(dest)
61 (last_first == LAST_TO_FIRST && comp_short_le_keys/*COMP_SHORT_KEYS*/ (&ih->ih_key, B_N_PKEY (dest, item_num_in_dest)))) { 61 - 1);
62 /* create new item in dest */ 62
63 struct item_head new_ih; 63 /* if there are no items in dest or the first/last item in dest is not item of the same directory */
64 64 if ((item_num_in_dest == -1) ||
65 /* form item header */ 65 (last_first == FIRST_TO_LAST && le_ih_k_offset(ih) == DOT_OFFSET) ||
66 memcpy (&new_ih.ih_key, &ih->ih_key, KEY_SIZE); 66 (last_first == LAST_TO_FIRST
67 put_ih_version( &new_ih, KEY_FORMAT_3_5 ); 67 && comp_short_le_keys /*COMP_SHORT_KEYS */ (&ih->ih_key,
68 /* calculate item len */ 68 B_N_PKEY(dest,
69 put_ih_item_len( &new_ih, DEH_SIZE * copy_count + copy_records_len ); 69 item_num_in_dest))))
70 put_ih_entry_count( &new_ih, 0 ); 70 {
71 71 /* create new item in dest */
72 if (last_first == LAST_TO_FIRST) { 72 struct item_head new_ih;
73 /* form key by the following way */ 73
74 if (from < I_ENTRY_COUNT(ih)) { 74 /* form item header */
75 set_le_ih_k_offset( &new_ih, deh_offset( &(deh[from]) ) ); 75 memcpy(&new_ih.ih_key, &ih->ih_key, KEY_SIZE);
76 /*memcpy (&new_ih.ih_key.k_offset, &deh[from].deh_offset, SHORT_KEY_SIZE);*/ 76 put_ih_version(&new_ih, KEY_FORMAT_3_5);
77 } else { 77 /* calculate item len */
78 /* no entries will be copied to this item in this function */ 78 put_ih_item_len(&new_ih,
79 set_le_ih_k_offset (&new_ih, U32_MAX); 79 DEH_SIZE * copy_count + copy_records_len);
80 /* this item is not yet valid, but we want I_IS_DIRECTORY_ITEM to return 1 for it, so we -1 */ 80 put_ih_entry_count(&new_ih, 0);
81 } 81
82 set_le_key_k_type (KEY_FORMAT_3_5, &(new_ih.ih_key), TYPE_DIRENTRY); 82 if (last_first == LAST_TO_FIRST) {
83 /* form key by the following way */
84 if (from < I_ENTRY_COUNT(ih)) {
85 set_le_ih_k_offset(&new_ih,
86 deh_offset(&(deh[from])));
87 /*memcpy (&new_ih.ih_key.k_offset, &deh[from].deh_offset, SHORT_KEY_SIZE); */
88 } else {
89 /* no entries will be copied to this item in this function */
90 set_le_ih_k_offset(&new_ih, U32_MAX);
91 /* this item is not yet valid, but we want I_IS_DIRECTORY_ITEM to return 1 for it, so we -1 */
92 }
93 set_le_key_k_type(KEY_FORMAT_3_5, &(new_ih.ih_key),
94 TYPE_DIRENTRY);
95 }
96
97 /* insert item into dest buffer */
98 leaf_insert_into_buf(dest_bi,
99 (last_first ==
100 LAST_TO_FIRST) ? 0 : B_NR_ITEMS(dest),
101 &new_ih, NULL, 0);
102 } else {
103 /* prepare space for entries */
104 leaf_paste_in_buffer(dest_bi,
105 (last_first ==
106 FIRST_TO_LAST) ? (B_NR_ITEMS(dest) -
107 1) : 0, MAX_US_INT,
108 DEH_SIZE * copy_count + copy_records_len,
109 records, 0);
83 } 110 }
84
85 /* insert item into dest buffer */
86 leaf_insert_into_buf (dest_bi, (last_first == LAST_TO_FIRST) ? 0 : B_NR_ITEMS(dest), &new_ih, NULL, 0);
87 } else {
88 /* prepare space for entries */
89 leaf_paste_in_buffer (dest_bi, (last_first==FIRST_TO_LAST) ? (B_NR_ITEMS(dest) - 1) : 0, MAX_US_INT,
90 DEH_SIZE * copy_count + copy_records_len, records, 0
91 );
92 }
93
94 item_num_in_dest = (last_first == FIRST_TO_LAST) ? (B_NR_ITEMS(dest)-1) : 0;
95
96 leaf_paste_entries (dest_bi->bi_bh, item_num_in_dest,
97 (last_first == FIRST_TO_LAST) ? I_ENTRY_COUNT(B_N_PITEM_HEAD (dest, item_num_in_dest)) : 0,
98 copy_count, deh + from, records,
99 DEH_SIZE * copy_count + copy_records_len
100 );
101}
102 111
112 item_num_in_dest =
113 (last_first == FIRST_TO_LAST) ? (B_NR_ITEMS(dest) - 1) : 0;
114
115 leaf_paste_entries(dest_bi->bi_bh, item_num_in_dest,
116 (last_first ==
117 FIRST_TO_LAST) ? I_ENTRY_COUNT(B_N_PITEM_HEAD(dest,
118 item_num_in_dest))
119 : 0, copy_count, deh + from, records,
120 DEH_SIZE * copy_count + copy_records_len);
121}
103 122
104/* Copy the first (if last_first == FIRST_TO_LAST) or last (last_first == LAST_TO_FIRST) item or 123/* Copy the first (if last_first == FIRST_TO_LAST) or last (last_first == LAST_TO_FIRST) item or
105 part of it or nothing (see the return 0 below) from SOURCE to the end 124 part of it or nothing (see the return 0 below) from SOURCE to the end
106 (if last_first) or beginning (!last_first) of the DEST */ 125 (if last_first) or beginning (!last_first) of the DEST */
107/* returns 1 if anything was copied, else 0 */ 126/* returns 1 if anything was copied, else 0 */
108static int leaf_copy_boundary_item (struct buffer_info * dest_bi, struct buffer_head * src, int last_first, 127static int leaf_copy_boundary_item(struct buffer_info *dest_bi,
109 int bytes_or_entries) 128 struct buffer_head *src, int last_first,
129 int bytes_or_entries)
110{ 130{
111 struct buffer_head * dest = dest_bi->bi_bh; 131 struct buffer_head *dest = dest_bi->bi_bh;
112 int dest_nr_item, src_nr_item; /* number of items in the source and destination buffers */ 132 int dest_nr_item, src_nr_item; /* number of items in the source and destination buffers */
113 struct item_head * ih; 133 struct item_head *ih;
114 struct item_head * dih; 134 struct item_head *dih;
115 135
116 dest_nr_item = B_NR_ITEMS(dest); 136 dest_nr_item = B_NR_ITEMS(dest);
117 137
118 if ( last_first == FIRST_TO_LAST ) { 138 if (last_first == FIRST_TO_LAST) {
119 /* if ( DEST is empty or first item of SOURCE and last item of DEST are the items of different objects 139 /* if ( DEST is empty or first item of SOURCE and last item of DEST are the items of different objects
120 or of different types ) then there is no need to treat this item differently from the other items 140 or of different types ) then there is no need to treat this item differently from the other items
121 that we copy, so we return */ 141 that we copy, so we return */
122 ih = B_N_PITEM_HEAD (src, 0); 142 ih = B_N_PITEM_HEAD(src, 0);
123 dih = B_N_PITEM_HEAD (dest, dest_nr_item - 1); 143 dih = B_N_PITEM_HEAD(dest, dest_nr_item - 1);
124 if (!dest_nr_item || (!op_is_left_mergeable (&(ih->ih_key), src->b_size))) 144 if (!dest_nr_item
125 /* there is nothing to merge */ 145 || (!op_is_left_mergeable(&(ih->ih_key), src->b_size)))
126 return 0; 146 /* there is nothing to merge */
127 147 return 0;
128 RFALSE( ! ih_item_len(ih), "vs-10010: item can not have empty length"); 148
129 149 RFALSE(!ih_item_len(ih),
130 if ( is_direntry_le_ih (ih) ) { 150 "vs-10010: item can not have empty length");
131 if ( bytes_or_entries == -1 ) 151
132 /* copy all entries to dest */ 152 if (is_direntry_le_ih(ih)) {
133 bytes_or_entries = ih_entry_count(ih); 153 if (bytes_or_entries == -1)
134 leaf_copy_dir_entries (dest_bi, src, FIRST_TO_LAST, 0, 0, bytes_or_entries); 154 /* copy all entries to dest */
135 return 1; 155 bytes_or_entries = ih_entry_count(ih);
136 } 156 leaf_copy_dir_entries(dest_bi, src, FIRST_TO_LAST, 0, 0,
137 157 bytes_or_entries);
138 /* copy part of the body of the first item of SOURCE to the end of the body of the last item of the DEST 158 return 1;
139 part defined by 'bytes_or_entries'; if bytes_or_entries == -1 copy whole body; don't create new item header 159 }
140 */ 160
141 if ( bytes_or_entries == -1 ) 161 /* copy part of the body of the first item of SOURCE to the end of the body of the last item of the DEST
142 bytes_or_entries = ih_item_len(ih); 162 part defined by 'bytes_or_entries'; if bytes_or_entries == -1 copy whole body; don't create new item header
163 */
164 if (bytes_or_entries == -1)
165 bytes_or_entries = ih_item_len(ih);
143 166
144#ifdef CONFIG_REISERFS_CHECK 167#ifdef CONFIG_REISERFS_CHECK
145 else { 168 else {
146 if (bytes_or_entries == ih_item_len(ih) && is_indirect_le_ih(ih)) 169 if (bytes_or_entries == ih_item_len(ih)
147 if (get_ih_free_space (ih)) 170 && is_indirect_le_ih(ih))
148 reiserfs_panic (NULL, "vs-10020: leaf_copy_boundary_item: " 171 if (get_ih_free_space(ih))
149 "last unformatted node must be filled entirely (%h)", 172 reiserfs_panic(NULL,
150 ih); 173 "vs-10020: leaf_copy_boundary_item: "
151 } 174 "last unformatted node must be filled entirely (%h)",
175 ih);
176 }
152#endif 177#endif
153
154 /* merge first item (or its part) of src buffer with the last
155 item of dest buffer. Both are of the same file */
156 leaf_paste_in_buffer (dest_bi,
157 dest_nr_item - 1, ih_item_len(dih), bytes_or_entries, B_I_PITEM(src,ih), 0
158 );
159
160 if (is_indirect_le_ih (dih)) {
161 RFALSE( get_ih_free_space (dih),
162 "vs-10030: merge to left: last unformatted node of non-last indirect item %h must have zerto free space",
163 ih);
164 if (bytes_or_entries == ih_item_len(ih))
165 set_ih_free_space (dih, get_ih_free_space (ih));
166 }
167
168 return 1;
169 }
170
171
172 /* copy boundary item to right (last_first == LAST_TO_FIRST) */
173
174 /* ( DEST is empty or last item of SOURCE and first item of DEST
175 are the items of different object or of different types )
176 */
177 src_nr_item = B_NR_ITEMS (src);
178 ih = B_N_PITEM_HEAD (src, src_nr_item - 1);
179 dih = B_N_PITEM_HEAD (dest, 0);
180
181 if (!dest_nr_item || !op_is_left_mergeable (&(dih->ih_key), src->b_size))
182 return 0;
183
184 if ( is_direntry_le_ih (ih)) {
185 if ( bytes_or_entries == -1 )
186 /* bytes_or_entries = entries number in last item body of SOURCE */
187 bytes_or_entries = ih_entry_count(ih);
188
189 leaf_copy_dir_entries (dest_bi, src, LAST_TO_FIRST, src_nr_item - 1, ih_entry_count(ih) - bytes_or_entries, bytes_or_entries);
190 return 1;
191 }
192
193 /* copy part of the body of the last item of SOURCE to the begin of the body of the first item of the DEST;
194 part defined by 'bytes_or_entries'; if byte_or_entriess == -1 copy whole body; change first item key of the DEST;
195 don't create new item header
196 */
197
198 RFALSE( is_indirect_le_ih(ih) && get_ih_free_space (ih),
199 "vs-10040: merge to right: last unformatted node of non-last indirect item must be filled entirely (%h)",
200 ih);
201
202 if ( bytes_or_entries == -1 ) {
203 /* bytes_or_entries = length of last item body of SOURCE */
204 bytes_or_entries = ih_item_len(ih);
205
206 RFALSE( le_ih_k_offset (dih) !=
207 le_ih_k_offset (ih) + op_bytes_number (ih, src->b_size),
208 "vs-10050: items %h and %h do not match", ih, dih);
209
210 /* change first item key of the DEST */
211 set_le_ih_k_offset (dih, le_ih_k_offset (ih));
212
213 /* item becomes non-mergeable */
214 /* or mergeable if left item was */
215 set_le_ih_k_type (dih, le_ih_k_type (ih));
216 } else {
217 /* merge to right only part of item */
218 RFALSE( ih_item_len(ih) <= bytes_or_entries,
219 "vs-10060: no so much bytes %lu (needed %lu)",
220 ( unsigned long )ih_item_len(ih), ( unsigned long )bytes_or_entries);
221
222 /* change first item key of the DEST */
223 if ( is_direct_le_ih (dih) ) {
224 RFALSE( le_ih_k_offset (dih) <= (unsigned long)bytes_or_entries,
225 "vs-10070: dih %h, bytes_or_entries(%d)", dih, bytes_or_entries);
226 set_le_ih_k_offset (dih, le_ih_k_offset (dih) - bytes_or_entries);
227 } else {
228 RFALSE( le_ih_k_offset (dih) <=
229 (bytes_or_entries / UNFM_P_SIZE) * dest->b_size,
230 "vs-10080: dih %h, bytes_or_entries(%d)",
231 dih, (bytes_or_entries/UNFM_P_SIZE)*dest->b_size);
232 set_le_ih_k_offset (dih, le_ih_k_offset (dih) - ((bytes_or_entries / UNFM_P_SIZE) * dest->b_size));
233 }
234 }
235
236 leaf_paste_in_buffer (dest_bi, 0, 0, bytes_or_entries, B_I_PITEM(src,ih) + ih_item_len(ih) - bytes_or_entries, 0);
237 return 1;
238}
239 178
179 /* merge first item (or its part) of src buffer with the last
180 item of dest buffer. Both are of the same file */
181 leaf_paste_in_buffer(dest_bi,
182 dest_nr_item - 1, ih_item_len(dih),
183 bytes_or_entries, B_I_PITEM(src, ih), 0);
184
185 if (is_indirect_le_ih(dih)) {
186 RFALSE(get_ih_free_space(dih),
187 "vs-10030: merge to left: last unformatted node of non-last indirect item %h must have zerto free space",
188 ih);
189 if (bytes_or_entries == ih_item_len(ih))
190 set_ih_free_space(dih, get_ih_free_space(ih));
191 }
192
193 return 1;
194 }
195
196 /* copy boundary item to right (last_first == LAST_TO_FIRST) */
197
198 /* ( DEST is empty or last item of SOURCE and first item of DEST
199 are the items of different object or of different types )
200 */
201 src_nr_item = B_NR_ITEMS(src);
202 ih = B_N_PITEM_HEAD(src, src_nr_item - 1);
203 dih = B_N_PITEM_HEAD(dest, 0);
204
205 if (!dest_nr_item || !op_is_left_mergeable(&(dih->ih_key), src->b_size))
206 return 0;
207
208 if (is_direntry_le_ih(ih)) {
209 if (bytes_or_entries == -1)
210 /* bytes_or_entries = entries number in last item body of SOURCE */
211 bytes_or_entries = ih_entry_count(ih);
212
213 leaf_copy_dir_entries(dest_bi, src, LAST_TO_FIRST,
214 src_nr_item - 1,
215 ih_entry_count(ih) - bytes_or_entries,
216 bytes_or_entries);
217 return 1;
218 }
219
220 /* copy part of the body of the last item of SOURCE to the begin of the body of the first item of the DEST;
221 part defined by 'bytes_or_entries'; if byte_or_entriess == -1 copy whole body; change first item key of the DEST;
222 don't create new item header
223 */
224
225 RFALSE(is_indirect_le_ih(ih) && get_ih_free_space(ih),
226 "vs-10040: merge to right: last unformatted node of non-last indirect item must be filled entirely (%h)",
227 ih);
228
229 if (bytes_or_entries == -1) {
230 /* bytes_or_entries = length of last item body of SOURCE */
231 bytes_or_entries = ih_item_len(ih);
232
233 RFALSE(le_ih_k_offset(dih) !=
234 le_ih_k_offset(ih) + op_bytes_number(ih, src->b_size),
235 "vs-10050: items %h and %h do not match", ih, dih);
236
237 /* change first item key of the DEST */
238 set_le_ih_k_offset(dih, le_ih_k_offset(ih));
239
240 /* item becomes non-mergeable */
241 /* or mergeable if left item was */
242 set_le_ih_k_type(dih, le_ih_k_type(ih));
243 } else {
244 /* merge to right only part of item */
245 RFALSE(ih_item_len(ih) <= bytes_or_entries,
246 "vs-10060: no so much bytes %lu (needed %lu)",
247 (unsigned long)ih_item_len(ih),
248 (unsigned long)bytes_or_entries);
249
250 /* change first item key of the DEST */
251 if (is_direct_le_ih(dih)) {
252 RFALSE(le_ih_k_offset(dih) <=
253 (unsigned long)bytes_or_entries,
254 "vs-10070: dih %h, bytes_or_entries(%d)", dih,
255 bytes_or_entries);
256 set_le_ih_k_offset(dih,
257 le_ih_k_offset(dih) -
258 bytes_or_entries);
259 } else {
260 RFALSE(le_ih_k_offset(dih) <=
261 (bytes_or_entries / UNFM_P_SIZE) * dest->b_size,
262 "vs-10080: dih %h, bytes_or_entries(%d)",
263 dih,
264 (bytes_or_entries / UNFM_P_SIZE) * dest->b_size);
265 set_le_ih_k_offset(dih,
266 le_ih_k_offset(dih) -
267 ((bytes_or_entries / UNFM_P_SIZE) *
268 dest->b_size));
269 }
270 }
271
272 leaf_paste_in_buffer(dest_bi, 0, 0, bytes_or_entries,
273 B_I_PITEM(src,
274 ih) + ih_item_len(ih) - bytes_or_entries,
275 0);
276 return 1;
277}
240 278
241/* copy cpy_mun items from buffer src to buffer dest 279/* copy cpy_mun items from buffer src to buffer dest
242 * last_first == FIRST_TO_LAST means, that we copy cpy_num items beginning from first-th item in src to tail of dest 280 * last_first == FIRST_TO_LAST means, that we copy cpy_num items beginning from first-th item in src to tail of dest
243 * last_first == LAST_TO_FIRST means, that we copy cpy_num items beginning from first-th item in src to head of dest 281 * last_first == LAST_TO_FIRST means, that we copy cpy_num items beginning from first-th item in src to head of dest
244 */ 282 */
245static void leaf_copy_items_entirely (struct buffer_info * dest_bi, struct buffer_head * src, int last_first, 283static void leaf_copy_items_entirely(struct buffer_info *dest_bi,
246 int first, int cpy_num) 284 struct buffer_head *src, int last_first,
285 int first, int cpy_num)
247{ 286{
248 struct buffer_head * dest; 287 struct buffer_head *dest;
249 int nr, free_space; 288 int nr, free_space;
250 int dest_before; 289 int dest_before;
251 int last_loc, last_inserted_loc, location; 290 int last_loc, last_inserted_loc, location;
252 int i, j; 291 int i, j;
253 struct block_head * blkh; 292 struct block_head *blkh;
254 struct item_head * ih; 293 struct item_head *ih;
255 294
256 RFALSE( last_first != LAST_TO_FIRST && last_first != FIRST_TO_LAST, 295 RFALSE(last_first != LAST_TO_FIRST && last_first != FIRST_TO_LAST,
257 "vs-10090: bad last_first parameter %d", last_first); 296 "vs-10090: bad last_first parameter %d", last_first);
258 RFALSE( B_NR_ITEMS (src) - first < cpy_num, 297 RFALSE(B_NR_ITEMS(src) - first < cpy_num,
259 "vs-10100: too few items in source %d, required %d from %d", 298 "vs-10100: too few items in source %d, required %d from %d",
260 B_NR_ITEMS(src), cpy_num, first); 299 B_NR_ITEMS(src), cpy_num, first);
261 RFALSE( cpy_num < 0, "vs-10110: can not copy negative amount of items"); 300 RFALSE(cpy_num < 0, "vs-10110: can not copy negative amount of items");
262 RFALSE( ! dest_bi, "vs-10120: can not copy negative amount of items"); 301 RFALSE(!dest_bi, "vs-10120: can not copy negative amount of items");
263 302
264 dest = dest_bi->bi_bh; 303 dest = dest_bi->bi_bh;
265 304
266 RFALSE( ! dest, "vs-10130: can not copy negative amount of items"); 305 RFALSE(!dest, "vs-10130: can not copy negative amount of items");
267 306
268 if (cpy_num == 0) 307 if (cpy_num == 0)
269 return; 308 return;
270 309
271 blkh = B_BLK_HEAD(dest); 310 blkh = B_BLK_HEAD(dest);
272 nr = blkh_nr_item( blkh ); 311 nr = blkh_nr_item(blkh);
273 free_space = blkh_free_space(blkh); 312 free_space = blkh_free_space(blkh);
274 313
275 /* we will insert items before 0-th or nr-th item in dest buffer. It depends of last_first parameter */ 314 /* we will insert items before 0-th or nr-th item in dest buffer. It depends of last_first parameter */
276 dest_before = (last_first == LAST_TO_FIRST) ? 0 : nr; 315 dest_before = (last_first == LAST_TO_FIRST) ? 0 : nr;
277 316
278 /* location of head of first new item */ 317 /* location of head of first new item */
279 ih = B_N_PITEM_HEAD (dest, dest_before); 318 ih = B_N_PITEM_HEAD(dest, dest_before);
280 319
281 RFALSE( blkh_free_space(blkh) < cpy_num * IH_SIZE, 320 RFALSE(blkh_free_space(blkh) < cpy_num * IH_SIZE,
282 "vs-10140: not enough free space for headers %d (needed %d)", 321 "vs-10140: not enough free space for headers %d (needed %d)",
283 B_FREE_SPACE (dest), cpy_num * IH_SIZE); 322 B_FREE_SPACE(dest), cpy_num * IH_SIZE);
284 323
285 /* prepare space for headers */ 324 /* prepare space for headers */
286 memmove (ih + cpy_num, ih, (nr-dest_before) * IH_SIZE); 325 memmove(ih + cpy_num, ih, (nr - dest_before) * IH_SIZE);
287
288 /* copy item headers */
289 memcpy (ih, B_N_PITEM_HEAD (src, first), cpy_num * IH_SIZE);
290
291 free_space -= (IH_SIZE * cpy_num);
292 set_blkh_free_space( blkh, free_space );
293
294 /* location of unmovable item */
295 j = location = (dest_before == 0) ? dest->b_size : ih_location(ih-1);
296 for (i = dest_before; i < nr + cpy_num; i ++) {
297 location -= ih_item_len( ih + i - dest_before );
298 put_ih_location( ih + i - dest_before, location );
299 }
300
301 /* prepare space for items */
302 last_loc = ih_location( &(ih[nr+cpy_num-1-dest_before]) );
303 last_inserted_loc = ih_location( &(ih[cpy_num-1]) );
304
305 /* check free space */
306 RFALSE( free_space < j - last_inserted_loc,
307 "vs-10150: not enough free space for items %d (needed %d)",
308 free_space, j - last_inserted_loc);
309
310 memmove (dest->b_data + last_loc,
311 dest->b_data + last_loc + j - last_inserted_loc,
312 last_inserted_loc - last_loc);
313
314 /* copy items */
315 memcpy (dest->b_data + last_inserted_loc, B_N_PITEM(src,(first + cpy_num - 1)),
316 j - last_inserted_loc);
317
318 /* sizes, item number */
319 set_blkh_nr_item( blkh, nr + cpy_num );
320 set_blkh_free_space( blkh, free_space - (j - last_inserted_loc) );
321
322 do_balance_mark_leaf_dirty (dest_bi->tb, dest, 0);
323
324 if (dest_bi->bi_parent) {
325 struct disk_child *t_dc;
326 t_dc = B_N_CHILD (dest_bi->bi_parent, dest_bi->bi_position);
327 RFALSE( dc_block_number(t_dc) != dest->b_blocknr,
328 "vs-10160: block number in bh does not match to field in disk_child structure %lu and %lu",
329 ( long unsigned ) dest->b_blocknr,
330 ( long unsigned ) dc_block_number(t_dc));
331 put_dc_size( t_dc, dc_size(t_dc) + (j - last_inserted_loc + IH_SIZE * cpy_num ) );
332
333 do_balance_mark_internal_dirty (dest_bi->tb, dest_bi->bi_parent, 0);
334 }
335}
336 326
327 /* copy item headers */
328 memcpy(ih, B_N_PITEM_HEAD(src, first), cpy_num * IH_SIZE);
329
330 free_space -= (IH_SIZE * cpy_num);
331 set_blkh_free_space(blkh, free_space);
332
333 /* location of unmovable item */
334 j = location = (dest_before == 0) ? dest->b_size : ih_location(ih - 1);
335 for (i = dest_before; i < nr + cpy_num; i++) {
336 location -= ih_item_len(ih + i - dest_before);
337 put_ih_location(ih + i - dest_before, location);
338 }
339
340 /* prepare space for items */
341 last_loc = ih_location(&(ih[nr + cpy_num - 1 - dest_before]));
342 last_inserted_loc = ih_location(&(ih[cpy_num - 1]));
343
344 /* check free space */
345 RFALSE(free_space < j - last_inserted_loc,
346 "vs-10150: not enough free space for items %d (needed %d)",
347 free_space, j - last_inserted_loc);
348
349 memmove(dest->b_data + last_loc,
350 dest->b_data + last_loc + j - last_inserted_loc,
351 last_inserted_loc - last_loc);
352
353 /* copy items */
354 memcpy(dest->b_data + last_inserted_loc,
355 B_N_PITEM(src, (first + cpy_num - 1)), j - last_inserted_loc);
356
357 /* sizes, item number */
358 set_blkh_nr_item(blkh, nr + cpy_num);
359 set_blkh_free_space(blkh, free_space - (j - last_inserted_loc));
360
361 do_balance_mark_leaf_dirty(dest_bi->tb, dest, 0);
362
363 if (dest_bi->bi_parent) {
364 struct disk_child *t_dc;
365 t_dc = B_N_CHILD(dest_bi->bi_parent, dest_bi->bi_position);
366 RFALSE(dc_block_number(t_dc) != dest->b_blocknr,
367 "vs-10160: block number in bh does not match to field in disk_child structure %lu and %lu",
368 (long unsigned)dest->b_blocknr,
369 (long unsigned)dc_block_number(t_dc));
370 put_dc_size(t_dc,
371 dc_size(t_dc) + (j - last_inserted_loc +
372 IH_SIZE * cpy_num));
373
374 do_balance_mark_internal_dirty(dest_bi->tb, dest_bi->bi_parent,
375 0);
376 }
377}
337 378
338/* This function splits the (liquid) item into two items (useful when 379/* This function splits the (liquid) item into two items (useful when
339 shifting part of an item into another node.) */ 380 shifting part of an item into another node.) */
340static void leaf_item_bottle (struct buffer_info * dest_bi, struct buffer_head * src, int last_first, 381static void leaf_item_bottle(struct buffer_info *dest_bi,
341 int item_num, int cpy_bytes) 382 struct buffer_head *src, int last_first,
383 int item_num, int cpy_bytes)
342{ 384{
343 struct buffer_head * dest = dest_bi->bi_bh; 385 struct buffer_head *dest = dest_bi->bi_bh;
344 struct item_head * ih; 386 struct item_head *ih;
345 387
346 RFALSE( cpy_bytes == -1, "vs-10170: bytes == - 1 means: do not split item"); 388 RFALSE(cpy_bytes == -1,
347 389 "vs-10170: bytes == - 1 means: do not split item");
348 if ( last_first == FIRST_TO_LAST ) { 390
349 /* if ( if item in position item_num in buffer SOURCE is directory item ) */ 391 if (last_first == FIRST_TO_LAST) {
350 if (is_direntry_le_ih (ih = B_N_PITEM_HEAD(src,item_num))) 392 /* if ( if item in position item_num in buffer SOURCE is directory item ) */
351 leaf_copy_dir_entries (dest_bi, src, FIRST_TO_LAST, item_num, 0, cpy_bytes); 393 if (is_direntry_le_ih(ih = B_N_PITEM_HEAD(src, item_num)))
352 else { 394 leaf_copy_dir_entries(dest_bi, src, FIRST_TO_LAST,
353 struct item_head n_ih; 395 item_num, 0, cpy_bytes);
354 396 else {
355 /* copy part of the body of the item number 'item_num' of SOURCE to the end of the DEST 397 struct item_head n_ih;
356 part defined by 'cpy_bytes'; create new item header; change old item_header (????); 398
357 n_ih = new item_header; 399 /* copy part of the body of the item number 'item_num' of SOURCE to the end of the DEST
358 */ 400 part defined by 'cpy_bytes'; create new item header; change old item_header (????);
359 memcpy (&n_ih, ih, IH_SIZE); 401 n_ih = new item_header;
360 put_ih_item_len( &n_ih, cpy_bytes ); 402 */
361 if (is_indirect_le_ih (ih)) { 403 memcpy(&n_ih, ih, IH_SIZE);
362 RFALSE( cpy_bytes == ih_item_len(ih) && get_ih_free_space(ih), 404 put_ih_item_len(&n_ih, cpy_bytes);
363 "vs-10180: when whole indirect item is bottle to left neighbor, it must have free_space==0 (not %lu)", 405 if (is_indirect_le_ih(ih)) {
364 ( long unsigned ) get_ih_free_space (ih)); 406 RFALSE(cpy_bytes == ih_item_len(ih)
365 set_ih_free_space (&n_ih, 0); 407 && get_ih_free_space(ih),
366 } 408 "vs-10180: when whole indirect item is bottle to left neighbor, it must have free_space==0 (not %lu)",
367 409 (long unsigned)get_ih_free_space(ih));
368 RFALSE( op_is_left_mergeable (&(ih->ih_key), src->b_size), 410 set_ih_free_space(&n_ih, 0);
369 "vs-10190: bad mergeability of item %h", ih); 411 }
370 n_ih.ih_version = ih->ih_version; /* JDM Endian safe, both le */ 412
371 leaf_insert_into_buf (dest_bi, B_NR_ITEMS(dest), &n_ih, B_N_PITEM (src, item_num), 0); 413 RFALSE(op_is_left_mergeable(&(ih->ih_key), src->b_size),
414 "vs-10190: bad mergeability of item %h", ih);
415 n_ih.ih_version = ih->ih_version; /* JDM Endian safe, both le */
416 leaf_insert_into_buf(dest_bi, B_NR_ITEMS(dest), &n_ih,
417 B_N_PITEM(src, item_num), 0);
418 }
419 } else {
420 /* if ( if item in position item_num in buffer SOURCE is directory item ) */
421 if (is_direntry_le_ih(ih = B_N_PITEM_HEAD(src, item_num)))
422 leaf_copy_dir_entries(dest_bi, src, LAST_TO_FIRST,
423 item_num,
424 I_ENTRY_COUNT(ih) - cpy_bytes,
425 cpy_bytes);
426 else {
427 struct item_head n_ih;
428
429 /* copy part of the body of the item number 'item_num' of SOURCE to the begin of the DEST
430 part defined by 'cpy_bytes'; create new item header;
431 n_ih = new item_header;
432 */
433 memcpy(&n_ih, ih, SHORT_KEY_SIZE);
434
435 n_ih.ih_version = ih->ih_version; /* JDM Endian safe, both le */
436
437 if (is_direct_le_ih(ih)) {
438 set_le_ih_k_offset(&n_ih,
439 le_ih_k_offset(ih) +
440 ih_item_len(ih) - cpy_bytes);
441 set_le_ih_k_type(&n_ih, TYPE_DIRECT);
442 set_ih_free_space(&n_ih, MAX_US_INT);
443 } else {
444 /* indirect item */
445 RFALSE(!cpy_bytes && get_ih_free_space(ih),
446 "vs-10200: ih->ih_free_space must be 0 when indirect item will be appended");
447 set_le_ih_k_offset(&n_ih,
448 le_ih_k_offset(ih) +
449 (ih_item_len(ih) -
450 cpy_bytes) / UNFM_P_SIZE *
451 dest->b_size);
452 set_le_ih_k_type(&n_ih, TYPE_INDIRECT);
453 set_ih_free_space(&n_ih, get_ih_free_space(ih));
454 }
455
456 /* set item length */
457 put_ih_item_len(&n_ih, cpy_bytes);
458
459 n_ih.ih_version = ih->ih_version; /* JDM Endian safe, both le */
460
461 leaf_insert_into_buf(dest_bi, 0, &n_ih,
462 B_N_PITEM(src,
463 item_num) +
464 ih_item_len(ih) - cpy_bytes, 0);
465 }
372 } 466 }
373 } else {
374 /* if ( if item in position item_num in buffer SOURCE is directory item ) */
375 if (is_direntry_le_ih(ih = B_N_PITEM_HEAD (src, item_num)))
376 leaf_copy_dir_entries (dest_bi, src, LAST_TO_FIRST, item_num, I_ENTRY_COUNT(ih) - cpy_bytes, cpy_bytes);
377 else {
378 struct item_head n_ih;
379
380 /* copy part of the body of the item number 'item_num' of SOURCE to the begin of the DEST
381 part defined by 'cpy_bytes'; create new item header;
382 n_ih = new item_header;
383 */
384 memcpy (&n_ih, ih, SHORT_KEY_SIZE);
385
386 n_ih.ih_version = ih->ih_version; /* JDM Endian safe, both le */
387
388 if (is_direct_le_ih (ih)) {
389 set_le_ih_k_offset (&n_ih, le_ih_k_offset (ih) + ih_item_len(ih) - cpy_bytes);
390 set_le_ih_k_type (&n_ih, TYPE_DIRECT);
391 set_ih_free_space (&n_ih, MAX_US_INT);
392 } else {
393 /* indirect item */
394 RFALSE( !cpy_bytes && get_ih_free_space (ih),
395 "vs-10200: ih->ih_free_space must be 0 when indirect item will be appended");
396 set_le_ih_k_offset (&n_ih, le_ih_k_offset (ih) + (ih_item_len(ih) - cpy_bytes) / UNFM_P_SIZE * dest->b_size);
397 set_le_ih_k_type (&n_ih, TYPE_INDIRECT);
398 set_ih_free_space (&n_ih, get_ih_free_space (ih));
399 }
400
401 /* set item length */
402 put_ih_item_len( &n_ih, cpy_bytes );
403
404 n_ih.ih_version = ih->ih_version; /* JDM Endian safe, both le */
405
406 leaf_insert_into_buf (dest_bi, 0, &n_ih, B_N_PITEM(src,item_num) + ih_item_len(ih) - cpy_bytes, 0);
407 }
408 }
409} 467}
410 468
411
412/* If cpy_bytes equals minus one than copy cpy_num whole items from SOURCE to DEST. 469/* If cpy_bytes equals minus one than copy cpy_num whole items from SOURCE to DEST.
413 If cpy_bytes not equal to minus one than copy cpy_num-1 whole items from SOURCE to DEST. 470 If cpy_bytes not equal to minus one than copy cpy_num-1 whole items from SOURCE to DEST.
414 From last item copy cpy_num bytes for regular item and cpy_num directory entries for 471 From last item copy cpy_num bytes for regular item and cpy_num directory entries for
415 directory item. */ 472 directory item. */
416static int leaf_copy_items (struct buffer_info * dest_bi, struct buffer_head * src, int last_first, int cpy_num, 473static int leaf_copy_items(struct buffer_info *dest_bi, struct buffer_head *src,
417 int cpy_bytes) 474 int last_first, int cpy_num, int cpy_bytes)
418{ 475{
419 struct buffer_head * dest; 476 struct buffer_head *dest;
420 int pos, i, src_nr_item, bytes; 477 int pos, i, src_nr_item, bytes;
421 478
422 dest = dest_bi->bi_bh; 479 dest = dest_bi->bi_bh;
423 RFALSE( !dest || !src, "vs-10210: !dest || !src"); 480 RFALSE(!dest || !src, "vs-10210: !dest || !src");
424 RFALSE( last_first != FIRST_TO_LAST && last_first != LAST_TO_FIRST, 481 RFALSE(last_first != FIRST_TO_LAST && last_first != LAST_TO_FIRST,
425 "vs-10220:last_first != FIRST_TO_LAST && last_first != LAST_TO_FIRST"); 482 "vs-10220:last_first != FIRST_TO_LAST && last_first != LAST_TO_FIRST");
426 RFALSE( B_NR_ITEMS(src) < cpy_num, 483 RFALSE(B_NR_ITEMS(src) < cpy_num,
427 "vs-10230: No enough items: %d, req. %d", B_NR_ITEMS(src), cpy_num); 484 "vs-10230: No enough items: %d, req. %d", B_NR_ITEMS(src),
428 RFALSE( cpy_num < 0,"vs-10240: cpy_num < 0 (%d)", cpy_num); 485 cpy_num);
429 486 RFALSE(cpy_num < 0, "vs-10240: cpy_num < 0 (%d)", cpy_num);
430 if ( cpy_num == 0 ) 487
431 return 0; 488 if (cpy_num == 0)
432 489 return 0;
433 if ( last_first == FIRST_TO_LAST ) { 490
434 /* copy items to left */ 491 if (last_first == FIRST_TO_LAST) {
435 pos = 0; 492 /* copy items to left */
436 if ( cpy_num == 1 ) 493 pos = 0;
437 bytes = cpy_bytes; 494 if (cpy_num == 1)
438 else 495 bytes = cpy_bytes;
439 bytes = -1; 496 else
440 497 bytes = -1;
441 /* copy the first item or it part or nothing to the end of the DEST (i = leaf_copy_boundary_item(DEST,SOURCE,0,bytes)) */ 498
442 i = leaf_copy_boundary_item (dest_bi, src, FIRST_TO_LAST, bytes); 499 /* copy the first item or it part or nothing to the end of the DEST (i = leaf_copy_boundary_item(DEST,SOURCE,0,bytes)) */
443 cpy_num -= i; 500 i = leaf_copy_boundary_item(dest_bi, src, FIRST_TO_LAST, bytes);
444 if ( cpy_num == 0 ) 501 cpy_num -= i;
445 return i; 502 if (cpy_num == 0)
446 pos += i; 503 return i;
447 if ( cpy_bytes == -1 ) 504 pos += i;
448 /* copy first cpy_num items starting from position 'pos' of SOURCE to end of DEST */ 505 if (cpy_bytes == -1)
449 leaf_copy_items_entirely (dest_bi, src, FIRST_TO_LAST, pos, cpy_num); 506 /* copy first cpy_num items starting from position 'pos' of SOURCE to end of DEST */
450 else { 507 leaf_copy_items_entirely(dest_bi, src, FIRST_TO_LAST,
451 /* copy first cpy_num-1 items starting from position 'pos-1' of the SOURCE to the end of the DEST */ 508 pos, cpy_num);
452 leaf_copy_items_entirely (dest_bi, src, FIRST_TO_LAST, pos, cpy_num-1); 509 else {
453 510 /* copy first cpy_num-1 items starting from position 'pos-1' of the SOURCE to the end of the DEST */
454 /* copy part of the item which number is cpy_num+pos-1 to the end of the DEST */ 511 leaf_copy_items_entirely(dest_bi, src, FIRST_TO_LAST,
455 leaf_item_bottle (dest_bi, src, FIRST_TO_LAST, cpy_num+pos-1, cpy_bytes); 512 pos, cpy_num - 1);
456 } 513
457 } else { 514 /* copy part of the item which number is cpy_num+pos-1 to the end of the DEST */
458 /* copy items to right */ 515 leaf_item_bottle(dest_bi, src, FIRST_TO_LAST,
459 src_nr_item = B_NR_ITEMS (src); 516 cpy_num + pos - 1, cpy_bytes);
460 if ( cpy_num == 1 ) 517 }
461 bytes = cpy_bytes; 518 } else {
462 else 519 /* copy items to right */
463 bytes = -1; 520 src_nr_item = B_NR_ITEMS(src);
464 521 if (cpy_num == 1)
465 /* copy the last item or it part or nothing to the begin of the DEST (i = leaf_copy_boundary_item(DEST,SOURCE,1,bytes)); */ 522 bytes = cpy_bytes;
466 i = leaf_copy_boundary_item (dest_bi, src, LAST_TO_FIRST, bytes); 523 else
467 524 bytes = -1;
468 cpy_num -= i; 525
469 if ( cpy_num == 0 ) 526 /* copy the last item or it part or nothing to the begin of the DEST (i = leaf_copy_boundary_item(DEST,SOURCE,1,bytes)); */
470 return i; 527 i = leaf_copy_boundary_item(dest_bi, src, LAST_TO_FIRST, bytes);
471 528
472 pos = src_nr_item - cpy_num - i; 529 cpy_num -= i;
473 if ( cpy_bytes == -1 ) { 530 if (cpy_num == 0)
474 /* starting from position 'pos' copy last cpy_num items of SOURCE to begin of DEST */ 531 return i;
475 leaf_copy_items_entirely (dest_bi, src, LAST_TO_FIRST, pos, cpy_num); 532
476 } else { 533 pos = src_nr_item - cpy_num - i;
477 /* copy last cpy_num-1 items starting from position 'pos+1' of the SOURCE to the begin of the DEST; */ 534 if (cpy_bytes == -1) {
478 leaf_copy_items_entirely (dest_bi, src, LAST_TO_FIRST, pos+1, cpy_num-1); 535 /* starting from position 'pos' copy last cpy_num items of SOURCE to begin of DEST */
479 536 leaf_copy_items_entirely(dest_bi, src, LAST_TO_FIRST,
480 /* copy part of the item which number is pos to the begin of the DEST */ 537 pos, cpy_num);
481 leaf_item_bottle (dest_bi, src, LAST_TO_FIRST, pos, cpy_bytes); 538 } else {
482 } 539 /* copy last cpy_num-1 items starting from position 'pos+1' of the SOURCE to the begin of the DEST; */
483 } 540 leaf_copy_items_entirely(dest_bi, src, LAST_TO_FIRST,
484 return i; 541 pos + 1, cpy_num - 1);
542
543 /* copy part of the item which number is pos to the begin of the DEST */
544 leaf_item_bottle(dest_bi, src, LAST_TO_FIRST, pos,
545 cpy_bytes);
546 }
547 }
548 return i;
485} 549}
486 550
487
488/* there are types of coping: from S[0] to L[0], from S[0] to R[0], 551/* there are types of coping: from S[0] to L[0], from S[0] to R[0],
489 from R[0] to L[0]. for each of these we have to define parent and 552 from R[0] to L[0]. for each of these we have to define parent and
490 positions of destination and source buffers */ 553 positions of destination and source buffers */
491static void leaf_define_dest_src_infos (int shift_mode, struct tree_balance * tb, struct buffer_info * dest_bi, 554static void leaf_define_dest_src_infos(int shift_mode, struct tree_balance *tb,
492 struct buffer_info * src_bi, int * first_last, 555 struct buffer_info *dest_bi,
493 struct buffer_head * Snew) 556 struct buffer_info *src_bi,
557 int *first_last,
558 struct buffer_head *Snew)
494{ 559{
495 memset (dest_bi, 0, sizeof (struct buffer_info)); 560 memset(dest_bi, 0, sizeof(struct buffer_info));
496 memset (src_bi, 0, sizeof (struct buffer_info)); 561 memset(src_bi, 0, sizeof(struct buffer_info));
497 562
498 /* define dest, src, dest parent, dest position */ 563 /* define dest, src, dest parent, dest position */
499 switch (shift_mode) { 564 switch (shift_mode) {
500 case LEAF_FROM_S_TO_L: /* it is used in leaf_shift_left */ 565 case LEAF_FROM_S_TO_L: /* it is used in leaf_shift_left */
501 src_bi->tb = tb; 566 src_bi->tb = tb;
502 src_bi->bi_bh = PATH_PLAST_BUFFER (tb->tb_path); 567 src_bi->bi_bh = PATH_PLAST_BUFFER(tb->tb_path);
503 src_bi->bi_parent = PATH_H_PPARENT (tb->tb_path, 0); 568 src_bi->bi_parent = PATH_H_PPARENT(tb->tb_path, 0);
504 src_bi->bi_position = PATH_H_B_ITEM_ORDER (tb->tb_path, 0); /* src->b_item_order */ 569 src_bi->bi_position = PATH_H_B_ITEM_ORDER(tb->tb_path, 0); /* src->b_item_order */
505 dest_bi->tb = tb; 570 dest_bi->tb = tb;
506 dest_bi->bi_bh = tb->L[0]; 571 dest_bi->bi_bh = tb->L[0];
507 dest_bi->bi_parent = tb->FL[0]; 572 dest_bi->bi_parent = tb->FL[0];
508 dest_bi->bi_position = get_left_neighbor_position (tb, 0); 573 dest_bi->bi_position = get_left_neighbor_position(tb, 0);
509 *first_last = FIRST_TO_LAST; 574 *first_last = FIRST_TO_LAST;
510 break; 575 break;
511 576
512 case LEAF_FROM_S_TO_R: /* it is used in leaf_shift_right */ 577 case LEAF_FROM_S_TO_R: /* it is used in leaf_shift_right */
513 src_bi->tb = tb; 578 src_bi->tb = tb;
514 src_bi->bi_bh = PATH_PLAST_BUFFER (tb->tb_path); 579 src_bi->bi_bh = PATH_PLAST_BUFFER(tb->tb_path);
515 src_bi->bi_parent = PATH_H_PPARENT (tb->tb_path, 0); 580 src_bi->bi_parent = PATH_H_PPARENT(tb->tb_path, 0);
516 src_bi->bi_position = PATH_H_B_ITEM_ORDER (tb->tb_path, 0); 581 src_bi->bi_position = PATH_H_B_ITEM_ORDER(tb->tb_path, 0);
517 dest_bi->tb = tb; 582 dest_bi->tb = tb;
518 dest_bi->bi_bh = tb->R[0]; 583 dest_bi->bi_bh = tb->R[0];
519 dest_bi->bi_parent = tb->FR[0]; 584 dest_bi->bi_parent = tb->FR[0];
520 dest_bi->bi_position = get_right_neighbor_position (tb, 0); 585 dest_bi->bi_position = get_right_neighbor_position(tb, 0);
521 *first_last = LAST_TO_FIRST; 586 *first_last = LAST_TO_FIRST;
522 break; 587 break;
523 588
524 case LEAF_FROM_R_TO_L: /* it is used in balance_leaf_when_delete */ 589 case LEAF_FROM_R_TO_L: /* it is used in balance_leaf_when_delete */
525 src_bi->tb = tb; 590 src_bi->tb = tb;
526 src_bi->bi_bh = tb->R[0]; 591 src_bi->bi_bh = tb->R[0];
527 src_bi->bi_parent = tb->FR[0]; 592 src_bi->bi_parent = tb->FR[0];
528 src_bi->bi_position = get_right_neighbor_position (tb, 0); 593 src_bi->bi_position = get_right_neighbor_position(tb, 0);
529 dest_bi->tb = tb; 594 dest_bi->tb = tb;
530 dest_bi->bi_bh = tb->L[0]; 595 dest_bi->bi_bh = tb->L[0];
531 dest_bi->bi_parent = tb->FL[0]; 596 dest_bi->bi_parent = tb->FL[0];
532 dest_bi->bi_position = get_left_neighbor_position (tb, 0); 597 dest_bi->bi_position = get_left_neighbor_position(tb, 0);
533 *first_last = FIRST_TO_LAST; 598 *first_last = FIRST_TO_LAST;
534 break; 599 break;
535 600
536 case LEAF_FROM_L_TO_R: /* it is used in balance_leaf_when_delete */ 601 case LEAF_FROM_L_TO_R: /* it is used in balance_leaf_when_delete */
537 src_bi->tb = tb; 602 src_bi->tb = tb;
538 src_bi->bi_bh = tb->L[0]; 603 src_bi->bi_bh = tb->L[0];
539 src_bi->bi_parent = tb->FL[0]; 604 src_bi->bi_parent = tb->FL[0];
540 src_bi->bi_position = get_left_neighbor_position (tb, 0); 605 src_bi->bi_position = get_left_neighbor_position(tb, 0);
541 dest_bi->tb = tb; 606 dest_bi->tb = tb;
542 dest_bi->bi_bh = tb->R[0]; 607 dest_bi->bi_bh = tb->R[0];
543 dest_bi->bi_parent = tb->FR[0]; 608 dest_bi->bi_parent = tb->FR[0];
544 dest_bi->bi_position = get_right_neighbor_position (tb, 0); 609 dest_bi->bi_position = get_right_neighbor_position(tb, 0);
545 *first_last = LAST_TO_FIRST; 610 *first_last = LAST_TO_FIRST;
546 break; 611 break;
547 612
548 case LEAF_FROM_S_TO_SNEW: 613 case LEAF_FROM_S_TO_SNEW:
549 src_bi->tb = tb; 614 src_bi->tb = tb;
550 src_bi->bi_bh = PATH_PLAST_BUFFER (tb->tb_path); 615 src_bi->bi_bh = PATH_PLAST_BUFFER(tb->tb_path);
551 src_bi->bi_parent = PATH_H_PPARENT (tb->tb_path, 0); 616 src_bi->bi_parent = PATH_H_PPARENT(tb->tb_path, 0);
552 src_bi->bi_position = PATH_H_B_ITEM_ORDER (tb->tb_path, 0); 617 src_bi->bi_position = PATH_H_B_ITEM_ORDER(tb->tb_path, 0);
553 dest_bi->tb = tb; 618 dest_bi->tb = tb;
554 dest_bi->bi_bh = Snew; 619 dest_bi->bi_bh = Snew;
555 dest_bi->bi_parent = NULL; 620 dest_bi->bi_parent = NULL;
556 dest_bi->bi_position = 0; 621 dest_bi->bi_position = 0;
557 *first_last = LAST_TO_FIRST; 622 *first_last = LAST_TO_FIRST;
558 break; 623 break;
559 624
560 default: 625 default:
561 reiserfs_panic (NULL, "vs-10250: leaf_define_dest_src_infos: shift type is unknown (%d)", shift_mode); 626 reiserfs_panic(NULL,
562 } 627 "vs-10250: leaf_define_dest_src_infos: shift type is unknown (%d)",
563 RFALSE( src_bi->bi_bh == 0 || dest_bi->bi_bh == 0, 628 shift_mode);
564 "vs-10260: mode==%d, source (%p) or dest (%p) buffer is initialized incorrectly", 629 }
565 shift_mode, src_bi->bi_bh, dest_bi->bi_bh); 630 RFALSE(src_bi->bi_bh == 0 || dest_bi->bi_bh == 0,
631 "vs-10260: mode==%d, source (%p) or dest (%p) buffer is initialized incorrectly",
632 shift_mode, src_bi->bi_bh, dest_bi->bi_bh);
566} 633}
567 634
568
569
570
571/* copy mov_num items and mov_bytes of the (mov_num-1)th item to 635/* copy mov_num items and mov_bytes of the (mov_num-1)th item to
572 neighbor. Delete them from source */ 636 neighbor. Delete them from source */
573int leaf_move_items (int shift_mode, struct tree_balance * tb, int mov_num, int mov_bytes, struct buffer_head * Snew) 637int leaf_move_items(int shift_mode, struct tree_balance *tb, int mov_num,
638 int mov_bytes, struct buffer_head *Snew)
574{ 639{
575 int ret_value; 640 int ret_value;
576 struct buffer_info dest_bi, src_bi; 641 struct buffer_info dest_bi, src_bi;
577 int first_last; 642 int first_last;
578 643
579 leaf_define_dest_src_infos (shift_mode, tb, &dest_bi, &src_bi, &first_last, Snew); 644 leaf_define_dest_src_infos(shift_mode, tb, &dest_bi, &src_bi,
645 &first_last, Snew);
580 646
581 ret_value = leaf_copy_items (&dest_bi, src_bi.bi_bh, first_last, mov_num, mov_bytes); 647 ret_value =
648 leaf_copy_items(&dest_bi, src_bi.bi_bh, first_last, mov_num,
649 mov_bytes);
582 650
583 leaf_delete_items (&src_bi, first_last, (first_last == FIRST_TO_LAST) ? 0 : (B_NR_ITEMS(src_bi.bi_bh) - mov_num), mov_num, mov_bytes); 651 leaf_delete_items(&src_bi, first_last,
652 (first_last ==
653 FIRST_TO_LAST) ? 0 : (B_NR_ITEMS(src_bi.bi_bh) -
654 mov_num), mov_num, mov_bytes);
584 655
585 656 return ret_value;
586 return ret_value;
587} 657}
588 658
589
590/* Shift shift_num items (and shift_bytes of last shifted item if shift_bytes != -1) 659/* Shift shift_num items (and shift_bytes of last shifted item if shift_bytes != -1)
591 from S[0] to L[0] and replace the delimiting key */ 660 from S[0] to L[0] and replace the delimiting key */
592int leaf_shift_left (struct tree_balance * tb, int shift_num, int shift_bytes) 661int leaf_shift_left(struct tree_balance *tb, int shift_num, int shift_bytes)
593{ 662{
594 struct buffer_head * S0 = PATH_PLAST_BUFFER (tb->tb_path); 663 struct buffer_head *S0 = PATH_PLAST_BUFFER(tb->tb_path);
595 int i; 664 int i;
596 665
597 /* move shift_num (and shift_bytes bytes) items from S[0] to left neighbor L[0] */ 666 /* move shift_num (and shift_bytes bytes) items from S[0] to left neighbor L[0] */
598 i = leaf_move_items (LEAF_FROM_S_TO_L, tb, shift_num, shift_bytes, NULL); 667 i = leaf_move_items(LEAF_FROM_S_TO_L, tb, shift_num, shift_bytes, NULL);
599 668
600 if ( shift_num ) { 669 if (shift_num) {
601 if (B_NR_ITEMS (S0) == 0) { /* number of items in S[0] == 0 */ 670 if (B_NR_ITEMS(S0) == 0) { /* number of items in S[0] == 0 */
602 671
603 RFALSE( shift_bytes != -1, 672 RFALSE(shift_bytes != -1,
604 "vs-10270: S0 is empty now, but shift_bytes != -1 (%d)", 673 "vs-10270: S0 is empty now, but shift_bytes != -1 (%d)",
605 shift_bytes); 674 shift_bytes);
606#ifdef CONFIG_REISERFS_CHECK 675#ifdef CONFIG_REISERFS_CHECK
607 if (tb->tb_mode == M_PASTE || tb->tb_mode == M_INSERT) { 676 if (tb->tb_mode == M_PASTE || tb->tb_mode == M_INSERT) {
608 print_cur_tb ("vs-10275"); 677 print_cur_tb("vs-10275");
609 reiserfs_panic (tb->tb_sb, "vs-10275: leaf_shift_left: balance condition corrupted (%c)", tb->tb_mode); 678 reiserfs_panic(tb->tb_sb,
610 } 679 "vs-10275: leaf_shift_left: balance condition corrupted (%c)",
680 tb->tb_mode);
681 }
611#endif 682#endif
612 683
613 if (PATH_H_POSITION (tb->tb_path, 1) == 0) 684 if (PATH_H_POSITION(tb->tb_path, 1) == 0)
614 replace_key (tb, tb->CFL[0], tb->lkey[0], PATH_H_PPARENT (tb->tb_path, 0), 0); 685 replace_key(tb, tb->CFL[0], tb->lkey[0],
615 686 PATH_H_PPARENT(tb->tb_path, 0), 0);
616 } else { 687
617 /* replace lkey in CFL[0] by 0-th key from S[0]; */ 688 } else {
618 replace_key (tb, tb->CFL[0], tb->lkey[0], S0, 0); 689 /* replace lkey in CFL[0] by 0-th key from S[0]; */
619 690 replace_key(tb, tb->CFL[0], tb->lkey[0], S0, 0);
620 RFALSE( (shift_bytes != -1 && 691
621 !(is_direntry_le_ih (B_N_PITEM_HEAD (S0, 0)) 692 RFALSE((shift_bytes != -1 &&
622 && !I_ENTRY_COUNT (B_N_PITEM_HEAD (S0, 0)))) && 693 !(is_direntry_le_ih(B_N_PITEM_HEAD(S0, 0))
623 (!op_is_left_mergeable (B_N_PKEY (S0, 0), S0->b_size)), 694 && !I_ENTRY_COUNT(B_N_PITEM_HEAD(S0, 0)))) &&
624 "vs-10280: item must be mergeable"); 695 (!op_is_left_mergeable
625 } 696 (B_N_PKEY(S0, 0), S0->b_size)),
626 } 697 "vs-10280: item must be mergeable");
627 698 }
628 return i; 699 }
629}
630
631
632
633 700
701 return i;
702}
634 703
635/* CLEANING STOPPED HERE */ 704/* CLEANING STOPPED HERE */
636 705
637
638
639
640/* Shift shift_num (shift_bytes) items from S[0] to the right neighbor, and replace the delimiting key */ 706/* Shift shift_num (shift_bytes) items from S[0] to the right neighbor, and replace the delimiting key */
641int leaf_shift_right( 707int leaf_shift_right(struct tree_balance *tb, int shift_num, int shift_bytes)
642 struct tree_balance * tb,
643 int shift_num,
644 int shift_bytes
645 )
646{ 708{
647 // struct buffer_head * S0 = PATH_PLAST_BUFFER (tb->tb_path); 709 // struct buffer_head * S0 = PATH_PLAST_BUFFER (tb->tb_path);
648 int ret_value; 710 int ret_value;
649 711
650 /* move shift_num (and shift_bytes) items from S[0] to right neighbor R[0] */ 712 /* move shift_num (and shift_bytes) items from S[0] to right neighbor R[0] */
651 ret_value = leaf_move_items (LEAF_FROM_S_TO_R, tb, shift_num, shift_bytes, NULL); 713 ret_value =
714 leaf_move_items(LEAF_FROM_S_TO_R, tb, shift_num, shift_bytes, NULL);
652 715
653 /* replace rkey in CFR[0] by the 0-th key from R[0] */ 716 /* replace rkey in CFR[0] by the 0-th key from R[0] */
654 if (shift_num) { 717 if (shift_num) {
655 replace_key (tb, tb->CFR[0], tb->rkey[0], tb->R[0], 0); 718 replace_key(tb, tb->CFR[0], tb->rkey[0], tb->R[0], 0);
656 719
657 } 720 }
658 721
659 return ret_value; 722 return ret_value;
660} 723}
661 724
662 725static void leaf_delete_items_entirely(struct buffer_info *bi,
663 726 int first, int del_num);
664static void leaf_delete_items_entirely (struct buffer_info * bi,
665 int first, int del_num);
666/* If del_bytes == -1, starting from position 'first' delete del_num items in whole in buffer CUR. 727/* If del_bytes == -1, starting from position 'first' delete del_num items in whole in buffer CUR.
667 If not. 728 If not.
668 If last_first == 0. Starting from position 'first' delete del_num-1 items in whole. Delete part of body of 729 If last_first == 0. Starting from position 'first' delete del_num-1 items in whole. Delete part of body of
@@ -670,287 +731,292 @@ static void leaf_delete_items_entirely (struct buffer_info * bi,
670 If last_first == 1. Starting from position 'first+1' delete del_num-1 items in whole. Delete part of body of 731 If last_first == 1. Starting from position 'first+1' delete del_num-1 items in whole. Delete part of body of
671 the last item . Part defined by del_bytes. Don't delete last item header. 732 the last item . Part defined by del_bytes. Don't delete last item header.
672*/ 733*/
673void leaf_delete_items (struct buffer_info * cur_bi, int last_first, 734void leaf_delete_items(struct buffer_info *cur_bi, int last_first,
674 int first, int del_num, int del_bytes) 735 int first, int del_num, int del_bytes)
675{ 736{
676 struct buffer_head * bh; 737 struct buffer_head *bh;
677 int item_amount = B_NR_ITEMS (bh = cur_bi->bi_bh); 738 int item_amount = B_NR_ITEMS(bh = cur_bi->bi_bh);
678 739
679 RFALSE( !bh, "10155: bh is not defined"); 740 RFALSE(!bh, "10155: bh is not defined");
680 RFALSE( del_num < 0, "10160: del_num can not be < 0. del_num==%d", del_num); 741 RFALSE(del_num < 0, "10160: del_num can not be < 0. del_num==%d",
681 RFALSE( first < 0 || first + del_num > item_amount, 742 del_num);
682 "10165: invalid number of first item to be deleted (%d) or " 743 RFALSE(first < 0
683 "no so much items (%d) to delete (only %d)", 744 || first + del_num > item_amount,
684 first, first + del_num, item_amount); 745 "10165: invalid number of first item to be deleted (%d) or "
685 746 "no so much items (%d) to delete (only %d)", first,
686 if ( del_num == 0 ) 747 first + del_num, item_amount);
687 return; 748
688 749 if (del_num == 0)
689 if ( first == 0 && del_num == item_amount && del_bytes == -1 ) { 750 return;
690 make_empty_node (cur_bi); 751
691 do_balance_mark_leaf_dirty (cur_bi->tb, bh, 0); 752 if (first == 0 && del_num == item_amount && del_bytes == -1) {
692 return; 753 make_empty_node(cur_bi);
693 } 754 do_balance_mark_leaf_dirty(cur_bi->tb, bh, 0);
694 755 return;
695 if ( del_bytes == -1 )
696 /* delete del_num items beginning from item in position first */
697 leaf_delete_items_entirely (cur_bi, first, del_num);
698 else {
699 if ( last_first == FIRST_TO_LAST ) {
700 /* delete del_num-1 items beginning from item in position first */
701 leaf_delete_items_entirely (cur_bi, first, del_num-1);
702
703 /* delete the part of the first item of the bh
704 do not delete item header
705 */
706 leaf_cut_from_buffer (cur_bi, 0, 0, del_bytes);
707 } else {
708 struct item_head * ih;
709 int len;
710
711 /* delete del_num-1 items beginning from item in position first+1 */
712 leaf_delete_items_entirely (cur_bi, first+1, del_num-1);
713
714 if (is_direntry_le_ih (ih = B_N_PITEM_HEAD(bh, B_NR_ITEMS(bh)-1))) /* the last item is directory */
715 /* len = numbers of directory entries in this item */
716 len = ih_entry_count(ih);
717 else
718 /* len = body len of item */
719 len = ih_item_len(ih);
720
721 /* delete the part of the last item of the bh
722 do not delete item header
723 */
724 leaf_cut_from_buffer (cur_bi, B_NR_ITEMS(bh)-1, len - del_bytes, del_bytes);
725 } 756 }
726 }
727}
728 757
758 if (del_bytes == -1)
759 /* delete del_num items beginning from item in position first */
760 leaf_delete_items_entirely(cur_bi, first, del_num);
761 else {
762 if (last_first == FIRST_TO_LAST) {
763 /* delete del_num-1 items beginning from item in position first */
764 leaf_delete_items_entirely(cur_bi, first, del_num - 1);
765
766 /* delete the part of the first item of the bh
767 do not delete item header
768 */
769 leaf_cut_from_buffer(cur_bi, 0, 0, del_bytes);
770 } else {
771 struct item_head *ih;
772 int len;
773
774 /* delete del_num-1 items beginning from item in position first+1 */
775 leaf_delete_items_entirely(cur_bi, first + 1,
776 del_num - 1);
777
778 if (is_direntry_le_ih
779 (ih = B_N_PITEM_HEAD(bh, B_NR_ITEMS(bh) - 1)))
780 /* the last item is directory */
781 /* len = numbers of directory entries in this item */
782 len = ih_entry_count(ih);
783 else
784 /* len = body len of item */
785 len = ih_item_len(ih);
786
787 /* delete the part of the last item of the bh
788 do not delete item header
789 */
790 leaf_cut_from_buffer(cur_bi, B_NR_ITEMS(bh) - 1,
791 len - del_bytes, del_bytes);
792 }
793 }
794}
729 795
730/* insert item into the leaf node in position before */ 796/* insert item into the leaf node in position before */
731void leaf_insert_into_buf (struct buffer_info * bi, int before, 797void leaf_insert_into_buf(struct buffer_info *bi, int before,
732 struct item_head * inserted_item_ih, 798 struct item_head *inserted_item_ih,
733 const char * inserted_item_body, 799 const char *inserted_item_body, int zeros_number)
734 int zeros_number)
735{ 800{
736 struct buffer_head * bh = bi->bi_bh; 801 struct buffer_head *bh = bi->bi_bh;
737 int nr, free_space; 802 int nr, free_space;
738 struct block_head * blkh; 803 struct block_head *blkh;
739 struct item_head * ih; 804 struct item_head *ih;
740 int i; 805 int i;
741 int last_loc, unmoved_loc; 806 int last_loc, unmoved_loc;
742 char * to; 807 char *to;
743 808
744 809 blkh = B_BLK_HEAD(bh);
745 blkh = B_BLK_HEAD(bh); 810 nr = blkh_nr_item(blkh);
746 nr = blkh_nr_item(blkh); 811 free_space = blkh_free_space(blkh);
747 free_space = blkh_free_space( blkh ); 812
748 813 /* check free space */
749 /* check free space */ 814 RFALSE(free_space < ih_item_len(inserted_item_ih) + IH_SIZE,
750 RFALSE( free_space < ih_item_len(inserted_item_ih) + IH_SIZE, 815 "vs-10170: not enough free space in block %z, new item %h",
751 "vs-10170: not enough free space in block %z, new item %h", 816 bh, inserted_item_ih);
752 bh, inserted_item_ih); 817 RFALSE(zeros_number > ih_item_len(inserted_item_ih),
753 RFALSE( zeros_number > ih_item_len(inserted_item_ih), 818 "vs-10172: zero number == %d, item length == %d",
754 "vs-10172: zero number == %d, item length == %d", 819 zeros_number, ih_item_len(inserted_item_ih));
755 zeros_number, ih_item_len(inserted_item_ih)); 820
756 821 /* get item new item must be inserted before */
757 822 ih = B_N_PITEM_HEAD(bh, before);
758 /* get item new item must be inserted before */ 823
759 ih = B_N_PITEM_HEAD (bh, before); 824 /* prepare space for the body of new item */
760 825 last_loc = nr ? ih_location(&(ih[nr - before - 1])) : bh->b_size;
761 /* prepare space for the body of new item */ 826 unmoved_loc = before ? ih_location(ih - 1) : bh->b_size;
762 last_loc = nr ? ih_location( &(ih[nr - before - 1]) ) : bh->b_size; 827
763 unmoved_loc = before ? ih_location( ih-1 ) : bh->b_size; 828 memmove(bh->b_data + last_loc - ih_item_len(inserted_item_ih),
764 829 bh->b_data + last_loc, unmoved_loc - last_loc);
765 830
766 memmove (bh->b_data + last_loc - ih_item_len(inserted_item_ih), 831 to = bh->b_data + unmoved_loc - ih_item_len(inserted_item_ih);
767 bh->b_data + last_loc, unmoved_loc - last_loc); 832 memset(to, 0, zeros_number);
768 833 to += zeros_number;
769 to = bh->b_data + unmoved_loc - ih_item_len(inserted_item_ih); 834
770 memset (to, 0, zeros_number); 835 /* copy body to prepared space */
771 to += zeros_number; 836 if (inserted_item_body)
772 837 memmove(to, inserted_item_body,
773 /* copy body to prepared space */ 838 ih_item_len(inserted_item_ih) - zeros_number);
774 if (inserted_item_body) 839 else
775 memmove (to, inserted_item_body, ih_item_len(inserted_item_ih) - zeros_number); 840 memset(to, '\0', ih_item_len(inserted_item_ih) - zeros_number);
776 else 841
777 memset(to, '\0', ih_item_len(inserted_item_ih) - zeros_number); 842 /* insert item header */
778 843 memmove(ih + 1, ih, IH_SIZE * (nr - before));
779 /* insert item header */ 844 memmove(ih, inserted_item_ih, IH_SIZE);
780 memmove (ih + 1, ih, IH_SIZE * (nr - before)); 845
781 memmove (ih, inserted_item_ih, IH_SIZE); 846 /* change locations */
782 847 for (i = before; i < nr + 1; i++) {
783 /* change locations */ 848 unmoved_loc -= ih_item_len(&(ih[i - before]));
784 for (i = before; i < nr + 1; i ++) 849 put_ih_location(&(ih[i - before]), unmoved_loc);
785 { 850 }
786 unmoved_loc -= ih_item_len( &(ih[i-before]));
787 put_ih_location( &(ih[i-before]), unmoved_loc );
788 }
789
790 /* sizes, free space, item number */
791 set_blkh_nr_item( blkh, blkh_nr_item(blkh) + 1 );
792 set_blkh_free_space( blkh,
793 free_space - (IH_SIZE + ih_item_len(inserted_item_ih ) ) );
794 do_balance_mark_leaf_dirty (bi->tb, bh, 1);
795
796 if (bi->bi_parent) {
797 struct disk_child *t_dc;
798 t_dc = B_N_CHILD (bi->bi_parent, bi->bi_position);
799 put_dc_size( t_dc, dc_size(t_dc) + (IH_SIZE + ih_item_len(inserted_item_ih)));
800 do_balance_mark_internal_dirty (bi->tb, bi->bi_parent, 0);
801 }
802}
803 851
852 /* sizes, free space, item number */
853 set_blkh_nr_item(blkh, blkh_nr_item(blkh) + 1);
854 set_blkh_free_space(blkh,
855 free_space - (IH_SIZE +
856 ih_item_len(inserted_item_ih)));
857 do_balance_mark_leaf_dirty(bi->tb, bh, 1);
858
859 if (bi->bi_parent) {
860 struct disk_child *t_dc;
861 t_dc = B_N_CHILD(bi->bi_parent, bi->bi_position);
862 put_dc_size(t_dc,
863 dc_size(t_dc) + (IH_SIZE +
864 ih_item_len(inserted_item_ih)));
865 do_balance_mark_internal_dirty(bi->tb, bi->bi_parent, 0);
866 }
867}
804 868
805/* paste paste_size bytes to affected_item_num-th item. 869/* paste paste_size bytes to affected_item_num-th item.
806 When item is a directory, this only prepare space for new entries */ 870 When item is a directory, this only prepare space for new entries */
807void leaf_paste_in_buffer (struct buffer_info * bi, int affected_item_num, 871void leaf_paste_in_buffer(struct buffer_info *bi, int affected_item_num,
808 int pos_in_item, int paste_size, 872 int pos_in_item, int paste_size,
809 const char * body, 873 const char *body, int zeros_number)
810 int zeros_number)
811{ 874{
812 struct buffer_head * bh = bi->bi_bh; 875 struct buffer_head *bh = bi->bi_bh;
813 int nr, free_space; 876 int nr, free_space;
814 struct block_head * blkh; 877 struct block_head *blkh;
815 struct item_head * ih; 878 struct item_head *ih;
816 int i; 879 int i;
817 int last_loc, unmoved_loc; 880 int last_loc, unmoved_loc;
818 881
819 blkh = B_BLK_HEAD(bh); 882 blkh = B_BLK_HEAD(bh);
820 nr = blkh_nr_item(blkh); 883 nr = blkh_nr_item(blkh);
821 free_space = blkh_free_space(blkh); 884 free_space = blkh_free_space(blkh);
822 885
823 886 /* check free space */
824 /* check free space */ 887 RFALSE(free_space < paste_size,
825 RFALSE( free_space < paste_size, 888 "vs-10175: not enough free space: needed %d, available %d",
826 "vs-10175: not enough free space: needed %d, available %d", 889 paste_size, free_space);
827 paste_size, free_space);
828 890
829#ifdef CONFIG_REISERFS_CHECK 891#ifdef CONFIG_REISERFS_CHECK
830 if (zeros_number > paste_size) { 892 if (zeros_number > paste_size) {
831 print_cur_tb ("10177"); 893 print_cur_tb("10177");
832 reiserfs_panic ( NULL, "vs-10177: leaf_paste_in_buffer: ero number == %d, paste_size == %d", 894 reiserfs_panic(NULL,
833 zeros_number, paste_size); 895 "vs-10177: leaf_paste_in_buffer: ero number == %d, paste_size == %d",
834 } 896 zeros_number, paste_size);
835#endif /* CONFIG_REISERFS_CHECK */ 897 }
836 898#endif /* CONFIG_REISERFS_CHECK */
837 899
838 /* item to be appended */ 900 /* item to be appended */
839 ih = B_N_PITEM_HEAD(bh, affected_item_num); 901 ih = B_N_PITEM_HEAD(bh, affected_item_num);
840 902
841 last_loc = ih_location( &(ih[nr - affected_item_num - 1]) ); 903 last_loc = ih_location(&(ih[nr - affected_item_num - 1]));
842 unmoved_loc = affected_item_num ? ih_location( ih-1 ) : bh->b_size; 904 unmoved_loc = affected_item_num ? ih_location(ih - 1) : bh->b_size;
843 905
844 /* prepare space */ 906 /* prepare space */
845 memmove (bh->b_data + last_loc - paste_size, bh->b_data + last_loc, 907 memmove(bh->b_data + last_loc - paste_size, bh->b_data + last_loc,
846 unmoved_loc - last_loc); 908 unmoved_loc - last_loc);
847 909
848 910 /* change locations */
849 /* change locations */ 911 for (i = affected_item_num; i < nr; i++)
850 for (i = affected_item_num; i < nr; i ++) 912 put_ih_location(&(ih[i - affected_item_num]),
851 put_ih_location( &(ih[i-affected_item_num]), 913 ih_location(&(ih[i - affected_item_num])) -
852 ih_location( &(ih[i-affected_item_num])) - paste_size ); 914 paste_size);
853 915
854 if ( body ) { 916 if (body) {
855 if (!is_direntry_le_ih (ih)) { 917 if (!is_direntry_le_ih(ih)) {
856 if (!pos_in_item) { 918 if (!pos_in_item) {
857 /* shift data to right */ 919 /* shift data to right */
858 memmove (bh->b_data + ih_location(ih) + paste_size, 920 memmove(bh->b_data + ih_location(ih) +
859 bh->b_data + ih_location(ih), ih_item_len(ih)); 921 paste_size,
860 /* paste data in the head of item */ 922 bh->b_data + ih_location(ih),
861 memset (bh->b_data + ih_location(ih), 0, zeros_number); 923 ih_item_len(ih));
862 memcpy (bh->b_data + ih_location(ih) + zeros_number, body, paste_size - zeros_number); 924 /* paste data in the head of item */
863 } else { 925 memset(bh->b_data + ih_location(ih), 0,
864 memset (bh->b_data + unmoved_loc - paste_size, 0, zeros_number); 926 zeros_number);
865 memcpy (bh->b_data + unmoved_loc - paste_size + zeros_number, body, paste_size - zeros_number); 927 memcpy(bh->b_data + ih_location(ih) +
866 } 928 zeros_number, body,
929 paste_size - zeros_number);
930 } else {
931 memset(bh->b_data + unmoved_loc - paste_size, 0,
932 zeros_number);
933 memcpy(bh->b_data + unmoved_loc - paste_size +
934 zeros_number, body,
935 paste_size - zeros_number);
936 }
937 }
938 } else
939 memset(bh->b_data + unmoved_loc - paste_size, '\0', paste_size);
940
941 put_ih_item_len(ih, ih_item_len(ih) + paste_size);
942
943 /* change free space */
944 set_blkh_free_space(blkh, free_space - paste_size);
945
946 do_balance_mark_leaf_dirty(bi->tb, bh, 0);
947
948 if (bi->bi_parent) {
949 struct disk_child *t_dc =
950 B_N_CHILD(bi->bi_parent, bi->bi_position);
951 put_dc_size(t_dc, dc_size(t_dc) + paste_size);
952 do_balance_mark_internal_dirty(bi->tb, bi->bi_parent, 0);
867 } 953 }
868 }
869 else
870 memset(bh->b_data + unmoved_loc - paste_size, '\0', paste_size);
871
872 put_ih_item_len( ih, ih_item_len(ih) + paste_size );
873
874 /* change free space */
875 set_blkh_free_space( blkh, free_space - paste_size );
876
877 do_balance_mark_leaf_dirty (bi->tb, bh, 0);
878
879 if (bi->bi_parent) {
880 struct disk_child *t_dc = B_N_CHILD (bi->bi_parent, bi->bi_position);
881 put_dc_size( t_dc, dc_size(t_dc) + paste_size );
882 do_balance_mark_internal_dirty (bi->tb, bi->bi_parent, 0);
883 }
884} 954}
885 955
886
887/* cuts DEL_COUNT entries beginning from FROM-th entry. Directory item 956/* cuts DEL_COUNT entries beginning from FROM-th entry. Directory item
888 does not have free space, so it moves DEHs and remaining records as 957 does not have free space, so it moves DEHs and remaining records as
889 necessary. Return value is size of removed part of directory item 958 necessary. Return value is size of removed part of directory item
890 in bytes. */ 959 in bytes. */
891static int leaf_cut_entries ( 960static int leaf_cut_entries(struct buffer_head *bh,
892 struct buffer_head * bh, 961 struct item_head *ih, int from, int del_count)
893 struct item_head * ih,
894 int from,
895 int del_count
896 )
897{ 962{
898 char * item; 963 char *item;
899 struct reiserfs_de_head * deh; 964 struct reiserfs_de_head *deh;
900 int prev_record_offset; /* offset of record, that is (from-1)th */ 965 int prev_record_offset; /* offset of record, that is (from-1)th */
901 char * prev_record; /* */ 966 char *prev_record; /* */
902 int cut_records_len; /* length of all removed records */ 967 int cut_records_len; /* length of all removed records */
903 int i; 968 int i;
904 969
905 970 /* make sure, that item is directory and there are enough entries to
906 /* make sure, that item is directory and there are enough entries to 971 remove */
907 remove */ 972 RFALSE(!is_direntry_le_ih(ih), "10180: item is not directory item");
908 RFALSE( !is_direntry_le_ih (ih), "10180: item is not directory item"); 973 RFALSE(I_ENTRY_COUNT(ih) < from + del_count,
909 RFALSE( I_ENTRY_COUNT(ih) < from + del_count, 974 "10185: item contains not enough entries: entry_cout = %d, from = %d, to delete = %d",
910 "10185: item contains not enough entries: entry_cout = %d, from = %d, to delete = %d", 975 I_ENTRY_COUNT(ih), from, del_count);
911 I_ENTRY_COUNT(ih), from, del_count); 976
912 977 if (del_count == 0)
913 if (del_count == 0) 978 return 0;
914 return 0; 979
915 980 /* first byte of item */
916 /* first byte of item */ 981 item = bh->b_data + ih_location(ih);
917 item = bh->b_data + ih_location(ih); 982
918 983 /* entry head array */
919 /* entry head array */ 984 deh = B_I_DEH(bh, ih);
920 deh = B_I_DEH (bh, ih); 985
921 986 /* first byte of remaining entries, those are BEFORE cut entries
922 /* first byte of remaining entries, those are BEFORE cut entries 987 (prev_record) and length of all removed records (cut_records_len) */
923 (prev_record) and length of all removed records (cut_records_len) */ 988 prev_record_offset =
924 prev_record_offset = (from ? deh_location( &(deh[from - 1])) : ih_item_len(ih)); 989 (from ? deh_location(&(deh[from - 1])) : ih_item_len(ih));
925 cut_records_len = prev_record_offset/*from_record*/ - 990 cut_records_len = prev_record_offset /*from_record */ -
926 deh_location( &(deh[from + del_count - 1])); 991 deh_location(&(deh[from + del_count - 1]));
927 prev_record = item + prev_record_offset; 992 prev_record = item + prev_record_offset;
928 993
929 994 /* adjust locations of remaining entries */
930 /* adjust locations of remaining entries */ 995 for (i = I_ENTRY_COUNT(ih) - 1; i > from + del_count - 1; i--)
931 for (i = I_ENTRY_COUNT(ih) - 1; i > from + del_count - 1; i --) 996 put_deh_location(&(deh[i]),
932 put_deh_location( &(deh[i]), 997 deh_location(&deh[i]) -
933 deh_location( &deh[i] ) - (DEH_SIZE * del_count ) ); 998 (DEH_SIZE * del_count));
934 999
935 for (i = 0; i < from; i ++) 1000 for (i = 0; i < from; i++)
936 put_deh_location( &(deh[i]), 1001 put_deh_location(&(deh[i]),
937 deh_location( &deh[i] ) - (DEH_SIZE * del_count + cut_records_len) ); 1002 deh_location(&deh[i]) - (DEH_SIZE * del_count +
938 1003 cut_records_len));
939 put_ih_entry_count( ih, ih_entry_count(ih) - del_count ); 1004
940 1005 put_ih_entry_count(ih, ih_entry_count(ih) - del_count);
941 /* shift entry head array and entries those are AFTER removed entries */ 1006
942 memmove ((char *)(deh + from), 1007 /* shift entry head array and entries those are AFTER removed entries */
943 deh + from + del_count, 1008 memmove((char *)(deh + from),
944 prev_record - cut_records_len - (char *)(deh + from + del_count)); 1009 deh + from + del_count,
945 1010 prev_record - cut_records_len - (char *)(deh + from +
946 /* shift records, those are BEFORE removed entries */ 1011 del_count));
947 memmove (prev_record - cut_records_len - DEH_SIZE * del_count, 1012
948 prev_record, item + ih_item_len(ih) - prev_record); 1013 /* shift records, those are BEFORE removed entries */
949 1014 memmove(prev_record - cut_records_len - DEH_SIZE * del_count,
950 return DEH_SIZE * del_count + cut_records_len; 1015 prev_record, item + ih_item_len(ih) - prev_record);
1016
1017 return DEH_SIZE * del_count + cut_records_len;
951} 1018}
952 1019
953
954/* when cut item is part of regular file 1020/* when cut item is part of regular file
955 pos_in_item - first byte that must be cut 1021 pos_in_item - first byte that must be cut
956 cut_size - number of bytes to be cut beginning from pos_in_item 1022 cut_size - number of bytes to be cut beginning from pos_in_item
@@ -959,264 +1025,278 @@ static int leaf_cut_entries (
959 pos_in_item - number of first deleted entry 1025 pos_in_item - number of first deleted entry
960 cut_size - count of deleted entries 1026 cut_size - count of deleted entries
961 */ 1027 */
962void leaf_cut_from_buffer (struct buffer_info * bi, int cut_item_num, 1028void leaf_cut_from_buffer(struct buffer_info *bi, int cut_item_num,
963 int pos_in_item, int cut_size) 1029 int pos_in_item, int cut_size)
964{ 1030{
965 int nr; 1031 int nr;
966 struct buffer_head * bh = bi->bi_bh; 1032 struct buffer_head *bh = bi->bi_bh;
967 struct block_head * blkh; 1033 struct block_head *blkh;
968 struct item_head * ih; 1034 struct item_head *ih;
969 int last_loc, unmoved_loc; 1035 int last_loc, unmoved_loc;
970 int i; 1036 int i;
971 1037
972 blkh = B_BLK_HEAD(bh); 1038 blkh = B_BLK_HEAD(bh);
973 nr = blkh_nr_item(blkh); 1039 nr = blkh_nr_item(blkh);
974 1040
975 /* item head of truncated item */ 1041 /* item head of truncated item */
976 ih = B_N_PITEM_HEAD (bh, cut_item_num); 1042 ih = B_N_PITEM_HEAD(bh, cut_item_num);
977 1043
978 if (is_direntry_le_ih (ih)) { 1044 if (is_direntry_le_ih(ih)) {
979 /* first cut entry ()*/ 1045 /* first cut entry () */
980 cut_size = leaf_cut_entries (bh, ih, pos_in_item, cut_size); 1046 cut_size = leaf_cut_entries(bh, ih, pos_in_item, cut_size);
981 if (pos_in_item == 0) { 1047 if (pos_in_item == 0) {
982 /* change key */ 1048 /* change key */
983 RFALSE( cut_item_num, 1049 RFALSE(cut_item_num,
984 "when 0-th enrty of item is cut, that item must be first in the node, not %d-th", cut_item_num); 1050 "when 0-th enrty of item is cut, that item must be first in the node, not %d-th",
985 /* change item key by key of first entry in the item */ 1051 cut_item_num);
986 set_le_ih_k_offset (ih, deh_offset(B_I_DEH (bh, ih))); 1052 /* change item key by key of first entry in the item */
987 /*memcpy (&ih->ih_key.k_offset, &(B_I_DEH (bh, ih)->deh_offset), SHORT_KEY_SIZE);*/ 1053 set_le_ih_k_offset(ih, deh_offset(B_I_DEH(bh, ih)));
988 } 1054 /*memcpy (&ih->ih_key.k_offset, &(B_I_DEH (bh, ih)->deh_offset), SHORT_KEY_SIZE); */
989 } else { 1055 }
990 /* item is direct or indirect */ 1056 } else {
991 RFALSE( is_statdata_le_ih (ih), "10195: item is stat data"); 1057 /* item is direct or indirect */
992 RFALSE( pos_in_item && pos_in_item + cut_size != ih_item_len(ih), 1058 RFALSE(is_statdata_le_ih(ih), "10195: item is stat data");
993 "10200: invalid offset (%lu) or trunc_size (%lu) or ih_item_len (%lu)", 1059 RFALSE(pos_in_item && pos_in_item + cut_size != ih_item_len(ih),
994 ( long unsigned ) pos_in_item, ( long unsigned ) cut_size, 1060 "10200: invalid offset (%lu) or trunc_size (%lu) or ih_item_len (%lu)",
995 ( long unsigned ) ih_item_len (ih)); 1061 (long unsigned)pos_in_item, (long unsigned)cut_size,
996 1062 (long unsigned)ih_item_len(ih));
997 /* shift item body to left if cut is from the head of item */ 1063
998 if (pos_in_item == 0) { 1064 /* shift item body to left if cut is from the head of item */
999 memmove( bh->b_data + ih_location(ih), 1065 if (pos_in_item == 0) {
1000 bh->b_data + ih_location(ih) + cut_size, 1066 memmove(bh->b_data + ih_location(ih),
1001 ih_item_len(ih) - cut_size); 1067 bh->b_data + ih_location(ih) + cut_size,
1002 1068 ih_item_len(ih) - cut_size);
1003 /* change key of item */ 1069
1004 if (is_direct_le_ih (ih)) 1070 /* change key of item */
1005 set_le_ih_k_offset (ih, le_ih_k_offset (ih) + cut_size); 1071 if (is_direct_le_ih(ih))
1006 else { 1072 set_le_ih_k_offset(ih,
1007 set_le_ih_k_offset (ih, le_ih_k_offset (ih) + (cut_size / UNFM_P_SIZE) * bh->b_size); 1073 le_ih_k_offset(ih) +
1008 RFALSE( ih_item_len(ih) == cut_size && get_ih_free_space (ih), 1074 cut_size);
1009 "10205: invalid ih_free_space (%h)", ih); 1075 else {
1010 } 1076 set_le_ih_k_offset(ih,
1011 } 1077 le_ih_k_offset(ih) +
1012 } 1078 (cut_size / UNFM_P_SIZE) *
1013 1079 bh->b_size);
1014 1080 RFALSE(ih_item_len(ih) == cut_size
1015 /* location of the last item */ 1081 && get_ih_free_space(ih),
1016 last_loc = ih_location( &(ih[nr - cut_item_num - 1]) ); 1082 "10205: invalid ih_free_space (%h)", ih);
1017 1083 }
1018 /* location of the item, which is remaining at the same place */ 1084 }
1019 unmoved_loc = cut_item_num ? ih_location(ih-1) : bh->b_size; 1085 }
1020 1086
1021 1087 /* location of the last item */
1022 /* shift */ 1088 last_loc = ih_location(&(ih[nr - cut_item_num - 1]));
1023 memmove (bh->b_data + last_loc + cut_size, bh->b_data + last_loc, 1089
1024 unmoved_loc - last_loc - cut_size); 1090 /* location of the item, which is remaining at the same place */
1025 1091 unmoved_loc = cut_item_num ? ih_location(ih - 1) : bh->b_size;
1026 /* change item length */ 1092
1027 put_ih_item_len( ih, ih_item_len(ih) - cut_size ); 1093 /* shift */
1028 1094 memmove(bh->b_data + last_loc + cut_size, bh->b_data + last_loc,
1029 if (is_indirect_le_ih (ih)) { 1095 unmoved_loc - last_loc - cut_size);
1030 if (pos_in_item) 1096
1031 set_ih_free_space (ih, 0); 1097 /* change item length */
1032 } 1098 put_ih_item_len(ih, ih_item_len(ih) - cut_size);
1033
1034 /* change locations */
1035 for (i = cut_item_num; i < nr; i ++)
1036 put_ih_location( &(ih[i-cut_item_num]), ih_location( &ih[i-cut_item_num]) + cut_size );
1037
1038 /* size, free space */
1039 set_blkh_free_space( blkh, blkh_free_space(blkh) + cut_size );
1040
1041 do_balance_mark_leaf_dirty (bi->tb, bh, 0);
1042
1043 if (bi->bi_parent) {
1044 struct disk_child *t_dc;
1045 t_dc = B_N_CHILD (bi->bi_parent, bi->bi_position);
1046 put_dc_size( t_dc, dc_size(t_dc) - cut_size );
1047 do_balance_mark_internal_dirty (bi->tb, bi->bi_parent, 0);
1048 }
1049}
1050 1099
1100 if (is_indirect_le_ih(ih)) {
1101 if (pos_in_item)
1102 set_ih_free_space(ih, 0);
1103 }
1104
1105 /* change locations */
1106 for (i = cut_item_num; i < nr; i++)
1107 put_ih_location(&(ih[i - cut_item_num]),
1108 ih_location(&ih[i - cut_item_num]) + cut_size);
1109
1110 /* size, free space */
1111 set_blkh_free_space(blkh, blkh_free_space(blkh) + cut_size);
1112
1113 do_balance_mark_leaf_dirty(bi->tb, bh, 0);
1114
1115 if (bi->bi_parent) {
1116 struct disk_child *t_dc;
1117 t_dc = B_N_CHILD(bi->bi_parent, bi->bi_position);
1118 put_dc_size(t_dc, dc_size(t_dc) - cut_size);
1119 do_balance_mark_internal_dirty(bi->tb, bi->bi_parent, 0);
1120 }
1121}
1051 1122
1052/* delete del_num items from buffer starting from the first'th item */ 1123/* delete del_num items from buffer starting from the first'th item */
1053static void leaf_delete_items_entirely (struct buffer_info * bi, 1124static void leaf_delete_items_entirely(struct buffer_info *bi,
1054 int first, int del_num) 1125 int first, int del_num)
1055{ 1126{
1056 struct buffer_head * bh = bi->bi_bh; 1127 struct buffer_head *bh = bi->bi_bh;
1057 int nr; 1128 int nr;
1058 int i, j; 1129 int i, j;
1059 int last_loc, last_removed_loc; 1130 int last_loc, last_removed_loc;
1060 struct block_head * blkh; 1131 struct block_head *blkh;
1061 struct item_head * ih; 1132 struct item_head *ih;
1062 1133
1063 RFALSE( bh == NULL, "10210: buffer is 0"); 1134 RFALSE(bh == NULL, "10210: buffer is 0");
1064 RFALSE( del_num < 0, "10215: del_num less than 0 (%d)", del_num); 1135 RFALSE(del_num < 0, "10215: del_num less than 0 (%d)", del_num);
1065 1136
1066 if (del_num == 0) 1137 if (del_num == 0)
1067 return; 1138 return;
1068 1139
1069 blkh = B_BLK_HEAD(bh); 1140 blkh = B_BLK_HEAD(bh);
1070 nr = blkh_nr_item(blkh); 1141 nr = blkh_nr_item(blkh);
1071
1072 RFALSE( first < 0 || first + del_num > nr,
1073 "10220: first=%d, number=%d, there is %d items", first, del_num, nr);
1074
1075 if (first == 0 && del_num == nr) {
1076 /* this does not work */
1077 make_empty_node (bi);
1078
1079 do_balance_mark_leaf_dirty (bi->tb, bh, 0);
1080 return;
1081 }
1082
1083 ih = B_N_PITEM_HEAD (bh, first);
1084
1085 /* location of unmovable item */
1086 j = (first == 0) ? bh->b_size : ih_location(ih-1);
1087
1088 /* delete items */
1089 last_loc = ih_location( &(ih[nr-1-first]) );
1090 last_removed_loc = ih_location( &(ih[del_num-1]) );
1091
1092 memmove (bh->b_data + last_loc + j - last_removed_loc,
1093 bh->b_data + last_loc, last_removed_loc - last_loc);
1094
1095 /* delete item headers */
1096 memmove (ih, ih + del_num, (nr - first - del_num) * IH_SIZE);
1097
1098 /* change item location */
1099 for (i = first; i < nr - del_num; i ++)
1100 put_ih_location( &(ih[i-first]), ih_location( &(ih[i-first]) ) + (j - last_removed_loc) );
1101
1102 /* sizes, item number */
1103 set_blkh_nr_item( blkh, blkh_nr_item(blkh) - del_num );
1104 set_blkh_free_space( blkh, blkh_free_space(blkh) + (j - last_removed_loc + IH_SIZE * del_num) );
1105
1106 do_balance_mark_leaf_dirty (bi->tb, bh, 0);
1107
1108 if (bi->bi_parent) {
1109 struct disk_child *t_dc = B_N_CHILD (bi->bi_parent, bi->bi_position);
1110 put_dc_size( t_dc, dc_size(t_dc) -
1111 (j - last_removed_loc + IH_SIZE * del_num));
1112 do_balance_mark_internal_dirty (bi->tb, bi->bi_parent, 0);
1113 }
1114}
1115 1142
1143 RFALSE(first < 0 || first + del_num > nr,
1144 "10220: first=%d, number=%d, there is %d items", first, del_num,
1145 nr);
1146
1147 if (first == 0 && del_num == nr) {
1148 /* this does not work */
1149 make_empty_node(bi);
1150
1151 do_balance_mark_leaf_dirty(bi->tb, bh, 0);
1152 return;
1153 }
1116 1154
1155 ih = B_N_PITEM_HEAD(bh, first);
1117 1156
1157 /* location of unmovable item */
1158 j = (first == 0) ? bh->b_size : ih_location(ih - 1);
1118 1159
1160 /* delete items */
1161 last_loc = ih_location(&(ih[nr - 1 - first]));
1162 last_removed_loc = ih_location(&(ih[del_num - 1]));
1163
1164 memmove(bh->b_data + last_loc + j - last_removed_loc,
1165 bh->b_data + last_loc, last_removed_loc - last_loc);
1166
1167 /* delete item headers */
1168 memmove(ih, ih + del_num, (nr - first - del_num) * IH_SIZE);
1169
1170 /* change item location */
1171 for (i = first; i < nr - del_num; i++)
1172 put_ih_location(&(ih[i - first]),
1173 ih_location(&(ih[i - first])) + (j -
1174 last_removed_loc));
1175
1176 /* sizes, item number */
1177 set_blkh_nr_item(blkh, blkh_nr_item(blkh) - del_num);
1178 set_blkh_free_space(blkh,
1179 blkh_free_space(blkh) + (j - last_removed_loc +
1180 IH_SIZE * del_num));
1181
1182 do_balance_mark_leaf_dirty(bi->tb, bh, 0);
1183
1184 if (bi->bi_parent) {
1185 struct disk_child *t_dc =
1186 B_N_CHILD(bi->bi_parent, bi->bi_position);
1187 put_dc_size(t_dc,
1188 dc_size(t_dc) - (j - last_removed_loc +
1189 IH_SIZE * del_num));
1190 do_balance_mark_internal_dirty(bi->tb, bi->bi_parent, 0);
1191 }
1192}
1119 1193
1120/* paste new_entry_count entries (new_dehs, records) into position before to item_num-th item */ 1194/* paste new_entry_count entries (new_dehs, records) into position before to item_num-th item */
1121void leaf_paste_entries ( 1195void leaf_paste_entries(struct buffer_head *bh,
1122 struct buffer_head * bh,
1123 int item_num, 1196 int item_num,
1124 int before, 1197 int before,
1125 int new_entry_count, 1198 int new_entry_count,
1126 struct reiserfs_de_head * new_dehs, 1199 struct reiserfs_de_head *new_dehs,
1127 const char * records, 1200 const char *records, int paste_size)
1128 int paste_size
1129 )
1130{ 1201{
1131 struct item_head * ih; 1202 struct item_head *ih;
1132 char * item; 1203 char *item;
1133 struct reiserfs_de_head * deh; 1204 struct reiserfs_de_head *deh;
1134 char * insert_point; 1205 char *insert_point;
1135 int i, old_entry_num; 1206 int i, old_entry_num;
1136 1207
1137 if (new_entry_count == 0) 1208 if (new_entry_count == 0)
1138 return; 1209 return;
1139 1210
1140 ih = B_N_PITEM_HEAD(bh, item_num); 1211 ih = B_N_PITEM_HEAD(bh, item_num);
1141 1212
1142 /* make sure, that item is directory, and there are enough records in it */ 1213 /* make sure, that item is directory, and there are enough records in it */
1143 RFALSE( !is_direntry_le_ih (ih), "10225: item is not directory item"); 1214 RFALSE(!is_direntry_le_ih(ih), "10225: item is not directory item");
1144 RFALSE( I_ENTRY_COUNT (ih) < before, 1215 RFALSE(I_ENTRY_COUNT(ih) < before,
1145 "10230: there are no entry we paste entries before. entry_count = %d, before = %d", 1216 "10230: there are no entry we paste entries before. entry_count = %d, before = %d",
1146 I_ENTRY_COUNT (ih), before); 1217 I_ENTRY_COUNT(ih), before);
1147 1218
1148 1219 /* first byte of dest item */
1149 /* first byte of dest item */ 1220 item = bh->b_data + ih_location(ih);
1150 item = bh->b_data + ih_location(ih); 1221
1151 1222 /* entry head array */
1152 /* entry head array */ 1223 deh = B_I_DEH(bh, ih);
1153 deh = B_I_DEH (bh, ih); 1224
1154 1225 /* new records will be pasted at this point */
1155 /* new records will be pasted at this point */ 1226 insert_point =
1156 insert_point = item + (before ? deh_location( &(deh[before - 1])) : (ih_item_len(ih) - paste_size)); 1227 item +
1157 1228 (before ? deh_location(&(deh[before - 1]))
1158 /* adjust locations of records that will be AFTER new records */ 1229 : (ih_item_len(ih) - paste_size));
1159 for (i = I_ENTRY_COUNT(ih) - 1; i >= before; i --) 1230
1160 put_deh_location( &(deh[i]), 1231 /* adjust locations of records that will be AFTER new records */
1161 deh_location(&(deh[i])) + (DEH_SIZE * new_entry_count )); 1232 for (i = I_ENTRY_COUNT(ih) - 1; i >= before; i--)
1162 1233 put_deh_location(&(deh[i]),
1163 /* adjust locations of records that will be BEFORE new records */ 1234 deh_location(&(deh[i])) +
1164 for (i = 0; i < before; i ++) 1235 (DEH_SIZE * new_entry_count));
1165 put_deh_location( &(deh[i]), deh_location(&(deh[i])) + paste_size ); 1236
1166 1237 /* adjust locations of records that will be BEFORE new records */
1167 old_entry_num = I_ENTRY_COUNT(ih); 1238 for (i = 0; i < before; i++)
1168 put_ih_entry_count( ih, ih_entry_count(ih) + new_entry_count ); 1239 put_deh_location(&(deh[i]),
1169 1240 deh_location(&(deh[i])) + paste_size);
1170 /* prepare space for pasted records */ 1241
1171 memmove (insert_point + paste_size, insert_point, item + (ih_item_len(ih) - paste_size) - insert_point); 1242 old_entry_num = I_ENTRY_COUNT(ih);
1172 1243 put_ih_entry_count(ih, ih_entry_count(ih) + new_entry_count);
1173 /* copy new records */ 1244
1174 memcpy (insert_point + DEH_SIZE * new_entry_count, records, 1245 /* prepare space for pasted records */
1175 paste_size - DEH_SIZE * new_entry_count); 1246 memmove(insert_point + paste_size, insert_point,
1176 1247 item + (ih_item_len(ih) - paste_size) - insert_point);
1177 /* prepare space for new entry heads */ 1248
1178 deh += before; 1249 /* copy new records */
1179 memmove ((char *)(deh + new_entry_count), deh, insert_point - (char *)deh); 1250 memcpy(insert_point + DEH_SIZE * new_entry_count, records,
1180 1251 paste_size - DEH_SIZE * new_entry_count);
1181 /* copy new entry heads */ 1252
1182 deh = (struct reiserfs_de_head *)((char *)deh); 1253 /* prepare space for new entry heads */
1183 memcpy (deh, new_dehs, DEH_SIZE * new_entry_count); 1254 deh += before;
1184 1255 memmove((char *)(deh + new_entry_count), deh,
1185 /* set locations of new records */ 1256 insert_point - (char *)deh);
1186 for (i = 0; i < new_entry_count; i ++) 1257
1187 { 1258 /* copy new entry heads */
1188 put_deh_location( &(deh[i]), 1259 deh = (struct reiserfs_de_head *)((char *)deh);
1189 deh_location( &(deh[i] )) + 1260 memcpy(deh, new_dehs, DEH_SIZE * new_entry_count);
1190 (- deh_location( &(new_dehs[new_entry_count - 1])) + 1261
1191 insert_point + DEH_SIZE * new_entry_count - item)); 1262 /* set locations of new records */
1192 } 1263 for (i = 0; i < new_entry_count; i++) {
1193 1264 put_deh_location(&(deh[i]),
1194 1265 deh_location(&(deh[i])) +
1195 /* change item key if necessary (when we paste before 0-th entry */ 1266 (-deh_location
1196 if (!before) 1267 (&(new_dehs[new_entry_count - 1])) +
1197 { 1268 insert_point + DEH_SIZE * new_entry_count -
1198 set_le_ih_k_offset (ih, deh_offset(new_dehs)); 1269 item));
1270 }
1271
1272 /* change item key if necessary (when we paste before 0-th entry */
1273 if (!before) {
1274 set_le_ih_k_offset(ih, deh_offset(new_dehs));
1199/* memcpy (&ih->ih_key.k_offset, 1275/* memcpy (&ih->ih_key.k_offset,
1200 &new_dehs->deh_offset, SHORT_KEY_SIZE);*/ 1276 &new_dehs->deh_offset, SHORT_KEY_SIZE);*/
1201 } 1277 }
1202
1203#ifdef CONFIG_REISERFS_CHECK 1278#ifdef CONFIG_REISERFS_CHECK
1204 { 1279 {
1205 int prev, next; 1280 int prev, next;
1206 /* check record locations */ 1281 /* check record locations */
1207 deh = B_I_DEH (bh, ih); 1282 deh = B_I_DEH(bh, ih);
1208 for (i = 0; i < I_ENTRY_COUNT(ih); i ++) { 1283 for (i = 0; i < I_ENTRY_COUNT(ih); i++) {
1209 next = (i < I_ENTRY_COUNT(ih) - 1) ? deh_location( &(deh[i + 1])) : 0; 1284 next =
1210 prev = (i != 0) ? deh_location( &(deh[i - 1]) ) : 0; 1285 (i <
1211 1286 I_ENTRY_COUNT(ih) -
1212 if (prev && prev <= deh_location( &(deh[i]))) 1287 1) ? deh_location(&(deh[i + 1])) : 0;
1213 reiserfs_warning (NULL, "vs-10240: leaf_paste_entries: directory item (%h) corrupted (prev %a, cur(%d) %a)", 1288 prev = (i != 0) ? deh_location(&(deh[i - 1])) : 0;
1214 ih, deh + i - 1, i, deh + i); 1289
1215 if (next && next >= deh_location( &(deh[i]))) 1290 if (prev && prev <= deh_location(&(deh[i])))
1216 reiserfs_warning (NULL, "vs-10250: leaf_paste_entries: directory item (%h) corrupted (cur(%d) %a, next %a)", 1291 reiserfs_warning(NULL,
1217 ih, i, deh + i, deh + i + 1); 1292 "vs-10240: leaf_paste_entries: directory item (%h) corrupted (prev %a, cur(%d) %a)",
1218 } 1293 ih, deh + i - 1, i, deh + i);
1219 } 1294 if (next && next >= deh_location(&(deh[i])))
1295 reiserfs_warning(NULL,
1296 "vs-10250: leaf_paste_entries: directory item (%h) corrupted (cur(%d) %a, next %a)",
1297 ih, i, deh + i, deh + i + 1);
1298 }
1299 }
1220#endif 1300#endif
1221 1301
1222} 1302}
diff --git a/fs/reiserfs/namei.c b/fs/reiserfs/namei.c
index 4a333255f27a..a20bbc1642dc 100644
--- a/fs/reiserfs/namei.c
+++ b/fs/reiserfs/namei.c
@@ -25,86 +25,85 @@
25 25
26// directory item contains array of entry headers. This performs 26// directory item contains array of entry headers. This performs
27// binary search through that array 27// binary search through that array
28static int bin_search_in_dir_item (struct reiserfs_dir_entry * de, loff_t off) 28static int bin_search_in_dir_item(struct reiserfs_dir_entry *de, loff_t off)
29{ 29{
30 struct item_head * ih = de->de_ih; 30 struct item_head *ih = de->de_ih;
31 struct reiserfs_de_head * deh = de->de_deh; 31 struct reiserfs_de_head *deh = de->de_deh;
32 int rbound, lbound, j; 32 int rbound, lbound, j;
33 33
34 lbound = 0; 34 lbound = 0;
35 rbound = I_ENTRY_COUNT (ih) - 1; 35 rbound = I_ENTRY_COUNT(ih) - 1;
36 36
37 for (j = (rbound + lbound) / 2; lbound <= rbound; j = (rbound + lbound) / 2) { 37 for (j = (rbound + lbound) / 2; lbound <= rbound;
38 if (off < deh_offset (deh + j)) { 38 j = (rbound + lbound) / 2) {
39 rbound = j - 1; 39 if (off < deh_offset(deh + j)) {
40 continue; 40 rbound = j - 1;
41 continue;
42 }
43 if (off > deh_offset(deh + j)) {
44 lbound = j + 1;
45 continue;
46 }
47 // this is not name found, but matched third key component
48 de->de_entry_num = j;
49 return NAME_FOUND;
41 } 50 }
42 if (off > deh_offset (deh + j)) {
43 lbound = j + 1;
44 continue;
45 }
46 // this is not name found, but matched third key component
47 de->de_entry_num = j;
48 return NAME_FOUND;
49 }
50 51
51 de->de_entry_num = lbound; 52 de->de_entry_num = lbound;
52 return NAME_NOT_FOUND; 53 return NAME_NOT_FOUND;
53} 54}
54 55
55
56// comment? maybe something like set de to point to what the path points to? 56// comment? maybe something like set de to point to what the path points to?
57static inline void set_de_item_location (struct reiserfs_dir_entry * de, struct path * path) 57static inline void set_de_item_location(struct reiserfs_dir_entry *de,
58 struct path *path)
58{ 59{
59 de->de_bh = get_last_bh (path); 60 de->de_bh = get_last_bh(path);
60 de->de_ih = get_ih (path); 61 de->de_ih = get_ih(path);
61 de->de_deh = B_I_DEH (de->de_bh, de->de_ih); 62 de->de_deh = B_I_DEH(de->de_bh, de->de_ih);
62 de->de_item_num = PATH_LAST_POSITION (path); 63 de->de_item_num = PATH_LAST_POSITION(path);
63} 64}
64
65 65
66// de_bh, de_ih, de_deh (points to first element of array), de_item_num is set 66// de_bh, de_ih, de_deh (points to first element of array), de_item_num is set
67inline void set_de_name_and_namelen (struct reiserfs_dir_entry * de) 67inline void set_de_name_and_namelen(struct reiserfs_dir_entry *de)
68{ 68{
69 struct reiserfs_de_head * deh = de->de_deh + de->de_entry_num; 69 struct reiserfs_de_head *deh = de->de_deh + de->de_entry_num;
70 70
71 if (de->de_entry_num >= ih_entry_count (de->de_ih)) 71 if (de->de_entry_num >= ih_entry_count(de->de_ih))
72 BUG (); 72 BUG();
73 73
74 de->de_entrylen = entry_length (de->de_bh, de->de_ih, de->de_entry_num); 74 de->de_entrylen = entry_length(de->de_bh, de->de_ih, de->de_entry_num);
75 de->de_namelen = de->de_entrylen - (de_with_sd (deh) ? SD_SIZE : 0); 75 de->de_namelen = de->de_entrylen - (de_with_sd(deh) ? SD_SIZE : 0);
76 de->de_name = B_I_PITEM (de->de_bh, de->de_ih) + deh_location(deh); 76 de->de_name = B_I_PITEM(de->de_bh, de->de_ih) + deh_location(deh);
77 if (de->de_name[de->de_namelen - 1] == 0) 77 if (de->de_name[de->de_namelen - 1] == 0)
78 de->de_namelen = strlen (de->de_name); 78 de->de_namelen = strlen(de->de_name);
79} 79}
80 80
81
82// what entry points to 81// what entry points to
83static inline void set_de_object_key (struct reiserfs_dir_entry * de) 82static inline void set_de_object_key(struct reiserfs_dir_entry *de)
84{ 83{
85 if (de->de_entry_num >= ih_entry_count (de->de_ih)) 84 if (de->de_entry_num >= ih_entry_count(de->de_ih))
86 BUG (); 85 BUG();
87 de->de_dir_id = deh_dir_id( &(de->de_deh[de->de_entry_num])); 86 de->de_dir_id = deh_dir_id(&(de->de_deh[de->de_entry_num]));
88 de->de_objectid = deh_objectid( &(de->de_deh[de->de_entry_num])); 87 de->de_objectid = deh_objectid(&(de->de_deh[de->de_entry_num]));
89} 88}
90 89
91 90static inline void store_de_entry_key(struct reiserfs_dir_entry *de)
92static inline void store_de_entry_key (struct reiserfs_dir_entry * de)
93{ 91{
94 struct reiserfs_de_head * deh = de->de_deh + de->de_entry_num; 92 struct reiserfs_de_head *deh = de->de_deh + de->de_entry_num;
95 93
96 if (de->de_entry_num >= ih_entry_count (de->de_ih)) 94 if (de->de_entry_num >= ih_entry_count(de->de_ih))
97 BUG (); 95 BUG();
98 96
99 /* store key of the found entry */ 97 /* store key of the found entry */
100 de->de_entry_key.version = KEY_FORMAT_3_5; 98 de->de_entry_key.version = KEY_FORMAT_3_5;
101 de->de_entry_key.on_disk_key.k_dir_id = le32_to_cpu (de->de_ih->ih_key.k_dir_id); 99 de->de_entry_key.on_disk_key.k_dir_id =
102 de->de_entry_key.on_disk_key.k_objectid = le32_to_cpu (de->de_ih->ih_key.k_objectid); 100 le32_to_cpu(de->de_ih->ih_key.k_dir_id);
103 set_cpu_key_k_offset (&(de->de_entry_key), deh_offset (deh)); 101 de->de_entry_key.on_disk_key.k_objectid =
104 set_cpu_key_k_type (&(de->de_entry_key), TYPE_DIRENTRY); 102 le32_to_cpu(de->de_ih->ih_key.k_objectid);
103 set_cpu_key_k_offset(&(de->de_entry_key), deh_offset(deh));
104 set_cpu_key_k_type(&(de->de_entry_key), TYPE_DIRENTRY);
105} 105}
106 106
107
108/* We assign a key to each directory item, and place multiple entries 107/* We assign a key to each directory item, and place multiple entries
109in a single directory item. A directory item has a key equal to the 108in a single directory item. A directory item has a key equal to the
110key of the first directory entry in it. 109key of the first directory entry in it.
@@ -117,58 +116,60 @@ entry position in the item
117*/ 116*/
118 117
119/* The function is NOT SCHEDULE-SAFE! */ 118/* The function is NOT SCHEDULE-SAFE! */
120int search_by_entry_key (struct super_block * sb, const struct cpu_key * key, 119int search_by_entry_key(struct super_block *sb, const struct cpu_key *key,
121 struct path * path, struct reiserfs_dir_entry * de) 120 struct path *path, struct reiserfs_dir_entry *de)
122{ 121{
123 int retval; 122 int retval;
124 123
125 retval = search_item (sb, key, path); 124 retval = search_item(sb, key, path);
126 switch (retval) { 125 switch (retval) {
127 case ITEM_NOT_FOUND: 126 case ITEM_NOT_FOUND:
128 if (!PATH_LAST_POSITION (path)) { 127 if (!PATH_LAST_POSITION(path)) {
129 reiserfs_warning (sb, "vs-7000: search_by_entry_key: search_by_key returned item position == 0"); 128 reiserfs_warning(sb,
130 pathrelse(path) ; 129 "vs-7000: search_by_entry_key: search_by_key returned item position == 0");
131 return IO_ERROR ; 130 pathrelse(path);
131 return IO_ERROR;
132 }
133 PATH_LAST_POSITION(path)--;
134
135 case ITEM_FOUND:
136 break;
137
138 case IO_ERROR:
139 return retval;
140
141 default:
142 pathrelse(path);
143 reiserfs_warning(sb,
144 "vs-7002: search_by_entry_key: no path to here");
145 return IO_ERROR;
132 } 146 }
133 PATH_LAST_POSITION (path) --;
134
135 case ITEM_FOUND:
136 break;
137
138 case IO_ERROR:
139 return retval;
140 147
141 default: 148 set_de_item_location(de, path);
142 pathrelse (path);
143 reiserfs_warning (sb, "vs-7002: search_by_entry_key: no path to here");
144 return IO_ERROR;
145 }
146
147 set_de_item_location (de, path);
148 149
149#ifdef CONFIG_REISERFS_CHECK 150#ifdef CONFIG_REISERFS_CHECK
150 if (!is_direntry_le_ih (de->de_ih) || 151 if (!is_direntry_le_ih(de->de_ih) ||
151 COMP_SHORT_KEYS (&(de->de_ih->ih_key), key)) { 152 COMP_SHORT_KEYS(&(de->de_ih->ih_key), key)) {
152 print_block (de->de_bh, 0, -1, -1); 153 print_block(de->de_bh, 0, -1, -1);
153 reiserfs_panic (sb, "vs-7005: search_by_entry_key: found item %h is not directory item or " 154 reiserfs_panic(sb,
154 "does not belong to the same directory as key %K", de->de_ih, key); 155 "vs-7005: search_by_entry_key: found item %h is not directory item or "
155 } 156 "does not belong to the same directory as key %K",
156#endif /* CONFIG_REISERFS_CHECK */ 157 de->de_ih, key);
157 158 }
158 /* binary search in directory item by third componen t of the 159#endif /* CONFIG_REISERFS_CHECK */
159 key. sets de->de_entry_num of de */ 160
160 retval = bin_search_in_dir_item (de, cpu_key_k_offset (key)); 161 /* binary search in directory item by third componen t of the
161 path->pos_in_item = de->de_entry_num; 162 key. sets de->de_entry_num of de */
162 if (retval != NAME_NOT_FOUND) { 163 retval = bin_search_in_dir_item(de, cpu_key_k_offset(key));
163 // ugly, but rename needs de_bh, de_deh, de_name, de_namelen, de_objectid set 164 path->pos_in_item = de->de_entry_num;
164 set_de_name_and_namelen (de); 165 if (retval != NAME_NOT_FOUND) {
165 set_de_object_key (de); 166 // ugly, but rename needs de_bh, de_deh, de_name, de_namelen, de_objectid set
166 } 167 set_de_name_and_namelen(de);
167 return retval; 168 set_de_object_key(de);
169 }
170 return retval;
168} 171}
169 172
170
171
172/* Keyed 32-bit hash function using TEA in a Davis-Meyer function */ 173/* Keyed 32-bit hash function using TEA in a Davis-Meyer function */
173 174
174/* The third component is hashed, and you can choose from more than 175/* The third component is hashed, and you can choose from more than
@@ -176,197 +177,210 @@ int search_by_entry_key (struct super_block * sb, const struct cpu_key * key,
176 but are thought about. This function should be moved to hashes.c 177 but are thought about. This function should be moved to hashes.c
177 Jedi, please do so. -Hans */ 178 Jedi, please do so. -Hans */
178 179
179static __u32 get_third_component (struct super_block * s, 180static __u32 get_third_component(struct super_block *s,
180 const char * name, int len) 181 const char *name, int len)
181{ 182{
182 __u32 res; 183 __u32 res;
183 184
184 if (!len || (len == 1 && name[0] == '.')) 185 if (!len || (len == 1 && name[0] == '.'))
185 return DOT_OFFSET; 186 return DOT_OFFSET;
186 if (len == 2 && name[0] == '.' && name[1] == '.') 187 if (len == 2 && name[0] == '.' && name[1] == '.')
187 return DOT_DOT_OFFSET; 188 return DOT_DOT_OFFSET;
188 189
189 res = REISERFS_SB(s)->s_hash_function (name, len); 190 res = REISERFS_SB(s)->s_hash_function(name, len);
190 191
191 // take bits from 7-th to 30-th including both bounds 192 // take bits from 7-th to 30-th including both bounds
192 res = GET_HASH_VALUE(res); 193 res = GET_HASH_VALUE(res);
193 if (res == 0) 194 if (res == 0)
194 // needed to have no names before "." and ".." those have hash 195 // needed to have no names before "." and ".." those have hash
195 // value == 0 and generation conters 1 and 2 accordingly 196 // value == 0 and generation conters 1 and 2 accordingly
196 res = 128; 197 res = 128;
197 return res + MAX_GENERATION_NUMBER; 198 return res + MAX_GENERATION_NUMBER;
198} 199}
199 200
200 201static int reiserfs_match(struct reiserfs_dir_entry *de,
201static int reiserfs_match (struct reiserfs_dir_entry * de, 202 const char *name, int namelen)
202 const char * name, int namelen)
203{ 203{
204 int retval = NAME_NOT_FOUND; 204 int retval = NAME_NOT_FOUND;
205 205
206 if ((namelen == de->de_namelen) && 206 if ((namelen == de->de_namelen) &&
207 !memcmp(de->de_name, name, de->de_namelen)) 207 !memcmp(de->de_name, name, de->de_namelen))
208 retval = (de_visible (de->de_deh + de->de_entry_num) ? NAME_FOUND : NAME_FOUND_INVISIBLE); 208 retval =
209 (de_visible(de->de_deh + de->de_entry_num) ? NAME_FOUND :
210 NAME_FOUND_INVISIBLE);
209 211
210 return retval; 212 return retval;
211} 213}
212 214
213
214/* de's de_bh, de_ih, de_deh, de_item_num, de_entry_num are set already */ 215/* de's de_bh, de_ih, de_deh, de_item_num, de_entry_num are set already */
215 216
216 /* used when hash collisions exist */ 217 /* used when hash collisions exist */
217 218
218 219static int linear_search_in_dir_item(struct cpu_key *key,
219static int linear_search_in_dir_item (struct cpu_key * key, struct reiserfs_dir_entry * de, 220 struct reiserfs_dir_entry *de,
220 const char * name, int namelen) 221 const char *name, int namelen)
221{ 222{
222 struct reiserfs_de_head * deh = de->de_deh; 223 struct reiserfs_de_head *deh = de->de_deh;
223 int retval; 224 int retval;
224 int i; 225 int i;
225 226
226 i = de->de_entry_num; 227 i = de->de_entry_num;
227 228
228 if (i == I_ENTRY_COUNT (de->de_ih) || 229 if (i == I_ENTRY_COUNT(de->de_ih) ||
229 GET_HASH_VALUE (deh_offset (deh + i)) != GET_HASH_VALUE (cpu_key_k_offset (key))) { 230 GET_HASH_VALUE(deh_offset(deh + i)) !=
230 i --; 231 GET_HASH_VALUE(cpu_key_k_offset(key))) {
231 } 232 i--;
233 }
232 234
233 RFALSE( de->de_deh != B_I_DEH (de->de_bh, de->de_ih), 235 RFALSE(de->de_deh != B_I_DEH(de->de_bh, de->de_ih),
234 "vs-7010: array of entry headers not found"); 236 "vs-7010: array of entry headers not found");
235 237
236 deh += i; 238 deh += i;
237 239
238 for (; i >= 0; i --, deh --) { 240 for (; i >= 0; i--, deh--) {
239 if (GET_HASH_VALUE (deh_offset (deh)) != 241 if (GET_HASH_VALUE(deh_offset(deh)) !=
240 GET_HASH_VALUE (cpu_key_k_offset (key))) { 242 GET_HASH_VALUE(cpu_key_k_offset(key))) {
241 // hash value does not match, no need to check whole name 243 // hash value does not match, no need to check whole name
242 return NAME_NOT_FOUND; 244 return NAME_NOT_FOUND;
243 } 245 }
244 246
245 /* mark, that this generation number is used */ 247 /* mark, that this generation number is used */
246 if (de->de_gen_number_bit_string) 248 if (de->de_gen_number_bit_string)
247 set_bit (GET_GENERATION_NUMBER (deh_offset (deh)), (unsigned long *)de->de_gen_number_bit_string); 249 set_bit(GET_GENERATION_NUMBER(deh_offset(deh)),
250 (unsigned long *)de->de_gen_number_bit_string);
248 251
249 // calculate pointer to name and namelen 252 // calculate pointer to name and namelen
250 de->de_entry_num = i; 253 de->de_entry_num = i;
251 set_de_name_and_namelen (de); 254 set_de_name_and_namelen(de);
252 255
253 if ((retval = reiserfs_match (de, name, namelen)) != NAME_NOT_FOUND) { 256 if ((retval =
254 // de's de_name, de_namelen, de_recordlen are set. Fill the rest: 257 reiserfs_match(de, name, namelen)) != NAME_NOT_FOUND) {
258 // de's de_name, de_namelen, de_recordlen are set. Fill the rest:
255 259
256 // key of pointed object 260 // key of pointed object
257 set_de_object_key (de); 261 set_de_object_key(de);
258 262
259 store_de_entry_key (de); 263 store_de_entry_key(de);
260 264
261 // retval can be NAME_FOUND or NAME_FOUND_INVISIBLE 265 // retval can be NAME_FOUND or NAME_FOUND_INVISIBLE
262 return retval; 266 return retval;
267 }
263 } 268 }
264 }
265
266 if (GET_GENERATION_NUMBER (le_ih_k_offset (de->de_ih)) == 0)
267 /* we have reached left most entry in the node. In common we
268 have to go to the left neighbor, but if generation counter
269 is 0 already, we know for sure, that there is no name with
270 the same hash value */
271 // FIXME: this work correctly only because hash value can not
272 // be 0. Btw, in case of Yura's hash it is probably possible,
273 // so, this is a bug
274 return NAME_NOT_FOUND;
275 269
276 RFALSE( de->de_item_num, 270 if (GET_GENERATION_NUMBER(le_ih_k_offset(de->de_ih)) == 0)
277 "vs-7015: two diritems of the same directory in one node?"); 271 /* we have reached left most entry in the node. In common we
272 have to go to the left neighbor, but if generation counter
273 is 0 already, we know for sure, that there is no name with
274 the same hash value */
275 // FIXME: this work correctly only because hash value can not
276 // be 0. Btw, in case of Yura's hash it is probably possible,
277 // so, this is a bug
278 return NAME_NOT_FOUND;
278 279
279 return GOTO_PREVIOUS_ITEM; 280 RFALSE(de->de_item_num,
280} 281 "vs-7015: two diritems of the same directory in one node?");
281 282
283 return GOTO_PREVIOUS_ITEM;
284}
282 285
283// may return NAME_FOUND, NAME_FOUND_INVISIBLE, NAME_NOT_FOUND 286// may return NAME_FOUND, NAME_FOUND_INVISIBLE, NAME_NOT_FOUND
284// FIXME: should add something like IOERROR 287// FIXME: should add something like IOERROR
285static int reiserfs_find_entry (struct inode * dir, const char * name, int namelen, 288static int reiserfs_find_entry(struct inode *dir, const char *name, int namelen,
286 struct path * path_to_entry, struct reiserfs_dir_entry * de) 289 struct path *path_to_entry,
290 struct reiserfs_dir_entry *de)
287{ 291{
288 struct cpu_key key_to_search; 292 struct cpu_key key_to_search;
289 int retval; 293 int retval;
290 294
291 295 if (namelen > REISERFS_MAX_NAME(dir->i_sb->s_blocksize))
292 if (namelen > REISERFS_MAX_NAME (dir->i_sb->s_blocksize)) 296 return NAME_NOT_FOUND;
293 return NAME_NOT_FOUND; 297
294 298 /* we will search for this key in the tree */
295 /* we will search for this key in the tree */ 299 make_cpu_key(&key_to_search, dir,
296 make_cpu_key (&key_to_search, dir, 300 get_third_component(dir->i_sb, name, namelen),
297 get_third_component (dir->i_sb, name, namelen), TYPE_DIRENTRY, 3); 301 TYPE_DIRENTRY, 3);
298 302
299 while (1) { 303 while (1) {
300 retval = search_by_entry_key (dir->i_sb, &key_to_search, path_to_entry, de); 304 retval =
301 if (retval == IO_ERROR) { 305 search_by_entry_key(dir->i_sb, &key_to_search,
302 reiserfs_warning (dir->i_sb, "zam-7001: io error in %s", 306 path_to_entry, de);
303 __FUNCTION__); 307 if (retval == IO_ERROR) {
304 return IO_ERROR; 308 reiserfs_warning(dir->i_sb, "zam-7001: io error in %s",
305 } 309 __FUNCTION__);
306 310 return IO_ERROR;
307 /* compare names for all entries having given hash value */ 311 }
308 retval = linear_search_in_dir_item (&key_to_search, de, name, namelen); 312
309 if (retval != GOTO_PREVIOUS_ITEM) { 313 /* compare names for all entries having given hash value */
310 /* there is no need to scan directory anymore. Given entry found or does not exist */ 314 retval =
311 path_to_entry->pos_in_item = de->de_entry_num; 315 linear_search_in_dir_item(&key_to_search, de, name,
312 return retval; 316 namelen);
313 } 317 if (retval != GOTO_PREVIOUS_ITEM) {
314 318 /* there is no need to scan directory anymore. Given entry found or does not exist */
315 /* there is left neighboring item of this directory and given entry can be there */ 319 path_to_entry->pos_in_item = de->de_entry_num;
316 set_cpu_key_k_offset (&key_to_search, le_ih_k_offset (de->de_ih) - 1); 320 return retval;
317 pathrelse (path_to_entry); 321 }
318 322
319 } /* while (1) */ 323 /* there is left neighboring item of this directory and given entry can be there */
324 set_cpu_key_k_offset(&key_to_search,
325 le_ih_k_offset(de->de_ih) - 1);
326 pathrelse(path_to_entry);
327
328 } /* while (1) */
320} 329}
321 330
322 331static struct dentry *reiserfs_lookup(struct inode *dir, struct dentry *dentry,
323static struct dentry * reiserfs_lookup (struct inode * dir, struct dentry * dentry, struct nameidata *nd) 332 struct nameidata *nd)
324{ 333{
325 int retval; 334 int retval;
326 struct inode * inode = NULL; 335 struct inode *inode = NULL;
327 struct reiserfs_dir_entry de; 336 struct reiserfs_dir_entry de;
328 INITIALIZE_PATH (path_to_entry); 337 INITIALIZE_PATH(path_to_entry);
329 338
330 if (REISERFS_MAX_NAME (dir->i_sb->s_blocksize) < dentry->d_name.len) 339 if (REISERFS_MAX_NAME(dir->i_sb->s_blocksize) < dentry->d_name.len)
331 return ERR_PTR(-ENAMETOOLONG); 340 return ERR_PTR(-ENAMETOOLONG);
332 341
333 reiserfs_write_lock(dir->i_sb); 342 reiserfs_write_lock(dir->i_sb);
334 de.de_gen_number_bit_string = NULL; 343 de.de_gen_number_bit_string = NULL;
335 retval = reiserfs_find_entry (dir, dentry->d_name.name, dentry->d_name.len, &path_to_entry, &de); 344 retval =
336 pathrelse (&path_to_entry); 345 reiserfs_find_entry(dir, dentry->d_name.name, dentry->d_name.len,
337 if (retval == NAME_FOUND) { 346 &path_to_entry, &de);
338 /* Hide the .reiserfs_priv directory */ 347 pathrelse(&path_to_entry);
339 if (reiserfs_xattrs (dir->i_sb) && 348 if (retval == NAME_FOUND) {
340 !old_format_only(dir->i_sb) && 349 /* Hide the .reiserfs_priv directory */
341 REISERFS_SB(dir->i_sb)->priv_root && 350 if (reiserfs_xattrs(dir->i_sb) &&
342 REISERFS_SB(dir->i_sb)->priv_root->d_inode && 351 !old_format_only(dir->i_sb) &&
343 de.de_objectid == le32_to_cpu (INODE_PKEY(REISERFS_SB(dir->i_sb)->priv_root->d_inode)->k_objectid)) { 352 REISERFS_SB(dir->i_sb)->priv_root &&
344 reiserfs_write_unlock (dir->i_sb); 353 REISERFS_SB(dir->i_sb)->priv_root->d_inode &&
345 return ERR_PTR (-EACCES); 354 de.de_objectid ==
355 le32_to_cpu(INODE_PKEY
356 (REISERFS_SB(dir->i_sb)->priv_root->d_inode)->
357 k_objectid)) {
358 reiserfs_write_unlock(dir->i_sb);
359 return ERR_PTR(-EACCES);
360 }
361
362 inode =
363 reiserfs_iget(dir->i_sb, (struct cpu_key *)&(de.de_dir_id));
364 if (!inode || IS_ERR(inode)) {
365 reiserfs_write_unlock(dir->i_sb);
366 return ERR_PTR(-EACCES);
367 }
368
369 /* Propogate the priv_object flag so we know we're in the priv tree */
370 if (is_reiserfs_priv_object(dir))
371 reiserfs_mark_inode_private(inode);
372 }
373 reiserfs_write_unlock(dir->i_sb);
374 if (retval == IO_ERROR) {
375 return ERR_PTR(-EIO);
346 } 376 }
347 377
348 inode = reiserfs_iget (dir->i_sb, (struct cpu_key *)&(de.de_dir_id)); 378 if (inode)
349 if (!inode || IS_ERR(inode)) { 379 return d_splice_alias(inode, dentry);
350 reiserfs_write_unlock(dir->i_sb);
351 return ERR_PTR(-EACCES);
352 }
353
354 /* Propogate the priv_object flag so we know we're in the priv tree */
355 if (is_reiserfs_priv_object (dir))
356 reiserfs_mark_inode_private (inode);
357 }
358 reiserfs_write_unlock(dir->i_sb);
359 if ( retval == IO_ERROR ) {
360 return ERR_PTR(-EIO);
361 }
362
363 if (inode)
364 return d_splice_alias(inode, dentry);
365
366 d_add(dentry, inode);
367 return NULL;
368}
369 380
381 d_add(dentry, inode);
382 return NULL;
383}
370 384
371/* 385/*
372** looks up the dentry of the parent directory for child. 386** looks up the dentry of the parent directory for child.
@@ -374,40 +388,38 @@ static struct dentry * reiserfs_lookup (struct inode * dir, struct dentry * dent
374*/ 388*/
375struct dentry *reiserfs_get_parent(struct dentry *child) 389struct dentry *reiserfs_get_parent(struct dentry *child)
376{ 390{
377 int retval; 391 int retval;
378 struct inode * inode = NULL; 392 struct inode *inode = NULL;
379 struct reiserfs_dir_entry de; 393 struct reiserfs_dir_entry de;
380 INITIALIZE_PATH (path_to_entry); 394 INITIALIZE_PATH(path_to_entry);
381 struct dentry *parent; 395 struct dentry *parent;
382 struct inode *dir = child->d_inode ; 396 struct inode *dir = child->d_inode;
383 397
384 398 if (dir->i_nlink == 0) {
385 if (dir->i_nlink == 0) { 399 return ERR_PTR(-ENOENT);
386 return ERR_PTR(-ENOENT); 400 }
387 } 401 de.de_gen_number_bit_string = NULL;
388 de.de_gen_number_bit_string = NULL; 402
389 403 reiserfs_write_lock(dir->i_sb);
390 reiserfs_write_lock(dir->i_sb); 404 retval = reiserfs_find_entry(dir, "..", 2, &path_to_entry, &de);
391 retval = reiserfs_find_entry (dir, "..", 2, &path_to_entry, &de); 405 pathrelse(&path_to_entry);
392 pathrelse (&path_to_entry); 406 if (retval != NAME_FOUND) {
393 if (retval != NAME_FOUND) { 407 reiserfs_write_unlock(dir->i_sb);
408 return ERR_PTR(-ENOENT);
409 }
410 inode = reiserfs_iget(dir->i_sb, (struct cpu_key *)&(de.de_dir_id));
394 reiserfs_write_unlock(dir->i_sb); 411 reiserfs_write_unlock(dir->i_sb);
395 return ERR_PTR(-ENOENT);
396 }
397 inode = reiserfs_iget (dir->i_sb, (struct cpu_key *)&(de.de_dir_id));
398 reiserfs_write_unlock(dir->i_sb);
399
400 if (!inode || IS_ERR(inode)) {
401 return ERR_PTR(-EACCES);
402 }
403 parent = d_alloc_anon(inode);
404 if (!parent) {
405 iput(inode);
406 parent = ERR_PTR(-ENOMEM);
407 }
408 return parent;
409}
410 412
413 if (!inode || IS_ERR(inode)) {
414 return ERR_PTR(-EACCES);
415 }
416 parent = d_alloc_anon(inode);
417 if (!parent) {
418 iput(inode);
419 parent = ERR_PTR(-ENOMEM);
420 }
421 return parent;
422}
411 423
412/* add entry to the directory (entry can be hidden). 424/* add entry to the directory (entry can be hidden).
413 425
@@ -415,132 +427,143 @@ insert definition of when hidden directories are used here -Hans
415 427
416 Does not mark dir inode dirty, do it after successesfull call to it */ 428 Does not mark dir inode dirty, do it after successesfull call to it */
417 429
418static int reiserfs_add_entry (struct reiserfs_transaction_handle *th, struct inode * dir, 430static int reiserfs_add_entry(struct reiserfs_transaction_handle *th,
419 const char * name, int namelen, struct inode * inode, 431 struct inode *dir, const char *name, int namelen,
420 int visible) 432 struct inode *inode, int visible)
421{ 433{
422 struct cpu_key entry_key; 434 struct cpu_key entry_key;
423 struct reiserfs_de_head * deh; 435 struct reiserfs_de_head *deh;
424 INITIALIZE_PATH (path); 436 INITIALIZE_PATH(path);
425 struct reiserfs_dir_entry de; 437 struct reiserfs_dir_entry de;
426 int bit_string [MAX_GENERATION_NUMBER / (sizeof(int) * 8) + 1]; 438 int bit_string[MAX_GENERATION_NUMBER / (sizeof(int) * 8) + 1];
427 int gen_number; 439 int gen_number;
428 char small_buf[32+DEH_SIZE] ; /* 48 bytes now and we avoid kmalloc 440 char small_buf[32 + DEH_SIZE]; /* 48 bytes now and we avoid kmalloc
429 if we create file with short name */ 441 if we create file with short name */
430 char * buffer; 442 char *buffer;
431 int buflen, paste_size; 443 int buflen, paste_size;
432 int retval; 444 int retval;
433 445
434 BUG_ON (!th->t_trans_id); 446 BUG_ON(!th->t_trans_id);
435 447
436 /* cannot allow items to be added into a busy deleted directory */ 448 /* cannot allow items to be added into a busy deleted directory */
437 if (!namelen) 449 if (!namelen)
438 return -EINVAL; 450 return -EINVAL;
439 451
440 if (namelen > REISERFS_MAX_NAME (dir->i_sb->s_blocksize)) 452 if (namelen > REISERFS_MAX_NAME(dir->i_sb->s_blocksize))
441 return -ENAMETOOLONG; 453 return -ENAMETOOLONG;
442 454
443 /* each entry has unique key. compose it */ 455 /* each entry has unique key. compose it */
444 make_cpu_key (&entry_key, dir, 456 make_cpu_key(&entry_key, dir,
445 get_third_component (dir->i_sb, name, namelen), TYPE_DIRENTRY, 3); 457 get_third_component(dir->i_sb, name, namelen),
446 458 TYPE_DIRENTRY, 3);
447 /* get memory for composing the entry */ 459
448 buflen = DEH_SIZE + ROUND_UP (namelen); 460 /* get memory for composing the entry */
449 if (buflen > sizeof (small_buf)) { 461 buflen = DEH_SIZE + ROUND_UP(namelen);
450 buffer = reiserfs_kmalloc (buflen, GFP_NOFS, dir->i_sb); 462 if (buflen > sizeof(small_buf)) {
451 if (buffer == 0) 463 buffer = reiserfs_kmalloc(buflen, GFP_NOFS, dir->i_sb);
452 return -ENOMEM; 464 if (buffer == 0)
453 } else 465 return -ENOMEM;
454 buffer = small_buf; 466 } else
455 467 buffer = small_buf;
456 paste_size = (get_inode_sd_version (dir) == STAT_DATA_V1) ? (DEH_SIZE + namelen) : buflen; 468
457 469 paste_size =
458 /* fill buffer : directory entry head, name[, dir objectid | , stat data | ,stat data, dir objectid ] */ 470 (get_inode_sd_version(dir) ==
459 deh = (struct reiserfs_de_head *)buffer; 471 STAT_DATA_V1) ? (DEH_SIZE + namelen) : buflen;
460 deh->deh_location = 0; /* JDM Endian safe if 0 */ 472
461 put_deh_offset( deh, cpu_key_k_offset( &entry_key ) ); 473 /* fill buffer : directory entry head, name[, dir objectid | , stat data | ,stat data, dir objectid ] */
462 deh->deh_state = 0; /* JDM Endian safe if 0 */ 474 deh = (struct reiserfs_de_head *)buffer;
463 /* put key (ino analog) to de */ 475 deh->deh_location = 0; /* JDM Endian safe if 0 */
464 deh->deh_dir_id = INODE_PKEY (inode)->k_dir_id; /* safe: k_dir_id is le */ 476 put_deh_offset(deh, cpu_key_k_offset(&entry_key));
465 deh->deh_objectid = INODE_PKEY (inode)->k_objectid; /* safe: k_objectid is le */ 477 deh->deh_state = 0; /* JDM Endian safe if 0 */
466 478 /* put key (ino analog) to de */
467 /* copy name */ 479 deh->deh_dir_id = INODE_PKEY(inode)->k_dir_id; /* safe: k_dir_id is le */
468 memcpy ((char *)(deh + 1), name, namelen); 480 deh->deh_objectid = INODE_PKEY(inode)->k_objectid; /* safe: k_objectid is le */
469 /* padd by 0s to the 4 byte boundary */ 481
470 padd_item ((char *)(deh + 1), ROUND_UP (namelen), namelen); 482 /* copy name */
471 483 memcpy((char *)(deh + 1), name, namelen);
472 /* entry is ready to be pasted into tree, set 'visibility' and 'stat data in entry' attributes */ 484 /* padd by 0s to the 4 byte boundary */
473 mark_de_without_sd (deh); 485 padd_item((char *)(deh + 1), ROUND_UP(namelen), namelen);
474 visible ? mark_de_visible (deh) : mark_de_hidden (deh); 486
475 487 /* entry is ready to be pasted into tree, set 'visibility' and 'stat data in entry' attributes */
476 /* find the proper place for the new entry */ 488 mark_de_without_sd(deh);
477 memset (bit_string, 0, sizeof (bit_string)); 489 visible ? mark_de_visible(deh) : mark_de_hidden(deh);
478 de.de_gen_number_bit_string = (char *)bit_string; 490
479 retval = reiserfs_find_entry (dir, name, namelen, &path, &de); 491 /* find the proper place for the new entry */
480 if( retval != NAME_NOT_FOUND ) { 492 memset(bit_string, 0, sizeof(bit_string));
481 if (buffer != small_buf) 493 de.de_gen_number_bit_string = (char *)bit_string;
482 reiserfs_kfree (buffer, buflen, dir->i_sb); 494 retval = reiserfs_find_entry(dir, name, namelen, &path, &de);
483 pathrelse (&path); 495 if (retval != NAME_NOT_FOUND) {
496 if (buffer != small_buf)
497 reiserfs_kfree(buffer, buflen, dir->i_sb);
498 pathrelse(&path);
499
500 if (retval == IO_ERROR) {
501 return -EIO;
502 }
503
504 if (retval != NAME_FOUND) {
505 reiserfs_warning(dir->i_sb,
506 "zam-7002:%s: \"reiserfs_find_entry\" "
507 "has returned unexpected value (%d)",
508 __FUNCTION__, retval);
509 }
510
511 return -EEXIST;
512 }
484 513
485 if ( retval == IO_ERROR ) { 514 gen_number =
486 return -EIO; 515 find_first_zero_bit((unsigned long *)bit_string,
516 MAX_GENERATION_NUMBER + 1);
517 if (gen_number > MAX_GENERATION_NUMBER) {
518 /* there is no free generation number */
519 reiserfs_warning(dir->i_sb,
520 "reiserfs_add_entry: Congratulations! we have got hash function screwed up");
521 if (buffer != small_buf)
522 reiserfs_kfree(buffer, buflen, dir->i_sb);
523 pathrelse(&path);
524 return -EBUSY;
525 }
526 /* adjust offset of directory enrty */
527 put_deh_offset(deh, SET_GENERATION_NUMBER(deh_offset(deh), gen_number));
528 set_cpu_key_k_offset(&entry_key, deh_offset(deh));
529
530 /* update max-hash-collisions counter in reiserfs_sb_info */
531 PROC_INFO_MAX(th->t_super, max_hash_collisions, gen_number);
532
533 if (gen_number != 0) { /* we need to re-search for the insertion point */
534 if (search_by_entry_key(dir->i_sb, &entry_key, &path, &de) !=
535 NAME_NOT_FOUND) {
536 reiserfs_warning(dir->i_sb,
537 "vs-7032: reiserfs_add_entry: "
538 "entry with this key (%K) already exists",
539 &entry_key);
540
541 if (buffer != small_buf)
542 reiserfs_kfree(buffer, buflen, dir->i_sb);
543 pathrelse(&path);
544 return -EBUSY;
545 }
487 } 546 }
488 547
489 if (retval != NAME_FOUND) { 548 /* perform the insertion of the entry that we have prepared */
490 reiserfs_warning (dir->i_sb, "zam-7002:%s: \"reiserfs_find_entry\" " 549 retval =
491 "has returned unexpected value (%d)", 550 reiserfs_paste_into_item(th, &path, &entry_key, dir, buffer,
492 __FUNCTION__, retval); 551 paste_size);
493 } 552 if (buffer != small_buf)
494 553 reiserfs_kfree(buffer, buflen, dir->i_sb);
495 return -EEXIST; 554 if (retval) {
496 } 555 reiserfs_check_path(&path);
497 556 return retval;
498 gen_number = find_first_zero_bit ((unsigned long *)bit_string, MAX_GENERATION_NUMBER + 1);
499 if (gen_number > MAX_GENERATION_NUMBER) {
500 /* there is no free generation number */
501 reiserfs_warning (dir->i_sb, "reiserfs_add_entry: Congratulations! we have got hash function screwed up");
502 if (buffer != small_buf)
503 reiserfs_kfree (buffer, buflen, dir->i_sb);
504 pathrelse (&path);
505 return -EBUSY;
506 }
507 /* adjust offset of directory enrty */
508 put_deh_offset(deh, SET_GENERATION_NUMBER(deh_offset(deh), gen_number));
509 set_cpu_key_k_offset (&entry_key, deh_offset(deh));
510
511 /* update max-hash-collisions counter in reiserfs_sb_info */
512 PROC_INFO_MAX( th -> t_super, max_hash_collisions, gen_number );
513
514 if (gen_number != 0) { /* we need to re-search for the insertion point */
515 if (search_by_entry_key (dir->i_sb, &entry_key, &path, &de) != NAME_NOT_FOUND) {
516 reiserfs_warning (dir->i_sb, "vs-7032: reiserfs_add_entry: "
517 "entry with this key (%K) already exists",
518 &entry_key);
519
520 if (buffer != small_buf)
521 reiserfs_kfree (buffer, buflen, dir->i_sb);
522 pathrelse (&path);
523 return -EBUSY;
524 } 557 }
525 }
526
527 /* perform the insertion of the entry that we have prepared */
528 retval = reiserfs_paste_into_item (th, &path, &entry_key, dir, buffer, paste_size);
529 if (buffer != small_buf)
530 reiserfs_kfree (buffer, buflen, dir->i_sb);
531 if (retval) {
532 reiserfs_check_path(&path) ;
533 return retval;
534 }
535 558
536 dir->i_size += paste_size; 559 dir->i_size += paste_size;
537 dir->i_mtime = dir->i_ctime = CURRENT_TIME_SEC; 560 dir->i_mtime = dir->i_ctime = CURRENT_TIME_SEC;
538 if (!S_ISDIR (inode->i_mode) && visible) 561 if (!S_ISDIR(inode->i_mode) && visible)
539 // reiserfs_mkdir or reiserfs_rename will do that by itself 562 // reiserfs_mkdir or reiserfs_rename will do that by itself
540 reiserfs_update_sd (th, dir); 563 reiserfs_update_sd(th, dir);
541 564
542 reiserfs_check_path(&path) ; 565 reiserfs_check_path(&path);
543 return 0; 566 return 0;
544} 567}
545 568
546/* quota utility function, call if you've had to abort after calling 569/* quota utility function, call if you've had to abort after calling
@@ -548,12 +571,13 @@ static int reiserfs_add_entry (struct reiserfs_transaction_handle *th, struct in
548** This should only be called on inodes that do not have stat data 571** This should only be called on inodes that do not have stat data
549** inserted into the tree yet. 572** inserted into the tree yet.
550*/ 573*/
551static int drop_new_inode(struct inode *inode) { 574static int drop_new_inode(struct inode *inode)
552 DQUOT_DROP(inode); 575{
553 make_bad_inode(inode) ; 576 DQUOT_DROP(inode);
554 inode->i_flags |= S_NOQUOTA; 577 make_bad_inode(inode);
555 iput(inode) ; 578 inode->i_flags |= S_NOQUOTA;
556 return 0 ; 579 iput(inode);
580 return 0;
557} 581}
558 582
559/* utility function that does setup for reiserfs_new_inode. 583/* utility function that does setup for reiserfs_new_inode.
@@ -561,905 +585,968 @@ static int drop_new_inode(struct inode *inode) {
561** outside of a transaction, so we had to pull some bits of 585** outside of a transaction, so we had to pull some bits of
562** reiserfs_new_inode out into this func. 586** reiserfs_new_inode out into this func.
563*/ 587*/
564static int new_inode_init(struct inode *inode, struct inode *dir, int mode) { 588static int new_inode_init(struct inode *inode, struct inode *dir, int mode)
565 589{
566 /* the quota init calls have to know who to charge the quota to, so 590
567 ** we have to set uid and gid here 591 /* the quota init calls have to know who to charge the quota to, so
568 */ 592 ** we have to set uid and gid here
569 inode->i_uid = current->fsuid; 593 */
570 inode->i_mode = mode; 594 inode->i_uid = current->fsuid;
571 595 inode->i_mode = mode;
572 if (dir->i_mode & S_ISGID) { 596
573 inode->i_gid = dir->i_gid; 597 if (dir->i_mode & S_ISGID) {
574 if (S_ISDIR(mode)) 598 inode->i_gid = dir->i_gid;
575 inode->i_mode |= S_ISGID; 599 if (S_ISDIR(mode))
576 } else { 600 inode->i_mode |= S_ISGID;
577 inode->i_gid = current->fsgid; 601 } else {
578 } 602 inode->i_gid = current->fsgid;
579 DQUOT_INIT(inode); 603 }
580 return 0 ; 604 DQUOT_INIT(inode);
605 return 0;
581} 606}
582 607
583static int reiserfs_create (struct inode * dir, struct dentry *dentry, int mode, 608static int reiserfs_create(struct inode *dir, struct dentry *dentry, int mode,
584 struct nameidata *nd) 609 struct nameidata *nd)
585{ 610{
586 int retval; 611 int retval;
587 struct inode * inode; 612 struct inode *inode;
588 /* We need blocks for transaction + (user+group)*(quotas for new inode + update of quota for directory owner) */ 613 /* We need blocks for transaction + (user+group)*(quotas for new inode + update of quota for directory owner) */
589 int jbegin_count = JOURNAL_PER_BALANCE_CNT * 2 + 2 * (REISERFS_QUOTA_INIT_BLOCKS(dir->i_sb)+REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb)); 614 int jbegin_count =
590 struct reiserfs_transaction_handle th ; 615 JOURNAL_PER_BALANCE_CNT * 2 +
591 int locked; 616 2 * (REISERFS_QUOTA_INIT_BLOCKS(dir->i_sb) +
592 617 REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb));
593 if (!(inode = new_inode(dir->i_sb))) { 618 struct reiserfs_transaction_handle th;
594 return -ENOMEM ; 619 int locked;
595 } 620
596 new_inode_init(inode, dir, mode); 621 if (!(inode = new_inode(dir->i_sb))) {
597 622 return -ENOMEM;
598 locked = reiserfs_cache_default_acl (dir); 623 }
599 624 new_inode_init(inode, dir, mode);
600 reiserfs_write_lock(dir->i_sb);
601
602 if (locked)
603 reiserfs_write_lock_xattrs (dir->i_sb);
604
605 retval = journal_begin(&th, dir->i_sb, jbegin_count);
606 if (retval) {
607 drop_new_inode (inode);
608 goto out_failed;
609 }
610
611 retval = reiserfs_new_inode (&th, dir, mode, NULL, 0/*i_size*/, dentry, inode);
612 if (retval)
613 goto out_failed;
614
615 if (locked) {
616 reiserfs_write_unlock_xattrs (dir->i_sb);
617 locked = 0;
618 }
619
620 inode->i_op = &reiserfs_file_inode_operations;
621 inode->i_fop = &reiserfs_file_operations;
622 inode->i_mapping->a_ops = &reiserfs_address_space_operations ;
623
624 retval = reiserfs_add_entry (&th, dir, dentry->d_name.name, dentry->d_name.len,
625 inode, 1/*visible*/);
626 if (retval) {
627 int err;
628 inode->i_nlink--;
629 reiserfs_update_sd (&th, inode);
630 err = journal_end(&th, dir->i_sb, jbegin_count) ;
631 if (err)
632 retval = err;
633 iput (inode);
634 goto out_failed;
635 }
636 reiserfs_update_inode_transaction(inode) ;
637 reiserfs_update_inode_transaction(dir) ;
638
639 d_instantiate(dentry, inode);
640 retval = journal_end(&th, dir->i_sb, jbegin_count) ;
641
642out_failed:
643 if (locked)
644 reiserfs_write_unlock_xattrs (dir->i_sb);
645 reiserfs_write_unlock(dir->i_sb);
646 return retval;
647}
648 625
626 locked = reiserfs_cache_default_acl(dir);
649 627
650static int reiserfs_mknod (struct inode * dir, struct dentry *dentry, int mode, dev_t rdev) 628 reiserfs_write_lock(dir->i_sb);
651{
652 int retval;
653 struct inode * inode;
654 struct reiserfs_transaction_handle th ;
655 /* We need blocks for transaction + (user+group)*(quotas for new inode + update of quota for directory owner) */
656 int jbegin_count = JOURNAL_PER_BALANCE_CNT * 3 + 2 * (REISERFS_QUOTA_INIT_BLOCKS(dir->i_sb)+REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb));
657 int locked;
658 629
659 if (!new_valid_dev(rdev)) 630 if (locked)
660 return -EINVAL; 631 reiserfs_write_lock_xattrs(dir->i_sb);
632
633 retval = journal_begin(&th, dir->i_sb, jbegin_count);
634 if (retval) {
635 drop_new_inode(inode);
636 goto out_failed;
637 }
638
639 retval =
640 reiserfs_new_inode(&th, dir, mode, NULL, 0 /*i_size */ , dentry,
641 inode);
642 if (retval)
643 goto out_failed;
644
645 if (locked) {
646 reiserfs_write_unlock_xattrs(dir->i_sb);
647 locked = 0;
648 }
649
650 inode->i_op = &reiserfs_file_inode_operations;
651 inode->i_fop = &reiserfs_file_operations;
652 inode->i_mapping->a_ops = &reiserfs_address_space_operations;
653
654 retval =
655 reiserfs_add_entry(&th, dir, dentry->d_name.name,
656 dentry->d_name.len, inode, 1 /*visible */ );
657 if (retval) {
658 int err;
659 inode->i_nlink--;
660 reiserfs_update_sd(&th, inode);
661 err = journal_end(&th, dir->i_sb, jbegin_count);
662 if (err)
663 retval = err;
664 iput(inode);
665 goto out_failed;
666 }
667 reiserfs_update_inode_transaction(inode);
668 reiserfs_update_inode_transaction(dir);
661 669
662 if (!(inode = new_inode(dir->i_sb))) { 670 d_instantiate(dentry, inode);
663 return -ENOMEM ; 671 retval = journal_end(&th, dir->i_sb, jbegin_count);
664 }
665 new_inode_init(inode, dir, mode);
666 672
667 locked = reiserfs_cache_default_acl (dir); 673 out_failed:
674 if (locked)
675 reiserfs_write_unlock_xattrs(dir->i_sb);
676 reiserfs_write_unlock(dir->i_sb);
677 return retval;
678}
668 679
669 reiserfs_write_lock(dir->i_sb); 680static int reiserfs_mknod(struct inode *dir, struct dentry *dentry, int mode,
681 dev_t rdev)
682{
683 int retval;
684 struct inode *inode;
685 struct reiserfs_transaction_handle th;
686 /* We need blocks for transaction + (user+group)*(quotas for new inode + update of quota for directory owner) */
687 int jbegin_count =
688 JOURNAL_PER_BALANCE_CNT * 3 +
689 2 * (REISERFS_QUOTA_INIT_BLOCKS(dir->i_sb) +
690 REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb));
691 int locked;
692
693 if (!new_valid_dev(rdev))
694 return -EINVAL;
695
696 if (!(inode = new_inode(dir->i_sb))) {
697 return -ENOMEM;
698 }
699 new_inode_init(inode, dir, mode);
670 700
671 if (locked) 701 locked = reiserfs_cache_default_acl(dir);
672 reiserfs_write_lock_xattrs (dir->i_sb);
673 702
674 retval = journal_begin(&th, dir->i_sb, jbegin_count) ; 703 reiserfs_write_lock(dir->i_sb);
675 if (retval) {
676 drop_new_inode (inode);
677 goto out_failed;
678 }
679 704
680 retval = reiserfs_new_inode (&th, dir, mode, NULL, 0/*i_size*/, dentry, inode); 705 if (locked)
681 if (retval) { 706 reiserfs_write_lock_xattrs(dir->i_sb);
682 goto out_failed;
683 }
684 707
685 if (locked) { 708 retval = journal_begin(&th, dir->i_sb, jbegin_count);
686 reiserfs_write_unlock_xattrs (dir->i_sb); 709 if (retval) {
687 locked = 0; 710 drop_new_inode(inode);
688 } 711 goto out_failed;
712 }
689 713
714 retval =
715 reiserfs_new_inode(&th, dir, mode, NULL, 0 /*i_size */ , dentry,
716 inode);
717 if (retval) {
718 goto out_failed;
719 }
690 720
691 inode->i_op = &reiserfs_special_inode_operations; 721 if (locked) {
692 init_special_inode(inode, inode->i_mode, rdev) ; 722 reiserfs_write_unlock_xattrs(dir->i_sb);
723 locked = 0;
724 }
693 725
694 //FIXME: needed for block and char devices only 726 inode->i_op = &reiserfs_special_inode_operations;
695 reiserfs_update_sd (&th, inode); 727 init_special_inode(inode, inode->i_mode, rdev);
728
729 //FIXME: needed for block and char devices only
730 reiserfs_update_sd(&th, inode);
731
732 reiserfs_update_inode_transaction(inode);
733 reiserfs_update_inode_transaction(dir);
734
735 retval =
736 reiserfs_add_entry(&th, dir, dentry->d_name.name,
737 dentry->d_name.len, inode, 1 /*visible */ );
738 if (retval) {
739 int err;
740 inode->i_nlink--;
741 reiserfs_update_sd(&th, inode);
742 err = journal_end(&th, dir->i_sb, jbegin_count);
743 if (err)
744 retval = err;
745 iput(inode);
746 goto out_failed;
747 }
696 748
697 reiserfs_update_inode_transaction(inode) ; 749 d_instantiate(dentry, inode);
698 reiserfs_update_inode_transaction(dir) ; 750 retval = journal_end(&th, dir->i_sb, jbegin_count);
699 751
700 retval = reiserfs_add_entry (&th, dir, dentry->d_name.name, dentry->d_name.len, 752 out_failed:
701 inode, 1/*visible*/); 753 if (locked)
702 if (retval) { 754 reiserfs_write_unlock_xattrs(dir->i_sb);
703 int err; 755 reiserfs_write_unlock(dir->i_sb);
704 inode->i_nlink--; 756 return retval;
705 reiserfs_update_sd (&th, inode);
706 err = journal_end(&th, dir->i_sb, jbegin_count) ;
707 if (err)
708 retval = err;
709 iput (inode);
710 goto out_failed;
711 }
712
713 d_instantiate(dentry, inode);
714 retval = journal_end(&th, dir->i_sb, jbegin_count) ;
715
716out_failed:
717 if (locked)
718 reiserfs_write_unlock_xattrs (dir->i_sb);
719 reiserfs_write_unlock(dir->i_sb);
720 return retval;
721} 757}
722 758
723 759static int reiserfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
724static int reiserfs_mkdir (struct inode * dir, struct dentry *dentry, int mode)
725{ 760{
726 int retval; 761 int retval;
727 struct inode * inode; 762 struct inode *inode;
728 struct reiserfs_transaction_handle th ; 763 struct reiserfs_transaction_handle th;
729 /* We need blocks for transaction + (user+group)*(quotas for new inode + update of quota for directory owner) */ 764 /* We need blocks for transaction + (user+group)*(quotas for new inode + update of quota for directory owner) */
730 int jbegin_count = JOURNAL_PER_BALANCE_CNT * 3 + 2 * (REISERFS_QUOTA_INIT_BLOCKS(dir->i_sb)+REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb)); 765 int jbegin_count =
731 int locked; 766 JOURNAL_PER_BALANCE_CNT * 3 +
767 2 * (REISERFS_QUOTA_INIT_BLOCKS(dir->i_sb) +
768 REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb));
769 int locked;
732 770
733#ifdef DISPLACE_NEW_PACKING_LOCALITIES 771#ifdef DISPLACE_NEW_PACKING_LOCALITIES
734 /* set flag that new packing locality created and new blocks for the content * of that directory are not displaced yet */ 772 /* set flag that new packing locality created and new blocks for the content * of that directory are not displaced yet */
735 REISERFS_I(dir)->new_packing_locality = 1; 773 REISERFS_I(dir)->new_packing_locality = 1;
736#endif 774#endif
737 mode = S_IFDIR | mode; 775 mode = S_IFDIR | mode;
738 if (!(inode = new_inode(dir->i_sb))) { 776 if (!(inode = new_inode(dir->i_sb))) {
739 return -ENOMEM ; 777 return -ENOMEM;
740 } 778 }
741 new_inode_init(inode, dir, mode); 779 new_inode_init(inode, dir, mode);
742 780
743 locked = reiserfs_cache_default_acl (dir); 781 locked = reiserfs_cache_default_acl(dir);
744 782
745 reiserfs_write_lock(dir->i_sb); 783 reiserfs_write_lock(dir->i_sb);
746 if (locked) 784 if (locked)
747 reiserfs_write_lock_xattrs (dir->i_sb); 785 reiserfs_write_lock_xattrs(dir->i_sb);
748 786
749 retval = journal_begin(&th, dir->i_sb, jbegin_count) ; 787 retval = journal_begin(&th, dir->i_sb, jbegin_count);
750 if (retval) { 788 if (retval) {
751 drop_new_inode (inode); 789 drop_new_inode(inode);
752 goto out_failed; 790 goto out_failed;
753 } 791 }
754
755
756 /* inc the link count now, so another writer doesn't overflow it while
757 ** we sleep later on.
758 */
759 INC_DIR_INODE_NLINK(dir)
760
761 retval = reiserfs_new_inode (&th, dir, mode, NULL/*symlink*/,
762 old_format_only (dir->i_sb) ?
763 EMPTY_DIR_SIZE_V1 : EMPTY_DIR_SIZE,
764 dentry, inode);
765 if (retval) {
766 dir->i_nlink-- ;
767 goto out_failed;
768 }
769
770 if (locked) {
771 reiserfs_write_unlock_xattrs (dir->i_sb);
772 locked = 0;
773 }
774
775 reiserfs_update_inode_transaction(inode) ;
776 reiserfs_update_inode_transaction(dir) ;
777
778 inode->i_op = &reiserfs_dir_inode_operations;
779 inode->i_fop = &reiserfs_dir_operations;
780
781 // note, _this_ add_entry will not update dir's stat data
782 retval = reiserfs_add_entry (&th, dir, dentry->d_name.name, dentry->d_name.len,
783 inode, 1/*visible*/);
784 if (retval) {
785 int err;
786 inode->i_nlink = 0;
787 DEC_DIR_INODE_NLINK(dir);
788 reiserfs_update_sd (&th, inode);
789 err = journal_end(&th, dir->i_sb, jbegin_count) ;
790 if (err)
791 retval = err;
792 iput (inode);
793 goto out_failed;
794 }
795
796 // the above add_entry did not update dir's stat data
797 reiserfs_update_sd (&th, dir);
798
799 d_instantiate(dentry, inode);
800 retval = journal_end(&th, dir->i_sb, jbegin_count) ;
801out_failed:
802 if (locked)
803 reiserfs_write_unlock_xattrs (dir->i_sb);
804 reiserfs_write_unlock(dir->i_sb);
805 return retval;
806}
807 792
808static inline int reiserfs_empty_dir(struct inode *inode) { 793 /* inc the link count now, so another writer doesn't overflow it while
809 /* we can cheat because an old format dir cannot have 794 ** we sleep later on.
810 ** EMPTY_DIR_SIZE, and a new format dir cannot have 795 */
811 ** EMPTY_DIR_SIZE_V1. So, if the inode is either size, 796 INC_DIR_INODE_NLINK(dir)
812 ** regardless of disk format version, the directory is empty. 797
813 */ 798 retval = reiserfs_new_inode(&th, dir, mode, NULL /*symlink */ ,
814 if (inode->i_size != EMPTY_DIR_SIZE && 799 old_format_only(dir->i_sb) ?
815 inode->i_size != EMPTY_DIR_SIZE_V1) { 800 EMPTY_DIR_SIZE_V1 : EMPTY_DIR_SIZE,
816 return 0 ; 801 dentry, inode);
817 } 802 if (retval) {
818 return 1 ; 803 dir->i_nlink--;
804 goto out_failed;
805 }
806
807 if (locked) {
808 reiserfs_write_unlock_xattrs(dir->i_sb);
809 locked = 0;
810 }
811
812 reiserfs_update_inode_transaction(inode);
813 reiserfs_update_inode_transaction(dir);
814
815 inode->i_op = &reiserfs_dir_inode_operations;
816 inode->i_fop = &reiserfs_dir_operations;
817
818 // note, _this_ add_entry will not update dir's stat data
819 retval =
820 reiserfs_add_entry(&th, dir, dentry->d_name.name,
821 dentry->d_name.len, inode, 1 /*visible */ );
822 if (retval) {
823 int err;
824 inode->i_nlink = 0;
825 DEC_DIR_INODE_NLINK(dir);
826 reiserfs_update_sd(&th, inode);
827 err = journal_end(&th, dir->i_sb, jbegin_count);
828 if (err)
829 retval = err;
830 iput(inode);
831 goto out_failed;
832 }
833 // the above add_entry did not update dir's stat data
834 reiserfs_update_sd(&th, dir);
835
836 d_instantiate(dentry, inode);
837 retval = journal_end(&th, dir->i_sb, jbegin_count);
838 out_failed:
839 if (locked)
840 reiserfs_write_unlock_xattrs(dir->i_sb);
841 reiserfs_write_unlock(dir->i_sb);
842 return retval;
819} 843}
820 844
821static int reiserfs_rmdir (struct inode * dir, struct dentry *dentry) 845static inline int reiserfs_empty_dir(struct inode *inode)
822{ 846{
823 int retval, err; 847 /* we can cheat because an old format dir cannot have
824 struct inode * inode; 848 ** EMPTY_DIR_SIZE, and a new format dir cannot have
825 struct reiserfs_transaction_handle th ; 849 ** EMPTY_DIR_SIZE_V1. So, if the inode is either size,
826 int jbegin_count; 850 ** regardless of disk format version, the directory is empty.
827 INITIALIZE_PATH (path); 851 */
828 struct reiserfs_dir_entry de; 852 if (inode->i_size != EMPTY_DIR_SIZE &&
829 853 inode->i_size != EMPTY_DIR_SIZE_V1) {
830 854 return 0;
831 /* we will be doing 2 balancings and update 2 stat data, we change quotas 855 }
832 * of the owner of the directory and of the owner of the parent directory. 856 return 1;
833 * The quota structure is possibly deleted only on last iput => outside
834 * of this transaction */
835 jbegin_count = JOURNAL_PER_BALANCE_CNT * 2 + 2 + 4 * REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb);
836
837 reiserfs_write_lock(dir->i_sb);
838 retval = journal_begin(&th, dir->i_sb, jbegin_count) ;
839 if (retval)
840 goto out_rmdir;
841
842 de.de_gen_number_bit_string = NULL;
843 if ( (retval = reiserfs_find_entry (dir, dentry->d_name.name, dentry->d_name.len, &path, &de)) == NAME_NOT_FOUND) {
844 retval = -ENOENT;
845 goto end_rmdir;
846 } else if ( retval == IO_ERROR) {
847 retval = -EIO;
848 goto end_rmdir;
849 }
850
851 inode = dentry->d_inode;
852
853 reiserfs_update_inode_transaction(inode) ;
854 reiserfs_update_inode_transaction(dir) ;
855
856 if (de.de_objectid != inode->i_ino) {
857 // FIXME: compare key of an object and a key found in the
858 // entry
859 retval = -EIO;
860 goto end_rmdir;
861 }
862 if (!reiserfs_empty_dir(inode)) {
863 retval = -ENOTEMPTY;
864 goto end_rmdir;
865 }
866
867 /* cut entry from dir directory */
868 retval = reiserfs_cut_from_item (&th, &path, &(de.de_entry_key), dir,
869 NULL, /* page */
870 0/*new file size - not used here*/);
871 if (retval < 0)
872 goto end_rmdir;
873
874 if ( inode->i_nlink != 2 && inode->i_nlink != 1 )
875 reiserfs_warning (inode->i_sb, "%s: empty directory has nlink "
876 "!= 2 (%d)", __FUNCTION__, inode->i_nlink);
877
878 inode->i_nlink = 0;
879 inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC;
880 reiserfs_update_sd (&th, inode);
881
882 DEC_DIR_INODE_NLINK(dir)
883 dir->i_size -= (DEH_SIZE + de.de_entrylen);
884 reiserfs_update_sd (&th, dir);
885
886 /* prevent empty directory from getting lost */
887 add_save_link (&th, inode, 0/* not truncate */);
888
889 retval = journal_end(&th, dir->i_sb, jbegin_count) ;
890 reiserfs_check_path(&path) ;
891out_rmdir:
892 reiserfs_write_unlock(dir->i_sb);
893 return retval;
894
895 end_rmdir:
896 /* we must release path, because we did not call
897 reiserfs_cut_from_item, or reiserfs_cut_from_item does not
898 release path if operation was not complete */
899 pathrelse (&path);
900 err = journal_end(&th, dir->i_sb, jbegin_count) ;
901 reiserfs_write_unlock(dir->i_sb);
902 return err ? err : retval;
903} 857}
904 858
905static int reiserfs_unlink (struct inode * dir, struct dentry *dentry) 859static int reiserfs_rmdir(struct inode *dir, struct dentry *dentry)
906{ 860{
907 int retval, err; 861 int retval, err;
908 struct inode * inode; 862 struct inode *inode;
909 struct reiserfs_dir_entry de; 863 struct reiserfs_transaction_handle th;
910 INITIALIZE_PATH (path); 864 int jbegin_count;
911 struct reiserfs_transaction_handle th ; 865 INITIALIZE_PATH(path);
912 int jbegin_count; 866 struct reiserfs_dir_entry de;
913 unsigned long savelink; 867
914 868 /* we will be doing 2 balancings and update 2 stat data, we change quotas
915 inode = dentry->d_inode; 869 * of the owner of the directory and of the owner of the parent directory.
916 870 * The quota structure is possibly deleted only on last iput => outside
917 /* in this transaction we can be doing at max two balancings and update 871 * of this transaction */
918 * two stat datas, we change quotas of the owner of the directory and of 872 jbegin_count =
919 * the owner of the parent directory. The quota structure is possibly 873 JOURNAL_PER_BALANCE_CNT * 2 + 2 +
920 * deleted only on iput => outside of this transaction */ 874 4 * REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb);
921 jbegin_count = JOURNAL_PER_BALANCE_CNT * 2 + 2 + 4 * REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb); 875
922 876 reiserfs_write_lock(dir->i_sb);
923 reiserfs_write_lock(dir->i_sb); 877 retval = journal_begin(&th, dir->i_sb, jbegin_count);
924 retval = journal_begin(&th, dir->i_sb, jbegin_count) ; 878 if (retval)
925 if (retval) 879 goto out_rmdir;
926 goto out_unlink; 880
927 881 de.de_gen_number_bit_string = NULL;
928 de.de_gen_number_bit_string = NULL; 882 if ((retval =
929 if ( (retval = reiserfs_find_entry (dir, dentry->d_name.name, dentry->d_name.len, &path, &de)) == NAME_NOT_FOUND) { 883 reiserfs_find_entry(dir, dentry->d_name.name, dentry->d_name.len,
930 retval = -ENOENT; 884 &path, &de)) == NAME_NOT_FOUND) {
931 goto end_unlink; 885 retval = -ENOENT;
932 } else if (retval == IO_ERROR) { 886 goto end_rmdir;
933 retval = -EIO; 887 } else if (retval == IO_ERROR) {
934 goto end_unlink; 888 retval = -EIO;
935 } 889 goto end_rmdir;
936 890 }
937 reiserfs_update_inode_transaction(inode) ; 891
938 reiserfs_update_inode_transaction(dir) ; 892 inode = dentry->d_inode;
939 893
940 if (de.de_objectid != inode->i_ino) { 894 reiserfs_update_inode_transaction(inode);
941 // FIXME: compare key of an object and a key found in the 895 reiserfs_update_inode_transaction(dir);
942 // entry 896
943 retval = -EIO; 897 if (de.de_objectid != inode->i_ino) {
944 goto end_unlink; 898 // FIXME: compare key of an object and a key found in the
945 } 899 // entry
946 900 retval = -EIO;
947 if (!inode->i_nlink) { 901 goto end_rmdir;
948 reiserfs_warning (inode->i_sb, "%s: deleting nonexistent file " 902 }
949 "(%s:%lu), %d", __FUNCTION__, 903 if (!reiserfs_empty_dir(inode)) {
950 reiserfs_bdevname (inode->i_sb), inode->i_ino, 904 retval = -ENOTEMPTY;
951 inode->i_nlink); 905 goto end_rmdir;
952 inode->i_nlink = 1; 906 }
953 } 907
954 908 /* cut entry from dir directory */
955 inode->i_nlink--; 909 retval = reiserfs_cut_from_item(&th, &path, &(de.de_entry_key), dir, NULL, /* page */
956 910 0 /*new file size - not used here */ );
957 /* 911 if (retval < 0)
958 * we schedule before doing the add_save_link call, save the link 912 goto end_rmdir;
959 * count so we don't race 913
960 */ 914 if (inode->i_nlink != 2 && inode->i_nlink != 1)
961 savelink = inode->i_nlink; 915 reiserfs_warning(inode->i_sb, "%s: empty directory has nlink "
962 916 "!= 2 (%d)", __FUNCTION__, inode->i_nlink);
963 917
964 retval = reiserfs_cut_from_item (&th, &path, &(de.de_entry_key), dir, NULL, 0); 918 inode->i_nlink = 0;
965 if (retval < 0) { 919 inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC;
966 inode->i_nlink++; 920 reiserfs_update_sd(&th, inode);
967 goto end_unlink; 921
968 } 922 DEC_DIR_INODE_NLINK(dir)
969 inode->i_ctime = CURRENT_TIME_SEC; 923 dir->i_size -= (DEH_SIZE + de.de_entrylen);
970 reiserfs_update_sd (&th, inode); 924 reiserfs_update_sd(&th, dir);
971 925
972 dir->i_size -= (de.de_entrylen + DEH_SIZE); 926 /* prevent empty directory from getting lost */
973 dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC; 927 add_save_link(&th, inode, 0 /* not truncate */ );
974 reiserfs_update_sd (&th, dir); 928
975 929 retval = journal_end(&th, dir->i_sb, jbegin_count);
976 if (!savelink) 930 reiserfs_check_path(&path);
977 /* prevent file from getting lost */ 931 out_rmdir:
978 add_save_link (&th, inode, 0/* not truncate */); 932 reiserfs_write_unlock(dir->i_sb);
979 933 return retval;
980 retval = journal_end(&th, dir->i_sb, jbegin_count) ; 934
981 reiserfs_check_path(&path) ; 935 end_rmdir:
982 reiserfs_write_unlock(dir->i_sb); 936 /* we must release path, because we did not call
983 return retval; 937 reiserfs_cut_from_item, or reiserfs_cut_from_item does not
984 938 release path if operation was not complete */
985 end_unlink: 939 pathrelse(&path);
986 pathrelse (&path); 940 err = journal_end(&th, dir->i_sb, jbegin_count);
987 err = journal_end(&th, dir->i_sb, jbegin_count) ; 941 reiserfs_write_unlock(dir->i_sb);
988 reiserfs_check_path(&path) ; 942 return err ? err : retval;
989 if (err)
990 retval = err;
991out_unlink:
992 reiserfs_write_unlock(dir->i_sb);
993 return retval;
994} 943}
995 944
996static int reiserfs_symlink (struct inode * parent_dir, 945static int reiserfs_unlink(struct inode *dir, struct dentry *dentry)
997 struct dentry * dentry, const char * symname)
998{ 946{
999 int retval; 947 int retval, err;
1000 struct inode * inode; 948 struct inode *inode;
1001 char * name; 949 struct reiserfs_dir_entry de;
1002 int item_len; 950 INITIALIZE_PATH(path);
1003 struct reiserfs_transaction_handle th ; 951 struct reiserfs_transaction_handle th;
1004 int mode = S_IFLNK | S_IRWXUGO; 952 int jbegin_count;
1005 /* We need blocks for transaction + (user+group)*(quotas for new inode + update of quota for directory owner) */ 953 unsigned long savelink;
1006 int jbegin_count = JOURNAL_PER_BALANCE_CNT * 3 + 2 * (REISERFS_QUOTA_INIT_BLOCKS(parent_dir->i_sb)+REISERFS_QUOTA_TRANS_BLOCKS(parent_dir->i_sb)); 954
1007 955 inode = dentry->d_inode;
1008 if (!(inode = new_inode(parent_dir->i_sb))) { 956
1009 return -ENOMEM ; 957 /* in this transaction we can be doing at max two balancings and update
1010 } 958 * two stat datas, we change quotas of the owner of the directory and of
1011 new_inode_init(inode, parent_dir, mode); 959 * the owner of the parent directory. The quota structure is possibly
1012 960 * deleted only on iput => outside of this transaction */
1013 reiserfs_write_lock(parent_dir->i_sb); 961 jbegin_count =
1014 item_len = ROUND_UP (strlen (symname)); 962 JOURNAL_PER_BALANCE_CNT * 2 + 2 +
1015 if (item_len > MAX_DIRECT_ITEM_LEN (parent_dir->i_sb->s_blocksize)) { 963 4 * REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb);
1016 retval = -ENAMETOOLONG; 964
1017 drop_new_inode(inode); 965 reiserfs_write_lock(dir->i_sb);
1018 goto out_failed; 966 retval = journal_begin(&th, dir->i_sb, jbegin_count);
1019 } 967 if (retval)
1020 968 goto out_unlink;
1021 name = reiserfs_kmalloc (item_len, GFP_NOFS, parent_dir->i_sb); 969
1022 if (!name) { 970 de.de_gen_number_bit_string = NULL;
1023 drop_new_inode(inode); 971 if ((retval =
1024 retval = -ENOMEM; 972 reiserfs_find_entry(dir, dentry->d_name.name, dentry->d_name.len,
1025 goto out_failed; 973 &path, &de)) == NAME_NOT_FOUND) {
1026 } 974 retval = -ENOENT;
1027 memcpy (name, symname, strlen (symname)); 975 goto end_unlink;
1028 padd_item (name, item_len, strlen (symname)); 976 } else if (retval == IO_ERROR) {
1029 977 retval = -EIO;
1030 /* We would inherit the default ACL here, but symlinks don't get ACLs */ 978 goto end_unlink;
1031 979 }
1032 retval = journal_begin(&th, parent_dir->i_sb, jbegin_count) ; 980
1033 if (retval) { 981 reiserfs_update_inode_transaction(inode);
1034 drop_new_inode (inode); 982 reiserfs_update_inode_transaction(dir);
1035 reiserfs_kfree (name, item_len, parent_dir->i_sb); 983
1036 goto out_failed; 984 if (de.de_objectid != inode->i_ino) {
1037 } 985 // FIXME: compare key of an object and a key found in the
1038 986 // entry
1039 retval = reiserfs_new_inode (&th, parent_dir, mode, name, strlen (symname), 987 retval = -EIO;
1040 dentry, inode); 988 goto end_unlink;
1041 reiserfs_kfree (name, item_len, parent_dir->i_sb); 989 }
1042 if (retval) { /* reiserfs_new_inode iputs for us */ 990
1043 goto out_failed; 991 if (!inode->i_nlink) {
1044 } 992 reiserfs_warning(inode->i_sb, "%s: deleting nonexistent file "
1045 993 "(%s:%lu), %d", __FUNCTION__,
1046 reiserfs_update_inode_transaction(inode) ; 994 reiserfs_bdevname(inode->i_sb), inode->i_ino,
1047 reiserfs_update_inode_transaction(parent_dir) ; 995 inode->i_nlink);
1048 996 inode->i_nlink = 1;
1049 inode->i_op = &reiserfs_symlink_inode_operations; 997 }
1050 inode->i_mapping->a_ops = &reiserfs_address_space_operations; 998
1051
1052 // must be sure this inode is written with this transaction
1053 //
1054 //reiserfs_update_sd (&th, inode, READ_BLOCKS);
1055
1056 retval = reiserfs_add_entry (&th, parent_dir, dentry->d_name.name,
1057 dentry->d_name.len, inode, 1/*visible*/);
1058 if (retval) {
1059 int err;
1060 inode->i_nlink--; 999 inode->i_nlink--;
1061 reiserfs_update_sd (&th, inode); 1000
1062 err = journal_end(&th, parent_dir->i_sb, jbegin_count) ; 1001 /*
1002 * we schedule before doing the add_save_link call, save the link
1003 * count so we don't race
1004 */
1005 savelink = inode->i_nlink;
1006
1007 retval =
1008 reiserfs_cut_from_item(&th, &path, &(de.de_entry_key), dir, NULL,
1009 0);
1010 if (retval < 0) {
1011 inode->i_nlink++;
1012 goto end_unlink;
1013 }
1014 inode->i_ctime = CURRENT_TIME_SEC;
1015 reiserfs_update_sd(&th, inode);
1016
1017 dir->i_size -= (de.de_entrylen + DEH_SIZE);
1018 dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC;
1019 reiserfs_update_sd(&th, dir);
1020
1021 if (!savelink)
1022 /* prevent file from getting lost */
1023 add_save_link(&th, inode, 0 /* not truncate */ );
1024
1025 retval = journal_end(&th, dir->i_sb, jbegin_count);
1026 reiserfs_check_path(&path);
1027 reiserfs_write_unlock(dir->i_sb);
1028 return retval;
1029
1030 end_unlink:
1031 pathrelse(&path);
1032 err = journal_end(&th, dir->i_sb, jbegin_count);
1033 reiserfs_check_path(&path);
1063 if (err) 1034 if (err)
1064 retval = err; 1035 retval = err;
1065 iput (inode); 1036 out_unlink:
1066 goto out_failed; 1037 reiserfs_write_unlock(dir->i_sb);
1067 } 1038 return retval;
1068
1069 d_instantiate(dentry, inode);
1070 retval = journal_end(&th, parent_dir->i_sb, jbegin_count) ;
1071out_failed:
1072 reiserfs_write_unlock(parent_dir->i_sb);
1073 return retval;
1074} 1039}
1075 1040
1076static int reiserfs_link (struct dentry * old_dentry, struct inode * dir, struct dentry * dentry) 1041static int reiserfs_symlink(struct inode *parent_dir,
1042 struct dentry *dentry, const char *symname)
1077{ 1043{
1078 int retval; 1044 int retval;
1079 struct inode *inode = old_dentry->d_inode; 1045 struct inode *inode;
1080 struct reiserfs_transaction_handle th ; 1046 char *name;
1081 /* We need blocks for transaction + update of quotas for the owners of the directory */ 1047 int item_len;
1082 int jbegin_count = JOURNAL_PER_BALANCE_CNT * 3 + 2 * REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb); 1048 struct reiserfs_transaction_handle th;
1083 1049 int mode = S_IFLNK | S_IRWXUGO;
1084 reiserfs_write_lock(dir->i_sb); 1050 /* We need blocks for transaction + (user+group)*(quotas for new inode + update of quota for directory owner) */
1085 if (inode->i_nlink >= REISERFS_LINK_MAX) { 1051 int jbegin_count =
1086 //FIXME: sd_nlink is 32 bit for new files 1052 JOURNAL_PER_BALANCE_CNT * 3 +
1087 reiserfs_write_unlock(dir->i_sb); 1053 2 * (REISERFS_QUOTA_INIT_BLOCKS(parent_dir->i_sb) +
1088 return -EMLINK; 1054 REISERFS_QUOTA_TRANS_BLOCKS(parent_dir->i_sb));
1089 } 1055
1090 if (inode->i_nlink == 0) { 1056 if (!(inode = new_inode(parent_dir->i_sb))) {
1091 reiserfs_write_unlock(dir->i_sb); 1057 return -ENOMEM;
1092 return -ENOENT; 1058 }
1093 } 1059 new_inode_init(inode, parent_dir, mode);
1094 1060
1095 /* inc before scheduling so reiserfs_unlink knows we are here */ 1061 reiserfs_write_lock(parent_dir->i_sb);
1096 inode->i_nlink++; 1062 item_len = ROUND_UP(strlen(symname));
1097 1063 if (item_len > MAX_DIRECT_ITEM_LEN(parent_dir->i_sb->s_blocksize)) {
1098 retval = journal_begin(&th, dir->i_sb, jbegin_count) ; 1064 retval = -ENAMETOOLONG;
1099 if (retval) { 1065 drop_new_inode(inode);
1100 inode->i_nlink--; 1066 goto out_failed;
1101 reiserfs_write_unlock (dir->i_sb); 1067 }
1102 return retval; 1068
1103 } 1069 name = reiserfs_kmalloc(item_len, GFP_NOFS, parent_dir->i_sb);
1104 1070 if (!name) {
1105 /* create new entry */ 1071 drop_new_inode(inode);
1106 retval = reiserfs_add_entry (&th, dir, dentry->d_name.name, dentry->d_name.len, 1072 retval = -ENOMEM;
1107 inode, 1/*visible*/); 1073 goto out_failed;
1108 1074 }
1109 reiserfs_update_inode_transaction(inode) ; 1075 memcpy(name, symname, strlen(symname));
1110 reiserfs_update_inode_transaction(dir) ; 1076 padd_item(name, item_len, strlen(symname));
1111 1077
1112 if (retval) { 1078 /* We would inherit the default ACL here, but symlinks don't get ACLs */
1113 int err; 1079
1114 inode->i_nlink--; 1080 retval = journal_begin(&th, parent_dir->i_sb, jbegin_count);
1115 err = journal_end(&th, dir->i_sb, jbegin_count) ; 1081 if (retval) {
1116 reiserfs_write_unlock(dir->i_sb); 1082 drop_new_inode(inode);
1117 return err ? err : retval; 1083 reiserfs_kfree(name, item_len, parent_dir->i_sb);
1118 } 1084 goto out_failed;
1085 }
1086
1087 retval =
1088 reiserfs_new_inode(&th, parent_dir, mode, name, strlen(symname),
1089 dentry, inode);
1090 reiserfs_kfree(name, item_len, parent_dir->i_sb);
1091 if (retval) { /* reiserfs_new_inode iputs for us */
1092 goto out_failed;
1093 }
1119 1094
1120 inode->i_ctime = CURRENT_TIME_SEC; 1095 reiserfs_update_inode_transaction(inode);
1121 reiserfs_update_sd (&th, inode); 1096 reiserfs_update_inode_transaction(parent_dir);
1097
1098 inode->i_op = &reiserfs_symlink_inode_operations;
1099 inode->i_mapping->a_ops = &reiserfs_address_space_operations;
1100
1101 // must be sure this inode is written with this transaction
1102 //
1103 //reiserfs_update_sd (&th, inode, READ_BLOCKS);
1104
1105 retval = reiserfs_add_entry(&th, parent_dir, dentry->d_name.name,
1106 dentry->d_name.len, inode, 1 /*visible */ );
1107 if (retval) {
1108 int err;
1109 inode->i_nlink--;
1110 reiserfs_update_sd(&th, inode);
1111 err = journal_end(&th, parent_dir->i_sb, jbegin_count);
1112 if (err)
1113 retval = err;
1114 iput(inode);
1115 goto out_failed;
1116 }
1122 1117
1123 atomic_inc(&inode->i_count) ; 1118 d_instantiate(dentry, inode);
1124 d_instantiate(dentry, inode); 1119 retval = journal_end(&th, parent_dir->i_sb, jbegin_count);
1125 retval = journal_end(&th, dir->i_sb, jbegin_count) ; 1120 out_failed:
1126 reiserfs_write_unlock(dir->i_sb); 1121 reiserfs_write_unlock(parent_dir->i_sb);
1127 return retval; 1122 return retval;
1128} 1123}
1129 1124
1125static int reiserfs_link(struct dentry *old_dentry, struct inode *dir,
1126 struct dentry *dentry)
1127{
1128 int retval;
1129 struct inode *inode = old_dentry->d_inode;
1130 struct reiserfs_transaction_handle th;
1131 /* We need blocks for transaction + update of quotas for the owners of the directory */
1132 int jbegin_count =
1133 JOURNAL_PER_BALANCE_CNT * 3 +
1134 2 * REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb);
1135
1136 reiserfs_write_lock(dir->i_sb);
1137 if (inode->i_nlink >= REISERFS_LINK_MAX) {
1138 //FIXME: sd_nlink is 32 bit for new files
1139 reiserfs_write_unlock(dir->i_sb);
1140 return -EMLINK;
1141 }
1142 if (inode->i_nlink == 0) {
1143 reiserfs_write_unlock(dir->i_sb);
1144 return -ENOENT;
1145 }
1146
1147 /* inc before scheduling so reiserfs_unlink knows we are here */
1148 inode->i_nlink++;
1149
1150 retval = journal_begin(&th, dir->i_sb, jbegin_count);
1151 if (retval) {
1152 inode->i_nlink--;
1153 reiserfs_write_unlock(dir->i_sb);
1154 return retval;
1155 }
1156
1157 /* create new entry */
1158 retval =
1159 reiserfs_add_entry(&th, dir, dentry->d_name.name,
1160 dentry->d_name.len, inode, 1 /*visible */ );
1161
1162 reiserfs_update_inode_transaction(inode);
1163 reiserfs_update_inode_transaction(dir);
1164
1165 if (retval) {
1166 int err;
1167 inode->i_nlink--;
1168 err = journal_end(&th, dir->i_sb, jbegin_count);
1169 reiserfs_write_unlock(dir->i_sb);
1170 return err ? err : retval;
1171 }
1172
1173 inode->i_ctime = CURRENT_TIME_SEC;
1174 reiserfs_update_sd(&th, inode);
1175
1176 atomic_inc(&inode->i_count);
1177 d_instantiate(dentry, inode);
1178 retval = journal_end(&th, dir->i_sb, jbegin_count);
1179 reiserfs_write_unlock(dir->i_sb);
1180 return retval;
1181}
1130 1182
1131// de contains information pointing to an entry which 1183// de contains information pointing to an entry which
1132static int de_still_valid (const char * name, int len, struct reiserfs_dir_entry * de) 1184static int de_still_valid(const char *name, int len,
1185 struct reiserfs_dir_entry *de)
1133{ 1186{
1134 struct reiserfs_dir_entry tmp = *de; 1187 struct reiserfs_dir_entry tmp = *de;
1135 1188
1136 // recalculate pointer to name and name length 1189 // recalculate pointer to name and name length
1137 set_de_name_and_namelen (&tmp); 1190 set_de_name_and_namelen(&tmp);
1138 // FIXME: could check more 1191 // FIXME: could check more
1139 if (tmp.de_namelen != len || memcmp (name, de->de_name, len)) 1192 if (tmp.de_namelen != len || memcmp(name, de->de_name, len))
1140 return 0; 1193 return 0;
1141 return 1; 1194 return 1;
1142} 1195}
1143 1196
1144 1197static int entry_points_to_object(const char *name, int len,
1145static int entry_points_to_object (const char * name, int len, struct reiserfs_dir_entry * de, struct inode * inode) 1198 struct reiserfs_dir_entry *de,
1199 struct inode *inode)
1146{ 1200{
1147 if (!de_still_valid (name, len, de)) 1201 if (!de_still_valid(name, len, de))
1148 return 0; 1202 return 0;
1149 1203
1150 if (inode) { 1204 if (inode) {
1151 if (!de_visible (de->de_deh + de->de_entry_num)) 1205 if (!de_visible(de->de_deh + de->de_entry_num))
1152 reiserfs_panic (NULL, "vs-7042: entry_points_to_object: entry must be visible"); 1206 reiserfs_panic(NULL,
1153 return (de->de_objectid == inode->i_ino) ? 1 : 0; 1207 "vs-7042: entry_points_to_object: entry must be visible");
1154 } 1208 return (de->de_objectid == inode->i_ino) ? 1 : 0;
1209 }
1155 1210
1156 /* this must be added hidden entry */ 1211 /* this must be added hidden entry */
1157 if (de_visible (de->de_deh + de->de_entry_num)) 1212 if (de_visible(de->de_deh + de->de_entry_num))
1158 reiserfs_panic (NULL, "vs-7043: entry_points_to_object: entry must be visible"); 1213 reiserfs_panic(NULL,
1214 "vs-7043: entry_points_to_object: entry must be visible");
1159 1215
1160 return 1; 1216 return 1;
1161} 1217}
1162 1218
1163
1164/* sets key of objectid the entry has to point to */ 1219/* sets key of objectid the entry has to point to */
1165static void set_ino_in_dir_entry (struct reiserfs_dir_entry * de, struct reiserfs_key * key) 1220static void set_ino_in_dir_entry(struct reiserfs_dir_entry *de,
1221 struct reiserfs_key *key)
1166{ 1222{
1167 /* JDM These operations are endian safe - both are le */ 1223 /* JDM These operations are endian safe - both are le */
1168 de->de_deh[de->de_entry_num].deh_dir_id = key->k_dir_id; 1224 de->de_deh[de->de_entry_num].deh_dir_id = key->k_dir_id;
1169 de->de_deh[de->de_entry_num].deh_objectid = key->k_objectid; 1225 de->de_deh[de->de_entry_num].deh_objectid = key->k_objectid;
1170} 1226}
1171 1227
1172
1173/* 1228/*
1174 * process, that is going to call fix_nodes/do_balance must hold only 1229 * process, that is going to call fix_nodes/do_balance must hold only
1175 * one path. If it holds 2 or more, it can get into endless waiting in 1230 * one path. If it holds 2 or more, it can get into endless waiting in
1176 * get_empty_nodes or its clones 1231 * get_empty_nodes or its clones
1177 */ 1232 */
1178static int reiserfs_rename (struct inode * old_dir, struct dentry *old_dentry, 1233static int reiserfs_rename(struct inode *old_dir, struct dentry *old_dentry,
1179 struct inode * new_dir, struct dentry *new_dentry) 1234 struct inode *new_dir, struct dentry *new_dentry)
1180{ 1235{
1181 int retval; 1236 int retval;
1182 INITIALIZE_PATH (old_entry_path); 1237 INITIALIZE_PATH(old_entry_path);
1183 INITIALIZE_PATH (new_entry_path); 1238 INITIALIZE_PATH(new_entry_path);
1184 INITIALIZE_PATH (dot_dot_entry_path); 1239 INITIALIZE_PATH(dot_dot_entry_path);
1185 struct item_head new_entry_ih, old_entry_ih, dot_dot_ih ; 1240 struct item_head new_entry_ih, old_entry_ih, dot_dot_ih;
1186 struct reiserfs_dir_entry old_de, new_de, dot_dot_de; 1241 struct reiserfs_dir_entry old_de, new_de, dot_dot_de;
1187 struct inode * old_inode, * new_dentry_inode; 1242 struct inode *old_inode, *new_dentry_inode;
1188 struct reiserfs_transaction_handle th ; 1243 struct reiserfs_transaction_handle th;
1189 int jbegin_count ; 1244 int jbegin_count;
1190 umode_t old_inode_mode; 1245 umode_t old_inode_mode;
1191 unsigned long savelink = 1; 1246 unsigned long savelink = 1;
1192 struct timespec ctime; 1247 struct timespec ctime;
1193 1248
1194 /* three balancings: (1) old name removal, (2) new name insertion 1249 /* three balancings: (1) old name removal, (2) new name insertion
1195 and (3) maybe "save" link insertion 1250 and (3) maybe "save" link insertion
1196 stat data updates: (1) old directory, 1251 stat data updates: (1) old directory,
1197 (2) new directory and (3) maybe old object stat data (when it is 1252 (2) new directory and (3) maybe old object stat data (when it is
1198 directory) and (4) maybe stat data of object to which new entry 1253 directory) and (4) maybe stat data of object to which new entry
1199 pointed initially and (5) maybe block containing ".." of 1254 pointed initially and (5) maybe block containing ".." of
1200 renamed directory 1255 renamed directory
1201 quota updates: two parent directories */ 1256 quota updates: two parent directories */
1202 jbegin_count = JOURNAL_PER_BALANCE_CNT * 3 + 5 + 4 * REISERFS_QUOTA_TRANS_BLOCKS(old_dir->i_sb); 1257 jbegin_count =
1203 1258 JOURNAL_PER_BALANCE_CNT * 3 + 5 +
1204 old_inode = old_dentry->d_inode; 1259 4 * REISERFS_QUOTA_TRANS_BLOCKS(old_dir->i_sb);
1205 new_dentry_inode = new_dentry->d_inode; 1260
1206 1261 old_inode = old_dentry->d_inode;
1207 // make sure, that oldname still exists and points to an object we 1262 new_dentry_inode = new_dentry->d_inode;
1208 // are going to rename 1263
1209 old_de.de_gen_number_bit_string = NULL; 1264 // make sure, that oldname still exists and points to an object we
1210 reiserfs_write_lock(old_dir->i_sb); 1265 // are going to rename
1211 retval = reiserfs_find_entry (old_dir, old_dentry->d_name.name, old_dentry->d_name.len, 1266 old_de.de_gen_number_bit_string = NULL;
1212 &old_entry_path, &old_de); 1267 reiserfs_write_lock(old_dir->i_sb);
1213 pathrelse (&old_entry_path); 1268 retval =
1214 if (retval == IO_ERROR) { 1269 reiserfs_find_entry(old_dir, old_dentry->d_name.name,
1215 reiserfs_write_unlock(old_dir->i_sb); 1270 old_dentry->d_name.len, &old_entry_path,
1216 return -EIO; 1271 &old_de);
1217 } 1272 pathrelse(&old_entry_path);
1218 1273 if (retval == IO_ERROR) {
1219 if (retval != NAME_FOUND || old_de.de_objectid != old_inode->i_ino) {
1220 reiserfs_write_unlock(old_dir->i_sb);
1221 return -ENOENT;
1222 }
1223
1224 old_inode_mode = old_inode->i_mode;
1225 if (S_ISDIR(old_inode_mode)) {
1226 // make sure, that directory being renamed has correct ".."
1227 // and that its new parent directory has not too many links
1228 // already
1229
1230 if (new_dentry_inode) {
1231 if (!reiserfs_empty_dir(new_dentry_inode)) {
1232 reiserfs_write_unlock(old_dir->i_sb); 1274 reiserfs_write_unlock(old_dir->i_sb);
1233 return -ENOTEMPTY; 1275 return -EIO;
1234 }
1235 } 1276 }
1236 1277
1237 /* directory is renamed, its parent directory will be changed, 1278 if (retval != NAME_FOUND || old_de.de_objectid != old_inode->i_ino) {
1238 ** so find ".." entry 1279 reiserfs_write_unlock(old_dir->i_sb);
1239 */ 1280 return -ENOENT;
1240 dot_dot_de.de_gen_number_bit_string = NULL;
1241 retval = reiserfs_find_entry (old_inode, "..", 2, &dot_dot_entry_path, &dot_dot_de);
1242 pathrelse (&dot_dot_entry_path);
1243 if (retval != NAME_FOUND) {
1244 reiserfs_write_unlock(old_dir->i_sb);
1245 return -EIO;
1246 } 1281 }
1247 1282
1248 /* inode number of .. must equal old_dir->i_ino */ 1283 old_inode_mode = old_inode->i_mode;
1249 if (dot_dot_de.de_objectid != old_dir->i_ino) { 1284 if (S_ISDIR(old_inode_mode)) {
1250 reiserfs_write_unlock(old_dir->i_sb); 1285 // make sure, that directory being renamed has correct ".."
1251 return -EIO; 1286 // and that its new parent directory has not too many links
1287 // already
1288
1289 if (new_dentry_inode) {
1290 if (!reiserfs_empty_dir(new_dentry_inode)) {
1291 reiserfs_write_unlock(old_dir->i_sb);
1292 return -ENOTEMPTY;
1293 }
1294 }
1295
1296 /* directory is renamed, its parent directory will be changed,
1297 ** so find ".." entry
1298 */
1299 dot_dot_de.de_gen_number_bit_string = NULL;
1300 retval =
1301 reiserfs_find_entry(old_inode, "..", 2, &dot_dot_entry_path,
1302 &dot_dot_de);
1303 pathrelse(&dot_dot_entry_path);
1304 if (retval != NAME_FOUND) {
1305 reiserfs_write_unlock(old_dir->i_sb);
1306 return -EIO;
1307 }
1308
1309 /* inode number of .. must equal old_dir->i_ino */
1310 if (dot_dot_de.de_objectid != old_dir->i_ino) {
1311 reiserfs_write_unlock(old_dir->i_sb);
1312 return -EIO;
1313 }
1252 } 1314 }
1253 } 1315
1254 1316 retval = journal_begin(&th, old_dir->i_sb, jbegin_count);
1255 retval = journal_begin(&th, old_dir->i_sb, jbegin_count) ; 1317 if (retval) {
1256 if (retval) { 1318 reiserfs_write_unlock(old_dir->i_sb);
1257 reiserfs_write_unlock (old_dir->i_sb); 1319 return retval;
1258 return retval;
1259 }
1260
1261 /* add new entry (or find the existing one) */
1262 retval = reiserfs_add_entry (&th, new_dir, new_dentry->d_name.name, new_dentry->d_name.len,
1263 old_inode, 0);
1264 if (retval == -EEXIST) {
1265 if (!new_dentry_inode) {
1266 reiserfs_panic (old_dir->i_sb,
1267 "vs-7050: new entry is found, new inode == 0\n");
1268 } 1320 }
1269 } else if (retval) { 1321
1270 int err = journal_end(&th, old_dir->i_sb, jbegin_count) ; 1322 /* add new entry (or find the existing one) */
1271 reiserfs_write_unlock(old_dir->i_sb); 1323 retval =
1272 return err ? err : retval; 1324 reiserfs_add_entry(&th, new_dir, new_dentry->d_name.name,
1273 } 1325 new_dentry->d_name.len, old_inode, 0);
1274 1326 if (retval == -EEXIST) {
1275 reiserfs_update_inode_transaction(old_dir) ; 1327 if (!new_dentry_inode) {
1276 reiserfs_update_inode_transaction(new_dir) ; 1328 reiserfs_panic(old_dir->i_sb,
1277 1329 "vs-7050: new entry is found, new inode == 0\n");
1278 /* this makes it so an fsync on an open fd for the old name will 1330 }
1279 ** commit the rename operation 1331 } else if (retval) {
1280 */ 1332 int err = journal_end(&th, old_dir->i_sb, jbegin_count);
1281 reiserfs_update_inode_transaction(old_inode) ; 1333 reiserfs_write_unlock(old_dir->i_sb);
1282 1334 return err ? err : retval;
1283 if (new_dentry_inode)
1284 reiserfs_update_inode_transaction(new_dentry_inode) ;
1285
1286 while (1) {
1287 // look for old name using corresponding entry key (found by reiserfs_find_entry)
1288 if ((retval = search_by_entry_key (new_dir->i_sb, &old_de.de_entry_key,
1289 &old_entry_path, &old_de)) != NAME_FOUND) {
1290 pathrelse(&old_entry_path);
1291 journal_end(&th, old_dir->i_sb, jbegin_count);
1292 reiserfs_write_unlock(old_dir->i_sb);
1293 return -EIO;
1294 } 1335 }
1295 1336
1296 copy_item_head(&old_entry_ih, get_ih(&old_entry_path)) ; 1337 reiserfs_update_inode_transaction(old_dir);
1297 1338 reiserfs_update_inode_transaction(new_dir);
1298 reiserfs_prepare_for_journal(old_inode->i_sb, old_de.de_bh, 1) ; 1339
1299 1340 /* this makes it so an fsync on an open fd for the old name will
1300 // look for new name by reiserfs_find_entry 1341 ** commit the rename operation
1301 new_de.de_gen_number_bit_string = NULL; 1342 */
1302 retval = reiserfs_find_entry (new_dir, new_dentry->d_name.name, new_dentry->d_name.len, 1343 reiserfs_update_inode_transaction(old_inode);
1303 &new_entry_path, &new_de); 1344
1304 // reiserfs_add_entry should not return IO_ERROR, because it is called with essentially same parameters from 1345 if (new_dentry_inode)
1305 // reiserfs_add_entry above, and we'll catch any i/o errors before we get here. 1346 reiserfs_update_inode_transaction(new_dentry_inode);
1306 if (retval != NAME_FOUND_INVISIBLE && retval != NAME_FOUND) { 1347
1307 pathrelse(&new_entry_path); 1348 while (1) {
1308 pathrelse(&old_entry_path); 1349 // look for old name using corresponding entry key (found by reiserfs_find_entry)
1309 journal_end(&th, old_dir->i_sb, jbegin_count); 1350 if ((retval =
1310 reiserfs_write_unlock(old_dir->i_sb); 1351 search_by_entry_key(new_dir->i_sb, &old_de.de_entry_key,
1311 return -EIO; 1352 &old_entry_path,
1353 &old_de)) != NAME_FOUND) {
1354 pathrelse(&old_entry_path);
1355 journal_end(&th, old_dir->i_sb, jbegin_count);
1356 reiserfs_write_unlock(old_dir->i_sb);
1357 return -EIO;
1358 }
1359
1360 copy_item_head(&old_entry_ih, get_ih(&old_entry_path));
1361
1362 reiserfs_prepare_for_journal(old_inode->i_sb, old_de.de_bh, 1);
1363
1364 // look for new name by reiserfs_find_entry
1365 new_de.de_gen_number_bit_string = NULL;
1366 retval =
1367 reiserfs_find_entry(new_dir, new_dentry->d_name.name,
1368 new_dentry->d_name.len, &new_entry_path,
1369 &new_de);
1370 // reiserfs_add_entry should not return IO_ERROR, because it is called with essentially same parameters from
1371 // reiserfs_add_entry above, and we'll catch any i/o errors before we get here.
1372 if (retval != NAME_FOUND_INVISIBLE && retval != NAME_FOUND) {
1373 pathrelse(&new_entry_path);
1374 pathrelse(&old_entry_path);
1375 journal_end(&th, old_dir->i_sb, jbegin_count);
1376 reiserfs_write_unlock(old_dir->i_sb);
1377 return -EIO;
1378 }
1379
1380 copy_item_head(&new_entry_ih, get_ih(&new_entry_path));
1381
1382 reiserfs_prepare_for_journal(old_inode->i_sb, new_de.de_bh, 1);
1383
1384 if (S_ISDIR(old_inode->i_mode)) {
1385 if ((retval =
1386 search_by_entry_key(new_dir->i_sb,
1387 &dot_dot_de.de_entry_key,
1388 &dot_dot_entry_path,
1389 &dot_dot_de)) != NAME_FOUND) {
1390 pathrelse(&dot_dot_entry_path);
1391 pathrelse(&new_entry_path);
1392 pathrelse(&old_entry_path);
1393 journal_end(&th, old_dir->i_sb, jbegin_count);
1394 reiserfs_write_unlock(old_dir->i_sb);
1395 return -EIO;
1396 }
1397 copy_item_head(&dot_dot_ih,
1398 get_ih(&dot_dot_entry_path));
1399 // node containing ".." gets into transaction
1400 reiserfs_prepare_for_journal(old_inode->i_sb,
1401 dot_dot_de.de_bh, 1);
1402 }
1403 /* we should check seals here, not do
1404 this stuff, yes? Then, having
1405 gathered everything into RAM we
1406 should lock the buffers, yes? -Hans */
1407 /* probably. our rename needs to hold more
1408 ** than one path at once. The seals would
1409 ** have to be written to deal with multi-path
1410 ** issues -chris
1411 */
1412 /* sanity checking before doing the rename - avoid races many
1413 ** of the above checks could have scheduled. We have to be
1414 ** sure our items haven't been shifted by another process.
1415 */
1416 if (item_moved(&new_entry_ih, &new_entry_path) ||
1417 !entry_points_to_object(new_dentry->d_name.name,
1418 new_dentry->d_name.len,
1419 &new_de, new_dentry_inode) ||
1420 item_moved(&old_entry_ih, &old_entry_path) ||
1421 !entry_points_to_object(old_dentry->d_name.name,
1422 old_dentry->d_name.len,
1423 &old_de, old_inode)) {
1424 reiserfs_restore_prepared_buffer(old_inode->i_sb,
1425 new_de.de_bh);
1426 reiserfs_restore_prepared_buffer(old_inode->i_sb,
1427 old_de.de_bh);
1428 if (S_ISDIR(old_inode_mode))
1429 reiserfs_restore_prepared_buffer(old_inode->
1430 i_sb,
1431 dot_dot_de.
1432 de_bh);
1433 continue;
1434 }
1435 if (S_ISDIR(old_inode_mode)) {
1436 if (item_moved(&dot_dot_ih, &dot_dot_entry_path) ||
1437 !entry_points_to_object("..", 2, &dot_dot_de,
1438 old_dir)) {
1439 reiserfs_restore_prepared_buffer(old_inode->
1440 i_sb,
1441 old_de.de_bh);
1442 reiserfs_restore_prepared_buffer(old_inode->
1443 i_sb,
1444 new_de.de_bh);
1445 reiserfs_restore_prepared_buffer(old_inode->
1446 i_sb,
1447 dot_dot_de.
1448 de_bh);
1449 continue;
1450 }
1451 }
1452
1453 RFALSE(S_ISDIR(old_inode_mode) &&
1454 !buffer_journal_prepared(dot_dot_de.de_bh), "");
1455
1456 break;
1312 } 1457 }
1313 1458
1314 copy_item_head(&new_entry_ih, get_ih(&new_entry_path)) ; 1459 /* ok, all the changes can be done in one fell swoop when we
1460 have claimed all the buffers needed. */
1315 1461
1316 reiserfs_prepare_for_journal(old_inode->i_sb, new_de.de_bh, 1) ; 1462 mark_de_visible(new_de.de_deh + new_de.de_entry_num);
1463 set_ino_in_dir_entry(&new_de, INODE_PKEY(old_inode));
1464 journal_mark_dirty(&th, old_dir->i_sb, new_de.de_bh);
1317 1465
1318 if (S_ISDIR(old_inode->i_mode)) { 1466 mark_de_hidden(old_de.de_deh + old_de.de_entry_num);
1319 if ((retval = search_by_entry_key (new_dir->i_sb, &dot_dot_de.de_entry_key, 1467 journal_mark_dirty(&th, old_dir->i_sb, old_de.de_bh);
1320 &dot_dot_entry_path, &dot_dot_de)) != NAME_FOUND) { 1468 ctime = CURRENT_TIME_SEC;
1321 pathrelse(&dot_dot_entry_path); 1469 old_dir->i_ctime = old_dir->i_mtime = ctime;
1322 pathrelse(&new_entry_path); 1470 new_dir->i_ctime = new_dir->i_mtime = ctime;
1323 pathrelse(&old_entry_path); 1471 /* thanks to Alex Adriaanse <alex_a@caltech.edu> for patch which adds ctime update of
1324 journal_end(&th, old_dir->i_sb, jbegin_count); 1472 renamed object */
1325 reiserfs_write_unlock(old_dir->i_sb); 1473 old_inode->i_ctime = ctime;
1326 return -EIO; 1474
1327 } 1475 if (new_dentry_inode) {
1328 copy_item_head(&dot_dot_ih, get_ih(&dot_dot_entry_path)) ; 1476 // adjust link number of the victim
1329 // node containing ".." gets into transaction 1477 if (S_ISDIR(new_dentry_inode->i_mode)) {
1330 reiserfs_prepare_for_journal(old_inode->i_sb, dot_dot_de.de_bh, 1) ; 1478 new_dentry_inode->i_nlink = 0;
1331 } 1479 } else {
1332 /* we should check seals here, not do 1480 new_dentry_inode->i_nlink--;
1333 this stuff, yes? Then, having 1481 }
1334 gathered everything into RAM we 1482 new_dentry_inode->i_ctime = ctime;
1335 should lock the buffers, yes? -Hans */ 1483 savelink = new_dentry_inode->i_nlink;
1336 /* probably. our rename needs to hold more
1337 ** than one path at once. The seals would
1338 ** have to be written to deal with multi-path
1339 ** issues -chris
1340 */
1341 /* sanity checking before doing the rename - avoid races many
1342 ** of the above checks could have scheduled. We have to be
1343 ** sure our items haven't been shifted by another process.
1344 */
1345 if (item_moved(&new_entry_ih, &new_entry_path) ||
1346 !entry_points_to_object(new_dentry->d_name.name,
1347 new_dentry->d_name.len,
1348 &new_de, new_dentry_inode) ||
1349 item_moved(&old_entry_ih, &old_entry_path) ||
1350 !entry_points_to_object (old_dentry->d_name.name,
1351 old_dentry->d_name.len,
1352 &old_de, old_inode)) {
1353 reiserfs_restore_prepared_buffer (old_inode->i_sb, new_de.de_bh);
1354 reiserfs_restore_prepared_buffer (old_inode->i_sb, old_de.de_bh);
1355 if (S_ISDIR(old_inode_mode))
1356 reiserfs_restore_prepared_buffer (old_inode->i_sb, dot_dot_de.de_bh);
1357 continue;
1358 } 1484 }
1485
1359 if (S_ISDIR(old_inode_mode)) { 1486 if (S_ISDIR(old_inode_mode)) {
1360 if ( item_moved(&dot_dot_ih, &dot_dot_entry_path) || 1487 // adjust ".." of renamed directory
1361 !entry_points_to_object ( "..", 2, &dot_dot_de, old_dir) ) { 1488 set_ino_in_dir_entry(&dot_dot_de, INODE_PKEY(new_dir));
1362 reiserfs_restore_prepared_buffer (old_inode->i_sb, old_de.de_bh); 1489 journal_mark_dirty(&th, new_dir->i_sb, dot_dot_de.de_bh);
1363 reiserfs_restore_prepared_buffer (old_inode->i_sb, new_de.de_bh); 1490
1364 reiserfs_restore_prepared_buffer (old_inode->i_sb, dot_dot_de.de_bh); 1491 if (!new_dentry_inode)
1365 continue; 1492 /* there (in new_dir) was no directory, so it got new link
1366 } 1493 (".." of renamed directory) */
1494 INC_DIR_INODE_NLINK(new_dir);
1495
1496 /* old directory lost one link - ".. " of renamed directory */
1497 DEC_DIR_INODE_NLINK(old_dir);
1367 } 1498 }
1499 // looks like in 2.3.99pre3 brelse is atomic. so we can use pathrelse
1500 pathrelse(&new_entry_path);
1501 pathrelse(&dot_dot_entry_path);
1368 1502
1369 RFALSE( S_ISDIR(old_inode_mode) && 1503 // FIXME: this reiserfs_cut_from_item's return value may screw up
1370 !buffer_journal_prepared(dot_dot_de.de_bh), "" ); 1504 // anybody, but it will panic if will not be able to find the
1371 1505 // entry. This needs one more clean up
1372 break; 1506 if (reiserfs_cut_from_item
1373 } 1507 (&th, &old_entry_path, &(old_de.de_entry_key), old_dir, NULL,
1374 1508 0) < 0)
1375 /* ok, all the changes can be done in one fell swoop when we 1509 reiserfs_warning(old_dir->i_sb,
1376 have claimed all the buffers needed.*/ 1510 "vs-7060: reiserfs_rename: couldn't not cut old name. Fsck later?");
1377 1511
1378 mark_de_visible (new_de.de_deh + new_de.de_entry_num); 1512 old_dir->i_size -= DEH_SIZE + old_de.de_entrylen;
1379 set_ino_in_dir_entry (&new_de, INODE_PKEY (old_inode)); 1513
1380 journal_mark_dirty (&th, old_dir->i_sb, new_de.de_bh); 1514 reiserfs_update_sd(&th, old_dir);
1381 1515 reiserfs_update_sd(&th, new_dir);
1382 mark_de_hidden (old_de.de_deh + old_de.de_entry_num); 1516 reiserfs_update_sd(&th, old_inode);
1383 journal_mark_dirty (&th, old_dir->i_sb, old_de.de_bh); 1517
1384 ctime = CURRENT_TIME_SEC; 1518 if (new_dentry_inode) {
1385 old_dir->i_ctime = old_dir->i_mtime = ctime; 1519 if (savelink == 0)
1386 new_dir->i_ctime = new_dir->i_mtime = ctime; 1520 add_save_link(&th, new_dentry_inode,
1387 /* thanks to Alex Adriaanse <alex_a@caltech.edu> for patch which adds ctime update of 1521 0 /* not truncate */ );
1388 renamed object */ 1522 reiserfs_update_sd(&th, new_dentry_inode);
1389 old_inode->i_ctime = ctime;
1390
1391 if (new_dentry_inode) {
1392 // adjust link number of the victim
1393 if (S_ISDIR(new_dentry_inode->i_mode)) {
1394 new_dentry_inode->i_nlink = 0;
1395 } else {
1396 new_dentry_inode->i_nlink--;
1397 } 1523 }
1398 new_dentry_inode->i_ctime = ctime; 1524
1399 savelink = new_dentry_inode->i_nlink; 1525 retval = journal_end(&th, old_dir->i_sb, jbegin_count);
1400 } 1526 reiserfs_write_unlock(old_dir->i_sb);
1401 1527 return retval;
1402 if (S_ISDIR(old_inode_mode)) {
1403 // adjust ".." of renamed directory
1404 set_ino_in_dir_entry (&dot_dot_de, INODE_PKEY (new_dir));
1405 journal_mark_dirty (&th, new_dir->i_sb, dot_dot_de.de_bh);
1406
1407 if (!new_dentry_inode)
1408 /* there (in new_dir) was no directory, so it got new link
1409 (".." of renamed directory) */
1410 INC_DIR_INODE_NLINK(new_dir);
1411
1412 /* old directory lost one link - ".. " of renamed directory */
1413 DEC_DIR_INODE_NLINK(old_dir);
1414 }
1415
1416 // looks like in 2.3.99pre3 brelse is atomic. so we can use pathrelse
1417 pathrelse (&new_entry_path);
1418 pathrelse (&dot_dot_entry_path);
1419
1420 // FIXME: this reiserfs_cut_from_item's return value may screw up
1421 // anybody, but it will panic if will not be able to find the
1422 // entry. This needs one more clean up
1423 if (reiserfs_cut_from_item (&th, &old_entry_path, &(old_de.de_entry_key), old_dir, NULL, 0) < 0)
1424 reiserfs_warning (old_dir->i_sb, "vs-7060: reiserfs_rename: couldn't not cut old name. Fsck later?");
1425
1426 old_dir->i_size -= DEH_SIZE + old_de.de_entrylen;
1427
1428 reiserfs_update_sd (&th, old_dir);
1429 reiserfs_update_sd (&th, new_dir);
1430 reiserfs_update_sd (&th, old_inode);
1431
1432 if (new_dentry_inode) {
1433 if (savelink == 0)
1434 add_save_link (&th, new_dentry_inode, 0/* not truncate */);
1435 reiserfs_update_sd (&th, new_dentry_inode);
1436 }
1437
1438 retval = journal_end(&th, old_dir->i_sb, jbegin_count) ;
1439 reiserfs_write_unlock(old_dir->i_sb);
1440 return retval;
1441} 1528}
1442 1529
1443/* 1530/*
1444 * directories can handle most operations... 1531 * directories can handle most operations...
1445 */ 1532 */
1446struct inode_operations reiserfs_dir_inode_operations = { 1533struct inode_operations reiserfs_dir_inode_operations = {
1447 //&reiserfs_dir_operations, /* default_file_ops */ 1534 //&reiserfs_dir_operations, /* default_file_ops */
1448 .create = reiserfs_create, 1535 .create = reiserfs_create,
1449 .lookup = reiserfs_lookup, 1536 .lookup = reiserfs_lookup,
1450 .link = reiserfs_link, 1537 .link = reiserfs_link,
1451 .unlink = reiserfs_unlink, 1538 .unlink = reiserfs_unlink,
1452 .symlink = reiserfs_symlink, 1539 .symlink = reiserfs_symlink,
1453 .mkdir = reiserfs_mkdir, 1540 .mkdir = reiserfs_mkdir,
1454 .rmdir = reiserfs_rmdir, 1541 .rmdir = reiserfs_rmdir,
1455 .mknod = reiserfs_mknod, 1542 .mknod = reiserfs_mknod,
1456 .rename = reiserfs_rename, 1543 .rename = reiserfs_rename,
1457 .setattr = reiserfs_setattr, 1544 .setattr = reiserfs_setattr,
1458 .setxattr = reiserfs_setxattr, 1545 .setxattr = reiserfs_setxattr,
1459 .getxattr = reiserfs_getxattr, 1546 .getxattr = reiserfs_getxattr,
1460 .listxattr = reiserfs_listxattr, 1547 .listxattr = reiserfs_listxattr,
1461 .removexattr = reiserfs_removexattr, 1548 .removexattr = reiserfs_removexattr,
1462 .permission = reiserfs_permission, 1549 .permission = reiserfs_permission,
1463}; 1550};
1464 1551
1465/* 1552/*
@@ -1467,28 +1554,27 @@ struct inode_operations reiserfs_dir_inode_operations = {
1467 * stuff added 1554 * stuff added
1468 */ 1555 */
1469struct inode_operations reiserfs_symlink_inode_operations = { 1556struct inode_operations reiserfs_symlink_inode_operations = {
1470 .readlink = generic_readlink, 1557 .readlink = generic_readlink,
1471 .follow_link = page_follow_link_light, 1558 .follow_link = page_follow_link_light,
1472 .put_link = page_put_link, 1559 .put_link = page_put_link,
1473 .setattr = reiserfs_setattr, 1560 .setattr = reiserfs_setattr,
1474 .setxattr = reiserfs_setxattr, 1561 .setxattr = reiserfs_setxattr,
1475 .getxattr = reiserfs_getxattr, 1562 .getxattr = reiserfs_getxattr,
1476 .listxattr = reiserfs_listxattr, 1563 .listxattr = reiserfs_listxattr,
1477 .removexattr = reiserfs_removexattr, 1564 .removexattr = reiserfs_removexattr,
1478 .permission = reiserfs_permission, 1565 .permission = reiserfs_permission,
1479 1566
1480}; 1567};
1481 1568
1482
1483/* 1569/*
1484 * special file operations.. just xattr/acl stuff 1570 * special file operations.. just xattr/acl stuff
1485 */ 1571 */
1486struct inode_operations reiserfs_special_inode_operations = { 1572struct inode_operations reiserfs_special_inode_operations = {
1487 .setattr = reiserfs_setattr, 1573 .setattr = reiserfs_setattr,
1488 .setxattr = reiserfs_setxattr, 1574 .setxattr = reiserfs_setxattr,
1489 .getxattr = reiserfs_getxattr, 1575 .getxattr = reiserfs_getxattr,
1490 .listxattr = reiserfs_listxattr, 1576 .listxattr = reiserfs_listxattr,
1491 .removexattr = reiserfs_removexattr, 1577 .removexattr = reiserfs_removexattr,
1492 .permission = reiserfs_permission, 1578 .permission = reiserfs_permission,
1493 1579
1494}; 1580};
diff --git a/fs/reiserfs/objectid.c b/fs/reiserfs/objectid.c
index bfe8e25ef293..f62590aa9c95 100644
--- a/fs/reiserfs/objectid.c
+++ b/fs/reiserfs/objectid.c
@@ -14,24 +14,24 @@
14 (__le32 *)((struct reiserfs_super_block_v1 *)(rs) + 1) :\ 14 (__le32 *)((struct reiserfs_super_block_v1 *)(rs) + 1) :\
15 (__le32 *)((rs) + 1)) 15 (__le32 *)((rs) + 1))
16 16
17
18#ifdef CONFIG_REISERFS_CHECK 17#ifdef CONFIG_REISERFS_CHECK
19 18
20static void check_objectid_map (struct super_block * s, __le32 * map) 19static void check_objectid_map(struct super_block *s, __le32 * map)
21{ 20{
22 if (le32_to_cpu (map[0]) != 1) 21 if (le32_to_cpu(map[0]) != 1)
23 reiserfs_panic (s, "vs-15010: check_objectid_map: map corrupted: %lx", 22 reiserfs_panic(s,
24 ( long unsigned int ) le32_to_cpu (map[0])); 23 "vs-15010: check_objectid_map: map corrupted: %lx",
24 (long unsigned int)le32_to_cpu(map[0]));
25 25
26 // FIXME: add something else here 26 // FIXME: add something else here
27} 27}
28 28
29#else 29#else
30static void check_objectid_map (struct super_block * s, __le32 * map) 30static void check_objectid_map(struct super_block *s, __le32 * map)
31{;} 31{;
32}
32#endif 33#endif
33 34
34
35/* When we allocate objectids we allocate the first unused objectid. 35/* When we allocate objectids we allocate the first unused objectid.
36 Each sequence of objectids in use (the odd sequences) is followed 36 Each sequence of objectids in use (the odd sequences) is followed
37 by a sequence of objectids not in use (the even sequences). We 37 by a sequence of objectids not in use (the even sequences). We
@@ -46,161 +46,162 @@ static void check_objectid_map (struct super_block * s, __le32 * map)
46 interesting optimizations of layout could result from complicating 46 interesting optimizations of layout could result from complicating
47 objectid assignment, but we have deferred making them for now. */ 47 objectid assignment, but we have deferred making them for now. */
48 48
49
50/* get unique object identifier */ 49/* get unique object identifier */
51__u32 reiserfs_get_unused_objectid (struct reiserfs_transaction_handle *th) 50__u32 reiserfs_get_unused_objectid(struct reiserfs_transaction_handle *th)
52{ 51{
53 struct super_block * s = th->t_super; 52 struct super_block *s = th->t_super;
54 struct reiserfs_super_block * rs = SB_DISK_SUPER_BLOCK (s); 53 struct reiserfs_super_block *rs = SB_DISK_SUPER_BLOCK(s);
55 __le32 * map = objectid_map (s, rs); 54 __le32 *map = objectid_map(s, rs);
56 __u32 unused_objectid; 55 __u32 unused_objectid;
57 56
58 BUG_ON (!th->t_trans_id); 57 BUG_ON(!th->t_trans_id);
58
59 check_objectid_map(s, map);
60
61 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1);
62 /* comment needed -Hans */
63 unused_objectid = le32_to_cpu(map[1]);
64 if (unused_objectid == U32_MAX) {
65 reiserfs_warning(s, "%s: no more object ids", __FUNCTION__);
66 reiserfs_restore_prepared_buffer(s, SB_BUFFER_WITH_SB(s));
67 return 0;
68 }
59 69
60 check_objectid_map (s, map); 70 /* This incrementation allocates the first unused objectid. That
71 is to say, the first entry on the objectid map is the first
72 unused objectid, and by incrementing it we use it. See below
73 where we check to see if we eliminated a sequence of unused
74 objectids.... */
75 map[1] = cpu_to_le32(unused_objectid + 1);
76
77 /* Now we check to see if we eliminated the last remaining member of
78 the first even sequence (and can eliminate the sequence by
79 eliminating its last objectid from oids), and can collapse the
80 first two odd sequences into one sequence. If so, then the net
81 result is to eliminate a pair of objectids from oids. We do this
82 by shifting the entire map to the left. */
83 if (sb_oid_cursize(rs) > 2 && map[1] == map[2]) {
84 memmove(map + 1, map + 3,
85 (sb_oid_cursize(rs) - 3) * sizeof(__u32));
86 set_sb_oid_cursize(rs, sb_oid_cursize(rs) - 2);
87 }
61 88
62 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1) ; 89 journal_mark_dirty(th, s, SB_BUFFER_WITH_SB(s));
63 /* comment needed -Hans */ 90 return unused_objectid;
64 unused_objectid = le32_to_cpu (map[1]);
65 if (unused_objectid == U32_MAX) {
66 reiserfs_warning (s, "%s: no more object ids", __FUNCTION__);
67 reiserfs_restore_prepared_buffer(s, SB_BUFFER_WITH_SB(s)) ;
68 return 0;
69 }
70
71 /* This incrementation allocates the first unused objectid. That
72 is to say, the first entry on the objectid map is the first
73 unused objectid, and by incrementing it we use it. See below
74 where we check to see if we eliminated a sequence of unused
75 objectids.... */
76 map[1] = cpu_to_le32 (unused_objectid + 1);
77
78 /* Now we check to see if we eliminated the last remaining member of
79 the first even sequence (and can eliminate the sequence by
80 eliminating its last objectid from oids), and can collapse the
81 first two odd sequences into one sequence. If so, then the net
82 result is to eliminate a pair of objectids from oids. We do this
83 by shifting the entire map to the left. */
84 if (sb_oid_cursize(rs) > 2 && map[1] == map[2]) {
85 memmove (map + 1, map + 3, (sb_oid_cursize(rs) - 3) * sizeof(__u32));
86 set_sb_oid_cursize( rs, sb_oid_cursize(rs) - 2 );
87 }
88
89 journal_mark_dirty(th, s, SB_BUFFER_WITH_SB (s));
90 return unused_objectid;
91} 91}
92 92
93
94/* makes object identifier unused */ 93/* makes object identifier unused */
95void reiserfs_release_objectid (struct reiserfs_transaction_handle *th, 94void reiserfs_release_objectid(struct reiserfs_transaction_handle *th,
96 __u32 objectid_to_release) 95 __u32 objectid_to_release)
97{ 96{
98 struct super_block * s = th->t_super; 97 struct super_block *s = th->t_super;
99 struct reiserfs_super_block * rs = SB_DISK_SUPER_BLOCK (s); 98 struct reiserfs_super_block *rs = SB_DISK_SUPER_BLOCK(s);
100 __le32 * map = objectid_map (s, rs); 99 __le32 *map = objectid_map(s, rs);
101 int i = 0; 100 int i = 0;
102 101
103 BUG_ON (!th->t_trans_id); 102 BUG_ON(!th->t_trans_id);
104 //return; 103 //return;
105 check_objectid_map (s, map); 104 check_objectid_map(s, map);
106 105
107 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1) ; 106 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1);
108 journal_mark_dirty(th, s, SB_BUFFER_WITH_SB (s)); 107 journal_mark_dirty(th, s, SB_BUFFER_WITH_SB(s));
109 108
110 /* start at the beginning of the objectid map (i = 0) and go to 109 /* start at the beginning of the objectid map (i = 0) and go to
111 the end of it (i = disk_sb->s_oid_cursize). Linear search is 110 the end of it (i = disk_sb->s_oid_cursize). Linear search is
112 what we use, though it is possible that binary search would be 111 what we use, though it is possible that binary search would be
113 more efficient after performing lots of deletions (which is 112 more efficient after performing lots of deletions (which is
114 when oids is large.) We only check even i's. */ 113 when oids is large.) We only check even i's. */
115 while (i < sb_oid_cursize(rs)) { 114 while (i < sb_oid_cursize(rs)) {
116 if (objectid_to_release == le32_to_cpu (map[i])) { 115 if (objectid_to_release == le32_to_cpu(map[i])) {
117 /* This incrementation unallocates the objectid. */ 116 /* This incrementation unallocates the objectid. */
118 //map[i]++; 117 //map[i]++;
119 map[i] = cpu_to_le32 (le32_to_cpu (map[i]) + 1); 118 map[i] = cpu_to_le32(le32_to_cpu(map[i]) + 1);
120 119
121 /* Did we unallocate the last member of an odd sequence, and can shrink oids? */ 120 /* Did we unallocate the last member of an odd sequence, and can shrink oids? */
122 if (map[i] == map[i+1]) { 121 if (map[i] == map[i + 1]) {
123 /* shrink objectid map */ 122 /* shrink objectid map */
124 memmove (map + i, map + i + 2, 123 memmove(map + i, map + i + 2,
125 (sb_oid_cursize(rs) - i - 2) * sizeof (__u32)); 124 (sb_oid_cursize(rs) - i -
126 //disk_sb->s_oid_cursize -= 2; 125 2) * sizeof(__u32));
127 set_sb_oid_cursize( rs, sb_oid_cursize(rs) - 2 ); 126 //disk_sb->s_oid_cursize -= 2;
128 127 set_sb_oid_cursize(rs, sb_oid_cursize(rs) - 2);
129 RFALSE( sb_oid_cursize(rs) < 2 || 128
130 sb_oid_cursize(rs) > sb_oid_maxsize(rs), 129 RFALSE(sb_oid_cursize(rs) < 2 ||
131 "vs-15005: objectid map corrupted cur_size == %d (max == %d)", 130 sb_oid_cursize(rs) > sb_oid_maxsize(rs),
132 sb_oid_cursize(rs), sb_oid_maxsize(rs)); 131 "vs-15005: objectid map corrupted cur_size == %d (max == %d)",
133 } 132 sb_oid_cursize(rs), sb_oid_maxsize(rs));
134 return; 133 }
134 return;
135 }
136
137 if (objectid_to_release > le32_to_cpu(map[i]) &&
138 objectid_to_release < le32_to_cpu(map[i + 1])) {
139 /* size of objectid map is not changed */
140 if (objectid_to_release + 1 == le32_to_cpu(map[i + 1])) {
141 //objectid_map[i+1]--;
142 map[i + 1] =
143 cpu_to_le32(le32_to_cpu(map[i + 1]) - 1);
144 return;
145 }
146
147 /* JDM comparing two little-endian values for equality -- safe */
148 if (sb_oid_cursize(rs) == sb_oid_maxsize(rs)) {
149 /* objectid map must be expanded, but there is no space */
150 PROC_INFO_INC(s, leaked_oid);
151 return;
152 }
153
154 /* expand the objectid map */
155 memmove(map + i + 3, map + i + 1,
156 (sb_oid_cursize(rs) - i - 1) * sizeof(__u32));
157 map[i + 1] = cpu_to_le32(objectid_to_release);
158 map[i + 2] = cpu_to_le32(objectid_to_release + 1);
159 set_sb_oid_cursize(rs, sb_oid_cursize(rs) + 2);
160 return;
161 }
162 i += 2;
135 } 163 }
136 164
137 if (objectid_to_release > le32_to_cpu (map[i]) && 165 reiserfs_warning(s,
138 objectid_to_release < le32_to_cpu (map[i + 1])) { 166 "vs-15011: reiserfs_release_objectid: tried to free free object id (%lu)",
139 /* size of objectid map is not changed */ 167 (long unsigned)objectid_to_release);
140 if (objectid_to_release + 1 == le32_to_cpu (map[i + 1])) { 168}
141 //objectid_map[i+1]--;
142 map[i + 1] = cpu_to_le32 (le32_to_cpu (map[i + 1]) - 1);
143 return;
144 }
145
146 /* JDM comparing two little-endian values for equality -- safe */
147 if (sb_oid_cursize(rs) == sb_oid_maxsize(rs)) {
148 /* objectid map must be expanded, but there is no space */
149 PROC_INFO_INC( s, leaked_oid );
150 return;
151 }
152 169
153 /* expand the objectid map*/ 170int reiserfs_convert_objectid_map_v1(struct super_block *s)
154 memmove (map + i + 3, map + i + 1, 171{
155 (sb_oid_cursize(rs) - i - 1) * sizeof(__u32)); 172 struct reiserfs_super_block *disk_sb = SB_DISK_SUPER_BLOCK(s);
156 map[i + 1] = cpu_to_le32 (objectid_to_release); 173 int cur_size = sb_oid_cursize(disk_sb);
157 map[i + 2] = cpu_to_le32 (objectid_to_release + 1); 174 int new_size = (s->s_blocksize - SB_SIZE) / sizeof(__u32) / 2 * 2;
158 set_sb_oid_cursize( rs, sb_oid_cursize(rs) + 2 ); 175 int old_max = sb_oid_maxsize(disk_sb);
159 return; 176 struct reiserfs_super_block_v1 *disk_sb_v1;
177 __le32 *objectid_map, *new_objectid_map;
178 int i;
179
180 disk_sb_v1 =
181 (struct reiserfs_super_block_v1 *)(SB_BUFFER_WITH_SB(s)->b_data);
182 objectid_map = (__le32 *) (disk_sb_v1 + 1);
183 new_objectid_map = (__le32 *) (disk_sb + 1);
184
185 if (cur_size > new_size) {
186 /* mark everyone used that was listed as free at the end of the objectid
187 ** map
188 */
189 objectid_map[new_size - 1] = objectid_map[cur_size - 1];
190 set_sb_oid_cursize(disk_sb, new_size);
191 }
192 /* move the smaller objectid map past the end of the new super */
193 for (i = new_size - 1; i >= 0; i--) {
194 objectid_map[i + (old_max - new_size)] = objectid_map[i];
160 } 195 }
161 i += 2;
162 }
163 196
164 reiserfs_warning (s, "vs-15011: reiserfs_release_objectid: tried to free free object id (%lu)", 197 /* set the max size so we don't overflow later */
165 ( long unsigned ) objectid_to_release); 198 set_sb_oid_maxsize(disk_sb, new_size);
166}
167 199
200 /* Zero out label and generate random UUID */
201 memset(disk_sb->s_label, 0, sizeof(disk_sb->s_label));
202 generate_random_uuid(disk_sb->s_uuid);
168 203
169int reiserfs_convert_objectid_map_v1(struct super_block *s) { 204 /* finally, zero out the unused chunk of the new super */
170 struct reiserfs_super_block *disk_sb = SB_DISK_SUPER_BLOCK (s); 205 memset(disk_sb->s_unused, 0, sizeof(disk_sb->s_unused));
171 int cur_size = sb_oid_cursize(disk_sb); 206 return 0;
172 int new_size = (s->s_blocksize - SB_SIZE) / sizeof(__u32) / 2 * 2 ;
173 int old_max = sb_oid_maxsize(disk_sb);
174 struct reiserfs_super_block_v1 *disk_sb_v1 ;
175 __le32 *objectid_map, *new_objectid_map ;
176 int i ;
177
178 disk_sb_v1=(struct reiserfs_super_block_v1 *)(SB_BUFFER_WITH_SB(s)->b_data);
179 objectid_map = (__le32 *)(disk_sb_v1 + 1) ;
180 new_objectid_map = (__le32 *)(disk_sb + 1) ;
181
182 if (cur_size > new_size) {
183 /* mark everyone used that was listed as free at the end of the objectid
184 ** map
185 */
186 objectid_map[new_size - 1] = objectid_map[cur_size - 1] ;
187 set_sb_oid_cursize(disk_sb,new_size) ;
188 }
189 /* move the smaller objectid map past the end of the new super */
190 for (i = new_size - 1 ; i >= 0 ; i--) {
191 objectid_map[i + (old_max - new_size)] = objectid_map[i] ;
192 }
193
194
195 /* set the max size so we don't overflow later */
196 set_sb_oid_maxsize(disk_sb,new_size) ;
197
198 /* Zero out label and generate random UUID */
199 memset(disk_sb->s_label, 0, sizeof(disk_sb->s_label)) ;
200 generate_random_uuid(disk_sb->s_uuid);
201
202 /* finally, zero out the unused chunk of the new super */
203 memset(disk_sb->s_unused, 0, sizeof(disk_sb->s_unused)) ;
204 return 0 ;
205} 207}
206
diff --git a/fs/reiserfs/prints.c b/fs/reiserfs/prints.c
index 16fdca1d4bd7..d55e164bd5c2 100644
--- a/fs/reiserfs/prints.c
+++ b/fs/reiserfs/prints.c
@@ -15,168 +15,166 @@ static char error_buf[1024];
15static char fmt_buf[1024]; 15static char fmt_buf[1024];
16static char off_buf[80]; 16static char off_buf[80];
17 17
18 18static char *reiserfs_cpu_offset(struct cpu_key *key)
19static char * reiserfs_cpu_offset (struct cpu_key * key)
20{ 19{
21 if (cpu_key_k_type(key) == TYPE_DIRENTRY) 20 if (cpu_key_k_type(key) == TYPE_DIRENTRY)
22 sprintf (off_buf, "%Lu(%Lu)", 21 sprintf(off_buf, "%Lu(%Lu)",
23 (unsigned long long)GET_HASH_VALUE (cpu_key_k_offset (key)), 22 (unsigned long long)
24 (unsigned long long)GET_GENERATION_NUMBER (cpu_key_k_offset (key))); 23 GET_HASH_VALUE(cpu_key_k_offset(key)),
25 else 24 (unsigned long long)
26 sprintf (off_buf, "0x%Lx", (unsigned long long)cpu_key_k_offset (key)); 25 GET_GENERATION_NUMBER(cpu_key_k_offset(key)));
27 return off_buf; 26 else
27 sprintf(off_buf, "0x%Lx",
28 (unsigned long long)cpu_key_k_offset(key));
29 return off_buf;
28} 30}
29 31
30 32static char *le_offset(struct reiserfs_key *key)
31static char * le_offset (struct reiserfs_key * key)
32{ 33{
33 int version; 34 int version;
34 35
35 version = le_key_version (key); 36 version = le_key_version(key);
36 if (le_key_k_type (version, key) == TYPE_DIRENTRY) 37 if (le_key_k_type(version, key) == TYPE_DIRENTRY)
37 sprintf (off_buf, "%Lu(%Lu)", 38 sprintf(off_buf, "%Lu(%Lu)",
38 (unsigned long long)GET_HASH_VALUE (le_key_k_offset (version, key)), 39 (unsigned long long)
39 (unsigned long long)GET_GENERATION_NUMBER (le_key_k_offset (version, key))); 40 GET_HASH_VALUE(le_key_k_offset(version, key)),
40 else 41 (unsigned long long)
41 sprintf (off_buf, "0x%Lx", (unsigned long long)le_key_k_offset (version, key)); 42 GET_GENERATION_NUMBER(le_key_k_offset(version, key)));
42 return off_buf; 43 else
44 sprintf(off_buf, "0x%Lx",
45 (unsigned long long)le_key_k_offset(version, key));
46 return off_buf;
43} 47}
44 48
45 49static char *cpu_type(struct cpu_key *key)
46static char * cpu_type (struct cpu_key * key)
47{ 50{
48 if (cpu_key_k_type (key) == TYPE_STAT_DATA) 51 if (cpu_key_k_type(key) == TYPE_STAT_DATA)
49 return "SD"; 52 return "SD";
50 if (cpu_key_k_type (key) == TYPE_DIRENTRY) 53 if (cpu_key_k_type(key) == TYPE_DIRENTRY)
51 return "DIR"; 54 return "DIR";
52 if (cpu_key_k_type (key) == TYPE_DIRECT) 55 if (cpu_key_k_type(key) == TYPE_DIRECT)
53 return "DIRECT"; 56 return "DIRECT";
54 if (cpu_key_k_type (key) == TYPE_INDIRECT) 57 if (cpu_key_k_type(key) == TYPE_INDIRECT)
55 return "IND"; 58 return "IND";
56 return "UNKNOWN"; 59 return "UNKNOWN";
57} 60}
58 61
59 62static char *le_type(struct reiserfs_key *key)
60static char * le_type (struct reiserfs_key * key)
61{ 63{
62 int version; 64 int version;
63
64 version = le_key_version (key);
65 65
66 if (le_key_k_type (version, key) == TYPE_STAT_DATA) 66 version = le_key_version(key);
67 return "SD";
68 if (le_key_k_type (version, key) == TYPE_DIRENTRY)
69 return "DIR";
70 if (le_key_k_type (version, key) == TYPE_DIRECT)
71 return "DIRECT";
72 if (le_key_k_type (version, key) == TYPE_INDIRECT)
73 return "IND";
74 return "UNKNOWN";
75}
76 67
68 if (le_key_k_type(version, key) == TYPE_STAT_DATA)
69 return "SD";
70 if (le_key_k_type(version, key) == TYPE_DIRENTRY)
71 return "DIR";
72 if (le_key_k_type(version, key) == TYPE_DIRECT)
73 return "DIRECT";
74 if (le_key_k_type(version, key) == TYPE_INDIRECT)
75 return "IND";
76 return "UNKNOWN";
77}
77 78
78/* %k */ 79/* %k */
79static void sprintf_le_key (char * buf, struct reiserfs_key * key) 80static void sprintf_le_key(char *buf, struct reiserfs_key *key)
80{ 81{
81 if (key) 82 if (key)
82 sprintf (buf, "[%d %d %s %s]", le32_to_cpu (key->k_dir_id), 83 sprintf(buf, "[%d %d %s %s]", le32_to_cpu(key->k_dir_id),
83 le32_to_cpu (key->k_objectid), le_offset (key), le_type (key)); 84 le32_to_cpu(key->k_objectid), le_offset(key),
84 else 85 le_type(key));
85 sprintf (buf, "[NULL]"); 86 else
87 sprintf(buf, "[NULL]");
86} 88}
87 89
88
89/* %K */ 90/* %K */
90static void sprintf_cpu_key (char * buf, struct cpu_key * key) 91static void sprintf_cpu_key(char *buf, struct cpu_key *key)
91{ 92{
92 if (key) 93 if (key)
93 sprintf (buf, "[%d %d %s %s]", key->on_disk_key.k_dir_id, 94 sprintf(buf, "[%d %d %s %s]", key->on_disk_key.k_dir_id,
94 key->on_disk_key.k_objectid, reiserfs_cpu_offset (key), 95 key->on_disk_key.k_objectid, reiserfs_cpu_offset(key),
95 cpu_type (key)); 96 cpu_type(key));
96 else 97 else
97 sprintf (buf, "[NULL]"); 98 sprintf(buf, "[NULL]");
98} 99}
99 100
100static void sprintf_de_head( char *buf, struct reiserfs_de_head *deh ) 101static void sprintf_de_head(char *buf, struct reiserfs_de_head *deh)
101{ 102{
102 if( deh ) 103 if (deh)
103 sprintf( buf, "[offset=%d dir_id=%d objectid=%d location=%d state=%04x]", deh_offset(deh), deh_dir_id(deh), 104 sprintf(buf,
104 deh_objectid(deh), deh_location(deh), deh_state(deh) ); 105 "[offset=%d dir_id=%d objectid=%d location=%d state=%04x]",
105 else 106 deh_offset(deh), deh_dir_id(deh), deh_objectid(deh),
106 sprintf( buf, "[NULL]" ); 107 deh_location(deh), deh_state(deh));
108 else
109 sprintf(buf, "[NULL]");
107 110
108} 111}
109 112
110static void sprintf_item_head (char * buf, struct item_head * ih) 113static void sprintf_item_head(char *buf, struct item_head *ih)
111{ 114{
112 if (ih) { 115 if (ih) {
113 strcpy (buf, (ih_version (ih) == KEY_FORMAT_3_6) ? "*3.6* " : "*3.5*"); 116 strcpy(buf,
114 sprintf_le_key (buf + strlen (buf), &(ih->ih_key)); 117 (ih_version(ih) == KEY_FORMAT_3_6) ? "*3.6* " : "*3.5*");
115 sprintf (buf + strlen (buf), ", item_len %d, item_location %d, " 118 sprintf_le_key(buf + strlen(buf), &(ih->ih_key));
116 "free_space(entry_count) %d", 119 sprintf(buf + strlen(buf), ", item_len %d, item_location %d, "
117 ih_item_len(ih), ih_location(ih), ih_free_space (ih)); 120 "free_space(entry_count) %d",
118 } else 121 ih_item_len(ih), ih_location(ih), ih_free_space(ih));
119 sprintf (buf, "[NULL]"); 122 } else
123 sprintf(buf, "[NULL]");
120} 124}
121 125
122 126static void sprintf_direntry(char *buf, struct reiserfs_dir_entry *de)
123static void sprintf_direntry (char * buf, struct reiserfs_dir_entry * de)
124{ 127{
125 char name[20]; 128 char name[20];
126 129
127 memcpy (name, de->de_name, de->de_namelen > 19 ? 19 : de->de_namelen); 130 memcpy(name, de->de_name, de->de_namelen > 19 ? 19 : de->de_namelen);
128 name [de->de_namelen > 19 ? 19 : de->de_namelen] = 0; 131 name[de->de_namelen > 19 ? 19 : de->de_namelen] = 0;
129 sprintf (buf, "\"%s\"==>[%d %d]", name, de->de_dir_id, de->de_objectid); 132 sprintf(buf, "\"%s\"==>[%d %d]", name, de->de_dir_id, de->de_objectid);
130} 133}
131 134
132 135static void sprintf_block_head(char *buf, struct buffer_head *bh)
133static void sprintf_block_head (char * buf, struct buffer_head * bh)
134{ 136{
135 sprintf (buf, "level=%d, nr_items=%d, free_space=%d rdkey ", 137 sprintf(buf, "level=%d, nr_items=%d, free_space=%d rdkey ",
136 B_LEVEL (bh), B_NR_ITEMS (bh), B_FREE_SPACE (bh)); 138 B_LEVEL(bh), B_NR_ITEMS(bh), B_FREE_SPACE(bh));
137} 139}
138 140
139 141static void sprintf_buffer_head(char *buf, struct buffer_head *bh)
140static void sprintf_buffer_head (char * buf, struct buffer_head * bh)
141{ 142{
142 char b[BDEVNAME_SIZE]; 143 char b[BDEVNAME_SIZE];
143 144
144 sprintf (buf, "dev %s, size %d, blocknr %llu, count %d, state 0x%lx, page %p, (%s, %s, %s)", 145 sprintf(buf,
145 bdevname (bh->b_bdev, b), bh->b_size, 146 "dev %s, size %d, blocknr %llu, count %d, state 0x%lx, page %p, (%s, %s, %s)",
146 (unsigned long long)bh->b_blocknr, 147 bdevname(bh->b_bdev, b), bh->b_size,
147 atomic_read (&(bh->b_count)), 148 (unsigned long long)bh->b_blocknr, atomic_read(&(bh->b_count)),
148 bh->b_state, bh->b_page, 149 bh->b_state, bh->b_page,
149 buffer_uptodate (bh) ? "UPTODATE" : "!UPTODATE", 150 buffer_uptodate(bh) ? "UPTODATE" : "!UPTODATE",
150 buffer_dirty (bh) ? "DIRTY" : "CLEAN", 151 buffer_dirty(bh) ? "DIRTY" : "CLEAN",
151 buffer_locked (bh) ? "LOCKED" : "UNLOCKED"); 152 buffer_locked(bh) ? "LOCKED" : "UNLOCKED");
152} 153}
153 154
154 155static void sprintf_disk_child(char *buf, struct disk_child *dc)
155static void sprintf_disk_child (char * buf, struct disk_child * dc)
156{ 156{
157 sprintf (buf, "[dc_number=%d, dc_size=%u]", dc_block_number(dc), dc_size(dc)); 157 sprintf(buf, "[dc_number=%d, dc_size=%u]", dc_block_number(dc),
158 dc_size(dc));
158} 159}
159 160
160 161static char *is_there_reiserfs_struct(char *fmt, int *what, int *skip)
161static char * is_there_reiserfs_struct (char * fmt, int * what, int * skip)
162{ 162{
163 char * k = fmt; 163 char *k = fmt;
164 164
165 *skip = 0; 165 *skip = 0;
166
167 while ((k = strchr (k, '%')) != NULL)
168 {
169 if (k[1] == 'k' || k[1] == 'K' || k[1] == 'h' || k[1] == 't' ||
170 k[1] == 'z' || k[1] == 'b' || k[1] == 'y' || k[1] == 'a' ) {
171 *what = k[1];
172 break;
173 }
174 (*skip) ++;
175 k ++;
176 }
177 return k;
178}
179 166
167 while ((k = strchr(k, '%')) != NULL) {
168 if (k[1] == 'k' || k[1] == 'K' || k[1] == 'h' || k[1] == 't' ||
169 k[1] == 'z' || k[1] == 'b' || k[1] == 'y' || k[1] == 'a') {
170 *what = k[1];
171 break;
172 }
173 (*skip)++;
174 k++;
175 }
176 return k;
177}
180 178
181/* debugging reiserfs we used to print out a lot of different 179/* debugging reiserfs we used to print out a lot of different
182 variables, like keys, item headers, buffer heads etc. Values of 180 variables, like keys, item headers, buffer heads etc. Values of
@@ -191,61 +189,64 @@ static char * is_there_reiserfs_struct (char * fmt, int * what, int * skip)
191 key->k_offset, key->k_uniqueness); 189 key->k_offset, key->k_uniqueness);
192*/ 190*/
193 191
194 192static void prepare_error_buf(const char *fmt, va_list args)
195static void 193{
196prepare_error_buf( const char *fmt, va_list args ) 194 char *fmt1 = fmt_buf;
197{ 195 char *k;
198 char * fmt1 = fmt_buf; 196 char *p = error_buf;
199 char * k; 197 int i, j, what, skip;
200 char * p = error_buf; 198
201 int i, j, what, skip; 199 strcpy(fmt1, fmt);
202 200
203 strcpy (fmt1, fmt); 201 while ((k = is_there_reiserfs_struct(fmt1, &what, &skip)) != NULL) {
204 202 *k = 0;
205 while( (k = is_there_reiserfs_struct( fmt1, &what, &skip )) != NULL ) 203
206 { 204 p += vsprintf(p, fmt1, args);
207 *k = 0; 205
208 206 for (i = 0; i < skip; i++)
209 p += vsprintf (p, fmt1, args); 207 j = va_arg(args, int);
210 208
211 for (i = 0; i < skip; i ++) 209 switch (what) {
212 j = va_arg (args, int); 210 case 'k':
213 211 sprintf_le_key(p, va_arg(args, struct reiserfs_key *));
214 switch (what) { 212 break;
215 case 'k': 213 case 'K':
216 sprintf_le_key (p, va_arg(args, struct reiserfs_key *)); 214 sprintf_cpu_key(p, va_arg(args, struct cpu_key *));
217 break; 215 break;
218 case 'K': 216 case 'h':
219 sprintf_cpu_key (p, va_arg(args, struct cpu_key *)); 217 sprintf_item_head(p, va_arg(args, struct item_head *));
220 break; 218 break;
221 case 'h': 219 case 't':
222 sprintf_item_head (p, va_arg(args, struct item_head *)); 220 sprintf_direntry(p,
223 break; 221 va_arg(args,
224 case 't': 222 struct reiserfs_dir_entry *));
225 sprintf_direntry (p, va_arg(args, struct reiserfs_dir_entry *)); 223 break;
226 break; 224 case 'y':
227 case 'y': 225 sprintf_disk_child(p,
228 sprintf_disk_child (p, va_arg(args, struct disk_child *)); 226 va_arg(args, struct disk_child *));
229 break; 227 break;
230 case 'z': 228 case 'z':
231 sprintf_block_head (p, va_arg(args, struct buffer_head *)); 229 sprintf_block_head(p,
232 break; 230 va_arg(args, struct buffer_head *));
233 case 'b': 231 break;
234 sprintf_buffer_head (p, va_arg(args, struct buffer_head *)); 232 case 'b':
235 break; 233 sprintf_buffer_head(p,
236 case 'a': 234 va_arg(args, struct buffer_head *));
237 sprintf_de_head (p, va_arg(args, struct reiserfs_de_head *)); 235 break;
238 break; 236 case 'a':
239 } 237 sprintf_de_head(p,
240 238 va_arg(args,
241 p += strlen (p); 239 struct reiserfs_de_head *));
242 fmt1 = k + 2; 240 break;
243 } 241 }
244 vsprintf (p, fmt1, args); 242
243 p += strlen(p);
244 fmt1 = k + 2;
245 }
246 vsprintf(p, fmt1, args);
245 247
246} 248}
247 249
248
249/* in addition to usual conversion specifiers this accepts reiserfs 250/* in addition to usual conversion specifiers this accepts reiserfs
250 specific conversion specifiers: 251 specific conversion specifiers:
251 %k to print little endian key, 252 %k to print little endian key,
@@ -264,43 +265,43 @@ prepare_error_buf( const char *fmt, va_list args )
264 va_end( args );\ 265 va_end( args );\
265} 266}
266 267
267void reiserfs_warning (struct super_block *sb, const char * fmt, ...) 268void reiserfs_warning(struct super_block *sb, const char *fmt, ...)
268{ 269{
269 do_reiserfs_warning(fmt); 270 do_reiserfs_warning(fmt);
270 if (sb) 271 if (sb)
271 printk (KERN_WARNING "ReiserFS: %s: warning: %s\n", 272 printk(KERN_WARNING "ReiserFS: %s: warning: %s\n",
272 reiserfs_bdevname (sb), error_buf); 273 reiserfs_bdevname(sb), error_buf);
273 else 274 else
274 printk (KERN_WARNING "ReiserFS: warning: %s\n", error_buf); 275 printk(KERN_WARNING "ReiserFS: warning: %s\n", error_buf);
275} 276}
276 277
277/* No newline.. reiserfs_info calls can be followed by printk's */ 278/* No newline.. reiserfs_info calls can be followed by printk's */
278void reiserfs_info (struct super_block *sb, const char * fmt, ...) 279void reiserfs_info(struct super_block *sb, const char *fmt, ...)
279{ 280{
280 do_reiserfs_warning(fmt); 281 do_reiserfs_warning(fmt);
281 if (sb) 282 if (sb)
282 printk (KERN_NOTICE "ReiserFS: %s: %s", 283 printk(KERN_NOTICE "ReiserFS: %s: %s",
283 reiserfs_bdevname (sb), error_buf); 284 reiserfs_bdevname(sb), error_buf);
284 else 285 else
285 printk (KERN_NOTICE "ReiserFS: %s", error_buf); 286 printk(KERN_NOTICE "ReiserFS: %s", error_buf);
286} 287}
287 288
288/* No newline.. reiserfs_printk calls can be followed by printk's */ 289/* No newline.. reiserfs_printk calls can be followed by printk's */
289static void reiserfs_printk (const char * fmt, ...) 290static void reiserfs_printk(const char *fmt, ...)
290{ 291{
291 do_reiserfs_warning(fmt); 292 do_reiserfs_warning(fmt);
292 printk (error_buf); 293 printk(error_buf);
293} 294}
294 295
295void reiserfs_debug (struct super_block *s, int level, const char * fmt, ...) 296void reiserfs_debug(struct super_block *s, int level, const char *fmt, ...)
296{ 297{
297#ifdef CONFIG_REISERFS_CHECK 298#ifdef CONFIG_REISERFS_CHECK
298 do_reiserfs_warning(fmt); 299 do_reiserfs_warning(fmt);
299 if (s) 300 if (s)
300 printk (KERN_DEBUG "ReiserFS: %s: %s\n", 301 printk(KERN_DEBUG "ReiserFS: %s: %s\n",
301 reiserfs_bdevname (s), error_buf); 302 reiserfs_bdevname(s), error_buf);
302 else 303 else
303 printk (KERN_DEBUG "ReiserFS: %s\n", error_buf); 304 printk(KERN_DEBUG "ReiserFS: %s\n", error_buf);
304#endif 305#endif
305} 306}
306 307
@@ -349,379 +350,403 @@ void reiserfs_debug (struct super_block *s, int level, const char * fmt, ...)
349 350
350 . */ 351 . */
351 352
352
353#ifdef CONFIG_REISERFS_CHECK 353#ifdef CONFIG_REISERFS_CHECK
354extern struct tree_balance * cur_tb; 354extern struct tree_balance *cur_tb;
355#endif 355#endif
356 356
357void reiserfs_panic (struct super_block * sb, const char * fmt, ...) 357void reiserfs_panic(struct super_block *sb, const char *fmt, ...)
358{ 358{
359 do_reiserfs_warning(fmt); 359 do_reiserfs_warning(fmt);
360 printk (KERN_EMERG "REISERFS: panic (device %s): %s\n", 360 printk(KERN_EMERG "REISERFS: panic (device %s): %s\n",
361 reiserfs_bdevname (sb), error_buf); 361 reiserfs_bdevname(sb), error_buf);
362 BUG (); 362 BUG();
363 363
364 /* this is not actually called, but makes reiserfs_panic() "noreturn" */ 364 /* this is not actually called, but makes reiserfs_panic() "noreturn" */
365 panic ("REISERFS: panic (device %s): %s\n", 365 panic("REISERFS: panic (device %s): %s\n",
366 reiserfs_bdevname (sb), error_buf); 366 reiserfs_bdevname(sb), error_buf);
367} 367}
368 368
369void 369void reiserfs_abort(struct super_block *sb, int errno, const char *fmt, ...)
370reiserfs_abort (struct super_block *sb, int errno, const char *fmt, ...)
371{ 370{
372 do_reiserfs_warning (fmt); 371 do_reiserfs_warning(fmt);
373 372
374 if (reiserfs_error_panic (sb)) { 373 if (reiserfs_error_panic(sb)) {
375 panic (KERN_CRIT "REISERFS: panic (device %s): %s\n", 374 panic(KERN_CRIT "REISERFS: panic (device %s): %s\n",
376 reiserfs_bdevname (sb), error_buf); 375 reiserfs_bdevname(sb), error_buf);
377 } 376 }
378 377
379 if (sb->s_flags & MS_RDONLY) 378 if (sb->s_flags & MS_RDONLY)
380 return; 379 return;
381 380
382 printk (KERN_CRIT "REISERFS: abort (device %s): %s\n", 381 printk(KERN_CRIT "REISERFS: abort (device %s): %s\n",
383 reiserfs_bdevname (sb), error_buf); 382 reiserfs_bdevname(sb), error_buf);
384 383
385 sb->s_flags |= MS_RDONLY; 384 sb->s_flags |= MS_RDONLY;
386 reiserfs_journal_abort (sb, errno); 385 reiserfs_journal_abort(sb, errno);
387} 386}
388 387
389/* this prints internal nodes (4 keys/items in line) (dc_number, 388/* this prints internal nodes (4 keys/items in line) (dc_number,
390 dc_size)[k_dirid, k_objectid, k_offset, k_uniqueness](dc_number, 389 dc_size)[k_dirid, k_objectid, k_offset, k_uniqueness](dc_number,
391 dc_size)...*/ 390 dc_size)...*/
392static int print_internal (struct buffer_head * bh, int first, int last) 391static int print_internal(struct buffer_head *bh, int first, int last)
393{ 392{
394 struct reiserfs_key * key; 393 struct reiserfs_key *key;
395 struct disk_child * dc; 394 struct disk_child *dc;
396 int i; 395 int i;
397 int from, to; 396 int from, to;
398
399 if (!B_IS_KEYS_LEVEL (bh))
400 return 1;
401
402 check_internal (bh);
403
404 if (first == -1) {
405 from = 0;
406 to = B_NR_ITEMS (bh);
407 } else {
408 from = first;
409 to = last < B_NR_ITEMS (bh) ? last : B_NR_ITEMS (bh);
410 }
411
412 reiserfs_printk ("INTERNAL NODE (%ld) contains %z\n", bh->b_blocknr, bh);
413
414 dc = B_N_CHILD (bh, from);
415 reiserfs_printk ("PTR %d: %y ", from, dc);
416
417 for (i = from, key = B_N_PDELIM_KEY (bh, from), dc ++; i < to; i ++, key ++, dc ++) {
418 reiserfs_printk ("KEY %d: %k PTR %d: %y ", i, key, i + 1, dc);
419 if (i && i % 4 == 0)
420 printk ("\n");
421 }
422 printk ("\n");
423 return 0;
424}
425 397
398 if (!B_IS_KEYS_LEVEL(bh))
399 return 1;
426 400
401 check_internal(bh);
427 402
403 if (first == -1) {
404 from = 0;
405 to = B_NR_ITEMS(bh);
406 } else {
407 from = first;
408 to = last < B_NR_ITEMS(bh) ? last : B_NR_ITEMS(bh);
409 }
428 410
411 reiserfs_printk("INTERNAL NODE (%ld) contains %z\n", bh->b_blocknr, bh);
429 412
430static int print_leaf (struct buffer_head * bh, int print_mode, int first, int last) 413 dc = B_N_CHILD(bh, from);
431{ 414 reiserfs_printk("PTR %d: %y ", from, dc);
432 struct block_head * blkh;
433 struct item_head * ih;
434 int i, nr;
435 int from, to;
436 415
437 if (!B_IS_ITEMS_LEVEL (bh)) 416 for (i = from, key = B_N_PDELIM_KEY(bh, from), dc++; i < to;
438 return 1; 417 i++, key++, dc++) {
418 reiserfs_printk("KEY %d: %k PTR %d: %y ", i, key, i + 1, dc);
419 if (i && i % 4 == 0)
420 printk("\n");
421 }
422 printk("\n");
423 return 0;
424}
439 425
440 check_leaf (bh); 426static int print_leaf(struct buffer_head *bh, int print_mode, int first,
427 int last)
428{
429 struct block_head *blkh;
430 struct item_head *ih;
431 int i, nr;
432 int from, to;
441 433
442 blkh = B_BLK_HEAD (bh); 434 if (!B_IS_ITEMS_LEVEL(bh))
443 ih = B_N_PITEM_HEAD (bh,0); 435 return 1;
444 nr = blkh_nr_item(blkh);
445 436
446 printk ("\n===================================================================\n"); 437 check_leaf(bh);
447 reiserfs_printk ("LEAF NODE (%ld) contains %z\n", bh->b_blocknr, bh);
448 438
449 if (!(print_mode & PRINT_LEAF_ITEMS)) { 439 blkh = B_BLK_HEAD(bh);
450 reiserfs_printk ("FIRST ITEM_KEY: %k, LAST ITEM KEY: %k\n", 440 ih = B_N_PITEM_HEAD(bh, 0);
451 &(ih->ih_key), &((ih + nr - 1)->ih_key)); 441 nr = blkh_nr_item(blkh);
452 return 0;
453 }
454 442
455 if (first < 0 || first > nr - 1) 443 printk
456 from = 0; 444 ("\n===================================================================\n");
457 else 445 reiserfs_printk("LEAF NODE (%ld) contains %z\n", bh->b_blocknr, bh);
458 from = first;
459 446
460 if (last < 0 || last > nr ) 447 if (!(print_mode & PRINT_LEAF_ITEMS)) {
461 to = nr; 448 reiserfs_printk("FIRST ITEM_KEY: %k, LAST ITEM KEY: %k\n",
462 else 449 &(ih->ih_key), &((ih + nr - 1)->ih_key));
463 to = last; 450 return 0;
451 }
464 452
465 ih += from; 453 if (first < 0 || first > nr - 1)
466 printk ("-------------------------------------------------------------------------------\n"); 454 from = 0;
467 printk ("|##| type | key | ilen | free_space | version | loc |\n"); 455 else
468 for (i = from; i < to; i++, ih ++) { 456 from = first;
469 printk ("-------------------------------------------------------------------------------\n"); 457
470 reiserfs_printk ("|%2d| %h |\n", i, ih); 458 if (last < 0 || last > nr)
471 if (print_mode & PRINT_LEAF_ITEMS) 459 to = nr;
472 op_print_item (ih, B_I_PITEM (bh, ih)); 460 else
473 } 461 to = last;
462
463 ih += from;
464 printk
465 ("-------------------------------------------------------------------------------\n");
466 printk
467 ("|##| type | key | ilen | free_space | version | loc |\n");
468 for (i = from; i < to; i++, ih++) {
469 printk
470 ("-------------------------------------------------------------------------------\n");
471 reiserfs_printk("|%2d| %h |\n", i, ih);
472 if (print_mode & PRINT_LEAF_ITEMS)
473 op_print_item(ih, B_I_PITEM(bh, ih));
474 }
474 475
475 printk ("===================================================================\n"); 476 printk
477 ("===================================================================\n");
476 478
477 return 0; 479 return 0;
478} 480}
479 481
480char * reiserfs_hashname(int code) 482char *reiserfs_hashname(int code)
481{ 483{
482 if ( code == YURA_HASH) 484 if (code == YURA_HASH)
483 return "rupasov"; 485 return "rupasov";
484 if ( code == TEA_HASH) 486 if (code == TEA_HASH)
485 return "tea"; 487 return "tea";
486 if ( code == R5_HASH) 488 if (code == R5_HASH)
487 return "r5"; 489 return "r5";
488 490
489 return "unknown"; 491 return "unknown";
490} 492}
491 493
492/* return 1 if this is not super block */ 494/* return 1 if this is not super block */
493static int print_super_block (struct buffer_head * bh) 495static int print_super_block(struct buffer_head *bh)
494{ 496{
495 struct reiserfs_super_block * rs = (struct reiserfs_super_block *)(bh->b_data); 497 struct reiserfs_super_block *rs =
496 int skipped, data_blocks; 498 (struct reiserfs_super_block *)(bh->b_data);
497 char *version; 499 int skipped, data_blocks;
498 char b[BDEVNAME_SIZE]; 500 char *version;
499 501 char b[BDEVNAME_SIZE];
500 if (is_reiserfs_3_5(rs)) { 502
501 version = "3.5"; 503 if (is_reiserfs_3_5(rs)) {
502 } else if (is_reiserfs_3_6(rs)) { 504 version = "3.5";
503 version = "3.6"; 505 } else if (is_reiserfs_3_6(rs)) {
504 } else if (is_reiserfs_jr(rs)) { 506 version = "3.6";
505 version = ((sb_version(rs) == REISERFS_VERSION_2) ? 507 } else if (is_reiserfs_jr(rs)) {
506 "3.6" : "3.5"); 508 version = ((sb_version(rs) == REISERFS_VERSION_2) ?
507 } else { 509 "3.6" : "3.5");
508 return 1; 510 } else {
509 } 511 return 1;
510 512 }
511 printk ("%s\'s super block is in block %llu\n", bdevname (bh->b_bdev, b), 513
512 (unsigned long long)bh->b_blocknr); 514 printk("%s\'s super block is in block %llu\n", bdevname(bh->b_bdev, b),
513 printk ("Reiserfs version %s\n", version ); 515 (unsigned long long)bh->b_blocknr);
514 printk ("Block count %u\n", sb_block_count(rs)); 516 printk("Reiserfs version %s\n", version);
515 printk ("Blocksize %d\n", sb_blocksize(rs)); 517 printk("Block count %u\n", sb_block_count(rs));
516 printk ("Free blocks %u\n", sb_free_blocks(rs)); 518 printk("Blocksize %d\n", sb_blocksize(rs));
517 // FIXME: this would be confusing if 519 printk("Free blocks %u\n", sb_free_blocks(rs));
518 // someone stores reiserfs super block in some data block ;) 520 // FIXME: this would be confusing if
521 // someone stores reiserfs super block in some data block ;)
519// skipped = (bh->b_blocknr * bh->b_size) / sb_blocksize(rs); 522// skipped = (bh->b_blocknr * bh->b_size) / sb_blocksize(rs);
520 skipped = bh->b_blocknr; 523 skipped = bh->b_blocknr;
521 data_blocks = sb_block_count(rs) - skipped - 1 - sb_bmap_nr(rs) - 524 data_blocks = sb_block_count(rs) - skipped - 1 - sb_bmap_nr(rs) -
522 (!is_reiserfs_jr(rs) ? sb_jp_journal_size(rs) + 1 : sb_reserved_for_journal(rs)) - 525 (!is_reiserfs_jr(rs) ? sb_jp_journal_size(rs) +
523 sb_free_blocks(rs); 526 1 : sb_reserved_for_journal(rs)) - sb_free_blocks(rs);
524 printk ("Busy blocks (skipped %d, bitmaps - %d, journal (or reserved) blocks - %d\n" 527 printk
525 "1 super block, %d data blocks\n", 528 ("Busy blocks (skipped %d, bitmaps - %d, journal (or reserved) blocks - %d\n"
526 skipped, sb_bmap_nr(rs), (!is_reiserfs_jr(rs) ? (sb_jp_journal_size(rs) + 1) : 529 "1 super block, %d data blocks\n", skipped, sb_bmap_nr(rs),
527 sb_reserved_for_journal(rs)) , data_blocks); 530 (!is_reiserfs_jr(rs) ? (sb_jp_journal_size(rs) + 1) :
528 printk ("Root block %u\n", sb_root_block(rs)); 531 sb_reserved_for_journal(rs)), data_blocks);
529 printk ("Journal block (first) %d\n", sb_jp_journal_1st_block(rs)); 532 printk("Root block %u\n", sb_root_block(rs));
530 printk ("Journal dev %d\n", sb_jp_journal_dev(rs)); 533 printk("Journal block (first) %d\n", sb_jp_journal_1st_block(rs));
531 printk ("Journal orig size %d\n", sb_jp_journal_size(rs)); 534 printk("Journal dev %d\n", sb_jp_journal_dev(rs));
532 printk ("FS state %d\n", sb_fs_state(rs)); 535 printk("Journal orig size %d\n", sb_jp_journal_size(rs));
533 printk ("Hash function \"%s\"\n", 536 printk("FS state %d\n", sb_fs_state(rs));
534 reiserfs_hashname(sb_hash_function_code(rs))); 537 printk("Hash function \"%s\"\n",
535 538 reiserfs_hashname(sb_hash_function_code(rs)));
536 printk ("Tree height %d\n", sb_tree_height(rs)); 539
537 return 0; 540 printk("Tree height %d\n", sb_tree_height(rs));
541 return 0;
538} 542}
539 543
540static int print_desc_block (struct buffer_head * bh) 544static int print_desc_block(struct buffer_head *bh)
541{ 545{
542 struct reiserfs_journal_desc * desc; 546 struct reiserfs_journal_desc *desc;
543 547
544 if (memcmp(get_journal_desc_magic (bh), JOURNAL_DESC_MAGIC, 8)) 548 if (memcmp(get_journal_desc_magic(bh), JOURNAL_DESC_MAGIC, 8))
545 return 1; 549 return 1;
546 550
547 desc = (struct reiserfs_journal_desc *)(bh->b_data); 551 desc = (struct reiserfs_journal_desc *)(bh->b_data);
548 printk ("Desc block %llu (j_trans_id %d, j_mount_id %d, j_len %d)", 552 printk("Desc block %llu (j_trans_id %d, j_mount_id %d, j_len %d)",
549 (unsigned long long)bh->b_blocknr, get_desc_trans_id (desc), get_desc_mount_id (desc), 553 (unsigned long long)bh->b_blocknr, get_desc_trans_id(desc),
550 get_desc_trans_len (desc)); 554 get_desc_mount_id(desc), get_desc_trans_len(desc));
551 555
552 return 0; 556 return 0;
553} 557}
554 558
555 559void print_block(struct buffer_head *bh, ...) //int print_mode, int first, int last)
556void print_block (struct buffer_head * bh, ...)//int print_mode, int first, int last)
557{ 560{
558 va_list args; 561 va_list args;
559 int mode, first, last; 562 int mode, first, last;
560 563
561 va_start (args, bh); 564 va_start(args, bh);
562 565
563 if ( ! bh ) { 566 if (!bh) {
564 printk("print_block: buffer is NULL\n"); 567 printk("print_block: buffer is NULL\n");
565 return; 568 return;
566 } 569 }
567 570
568 mode = va_arg (args, int); 571 mode = va_arg(args, int);
569 first = va_arg (args, int); 572 first = va_arg(args, int);
570 last = va_arg (args, int); 573 last = va_arg(args, int);
571 if (print_leaf (bh, mode, first, last)) 574 if (print_leaf(bh, mode, first, last))
572 if (print_internal (bh, first, last)) 575 if (print_internal(bh, first, last))
573 if (print_super_block (bh)) 576 if (print_super_block(bh))
574 if (print_desc_block (bh)) 577 if (print_desc_block(bh))
575 printk ("Block %llu contains unformatted data\n", (unsigned long long)bh->b_blocknr); 578 printk
579 ("Block %llu contains unformatted data\n",
580 (unsigned long long)bh->b_blocknr);
576} 581}
577 582
578
579
580static char print_tb_buf[2048]; 583static char print_tb_buf[2048];
581 584
582/* this stores initial state of tree balance in the print_tb_buf */ 585/* this stores initial state of tree balance in the print_tb_buf */
583void store_print_tb (struct tree_balance * tb) 586void store_print_tb(struct tree_balance *tb)
584{ 587{
585 int h = 0; 588 int h = 0;
586 int i; 589 int i;
587 struct buffer_head * tbSh, * tbFh; 590 struct buffer_head *tbSh, *tbFh;
588 591
589 if (!tb) 592 if (!tb)
590 return; 593 return;
591 594
592 sprintf (print_tb_buf, "\n" 595 sprintf(print_tb_buf, "\n"
593 "BALANCING %d\n" 596 "BALANCING %d\n"
594 "MODE=%c, ITEM_POS=%d POS_IN_ITEM=%d\n" 597 "MODE=%c, ITEM_POS=%d POS_IN_ITEM=%d\n"
595 "=====================================================================\n" 598 "=====================================================================\n"
596 "* h * S * L * R * F * FL * FR * CFL * CFR *\n", 599 "* h * S * L * R * F * FL * FR * CFL * CFR *\n",
597 REISERFS_SB(tb->tb_sb)->s_do_balance, 600 REISERFS_SB(tb->tb_sb)->s_do_balance,
598 tb->tb_mode, PATH_LAST_POSITION (tb->tb_path), tb->tb_path->pos_in_item); 601 tb->tb_mode, PATH_LAST_POSITION(tb->tb_path),
599 602 tb->tb_path->pos_in_item);
600 for (h = 0; h < sizeof(tb->insert_size) / sizeof (tb->insert_size[0]); h ++) { 603
601 if (PATH_H_PATH_OFFSET (tb->tb_path, h) <= tb->tb_path->path_length && 604 for (h = 0; h < sizeof(tb->insert_size) / sizeof(tb->insert_size[0]);
602 PATH_H_PATH_OFFSET (tb->tb_path, h) > ILLEGAL_PATH_ELEMENT_OFFSET) { 605 h++) {
603 tbSh = PATH_H_PBUFFER (tb->tb_path, h); 606 if (PATH_H_PATH_OFFSET(tb->tb_path, h) <=
604 tbFh = PATH_H_PPARENT (tb->tb_path, h); 607 tb->tb_path->path_length
605 } else { 608 && PATH_H_PATH_OFFSET(tb->tb_path,
606 tbSh = NULL; 609 h) > ILLEGAL_PATH_ELEMENT_OFFSET) {
607 tbFh = NULL; 610 tbSh = PATH_H_PBUFFER(tb->tb_path, h);
611 tbFh = PATH_H_PPARENT(tb->tb_path, h);
612 } else {
613 tbSh = NULL;
614 tbFh = NULL;
615 }
616 sprintf(print_tb_buf + strlen(print_tb_buf),
617 "* %d * %3lld(%2d) * %3lld(%2d) * %3lld(%2d) * %5lld * %5lld * %5lld * %5lld * %5lld *\n",
618 h,
619 (tbSh) ? (long long)(tbSh->b_blocknr) : (-1LL),
620 (tbSh) ? atomic_read(&(tbSh->b_count)) : -1,
621 (tb->L[h]) ? (long long)(tb->L[h]->b_blocknr) : (-1LL),
622 (tb->L[h]) ? atomic_read(&(tb->L[h]->b_count)) : -1,
623 (tb->R[h]) ? (long long)(tb->R[h]->b_blocknr) : (-1LL),
624 (tb->R[h]) ? atomic_read(&(tb->R[h]->b_count)) : -1,
625 (tbFh) ? (long long)(tbFh->b_blocknr) : (-1LL),
626 (tb->FL[h]) ? (long long)(tb->FL[h]->
627 b_blocknr) : (-1LL),
628 (tb->FR[h]) ? (long long)(tb->FR[h]->
629 b_blocknr) : (-1LL),
630 (tb->CFL[h]) ? (long long)(tb->CFL[h]->
631 b_blocknr) : (-1LL),
632 (tb->CFR[h]) ? (long long)(tb->CFR[h]->
633 b_blocknr) : (-1LL));
608 } 634 }
609 sprintf (print_tb_buf + strlen (print_tb_buf),
610 "* %d * %3lld(%2d) * %3lld(%2d) * %3lld(%2d) * %5lld * %5lld * %5lld * %5lld * %5lld *\n",
611 h,
612 (tbSh) ? (long long)(tbSh->b_blocknr):(-1LL),
613 (tbSh) ? atomic_read (&(tbSh->b_count)) : -1,
614 (tb->L[h]) ? (long long)(tb->L[h]->b_blocknr):(-1LL),
615 (tb->L[h]) ? atomic_read (&(tb->L[h]->b_count)) : -1,
616 (tb->R[h]) ? (long long)(tb->R[h]->b_blocknr):(-1LL),
617 (tb->R[h]) ? atomic_read (&(tb->R[h]->b_count)) : -1,
618 (tbFh) ? (long long)(tbFh->b_blocknr):(-1LL),
619 (tb->FL[h]) ? (long long)(tb->FL[h]->b_blocknr):(-1LL),
620 (tb->FR[h]) ? (long long)(tb->FR[h]->b_blocknr):(-1LL),
621 (tb->CFL[h]) ? (long long)(tb->CFL[h]->b_blocknr):(-1LL),
622 (tb->CFR[h]) ? (long long)(tb->CFR[h]->b_blocknr):(-1LL));
623 }
624
625 sprintf (print_tb_buf + strlen (print_tb_buf),
626 "=====================================================================\n"
627 "* h * size * ln * lb * rn * rb * blkn * s0 * s1 * s1b * s2 * s2b * curb * lk * rk *\n"
628 "* 0 * %4d * %2d * %2d * %2d * %2d * %4d * %2d * %2d * %3d * %2d * %3d * %4d * %2d * %2d *\n",
629 tb->insert_size[0], tb->lnum[0], tb->lbytes, tb->rnum[0],tb->rbytes, tb->blknum[0],
630 tb->s0num, tb->s1num,tb->s1bytes, tb->s2num, tb->s2bytes, tb->cur_blknum, tb->lkey[0], tb->rkey[0]);
631
632 /* this prints balance parameters for non-leaf levels */
633 h = 0;
634 do {
635 h++;
636 sprintf (print_tb_buf + strlen (print_tb_buf),
637 "* %d * %4d * %2d * * %2d * * %2d *\n",
638 h, tb->insert_size[h], tb->lnum[h], tb->rnum[h], tb->blknum[h]);
639 } while (tb->insert_size[h]);
640
641 sprintf (print_tb_buf + strlen (print_tb_buf),
642 "=====================================================================\n"
643 "FEB list: ");
644
645 /* print FEB list (list of buffers in form (bh (b_blocknr, b_count), that will be used for new nodes) */
646 h = 0;
647 for (i = 0; i < sizeof (tb->FEB) / sizeof (tb->FEB[0]); i ++)
648 sprintf (print_tb_buf + strlen (print_tb_buf),
649 "%p (%llu %d)%s", tb->FEB[i], tb->FEB[i] ? (unsigned long long)tb->FEB[i]->b_blocknr : 0ULL,
650 tb->FEB[i] ? atomic_read (&(tb->FEB[i]->b_count)) : 0,
651 (i == sizeof (tb->FEB) / sizeof (tb->FEB[0]) - 1) ? "\n" : ", ");
652
653 sprintf (print_tb_buf + strlen (print_tb_buf),
654 "======================== the end ====================================\n");
655}
656
657void print_cur_tb (char * mes)
658{
659 printk ("%s\n%s", mes, print_tb_buf);
660}
661
662static void check_leaf_block_head (struct buffer_head * bh)
663{
664 struct block_head * blkh;
665 int nr;
666
667 blkh = B_BLK_HEAD (bh);
668 nr = blkh_nr_item(blkh);
669 if ( nr > (bh->b_size - BLKH_SIZE) / IH_SIZE)
670 reiserfs_panic (NULL, "vs-6010: check_leaf_block_head: invalid item number %z", bh);
671 if ( blkh_free_space(blkh) >
672 bh->b_size - BLKH_SIZE - IH_SIZE * nr )
673 reiserfs_panic (NULL, "vs-6020: check_leaf_block_head: invalid free space %z", bh);
674
675}
676 635
677static void check_internal_block_head (struct buffer_head * bh) 636 sprintf(print_tb_buf + strlen(print_tb_buf),
678{ 637 "=====================================================================\n"
679 struct block_head * blkh; 638 "* h * size * ln * lb * rn * rb * blkn * s0 * s1 * s1b * s2 * s2b * curb * lk * rk *\n"
680 639 "* 0 * %4d * %2d * %2d * %2d * %2d * %4d * %2d * %2d * %3d * %2d * %3d * %4d * %2d * %2d *\n",
681 blkh = B_BLK_HEAD (bh); 640 tb->insert_size[0], tb->lnum[0], tb->lbytes, tb->rnum[0],
682 if (!(B_LEVEL (bh) > DISK_LEAF_NODE_LEVEL && B_LEVEL (bh) <= MAX_HEIGHT)) 641 tb->rbytes, tb->blknum[0], tb->s0num, tb->s1num, tb->s1bytes,
683 reiserfs_panic (NULL, "vs-6025: check_internal_block_head: invalid level %z", bh); 642 tb->s2num, tb->s2bytes, tb->cur_blknum, tb->lkey[0],
643 tb->rkey[0]);
644
645 /* this prints balance parameters for non-leaf levels */
646 h = 0;
647 do {
648 h++;
649 sprintf(print_tb_buf + strlen(print_tb_buf),
650 "* %d * %4d * %2d * * %2d * * %2d *\n",
651 h, tb->insert_size[h], tb->lnum[h], tb->rnum[h],
652 tb->blknum[h]);
653 } while (tb->insert_size[h]);
684 654
685 if (B_NR_ITEMS (bh) > (bh->b_size - BLKH_SIZE) / IH_SIZE) 655 sprintf(print_tb_buf + strlen(print_tb_buf),
686 reiserfs_panic (NULL, "vs-6030: check_internal_block_head: invalid item number %z", bh); 656 "=====================================================================\n"
657 "FEB list: ");
687 658
688 if (B_FREE_SPACE (bh) != 659 /* print FEB list (list of buffers in form (bh (b_blocknr, b_count), that will be used for new nodes) */
689 bh->b_size - BLKH_SIZE - KEY_SIZE * B_NR_ITEMS (bh) - DC_SIZE * (B_NR_ITEMS (bh) + 1)) 660 h = 0;
690 reiserfs_panic (NULL, "vs-6040: check_internal_block_head: invalid free space %z", bh); 661 for (i = 0; i < sizeof(tb->FEB) / sizeof(tb->FEB[0]); i++)
662 sprintf(print_tb_buf + strlen(print_tb_buf),
663 "%p (%llu %d)%s", tb->FEB[i],
664 tb->FEB[i] ? (unsigned long long)tb->FEB[i]->
665 b_blocknr : 0ULL,
666 tb->FEB[i] ? atomic_read(&(tb->FEB[i]->b_count)) : 0,
667 (i ==
668 sizeof(tb->FEB) / sizeof(tb->FEB[0]) -
669 1) ? "\n" : ", ");
691 670
671 sprintf(print_tb_buf + strlen(print_tb_buf),
672 "======================== the end ====================================\n");
692} 673}
693 674
675void print_cur_tb(char *mes)
676{
677 printk("%s\n%s", mes, print_tb_buf);
678}
694 679
695void check_leaf (struct buffer_head * bh) 680static void check_leaf_block_head(struct buffer_head *bh)
696{ 681{
697 int i; 682 struct block_head *blkh;
698 struct item_head * ih; 683 int nr;
684
685 blkh = B_BLK_HEAD(bh);
686 nr = blkh_nr_item(blkh);
687 if (nr > (bh->b_size - BLKH_SIZE) / IH_SIZE)
688 reiserfs_panic(NULL,
689 "vs-6010: check_leaf_block_head: invalid item number %z",
690 bh);
691 if (blkh_free_space(blkh) > bh->b_size - BLKH_SIZE - IH_SIZE * nr)
692 reiserfs_panic(NULL,
693 "vs-6020: check_leaf_block_head: invalid free space %z",
694 bh);
699 695
700 if (!bh)
701 return;
702 check_leaf_block_head (bh);
703 for (i = 0, ih = B_N_PITEM_HEAD (bh, 0); i < B_NR_ITEMS (bh); i ++, ih ++)
704 op_check_item (ih, B_I_PITEM (bh, ih));
705} 696}
706 697
698static void check_internal_block_head(struct buffer_head *bh)
699{
700 struct block_head *blkh;
701
702 blkh = B_BLK_HEAD(bh);
703 if (!(B_LEVEL(bh) > DISK_LEAF_NODE_LEVEL && B_LEVEL(bh) <= MAX_HEIGHT))
704 reiserfs_panic(NULL,
705 "vs-6025: check_internal_block_head: invalid level %z",
706 bh);
707
708 if (B_NR_ITEMS(bh) > (bh->b_size - BLKH_SIZE) / IH_SIZE)
709 reiserfs_panic(NULL,
710 "vs-6030: check_internal_block_head: invalid item number %z",
711 bh);
712
713 if (B_FREE_SPACE(bh) !=
714 bh->b_size - BLKH_SIZE - KEY_SIZE * B_NR_ITEMS(bh) -
715 DC_SIZE * (B_NR_ITEMS(bh) + 1))
716 reiserfs_panic(NULL,
717 "vs-6040: check_internal_block_head: invalid free space %z",
718 bh);
719
720}
707 721
708void check_internal (struct buffer_head * bh) 722void check_leaf(struct buffer_head *bh)
709{ 723{
710 if (!bh) 724 int i;
711 return; 725 struct item_head *ih;
712 check_internal_block_head (bh); 726
727 if (!bh)
728 return;
729 check_leaf_block_head(bh);
730 for (i = 0, ih = B_N_PITEM_HEAD(bh, 0); i < B_NR_ITEMS(bh); i++, ih++)
731 op_check_item(ih, B_I_PITEM(bh, ih));
713} 732}
714 733
734void check_internal(struct buffer_head *bh)
735{
736 if (!bh)
737 return;
738 check_internal_block_head(bh);
739}
715 740
716void print_statistics (struct super_block * s) 741void print_statistics(struct super_block *s)
717{ 742{
718 743
719 /* 744 /*
720 printk ("reiserfs_put_super: session statistics: balances %d, fix_nodes %d, \ 745 printk ("reiserfs_put_super: session statistics: balances %d, fix_nodes %d, \
721bmap with search %d, without %d, dir2ind %d, ind2dir %d\n", 746 bmap with search %d, without %d, dir2ind %d, ind2dir %d\n",
722 REISERFS_SB(s)->s_do_balance, REISERFS_SB(s)->s_fix_nodes, 747 REISERFS_SB(s)->s_do_balance, REISERFS_SB(s)->s_fix_nodes,
723 REISERFS_SB(s)->s_bmaps, REISERFS_SB(s)->s_bmaps_without_search, 748 REISERFS_SB(s)->s_bmaps, REISERFS_SB(s)->s_bmaps_without_search,
724 REISERFS_SB(s)->s_direct2indirect, REISERFS_SB(s)->s_indirect2direct); 749 REISERFS_SB(s)->s_direct2indirect, REISERFS_SB(s)->s_indirect2direct);
725 */ 750 */
726 751
727} 752}
diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
index e242ebc7f6f6..fc2f43c75df4 100644
--- a/fs/reiserfs/procfs.c
+++ b/fs/reiserfs/procfs.c
@@ -33,28 +33,27 @@
33static int show_version(struct seq_file *m, struct super_block *sb) 33static int show_version(struct seq_file *m, struct super_block *sb)
34{ 34{
35 char *format; 35 char *format;
36 36
37 if ( REISERFS_SB(sb)->s_properties & (1 << REISERFS_3_6) ) { 37 if (REISERFS_SB(sb)->s_properties & (1 << REISERFS_3_6)) {
38 format = "3.6"; 38 format = "3.6";
39 } else if ( REISERFS_SB(sb)->s_properties & (1 << REISERFS_3_5) ) { 39 } else if (REISERFS_SB(sb)->s_properties & (1 << REISERFS_3_5)) {
40 format = "3.5"; 40 format = "3.5";
41 } else { 41 } else {
42 format = "unknown"; 42 format = "unknown";
43 } 43 }
44 44
45 seq_printf(m, "%s format\twith checks %s\n", 45 seq_printf(m, "%s format\twith checks %s\n", format,
46 format,
47#if defined( CONFIG_REISERFS_CHECK ) 46#if defined( CONFIG_REISERFS_CHECK )
48 "on" 47 "on"
49#else 48#else
50 "off" 49 "off"
51#endif 50#endif
52 ); 51 );
53 return 0; 52 return 0;
54} 53}
55 54
56int reiserfs_global_version_in_proc( char *buffer, char **start, off_t offset, 55int reiserfs_global_version_in_proc(char *buffer, char **start, off_t offset,
57 int count, int *eof, void *data ) 56 int count, int *eof, void *data)
58{ 57{
59 *start = buffer; 58 *start = buffer;
60 *eof = 1; 59 *eof = 1;
@@ -79,87 +78,68 @@ int reiserfs_global_version_in_proc( char *buffer, char **start, off_t offset,
79 78
80#define DJF( x ) le32_to_cpu( rs -> x ) 79#define DJF( x ) le32_to_cpu( rs -> x )
81#define DJV( x ) le32_to_cpu( s_v1 -> x ) 80#define DJV( x ) le32_to_cpu( s_v1 -> x )
82#define DJP( x ) le32_to_cpu( jp -> x ) 81#define DJP( x ) le32_to_cpu( jp -> x )
83#define JF( x ) ( r -> s_journal -> x ) 82#define JF( x ) ( r -> s_journal -> x )
84 83
85static int show_super(struct seq_file *m, struct super_block *sb) 84static int show_super(struct seq_file *m, struct super_block *sb)
86{ 85{
87 struct reiserfs_sb_info *r = REISERFS_SB(sb); 86 struct reiserfs_sb_info *r = REISERFS_SB(sb);
88 87
89 seq_printf(m, "state: \t%s\n" 88 seq_printf(m, "state: \t%s\n"
90 "mount options: \t%s%s%s%s%s%s%s%s%s%s%s\n" 89 "mount options: \t%s%s%s%s%s%s%s%s%s%s%s\n"
91 "gen. counter: \t%i\n" 90 "gen. counter: \t%i\n"
92 "s_kmallocs: \t%i\n" 91 "s_kmallocs: \t%i\n"
93 "s_disk_reads: \t%i\n" 92 "s_disk_reads: \t%i\n"
94 "s_disk_writes: \t%i\n" 93 "s_disk_writes: \t%i\n"
95 "s_fix_nodes: \t%i\n" 94 "s_fix_nodes: \t%i\n"
96 "s_do_balance: \t%i\n" 95 "s_do_balance: \t%i\n"
97 "s_unneeded_left_neighbor: \t%i\n" 96 "s_unneeded_left_neighbor: \t%i\n"
98 "s_good_search_by_key_reada: \t%i\n" 97 "s_good_search_by_key_reada: \t%i\n"
99 "s_bmaps: \t%i\n" 98 "s_bmaps: \t%i\n"
100 "s_bmaps_without_search: \t%i\n" 99 "s_bmaps_without_search: \t%i\n"
101 "s_direct2indirect: \t%i\n" 100 "s_direct2indirect: \t%i\n"
102 "s_indirect2direct: \t%i\n" 101 "s_indirect2direct: \t%i\n"
103 "\n" 102 "\n"
104 "max_hash_collisions: \t%i\n" 103 "max_hash_collisions: \t%i\n"
105 104 "breads: \t%lu\n"
106 "breads: \t%lu\n" 105 "bread_misses: \t%lu\n"
107 "bread_misses: \t%lu\n" 106 "search_by_key: \t%lu\n"
108 107 "search_by_key_fs_changed: \t%lu\n"
109 "search_by_key: \t%lu\n" 108 "search_by_key_restarted: \t%lu\n"
110 "search_by_key_fs_changed: \t%lu\n" 109 "insert_item_restarted: \t%lu\n"
111 "search_by_key_restarted: \t%lu\n" 110 "paste_into_item_restarted: \t%lu\n"
112 111 "cut_from_item_restarted: \t%lu\n"
113 "insert_item_restarted: \t%lu\n" 112 "delete_solid_item_restarted: \t%lu\n"
114 "paste_into_item_restarted: \t%lu\n" 113 "delete_item_restarted: \t%lu\n"
115 "cut_from_item_restarted: \t%lu\n" 114 "leaked_oid: \t%lu\n"
116 "delete_solid_item_restarted: \t%lu\n" 115 "leaves_removable: \t%lu\n",
117 "delete_item_restarted: \t%lu\n" 116 SF(s_mount_state) == REISERFS_VALID_FS ?
118 117 "REISERFS_VALID_FS" : "REISERFS_ERROR_FS",
119 "leaked_oid: \t%lu\n" 118 reiserfs_r5_hash(sb) ? "FORCE_R5 " : "",
120 "leaves_removable: \t%lu\n", 119 reiserfs_rupasov_hash(sb) ? "FORCE_RUPASOV " : "",
121 120 reiserfs_tea_hash(sb) ? "FORCE_TEA " : "",
122 SF( s_mount_state ) == REISERFS_VALID_FS ? 121 reiserfs_hash_detect(sb) ? "DETECT_HASH " : "",
123 "REISERFS_VALID_FS" : "REISERFS_ERROR_FS", 122 reiserfs_no_border(sb) ? "NO_BORDER " : "BORDER ",
124 reiserfs_r5_hash( sb ) ? "FORCE_R5 " : "", 123 reiserfs_no_unhashed_relocation(sb) ?
125 reiserfs_rupasov_hash( sb ) ? "FORCE_RUPASOV " : "", 124 "NO_UNHASHED_RELOCATION " : "",
126 reiserfs_tea_hash( sb ) ? "FORCE_TEA " : "", 125 reiserfs_hashed_relocation(sb) ? "UNHASHED_RELOCATION " : "",
127 reiserfs_hash_detect( sb ) ? "DETECT_HASH " : "", 126 reiserfs_test4(sb) ? "TEST4 " : "",
128 reiserfs_no_border( sb ) ? "NO_BORDER " : "BORDER ", 127 have_large_tails(sb) ? "TAILS " : have_small_tails(sb) ?
129 reiserfs_no_unhashed_relocation( sb ) ? "NO_UNHASHED_RELOCATION " : "", 128 "SMALL_TAILS " : "NO_TAILS ",
130 reiserfs_hashed_relocation( sb ) ? "UNHASHED_RELOCATION " : "", 129 replay_only(sb) ? "REPLAY_ONLY " : "",
131 reiserfs_test4( sb ) ? "TEST4 " : "", 130 convert_reiserfs(sb) ? "CONV " : "",
132 have_large_tails( sb ) ? "TAILS " : have_small_tails(sb)?"SMALL_TAILS ":"NO_TAILS ", 131 atomic_read(&r->s_generation_counter), SF(s_kmallocs),
133 replay_only( sb ) ? "REPLAY_ONLY " : "", 132 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
134 convert_reiserfs( sb ) ? "CONV " : "", 133 SF(s_do_balance), SF(s_unneeded_left_neighbor),
135 134 SF(s_good_search_by_key_reada), SF(s_bmaps),
136 atomic_read( &r -> s_generation_counter ), 135 SF(s_bmaps_without_search), SF(s_direct2indirect),
137 SF( s_kmallocs ), 136 SF(s_indirect2direct), SFP(max_hash_collisions), SFP(breads),
138 SF( s_disk_reads ), 137 SFP(bread_miss), SFP(search_by_key),
139 SF( s_disk_writes ), 138 SFP(search_by_key_fs_changed), SFP(search_by_key_restarted),
140 SF( s_fix_nodes ), 139 SFP(insert_item_restarted), SFP(paste_into_item_restarted),
141 SF( s_do_balance ), 140 SFP(cut_from_item_restarted),
142 SF( s_unneeded_left_neighbor ), 141 SFP(delete_solid_item_restarted), SFP(delete_item_restarted),
143 SF( s_good_search_by_key_reada ), 142 SFP(leaked_oid), SFP(leaves_removable));
144 SF( s_bmaps ),
145 SF( s_bmaps_without_search ),
146 SF( s_direct2indirect ),
147 SF( s_indirect2direct ),
148 SFP( max_hash_collisions ),
149 SFP( breads ),
150 SFP( bread_miss ),
151 SFP( search_by_key ),
152 SFP( search_by_key_fs_changed ),
153 SFP( search_by_key_restarted ),
154
155 SFP( insert_item_restarted ),
156 SFP( paste_into_item_restarted ),
157 SFP( cut_from_item_restarted ),
158 SFP( delete_solid_item_restarted ),
159 SFP( delete_item_restarted ),
160
161 SFP( leaked_oid ),
162 SFP( leaves_removable ) );
163 143
164 return 0; 144 return 0;
165} 145}
@@ -169,61 +149,55 @@ static int show_per_level(struct seq_file *m, struct super_block *sb)
169 struct reiserfs_sb_info *r = REISERFS_SB(sb); 149 struct reiserfs_sb_info *r = REISERFS_SB(sb);
170 int level; 150 int level;
171 151
172 seq_printf(m, "level\t" 152 seq_printf(m, "level\t"
173 " balances" 153 " balances"
174 " [sbk: reads" 154 " [sbk: reads"
175 " fs_changed" 155 " fs_changed"
176 " restarted]" 156 " restarted]"
177 " free space" 157 " free space"
178 " items" 158 " items"
179 " can_remove" 159 " can_remove"
180 " lnum" 160 " lnum"
181 " rnum" 161 " rnum"
182 " lbytes" 162 " lbytes"
183 " rbytes" 163 " rbytes"
184 " get_neig" 164 " get_neig"
185 " get_neig_res" 165 " get_neig_res" " need_l_neig" " need_r_neig" "\n");
186 " need_l_neig" 166
187 " need_r_neig" 167 for (level = 0; level < MAX_HEIGHT; ++level) {
188 "\n" 168 seq_printf(m, "%i\t"
189 169 " %12lu"
190 ); 170 " %12lu"
191 171 " %12lu"
192 for( level = 0 ; level < MAX_HEIGHT ; ++ level ) { 172 " %12lu"
193 seq_printf(m, "%i\t" 173 " %12lu"
194 " %12lu" 174 " %12lu"
195 " %12lu" 175 " %12lu"
196 " %12lu" 176 " %12li"
197 " %12lu" 177 " %12li"
198 " %12lu" 178 " %12li"
199 " %12lu" 179 " %12li"
200 " %12lu" 180 " %12lu"
201 " %12li" 181 " %12lu"
202 " %12li" 182 " %12lu"
203 " %12li" 183 " %12lu"
204 " %12li" 184 "\n",
205 " %12lu" 185 level,
206 " %12lu" 186 SFPL(balance_at),
207 " %12lu" 187 SFPL(sbk_read_at),
208 " %12lu" 188 SFPL(sbk_fs_changed),
209 "\n", 189 SFPL(sbk_restarted),
210 level, 190 SFPL(free_at),
211 SFPL( balance_at ), 191 SFPL(items_at),
212 SFPL( sbk_read_at ), 192 SFPL(can_node_be_removed),
213 SFPL( sbk_fs_changed ), 193 SFPL(lnum),
214 SFPL( sbk_restarted ), 194 SFPL(rnum),
215 SFPL( free_at ), 195 SFPL(lbytes),
216 SFPL( items_at ), 196 SFPL(rbytes),
217 SFPL( can_node_be_removed ), 197 SFPL(get_neighbors),
218 SFPL( lnum ), 198 SFPL(get_neighbors_restart),
219 SFPL( rnum ), 199 SFPL(need_l_neighbor), SFPL(need_r_neighbor)
220 SFPL( lbytes ), 200 );
221 SFPL( rbytes ),
222 SFPL( get_neighbors ),
223 SFPL( get_neighbors_restart ),
224 SFPL( need_l_neighbor ),
225 SFPL( need_r_neighbor )
226 );
227 } 201 }
228 return 0; 202 return 0;
229} 203}
@@ -232,31 +206,30 @@ static int show_bitmap(struct seq_file *m, struct super_block *sb)
232{ 206{
233 struct reiserfs_sb_info *r = REISERFS_SB(sb); 207 struct reiserfs_sb_info *r = REISERFS_SB(sb);
234 208
235 seq_printf(m, "free_block: %lu\n" 209 seq_printf(m, "free_block: %lu\n"
236 " scan_bitmap:" 210 " scan_bitmap:"
237 " wait" 211 " wait"
238 " bmap" 212 " bmap"
239 " retry" 213 " retry"
240 " stolen" 214 " stolen"
241 " journal_hint" 215 " journal_hint"
242 "journal_nohint" 216 "journal_nohint"
243 "\n" 217 "\n"
244 " %14lu" 218 " %14lu"
245 " %14lu" 219 " %14lu"
246 " %14lu" 220 " %14lu"
247 " %14lu" 221 " %14lu"
248 " %14lu" 222 " %14lu"
249 " %14lu" 223 " %14lu"
250 " %14lu" 224 " %14lu"
251 "\n", 225 "\n",
252 SFP( free_block ), 226 SFP(free_block),
253 SFPF( call ), 227 SFPF(call),
254 SFPF( wait ), 228 SFPF(wait),
255 SFPF( bmap ), 229 SFPF(bmap),
256 SFPF( retry ), 230 SFPF(retry),
257 SFPF( stolen ), 231 SFPF(stolen),
258 SFPF( in_journal_hint ), 232 SFPF(in_journal_hint), SFPF(in_journal_nohint));
259 SFPF( in_journal_nohint ) );
260 233
261 return 0; 234 return 0;
262} 235}
@@ -264,46 +237,42 @@ static int show_bitmap(struct seq_file *m, struct super_block *sb)
264static int show_on_disk_super(struct seq_file *m, struct super_block *sb) 237static int show_on_disk_super(struct seq_file *m, struct super_block *sb)
265{ 238{
266 struct reiserfs_sb_info *sb_info = REISERFS_SB(sb); 239 struct reiserfs_sb_info *sb_info = REISERFS_SB(sb);
267 struct reiserfs_super_block *rs = sb_info -> s_rs; 240 struct reiserfs_super_block *rs = sb_info->s_rs;
268 int hash_code = DFL( s_hash_function_code ); 241 int hash_code = DFL(s_hash_function_code);
269 __u32 flags = DJF( s_flags ); 242 __u32 flags = DJF(s_flags);
270 243
271 seq_printf(m, "block_count: \t%i\n" 244 seq_printf(m, "block_count: \t%i\n"
272 "free_blocks: \t%i\n" 245 "free_blocks: \t%i\n"
273 "root_block: \t%i\n" 246 "root_block: \t%i\n"
274 "blocksize: \t%i\n" 247 "blocksize: \t%i\n"
275 "oid_maxsize: \t%i\n" 248 "oid_maxsize: \t%i\n"
276 "oid_cursize: \t%i\n" 249 "oid_cursize: \t%i\n"
277 "umount_state: \t%i\n" 250 "umount_state: \t%i\n"
278 "magic: \t%10.10s\n" 251 "magic: \t%10.10s\n"
279 "fs_state: \t%i\n" 252 "fs_state: \t%i\n"
280 "hash: \t%s\n" 253 "hash: \t%s\n"
281 "tree_height: \t%i\n" 254 "tree_height: \t%i\n"
282 "bmap_nr: \t%i\n" 255 "bmap_nr: \t%i\n"
283 "version: \t%i\n" 256 "version: \t%i\n"
284 "flags: \t%x[%s]\n" 257 "flags: \t%x[%s]\n"
285 "reserved_for_journal: \t%i\n", 258 "reserved_for_journal: \t%i\n",
286 259 DFL(s_block_count),
287 DFL( s_block_count ), 260 DFL(s_free_blocks),
288 DFL( s_free_blocks ), 261 DFL(s_root_block),
289 DFL( s_root_block ), 262 DF(s_blocksize),
290 DF( s_blocksize ), 263 DF(s_oid_maxsize),
291 DF( s_oid_maxsize ), 264 DF(s_oid_cursize),
292 DF( s_oid_cursize ), 265 DF(s_umount_state),
293 DF( s_umount_state ), 266 rs->s_v1.s_magic,
294 rs -> s_v1.s_magic, 267 DF(s_fs_state),
295 DF( s_fs_state ), 268 hash_code == TEA_HASH ? "tea" :
296 hash_code == TEA_HASH ? "tea" : 269 (hash_code == YURA_HASH) ? "rupasov" :
297 ( hash_code == YURA_HASH ) ? "rupasov" : 270 (hash_code == R5_HASH) ? "r5" :
298 ( hash_code == R5_HASH ) ? "r5" : 271 (hash_code == UNSET_HASH) ? "unset" : "unknown",
299 ( hash_code == UNSET_HASH ) ? "unset" : "unknown", 272 DF(s_tree_height),
300 DF( s_tree_height ), 273 DF(s_bmap_nr),
301 DF( s_bmap_nr ), 274 DF(s_version), flags, (flags & reiserfs_attrs_cleared)
302 DF( s_version ), 275 ? "attrs_cleared" : "", DF(s_reserved_for_journal));
303 flags,
304 ( flags & reiserfs_attrs_cleared )
305 ? "attrs_cleared" : "",
306 DF (s_reserved_for_journal));
307 276
308 return 0; 277 return 0;
309} 278}
@@ -311,131 +280,122 @@ static int show_on_disk_super(struct seq_file *m, struct super_block *sb)
311static int show_oidmap(struct seq_file *m, struct super_block *sb) 280static int show_oidmap(struct seq_file *m, struct super_block *sb)
312{ 281{
313 struct reiserfs_sb_info *sb_info = REISERFS_SB(sb); 282 struct reiserfs_sb_info *sb_info = REISERFS_SB(sb);
314 struct reiserfs_super_block *rs = sb_info -> s_rs; 283 struct reiserfs_super_block *rs = sb_info->s_rs;
315 unsigned int mapsize = le16_to_cpu( rs -> s_v1.s_oid_cursize ); 284 unsigned int mapsize = le16_to_cpu(rs->s_v1.s_oid_cursize);
316 unsigned long total_used = 0; 285 unsigned long total_used = 0;
317 int i; 286 int i;
318 287
319 for( i = 0 ; i < mapsize ; ++i ) { 288 for (i = 0; i < mapsize; ++i) {
320 __u32 right; 289 __u32 right;
321 290
322 right = ( i == mapsize - 1 ) ? MAX_KEY_OBJECTID : MAP( i + 1 ); 291 right = (i == mapsize - 1) ? MAX_KEY_OBJECTID : MAP(i + 1);
323 seq_printf(m, "%s: [ %x .. %x )\n", 292 seq_printf(m, "%s: [ %x .. %x )\n",
324 ( i & 1 ) ? "free" : "used", MAP( i ), right ); 293 (i & 1) ? "free" : "used", MAP(i), right);
325 if( ! ( i & 1 ) ) { 294 if (!(i & 1)) {
326 total_used += right - MAP( i ); 295 total_used += right - MAP(i);
327 } 296 }
328 } 297 }
329#if defined( REISERFS_USE_OIDMAPF ) 298#if defined( REISERFS_USE_OIDMAPF )
330 if( sb_info -> oidmap.use_file && ( sb_info -> oidmap.mapf != NULL ) ) { 299 if (sb_info->oidmap.use_file && (sb_info->oidmap.mapf != NULL)) {
331 loff_t size = sb_info->oidmap.mapf->f_dentry->d_inode->i_size; 300 loff_t size = sb_info->oidmap.mapf->f_dentry->d_inode->i_size;
332 total_used += size / sizeof( reiserfs_oidinterval_d_t ); 301 total_used += size / sizeof(reiserfs_oidinterval_d_t);
333 } 302 }
334#endif 303#endif
335 seq_printf(m, "total: \t%i [%i/%i] used: %lu [exact]\n", 304 seq_printf(m, "total: \t%i [%i/%i] used: %lu [exact]\n",
336 mapsize, 305 mapsize,
337 mapsize, le16_to_cpu( rs -> s_v1.s_oid_maxsize ), 306 mapsize, le16_to_cpu(rs->s_v1.s_oid_maxsize), total_used);
338 total_used);
339 return 0; 307 return 0;
340} 308}
341 309
342static int show_journal(struct seq_file *m, struct super_block *sb) 310static int show_journal(struct seq_file *m, struct super_block *sb)
343{ 311{
344 struct reiserfs_sb_info *r = REISERFS_SB(sb); 312 struct reiserfs_sb_info *r = REISERFS_SB(sb);
345 struct reiserfs_super_block *rs = r -> s_rs; 313 struct reiserfs_super_block *rs = r->s_rs;
346 struct journal_params *jp = &rs->s_v1.s_journal; 314 struct journal_params *jp = &rs->s_v1.s_journal;
347 char b[BDEVNAME_SIZE]; 315 char b[BDEVNAME_SIZE];
348 316
349 317 seq_printf(m, /* on-disk fields */
350 seq_printf(m, /* on-disk fields */ 318 "jp_journal_1st_block: \t%i\n"
351 "jp_journal_1st_block: \t%i\n" 319 "jp_journal_dev: \t%s[%x]\n"
352 "jp_journal_dev: \t%s[%x]\n" 320 "jp_journal_size: \t%i\n"
353 "jp_journal_size: \t%i\n" 321 "jp_journal_trans_max: \t%i\n"
354 "jp_journal_trans_max: \t%i\n" 322 "jp_journal_magic: \t%i\n"
355 "jp_journal_magic: \t%i\n" 323 "jp_journal_max_batch: \t%i\n"
356 "jp_journal_max_batch: \t%i\n" 324 "jp_journal_max_commit_age: \t%i\n"
357 "jp_journal_max_commit_age: \t%i\n" 325 "jp_journal_max_trans_age: \t%i\n"
358 "jp_journal_max_trans_age: \t%i\n" 326 /* incore fields */
359 /* incore fields */ 327 "j_1st_reserved_block: \t%i\n"
360 "j_1st_reserved_block: \t%i\n" 328 "j_state: \t%li\n"
361 "j_state: \t%li\n" 329 "j_trans_id: \t%lu\n"
362 "j_trans_id: \t%lu\n" 330 "j_mount_id: \t%lu\n"
363 "j_mount_id: \t%lu\n" 331 "j_start: \t%lu\n"
364 "j_start: \t%lu\n" 332 "j_len: \t%lu\n"
365 "j_len: \t%lu\n" 333 "j_len_alloc: \t%lu\n"
366 "j_len_alloc: \t%lu\n" 334 "j_wcount: \t%i\n"
367 "j_wcount: \t%i\n" 335 "j_bcount: \t%lu\n"
368 "j_bcount: \t%lu\n" 336 "j_first_unflushed_offset: \t%lu\n"
369 "j_first_unflushed_offset: \t%lu\n" 337 "j_last_flush_trans_id: \t%lu\n"
370 "j_last_flush_trans_id: \t%lu\n" 338 "j_trans_start_time: \t%li\n"
371 "j_trans_start_time: \t%li\n" 339 "j_list_bitmap_index: \t%i\n"
372 "j_list_bitmap_index: \t%i\n" 340 "j_must_wait: \t%i\n"
373 "j_must_wait: \t%i\n" 341 "j_next_full_flush: \t%i\n"
374 "j_next_full_flush: \t%i\n" 342 "j_next_async_flush: \t%i\n"
375 "j_next_async_flush: \t%i\n" 343 "j_cnode_used: \t%i\n" "j_cnode_free: \t%i\n" "\n"
376 "j_cnode_used: \t%i\n" 344 /* reiserfs_proc_info_data_t.journal fields */
377 "j_cnode_free: \t%i\n" 345 "in_journal: \t%12lu\n"
378 "\n" 346 "in_journal_bitmap: \t%12lu\n"
379 /* reiserfs_proc_info_data_t.journal fields */ 347 "in_journal_reusable: \t%12lu\n"
380 "in_journal: \t%12lu\n" 348 "lock_journal: \t%12lu\n"
381 "in_journal_bitmap: \t%12lu\n" 349 "lock_journal_wait: \t%12lu\n"
382 "in_journal_reusable: \t%12lu\n" 350 "journal_begin: \t%12lu\n"
383 "lock_journal: \t%12lu\n" 351 "journal_relock_writers: \t%12lu\n"
384 "lock_journal_wait: \t%12lu\n" 352 "journal_relock_wcount: \t%12lu\n"
385 "journal_begin: \t%12lu\n" 353 "mark_dirty: \t%12lu\n"
386 "journal_relock_writers: \t%12lu\n" 354 "mark_dirty_already: \t%12lu\n"
387 "journal_relock_wcount: \t%12lu\n" 355 "mark_dirty_notjournal: \t%12lu\n"
388 "mark_dirty: \t%12lu\n" 356 "restore_prepared: \t%12lu\n"
389 "mark_dirty_already: \t%12lu\n" 357 "prepare: \t%12lu\n"
390 "mark_dirty_notjournal: \t%12lu\n" 358 "prepare_retry: \t%12lu\n",
391 "restore_prepared: \t%12lu\n" 359 DJP(jp_journal_1st_block),
392 "prepare: \t%12lu\n" 360 bdevname(SB_JOURNAL(sb)->j_dev_bd, b),
393 "prepare_retry: \t%12lu\n", 361 DJP(jp_journal_dev),
394 362 DJP(jp_journal_size),
395 DJP( jp_journal_1st_block ), 363 DJP(jp_journal_trans_max),
396 bdevname(SB_JOURNAL(sb)->j_dev_bd, b), 364 DJP(jp_journal_magic),
397 DJP( jp_journal_dev ), 365 DJP(jp_journal_max_batch),
398 DJP( jp_journal_size ), 366 SB_JOURNAL(sb)->j_max_commit_age,
399 DJP( jp_journal_trans_max ), 367 DJP(jp_journal_max_trans_age),
400 DJP( jp_journal_magic ), 368 JF(j_1st_reserved_block),
401 DJP( jp_journal_max_batch ), 369 JF(j_state),
402 SB_JOURNAL(sb)->j_max_commit_age, 370 JF(j_trans_id),
403 DJP( jp_journal_max_trans_age ), 371 JF(j_mount_id),
404 372 JF(j_start),
405 JF( j_1st_reserved_block ), 373 JF(j_len),
406 JF( j_state ), 374 JF(j_len_alloc),
407 JF( j_trans_id ), 375 atomic_read(&r->s_journal->j_wcount),
408 JF( j_mount_id ), 376 JF(j_bcount),
409 JF( j_start ), 377 JF(j_first_unflushed_offset),
410 JF( j_len ), 378 JF(j_last_flush_trans_id),
411 JF( j_len_alloc ), 379 JF(j_trans_start_time),
412 atomic_read( & r -> s_journal -> j_wcount ), 380 JF(j_list_bitmap_index),
413 JF( j_bcount ), 381 JF(j_must_wait),
414 JF( j_first_unflushed_offset ), 382 JF(j_next_full_flush),
415 JF( j_last_flush_trans_id ), 383 JF(j_next_async_flush),
416 JF( j_trans_start_time ), 384 JF(j_cnode_used),
417 JF( j_list_bitmap_index ), 385 JF(j_cnode_free),
418 JF( j_must_wait ), 386 SFPJ(in_journal),
419 JF( j_next_full_flush ), 387 SFPJ(in_journal_bitmap),
420 JF( j_next_async_flush ), 388 SFPJ(in_journal_reusable),
421 JF( j_cnode_used ), 389 SFPJ(lock_journal),
422 JF( j_cnode_free ), 390 SFPJ(lock_journal_wait),
423 391 SFPJ(journal_being),
424 SFPJ( in_journal ), 392 SFPJ(journal_relock_writers),
425 SFPJ( in_journal_bitmap ), 393 SFPJ(journal_relock_wcount),
426 SFPJ( in_journal_reusable ), 394 SFPJ(mark_dirty),
427 SFPJ( lock_journal ), 395 SFPJ(mark_dirty_already),
428 SFPJ( lock_journal_wait ), 396 SFPJ(mark_dirty_notjournal),
429 SFPJ( journal_being ), 397 SFPJ(restore_prepared), SFPJ(prepare), SFPJ(prepare_retry)
430 SFPJ( journal_relock_writers ), 398 );
431 SFPJ( journal_relock_wcount ),
432 SFPJ( mark_dirty ),
433 SFPJ( mark_dirty_already ),
434 SFPJ( mark_dirty_notjournal ),
435 SFPJ( restore_prepared ),
436 SFPJ( prepare ),
437 SFPJ( prepare_retry )
438 );
439 return 0; 399 return 0;
440} 400}
441 401
@@ -450,7 +410,7 @@ static int set_sb(struct super_block *sb, void *data)
450 return -ENOENT; 410 return -ENOENT;
451} 411}
452 412
453static void *r_start(struct seq_file *m, loff_t *pos) 413static void *r_start(struct seq_file *m, loff_t * pos)
454{ 414{
455 struct proc_dir_entry *de = m->private; 415 struct proc_dir_entry *de = m->private;
456 struct super_block *s = de->parent->data; 416 struct super_block *s = de->parent->data;
@@ -472,7 +432,7 @@ static void *r_start(struct seq_file *m, loff_t *pos)
472 return s; 432 return s;
473} 433}
474 434
475static void *r_next(struct seq_file *m, void *v, loff_t *pos) 435static void *r_next(struct seq_file *m, void *v, loff_t * pos)
476{ 436{
477 ++*pos; 437 ++*pos;
478 if (v) 438 if (v)
@@ -489,7 +449,7 @@ static void r_stop(struct seq_file *m, void *v)
489static int r_show(struct seq_file *m, void *v) 449static int r_show(struct seq_file *m, void *v)
490{ 450{
491 struct proc_dir_entry *de = m->private; 451 struct proc_dir_entry *de = m->private;
492 int (*show)(struct seq_file *, struct super_block *) = de->data; 452 int (*show) (struct seq_file *, struct super_block *) = de->data;
493 return show(m, v); 453 return show(m, v);
494} 454}
495 455
@@ -512,17 +472,17 @@ static int r_open(struct inode *inode, struct file *file)
512} 472}
513 473
514static struct file_operations r_file_operations = { 474static struct file_operations r_file_operations = {
515 .open = r_open, 475 .open = r_open,
516 .read = seq_read, 476 .read = seq_read,
517 .llseek = seq_lseek, 477 .llseek = seq_lseek,
518 .release = seq_release, 478 .release = seq_release,
519}; 479};
520 480
521static struct proc_dir_entry *proc_info_root = NULL; 481static struct proc_dir_entry *proc_info_root = NULL;
522static const char proc_info_root_name[] = "fs/reiserfs"; 482static const char proc_info_root_name[] = "fs/reiserfs";
523 483
524static void add_file(struct super_block *sb, char *name, 484static void add_file(struct super_block *sb, char *name,
525 int (*func)(struct seq_file *, struct super_block *)) 485 int (*func) (struct seq_file *, struct super_block *))
526{ 486{
527 struct proc_dir_entry *de; 487 struct proc_dir_entry *de;
528 de = create_proc_entry(name, 0, REISERFS_SB(sb)->procdir); 488 de = create_proc_entry(name, 0, REISERFS_SB(sb)->procdir);
@@ -532,11 +492,12 @@ static void add_file(struct super_block *sb, char *name,
532 } 492 }
533} 493}
534 494
535int reiserfs_proc_info_init( struct super_block *sb ) 495int reiserfs_proc_info_init(struct super_block *sb)
536{ 496{
537 spin_lock_init( & __PINFO( sb ).lock ); 497 spin_lock_init(&__PINFO(sb).lock);
538 REISERFS_SB(sb)->procdir = proc_mkdir(reiserfs_bdevname (sb), proc_info_root); 498 REISERFS_SB(sb)->procdir =
539 if( REISERFS_SB(sb)->procdir ) { 499 proc_mkdir(reiserfs_bdevname(sb), proc_info_root);
500 if (REISERFS_SB(sb)->procdir) {
540 REISERFS_SB(sb)->procdir->owner = THIS_MODULE; 501 REISERFS_SB(sb)->procdir->owner = THIS_MODULE;
541 REISERFS_SB(sb)->procdir->data = sb; 502 REISERFS_SB(sb)->procdir->data = sb;
542 add_file(sb, "version", show_version); 503 add_file(sb, "version", show_version);
@@ -549,11 +510,11 @@ int reiserfs_proc_info_init( struct super_block *sb )
549 return 0; 510 return 0;
550 } 511 }
551 reiserfs_warning(sb, "reiserfs: cannot create /proc/%s/%s", 512 reiserfs_warning(sb, "reiserfs: cannot create /proc/%s/%s",
552 proc_info_root_name, reiserfs_bdevname (sb) ); 513 proc_info_root_name, reiserfs_bdevname(sb));
553 return 1; 514 return 1;
554} 515}
555 516
556int reiserfs_proc_info_done( struct super_block *sb ) 517int reiserfs_proc_info_done(struct super_block *sb)
557{ 518{
558 struct proc_dir_entry *de = REISERFS_SB(sb)->procdir; 519 struct proc_dir_entry *de = REISERFS_SB(sb)->procdir;
559 if (de) { 520 if (de) {
@@ -565,48 +526,48 @@ int reiserfs_proc_info_done( struct super_block *sb )
565 remove_proc_entry("super", de); 526 remove_proc_entry("super", de);
566 remove_proc_entry("version", de); 527 remove_proc_entry("version", de);
567 } 528 }
568 spin_lock( & __PINFO( sb ).lock ); 529 spin_lock(&__PINFO(sb).lock);
569 __PINFO( sb ).exiting = 1; 530 __PINFO(sb).exiting = 1;
570 spin_unlock( & __PINFO( sb ).lock ); 531 spin_unlock(&__PINFO(sb).lock);
571 if ( proc_info_root ) { 532 if (proc_info_root) {
572 remove_proc_entry( reiserfs_bdevname (sb), proc_info_root ); 533 remove_proc_entry(reiserfs_bdevname(sb), proc_info_root);
573 REISERFS_SB(sb)->procdir = NULL; 534 REISERFS_SB(sb)->procdir = NULL;
574 } 535 }
575 return 0; 536 return 0;
576} 537}
577 538
578struct proc_dir_entry *reiserfs_proc_register_global( char *name, 539struct proc_dir_entry *reiserfs_proc_register_global(char *name,
579 read_proc_t *func ) 540 read_proc_t * func)
580{ 541{
581 return ( proc_info_root ) ? create_proc_read_entry( name, 0, 542 return (proc_info_root) ? create_proc_read_entry(name, 0,
582 proc_info_root, 543 proc_info_root,
583 func, NULL ) : NULL; 544 func, NULL) : NULL;
584} 545}
585 546
586void reiserfs_proc_unregister_global( const char *name ) 547void reiserfs_proc_unregister_global(const char *name)
587{ 548{
588 remove_proc_entry( name, proc_info_root ); 549 remove_proc_entry(name, proc_info_root);
589} 550}
590 551
591int reiserfs_proc_info_global_init( void ) 552int reiserfs_proc_info_global_init(void)
592{ 553{
593 if( proc_info_root == NULL ) { 554 if (proc_info_root == NULL) {
594 proc_info_root = proc_mkdir(proc_info_root_name, NULL); 555 proc_info_root = proc_mkdir(proc_info_root_name, NULL);
595 if( proc_info_root ) { 556 if (proc_info_root) {
596 proc_info_root -> owner = THIS_MODULE; 557 proc_info_root->owner = THIS_MODULE;
597 } else { 558 } else {
598 reiserfs_warning (NULL, 559 reiserfs_warning(NULL,
599 "reiserfs: cannot create /proc/%s", 560 "reiserfs: cannot create /proc/%s",
600 proc_info_root_name ); 561 proc_info_root_name);
601 return 1; 562 return 1;
602 } 563 }
603 } 564 }
604 return 0; 565 return 0;
605} 566}
606 567
607int reiserfs_proc_info_global_done( void ) 568int reiserfs_proc_info_global_done(void)
608{ 569{
609 if ( proc_info_root != NULL ) { 570 if (proc_info_root != NULL) {
610 proc_info_root = NULL; 571 proc_info_root = NULL;
611 remove_proc_entry(proc_info_root_name, NULL); 572 remove_proc_entry(proc_info_root_name, NULL);
612 } 573 }
@@ -616,22 +577,40 @@ int reiserfs_proc_info_global_done( void )
616/* REISERFS_PROC_INFO */ 577/* REISERFS_PROC_INFO */
617#else 578#else
618 579
619int reiserfs_proc_info_init( struct super_block *sb ) { return 0; } 580int reiserfs_proc_info_init(struct super_block *sb)
620int reiserfs_proc_info_done( struct super_block *sb ) { return 0; } 581{
582 return 0;
583}
584int reiserfs_proc_info_done(struct super_block *sb)
585{
586 return 0;
587}
621 588
622struct proc_dir_entry *reiserfs_proc_register_global( char *name, 589struct proc_dir_entry *reiserfs_proc_register_global(char *name,
623 read_proc_t *func ) 590 read_proc_t * func)
624{ return NULL; } 591{
592 return NULL;
593}
625 594
626void reiserfs_proc_unregister_global( const char *name ) {;} 595void reiserfs_proc_unregister_global(const char *name)
596{;
597}
627 598
628int reiserfs_proc_info_global_init( void ) { return 0; } 599int reiserfs_proc_info_global_init(void)
629int reiserfs_proc_info_global_done( void ) { return 0; } 600{
601 return 0;
602}
603int reiserfs_proc_info_global_done(void)
604{
605 return 0;
606}
630 607
631int reiserfs_global_version_in_proc( char *buffer, char **start, 608int reiserfs_global_version_in_proc(char *buffer, char **start,
632 off_t offset, 609 off_t offset,
633 int count, int *eof, void *data ) 610 int count, int *eof, void *data)
634{ return 0; } 611{
612 return 0;
613}
635 614
636/* REISERFS_PROC_INFO */ 615/* REISERFS_PROC_INFO */
637#endif 616#endif
diff --git a/fs/reiserfs/resize.c b/fs/reiserfs/resize.c
index 170012078b76..39cc7f47f5dc 100644
--- a/fs/reiserfs/resize.c
+++ b/fs/reiserfs/resize.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README 2 * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
3 */ 3 */
4 4
5/* 5/*
6 * Written by Alexander Zarochentcev. 6 * Written by Alexander Zarochentcev.
7 * 7 *
@@ -17,23 +17,23 @@
17#include <linux/reiserfs_fs_sb.h> 17#include <linux/reiserfs_fs_sb.h>
18#include <linux/buffer_head.h> 18#include <linux/buffer_head.h>
19 19
20int reiserfs_resize (struct super_block * s, unsigned long block_count_new) 20int reiserfs_resize(struct super_block *s, unsigned long block_count_new)
21{ 21{
22 int err = 0; 22 int err = 0;
23 struct reiserfs_super_block * sb; 23 struct reiserfs_super_block *sb;
24 struct reiserfs_bitmap_info *bitmap; 24 struct reiserfs_bitmap_info *bitmap;
25 struct reiserfs_bitmap_info *old_bitmap = SB_AP_BITMAP(s); 25 struct reiserfs_bitmap_info *old_bitmap = SB_AP_BITMAP(s);
26 struct buffer_head * bh; 26 struct buffer_head *bh;
27 struct reiserfs_transaction_handle th; 27 struct reiserfs_transaction_handle th;
28 unsigned int bmap_nr_new, bmap_nr; 28 unsigned int bmap_nr_new, bmap_nr;
29 unsigned int block_r_new, block_r; 29 unsigned int block_r_new, block_r;
30 30
31 struct reiserfs_list_bitmap * jb; 31 struct reiserfs_list_bitmap *jb;
32 struct reiserfs_list_bitmap jbitmap[JOURNAL_NUM_BITMAPS]; 32 struct reiserfs_list_bitmap jbitmap[JOURNAL_NUM_BITMAPS];
33 33
34 unsigned long int block_count, free_blocks; 34 unsigned long int block_count, free_blocks;
35 int i; 35 int i;
36 int copy_size ; 36 int copy_size;
37 37
38 sb = SB_DISK_SUPER_BLOCK(s); 38 sb = SB_DISK_SUPER_BLOCK(s);
39 39
@@ -47,136 +47,145 @@ int reiserfs_resize (struct super_block * s, unsigned long block_count_new)
47 if (!bh) { 47 if (!bh) {
48 printk("reiserfs_resize: can\'t read last block\n"); 48 printk("reiserfs_resize: can\'t read last block\n");
49 return -EINVAL; 49 return -EINVAL;
50 } 50 }
51 bforget(bh); 51 bforget(bh);
52 52
53 /* old disk layout detection; those partitions can be mounted, but 53 /* old disk layout detection; those partitions can be mounted, but
54 * cannot be resized */ 54 * cannot be resized */
55 if (SB_BUFFER_WITH_SB(s)->b_blocknr * SB_BUFFER_WITH_SB(s)->b_size 55 if (SB_BUFFER_WITH_SB(s)->b_blocknr * SB_BUFFER_WITH_SB(s)->b_size
56 != REISERFS_DISK_OFFSET_IN_BYTES ) { 56 != REISERFS_DISK_OFFSET_IN_BYTES) {
57 printk("reiserfs_resize: unable to resize a reiserfs without distributed bitmap (fs version < 3.5.12)\n"); 57 printk
58 ("reiserfs_resize: unable to resize a reiserfs without distributed bitmap (fs version < 3.5.12)\n");
58 return -ENOTSUPP; 59 return -ENOTSUPP;
59 } 60 }
60 61
61 /* count used bits in last bitmap block */ 62 /* count used bits in last bitmap block */
62 block_r = SB_BLOCK_COUNT(s) - 63 block_r = SB_BLOCK_COUNT(s) - (SB_BMAP_NR(s) - 1) * s->s_blocksize * 8;
63 (SB_BMAP_NR(s) - 1) * s->s_blocksize * 8; 64
64
65 /* count bitmap blocks in new fs */ 65 /* count bitmap blocks in new fs */
66 bmap_nr_new = block_count_new / ( s->s_blocksize * 8 ); 66 bmap_nr_new = block_count_new / (s->s_blocksize * 8);
67 block_r_new = block_count_new - bmap_nr_new * s->s_blocksize * 8; 67 block_r_new = block_count_new - bmap_nr_new * s->s_blocksize * 8;
68 if (block_r_new) 68 if (block_r_new)
69 bmap_nr_new++; 69 bmap_nr_new++;
70 else 70 else
71 block_r_new = s->s_blocksize * 8; 71 block_r_new = s->s_blocksize * 8;
72 72
73 /* save old values */ 73 /* save old values */
74 block_count = SB_BLOCK_COUNT(s); 74 block_count = SB_BLOCK_COUNT(s);
75 bmap_nr = SB_BMAP_NR(s); 75 bmap_nr = SB_BMAP_NR(s);
76 76
77 /* resizing of reiserfs bitmaps (journal and real), if needed */ 77 /* resizing of reiserfs bitmaps (journal and real), if needed */
78 if (bmap_nr_new > bmap_nr) { 78 if (bmap_nr_new > bmap_nr) {
79 /* reallocate journal bitmaps */ 79 /* reallocate journal bitmaps */
80 if (reiserfs_allocate_list_bitmaps(s, jbitmap, bmap_nr_new) < 0) { 80 if (reiserfs_allocate_list_bitmaps(s, jbitmap, bmap_nr_new) < 0) {
81 printk("reiserfs_resize: unable to allocate memory for journal bitmaps\n"); 81 printk
82 unlock_super(s) ; 82 ("reiserfs_resize: unable to allocate memory for journal bitmaps\n");
83 return -ENOMEM ; 83 unlock_super(s);
84 } 84 return -ENOMEM;
85 /* the new journal bitmaps are zero filled, now we copy in the bitmap 85 }
86 ** node pointers from the old journal bitmap structs, and then 86 /* the new journal bitmaps are zero filled, now we copy in the bitmap
87 ** transfer the new data structures into the journal struct. 87 ** node pointers from the old journal bitmap structs, and then
88 ** 88 ** transfer the new data structures into the journal struct.
89 ** using the copy_size var below allows this code to work for 89 **
90 ** both shrinking and expanding the FS. 90 ** using the copy_size var below allows this code to work for
91 */ 91 ** both shrinking and expanding the FS.
92 copy_size = bmap_nr_new < bmap_nr ? bmap_nr_new : bmap_nr ; 92 */
93 copy_size = copy_size * sizeof(struct reiserfs_list_bitmap_node *) ; 93 copy_size = bmap_nr_new < bmap_nr ? bmap_nr_new : bmap_nr;
94 for (i = 0 ; i < JOURNAL_NUM_BITMAPS ; i++) { 94 copy_size =
95 struct reiserfs_bitmap_node **node_tmp ; 95 copy_size * sizeof(struct reiserfs_list_bitmap_node *);
96 jb = SB_JOURNAL(s)->j_list_bitmap + i ; 96 for (i = 0; i < JOURNAL_NUM_BITMAPS; i++) {
97 memcpy(jbitmap[i].bitmaps, jb->bitmaps, copy_size) ; 97 struct reiserfs_bitmap_node **node_tmp;
98 98 jb = SB_JOURNAL(s)->j_list_bitmap + i;
99 /* just in case vfree schedules on us, copy the new 99 memcpy(jbitmap[i].bitmaps, jb->bitmaps, copy_size);
100 ** pointer into the journal struct before freeing the 100
101 ** old one 101 /* just in case vfree schedules on us, copy the new
102 */ 102 ** pointer into the journal struct before freeing the
103 node_tmp = jb->bitmaps ; 103 ** old one
104 jb->bitmaps = jbitmap[i].bitmaps ; 104 */
105 vfree(node_tmp) ; 105 node_tmp = jb->bitmaps;
106 } 106 jb->bitmaps = jbitmap[i].bitmaps;
107 107 vfree(node_tmp);
108 /* allocate additional bitmap blocks, reallocate array of bitmap 108 }
109 * block pointers */ 109
110 bitmap = vmalloc(sizeof(struct reiserfs_bitmap_info) * bmap_nr_new); 110 /* allocate additional bitmap blocks, reallocate array of bitmap
111 if (!bitmap) { 111 * block pointers */
112 /* Journal bitmaps are still supersized, but the memory isn't 112 bitmap =
113 * leaked, so I guess it's ok */ 113 vmalloc(sizeof(struct reiserfs_bitmap_info) * bmap_nr_new);
114 printk("reiserfs_resize: unable to allocate memory.\n"); 114 if (!bitmap) {
115 return -ENOMEM; 115 /* Journal bitmaps are still supersized, but the memory isn't
116 } 116 * leaked, so I guess it's ok */
117 memset (bitmap, 0, sizeof (struct reiserfs_bitmap_info) * SB_BMAP_NR(s)); 117 printk("reiserfs_resize: unable to allocate memory.\n");
118 for (i = 0; i < bmap_nr; i++) 118 return -ENOMEM;
119 bitmap[i] = old_bitmap[i]; 119 }
120 120 memset(bitmap, 0,
121 /* This doesn't go through the journal, but it doesn't have to. 121 sizeof(struct reiserfs_bitmap_info) * SB_BMAP_NR(s));
122 * The changes are still atomic: We're synced up when the journal 122 for (i = 0; i < bmap_nr; i++)
123 * transaction begins, and the new bitmaps don't matter if the 123 bitmap[i] = old_bitmap[i];
124 * transaction fails. */ 124
125 for (i = bmap_nr; i < bmap_nr_new; i++) { 125 /* This doesn't go through the journal, but it doesn't have to.
126 bitmap[i].bh = sb_getblk(s, i * s->s_blocksize * 8); 126 * The changes are still atomic: We're synced up when the journal
127 memset(bitmap[i].bh->b_data, 0, sb_blocksize(sb)); 127 * transaction begins, and the new bitmaps don't matter if the
128 reiserfs_test_and_set_le_bit(0, bitmap[i].bh->b_data); 128 * transaction fails. */
129 129 for (i = bmap_nr; i < bmap_nr_new; i++) {
130 set_buffer_uptodate(bitmap[i].bh); 130 bitmap[i].bh = sb_getblk(s, i * s->s_blocksize * 8);
131 mark_buffer_dirty(bitmap[i].bh) ; 131 memset(bitmap[i].bh->b_data, 0, sb_blocksize(sb));
132 sync_dirty_buffer(bitmap[i].bh); 132 reiserfs_test_and_set_le_bit(0, bitmap[i].bh->b_data);
133 // update bitmap_info stuff 133
134 bitmap[i].first_zero_hint=1; 134 set_buffer_uptodate(bitmap[i].bh);
135 bitmap[i].free_count = sb_blocksize(sb) * 8 - 1; 135 mark_buffer_dirty(bitmap[i].bh);
136 } 136 sync_dirty_buffer(bitmap[i].bh);
137 /* free old bitmap blocks array */ 137 // update bitmap_info stuff
138 SB_AP_BITMAP(s) = bitmap; 138 bitmap[i].first_zero_hint = 1;
139 vfree (old_bitmap); 139 bitmap[i].free_count = sb_blocksize(sb) * 8 - 1;
140 }
141 /* free old bitmap blocks array */
142 SB_AP_BITMAP(s) = bitmap;
143 vfree(old_bitmap);
140 } 144 }
141 145
142 /* begin transaction, if there was an error, it's fine. Yes, we have 146 /* begin transaction, if there was an error, it's fine. Yes, we have
143 * incorrect bitmaps now, but none of it is ever going to touch the 147 * incorrect bitmaps now, but none of it is ever going to touch the
144 * disk anyway. */ 148 * disk anyway. */
145 err = journal_begin(&th, s, 10); 149 err = journal_begin(&th, s, 10);
146 if (err) 150 if (err)
147 return err; 151 return err;
148 152
149 /* correct last bitmap blocks in old and new disk layout */ 153 /* correct last bitmap blocks in old and new disk layout */
150 reiserfs_prepare_for_journal(s, SB_AP_BITMAP(s)[bmap_nr - 1].bh, 1); 154 reiserfs_prepare_for_journal(s, SB_AP_BITMAP(s)[bmap_nr - 1].bh, 1);
151 for (i = block_r; i < s->s_blocksize * 8; i++) 155 for (i = block_r; i < s->s_blocksize * 8; i++)
152 reiserfs_test_and_clear_le_bit(i, 156 reiserfs_test_and_clear_le_bit(i,
153 SB_AP_BITMAP(s)[bmap_nr - 1].bh->b_data); 157 SB_AP_BITMAP(s)[bmap_nr -
158 1].bh->b_data);
154 SB_AP_BITMAP(s)[bmap_nr - 1].free_count += s->s_blocksize * 8 - block_r; 159 SB_AP_BITMAP(s)[bmap_nr - 1].free_count += s->s_blocksize * 8 - block_r;
155 if ( !SB_AP_BITMAP(s)[bmap_nr - 1].first_zero_hint) 160 if (!SB_AP_BITMAP(s)[bmap_nr - 1].first_zero_hint)
156 SB_AP_BITMAP(s)[bmap_nr - 1].first_zero_hint = block_r; 161 SB_AP_BITMAP(s)[bmap_nr - 1].first_zero_hint = block_r;
157 162
158 journal_mark_dirty(&th, s, SB_AP_BITMAP(s)[bmap_nr - 1].bh); 163 journal_mark_dirty(&th, s, SB_AP_BITMAP(s)[bmap_nr - 1].bh);
159 164
160 reiserfs_prepare_for_journal(s, SB_AP_BITMAP(s)[bmap_nr_new - 1].bh, 1); 165 reiserfs_prepare_for_journal(s, SB_AP_BITMAP(s)[bmap_nr_new - 1].bh, 1);
161 for (i = block_r_new; i < s->s_blocksize * 8; i++) 166 for (i = block_r_new; i < s->s_blocksize * 8; i++)
162 reiserfs_test_and_set_le_bit(i, 167 reiserfs_test_and_set_le_bit(i,
163 SB_AP_BITMAP(s)[bmap_nr_new - 1].bh->b_data); 168 SB_AP_BITMAP(s)[bmap_nr_new -
169 1].bh->b_data);
164 journal_mark_dirty(&th, s, SB_AP_BITMAP(s)[bmap_nr_new - 1].bh); 170 journal_mark_dirty(&th, s, SB_AP_BITMAP(s)[bmap_nr_new - 1].bh);
165 171
166 SB_AP_BITMAP(s)[bmap_nr_new - 1].free_count -= s->s_blocksize * 8 - block_r_new; 172 SB_AP_BITMAP(s)[bmap_nr_new - 1].free_count -=
173 s->s_blocksize * 8 - block_r_new;
167 /* Extreme case where last bitmap is the only valid block in itself. */ 174 /* Extreme case where last bitmap is the only valid block in itself. */
168 if ( !SB_AP_BITMAP(s)[bmap_nr_new - 1].free_count ) 175 if (!SB_AP_BITMAP(s)[bmap_nr_new - 1].free_count)
169 SB_AP_BITMAP(s)[bmap_nr_new - 1].first_zero_hint = 0; 176 SB_AP_BITMAP(s)[bmap_nr_new - 1].first_zero_hint = 0;
170 /* update super */ 177 /* update super */
171 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1) ; 178 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1);
172 free_blocks = SB_FREE_BLOCKS(s); 179 free_blocks = SB_FREE_BLOCKS(s);
173 PUT_SB_FREE_BLOCKS(s, free_blocks + (block_count_new - block_count - (bmap_nr_new - bmap_nr))); 180 PUT_SB_FREE_BLOCKS(s,
181 free_blocks + (block_count_new - block_count -
182 (bmap_nr_new - bmap_nr)));
174 PUT_SB_BLOCK_COUNT(s, block_count_new); 183 PUT_SB_BLOCK_COUNT(s, block_count_new);
175 PUT_SB_BMAP_NR(s, bmap_nr_new); 184 PUT_SB_BMAP_NR(s, bmap_nr_new);
176 s->s_dirt = 1; 185 s->s_dirt = 1;
177 186
178 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s)); 187 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
179 188
180 SB_JOURNAL(s)->j_must_wait = 1; 189 SB_JOURNAL(s)->j_must_wait = 1;
181 return journal_end(&th, s, 10); 190 return journal_end(&th, s, 10);
182} 191}
diff --git a/fs/reiserfs/stree.c b/fs/reiserfs/stree.c
index 63158491e152..e2d08d7bcffc 100644
--- a/fs/reiserfs/stree.c
+++ b/fs/reiserfs/stree.c
@@ -59,46 +59,45 @@
59#include <linux/quotaops.h> 59#include <linux/quotaops.h>
60 60
61/* Does the buffer contain a disk block which is in the tree. */ 61/* Does the buffer contain a disk block which is in the tree. */
62inline int B_IS_IN_TREE (const struct buffer_head * p_s_bh) 62inline int B_IS_IN_TREE(const struct buffer_head *p_s_bh)
63{ 63{
64 64
65 RFALSE( B_LEVEL (p_s_bh) > MAX_HEIGHT, 65 RFALSE(B_LEVEL(p_s_bh) > MAX_HEIGHT,
66 "PAP-1010: block (%b) has too big level (%z)", p_s_bh, p_s_bh); 66 "PAP-1010: block (%b) has too big level (%z)", p_s_bh, p_s_bh);
67 67
68 return ( B_LEVEL (p_s_bh) != FREE_LEVEL ); 68 return (B_LEVEL(p_s_bh) != FREE_LEVEL);
69} 69}
70 70
71// 71//
72// to gets item head in le form 72// to gets item head in le form
73// 73//
74inline void copy_item_head(struct item_head * p_v_to, 74inline void copy_item_head(struct item_head *p_v_to,
75 const struct item_head * p_v_from) 75 const struct item_head *p_v_from)
76{ 76{
77 memcpy (p_v_to, p_v_from, IH_SIZE); 77 memcpy(p_v_to, p_v_from, IH_SIZE);
78} 78}
79 79
80
81/* k1 is pointer to on-disk structure which is stored in little-endian 80/* k1 is pointer to on-disk structure which is stored in little-endian
82 form. k2 is pointer to cpu variable. For key of items of the same 81 form. k2 is pointer to cpu variable. For key of items of the same
83 object this returns 0. 82 object this returns 0.
84 Returns: -1 if key1 < key2 83 Returns: -1 if key1 < key2
85 0 if key1 == key2 84 0 if key1 == key2
86 1 if key1 > key2 */ 85 1 if key1 > key2 */
87inline int comp_short_keys (const struct reiserfs_key * le_key, 86inline int comp_short_keys(const struct reiserfs_key *le_key,
88 const struct cpu_key * cpu_key) 87 const struct cpu_key *cpu_key)
89{ 88{
90 __u32 n; 89 __u32 n;
91 n = le32_to_cpu(le_key->k_dir_id); 90 n = le32_to_cpu(le_key->k_dir_id);
92 if (n < cpu_key->on_disk_key.k_dir_id) 91 if (n < cpu_key->on_disk_key.k_dir_id)
93 return -1; 92 return -1;
94 if (n > cpu_key->on_disk_key.k_dir_id) 93 if (n > cpu_key->on_disk_key.k_dir_id)
95 return 1; 94 return 1;
96 n = le32_to_cpu(le_key->k_objectid); 95 n = le32_to_cpu(le_key->k_objectid);
97 if (n < cpu_key->on_disk_key.k_objectid) 96 if (n < cpu_key->on_disk_key.k_objectid)
98 return -1; 97 return -1;
99 if (n > cpu_key->on_disk_key.k_objectid) 98 if (n > cpu_key->on_disk_key.k_objectid)
100 return 1; 99 return 1;
101 return 0; 100 return 0;
102} 101}
103 102
104/* k1 is pointer to on-disk structure which is stored in little-endian 103/* k1 is pointer to on-disk structure which is stored in little-endian
@@ -106,68 +105,72 @@ inline int comp_short_keys (const struct reiserfs_key * le_key,
106 Compare keys using all 4 key fields. 105 Compare keys using all 4 key fields.
107 Returns: -1 if key1 < key2 0 106 Returns: -1 if key1 < key2 0
108 if key1 = key2 1 if key1 > key2 */ 107 if key1 = key2 1 if key1 > key2 */
109static inline int comp_keys (const struct reiserfs_key * le_key, const struct cpu_key * cpu_key) 108static inline int comp_keys(const struct reiserfs_key *le_key,
109 const struct cpu_key *cpu_key)
110{ 110{
111 int retval; 111 int retval;
112 112
113 retval = comp_short_keys (le_key, cpu_key); 113 retval = comp_short_keys(le_key, cpu_key);
114 if (retval) 114 if (retval)
115 return retval; 115 return retval;
116 if (le_key_k_offset (le_key_version(le_key), le_key) < cpu_key_k_offset (cpu_key)) 116 if (le_key_k_offset(le_key_version(le_key), le_key) <
117 return -1; 117 cpu_key_k_offset(cpu_key))
118 if (le_key_k_offset (le_key_version(le_key), le_key) > cpu_key_k_offset (cpu_key)) 118 return -1;
119 return 1; 119 if (le_key_k_offset(le_key_version(le_key), le_key) >
120 120 cpu_key_k_offset(cpu_key))
121 if (cpu_key->key_length == 3) 121 return 1;
122 return 0; 122
123 123 if (cpu_key->key_length == 3)
124 /* this part is needed only when tail conversion is in progress */ 124 return 0;
125 if (le_key_k_type (le_key_version(le_key), le_key) < cpu_key_k_type (cpu_key)) 125
126 return -1; 126 /* this part is needed only when tail conversion is in progress */
127 if (le_key_k_type(le_key_version(le_key), le_key) <
128 cpu_key_k_type(cpu_key))
129 return -1;
130
131 if (le_key_k_type(le_key_version(le_key), le_key) >
132 cpu_key_k_type(cpu_key))
133 return 1;
127 134
128 if (le_key_k_type (le_key_version(le_key), le_key) > cpu_key_k_type (cpu_key)) 135 return 0;
129 return 1;
130
131 return 0;
132} 136}
133 137
134 138inline int comp_short_le_keys(const struct reiserfs_key *key1,
135inline int comp_short_le_keys (const struct reiserfs_key * key1, const struct reiserfs_key * key2) 139 const struct reiserfs_key *key2)
136{ 140{
137 __u32 * p_s_1_u32, * p_s_2_u32; 141 __u32 *p_s_1_u32, *p_s_2_u32;
138 int n_key_length = REISERFS_SHORT_KEY_LEN; 142 int n_key_length = REISERFS_SHORT_KEY_LEN;
139 143
140 p_s_1_u32 = (__u32 *)key1; 144 p_s_1_u32 = (__u32 *) key1;
141 p_s_2_u32 = (__u32 *)key2; 145 p_s_2_u32 = (__u32 *) key2;
142 for( ; n_key_length--; ++p_s_1_u32, ++p_s_2_u32 ) { 146 for (; n_key_length--; ++p_s_1_u32, ++p_s_2_u32) {
143 if ( le32_to_cpu (*p_s_1_u32) < le32_to_cpu (*p_s_2_u32) ) 147 if (le32_to_cpu(*p_s_1_u32) < le32_to_cpu(*p_s_2_u32))
144 return -1; 148 return -1;
145 if ( le32_to_cpu (*p_s_1_u32) > le32_to_cpu (*p_s_2_u32) ) 149 if (le32_to_cpu(*p_s_1_u32) > le32_to_cpu(*p_s_2_u32))
146 return 1; 150 return 1;
147 } 151 }
148 return 0; 152 return 0;
149} 153}
150 154
151inline void le_key2cpu_key (struct cpu_key * to, const struct reiserfs_key * from) 155inline void le_key2cpu_key(struct cpu_key *to, const struct reiserfs_key *from)
152{ 156{
153 int version; 157 int version;
154 to->on_disk_key.k_dir_id = le32_to_cpu (from->k_dir_id); 158 to->on_disk_key.k_dir_id = le32_to_cpu(from->k_dir_id);
155 to->on_disk_key.k_objectid = le32_to_cpu (from->k_objectid); 159 to->on_disk_key.k_objectid = le32_to_cpu(from->k_objectid);
156 160
157 // find out version of the key 161 // find out version of the key
158 version = le_key_version (from); 162 version = le_key_version(from);
159 to->version = version; 163 to->version = version;
160 to->on_disk_key.k_offset = le_key_k_offset(version, from); 164 to->on_disk_key.k_offset = le_key_k_offset(version, from);
161 to->on_disk_key.k_type = le_key_k_type(version, from); 165 to->on_disk_key.k_type = le_key_k_type(version, from);
162} 166}
163 167
164
165
166// this does not say which one is bigger, it only returns 1 if keys 168// this does not say which one is bigger, it only returns 1 if keys
167// are not equal, 0 otherwise 169// are not equal, 0 otherwise
168inline int comp_le_keys (const struct reiserfs_key * k1, const struct reiserfs_key * k2) 170inline int comp_le_keys(const struct reiserfs_key *k1,
171 const struct reiserfs_key *k2)
169{ 172{
170 return memcmp (k1, k2, sizeof (struct reiserfs_key)); 173 return memcmp(k1, k2, sizeof(struct reiserfs_key));
171} 174}
172 175
173/************************************************************************** 176/**************************************************************************
@@ -184,373 +187,396 @@ inline int comp_le_keys (const struct reiserfs_key * k1, const struct reiserfs_k
184 there are no possible items, and we have not found it. With each examination we 187 there are no possible items, and we have not found it. With each examination we
185 cut the number of possible items it could be by one more than half rounded down, 188 cut the number of possible items it could be by one more than half rounded down,
186 or we find it. */ 189 or we find it. */
187static inline int bin_search ( 190static inline int bin_search(const void *p_v_key, /* Key to search for. */
188 const void * p_v_key, /* Key to search for. */ 191 const void *p_v_base, /* First item in the array. */
189 const void * p_v_base,/* First item in the array. */ 192 int p_n_num, /* Number of items in the array. */
190 int p_n_num, /* Number of items in the array. */ 193 int p_n_width, /* Item size in the array.
191 int p_n_width, /* Item size in the array. 194 searched. Lest the reader be
192 searched. Lest the reader be 195 confused, note that this is crafted
193 confused, note that this is crafted 196 as a general function, and when it
194 as a general function, and when it 197 is applied specifically to the array
195 is applied specifically to the array 198 of item headers in a node, p_n_width
196 of item headers in a node, p_n_width 199 is actually the item header size not
197 is actually the item header size not 200 the item size. */
198 the item size. */ 201 int *p_n_pos /* Number of the searched for element. */
199 int * p_n_pos /* Number of the searched for element. */ 202 )
200 ) { 203{
201 int n_rbound, n_lbound, n_j; 204 int n_rbound, n_lbound, n_j;
202 205
203 for ( n_j = ((n_rbound = p_n_num - 1) + (n_lbound = 0))/2; n_lbound <= n_rbound; n_j = (n_rbound + n_lbound)/2 ) 206 for (n_j = ((n_rbound = p_n_num - 1) + (n_lbound = 0)) / 2;
204 switch( comp_keys((struct reiserfs_key *)((char * )p_v_base + n_j * p_n_width), (struct cpu_key *)p_v_key) ) { 207 n_lbound <= n_rbound; n_j = (n_rbound + n_lbound) / 2)
205 case -1: n_lbound = n_j + 1; continue; 208 switch (comp_keys
206 case 1: n_rbound = n_j - 1; continue; 209 ((struct reiserfs_key *)((char *)p_v_base +
207 case 0: *p_n_pos = n_j; return ITEM_FOUND; /* Key found in the array. */ 210 n_j * p_n_width),
208 } 211 (struct cpu_key *)p_v_key)) {
209 212 case -1:
210 /* bin_search did not find given key, it returns position of key, 213 n_lbound = n_j + 1;
211 that is minimal and greater than the given one. */ 214 continue;
212 *p_n_pos = n_lbound; 215 case 1:
213 return ITEM_NOT_FOUND; 216 n_rbound = n_j - 1;
217 continue;
218 case 0:
219 *p_n_pos = n_j;
220 return ITEM_FOUND; /* Key found in the array. */
221 }
222
223 /* bin_search did not find given key, it returns position of key,
224 that is minimal and greater than the given one. */
225 *p_n_pos = n_lbound;
226 return ITEM_NOT_FOUND;
214} 227}
215 228
216#ifdef CONFIG_REISERFS_CHECK 229#ifdef CONFIG_REISERFS_CHECK
217extern struct tree_balance * cur_tb; 230extern struct tree_balance *cur_tb;
218#endif 231#endif
219 232
220
221
222/* Minimal possible key. It is never in the tree. */ 233/* Minimal possible key. It is never in the tree. */
223const struct reiserfs_key MIN_KEY = {0, 0, {{0, 0},}}; 234const struct reiserfs_key MIN_KEY = { 0, 0, {{0, 0},} };
224 235
225/* Maximal possible key. It is never in the tree. */ 236/* Maximal possible key. It is never in the tree. */
226static const struct reiserfs_key MAX_KEY = { 237static const struct reiserfs_key MAX_KEY = {
227 __constant_cpu_to_le32(0xffffffff), 238 __constant_cpu_to_le32(0xffffffff),
228 __constant_cpu_to_le32(0xffffffff), 239 __constant_cpu_to_le32(0xffffffff),
229 {{__constant_cpu_to_le32(0xffffffff), 240 {{__constant_cpu_to_le32(0xffffffff),
230 __constant_cpu_to_le32(0xffffffff)},} 241 __constant_cpu_to_le32(0xffffffff)},}
231}; 242};
232 243
233
234/* Get delimiting key of the buffer by looking for it in the buffers in the path, starting from the bottom 244/* Get delimiting key of the buffer by looking for it in the buffers in the path, starting from the bottom
235 of the path, and going upwards. We must check the path's validity at each step. If the key is not in 245 of the path, and going upwards. We must check the path's validity at each step. If the key is not in
236 the path, there is no delimiting key in the tree (buffer is first or last buffer in tree), and in this 246 the path, there is no delimiting key in the tree (buffer is first or last buffer in tree), and in this
237 case we return a special key, either MIN_KEY or MAX_KEY. */ 247 case we return a special key, either MIN_KEY or MAX_KEY. */
238static inline const struct reiserfs_key * get_lkey ( 248static inline const struct reiserfs_key *get_lkey(const struct path
239 const struct path * p_s_chk_path, 249 *p_s_chk_path,
240 const struct super_block * p_s_sb 250 const struct super_block
241 ) { 251 *p_s_sb)
242 int n_position, n_path_offset = p_s_chk_path->path_length; 252{
243 struct buffer_head * p_s_parent; 253 int n_position, n_path_offset = p_s_chk_path->path_length;
244 254 struct buffer_head *p_s_parent;
245 RFALSE( n_path_offset < FIRST_PATH_ELEMENT_OFFSET, 255
246 "PAP-5010: invalid offset in the path"); 256 RFALSE(n_path_offset < FIRST_PATH_ELEMENT_OFFSET,
247 257 "PAP-5010: invalid offset in the path");
248 /* While not higher in path than first element. */ 258
249 while ( n_path_offset-- > FIRST_PATH_ELEMENT_OFFSET ) { 259 /* While not higher in path than first element. */
250 260 while (n_path_offset-- > FIRST_PATH_ELEMENT_OFFSET) {
251 RFALSE( ! buffer_uptodate(PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset)), 261
252 "PAP-5020: parent is not uptodate"); 262 RFALSE(!buffer_uptodate
253 263 (PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset)),
254 /* Parent at the path is not in the tree now. */ 264 "PAP-5020: parent is not uptodate");
255 if ( ! B_IS_IN_TREE(p_s_parent = PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset)) ) 265
256 return &MAX_KEY; 266 /* Parent at the path is not in the tree now. */
257 /* Check whether position in the parent is correct. */ 267 if (!B_IS_IN_TREE
258 if ( (n_position = PATH_OFFSET_POSITION(p_s_chk_path, n_path_offset)) > B_NR_ITEMS(p_s_parent) ) 268 (p_s_parent =
259 return &MAX_KEY; 269 PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset)))
260 /* Check whether parent at the path really points to the child. */ 270 return &MAX_KEY;
261 if ( B_N_CHILD_NUM(p_s_parent, n_position) != 271 /* Check whether position in the parent is correct. */
262 PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset + 1)->b_blocknr ) 272 if ((n_position =
263 return &MAX_KEY; 273 PATH_OFFSET_POSITION(p_s_chk_path,
264 /* Return delimiting key if position in the parent is not equal to zero. */ 274 n_path_offset)) >
265 if ( n_position ) 275 B_NR_ITEMS(p_s_parent))
266 return B_N_PDELIM_KEY(p_s_parent, n_position - 1); 276 return &MAX_KEY;
267 } 277 /* Check whether parent at the path really points to the child. */
268 /* Return MIN_KEY if we are in the root of the buffer tree. */ 278 if (B_N_CHILD_NUM(p_s_parent, n_position) !=
269 if ( PATH_OFFSET_PBUFFER(p_s_chk_path, FIRST_PATH_ELEMENT_OFFSET)->b_blocknr == 279 PATH_OFFSET_PBUFFER(p_s_chk_path,
270 SB_ROOT_BLOCK (p_s_sb) ) 280 n_path_offset + 1)->b_blocknr)
271 return &MIN_KEY; 281 return &MAX_KEY;
272 return &MAX_KEY; 282 /* Return delimiting key if position in the parent is not equal to zero. */
283 if (n_position)
284 return B_N_PDELIM_KEY(p_s_parent, n_position - 1);
285 }
286 /* Return MIN_KEY if we are in the root of the buffer tree. */
287 if (PATH_OFFSET_PBUFFER(p_s_chk_path, FIRST_PATH_ELEMENT_OFFSET)->
288 b_blocknr == SB_ROOT_BLOCK(p_s_sb))
289 return &MIN_KEY;
290 return &MAX_KEY;
273} 291}
274 292
275
276/* Get delimiting key of the buffer at the path and its right neighbor. */ 293/* Get delimiting key of the buffer at the path and its right neighbor. */
277inline const struct reiserfs_key * get_rkey ( 294inline const struct reiserfs_key *get_rkey(const struct path *p_s_chk_path,
278 const struct path * p_s_chk_path, 295 const struct super_block *p_s_sb)
279 const struct super_block * p_s_sb 296{
280 ) { 297 int n_position, n_path_offset = p_s_chk_path->path_length;
281 int n_position, 298 struct buffer_head *p_s_parent;
282 n_path_offset = p_s_chk_path->path_length; 299
283 struct buffer_head * p_s_parent; 300 RFALSE(n_path_offset < FIRST_PATH_ELEMENT_OFFSET,
284 301 "PAP-5030: invalid offset in the path");
285 RFALSE( n_path_offset < FIRST_PATH_ELEMENT_OFFSET, 302
286 "PAP-5030: invalid offset in the path"); 303 while (n_path_offset-- > FIRST_PATH_ELEMENT_OFFSET) {
287 304
288 while ( n_path_offset-- > FIRST_PATH_ELEMENT_OFFSET ) { 305 RFALSE(!buffer_uptodate
289 306 (PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset)),
290 RFALSE( ! buffer_uptodate(PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset)), 307 "PAP-5040: parent is not uptodate");
291 "PAP-5040: parent is not uptodate"); 308
292 309 /* Parent at the path is not in the tree now. */
293 /* Parent at the path is not in the tree now. */ 310 if (!B_IS_IN_TREE
294 if ( ! B_IS_IN_TREE(p_s_parent = PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset)) ) 311 (p_s_parent =
295 return &MIN_KEY; 312 PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset)))
296 /* Check whether position in the parent is correct. */ 313 return &MIN_KEY;
297 if ( (n_position = PATH_OFFSET_POSITION(p_s_chk_path, n_path_offset)) > B_NR_ITEMS(p_s_parent) ) 314 /* Check whether position in the parent is correct. */
298 return &MIN_KEY; 315 if ((n_position =
299 /* Check whether parent at the path really points to the child. */ 316 PATH_OFFSET_POSITION(p_s_chk_path,
300 if ( B_N_CHILD_NUM(p_s_parent, n_position) != 317 n_path_offset)) >
301 PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset + 1)->b_blocknr ) 318 B_NR_ITEMS(p_s_parent))
302 return &MIN_KEY; 319 return &MIN_KEY;
303 /* Return delimiting key if position in the parent is not the last one. */ 320 /* Check whether parent at the path really points to the child. */
304 if ( n_position != B_NR_ITEMS(p_s_parent) ) 321 if (B_N_CHILD_NUM(p_s_parent, n_position) !=
305 return B_N_PDELIM_KEY(p_s_parent, n_position); 322 PATH_OFFSET_PBUFFER(p_s_chk_path,
306 } 323 n_path_offset + 1)->b_blocknr)
307 /* Return MAX_KEY if we are in the root of the buffer tree. */ 324 return &MIN_KEY;
308 if ( PATH_OFFSET_PBUFFER(p_s_chk_path, FIRST_PATH_ELEMENT_OFFSET)->b_blocknr == 325 /* Return delimiting key if position in the parent is not the last one. */
309 SB_ROOT_BLOCK (p_s_sb) ) 326 if (n_position != B_NR_ITEMS(p_s_parent))
310 return &MAX_KEY; 327 return B_N_PDELIM_KEY(p_s_parent, n_position);
311 return &MIN_KEY; 328 }
329 /* Return MAX_KEY if we are in the root of the buffer tree. */
330 if (PATH_OFFSET_PBUFFER(p_s_chk_path, FIRST_PATH_ELEMENT_OFFSET)->
331 b_blocknr == SB_ROOT_BLOCK(p_s_sb))
332 return &MAX_KEY;
333 return &MIN_KEY;
312} 334}
313 335
314
315/* Check whether a key is contained in the tree rooted from a buffer at a path. */ 336/* Check whether a key is contained in the tree rooted from a buffer at a path. */
316/* This works by looking at the left and right delimiting keys for the buffer in the last path_element in 337/* This works by looking at the left and right delimiting keys for the buffer in the last path_element in
317 the path. These delimiting keys are stored at least one level above that buffer in the tree. If the 338 the path. These delimiting keys are stored at least one level above that buffer in the tree. If the
318 buffer is the first or last node in the tree order then one of the delimiting keys may be absent, and in 339 buffer is the first or last node in the tree order then one of the delimiting keys may be absent, and in
319 this case get_lkey and get_rkey return a special key which is MIN_KEY or MAX_KEY. */ 340 this case get_lkey and get_rkey return a special key which is MIN_KEY or MAX_KEY. */
320static inline int key_in_buffer ( 341static inline int key_in_buffer(struct path *p_s_chk_path, /* Path which should be checked. */
321 struct path * p_s_chk_path, /* Path which should be checked. */ 342 const struct cpu_key *p_s_key, /* Key which should be checked. */
322 const struct cpu_key * p_s_key, /* Key which should be checked. */ 343 struct super_block *p_s_sb /* Super block pointer. */
323 struct super_block * p_s_sb /* Super block pointer. */ 344 )
324 ) { 345{
325
326 RFALSE( ! p_s_key || p_s_chk_path->path_length < FIRST_PATH_ELEMENT_OFFSET ||
327 p_s_chk_path->path_length > MAX_HEIGHT,
328 "PAP-5050: pointer to the key(%p) is NULL or invalid path length(%d)",
329 p_s_key, p_s_chk_path->path_length);
330 RFALSE( !PATH_PLAST_BUFFER(p_s_chk_path)->b_bdev,
331 "PAP-5060: device must not be NODEV");
332
333 if ( comp_keys(get_lkey(p_s_chk_path, p_s_sb), p_s_key) == 1 )
334 /* left delimiting key is bigger, that the key we look for */
335 return 0;
336 // if ( comp_keys(p_s_key, get_rkey(p_s_chk_path, p_s_sb)) != -1 )
337 if ( comp_keys(get_rkey(p_s_chk_path, p_s_sb), p_s_key) != 1 )
338 /* p_s_key must be less than right delimitiing key */
339 return 0;
340 return 1;
341}
342
343 346
344inline void decrement_bcount( 347 RFALSE(!p_s_key || p_s_chk_path->path_length < FIRST_PATH_ELEMENT_OFFSET
345 struct buffer_head * p_s_bh 348 || p_s_chk_path->path_length > MAX_HEIGHT,
346 ) { 349 "PAP-5050: pointer to the key(%p) is NULL or invalid path length(%d)",
347 if ( p_s_bh ) { 350 p_s_key, p_s_chk_path->path_length);
348 if ( atomic_read (&(p_s_bh->b_count)) ) { 351 RFALSE(!PATH_PLAST_BUFFER(p_s_chk_path)->b_bdev,
349 put_bh(p_s_bh) ; 352 "PAP-5060: device must not be NODEV");
350 return; 353
351 } 354 if (comp_keys(get_lkey(p_s_chk_path, p_s_sb), p_s_key) == 1)
352 reiserfs_panic(NULL, "PAP-5070: decrement_bcount: trying to free free buffer %b", p_s_bh); 355 /* left delimiting key is bigger, that the key we look for */
353 } 356 return 0;
357 // if ( comp_keys(p_s_key, get_rkey(p_s_chk_path, p_s_sb)) != -1 )
358 if (comp_keys(get_rkey(p_s_chk_path, p_s_sb), p_s_key) != 1)
359 /* p_s_key must be less than right delimitiing key */
360 return 0;
361 return 1;
354} 362}
355 363
364inline void decrement_bcount(struct buffer_head *p_s_bh)
365{
366 if (p_s_bh) {
367 if (atomic_read(&(p_s_bh->b_count))) {
368 put_bh(p_s_bh);
369 return;
370 }
371 reiserfs_panic(NULL,
372 "PAP-5070: decrement_bcount: trying to free free buffer %b",
373 p_s_bh);
374 }
375}
356 376
357/* Decrement b_count field of the all buffers in the path. */ 377/* Decrement b_count field of the all buffers in the path. */
358void decrement_counters_in_path ( 378void decrement_counters_in_path(struct path *p_s_search_path)
359 struct path * p_s_search_path 379{
360 ) { 380 int n_path_offset = p_s_search_path->path_length;
361 int n_path_offset = p_s_search_path->path_length; 381
362 382 RFALSE(n_path_offset < ILLEGAL_PATH_ELEMENT_OFFSET ||
363 RFALSE( n_path_offset < ILLEGAL_PATH_ELEMENT_OFFSET || 383 n_path_offset > EXTENDED_MAX_HEIGHT - 1,
364 n_path_offset > EXTENDED_MAX_HEIGHT - 1, 384 "PAP-5080: invalid path offset of %d", n_path_offset);
365 "PAP-5080: invalid path offset of %d", n_path_offset);
366
367 while ( n_path_offset > ILLEGAL_PATH_ELEMENT_OFFSET ) {
368 struct buffer_head * bh;
369
370 bh = PATH_OFFSET_PBUFFER(p_s_search_path, n_path_offset--);
371 decrement_bcount (bh);
372 }
373 p_s_search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET;
374}
375 385
386 while (n_path_offset > ILLEGAL_PATH_ELEMENT_OFFSET) {
387 struct buffer_head *bh;
376 388
377int reiserfs_check_path(struct path *p) { 389 bh = PATH_OFFSET_PBUFFER(p_s_search_path, n_path_offset--);
378 RFALSE( p->path_length != ILLEGAL_PATH_ELEMENT_OFFSET, 390 decrement_bcount(bh);
379 "path not properly relsed") ; 391 }
380 return 0 ; 392 p_s_search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET;
381} 393}
382 394
395int reiserfs_check_path(struct path *p)
396{
397 RFALSE(p->path_length != ILLEGAL_PATH_ELEMENT_OFFSET,
398 "path not properly relsed");
399 return 0;
400}
383 401
384/* Release all buffers in the path. Restore dirty bits clean 402/* Release all buffers in the path. Restore dirty bits clean
385** when preparing the buffer for the log 403** when preparing the buffer for the log
386** 404**
387** only called from fix_nodes() 405** only called from fix_nodes()
388*/ 406*/
389void pathrelse_and_restore ( 407void pathrelse_and_restore(struct super_block *s, struct path *p_s_search_path)
390 struct super_block *s, 408{
391 struct path * p_s_search_path 409 int n_path_offset = p_s_search_path->path_length;
392 ) { 410
393 int n_path_offset = p_s_search_path->path_length; 411 RFALSE(n_path_offset < ILLEGAL_PATH_ELEMENT_OFFSET,
394 412 "clm-4000: invalid path offset");
395 RFALSE( n_path_offset < ILLEGAL_PATH_ELEMENT_OFFSET, 413
396 "clm-4000: invalid path offset"); 414 while (n_path_offset > ILLEGAL_PATH_ELEMENT_OFFSET) {
397 415 reiserfs_restore_prepared_buffer(s,
398 while ( n_path_offset > ILLEGAL_PATH_ELEMENT_OFFSET ) { 416 PATH_OFFSET_PBUFFER
399 reiserfs_restore_prepared_buffer(s, PATH_OFFSET_PBUFFER(p_s_search_path, 417 (p_s_search_path,
400 n_path_offset)); 418 n_path_offset));
401 brelse(PATH_OFFSET_PBUFFER(p_s_search_path, n_path_offset--)); 419 brelse(PATH_OFFSET_PBUFFER(p_s_search_path, n_path_offset--));
402 } 420 }
403 p_s_search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET; 421 p_s_search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET;
404} 422}
405 423
406/* Release all buffers in the path. */ 424/* Release all buffers in the path. */
407void pathrelse ( 425void pathrelse(struct path *p_s_search_path)
408 struct path * p_s_search_path 426{
409 ) { 427 int n_path_offset = p_s_search_path->path_length;
410 int n_path_offset = p_s_search_path->path_length;
411
412 RFALSE( n_path_offset < ILLEGAL_PATH_ELEMENT_OFFSET,
413 "PAP-5090: invalid path offset");
414
415 while ( n_path_offset > ILLEGAL_PATH_ELEMENT_OFFSET )
416 brelse(PATH_OFFSET_PBUFFER(p_s_search_path, n_path_offset--));
417
418 p_s_search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET;
419}
420 428
429 RFALSE(n_path_offset < ILLEGAL_PATH_ELEMENT_OFFSET,
430 "PAP-5090: invalid path offset");
421 431
432 while (n_path_offset > ILLEGAL_PATH_ELEMENT_OFFSET)
433 brelse(PATH_OFFSET_PBUFFER(p_s_search_path, n_path_offset--));
422 434
423static int is_leaf (char * buf, int blocksize, struct buffer_head * bh) 435 p_s_search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET;
424{ 436}
425 struct block_head * blkh;
426 struct item_head * ih;
427 int used_space;
428 int prev_location;
429 int i;
430 int nr;
431
432 blkh = (struct block_head *)buf;
433 if ( blkh_level(blkh) != DISK_LEAF_NODE_LEVEL) {
434 reiserfs_warning (NULL, "is_leaf: this should be caught earlier");
435 return 0;
436 }
437 437
438 nr = blkh_nr_item(blkh); 438static int is_leaf(char *buf, int blocksize, struct buffer_head *bh)
439 if (nr < 1 || nr > ((blocksize - BLKH_SIZE) / (IH_SIZE + MIN_ITEM_LEN))) { 439{
440 /* item number is too big or too small */ 440 struct block_head *blkh;
441 reiserfs_warning (NULL, "is_leaf: nr_item seems wrong: %z", bh); 441 struct item_head *ih;
442 return 0; 442 int used_space;
443 } 443 int prev_location;
444 ih = (struct item_head *)(buf + BLKH_SIZE) + nr - 1; 444 int i;
445 used_space = BLKH_SIZE + IH_SIZE * nr + (blocksize - ih_location (ih)); 445 int nr;
446 if (used_space != blocksize - blkh_free_space(blkh)) { 446
447 /* free space does not match to calculated amount of use space */ 447 blkh = (struct block_head *)buf;
448 reiserfs_warning (NULL, "is_leaf: free space seems wrong: %z", bh); 448 if (blkh_level(blkh) != DISK_LEAF_NODE_LEVEL) {
449 return 0; 449 reiserfs_warning(NULL,
450 } 450 "is_leaf: this should be caught earlier");
451 451 return 0;
452 // FIXME: it is_leaf will hit performance too much - we may have
453 // return 1 here
454
455 /* check tables of item heads */
456 ih = (struct item_head *)(buf + BLKH_SIZE);
457 prev_location = blocksize;
458 for (i = 0; i < nr; i ++, ih ++) {
459 if ( le_ih_k_type(ih) == TYPE_ANY) {
460 reiserfs_warning (NULL, "is_leaf: wrong item type for item %h",ih);
461 return 0;
462 } 452 }
463 if (ih_location (ih) >= blocksize || ih_location (ih) < IH_SIZE * nr) { 453
464 reiserfs_warning (NULL, "is_leaf: item location seems wrong: %h", ih); 454 nr = blkh_nr_item(blkh);
465 return 0; 455 if (nr < 1 || nr > ((blocksize - BLKH_SIZE) / (IH_SIZE + MIN_ITEM_LEN))) {
456 /* item number is too big or too small */
457 reiserfs_warning(NULL, "is_leaf: nr_item seems wrong: %z", bh);
458 return 0;
466 } 459 }
467 if (ih_item_len (ih) < 1 || ih_item_len (ih) > MAX_ITEM_LEN (blocksize)) { 460 ih = (struct item_head *)(buf + BLKH_SIZE) + nr - 1;
468 reiserfs_warning (NULL, "is_leaf: item length seems wrong: %h", ih); 461 used_space = BLKH_SIZE + IH_SIZE * nr + (blocksize - ih_location(ih));
469 return 0; 462 if (used_space != blocksize - blkh_free_space(blkh)) {
463 /* free space does not match to calculated amount of use space */
464 reiserfs_warning(NULL, "is_leaf: free space seems wrong: %z",
465 bh);
466 return 0;
470 } 467 }
471 if (prev_location - ih_location (ih) != ih_item_len (ih)) { 468 // FIXME: it is_leaf will hit performance too much - we may have
472 reiserfs_warning (NULL, "is_leaf: item location seems wrong (second one): %h", ih); 469 // return 1 here
473 return 0; 470
471 /* check tables of item heads */
472 ih = (struct item_head *)(buf + BLKH_SIZE);
473 prev_location = blocksize;
474 for (i = 0; i < nr; i++, ih++) {
475 if (le_ih_k_type(ih) == TYPE_ANY) {
476 reiserfs_warning(NULL,
477 "is_leaf: wrong item type for item %h",
478 ih);
479 return 0;
480 }
481 if (ih_location(ih) >= blocksize
482 || ih_location(ih) < IH_SIZE * nr) {
483 reiserfs_warning(NULL,
484 "is_leaf: item location seems wrong: %h",
485 ih);
486 return 0;
487 }
488 if (ih_item_len(ih) < 1
489 || ih_item_len(ih) > MAX_ITEM_LEN(blocksize)) {
490 reiserfs_warning(NULL,
491 "is_leaf: item length seems wrong: %h",
492 ih);
493 return 0;
494 }
495 if (prev_location - ih_location(ih) != ih_item_len(ih)) {
496 reiserfs_warning(NULL,
497 "is_leaf: item location seems wrong (second one): %h",
498 ih);
499 return 0;
500 }
501 prev_location = ih_location(ih);
474 } 502 }
475 prev_location = ih_location (ih);
476 }
477 503
478 // one may imagine much more checks 504 // one may imagine much more checks
479 return 1; 505 return 1;
480} 506}
481 507
482
483/* returns 1 if buf looks like an internal node, 0 otherwise */ 508/* returns 1 if buf looks like an internal node, 0 otherwise */
484static int is_internal (char * buf, int blocksize, struct buffer_head * bh) 509static int is_internal(char *buf, int blocksize, struct buffer_head *bh)
485{ 510{
486 struct block_head * blkh; 511 struct block_head *blkh;
487 int nr; 512 int nr;
488 int used_space; 513 int used_space;
489 514
490 blkh = (struct block_head *)buf; 515 blkh = (struct block_head *)buf;
491 nr = blkh_level(blkh); 516 nr = blkh_level(blkh);
492 if (nr <= DISK_LEAF_NODE_LEVEL || nr > MAX_HEIGHT) { 517 if (nr <= DISK_LEAF_NODE_LEVEL || nr > MAX_HEIGHT) {
493 /* this level is not possible for internal nodes */ 518 /* this level is not possible for internal nodes */
494 reiserfs_warning (NULL, "is_internal: this should be caught earlier"); 519 reiserfs_warning(NULL,
495 return 0; 520 "is_internal: this should be caught earlier");
496 } 521 return 0;
497 522 }
498 nr = blkh_nr_item(blkh);
499 if (nr > (blocksize - BLKH_SIZE - DC_SIZE) / (KEY_SIZE + DC_SIZE)) {
500 /* for internal which is not root we might check min number of keys */
501 reiserfs_warning (NULL, "is_internal: number of key seems wrong: %z", bh);
502 return 0;
503 }
504 523
505 used_space = BLKH_SIZE + KEY_SIZE * nr + DC_SIZE * (nr + 1); 524 nr = blkh_nr_item(blkh);
506 if (used_space != blocksize - blkh_free_space(blkh)) { 525 if (nr > (blocksize - BLKH_SIZE - DC_SIZE) / (KEY_SIZE + DC_SIZE)) {
507 reiserfs_warning (NULL, "is_internal: free space seems wrong: %z", bh); 526 /* for internal which is not root we might check min number of keys */
508 return 0; 527 reiserfs_warning(NULL,
509 } 528 "is_internal: number of key seems wrong: %z",
529 bh);
530 return 0;
531 }
510 532
511 // one may imagine much more checks 533 used_space = BLKH_SIZE + KEY_SIZE * nr + DC_SIZE * (nr + 1);
512 return 1; 534 if (used_space != blocksize - blkh_free_space(blkh)) {
535 reiserfs_warning(NULL,
536 "is_internal: free space seems wrong: %z", bh);
537 return 0;
538 }
539 // one may imagine much more checks
540 return 1;
513} 541}
514 542
515
516// make sure that bh contains formatted node of reiserfs tree of 543// make sure that bh contains formatted node of reiserfs tree of
517// 'level'-th level 544// 'level'-th level
518static int is_tree_node (struct buffer_head * bh, int level) 545static int is_tree_node(struct buffer_head *bh, int level)
519{ 546{
520 if (B_LEVEL (bh) != level) { 547 if (B_LEVEL(bh) != level) {
521 reiserfs_warning (NULL, "is_tree_node: node level %d does not match to the expected one %d", 548 reiserfs_warning(NULL,
522 B_LEVEL (bh), level); 549 "is_tree_node: node level %d does not match to the expected one %d",
523 return 0; 550 B_LEVEL(bh), level);
524 } 551 return 0;
525 if (level == DISK_LEAF_NODE_LEVEL) 552 }
526 return is_leaf (bh->b_data, bh->b_size, bh); 553 if (level == DISK_LEAF_NODE_LEVEL)
554 return is_leaf(bh->b_data, bh->b_size, bh);
527 555
528 return is_internal (bh->b_data, bh->b_size, bh); 556 return is_internal(bh->b_data, bh->b_size, bh);
529} 557}
530 558
531
532
533#define SEARCH_BY_KEY_READA 16 559#define SEARCH_BY_KEY_READA 16
534 560
535/* The function is NOT SCHEDULE-SAFE! */ 561/* The function is NOT SCHEDULE-SAFE! */
536static void search_by_key_reada (struct super_block * s, 562static void search_by_key_reada(struct super_block *s,
537 struct buffer_head **bh, 563 struct buffer_head **bh,
538 unsigned long *b, int num) 564 unsigned long *b, int num)
539{ 565{
540 int i,j; 566 int i, j;
541 567
542 for (i = 0 ; i < num ; i++) { 568 for (i = 0; i < num; i++) {
543 bh[i] = sb_getblk (s, b[i]); 569 bh[i] = sb_getblk(s, b[i]);
544 } 570 }
545 for (j = 0 ; j < i ; j++) { 571 for (j = 0; j < i; j++) {
546 /* 572 /*
547 * note, this needs attention if we are getting rid of the BKL 573 * note, this needs attention if we are getting rid of the BKL
548 * you have to make sure the prepared bit isn't set on this buffer 574 * you have to make sure the prepared bit isn't set on this buffer
549 */ 575 */
550 if (!buffer_uptodate(bh[j])) 576 if (!buffer_uptodate(bh[j]))
551 ll_rw_block(READA, 1, bh + j); 577 ll_rw_block(READA, 1, bh + j);
552 brelse(bh[j]); 578 brelse(bh[j]);
553 } 579 }
554} 580}
555 581
556/************************************************************************** 582/**************************************************************************
@@ -576,194 +602,200 @@ static void search_by_key_reada (struct super_block * s,
576 correctness of the top of the path but need not be checked for the 602 correctness of the top of the path but need not be checked for the
577 correctness of the bottom of the path */ 603 correctness of the bottom of the path */
578/* The function is NOT SCHEDULE-SAFE! */ 604/* The function is NOT SCHEDULE-SAFE! */
579int search_by_key (struct super_block * p_s_sb, 605int search_by_key(struct super_block *p_s_sb, const struct cpu_key *p_s_key, /* Key to search. */
580 const struct cpu_key * p_s_key, /* Key to search. */ 606 struct path *p_s_search_path, /* This structure was
581 struct path * p_s_search_path, /* This structure was 607 allocated and initialized
582 allocated and initialized 608 by the calling
583 by the calling 609 function. It is filled up
584 function. It is filled up 610 by this function. */
585 by this function. */ 611 int n_stop_level /* How far down the tree to search. To
586 int n_stop_level /* How far down the tree to search. To 612 stop at leaf level - set to
587 stop at leaf level - set to 613 DISK_LEAF_NODE_LEVEL */
588 DISK_LEAF_NODE_LEVEL */ 614 )
589 ) { 615{
590 int n_block_number; 616 int n_block_number;
591 int expected_level; 617 int expected_level;
592 struct buffer_head * p_s_bh; 618 struct buffer_head *p_s_bh;
593 struct path_element * p_s_last_element; 619 struct path_element *p_s_last_element;
594 int n_node_level, n_retval; 620 int n_node_level, n_retval;
595 int right_neighbor_of_leaf_node; 621 int right_neighbor_of_leaf_node;
596 int fs_gen; 622 int fs_gen;
597 struct buffer_head *reada_bh[SEARCH_BY_KEY_READA]; 623 struct buffer_head *reada_bh[SEARCH_BY_KEY_READA];
598 unsigned long reada_blocks[SEARCH_BY_KEY_READA]; 624 unsigned long reada_blocks[SEARCH_BY_KEY_READA];
599 int reada_count = 0; 625 int reada_count = 0;
600 626
601#ifdef CONFIG_REISERFS_CHECK 627#ifdef CONFIG_REISERFS_CHECK
602 int n_repeat_counter = 0; 628 int n_repeat_counter = 0;
603#endif 629#endif
604
605 PROC_INFO_INC( p_s_sb, search_by_key );
606
607 /* As we add each node to a path we increase its count. This means that
608 we must be careful to release all nodes in a path before we either
609 discard the path struct or re-use the path struct, as we do here. */
610 630
611 decrement_counters_in_path(p_s_search_path); 631 PROC_INFO_INC(p_s_sb, search_by_key);
632
633 /* As we add each node to a path we increase its count. This means that
634 we must be careful to release all nodes in a path before we either
635 discard the path struct or re-use the path struct, as we do here. */
612 636
613 right_neighbor_of_leaf_node = 0; 637 decrement_counters_in_path(p_s_search_path);
614 638
615 /* With each iteration of this loop we search through the items in the 639 right_neighbor_of_leaf_node = 0;
616 current node, and calculate the next current node(next path element) 640
617 for the next iteration of this loop.. */ 641 /* With each iteration of this loop we search through the items in the
618 n_block_number = SB_ROOT_BLOCK (p_s_sb); 642 current node, and calculate the next current node(next path element)
619 expected_level = -1; 643 for the next iteration of this loop.. */
620 while ( 1 ) { 644 n_block_number = SB_ROOT_BLOCK(p_s_sb);
645 expected_level = -1;
646 while (1) {
621 647
622#ifdef CONFIG_REISERFS_CHECK 648#ifdef CONFIG_REISERFS_CHECK
623 if ( !(++n_repeat_counter % 50000) ) 649 if (!(++n_repeat_counter % 50000))
624 reiserfs_warning (p_s_sb, "PAP-5100: search_by_key: %s:" 650 reiserfs_warning(p_s_sb, "PAP-5100: search_by_key: %s:"
625 "there were %d iterations of while loop " 651 "there were %d iterations of while loop "
626 "looking for key %K", 652 "looking for key %K",
627 current->comm, n_repeat_counter, p_s_key); 653 current->comm, n_repeat_counter,
654 p_s_key);
628#endif 655#endif
629 656
630 /* prep path to have another element added to it. */ 657 /* prep path to have another element added to it. */
631 p_s_last_element = PATH_OFFSET_PELEMENT(p_s_search_path, ++p_s_search_path->path_length); 658 p_s_last_element =
632 fs_gen = get_generation (p_s_sb); 659 PATH_OFFSET_PELEMENT(p_s_search_path,
633 660 ++p_s_search_path->path_length);
634 /* Read the next tree node, and set the last element in the path to 661 fs_gen = get_generation(p_s_sb);
635 have a pointer to it. */ 662
636 if ((p_s_bh = p_s_last_element->pe_buffer = 663 /* Read the next tree node, and set the last element in the path to
637 sb_getblk(p_s_sb, n_block_number)) ) { 664 have a pointer to it. */
638 if (!buffer_uptodate(p_s_bh) && reada_count > 1) { 665 if ((p_s_bh = p_s_last_element->pe_buffer =
639 search_by_key_reada (p_s_sb, reada_bh, 666 sb_getblk(p_s_sb, n_block_number))) {
640 reada_blocks, reada_count); 667 if (!buffer_uptodate(p_s_bh) && reada_count > 1) {
641 } 668 search_by_key_reada(p_s_sb, reada_bh,
642 ll_rw_block(READ, 1, &p_s_bh); 669 reada_blocks, reada_count);
643 wait_on_buffer(p_s_bh); 670 }
644 if (!buffer_uptodate(p_s_bh)) 671 ll_rw_block(READ, 1, &p_s_bh);
645 goto io_error; 672 wait_on_buffer(p_s_bh);
646 } else { 673 if (!buffer_uptodate(p_s_bh))
647io_error: 674 goto io_error;
648 p_s_search_path->path_length --; 675 } else {
649 pathrelse(p_s_search_path); 676 io_error:
650 return IO_ERROR; 677 p_s_search_path->path_length--;
651 } 678 pathrelse(p_s_search_path);
652 reada_count = 0; 679 return IO_ERROR;
653 if (expected_level == -1) 680 }
654 expected_level = SB_TREE_HEIGHT (p_s_sb); 681 reada_count = 0;
655 expected_level --; 682 if (expected_level == -1)
656 683 expected_level = SB_TREE_HEIGHT(p_s_sb);
657 /* It is possible that schedule occurred. We must check whether the key 684 expected_level--;
658 to search is still in the tree rooted from the current buffer. If 685
659 not then repeat search from the root. */ 686 /* It is possible that schedule occurred. We must check whether the key
660 if ( fs_changed (fs_gen, p_s_sb) && 687 to search is still in the tree rooted from the current buffer. If
661 (!B_IS_IN_TREE (p_s_bh) || 688 not then repeat search from the root. */
662 B_LEVEL(p_s_bh) != expected_level || 689 if (fs_changed(fs_gen, p_s_sb) &&
663 !key_in_buffer(p_s_search_path, p_s_key, p_s_sb))) { 690 (!B_IS_IN_TREE(p_s_bh) ||
664 PROC_INFO_INC( p_s_sb, search_by_key_fs_changed ); 691 B_LEVEL(p_s_bh) != expected_level ||
665 PROC_INFO_INC( p_s_sb, search_by_key_restarted ); 692 !key_in_buffer(p_s_search_path, p_s_key, p_s_sb))) {
666 PROC_INFO_INC( p_s_sb, sbk_restarted[ expected_level - 1 ] ); 693 PROC_INFO_INC(p_s_sb, search_by_key_fs_changed);
667 decrement_counters_in_path(p_s_search_path); 694 PROC_INFO_INC(p_s_sb, search_by_key_restarted);
668 695 PROC_INFO_INC(p_s_sb,
669 /* Get the root block number so that we can repeat the search 696 sbk_restarted[expected_level - 1]);
670 starting from the root. */ 697 decrement_counters_in_path(p_s_search_path);
671 n_block_number = SB_ROOT_BLOCK (p_s_sb); 698
672 expected_level = -1; 699 /* Get the root block number so that we can repeat the search
673 right_neighbor_of_leaf_node = 0; 700 starting from the root. */
674 701 n_block_number = SB_ROOT_BLOCK(p_s_sb);
675 /* repeat search from the root */ 702 expected_level = -1;
676 continue; 703 right_neighbor_of_leaf_node = 0;
677 } 704
705 /* repeat search from the root */
706 continue;
707 }
678 708
679 /* only check that the key is in the buffer if p_s_key is not 709 /* only check that the key is in the buffer if p_s_key is not
680 equal to the MAX_KEY. Latter case is only possible in 710 equal to the MAX_KEY. Latter case is only possible in
681 "finish_unfinished()" processing during mount. */ 711 "finish_unfinished()" processing during mount. */
682 RFALSE( comp_keys( &MAX_KEY, p_s_key ) && 712 RFALSE(comp_keys(&MAX_KEY, p_s_key) &&
683 ! key_in_buffer(p_s_search_path, p_s_key, p_s_sb), 713 !key_in_buffer(p_s_search_path, p_s_key, p_s_sb),
684 "PAP-5130: key is not in the buffer"); 714 "PAP-5130: key is not in the buffer");
685#ifdef CONFIG_REISERFS_CHECK 715#ifdef CONFIG_REISERFS_CHECK
686 if ( cur_tb ) { 716 if (cur_tb) {
687 print_cur_tb ("5140"); 717 print_cur_tb("5140");
688 reiserfs_panic(p_s_sb, "PAP-5140: search_by_key: schedule occurred in do_balance!"); 718 reiserfs_panic(p_s_sb,
689 } 719 "PAP-5140: search_by_key: schedule occurred in do_balance!");
720 }
690#endif 721#endif
691 722
692 // make sure, that the node contents look like a node of 723 // make sure, that the node contents look like a node of
693 // certain level 724 // certain level
694 if (!is_tree_node (p_s_bh, expected_level)) { 725 if (!is_tree_node(p_s_bh, expected_level)) {
695 reiserfs_warning (p_s_sb, "vs-5150: search_by_key: " 726 reiserfs_warning(p_s_sb, "vs-5150: search_by_key: "
696 "invalid format found in block %ld. Fsck?", 727 "invalid format found in block %ld. Fsck?",
697 p_s_bh->b_blocknr); 728 p_s_bh->b_blocknr);
698 pathrelse (p_s_search_path); 729 pathrelse(p_s_search_path);
699 return IO_ERROR; 730 return IO_ERROR;
700 } 731 }
701
702 /* ok, we have acquired next formatted node in the tree */
703 n_node_level = B_LEVEL (p_s_bh);
704
705 PROC_INFO_BH_STAT( p_s_sb, p_s_bh, n_node_level - 1 );
706
707 RFALSE( n_node_level < n_stop_level,
708 "vs-5152: tree level (%d) is less than stop level (%d)",
709 n_node_level, n_stop_level);
710
711 n_retval = bin_search( p_s_key, B_N_PITEM_HEAD(p_s_bh, 0),
712 B_NR_ITEMS(p_s_bh),
713 ( n_node_level == DISK_LEAF_NODE_LEVEL ) ? IH_SIZE : KEY_SIZE,
714 &(p_s_last_element->pe_position));
715 if (n_node_level == n_stop_level) {
716 return n_retval;
717 }
718 732
719 /* we are not in the stop level */ 733 /* ok, we have acquired next formatted node in the tree */
720 if (n_retval == ITEM_FOUND) 734 n_node_level = B_LEVEL(p_s_bh);
721 /* item has been found, so we choose the pointer which is to the right of the found one */
722 p_s_last_element->pe_position++;
723 735
724 /* if item was not found we choose the position which is to 736 PROC_INFO_BH_STAT(p_s_sb, p_s_bh, n_node_level - 1);
725 the left of the found item. This requires no code,
726 bin_search did it already.*/
727 737
728 /* So we have chosen a position in the current node which is 738 RFALSE(n_node_level < n_stop_level,
729 an internal node. Now we calculate child block number by 739 "vs-5152: tree level (%d) is less than stop level (%d)",
730 position in the node. */ 740 n_node_level, n_stop_level);
731 n_block_number = B_N_CHILD_NUM(p_s_bh, p_s_last_element->pe_position);
732 741
733 /* if we are going to read leaf nodes, try for read ahead as well */ 742 n_retval = bin_search(p_s_key, B_N_PITEM_HEAD(p_s_bh, 0),
734 if ((p_s_search_path->reada & PATH_READA) && 743 B_NR_ITEMS(p_s_bh),
735 n_node_level == DISK_LEAF_NODE_LEVEL + 1) 744 (n_node_level ==
736 { 745 DISK_LEAF_NODE_LEVEL) ? IH_SIZE :
737 int pos = p_s_last_element->pe_position; 746 KEY_SIZE,
738 int limit = B_NR_ITEMS(p_s_bh); 747 &(p_s_last_element->pe_position));
739 struct reiserfs_key *le_key; 748 if (n_node_level == n_stop_level) {
740 749 return n_retval;
741 if (p_s_search_path->reada & PATH_READA_BACK) 750 }
742 limit = 0;
743 while(reada_count < SEARCH_BY_KEY_READA) {
744 if (pos == limit)
745 break;
746 reada_blocks[reada_count++] = B_N_CHILD_NUM(p_s_bh, pos);
747 if (p_s_search_path->reada & PATH_READA_BACK)
748 pos--;
749 else
750 pos++;
751 751
752 /* 752 /* we are not in the stop level */
753 * check to make sure we're in the same object 753 if (n_retval == ITEM_FOUND)
754 */ 754 /* item has been found, so we choose the pointer which is to the right of the found one */
755 le_key = B_N_PDELIM_KEY(p_s_bh, pos); 755 p_s_last_element->pe_position++;
756 if (le32_to_cpu(le_key->k_objectid) != 756
757 p_s_key->on_disk_key.k_objectid) 757 /* if item was not found we choose the position which is to
758 { 758 the left of the found item. This requires no code,
759 break; 759 bin_search did it already. */
760
761 /* So we have chosen a position in the current node which is
762 an internal node. Now we calculate child block number by
763 position in the node. */
764 n_block_number =
765 B_N_CHILD_NUM(p_s_bh, p_s_last_element->pe_position);
766
767 /* if we are going to read leaf nodes, try for read ahead as well */
768 if ((p_s_search_path->reada & PATH_READA) &&
769 n_node_level == DISK_LEAF_NODE_LEVEL + 1) {
770 int pos = p_s_last_element->pe_position;
771 int limit = B_NR_ITEMS(p_s_bh);
772 struct reiserfs_key *le_key;
773
774 if (p_s_search_path->reada & PATH_READA_BACK)
775 limit = 0;
776 while (reada_count < SEARCH_BY_KEY_READA) {
777 if (pos == limit)
778 break;
779 reada_blocks[reada_count++] =
780 B_N_CHILD_NUM(p_s_bh, pos);
781 if (p_s_search_path->reada & PATH_READA_BACK)
782 pos--;
783 else
784 pos++;
785
786 /*
787 * check to make sure we're in the same object
788 */
789 le_key = B_N_PDELIM_KEY(p_s_bh, pos);
790 if (le32_to_cpu(le_key->k_objectid) !=
791 p_s_key->on_disk_key.k_objectid) {
792 break;
793 }
794 }
760 } 795 }
761 } 796 }
762 }
763 }
764} 797}
765 798
766
767/* Form the path to an item and position in this item which contains 799/* Form the path to an item and position in this item which contains
768 file byte defined by p_s_key. If there is no such item 800 file byte defined by p_s_key. If there is no such item
769 corresponding to the key, we point the path to the item with 801 corresponding to the key, we point the path to the item with
@@ -780,94 +812,97 @@ io_error:
780 units of directory entries. */ 812 units of directory entries. */
781 813
782/* The function is NOT SCHEDULE-SAFE! */ 814/* The function is NOT SCHEDULE-SAFE! */
783int search_for_position_by_key (struct super_block * p_s_sb, /* Pointer to the super block. */ 815int search_for_position_by_key(struct super_block *p_s_sb, /* Pointer to the super block. */
784 const struct cpu_key * p_cpu_key, /* Key to search (cpu variable) */ 816 const struct cpu_key *p_cpu_key, /* Key to search (cpu variable) */
785 struct path * p_s_search_path /* Filled up by this function. */ 817 struct path *p_s_search_path /* Filled up by this function. */
786 ) { 818 )
787 struct item_head * p_le_ih; /* pointer to on-disk structure */ 819{
788 int n_blk_size; 820 struct item_head *p_le_ih; /* pointer to on-disk structure */
789 loff_t item_offset, offset; 821 int n_blk_size;
790 struct reiserfs_dir_entry de; 822 loff_t item_offset, offset;
791 int retval; 823 struct reiserfs_dir_entry de;
792 824 int retval;
793 /* If searching for directory entry. */ 825
794 if ( is_direntry_cpu_key (p_cpu_key) ) 826 /* If searching for directory entry. */
795 return search_by_entry_key (p_s_sb, p_cpu_key, p_s_search_path, &de); 827 if (is_direntry_cpu_key(p_cpu_key))
796 828 return search_by_entry_key(p_s_sb, p_cpu_key, p_s_search_path,
797 /* If not searching for directory entry. */ 829 &de);
798 830
799 /* If item is found. */ 831 /* If not searching for directory entry. */
800 retval = search_item (p_s_sb, p_cpu_key, p_s_search_path); 832
801 if (retval == IO_ERROR) 833 /* If item is found. */
802 return retval; 834 retval = search_item(p_s_sb, p_cpu_key, p_s_search_path);
803 if ( retval == ITEM_FOUND ) { 835 if (retval == IO_ERROR)
804 836 return retval;
805 RFALSE( ! ih_item_len( 837 if (retval == ITEM_FOUND) {
806 B_N_PITEM_HEAD(PATH_PLAST_BUFFER(p_s_search_path),
807 PATH_LAST_POSITION(p_s_search_path))),
808 "PAP-5165: item length equals zero");
809 838
810 pos_in_item(p_s_search_path) = 0; 839 RFALSE(!ih_item_len
811 return POSITION_FOUND; 840 (B_N_PITEM_HEAD
812 } 841 (PATH_PLAST_BUFFER(p_s_search_path),
842 PATH_LAST_POSITION(p_s_search_path))),
843 "PAP-5165: item length equals zero");
813 844
814 RFALSE( ! PATH_LAST_POSITION(p_s_search_path), 845 pos_in_item(p_s_search_path) = 0;
815 "PAP-5170: position equals zero"); 846 return POSITION_FOUND;
847 }
816 848
817 /* Item is not found. Set path to the previous item. */ 849 RFALSE(!PATH_LAST_POSITION(p_s_search_path),
818 p_le_ih = B_N_PITEM_HEAD(PATH_PLAST_BUFFER(p_s_search_path), --PATH_LAST_POSITION(p_s_search_path)); 850 "PAP-5170: position equals zero");
819 n_blk_size = p_s_sb->s_blocksize;
820 851
821 if (comp_short_keys (&(p_le_ih->ih_key), p_cpu_key)) { 852 /* Item is not found. Set path to the previous item. */
822 return FILE_NOT_FOUND; 853 p_le_ih =
823 } 854 B_N_PITEM_HEAD(PATH_PLAST_BUFFER(p_s_search_path),
855 --PATH_LAST_POSITION(p_s_search_path));
856 n_blk_size = p_s_sb->s_blocksize;
824 857
825 // FIXME: quite ugly this far 858 if (comp_short_keys(&(p_le_ih->ih_key), p_cpu_key)) {
859 return FILE_NOT_FOUND;
860 }
861 // FIXME: quite ugly this far
826 862
827 item_offset = le_ih_k_offset (p_le_ih); 863 item_offset = le_ih_k_offset(p_le_ih);
828 offset = cpu_key_k_offset (p_cpu_key); 864 offset = cpu_key_k_offset(p_cpu_key);
829 865
830 /* Needed byte is contained in the item pointed to by the path.*/ 866 /* Needed byte is contained in the item pointed to by the path. */
831 if (item_offset <= offset && 867 if (item_offset <= offset &&
832 item_offset + op_bytes_number (p_le_ih, n_blk_size) > offset) { 868 item_offset + op_bytes_number(p_le_ih, n_blk_size) > offset) {
833 pos_in_item (p_s_search_path) = offset - item_offset; 869 pos_in_item(p_s_search_path) = offset - item_offset;
834 if ( is_indirect_le_ih(p_le_ih) ) { 870 if (is_indirect_le_ih(p_le_ih)) {
835 pos_in_item (p_s_search_path) /= n_blk_size; 871 pos_in_item(p_s_search_path) /= n_blk_size;
872 }
873 return POSITION_FOUND;
836 } 874 }
837 return POSITION_FOUND;
838 }
839
840 /* Needed byte is not contained in the item pointed to by the
841 path. Set pos_in_item out of the item. */
842 if ( is_indirect_le_ih (p_le_ih) )
843 pos_in_item (p_s_search_path) = ih_item_len(p_le_ih) / UNFM_P_SIZE;
844 else
845 pos_in_item (p_s_search_path) = ih_item_len( p_le_ih );
846
847 return POSITION_NOT_FOUND;
848}
849 875
876 /* Needed byte is not contained in the item pointed to by the
877 path. Set pos_in_item out of the item. */
878 if (is_indirect_le_ih(p_le_ih))
879 pos_in_item(p_s_search_path) =
880 ih_item_len(p_le_ih) / UNFM_P_SIZE;
881 else
882 pos_in_item(p_s_search_path) = ih_item_len(p_le_ih);
883
884 return POSITION_NOT_FOUND;
885}
850 886
851/* Compare given item and item pointed to by the path. */ 887/* Compare given item and item pointed to by the path. */
852int comp_items (const struct item_head * stored_ih, const struct path * p_s_path) 888int comp_items(const struct item_head *stored_ih, const struct path *p_s_path)
853{ 889{
854 struct buffer_head * p_s_bh; 890 struct buffer_head *p_s_bh;
855 struct item_head * ih; 891 struct item_head *ih;
856 892
857 /* Last buffer at the path is not in the tree. */ 893 /* Last buffer at the path is not in the tree. */
858 if ( ! B_IS_IN_TREE(p_s_bh = PATH_PLAST_BUFFER(p_s_path)) ) 894 if (!B_IS_IN_TREE(p_s_bh = PATH_PLAST_BUFFER(p_s_path)))
859 return 1; 895 return 1;
860 896
861 /* Last path position is invalid. */ 897 /* Last path position is invalid. */
862 if ( PATH_LAST_POSITION(p_s_path) >= B_NR_ITEMS(p_s_bh) ) 898 if (PATH_LAST_POSITION(p_s_path) >= B_NR_ITEMS(p_s_bh))
863 return 1; 899 return 1;
864 900
865 /* we need only to know, whether it is the same item */ 901 /* we need only to know, whether it is the same item */
866 ih = get_ih (p_s_path); 902 ih = get_ih(p_s_path);
867 return memcmp (stored_ih, ih, IH_SIZE); 903 return memcmp(stored_ih, ih, IH_SIZE);
868} 904}
869 905
870
871/* unformatted nodes are not logged anymore, ever. This is safe 906/* unformatted nodes are not logged anymore, ever. This is safe
872** now 907** now
873*/ 908*/
@@ -876,461 +911,466 @@ int comp_items (const struct item_head * stored_ih, const struct path * p_s_path
876// block can not be forgotten as it is in I/O or held by someone 911// block can not be forgotten as it is in I/O or held by someone
877#define block_in_use(bh) (buffer_locked(bh) || (held_by_others(bh))) 912#define block_in_use(bh) (buffer_locked(bh) || (held_by_others(bh)))
878 913
879
880
881// prepare for delete or cut of direct item 914// prepare for delete or cut of direct item
882static inline int prepare_for_direct_item (struct path * path, 915static inline int prepare_for_direct_item(struct path *path,
883 struct item_head * le_ih, 916 struct item_head *le_ih,
884 struct inode * inode, 917 struct inode *inode,
885 loff_t new_file_length, 918 loff_t new_file_length, int *cut_size)
886 int * cut_size)
887{ 919{
888 loff_t round_len; 920 loff_t round_len;
889 921
890 922 if (new_file_length == max_reiserfs_offset(inode)) {
891 if ( new_file_length == max_reiserfs_offset (inode) ) { 923 /* item has to be deleted */
892 /* item has to be deleted */ 924 *cut_size = -(IH_SIZE + ih_item_len(le_ih));
893 *cut_size = -(IH_SIZE + ih_item_len(le_ih)); 925 return M_DELETE;
894 return M_DELETE; 926 }
895 } 927 // new file gets truncated
896 928 if (get_inode_item_key_version(inode) == KEY_FORMAT_3_6) {
897 // new file gets truncated 929 //
898 if (get_inode_item_key_version (inode) == KEY_FORMAT_3_6) { 930 round_len = ROUND_UP(new_file_length);
899 // 931 /* this was n_new_file_length < le_ih ... */
900 round_len = ROUND_UP (new_file_length); 932 if (round_len < le_ih_k_offset(le_ih)) {
901 /* this was n_new_file_length < le_ih ... */ 933 *cut_size = -(IH_SIZE + ih_item_len(le_ih));
902 if ( round_len < le_ih_k_offset (le_ih) ) { 934 return M_DELETE; /* Delete this item. */
903 *cut_size = -(IH_SIZE + ih_item_len(le_ih)); 935 }
904 return M_DELETE; /* Delete this item. */ 936 /* Calculate first position and size for cutting from item. */
937 pos_in_item(path) = round_len - (le_ih_k_offset(le_ih) - 1);
938 *cut_size = -(ih_item_len(le_ih) - pos_in_item(path));
939
940 return M_CUT; /* Cut from this item. */
941 }
942
943 // old file: items may have any length
944
945 if (new_file_length < le_ih_k_offset(le_ih)) {
946 *cut_size = -(IH_SIZE + ih_item_len(le_ih));
947 return M_DELETE; /* Delete this item. */
905 } 948 }
906 /* Calculate first position and size for cutting from item. */ 949 /* Calculate first position and size for cutting from item. */
907 pos_in_item (path) = round_len - (le_ih_k_offset (le_ih) - 1); 950 *cut_size = -(ih_item_len(le_ih) -
908 *cut_size = -(ih_item_len(le_ih) - pos_in_item(path)); 951 (pos_in_item(path) =
909 952 new_file_length + 1 - le_ih_k_offset(le_ih)));
910 return M_CUT; /* Cut from this item. */ 953 return M_CUT; /* Cut from this item. */
911 }
912
913
914 // old file: items may have any length
915
916 if ( new_file_length < le_ih_k_offset (le_ih) ) {
917 *cut_size = -(IH_SIZE + ih_item_len(le_ih));
918 return M_DELETE; /* Delete this item. */
919 }
920 /* Calculate first position and size for cutting from item. */
921 *cut_size = -(ih_item_len(le_ih) -
922 (pos_in_item (path) = new_file_length + 1 - le_ih_k_offset (le_ih)));
923 return M_CUT; /* Cut from this item. */
924} 954}
925 955
926 956static inline int prepare_for_direntry_item(struct path *path,
927static inline int prepare_for_direntry_item (struct path * path, 957 struct item_head *le_ih,
928 struct item_head * le_ih, 958 struct inode *inode,
929 struct inode * inode, 959 loff_t new_file_length,
930 loff_t new_file_length, 960 int *cut_size)
931 int * cut_size)
932{ 961{
933 if (le_ih_k_offset (le_ih) == DOT_OFFSET && 962 if (le_ih_k_offset(le_ih) == DOT_OFFSET &&
934 new_file_length == max_reiserfs_offset (inode)) { 963 new_file_length == max_reiserfs_offset(inode)) {
935 RFALSE( ih_entry_count (le_ih) != 2, 964 RFALSE(ih_entry_count(le_ih) != 2,
936 "PAP-5220: incorrect empty directory item (%h)", le_ih); 965 "PAP-5220: incorrect empty directory item (%h)", le_ih);
937 *cut_size = -(IH_SIZE + ih_item_len(le_ih)); 966 *cut_size = -(IH_SIZE + ih_item_len(le_ih));
938 return M_DELETE; /* Delete the directory item containing "." and ".." entry. */ 967 return M_DELETE; /* Delete the directory item containing "." and ".." entry. */
939 } 968 }
940
941 if ( ih_entry_count (le_ih) == 1 ) {
942 /* Delete the directory item such as there is one record only
943 in this item*/
944 *cut_size = -(IH_SIZE + ih_item_len(le_ih));
945 return M_DELETE;
946 }
947
948 /* Cut one record from the directory item. */
949 *cut_size = -(DEH_SIZE + entry_length (get_last_bh (path), le_ih, pos_in_item (path)));
950 return M_CUT;
951}
952 969
970 if (ih_entry_count(le_ih) == 1) {
971 /* Delete the directory item such as there is one record only
972 in this item */
973 *cut_size = -(IH_SIZE + ih_item_len(le_ih));
974 return M_DELETE;
975 }
976
977 /* Cut one record from the directory item. */
978 *cut_size =
979 -(DEH_SIZE +
980 entry_length(get_last_bh(path), le_ih, pos_in_item(path)));
981 return M_CUT;
982}
953 983
954/* If the path points to a directory or direct item, calculate mode and the size cut, for balance. 984/* If the path points to a directory or direct item, calculate mode and the size cut, for balance.
955 If the path points to an indirect item, remove some number of its unformatted nodes. 985 If the path points to an indirect item, remove some number of its unformatted nodes.
956 In case of file truncate calculate whether this item must be deleted/truncated or last 986 In case of file truncate calculate whether this item must be deleted/truncated or last
957 unformatted node of this item will be converted to a direct item. 987 unformatted node of this item will be converted to a direct item.
958 This function returns a determination of what balance mode the calling function should employ. */ 988 This function returns a determination of what balance mode the calling function should employ. */
959static char prepare_for_delete_or_cut( 989static char prepare_for_delete_or_cut(struct reiserfs_transaction_handle *th, struct inode *inode, struct path *p_s_path, const struct cpu_key *p_s_item_key, int *p_n_removed, /* Number of unformatted nodes which were removed
960 struct reiserfs_transaction_handle *th, 990 from end of the file. */
961 struct inode * inode, 991 int *p_n_cut_size, unsigned long long n_new_file_length /* MAX_KEY_OFFSET in case of delete. */
962 struct path * p_s_path, 992 )
963 const struct cpu_key * p_s_item_key, 993{
964 int * p_n_removed, /* Number of unformatted nodes which were removed 994 struct super_block *p_s_sb = inode->i_sb;
965 from end of the file. */ 995 struct item_head *p_le_ih = PATH_PITEM_HEAD(p_s_path);
966 int * p_n_cut_size, 996 struct buffer_head *p_s_bh = PATH_PLAST_BUFFER(p_s_path);
967 unsigned long long n_new_file_length /* MAX_KEY_OFFSET in case of delete. */
968 ) {
969 struct super_block * p_s_sb = inode->i_sb;
970 struct item_head * p_le_ih = PATH_PITEM_HEAD(p_s_path);
971 struct buffer_head * p_s_bh = PATH_PLAST_BUFFER(p_s_path);
972
973 BUG_ON (!th->t_trans_id);
974
975 /* Stat_data item. */
976 if ( is_statdata_le_ih (p_le_ih) ) {
977
978 RFALSE( n_new_file_length != max_reiserfs_offset (inode),
979 "PAP-5210: mode must be M_DELETE");
980
981 *p_n_cut_size = -(IH_SIZE + ih_item_len(p_le_ih));
982 return M_DELETE;
983 }
984
985
986 /* Directory item. */
987 if ( is_direntry_le_ih (p_le_ih) )
988 return prepare_for_direntry_item (p_s_path, p_le_ih, inode, n_new_file_length, p_n_cut_size);
989
990 /* Direct item. */
991 if ( is_direct_le_ih (p_le_ih) )
992 return prepare_for_direct_item (p_s_path, p_le_ih, inode, n_new_file_length, p_n_cut_size);
993
994
995 /* Case of an indirect item. */
996 {
997 int n_unfm_number, /* Number of the item unformatted nodes. */
998 n_counter,
999 n_blk_size;
1000 __le32 * p_n_unfm_pointer; /* Pointer to the unformatted node number. */
1001 __u32 tmp;
1002 struct item_head s_ih; /* Item header. */
1003 char c_mode; /* Returned mode of the balance. */
1004 int need_research;
1005 997
998 BUG_ON(!th->t_trans_id);
1006 999
1007 n_blk_size = p_s_sb->s_blocksize; 1000 /* Stat_data item. */
1001 if (is_statdata_le_ih(p_le_ih)) {
1008 1002
1009 /* Search for the needed object indirect item until there are no unformatted nodes to be removed. */ 1003 RFALSE(n_new_file_length != max_reiserfs_offset(inode),
1010 do { 1004 "PAP-5210: mode must be M_DELETE");
1011 need_research = 0;
1012 p_s_bh = PATH_PLAST_BUFFER(p_s_path);
1013 /* Copy indirect item header to a temp variable. */
1014 copy_item_head(&s_ih, PATH_PITEM_HEAD(p_s_path));
1015 /* Calculate number of unformatted nodes in this item. */
1016 n_unfm_number = I_UNFM_NUM(&s_ih);
1017
1018 RFALSE( ! is_indirect_le_ih(&s_ih) || ! n_unfm_number ||
1019 pos_in_item (p_s_path) + 1 != n_unfm_number,
1020 "PAP-5240: invalid item %h "
1021 "n_unfm_number = %d *p_n_pos_in_item = %d",
1022 &s_ih, n_unfm_number, pos_in_item (p_s_path));
1023
1024 /* Calculate balance mode and position in the item to remove unformatted nodes. */
1025 if ( n_new_file_length == max_reiserfs_offset (inode) ) {/* Case of delete. */
1026 pos_in_item (p_s_path) = 0;
1027 *p_n_cut_size = -(IH_SIZE + ih_item_len(&s_ih));
1028 c_mode = M_DELETE;
1029 }
1030 else { /* Case of truncate. */
1031 if ( n_new_file_length < le_ih_k_offset (&s_ih) ) {
1032 pos_in_item (p_s_path) = 0;
1033 *p_n_cut_size = -(IH_SIZE + ih_item_len(&s_ih));
1034 c_mode = M_DELETE; /* Delete this item. */
1035 }
1036 else {
1037 /* indirect item must be truncated starting from *p_n_pos_in_item-th position */
1038 pos_in_item (p_s_path) = (n_new_file_length + n_blk_size - le_ih_k_offset (&s_ih) ) >> p_s_sb->s_blocksize_bits;
1039
1040 RFALSE( pos_in_item (p_s_path) > n_unfm_number,
1041 "PAP-5250: invalid position in the item");
1042
1043 /* Either convert last unformatted node of indirect item to direct item or increase
1044 its free space. */
1045 if ( pos_in_item (p_s_path) == n_unfm_number ) {
1046 *p_n_cut_size = 0; /* Nothing to cut. */
1047 return M_CONVERT; /* Maybe convert last unformatted node to the direct item. */
1048 }
1049 /* Calculate size to cut. */
1050 *p_n_cut_size = -(ih_item_len(&s_ih) - pos_in_item(p_s_path) * UNFM_P_SIZE);
1051
1052 c_mode = M_CUT; /* Cut from this indirect item. */
1053 }
1054 }
1055
1056 RFALSE( n_unfm_number <= pos_in_item (p_s_path),
1057 "PAP-5260: invalid position in the indirect item");
1058
1059 /* pointers to be cut */
1060 n_unfm_number -= pos_in_item (p_s_path);
1061 /* Set pointer to the last unformatted node pointer that is to be cut. */
1062 p_n_unfm_pointer = (__le32 *)B_I_PITEM(p_s_bh, &s_ih) + I_UNFM_NUM(&s_ih) - 1 - *p_n_removed;
1063
1064
1065 /* We go through the unformatted nodes pointers of the indirect
1066 item and look for the unformatted nodes in the cache. If we
1067 found some of them we free it, zero corresponding indirect item
1068 entry and log buffer containing that indirect item. For this we
1069 need to prepare last path element for logging. If some
1070 unformatted node has b_count > 1 we must not free this
1071 unformatted node since it is in use. */
1072 reiserfs_prepare_for_journal(p_s_sb, p_s_bh, 1);
1073 // note: path could be changed, first line in for loop takes care
1074 // of it
1075
1076 for (n_counter = *p_n_removed;
1077 n_counter < n_unfm_number; n_counter++, p_n_unfm_pointer-- ) {
1078
1079 cond_resched();
1080 if (item_moved (&s_ih, p_s_path)) {
1081 need_research = 1 ;
1082 break;
1083 }
1084 RFALSE( p_n_unfm_pointer < (__le32 *)B_I_PITEM(p_s_bh, &s_ih) ||
1085 p_n_unfm_pointer > (__le32 *)B_I_PITEM(p_s_bh, &s_ih) + I_UNFM_NUM(&s_ih) - 1,
1086 "vs-5265: pointer out of range");
1087 1005
1088 /* Hole, nothing to remove. */ 1006 *p_n_cut_size = -(IH_SIZE + ih_item_len(p_le_ih));
1089 if ( ! get_block_num(p_n_unfm_pointer,0) ) { 1007 return M_DELETE;
1090 (*p_n_removed)++; 1008 }
1091 continue;
1092 }
1093 1009
1094 (*p_n_removed)++; 1010 /* Directory item. */
1011 if (is_direntry_le_ih(p_le_ih))
1012 return prepare_for_direntry_item(p_s_path, p_le_ih, inode,
1013 n_new_file_length,
1014 p_n_cut_size);
1095 1015
1096 tmp = get_block_num(p_n_unfm_pointer,0); 1016 /* Direct item. */
1097 put_block_num(p_n_unfm_pointer, 0, 0); 1017 if (is_direct_le_ih(p_le_ih))
1098 journal_mark_dirty (th, p_s_sb, p_s_bh); 1018 return prepare_for_direct_item(p_s_path, p_le_ih, inode,
1099 reiserfs_free_block(th, inode, tmp, 1); 1019 n_new_file_length, p_n_cut_size);
1100 if ( item_moved (&s_ih, p_s_path) ) { 1020
1101 need_research = 1; 1021 /* Case of an indirect item. */
1102 break ; 1022 {
1103 } 1023 int n_unfm_number, /* Number of the item unformatted nodes. */
1104 } 1024 n_counter, n_blk_size;
1105 1025 __le32 *p_n_unfm_pointer; /* Pointer to the unformatted node number. */
1106 /* a trick. If the buffer has been logged, this 1026 __u32 tmp;
1107 ** will do nothing. If we've broken the loop without 1027 struct item_head s_ih; /* Item header. */
1108 ** logging it, it will restore the buffer 1028 char c_mode; /* Returned mode of the balance. */
1109 ** 1029 int need_research;
1110 */ 1030
1111 reiserfs_restore_prepared_buffer(p_s_sb, p_s_bh); 1031 n_blk_size = p_s_sb->s_blocksize;
1112 1032
1113 /* This loop can be optimized. */ 1033 /* Search for the needed object indirect item until there are no unformatted nodes to be removed. */
1114 } while ( (*p_n_removed < n_unfm_number || need_research) && 1034 do {
1115 search_for_position_by_key(p_s_sb, p_s_item_key, p_s_path) == POSITION_FOUND ); 1035 need_research = 0;
1116 1036 p_s_bh = PATH_PLAST_BUFFER(p_s_path);
1117 RFALSE( *p_n_removed < n_unfm_number, 1037 /* Copy indirect item header to a temp variable. */
1118 "PAP-5310: indirect item is not found"); 1038 copy_item_head(&s_ih, PATH_PITEM_HEAD(p_s_path));
1119 RFALSE( item_moved (&s_ih, p_s_path), 1039 /* Calculate number of unformatted nodes in this item. */
1120 "after while, comp failed, retry") ; 1040 n_unfm_number = I_UNFM_NUM(&s_ih);
1121 1041
1122 if (c_mode == M_CUT) 1042 RFALSE(!is_indirect_le_ih(&s_ih) || !n_unfm_number ||
1123 pos_in_item (p_s_path) *= UNFM_P_SIZE; 1043 pos_in_item(p_s_path) + 1 != n_unfm_number,
1124 return c_mode; 1044 "PAP-5240: invalid item %h "
1125 } 1045 "n_unfm_number = %d *p_n_pos_in_item = %d",
1046 &s_ih, n_unfm_number, pos_in_item(p_s_path));
1047
1048 /* Calculate balance mode and position in the item to remove unformatted nodes. */
1049 if (n_new_file_length == max_reiserfs_offset(inode)) { /* Case of delete. */
1050 pos_in_item(p_s_path) = 0;
1051 *p_n_cut_size = -(IH_SIZE + ih_item_len(&s_ih));
1052 c_mode = M_DELETE;
1053 } else { /* Case of truncate. */
1054 if (n_new_file_length < le_ih_k_offset(&s_ih)) {
1055 pos_in_item(p_s_path) = 0;
1056 *p_n_cut_size =
1057 -(IH_SIZE + ih_item_len(&s_ih));
1058 c_mode = M_DELETE; /* Delete this item. */
1059 } else {
1060 /* indirect item must be truncated starting from *p_n_pos_in_item-th position */
1061 pos_in_item(p_s_path) =
1062 (n_new_file_length + n_blk_size -
1063 le_ih_k_offset(&s_ih)) >> p_s_sb->
1064 s_blocksize_bits;
1065
1066 RFALSE(pos_in_item(p_s_path) >
1067 n_unfm_number,
1068 "PAP-5250: invalid position in the item");
1069
1070 /* Either convert last unformatted node of indirect item to direct item or increase
1071 its free space. */
1072 if (pos_in_item(p_s_path) ==
1073 n_unfm_number) {
1074 *p_n_cut_size = 0; /* Nothing to cut. */
1075 return M_CONVERT; /* Maybe convert last unformatted node to the direct item. */
1076 }
1077 /* Calculate size to cut. */
1078 *p_n_cut_size =
1079 -(ih_item_len(&s_ih) -
1080 pos_in_item(p_s_path) *
1081 UNFM_P_SIZE);
1082
1083 c_mode = M_CUT; /* Cut from this indirect item. */
1084 }
1085 }
1086
1087 RFALSE(n_unfm_number <= pos_in_item(p_s_path),
1088 "PAP-5260: invalid position in the indirect item");
1089
1090 /* pointers to be cut */
1091 n_unfm_number -= pos_in_item(p_s_path);
1092 /* Set pointer to the last unformatted node pointer that is to be cut. */
1093 p_n_unfm_pointer =
1094 (__le32 *) B_I_PITEM(p_s_bh,
1095 &s_ih) + I_UNFM_NUM(&s_ih) -
1096 1 - *p_n_removed;
1097
1098 /* We go through the unformatted nodes pointers of the indirect
1099 item and look for the unformatted nodes in the cache. If we
1100 found some of them we free it, zero corresponding indirect item
1101 entry and log buffer containing that indirect item. For this we
1102 need to prepare last path element for logging. If some
1103 unformatted node has b_count > 1 we must not free this
1104 unformatted node since it is in use. */
1105 reiserfs_prepare_for_journal(p_s_sb, p_s_bh, 1);
1106 // note: path could be changed, first line in for loop takes care
1107 // of it
1108
1109 for (n_counter = *p_n_removed;
1110 n_counter < n_unfm_number;
1111 n_counter++, p_n_unfm_pointer--) {
1112
1113 cond_resched();
1114 if (item_moved(&s_ih, p_s_path)) {
1115 need_research = 1;
1116 break;
1117 }
1118 RFALSE(p_n_unfm_pointer <
1119 (__le32 *) B_I_PITEM(p_s_bh, &s_ih)
1120 || p_n_unfm_pointer >
1121 (__le32 *) B_I_PITEM(p_s_bh,
1122 &s_ih) +
1123 I_UNFM_NUM(&s_ih) - 1,
1124 "vs-5265: pointer out of range");
1125
1126 /* Hole, nothing to remove. */
1127 if (!get_block_num(p_n_unfm_pointer, 0)) {
1128 (*p_n_removed)++;
1129 continue;
1130 }
1131
1132 (*p_n_removed)++;
1133
1134 tmp = get_block_num(p_n_unfm_pointer, 0);
1135 put_block_num(p_n_unfm_pointer, 0, 0);
1136 journal_mark_dirty(th, p_s_sb, p_s_bh);
1137 reiserfs_free_block(th, inode, tmp, 1);
1138 if (item_moved(&s_ih, p_s_path)) {
1139 need_research = 1;
1140 break;
1141 }
1142 }
1143
1144 /* a trick. If the buffer has been logged, this
1145 ** will do nothing. If we've broken the loop without
1146 ** logging it, it will restore the buffer
1147 **
1148 */
1149 reiserfs_restore_prepared_buffer(p_s_sb, p_s_bh);
1150
1151 /* This loop can be optimized. */
1152 } while ((*p_n_removed < n_unfm_number || need_research) &&
1153 search_for_position_by_key(p_s_sb, p_s_item_key,
1154 p_s_path) ==
1155 POSITION_FOUND);
1156
1157 RFALSE(*p_n_removed < n_unfm_number,
1158 "PAP-5310: indirect item is not found");
1159 RFALSE(item_moved(&s_ih, p_s_path),
1160 "after while, comp failed, retry");
1161
1162 if (c_mode == M_CUT)
1163 pos_in_item(p_s_path) *= UNFM_P_SIZE;
1164 return c_mode;
1165 }
1126} 1166}
1127 1167
1128/* Calculate number of bytes which will be deleted or cut during balance */ 1168/* Calculate number of bytes which will be deleted or cut during balance */
1129static int calc_deleted_bytes_number( 1169static int calc_deleted_bytes_number(struct tree_balance *p_s_tb, char c_mode)
1130 struct tree_balance * p_s_tb, 1170{
1131 char c_mode 1171 int n_del_size;
1132 ) { 1172 struct item_head *p_le_ih = PATH_PITEM_HEAD(p_s_tb->tb_path);
1133 int n_del_size; 1173
1134 struct item_head * p_le_ih = PATH_PITEM_HEAD(p_s_tb->tb_path); 1174 if (is_statdata_le_ih(p_le_ih))
1135 1175 return 0;
1136 if ( is_statdata_le_ih (p_le_ih) ) 1176
1137 return 0; 1177 n_del_size =
1178 (c_mode ==
1179 M_DELETE) ? ih_item_len(p_le_ih) : -p_s_tb->insert_size[0];
1180 if (is_direntry_le_ih(p_le_ih)) {
1181 // return EMPTY_DIR_SIZE; /* We delete emty directoris only. */
1182 // we can't use EMPTY_DIR_SIZE, as old format dirs have a different
1183 // empty size. ick. FIXME, is this right?
1184 //
1185 return n_del_size;
1186 }
1138 1187
1139 n_del_size = ( c_mode == M_DELETE ) ? ih_item_len(p_le_ih) : -p_s_tb->insert_size[0]; 1188 if (is_indirect_le_ih(p_le_ih))
1140 if ( is_direntry_le_ih (p_le_ih) ) { 1189 n_del_size = (n_del_size / UNFM_P_SIZE) * (PATH_PLAST_BUFFER(p_s_tb->tb_path)->b_size); // - get_ih_free_space (p_le_ih);
1141 // return EMPTY_DIR_SIZE; /* We delete emty directoris only. */ 1190 return n_del_size;
1142 // we can't use EMPTY_DIR_SIZE, as old format dirs have a different
1143 // empty size. ick. FIXME, is this right?
1144 //
1145 return n_del_size ;
1146 }
1147
1148 if ( is_indirect_le_ih (p_le_ih) )
1149 n_del_size = (n_del_size/UNFM_P_SIZE)*
1150 (PATH_PLAST_BUFFER(p_s_tb->tb_path)->b_size);// - get_ih_free_space (p_le_ih);
1151 return n_del_size;
1152} 1191}
1153 1192
1154static void init_tb_struct( 1193static void init_tb_struct(struct reiserfs_transaction_handle *th,
1155 struct reiserfs_transaction_handle *th, 1194 struct tree_balance *p_s_tb,
1156 struct tree_balance * p_s_tb, 1195 struct super_block *p_s_sb,
1157 struct super_block * p_s_sb, 1196 struct path *p_s_path, int n_size)
1158 struct path * p_s_path, 1197{
1159 int n_size
1160 ) {
1161
1162 BUG_ON (!th->t_trans_id);
1163
1164 memset (p_s_tb,'\0',sizeof(struct tree_balance));
1165 p_s_tb->transaction_handle = th ;
1166 p_s_tb->tb_sb = p_s_sb;
1167 p_s_tb->tb_path = p_s_path;
1168 PATH_OFFSET_PBUFFER(p_s_path, ILLEGAL_PATH_ELEMENT_OFFSET) = NULL;
1169 PATH_OFFSET_POSITION(p_s_path, ILLEGAL_PATH_ELEMENT_OFFSET) = 0;
1170 p_s_tb->insert_size[0] = n_size;
1171}
1172 1198
1199 BUG_ON(!th->t_trans_id);
1173 1200
1201 memset(p_s_tb, '\0', sizeof(struct tree_balance));
1202 p_s_tb->transaction_handle = th;
1203 p_s_tb->tb_sb = p_s_sb;
1204 p_s_tb->tb_path = p_s_path;
1205 PATH_OFFSET_PBUFFER(p_s_path, ILLEGAL_PATH_ELEMENT_OFFSET) = NULL;
1206 PATH_OFFSET_POSITION(p_s_path, ILLEGAL_PATH_ELEMENT_OFFSET) = 0;
1207 p_s_tb->insert_size[0] = n_size;
1208}
1174 1209
1175void padd_item (char * item, int total_length, int length) 1210void padd_item(char *item, int total_length, int length)
1176{ 1211{
1177 int i; 1212 int i;
1178 1213
1179 for (i = total_length; i > length; ) 1214 for (i = total_length; i > length;)
1180 item [--i] = 0; 1215 item[--i] = 0;
1181} 1216}
1182 1217
1183#ifdef REISERQUOTA_DEBUG 1218#ifdef REISERQUOTA_DEBUG
1184char key2type(struct reiserfs_key *ih) 1219char key2type(struct reiserfs_key *ih)
1185{ 1220{
1186 if (is_direntry_le_key(2, ih)) 1221 if (is_direntry_le_key(2, ih))
1187 return 'd'; 1222 return 'd';
1188 if (is_direct_le_key(2, ih)) 1223 if (is_direct_le_key(2, ih))
1189 return 'D'; 1224 return 'D';
1190 if (is_indirect_le_key(2, ih)) 1225 if (is_indirect_le_key(2, ih))
1191 return 'i'; 1226 return 'i';
1192 if (is_statdata_le_key(2, ih)) 1227 if (is_statdata_le_key(2, ih))
1193 return 's'; 1228 return 's';
1194 return 'u'; 1229 return 'u';
1195} 1230}
1196 1231
1197char head2type(struct item_head *ih) 1232char head2type(struct item_head *ih)
1198{ 1233{
1199 if (is_direntry_le_ih(ih)) 1234 if (is_direntry_le_ih(ih))
1200 return 'd'; 1235 return 'd';
1201 if (is_direct_le_ih(ih)) 1236 if (is_direct_le_ih(ih))
1202 return 'D'; 1237 return 'D';
1203 if (is_indirect_le_ih(ih)) 1238 if (is_indirect_le_ih(ih))
1204 return 'i'; 1239 return 'i';
1205 if (is_statdata_le_ih(ih)) 1240 if (is_statdata_le_ih(ih))
1206 return 's'; 1241 return 's';
1207 return 'u'; 1242 return 'u';
1208} 1243}
1209#endif 1244#endif
1210 1245
1211/* Delete object item. */ 1246/* Delete object item. */
1212int reiserfs_delete_item (struct reiserfs_transaction_handle *th, 1247int reiserfs_delete_item(struct reiserfs_transaction_handle *th, struct path *p_s_path, /* Path to the deleted item. */
1213 struct path * p_s_path, /* Path to the deleted item. */ 1248 const struct cpu_key *p_s_item_key, /* Key to search for the deleted item. */
1214 const struct cpu_key * p_s_item_key, /* Key to search for the deleted item. */ 1249 struct inode *p_s_inode, /* inode is here just to update i_blocks and quotas */
1215 struct inode * p_s_inode,/* inode is here just to update i_blocks and quotas */ 1250 struct buffer_head *p_s_un_bh)
1216 struct buffer_head * p_s_un_bh) /* NULL or unformatted node pointer. */ 1251{ /* NULL or unformatted node pointer. */
1217{ 1252 struct super_block *p_s_sb = p_s_inode->i_sb;
1218 struct super_block * p_s_sb = p_s_inode->i_sb; 1253 struct tree_balance s_del_balance;
1219 struct tree_balance s_del_balance; 1254 struct item_head s_ih;
1220 struct item_head s_ih; 1255 struct item_head *q_ih;
1221 struct item_head *q_ih; 1256 int quota_cut_bytes;
1222 int quota_cut_bytes; 1257 int n_ret_value, n_del_size, n_removed;
1223 int n_ret_value,
1224 n_del_size,
1225 n_removed;
1226 1258
1227#ifdef CONFIG_REISERFS_CHECK 1259#ifdef CONFIG_REISERFS_CHECK
1228 char c_mode; 1260 char c_mode;
1229 int n_iter = 0; 1261 int n_iter = 0;
1230#endif 1262#endif
1231 1263
1232 BUG_ON (!th->t_trans_id); 1264 BUG_ON(!th->t_trans_id);
1233 1265
1234 init_tb_struct(th, &s_del_balance, p_s_sb, p_s_path, 0/*size is unknown*/); 1266 init_tb_struct(th, &s_del_balance, p_s_sb, p_s_path,
1267 0 /*size is unknown */ );
1235 1268
1236 while ( 1 ) { 1269 while (1) {
1237 n_removed = 0; 1270 n_removed = 0;
1238 1271
1239#ifdef CONFIG_REISERFS_CHECK 1272#ifdef CONFIG_REISERFS_CHECK
1240 n_iter++; 1273 n_iter++;
1241 c_mode = 1274 c_mode =
1242#endif 1275#endif
1243 prepare_for_delete_or_cut(th, p_s_inode, p_s_path, p_s_item_key, &n_removed, &n_del_size, max_reiserfs_offset (p_s_inode)); 1276 prepare_for_delete_or_cut(th, p_s_inode, p_s_path,
1244 1277 p_s_item_key, &n_removed,
1245 RFALSE( c_mode != M_DELETE, "PAP-5320: mode must be M_DELETE"); 1278 &n_del_size,
1246 1279 max_reiserfs_offset(p_s_inode));
1247 copy_item_head(&s_ih, PATH_PITEM_HEAD(p_s_path)); 1280
1248 s_del_balance.insert_size[0] = n_del_size; 1281 RFALSE(c_mode != M_DELETE, "PAP-5320: mode must be M_DELETE");
1249 1282
1250 n_ret_value = fix_nodes(M_DELETE, &s_del_balance, NULL, NULL); 1283 copy_item_head(&s_ih, PATH_PITEM_HEAD(p_s_path));
1251 if ( n_ret_value != REPEAT_SEARCH ) 1284 s_del_balance.insert_size[0] = n_del_size;
1252 break; 1285
1253 1286 n_ret_value = fix_nodes(M_DELETE, &s_del_balance, NULL, NULL);
1254 PROC_INFO_INC( p_s_sb, delete_item_restarted ); 1287 if (n_ret_value != REPEAT_SEARCH)
1288 break;
1289
1290 PROC_INFO_INC(p_s_sb, delete_item_restarted);
1291
1292 // file system changed, repeat search
1293 n_ret_value =
1294 search_for_position_by_key(p_s_sb, p_s_item_key, p_s_path);
1295 if (n_ret_value == IO_ERROR)
1296 break;
1297 if (n_ret_value == FILE_NOT_FOUND) {
1298 reiserfs_warning(p_s_sb,
1299 "vs-5340: reiserfs_delete_item: "
1300 "no items of the file %K found",
1301 p_s_item_key);
1302 break;
1303 }
1304 } /* while (1) */
1255 1305
1256 // file system changed, repeat search 1306 if (n_ret_value != CARRY_ON) {
1257 n_ret_value = search_for_position_by_key(p_s_sb, p_s_item_key, p_s_path); 1307 unfix_nodes(&s_del_balance);
1258 if (n_ret_value == IO_ERROR) 1308 return 0;
1259 break; 1309 }
1260 if (n_ret_value == FILE_NOT_FOUND) { 1310 // reiserfs_delete_item returns item length when success
1261 reiserfs_warning (p_s_sb, "vs-5340: reiserfs_delete_item: " 1311 n_ret_value = calc_deleted_bytes_number(&s_del_balance, M_DELETE);
1262 "no items of the file %K found", p_s_item_key); 1312 q_ih = get_ih(p_s_path);
1263 break; 1313 quota_cut_bytes = ih_item_len(q_ih);
1314
1315 /* hack so the quota code doesn't have to guess if the file
1316 ** has a tail. On tail insert, we allocate quota for 1 unformatted node.
1317 ** We test the offset because the tail might have been
1318 ** split into multiple items, and we only want to decrement for
1319 ** the unfm node once
1320 */
1321 if (!S_ISLNK(p_s_inode->i_mode) && is_direct_le_ih(q_ih)) {
1322 if ((le_ih_k_offset(q_ih) & (p_s_sb->s_blocksize - 1)) == 1) {
1323 quota_cut_bytes = p_s_sb->s_blocksize + UNFM_P_SIZE;
1324 } else {
1325 quota_cut_bytes = 0;
1326 }
1264 } 1327 }
1265 } /* while (1) */
1266 1328
1267 if ( n_ret_value != CARRY_ON ) { 1329 if (p_s_un_bh) {
1268 unfix_nodes(&s_del_balance); 1330 int off;
1269 return 0; 1331 char *data;
1270 } 1332
1271 1333 /* We are in direct2indirect conversion, so move tail contents
1272 // reiserfs_delete_item returns item length when success 1334 to the unformatted node */
1273 n_ret_value = calc_deleted_bytes_number(&s_del_balance, M_DELETE); 1335 /* note, we do the copy before preparing the buffer because we
1274 q_ih = get_ih(p_s_path) ; 1336 ** don't care about the contents of the unformatted node yet.
1275 quota_cut_bytes = ih_item_len(q_ih) ; 1337 ** the only thing we really care about is the direct item's data
1276 1338 ** is in the unformatted node.
1277 /* hack so the quota code doesn't have to guess if the file 1339 **
1278 ** has a tail. On tail insert, we allocate quota for 1 unformatted node. 1340 ** Otherwise, we would have to call reiserfs_prepare_for_journal on
1279 ** We test the offset because the tail might have been 1341 ** the unformatted node, which might schedule, meaning we'd have to
1280 ** split into multiple items, and we only want to decrement for 1342 ** loop all the way back up to the start of the while loop.
1281 ** the unfm node once 1343 **
1282 */ 1344 ** The unformatted node must be dirtied later on. We can't be
1283 if (!S_ISLNK (p_s_inode->i_mode) && is_direct_le_ih(q_ih)) { 1345 ** sure here if the entire tail has been deleted yet.
1284 if ((le_ih_k_offset(q_ih) & (p_s_sb->s_blocksize - 1)) == 1) { 1346 **
1285 quota_cut_bytes = p_s_sb->s_blocksize + UNFM_P_SIZE; 1347 ** p_s_un_bh is from the page cache (all unformatted nodes are
1286 } else { 1348 ** from the page cache) and might be a highmem page. So, we
1287 quota_cut_bytes = 0 ; 1349 ** can't use p_s_un_bh->b_data.
1350 ** -clm
1351 */
1352
1353 data = kmap_atomic(p_s_un_bh->b_page, KM_USER0);
1354 off = ((le_ih_k_offset(&s_ih) - 1) & (PAGE_CACHE_SIZE - 1));
1355 memcpy(data + off,
1356 B_I_PITEM(PATH_PLAST_BUFFER(p_s_path), &s_ih),
1357 n_ret_value);
1358 kunmap_atomic(data, KM_USER0);
1288 } 1359 }
1289 } 1360 /* Perform balancing after all resources have been collected at once. */
1290 1361 do_balance(&s_del_balance, NULL, NULL, M_DELETE);
1291 if ( p_s_un_bh ) {
1292 int off;
1293 char *data ;
1294
1295 /* We are in direct2indirect conversion, so move tail contents
1296 to the unformatted node */
1297 /* note, we do the copy before preparing the buffer because we
1298 ** don't care about the contents of the unformatted node yet.
1299 ** the only thing we really care about is the direct item's data
1300 ** is in the unformatted node.
1301 **
1302 ** Otherwise, we would have to call reiserfs_prepare_for_journal on
1303 ** the unformatted node, which might schedule, meaning we'd have to
1304 ** loop all the way back up to the start of the while loop.
1305 **
1306 ** The unformatted node must be dirtied later on. We can't be
1307 ** sure here if the entire tail has been deleted yet.
1308 **
1309 ** p_s_un_bh is from the page cache (all unformatted nodes are
1310 ** from the page cache) and might be a highmem page. So, we
1311 ** can't use p_s_un_bh->b_data.
1312 ** -clm
1313 */
1314
1315 data = kmap_atomic(p_s_un_bh->b_page, KM_USER0);
1316 off = ((le_ih_k_offset (&s_ih) - 1) & (PAGE_CACHE_SIZE - 1));
1317 memcpy(data + off,
1318 B_I_PITEM(PATH_PLAST_BUFFER(p_s_path), &s_ih), n_ret_value);
1319 kunmap_atomic(data, KM_USER0);
1320 }
1321 /* Perform balancing after all resources have been collected at once. */
1322 do_balance(&s_del_balance, NULL, NULL, M_DELETE);
1323 1362
1324#ifdef REISERQUOTA_DEBUG 1363#ifdef REISERQUOTA_DEBUG
1325 reiserfs_debug (p_s_sb, REISERFS_DEBUG_CODE, "reiserquota delete_item(): freeing %u, id=%u type=%c", quota_cut_bytes, p_s_inode->i_uid, head2type(&s_ih)); 1364 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE,
1365 "reiserquota delete_item(): freeing %u, id=%u type=%c",
1366 quota_cut_bytes, p_s_inode->i_uid, head2type(&s_ih));
1326#endif 1367#endif
1327 DQUOT_FREE_SPACE_NODIRTY(p_s_inode, quota_cut_bytes); 1368 DQUOT_FREE_SPACE_NODIRTY(p_s_inode, quota_cut_bytes);
1328 1369
1329 /* Return deleted body length */ 1370 /* Return deleted body length */
1330 return n_ret_value; 1371 return n_ret_value;
1331} 1372}
1332 1373
1333
1334/* Summary Of Mechanisms For Handling Collisions Between Processes: 1374/* Summary Of Mechanisms For Handling Collisions Between Processes:
1335 1375
1336 deletion of the body of the object is performed by iput(), with the 1376 deletion of the body of the object is performed by iput(), with the
@@ -1347,727 +1387,804 @@ int reiserfs_delete_item (struct reiserfs_transaction_handle *th,
1347 - Hans 1387 - Hans
1348*/ 1388*/
1349 1389
1350
1351/* this deletes item which never gets split */ 1390/* this deletes item which never gets split */
1352void reiserfs_delete_solid_item (struct reiserfs_transaction_handle *th, 1391void reiserfs_delete_solid_item(struct reiserfs_transaction_handle *th,
1353 struct inode *inode, 1392 struct inode *inode, struct reiserfs_key *key)
1354 struct reiserfs_key * key)
1355{ 1393{
1356 struct tree_balance tb; 1394 struct tree_balance tb;
1357 INITIALIZE_PATH (path); 1395 INITIALIZE_PATH(path);
1358 int item_len = 0; 1396 int item_len = 0;
1359 int tb_init = 0 ; 1397 int tb_init = 0;
1360 struct cpu_key cpu_key; 1398 struct cpu_key cpu_key;
1361 int retval; 1399 int retval;
1362 int quota_cut_bytes = 0; 1400 int quota_cut_bytes = 0;
1363 1401
1364 BUG_ON (!th->t_trans_id); 1402 BUG_ON(!th->t_trans_id);
1365 1403
1366 le_key2cpu_key (&cpu_key, key); 1404 le_key2cpu_key(&cpu_key, key);
1367 1405
1368 while (1) { 1406 while (1) {
1369 retval = search_item (th->t_super, &cpu_key, &path); 1407 retval = search_item(th->t_super, &cpu_key, &path);
1370 if (retval == IO_ERROR) { 1408 if (retval == IO_ERROR) {
1371 reiserfs_warning (th->t_super, 1409 reiserfs_warning(th->t_super,
1372 "vs-5350: reiserfs_delete_solid_item: " 1410 "vs-5350: reiserfs_delete_solid_item: "
1373 "i/o failure occurred trying to delete %K", 1411 "i/o failure occurred trying to delete %K",
1374 &cpu_key); 1412 &cpu_key);
1375 break; 1413 break;
1376 } 1414 }
1377 if (retval != ITEM_FOUND) { 1415 if (retval != ITEM_FOUND) {
1378 pathrelse (&path); 1416 pathrelse(&path);
1379 // No need for a warning, if there is just no free space to insert '..' item into the newly-created subdir 1417 // No need for a warning, if there is just no free space to insert '..' item into the newly-created subdir
1380 if ( !( (unsigned long long) GET_HASH_VALUE (le_key_k_offset (le_key_version (key), key)) == 0 && \ 1418 if (!
1381 (unsigned long long) GET_GENERATION_NUMBER (le_key_k_offset (le_key_version (key), key)) == 1 ) ) 1419 ((unsigned long long)
1382 reiserfs_warning (th->t_super, "vs-5355: reiserfs_delete_solid_item: %k not found", key); 1420 GET_HASH_VALUE(le_key_k_offset
1383 break; 1421 (le_key_version(key), key)) == 0
1384 } 1422 && (unsigned long long)
1385 if (!tb_init) { 1423 GET_GENERATION_NUMBER(le_key_k_offset
1386 tb_init = 1 ; 1424 (le_key_version(key),
1387 item_len = ih_item_len( PATH_PITEM_HEAD(&path) ); 1425 key)) == 1))
1388 init_tb_struct (th, &tb, th->t_super, &path, - (IH_SIZE + item_len)); 1426 reiserfs_warning(th->t_super,
1389 } 1427 "vs-5355: reiserfs_delete_solid_item: %k not found",
1390 quota_cut_bytes = ih_item_len(PATH_PITEM_HEAD(&path)) ; 1428 key);
1429 break;
1430 }
1431 if (!tb_init) {
1432 tb_init = 1;
1433 item_len = ih_item_len(PATH_PITEM_HEAD(&path));
1434 init_tb_struct(th, &tb, th->t_super, &path,
1435 -(IH_SIZE + item_len));
1436 }
1437 quota_cut_bytes = ih_item_len(PATH_PITEM_HEAD(&path));
1391 1438
1392 retval = fix_nodes (M_DELETE, &tb, NULL, NULL); 1439 retval = fix_nodes(M_DELETE, &tb, NULL, NULL);
1393 if (retval == REPEAT_SEARCH) { 1440 if (retval == REPEAT_SEARCH) {
1394 PROC_INFO_INC( th -> t_super, delete_solid_item_restarted ); 1441 PROC_INFO_INC(th->t_super, delete_solid_item_restarted);
1395 continue; 1442 continue;
1396 } 1443 }
1397 1444
1398 if (retval == CARRY_ON) { 1445 if (retval == CARRY_ON) {
1399 do_balance (&tb, NULL, NULL, M_DELETE); 1446 do_balance(&tb, NULL, NULL, M_DELETE);
1400 if (inode) { /* Should we count quota for item? (we don't count quotas for save-links) */ 1447 if (inode) { /* Should we count quota for item? (we don't count quotas for save-links) */
1401#ifdef REISERQUOTA_DEBUG 1448#ifdef REISERQUOTA_DEBUG
1402 reiserfs_debug (th->t_super, REISERFS_DEBUG_CODE, "reiserquota delete_solid_item(): freeing %u id=%u type=%c", quota_cut_bytes, inode->i_uid, key2type(key)); 1449 reiserfs_debug(th->t_super, REISERFS_DEBUG_CODE,
1450 "reiserquota delete_solid_item(): freeing %u id=%u type=%c",
1451 quota_cut_bytes, inode->i_uid,
1452 key2type(key));
1403#endif 1453#endif
1404 DQUOT_FREE_SPACE_NODIRTY(inode, quota_cut_bytes); 1454 DQUOT_FREE_SPACE_NODIRTY(inode,
1405 } 1455 quota_cut_bytes);
1406 break; 1456 }
1457 break;
1458 }
1459 // IO_ERROR, NO_DISK_SPACE, etc
1460 reiserfs_warning(th->t_super,
1461 "vs-5360: reiserfs_delete_solid_item: "
1462 "could not delete %K due to fix_nodes failure",
1463 &cpu_key);
1464 unfix_nodes(&tb);
1465 break;
1407 } 1466 }
1408 1467
1409 // IO_ERROR, NO_DISK_SPACE, etc 1468 reiserfs_check_path(&path);
1410 reiserfs_warning (th->t_super, "vs-5360: reiserfs_delete_solid_item: "
1411 "could not delete %K due to fix_nodes failure", &cpu_key);
1412 unfix_nodes (&tb);
1413 break;
1414 }
1415
1416 reiserfs_check_path(&path) ;
1417} 1469}
1418 1470
1419 1471int reiserfs_delete_object(struct reiserfs_transaction_handle *th,
1420int reiserfs_delete_object (struct reiserfs_transaction_handle *th, struct inode * inode) 1472 struct inode *inode)
1421{ 1473{
1422 int err; 1474 int err;
1423 inode->i_size = 0; 1475 inode->i_size = 0;
1424 BUG_ON (!th->t_trans_id); 1476 BUG_ON(!th->t_trans_id);
1425 1477
1426 /* for directory this deletes item containing "." and ".." */ 1478 /* for directory this deletes item containing "." and ".." */
1427 err = reiserfs_do_truncate (th, inode, NULL, 0/*no timestamp updates*/); 1479 err =
1428 if (err) 1480 reiserfs_do_truncate(th, inode, NULL, 0 /*no timestamp updates */ );
1429 return err; 1481 if (err)
1430 1482 return err;
1483
1431#if defined( USE_INODE_GENERATION_COUNTER ) 1484#if defined( USE_INODE_GENERATION_COUNTER )
1432 if( !old_format_only ( th -> t_super ) ) 1485 if (!old_format_only(th->t_super)) {
1433 { 1486 __le32 *inode_generation;
1434 __le32 *inode_generation; 1487
1435 1488 inode_generation =
1436 inode_generation = 1489 &REISERFS_SB(th->t_super)->s_rs->s_inode_generation;
1437 &REISERFS_SB(th -> t_super) -> s_rs -> s_inode_generation; 1490 *inode_generation =
1438 *inode_generation = cpu_to_le32( le32_to_cpu( *inode_generation ) + 1 ); 1491 cpu_to_le32(le32_to_cpu(*inode_generation) + 1);
1439 } 1492 }
1440/* USE_INODE_GENERATION_COUNTER */ 1493/* USE_INODE_GENERATION_COUNTER */
1441#endif 1494#endif
1442 reiserfs_delete_solid_item (th, inode, INODE_PKEY (inode)); 1495 reiserfs_delete_solid_item(th, inode, INODE_PKEY(inode));
1443 1496
1444 return err; 1497 return err;
1445} 1498}
1446 1499
1447static void 1500static void unmap_buffers(struct page *page, loff_t pos)
1448unmap_buffers(struct page *page, loff_t pos) { 1501{
1449 struct buffer_head *bh ; 1502 struct buffer_head *bh;
1450 struct buffer_head *head ; 1503 struct buffer_head *head;
1451 struct buffer_head *next ; 1504 struct buffer_head *next;
1452 unsigned long tail_index ; 1505 unsigned long tail_index;
1453 unsigned long cur_index ; 1506 unsigned long cur_index;
1454 1507
1455 if (page) { 1508 if (page) {
1456 if (page_has_buffers(page)) { 1509 if (page_has_buffers(page)) {
1457 tail_index = pos & (PAGE_CACHE_SIZE - 1) ; 1510 tail_index = pos & (PAGE_CACHE_SIZE - 1);
1458 cur_index = 0 ; 1511 cur_index = 0;
1459 head = page_buffers(page) ; 1512 head = page_buffers(page);
1460 bh = head ; 1513 bh = head;
1461 do { 1514 do {
1462 next = bh->b_this_page ; 1515 next = bh->b_this_page;
1463 1516
1464 /* we want to unmap the buffers that contain the tail, and 1517 /* we want to unmap the buffers that contain the tail, and
1465 ** all the buffers after it (since the tail must be at the 1518 ** all the buffers after it (since the tail must be at the
1466 ** end of the file). We don't want to unmap file data 1519 ** end of the file). We don't want to unmap file data
1467 ** before the tail, since it might be dirty and waiting to 1520 ** before the tail, since it might be dirty and waiting to
1468 ** reach disk 1521 ** reach disk
1469 */ 1522 */
1470 cur_index += bh->b_size ; 1523 cur_index += bh->b_size;
1471 if (cur_index > tail_index) { 1524 if (cur_index > tail_index) {
1472 reiserfs_unmap_buffer(bh) ; 1525 reiserfs_unmap_buffer(bh);
1526 }
1527 bh = next;
1528 } while (bh != head);
1529 if (PAGE_SIZE == bh->b_size) {
1530 clear_page_dirty(page);
1531 }
1473 } 1532 }
1474 bh = next ;
1475 } while (bh != head) ;
1476 if ( PAGE_SIZE == bh->b_size ) {
1477 clear_page_dirty(page);
1478 }
1479 } 1533 }
1480 }
1481} 1534}
1482 1535
1483static int maybe_indirect_to_direct (struct reiserfs_transaction_handle *th, 1536static int maybe_indirect_to_direct(struct reiserfs_transaction_handle *th,
1484 struct inode * p_s_inode, 1537 struct inode *p_s_inode,
1485 struct page *page, 1538 struct page *page,
1486 struct path * p_s_path, 1539 struct path *p_s_path,
1487 const struct cpu_key * p_s_item_key, 1540 const struct cpu_key *p_s_item_key,
1488 loff_t n_new_file_size, 1541 loff_t n_new_file_size, char *p_c_mode)
1489 char * p_c_mode 1542{
1490 ) { 1543 struct super_block *p_s_sb = p_s_inode->i_sb;
1491 struct super_block * p_s_sb = p_s_inode->i_sb; 1544 int n_block_size = p_s_sb->s_blocksize;
1492 int n_block_size = p_s_sb->s_blocksize; 1545 int cut_bytes;
1493 int cut_bytes; 1546 BUG_ON(!th->t_trans_id);
1494 BUG_ON (!th->t_trans_id); 1547
1495 1548 if (n_new_file_size != p_s_inode->i_size)
1496 if (n_new_file_size != p_s_inode->i_size) 1549 BUG();
1497 BUG ();
1498
1499 /* the page being sent in could be NULL if there was an i/o error
1500 ** reading in the last block. The user will hit problems trying to
1501 ** read the file, but for now we just skip the indirect2direct
1502 */
1503 if (atomic_read(&p_s_inode->i_count) > 1 ||
1504 !tail_has_to_be_packed (p_s_inode) ||
1505 !page || (REISERFS_I(p_s_inode)->i_flags & i_nopack_mask)) {
1506 // leave tail in an unformatted node
1507 *p_c_mode = M_SKIP_BALANCING;
1508 cut_bytes = n_block_size - (n_new_file_size & (n_block_size - 1));
1509 pathrelse(p_s_path);
1510 return cut_bytes;
1511 }
1512 /* Permorm the conversion to a direct_item. */
1513 /*return indirect_to_direct (p_s_inode, p_s_path, p_s_item_key, n_new_file_size, p_c_mode);*/
1514 return indirect2direct (th, p_s_inode, page, p_s_path, p_s_item_key, n_new_file_size, p_c_mode);
1515}
1516 1550
1551 /* the page being sent in could be NULL if there was an i/o error
1552 ** reading in the last block. The user will hit problems trying to
1553 ** read the file, but for now we just skip the indirect2direct
1554 */
1555 if (atomic_read(&p_s_inode->i_count) > 1 ||
1556 !tail_has_to_be_packed(p_s_inode) ||
1557 !page || (REISERFS_I(p_s_inode)->i_flags & i_nopack_mask)) {
1558 // leave tail in an unformatted node
1559 *p_c_mode = M_SKIP_BALANCING;
1560 cut_bytes =
1561 n_block_size - (n_new_file_size & (n_block_size - 1));
1562 pathrelse(p_s_path);
1563 return cut_bytes;
1564 }
1565 /* Permorm the conversion to a direct_item. */
1566 /*return indirect_to_direct (p_s_inode, p_s_path, p_s_item_key, n_new_file_size, p_c_mode); */
1567 return indirect2direct(th, p_s_inode, page, p_s_path, p_s_item_key,
1568 n_new_file_size, p_c_mode);
1569}
1517 1570
1518/* we did indirect_to_direct conversion. And we have inserted direct 1571/* we did indirect_to_direct conversion. And we have inserted direct
1519 item successesfully, but there were no disk space to cut unfm 1572 item successesfully, but there were no disk space to cut unfm
1520 pointer being converted. Therefore we have to delete inserted 1573 pointer being converted. Therefore we have to delete inserted
1521 direct item(s) */ 1574 direct item(s) */
1522static void indirect_to_direct_roll_back (struct reiserfs_transaction_handle *th, struct inode * inode, struct path * path) 1575static void indirect_to_direct_roll_back(struct reiserfs_transaction_handle *th,
1576 struct inode *inode, struct path *path)
1523{ 1577{
1524 struct cpu_key tail_key; 1578 struct cpu_key tail_key;
1525 int tail_len; 1579 int tail_len;
1526 int removed; 1580 int removed;
1527 BUG_ON (!th->t_trans_id); 1581 BUG_ON(!th->t_trans_id);
1528 1582
1529 make_cpu_key (&tail_key, inode, inode->i_size + 1, TYPE_DIRECT, 4);// !!!! 1583 make_cpu_key(&tail_key, inode, inode->i_size + 1, TYPE_DIRECT, 4); // !!!!
1530 tail_key.key_length = 4; 1584 tail_key.key_length = 4;
1531 1585
1532 tail_len = (cpu_key_k_offset (&tail_key) & (inode->i_sb->s_blocksize - 1)) - 1; 1586 tail_len =
1533 while (tail_len) { 1587 (cpu_key_k_offset(&tail_key) & (inode->i_sb->s_blocksize - 1)) - 1;
1534 /* look for the last byte of the tail */ 1588 while (tail_len) {
1535 if (search_for_position_by_key (inode->i_sb, &tail_key, path) == POSITION_NOT_FOUND) 1589 /* look for the last byte of the tail */
1536 reiserfs_panic (inode->i_sb, "vs-5615: indirect_to_direct_roll_back: found invalid item"); 1590 if (search_for_position_by_key(inode->i_sb, &tail_key, path) ==
1537 RFALSE( path->pos_in_item != ih_item_len(PATH_PITEM_HEAD (path)) - 1, 1591 POSITION_NOT_FOUND)
1538 "vs-5616: appended bytes found"); 1592 reiserfs_panic(inode->i_sb,
1539 PATH_LAST_POSITION (path) --; 1593 "vs-5615: indirect_to_direct_roll_back: found invalid item");
1540 1594 RFALSE(path->pos_in_item !=
1541 removed = reiserfs_delete_item (th, path, &tail_key, inode, NULL/*unbh not needed*/); 1595 ih_item_len(PATH_PITEM_HEAD(path)) - 1,
1542 RFALSE( removed <= 0 || removed > tail_len, 1596 "vs-5616: appended bytes found");
1543 "vs-5617: there was tail %d bytes, removed item length %d bytes", 1597 PATH_LAST_POSITION(path)--;
1544 tail_len, removed); 1598
1545 tail_len -= removed; 1599 removed =
1546 set_cpu_key_k_offset (&tail_key, cpu_key_k_offset (&tail_key) - removed); 1600 reiserfs_delete_item(th, path, &tail_key, inode,
1547 } 1601 NULL /*unbh not needed */ );
1548 reiserfs_warning (inode->i_sb, "indirect_to_direct_roll_back: indirect_to_direct conversion has been rolled back due to lack of disk space"); 1602 RFALSE(removed <= 0
1549 //mark_file_without_tail (inode); 1603 || removed > tail_len,
1550 mark_inode_dirty (inode); 1604 "vs-5617: there was tail %d bytes, removed item length %d bytes",
1605 tail_len, removed);
1606 tail_len -= removed;
1607 set_cpu_key_k_offset(&tail_key,
1608 cpu_key_k_offset(&tail_key) - removed);
1609 }
1610 reiserfs_warning(inode->i_sb,
1611 "indirect_to_direct_roll_back: indirect_to_direct conversion has been rolled back due to lack of disk space");
1612 //mark_file_without_tail (inode);
1613 mark_inode_dirty(inode);
1551} 1614}
1552 1615
1553
1554/* (Truncate or cut entry) or delete object item. Returns < 0 on failure */ 1616/* (Truncate or cut entry) or delete object item. Returns < 0 on failure */
1555int reiserfs_cut_from_item (struct reiserfs_transaction_handle *th, 1617int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
1556 struct path * p_s_path, 1618 struct path *p_s_path,
1557 struct cpu_key * p_s_item_key, 1619 struct cpu_key *p_s_item_key,
1558 struct inode * p_s_inode, 1620 struct inode *p_s_inode,
1559 struct page *page, 1621 struct page *page, loff_t n_new_file_size)
1560 loff_t n_new_file_size)
1561{ 1622{
1562 struct super_block * p_s_sb = p_s_inode->i_sb; 1623 struct super_block *p_s_sb = p_s_inode->i_sb;
1563 /* Every function which is going to call do_balance must first 1624 /* Every function which is going to call do_balance must first
1564 create a tree_balance structure. Then it must fill up this 1625 create a tree_balance structure. Then it must fill up this
1565 structure by using the init_tb_struct and fix_nodes functions. 1626 structure by using the init_tb_struct and fix_nodes functions.
1566 After that we can make tree balancing. */ 1627 After that we can make tree balancing. */
1567 struct tree_balance s_cut_balance; 1628 struct tree_balance s_cut_balance;
1568 struct item_head *p_le_ih; 1629 struct item_head *p_le_ih;
1569 int n_cut_size = 0, /* Amount to be cut. */ 1630 int n_cut_size = 0, /* Amount to be cut. */
1570 n_ret_value = CARRY_ON, 1631 n_ret_value = CARRY_ON, n_removed = 0, /* Number of the removed unformatted nodes. */
1571 n_removed = 0, /* Number of the removed unformatted nodes. */ 1632 n_is_inode_locked = 0;
1572 n_is_inode_locked = 0; 1633 char c_mode; /* Mode of the balance. */
1573 char c_mode; /* Mode of the balance. */ 1634 int retval2 = -1;
1574 int retval2 = -1; 1635 int quota_cut_bytes;
1575 int quota_cut_bytes; 1636 loff_t tail_pos = 0;
1576 loff_t tail_pos = 0; 1637
1577 1638 BUG_ON(!th->t_trans_id);
1578 BUG_ON (!th->t_trans_id); 1639
1579 1640 init_tb_struct(th, &s_cut_balance, p_s_inode->i_sb, p_s_path,
1580 init_tb_struct(th, &s_cut_balance, p_s_inode->i_sb, p_s_path, n_cut_size); 1641 n_cut_size);
1581 1642
1582 1643 /* Repeat this loop until we either cut the item without needing
1583 /* Repeat this loop until we either cut the item without needing 1644 to balance, or we fix_nodes without schedule occurring */
1584 to balance, or we fix_nodes without schedule occurring */ 1645 while (1) {
1585 while ( 1 ) { 1646 /* Determine the balance mode, position of the first byte to
1586 /* Determine the balance mode, position of the first byte to 1647 be cut, and size to be cut. In case of the indirect item
1587 be cut, and size to be cut. In case of the indirect item 1648 free unformatted nodes which are pointed to by the cut
1588 free unformatted nodes which are pointed to by the cut 1649 pointers. */
1589 pointers. */ 1650
1590 1651 c_mode =
1591 c_mode = prepare_for_delete_or_cut(th, p_s_inode, p_s_path, p_s_item_key, &n_removed, 1652 prepare_for_delete_or_cut(th, p_s_inode, p_s_path,
1592 &n_cut_size, n_new_file_size); 1653 p_s_item_key, &n_removed,
1593 if ( c_mode == M_CONVERT ) { 1654 &n_cut_size, n_new_file_size);
1594 /* convert last unformatted node to direct item or leave 1655 if (c_mode == M_CONVERT) {
1595 tail in the unformatted node */ 1656 /* convert last unformatted node to direct item or leave
1596 RFALSE( n_ret_value != CARRY_ON, "PAP-5570: can not convert twice"); 1657 tail in the unformatted node */
1597 1658 RFALSE(n_ret_value != CARRY_ON,
1598 n_ret_value = maybe_indirect_to_direct (th, p_s_inode, page, p_s_path, p_s_item_key, 1659 "PAP-5570: can not convert twice");
1599 n_new_file_size, &c_mode); 1660
1600 if ( c_mode == M_SKIP_BALANCING ) 1661 n_ret_value =
1601 /* tail has been left in the unformatted node */ 1662 maybe_indirect_to_direct(th, p_s_inode, page,
1602 return n_ret_value; 1663 p_s_path, p_s_item_key,
1603 1664 n_new_file_size, &c_mode);
1604 n_is_inode_locked = 1; 1665 if (c_mode == M_SKIP_BALANCING)
1605 1666 /* tail has been left in the unformatted node */
1606 /* removing of last unformatted node will change value we 1667 return n_ret_value;
1607 have to return to truncate. Save it */ 1668
1608 retval2 = n_ret_value; 1669 n_is_inode_locked = 1;
1609 /*retval2 = p_s_sb->s_blocksize - (n_new_file_size & (p_s_sb->s_blocksize - 1));*/ 1670
1610 1671 /* removing of last unformatted node will change value we
1611 /* So, we have performed the first part of the conversion: 1672 have to return to truncate. Save it */
1612 inserting the new direct item. Now we are removing the 1673 retval2 = n_ret_value;
1613 last unformatted node pointer. Set key to search for 1674 /*retval2 = p_s_sb->s_blocksize - (n_new_file_size & (p_s_sb->s_blocksize - 1)); */
1614 it. */ 1675
1615 set_cpu_key_k_type (p_s_item_key, TYPE_INDIRECT); 1676 /* So, we have performed the first part of the conversion:
1616 p_s_item_key->key_length = 4; 1677 inserting the new direct item. Now we are removing the
1617 n_new_file_size -= (n_new_file_size & (p_s_sb->s_blocksize - 1)); 1678 last unformatted node pointer. Set key to search for
1618 tail_pos = n_new_file_size; 1679 it. */
1619 set_cpu_key_k_offset (p_s_item_key, n_new_file_size + 1); 1680 set_cpu_key_k_type(p_s_item_key, TYPE_INDIRECT);
1620 if ( search_for_position_by_key(p_s_sb, p_s_item_key, p_s_path) == POSITION_NOT_FOUND ){ 1681 p_s_item_key->key_length = 4;
1621 print_block (PATH_PLAST_BUFFER (p_s_path), 3, PATH_LAST_POSITION (p_s_path) - 1, PATH_LAST_POSITION (p_s_path) + 1); 1682 n_new_file_size -=
1622 reiserfs_panic(p_s_sb, "PAP-5580: reiserfs_cut_from_item: item to convert does not exist (%K)", p_s_item_key); 1683 (n_new_file_size & (p_s_sb->s_blocksize - 1));
1623 } 1684 tail_pos = n_new_file_size;
1624 continue; 1685 set_cpu_key_k_offset(p_s_item_key, n_new_file_size + 1);
1625 } 1686 if (search_for_position_by_key
1626 if (n_cut_size == 0) { 1687 (p_s_sb, p_s_item_key,
1627 pathrelse (p_s_path); 1688 p_s_path) == POSITION_NOT_FOUND) {
1628 return 0; 1689 print_block(PATH_PLAST_BUFFER(p_s_path), 3,
1629 } 1690 PATH_LAST_POSITION(p_s_path) - 1,
1691 PATH_LAST_POSITION(p_s_path) + 1);
1692 reiserfs_panic(p_s_sb,
1693 "PAP-5580: reiserfs_cut_from_item: item to convert does not exist (%K)",
1694 p_s_item_key);
1695 }
1696 continue;
1697 }
1698 if (n_cut_size == 0) {
1699 pathrelse(p_s_path);
1700 return 0;
1701 }
1702
1703 s_cut_balance.insert_size[0] = n_cut_size;
1704
1705 n_ret_value = fix_nodes(c_mode, &s_cut_balance, NULL, NULL);
1706 if (n_ret_value != REPEAT_SEARCH)
1707 break;
1708
1709 PROC_INFO_INC(p_s_sb, cut_from_item_restarted);
1710
1711 n_ret_value =
1712 search_for_position_by_key(p_s_sb, p_s_item_key, p_s_path);
1713 if (n_ret_value == POSITION_FOUND)
1714 continue;
1630 1715
1631 s_cut_balance.insert_size[0] = n_cut_size; 1716 reiserfs_warning(p_s_sb,
1632 1717 "PAP-5610: reiserfs_cut_from_item: item %K not found",
1633 n_ret_value = fix_nodes(c_mode, &s_cut_balance, NULL, NULL); 1718 p_s_item_key);
1634 if ( n_ret_value != REPEAT_SEARCH ) 1719 unfix_nodes(&s_cut_balance);
1635 break; 1720 return (n_ret_value == IO_ERROR) ? -EIO : -ENOENT;
1636 1721 } /* while */
1637 PROC_INFO_INC( p_s_sb, cut_from_item_restarted ); 1722
1638 1723 // check fix_nodes results (IO_ERROR or NO_DISK_SPACE)
1639 n_ret_value = search_for_position_by_key(p_s_sb, p_s_item_key, p_s_path); 1724 if (n_ret_value != CARRY_ON) {
1640 if (n_ret_value == POSITION_FOUND) 1725 if (n_is_inode_locked) {
1641 continue; 1726 // FIXME: this seems to be not needed: we are always able
1642 1727 // to cut item
1643 reiserfs_warning (p_s_sb, "PAP-5610: reiserfs_cut_from_item: item %K not found", p_s_item_key); 1728 indirect_to_direct_roll_back(th, p_s_inode, p_s_path);
1644 unfix_nodes (&s_cut_balance); 1729 }
1645 return (n_ret_value == IO_ERROR) ? -EIO : -ENOENT; 1730 if (n_ret_value == NO_DISK_SPACE)
1646 } /* while */ 1731 reiserfs_warning(p_s_sb, "NO_DISK_SPACE");
1647 1732 unfix_nodes(&s_cut_balance);
1648 // check fix_nodes results (IO_ERROR or NO_DISK_SPACE) 1733 return -EIO;
1649 if ( n_ret_value != CARRY_ON ) {
1650 if ( n_is_inode_locked ) {
1651 // FIXME: this seems to be not needed: we are always able
1652 // to cut item
1653 indirect_to_direct_roll_back (th, p_s_inode, p_s_path);
1654 } 1734 }
1655 if (n_ret_value == NO_DISK_SPACE) 1735
1656 reiserfs_warning (p_s_sb, "NO_DISK_SPACE"); 1736 /* go ahead and perform balancing */
1657 unfix_nodes (&s_cut_balance); 1737
1658 return -EIO; 1738 RFALSE(c_mode == M_PASTE || c_mode == M_INSERT, "invalid mode");
1659 } 1739
1660 1740 /* Calculate number of bytes that need to be cut from the item. */
1661 /* go ahead and perform balancing */ 1741 quota_cut_bytes =
1662 1742 (c_mode ==
1663 RFALSE( c_mode == M_PASTE || c_mode == M_INSERT, "invalid mode"); 1743 M_DELETE) ? ih_item_len(get_ih(p_s_path)) : -s_cut_balance.
1664 1744 insert_size[0];
1665 /* Calculate number of bytes that need to be cut from the item. */ 1745 if (retval2 == -1)
1666 quota_cut_bytes = ( c_mode == M_DELETE ) ? ih_item_len(get_ih(p_s_path)) : -s_cut_balance.insert_size[0]; 1746 n_ret_value = calc_deleted_bytes_number(&s_cut_balance, c_mode);
1667 if (retval2 == -1) 1747 else
1668 n_ret_value = calc_deleted_bytes_number(&s_cut_balance, c_mode); 1748 n_ret_value = retval2;
1669 else 1749
1670 n_ret_value = retval2; 1750 /* For direct items, we only change the quota when deleting the last
1671 1751 ** item.
1672 1752 */
1673 /* For direct items, we only change the quota when deleting the last 1753 p_le_ih = PATH_PITEM_HEAD(s_cut_balance.tb_path);
1674 ** item. 1754 if (!S_ISLNK(p_s_inode->i_mode) && is_direct_le_ih(p_le_ih)) {
1675 */ 1755 if (c_mode == M_DELETE &&
1676 p_le_ih = PATH_PITEM_HEAD (s_cut_balance.tb_path); 1756 (le_ih_k_offset(p_le_ih) & (p_s_sb->s_blocksize - 1)) ==
1677 if (!S_ISLNK (p_s_inode->i_mode) && is_direct_le_ih(p_le_ih)) { 1757 1) {
1678 if (c_mode == M_DELETE && 1758 // FIXME: this is to keep 3.5 happy
1679 (le_ih_k_offset (p_le_ih) & (p_s_sb->s_blocksize - 1)) == 1 ) { 1759 REISERFS_I(p_s_inode)->i_first_direct_byte = U32_MAX;
1680 // FIXME: this is to keep 3.5 happy 1760 quota_cut_bytes = p_s_sb->s_blocksize + UNFM_P_SIZE;
1681 REISERFS_I(p_s_inode)->i_first_direct_byte = U32_MAX; 1761 } else {
1682 quota_cut_bytes = p_s_sb->s_blocksize + UNFM_P_SIZE ; 1762 quota_cut_bytes = 0;
1683 } else { 1763 }
1684 quota_cut_bytes = 0 ;
1685 } 1764 }
1686 }
1687#ifdef CONFIG_REISERFS_CHECK 1765#ifdef CONFIG_REISERFS_CHECK
1688 if (n_is_inode_locked) { 1766 if (n_is_inode_locked) {
1689 struct item_head * le_ih = PATH_PITEM_HEAD (s_cut_balance.tb_path); 1767 struct item_head *le_ih =
1690 /* we are going to complete indirect2direct conversion. Make 1768 PATH_PITEM_HEAD(s_cut_balance.tb_path);
1691 sure, that we exactly remove last unformatted node pointer 1769 /* we are going to complete indirect2direct conversion. Make
1692 of the item */ 1770 sure, that we exactly remove last unformatted node pointer
1693 if (!is_indirect_le_ih (le_ih)) 1771 of the item */
1694 reiserfs_panic (p_s_sb, "vs-5652: reiserfs_cut_from_item: " 1772 if (!is_indirect_le_ih(le_ih))
1695 "item must be indirect %h", le_ih); 1773 reiserfs_panic(p_s_sb,
1696 1774 "vs-5652: reiserfs_cut_from_item: "
1697 if (c_mode == M_DELETE && ih_item_len(le_ih) != UNFM_P_SIZE) 1775 "item must be indirect %h", le_ih);
1698 reiserfs_panic (p_s_sb, "vs-5653: reiserfs_cut_from_item: " 1776
1699 "completing indirect2direct conversion indirect item %h " 1777 if (c_mode == M_DELETE && ih_item_len(le_ih) != UNFM_P_SIZE)
1700 "being deleted must be of 4 byte long", le_ih); 1778 reiserfs_panic(p_s_sb,
1701 1779 "vs-5653: reiserfs_cut_from_item: "
1702 if (c_mode == M_CUT && s_cut_balance.insert_size[0] != -UNFM_P_SIZE) { 1780 "completing indirect2direct conversion indirect item %h "
1703 reiserfs_panic (p_s_sb, "vs-5654: reiserfs_cut_from_item: " 1781 "being deleted must be of 4 byte long",
1704 "can not complete indirect2direct conversion of %h (CUT, insert_size==%d)", 1782 le_ih);
1705 le_ih, s_cut_balance.insert_size[0]); 1783
1784 if (c_mode == M_CUT
1785 && s_cut_balance.insert_size[0] != -UNFM_P_SIZE) {
1786 reiserfs_panic(p_s_sb,
1787 "vs-5654: reiserfs_cut_from_item: "
1788 "can not complete indirect2direct conversion of %h (CUT, insert_size==%d)",
1789 le_ih, s_cut_balance.insert_size[0]);
1790 }
1791 /* it would be useful to make sure, that right neighboring
1792 item is direct item of this file */
1706 } 1793 }
1707 /* it would be useful to make sure, that right neighboring
1708 item is direct item of this file */
1709 }
1710#endif 1794#endif
1711 1795
1712 do_balance(&s_cut_balance, NULL, NULL, c_mode); 1796 do_balance(&s_cut_balance, NULL, NULL, c_mode);
1713 if ( n_is_inode_locked ) { 1797 if (n_is_inode_locked) {
1714 /* we've done an indirect->direct conversion. when the data block 1798 /* we've done an indirect->direct conversion. when the data block
1715 ** was freed, it was removed from the list of blocks that must 1799 ** was freed, it was removed from the list of blocks that must
1716 ** be flushed before the transaction commits, make sure to 1800 ** be flushed before the transaction commits, make sure to
1717 ** unmap and invalidate it 1801 ** unmap and invalidate it
1718 */ 1802 */
1719 unmap_buffers(page, tail_pos); 1803 unmap_buffers(page, tail_pos);
1720 REISERFS_I(p_s_inode)->i_flags &= ~i_pack_on_close_mask ; 1804 REISERFS_I(p_s_inode)->i_flags &= ~i_pack_on_close_mask;
1721 } 1805 }
1722#ifdef REISERQUOTA_DEBUG 1806#ifdef REISERQUOTA_DEBUG
1723 reiserfs_debug (p_s_inode->i_sb, REISERFS_DEBUG_CODE, "reiserquota cut_from_item(): freeing %u id=%u type=%c", quota_cut_bytes, p_s_inode->i_uid, '?'); 1807 reiserfs_debug(p_s_inode->i_sb, REISERFS_DEBUG_CODE,
1808 "reiserquota cut_from_item(): freeing %u id=%u type=%c",
1809 quota_cut_bytes, p_s_inode->i_uid, '?');
1724#endif 1810#endif
1725 DQUOT_FREE_SPACE_NODIRTY(p_s_inode, quota_cut_bytes); 1811 DQUOT_FREE_SPACE_NODIRTY(p_s_inode, quota_cut_bytes);
1726 return n_ret_value; 1812 return n_ret_value;
1727} 1813}
1728 1814
1729static void truncate_directory (struct reiserfs_transaction_handle *th, struct inode * inode) 1815static void truncate_directory(struct reiserfs_transaction_handle *th,
1816 struct inode *inode)
1730{ 1817{
1731 BUG_ON (!th->t_trans_id); 1818 BUG_ON(!th->t_trans_id);
1732 if (inode->i_nlink) 1819 if (inode->i_nlink)
1733 reiserfs_warning (inode->i_sb, 1820 reiserfs_warning(inode->i_sb,
1734 "vs-5655: truncate_directory: link count != 0"); 1821 "vs-5655: truncate_directory: link count != 0");
1735 1822
1736 set_le_key_k_offset (KEY_FORMAT_3_5, INODE_PKEY (inode), DOT_OFFSET); 1823 set_le_key_k_offset(KEY_FORMAT_3_5, INODE_PKEY(inode), DOT_OFFSET);
1737 set_le_key_k_type (KEY_FORMAT_3_5, INODE_PKEY (inode), TYPE_DIRENTRY); 1824 set_le_key_k_type(KEY_FORMAT_3_5, INODE_PKEY(inode), TYPE_DIRENTRY);
1738 reiserfs_delete_solid_item (th, inode, INODE_PKEY (inode)); 1825 reiserfs_delete_solid_item(th, inode, INODE_PKEY(inode));
1739 reiserfs_update_sd(th, inode) ; 1826 reiserfs_update_sd(th, inode);
1740 set_le_key_k_offset (KEY_FORMAT_3_5, INODE_PKEY (inode), SD_OFFSET); 1827 set_le_key_k_offset(KEY_FORMAT_3_5, INODE_PKEY(inode), SD_OFFSET);
1741 set_le_key_k_type (KEY_FORMAT_3_5, INODE_PKEY (inode), TYPE_STAT_DATA); 1828 set_le_key_k_type(KEY_FORMAT_3_5, INODE_PKEY(inode), TYPE_STAT_DATA);
1742} 1829}
1743 1830
1831/* Truncate file to the new size. Note, this must be called with a transaction
1832 already started */
1833int reiserfs_do_truncate(struct reiserfs_transaction_handle *th, struct inode *p_s_inode, /* ->i_size contains new
1834 size */
1835 struct page *page, /* up to date for last block */
1836 int update_timestamps /* when it is called by
1837 file_release to convert
1838 the tail - no timestamps
1839 should be updated */
1840 )
1841{
1842 INITIALIZE_PATH(s_search_path); /* Path to the current object item. */
1843 struct item_head *p_le_ih; /* Pointer to an item header. */
1844 struct cpu_key s_item_key; /* Key to search for a previous file item. */
1845 loff_t n_file_size, /* Old file size. */
1846 n_new_file_size; /* New file size. */
1847 int n_deleted; /* Number of deleted or truncated bytes. */
1848 int retval;
1849 int err = 0;
1850
1851 BUG_ON(!th->t_trans_id);
1852 if (!
1853 (S_ISREG(p_s_inode->i_mode) || S_ISDIR(p_s_inode->i_mode)
1854 || S_ISLNK(p_s_inode->i_mode)))
1855 return 0;
1856
1857 if (S_ISDIR(p_s_inode->i_mode)) {
1858 // deletion of directory - no need to update timestamps
1859 truncate_directory(th, p_s_inode);
1860 return 0;
1861 }
1744 1862
1863 /* Get new file size. */
1864 n_new_file_size = p_s_inode->i_size;
1745 1865
1866 // FIXME: note, that key type is unimportant here
1867 make_cpu_key(&s_item_key, p_s_inode, max_reiserfs_offset(p_s_inode),
1868 TYPE_DIRECT, 3);
1746 1869
1747/* Truncate file to the new size. Note, this must be called with a transaction 1870 retval =
1748 already started */ 1871 search_for_position_by_key(p_s_inode->i_sb, &s_item_key,
1749int reiserfs_do_truncate (struct reiserfs_transaction_handle *th, 1872 &s_search_path);
1750 struct inode * p_s_inode, /* ->i_size contains new 1873 if (retval == IO_ERROR) {
1751 size */ 1874 reiserfs_warning(p_s_inode->i_sb,
1752 struct page *page, /* up to date for last block */ 1875 "vs-5657: reiserfs_do_truncate: "
1753 int update_timestamps /* when it is called by 1876 "i/o failure occurred trying to truncate %K",
1754 file_release to convert 1877 &s_item_key);
1755 the tail - no timestamps 1878 err = -EIO;
1756 should be updated */ 1879 goto out;
1757 ) { 1880 }
1758 INITIALIZE_PATH (s_search_path); /* Path to the current object item. */ 1881 if (retval == POSITION_FOUND || retval == FILE_NOT_FOUND) {
1759 struct item_head * p_le_ih; /* Pointer to an item header. */ 1882 reiserfs_warning(p_s_inode->i_sb,
1760 struct cpu_key s_item_key; /* Key to search for a previous file item. */ 1883 "PAP-5660: reiserfs_do_truncate: "
1761 loff_t n_file_size, /* Old file size. */ 1884 "wrong result %d of search for %K", retval,
1762 n_new_file_size;/* New file size. */ 1885 &s_item_key);
1763 int n_deleted; /* Number of deleted or truncated bytes. */ 1886
1764 int retval; 1887 err = -EIO;
1765 int err = 0; 1888 goto out;
1766 1889 }
1767 BUG_ON (!th->t_trans_id);
1768 if ( ! (S_ISREG(p_s_inode->i_mode) || S_ISDIR(p_s_inode->i_mode) || S_ISLNK(p_s_inode->i_mode)) )
1769 return 0;
1770 1890
1771 if (S_ISDIR(p_s_inode->i_mode)) { 1891 s_search_path.pos_in_item--;
1772 // deletion of directory - no need to update timestamps 1892
1773 truncate_directory (th, p_s_inode); 1893 /* Get real file size (total length of all file items) */
1774 return 0; 1894 p_le_ih = PATH_PITEM_HEAD(&s_search_path);
1775 } 1895 if (is_statdata_le_ih(p_le_ih))
1776 1896 n_file_size = 0;
1777 /* Get new file size. */ 1897 else {
1778 n_new_file_size = p_s_inode->i_size; 1898 loff_t offset = le_ih_k_offset(p_le_ih);
1779 1899 int bytes =
1780 // FIXME: note, that key type is unimportant here 1900 op_bytes_number(p_le_ih, p_s_inode->i_sb->s_blocksize);
1781 make_cpu_key (&s_item_key, p_s_inode, max_reiserfs_offset (p_s_inode), TYPE_DIRECT, 3); 1901
1782 1902 /* this may mismatch with real file size: if last direct item
1783 retval = search_for_position_by_key(p_s_inode->i_sb, &s_item_key, &s_search_path); 1903 had no padding zeros and last unformatted node had no free
1784 if (retval == IO_ERROR) { 1904 space, this file would have this file size */
1785 reiserfs_warning (p_s_inode->i_sb, "vs-5657: reiserfs_do_truncate: " 1905 n_file_size = offset + bytes - 1;
1786 "i/o failure occurred trying to truncate %K", &s_item_key); 1906 }
1787 err = -EIO; 1907 /*
1788 goto out; 1908 * are we doing a full truncate or delete, if so
1789 } 1909 * kick in the reada code
1790 if (retval == POSITION_FOUND || retval == FILE_NOT_FOUND) { 1910 */
1791 reiserfs_warning (p_s_inode->i_sb, "PAP-5660: reiserfs_do_truncate: " 1911 if (n_new_file_size == 0)
1792 "wrong result %d of search for %K", retval, &s_item_key); 1912 s_search_path.reada = PATH_READA | PATH_READA_BACK;
1793 1913
1794 err = -EIO; 1914 if (n_file_size == 0 || n_file_size < n_new_file_size) {
1795 goto out; 1915 goto update_and_out;
1796 }
1797
1798 s_search_path.pos_in_item --;
1799
1800 /* Get real file size (total length of all file items) */
1801 p_le_ih = PATH_PITEM_HEAD(&s_search_path);
1802 if ( is_statdata_le_ih (p_le_ih) )
1803 n_file_size = 0;
1804 else {
1805 loff_t offset = le_ih_k_offset (p_le_ih);
1806 int bytes = op_bytes_number (p_le_ih,p_s_inode->i_sb->s_blocksize);
1807
1808 /* this may mismatch with real file size: if last direct item
1809 had no padding zeros and last unformatted node had no free
1810 space, this file would have this file size */
1811 n_file_size = offset + bytes - 1;
1812 }
1813 /*
1814 * are we doing a full truncate or delete, if so
1815 * kick in the reada code
1816 */
1817 if (n_new_file_size == 0)
1818 s_search_path.reada = PATH_READA | PATH_READA_BACK;
1819
1820 if ( n_file_size == 0 || n_file_size < n_new_file_size ) {
1821 goto update_and_out ;
1822 }
1823
1824 /* Update key to search for the last file item. */
1825 set_cpu_key_k_offset (&s_item_key, n_file_size);
1826
1827 do {
1828 /* Cut or delete file item. */
1829 n_deleted = reiserfs_cut_from_item(th, &s_search_path, &s_item_key, p_s_inode, page, n_new_file_size);
1830 if (n_deleted < 0) {
1831 reiserfs_warning (p_s_inode->i_sb, "vs-5665: reiserfs_do_truncate: reiserfs_cut_from_item failed");
1832 reiserfs_check_path(&s_search_path) ;
1833 return 0;
1834 } 1916 }
1835 1917
1836 RFALSE( n_deleted > n_file_size, 1918 /* Update key to search for the last file item. */
1837 "PAP-5670: reiserfs_cut_from_item: too many bytes deleted: deleted %d, file_size %lu, item_key %K", 1919 set_cpu_key_k_offset(&s_item_key, n_file_size);
1838 n_deleted, n_file_size, &s_item_key); 1920
1921 do {
1922 /* Cut or delete file item. */
1923 n_deleted =
1924 reiserfs_cut_from_item(th, &s_search_path, &s_item_key,
1925 p_s_inode, page, n_new_file_size);
1926 if (n_deleted < 0) {
1927 reiserfs_warning(p_s_inode->i_sb,
1928 "vs-5665: reiserfs_do_truncate: reiserfs_cut_from_item failed");
1929 reiserfs_check_path(&s_search_path);
1930 return 0;
1931 }
1839 1932
1840 /* Change key to search the last file item. */ 1933 RFALSE(n_deleted > n_file_size,
1841 n_file_size -= n_deleted; 1934 "PAP-5670: reiserfs_cut_from_item: too many bytes deleted: deleted %d, file_size %lu, item_key %K",
1935 n_deleted, n_file_size, &s_item_key);
1842 1936
1843 set_cpu_key_k_offset (&s_item_key, n_file_size); 1937 /* Change key to search the last file item. */
1938 n_file_size -= n_deleted;
1844 1939
1845 /* While there are bytes to truncate and previous file item is presented in the tree. */ 1940 set_cpu_key_k_offset(&s_item_key, n_file_size);
1846 1941
1847 /* 1942 /* While there are bytes to truncate and previous file item is presented in the tree. */
1848 ** This loop could take a really long time, and could log 1943
1849 ** many more blocks than a transaction can hold. So, we do a polite 1944 /*
1850 ** journal end here, and if the transaction needs ending, we make 1945 ** This loop could take a really long time, and could log
1851 ** sure the file is consistent before ending the current trans 1946 ** many more blocks than a transaction can hold. So, we do a polite
1852 ** and starting a new one 1947 ** journal end here, and if the transaction needs ending, we make
1853 */ 1948 ** sure the file is consistent before ending the current trans
1854 if (journal_transaction_should_end(th, th->t_blocks_allocated)) { 1949 ** and starting a new one
1855 int orig_len_alloc = th->t_blocks_allocated ; 1950 */
1856 decrement_counters_in_path(&s_search_path) ; 1951 if (journal_transaction_should_end(th, th->t_blocks_allocated)) {
1857 1952 int orig_len_alloc = th->t_blocks_allocated;
1858 if (update_timestamps) { 1953 decrement_counters_in_path(&s_search_path);
1859 p_s_inode->i_mtime = p_s_inode->i_ctime = CURRENT_TIME_SEC; 1954
1860 } 1955 if (update_timestamps) {
1861 reiserfs_update_sd(th, p_s_inode) ; 1956 p_s_inode->i_mtime = p_s_inode->i_ctime =
1862 1957 CURRENT_TIME_SEC;
1863 err = journal_end(th, p_s_inode->i_sb, orig_len_alloc) ; 1958 }
1864 if (err) 1959 reiserfs_update_sd(th, p_s_inode);
1865 goto out; 1960
1866 err = journal_begin (th, p_s_inode->i_sb, 1961 err = journal_end(th, p_s_inode->i_sb, orig_len_alloc);
1867 JOURNAL_PER_BALANCE_CNT * 6); 1962 if (err)
1868 if (err) 1963 goto out;
1869 goto out; 1964 err = journal_begin(th, p_s_inode->i_sb,
1870 reiserfs_update_inode_transaction(p_s_inode) ; 1965 JOURNAL_PER_BALANCE_CNT * 6);
1966 if (err)
1967 goto out;
1968 reiserfs_update_inode_transaction(p_s_inode);
1969 }
1970 } while (n_file_size > ROUND_UP(n_new_file_size) &&
1971 search_for_position_by_key(p_s_inode->i_sb, &s_item_key,
1972 &s_search_path) == POSITION_FOUND);
1973
1974 RFALSE(n_file_size > ROUND_UP(n_new_file_size),
1975 "PAP-5680: truncate did not finish: new_file_size %Ld, current %Ld, oid %d",
1976 n_new_file_size, n_file_size, s_item_key.on_disk_key.k_objectid);
1977
1978 update_and_out:
1979 if (update_timestamps) {
1980 // this is truncate, not file closing
1981 p_s_inode->i_mtime = p_s_inode->i_ctime = CURRENT_TIME_SEC;
1871 } 1982 }
1872 } while ( n_file_size > ROUND_UP (n_new_file_size) && 1983 reiserfs_update_sd(th, p_s_inode);
1873 search_for_position_by_key(p_s_inode->i_sb, &s_item_key, &s_search_path) == POSITION_FOUND ) ;
1874
1875 RFALSE( n_file_size > ROUND_UP (n_new_file_size),
1876 "PAP-5680: truncate did not finish: new_file_size %Ld, current %Ld, oid %d",
1877 n_new_file_size, n_file_size, s_item_key.on_disk_key.k_objectid);
1878
1879update_and_out:
1880 if (update_timestamps) {
1881 // this is truncate, not file closing
1882 p_s_inode->i_mtime = p_s_inode->i_ctime = CURRENT_TIME_SEC;
1883 }
1884 reiserfs_update_sd (th, p_s_inode);
1885
1886out:
1887 pathrelse(&s_search_path) ;
1888 return err;
1889}
1890 1984
1985 out:
1986 pathrelse(&s_search_path);
1987 return err;
1988}
1891 1989
1892#ifdef CONFIG_REISERFS_CHECK 1990#ifdef CONFIG_REISERFS_CHECK
1893// this makes sure, that we __append__, not overwrite or add holes 1991// this makes sure, that we __append__, not overwrite or add holes
1894static void check_research_for_paste (struct path * path, 1992static void check_research_for_paste(struct path *path,
1895 const struct cpu_key * p_s_key) 1993 const struct cpu_key *p_s_key)
1896{ 1994{
1897 struct item_head * found_ih = get_ih (path); 1995 struct item_head *found_ih = get_ih(path);
1898 1996
1899 if (is_direct_le_ih (found_ih)) { 1997 if (is_direct_le_ih(found_ih)) {
1900 if (le_ih_k_offset (found_ih) + op_bytes_number (found_ih, get_last_bh (path)->b_size) != 1998 if (le_ih_k_offset(found_ih) +
1901 cpu_key_k_offset (p_s_key) || 1999 op_bytes_number(found_ih,
1902 op_bytes_number (found_ih, get_last_bh (path)->b_size) != pos_in_item (path)) 2000 get_last_bh(path)->b_size) !=
1903 reiserfs_panic (NULL, "PAP-5720: check_research_for_paste: " 2001 cpu_key_k_offset(p_s_key)
1904 "found direct item %h or position (%d) does not match to key %K", 2002 || op_bytes_number(found_ih,
1905 found_ih, pos_in_item (path), p_s_key); 2003 get_last_bh(path)->b_size) !=
1906 } 2004 pos_in_item(path))
1907 if (is_indirect_le_ih (found_ih)) { 2005 reiserfs_panic(NULL,
1908 if (le_ih_k_offset (found_ih) + op_bytes_number (found_ih, get_last_bh (path)->b_size) != cpu_key_k_offset (p_s_key) || 2006 "PAP-5720: check_research_for_paste: "
1909 I_UNFM_NUM (found_ih) != pos_in_item (path) || 2007 "found direct item %h or position (%d) does not match to key %K",
1910 get_ih_free_space (found_ih) != 0) 2008 found_ih, pos_in_item(path), p_s_key);
1911 reiserfs_panic (NULL, "PAP-5730: check_research_for_paste: " 2009 }
1912 "found indirect item (%h) or position (%d) does not match to key (%K)", 2010 if (is_indirect_le_ih(found_ih)) {
1913 found_ih, pos_in_item (path), p_s_key); 2011 if (le_ih_k_offset(found_ih) +
1914 } 2012 op_bytes_number(found_ih,
2013 get_last_bh(path)->b_size) !=
2014 cpu_key_k_offset(p_s_key)
2015 || I_UNFM_NUM(found_ih) != pos_in_item(path)
2016 || get_ih_free_space(found_ih) != 0)
2017 reiserfs_panic(NULL,
2018 "PAP-5730: check_research_for_paste: "
2019 "found indirect item (%h) or position (%d) does not match to key (%K)",
2020 found_ih, pos_in_item(path), p_s_key);
2021 }
1915} 2022}
1916#endif /* config reiserfs check */ 2023#endif /* config reiserfs check */
1917
1918 2024
1919/* Paste bytes to the existing item. Returns bytes number pasted into the item. */ 2025/* Paste bytes to the existing item. Returns bytes number pasted into the item. */
1920int reiserfs_paste_into_item (struct reiserfs_transaction_handle *th, 2026int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th, struct path *p_s_search_path, /* Path to the pasted item. */
1921 struct path * p_s_search_path, /* Path to the pasted item. */ 2027 const struct cpu_key *p_s_key, /* Key to search for the needed item. */
1922 const struct cpu_key * p_s_key, /* Key to search for the needed item.*/ 2028 struct inode *inode, /* Inode item belongs to */
1923 struct inode * inode, /* Inode item belongs to */ 2029 const char *p_c_body, /* Pointer to the bytes to paste. */
1924 const char * p_c_body, /* Pointer to the bytes to paste. */ 2030 int n_pasted_size)
1925 int n_pasted_size) /* Size of pasted bytes. */ 2031{ /* Size of pasted bytes. */
1926{ 2032 struct tree_balance s_paste_balance;
1927 struct tree_balance s_paste_balance; 2033 int retval;
1928 int retval; 2034 int fs_gen;
1929 int fs_gen; 2035
2036 BUG_ON(!th->t_trans_id);
1930 2037
1931 BUG_ON (!th->t_trans_id); 2038 fs_gen = get_generation(inode->i_sb);
1932
1933 fs_gen = get_generation(inode->i_sb) ;
1934 2039
1935#ifdef REISERQUOTA_DEBUG 2040#ifdef REISERQUOTA_DEBUG
1936 reiserfs_debug (inode->i_sb, REISERFS_DEBUG_CODE, "reiserquota paste_into_item(): allocating %u id=%u type=%c", n_pasted_size, inode->i_uid, key2type(&(p_s_key->on_disk_key))); 2041 reiserfs_debug(inode->i_sb, REISERFS_DEBUG_CODE,
2042 "reiserquota paste_into_item(): allocating %u id=%u type=%c",
2043 n_pasted_size, inode->i_uid,
2044 key2type(&(p_s_key->on_disk_key)));
1937#endif 2045#endif
1938 2046
1939 if (DQUOT_ALLOC_SPACE_NODIRTY(inode, n_pasted_size)) { 2047 if (DQUOT_ALLOC_SPACE_NODIRTY(inode, n_pasted_size)) {
1940 pathrelse(p_s_search_path); 2048 pathrelse(p_s_search_path);
1941 return -EDQUOT; 2049 return -EDQUOT;
1942 } 2050 }
1943 init_tb_struct(th, &s_paste_balance, th->t_super, p_s_search_path, n_pasted_size); 2051 init_tb_struct(th, &s_paste_balance, th->t_super, p_s_search_path,
2052 n_pasted_size);
1944#ifdef DISPLACE_NEW_PACKING_LOCALITIES 2053#ifdef DISPLACE_NEW_PACKING_LOCALITIES
1945 s_paste_balance.key = p_s_key->on_disk_key; 2054 s_paste_balance.key = p_s_key->on_disk_key;
1946#endif 2055#endif
1947 2056
1948 /* DQUOT_* can schedule, must check before the fix_nodes */ 2057 /* DQUOT_* can schedule, must check before the fix_nodes */
1949 if (fs_changed(fs_gen, inode->i_sb)) { 2058 if (fs_changed(fs_gen, inode->i_sb)) {
1950 goto search_again; 2059 goto search_again;
1951 }
1952
1953 while ((retval = fix_nodes(M_PASTE, &s_paste_balance, NULL, p_c_body)) ==
1954REPEAT_SEARCH ) {
1955search_again:
1956 /* file system changed while we were in the fix_nodes */
1957 PROC_INFO_INC( th -> t_super, paste_into_item_restarted );
1958 retval = search_for_position_by_key (th->t_super, p_s_key, p_s_search_path);
1959 if (retval == IO_ERROR) {
1960 retval = -EIO ;
1961 goto error_out ;
1962 } 2060 }
1963 if (retval == POSITION_FOUND) { 2061
1964 reiserfs_warning (inode->i_sb, "PAP-5710: reiserfs_paste_into_item: entry or pasted byte (%K) exists", p_s_key); 2062 while ((retval =
1965 retval = -EEXIST ; 2063 fix_nodes(M_PASTE, &s_paste_balance, NULL,
1966 goto error_out ; 2064 p_c_body)) == REPEAT_SEARCH) {
1967 } 2065 search_again:
1968 2066 /* file system changed while we were in the fix_nodes */
2067 PROC_INFO_INC(th->t_super, paste_into_item_restarted);
2068 retval =
2069 search_for_position_by_key(th->t_super, p_s_key,
2070 p_s_search_path);
2071 if (retval == IO_ERROR) {
2072 retval = -EIO;
2073 goto error_out;
2074 }
2075 if (retval == POSITION_FOUND) {
2076 reiserfs_warning(inode->i_sb,
2077 "PAP-5710: reiserfs_paste_into_item: entry or pasted byte (%K) exists",
2078 p_s_key);
2079 retval = -EEXIST;
2080 goto error_out;
2081 }
1969#ifdef CONFIG_REISERFS_CHECK 2082#ifdef CONFIG_REISERFS_CHECK
1970 check_research_for_paste (p_s_search_path, p_s_key); 2083 check_research_for_paste(p_s_search_path, p_s_key);
1971#endif 2084#endif
1972 } 2085 }
1973 2086
1974 /* Perform balancing after all resources are collected by fix_nodes, and 2087 /* Perform balancing after all resources are collected by fix_nodes, and
1975 accessing them will not risk triggering schedule. */ 2088 accessing them will not risk triggering schedule. */
1976 if ( retval == CARRY_ON ) { 2089 if (retval == CARRY_ON) {
1977 do_balance(&s_paste_balance, NULL/*ih*/, p_c_body, M_PASTE); 2090 do_balance(&s_paste_balance, NULL /*ih */ , p_c_body, M_PASTE);
1978 return 0; 2091 return 0;
1979 } 2092 }
1980 retval = (retval == NO_DISK_SPACE) ? -ENOSPC : -EIO; 2093 retval = (retval == NO_DISK_SPACE) ? -ENOSPC : -EIO;
1981error_out: 2094 error_out:
1982 /* this also releases the path */ 2095 /* this also releases the path */
1983 unfix_nodes(&s_paste_balance); 2096 unfix_nodes(&s_paste_balance);
1984#ifdef REISERQUOTA_DEBUG 2097#ifdef REISERQUOTA_DEBUG
1985 reiserfs_debug (inode->i_sb, REISERFS_DEBUG_CODE, "reiserquota paste_into_item(): freeing %u id=%u type=%c", n_pasted_size, inode->i_uid, key2type(&(p_s_key->on_disk_key))); 2098 reiserfs_debug(inode->i_sb, REISERFS_DEBUG_CODE,
2099 "reiserquota paste_into_item(): freeing %u id=%u type=%c",
2100 n_pasted_size, inode->i_uid,
2101 key2type(&(p_s_key->on_disk_key)));
1986#endif 2102#endif
1987 DQUOT_FREE_SPACE_NODIRTY(inode, n_pasted_size); 2103 DQUOT_FREE_SPACE_NODIRTY(inode, n_pasted_size);
1988 return retval ; 2104 return retval;
1989} 2105}
1990 2106
1991
1992/* Insert new item into the buffer at the path. */ 2107/* Insert new item into the buffer at the path. */
1993int reiserfs_insert_item(struct reiserfs_transaction_handle *th, 2108int reiserfs_insert_item(struct reiserfs_transaction_handle *th, struct path *p_s_path, /* Path to the inserteded item. */
1994 struct path * p_s_path, /* Path to the inserteded item. */ 2109 const struct cpu_key *key, struct item_head *p_s_ih, /* Pointer to the item header to insert. */
1995 const struct cpu_key * key, 2110 struct inode *inode, const char *p_c_body)
1996 struct item_head * p_s_ih, /* Pointer to the item header to insert.*/ 2111{ /* Pointer to the bytes to insert. */
1997 struct inode * inode, 2112 struct tree_balance s_ins_balance;
1998 const char * p_c_body) /* Pointer to the bytes to insert. */ 2113 int retval;
1999{ 2114 int fs_gen = 0;
2000 struct tree_balance s_ins_balance; 2115 int quota_bytes = 0;
2001 int retval; 2116
2002 int fs_gen = 0 ; 2117 BUG_ON(!th->t_trans_id);
2003 int quota_bytes = 0 ; 2118
2004 2119 if (inode) { /* Do we count quotas for item? */
2005 BUG_ON (!th->t_trans_id); 2120 fs_gen = get_generation(inode->i_sb);
2006 2121 quota_bytes = ih_item_len(p_s_ih);
2007 if (inode) { /* Do we count quotas for item? */ 2122
2008 fs_gen = get_generation(inode->i_sb); 2123 /* hack so the quota code doesn't have to guess if the file has
2009 quota_bytes = ih_item_len(p_s_ih); 2124 ** a tail, links are always tails, so there's no guessing needed
2010 2125 */
2011 /* hack so the quota code doesn't have to guess if the file has 2126 if (!S_ISLNK(inode->i_mode) && is_direct_le_ih(p_s_ih)) {
2012 ** a tail, links are always tails, so there's no guessing needed 2127 quota_bytes = inode->i_sb->s_blocksize + UNFM_P_SIZE;
2013 */ 2128 }
2014 if (!S_ISLNK (inode->i_mode) && is_direct_le_ih(p_s_ih)) {
2015 quota_bytes = inode->i_sb->s_blocksize + UNFM_P_SIZE ;
2016 }
2017#ifdef REISERQUOTA_DEBUG 2129#ifdef REISERQUOTA_DEBUG
2018 reiserfs_debug (inode->i_sb, REISERFS_DEBUG_CODE, "reiserquota insert_item(): allocating %u id=%u type=%c", quota_bytes, inode->i_uid, head2type(p_s_ih)); 2130 reiserfs_debug(inode->i_sb, REISERFS_DEBUG_CODE,
2131 "reiserquota insert_item(): allocating %u id=%u type=%c",
2132 quota_bytes, inode->i_uid, head2type(p_s_ih));
2019#endif 2133#endif
2020 /* We can't dirty inode here. It would be immediately written but 2134 /* We can't dirty inode here. It would be immediately written but
2021 * appropriate stat item isn't inserted yet... */ 2135 * appropriate stat item isn't inserted yet... */
2022 if (DQUOT_ALLOC_SPACE_NODIRTY(inode, quota_bytes)) { 2136 if (DQUOT_ALLOC_SPACE_NODIRTY(inode, quota_bytes)) {
2023 pathrelse(p_s_path); 2137 pathrelse(p_s_path);
2024 return -EDQUOT; 2138 return -EDQUOT;
2139 }
2025 } 2140 }
2026 } 2141 init_tb_struct(th, &s_ins_balance, th->t_super, p_s_path,
2027 init_tb_struct(th, &s_ins_balance, th->t_super, p_s_path, IH_SIZE + ih_item_len(p_s_ih)); 2142 IH_SIZE + ih_item_len(p_s_ih));
2028#ifdef DISPLACE_NEW_PACKING_LOCALITIES 2143#ifdef DISPLACE_NEW_PACKING_LOCALITIES
2029 s_ins_balance.key = key->on_disk_key; 2144 s_ins_balance.key = key->on_disk_key;
2030#endif 2145#endif
2031 /* DQUOT_* can schedule, must check to be sure calling fix_nodes is safe */ 2146 /* DQUOT_* can schedule, must check to be sure calling fix_nodes is safe */
2032 if (inode && fs_changed(fs_gen, inode->i_sb)) { 2147 if (inode && fs_changed(fs_gen, inode->i_sb)) {
2033 goto search_again; 2148 goto search_again;
2034 }
2035
2036 while ( (retval = fix_nodes(M_INSERT, &s_ins_balance, p_s_ih, p_c_body)) == REPEAT_SEARCH) {
2037search_again:
2038 /* file system changed while we were in the fix_nodes */
2039 PROC_INFO_INC( th -> t_super, insert_item_restarted );
2040 retval = search_item (th->t_super, key, p_s_path);
2041 if (retval == IO_ERROR) {
2042 retval = -EIO;
2043 goto error_out ;
2044 } 2149 }
2045 if (retval == ITEM_FOUND) { 2150
2046 reiserfs_warning (th->t_super, "PAP-5760: reiserfs_insert_item: " 2151 while ((retval =
2047 "key %K already exists in the tree", key); 2152 fix_nodes(M_INSERT, &s_ins_balance, p_s_ih,
2048 retval = -EEXIST ; 2153 p_c_body)) == REPEAT_SEARCH) {
2049 goto error_out; 2154 search_again:
2155 /* file system changed while we were in the fix_nodes */
2156 PROC_INFO_INC(th->t_super, insert_item_restarted);
2157 retval = search_item(th->t_super, key, p_s_path);
2158 if (retval == IO_ERROR) {
2159 retval = -EIO;
2160 goto error_out;
2161 }
2162 if (retval == ITEM_FOUND) {
2163 reiserfs_warning(th->t_super,
2164 "PAP-5760: reiserfs_insert_item: "
2165 "key %K already exists in the tree",
2166 key);
2167 retval = -EEXIST;
2168 goto error_out;
2169 }
2050 } 2170 }
2051 }
2052 2171
2053 /* make balancing after all resources will be collected at a time */ 2172 /* make balancing after all resources will be collected at a time */
2054 if ( retval == CARRY_ON ) { 2173 if (retval == CARRY_ON) {
2055 do_balance (&s_ins_balance, p_s_ih, p_c_body, M_INSERT); 2174 do_balance(&s_ins_balance, p_s_ih, p_c_body, M_INSERT);
2056 return 0; 2175 return 0;
2057 } 2176 }
2058 2177
2059 retval = (retval == NO_DISK_SPACE) ? -ENOSPC : -EIO; 2178 retval = (retval == NO_DISK_SPACE) ? -ENOSPC : -EIO;
2060error_out: 2179 error_out:
2061 /* also releases the path */ 2180 /* also releases the path */
2062 unfix_nodes(&s_ins_balance); 2181 unfix_nodes(&s_ins_balance);
2063#ifdef REISERQUOTA_DEBUG 2182#ifdef REISERQUOTA_DEBUG
2064 reiserfs_debug (th->t_super, REISERFS_DEBUG_CODE, "reiserquota insert_item(): freeing %u id=%u type=%c", quota_bytes, inode->i_uid, head2type(p_s_ih)); 2183 reiserfs_debug(th->t_super, REISERFS_DEBUG_CODE,
2184 "reiserquota insert_item(): freeing %u id=%u type=%c",
2185 quota_bytes, inode->i_uid, head2type(p_s_ih));
2065#endif 2186#endif
2066 if (inode) 2187 if (inode)
2067 DQUOT_FREE_SPACE_NODIRTY(inode, quota_bytes) ; 2188 DQUOT_FREE_SPACE_NODIRTY(inode, quota_bytes);
2068 return retval; 2189 return retval;
2069} 2190}
2070
2071
2072
2073
diff --git a/fs/reiserfs/super.c b/fs/reiserfs/super.c
index 4b80ab95d338..6951c35755be 100644
--- a/fs/reiserfs/super.c
+++ b/fs/reiserfs/super.c
@@ -35,83 +35,81 @@ static const char reiserfs_3_5_magic_string[] = REISERFS_SUPER_MAGIC_STRING;
35static const char reiserfs_3_6_magic_string[] = REISER2FS_SUPER_MAGIC_STRING; 35static const char reiserfs_3_6_magic_string[] = REISER2FS_SUPER_MAGIC_STRING;
36static const char reiserfs_jr_magic_string[] = REISER2FS_JR_SUPER_MAGIC_STRING; 36static const char reiserfs_jr_magic_string[] = REISER2FS_JR_SUPER_MAGIC_STRING;
37 37
38int is_reiserfs_3_5 (struct reiserfs_super_block * rs) 38int is_reiserfs_3_5(struct reiserfs_super_block *rs)
39{ 39{
40 return !strncmp (rs->s_v1.s_magic, reiserfs_3_5_magic_string, 40 return !strncmp(rs->s_v1.s_magic, reiserfs_3_5_magic_string,
41 strlen (reiserfs_3_5_magic_string)); 41 strlen(reiserfs_3_5_magic_string));
42} 42}
43 43
44 44int is_reiserfs_3_6(struct reiserfs_super_block *rs)
45int is_reiserfs_3_6 (struct reiserfs_super_block * rs)
46{ 45{
47 return !strncmp (rs->s_v1.s_magic, reiserfs_3_6_magic_string, 46 return !strncmp(rs->s_v1.s_magic, reiserfs_3_6_magic_string,
48 strlen (reiserfs_3_6_magic_string)); 47 strlen(reiserfs_3_6_magic_string));
49} 48}
50 49
51 50int is_reiserfs_jr(struct reiserfs_super_block *rs)
52int is_reiserfs_jr (struct reiserfs_super_block * rs)
53{ 51{
54 return !strncmp (rs->s_v1.s_magic, reiserfs_jr_magic_string, 52 return !strncmp(rs->s_v1.s_magic, reiserfs_jr_magic_string,
55 strlen (reiserfs_jr_magic_string)); 53 strlen(reiserfs_jr_magic_string));
56} 54}
57 55
58 56static int is_any_reiserfs_magic_string(struct reiserfs_super_block *rs)
59static int is_any_reiserfs_magic_string (struct reiserfs_super_block * rs)
60{ 57{
61 return (is_reiserfs_3_5 (rs) || is_reiserfs_3_6 (rs) || 58 return (is_reiserfs_3_5(rs) || is_reiserfs_3_6(rs) ||
62 is_reiserfs_jr (rs)); 59 is_reiserfs_jr(rs));
63} 60}
64 61
65static int reiserfs_remount (struct super_block * s, int * flags, char * data); 62static int reiserfs_remount(struct super_block *s, int *flags, char *data);
66static int reiserfs_statfs (struct super_block * s, struct kstatfs * buf); 63static int reiserfs_statfs(struct super_block *s, struct kstatfs *buf);
67 64
68static int reiserfs_sync_fs (struct super_block * s, int wait) 65static int reiserfs_sync_fs(struct super_block *s, int wait)
69{ 66{
70 if (!(s->s_flags & MS_RDONLY)) { 67 if (!(s->s_flags & MS_RDONLY)) {
71 struct reiserfs_transaction_handle th; 68 struct reiserfs_transaction_handle th;
72 reiserfs_write_lock(s); 69 reiserfs_write_lock(s);
73 if (!journal_begin(&th, s, 1)) 70 if (!journal_begin(&th, s, 1))
74 if (!journal_end_sync(&th, s, 1)) 71 if (!journal_end_sync(&th, s, 1))
75 reiserfs_flush_old_commits(s); 72 reiserfs_flush_old_commits(s);
76 s->s_dirt = 0; /* Even if it's not true. 73 s->s_dirt = 0; /* Even if it's not true.
77 * We'll loop forever in sync_supers otherwise */ 74 * We'll loop forever in sync_supers otherwise */
78 reiserfs_write_unlock(s); 75 reiserfs_write_unlock(s);
79 } else { 76 } else {
80 s->s_dirt = 0; 77 s->s_dirt = 0;
81 } 78 }
82 return 0; 79 return 0;
83} 80}
84 81
85static void reiserfs_write_super(struct super_block *s) 82static void reiserfs_write_super(struct super_block *s)
86{ 83{
87 reiserfs_sync_fs(s, 1); 84 reiserfs_sync_fs(s, 1);
88} 85}
89 86
90static void reiserfs_write_super_lockfs (struct super_block * s) 87static void reiserfs_write_super_lockfs(struct super_block *s)
91{ 88{
92 struct reiserfs_transaction_handle th ; 89 struct reiserfs_transaction_handle th;
93 reiserfs_write_lock(s); 90 reiserfs_write_lock(s);
94 if (!(s->s_flags & MS_RDONLY)) { 91 if (!(s->s_flags & MS_RDONLY)) {
95 int err = journal_begin(&th, s, 1) ; 92 int err = journal_begin(&th, s, 1);
96 if (err) { 93 if (err) {
97 reiserfs_block_writes(&th) ; 94 reiserfs_block_writes(&th);
98 } else { 95 } else {
99 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1); 96 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s),
100 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB (s)); 97 1);
101 reiserfs_block_writes(&th) ; 98 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
102 journal_end_sync(&th, s, 1) ; 99 reiserfs_block_writes(&th);
103 } 100 journal_end_sync(&th, s, 1);
104 } 101 }
105 s->s_dirt = 0; 102 }
106 reiserfs_write_unlock(s); 103 s->s_dirt = 0;
104 reiserfs_write_unlock(s);
107} 105}
108 106
109static void reiserfs_unlockfs(struct super_block *s) { 107static void reiserfs_unlockfs(struct super_block *s)
110 reiserfs_allow_writes(s) ; 108{
109 reiserfs_allow_writes(s);
111} 110}
112 111
113extern const struct in_core_key MAX_IN_CORE_KEY; 112extern const struct in_core_key MAX_IN_CORE_KEY;
114
115 113
116/* this is used to delete "save link" when there are no items of a 114/* this is used to delete "save link" when there are no items of a
117 file it points to. It can either happen if unlink is completed but 115 file it points to. It can either happen if unlink is completed but
@@ -120,364 +118,387 @@ extern const struct in_core_key MAX_IN_CORE_KEY;
120 protecting unlink is bigger that a key lf "save link" which 118 protecting unlink is bigger that a key lf "save link" which
121 protects truncate), so there left no items to make truncate 119 protects truncate), so there left no items to make truncate
122 completion on */ 120 completion on */
123static int remove_save_link_only (struct super_block * s, struct reiserfs_key * key, int oid_free) 121static int remove_save_link_only(struct super_block *s,
122 struct reiserfs_key *key, int oid_free)
124{ 123{
125 struct reiserfs_transaction_handle th; 124 struct reiserfs_transaction_handle th;
126 int err; 125 int err;
127 126
128 /* we are going to do one balancing */ 127 /* we are going to do one balancing */
129 err = journal_begin (&th, s, JOURNAL_PER_BALANCE_CNT); 128 err = journal_begin(&th, s, JOURNAL_PER_BALANCE_CNT);
130 if (err) 129 if (err)
131 return err; 130 return err;
132 131
133 reiserfs_delete_solid_item (&th, NULL, key); 132 reiserfs_delete_solid_item(&th, NULL, key);
134 if (oid_free) 133 if (oid_free)
135 /* removals are protected by direct items */ 134 /* removals are protected by direct items */
136 reiserfs_release_objectid (&th, le32_to_cpu (key->k_objectid)); 135 reiserfs_release_objectid(&th, le32_to_cpu(key->k_objectid));
137 136
138 return journal_end (&th, s, JOURNAL_PER_BALANCE_CNT); 137 return journal_end(&th, s, JOURNAL_PER_BALANCE_CNT);
139} 138}
140 139
141#ifdef CONFIG_QUOTA 140#ifdef CONFIG_QUOTA
142static int reiserfs_quota_on_mount(struct super_block *, int); 141static int reiserfs_quota_on_mount(struct super_block *, int);
143#endif 142#endif
144 143
145/* look for uncompleted unlinks and truncates and complete them */ 144/* look for uncompleted unlinks and truncates and complete them */
146static int finish_unfinished (struct super_block * s) 145static int finish_unfinished(struct super_block *s)
147{ 146{
148 INITIALIZE_PATH (path); 147 INITIALIZE_PATH(path);
149 struct cpu_key max_cpu_key, obj_key; 148 struct cpu_key max_cpu_key, obj_key;
150 struct reiserfs_key save_link_key; 149 struct reiserfs_key save_link_key;
151 int retval = 0; 150 int retval = 0;
152 struct item_head * ih; 151 struct item_head *ih;
153 struct buffer_head * bh; 152 struct buffer_head *bh;
154 int item_pos; 153 int item_pos;
155 char * item; 154 char *item;
156 int done; 155 int done;
157 struct inode * inode; 156 struct inode *inode;
158 int truncate; 157 int truncate;
159#ifdef CONFIG_QUOTA 158#ifdef CONFIG_QUOTA
160 int i; 159 int i;
161 int ms_active_set; 160 int ms_active_set;
162#endif 161#endif
163 162
164 163 /* compose key to look for "save" links */
165 /* compose key to look for "save" links */ 164 max_cpu_key.version = KEY_FORMAT_3_5;
166 max_cpu_key.version = KEY_FORMAT_3_5; 165 max_cpu_key.on_disk_key.k_dir_id = ~0U;
167 max_cpu_key.on_disk_key.k_dir_id = ~0U; 166 max_cpu_key.on_disk_key.k_objectid = ~0U;
168 max_cpu_key.on_disk_key.k_objectid = ~0U; 167 set_cpu_key_k_offset(&max_cpu_key, ~0U);
169 set_cpu_key_k_offset (&max_cpu_key, ~0U); 168 max_cpu_key.key_length = 3;
170 max_cpu_key.key_length = 3;
171 169
172#ifdef CONFIG_QUOTA 170#ifdef CONFIG_QUOTA
173 /* Needed for iput() to work correctly and not trash data */ 171 /* Needed for iput() to work correctly and not trash data */
174 if (s->s_flags & MS_ACTIVE) { 172 if (s->s_flags & MS_ACTIVE) {
175 ms_active_set = 0; 173 ms_active_set = 0;
176 } else { 174 } else {
177 ms_active_set = 1; 175 ms_active_set = 1;
178 s->s_flags |= MS_ACTIVE; 176 s->s_flags |= MS_ACTIVE;
179 } 177 }
180 /* Turn on quotas so that they are updated correctly */ 178 /* Turn on quotas so that they are updated correctly */
181 for (i = 0; i < MAXQUOTAS; i++) { 179 for (i = 0; i < MAXQUOTAS; i++) {
182 if (REISERFS_SB(s)->s_qf_names[i]) { 180 if (REISERFS_SB(s)->s_qf_names[i]) {
183 int ret = reiserfs_quota_on_mount(s, i); 181 int ret = reiserfs_quota_on_mount(s, i);
184 if (ret < 0) 182 if (ret < 0)
185 reiserfs_warning(s, "reiserfs: cannot turn on journalled quota: error %d", ret); 183 reiserfs_warning(s,
186 } 184 "reiserfs: cannot turn on journalled quota: error %d",
187 } 185 ret);
186 }
187 }
188#endif 188#endif
189 189
190 done = 0; 190 done = 0;
191 REISERFS_SB(s)->s_is_unlinked_ok = 1; 191 REISERFS_SB(s)->s_is_unlinked_ok = 1;
192 while (!retval) { 192 while (!retval) {
193 retval = search_item (s, &max_cpu_key, &path); 193 retval = search_item(s, &max_cpu_key, &path);
194 if (retval != ITEM_NOT_FOUND) { 194 if (retval != ITEM_NOT_FOUND) {
195 reiserfs_warning (s, "vs-2140: finish_unfinished: search_by_key returned %d", 195 reiserfs_warning(s,
196 retval); 196 "vs-2140: finish_unfinished: search_by_key returned %d",
197 break; 197 retval);
198 } 198 break;
199 199 }
200 bh = get_last_bh (&path); 200
201 item_pos = get_item_pos (&path); 201 bh = get_last_bh(&path);
202 if (item_pos != B_NR_ITEMS (bh)) { 202 item_pos = get_item_pos(&path);
203 reiserfs_warning (s, "vs-2060: finish_unfinished: wrong position found"); 203 if (item_pos != B_NR_ITEMS(bh)) {
204 break; 204 reiserfs_warning(s,
205 } 205 "vs-2060: finish_unfinished: wrong position found");
206 item_pos --; 206 break;
207 ih = B_N_PITEM_HEAD (bh, item_pos); 207 }
208 208 item_pos--;
209 if (le32_to_cpu (ih->ih_key.k_dir_id) != MAX_KEY_OBJECTID) 209 ih = B_N_PITEM_HEAD(bh, item_pos);
210 /* there are no "save" links anymore */ 210
211 break; 211 if (le32_to_cpu(ih->ih_key.k_dir_id) != MAX_KEY_OBJECTID)
212 212 /* there are no "save" links anymore */
213 save_link_key = ih->ih_key; 213 break;
214 if (is_indirect_le_ih (ih)) 214
215 truncate = 1; 215 save_link_key = ih->ih_key;
216 else 216 if (is_indirect_le_ih(ih))
217 truncate = 0; 217 truncate = 1;
218 218 else
219 /* reiserfs_iget needs k_dirid and k_objectid only */ 219 truncate = 0;
220 item = B_I_PITEM (bh, ih); 220
221 obj_key.on_disk_key.k_dir_id = le32_to_cpu (*(__le32 *)item); 221 /* reiserfs_iget needs k_dirid and k_objectid only */
222 obj_key.on_disk_key.k_objectid = le32_to_cpu (ih->ih_key.k_objectid); 222 item = B_I_PITEM(bh, ih);
223 obj_key.on_disk_key.k_offset = 0; 223 obj_key.on_disk_key.k_dir_id = le32_to_cpu(*(__le32 *) item);
224 obj_key.on_disk_key.k_type = 0; 224 obj_key.on_disk_key.k_objectid =
225 225 le32_to_cpu(ih->ih_key.k_objectid);
226 pathrelse (&path); 226 obj_key.on_disk_key.k_offset = 0;
227 227 obj_key.on_disk_key.k_type = 0;
228 inode = reiserfs_iget (s, &obj_key); 228
229 if (!inode) { 229 pathrelse(&path);
230 /* the unlink almost completed, it just did not manage to remove 230
231 "save" link and release objectid */ 231 inode = reiserfs_iget(s, &obj_key);
232 reiserfs_warning (s, "vs-2180: finish_unfinished: iget failed for %K", 232 if (!inode) {
233 &obj_key); 233 /* the unlink almost completed, it just did not manage to remove
234 retval = remove_save_link_only (s, &save_link_key, 1); 234 "save" link and release objectid */
235 continue; 235 reiserfs_warning(s,
236 } 236 "vs-2180: finish_unfinished: iget failed for %K",
237 237 &obj_key);
238 if (!truncate && inode->i_nlink) { 238 retval = remove_save_link_only(s, &save_link_key, 1);
239 /* file is not unlinked */ 239 continue;
240 reiserfs_warning (s, "vs-2185: finish_unfinished: file %K is not unlinked", 240 }
241 &obj_key); 241
242 retval = remove_save_link_only (s, &save_link_key, 0); 242 if (!truncate && inode->i_nlink) {
243 continue; 243 /* file is not unlinked */
244 } 244 reiserfs_warning(s,
245 DQUOT_INIT(inode); 245 "vs-2185: finish_unfinished: file %K is not unlinked",
246 246 &obj_key);
247 if (truncate && S_ISDIR (inode->i_mode) ) { 247 retval = remove_save_link_only(s, &save_link_key, 0);
248 /* We got a truncate request for a dir which is impossible. 248 continue;
249 The only imaginable way is to execute unfinished truncate request 249 }
250 then boot into old kernel, remove the file and create dir with 250 DQUOT_INIT(inode);
251 the same key. */ 251
252 reiserfs_warning(s, "green-2101: impossible truncate on a directory %k. Please report", INODE_PKEY (inode)); 252 if (truncate && S_ISDIR(inode->i_mode)) {
253 retval = remove_save_link_only (s, &save_link_key, 0); 253 /* We got a truncate request for a dir which is impossible.
254 truncate = 0; 254 The only imaginable way is to execute unfinished truncate request
255 iput (inode); 255 then boot into old kernel, remove the file and create dir with
256 continue; 256 the same key. */
257 } 257 reiserfs_warning(s,
258 258 "green-2101: impossible truncate on a directory %k. Please report",
259 if (truncate) { 259 INODE_PKEY(inode));
260 REISERFS_I(inode) -> i_flags |= i_link_saved_truncate_mask; 260 retval = remove_save_link_only(s, &save_link_key, 0);
261 /* not completed truncate found. New size was committed together 261 truncate = 0;
262 with "save" link */ 262 iput(inode);
263 reiserfs_info (s, "Truncating %k to %Ld ..", 263 continue;
264 INODE_PKEY (inode), inode->i_size); 264 }
265 reiserfs_truncate_file (inode, 0/*don't update modification time*/); 265
266 retval = remove_save_link (inode, truncate); 266 if (truncate) {
267 } else { 267 REISERFS_I(inode)->i_flags |=
268 REISERFS_I(inode) -> i_flags |= i_link_saved_unlink_mask; 268 i_link_saved_truncate_mask;
269 /* not completed unlink (rmdir) found */ 269 /* not completed truncate found. New size was committed together
270 reiserfs_info (s, "Removing %k..", INODE_PKEY (inode)); 270 with "save" link */
271 /* removal gets completed in iput */ 271 reiserfs_info(s, "Truncating %k to %Ld ..",
272 retval = 0; 272 INODE_PKEY(inode), inode->i_size);
273 } 273 reiserfs_truncate_file(inode,
274 274 0
275 iput (inode); 275 /*don't update modification time */
276 printk ("done\n"); 276 );
277 done ++; 277 retval = remove_save_link(inode, truncate);
278 } 278 } else {
279 REISERFS_SB(s)->s_is_unlinked_ok = 0; 279 REISERFS_I(inode)->i_flags |= i_link_saved_unlink_mask;
280 280 /* not completed unlink (rmdir) found */
281 reiserfs_info(s, "Removing %k..", INODE_PKEY(inode));
282 /* removal gets completed in iput */
283 retval = 0;
284 }
285
286 iput(inode);
287 printk("done\n");
288 done++;
289 }
290 REISERFS_SB(s)->s_is_unlinked_ok = 0;
291
281#ifdef CONFIG_QUOTA 292#ifdef CONFIG_QUOTA
282 /* Turn quotas off */ 293 /* Turn quotas off */
283 for (i = 0; i < MAXQUOTAS; i++) { 294 for (i = 0; i < MAXQUOTAS; i++) {
284 if (sb_dqopt(s)->files[i]) 295 if (sb_dqopt(s)->files[i])
285 vfs_quota_off_mount(s, i); 296 vfs_quota_off_mount(s, i);
286 } 297 }
287 if (ms_active_set) 298 if (ms_active_set)
288 /* Restore the flag back */ 299 /* Restore the flag back */
289 s->s_flags &= ~MS_ACTIVE; 300 s->s_flags &= ~MS_ACTIVE;
290#endif 301#endif
291 pathrelse (&path); 302 pathrelse(&path);
292 if (done) 303 if (done)
293 reiserfs_info (s, "There were %d uncompleted unlinks/truncates. " 304 reiserfs_info(s, "There were %d uncompleted unlinks/truncates. "
294 "Completed\n", done); 305 "Completed\n", done);
295 return retval; 306 return retval;
296} 307}
297 308
298/* to protect file being unlinked from getting lost we "safe" link files 309/* to protect file being unlinked from getting lost we "safe" link files
299 being unlinked. This link will be deleted in the same transaction with last 310 being unlinked. This link will be deleted in the same transaction with last
300 item of file. mounting the filesytem we scan all these links and remove 311 item of file. mounting the filesytem we scan all these links and remove
301 files which almost got lost */ 312 files which almost got lost */
302void add_save_link (struct reiserfs_transaction_handle * th, 313void add_save_link(struct reiserfs_transaction_handle *th,
303 struct inode * inode, int truncate) 314 struct inode *inode, int truncate)
304{ 315{
305 INITIALIZE_PATH (path); 316 INITIALIZE_PATH(path);
306 int retval; 317 int retval;
307 struct cpu_key key; 318 struct cpu_key key;
308 struct item_head ih; 319 struct item_head ih;
309 __le32 link; 320 __le32 link;
310 321
311 BUG_ON (!th->t_trans_id); 322 BUG_ON(!th->t_trans_id);
312 323
313 /* file can only get one "save link" of each kind */ 324 /* file can only get one "save link" of each kind */
314 RFALSE( truncate && 325 RFALSE(truncate &&
315 ( REISERFS_I(inode) -> i_flags & i_link_saved_truncate_mask ), 326 (REISERFS_I(inode)->i_flags & i_link_saved_truncate_mask),
316 "saved link already exists for truncated inode %lx", 327 "saved link already exists for truncated inode %lx",
317 ( long ) inode -> i_ino ); 328 (long)inode->i_ino);
318 RFALSE( !truncate && 329 RFALSE(!truncate &&
319 ( REISERFS_I(inode) -> i_flags & i_link_saved_unlink_mask ), 330 (REISERFS_I(inode)->i_flags & i_link_saved_unlink_mask),
320 "saved link already exists for unlinked inode %lx", 331 "saved link already exists for unlinked inode %lx",
321 ( long ) inode -> i_ino ); 332 (long)inode->i_ino);
322 333
323 /* setup key of "save" link */ 334 /* setup key of "save" link */
324 key.version = KEY_FORMAT_3_5; 335 key.version = KEY_FORMAT_3_5;
325 key.on_disk_key.k_dir_id = MAX_KEY_OBJECTID; 336 key.on_disk_key.k_dir_id = MAX_KEY_OBJECTID;
326 key.on_disk_key.k_objectid = inode->i_ino; 337 key.on_disk_key.k_objectid = inode->i_ino;
327 if (!truncate) { 338 if (!truncate) {
328 /* unlink, rmdir, rename */ 339 /* unlink, rmdir, rename */
329 set_cpu_key_k_offset (&key, 1 + inode->i_sb->s_blocksize); 340 set_cpu_key_k_offset(&key, 1 + inode->i_sb->s_blocksize);
330 set_cpu_key_k_type (&key, TYPE_DIRECT); 341 set_cpu_key_k_type(&key, TYPE_DIRECT);
331 342
332 /* item head of "safe" link */ 343 /* item head of "safe" link */
333 make_le_item_head (&ih, &key, key.version, 1 + inode->i_sb->s_blocksize, TYPE_DIRECT, 344 make_le_item_head(&ih, &key, key.version,
334 4/*length*/, 0xffff/*free space*/); 345 1 + inode->i_sb->s_blocksize, TYPE_DIRECT,
335 } else { 346 4 /*length */ , 0xffff /*free space */ );
336 /* truncate */ 347 } else {
337 if (S_ISDIR (inode->i_mode)) 348 /* truncate */
338 reiserfs_warning(inode->i_sb, "green-2102: Adding a truncate savelink for a directory %k! Please report", INODE_PKEY(inode)); 349 if (S_ISDIR(inode->i_mode))
339 set_cpu_key_k_offset (&key, 1); 350 reiserfs_warning(inode->i_sb,
340 set_cpu_key_k_type (&key, TYPE_INDIRECT); 351 "green-2102: Adding a truncate savelink for a directory %k! Please report",
341 352 INODE_PKEY(inode));
342 /* item head of "safe" link */ 353 set_cpu_key_k_offset(&key, 1);
343 make_le_item_head (&ih, &key, key.version, 1, TYPE_INDIRECT, 354 set_cpu_key_k_type(&key, TYPE_INDIRECT);
344 4/*length*/, 0/*free space*/); 355
345 } 356 /* item head of "safe" link */
346 key.key_length = 3; 357 make_le_item_head(&ih, &key, key.version, 1, TYPE_INDIRECT,
347 358 4 /*length */ , 0 /*free space */ );
348 /* look for its place in the tree */ 359 }
349 retval = search_item (inode->i_sb, &key, &path); 360 key.key_length = 3;
350 if (retval != ITEM_NOT_FOUND) { 361
351 if ( retval != -ENOSPC ) 362 /* look for its place in the tree */
352 reiserfs_warning (inode->i_sb, "vs-2100: add_save_link:" 363 retval = search_item(inode->i_sb, &key, &path);
353 "search_by_key (%K) returned %d", &key, retval); 364 if (retval != ITEM_NOT_FOUND) {
354 pathrelse (&path); 365 if (retval != -ENOSPC)
355 return; 366 reiserfs_warning(inode->i_sb, "vs-2100: add_save_link:"
356 } 367 "search_by_key (%K) returned %d", &key,
357 368 retval);
358 /* body of "save" link */ 369 pathrelse(&path);
359 link = INODE_PKEY (inode)->k_dir_id; 370 return;
360 371 }
361 /* put "save" link inot tree, don't charge quota to anyone */
362 retval = reiserfs_insert_item (th, &path, &key, &ih, NULL, (char *)&link);
363 if (retval) {
364 if (retval != -ENOSPC)
365 reiserfs_warning (inode->i_sb, "vs-2120: add_save_link: insert_item returned %d",
366 retval);
367 } else {
368 if( truncate )
369 REISERFS_I(inode) -> i_flags |= i_link_saved_truncate_mask;
370 else
371 REISERFS_I(inode) -> i_flags |= i_link_saved_unlink_mask;
372 }
373}
374 372
373 /* body of "save" link */
374 link = INODE_PKEY(inode)->k_dir_id;
375
376 /* put "save" link inot tree, don't charge quota to anyone */
377 retval =
378 reiserfs_insert_item(th, &path, &key, &ih, NULL, (char *)&link);
379 if (retval) {
380 if (retval != -ENOSPC)
381 reiserfs_warning(inode->i_sb,
382 "vs-2120: add_save_link: insert_item returned %d",
383 retval);
384 } else {
385 if (truncate)
386 REISERFS_I(inode)->i_flags |=
387 i_link_saved_truncate_mask;
388 else
389 REISERFS_I(inode)->i_flags |= i_link_saved_unlink_mask;
390 }
391}
375 392
376/* this opens transaction unlike add_save_link */ 393/* this opens transaction unlike add_save_link */
377int remove_save_link (struct inode * inode, int truncate) 394int remove_save_link(struct inode *inode, int truncate)
378{ 395{
379 struct reiserfs_transaction_handle th; 396 struct reiserfs_transaction_handle th;
380 struct reiserfs_key key; 397 struct reiserfs_key key;
381 int err; 398 int err;
382 399
383 /* we are going to do one balancing only */ 400 /* we are going to do one balancing only */
384 err = journal_begin (&th, inode->i_sb, JOURNAL_PER_BALANCE_CNT); 401 err = journal_begin(&th, inode->i_sb, JOURNAL_PER_BALANCE_CNT);
385 if (err) 402 if (err)
386 return err; 403 return err;
387 404
388 /* setup key of "save" link */ 405 /* setup key of "save" link */
389 key.k_dir_id = cpu_to_le32 (MAX_KEY_OBJECTID); 406 key.k_dir_id = cpu_to_le32(MAX_KEY_OBJECTID);
390 key.k_objectid = INODE_PKEY (inode)->k_objectid; 407 key.k_objectid = INODE_PKEY(inode)->k_objectid;
391 if (!truncate) { 408 if (!truncate) {
392 /* unlink, rmdir, rename */ 409 /* unlink, rmdir, rename */
393 set_le_key_k_offset (KEY_FORMAT_3_5, &key, 410 set_le_key_k_offset(KEY_FORMAT_3_5, &key,
394 1 + inode->i_sb->s_blocksize); 411 1 + inode->i_sb->s_blocksize);
395 set_le_key_k_type (KEY_FORMAT_3_5, &key, TYPE_DIRECT); 412 set_le_key_k_type(KEY_FORMAT_3_5, &key, TYPE_DIRECT);
396 } else { 413 } else {
397 /* truncate */ 414 /* truncate */
398 set_le_key_k_offset (KEY_FORMAT_3_5, &key, 1); 415 set_le_key_k_offset(KEY_FORMAT_3_5, &key, 1);
399 set_le_key_k_type (KEY_FORMAT_3_5, &key, TYPE_INDIRECT); 416 set_le_key_k_type(KEY_FORMAT_3_5, &key, TYPE_INDIRECT);
400 } 417 }
401
402 if( ( truncate &&
403 ( REISERFS_I(inode) -> i_flags & i_link_saved_truncate_mask ) ) ||
404 ( !truncate &&
405 ( REISERFS_I(inode) -> i_flags & i_link_saved_unlink_mask ) ) )
406 /* don't take quota bytes from anywhere */
407 reiserfs_delete_solid_item (&th, NULL, &key);
408 if (!truncate) {
409 reiserfs_release_objectid (&th, inode->i_ino);
410 REISERFS_I(inode) -> i_flags &= ~i_link_saved_unlink_mask;
411 } else
412 REISERFS_I(inode) -> i_flags &= ~i_link_saved_truncate_mask;
413
414 return journal_end (&th, inode->i_sb, JOURNAL_PER_BALANCE_CNT);
415}
416 418
419 if ((truncate &&
420 (REISERFS_I(inode)->i_flags & i_link_saved_truncate_mask)) ||
421 (!truncate &&
422 (REISERFS_I(inode)->i_flags & i_link_saved_unlink_mask)))
423 /* don't take quota bytes from anywhere */
424 reiserfs_delete_solid_item(&th, NULL, &key);
425 if (!truncate) {
426 reiserfs_release_objectid(&th, inode->i_ino);
427 REISERFS_I(inode)->i_flags &= ~i_link_saved_unlink_mask;
428 } else
429 REISERFS_I(inode)->i_flags &= ~i_link_saved_truncate_mask;
430
431 return journal_end(&th, inode->i_sb, JOURNAL_PER_BALANCE_CNT);
432}
417 433
418static void reiserfs_put_super (struct super_block * s) 434static void reiserfs_put_super(struct super_block *s)
419{ 435{
420 int i; 436 int i;
421 struct reiserfs_transaction_handle th ; 437 struct reiserfs_transaction_handle th;
422 th.t_trans_id = 0; 438 th.t_trans_id = 0;
423 439
424 if (REISERFS_SB(s)->xattr_root) { 440 if (REISERFS_SB(s)->xattr_root) {
425 d_invalidate (REISERFS_SB(s)->xattr_root); 441 d_invalidate(REISERFS_SB(s)->xattr_root);
426 dput (REISERFS_SB(s)->xattr_root); 442 dput(REISERFS_SB(s)->xattr_root);
427 } 443 }
428 444
429 if (REISERFS_SB(s)->priv_root) { 445 if (REISERFS_SB(s)->priv_root) {
430 d_invalidate (REISERFS_SB(s)->priv_root); 446 d_invalidate(REISERFS_SB(s)->priv_root);
431 dput (REISERFS_SB(s)->priv_root); 447 dput(REISERFS_SB(s)->priv_root);
432 } 448 }
433 449
434 /* change file system state to current state if it was mounted with read-write permissions */ 450 /* change file system state to current state if it was mounted with read-write permissions */
435 if (!(s->s_flags & MS_RDONLY)) { 451 if (!(s->s_flags & MS_RDONLY)) {
436 if (!journal_begin(&th, s, 10)) { 452 if (!journal_begin(&th, s, 10)) {
437 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1) ; 453 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s),
438 set_sb_umount_state( SB_DISK_SUPER_BLOCK(s), REISERFS_SB(s)->s_mount_state ); 454 1);
439 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB (s)); 455 set_sb_umount_state(SB_DISK_SUPER_BLOCK(s),
440 } 456 REISERFS_SB(s)->s_mount_state);
441 } 457 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
442 458 }
443 /* note, journal_release checks for readonly mount, and can decide not 459 }
444 ** to do a journal_end 460
445 */ 461 /* note, journal_release checks for readonly mount, and can decide not
446 journal_release(&th, s) ; 462 ** to do a journal_end
447 463 */
448 for (i = 0; i < SB_BMAP_NR (s); i ++) 464 journal_release(&th, s);
449 brelse (SB_AP_BITMAP (s)[i].bh); 465
450 466 for (i = 0; i < SB_BMAP_NR(s); i++)
451 vfree (SB_AP_BITMAP (s)); 467 brelse(SB_AP_BITMAP(s)[i].bh);
452 468
453 brelse (SB_BUFFER_WITH_SB (s)); 469 vfree(SB_AP_BITMAP(s));
454 470
455 print_statistics (s); 471 brelse(SB_BUFFER_WITH_SB(s));
456 472
457 if (REISERFS_SB(s)->s_kmallocs != 0) { 473 print_statistics(s);
458 reiserfs_warning (s, "vs-2004: reiserfs_put_super: allocated memory left %d", 474
459 REISERFS_SB(s)->s_kmallocs); 475 if (REISERFS_SB(s)->s_kmallocs != 0) {
460 } 476 reiserfs_warning(s,
461 477 "vs-2004: reiserfs_put_super: allocated memory left %d",
462 if (REISERFS_SB(s)->reserved_blocks != 0) { 478 REISERFS_SB(s)->s_kmallocs);
463 reiserfs_warning (s, "green-2005: reiserfs_put_super: reserved blocks left %d", 479 }
464 REISERFS_SB(s)->reserved_blocks); 480
465 } 481 if (REISERFS_SB(s)->reserved_blocks != 0) {
466 482 reiserfs_warning(s,
467 reiserfs_proc_info_done( s ); 483 "green-2005: reiserfs_put_super: reserved blocks left %d",
468 484 REISERFS_SB(s)->reserved_blocks);
469 kfree(s->s_fs_info); 485 }
470 s->s_fs_info = NULL; 486
471 487 reiserfs_proc_info_done(s);
472 return; 488
489 kfree(s->s_fs_info);
490 s->s_fs_info = NULL;
491
492 return;
473} 493}
474 494
475static kmem_cache_t * reiserfs_inode_cachep; 495static kmem_cache_t *reiserfs_inode_cachep;
476 496
477static struct inode *reiserfs_alloc_inode(struct super_block *sb) 497static struct inode *reiserfs_alloc_inode(struct super_block *sb)
478{ 498{
479 struct reiserfs_inode_info *ei; 499 struct reiserfs_inode_info *ei;
480 ei = (struct reiserfs_inode_info *)kmem_cache_alloc(reiserfs_inode_cachep, SLAB_KERNEL); 500 ei = (struct reiserfs_inode_info *)
501 kmem_cache_alloc(reiserfs_inode_cachep, SLAB_KERNEL);
481 if (!ei) 502 if (!ei)
482 return NULL; 503 return NULL;
483 return &ei->vfs_inode; 504 return &ei->vfs_inode;
@@ -488,25 +509,26 @@ static void reiserfs_destroy_inode(struct inode *inode)
488 kmem_cache_free(reiserfs_inode_cachep, REISERFS_I(inode)); 509 kmem_cache_free(reiserfs_inode_cachep, REISERFS_I(inode));
489} 510}
490 511
491static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags) 512static void init_once(void *foo, kmem_cache_t * cachep, unsigned long flags)
492{ 513{
493 struct reiserfs_inode_info *ei = (struct reiserfs_inode_info *) foo; 514 struct reiserfs_inode_info *ei = (struct reiserfs_inode_info *)foo;
494 515
495 if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == 516 if ((flags & (SLAB_CTOR_VERIFY | SLAB_CTOR_CONSTRUCTOR)) ==
496 SLAB_CTOR_CONSTRUCTOR) { 517 SLAB_CTOR_CONSTRUCTOR) {
497 INIT_LIST_HEAD(&ei->i_prealloc_list) ; 518 INIT_LIST_HEAD(&ei->i_prealloc_list);
498 inode_init_once(&ei->vfs_inode); 519 inode_init_once(&ei->vfs_inode);
499 ei->i_acl_access = NULL; 520 ei->i_acl_access = NULL;
500 ei->i_acl_default = NULL; 521 ei->i_acl_default = NULL;
501 } 522 }
502} 523}
503 524
504static int init_inodecache(void) 525static int init_inodecache(void)
505{ 526{
506 reiserfs_inode_cachep = kmem_cache_create("reiser_inode_cache", 527 reiserfs_inode_cachep = kmem_cache_create("reiser_inode_cache",
507 sizeof(struct reiserfs_inode_info), 528 sizeof(struct
508 0, SLAB_RECLAIM_ACCOUNT, 529 reiserfs_inode_info),
509 init_once, NULL); 530 0, SLAB_RECLAIM_ACCOUNT,
531 init_once, NULL);
510 if (reiserfs_inode_cachep == NULL) 532 if (reiserfs_inode_cachep == NULL)
511 return -ENOMEM; 533 return -ENOMEM;
512 return 0; 534 return 0;
@@ -515,72 +537,76 @@ static int init_inodecache(void)
515static void destroy_inodecache(void) 537static void destroy_inodecache(void)
516{ 538{
517 if (kmem_cache_destroy(reiserfs_inode_cachep)) 539 if (kmem_cache_destroy(reiserfs_inode_cachep))
518 reiserfs_warning (NULL, "reiserfs_inode_cache: not all structures were freed"); 540 reiserfs_warning(NULL,
541 "reiserfs_inode_cache: not all structures were freed");
519} 542}
520 543
521/* we don't mark inodes dirty, we just log them */ 544/* we don't mark inodes dirty, we just log them */
522static void reiserfs_dirty_inode (struct inode * inode) { 545static void reiserfs_dirty_inode(struct inode *inode)
523 struct reiserfs_transaction_handle th ; 546{
524 547 struct reiserfs_transaction_handle th;
525 int err = 0; 548
526 if (inode->i_sb->s_flags & MS_RDONLY) { 549 int err = 0;
527 reiserfs_warning(inode->i_sb, "clm-6006: writing inode %lu on readonly FS", 550 if (inode->i_sb->s_flags & MS_RDONLY) {
528 inode->i_ino) ; 551 reiserfs_warning(inode->i_sb,
529 return ; 552 "clm-6006: writing inode %lu on readonly FS",
530 } 553 inode->i_ino);
531 reiserfs_write_lock(inode->i_sb); 554 return;
532 555 }
533 /* this is really only used for atime updates, so they don't have 556 reiserfs_write_lock(inode->i_sb);
534 ** to be included in O_SYNC or fsync 557
535 */ 558 /* this is really only used for atime updates, so they don't have
536 err = journal_begin(&th, inode->i_sb, 1) ; 559 ** to be included in O_SYNC or fsync
537 if (err) { 560 */
538 reiserfs_write_unlock (inode->i_sb); 561 err = journal_begin(&th, inode->i_sb, 1);
539 return; 562 if (err) {
540 } 563 reiserfs_write_unlock(inode->i_sb);
541 reiserfs_update_sd (&th, inode); 564 return;
542 journal_end(&th, inode->i_sb, 1) ; 565 }
543 reiserfs_write_unlock(inode->i_sb); 566 reiserfs_update_sd(&th, inode);
567 journal_end(&th, inode->i_sb, 1);
568 reiserfs_write_unlock(inode->i_sb);
544} 569}
545 570
546static void reiserfs_clear_inode (struct inode *inode) 571static void reiserfs_clear_inode(struct inode *inode)
547{ 572{
548 struct posix_acl *acl; 573 struct posix_acl *acl;
549 574
550 acl = REISERFS_I(inode)->i_acl_access; 575 acl = REISERFS_I(inode)->i_acl_access;
551 if (acl && !IS_ERR (acl)) 576 if (acl && !IS_ERR(acl))
552 posix_acl_release (acl); 577 posix_acl_release(acl);
553 REISERFS_I(inode)->i_acl_access = NULL; 578 REISERFS_I(inode)->i_acl_access = NULL;
554 579
555 acl = REISERFS_I(inode)->i_acl_default; 580 acl = REISERFS_I(inode)->i_acl_default;
556 if (acl && !IS_ERR (acl)) 581 if (acl && !IS_ERR(acl))
557 posix_acl_release (acl); 582 posix_acl_release(acl);
558 REISERFS_I(inode)->i_acl_default = NULL; 583 REISERFS_I(inode)->i_acl_default = NULL;
559} 584}
560 585
561#ifdef CONFIG_QUOTA 586#ifdef CONFIG_QUOTA
562static ssize_t reiserfs_quota_write(struct super_block *, int, const char *, size_t, loff_t); 587static ssize_t reiserfs_quota_write(struct super_block *, int, const char *,
563static ssize_t reiserfs_quota_read(struct super_block *, int, char *, size_t, loff_t); 588 size_t, loff_t);
589static ssize_t reiserfs_quota_read(struct super_block *, int, char *, size_t,
590 loff_t);
564#endif 591#endif
565 592
566static struct super_operations reiserfs_sops = 593static struct super_operations reiserfs_sops = {
567{ 594 .alloc_inode = reiserfs_alloc_inode,
568 .alloc_inode = reiserfs_alloc_inode, 595 .destroy_inode = reiserfs_destroy_inode,
569 .destroy_inode = reiserfs_destroy_inode, 596 .write_inode = reiserfs_write_inode,
570 .write_inode = reiserfs_write_inode, 597 .dirty_inode = reiserfs_dirty_inode,
571 .dirty_inode = reiserfs_dirty_inode, 598 .delete_inode = reiserfs_delete_inode,
572 .delete_inode = reiserfs_delete_inode, 599 .clear_inode = reiserfs_clear_inode,
573 .clear_inode = reiserfs_clear_inode, 600 .put_super = reiserfs_put_super,
574 .put_super = reiserfs_put_super, 601 .write_super = reiserfs_write_super,
575 .write_super = reiserfs_write_super, 602 .sync_fs = reiserfs_sync_fs,
576 .sync_fs = reiserfs_sync_fs, 603 .write_super_lockfs = reiserfs_write_super_lockfs,
577 .write_super_lockfs = reiserfs_write_super_lockfs, 604 .unlockfs = reiserfs_unlockfs,
578 .unlockfs = reiserfs_unlockfs, 605 .statfs = reiserfs_statfs,
579 .statfs = reiserfs_statfs, 606 .remount_fs = reiserfs_remount,
580 .remount_fs = reiserfs_remount,
581#ifdef CONFIG_QUOTA 607#ifdef CONFIG_QUOTA
582 .quota_read = reiserfs_quota_read, 608 .quota_read = reiserfs_quota_read,
583 .quota_write = reiserfs_quota_write, 609 .quota_write = reiserfs_quota_write,
584#endif 610#endif
585}; 611};
586 612
@@ -596,50 +622,48 @@ static int reiserfs_mark_dquot_dirty(struct dquot *);
596static int reiserfs_write_info(struct super_block *, int); 622static int reiserfs_write_info(struct super_block *, int);
597static int reiserfs_quota_on(struct super_block *, int, int, char *); 623static int reiserfs_quota_on(struct super_block *, int, int, char *);
598 624
599static struct dquot_operations reiserfs_quota_operations = 625static struct dquot_operations reiserfs_quota_operations = {
600{ 626 .initialize = reiserfs_dquot_initialize,
601 .initialize = reiserfs_dquot_initialize, 627 .drop = reiserfs_dquot_drop,
602 .drop = reiserfs_dquot_drop, 628 .alloc_space = dquot_alloc_space,
603 .alloc_space = dquot_alloc_space, 629 .alloc_inode = dquot_alloc_inode,
604 .alloc_inode = dquot_alloc_inode, 630 .free_space = dquot_free_space,
605 .free_space = dquot_free_space, 631 .free_inode = dquot_free_inode,
606 .free_inode = dquot_free_inode, 632 .transfer = dquot_transfer,
607 .transfer = dquot_transfer, 633 .write_dquot = reiserfs_write_dquot,
608 .write_dquot = reiserfs_write_dquot, 634 .acquire_dquot = reiserfs_acquire_dquot,
609 .acquire_dquot = reiserfs_acquire_dquot, 635 .release_dquot = reiserfs_release_dquot,
610 .release_dquot = reiserfs_release_dquot, 636 .mark_dirty = reiserfs_mark_dquot_dirty,
611 .mark_dirty = reiserfs_mark_dquot_dirty, 637 .write_info = reiserfs_write_info,
612 .write_info = reiserfs_write_info,
613}; 638};
614 639
615static struct quotactl_ops reiserfs_qctl_operations = 640static struct quotactl_ops reiserfs_qctl_operations = {
616{ 641 .quota_on = reiserfs_quota_on,
617 .quota_on = reiserfs_quota_on, 642 .quota_off = vfs_quota_off,
618 .quota_off = vfs_quota_off, 643 .quota_sync = vfs_quota_sync,
619 .quota_sync = vfs_quota_sync, 644 .get_info = vfs_get_dqinfo,
620 .get_info = vfs_get_dqinfo, 645 .set_info = vfs_set_dqinfo,
621 .set_info = vfs_set_dqinfo, 646 .get_dqblk = vfs_get_dqblk,
622 .get_dqblk = vfs_get_dqblk, 647 .set_dqblk = vfs_set_dqblk,
623 .set_dqblk = vfs_set_dqblk,
624}; 648};
625#endif 649#endif
626 650
627static struct export_operations reiserfs_export_ops = { 651static struct export_operations reiserfs_export_ops = {
628 .encode_fh = reiserfs_encode_fh, 652 .encode_fh = reiserfs_encode_fh,
629 .decode_fh = reiserfs_decode_fh, 653 .decode_fh = reiserfs_decode_fh,
630 .get_parent = reiserfs_get_parent, 654 .get_parent = reiserfs_get_parent,
631 .get_dentry = reiserfs_get_dentry, 655 .get_dentry = reiserfs_get_dentry,
632} ; 656};
633 657
634/* this struct is used in reiserfs_getopt () for containing the value for those 658/* this struct is used in reiserfs_getopt () for containing the value for those
635 mount options that have values rather than being toggles. */ 659 mount options that have values rather than being toggles. */
636typedef struct { 660typedef struct {
637 char * value; 661 char *value;
638 int setmask; /* bitmask which is to set on mount_options bitmask when this 662 int setmask; /* bitmask which is to set on mount_options bitmask when this
639 value is found, 0 is no bits are to be changed. */ 663 value is found, 0 is no bits are to be changed. */
640 int clrmask; /* bitmask which is to clear on mount_options bitmask when this 664 int clrmask; /* bitmask which is to clear on mount_options bitmask when this
641 value is found, 0 is no bits are to be changed. This is 665 value is found, 0 is no bits are to be changed. This is
642 applied BEFORE setmask */ 666 applied BEFORE setmask */
643} arg_desc_t; 667} arg_desc_t;
644 668
645/* Set this bit in arg_required to allow empty arguments */ 669/* Set this bit in arg_required to allow empty arguments */
@@ -648,67 +672,70 @@ typedef struct {
648/* this struct is used in reiserfs_getopt() for describing the set of reiserfs 672/* this struct is used in reiserfs_getopt() for describing the set of reiserfs
649 mount options */ 673 mount options */
650typedef struct { 674typedef struct {
651 char * option_name; 675 char *option_name;
652 int arg_required; /* 0 if argument is not required, not 0 otherwise */ 676 int arg_required; /* 0 if argument is not required, not 0 otherwise */
653 const arg_desc_t * values; /* list of values accepted by an option */ 677 const arg_desc_t *values; /* list of values accepted by an option */
654 int setmask; /* bitmask which is to set on mount_options bitmask when this 678 int setmask; /* bitmask which is to set on mount_options bitmask when this
655 value is found, 0 is no bits are to be changed. */ 679 value is found, 0 is no bits are to be changed. */
656 int clrmask; /* bitmask which is to clear on mount_options bitmask when this 680 int clrmask; /* bitmask which is to clear on mount_options bitmask when this
657 value is found, 0 is no bits are to be changed. This is 681 value is found, 0 is no bits are to be changed. This is
658 applied BEFORE setmask */ 682 applied BEFORE setmask */
659} opt_desc_t; 683} opt_desc_t;
660 684
661/* possible values for -o data= */ 685/* possible values for -o data= */
662static const arg_desc_t logging_mode[] = { 686static const arg_desc_t logging_mode[] = {
663 {"ordered", 1<<REISERFS_DATA_ORDERED, (1<<REISERFS_DATA_LOG|1<<REISERFS_DATA_WRITEBACK)}, 687 {"ordered", 1 << REISERFS_DATA_ORDERED,
664 {"journal", 1<<REISERFS_DATA_LOG, (1<<REISERFS_DATA_ORDERED|1<<REISERFS_DATA_WRITEBACK)}, 688 (1 << REISERFS_DATA_LOG | 1 << REISERFS_DATA_WRITEBACK)},
665 {"writeback", 1<<REISERFS_DATA_WRITEBACK, (1<<REISERFS_DATA_ORDERED|1<<REISERFS_DATA_LOG)}, 689 {"journal", 1 << REISERFS_DATA_LOG,
666 {NULL, 0} 690 (1 << REISERFS_DATA_ORDERED | 1 << REISERFS_DATA_WRITEBACK)},
691 {"writeback", 1 << REISERFS_DATA_WRITEBACK,
692 (1 << REISERFS_DATA_ORDERED | 1 << REISERFS_DATA_LOG)},
693 {NULL, 0}
667}; 694};
668 695
669/* possible values for -o barrier= */ 696/* possible values for -o barrier= */
670static const arg_desc_t barrier_mode[] = { 697static const arg_desc_t barrier_mode[] = {
671 {"none", 1<<REISERFS_BARRIER_NONE, 1<<REISERFS_BARRIER_FLUSH}, 698 {"none", 1 << REISERFS_BARRIER_NONE, 1 << REISERFS_BARRIER_FLUSH},
672 {"flush", 1<<REISERFS_BARRIER_FLUSH, 1<<REISERFS_BARRIER_NONE}, 699 {"flush", 1 << REISERFS_BARRIER_FLUSH, 1 << REISERFS_BARRIER_NONE},
673 {NULL, 0} 700 {NULL, 0}
674}; 701};
675 702
676/* possible values for "-o block-allocator=" and bits which are to be set in 703/* possible values for "-o block-allocator=" and bits which are to be set in
677 s_mount_opt of reiserfs specific part of in-core super block */ 704 s_mount_opt of reiserfs specific part of in-core super block */
678static const arg_desc_t balloc[] = { 705static const arg_desc_t balloc[] = {
679 {"noborder", 1<<REISERFS_NO_BORDER, 0}, 706 {"noborder", 1 << REISERFS_NO_BORDER, 0},
680 {"border", 0, 1<<REISERFS_NO_BORDER}, 707 {"border", 0, 1 << REISERFS_NO_BORDER},
681 {"no_unhashed_relocation", 1<<REISERFS_NO_UNHASHED_RELOCATION, 0}, 708 {"no_unhashed_relocation", 1 << REISERFS_NO_UNHASHED_RELOCATION, 0},
682 {"hashed_relocation", 1<<REISERFS_HASHED_RELOCATION, 0}, 709 {"hashed_relocation", 1 << REISERFS_HASHED_RELOCATION, 0},
683 {"test4", 1<<REISERFS_TEST4, 0}, 710 {"test4", 1 << REISERFS_TEST4, 0},
684 {"notest4", 0, 1<<REISERFS_TEST4}, 711 {"notest4", 0, 1 << REISERFS_TEST4},
685 {NULL, 0, 0} 712 {NULL, 0, 0}
686}; 713};
687 714
688static const arg_desc_t tails[] = { 715static const arg_desc_t tails[] = {
689 {"on", 1<<REISERFS_LARGETAIL, 1<<REISERFS_SMALLTAIL}, 716 {"on", 1 << REISERFS_LARGETAIL, 1 << REISERFS_SMALLTAIL},
690 {"off", 0, (1<<REISERFS_LARGETAIL)|(1<<REISERFS_SMALLTAIL)}, 717 {"off", 0, (1 << REISERFS_LARGETAIL) | (1 << REISERFS_SMALLTAIL)},
691 {"small", 1<<REISERFS_SMALLTAIL, 1<<REISERFS_LARGETAIL}, 718 {"small", 1 << REISERFS_SMALLTAIL, 1 << REISERFS_LARGETAIL},
692 {NULL, 0, 0} 719 {NULL, 0, 0}
693}; 720};
694 721
695static const arg_desc_t error_actions[] = { 722static const arg_desc_t error_actions[] = {
696 {"panic", 1 << REISERFS_ERROR_PANIC, 723 {"panic", 1 << REISERFS_ERROR_PANIC,
697 (1 << REISERFS_ERROR_RO | 1 << REISERFS_ERROR_CONTINUE)}, 724 (1 << REISERFS_ERROR_RO | 1 << REISERFS_ERROR_CONTINUE)},
698 {"ro-remount", 1 << REISERFS_ERROR_RO, 725 {"ro-remount", 1 << REISERFS_ERROR_RO,
699 (1 << REISERFS_ERROR_PANIC | 1 << REISERFS_ERROR_CONTINUE)}, 726 (1 << REISERFS_ERROR_PANIC | 1 << REISERFS_ERROR_CONTINUE)},
700#ifdef REISERFS_JOURNAL_ERROR_ALLOWS_NO_LOG 727#ifdef REISERFS_JOURNAL_ERROR_ALLOWS_NO_LOG
701 {"continue", 1 << REISERFS_ERROR_CONTINUE, 728 {"continue", 1 << REISERFS_ERROR_CONTINUE,
702 (1 << REISERFS_ERROR_PANIC | 1 << REISERFS_ERROR_RO)}, 729 (1 << REISERFS_ERROR_PANIC | 1 << REISERFS_ERROR_RO)},
703#endif 730#endif
704 {NULL, 0, 0}, 731 {NULL, 0, 0},
705}; 732};
706 733
707int reiserfs_default_io_size = 128 * 1024; /* Default recommended I/O size is 128k. 734int reiserfs_default_io_size = 128 * 1024; /* Default recommended I/O size is 128k.
708 There might be broken applications that are 735 There might be broken applications that are
709 confused by this. Use nolargeio mount option 736 confused by this. Use nolargeio mount option
710 to get usual i/o size = PAGE_SIZE. 737 to get usual i/o size = PAGE_SIZE.
711 */ 738 */
712 739
713/* proceed only one option from a list *cur - string containing of mount options 740/* proceed only one option from a list *cur - string containing of mount options
714 opts - array of options which are accepted 741 opts - array of options which are accepted
@@ -716,486 +743,530 @@ int reiserfs_default_io_size = 128 * 1024; /* Default recommended I/O size is 12
716 in the input - pointer to the argument is stored here 743 in the input - pointer to the argument is stored here
717 bit_flags - if option requires to set a certain bit - it is set here 744 bit_flags - if option requires to set a certain bit - it is set here
718 return -1 if unknown option is found, opt->arg_required otherwise */ 745 return -1 if unknown option is found, opt->arg_required otherwise */
719static int reiserfs_getopt ( struct super_block * s, char ** cur, opt_desc_t * opts, char ** opt_arg, 746static int reiserfs_getopt(struct super_block *s, char **cur, opt_desc_t * opts,
720 unsigned long * bit_flags) 747 char **opt_arg, unsigned long *bit_flags)
721{ 748{
722 char * p; 749 char *p;
723 /* foo=bar, 750 /* foo=bar,
724 ^ ^ ^ 751 ^ ^ ^
725 | | +-- option_end 752 | | +-- option_end
726 | +-- arg_start 753 | +-- arg_start
727 +-- option_start 754 +-- option_start
728 */ 755 */
729 const opt_desc_t * opt; 756 const opt_desc_t *opt;
730 const arg_desc_t * arg; 757 const arg_desc_t *arg;
731 758
732 759 p = *cur;
733 p = *cur; 760
734 761 /* assume argument cannot contain commas */
735 /* assume argument cannot contain commas */ 762 *cur = strchr(p, ',');
736 *cur = strchr (p, ','); 763 if (*cur) {
737 if (*cur) { 764 *(*cur) = '\0';
738 *(*cur) = '\0'; 765 (*cur)++;
739 (*cur) ++; 766 }
740 } 767
741 768 if (!strncmp(p, "alloc=", 6)) {
742 if ( !strncmp (p, "alloc=", 6) ) { 769 /* Ugly special case, probably we should redo options parser so that
743 /* Ugly special case, probably we should redo options parser so that 770 it can understand several arguments for some options, also so that
744 it can understand several arguments for some options, also so that 771 it can fill several bitfields with option values. */
745 it can fill several bitfields with option values. */ 772 if (reiserfs_parse_alloc_options(s, p + 6)) {
746 if ( reiserfs_parse_alloc_options( s, p + 6) ) { 773 return -1;
747 return -1; 774 } else {
748 } else { 775 return 0;
749 return 0; 776 }
750 } 777 }
751 } 778
752 779 /* for every option in the list */
753 780 for (opt = opts; opt->option_name; opt++) {
754 /* for every option in the list */ 781 if (!strncmp(p, opt->option_name, strlen(opt->option_name))) {
755 for (opt = opts; opt->option_name; opt ++) { 782 if (bit_flags) {
756 if (!strncmp (p, opt->option_name, strlen (opt->option_name))) { 783 if (opt->clrmask ==
757 if (bit_flags) { 784 (1 << REISERFS_UNSUPPORTED_OPT))
758 if (opt->clrmask == (1 << REISERFS_UNSUPPORTED_OPT)) 785 reiserfs_warning(s, "%s not supported.",
759 reiserfs_warning (s, "%s not supported.", p); 786 p);
760 else 787 else
761 *bit_flags &= ~opt->clrmask; 788 *bit_flags &= ~opt->clrmask;
762 if (opt->setmask == (1 << REISERFS_UNSUPPORTED_OPT)) 789 if (opt->setmask ==
763 reiserfs_warning (s, "%s not supported.", p); 790 (1 << REISERFS_UNSUPPORTED_OPT))
764 else 791 reiserfs_warning(s, "%s not supported.",
765 *bit_flags |= opt->setmask; 792 p);
766 } 793 else
767 break; 794 *bit_flags |= opt->setmask;
768 } 795 }
769 } 796 break;
770 if (!opt->option_name) { 797 }
771 reiserfs_warning (s, "unknown mount option \"%s\"", p); 798 }
772 return -1; 799 if (!opt->option_name) {
773 } 800 reiserfs_warning(s, "unknown mount option \"%s\"", p);
774 801 return -1;
775 p += strlen (opt->option_name); 802 }
776 switch (*p) { 803
777 case '=': 804 p += strlen(opt->option_name);
778 if (!opt->arg_required) { 805 switch (*p) {
779 reiserfs_warning (s, "the option \"%s\" does not require an argument", 806 case '=':
780 opt->option_name); 807 if (!opt->arg_required) {
781 return -1; 808 reiserfs_warning(s,
782 } 809 "the option \"%s\" does not require an argument",
783 break; 810 opt->option_name);
784 811 return -1;
785 case 0: 812 }
786 if (opt->arg_required) { 813 break;
787 reiserfs_warning (s, "the option \"%s\" requires an argument", opt->option_name); 814
788 return -1; 815 case 0:
789 } 816 if (opt->arg_required) {
790 break; 817 reiserfs_warning(s,
791 default: 818 "the option \"%s\" requires an argument",
792 reiserfs_warning (s, "head of option \"%s\" is only correct", opt->option_name); 819 opt->option_name);
793 return -1; 820 return -1;
794 } 821 }
795 822 break;
796 /* move to the argument, or to next option if argument is not required */ 823 default:
797 p ++; 824 reiserfs_warning(s, "head of option \"%s\" is only correct",
798 825 opt->option_name);
799 if ( opt->arg_required && !(opt->arg_required & (1<<REISERFS_OPT_ALLOWEMPTY)) && !strlen (p) ) { 826 return -1;
800 /* this catches "option=," if not allowed */ 827 }
801 reiserfs_warning (s, "empty argument for \"%s\"", opt->option_name); 828
829 /* move to the argument, or to next option if argument is not required */
830 p++;
831
832 if (opt->arg_required
833 && !(opt->arg_required & (1 << REISERFS_OPT_ALLOWEMPTY))
834 && !strlen(p)) {
835 /* this catches "option=," if not allowed */
836 reiserfs_warning(s, "empty argument for \"%s\"",
837 opt->option_name);
838 return -1;
839 }
840
841 if (!opt->values) {
842 /* *=NULLopt_arg contains pointer to argument */
843 *opt_arg = p;
844 return opt->arg_required & ~(1 << REISERFS_OPT_ALLOWEMPTY);
845 }
846
847 /* values possible for this option are listed in opt->values */
848 for (arg = opt->values; arg->value; arg++) {
849 if (!strcmp(p, arg->value)) {
850 if (bit_flags) {
851 *bit_flags &= ~arg->clrmask;
852 *bit_flags |= arg->setmask;
853 }
854 return opt->arg_required;
855 }
856 }
857
858 reiserfs_warning(s, "bad value \"%s\" for option \"%s\"", p,
859 opt->option_name);
802 return -1; 860 return -1;
803 }
804
805 if (!opt->values) {
806 /* *=NULLopt_arg contains pointer to argument */
807 *opt_arg = p;
808 return opt->arg_required & ~(1<<REISERFS_OPT_ALLOWEMPTY);
809 }
810
811 /* values possible for this option are listed in opt->values */
812 for (arg = opt->values; arg->value; arg ++) {
813 if (!strcmp (p, arg->value)) {
814 if (bit_flags) {
815 *bit_flags &= ~arg->clrmask;
816 *bit_flags |= arg->setmask;
817 }
818 return opt->arg_required;
819 }
820 }
821
822 reiserfs_warning (s, "bad value \"%s\" for option \"%s\"", p, opt->option_name);
823 return -1;
824} 861}
825 862
826/* returns 0 if something is wrong in option string, 1 - otherwise */ 863/* returns 0 if something is wrong in option string, 1 - otherwise */
827static int reiserfs_parse_options (struct super_block * s, char * options, /* string given via mount's -o */ 864static int reiserfs_parse_options(struct super_block *s, char *options, /* string given via mount's -o */
828 unsigned long * mount_options, 865 unsigned long *mount_options,
829 /* after the parsing phase, contains the 866 /* after the parsing phase, contains the
830 collection of bitflags defining what 867 collection of bitflags defining what
831 mount options were selected. */ 868 mount options were selected. */
832 unsigned long * blocks, /* strtol-ed from NNN of resize=NNN */ 869 unsigned long *blocks, /* strtol-ed from NNN of resize=NNN */
833 char ** jdev_name, 870 char **jdev_name,
834 unsigned int * commit_max_age) 871 unsigned int *commit_max_age)
835{ 872{
836 int c; 873 int c;
837 char * arg = NULL; 874 char *arg = NULL;
838 char * pos; 875 char *pos;
839 opt_desc_t opts[] = { 876 opt_desc_t opts[] = {
840 /* Compatibility stuff, so that -o notail for old setups still work */ 877 /* Compatibility stuff, so that -o notail for old setups still work */
841 {"tails", .arg_required = 't', .values = tails}, 878 {"tails",.arg_required = 't',.values = tails},
842 {"notail", .clrmask = (1<<REISERFS_LARGETAIL)|(1<<REISERFS_SMALLTAIL)}, 879 {"notail",.clrmask =
843 {"conv", .setmask = 1<<REISERFS_CONVERT}, 880 (1 << REISERFS_LARGETAIL) | (1 << REISERFS_SMALLTAIL)},
844 {"attrs", .setmask = 1<<REISERFS_ATTRS}, 881 {"conv",.setmask = 1 << REISERFS_CONVERT},
845 {"noattrs", .clrmask = 1<<REISERFS_ATTRS}, 882 {"attrs",.setmask = 1 << REISERFS_ATTRS},
883 {"noattrs",.clrmask = 1 << REISERFS_ATTRS},
846#ifdef CONFIG_REISERFS_FS_XATTR 884#ifdef CONFIG_REISERFS_FS_XATTR
847 {"user_xattr", .setmask = 1<<REISERFS_XATTRS_USER}, 885 {"user_xattr",.setmask = 1 << REISERFS_XATTRS_USER},
848 {"nouser_xattr",.clrmask = 1<<REISERFS_XATTRS_USER}, 886 {"nouser_xattr",.clrmask = 1 << REISERFS_XATTRS_USER},
849#else 887#else
850 {"user_xattr", .setmask = 1<<REISERFS_UNSUPPORTED_OPT}, 888 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
851 {"nouser_xattr",.clrmask = 1<<REISERFS_UNSUPPORTED_OPT}, 889 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
852#endif 890#endif
853#ifdef CONFIG_REISERFS_FS_POSIX_ACL 891#ifdef CONFIG_REISERFS_FS_POSIX_ACL
854 {"acl", .setmask = 1<<REISERFS_POSIXACL}, 892 {"acl",.setmask = 1 << REISERFS_POSIXACL},
855 {"noacl", .clrmask = 1<<REISERFS_POSIXACL}, 893 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
856#else 894#else
857 {"acl", .setmask = 1<<REISERFS_UNSUPPORTED_OPT}, 895 {"acl",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
858 {"noacl", .clrmask = 1<<REISERFS_UNSUPPORTED_OPT}, 896 {"noacl",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
859#endif 897#endif
860 {"nolog",}, /* This is unsupported */ 898 {"nolog",}, /* This is unsupported */
861 {"replayonly", .setmask = 1<<REPLAYONLY}, 899 {"replayonly",.setmask = 1 << REPLAYONLY},
862 {"block-allocator", .arg_required = 'a', .values = balloc}, 900 {"block-allocator",.arg_required = 'a',.values = balloc},
863 {"data", .arg_required = 'd', .values = logging_mode}, 901 {"data",.arg_required = 'd',.values = logging_mode},
864 {"barrier", .arg_required = 'b', .values = barrier_mode}, 902 {"barrier",.arg_required = 'b',.values = barrier_mode},
865 {"resize", .arg_required = 'r', .values = NULL}, 903 {"resize",.arg_required = 'r',.values = NULL},
866 {"jdev", .arg_required = 'j', .values = NULL}, 904 {"jdev",.arg_required = 'j',.values = NULL},
867 {"nolargeio", .arg_required = 'w', .values = NULL}, 905 {"nolargeio",.arg_required = 'w',.values = NULL},
868 {"commit", .arg_required = 'c', .values = NULL}, 906 {"commit",.arg_required = 'c',.values = NULL},
869 {"usrquota", .setmask = 1<<REISERFS_QUOTA}, 907 {"usrquota",.setmask = 1 << REISERFS_QUOTA},
870 {"grpquota", .setmask = 1<<REISERFS_QUOTA}, 908 {"grpquota",.setmask = 1 << REISERFS_QUOTA},
871 {"noquota", .clrmask = 1<<REISERFS_QUOTA}, 909 {"noquota",.clrmask = 1 << REISERFS_QUOTA},
872 {"errors", .arg_required = 'e', .values = error_actions}, 910 {"errors",.arg_required = 'e',.values = error_actions},
873 {"usrjquota", .arg_required = 'u'|(1<<REISERFS_OPT_ALLOWEMPTY), .values = NULL}, 911 {"usrjquota",.arg_required =
874 {"grpjquota", .arg_required = 'g'|(1<<REISERFS_OPT_ALLOWEMPTY), .values = NULL}, 912 'u' | (1 << REISERFS_OPT_ALLOWEMPTY),.values = NULL},
875 {"jqfmt", .arg_required = 'f', .values = NULL}, 913 {"grpjquota",.arg_required =
876 {NULL,} 914 'g' | (1 << REISERFS_OPT_ALLOWEMPTY),.values = NULL},
877 }; 915 {"jqfmt",.arg_required = 'f',.values = NULL},
878 916 {NULL,}
879 *blocks = 0; 917 };
880 if (!options || !*options) 918
881 /* use default configuration: create tails, journaling on, no 919 *blocks = 0;
882 conversion to newest format */ 920 if (!options || !*options)
883 return 1; 921 /* use default configuration: create tails, journaling on, no
884 922 conversion to newest format */
885 for (pos = options; pos; ) { 923 return 1;
886 c = reiserfs_getopt (s, &pos, opts, &arg, mount_options); 924
887 if (c == -1) 925 for (pos = options; pos;) {
888 /* wrong option is given */ 926 c = reiserfs_getopt(s, &pos, opts, &arg, mount_options);
889 return 0; 927 if (c == -1)
890 928 /* wrong option is given */
891 if (c == 'r') {
892 char * p;
893
894 p = NULL;
895 /* "resize=NNN" or "resize=auto" */
896
897 if (!strcmp(arg, "auto")) {
898 /* From JFS code, to auto-get the size.*/
899 *blocks = s->s_bdev->bd_inode->i_size >> s->s_blocksize_bits;
900 } else {
901 *blocks = simple_strtoul (arg, &p, 0);
902 if (*p != '\0') {
903 /* NNN does not look like a number */
904 reiserfs_warning (s, "reiserfs_parse_options: bad value %s", arg);
905 return 0; 929 return 0;
906 }
907 }
908 }
909 930
910 if ( c == 'c' ) { 931 if (c == 'r') {
911 char *p = NULL; 932 char *p;
912 unsigned long val = simple_strtoul (arg, &p, 0); 933
913 /* commit=NNN (time in seconds) */ 934 p = NULL;
914 if ( *p != '\0' || val >= (unsigned int)-1) { 935 /* "resize=NNN" or "resize=auto" */
915 reiserfs_warning (s, "reiserfs_parse_options: bad value %s", arg); 936
916 return 0; 937 if (!strcmp(arg, "auto")) {
938 /* From JFS code, to auto-get the size. */
939 *blocks =
940 s->s_bdev->bd_inode->i_size >> s->
941 s_blocksize_bits;
942 } else {
943 *blocks = simple_strtoul(arg, &p, 0);
944 if (*p != '\0') {
945 /* NNN does not look like a number */
946 reiserfs_warning(s,
947 "reiserfs_parse_options: bad value %s",
948 arg);
949 return 0;
950 }
951 }
917 } 952 }
918 *commit_max_age = (unsigned int)val;
919 }
920 953
921 if ( c == 'w' ) { 954 if (c == 'c') {
922 char *p=NULL; 955 char *p = NULL;
923 int val = simple_strtoul (arg, &p, 0); 956 unsigned long val = simple_strtoul(arg, &p, 0);
924 957 /* commit=NNN (time in seconds) */
925 if ( *p != '\0') { 958 if (*p != '\0' || val >= (unsigned int)-1) {
926 reiserfs_warning (s, "reiserfs_parse_options: non-numeric value %s for nolargeio option", arg); 959 reiserfs_warning(s,
927 return 0; 960 "reiserfs_parse_options: bad value %s",
961 arg);
962 return 0;
963 }
964 *commit_max_age = (unsigned int)val;
928 } 965 }
929 if ( val )
930 reiserfs_default_io_size = PAGE_SIZE;
931 else
932 reiserfs_default_io_size = 128 * 1024;
933 }
934 966
935 if (c == 'j') { 967 if (c == 'w') {
936 if (arg && *arg && jdev_name) { 968 char *p = NULL;
937 if ( *jdev_name ) { //Hm, already assigned? 969 int val = simple_strtoul(arg, &p, 0);
938 reiserfs_warning (s, "reiserfs_parse_options: journal device was already specified to be %s", *jdev_name); 970
939 return 0; 971 if (*p != '\0') {
972 reiserfs_warning(s,
973 "reiserfs_parse_options: non-numeric value %s for nolargeio option",
974 arg);
975 return 0;
976 }
977 if (val)
978 reiserfs_default_io_size = PAGE_SIZE;
979 else
980 reiserfs_default_io_size = 128 * 1024;
940 } 981 }
941 *jdev_name = arg;
942 }
943 }
944 982
945#ifdef CONFIG_QUOTA 983 if (c == 'j') {
946 if (c == 'u' || c == 'g') { 984 if (arg && *arg && jdev_name) {
947 int qtype = c == 'u' ? USRQUOTA : GRPQUOTA; 985 if (*jdev_name) { //Hm, already assigned?
948 986 reiserfs_warning(s,
949 if (sb_any_quota_enabled(s)) { 987 "reiserfs_parse_options: journal device was already specified to be %s",
950 reiserfs_warning(s, "reiserfs_parse_options: cannot change journalled quota options when quota turned on."); 988 *jdev_name);
951 return 0; 989 return 0;
952 } 990 }
953 if (*arg) { /* Some filename specified? */ 991 *jdev_name = arg;
954 if (REISERFS_SB(s)->s_qf_names[qtype] && strcmp(REISERFS_SB(s)->s_qf_names[qtype], arg)) { 992 }
955 reiserfs_warning(s, "reiserfs_parse_options: %s quota file already specified.", QTYPE2NAME(qtype));
956 return 0;
957 } 993 }
958 if (strchr(arg, '/')) { 994#ifdef CONFIG_QUOTA
959 reiserfs_warning(s, "reiserfs_parse_options: quotafile must be on filesystem root."); 995 if (c == 'u' || c == 'g') {
960 return 0; 996 int qtype = c == 'u' ? USRQUOTA : GRPQUOTA;
997
998 if (sb_any_quota_enabled(s)) {
999 reiserfs_warning(s,
1000 "reiserfs_parse_options: cannot change journalled quota options when quota turned on.");
1001 return 0;
1002 }
1003 if (*arg) { /* Some filename specified? */
1004 if (REISERFS_SB(s)->s_qf_names[qtype]
1005 && strcmp(REISERFS_SB(s)->s_qf_names[qtype],
1006 arg)) {
1007 reiserfs_warning(s,
1008 "reiserfs_parse_options: %s quota file already specified.",
1009 QTYPE2NAME(qtype));
1010 return 0;
1011 }
1012 if (strchr(arg, '/')) {
1013 reiserfs_warning(s,
1014 "reiserfs_parse_options: quotafile must be on filesystem root.");
1015 return 0;
1016 }
1017 REISERFS_SB(s)->s_qf_names[qtype] =
1018 kmalloc(strlen(arg) + 1, GFP_KERNEL);
1019 if (!REISERFS_SB(s)->s_qf_names[qtype]) {
1020 reiserfs_warning(s,
1021 "reiserfs_parse_options: not enough memory for storing quotafile name.");
1022 return 0;
1023 }
1024 strcpy(REISERFS_SB(s)->s_qf_names[qtype], arg);
1025 *mount_options |= 1 << REISERFS_QUOTA;
1026 } else {
1027 if (REISERFS_SB(s)->s_qf_names[qtype]) {
1028 kfree(REISERFS_SB(s)->
1029 s_qf_names[qtype]);
1030 REISERFS_SB(s)->s_qf_names[qtype] =
1031 NULL;
1032 }
1033 }
961 } 1034 }
962 REISERFS_SB(s)->s_qf_names[qtype] = kmalloc(strlen(arg)+1, GFP_KERNEL); 1035 if (c == 'f') {
963 if (!REISERFS_SB(s)->s_qf_names[qtype]) { 1036 if (!strcmp(arg, "vfsold"))
964 reiserfs_warning(s, "reiserfs_parse_options: not enough memory for storing quotafile name."); 1037 REISERFS_SB(s)->s_jquota_fmt = QFMT_VFS_OLD;
965 return 0; 1038 else if (!strcmp(arg, "vfsv0"))
1039 REISERFS_SB(s)->s_jquota_fmt = QFMT_VFS_V0;
1040 else {
1041 reiserfs_warning(s,
1042 "reiserfs_parse_options: unknown quota format specified.");
1043 return 0;
1044 }
966 } 1045 }
967 strcpy(REISERFS_SB(s)->s_qf_names[qtype], arg); 1046#else
968 *mount_options |= 1<<REISERFS_QUOTA; 1047 if (c == 'u' || c == 'g' || c == 'f') {
969 } 1048 reiserfs_warning(s,
970 else { 1049 "reiserfs_parse_options: journalled quota options not supported.");
971 if (REISERFS_SB(s)->s_qf_names[qtype]) { 1050 return 0;
972 kfree(REISERFS_SB(s)->s_qf_names[qtype]);
973 REISERFS_SB(s)->s_qf_names[qtype] = NULL;
974 } 1051 }
975 } 1052#endif
976 } 1053 }
977 if (c == 'f') { 1054
978 if (!strcmp(arg, "vfsold")) 1055#ifdef CONFIG_QUOTA
979 REISERFS_SB(s)->s_jquota_fmt = QFMT_VFS_OLD; 1056 if (!REISERFS_SB(s)->s_jquota_fmt
980 else if (!strcmp(arg, "vfsv0")) 1057 && (REISERFS_SB(s)->s_qf_names[USRQUOTA]
981 REISERFS_SB(s)->s_jquota_fmt = QFMT_VFS_V0; 1058 || REISERFS_SB(s)->s_qf_names[GRPQUOTA])) {
982 else { 1059 reiserfs_warning(s,
983 reiserfs_warning(s, "reiserfs_parse_options: unknown quota format specified."); 1060 "reiserfs_parse_options: journalled quota format not specified.");
984 return 0; 1061 return 0;
985 }
986 } 1062 }
987#else 1063 /* This checking is not precise wrt the quota type but for our purposes it is sufficient */
988 if (c == 'u' || c == 'g' || c == 'f') { 1064 if (!(*mount_options & (1 << REISERFS_QUOTA))
989 reiserfs_warning(s, "reiserfs_parse_options: journalled quota options not supported."); 1065 && sb_any_quota_enabled(s)) {
990 return 0; 1066 reiserfs_warning(s,
1067 "reiserfs_parse_options: quota options must be present when quota is turned on.");
1068 return 0;
991 } 1069 }
992#endif 1070#endif
993 }
994
995#ifdef CONFIG_QUOTA
996 if (!REISERFS_SB(s)->s_jquota_fmt && (REISERFS_SB(s)->s_qf_names[USRQUOTA] || REISERFS_SB(s)->s_qf_names[GRPQUOTA])) {
997 reiserfs_warning(s, "reiserfs_parse_options: journalled quota format not specified.");
998 return 0;
999 }
1000 /* This checking is not precise wrt the quota type but for our purposes it is sufficient */
1001 if (!(*mount_options & (1<<REISERFS_QUOTA)) && sb_any_quota_enabled(s)) {
1002 reiserfs_warning(s, "reiserfs_parse_options: quota options must be present when quota is turned on.");
1003 return 0;
1004 }
1005#endif
1006 1071
1007 return 1; 1072 return 1;
1008} 1073}
1009 1074
1010static void switch_data_mode(struct super_block *s, unsigned long mode) { 1075static void switch_data_mode(struct super_block *s, unsigned long mode)
1011 REISERFS_SB(s)->s_mount_opt &= ~((1 << REISERFS_DATA_LOG) | 1076{
1012 (1 << REISERFS_DATA_ORDERED) | 1077 REISERFS_SB(s)->s_mount_opt &= ~((1 << REISERFS_DATA_LOG) |
1013 (1 << REISERFS_DATA_WRITEBACK)); 1078 (1 << REISERFS_DATA_ORDERED) |
1014 REISERFS_SB(s)->s_mount_opt |= (1 << mode); 1079 (1 << REISERFS_DATA_WRITEBACK));
1080 REISERFS_SB(s)->s_mount_opt |= (1 << mode);
1015} 1081}
1016 1082
1017static void handle_data_mode(struct super_block *s, unsigned long mount_options) 1083static void handle_data_mode(struct super_block *s, unsigned long mount_options)
1018{ 1084{
1019 if (mount_options & (1 << REISERFS_DATA_LOG)) { 1085 if (mount_options & (1 << REISERFS_DATA_LOG)) {
1020 if (!reiserfs_data_log(s)) { 1086 if (!reiserfs_data_log(s)) {
1021 switch_data_mode(s, REISERFS_DATA_LOG); 1087 switch_data_mode(s, REISERFS_DATA_LOG);
1022 reiserfs_info (s, "switching to journaled data mode\n"); 1088 reiserfs_info(s, "switching to journaled data mode\n");
1023 } 1089 }
1024 } else if (mount_options & (1 << REISERFS_DATA_ORDERED)) { 1090 } else if (mount_options & (1 << REISERFS_DATA_ORDERED)) {
1025 if (!reiserfs_data_ordered(s)) { 1091 if (!reiserfs_data_ordered(s)) {
1026 switch_data_mode(s, REISERFS_DATA_ORDERED); 1092 switch_data_mode(s, REISERFS_DATA_ORDERED);
1027 reiserfs_info (s, "switching to ordered data mode\n"); 1093 reiserfs_info(s, "switching to ordered data mode\n");
1028 } 1094 }
1029 } else if (mount_options & (1 << REISERFS_DATA_WRITEBACK)) { 1095 } else if (mount_options & (1 << REISERFS_DATA_WRITEBACK)) {
1030 if (!reiserfs_data_writeback(s)) { 1096 if (!reiserfs_data_writeback(s)) {
1031 switch_data_mode(s, REISERFS_DATA_WRITEBACK); 1097 switch_data_mode(s, REISERFS_DATA_WRITEBACK);
1032 reiserfs_info (s, "switching to writeback data mode\n"); 1098 reiserfs_info(s, "switching to writeback data mode\n");
1033 } 1099 }
1034 } 1100 }
1035} 1101}
1036 1102
1037static void handle_barrier_mode(struct super_block *s, unsigned long bits) { 1103static void handle_barrier_mode(struct super_block *s, unsigned long bits)
1038 int flush = (1 << REISERFS_BARRIER_FLUSH); 1104{
1039 int none = (1 << REISERFS_BARRIER_NONE); 1105 int flush = (1 << REISERFS_BARRIER_FLUSH);
1040 int all_barrier = flush | none; 1106 int none = (1 << REISERFS_BARRIER_NONE);
1041 1107 int all_barrier = flush | none;
1042 if (bits & all_barrier) { 1108
1043 REISERFS_SB(s)->s_mount_opt &= ~all_barrier; 1109 if (bits & all_barrier) {
1044 if (bits & flush) { 1110 REISERFS_SB(s)->s_mount_opt &= ~all_barrier;
1045 REISERFS_SB(s)->s_mount_opt |= flush; 1111 if (bits & flush) {
1046 printk("reiserfs: enabling write barrier flush mode\n"); 1112 REISERFS_SB(s)->s_mount_opt |= flush;
1047 } else if (bits & none) { 1113 printk("reiserfs: enabling write barrier flush mode\n");
1048 REISERFS_SB(s)->s_mount_opt |= none; 1114 } else if (bits & none) {
1049 printk("reiserfs: write barriers turned off\n"); 1115 REISERFS_SB(s)->s_mount_opt |= none;
1050 } 1116 printk("reiserfs: write barriers turned off\n");
1051 } 1117 }
1118 }
1052} 1119}
1053 1120
1054static void handle_attrs( struct super_block *s ) 1121static void handle_attrs(struct super_block *s)
1055{ 1122{
1056 struct reiserfs_super_block * rs = SB_DISK_SUPER_BLOCK (s); 1123 struct reiserfs_super_block *rs = SB_DISK_SUPER_BLOCK(s);
1057 1124
1058 if( reiserfs_attrs( s ) ) { 1125 if (reiserfs_attrs(s)) {
1059 if( old_format_only(s) ) { 1126 if (old_format_only(s)) {
1060 reiserfs_warning(s, "reiserfs: cannot support attributes on 3.5.x disk format" ); 1127 reiserfs_warning(s,
1061 REISERFS_SB(s) -> s_mount_opt &= ~ ( 1 << REISERFS_ATTRS ); 1128 "reiserfs: cannot support attributes on 3.5.x disk format");
1129 REISERFS_SB(s)->s_mount_opt &= ~(1 << REISERFS_ATTRS);
1062 return; 1130 return;
1063 } 1131 }
1064 if( !( le32_to_cpu( rs -> s_flags ) & reiserfs_attrs_cleared ) ) { 1132 if (!(le32_to_cpu(rs->s_flags) & reiserfs_attrs_cleared)) {
1065 reiserfs_warning(s, "reiserfs: cannot support attributes until flag is set in super-block" ); 1133 reiserfs_warning(s,
1066 REISERFS_SB(s) -> s_mount_opt &= ~ ( 1 << REISERFS_ATTRS ); 1134 "reiserfs: cannot support attributes until flag is set in super-block");
1135 REISERFS_SB(s)->s_mount_opt &= ~(1 << REISERFS_ATTRS);
1067 } 1136 }
1068 } else if (le32_to_cpu( rs -> s_flags ) & reiserfs_attrs_cleared) { 1137 } else if (le32_to_cpu(rs->s_flags) & reiserfs_attrs_cleared) {
1069 REISERFS_SB(s)->s_mount_opt |= REISERFS_ATTRS; 1138 REISERFS_SB(s)->s_mount_opt |= REISERFS_ATTRS;
1070 } 1139 }
1071} 1140}
1072 1141
1073static int reiserfs_remount (struct super_block * s, int * mount_flags, char * arg) 1142static int reiserfs_remount(struct super_block *s, int *mount_flags, char *arg)
1074{ 1143{
1075 struct reiserfs_super_block * rs; 1144 struct reiserfs_super_block *rs;
1076 struct reiserfs_transaction_handle th ; 1145 struct reiserfs_transaction_handle th;
1077 unsigned long blocks; 1146 unsigned long blocks;
1078 unsigned long mount_options = REISERFS_SB(s)->s_mount_opt; 1147 unsigned long mount_options = REISERFS_SB(s)->s_mount_opt;
1079 unsigned long safe_mask = 0; 1148 unsigned long safe_mask = 0;
1080 unsigned int commit_max_age = (unsigned int)-1; 1149 unsigned int commit_max_age = (unsigned int)-1;
1081 struct reiserfs_journal *journal = SB_JOURNAL(s); 1150 struct reiserfs_journal *journal = SB_JOURNAL(s);
1082 int err; 1151 int err;
1083#ifdef CONFIG_QUOTA 1152#ifdef CONFIG_QUOTA
1084 int i; 1153 int i;
1085#endif 1154#endif
1086 1155
1087 rs = SB_DISK_SUPER_BLOCK (s); 1156 rs = SB_DISK_SUPER_BLOCK(s);
1088 1157
1089 if (!reiserfs_parse_options(s, arg, &mount_options, &blocks, NULL, &commit_max_age)) { 1158 if (!reiserfs_parse_options
1159 (s, arg, &mount_options, &blocks, NULL, &commit_max_age)) {
1090#ifdef CONFIG_QUOTA 1160#ifdef CONFIG_QUOTA
1091 for (i = 0; i < MAXQUOTAS; i++) 1161 for (i = 0; i < MAXQUOTAS; i++)
1092 if (REISERFS_SB(s)->s_qf_names[i]) { 1162 if (REISERFS_SB(s)->s_qf_names[i]) {
1093 kfree(REISERFS_SB(s)->s_qf_names[i]); 1163 kfree(REISERFS_SB(s)->s_qf_names[i]);
1094 REISERFS_SB(s)->s_qf_names[i] = NULL; 1164 REISERFS_SB(s)->s_qf_names[i] = NULL;
1095 } 1165 }
1096#endif 1166#endif
1097 return -EINVAL; 1167 return -EINVAL;
1098 } 1168 }
1099 1169
1100 handle_attrs(s); 1170 handle_attrs(s);
1101 1171
1102 /* Add options that are safe here */ 1172 /* Add options that are safe here */
1103 safe_mask |= 1 << REISERFS_SMALLTAIL; 1173 safe_mask |= 1 << REISERFS_SMALLTAIL;
1104 safe_mask |= 1 << REISERFS_LARGETAIL; 1174 safe_mask |= 1 << REISERFS_LARGETAIL;
1105 safe_mask |= 1 << REISERFS_NO_BORDER; 1175 safe_mask |= 1 << REISERFS_NO_BORDER;
1106 safe_mask |= 1 << REISERFS_NO_UNHASHED_RELOCATION; 1176 safe_mask |= 1 << REISERFS_NO_UNHASHED_RELOCATION;
1107 safe_mask |= 1 << REISERFS_HASHED_RELOCATION; 1177 safe_mask |= 1 << REISERFS_HASHED_RELOCATION;
1108 safe_mask |= 1 << REISERFS_TEST4; 1178 safe_mask |= 1 << REISERFS_TEST4;
1109 safe_mask |= 1 << REISERFS_ATTRS; 1179 safe_mask |= 1 << REISERFS_ATTRS;
1110 safe_mask |= 1 << REISERFS_XATTRS_USER; 1180 safe_mask |= 1 << REISERFS_XATTRS_USER;
1111 safe_mask |= 1 << REISERFS_POSIXACL; 1181 safe_mask |= 1 << REISERFS_POSIXACL;
1112 safe_mask |= 1 << REISERFS_BARRIER_FLUSH; 1182 safe_mask |= 1 << REISERFS_BARRIER_FLUSH;
1113 safe_mask |= 1 << REISERFS_BARRIER_NONE; 1183 safe_mask |= 1 << REISERFS_BARRIER_NONE;
1114 safe_mask |= 1 << REISERFS_ERROR_RO; 1184 safe_mask |= 1 << REISERFS_ERROR_RO;
1115 safe_mask |= 1 << REISERFS_ERROR_CONTINUE; 1185 safe_mask |= 1 << REISERFS_ERROR_CONTINUE;
1116 safe_mask |= 1 << REISERFS_ERROR_PANIC; 1186 safe_mask |= 1 << REISERFS_ERROR_PANIC;
1117 safe_mask |= 1 << REISERFS_QUOTA; 1187 safe_mask |= 1 << REISERFS_QUOTA;
1118 1188
1119 /* Update the bitmask, taking care to keep 1189 /* Update the bitmask, taking care to keep
1120 * the bits we're not allowed to change here */ 1190 * the bits we're not allowed to change here */
1121 REISERFS_SB(s)->s_mount_opt = (REISERFS_SB(s)->s_mount_opt & ~safe_mask) | (mount_options & safe_mask); 1191 REISERFS_SB(s)->s_mount_opt =
1122 1192 (REISERFS_SB(s)->
1123 if(commit_max_age != 0 && commit_max_age != (unsigned int)-1) { 1193 s_mount_opt & ~safe_mask) | (mount_options & safe_mask);
1124 journal->j_max_commit_age = commit_max_age; 1194
1125 journal->j_max_trans_age = commit_max_age; 1195 if (commit_max_age != 0 && commit_max_age != (unsigned int)-1) {
1126 } 1196 journal->j_max_commit_age = commit_max_age;
1127 else if(commit_max_age == 0) 1197 journal->j_max_trans_age = commit_max_age;
1128 { 1198 } else if (commit_max_age == 0) {
1129 /* 0 means restore defaults. */ 1199 /* 0 means restore defaults. */
1130 journal->j_max_commit_age = journal->j_default_max_commit_age; 1200 journal->j_max_commit_age = journal->j_default_max_commit_age;
1131 journal->j_max_trans_age = JOURNAL_MAX_TRANS_AGE; 1201 journal->j_max_trans_age = JOURNAL_MAX_TRANS_AGE;
1132 } 1202 }
1133 1203
1134 if(blocks) { 1204 if (blocks) {
1135 int rc = reiserfs_resize(s, blocks); 1205 int rc = reiserfs_resize(s, blocks);
1136 if (rc != 0) 1206 if (rc != 0)
1137 return rc; 1207 return rc;
1138 } 1208 }
1139 1209
1140 if (*mount_flags & MS_RDONLY) { 1210 if (*mount_flags & MS_RDONLY) {
1141 reiserfs_xattr_init (s, *mount_flags); 1211 reiserfs_xattr_init(s, *mount_flags);
1142 /* remount read-only */ 1212 /* remount read-only */
1143 if (s->s_flags & MS_RDONLY) 1213 if (s->s_flags & MS_RDONLY)
1144 /* it is read-only already */ 1214 /* it is read-only already */
1145 return 0; 1215 return 0;
1146 /* try to remount file system with read-only permissions */ 1216 /* try to remount file system with read-only permissions */
1147 if (sb_umount_state(rs) == REISERFS_VALID_FS || REISERFS_SB(s)->s_mount_state != REISERFS_VALID_FS) { 1217 if (sb_umount_state(rs) == REISERFS_VALID_FS
1148 return 0; 1218 || REISERFS_SB(s)->s_mount_state != REISERFS_VALID_FS) {
1149 } 1219 return 0;
1150 1220 }
1151 err = journal_begin(&th, s, 10) ; 1221
1152 if (err) 1222 err = journal_begin(&th, s, 10);
1153 return err; 1223 if (err)
1154 1224 return err;
1155 /* Mounting a rw partition read-only. */ 1225
1156 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1) ; 1226 /* Mounting a rw partition read-only. */
1157 set_sb_umount_state( rs, REISERFS_SB(s)->s_mount_state ); 1227 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1);
1158 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB (s)); 1228 set_sb_umount_state(rs, REISERFS_SB(s)->s_mount_state);
1159 } else { 1229 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
1160 /* remount read-write */ 1230 } else {
1161 if (!(s->s_flags & MS_RDONLY)) { 1231 /* remount read-write */
1162 reiserfs_xattr_init (s, *mount_flags); 1232 if (!(s->s_flags & MS_RDONLY)) {
1163 return 0; /* We are read-write already */ 1233 reiserfs_xattr_init(s, *mount_flags);
1164 } 1234 return 0; /* We are read-write already */
1165 1235 }
1166 if (reiserfs_is_journal_aborted (journal)) 1236
1167 return journal->j_errno; 1237 if (reiserfs_is_journal_aborted(journal))
1168 1238 return journal->j_errno;
1169 handle_data_mode(s, mount_options); 1239
1170 handle_barrier_mode(s, mount_options); 1240 handle_data_mode(s, mount_options);
1171 REISERFS_SB(s)->s_mount_state = sb_umount_state(rs) ; 1241 handle_barrier_mode(s, mount_options);
1172 s->s_flags &= ~MS_RDONLY ; /* now it is safe to call journal_begin */ 1242 REISERFS_SB(s)->s_mount_state = sb_umount_state(rs);
1173 err = journal_begin(&th, s, 10) ; 1243 s->s_flags &= ~MS_RDONLY; /* now it is safe to call journal_begin */
1174 if (err) 1244 err = journal_begin(&th, s, 10);
1175 return err; 1245 if (err)
1176 1246 return err;
1177 /* Mount a partition which is read-only, read-write */ 1247
1178 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1) ; 1248 /* Mount a partition which is read-only, read-write */
1179 REISERFS_SB(s)->s_mount_state = sb_umount_state(rs); 1249 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1);
1180 s->s_flags &= ~MS_RDONLY; 1250 REISERFS_SB(s)->s_mount_state = sb_umount_state(rs);
1181 set_sb_umount_state( rs, REISERFS_ERROR_FS ); 1251 s->s_flags &= ~MS_RDONLY;
1182 /* mark_buffer_dirty (SB_BUFFER_WITH_SB (s), 1); */ 1252 set_sb_umount_state(rs, REISERFS_ERROR_FS);
1183 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB (s)); 1253 /* mark_buffer_dirty (SB_BUFFER_WITH_SB (s), 1); */
1184 REISERFS_SB(s)->s_mount_state = REISERFS_VALID_FS ; 1254 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
1185 } 1255 REISERFS_SB(s)->s_mount_state = REISERFS_VALID_FS;
1186 /* this will force a full flush of all journal lists */ 1256 }
1187 SB_JOURNAL(s)->j_must_wait = 1 ; 1257 /* this will force a full flush of all journal lists */
1188 err = journal_end(&th, s, 10) ; 1258 SB_JOURNAL(s)->j_must_wait = 1;
1189 if (err) 1259 err = journal_end(&th, s, 10);
1190 return err; 1260 if (err)
1191 s->s_dirt = 0; 1261 return err;
1192 1262 s->s_dirt = 0;
1193 if (!( *mount_flags & MS_RDONLY ) ) { 1263
1194 finish_unfinished( s ); 1264 if (!(*mount_flags & MS_RDONLY)) {
1195 reiserfs_xattr_init (s, *mount_flags); 1265 finish_unfinished(s);
1196 } 1266 reiserfs_xattr_init(s, *mount_flags);
1197 1267 }
1198 return 0; 1268
1269 return 0;
1199} 1270}
1200 1271
1201/* load_bitmap_info_data - Sets up the reiserfs_bitmap_info structure from disk. 1272/* load_bitmap_info_data - Sets up the reiserfs_bitmap_info structure from disk.
@@ -1214,761 +1285,829 @@ static int reiserfs_remount (struct super_block * s, int * mount_flags, char * a
1214 * free blocks at all. 1285 * free blocks at all.
1215 */ 1286 */
1216 1287
1217static void load_bitmap_info_data (struct super_block *sb, 1288static void load_bitmap_info_data(struct super_block *sb,
1218 struct reiserfs_bitmap_info *bi) 1289 struct reiserfs_bitmap_info *bi)
1219{ 1290{
1220 unsigned long *cur = (unsigned long *)bi->bh->b_data; 1291 unsigned long *cur = (unsigned long *)bi->bh->b_data;
1221 1292
1222 while ((char *)cur < (bi->bh->b_data + sb->s_blocksize)) { 1293 while ((char *)cur < (bi->bh->b_data + sb->s_blocksize)) {
1223 1294
1224 /* No need to scan if all 0's or all 1's. 1295 /* No need to scan if all 0's or all 1's.
1225 * Since we're only counting 0's, we can simply ignore all 1's */ 1296 * Since we're only counting 0's, we can simply ignore all 1's */
1226 if (*cur == 0) { 1297 if (*cur == 0) {
1227 if (bi->first_zero_hint == 0) { 1298 if (bi->first_zero_hint == 0) {
1228 bi->first_zero_hint = ((char *)cur - bi->bh->b_data) << 3; 1299 bi->first_zero_hint =
1229 } 1300 ((char *)cur - bi->bh->b_data) << 3;
1230 bi->free_count += sizeof(unsigned long)*8; 1301 }
1231 } else if (*cur != ~0L) { 1302 bi->free_count += sizeof(unsigned long) * 8;
1232 int b; 1303 } else if (*cur != ~0L) {
1233 for (b = 0; b < sizeof(unsigned long)*8; b++) { 1304 int b;
1234 if (!reiserfs_test_le_bit (b, cur)) { 1305 for (b = 0; b < sizeof(unsigned long) * 8; b++) {
1235 bi->free_count ++; 1306 if (!reiserfs_test_le_bit(b, cur)) {
1236 if (bi->first_zero_hint == 0) 1307 bi->free_count++;
1237 bi->first_zero_hint = 1308 if (bi->first_zero_hint == 0)
1238 (((char *)cur - bi->bh->b_data) << 3) + b; 1309 bi->first_zero_hint =
1239 } 1310 (((char *)cur -
1311 bi->bh->b_data) << 3) + b;
1312 }
1313 }
1240 } 1314 }
1241 } 1315 cur++;
1242 cur ++; 1316 }
1243 }
1244 1317
1245#ifdef CONFIG_REISERFS_CHECK 1318#ifdef CONFIG_REISERFS_CHECK
1246// This outputs a lot of unneded info on big FSes 1319// This outputs a lot of unneded info on big FSes
1247// reiserfs_warning ("bitmap loaded from block %d: %d free blocks", 1320// reiserfs_warning ("bitmap loaded from block %d: %d free blocks",
1248// bi->bh->b_blocknr, bi->free_count); 1321// bi->bh->b_blocknr, bi->free_count);
1249#endif 1322#endif
1250} 1323}
1251 1324
1252static int read_bitmaps (struct super_block * s) 1325static int read_bitmaps(struct super_block *s)
1253{ 1326{
1254 int i, bmap_nr; 1327 int i, bmap_nr;
1328
1329 SB_AP_BITMAP(s) =
1330 vmalloc(sizeof(struct reiserfs_bitmap_info) * SB_BMAP_NR(s));
1331 if (SB_AP_BITMAP(s) == 0)
1332 return 1;
1333 memset(SB_AP_BITMAP(s), 0,
1334 sizeof(struct reiserfs_bitmap_info) * SB_BMAP_NR(s));
1335 for (i = 0, bmap_nr =
1336 REISERFS_DISK_OFFSET_IN_BYTES / s->s_blocksize + 1;
1337 i < SB_BMAP_NR(s); i++, bmap_nr = s->s_blocksize * 8 * i) {
1338 SB_AP_BITMAP(s)[i].bh = sb_getblk(s, bmap_nr);
1339 if (!buffer_uptodate(SB_AP_BITMAP(s)[i].bh))
1340 ll_rw_block(READ, 1, &SB_AP_BITMAP(s)[i].bh);
1341 }
1342 for (i = 0; i < SB_BMAP_NR(s); i++) {
1343 wait_on_buffer(SB_AP_BITMAP(s)[i].bh);
1344 if (!buffer_uptodate(SB_AP_BITMAP(s)[i].bh)) {
1345 reiserfs_warning(s, "sh-2029: reiserfs read_bitmaps: "
1346 "bitmap block (#%lu) reading failed",
1347 SB_AP_BITMAP(s)[i].bh->b_blocknr);
1348 for (i = 0; i < SB_BMAP_NR(s); i++)
1349 brelse(SB_AP_BITMAP(s)[i].bh);
1350 vfree(SB_AP_BITMAP(s));
1351 SB_AP_BITMAP(s) = NULL;
1352 return 1;
1353 }
1354 load_bitmap_info_data(s, SB_AP_BITMAP(s) + i);
1355 }
1356 return 0;
1357}
1255 1358
1256 SB_AP_BITMAP (s) = vmalloc (sizeof (struct reiserfs_bitmap_info) * SB_BMAP_NR(s)); 1359static int read_old_bitmaps(struct super_block *s)
1257 if (SB_AP_BITMAP (s) == 0) 1360{
1258 return 1; 1361 int i;
1259 memset (SB_AP_BITMAP (s), 0, sizeof (struct reiserfs_bitmap_info) * SB_BMAP_NR(s)); 1362 struct reiserfs_super_block *rs = SB_DISK_SUPER_BLOCK(s);
1260 for (i = 0, bmap_nr = REISERFS_DISK_OFFSET_IN_BYTES / s->s_blocksize + 1; 1363 int bmp1 = (REISERFS_OLD_DISK_OFFSET_IN_BYTES / s->s_blocksize) + 1; /* first of bitmap blocks */
1261 i < SB_BMAP_NR(s); i++, bmap_nr = s->s_blocksize * 8 * i) { 1364
1262 SB_AP_BITMAP (s)[i].bh = sb_getblk(s, bmap_nr); 1365 /* read true bitmap */
1263 if (!buffer_uptodate(SB_AP_BITMAP(s)[i].bh)) 1366 SB_AP_BITMAP(s) =
1264 ll_rw_block(READ, 1, &SB_AP_BITMAP(s)[i].bh); 1367 vmalloc(sizeof(struct reiserfs_buffer_info *) * sb_bmap_nr(rs));
1265 } 1368 if (SB_AP_BITMAP(s) == 0)
1266 for (i = 0; i < SB_BMAP_NR(s); i++) { 1369 return 1;
1267 wait_on_buffer(SB_AP_BITMAP (s)[i].bh); 1370
1268 if (!buffer_uptodate(SB_AP_BITMAP(s)[i].bh)) { 1371 memset(SB_AP_BITMAP(s), 0,
1269 reiserfs_warning(s,"sh-2029: reiserfs read_bitmaps: " 1372 sizeof(struct reiserfs_buffer_info *) * sb_bmap_nr(rs));
1270 "bitmap block (#%lu) reading failed", 1373
1271 SB_AP_BITMAP(s)[i].bh->b_blocknr); 1374 for (i = 0; i < sb_bmap_nr(rs); i++) {
1272 for (i = 0; i < SB_BMAP_NR(s); i++) 1375 SB_AP_BITMAP(s)[i].bh = sb_bread(s, bmp1 + i);
1273 brelse(SB_AP_BITMAP(s)[i].bh); 1376 if (!SB_AP_BITMAP(s)[i].bh)
1274 vfree(SB_AP_BITMAP(s)); 1377 return 1;
1275 SB_AP_BITMAP(s) = NULL; 1378 load_bitmap_info_data(s, SB_AP_BITMAP(s) + i);
1276 return 1;
1277 } 1379 }
1278 load_bitmap_info_data (s, SB_AP_BITMAP (s) + i); 1380
1279 } 1381 return 0;
1280 return 0;
1281} 1382}
1282 1383
1283static int read_old_bitmaps (struct super_block * s) 1384static int read_super_block(struct super_block *s, int offset)
1284{ 1385{
1285 int i ; 1386 struct buffer_head *bh;
1286 struct reiserfs_super_block * rs = SB_DISK_SUPER_BLOCK(s); 1387 struct reiserfs_super_block *rs;
1287 int bmp1 = (REISERFS_OLD_DISK_OFFSET_IN_BYTES / s->s_blocksize) + 1; /* first of bitmap blocks */ 1388 int fs_blocksize;
1288 1389
1289 /* read true bitmap */ 1390 bh = sb_bread(s, offset / s->s_blocksize);
1290 SB_AP_BITMAP (s) = vmalloc (sizeof (struct reiserfs_buffer_info *) * sb_bmap_nr(rs)); 1391 if (!bh) {
1291 if (SB_AP_BITMAP (s) == 0) 1392 reiserfs_warning(s, "sh-2006: read_super_block: "
1292 return 1; 1393 "bread failed (dev %s, block %lu, size %lu)",
1394 reiserfs_bdevname(s), offset / s->s_blocksize,
1395 s->s_blocksize);
1396 return 1;
1397 }
1293 1398
1294 memset (SB_AP_BITMAP (s), 0, sizeof (struct reiserfs_buffer_info *) * sb_bmap_nr(rs)); 1399 rs = (struct reiserfs_super_block *)bh->b_data;
1400 if (!is_any_reiserfs_magic_string(rs)) {
1401 brelse(bh);
1402 return 1;
1403 }
1404 //
1405 // ok, reiserfs signature (old or new) found in at the given offset
1406 //
1407 fs_blocksize = sb_blocksize(rs);
1408 brelse(bh);
1409 sb_set_blocksize(s, fs_blocksize);
1295 1410
1296 for (i = 0; i < sb_bmap_nr(rs); i ++) { 1411 bh = sb_bread(s, offset / s->s_blocksize);
1297 SB_AP_BITMAP (s)[i].bh = sb_bread (s, bmp1 + i); 1412 if (!bh) {
1298 if (!SB_AP_BITMAP (s)[i].bh) 1413 reiserfs_warning(s, "sh-2007: read_super_block: "
1299 return 1; 1414 "bread failed (dev %s, block %lu, size %lu)\n",
1300 load_bitmap_info_data (s, SB_AP_BITMAP (s) + i); 1415 reiserfs_bdevname(s), offset / s->s_blocksize,
1301 } 1416 s->s_blocksize);
1417 return 1;
1418 }
1302 1419
1303 return 0; 1420 rs = (struct reiserfs_super_block *)bh->b_data;
1304} 1421 if (sb_blocksize(rs) != s->s_blocksize) {
1422 reiserfs_warning(s, "sh-2011: read_super_block: "
1423 "can't find a reiserfs filesystem on (dev %s, block %Lu, size %lu)\n",
1424 reiserfs_bdevname(s),
1425 (unsigned long long)bh->b_blocknr,
1426 s->s_blocksize);
1427 brelse(bh);
1428 return 1;
1429 }
1305 1430
1306static int read_super_block (struct super_block * s, int offset) 1431 if (rs->s_v1.s_root_block == cpu_to_le32(-1)) {
1307{ 1432 brelse(bh);
1308 struct buffer_head * bh; 1433 reiserfs_warning(s,
1309 struct reiserfs_super_block * rs; 1434 "Unfinished reiserfsck --rebuild-tree run detected. Please run\n"
1310 int fs_blocksize; 1435 "reiserfsck --rebuild-tree and wait for a completion. If that fails\n"
1311 1436 "get newer reiserfsprogs package");
1312 1437 return 1;
1313 bh = sb_bread (s, offset / s->s_blocksize);
1314 if (!bh) {
1315 reiserfs_warning (s, "sh-2006: read_super_block: "
1316 "bread failed (dev %s, block %lu, size %lu)",
1317 reiserfs_bdevname (s), offset / s->s_blocksize, s->s_blocksize);
1318 return 1;
1319 }
1320
1321 rs = (struct reiserfs_super_block *)bh->b_data;
1322 if (!is_any_reiserfs_magic_string (rs)) {
1323 brelse (bh);
1324 return 1;
1325 }
1326
1327 //
1328 // ok, reiserfs signature (old or new) found in at the given offset
1329 //
1330 fs_blocksize = sb_blocksize(rs);
1331 brelse (bh);
1332 sb_set_blocksize (s, fs_blocksize);
1333
1334 bh = sb_bread (s, offset / s->s_blocksize);
1335 if (!bh) {
1336 reiserfs_warning (s, "sh-2007: read_super_block: "
1337 "bread failed (dev %s, block %lu, size %lu)\n",
1338 reiserfs_bdevname (s), offset / s->s_blocksize, s->s_blocksize);
1339 return 1;
1340 }
1341
1342 rs = (struct reiserfs_super_block *)bh->b_data;
1343 if (sb_blocksize(rs) != s->s_blocksize) {
1344 reiserfs_warning (s, "sh-2011: read_super_block: "
1345 "can't find a reiserfs filesystem on (dev %s, block %Lu, size %lu)\n",
1346 reiserfs_bdevname (s), (unsigned long long)bh->b_blocknr, s->s_blocksize);
1347 brelse (bh);
1348 return 1;
1349 }
1350
1351 if ( rs->s_v1.s_root_block == cpu_to_le32(-1) ) {
1352 brelse(bh) ;
1353 reiserfs_warning (s, "Unfinished reiserfsck --rebuild-tree run detected. Please run\n"
1354 "reiserfsck --rebuild-tree and wait for a completion. If that fails\n"
1355 "get newer reiserfsprogs package");
1356 return 1;
1357 }
1358
1359 SB_BUFFER_WITH_SB (s) = bh;
1360 SB_DISK_SUPER_BLOCK (s) = rs;
1361
1362 if (is_reiserfs_jr (rs)) {
1363 /* magic is of non-standard journal filesystem, look at s_version to
1364 find which format is in use */
1365 if (sb_version(rs) == REISERFS_VERSION_2)
1366 reiserfs_warning (s, "read_super_block: found reiserfs format \"3.6\""
1367 " with non-standard journal");
1368 else if (sb_version(rs) == REISERFS_VERSION_1)
1369 reiserfs_warning (s, "read_super_block: found reiserfs format \"3.5\""
1370 " with non-standard journal");
1371 else {
1372 reiserfs_warning (s, "sh-2012: read_super_block: found unknown "
1373 "format \"%u\" of reiserfs with non-standard magic",
1374 sb_version(rs));
1375 return 1;
1376 } 1438 }
1377 }
1378 else
1379 /* s_version of standard format may contain incorrect information,
1380 so we just look at the magic string */
1381 reiserfs_info (s, "found reiserfs format \"%s\" with standard journal\n",
1382 is_reiserfs_3_5 (rs) ? "3.5" : "3.6");
1383 1439
1384 s->s_op = &reiserfs_sops; 1440 SB_BUFFER_WITH_SB(s) = bh;
1385 s->s_export_op = &reiserfs_export_ops; 1441 SB_DISK_SUPER_BLOCK(s) = rs;
1442
1443 if (is_reiserfs_jr(rs)) {
1444 /* magic is of non-standard journal filesystem, look at s_version to
1445 find which format is in use */
1446 if (sb_version(rs) == REISERFS_VERSION_2)
1447 reiserfs_warning(s,
1448 "read_super_block: found reiserfs format \"3.6\""
1449 " with non-standard journal");
1450 else if (sb_version(rs) == REISERFS_VERSION_1)
1451 reiserfs_warning(s,
1452 "read_super_block: found reiserfs format \"3.5\""
1453 " with non-standard journal");
1454 else {
1455 reiserfs_warning(s,
1456 "sh-2012: read_super_block: found unknown "
1457 "format \"%u\" of reiserfs with non-standard magic",
1458 sb_version(rs));
1459 return 1;
1460 }
1461 } else
1462 /* s_version of standard format may contain incorrect information,
1463 so we just look at the magic string */
1464 reiserfs_info(s,
1465 "found reiserfs format \"%s\" with standard journal\n",
1466 is_reiserfs_3_5(rs) ? "3.5" : "3.6");
1467
1468 s->s_op = &reiserfs_sops;
1469 s->s_export_op = &reiserfs_export_ops;
1386#ifdef CONFIG_QUOTA 1470#ifdef CONFIG_QUOTA
1387 s->s_qcop = &reiserfs_qctl_operations; 1471 s->s_qcop = &reiserfs_qctl_operations;
1388 s->dq_op = &reiserfs_quota_operations; 1472 s->dq_op = &reiserfs_quota_operations;
1389#endif 1473#endif
1390 1474
1391 /* new format is limited by the 32 bit wide i_blocks field, want to 1475 /* new format is limited by the 32 bit wide i_blocks field, want to
1392 ** be one full block below that. 1476 ** be one full block below that.
1393 */ 1477 */
1394 s->s_maxbytes = (512LL << 32) - s->s_blocksize ; 1478 s->s_maxbytes = (512LL << 32) - s->s_blocksize;
1395 return 0; 1479 return 0;
1396} 1480}
1397 1481
1398
1399
1400/* after journal replay, reread all bitmap and super blocks */ 1482/* after journal replay, reread all bitmap and super blocks */
1401static int reread_meta_blocks(struct super_block *s) { 1483static int reread_meta_blocks(struct super_block *s)
1402 int i ; 1484{
1403 ll_rw_block(READ, 1, &(SB_BUFFER_WITH_SB(s))) ; 1485 int i;
1404 wait_on_buffer(SB_BUFFER_WITH_SB(s)) ; 1486 ll_rw_block(READ, 1, &(SB_BUFFER_WITH_SB(s)));
1405 if (!buffer_uptodate(SB_BUFFER_WITH_SB(s))) { 1487 wait_on_buffer(SB_BUFFER_WITH_SB(s));
1406 reiserfs_warning (s, "reread_meta_blocks, error reading the super") ; 1488 if (!buffer_uptodate(SB_BUFFER_WITH_SB(s))) {
1407 return 1 ; 1489 reiserfs_warning(s,
1408 } 1490 "reread_meta_blocks, error reading the super");
1409 1491 return 1;
1410 for (i = 0; i < SB_BMAP_NR(s) ; i++) { 1492 }
1411 ll_rw_block(READ, 1, &(SB_AP_BITMAP(s)[i].bh)) ;
1412 wait_on_buffer(SB_AP_BITMAP(s)[i].bh) ;
1413 if (!buffer_uptodate(SB_AP_BITMAP(s)[i].bh)) {
1414 reiserfs_warning (s, "reread_meta_blocks, error reading bitmap block number %d at %llu",
1415 i, (unsigned long long)SB_AP_BITMAP(s)[i].bh->b_blocknr) ;
1416 return 1 ;
1417 }
1418 }
1419 return 0 ;
1420 1493
1421} 1494 for (i = 0; i < SB_BMAP_NR(s); i++) {
1495 ll_rw_block(READ, 1, &(SB_AP_BITMAP(s)[i].bh));
1496 wait_on_buffer(SB_AP_BITMAP(s)[i].bh);
1497 if (!buffer_uptodate(SB_AP_BITMAP(s)[i].bh)) {
1498 reiserfs_warning(s,
1499 "reread_meta_blocks, error reading bitmap block number %d at %llu",
1500 i,
1501 (unsigned long long)SB_AP_BITMAP(s)[i].
1502 bh->b_blocknr);
1503 return 1;
1504 }
1505 }
1506 return 0;
1422 1507
1508}
1423 1509
1424///////////////////////////////////////////////////// 1510/////////////////////////////////////////////////////
1425// hash detection stuff 1511// hash detection stuff
1426 1512
1427
1428// if root directory is empty - we set default - Yura's - hash and 1513// if root directory is empty - we set default - Yura's - hash and
1429// warn about it 1514// warn about it
1430// FIXME: we look for only one name in a directory. If tea and yura 1515// FIXME: we look for only one name in a directory. If tea and yura
1431// bith have the same value - we ask user to send report to the 1516// bith have the same value - we ask user to send report to the
1432// mailing list 1517// mailing list
1433static __u32 find_hash_out (struct super_block * s) 1518static __u32 find_hash_out(struct super_block *s)
1434{ 1519{
1435 int retval; 1520 int retval;
1436 struct inode * inode; 1521 struct inode *inode;
1437 struct cpu_key key; 1522 struct cpu_key key;
1438 INITIALIZE_PATH (path); 1523 INITIALIZE_PATH(path);
1439 struct reiserfs_dir_entry de; 1524 struct reiserfs_dir_entry de;
1440 __u32 hash = DEFAULT_HASH; 1525 __u32 hash = DEFAULT_HASH;
1441 1526
1442 inode = s->s_root->d_inode; 1527 inode = s->s_root->d_inode;
1443 1528
1444 do { // Some serious "goto"-hater was there ;) 1529 do { // Some serious "goto"-hater was there ;)
1445 u32 teahash, r5hash, yurahash; 1530 u32 teahash, r5hash, yurahash;
1446 1531
1447 make_cpu_key (&key, inode, ~0, TYPE_DIRENTRY, 3); 1532 make_cpu_key(&key, inode, ~0, TYPE_DIRENTRY, 3);
1448 retval = search_by_entry_key (s, &key, &path, &de); 1533 retval = search_by_entry_key(s, &key, &path, &de);
1449 if (retval == IO_ERROR) { 1534 if (retval == IO_ERROR) {
1450 pathrelse (&path); 1535 pathrelse(&path);
1451 return UNSET_HASH ; 1536 return UNSET_HASH;
1452 } 1537 }
1453 if (retval == NAME_NOT_FOUND) 1538 if (retval == NAME_NOT_FOUND)
1454 de.de_entry_num --; 1539 de.de_entry_num--;
1455 set_de_name_and_namelen (&de); 1540 set_de_name_and_namelen(&de);
1456 if (deh_offset( &(de.de_deh[de.de_entry_num]) ) == DOT_DOT_OFFSET) { 1541 if (deh_offset(&(de.de_deh[de.de_entry_num])) == DOT_DOT_OFFSET) {
1457 /* allow override in this case */ 1542 /* allow override in this case */
1458 if (reiserfs_rupasov_hash(s)) { 1543 if (reiserfs_rupasov_hash(s)) {
1459 hash = YURA_HASH ; 1544 hash = YURA_HASH;
1460 } 1545 }
1461 reiserfs_warning(s,"FS seems to be empty, autodetect " 1546 reiserfs_warning(s, "FS seems to be empty, autodetect "
1462 "is using the default hash"); 1547 "is using the default hash");
1463 break; 1548 break;
1464 } 1549 }
1465 r5hash=GET_HASH_VALUE (r5_hash (de.de_name, de.de_namelen)); 1550 r5hash = GET_HASH_VALUE(r5_hash(de.de_name, de.de_namelen));
1466 teahash=GET_HASH_VALUE (keyed_hash (de.de_name, de.de_namelen)); 1551 teahash = GET_HASH_VALUE(keyed_hash(de.de_name, de.de_namelen));
1467 yurahash=GET_HASH_VALUE (yura_hash (de.de_name, de.de_namelen)); 1552 yurahash = GET_HASH_VALUE(yura_hash(de.de_name, de.de_namelen));
1468 if ( ( (teahash == r5hash) && (GET_HASH_VALUE( deh_offset(&(de.de_deh[de.de_entry_num]))) == r5hash) ) || 1553 if (((teahash == r5hash)
1469 ( (teahash == yurahash) && (yurahash == GET_HASH_VALUE( deh_offset(&(de.de_deh[de.de_entry_num])))) ) || 1554 &&
1470 ( (r5hash == yurahash) && (yurahash == GET_HASH_VALUE( deh_offset(&(de.de_deh[de.de_entry_num])))) ) ) { 1555 (GET_HASH_VALUE(deh_offset(&(de.de_deh[de.de_entry_num])))
1471 reiserfs_warning(s,"Unable to automatically detect hash function. " 1556 == r5hash)) || ((teahash == yurahash)
1472 "Please mount with -o hash={tea,rupasov,r5}", 1557 && (yurahash ==
1473 reiserfs_bdevname (s)); 1558 GET_HASH_VALUE(deh_offset
1474 hash = UNSET_HASH; 1559 (&
1475 break; 1560 (de.
1476 } 1561 de_deh[de.
1477 if (GET_HASH_VALUE( deh_offset(&(de.de_deh[de.de_entry_num])) ) == yurahash) 1562 de_entry_num])))))
1478 hash = YURA_HASH; 1563 || ((r5hash == yurahash)
1479 else if (GET_HASH_VALUE( deh_offset(&(de.de_deh[de.de_entry_num])) ) == teahash) 1564 && (yurahash ==
1480 hash = TEA_HASH; 1565 GET_HASH_VALUE(deh_offset
1481 else if (GET_HASH_VALUE( deh_offset(&(de.de_deh[de.de_entry_num])) ) == r5hash) 1566 (&(de.de_deh[de.de_entry_num])))))) {
1482 hash = R5_HASH; 1567 reiserfs_warning(s,
1483 else { 1568 "Unable to automatically detect hash function. "
1484 reiserfs_warning (s,"Unrecognised hash function"); 1569 "Please mount with -o hash={tea,rupasov,r5}",
1485 hash = UNSET_HASH; 1570 reiserfs_bdevname(s));
1486 } 1571 hash = UNSET_HASH;
1487 } while (0); 1572 break;
1488 1573 }
1489 pathrelse (&path); 1574 if (GET_HASH_VALUE(deh_offset(&(de.de_deh[de.de_entry_num]))) ==
1490 return hash; 1575 yurahash)
1576 hash = YURA_HASH;
1577 else if (GET_HASH_VALUE
1578 (deh_offset(&(de.de_deh[de.de_entry_num]))) == teahash)
1579 hash = TEA_HASH;
1580 else if (GET_HASH_VALUE
1581 (deh_offset(&(de.de_deh[de.de_entry_num]))) == r5hash)
1582 hash = R5_HASH;
1583 else {
1584 reiserfs_warning(s, "Unrecognised hash function");
1585 hash = UNSET_HASH;
1586 }
1587 } while (0);
1588
1589 pathrelse(&path);
1590 return hash;
1491} 1591}
1492 1592
1493// finds out which hash names are sorted with 1593// finds out which hash names are sorted with
1494static int what_hash (struct super_block * s) 1594static int what_hash(struct super_block *s)
1495{ 1595{
1496 __u32 code; 1596 __u32 code;
1497 1597
1498 code = sb_hash_function_code(SB_DISK_SUPER_BLOCK(s)); 1598 code = sb_hash_function_code(SB_DISK_SUPER_BLOCK(s));
1499 1599
1500 /* reiserfs_hash_detect() == true if any of the hash mount options 1600 /* reiserfs_hash_detect() == true if any of the hash mount options
1501 ** were used. We must check them to make sure the user isn't 1601 ** were used. We must check them to make sure the user isn't
1502 ** using a bad hash value 1602 ** using a bad hash value
1503 */ 1603 */
1504 if (code == UNSET_HASH || reiserfs_hash_detect(s)) 1604 if (code == UNSET_HASH || reiserfs_hash_detect(s))
1505 code = find_hash_out (s); 1605 code = find_hash_out(s);
1506 1606
1507 if (code != UNSET_HASH && reiserfs_hash_detect(s)) { 1607 if (code != UNSET_HASH && reiserfs_hash_detect(s)) {
1508 /* detection has found the hash, and we must check against the 1608 /* detection has found the hash, and we must check against the
1509 ** mount options 1609 ** mount options
1510 */ 1610 */
1511 if (reiserfs_rupasov_hash(s) && code != YURA_HASH) { 1611 if (reiserfs_rupasov_hash(s) && code != YURA_HASH) {
1512 reiserfs_warning (s, "Error, %s hash detected, " 1612 reiserfs_warning(s, "Error, %s hash detected, "
1513 "unable to force rupasov hash", reiserfs_hashname(code)) ; 1613 "unable to force rupasov hash",
1514 code = UNSET_HASH ; 1614 reiserfs_hashname(code));
1515 } else if (reiserfs_tea_hash(s) && code != TEA_HASH) { 1615 code = UNSET_HASH;
1516 reiserfs_warning (s, "Error, %s hash detected, " 1616 } else if (reiserfs_tea_hash(s) && code != TEA_HASH) {
1517 "unable to force tea hash", reiserfs_hashname(code)) ; 1617 reiserfs_warning(s, "Error, %s hash detected, "
1518 code = UNSET_HASH ; 1618 "unable to force tea hash",
1519 } else if (reiserfs_r5_hash(s) && code != R5_HASH) { 1619 reiserfs_hashname(code));
1520 reiserfs_warning (s, "Error, %s hash detected, " 1620 code = UNSET_HASH;
1521 "unable to force r5 hash", reiserfs_hashname(code)) ; 1621 } else if (reiserfs_r5_hash(s) && code != R5_HASH) {
1522 code = UNSET_HASH ; 1622 reiserfs_warning(s, "Error, %s hash detected, "
1523 } 1623 "unable to force r5 hash",
1524 } else { 1624 reiserfs_hashname(code));
1525 /* find_hash_out was not called or could not determine the hash */ 1625 code = UNSET_HASH;
1526 if (reiserfs_rupasov_hash(s)) { 1626 }
1527 code = YURA_HASH ; 1627 } else {
1528 } else if (reiserfs_tea_hash(s)) { 1628 /* find_hash_out was not called or could not determine the hash */
1529 code = TEA_HASH ; 1629 if (reiserfs_rupasov_hash(s)) {
1530 } else if (reiserfs_r5_hash(s)) { 1630 code = YURA_HASH;
1531 code = R5_HASH ; 1631 } else if (reiserfs_tea_hash(s)) {
1532 } 1632 code = TEA_HASH;
1533 } 1633 } else if (reiserfs_r5_hash(s)) {
1534 1634 code = R5_HASH;
1535 /* if we are mounted RW, and we have a new valid hash code, update 1635 }
1536 ** the super 1636 }
1537 */ 1637
1538 if (code != UNSET_HASH && 1638 /* if we are mounted RW, and we have a new valid hash code, update
1539 !(s->s_flags & MS_RDONLY) && 1639 ** the super
1540 code != sb_hash_function_code(SB_DISK_SUPER_BLOCK(s))) { 1640 */
1541 set_sb_hash_function_code(SB_DISK_SUPER_BLOCK(s), code); 1641 if (code != UNSET_HASH &&
1542 } 1642 !(s->s_flags & MS_RDONLY) &&
1543 return code; 1643 code != sb_hash_function_code(SB_DISK_SUPER_BLOCK(s))) {
1644 set_sb_hash_function_code(SB_DISK_SUPER_BLOCK(s), code);
1645 }
1646 return code;
1544} 1647}
1545 1648
1546// return pointer to appropriate function 1649// return pointer to appropriate function
1547static hashf_t hash_function (struct super_block * s) 1650static hashf_t hash_function(struct super_block *s)
1548{ 1651{
1549 switch (what_hash (s)) { 1652 switch (what_hash(s)) {
1550 case TEA_HASH: 1653 case TEA_HASH:
1551 reiserfs_info (s, "Using tea hash to sort names\n"); 1654 reiserfs_info(s, "Using tea hash to sort names\n");
1552 return keyed_hash; 1655 return keyed_hash;
1553 case YURA_HASH: 1656 case YURA_HASH:
1554 reiserfs_info (s, "Using rupasov hash to sort names\n"); 1657 reiserfs_info(s, "Using rupasov hash to sort names\n");
1555 return yura_hash; 1658 return yura_hash;
1556 case R5_HASH: 1659 case R5_HASH:
1557 reiserfs_info (s, "Using r5 hash to sort names\n"); 1660 reiserfs_info(s, "Using r5 hash to sort names\n");
1558 return r5_hash; 1661 return r5_hash;
1559 } 1662 }
1560 return NULL; 1663 return NULL;
1561} 1664}
1562 1665
1563// this is used to set up correct value for old partitions 1666// this is used to set up correct value for old partitions
1564static int function2code (hashf_t func) 1667static int function2code(hashf_t func)
1565{ 1668{
1566 if (func == keyed_hash) 1669 if (func == keyed_hash)
1567 return TEA_HASH; 1670 return TEA_HASH;
1568 if (func == yura_hash) 1671 if (func == yura_hash)
1569 return YURA_HASH; 1672 return YURA_HASH;
1570 if (func == r5_hash) 1673 if (func == r5_hash)
1571 return R5_HASH; 1674 return R5_HASH;
1572 1675
1573 BUG() ; // should never happen 1676 BUG(); // should never happen
1574 1677
1575 return 0; 1678 return 0;
1576} 1679}
1577 1680
1578#define SWARN(silent, s, ...) \ 1681#define SWARN(silent, s, ...) \
1579 if (!(silent)) \ 1682 if (!(silent)) \
1580 reiserfs_warning (s, __VA_ARGS__) 1683 reiserfs_warning (s, __VA_ARGS__)
1581 1684
1582static int reiserfs_fill_super (struct super_block * s, void * data, int silent) 1685static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
1583{ 1686{
1584 struct inode *root_inode; 1687 struct inode *root_inode;
1585 int j; 1688 int j;
1586 struct reiserfs_transaction_handle th ; 1689 struct reiserfs_transaction_handle th;
1587 int old_format = 0; 1690 int old_format = 0;
1588 unsigned long blocks; 1691 unsigned long blocks;
1589 unsigned int commit_max_age = 0; 1692 unsigned int commit_max_age = 0;
1590 int jinit_done = 0 ; 1693 int jinit_done = 0;
1591 struct reiserfs_iget_args args ; 1694 struct reiserfs_iget_args args;
1592 struct reiserfs_super_block * rs; 1695 struct reiserfs_super_block *rs;
1593 char *jdev_name; 1696 char *jdev_name;
1594 struct reiserfs_sb_info *sbi; 1697 struct reiserfs_sb_info *sbi;
1595 int errval = -EINVAL; 1698 int errval = -EINVAL;
1596 1699
1597 sbi = kmalloc(sizeof(struct reiserfs_sb_info), GFP_KERNEL); 1700 sbi = kmalloc(sizeof(struct reiserfs_sb_info), GFP_KERNEL);
1598 if (!sbi) { 1701 if (!sbi) {
1599 errval = -ENOMEM; 1702 errval = -ENOMEM;
1600 goto error; 1703 goto error;
1601 } 1704 }
1602 s->s_fs_info = sbi; 1705 s->s_fs_info = sbi;
1603 memset (sbi, 0, sizeof (struct reiserfs_sb_info)); 1706 memset(sbi, 0, sizeof(struct reiserfs_sb_info));
1604 /* Set default values for options: non-aggressive tails, RO on errors */ 1707 /* Set default values for options: non-aggressive tails, RO on errors */
1605 REISERFS_SB(s)->s_mount_opt |= (1 << REISERFS_SMALLTAIL); 1708 REISERFS_SB(s)->s_mount_opt |= (1 << REISERFS_SMALLTAIL);
1606 REISERFS_SB(s)->s_mount_opt |= (1 << REISERFS_ERROR_RO); 1709 REISERFS_SB(s)->s_mount_opt |= (1 << REISERFS_ERROR_RO);
1607 /* no preallocation minimum, be smart in 1710 /* no preallocation minimum, be smart in
1608 reiserfs_file_write instead */ 1711 reiserfs_file_write instead */
1609 REISERFS_SB(s)->s_alloc_options.preallocmin = 0; 1712 REISERFS_SB(s)->s_alloc_options.preallocmin = 0;
1610 /* Preallocate by 16 blocks (17-1) at once */ 1713 /* Preallocate by 16 blocks (17-1) at once */
1611 REISERFS_SB(s)->s_alloc_options.preallocsize = 17; 1714 REISERFS_SB(s)->s_alloc_options.preallocsize = 17;
1612 /* Initialize the rwsem for xattr dir */ 1715 /* Initialize the rwsem for xattr dir */
1613 init_rwsem(&REISERFS_SB(s)->xattr_dir_sem); 1716 init_rwsem(&REISERFS_SB(s)->xattr_dir_sem);
1614 1717
1615 /* setup default block allocator options */ 1718 /* setup default block allocator options */
1616 reiserfs_init_alloc_options(s); 1719 reiserfs_init_alloc_options(s);
1617 1720
1618 jdev_name = NULL; 1721 jdev_name = NULL;
1619 if (reiserfs_parse_options (s, (char *) data, &(sbi->s_mount_opt), &blocks, &jdev_name, &commit_max_age) == 0) { 1722 if (reiserfs_parse_options
1620 goto error; 1723 (s, (char *)data, &(sbi->s_mount_opt), &blocks, &jdev_name,
1621 } 1724 &commit_max_age) == 0) {
1622 1725 goto error;
1623 if (blocks) { 1726 }
1624 SWARN (silent, s, "jmacd-7: reiserfs_fill_super: resize option " 1727
1625 "for remount only"); 1728 if (blocks) {
1626 goto error; 1729 SWARN(silent, s, "jmacd-7: reiserfs_fill_super: resize option "
1627 } 1730 "for remount only");
1628 1731 goto error;
1629 /* try old format (undistributed bitmap, super block in 8-th 1k block of a device) */ 1732 }
1630 if (!read_super_block (s, REISERFS_OLD_DISK_OFFSET_IN_BYTES)) 1733
1631 old_format = 1; 1734 /* try old format (undistributed bitmap, super block in 8-th 1k block of a device) */
1632 /* try new format (64-th 1k block), which can contain reiserfs super block */ 1735 if (!read_super_block(s, REISERFS_OLD_DISK_OFFSET_IN_BYTES))
1633 else if (read_super_block (s, REISERFS_DISK_OFFSET_IN_BYTES)) { 1736 old_format = 1;
1634 SWARN(silent, s, "sh-2021: reiserfs_fill_super: can not find reiserfs on %s", reiserfs_bdevname (s)); 1737 /* try new format (64-th 1k block), which can contain reiserfs super block */
1635 goto error; 1738 else if (read_super_block(s, REISERFS_DISK_OFFSET_IN_BYTES)) {
1636 } 1739 SWARN(silent, s,
1637 1740 "sh-2021: reiserfs_fill_super: can not find reiserfs on %s",
1638 rs = SB_DISK_SUPER_BLOCK (s); 1741 reiserfs_bdevname(s));
1639 /* Let's do basic sanity check to verify that underlying device is not 1742 goto error;
1640 smaller than the filesystem. If the check fails then abort and scream, 1743 }
1641 because bad stuff will happen otherwise. */ 1744
1642 if ( s->s_bdev && s->s_bdev->bd_inode && i_size_read(s->s_bdev->bd_inode) < sb_block_count(rs)*sb_blocksize(rs)) { 1745 rs = SB_DISK_SUPER_BLOCK(s);
1643 SWARN (silent, s, "Filesystem on %s cannot be mounted because it is bigger than the device", reiserfs_bdevname(s)); 1746 /* Let's do basic sanity check to verify that underlying device is not
1644 SWARN(silent, s, "You may need to run fsck or increase size of your LVM partition"); 1747 smaller than the filesystem. If the check fails then abort and scream,
1645 SWARN(silent, s, "Or may be you forgot to reboot after fdisk when it told you to"); 1748 because bad stuff will happen otherwise. */
1646 goto error; 1749 if (s->s_bdev && s->s_bdev->bd_inode
1647 } 1750 && i_size_read(s->s_bdev->bd_inode) <
1648 1751 sb_block_count(rs) * sb_blocksize(rs)) {
1649 sbi->s_mount_state = SB_REISERFS_STATE(s); 1752 SWARN(silent, s,
1650 sbi->s_mount_state = REISERFS_VALID_FS ; 1753 "Filesystem on %s cannot be mounted because it is bigger than the device",
1651 1754 reiserfs_bdevname(s));
1652 if (old_format ? read_old_bitmaps(s) : read_bitmaps(s)) { 1755 SWARN(silent, s,
1653 SWARN(silent, s, "jmacd-8: reiserfs_fill_super: unable to read bitmap"); 1756 "You may need to run fsck or increase size of your LVM partition");
1654 goto error; 1757 SWARN(silent, s,
1655 } 1758 "Or may be you forgot to reboot after fdisk when it told you to");
1759 goto error;
1760 }
1761
1762 sbi->s_mount_state = SB_REISERFS_STATE(s);
1763 sbi->s_mount_state = REISERFS_VALID_FS;
1764
1765 if (old_format ? read_old_bitmaps(s) : read_bitmaps(s)) {
1766 SWARN(silent, s,
1767 "jmacd-8: reiserfs_fill_super: unable to read bitmap");
1768 goto error;
1769 }
1656#ifdef CONFIG_REISERFS_CHECK 1770#ifdef CONFIG_REISERFS_CHECK
1657 SWARN (silent, s, "CONFIG_REISERFS_CHECK is set ON"); 1771 SWARN(silent, s, "CONFIG_REISERFS_CHECK is set ON");
1658 SWARN (silent, s, "- it is slow mode for debugging."); 1772 SWARN(silent, s, "- it is slow mode for debugging.");
1659#endif 1773#endif
1660 1774
1661 /* make data=ordered the default */ 1775 /* make data=ordered the default */
1662 if (!reiserfs_data_log(s) && !reiserfs_data_ordered(s) && 1776 if (!reiserfs_data_log(s) && !reiserfs_data_ordered(s) &&
1663 !reiserfs_data_writeback(s)) 1777 !reiserfs_data_writeback(s)) {
1664 { 1778 REISERFS_SB(s)->s_mount_opt |= (1 << REISERFS_DATA_ORDERED);
1665 REISERFS_SB(s)->s_mount_opt |= (1 << REISERFS_DATA_ORDERED); 1779 }
1666 } 1780
1667 1781 if (reiserfs_data_log(s)) {
1668 if (reiserfs_data_log(s)) { 1782 reiserfs_info(s, "using journaled data mode\n");
1669 reiserfs_info (s, "using journaled data mode\n"); 1783 } else if (reiserfs_data_ordered(s)) {
1670 } else if (reiserfs_data_ordered(s)) { 1784 reiserfs_info(s, "using ordered data mode\n");
1671 reiserfs_info (s, "using ordered data mode\n"); 1785 } else {
1672 } else { 1786 reiserfs_info(s, "using writeback data mode\n");
1673 reiserfs_info (s, "using writeback data mode\n"); 1787 }
1674 } 1788 if (reiserfs_barrier_flush(s)) {
1675 if (reiserfs_barrier_flush(s)) { 1789 printk("reiserfs: using flush barriers\n");
1676 printk("reiserfs: using flush barriers\n"); 1790 }
1677 } 1791 // set_device_ro(s->s_dev, 1) ;
1678 1792 if (journal_init(s, jdev_name, old_format, commit_max_age)) {
1679 // set_device_ro(s->s_dev, 1) ; 1793 SWARN(silent, s,
1680 if( journal_init(s, jdev_name, old_format, commit_max_age) ) { 1794 "sh-2022: reiserfs_fill_super: unable to initialize journal space");
1681 SWARN(silent, s, "sh-2022: reiserfs_fill_super: unable to initialize journal space") ; 1795 goto error;
1682 goto error ; 1796 } else {
1683 } else { 1797 jinit_done = 1; /* once this is set, journal_release must be called
1684 jinit_done = 1 ; /* once this is set, journal_release must be called 1798 ** if we error out of the mount
1685 ** if we error out of the mount 1799 */
1686 */ 1800 }
1687 } 1801 if (reread_meta_blocks(s)) {
1688 if (reread_meta_blocks(s)) { 1802 SWARN(silent, s,
1689 SWARN(silent, s, "jmacd-9: reiserfs_fill_super: unable to reread meta blocks after journal init") ; 1803 "jmacd-9: reiserfs_fill_super: unable to reread meta blocks after journal init");
1690 goto error ; 1804 goto error;
1691 } 1805 }
1692 1806
1693 if (replay_only (s)) 1807 if (replay_only(s))
1694 goto error; 1808 goto error;
1695 1809
1696 if (bdev_read_only(s->s_bdev) && !(s->s_flags & MS_RDONLY)) { 1810 if (bdev_read_only(s->s_bdev) && !(s->s_flags & MS_RDONLY)) {
1697 SWARN(silent, s, "clm-7000: Detected readonly device, marking FS readonly") ; 1811 SWARN(silent, s,
1698 s->s_flags |= MS_RDONLY ; 1812 "clm-7000: Detected readonly device, marking FS readonly");
1699 } 1813 s->s_flags |= MS_RDONLY;
1700 args.objectid = REISERFS_ROOT_OBJECTID ; 1814 }
1701 args.dirid = REISERFS_ROOT_PARENT_OBJECTID ; 1815 args.objectid = REISERFS_ROOT_OBJECTID;
1702 root_inode = iget5_locked (s, REISERFS_ROOT_OBJECTID, reiserfs_find_actor, reiserfs_init_locked_inode, (void *)(&args)); 1816 args.dirid = REISERFS_ROOT_PARENT_OBJECTID;
1703 if (!root_inode) { 1817 root_inode =
1704 SWARN(silent, s, "jmacd-10: reiserfs_fill_super: get root inode failed"); 1818 iget5_locked(s, REISERFS_ROOT_OBJECTID, reiserfs_find_actor,
1705 goto error; 1819 reiserfs_init_locked_inode, (void *)(&args));
1706 } 1820 if (!root_inode) {
1707 1821 SWARN(silent, s,
1708 if (root_inode->i_state & I_NEW) { 1822 "jmacd-10: reiserfs_fill_super: get root inode failed");
1709 reiserfs_read_locked_inode(root_inode, &args); 1823 goto error;
1710 unlock_new_inode(root_inode); 1824 }
1711 } 1825
1712 1826 if (root_inode->i_state & I_NEW) {
1713 s->s_root = d_alloc_root(root_inode); 1827 reiserfs_read_locked_inode(root_inode, &args);
1714 if (!s->s_root) { 1828 unlock_new_inode(root_inode);
1715 iput(root_inode); 1829 }
1716 goto error; 1830
1717 } 1831 s->s_root = d_alloc_root(root_inode);
1718 1832 if (!s->s_root) {
1719 // define and initialize hash function 1833 iput(root_inode);
1720 sbi->s_hash_function = hash_function (s); 1834 goto error;
1721 if (sbi->s_hash_function == NULL) { 1835 }
1722 dput(s->s_root) ; 1836 // define and initialize hash function
1723 s->s_root = NULL ; 1837 sbi->s_hash_function = hash_function(s);
1724 goto error ; 1838 if (sbi->s_hash_function == NULL) {
1725 } 1839 dput(s->s_root);
1726 1840 s->s_root = NULL;
1727 if (is_reiserfs_3_5 (rs) || (is_reiserfs_jr (rs) && SB_VERSION (s) == REISERFS_VERSION_1)) 1841 goto error;
1728 set_bit(REISERFS_3_5, &(sbi->s_properties)); 1842 }
1729 else 1843
1730 set_bit(REISERFS_3_6, &(sbi->s_properties)); 1844 if (is_reiserfs_3_5(rs)
1731 1845 || (is_reiserfs_jr(rs) && SB_VERSION(s) == REISERFS_VERSION_1))
1732 if (!(s->s_flags & MS_RDONLY)) { 1846 set_bit(REISERFS_3_5, &(sbi->s_properties));
1733 1847 else
1734 errval = journal_begin(&th, s, 1) ; 1848 set_bit(REISERFS_3_6, &(sbi->s_properties));
1735 if (errval) { 1849
1736 dput (s->s_root); 1850 if (!(s->s_flags & MS_RDONLY)) {
1737 s->s_root = NULL; 1851
1738 goto error; 1852 errval = journal_begin(&th, s, 1);
1739 } 1853 if (errval) {
1740 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1) ; 1854 dput(s->s_root);
1741 1855 s->s_root = NULL;
1742 set_sb_umount_state( rs, REISERFS_ERROR_FS ); 1856 goto error;
1743 set_sb_fs_state (rs, 0); 1857 }
1744 1858 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1);
1745 if (old_format_only(s)) { 1859
1746 /* filesystem of format 3.5 either with standard or non-standard 1860 set_sb_umount_state(rs, REISERFS_ERROR_FS);
1747 journal */ 1861 set_sb_fs_state(rs, 0);
1748 if (convert_reiserfs (s)) { 1862
1749 /* and -o conv is given */ 1863 if (old_format_only(s)) {
1750 if(!silent) 1864 /* filesystem of format 3.5 either with standard or non-standard
1751 reiserfs_info (s,"converting 3.5 filesystem to the 3.6 format") ; 1865 journal */
1752 1866 if (convert_reiserfs(s)) {
1753 if (is_reiserfs_3_5 (rs)) 1867 /* and -o conv is given */
1754 /* put magic string of 3.6 format. 2.2 will not be able to 1868 if (!silent)
1755 mount this filesystem anymore */ 1869 reiserfs_info(s,
1756 memcpy (rs->s_v1.s_magic, reiserfs_3_6_magic_string, 1870 "converting 3.5 filesystem to the 3.6 format");
1757 sizeof (reiserfs_3_6_magic_string)); 1871
1758 1872 if (is_reiserfs_3_5(rs))
1759 set_sb_version(rs,REISERFS_VERSION_2); 1873 /* put magic string of 3.6 format. 2.2 will not be able to
1760 reiserfs_convert_objectid_map_v1(s) ; 1874 mount this filesystem anymore */
1761 set_bit(REISERFS_3_6, &(sbi->s_properties)); 1875 memcpy(rs->s_v1.s_magic,
1762 clear_bit(REISERFS_3_5, &(sbi->s_properties)); 1876 reiserfs_3_6_magic_string,
1763 } else if (!silent){ 1877 sizeof
1764 reiserfs_info (s, "using 3.5.x disk format\n") ; 1878 (reiserfs_3_6_magic_string));
1765 } 1879
1766 } 1880 set_sb_version(rs, REISERFS_VERSION_2);
1767 1881 reiserfs_convert_objectid_map_v1(s);
1768 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB (s)); 1882 set_bit(REISERFS_3_6, &(sbi->s_properties));
1769 errval = journal_end(&th, s, 1) ; 1883 clear_bit(REISERFS_3_5, &(sbi->s_properties));
1770 if (errval) { 1884 } else if (!silent) {
1771 dput (s->s_root); 1885 reiserfs_info(s, "using 3.5.x disk format\n");
1772 s->s_root = NULL; 1886 }
1773 goto error; 1887 }
1774 } 1888
1775 1889 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
1776 if ((errval = reiserfs_xattr_init (s, s->s_flags))) { 1890 errval = journal_end(&th, s, 1);
1777 dput (s->s_root); 1891 if (errval) {
1778 s->s_root = NULL; 1892 dput(s->s_root);
1779 goto error; 1893 s->s_root = NULL;
1780 } 1894 goto error;
1781 1895 }
1782 /* look for files which were to be removed in previous session */ 1896
1783 finish_unfinished (s); 1897 if ((errval = reiserfs_xattr_init(s, s->s_flags))) {
1784 } else { 1898 dput(s->s_root);
1785 if ( old_format_only(s) && !silent) { 1899 s->s_root = NULL;
1786 reiserfs_info (s, "using 3.5.x disk format\n") ; 1900 goto error;
1787 } 1901 }
1788 1902
1789 if ((errval = reiserfs_xattr_init (s, s->s_flags))) { 1903 /* look for files which were to be removed in previous session */
1790 dput (s->s_root); 1904 finish_unfinished(s);
1791 s->s_root = NULL; 1905 } else {
1792 goto error; 1906 if (old_format_only(s) && !silent) {
1793 } 1907 reiserfs_info(s, "using 3.5.x disk format\n");
1794 } 1908 }
1795 // mark hash in super block: it could be unset. overwrite should be ok 1909
1796 set_sb_hash_function_code( rs, function2code(sbi->s_hash_function ) ); 1910 if ((errval = reiserfs_xattr_init(s, s->s_flags))) {
1797 1911 dput(s->s_root);
1798 handle_attrs( s ); 1912 s->s_root = NULL;
1799 1913 goto error;
1800 reiserfs_proc_info_init( s ); 1914 }
1801 1915 }
1802 init_waitqueue_head (&(sbi->s_wait)); 1916 // mark hash in super block: it could be unset. overwrite should be ok
1803 spin_lock_init(&sbi->bitmap_lock); 1917 set_sb_hash_function_code(rs, function2code(sbi->s_hash_function));
1804 1918
1805 return (0); 1919 handle_attrs(s);
1806 1920
1807 error: 1921 reiserfs_proc_info_init(s);
1808 if (jinit_done) { /* kill the commit thread, free journal ram */ 1922
1809 journal_release_error(NULL, s) ; 1923 init_waitqueue_head(&(sbi->s_wait));
1810 } 1924 spin_lock_init(&sbi->bitmap_lock);
1811 if (SB_DISK_SUPER_BLOCK (s)) { 1925
1812 for (j = 0; j < SB_BMAP_NR (s); j ++) { 1926 return (0);
1813 if (SB_AP_BITMAP (s)) 1927
1814 brelse (SB_AP_BITMAP (s)[j].bh); 1928 error:
1815 } 1929 if (jinit_done) { /* kill the commit thread, free journal ram */
1816 if (SB_AP_BITMAP (s)) 1930 journal_release_error(NULL, s);
1817 vfree (SB_AP_BITMAP (s)); 1931 }
1818 } 1932 if (SB_DISK_SUPER_BLOCK(s)) {
1819 if (SB_BUFFER_WITH_SB (s)) 1933 for (j = 0; j < SB_BMAP_NR(s); j++) {
1820 brelse(SB_BUFFER_WITH_SB (s)); 1934 if (SB_AP_BITMAP(s))
1935 brelse(SB_AP_BITMAP(s)[j].bh);
1936 }
1937 if (SB_AP_BITMAP(s))
1938 vfree(SB_AP_BITMAP(s));
1939 }
1940 if (SB_BUFFER_WITH_SB(s))
1941 brelse(SB_BUFFER_WITH_SB(s));
1821#ifdef CONFIG_QUOTA 1942#ifdef CONFIG_QUOTA
1822 for (j = 0; j < MAXQUOTAS; j++) { 1943 for (j = 0; j < MAXQUOTAS; j++) {
1823 if (sbi->s_qf_names[j]) 1944 if (sbi->s_qf_names[j])
1824 kfree(sbi->s_qf_names[j]); 1945 kfree(sbi->s_qf_names[j]);
1825 } 1946 }
1826#endif 1947#endif
1827 if (sbi != NULL) { 1948 if (sbi != NULL) {
1828 kfree(sbi); 1949 kfree(sbi);
1829 } 1950 }
1830 1951
1831 s->s_fs_info = NULL; 1952 s->s_fs_info = NULL;
1832 return errval; 1953 return errval;
1833} 1954}
1834 1955
1835 1956static int reiserfs_statfs(struct super_block *s, struct kstatfs *buf)
1836static int reiserfs_statfs (struct super_block * s, struct kstatfs * buf)
1837{ 1957{
1838 struct reiserfs_super_block * rs = SB_DISK_SUPER_BLOCK (s); 1958 struct reiserfs_super_block *rs = SB_DISK_SUPER_BLOCK(s);
1839 1959
1840 buf->f_namelen = (REISERFS_MAX_NAME (s->s_blocksize)); 1960 buf->f_namelen = (REISERFS_MAX_NAME(s->s_blocksize));
1841 buf->f_bfree = sb_free_blocks(rs); 1961 buf->f_bfree = sb_free_blocks(rs);
1842 buf->f_bavail = buf->f_bfree; 1962 buf->f_bavail = buf->f_bfree;
1843 buf->f_blocks = sb_block_count(rs) - sb_bmap_nr(rs) - 1; 1963 buf->f_blocks = sb_block_count(rs) - sb_bmap_nr(rs) - 1;
1844 buf->f_bsize = s->s_blocksize; 1964 buf->f_bsize = s->s_blocksize;
1845 /* changed to accommodate gcc folks.*/ 1965 /* changed to accommodate gcc folks. */
1846 buf->f_type = REISERFS_SUPER_MAGIC; 1966 buf->f_type = REISERFS_SUPER_MAGIC;
1847 return 0; 1967 return 0;
1848} 1968}
1849 1969
1850#ifdef CONFIG_QUOTA 1970#ifdef CONFIG_QUOTA
1851static int reiserfs_dquot_initialize(struct inode *inode, int type) 1971static int reiserfs_dquot_initialize(struct inode *inode, int type)
1852{ 1972{
1853 struct reiserfs_transaction_handle th; 1973 struct reiserfs_transaction_handle th;
1854 int ret, err; 1974 int ret, err;
1855 1975
1856 /* We may create quota structure so we need to reserve enough blocks */ 1976 /* We may create quota structure so we need to reserve enough blocks */
1857 reiserfs_write_lock(inode->i_sb); 1977 reiserfs_write_lock(inode->i_sb);
1858 ret = journal_begin(&th, inode->i_sb, 2*REISERFS_QUOTA_INIT_BLOCKS(inode->i_sb)); 1978 ret =
1859 if (ret) 1979 journal_begin(&th, inode->i_sb,
1860 goto out; 1980 2 * REISERFS_QUOTA_INIT_BLOCKS(inode->i_sb));
1861 ret = dquot_initialize(inode, type); 1981 if (ret)
1862 err = journal_end(&th, inode->i_sb, 2*REISERFS_QUOTA_INIT_BLOCKS(inode->i_sb)); 1982 goto out;
1863 if (!ret && err) 1983 ret = dquot_initialize(inode, type);
1864 ret = err; 1984 err =
1865out: 1985 journal_end(&th, inode->i_sb,
1866 reiserfs_write_unlock(inode->i_sb); 1986 2 * REISERFS_QUOTA_INIT_BLOCKS(inode->i_sb));
1867 return ret; 1987 if (!ret && err)
1988 ret = err;
1989 out:
1990 reiserfs_write_unlock(inode->i_sb);
1991 return ret;
1868} 1992}
1869 1993
1870static int reiserfs_dquot_drop(struct inode *inode) 1994static int reiserfs_dquot_drop(struct inode *inode)
1871{ 1995{
1872 struct reiserfs_transaction_handle th; 1996 struct reiserfs_transaction_handle th;
1873 int ret, err; 1997 int ret, err;
1874 1998
1875 /* We may delete quota structure so we need to reserve enough blocks */ 1999 /* We may delete quota structure so we need to reserve enough blocks */
1876 reiserfs_write_lock(inode->i_sb); 2000 reiserfs_write_lock(inode->i_sb);
1877 ret = journal_begin(&th, inode->i_sb, 2*REISERFS_QUOTA_DEL_BLOCKS(inode->i_sb)); 2001 ret =
1878 if (ret) 2002 journal_begin(&th, inode->i_sb,
1879 goto out; 2003 2 * REISERFS_QUOTA_DEL_BLOCKS(inode->i_sb));
1880 ret = dquot_drop(inode); 2004 if (ret)
1881 err = journal_end(&th, inode->i_sb, 2*REISERFS_QUOTA_DEL_BLOCKS(inode->i_sb)); 2005 goto out;
1882 if (!ret && err) 2006 ret = dquot_drop(inode);
1883 ret = err; 2007 err =
1884out: 2008 journal_end(&th, inode->i_sb,
1885 reiserfs_write_unlock(inode->i_sb); 2009 2 * REISERFS_QUOTA_DEL_BLOCKS(inode->i_sb));
1886 return ret; 2010 if (!ret && err)
2011 ret = err;
2012 out:
2013 reiserfs_write_unlock(inode->i_sb);
2014 return ret;
1887} 2015}
1888 2016
1889static int reiserfs_write_dquot(struct dquot *dquot) 2017static int reiserfs_write_dquot(struct dquot *dquot)
1890{ 2018{
1891 struct reiserfs_transaction_handle th; 2019 struct reiserfs_transaction_handle th;
1892 int ret, err; 2020 int ret, err;
1893 2021
1894 reiserfs_write_lock(dquot->dq_sb); 2022 reiserfs_write_lock(dquot->dq_sb);
1895 ret = journal_begin(&th, dquot->dq_sb, REISERFS_QUOTA_TRANS_BLOCKS(dquot->dq_sb)); 2023 ret =
1896 if (ret) 2024 journal_begin(&th, dquot->dq_sb,
1897 goto out; 2025 REISERFS_QUOTA_TRANS_BLOCKS(dquot->dq_sb));
1898 ret = dquot_commit(dquot); 2026 if (ret)
1899 err = journal_end(&th, dquot->dq_sb, REISERFS_QUOTA_TRANS_BLOCKS(dquot->dq_sb)); 2027 goto out;
1900 if (!ret && err) 2028 ret = dquot_commit(dquot);
1901 ret = err; 2029 err =
1902out: 2030 journal_end(&th, dquot->dq_sb,
1903 reiserfs_write_unlock(dquot->dq_sb); 2031 REISERFS_QUOTA_TRANS_BLOCKS(dquot->dq_sb));
1904 return ret; 2032 if (!ret && err)
2033 ret = err;
2034 out:
2035 reiserfs_write_unlock(dquot->dq_sb);
2036 return ret;
1905} 2037}
1906 2038
1907static int reiserfs_acquire_dquot(struct dquot *dquot) 2039static int reiserfs_acquire_dquot(struct dquot *dquot)
1908{ 2040{
1909 struct reiserfs_transaction_handle th; 2041 struct reiserfs_transaction_handle th;
1910 int ret, err; 2042 int ret, err;
1911 2043
1912 reiserfs_write_lock(dquot->dq_sb); 2044 reiserfs_write_lock(dquot->dq_sb);
1913 ret = journal_begin(&th, dquot->dq_sb, REISERFS_QUOTA_INIT_BLOCKS(dquot->dq_sb)); 2045 ret =
1914 if (ret) 2046 journal_begin(&th, dquot->dq_sb,
1915 goto out; 2047 REISERFS_QUOTA_INIT_BLOCKS(dquot->dq_sb));
1916 ret = dquot_acquire(dquot); 2048 if (ret)
1917 err = journal_end(&th, dquot->dq_sb, REISERFS_QUOTA_INIT_BLOCKS(dquot->dq_sb)); 2049 goto out;
1918 if (!ret && err) 2050 ret = dquot_acquire(dquot);
1919 ret = err; 2051 err =
1920out: 2052 journal_end(&th, dquot->dq_sb,
1921 reiserfs_write_unlock(dquot->dq_sb); 2053 REISERFS_QUOTA_INIT_BLOCKS(dquot->dq_sb));
1922 return ret; 2054 if (!ret && err)
2055 ret = err;
2056 out:
2057 reiserfs_write_unlock(dquot->dq_sb);
2058 return ret;
1923} 2059}
1924 2060
1925static int reiserfs_release_dquot(struct dquot *dquot) 2061static int reiserfs_release_dquot(struct dquot *dquot)
1926{ 2062{
1927 struct reiserfs_transaction_handle th; 2063 struct reiserfs_transaction_handle th;
1928 int ret, err; 2064 int ret, err;
1929 2065
1930 reiserfs_write_lock(dquot->dq_sb); 2066 reiserfs_write_lock(dquot->dq_sb);
1931 ret = journal_begin(&th, dquot->dq_sb, REISERFS_QUOTA_DEL_BLOCKS(dquot->dq_sb)); 2067 ret =
1932 if (ret) 2068 journal_begin(&th, dquot->dq_sb,
1933 goto out; 2069 REISERFS_QUOTA_DEL_BLOCKS(dquot->dq_sb));
1934 ret = dquot_release(dquot); 2070 if (ret)
1935 err = journal_end(&th, dquot->dq_sb, REISERFS_QUOTA_DEL_BLOCKS(dquot->dq_sb)); 2071 goto out;
1936 if (!ret && err) 2072 ret = dquot_release(dquot);
1937 ret = err; 2073 err =
1938out: 2074 journal_end(&th, dquot->dq_sb,
1939 reiserfs_write_unlock(dquot->dq_sb); 2075 REISERFS_QUOTA_DEL_BLOCKS(dquot->dq_sb));
1940 return ret; 2076 if (!ret && err)
2077 ret = err;
2078 out:
2079 reiserfs_write_unlock(dquot->dq_sb);
2080 return ret;
1941} 2081}
1942 2082
1943static int reiserfs_mark_dquot_dirty(struct dquot *dquot) 2083static int reiserfs_mark_dquot_dirty(struct dquot *dquot)
1944{ 2084{
1945 /* Are we journalling quotas? */ 2085 /* Are we journalling quotas? */
1946 if (REISERFS_SB(dquot->dq_sb)->s_qf_names[USRQUOTA] || 2086 if (REISERFS_SB(dquot->dq_sb)->s_qf_names[USRQUOTA] ||
1947 REISERFS_SB(dquot->dq_sb)->s_qf_names[GRPQUOTA]) { 2087 REISERFS_SB(dquot->dq_sb)->s_qf_names[GRPQUOTA]) {
1948 dquot_mark_dquot_dirty(dquot); 2088 dquot_mark_dquot_dirty(dquot);
1949 return reiserfs_write_dquot(dquot); 2089 return reiserfs_write_dquot(dquot);
1950 } 2090 } else
1951 else 2091 return dquot_mark_dquot_dirty(dquot);
1952 return dquot_mark_dquot_dirty(dquot);
1953} 2092}
1954 2093
1955static int reiserfs_write_info(struct super_block *sb, int type) 2094static int reiserfs_write_info(struct super_block *sb, int type)
1956{ 2095{
1957 struct reiserfs_transaction_handle th; 2096 struct reiserfs_transaction_handle th;
1958 int ret, err; 2097 int ret, err;
1959 2098
1960 /* Data block + inode block */ 2099 /* Data block + inode block */
1961 reiserfs_write_lock(sb); 2100 reiserfs_write_lock(sb);
1962 ret = journal_begin(&th, sb, 2); 2101 ret = journal_begin(&th, sb, 2);
1963 if (ret) 2102 if (ret)
1964 goto out; 2103 goto out;
1965 ret = dquot_commit_info(sb, type); 2104 ret = dquot_commit_info(sb, type);
1966 err = journal_end(&th, sb, 2); 2105 err = journal_end(&th, sb, 2);
1967 if (!ret && err) 2106 if (!ret && err)
1968 ret = err; 2107 ret = err;
1969out: 2108 out:
1970 reiserfs_write_unlock(sb); 2109 reiserfs_write_unlock(sb);
1971 return ret; 2110 return ret;
1972} 2111}
1973 2112
1974/* 2113/*
@@ -1977,45 +2116,48 @@ out:
1977static int reiserfs_quota_on_mount(struct super_block *sb, int type) 2116static int reiserfs_quota_on_mount(struct super_block *sb, int type)
1978{ 2117{
1979 return vfs_quota_on_mount(sb, REISERFS_SB(sb)->s_qf_names[type], 2118 return vfs_quota_on_mount(sb, REISERFS_SB(sb)->s_qf_names[type],
1980 REISERFS_SB(sb)->s_jquota_fmt, type); 2119 REISERFS_SB(sb)->s_jquota_fmt, type);
1981} 2120}
1982 2121
1983/* 2122/*
1984 * Standard function to be called on quota_on 2123 * Standard function to be called on quota_on
1985 */ 2124 */
1986static int reiserfs_quota_on(struct super_block *sb, int type, int format_id, char *path) 2125static int reiserfs_quota_on(struct super_block *sb, int type, int format_id,
2126 char *path)
1987{ 2127{
1988 int err; 2128 int err;
1989 struct nameidata nd; 2129 struct nameidata nd;
1990 2130
1991 if (!(REISERFS_SB(sb)->s_mount_opt & (1<<REISERFS_QUOTA))) 2131 if (!(REISERFS_SB(sb)->s_mount_opt & (1 << REISERFS_QUOTA)))
1992 return -EINVAL; 2132 return -EINVAL;
1993 err = path_lookup(path, LOOKUP_FOLLOW, &nd); 2133 err = path_lookup(path, LOOKUP_FOLLOW, &nd);
1994 if (err) 2134 if (err)
1995 return err; 2135 return err;
1996 /* Quotafile not on the same filesystem? */ 2136 /* Quotafile not on the same filesystem? */
1997 if (nd.mnt->mnt_sb != sb) { 2137 if (nd.mnt->mnt_sb != sb) {
1998 path_release(&nd); 2138 path_release(&nd);
1999 return -EXDEV; 2139 return -EXDEV;
2000 } 2140 }
2001 /* We must not pack tails for quota files on reiserfs for quota IO to work */ 2141 /* We must not pack tails for quota files on reiserfs for quota IO to work */
2002 if (!REISERFS_I(nd.dentry->d_inode)->i_flags & i_nopack_mask) { 2142 if (!REISERFS_I(nd.dentry->d_inode)->i_flags & i_nopack_mask) {
2003 reiserfs_warning(sb, "reiserfs: Quota file must have tail packing disabled."); 2143 reiserfs_warning(sb,
2004 path_release(&nd); 2144 "reiserfs: Quota file must have tail packing disabled.");
2005 return -EINVAL; 2145 path_release(&nd);
2006 } 2146 return -EINVAL;
2007 /* Not journalling quota? No more tests needed... */ 2147 }
2008 if (!REISERFS_SB(sb)->s_qf_names[USRQUOTA] && 2148 /* Not journalling quota? No more tests needed... */
2009 !REISERFS_SB(sb)->s_qf_names[GRPQUOTA]) { 2149 if (!REISERFS_SB(sb)->s_qf_names[USRQUOTA] &&
2150 !REISERFS_SB(sb)->s_qf_names[GRPQUOTA]) {
2151 path_release(&nd);
2152 return vfs_quota_on(sb, type, format_id, path);
2153 }
2154 /* Quotafile not of fs root? */
2155 if (nd.dentry->d_parent->d_inode != sb->s_root->d_inode)
2156 reiserfs_warning(sb,
2157 "reiserfs: Quota file not on filesystem root. "
2158 "Journalled quota will not work.");
2010 path_release(&nd); 2159 path_release(&nd);
2011 return vfs_quota_on(sb, type, format_id, path); 2160 return vfs_quota_on(sb, type, format_id, path);
2012 }
2013 /* Quotafile not of fs root? */
2014 if (nd.dentry->d_parent->d_inode != sb->s_root->d_inode)
2015 reiserfs_warning(sb, "reiserfs: Quota file not on filesystem root. "
2016 "Journalled quota will not work.");
2017 path_release(&nd);
2018 return vfs_quota_on(sb, type, format_id, path);
2019} 2161}
2020 2162
2021/* Read data from quotafile - avoid pagecache and such because we cannot afford 2163/* Read data from quotafile - avoid pagecache and such because we cannot afford
@@ -2025,42 +2167,44 @@ static int reiserfs_quota_on(struct super_block *sb, int type, int format_id, ch
2025static ssize_t reiserfs_quota_read(struct super_block *sb, int type, char *data, 2167static ssize_t reiserfs_quota_read(struct super_block *sb, int type, char *data,
2026 size_t len, loff_t off) 2168 size_t len, loff_t off)
2027{ 2169{
2028 struct inode *inode = sb_dqopt(sb)->files[type]; 2170 struct inode *inode = sb_dqopt(sb)->files[type];
2029 unsigned long blk = off >> sb->s_blocksize_bits; 2171 unsigned long blk = off >> sb->s_blocksize_bits;
2030 int err = 0, offset = off & (sb->s_blocksize - 1), tocopy; 2172 int err = 0, offset = off & (sb->s_blocksize - 1), tocopy;
2031 size_t toread; 2173 size_t toread;
2032 struct buffer_head tmp_bh, *bh; 2174 struct buffer_head tmp_bh, *bh;
2033 loff_t i_size = i_size_read(inode); 2175 loff_t i_size = i_size_read(inode);
2034 2176
2035 if (off > i_size) 2177 if (off > i_size)
2036 return 0; 2178 return 0;
2037 if (off+len > i_size) 2179 if (off + len > i_size)
2038 len = i_size-off; 2180 len = i_size - off;
2039 toread = len; 2181 toread = len;
2040 while (toread > 0) { 2182 while (toread > 0) {
2041 tocopy = sb->s_blocksize - offset < toread ? sb->s_blocksize - offset : toread; 2183 tocopy =
2042 tmp_bh.b_state = 0; 2184 sb->s_blocksize - offset <
2043 /* Quota files are without tails so we can safely use this function */ 2185 toread ? sb->s_blocksize - offset : toread;
2044 reiserfs_write_lock(sb); 2186 tmp_bh.b_state = 0;
2045 err = reiserfs_get_block(inode, blk, &tmp_bh, 0); 2187 /* Quota files are without tails so we can safely use this function */
2046 reiserfs_write_unlock(sb); 2188 reiserfs_write_lock(sb);
2047 if (err) 2189 err = reiserfs_get_block(inode, blk, &tmp_bh, 0);
2048 return err; 2190 reiserfs_write_unlock(sb);
2049 if (!buffer_mapped(&tmp_bh)) /* A hole? */ 2191 if (err)
2050 memset(data, 0, tocopy); 2192 return err;
2051 else { 2193 if (!buffer_mapped(&tmp_bh)) /* A hole? */
2052 bh = sb_bread(sb, tmp_bh.b_blocknr); 2194 memset(data, 0, tocopy);
2053 if (!bh) 2195 else {
2054 return -EIO; 2196 bh = sb_bread(sb, tmp_bh.b_blocknr);
2055 memcpy(data, bh->b_data+offset, tocopy); 2197 if (!bh)
2056 brelse(bh); 2198 return -EIO;
2057 } 2199 memcpy(data, bh->b_data + offset, tocopy);
2058 offset = 0; 2200 brelse(bh);
2059 toread -= tocopy; 2201 }
2060 data += tocopy; 2202 offset = 0;
2061 blk++; 2203 toread -= tocopy;
2062 } 2204 data += tocopy;
2063 return len; 2205 blk++;
2206 }
2207 return len;
2064} 2208}
2065 2209
2066/* Write to quotafile (we know the transaction is already started and has 2210/* Write to quotafile (we know the transaction is already started and has
@@ -2068,117 +2212,116 @@ static ssize_t reiserfs_quota_read(struct super_block *sb, int type, char *data,
2068static ssize_t reiserfs_quota_write(struct super_block *sb, int type, 2212static ssize_t reiserfs_quota_write(struct super_block *sb, int type,
2069 const char *data, size_t len, loff_t off) 2213 const char *data, size_t len, loff_t off)
2070{ 2214{
2071 struct inode *inode = sb_dqopt(sb)->files[type]; 2215 struct inode *inode = sb_dqopt(sb)->files[type];
2072 unsigned long blk = off >> sb->s_blocksize_bits; 2216 unsigned long blk = off >> sb->s_blocksize_bits;
2073 int err = 0, offset = off & (sb->s_blocksize - 1), tocopy; 2217 int err = 0, offset = off & (sb->s_blocksize - 1), tocopy;
2074 int journal_quota = REISERFS_SB(sb)->s_qf_names[type] != NULL; 2218 int journal_quota = REISERFS_SB(sb)->s_qf_names[type] != NULL;
2075 size_t towrite = len; 2219 size_t towrite = len;
2076 struct buffer_head tmp_bh, *bh; 2220 struct buffer_head tmp_bh, *bh;
2077 2221
2078 down(&inode->i_sem); 2222 down(&inode->i_sem);
2079 while (towrite > 0) { 2223 while (towrite > 0) {
2080 tocopy = sb->s_blocksize - offset < towrite ? 2224 tocopy = sb->s_blocksize - offset < towrite ?
2081 sb->s_blocksize - offset : towrite; 2225 sb->s_blocksize - offset : towrite;
2082 tmp_bh.b_state = 0; 2226 tmp_bh.b_state = 0;
2083 err = reiserfs_get_block(inode, blk, &tmp_bh, GET_BLOCK_CREATE); 2227 err = reiserfs_get_block(inode, blk, &tmp_bh, GET_BLOCK_CREATE);
2084 if (err) 2228 if (err)
2085 goto out; 2229 goto out;
2086 if (offset || tocopy != sb->s_blocksize) 2230 if (offset || tocopy != sb->s_blocksize)
2087 bh = sb_bread(sb, tmp_bh.b_blocknr); 2231 bh = sb_bread(sb, tmp_bh.b_blocknr);
2088 else 2232 else
2089 bh = sb_getblk(sb, tmp_bh.b_blocknr); 2233 bh = sb_getblk(sb, tmp_bh.b_blocknr);
2090 if (!bh) { 2234 if (!bh) {
2091 err = -EIO; 2235 err = -EIO;
2092 goto out; 2236 goto out;
2093 } 2237 }
2094 lock_buffer(bh); 2238 lock_buffer(bh);
2095 memcpy(bh->b_data+offset, data, tocopy); 2239 memcpy(bh->b_data + offset, data, tocopy);
2096 flush_dcache_page(bh->b_page); 2240 flush_dcache_page(bh->b_page);
2097 set_buffer_uptodate(bh); 2241 set_buffer_uptodate(bh);
2098 unlock_buffer(bh); 2242 unlock_buffer(bh);
2099 reiserfs_prepare_for_journal(sb, bh, 1); 2243 reiserfs_prepare_for_journal(sb, bh, 1);
2100 journal_mark_dirty(current->journal_info, sb, bh); 2244 journal_mark_dirty(current->journal_info, sb, bh);
2101 if (!journal_quota) 2245 if (!journal_quota)
2102 reiserfs_add_ordered_list(inode, bh); 2246 reiserfs_add_ordered_list(inode, bh);
2103 brelse(bh); 2247 brelse(bh);
2104 offset = 0; 2248 offset = 0;
2105 towrite -= tocopy; 2249 towrite -= tocopy;
2106 data += tocopy; 2250 data += tocopy;
2107 blk++; 2251 blk++;
2108 } 2252 }
2109out: 2253 out:
2110 if (len == towrite) 2254 if (len == towrite)
2111 return err; 2255 return err;
2112 if (inode->i_size < off+len-towrite) 2256 if (inode->i_size < off + len - towrite)
2113 i_size_write(inode, off+len-towrite); 2257 i_size_write(inode, off + len - towrite);
2114 inode->i_version++; 2258 inode->i_version++;
2115 inode->i_mtime = inode->i_ctime = CURRENT_TIME; 2259 inode->i_mtime = inode->i_ctime = CURRENT_TIME;
2116 mark_inode_dirty(inode); 2260 mark_inode_dirty(inode);
2117 up(&inode->i_sem); 2261 up(&inode->i_sem);
2118 return len - towrite; 2262 return len - towrite;
2119} 2263}
2120 2264
2121#endif 2265#endif
2122 2266
2123static struct super_block* 2267static struct super_block *get_super_block(struct file_system_type *fs_type,
2124get_super_block (struct file_system_type *fs_type, int flags, 2268 int flags, const char *dev_name,
2125 const char *dev_name, void *data) 2269 void *data)
2126{ 2270{
2127 return get_sb_bdev(fs_type, flags, dev_name, data, reiserfs_fill_super); 2271 return get_sb_bdev(fs_type, flags, dev_name, data, reiserfs_fill_super);
2128} 2272}
2129 2273
2130static int __init 2274static int __init init_reiserfs_fs(void)
2131init_reiserfs_fs ( void )
2132{ 2275{
2133 int ret; 2276 int ret;
2134 2277
2135 if ((ret = init_inodecache ())) { 2278 if ((ret = init_inodecache())) {
2136 return ret; 2279 return ret;
2137 } 2280 }
2138 2281
2139 if ((ret = reiserfs_xattr_register_handlers ())) 2282 if ((ret = reiserfs_xattr_register_handlers()))
2140 goto failed_reiserfs_xattr_register_handlers; 2283 goto failed_reiserfs_xattr_register_handlers;
2141 2284
2142 reiserfs_proc_info_global_init (); 2285 reiserfs_proc_info_global_init();
2143 reiserfs_proc_register_global ("version", reiserfs_global_version_in_proc); 2286 reiserfs_proc_register_global("version",
2287 reiserfs_global_version_in_proc);
2144 2288
2145 ret = register_filesystem (& reiserfs_fs_type); 2289 ret = register_filesystem(&reiserfs_fs_type);
2146 2290
2147 if (ret == 0) { 2291 if (ret == 0) {
2148 return 0; 2292 return 0;
2149 } 2293 }
2150 2294
2151 reiserfs_xattr_unregister_handlers (); 2295 reiserfs_xattr_unregister_handlers();
2152 2296
2153failed_reiserfs_xattr_register_handlers: 2297 failed_reiserfs_xattr_register_handlers:
2154 reiserfs_proc_unregister_global ("version"); 2298 reiserfs_proc_unregister_global("version");
2155 reiserfs_proc_info_global_done (); 2299 reiserfs_proc_info_global_done();
2156 destroy_inodecache (); 2300 destroy_inodecache();
2157 2301
2158 return ret; 2302 return ret;
2159} 2303}
2160 2304
2161static void __exit 2305static void __exit exit_reiserfs_fs(void)
2162exit_reiserfs_fs ( void )
2163{ 2306{
2164 reiserfs_xattr_unregister_handlers (); 2307 reiserfs_xattr_unregister_handlers();
2165 reiserfs_proc_unregister_global ("version"); 2308 reiserfs_proc_unregister_global("version");
2166 reiserfs_proc_info_global_done (); 2309 reiserfs_proc_info_global_done();
2167 unregister_filesystem (& reiserfs_fs_type); 2310 unregister_filesystem(&reiserfs_fs_type);
2168 destroy_inodecache (); 2311 destroy_inodecache();
2169} 2312}
2170 2313
2171struct file_system_type reiserfs_fs_type = { 2314struct file_system_type reiserfs_fs_type = {
2172 .owner = THIS_MODULE, 2315 .owner = THIS_MODULE,
2173 .name = "reiserfs", 2316 .name = "reiserfs",
2174 .get_sb = get_super_block, 2317 .get_sb = get_super_block,
2175 .kill_sb = kill_block_super, 2318 .kill_sb = kill_block_super,
2176 .fs_flags = FS_REQUIRES_DEV, 2319 .fs_flags = FS_REQUIRES_DEV,
2177}; 2320};
2178 2321
2179MODULE_DESCRIPTION ("ReiserFS journaled filesystem"); 2322MODULE_DESCRIPTION("ReiserFS journaled filesystem");
2180MODULE_AUTHOR ("Hans Reiser <reiser@namesys.com>"); 2323MODULE_AUTHOR("Hans Reiser <reiser@namesys.com>");
2181MODULE_LICENSE ("GPL"); 2324MODULE_LICENSE("GPL");
2182 2325
2183module_init (init_reiserfs_fs); 2326module_init(init_reiserfs_fs);
2184module_exit (exit_reiserfs_fs); 2327module_exit(exit_reiserfs_fs);
diff --git a/fs/reiserfs/tail_conversion.c b/fs/reiserfs/tail_conversion.c
index 6191909d5165..c92e124f628e 100644
--- a/fs/reiserfs/tail_conversion.c
+++ b/fs/reiserfs/tail_conversion.c
@@ -11,156 +11,159 @@
11/* access to tail : when one is going to read tail it must make sure, that is not running. 11/* access to tail : when one is going to read tail it must make sure, that is not running.
12 direct2indirect and indirect2direct can not run concurrently */ 12 direct2indirect and indirect2direct can not run concurrently */
13 13
14
15/* Converts direct items to an unformatted node. Panics if file has no 14/* Converts direct items to an unformatted node. Panics if file has no
16 tail. -ENOSPC if no disk space for conversion */ 15 tail. -ENOSPC if no disk space for conversion */
17/* path points to first direct item of the file regarless of how many of 16/* path points to first direct item of the file regarless of how many of
18 them are there */ 17 them are there */
19int direct2indirect (struct reiserfs_transaction_handle *th, struct inode * inode, 18int direct2indirect(struct reiserfs_transaction_handle *th, struct inode *inode,
20 struct path * path, struct buffer_head * unbh, 19 struct path *path, struct buffer_head *unbh,
21 loff_t tail_offset) 20 loff_t tail_offset)
22{ 21{
23 struct super_block * sb = inode->i_sb; 22 struct super_block *sb = inode->i_sb;
24 struct buffer_head *up_to_date_bh ; 23 struct buffer_head *up_to_date_bh;
25 struct item_head * p_le_ih = PATH_PITEM_HEAD (path); 24 struct item_head *p_le_ih = PATH_PITEM_HEAD(path);
26 unsigned long total_tail = 0 ; 25 unsigned long total_tail = 0;
27 struct cpu_key end_key; /* Key to search for the last byte of the 26 struct cpu_key end_key; /* Key to search for the last byte of the
28 converted item. */ 27 converted item. */
29 struct item_head ind_ih; /* new indirect item to be inserted or 28 struct item_head ind_ih; /* new indirect item to be inserted or
30 key of unfm pointer to be pasted */ 29 key of unfm pointer to be pasted */
31 int n_blk_size, 30 int n_blk_size, n_retval; /* returned value for reiserfs_insert_item and clones */
32 n_retval; /* returned value for reiserfs_insert_item and clones */ 31 unp_t unfm_ptr; /* Handle on an unformatted node
33 unp_t unfm_ptr; /* Handle on an unformatted node 32 that will be inserted in the
34 that will be inserted in the 33 tree. */
35 tree. */ 34
36 35 BUG_ON(!th->t_trans_id);
37 BUG_ON (!th->t_trans_id); 36
38 37 REISERFS_SB(sb)->s_direct2indirect++;
39 REISERFS_SB(sb)->s_direct2indirect ++; 38
40 39 n_blk_size = sb->s_blocksize;
41 n_blk_size = sb->s_blocksize; 40
42 41 /* and key to search for append or insert pointer to the new
43 /* and key to search for append or insert pointer to the new 42 unformatted node. */
44 unformatted node. */ 43 copy_item_head(&ind_ih, p_le_ih);
45 copy_item_head (&ind_ih, p_le_ih); 44 set_le_ih_k_offset(&ind_ih, tail_offset);
46 set_le_ih_k_offset (&ind_ih, tail_offset); 45 set_le_ih_k_type(&ind_ih, TYPE_INDIRECT);
47 set_le_ih_k_type (&ind_ih, TYPE_INDIRECT); 46
48 47 /* Set the key to search for the place for new unfm pointer */
49 /* Set the key to search for the place for new unfm pointer */ 48 make_cpu_key(&end_key, inode, tail_offset, TYPE_INDIRECT, 4);
50 make_cpu_key (&end_key, inode, tail_offset, TYPE_INDIRECT, 4); 49
51 50 // FIXME: we could avoid this
52 // FIXME: we could avoid this 51 if (search_for_position_by_key(sb, &end_key, path) == POSITION_FOUND) {
53 if ( search_for_position_by_key (sb, &end_key, path) == POSITION_FOUND ) { 52 reiserfs_warning(sb, "PAP-14030: direct2indirect: "
54 reiserfs_warning (sb, "PAP-14030: direct2indirect: " 53 "pasted or inserted byte exists in the tree %K. "
55 "pasted or inserted byte exists in the tree %K. " 54 "Use fsck to repair.", &end_key);
56 "Use fsck to repair.", &end_key); 55 pathrelse(path);
57 pathrelse(path); 56 return -EIO;
58 return -EIO; 57 }
59 } 58
60 59 p_le_ih = PATH_PITEM_HEAD(path);
61 p_le_ih = PATH_PITEM_HEAD (path); 60
62 61 unfm_ptr = cpu_to_le32(unbh->b_blocknr);
63 unfm_ptr = cpu_to_le32 (unbh->b_blocknr); 62
64 63 if (is_statdata_le_ih(p_le_ih)) {
65 if ( is_statdata_le_ih (p_le_ih) ) { 64 /* Insert new indirect item. */
66 /* Insert new indirect item. */ 65 set_ih_free_space(&ind_ih, 0); /* delete at nearest future */
67 set_ih_free_space (&ind_ih, 0); /* delete at nearest future */ 66 put_ih_item_len(&ind_ih, UNFM_P_SIZE);
68 put_ih_item_len( &ind_ih, UNFM_P_SIZE ); 67 PATH_LAST_POSITION(path)++;
69 PATH_LAST_POSITION (path)++; 68 n_retval =
70 n_retval = reiserfs_insert_item (th, path, &end_key, &ind_ih, inode, 69 reiserfs_insert_item(th, path, &end_key, &ind_ih, inode,
71 (char *)&unfm_ptr); 70 (char *)&unfm_ptr);
72 } else {
73 /* Paste into last indirect item of an object. */
74 n_retval = reiserfs_paste_into_item(th, path, &end_key, inode,
75 (char *)&unfm_ptr, UNFM_P_SIZE);
76 }
77 if ( n_retval ) {
78 return n_retval;
79 }
80
81 // note: from here there are two keys which have matching first
82 // three key components. They only differ by the fourth one.
83
84
85 /* Set the key to search for the direct items of the file */
86 make_cpu_key (&end_key, inode, max_reiserfs_offset (inode), TYPE_DIRECT, 4);
87
88 /* Move bytes from the direct items to the new unformatted node
89 and delete them. */
90 while (1) {
91 int tail_size;
92
93 /* end_key.k_offset is set so, that we will always have found
94 last item of the file */
95 if ( search_for_position_by_key (sb, &end_key, path) == POSITION_FOUND )
96 reiserfs_panic (sb, "PAP-14050: direct2indirect: "
97 "direct item (%K) not found", &end_key);
98 p_le_ih = PATH_PITEM_HEAD (path);
99 RFALSE( !is_direct_le_ih (p_le_ih),
100 "vs-14055: direct item expected(%K), found %h",
101 &end_key, p_le_ih);
102 tail_size = (le_ih_k_offset (p_le_ih) & (n_blk_size - 1))
103 + ih_item_len(p_le_ih) - 1;
104
105 /* we only send the unbh pointer if the buffer is not up to date.
106 ** this avoids overwriting good data from writepage() with old data
107 ** from the disk or buffer cache
108 ** Special case: unbh->b_page will be NULL if we are coming through
109 ** DIRECT_IO handler here.
110 */
111 if (!unbh->b_page || buffer_uptodate(unbh) || PageUptodate(unbh->b_page)) {
112 up_to_date_bh = NULL ;
113 } else { 71 } else {
114 up_to_date_bh = unbh ; 72 /* Paste into last indirect item of an object. */
73 n_retval = reiserfs_paste_into_item(th, path, &end_key, inode,
74 (char *)&unfm_ptr,
75 UNFM_P_SIZE);
115 } 76 }
116 n_retval = reiserfs_delete_item (th, path, &end_key, inode, 77 if (n_retval) {
117 up_to_date_bh) ; 78 return n_retval;
118 79 }
119 total_tail += n_retval ; 80 // note: from here there are two keys which have matching first
120 if (tail_size == n_retval) 81 // three key components. They only differ by the fourth one.
121 // done: file does not have direct items anymore 82
122 break; 83 /* Set the key to search for the direct items of the file */
123 84 make_cpu_key(&end_key, inode, max_reiserfs_offset(inode), TYPE_DIRECT,
124 } 85 4);
125 /* if we've copied bytes from disk into the page, we need to zero 86
126 ** out the unused part of the block (it was not up to date before) 87 /* Move bytes from the direct items to the new unformatted node
127 */ 88 and delete them. */
128 if (up_to_date_bh) { 89 while (1) {
129 unsigned pgoff = (tail_offset + total_tail - 1) & (PAGE_CACHE_SIZE - 1); 90 int tail_size;
130 char *kaddr=kmap_atomic(up_to_date_bh->b_page, KM_USER0); 91
131 memset(kaddr + pgoff, 0, n_blk_size - total_tail) ; 92 /* end_key.k_offset is set so, that we will always have found
132 kunmap_atomic(kaddr, KM_USER0); 93 last item of the file */
133 } 94 if (search_for_position_by_key(sb, &end_key, path) ==
134 95 POSITION_FOUND)
135 REISERFS_I(inode)->i_first_direct_byte = U32_MAX; 96 reiserfs_panic(sb,
136 97 "PAP-14050: direct2indirect: "
137 return 0; 98 "direct item (%K) not found", &end_key);
138} 99 p_le_ih = PATH_PITEM_HEAD(path);
100 RFALSE(!is_direct_le_ih(p_le_ih),
101 "vs-14055: direct item expected(%K), found %h",
102 &end_key, p_le_ih);
103 tail_size = (le_ih_k_offset(p_le_ih) & (n_blk_size - 1))
104 + ih_item_len(p_le_ih) - 1;
105
106 /* we only send the unbh pointer if the buffer is not up to date.
107 ** this avoids overwriting good data from writepage() with old data
108 ** from the disk or buffer cache
109 ** Special case: unbh->b_page will be NULL if we are coming through
110 ** DIRECT_IO handler here.
111 */
112 if (!unbh->b_page || buffer_uptodate(unbh)
113 || PageUptodate(unbh->b_page)) {
114 up_to_date_bh = NULL;
115 } else {
116 up_to_date_bh = unbh;
117 }
118 n_retval = reiserfs_delete_item(th, path, &end_key, inode,
119 up_to_date_bh);
120
121 total_tail += n_retval;
122 if (tail_size == n_retval)
123 // done: file does not have direct items anymore
124 break;
139 125
126 }
127 /* if we've copied bytes from disk into the page, we need to zero
128 ** out the unused part of the block (it was not up to date before)
129 */
130 if (up_to_date_bh) {
131 unsigned pgoff =
132 (tail_offset + total_tail - 1) & (PAGE_CACHE_SIZE - 1);
133 char *kaddr = kmap_atomic(up_to_date_bh->b_page, KM_USER0);
134 memset(kaddr + pgoff, 0, n_blk_size - total_tail);
135 kunmap_atomic(kaddr, KM_USER0);
136 }
137
138 REISERFS_I(inode)->i_first_direct_byte = U32_MAX;
139
140 return 0;
141}
140 142
141/* stolen from fs/buffer.c */ 143/* stolen from fs/buffer.c */
142void reiserfs_unmap_buffer(struct buffer_head *bh) { 144void reiserfs_unmap_buffer(struct buffer_head *bh)
143 lock_buffer(bh) ; 145{
144 if (buffer_journaled(bh) || buffer_journal_dirty(bh)) { 146 lock_buffer(bh);
145 BUG() ; 147 if (buffer_journaled(bh) || buffer_journal_dirty(bh)) {
146 } 148 BUG();
147 clear_buffer_dirty(bh) ; 149 }
148 /* Remove the buffer from whatever list it belongs to. We are mostly 150 clear_buffer_dirty(bh);
149 interested in removing it from per-sb j_dirty_buffers list, to avoid 151 /* Remove the buffer from whatever list it belongs to. We are mostly
150 BUG() on attempt to write not mapped buffer */ 152 interested in removing it from per-sb j_dirty_buffers list, to avoid
151 if ( (!list_empty(&bh->b_assoc_buffers) || bh->b_private) && bh->b_page) { 153 BUG() on attempt to write not mapped buffer */
152 struct inode *inode = bh->b_page->mapping->host; 154 if ((!list_empty(&bh->b_assoc_buffers) || bh->b_private) && bh->b_page) {
153 struct reiserfs_journal *j = SB_JOURNAL(inode->i_sb); 155 struct inode *inode = bh->b_page->mapping->host;
154 spin_lock(&j->j_dirty_buffers_lock); 156 struct reiserfs_journal *j = SB_JOURNAL(inode->i_sb);
155 list_del_init(&bh->b_assoc_buffers); 157 spin_lock(&j->j_dirty_buffers_lock);
156 reiserfs_free_jh(bh); 158 list_del_init(&bh->b_assoc_buffers);
157 spin_unlock(&j->j_dirty_buffers_lock); 159 reiserfs_free_jh(bh);
158 } 160 spin_unlock(&j->j_dirty_buffers_lock);
159 clear_buffer_mapped(bh) ; 161 }
160 clear_buffer_req(bh) ; 162 clear_buffer_mapped(bh);
161 clear_buffer_new(bh); 163 clear_buffer_req(bh);
162 bh->b_bdev = NULL; 164 clear_buffer_new(bh);
163 unlock_buffer(bh) ; 165 bh->b_bdev = NULL;
166 unlock_buffer(bh);
164} 167}
165 168
166/* this first locks inode (neither reads nor sync are permitted), 169/* this first locks inode (neither reads nor sync are permitted),
@@ -169,108 +172,108 @@ void reiserfs_unmap_buffer(struct buffer_head *bh) {
169 what we expect from it (number of cut bytes). But when tail remains 172 what we expect from it (number of cut bytes). But when tail remains
170 in the unformatted node, we set mode to SKIP_BALANCING and unlock 173 in the unformatted node, we set mode to SKIP_BALANCING and unlock
171 inode */ 174 inode */
172int indirect2direct (struct reiserfs_transaction_handle *th, 175int indirect2direct(struct reiserfs_transaction_handle *th, struct inode *p_s_inode, struct page *page, struct path *p_s_path, /* path to the indirect item. */
173 struct inode * p_s_inode, 176 const struct cpu_key *p_s_item_key, /* Key to look for unformatted node pointer to be cut. */
174 struct page *page, 177 loff_t n_new_file_size, /* New file size. */
175 struct path * p_s_path, /* path to the indirect item. */ 178 char *p_c_mode)
176 const struct cpu_key * p_s_item_key, /* Key to look for unformatted node pointer to be cut. */
177 loff_t n_new_file_size, /* New file size. */
178 char * p_c_mode)
179{ 179{
180 struct super_block * p_s_sb = p_s_inode->i_sb; 180 struct super_block *p_s_sb = p_s_inode->i_sb;
181 struct item_head s_ih; 181 struct item_head s_ih;
182 unsigned long n_block_size = p_s_sb->s_blocksize; 182 unsigned long n_block_size = p_s_sb->s_blocksize;
183 char * tail; 183 char *tail;
184 int tail_len, round_tail_len; 184 int tail_len, round_tail_len;
185 loff_t pos, pos1; /* position of first byte of the tail */ 185 loff_t pos, pos1; /* position of first byte of the tail */
186 struct cpu_key key; 186 struct cpu_key key;
187 187
188 BUG_ON (!th->t_trans_id); 188 BUG_ON(!th->t_trans_id);
189 189
190 REISERFS_SB(p_s_sb)->s_indirect2direct ++; 190 REISERFS_SB(p_s_sb)->s_indirect2direct++;
191 191
192 *p_c_mode = M_SKIP_BALANCING; 192 *p_c_mode = M_SKIP_BALANCING;
193 193
194 /* store item head path points to. */ 194 /* store item head path points to. */
195 copy_item_head (&s_ih, PATH_PITEM_HEAD(p_s_path));
196
197 tail_len = (n_new_file_size & (n_block_size - 1));
198 if (get_inode_sd_version (p_s_inode) == STAT_DATA_V2)
199 round_tail_len = ROUND_UP (tail_len);
200 else
201 round_tail_len = tail_len;
202
203 pos = le_ih_k_offset (&s_ih) - 1 + (ih_item_len(&s_ih) / UNFM_P_SIZE - 1) * p_s_sb->s_blocksize;
204 pos1 = pos;
205
206 // we are protected by i_sem. The tail can not disapper, not
207 // append can be done either
208 // we are in truncate or packing tail in file_release
209
210 tail = (char *)kmap(page) ; /* this can schedule */
211
212 if (path_changed (&s_ih, p_s_path)) {
213 /* re-search indirect item */
214 if ( search_for_position_by_key (p_s_sb, p_s_item_key, p_s_path) == POSITION_NOT_FOUND )
215 reiserfs_panic(p_s_sb, "PAP-5520: indirect2direct: "
216 "item to be converted %K does not exist", p_s_item_key);
217 copy_item_head(&s_ih, PATH_PITEM_HEAD(p_s_path)); 195 copy_item_head(&s_ih, PATH_PITEM_HEAD(p_s_path));
196
197 tail_len = (n_new_file_size & (n_block_size - 1));
198 if (get_inode_sd_version(p_s_inode) == STAT_DATA_V2)
199 round_tail_len = ROUND_UP(tail_len);
200 else
201 round_tail_len = tail_len;
202
203 pos =
204 le_ih_k_offset(&s_ih) - 1 + (ih_item_len(&s_ih) / UNFM_P_SIZE -
205 1) * p_s_sb->s_blocksize;
206 pos1 = pos;
207
208 // we are protected by i_sem. The tail can not disapper, not
209 // append can be done either
210 // we are in truncate or packing tail in file_release
211
212 tail = (char *)kmap(page); /* this can schedule */
213
214 if (path_changed(&s_ih, p_s_path)) {
215 /* re-search indirect item */
216 if (search_for_position_by_key(p_s_sb, p_s_item_key, p_s_path)
217 == POSITION_NOT_FOUND)
218 reiserfs_panic(p_s_sb,
219 "PAP-5520: indirect2direct: "
220 "item to be converted %K does not exist",
221 p_s_item_key);
222 copy_item_head(&s_ih, PATH_PITEM_HEAD(p_s_path));
218#ifdef CONFIG_REISERFS_CHECK 223#ifdef CONFIG_REISERFS_CHECK
219 pos = le_ih_k_offset (&s_ih) - 1 + 224 pos = le_ih_k_offset(&s_ih) - 1 +
220 (ih_item_len(&s_ih) / UNFM_P_SIZE - 1) * p_s_sb->s_blocksize; 225 (ih_item_len(&s_ih) / UNFM_P_SIZE -
221 if (pos != pos1) 226 1) * p_s_sb->s_blocksize;
222 reiserfs_panic (p_s_sb, "vs-5530: indirect2direct: " 227 if (pos != pos1)
223 "tail position changed while we were reading it"); 228 reiserfs_panic(p_s_sb, "vs-5530: indirect2direct: "
229 "tail position changed while we were reading it");
224#endif 230#endif
225 } 231 }
226
227
228 /* Set direct item header to insert. */
229 make_le_item_head (&s_ih, NULL, get_inode_item_key_version (p_s_inode), pos1 + 1,
230 TYPE_DIRECT, round_tail_len, 0xffff/*ih_free_space*/);
231
232 /* we want a pointer to the first byte of the tail in the page.
233 ** the page was locked and this part of the page was up to date when
234 ** indirect2direct was called, so we know the bytes are still valid
235 */
236 tail = tail + (pos & (PAGE_CACHE_SIZE - 1)) ;
237
238 PATH_LAST_POSITION(p_s_path)++;
239
240 key = *p_s_item_key;
241 set_cpu_key_k_type (&key, TYPE_DIRECT);
242 key.key_length = 4;
243 /* Insert tail as new direct item in the tree */
244 if ( reiserfs_insert_item(th, p_s_path, &key, &s_ih, p_s_inode,
245 tail ? tail : NULL) < 0 ) {
246 /* No disk memory. So we can not convert last unformatted node
247 to the direct item. In this case we used to adjust
248 indirect items's ih_free_space. Now ih_free_space is not
249 used, it would be ideal to write zeros to corresponding
250 unformatted node. For now i_size is considered as guard for
251 going out of file size */
252 kunmap(page) ;
253 return n_block_size - round_tail_len;
254 }
255 kunmap(page) ;
256
257 /* make sure to get the i_blocks changes from reiserfs_insert_item */
258 reiserfs_update_sd(th, p_s_inode);
259 232
260 // note: we have now the same as in above direct2indirect 233 /* Set direct item header to insert. */
261 // conversion: there are two keys which have matching first three 234 make_le_item_head(&s_ih, NULL, get_inode_item_key_version(p_s_inode),
262 // key components. They only differ by the fouhth one. 235 pos1 + 1, TYPE_DIRECT, round_tail_len,
236 0xffff /*ih_free_space */ );
237
238 /* we want a pointer to the first byte of the tail in the page.
239 ** the page was locked and this part of the page was up to date when
240 ** indirect2direct was called, so we know the bytes are still valid
241 */
242 tail = tail + (pos & (PAGE_CACHE_SIZE - 1));
243
244 PATH_LAST_POSITION(p_s_path)++;
245
246 key = *p_s_item_key;
247 set_cpu_key_k_type(&key, TYPE_DIRECT);
248 key.key_length = 4;
249 /* Insert tail as new direct item in the tree */
250 if (reiserfs_insert_item(th, p_s_path, &key, &s_ih, p_s_inode,
251 tail ? tail : NULL) < 0) {
252 /* No disk memory. So we can not convert last unformatted node
253 to the direct item. In this case we used to adjust
254 indirect items's ih_free_space. Now ih_free_space is not
255 used, it would be ideal to write zeros to corresponding
256 unformatted node. For now i_size is considered as guard for
257 going out of file size */
258 kunmap(page);
259 return n_block_size - round_tail_len;
260 }
261 kunmap(page);
263 262
264 /* We have inserted new direct item and must remove last 263 /* make sure to get the i_blocks changes from reiserfs_insert_item */
265 unformatted node. */ 264 reiserfs_update_sd(th, p_s_inode);
266 *p_c_mode = M_CUT;
267 265
268 /* we store position of first direct item in the in-core inode */ 266 // note: we have now the same as in above direct2indirect
269 //mark_file_with_tail (p_s_inode, pos1 + 1); 267 // conversion: there are two keys which have matching first three
270 REISERFS_I(p_s_inode)->i_first_direct_byte = pos1 + 1; 268 // key components. They only differ by the fouhth one.
271
272 return n_block_size - round_tail_len;
273}
274 269
270 /* We have inserted new direct item and must remove last
271 unformatted node. */
272 *p_c_mode = M_CUT;
275 273
274 /* we store position of first direct item in the in-core inode */
275 //mark_file_with_tail (p_s_inode, pos1 + 1);
276 REISERFS_I(p_s_inode)->i_first_direct_byte = pos1 + 1;
276 277
278 return n_block_size - round_tail_len;
279}
diff --git a/fs/reiserfs/xattr.c b/fs/reiserfs/xattr.c
index 45582fe8b466..e386d3db3051 100644
--- a/fs/reiserfs/xattr.c
+++ b/fs/reiserfs/xattr.c
@@ -51,67 +51,68 @@
51#define PRIVROOT_NAME ".reiserfs_priv" 51#define PRIVROOT_NAME ".reiserfs_priv"
52#define XAROOT_NAME "xattrs" 52#define XAROOT_NAME "xattrs"
53 53
54static struct reiserfs_xattr_handler *find_xattr_handler_prefix (const char *prefix); 54static struct reiserfs_xattr_handler *find_xattr_handler_prefix(const char
55 *prefix);
55 56
56static struct dentry * 57static struct dentry *create_xa_root(struct super_block *sb)
57create_xa_root (struct super_block *sb)
58{ 58{
59 struct dentry *privroot = dget (REISERFS_SB(sb)->priv_root); 59 struct dentry *privroot = dget(REISERFS_SB(sb)->priv_root);
60 struct dentry *xaroot; 60 struct dentry *xaroot;
61 61
62 /* This needs to be created at mount-time */ 62 /* This needs to be created at mount-time */
63 if (!privroot) 63 if (!privroot)
64 return ERR_PTR(-EOPNOTSUPP); 64 return ERR_PTR(-EOPNOTSUPP);
65 65
66 xaroot = lookup_one_len (XAROOT_NAME, privroot, strlen (XAROOT_NAME)); 66 xaroot = lookup_one_len(XAROOT_NAME, privroot, strlen(XAROOT_NAME));
67 if (IS_ERR (xaroot)) { 67 if (IS_ERR(xaroot)) {
68 goto out; 68 goto out;
69 } else if (!xaroot->d_inode) { 69 } else if (!xaroot->d_inode) {
70 int err; 70 int err;
71 down (&privroot->d_inode->i_sem); 71 down(&privroot->d_inode->i_sem);
72 err = privroot->d_inode->i_op->mkdir (privroot->d_inode, xaroot, 0700); 72 err =
73 up (&privroot->d_inode->i_sem); 73 privroot->d_inode->i_op->mkdir(privroot->d_inode, xaroot,
74 74 0700);
75 if (err) { 75 up(&privroot->d_inode->i_sem);
76 dput (xaroot); 76
77 dput (privroot); 77 if (err) {
78 return ERR_PTR (err); 78 dput(xaroot);
79 } 79 dput(privroot);
80 REISERFS_SB(sb)->xattr_root = dget (xaroot); 80 return ERR_PTR(err);
81 } 81 }
82 82 REISERFS_SB(sb)->xattr_root = dget(xaroot);
83out: 83 }
84 dput (privroot); 84
85 return xaroot; 85 out:
86 dput(privroot);
87 return xaroot;
86} 88}
87 89
88/* This will return a dentry, or error, refering to the xa root directory. 90/* This will return a dentry, or error, refering to the xa root directory.
89 * If the xa root doesn't exist yet, the dentry will be returned without 91 * If the xa root doesn't exist yet, the dentry will be returned without
90 * an associated inode. This dentry can be used with ->mkdir to create 92 * an associated inode. This dentry can be used with ->mkdir to create
91 * the xa directory. */ 93 * the xa directory. */
92static struct dentry * 94static struct dentry *__get_xa_root(struct super_block *s)
93__get_xa_root (struct super_block *s)
94{ 95{
95 struct dentry *privroot = dget (REISERFS_SB(s)->priv_root); 96 struct dentry *privroot = dget(REISERFS_SB(s)->priv_root);
96 struct dentry *xaroot = NULL; 97 struct dentry *xaroot = NULL;
97 98
98 if (IS_ERR (privroot) || !privroot) 99 if (IS_ERR(privroot) || !privroot)
99 return privroot; 100 return privroot;
100 101
101 xaroot = lookup_one_len (XAROOT_NAME, privroot, strlen (XAROOT_NAME)); 102 xaroot = lookup_one_len(XAROOT_NAME, privroot, strlen(XAROOT_NAME));
102 if (IS_ERR (xaroot)) { 103 if (IS_ERR(xaroot)) {
103 goto out; 104 goto out;
104 } else if (!xaroot->d_inode) { 105 } else if (!xaroot->d_inode) {
105 dput (xaroot); 106 dput(xaroot);
106 xaroot = NULL; 107 xaroot = NULL;
107 goto out; 108 goto out;
108 } 109 }
109 110
110 REISERFS_SB(s)->xattr_root = dget (xaroot); 111 REISERFS_SB(s)->xattr_root = dget(xaroot);
111 112
112out: 113 out:
113 dput (privroot); 114 dput(privroot);
114 return xaroot; 115 return xaroot;
115} 116}
116 117
117/* Returns the dentry (or NULL) referring to the root of the extended 118/* Returns the dentry (or NULL) referring to the root of the extended
@@ -119,147 +120,145 @@ out:
119 * Otherwise, we attempt to retreive it from disk. It may also return 120 * Otherwise, we attempt to retreive it from disk. It may also return
120 * a pointer-encoded error. 121 * a pointer-encoded error.
121 */ 122 */
122static inline struct dentry * 123static inline struct dentry *get_xa_root(struct super_block *s)
123get_xa_root (struct super_block *s)
124{ 124{
125 struct dentry *dentry = dget (REISERFS_SB(s)->xattr_root); 125 struct dentry *dentry = dget(REISERFS_SB(s)->xattr_root);
126 126
127 if (!dentry) 127 if (!dentry)
128 dentry = __get_xa_root (s); 128 dentry = __get_xa_root(s);
129 129
130 return dentry; 130 return dentry;
131} 131}
132 132
133/* Opens the directory corresponding to the inode's extended attribute store. 133/* Opens the directory corresponding to the inode's extended attribute store.
134 * If flags allow, the tree to the directory may be created. If creation is 134 * If flags allow, the tree to the directory may be created. If creation is
135 * prohibited, -ENODATA is returned. */ 135 * prohibited, -ENODATA is returned. */
136static struct dentry * 136static struct dentry *open_xa_dir(const struct inode *inode, int flags)
137open_xa_dir (const struct inode *inode, int flags)
138{ 137{
139 struct dentry *xaroot, *xadir; 138 struct dentry *xaroot, *xadir;
140 char namebuf[17]; 139 char namebuf[17];
141 140
142 xaroot = get_xa_root (inode->i_sb); 141 xaroot = get_xa_root(inode->i_sb);
143 if (IS_ERR (xaroot)) { 142 if (IS_ERR(xaroot)) {
144 return xaroot; 143 return xaroot;
145 } else if (!xaroot) { 144 } else if (!xaroot) {
146 if (flags == 0 || flags & XATTR_CREATE) { 145 if (flags == 0 || flags & XATTR_CREATE) {
147 xaroot = create_xa_root (inode->i_sb); 146 xaroot = create_xa_root(inode->i_sb);
148 if (IS_ERR (xaroot)) 147 if (IS_ERR(xaroot))
149 return xaroot; 148 return xaroot;
150 } 149 }
151 if (!xaroot) 150 if (!xaroot)
152 return ERR_PTR (-ENODATA); 151 return ERR_PTR(-ENODATA);
153 } 152 }
154 153
155 /* ok, we have xaroot open */ 154 /* ok, we have xaroot open */
156 155
157 snprintf (namebuf, sizeof (namebuf), "%X.%X", 156 snprintf(namebuf, sizeof(namebuf), "%X.%X",
158 le32_to_cpu (INODE_PKEY (inode)->k_objectid), 157 le32_to_cpu(INODE_PKEY(inode)->k_objectid),
159 inode->i_generation); 158 inode->i_generation);
160 xadir = lookup_one_len (namebuf, xaroot, strlen (namebuf)); 159 xadir = lookup_one_len(namebuf, xaroot, strlen(namebuf));
161 if (IS_ERR (xadir)) { 160 if (IS_ERR(xadir)) {
162 dput (xaroot); 161 dput(xaroot);
163 return xadir; 162 return xadir;
164 } 163 }
165 164
166 if (!xadir->d_inode) { 165 if (!xadir->d_inode) {
167 int err; 166 int err;
168 if (flags == 0 || flags & XATTR_CREATE) { 167 if (flags == 0 || flags & XATTR_CREATE) {
169 /* Although there is nothing else trying to create this directory, 168 /* Although there is nothing else trying to create this directory,
170 * another directory with the same hash may be created, so we need 169 * another directory with the same hash may be created, so we need
171 * to protect against that */ 170 * to protect against that */
172 err = xaroot->d_inode->i_op->mkdir (xaroot->d_inode, xadir, 0700); 171 err =
173 if (err) { 172 xaroot->d_inode->i_op->mkdir(xaroot->d_inode, xadir,
174 dput (xaroot); 173 0700);
175 dput (xadir); 174 if (err) {
176 return ERR_PTR (err); 175 dput(xaroot);
177 } 176 dput(xadir);
178 } 177 return ERR_PTR(err);
179 if (!xadir->d_inode) { 178 }
180 dput (xaroot); 179 }
181 dput (xadir); 180 if (!xadir->d_inode) {
182 return ERR_PTR (-ENODATA); 181 dput(xaroot);
183 } 182 dput(xadir);
184 } 183 return ERR_PTR(-ENODATA);
185 184 }
186 dput (xaroot); 185 }
187 return xadir; 186
187 dput(xaroot);
188 return xadir;
188} 189}
189 190
190/* Returns a dentry corresponding to a specific extended attribute file 191/* Returns a dentry corresponding to a specific extended attribute file
191 * for the inode. If flags allow, the file is created. Otherwise, a 192 * for the inode. If flags allow, the file is created. Otherwise, a
192 * valid or negative dentry, or an error is returned. */ 193 * valid or negative dentry, or an error is returned. */
193static struct dentry * 194static struct dentry *get_xa_file_dentry(const struct inode *inode,
194get_xa_file_dentry (const struct inode *inode, const char *name, int flags) 195 const char *name, int flags)
195{ 196{
196 struct dentry *xadir, *xafile; 197 struct dentry *xadir, *xafile;
197 int err = 0; 198 int err = 0;
198 199
199 xadir = open_xa_dir (inode, flags); 200 xadir = open_xa_dir(inode, flags);
200 if (IS_ERR (xadir)) { 201 if (IS_ERR(xadir)) {
201 return ERR_PTR (PTR_ERR (xadir)); 202 return ERR_PTR(PTR_ERR(xadir));
202 } else if (xadir && !xadir->d_inode) { 203 } else if (xadir && !xadir->d_inode) {
203 dput (xadir); 204 dput(xadir);
204 return ERR_PTR (-ENODATA); 205 return ERR_PTR(-ENODATA);
205 } 206 }
206 207
207 xafile = lookup_one_len (name, xadir, strlen (name)); 208 xafile = lookup_one_len(name, xadir, strlen(name));
208 if (IS_ERR (xafile)) { 209 if (IS_ERR(xafile)) {
209 dput (xadir); 210 dput(xadir);
210 return ERR_PTR (PTR_ERR (xafile)); 211 return ERR_PTR(PTR_ERR(xafile));
211 } 212 }
212 213
213 if (xafile->d_inode) { /* file exists */ 214 if (xafile->d_inode) { /* file exists */
214 if (flags & XATTR_CREATE) { 215 if (flags & XATTR_CREATE) {
215 err = -EEXIST; 216 err = -EEXIST;
216 dput (xafile); 217 dput(xafile);
217 goto out; 218 goto out;
218 } 219 }
219 } else if (flags & XATTR_REPLACE || flags & FL_READONLY) { 220 } else if (flags & XATTR_REPLACE || flags & FL_READONLY) {
220 goto out; 221 goto out;
221 } else { 222 } else {
222 /* inode->i_sem is down, so nothing else can try to create 223 /* inode->i_sem is down, so nothing else can try to create
223 * the same xattr */ 224 * the same xattr */
224 err = xadir->d_inode->i_op->create (xadir->d_inode, xafile, 225 err = xadir->d_inode->i_op->create(xadir->d_inode, xafile,
225 0700|S_IFREG, NULL); 226 0700 | S_IFREG, NULL);
226 227
227 if (err) { 228 if (err) {
228 dput (xafile); 229 dput(xafile);
229 goto out; 230 goto out;
230 } 231 }
231 } 232 }
232
233out:
234 dput (xadir);
235 if (err)
236 xafile = ERR_PTR (err);
237 return xafile;
238}
239 233
234 out:
235 dput(xadir);
236 if (err)
237 xafile = ERR_PTR(err);
238 return xafile;
239}
240 240
241/* Opens a file pointer to the attribute associated with inode */ 241/* Opens a file pointer to the attribute associated with inode */
242static struct file * 242static struct file *open_xa_file(const struct inode *inode, const char *name,
243open_xa_file (const struct inode *inode, const char *name, int flags) 243 int flags)
244{ 244{
245 struct dentry *xafile; 245 struct dentry *xafile;
246 struct file *fp; 246 struct file *fp;
247 247
248 xafile = get_xa_file_dentry (inode, name, flags); 248 xafile = get_xa_file_dentry(inode, name, flags);
249 if (IS_ERR (xafile)) 249 if (IS_ERR(xafile))
250 return ERR_PTR (PTR_ERR (xafile)); 250 return ERR_PTR(PTR_ERR(xafile));
251 else if (!xafile->d_inode) { 251 else if (!xafile->d_inode) {
252 dput (xafile); 252 dput(xafile);
253 return ERR_PTR (-ENODATA); 253 return ERR_PTR(-ENODATA);
254 } 254 }
255 255
256 fp = dentry_open (xafile, NULL, O_RDWR); 256 fp = dentry_open(xafile, NULL, O_RDWR);
257 /* dentry_open dputs the dentry if it fails */ 257 /* dentry_open dputs the dentry if it fails */
258 258
259 return fp; 259 return fp;
260} 260}
261 261
262
263/* 262/*
264 * this is very similar to fs/reiserfs/dir.c:reiserfs_readdir, but 263 * this is very similar to fs/reiserfs/dir.c:reiserfs_readdir, but
265 * we need to drop the path before calling the filldir struct. That 264 * we need to drop the path before calling the filldir struct. That
@@ -273,139 +272,146 @@ open_xa_file (const struct inode *inode, const char *name, int flags)
273 * we're called with i_sem held, so there are no worries about the directory 272 * we're called with i_sem held, so there are no worries about the directory
274 * changing underneath us. 273 * changing underneath us.
275 */ 274 */
276static int __xattr_readdir(struct file * filp, void * dirent, filldir_t filldir) 275static int __xattr_readdir(struct file *filp, void *dirent, filldir_t filldir)
277{ 276{
278 struct inode *inode = filp->f_dentry->d_inode; 277 struct inode *inode = filp->f_dentry->d_inode;
279 struct cpu_key pos_key; /* key of current position in the directory (key of directory entry) */ 278 struct cpu_key pos_key; /* key of current position in the directory (key of directory entry) */
280 INITIALIZE_PATH (path_to_entry); 279 INITIALIZE_PATH(path_to_entry);
281 struct buffer_head * bh; 280 struct buffer_head *bh;
282 int entry_num; 281 int entry_num;
283 struct item_head * ih, tmp_ih; 282 struct item_head *ih, tmp_ih;
284 int search_res; 283 int search_res;
285 char * local_buf; 284 char *local_buf;
286 loff_t next_pos; 285 loff_t next_pos;
287 char small_buf[32] ; /* avoid kmalloc if we can */ 286 char small_buf[32]; /* avoid kmalloc if we can */
288 struct reiserfs_de_head *deh; 287 struct reiserfs_de_head *deh;
289 int d_reclen; 288 int d_reclen;
290 char * d_name; 289 char *d_name;
291 off_t d_off; 290 off_t d_off;
292 ino_t d_ino; 291 ino_t d_ino;
293 struct reiserfs_dir_entry de; 292 struct reiserfs_dir_entry de;
294 293
295 294 /* form key for search the next directory entry using f_pos field of
296 /* form key for search the next directory entry using f_pos field of 295 file structure */
297 file structure */ 296 next_pos = max_reiserfs_offset(inode);
298 next_pos = max_reiserfs_offset(inode); 297
299 298 while (1) {
300 while (1) { 299 research:
301research: 300 if (next_pos <= DOT_DOT_OFFSET)
302 if (next_pos <= DOT_DOT_OFFSET) 301 break;
303 break; 302 make_cpu_key(&pos_key, inode, next_pos, TYPE_DIRENTRY, 3);
304 make_cpu_key (&pos_key, inode, next_pos, TYPE_DIRENTRY, 3); 303
305 304 search_res =
306 search_res = search_by_entry_key(inode->i_sb, &pos_key, &path_to_entry, &de); 305 search_by_entry_key(inode->i_sb, &pos_key, &path_to_entry,
307 if (search_res == IO_ERROR) { 306 &de);
308 // FIXME: we could just skip part of directory which could 307 if (search_res == IO_ERROR) {
309 // not be read 308 // FIXME: we could just skip part of directory which could
310 pathrelse(&path_to_entry); 309 // not be read
311 return -EIO; 310 pathrelse(&path_to_entry);
312 } 311 return -EIO;
313 312 }
314 if (search_res == NAME_NOT_FOUND)
315 de.de_entry_num--;
316 313
317 set_de_name_and_namelen(&de); 314 if (search_res == NAME_NOT_FOUND)
318 entry_num = de.de_entry_num; 315 de.de_entry_num--;
319 deh = &(de.de_deh[entry_num]);
320 316
321 bh = de.de_bh; 317 set_de_name_and_namelen(&de);
322 ih = de.de_ih; 318 entry_num = de.de_entry_num;
319 deh = &(de.de_deh[entry_num]);
323 320
324 if (!is_direntry_le_ih(ih)) { 321 bh = de.de_bh;
325 reiserfs_warning(inode->i_sb, "not direntry %h", ih); 322 ih = de.de_ih;
326 break;
327 }
328 copy_item_head(&tmp_ih, ih);
329 323
330 /* we must have found item, that is item of this directory, */ 324 if (!is_direntry_le_ih(ih)) {
331 RFALSE( COMP_SHORT_KEYS (&(ih->ih_key), &pos_key), 325 reiserfs_warning(inode->i_sb, "not direntry %h", ih);
332 "vs-9000: found item %h does not match to dir we readdir %K", 326 break;
333 ih, &pos_key); 327 }
328 copy_item_head(&tmp_ih, ih);
334 329
335 if (deh_offset(deh) <= DOT_DOT_OFFSET) { 330 /* we must have found item, that is item of this directory, */
336 break; 331 RFALSE(COMP_SHORT_KEYS(&(ih->ih_key), &pos_key),
337 } 332 "vs-9000: found item %h does not match to dir we readdir %K",
333 ih, &pos_key);
338 334
339 /* look for the previous entry in the directory */ 335 if (deh_offset(deh) <= DOT_DOT_OFFSET) {
340 next_pos = deh_offset (deh) - 1; 336 break;
337 }
341 338
342 if (!de_visible (deh)) 339 /* look for the previous entry in the directory */
343 /* it is hidden entry */ 340 next_pos = deh_offset(deh) - 1;
344 continue;
345 341
346 d_reclen = entry_length(bh, ih, entry_num); 342 if (!de_visible(deh))
347 d_name = B_I_DEH_ENTRY_FILE_NAME (bh, ih, deh); 343 /* it is hidden entry */
348 d_off = deh_offset (deh); 344 continue;
349 d_ino = deh_objectid (deh);
350 345
351 if (!d_name[d_reclen - 1]) 346 d_reclen = entry_length(bh, ih, entry_num);
352 d_reclen = strlen (d_name); 347 d_name = B_I_DEH_ENTRY_FILE_NAME(bh, ih, deh);
348 d_off = deh_offset(deh);
349 d_ino = deh_objectid(deh);
353 350
354 if (d_reclen > REISERFS_MAX_NAME(inode->i_sb->s_blocksize)){ 351 if (!d_name[d_reclen - 1])
355 /* too big to send back to VFS */ 352 d_reclen = strlen(d_name);
356 continue ;
357 }
358 353
359 /* Ignore the .reiserfs_priv entry */ 354 if (d_reclen > REISERFS_MAX_NAME(inode->i_sb->s_blocksize)) {
360 if (reiserfs_xattrs (inode->i_sb) && 355 /* too big to send back to VFS */
361 !old_format_only(inode->i_sb) && 356 continue;
362 deh_objectid (deh) == le32_to_cpu (INODE_PKEY(REISERFS_SB(inode->i_sb)->priv_root->d_inode)->k_objectid)) 357 }
363 continue;
364 358
365 if (d_reclen <= 32) { 359 /* Ignore the .reiserfs_priv entry */
366 local_buf = small_buf ; 360 if (reiserfs_xattrs(inode->i_sb) &&
367 } else { 361 !old_format_only(inode->i_sb) &&
368 local_buf = reiserfs_kmalloc(d_reclen, GFP_NOFS, inode->i_sb) ; 362 deh_objectid(deh) ==
369 if (!local_buf) { 363 le32_to_cpu(INODE_PKEY
370 pathrelse (&path_to_entry); 364 (REISERFS_SB(inode->i_sb)->priv_root->d_inode)->
371 return -ENOMEM ; 365 k_objectid))
372 } 366 continue;
373 if (item_moved (&tmp_ih, &path_to_entry)) { 367
374 reiserfs_kfree(local_buf, d_reclen, inode->i_sb) ; 368 if (d_reclen <= 32) {
375 369 local_buf = small_buf;
376 /* sigh, must retry. Do this same offset again */ 370 } else {
377 next_pos = d_off; 371 local_buf =
378 goto research; 372 reiserfs_kmalloc(d_reclen, GFP_NOFS, inode->i_sb);
379 } 373 if (!local_buf) {
380 } 374 pathrelse(&path_to_entry);
375 return -ENOMEM;
376 }
377 if (item_moved(&tmp_ih, &path_to_entry)) {
378 reiserfs_kfree(local_buf, d_reclen,
379 inode->i_sb);
380
381 /* sigh, must retry. Do this same offset again */
382 next_pos = d_off;
383 goto research;
384 }
385 }
381 386
382 // Note, that we copy name to user space via temporary 387 // Note, that we copy name to user space via temporary
383 // buffer (local_buf) because filldir will block if 388 // buffer (local_buf) because filldir will block if
384 // user space buffer is swapped out. At that time 389 // user space buffer is swapped out. At that time
385 // entry can move to somewhere else 390 // entry can move to somewhere else
386 memcpy (local_buf, d_name, d_reclen); 391 memcpy(local_buf, d_name, d_reclen);
387 392
388 /* the filldir function might need to start transactions, 393 /* the filldir function might need to start transactions,
389 * or do who knows what. Release the path now that we've 394 * or do who knows what. Release the path now that we've
390 * copied all the important stuff out of the deh 395 * copied all the important stuff out of the deh
391 */ 396 */
392 pathrelse (&path_to_entry); 397 pathrelse(&path_to_entry);
393 398
394 if (filldir (dirent, local_buf, d_reclen, d_off, d_ino, 399 if (filldir(dirent, local_buf, d_reclen, d_off, d_ino,
395 DT_UNKNOWN) < 0) { 400 DT_UNKNOWN) < 0) {
396 if (local_buf != small_buf) { 401 if (local_buf != small_buf) {
397 reiserfs_kfree(local_buf, d_reclen, inode->i_sb) ; 402 reiserfs_kfree(local_buf, d_reclen,
398 } 403 inode->i_sb);
399 goto end; 404 }
400 } 405 goto end;
401 if (local_buf != small_buf) { 406 }
402 reiserfs_kfree(local_buf, d_reclen, inode->i_sb) ; 407 if (local_buf != small_buf) {
403 } 408 reiserfs_kfree(local_buf, d_reclen, inode->i_sb);
404 } /* while */ 409 }
410 } /* while */
405 411
406end: 412 end:
407 pathrelse (&path_to_entry); 413 pathrelse(&path_to_entry);
408 return 0; 414 return 0;
409} 415}
410 416
411/* 417/*
@@ -417,63 +423,59 @@ end:
417static 423static
418int xattr_readdir(struct file *file, filldir_t filler, void *buf) 424int xattr_readdir(struct file *file, filldir_t filler, void *buf)
419{ 425{
420 struct inode *inode = file->f_dentry->d_inode; 426 struct inode *inode = file->f_dentry->d_inode;
421 int res = -ENOTDIR; 427 int res = -ENOTDIR;
422 if (!file->f_op || !file->f_op->readdir) 428 if (!file->f_op || !file->f_op->readdir)
423 goto out; 429 goto out;
424 down(&inode->i_sem); 430 down(&inode->i_sem);
425// down(&inode->i_zombie); 431// down(&inode->i_zombie);
426 res = -ENOENT; 432 res = -ENOENT;
427 if (!IS_DEADDIR(inode)) { 433 if (!IS_DEADDIR(inode)) {
428 lock_kernel(); 434 lock_kernel();
429 res = __xattr_readdir(file, buf, filler); 435 res = __xattr_readdir(file, buf, filler);
430 unlock_kernel(); 436 unlock_kernel();
431 } 437 }
432// up(&inode->i_zombie); 438// up(&inode->i_zombie);
433 up(&inode->i_sem); 439 up(&inode->i_sem);
434out: 440 out:
435 return res; 441 return res;
436} 442}
437 443
438
439/* Internal operations on file data */ 444/* Internal operations on file data */
440static inline void 445static inline void reiserfs_put_page(struct page *page)
441reiserfs_put_page(struct page *page)
442{ 446{
443 kunmap(page); 447 kunmap(page);
444 page_cache_release(page); 448 page_cache_release(page);
445} 449}
446 450
447static struct page * 451static struct page *reiserfs_get_page(struct inode *dir, unsigned long n)
448reiserfs_get_page(struct inode *dir, unsigned long n)
449{ 452{
450 struct address_space *mapping = dir->i_mapping; 453 struct address_space *mapping = dir->i_mapping;
451 struct page *page; 454 struct page *page;
452 /* We can deadlock if we try to free dentries, 455 /* We can deadlock if we try to free dentries,
453 and an unlink/rmdir has just occured - GFP_NOFS avoids this */ 456 and an unlink/rmdir has just occured - GFP_NOFS avoids this */
454 mapping->flags = (mapping->flags & ~__GFP_BITS_MASK) | GFP_NOFS; 457 mapping->flags = (mapping->flags & ~__GFP_BITS_MASK) | GFP_NOFS;
455 page = read_cache_page (mapping, n, 458 page = read_cache_page(mapping, n,
456 (filler_t*)mapping->a_ops->readpage, NULL); 459 (filler_t *) mapping->a_ops->readpage, NULL);
457 if (!IS_ERR(page)) { 460 if (!IS_ERR(page)) {
458 wait_on_page_locked(page); 461 wait_on_page_locked(page);
459 kmap(page); 462 kmap(page);
460 if (!PageUptodate(page)) 463 if (!PageUptodate(page))
461 goto fail; 464 goto fail;
462 465
463 if (PageError(page)) 466 if (PageError(page))
464 goto fail; 467 goto fail;
465 } 468 }
466 return page; 469 return page;
467 470
468fail: 471 fail:
469 reiserfs_put_page(page); 472 reiserfs_put_page(page);
470 return ERR_PTR(-EIO); 473 return ERR_PTR(-EIO);
471} 474}
472 475
473static inline __u32 476static inline __u32 xattr_hash(const char *msg, int len)
474xattr_hash (const char *msg, int len)
475{ 477{
476 return csum_partial (msg, len, 0); 478 return csum_partial(msg, len, 0);
477} 479}
478 480
479/* Generic extended attribute operations that can be used by xa plugins */ 481/* Generic extended attribute operations that can be used by xa plugins */
@@ -482,294 +484,300 @@ xattr_hash (const char *msg, int len)
482 * inode->i_sem: down 484 * inode->i_sem: down
483 */ 485 */
484int 486int
485reiserfs_xattr_set (struct inode *inode, const char *name, const void *buffer, 487reiserfs_xattr_set(struct inode *inode, const char *name, const void *buffer,
486 size_t buffer_size, int flags) 488 size_t buffer_size, int flags)
487{ 489{
488 int err = 0; 490 int err = 0;
489 struct file *fp; 491 struct file *fp;
490 struct page *page; 492 struct page *page;
491 char *data; 493 char *data;
492 struct address_space *mapping; 494 struct address_space *mapping;
493 size_t file_pos = 0; 495 size_t file_pos = 0;
494 size_t buffer_pos = 0; 496 size_t buffer_pos = 0;
495 struct inode *xinode; 497 struct inode *xinode;
496 struct iattr newattrs; 498 struct iattr newattrs;
497 __u32 xahash = 0; 499 __u32 xahash = 0;
498 500
499 if (IS_RDONLY (inode)) 501 if (IS_RDONLY(inode))
500 return -EROFS; 502 return -EROFS;
501 503
502 if (IS_IMMUTABLE (inode) || IS_APPEND (inode)) 504 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
503 return -EPERM; 505 return -EPERM;
504 506
505 if (get_inode_sd_version (inode) == STAT_DATA_V1) 507 if (get_inode_sd_version(inode) == STAT_DATA_V1)
506 return -EOPNOTSUPP; 508 return -EOPNOTSUPP;
507 509
508 /* Empty xattrs are ok, they're just empty files, no hash */ 510 /* Empty xattrs are ok, they're just empty files, no hash */
509 if (buffer && buffer_size) 511 if (buffer && buffer_size)
510 xahash = xattr_hash (buffer, buffer_size); 512 xahash = xattr_hash(buffer, buffer_size);
511 513
512open_file: 514 open_file:
513 fp = open_xa_file (inode, name, flags); 515 fp = open_xa_file(inode, name, flags);
514 if (IS_ERR (fp)) { 516 if (IS_ERR(fp)) {
515 err = PTR_ERR (fp); 517 err = PTR_ERR(fp);
516 goto out; 518 goto out;
517 } 519 }
518 520
519 xinode = fp->f_dentry->d_inode; 521 xinode = fp->f_dentry->d_inode;
520 REISERFS_I(inode)->i_flags |= i_has_xattr_dir; 522 REISERFS_I(inode)->i_flags |= i_has_xattr_dir;
521 523
522 /* we need to copy it off.. */ 524 /* we need to copy it off.. */
523 if (xinode->i_nlink > 1) { 525 if (xinode->i_nlink > 1) {
524 fput(fp); 526 fput(fp);
525 err = reiserfs_xattr_del (inode, name); 527 err = reiserfs_xattr_del(inode, name);
526 if (err < 0) 528 if (err < 0)
527 goto out; 529 goto out;
528 /* We just killed the old one, we're not replacing anymore */ 530 /* We just killed the old one, we're not replacing anymore */
529 if (flags & XATTR_REPLACE) 531 if (flags & XATTR_REPLACE)
530 flags &= ~XATTR_REPLACE; 532 flags &= ~XATTR_REPLACE;
531 goto open_file; 533 goto open_file;
532 } 534 }
533 535
534 /* Resize it so we're ok to write there */ 536 /* Resize it so we're ok to write there */
535 newattrs.ia_size = buffer_size; 537 newattrs.ia_size = buffer_size;
536 newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME; 538 newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
537 down (&xinode->i_sem); 539 down(&xinode->i_sem);
538 err = notify_change(fp->f_dentry, &newattrs); 540 err = notify_change(fp->f_dentry, &newattrs);
539 if (err) 541 if (err)
540 goto out_filp; 542 goto out_filp;
541 543
542 mapping = xinode->i_mapping; 544 mapping = xinode->i_mapping;
543 while (buffer_pos < buffer_size || buffer_pos == 0) { 545 while (buffer_pos < buffer_size || buffer_pos == 0) {
544 size_t chunk; 546 size_t chunk;
545 size_t skip = 0; 547 size_t skip = 0;
546 size_t page_offset = (file_pos & (PAGE_CACHE_SIZE - 1)); 548 size_t page_offset = (file_pos & (PAGE_CACHE_SIZE - 1));
547 if (buffer_size - buffer_pos > PAGE_CACHE_SIZE) 549 if (buffer_size - buffer_pos > PAGE_CACHE_SIZE)
548 chunk = PAGE_CACHE_SIZE; 550 chunk = PAGE_CACHE_SIZE;
549 else 551 else
550 chunk = buffer_size - buffer_pos; 552 chunk = buffer_size - buffer_pos;
551 553
552 page = reiserfs_get_page (xinode, file_pos >> PAGE_CACHE_SHIFT); 554 page = reiserfs_get_page(xinode, file_pos >> PAGE_CACHE_SHIFT);
553 if (IS_ERR (page)) { 555 if (IS_ERR(page)) {
554 err = PTR_ERR (page); 556 err = PTR_ERR(page);
555 goto out_filp; 557 goto out_filp;
556 } 558 }
557 559
558 lock_page (page); 560 lock_page(page);
559 data = page_address (page); 561 data = page_address(page);
560 562
561 if (file_pos == 0) { 563 if (file_pos == 0) {
562 struct reiserfs_xattr_header *rxh; 564 struct reiserfs_xattr_header *rxh;
563 skip = file_pos = sizeof (struct reiserfs_xattr_header); 565 skip = file_pos = sizeof(struct reiserfs_xattr_header);
564 if (chunk + skip > PAGE_CACHE_SIZE) 566 if (chunk + skip > PAGE_CACHE_SIZE)
565 chunk = PAGE_CACHE_SIZE - skip; 567 chunk = PAGE_CACHE_SIZE - skip;
566 rxh = (struct reiserfs_xattr_header *)data; 568 rxh = (struct reiserfs_xattr_header *)data;
567 rxh->h_magic = cpu_to_le32 (REISERFS_XATTR_MAGIC); 569 rxh->h_magic = cpu_to_le32(REISERFS_XATTR_MAGIC);
568 rxh->h_hash = cpu_to_le32 (xahash); 570 rxh->h_hash = cpu_to_le32(xahash);
569 } 571 }
570 572
571 err = mapping->a_ops->prepare_write (fp, page, page_offset, 573 err = mapping->a_ops->prepare_write(fp, page, page_offset,
572 page_offset + chunk + skip); 574 page_offset + chunk + skip);
573 if (!err) { 575 if (!err) {
574 if (buffer) 576 if (buffer)
575 memcpy (data + skip, buffer + buffer_pos, chunk); 577 memcpy(data + skip, buffer + buffer_pos, chunk);
576 err = mapping->a_ops->commit_write (fp, page, page_offset, 578 err =
577 page_offset + chunk + skip); 579 mapping->a_ops->commit_write(fp, page, page_offset,
580 page_offset + chunk +
581 skip);
582 }
583 unlock_page(page);
584 reiserfs_put_page(page);
585 buffer_pos += chunk;
586 file_pos += chunk;
587 skip = 0;
588 if (err || buffer_size == 0 || !buffer)
589 break;
590 }
591
592 /* We can't mark the inode dirty if it's not hashed. This is the case
593 * when we're inheriting the default ACL. If we dirty it, the inode
594 * gets marked dirty, but won't (ever) make it onto the dirty list until
595 * it's synced explicitly to clear I_DIRTY. This is bad. */
596 if (!hlist_unhashed(&inode->i_hash)) {
597 inode->i_ctime = CURRENT_TIME_SEC;
598 mark_inode_dirty(inode);
578 } 599 }
579 unlock_page (page); 600
580 reiserfs_put_page (page); 601 out_filp:
581 buffer_pos += chunk; 602 up(&xinode->i_sem);
582 file_pos += chunk; 603 fput(fp);
583 skip = 0; 604
584 if (err || buffer_size == 0 || !buffer) 605 out:
585 break; 606 return err;
586 }
587
588 /* We can't mark the inode dirty if it's not hashed. This is the case
589 * when we're inheriting the default ACL. If we dirty it, the inode
590 * gets marked dirty, but won't (ever) make it onto the dirty list until
591 * it's synced explicitly to clear I_DIRTY. This is bad. */
592 if (!hlist_unhashed(&inode->i_hash)) {
593 inode->i_ctime = CURRENT_TIME_SEC;
594 mark_inode_dirty (inode);
595 }
596
597out_filp:
598 up (&xinode->i_sem);
599 fput(fp);
600
601out:
602 return err;
603} 607}
604 608
605/* 609/*
606 * inode->i_sem: down 610 * inode->i_sem: down
607 */ 611 */
608int 612int
609reiserfs_xattr_get (const struct inode *inode, const char *name, void *buffer, 613reiserfs_xattr_get(const struct inode *inode, const char *name, void *buffer,
610 size_t buffer_size) 614 size_t buffer_size)
611{ 615{
612 ssize_t err = 0; 616 ssize_t err = 0;
613 struct file *fp; 617 struct file *fp;
614 size_t isize; 618 size_t isize;
615 size_t file_pos = 0; 619 size_t file_pos = 0;
616 size_t buffer_pos = 0; 620 size_t buffer_pos = 0;
617 struct page *page; 621 struct page *page;
618 struct inode *xinode; 622 struct inode *xinode;
619 __u32 hash = 0; 623 __u32 hash = 0;
620 624
621 if (name == NULL) 625 if (name == NULL)
622 return -EINVAL; 626 return -EINVAL;
623 627
624 /* We can't have xattrs attached to v1 items since they don't have 628 /* We can't have xattrs attached to v1 items since they don't have
625 * generation numbers */ 629 * generation numbers */
626 if (get_inode_sd_version (inode) == STAT_DATA_V1) 630 if (get_inode_sd_version(inode) == STAT_DATA_V1)
627 return -EOPNOTSUPP; 631 return -EOPNOTSUPP;
628 632
629 fp = open_xa_file (inode, name, FL_READONLY); 633 fp = open_xa_file(inode, name, FL_READONLY);
630 if (IS_ERR (fp)) { 634 if (IS_ERR(fp)) {
631 err = PTR_ERR (fp); 635 err = PTR_ERR(fp);
632 goto out; 636 goto out;
633 } 637 }
634 638
635 xinode = fp->f_dentry->d_inode; 639 xinode = fp->f_dentry->d_inode;
636 isize = xinode->i_size; 640 isize = xinode->i_size;
637 REISERFS_I(inode)->i_flags |= i_has_xattr_dir; 641 REISERFS_I(inode)->i_flags |= i_has_xattr_dir;
638 642
639 /* Just return the size needed */ 643 /* Just return the size needed */
640 if (buffer == NULL) { 644 if (buffer == NULL) {
641 err = isize - sizeof (struct reiserfs_xattr_header); 645 err = isize - sizeof(struct reiserfs_xattr_header);
642 goto out_dput; 646 goto out_dput;
643 } 647 }
644 648
645 if (buffer_size < isize - sizeof (struct reiserfs_xattr_header)) { 649 if (buffer_size < isize - sizeof(struct reiserfs_xattr_header)) {
646 err = -ERANGE; 650 err = -ERANGE;
647 goto out_dput; 651 goto out_dput;
648 } 652 }
649 653
650 while (file_pos < isize) { 654 while (file_pos < isize) {
651 size_t chunk; 655 size_t chunk;
652 char *data; 656 char *data;
653 size_t skip = 0; 657 size_t skip = 0;
654 if (isize - file_pos > PAGE_CACHE_SIZE) 658 if (isize - file_pos > PAGE_CACHE_SIZE)
655 chunk = PAGE_CACHE_SIZE; 659 chunk = PAGE_CACHE_SIZE;
656 else 660 else
657 chunk = isize - file_pos; 661 chunk = isize - file_pos;
658 662
659 page = reiserfs_get_page (xinode, file_pos >> PAGE_CACHE_SHIFT); 663 page = reiserfs_get_page(xinode, file_pos >> PAGE_CACHE_SHIFT);
660 if (IS_ERR (page)) { 664 if (IS_ERR(page)) {
661 err = PTR_ERR (page); 665 err = PTR_ERR(page);
662 goto out_dput; 666 goto out_dput;
663 } 667 }
664 668
665 lock_page (page); 669 lock_page(page);
666 data = page_address (page); 670 data = page_address(page);
667 if (file_pos == 0) { 671 if (file_pos == 0) {
668 struct reiserfs_xattr_header *rxh = 672 struct reiserfs_xattr_header *rxh =
669 (struct reiserfs_xattr_header *)data; 673 (struct reiserfs_xattr_header *)data;
670 skip = file_pos = sizeof (struct reiserfs_xattr_header); 674 skip = file_pos = sizeof(struct reiserfs_xattr_header);
671 chunk -= skip; 675 chunk -= skip;
672 /* Magic doesn't match up.. */ 676 /* Magic doesn't match up.. */
673 if (rxh->h_magic != cpu_to_le32 (REISERFS_XATTR_MAGIC)) { 677 if (rxh->h_magic != cpu_to_le32(REISERFS_XATTR_MAGIC)) {
674 unlock_page (page); 678 unlock_page(page);
675 reiserfs_put_page (page); 679 reiserfs_put_page(page);
676 reiserfs_warning (inode->i_sb, "Invalid magic for xattr (%s) " 680 reiserfs_warning(inode->i_sb,
677 "associated with %k", name, 681 "Invalid magic for xattr (%s) "
678 INODE_PKEY (inode)); 682 "associated with %k", name,
679 err = -EIO; 683 INODE_PKEY(inode));
680 goto out_dput; 684 err = -EIO;
681 } 685 goto out_dput;
682 hash = le32_to_cpu (rxh->h_hash); 686 }
683 } 687 hash = le32_to_cpu(rxh->h_hash);
684 memcpy (buffer + buffer_pos, data + skip, chunk); 688 }
685 unlock_page (page); 689 memcpy(buffer + buffer_pos, data + skip, chunk);
686 reiserfs_put_page (page); 690 unlock_page(page);
687 file_pos += chunk; 691 reiserfs_put_page(page);
688 buffer_pos += chunk; 692 file_pos += chunk;
689 skip = 0; 693 buffer_pos += chunk;
690 } 694 skip = 0;
691 err = isize - sizeof (struct reiserfs_xattr_header); 695 }
692 696 err = isize - sizeof(struct reiserfs_xattr_header);
693 if (xattr_hash (buffer, isize - sizeof (struct reiserfs_xattr_header)) != hash) { 697
694 reiserfs_warning (inode->i_sb, "Invalid hash for xattr (%s) associated " 698 if (xattr_hash(buffer, isize - sizeof(struct reiserfs_xattr_header)) !=
695 "with %k", name, INODE_PKEY (inode)); 699 hash) {
696 err = -EIO; 700 reiserfs_warning(inode->i_sb,
697 } 701 "Invalid hash for xattr (%s) associated "
698 702 "with %k", name, INODE_PKEY(inode));
699out_dput: 703 err = -EIO;
700 fput(fp); 704 }
701 705
702out: 706 out_dput:
703 return err; 707 fput(fp);
708
709 out:
710 return err;
704} 711}
705 712
706static int 713static int
707__reiserfs_xattr_del (struct dentry *xadir, const char *name, int namelen) 714__reiserfs_xattr_del(struct dentry *xadir, const char *name, int namelen)
708{ 715{
709 struct dentry *dentry; 716 struct dentry *dentry;
710 struct inode *dir = xadir->d_inode; 717 struct inode *dir = xadir->d_inode;
711 int err = 0; 718 int err = 0;
712 719
713 dentry = lookup_one_len (name, xadir, namelen); 720 dentry = lookup_one_len(name, xadir, namelen);
714 if (IS_ERR (dentry)) { 721 if (IS_ERR(dentry)) {
715 err = PTR_ERR (dentry); 722 err = PTR_ERR(dentry);
716 goto out; 723 goto out;
717 } else if (!dentry->d_inode) { 724 } else if (!dentry->d_inode) {
718 err = -ENODATA; 725 err = -ENODATA;
719 goto out_file; 726 goto out_file;
720 } 727 }
721 728
722 /* Skip directories.. */ 729 /* Skip directories.. */
723 if (S_ISDIR (dentry->d_inode->i_mode)) 730 if (S_ISDIR(dentry->d_inode->i_mode))
724 goto out_file; 731 goto out_file;
725 732
726 if (!is_reiserfs_priv_object (dentry->d_inode)) { 733 if (!is_reiserfs_priv_object(dentry->d_inode)) {
727 reiserfs_warning (dir->i_sb, "OID %08x [%.*s/%.*s] doesn't have " 734 reiserfs_warning(dir->i_sb, "OID %08x [%.*s/%.*s] doesn't have "
728 "priv flag set [parent is %sset].", 735 "priv flag set [parent is %sset].",
729 le32_to_cpu (INODE_PKEY (dentry->d_inode)->k_objectid), 736 le32_to_cpu(INODE_PKEY(dentry->d_inode)->
730 xadir->d_name.len, xadir->d_name.name, namelen, name, 737 k_objectid), xadir->d_name.len,
731 is_reiserfs_priv_object (xadir->d_inode) ? "" : "not "); 738 xadir->d_name.name, namelen, name,
732 dput (dentry); 739 is_reiserfs_priv_object(xadir->
733 return -EIO; 740 d_inode) ? "" :
734 } 741 "not ");
735 742 dput(dentry);
736 err = dir->i_op->unlink (dir, dentry); 743 return -EIO;
737 if (!err) 744 }
738 d_delete (dentry);
739
740out_file:
741 dput (dentry);
742
743out:
744 return err;
745}
746 745
746 err = dir->i_op->unlink(dir, dentry);
747 if (!err)
748 d_delete(dentry);
747 749
748int 750 out_file:
749reiserfs_xattr_del (struct inode *inode, const char *name) 751 dput(dentry);
752
753 out:
754 return err;
755}
756
757int reiserfs_xattr_del(struct inode *inode, const char *name)
750{ 758{
751 struct dentry *dir; 759 struct dentry *dir;
752 int err; 760 int err;
753 761
754 if (IS_RDONLY (inode)) 762 if (IS_RDONLY(inode))
755 return -EROFS; 763 return -EROFS;
756 764
757 dir = open_xa_dir (inode, FL_READONLY); 765 dir = open_xa_dir(inode, FL_READONLY);
758 if (IS_ERR (dir)) { 766 if (IS_ERR(dir)) {
759 err = PTR_ERR (dir); 767 err = PTR_ERR(dir);
760 goto out; 768 goto out;
761 } 769 }
762 770
763 err = __reiserfs_xattr_del (dir, name, strlen (name)); 771 err = __reiserfs_xattr_del(dir, name, strlen(name));
764 dput (dir); 772 dput(dir);
765 773
766 if (!err) { 774 if (!err) {
767 inode->i_ctime = CURRENT_TIME_SEC; 775 inode->i_ctime = CURRENT_TIME_SEC;
768 mark_inode_dirty (inode); 776 mark_inode_dirty(inode);
769 } 777 }
770 778
771out: 779 out:
772 return err; 780 return err;
773} 781}
774 782
775/* The following are side effects of other operations that aren't explicitly 783/* The following are side effects of other operations that aren't explicitly
@@ -777,167 +785,163 @@ out:
777 * or ownership changes, object deletions, etc. */ 785 * or ownership changes, object deletions, etc. */
778 786
779static int 787static int
780reiserfs_delete_xattrs_filler (void *buf, const char *name, int namelen, 788reiserfs_delete_xattrs_filler(void *buf, const char *name, int namelen,
781 loff_t offset, ino_t ino, unsigned int d_type) 789 loff_t offset, ino_t ino, unsigned int d_type)
782{ 790{
783 struct dentry *xadir = (struct dentry *)buf; 791 struct dentry *xadir = (struct dentry *)buf;
784 792
785 return __reiserfs_xattr_del (xadir, name, namelen); 793 return __reiserfs_xattr_del(xadir, name, namelen);
786 794
787} 795}
788 796
789/* This is called w/ inode->i_sem downed */ 797/* This is called w/ inode->i_sem downed */
790int 798int reiserfs_delete_xattrs(struct inode *inode)
791reiserfs_delete_xattrs (struct inode *inode)
792{ 799{
793 struct file *fp; 800 struct file *fp;
794 struct dentry *dir, *root; 801 struct dentry *dir, *root;
795 int err = 0; 802 int err = 0;
796 803
797 /* Skip out, an xattr has no xattrs associated with it */ 804 /* Skip out, an xattr has no xattrs associated with it */
798 if (is_reiserfs_priv_object (inode) || 805 if (is_reiserfs_priv_object(inode) ||
799 get_inode_sd_version (inode) == STAT_DATA_V1 || 806 get_inode_sd_version(inode) == STAT_DATA_V1 ||
800 !reiserfs_xattrs(inode->i_sb)) 807 !reiserfs_xattrs(inode->i_sb)) {
801 { 808 return 0;
802 return 0; 809 }
803 } 810 reiserfs_read_lock_xattrs(inode->i_sb);
804 reiserfs_read_lock_xattrs (inode->i_sb); 811 dir = open_xa_dir(inode, FL_READONLY);
805 dir = open_xa_dir (inode, FL_READONLY); 812 reiserfs_read_unlock_xattrs(inode->i_sb);
806 reiserfs_read_unlock_xattrs (inode->i_sb); 813 if (IS_ERR(dir)) {
807 if (IS_ERR (dir)) { 814 err = PTR_ERR(dir);
808 err = PTR_ERR (dir); 815 goto out;
809 goto out; 816 } else if (!dir->d_inode) {
810 } else if (!dir->d_inode) { 817 dput(dir);
811 dput (dir); 818 return 0;
812 return 0; 819 }
813 } 820
814 821 fp = dentry_open(dir, NULL, O_RDWR);
815 fp = dentry_open (dir, NULL, O_RDWR); 822 if (IS_ERR(fp)) {
816 if (IS_ERR (fp)) { 823 err = PTR_ERR(fp);
817 err = PTR_ERR (fp); 824 /* dentry_open dputs the dentry if it fails */
818 /* dentry_open dputs the dentry if it fails */ 825 goto out;
819 goto out; 826 }
820 } 827
821 828 lock_kernel();
822 lock_kernel (); 829 err = xattr_readdir(fp, reiserfs_delete_xattrs_filler, dir);
823 err = xattr_readdir (fp, reiserfs_delete_xattrs_filler, dir); 830 if (err) {
824 if (err) { 831 unlock_kernel();
825 unlock_kernel (); 832 goto out_dir;
826 goto out_dir; 833 }
827 } 834
828 835 /* Leftovers besides . and .. -- that's not good. */
829 /* Leftovers besides . and .. -- that's not good. */ 836 if (dir->d_inode->i_nlink <= 2) {
830 if (dir->d_inode->i_nlink <= 2) { 837 root = get_xa_root(inode->i_sb);
831 root = get_xa_root (inode->i_sb); 838 reiserfs_write_lock_xattrs(inode->i_sb);
832 reiserfs_write_lock_xattrs (inode->i_sb); 839 err = vfs_rmdir(root->d_inode, dir);
833 err = vfs_rmdir (root->d_inode, dir); 840 reiserfs_write_unlock_xattrs(inode->i_sb);
834 reiserfs_write_unlock_xattrs (inode->i_sb); 841 dput(root);
835 dput (root); 842 } else {
836 } else { 843 reiserfs_warning(inode->i_sb,
837 reiserfs_warning (inode->i_sb, 844 "Couldn't remove all entries in directory");
838 "Couldn't remove all entries in directory"); 845 }
839 } 846 unlock_kernel();
840 unlock_kernel (); 847
841 848 out_dir:
842out_dir: 849 fput(fp);
843 fput(fp); 850
844 851 out:
845out: 852 if (!err)
846 if (!err) 853 REISERFS_I(inode)->i_flags =
847 REISERFS_I(inode)->i_flags = REISERFS_I(inode)->i_flags & ~i_has_xattr_dir; 854 REISERFS_I(inode)->i_flags & ~i_has_xattr_dir;
848 return err; 855 return err;
849} 856}
850 857
851struct reiserfs_chown_buf { 858struct reiserfs_chown_buf {
852 struct inode *inode; 859 struct inode *inode;
853 struct dentry *xadir; 860 struct dentry *xadir;
854 struct iattr *attrs; 861 struct iattr *attrs;
855}; 862};
856 863
857/* XXX: If there is a better way to do this, I'd love to hear about it */ 864/* XXX: If there is a better way to do this, I'd love to hear about it */
858static int 865static int
859reiserfs_chown_xattrs_filler (void *buf, const char *name, int namelen, 866reiserfs_chown_xattrs_filler(void *buf, const char *name, int namelen,
860 loff_t offset, ino_t ino, unsigned int d_type) 867 loff_t offset, ino_t ino, unsigned int d_type)
861{ 868{
862 struct reiserfs_chown_buf *chown_buf = (struct reiserfs_chown_buf *)buf; 869 struct reiserfs_chown_buf *chown_buf = (struct reiserfs_chown_buf *)buf;
863 struct dentry *xafile, *xadir = chown_buf->xadir; 870 struct dentry *xafile, *xadir = chown_buf->xadir;
864 struct iattr *attrs = chown_buf->attrs; 871 struct iattr *attrs = chown_buf->attrs;
865 int err = 0; 872 int err = 0;
866 873
867 xafile = lookup_one_len (name, xadir, namelen); 874 xafile = lookup_one_len(name, xadir, namelen);
868 if (IS_ERR (xafile)) 875 if (IS_ERR(xafile))
869 return PTR_ERR (xafile); 876 return PTR_ERR(xafile);
870 else if (!xafile->d_inode) { 877 else if (!xafile->d_inode) {
871 dput (xafile); 878 dput(xafile);
872 return -ENODATA; 879 return -ENODATA;
873 } 880 }
874 881
875 if (!S_ISDIR (xafile->d_inode->i_mode)) 882 if (!S_ISDIR(xafile->d_inode->i_mode))
876 err = notify_change (xafile, attrs); 883 err = notify_change(xafile, attrs);
877 dput (xafile); 884 dput(xafile);
878 885
879 return err; 886 return err;
880} 887}
881 888
882int 889int reiserfs_chown_xattrs(struct inode *inode, struct iattr *attrs)
883reiserfs_chown_xattrs (struct inode *inode, struct iattr *attrs)
884{ 890{
885 struct file *fp; 891 struct file *fp;
886 struct dentry *dir; 892 struct dentry *dir;
887 int err = 0; 893 int err = 0;
888 struct reiserfs_chown_buf buf; 894 struct reiserfs_chown_buf buf;
889 unsigned int ia_valid = attrs->ia_valid; 895 unsigned int ia_valid = attrs->ia_valid;
890 896
891 /* Skip out, an xattr has no xattrs associated with it */ 897 /* Skip out, an xattr has no xattrs associated with it */
892 if (is_reiserfs_priv_object (inode) || 898 if (is_reiserfs_priv_object(inode) ||
893 get_inode_sd_version (inode) == STAT_DATA_V1 || 899 get_inode_sd_version(inode) == STAT_DATA_V1 ||
894 !reiserfs_xattrs(inode->i_sb)) 900 !reiserfs_xattrs(inode->i_sb)) {
895 { 901 return 0;
896 return 0; 902 }
897 } 903 reiserfs_read_lock_xattrs(inode->i_sb);
898 reiserfs_read_lock_xattrs (inode->i_sb); 904 dir = open_xa_dir(inode, FL_READONLY);
899 dir = open_xa_dir (inode, FL_READONLY); 905 reiserfs_read_unlock_xattrs(inode->i_sb);
900 reiserfs_read_unlock_xattrs (inode->i_sb); 906 if (IS_ERR(dir)) {
901 if (IS_ERR (dir)) { 907 if (PTR_ERR(dir) != -ENODATA)
902 if (PTR_ERR (dir) != -ENODATA) 908 err = PTR_ERR(dir);
903 err = PTR_ERR (dir); 909 goto out;
904 goto out; 910 } else if (!dir->d_inode) {
905 } else if (!dir->d_inode) { 911 dput(dir);
906 dput (dir); 912 goto out;
907 goto out; 913 }
908 } 914
909 915 fp = dentry_open(dir, NULL, O_RDWR);
910 fp = dentry_open (dir, NULL, O_RDWR); 916 if (IS_ERR(fp)) {
911 if (IS_ERR (fp)) { 917 err = PTR_ERR(fp);
912 err = PTR_ERR (fp); 918 /* dentry_open dputs the dentry if it fails */
913 /* dentry_open dputs the dentry if it fails */ 919 goto out;
914 goto out; 920 }
915 }
916
917 lock_kernel ();
918
919 attrs->ia_valid &= (ATTR_UID | ATTR_GID | ATTR_CTIME);
920 buf.xadir = dir;
921 buf.attrs = attrs;
922 buf.inode = inode;
923
924 err = xattr_readdir (fp, reiserfs_chown_xattrs_filler, &buf);
925 if (err) {
926 unlock_kernel ();
927 goto out_dir;
928 }
929
930 err = notify_change (dir, attrs);
931 unlock_kernel ();
932
933out_dir:
934 fput(fp);
935
936out:
937 attrs->ia_valid = ia_valid;
938 return err;
939}
940 921
922 lock_kernel();
923
924 attrs->ia_valid &= (ATTR_UID | ATTR_GID | ATTR_CTIME);
925 buf.xadir = dir;
926 buf.attrs = attrs;
927 buf.inode = inode;
928
929 err = xattr_readdir(fp, reiserfs_chown_xattrs_filler, &buf);
930 if (err) {
931 unlock_kernel();
932 goto out_dir;
933 }
934
935 err = notify_change(dir, attrs);
936 unlock_kernel();
937
938 out_dir:
939 fput(fp);
940
941 out:
942 attrs->ia_valid = ia_valid;
943 return err;
944}
941 945
942/* Actual operations that are exported to VFS-land */ 946/* Actual operations that are exported to VFS-land */
943 947
@@ -946,61 +950,60 @@ out:
946 * Preliminary locking: we down dentry->d_inode->i_sem 950 * Preliminary locking: we down dentry->d_inode->i_sem
947 */ 951 */
948ssize_t 952ssize_t
949reiserfs_getxattr (struct dentry *dentry, const char *name, void *buffer, 953reiserfs_getxattr(struct dentry * dentry, const char *name, void *buffer,
950 size_t size) 954 size_t size)
951{ 955{
952 struct reiserfs_xattr_handler *xah = find_xattr_handler_prefix (name); 956 struct reiserfs_xattr_handler *xah = find_xattr_handler_prefix(name);
953 int err; 957 int err;
954 958
955 if (!xah || !reiserfs_xattrs(dentry->d_sb) || 959 if (!xah || !reiserfs_xattrs(dentry->d_sb) ||
956 get_inode_sd_version (dentry->d_inode) == STAT_DATA_V1) 960 get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1)
957 return -EOPNOTSUPP; 961 return -EOPNOTSUPP;
958 962
959 reiserfs_read_lock_xattr_i (dentry->d_inode); 963 reiserfs_read_lock_xattr_i(dentry->d_inode);
960 reiserfs_read_lock_xattrs (dentry->d_sb); 964 reiserfs_read_lock_xattrs(dentry->d_sb);
961 err = xah->get (dentry->d_inode, name, buffer, size); 965 err = xah->get(dentry->d_inode, name, buffer, size);
962 reiserfs_read_unlock_xattrs (dentry->d_sb); 966 reiserfs_read_unlock_xattrs(dentry->d_sb);
963 reiserfs_read_unlock_xattr_i (dentry->d_inode); 967 reiserfs_read_unlock_xattr_i(dentry->d_inode);
964 return err; 968 return err;
965} 969}
966 970
967
968/* 971/*
969 * Inode operation setxattr() 972 * Inode operation setxattr()
970 * 973 *
971 * dentry->d_inode->i_sem down 974 * dentry->d_inode->i_sem down
972 */ 975 */
973int 976int
974reiserfs_setxattr (struct dentry *dentry, const char *name, const void *value, 977reiserfs_setxattr(struct dentry *dentry, const char *name, const void *value,
975 size_t size, int flags) 978 size_t size, int flags)
976{ 979{
977 struct reiserfs_xattr_handler *xah = find_xattr_handler_prefix (name); 980 struct reiserfs_xattr_handler *xah = find_xattr_handler_prefix(name);
978 int err; 981 int err;
979 int lock; 982 int lock;
980 983
981 if (!xah || !reiserfs_xattrs(dentry->d_sb) || 984 if (!xah || !reiserfs_xattrs(dentry->d_sb) ||
982 get_inode_sd_version (dentry->d_inode) == STAT_DATA_V1) 985 get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1)
983 return -EOPNOTSUPP; 986 return -EOPNOTSUPP;
984 987
985 if (IS_RDONLY (dentry->d_inode)) 988 if (IS_RDONLY(dentry->d_inode))
986 return -EROFS; 989 return -EROFS;
987 990
988 if (IS_IMMUTABLE (dentry->d_inode) || IS_APPEND (dentry->d_inode)) 991 if (IS_IMMUTABLE(dentry->d_inode) || IS_APPEND(dentry->d_inode))
989 return -EROFS; 992 return -EROFS;
990 993
991 reiserfs_write_lock_xattr_i (dentry->d_inode); 994 reiserfs_write_lock_xattr_i(dentry->d_inode);
992 lock = !has_xattr_dir (dentry->d_inode); 995 lock = !has_xattr_dir(dentry->d_inode);
993 if (lock) 996 if (lock)
994 reiserfs_write_lock_xattrs (dentry->d_sb); 997 reiserfs_write_lock_xattrs(dentry->d_sb);
995 else 998 else
996 reiserfs_read_lock_xattrs (dentry->d_sb); 999 reiserfs_read_lock_xattrs(dentry->d_sb);
997 err = xah->set (dentry->d_inode, name, value, size, flags); 1000 err = xah->set(dentry->d_inode, name, value, size, flags);
998 if (lock) 1001 if (lock)
999 reiserfs_write_unlock_xattrs (dentry->d_sb); 1002 reiserfs_write_unlock_xattrs(dentry->d_sb);
1000 else 1003 else
1001 reiserfs_read_unlock_xattrs (dentry->d_sb); 1004 reiserfs_read_unlock_xattrs(dentry->d_sb);
1002 reiserfs_write_unlock_xattr_i (dentry->d_inode); 1005 reiserfs_write_unlock_xattr_i(dentry->d_inode);
1003 return err; 1006 return err;
1004} 1007}
1005 1008
1006/* 1009/*
@@ -1008,344 +1011,343 @@ reiserfs_setxattr (struct dentry *dentry, const char *name, const void *value,
1008 * 1011 *
1009 * dentry->d_inode->i_sem down 1012 * dentry->d_inode->i_sem down
1010 */ 1013 */
1011int 1014int reiserfs_removexattr(struct dentry *dentry, const char *name)
1012reiserfs_removexattr (struct dentry *dentry, const char *name)
1013{ 1015{
1014 int err; 1016 int err;
1015 struct reiserfs_xattr_handler *xah = find_xattr_handler_prefix (name); 1017 struct reiserfs_xattr_handler *xah = find_xattr_handler_prefix(name);
1016 1018
1017 if (!xah || !reiserfs_xattrs(dentry->d_sb) || 1019 if (!xah || !reiserfs_xattrs(dentry->d_sb) ||
1018 get_inode_sd_version (dentry->d_inode) == STAT_DATA_V1) 1020 get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1)
1019 return -EOPNOTSUPP; 1021 return -EOPNOTSUPP;
1020 1022
1021 if (IS_RDONLY (dentry->d_inode)) 1023 if (IS_RDONLY(dentry->d_inode))
1022 return -EROFS; 1024 return -EROFS;
1023 1025
1024 if (IS_IMMUTABLE (dentry->d_inode) || IS_APPEND (dentry->d_inode)) 1026 if (IS_IMMUTABLE(dentry->d_inode) || IS_APPEND(dentry->d_inode))
1025 return -EPERM; 1027 return -EPERM;
1026 1028
1027 reiserfs_write_lock_xattr_i (dentry->d_inode); 1029 reiserfs_write_lock_xattr_i(dentry->d_inode);
1028 reiserfs_read_lock_xattrs (dentry->d_sb); 1030 reiserfs_read_lock_xattrs(dentry->d_sb);
1029 1031
1030 /* Deletion pre-operation */ 1032 /* Deletion pre-operation */
1031 if (xah->del) { 1033 if (xah->del) {
1032 err = xah->del (dentry->d_inode, name); 1034 err = xah->del(dentry->d_inode, name);
1033 if (err) 1035 if (err)
1034 goto out; 1036 goto out;
1035 } 1037 }
1036 1038
1037 err = reiserfs_xattr_del (dentry->d_inode, name); 1039 err = reiserfs_xattr_del(dentry->d_inode, name);
1038 1040
1039 dentry->d_inode->i_ctime = CURRENT_TIME_SEC; 1041 dentry->d_inode->i_ctime = CURRENT_TIME_SEC;
1040 mark_inode_dirty (dentry->d_inode); 1042 mark_inode_dirty(dentry->d_inode);
1041 1043
1042out: 1044 out:
1043 reiserfs_read_unlock_xattrs (dentry->d_sb); 1045 reiserfs_read_unlock_xattrs(dentry->d_sb);
1044 reiserfs_write_unlock_xattr_i (dentry->d_inode); 1046 reiserfs_write_unlock_xattr_i(dentry->d_inode);
1045 return err; 1047 return err;
1046} 1048}
1047 1049
1048
1049/* This is what filldir will use: 1050/* This is what filldir will use:
1050 * r_pos will always contain the amount of space required for the entire 1051 * r_pos will always contain the amount of space required for the entire
1051 * list. If r_pos becomes larger than r_size, we need more space and we 1052 * list. If r_pos becomes larger than r_size, we need more space and we
1052 * return an error indicating this. If r_pos is less than r_size, then we've 1053 * return an error indicating this. If r_pos is less than r_size, then we've
1053 * filled the buffer successfully and we return success */ 1054 * filled the buffer successfully and we return success */
1054struct reiserfs_listxattr_buf { 1055struct reiserfs_listxattr_buf {
1055 int r_pos; 1056 int r_pos;
1056 int r_size; 1057 int r_size;
1057 char *r_buf; 1058 char *r_buf;
1058 struct inode *r_inode; 1059 struct inode *r_inode;
1059}; 1060};
1060 1061
1061static int 1062static int
1062reiserfs_listxattr_filler (void *buf, const char *name, int namelen, 1063reiserfs_listxattr_filler(void *buf, const char *name, int namelen,
1063 loff_t offset, ino_t ino, unsigned int d_type) 1064 loff_t offset, ino_t ino, unsigned int d_type)
1064{ 1065{
1065 struct reiserfs_listxattr_buf *b = (struct reiserfs_listxattr_buf *)buf; 1066 struct reiserfs_listxattr_buf *b = (struct reiserfs_listxattr_buf *)buf;
1066 int len = 0; 1067 int len = 0;
1067 if (name[0] != '.' || (namelen != 1 && (name[1] != '.' || namelen != 2))) { 1068 if (name[0] != '.'
1068 struct reiserfs_xattr_handler *xah = find_xattr_handler_prefix (name); 1069 || (namelen != 1 && (name[1] != '.' || namelen != 2))) {
1069 if (!xah) return 0; /* Unsupported xattr name, skip it */ 1070 struct reiserfs_xattr_handler *xah =
1070 1071 find_xattr_handler_prefix(name);
1071 /* We call ->list() twice because the operation isn't required to just 1072 if (!xah)
1072 * return the name back - we want to make sure we have enough space */ 1073 return 0; /* Unsupported xattr name, skip it */
1073 len += xah->list (b->r_inode, name, namelen, NULL); 1074
1074 1075 /* We call ->list() twice because the operation isn't required to just
1075 if (len) { 1076 * return the name back - we want to make sure we have enough space */
1076 if (b->r_pos + len + 1 <= b->r_size) { 1077 len += xah->list(b->r_inode, name, namelen, NULL);
1077 char *p = b->r_buf + b->r_pos; 1078
1078 p += xah->list (b->r_inode, name, namelen, p); 1079 if (len) {
1079 *p++ = '\0'; 1080 if (b->r_pos + len + 1 <= b->r_size) {
1080 } 1081 char *p = b->r_buf + b->r_pos;
1081 b->r_pos += len + 1; 1082 p += xah->list(b->r_inode, name, namelen, p);
1082 } 1083 *p++ = '\0';
1083 } 1084 }
1084 1085 b->r_pos += len + 1;
1085 return 0; 1086 }
1087 }
1088
1089 return 0;
1086} 1090}
1091
1087/* 1092/*
1088 * Inode operation listxattr() 1093 * Inode operation listxattr()
1089 * 1094 *
1090 * Preliminary locking: we down dentry->d_inode->i_sem 1095 * Preliminary locking: we down dentry->d_inode->i_sem
1091 */ 1096 */
1092ssize_t 1097ssize_t reiserfs_listxattr(struct dentry * dentry, char *buffer, size_t size)
1093reiserfs_listxattr (struct dentry *dentry, char *buffer, size_t size)
1094{ 1098{
1095 struct file *fp; 1099 struct file *fp;
1096 struct dentry *dir; 1100 struct dentry *dir;
1097 int err = 0; 1101 int err = 0;
1098 struct reiserfs_listxattr_buf buf; 1102 struct reiserfs_listxattr_buf buf;
1099 1103
1100 if (!dentry->d_inode) 1104 if (!dentry->d_inode)
1101 return -EINVAL; 1105 return -EINVAL;
1102 1106
1103 if (!reiserfs_xattrs(dentry->d_sb) || 1107 if (!reiserfs_xattrs(dentry->d_sb) ||
1104 get_inode_sd_version (dentry->d_inode) == STAT_DATA_V1) 1108 get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1)
1105 return -EOPNOTSUPP; 1109 return -EOPNOTSUPP;
1106 1110
1107 reiserfs_read_lock_xattr_i (dentry->d_inode); 1111 reiserfs_read_lock_xattr_i(dentry->d_inode);
1108 reiserfs_read_lock_xattrs (dentry->d_sb); 1112 reiserfs_read_lock_xattrs(dentry->d_sb);
1109 dir = open_xa_dir (dentry->d_inode, FL_READONLY); 1113 dir = open_xa_dir(dentry->d_inode, FL_READONLY);
1110 reiserfs_read_unlock_xattrs (dentry->d_sb); 1114 reiserfs_read_unlock_xattrs(dentry->d_sb);
1111 if (IS_ERR (dir)) { 1115 if (IS_ERR(dir)) {
1112 err = PTR_ERR (dir); 1116 err = PTR_ERR(dir);
1113 if (err == -ENODATA) 1117 if (err == -ENODATA)
1114 err = 0; /* Not an error if there aren't any xattrs */ 1118 err = 0; /* Not an error if there aren't any xattrs */
1115 goto out; 1119 goto out;
1116 } 1120 }
1117 1121
1118 fp = dentry_open (dir, NULL, O_RDWR); 1122 fp = dentry_open(dir, NULL, O_RDWR);
1119 if (IS_ERR (fp)) { 1123 if (IS_ERR(fp)) {
1120 err = PTR_ERR (fp); 1124 err = PTR_ERR(fp);
1121 /* dentry_open dputs the dentry if it fails */ 1125 /* dentry_open dputs the dentry if it fails */
1122 goto out; 1126 goto out;
1123 } 1127 }
1124 1128
1125 buf.r_buf = buffer; 1129 buf.r_buf = buffer;
1126 buf.r_size = buffer ? size : 0; 1130 buf.r_size = buffer ? size : 0;
1127 buf.r_pos = 0; 1131 buf.r_pos = 0;
1128 buf.r_inode = dentry->d_inode; 1132 buf.r_inode = dentry->d_inode;
1129 1133
1130 REISERFS_I(dentry->d_inode)->i_flags |= i_has_xattr_dir; 1134 REISERFS_I(dentry->d_inode)->i_flags |= i_has_xattr_dir;
1131 1135
1132 err = xattr_readdir (fp, reiserfs_listxattr_filler, &buf); 1136 err = xattr_readdir(fp, reiserfs_listxattr_filler, &buf);
1133 if (err) 1137 if (err)
1134 goto out_dir; 1138 goto out_dir;
1135 1139
1136 if (buf.r_pos > buf.r_size && buffer != NULL) 1140 if (buf.r_pos > buf.r_size && buffer != NULL)
1137 err = -ERANGE; 1141 err = -ERANGE;
1138 else 1142 else
1139 err = buf.r_pos; 1143 err = buf.r_pos;
1140 1144
1141out_dir: 1145 out_dir:
1142 fput(fp); 1146 fput(fp);
1143 1147
1144out: 1148 out:
1145 reiserfs_read_unlock_xattr_i (dentry->d_inode); 1149 reiserfs_read_unlock_xattr_i(dentry->d_inode);
1146 return err; 1150 return err;
1147} 1151}
1148 1152
1149/* This is the implementation for the xattr plugin infrastructure */ 1153/* This is the implementation for the xattr plugin infrastructure */
1150static struct list_head xattr_handlers = LIST_HEAD_INIT (xattr_handlers); 1154static struct list_head xattr_handlers = LIST_HEAD_INIT(xattr_handlers);
1151static DEFINE_RWLOCK(handler_lock); 1155static DEFINE_RWLOCK(handler_lock);
1152 1156
1153static struct reiserfs_xattr_handler * 1157static struct reiserfs_xattr_handler *find_xattr_handler_prefix(const char
1154find_xattr_handler_prefix (const char *prefix) 1158 *prefix)
1155{ 1159{
1156 struct reiserfs_xattr_handler *xah = NULL; 1160 struct reiserfs_xattr_handler *xah = NULL;
1157 struct list_head *p; 1161 struct list_head *p;
1158 1162
1159 read_lock (&handler_lock); 1163 read_lock(&handler_lock);
1160 list_for_each (p, &xattr_handlers) { 1164 list_for_each(p, &xattr_handlers) {
1161 xah = list_entry (p, struct reiserfs_xattr_handler, handlers); 1165 xah = list_entry(p, struct reiserfs_xattr_handler, handlers);
1162 if (strncmp (xah->prefix, prefix, strlen (xah->prefix)) == 0) 1166 if (strncmp(xah->prefix, prefix, strlen(xah->prefix)) == 0)
1163 break; 1167 break;
1164 xah = NULL; 1168 xah = NULL;
1165 } 1169 }
1166 1170
1167 read_unlock (&handler_lock); 1171 read_unlock(&handler_lock);
1168 return xah; 1172 return xah;
1169} 1173}
1170 1174
1171static void 1175static void __unregister_handlers(void)
1172__unregister_handlers (void)
1173{ 1176{
1174 struct reiserfs_xattr_handler *xah; 1177 struct reiserfs_xattr_handler *xah;
1175 struct list_head *p, *tmp; 1178 struct list_head *p, *tmp;
1176 1179
1177 list_for_each_safe (p, tmp, &xattr_handlers) { 1180 list_for_each_safe(p, tmp, &xattr_handlers) {
1178 xah = list_entry (p, struct reiserfs_xattr_handler, handlers); 1181 xah = list_entry(p, struct reiserfs_xattr_handler, handlers);
1179 if (xah->exit) 1182 if (xah->exit)
1180 xah->exit(); 1183 xah->exit();
1181 1184
1182 list_del_init (p); 1185 list_del_init(p);
1183 } 1186 }
1184 INIT_LIST_HEAD (&xattr_handlers); 1187 INIT_LIST_HEAD(&xattr_handlers);
1185} 1188}
1186 1189
1187int __init 1190int __init reiserfs_xattr_register_handlers(void)
1188reiserfs_xattr_register_handlers (void)
1189{ 1191{
1190 int err = 0; 1192 int err = 0;
1191 struct reiserfs_xattr_handler *xah; 1193 struct reiserfs_xattr_handler *xah;
1192 struct list_head *p; 1194 struct list_head *p;
1193 1195
1194 write_lock (&handler_lock); 1196 write_lock(&handler_lock);
1195 1197
1196 /* If we're already initialized, nothing to do */ 1198 /* If we're already initialized, nothing to do */
1197 if (!list_empty (&xattr_handlers)) { 1199 if (!list_empty(&xattr_handlers)) {
1198 write_unlock (&handler_lock); 1200 write_unlock(&handler_lock);
1199 return 0; 1201 return 0;
1200 } 1202 }
1201 1203
1202 /* Add the handlers */ 1204 /* Add the handlers */
1203 list_add_tail (&user_handler.handlers, &xattr_handlers); 1205 list_add_tail(&user_handler.handlers, &xattr_handlers);
1204 list_add_tail (&trusted_handler.handlers, &xattr_handlers); 1206 list_add_tail(&trusted_handler.handlers, &xattr_handlers);
1205#ifdef CONFIG_REISERFS_FS_SECURITY 1207#ifdef CONFIG_REISERFS_FS_SECURITY
1206 list_add_tail (&security_handler.handlers, &xattr_handlers); 1208 list_add_tail(&security_handler.handlers, &xattr_handlers);
1207#endif 1209#endif
1208#ifdef CONFIG_REISERFS_FS_POSIX_ACL 1210#ifdef CONFIG_REISERFS_FS_POSIX_ACL
1209 list_add_tail (&posix_acl_access_handler.handlers, &xattr_handlers); 1211 list_add_tail(&posix_acl_access_handler.handlers, &xattr_handlers);
1210 list_add_tail (&posix_acl_default_handler.handlers, &xattr_handlers); 1212 list_add_tail(&posix_acl_default_handler.handlers, &xattr_handlers);
1211#endif 1213#endif
1212 1214
1213 /* Run initializers, if available */ 1215 /* Run initializers, if available */
1214 list_for_each (p, &xattr_handlers) { 1216 list_for_each(p, &xattr_handlers) {
1215 xah = list_entry (p, struct reiserfs_xattr_handler, handlers); 1217 xah = list_entry(p, struct reiserfs_xattr_handler, handlers);
1216 if (xah->init) { 1218 if (xah->init) {
1217 err = xah->init (); 1219 err = xah->init();
1218 if (err) { 1220 if (err) {
1219 list_del_init (p); 1221 list_del_init(p);
1220 break; 1222 break;
1221 } 1223 }
1222 } 1224 }
1223 } 1225 }
1224 1226
1225 /* Clean up other handlers, if any failed */ 1227 /* Clean up other handlers, if any failed */
1226 if (err) 1228 if (err)
1227 __unregister_handlers (); 1229 __unregister_handlers();
1228 1230
1229 write_unlock (&handler_lock); 1231 write_unlock(&handler_lock);
1230 return err; 1232 return err;
1231} 1233}
1232 1234
1233void 1235void reiserfs_xattr_unregister_handlers(void)
1234reiserfs_xattr_unregister_handlers (void)
1235{ 1236{
1236 write_lock (&handler_lock); 1237 write_lock(&handler_lock);
1237 __unregister_handlers (); 1238 __unregister_handlers();
1238 write_unlock (&handler_lock); 1239 write_unlock(&handler_lock);
1239} 1240}
1240 1241
1241/* This will catch lookups from the fs root to .reiserfs_priv */ 1242/* This will catch lookups from the fs root to .reiserfs_priv */
1242static int 1243static int
1243xattr_lookup_poison (struct dentry *dentry, struct qstr *q1, struct qstr *name) 1244xattr_lookup_poison(struct dentry *dentry, struct qstr *q1, struct qstr *name)
1244{ 1245{
1245 struct dentry *priv_root = REISERFS_SB(dentry->d_sb)->priv_root; 1246 struct dentry *priv_root = REISERFS_SB(dentry->d_sb)->priv_root;
1246 if (name->len == priv_root->d_name.len && 1247 if (name->len == priv_root->d_name.len &&
1247 name->hash == priv_root->d_name.hash && 1248 name->hash == priv_root->d_name.hash &&
1248 !memcmp (name->name, priv_root->d_name.name, name->len)) { 1249 !memcmp(name->name, priv_root->d_name.name, name->len)) {
1249 return -ENOENT; 1250 return -ENOENT;
1250 } else if (q1->len == name->len && 1251 } else if (q1->len == name->len &&
1251 !memcmp(q1->name, name->name, name->len)) 1252 !memcmp(q1->name, name->name, name->len))
1252 return 0; 1253 return 0;
1253 return 1; 1254 return 1;
1254} 1255}
1255 1256
1256static struct dentry_operations xattr_lookup_poison_ops = { 1257static struct dentry_operations xattr_lookup_poison_ops = {
1257 .d_compare = xattr_lookup_poison, 1258 .d_compare = xattr_lookup_poison,
1258}; 1259};
1259 1260
1260
1261/* We need to take a copy of the mount flags since things like 1261/* We need to take a copy of the mount flags since things like
1262 * MS_RDONLY don't get set until *after* we're called. 1262 * MS_RDONLY don't get set until *after* we're called.
1263 * mount_flags != mount_options */ 1263 * mount_flags != mount_options */
1264int 1264int reiserfs_xattr_init(struct super_block *s, int mount_flags)
1265reiserfs_xattr_init (struct super_block *s, int mount_flags)
1266{ 1265{
1267 int err = 0; 1266 int err = 0;
1268 1267
1269 /* We need generation numbers to ensure that the oid mapping is correct 1268 /* We need generation numbers to ensure that the oid mapping is correct
1270 * v3.5 filesystems don't have them. */ 1269 * v3.5 filesystems don't have them. */
1271 if (!old_format_only (s)) { 1270 if (!old_format_only(s)) {
1272 set_bit (REISERFS_XATTRS, &(REISERFS_SB(s)->s_mount_opt)); 1271 set_bit(REISERFS_XATTRS, &(REISERFS_SB(s)->s_mount_opt));
1273 } else if (reiserfs_xattrs_optional (s)) { 1272 } else if (reiserfs_xattrs_optional(s)) {
1274 /* Old format filesystem, but optional xattrs have been enabled 1273 /* Old format filesystem, but optional xattrs have been enabled
1275 * at mount time. Error out. */ 1274 * at mount time. Error out. */
1276 reiserfs_warning (s, "xattrs/ACLs not supported on pre v3.6 " 1275 reiserfs_warning(s, "xattrs/ACLs not supported on pre v3.6 "
1277 "format filesystem. Failing mount."); 1276 "format filesystem. Failing mount.");
1278 err = -EOPNOTSUPP; 1277 err = -EOPNOTSUPP;
1279 goto error; 1278 goto error;
1280 } else { 1279 } else {
1281 /* Old format filesystem, but no optional xattrs have been enabled. This 1280 /* Old format filesystem, but no optional xattrs have been enabled. This
1282 * means we silently disable xattrs on the filesystem. */ 1281 * means we silently disable xattrs on the filesystem. */
1283 clear_bit (REISERFS_XATTRS, &(REISERFS_SB(s)->s_mount_opt)); 1282 clear_bit(REISERFS_XATTRS, &(REISERFS_SB(s)->s_mount_opt));
1284 } 1283 }
1285 1284
1286 /* If we don't have the privroot located yet - go find it */ 1285 /* If we don't have the privroot located yet - go find it */
1287 if (reiserfs_xattrs (s) && !REISERFS_SB(s)->priv_root) { 1286 if (reiserfs_xattrs(s) && !REISERFS_SB(s)->priv_root) {
1288 struct dentry *dentry; 1287 struct dentry *dentry;
1289 dentry = lookup_one_len (PRIVROOT_NAME, s->s_root, 1288 dentry = lookup_one_len(PRIVROOT_NAME, s->s_root,
1290 strlen (PRIVROOT_NAME)); 1289 strlen(PRIVROOT_NAME));
1291 if (!IS_ERR (dentry)) { 1290 if (!IS_ERR(dentry)) {
1292 if (!(mount_flags & MS_RDONLY) && !dentry->d_inode) { 1291 if (!(mount_flags & MS_RDONLY) && !dentry->d_inode) {
1293 struct inode *inode = dentry->d_parent->d_inode; 1292 struct inode *inode = dentry->d_parent->d_inode;
1294 down (&inode->i_sem); 1293 down(&inode->i_sem);
1295 err = inode->i_op->mkdir (inode, dentry, 0700); 1294 err = inode->i_op->mkdir(inode, dentry, 0700);
1296 up (&inode->i_sem); 1295 up(&inode->i_sem);
1297 if (err) { 1296 if (err) {
1298 dput (dentry); 1297 dput(dentry);
1299 dentry = NULL; 1298 dentry = NULL;
1300 } 1299 }
1301 1300
1302 if (dentry && dentry->d_inode) 1301 if (dentry && dentry->d_inode)
1303 reiserfs_warning (s, "Created %s on %s - reserved for " 1302 reiserfs_warning(s,
1304 "xattr storage.", PRIVROOT_NAME, 1303 "Created %s on %s - reserved for "
1305 reiserfs_bdevname (inode->i_sb)); 1304 "xattr storage.",
1306 } else if (!dentry->d_inode) { 1305 PRIVROOT_NAME,
1307 dput (dentry); 1306 reiserfs_bdevname
1308 dentry = NULL; 1307 (inode->i_sb));
1309 } 1308 } else if (!dentry->d_inode) {
1310 } else 1309 dput(dentry);
1311 err = PTR_ERR (dentry); 1310 dentry = NULL;
1312 1311 }
1313 if (!err && dentry) { 1312 } else
1314 s->s_root->d_op = &xattr_lookup_poison_ops; 1313 err = PTR_ERR(dentry);
1315 reiserfs_mark_inode_private (dentry->d_inode); 1314
1316 REISERFS_SB(s)->priv_root = dentry; 1315 if (!err && dentry) {
1317 } else if (!(mount_flags & MS_RDONLY)) { /* xattrs are unavailable */ 1316 s->s_root->d_op = &xattr_lookup_poison_ops;
1318 /* If we're read-only it just means that the dir hasn't been 1317 reiserfs_mark_inode_private(dentry->d_inode);
1319 * created. Not an error -- just no xattrs on the fs. We'll 1318 REISERFS_SB(s)->priv_root = dentry;
1320 * check again if we go read-write */ 1319 } else if (!(mount_flags & MS_RDONLY)) { /* xattrs are unavailable */
1321 reiserfs_warning (s, "xattrs/ACLs enabled and couldn't " 1320 /* If we're read-only it just means that the dir hasn't been
1322 "find/create .reiserfs_priv. Failing mount."); 1321 * created. Not an error -- just no xattrs on the fs. We'll
1323 err = -EOPNOTSUPP; 1322 * check again if we go read-write */
1324 } 1323 reiserfs_warning(s, "xattrs/ACLs enabled and couldn't "
1325 } 1324 "find/create .reiserfs_priv. Failing mount.");
1326 1325 err = -EOPNOTSUPP;
1327error: 1326 }
1328 /* This is only nonzero if there was an error initializing the xattr 1327 }
1329 * directory or if there is a condition where we don't support them. */ 1328
1330 if (err) { 1329 error:
1331 clear_bit (REISERFS_XATTRS, &(REISERFS_SB(s)->s_mount_opt)); 1330 /* This is only nonzero if there was an error initializing the xattr
1332 clear_bit (REISERFS_XATTRS_USER, &(REISERFS_SB(s)->s_mount_opt)); 1331 * directory or if there is a condition where we don't support them. */
1333 clear_bit (REISERFS_POSIXACL, &(REISERFS_SB(s)->s_mount_opt)); 1332 if (err) {
1334 } 1333 clear_bit(REISERFS_XATTRS, &(REISERFS_SB(s)->s_mount_opt));
1335 1334 clear_bit(REISERFS_XATTRS_USER, &(REISERFS_SB(s)->s_mount_opt));
1336 /* The super_block MS_POSIXACL must mirror the (no)acl mount option. */ 1335 clear_bit(REISERFS_POSIXACL, &(REISERFS_SB(s)->s_mount_opt));
1337 s->s_flags = s->s_flags & ~MS_POSIXACL; 1336 }
1338 if (reiserfs_posixacl (s)) 1337
1339 s->s_flags |= MS_POSIXACL; 1338 /* The super_block MS_POSIXACL must mirror the (no)acl mount option. */
1340 1339 s->s_flags = s->s_flags & ~MS_POSIXACL;
1341 return err; 1340 if (reiserfs_posixacl(s))
1341 s->s_flags |= MS_POSIXACL;
1342
1343 return err;
1342} 1344}
1343 1345
1344static int 1346static int
1345__reiserfs_permission (struct inode *inode, int mask, struct nameidata *nd, 1347__reiserfs_permission(struct inode *inode, int mask, struct nameidata *nd,
1346 int need_lock) 1348 int need_lock)
1347{ 1349{
1348 umode_t mode = inode->i_mode; 1350 umode_t mode = inode->i_mode;
1349 1351
1350 if (mask & MAY_WRITE) { 1352 if (mask & MAY_WRITE) {
1351 /* 1353 /*
@@ -1363,50 +1365,50 @@ __reiserfs_permission (struct inode *inode, int mask, struct nameidata *nd,
1363 } 1365 }
1364 1366
1365 /* We don't do permission checks on the internal objects. 1367 /* We don't do permission checks on the internal objects.
1366 * Permissions are determined by the "owning" object. */ 1368 * Permissions are determined by the "owning" object. */
1367 if (is_reiserfs_priv_object (inode)) 1369 if (is_reiserfs_priv_object(inode))
1368 return 0; 1370 return 0;
1369 1371
1370 if (current->fsuid == inode->i_uid) { 1372 if (current->fsuid == inode->i_uid) {
1371 mode >>= 6; 1373 mode >>= 6;
1372#ifdef CONFIG_REISERFS_FS_POSIX_ACL 1374#ifdef CONFIG_REISERFS_FS_POSIX_ACL
1373 } else if (reiserfs_posixacl(inode->i_sb) && 1375 } else if (reiserfs_posixacl(inode->i_sb) &&
1374 get_inode_sd_version (inode) != STAT_DATA_V1) { 1376 get_inode_sd_version(inode) != STAT_DATA_V1) {
1375 struct posix_acl *acl; 1377 struct posix_acl *acl;
1376 1378
1377 /* ACL can't contain additional permissions if 1379 /* ACL can't contain additional permissions if
1378 the ACL_MASK entry is 0 */ 1380 the ACL_MASK entry is 0 */
1379 if (!(mode & S_IRWXG)) 1381 if (!(mode & S_IRWXG))
1380 goto check_groups; 1382 goto check_groups;
1381 1383
1382 if (need_lock) { 1384 if (need_lock) {
1383 reiserfs_read_lock_xattr_i (inode); 1385 reiserfs_read_lock_xattr_i(inode);
1384 reiserfs_read_lock_xattrs (inode->i_sb); 1386 reiserfs_read_lock_xattrs(inode->i_sb);
1387 }
1388 acl = reiserfs_get_acl(inode, ACL_TYPE_ACCESS);
1389 if (need_lock) {
1390 reiserfs_read_unlock_xattrs(inode->i_sb);
1391 reiserfs_read_unlock_xattr_i(inode);
1385 } 1392 }
1386 acl = reiserfs_get_acl (inode, ACL_TYPE_ACCESS); 1393 if (IS_ERR(acl)) {
1387 if (need_lock) { 1394 if (PTR_ERR(acl) == -ENODATA)
1388 reiserfs_read_unlock_xattrs (inode->i_sb); 1395 goto check_groups;
1389 reiserfs_read_unlock_xattr_i (inode); 1396 return PTR_ERR(acl);
1390 } 1397 }
1391 if (IS_ERR (acl)) { 1398
1392 if (PTR_ERR (acl) == -ENODATA) 1399 if (acl) {
1393 goto check_groups; 1400 int err = posix_acl_permission(inode, acl, mask);
1394 return PTR_ERR (acl); 1401 posix_acl_release(acl);
1395 } 1402 if (err == -EACCES) {
1396 1403 goto check_capabilities;
1397 if (acl) { 1404 }
1398 int err = posix_acl_permission (inode, acl, mask); 1405 return err;
1399 posix_acl_release (acl);
1400 if (err == -EACCES) {
1401 goto check_capabilities;
1402 }
1403 return err;
1404 } else { 1406 } else {
1405 goto check_groups; 1407 goto check_groups;
1406 } 1408 }
1407#endif 1409#endif
1408 } else { 1410 } else {
1409check_groups: 1411 check_groups:
1410 if (in_group_p(inode->i_gid)) 1412 if (in_group_p(inode->i_gid))
1411 mode >>= 3; 1413 mode >>= 3;
1412 } 1414 }
@@ -1414,10 +1416,10 @@ check_groups:
1414 /* 1416 /*
1415 * If the DACs are ok we don't need any capability check. 1417 * If the DACs are ok we don't need any capability check.
1416 */ 1418 */
1417 if (((mode & mask & (MAY_READ|MAY_WRITE|MAY_EXEC)) == mask)) 1419 if (((mode & mask & (MAY_READ | MAY_WRITE | MAY_EXEC)) == mask))
1418 return 0; 1420 return 0;
1419 1421
1420check_capabilities: 1422 check_capabilities:
1421 /* 1423 /*
1422 * Read/write DACs are always overridable. 1424 * Read/write DACs are always overridable.
1423 * Executable DACs are overridable if at least one exec bit is set. 1425 * Executable DACs are overridable if at least one exec bit is set.
@@ -1437,14 +1439,13 @@ check_capabilities:
1437 return -EACCES; 1439 return -EACCES;
1438} 1440}
1439 1441
1440int 1442int reiserfs_permission(struct inode *inode, int mask, struct nameidata *nd)
1441reiserfs_permission (struct inode *inode, int mask, struct nameidata *nd)
1442{ 1443{
1443 return __reiserfs_permission (inode, mask, nd, 1); 1444 return __reiserfs_permission(inode, mask, nd, 1);
1444} 1445}
1445 1446
1446int 1447int
1447reiserfs_permission_locked (struct inode *inode, int mask, struct nameidata *nd) 1448reiserfs_permission_locked(struct inode *inode, int mask, struct nameidata *nd)
1448{ 1449{
1449 return __reiserfs_permission (inode, mask, nd, 0); 1450 return __reiserfs_permission(inode, mask, nd, 0);
1450} 1451}
diff --git a/fs/reiserfs/xattr_acl.c b/fs/reiserfs/xattr_acl.c
index c312881c5f53..6703efa3c430 100644
--- a/fs/reiserfs/xattr_acl.c
+++ b/fs/reiserfs/xattr_acl.c
@@ -9,7 +9,8 @@
9#include <linux/reiserfs_acl.h> 9#include <linux/reiserfs_acl.h>
10#include <asm/uaccess.h> 10#include <asm/uaccess.h>
11 11
12static int reiserfs_set_acl(struct inode *inode, int type, struct posix_acl *acl); 12static int reiserfs_set_acl(struct inode *inode, int type,
13 struct posix_acl *acl);
13 14
14static int 15static int
15xattr_set_acl(struct inode *inode, int type, const void *value, size_t size) 16xattr_set_acl(struct inode *inode, int type, const void *value, size_t size)
@@ -34,14 +35,13 @@ xattr_set_acl(struct inode *inode, int type, const void *value, size_t size)
34 } else 35 } else
35 acl = NULL; 36 acl = NULL;
36 37
37 error = reiserfs_set_acl (inode, type, acl); 38 error = reiserfs_set_acl(inode, type, acl);
38 39
39release_and_out: 40 release_and_out:
40 posix_acl_release(acl); 41 posix_acl_release(acl);
41 return error; 42 return error;
42} 43}
43 44
44
45static int 45static int
46xattr_get_acl(struct inode *inode, int type, void *buffer, size_t size) 46xattr_get_acl(struct inode *inode, int type, void *buffer, size_t size)
47{ 47{
@@ -51,7 +51,7 @@ xattr_get_acl(struct inode *inode, int type, void *buffer, size_t size)
51 if (!reiserfs_posixacl(inode->i_sb)) 51 if (!reiserfs_posixacl(inode->i_sb))
52 return -EOPNOTSUPP; 52 return -EOPNOTSUPP;
53 53
54 acl = reiserfs_get_acl (inode, type); 54 acl = reiserfs_get_acl(inode, type);
55 if (IS_ERR(acl)) 55 if (IS_ERR(acl))
56 return PTR_ERR(acl); 56 return PTR_ERR(acl);
57 if (acl == NULL) 57 if (acl == NULL)
@@ -62,12 +62,10 @@ xattr_get_acl(struct inode *inode, int type, void *buffer, size_t size)
62 return error; 62 return error;
63} 63}
64 64
65
66/* 65/*
67 * Convert from filesystem to in-memory representation. 66 * Convert from filesystem to in-memory representation.
68 */ 67 */
69static struct posix_acl * 68static struct posix_acl *posix_acl_from_disk(const void *value, size_t size)
70posix_acl_from_disk(const void *value, size_t size)
71{ 69{
72 const char *end = (char *)value + size; 70 const char *end = (char *)value + size;
73 int n, count; 71 int n, count;
@@ -76,8 +74,8 @@ posix_acl_from_disk(const void *value, size_t size)
76 if (!value) 74 if (!value)
77 return NULL; 75 return NULL;
78 if (size < sizeof(reiserfs_acl_header)) 76 if (size < sizeof(reiserfs_acl_header))
79 return ERR_PTR(-EINVAL); 77 return ERR_PTR(-EINVAL);
80 if (((reiserfs_acl_header *)value)->a_version != 78 if (((reiserfs_acl_header *) value)->a_version !=
81 cpu_to_le32(REISERFS_ACL_VERSION)) 79 cpu_to_le32(REISERFS_ACL_VERSION))
82 return ERR_PTR(-EINVAL); 80 return ERR_PTR(-EINVAL);
83 value = (char *)value + sizeof(reiserfs_acl_header); 81 value = (char *)value + sizeof(reiserfs_acl_header);
@@ -89,41 +87,39 @@ posix_acl_from_disk(const void *value, size_t size)
89 acl = posix_acl_alloc(count, GFP_NOFS); 87 acl = posix_acl_alloc(count, GFP_NOFS);
90 if (!acl) 88 if (!acl)
91 return ERR_PTR(-ENOMEM); 89 return ERR_PTR(-ENOMEM);
92 for (n=0; n < count; n++) { 90 for (n = 0; n < count; n++) {
93 reiserfs_acl_entry *entry = 91 reiserfs_acl_entry *entry = (reiserfs_acl_entry *) value;
94 (reiserfs_acl_entry *)value;
95 if ((char *)value + sizeof(reiserfs_acl_entry_short) > end) 92 if ((char *)value + sizeof(reiserfs_acl_entry_short) > end)
96 goto fail; 93 goto fail;
97 acl->a_entries[n].e_tag = le16_to_cpu(entry->e_tag); 94 acl->a_entries[n].e_tag = le16_to_cpu(entry->e_tag);
98 acl->a_entries[n].e_perm = le16_to_cpu(entry->e_perm); 95 acl->a_entries[n].e_perm = le16_to_cpu(entry->e_perm);
99 switch(acl->a_entries[n].e_tag) { 96 switch (acl->a_entries[n].e_tag) {
100 case ACL_USER_OBJ: 97 case ACL_USER_OBJ:
101 case ACL_GROUP_OBJ: 98 case ACL_GROUP_OBJ:
102 case ACL_MASK: 99 case ACL_MASK:
103 case ACL_OTHER: 100 case ACL_OTHER:
104 value = (char *)value + 101 value = (char *)value +
105 sizeof(reiserfs_acl_entry_short); 102 sizeof(reiserfs_acl_entry_short);
106 acl->a_entries[n].e_id = ACL_UNDEFINED_ID; 103 acl->a_entries[n].e_id = ACL_UNDEFINED_ID;
107 break; 104 break;
108 105
109 case ACL_USER: 106 case ACL_USER:
110 case ACL_GROUP: 107 case ACL_GROUP:
111 value = (char *)value + sizeof(reiserfs_acl_entry); 108 value = (char *)value + sizeof(reiserfs_acl_entry);
112 if ((char *)value > end) 109 if ((char *)value > end)
113 goto fail;
114 acl->a_entries[n].e_id =
115 le32_to_cpu(entry->e_id);
116 break;
117
118 default:
119 goto fail; 110 goto fail;
111 acl->a_entries[n].e_id = le32_to_cpu(entry->e_id);
112 break;
113
114 default:
115 goto fail;
120 } 116 }
121 } 117 }
122 if (value != end) 118 if (value != end)
123 goto fail; 119 goto fail;
124 return acl; 120 return acl;
125 121
126fail: 122 fail:
127 posix_acl_release(acl); 123 posix_acl_release(acl);
128 return ERR_PTR(-EINVAL); 124 return ERR_PTR(-EINVAL);
129} 125}
@@ -131,46 +127,46 @@ fail:
131/* 127/*
132 * Convert from in-memory to filesystem representation. 128 * Convert from in-memory to filesystem representation.
133 */ 129 */
134static void * 130static void *posix_acl_to_disk(const struct posix_acl *acl, size_t * size)
135posix_acl_to_disk(const struct posix_acl *acl, size_t *size)
136{ 131{
137 reiserfs_acl_header *ext_acl; 132 reiserfs_acl_header *ext_acl;
138 char *e; 133 char *e;
139 int n; 134 int n;
140 135
141 *size = reiserfs_acl_size(acl->a_count); 136 *size = reiserfs_acl_size(acl->a_count);
142 ext_acl = (reiserfs_acl_header *)kmalloc(sizeof(reiserfs_acl_header) + 137 ext_acl = (reiserfs_acl_header *) kmalloc(sizeof(reiserfs_acl_header) +
143 acl->a_count * sizeof(reiserfs_acl_entry), GFP_NOFS); 138 acl->a_count *
139 sizeof(reiserfs_acl_entry),
140 GFP_NOFS);
144 if (!ext_acl) 141 if (!ext_acl)
145 return ERR_PTR(-ENOMEM); 142 return ERR_PTR(-ENOMEM);
146 ext_acl->a_version = cpu_to_le32(REISERFS_ACL_VERSION); 143 ext_acl->a_version = cpu_to_le32(REISERFS_ACL_VERSION);
147 e = (char *)ext_acl + sizeof(reiserfs_acl_header); 144 e = (char *)ext_acl + sizeof(reiserfs_acl_header);
148 for (n=0; n < acl->a_count; n++) { 145 for (n = 0; n < acl->a_count; n++) {
149 reiserfs_acl_entry *entry = (reiserfs_acl_entry *)e; 146 reiserfs_acl_entry *entry = (reiserfs_acl_entry *) e;
150 entry->e_tag = cpu_to_le16(acl->a_entries[n].e_tag); 147 entry->e_tag = cpu_to_le16(acl->a_entries[n].e_tag);
151 entry->e_perm = cpu_to_le16(acl->a_entries[n].e_perm); 148 entry->e_perm = cpu_to_le16(acl->a_entries[n].e_perm);
152 switch(acl->a_entries[n].e_tag) { 149 switch (acl->a_entries[n].e_tag) {
153 case ACL_USER: 150 case ACL_USER:
154 case ACL_GROUP: 151 case ACL_GROUP:
155 entry->e_id = 152 entry->e_id = cpu_to_le32(acl->a_entries[n].e_id);
156 cpu_to_le32(acl->a_entries[n].e_id); 153 e += sizeof(reiserfs_acl_entry);
157 e += sizeof(reiserfs_acl_entry); 154 break;
158 break; 155
159 156 case ACL_USER_OBJ:
160 case ACL_USER_OBJ: 157 case ACL_GROUP_OBJ:
161 case ACL_GROUP_OBJ: 158 case ACL_MASK:
162 case ACL_MASK: 159 case ACL_OTHER:
163 case ACL_OTHER: 160 e += sizeof(reiserfs_acl_entry_short);
164 e += sizeof(reiserfs_acl_entry_short); 161 break;
165 break; 162
166 163 default:
167 default: 164 goto fail;
168 goto fail;
169 } 165 }
170 } 166 }
171 return (char *)ext_acl; 167 return (char *)ext_acl;
172 168
173fail: 169 fail:
174 kfree(ext_acl); 170 kfree(ext_acl);
175 return ERR_PTR(-EINVAL); 171 return ERR_PTR(-EINVAL);
176} 172}
@@ -181,59 +177,58 @@ fail:
181 * inode->i_sem: down 177 * inode->i_sem: down
182 * BKL held [before 2.5.x] 178 * BKL held [before 2.5.x]
183 */ 179 */
184struct posix_acl * 180struct posix_acl *reiserfs_get_acl(struct inode *inode, int type)
185reiserfs_get_acl(struct inode *inode, int type)
186{ 181{
187 char *name, *value; 182 char *name, *value;
188 struct posix_acl *acl, **p_acl; 183 struct posix_acl *acl, **p_acl;
189 size_t size; 184 size_t size;
190 int retval; 185 int retval;
191 struct reiserfs_inode_info *reiserfs_i = REISERFS_I(inode); 186 struct reiserfs_inode_info *reiserfs_i = REISERFS_I(inode);
192 187
193 switch (type) { 188 switch (type) {
194 case ACL_TYPE_ACCESS: 189 case ACL_TYPE_ACCESS:
195 name = POSIX_ACL_XATTR_ACCESS; 190 name = POSIX_ACL_XATTR_ACCESS;
196 p_acl = &reiserfs_i->i_acl_access; 191 p_acl = &reiserfs_i->i_acl_access;
197 break; 192 break;
198 case ACL_TYPE_DEFAULT: 193 case ACL_TYPE_DEFAULT:
199 name = POSIX_ACL_XATTR_DEFAULT; 194 name = POSIX_ACL_XATTR_DEFAULT;
200 p_acl = &reiserfs_i->i_acl_default; 195 p_acl = &reiserfs_i->i_acl_default;
201 break; 196 break;
202 default: 197 default:
203 return ERR_PTR (-EINVAL); 198 return ERR_PTR(-EINVAL);
204 } 199 }
205 200
206 if (IS_ERR (*p_acl)) { 201 if (IS_ERR(*p_acl)) {
207 if (PTR_ERR (*p_acl) == -ENODATA) 202 if (PTR_ERR(*p_acl) == -ENODATA)
208 return NULL; 203 return NULL;
209 } else if (*p_acl != NULL) 204 } else if (*p_acl != NULL)
210 return posix_acl_dup (*p_acl); 205 return posix_acl_dup(*p_acl);
211 206
212 size = reiserfs_xattr_get (inode, name, NULL, 0); 207 size = reiserfs_xattr_get(inode, name, NULL, 0);
213 if ((int)size < 0) { 208 if ((int)size < 0) {
214 if (size == -ENODATA || size == -ENOSYS) { 209 if (size == -ENODATA || size == -ENOSYS) {
215 *p_acl = ERR_PTR (-ENODATA); 210 *p_acl = ERR_PTR(-ENODATA);
216 return NULL; 211 return NULL;
217 } 212 }
218 return ERR_PTR (size); 213 return ERR_PTR(size);
219 } 214 }
220 215
221 value = kmalloc (size, GFP_NOFS); 216 value = kmalloc(size, GFP_NOFS);
222 if (!value) 217 if (!value)
223 return ERR_PTR (-ENOMEM); 218 return ERR_PTR(-ENOMEM);
224 219
225 retval = reiserfs_xattr_get(inode, name, value, size); 220 retval = reiserfs_xattr_get(inode, name, value, size);
226 if (retval == -ENODATA || retval == -ENOSYS) { 221 if (retval == -ENODATA || retval == -ENOSYS) {
227 /* This shouldn't actually happen as it should have 222 /* This shouldn't actually happen as it should have
228 been caught above.. but just in case */ 223 been caught above.. but just in case */
229 acl = NULL; 224 acl = NULL;
230 *p_acl = ERR_PTR (-ENODATA); 225 *p_acl = ERR_PTR(-ENODATA);
231 } else if (retval < 0) { 226 } else if (retval < 0) {
232 acl = ERR_PTR(retval); 227 acl = ERR_PTR(retval);
233 } else { 228 } else {
234 acl = posix_acl_from_disk(value, retval); 229 acl = posix_acl_from_disk(value, retval);
235 *p_acl = posix_acl_dup (acl); 230 *p_acl = posix_acl_dup(acl);
236 } 231 }
237 232
238 kfree(value); 233 kfree(value);
239 return acl; 234 return acl;
@@ -248,72 +243,72 @@ reiserfs_get_acl(struct inode *inode, int type)
248static int 243static int
249reiserfs_set_acl(struct inode *inode, int type, struct posix_acl *acl) 244reiserfs_set_acl(struct inode *inode, int type, struct posix_acl *acl)
250{ 245{
251 char *name; 246 char *name;
252 void *value = NULL; 247 void *value = NULL;
253 struct posix_acl **p_acl; 248 struct posix_acl **p_acl;
254 size_t size; 249 size_t size;
255 int error; 250 int error;
256 struct reiserfs_inode_info *reiserfs_i = REISERFS_I(inode); 251 struct reiserfs_inode_info *reiserfs_i = REISERFS_I(inode);
257 252
258 if (S_ISLNK(inode->i_mode)) 253 if (S_ISLNK(inode->i_mode))
259 return -EOPNOTSUPP; 254 return -EOPNOTSUPP;
260 255
261 switch (type) { 256 switch (type) {
262 case ACL_TYPE_ACCESS: 257 case ACL_TYPE_ACCESS:
263 name = POSIX_ACL_XATTR_ACCESS; 258 name = POSIX_ACL_XATTR_ACCESS;
264 p_acl = &reiserfs_i->i_acl_access; 259 p_acl = &reiserfs_i->i_acl_access;
265 if (acl) { 260 if (acl) {
266 mode_t mode = inode->i_mode; 261 mode_t mode = inode->i_mode;
267 error = posix_acl_equiv_mode (acl, &mode); 262 error = posix_acl_equiv_mode(acl, &mode);
268 if (error < 0) 263 if (error < 0)
269 return error; 264 return error;
270 else { 265 else {
271 inode->i_mode = mode; 266 inode->i_mode = mode;
272 if (error == 0) 267 if (error == 0)
273 acl = NULL; 268 acl = NULL;
274 } 269 }
275 } 270 }
276 break; 271 break;
277 case ACL_TYPE_DEFAULT: 272 case ACL_TYPE_DEFAULT:
278 name = POSIX_ACL_XATTR_DEFAULT; 273 name = POSIX_ACL_XATTR_DEFAULT;
279 p_acl = &reiserfs_i->i_acl_default; 274 p_acl = &reiserfs_i->i_acl_default;
280 if (!S_ISDIR (inode->i_mode)) 275 if (!S_ISDIR(inode->i_mode))
281 return acl ? -EACCES : 0; 276 return acl ? -EACCES : 0;
282 break; 277 break;
283 default: 278 default:
284 return -EINVAL; 279 return -EINVAL;
285 } 280 }
286 281
287 if (acl) { 282 if (acl) {
288 value = posix_acl_to_disk(acl, &size); 283 value = posix_acl_to_disk(acl, &size);
289 if (IS_ERR(value)) 284 if (IS_ERR(value))
290 return (int)PTR_ERR(value); 285 return (int)PTR_ERR(value);
291 error = reiserfs_xattr_set(inode, name, value, size, 0); 286 error = reiserfs_xattr_set(inode, name, value, size, 0);
292 } else { 287 } else {
293 error = reiserfs_xattr_del (inode, name); 288 error = reiserfs_xattr_del(inode, name);
294 if (error == -ENODATA) { 289 if (error == -ENODATA) {
295 /* This may seem odd here, but it means that the ACL was set 290 /* This may seem odd here, but it means that the ACL was set
296 * with a value representable with mode bits. If there was 291 * with a value representable with mode bits. If there was
297 * an ACL before, reiserfs_xattr_del already dirtied the inode. 292 * an ACL before, reiserfs_xattr_del already dirtied the inode.
298 */ 293 */
299 mark_inode_dirty (inode); 294 mark_inode_dirty(inode);
300 error = 0; 295 error = 0;
301 } 296 }
302 } 297 }
303 298
304 if (value) 299 if (value)
305 kfree(value); 300 kfree(value);
306 301
307 if (!error) { 302 if (!error) {
308 /* Release the old one */ 303 /* Release the old one */
309 if (!IS_ERR (*p_acl) && *p_acl) 304 if (!IS_ERR(*p_acl) && *p_acl)
310 posix_acl_release (*p_acl); 305 posix_acl_release(*p_acl);
311 306
312 if (acl == NULL) 307 if (acl == NULL)
313 *p_acl = ERR_PTR (-ENODATA); 308 *p_acl = ERR_PTR(-ENODATA);
314 else 309 else
315 *p_acl = posix_acl_dup (acl); 310 *p_acl = posix_acl_dup(acl);
316 } 311 }
317 312
318 return error; 313 return error;
319} 314}
@@ -321,192 +316,190 @@ reiserfs_set_acl(struct inode *inode, int type, struct posix_acl *acl)
321/* dir->i_sem: down, 316/* dir->i_sem: down,
322 * inode is new and not released into the wild yet */ 317 * inode is new and not released into the wild yet */
323int 318int
324reiserfs_inherit_default_acl (struct inode *dir, struct dentry *dentry, struct inode *inode) 319reiserfs_inherit_default_acl(struct inode *dir, struct dentry *dentry,
320 struct inode *inode)
325{ 321{
326 struct posix_acl *acl; 322 struct posix_acl *acl;
327 int err = 0; 323 int err = 0;
328 324
329 /* ACLs only get applied to files and directories */ 325 /* ACLs only get applied to files and directories */
330 if (S_ISLNK (inode->i_mode)) 326 if (S_ISLNK(inode->i_mode))
331 return 0; 327 return 0;
332 328
333 /* ACLs can only be used on "new" objects, so if it's an old object 329 /* ACLs can only be used on "new" objects, so if it's an old object
334 * there is nothing to inherit from */ 330 * there is nothing to inherit from */
335 if (get_inode_sd_version (dir) == STAT_DATA_V1) 331 if (get_inode_sd_version(dir) == STAT_DATA_V1)
336 goto apply_umask; 332 goto apply_umask;
337 333
338 /* Don't apply ACLs to objects in the .reiserfs_priv tree.. This 334 /* Don't apply ACLs to objects in the .reiserfs_priv tree.. This
339 * would be useless since permissions are ignored, and a pain because 335 * would be useless since permissions are ignored, and a pain because
340 * it introduces locking cycles */ 336 * it introduces locking cycles */
341 if (is_reiserfs_priv_object (dir)) { 337 if (is_reiserfs_priv_object(dir)) {
342 reiserfs_mark_inode_private (inode); 338 reiserfs_mark_inode_private(inode);
343 goto apply_umask; 339 goto apply_umask;
344 } 340 }
345 341
346 acl = reiserfs_get_acl (dir, ACL_TYPE_DEFAULT); 342 acl = reiserfs_get_acl(dir, ACL_TYPE_DEFAULT);
347 if (IS_ERR (acl)) { 343 if (IS_ERR(acl)) {
348 if (PTR_ERR (acl) == -ENODATA) 344 if (PTR_ERR(acl) == -ENODATA)
349 goto apply_umask; 345 goto apply_umask;
350 return PTR_ERR (acl); 346 return PTR_ERR(acl);
351 } 347 }
352 348
353 if (acl) { 349 if (acl) {
354 struct posix_acl *acl_copy; 350 struct posix_acl *acl_copy;
355 mode_t mode = inode->i_mode; 351 mode_t mode = inode->i_mode;
356 int need_acl; 352 int need_acl;
357 353
358 /* Copy the default ACL to the default ACL of a new directory */ 354 /* Copy the default ACL to the default ACL of a new directory */
359 if (S_ISDIR (inode->i_mode)) { 355 if (S_ISDIR(inode->i_mode)) {
360 err = reiserfs_set_acl (inode, ACL_TYPE_DEFAULT, acl); 356 err = reiserfs_set_acl(inode, ACL_TYPE_DEFAULT, acl);
361 if (err) 357 if (err)
362 goto cleanup; 358 goto cleanup;
363 } 359 }
364 360
365 /* Now we reconcile the new ACL and the mode, 361 /* Now we reconcile the new ACL and the mode,
366 potentially modifying both */ 362 potentially modifying both */
367 acl_copy = posix_acl_clone (acl, GFP_NOFS); 363 acl_copy = posix_acl_clone(acl, GFP_NOFS);
368 if (!acl_copy) { 364 if (!acl_copy) {
369 err = -ENOMEM; 365 err = -ENOMEM;
370 goto cleanup; 366 goto cleanup;
371 } 367 }
372 368
373 369 need_acl = posix_acl_create_masq(acl_copy, &mode);
374 need_acl = posix_acl_create_masq (acl_copy, &mode); 370 if (need_acl >= 0) {
375 if (need_acl >= 0) { 371 if (mode != inode->i_mode) {
376 if (mode != inode->i_mode) { 372 inode->i_mode = mode;
377 inode->i_mode = mode; 373 }
378 } 374
379 375 /* If we need an ACL.. */
380 /* If we need an ACL.. */ 376 if (need_acl > 0) {
381 if (need_acl > 0) { 377 err =
382 err = reiserfs_set_acl (inode, ACL_TYPE_ACCESS, acl_copy); 378 reiserfs_set_acl(inode, ACL_TYPE_ACCESS,
383 if (err) 379 acl_copy);
384 goto cleanup_copy; 380 if (err)
385 } 381 goto cleanup_copy;
386 } 382 }
387cleanup_copy: 383 }
388 posix_acl_release (acl_copy); 384 cleanup_copy:
389cleanup: 385 posix_acl_release(acl_copy);
390 posix_acl_release (acl); 386 cleanup:
391 } else { 387 posix_acl_release(acl);
392apply_umask: 388 } else {
393 /* no ACL, apply umask */ 389 apply_umask:
394 inode->i_mode &= ~current->fs->umask; 390 /* no ACL, apply umask */
395 } 391 inode->i_mode &= ~current->fs->umask;
396 392 }
397 return err; 393
394 return err;
398} 395}
399 396
400/* Looks up and caches the result of the default ACL. 397/* Looks up and caches the result of the default ACL.
401 * We do this so that we don't need to carry the xattr_sem into 398 * We do this so that we don't need to carry the xattr_sem into
402 * reiserfs_new_inode if we don't need to */ 399 * reiserfs_new_inode if we don't need to */
403int 400int reiserfs_cache_default_acl(struct inode *inode)
404reiserfs_cache_default_acl (struct inode *inode)
405{ 401{
406 int ret = 0; 402 int ret = 0;
407 if (reiserfs_posixacl (inode->i_sb) && 403 if (reiserfs_posixacl(inode->i_sb) && !is_reiserfs_priv_object(inode)) {
408 !is_reiserfs_priv_object (inode)) { 404 struct posix_acl *acl;
409 struct posix_acl *acl; 405 reiserfs_read_lock_xattr_i(inode);
410 reiserfs_read_lock_xattr_i (inode); 406 reiserfs_read_lock_xattrs(inode->i_sb);
411 reiserfs_read_lock_xattrs (inode->i_sb); 407 acl = reiserfs_get_acl(inode, ACL_TYPE_DEFAULT);
412 acl = reiserfs_get_acl (inode, ACL_TYPE_DEFAULT); 408 reiserfs_read_unlock_xattrs(inode->i_sb);
413 reiserfs_read_unlock_xattrs (inode->i_sb); 409 reiserfs_read_unlock_xattr_i(inode);
414 reiserfs_read_unlock_xattr_i (inode); 410 ret = acl ? 1 : 0;
415 ret = acl ? 1 : 0; 411 posix_acl_release(acl);
416 posix_acl_release (acl); 412 }
417 } 413
418 414 return ret;
419 return ret;
420} 415}
421 416
422int 417int reiserfs_acl_chmod(struct inode *inode)
423reiserfs_acl_chmod (struct inode *inode)
424{ 418{
425 struct posix_acl *acl, *clone; 419 struct posix_acl *acl, *clone;
426 int error; 420 int error;
427 421
428 if (S_ISLNK(inode->i_mode)) 422 if (S_ISLNK(inode->i_mode))
429 return -EOPNOTSUPP; 423 return -EOPNOTSUPP;
430 424
431 if (get_inode_sd_version (inode) == STAT_DATA_V1 || 425 if (get_inode_sd_version(inode) == STAT_DATA_V1 ||
432 !reiserfs_posixacl(inode->i_sb)) 426 !reiserfs_posixacl(inode->i_sb)) {
433 { 427 return 0;
434 return 0;
435 } 428 }
436 429
437 reiserfs_read_lock_xattrs (inode->i_sb); 430 reiserfs_read_lock_xattrs(inode->i_sb);
438 acl = reiserfs_get_acl(inode, ACL_TYPE_ACCESS); 431 acl = reiserfs_get_acl(inode, ACL_TYPE_ACCESS);
439 reiserfs_read_unlock_xattrs (inode->i_sb); 432 reiserfs_read_unlock_xattrs(inode->i_sb);
440 if (!acl) 433 if (!acl)
441 return 0; 434 return 0;
442 if (IS_ERR(acl)) 435 if (IS_ERR(acl))
443 return PTR_ERR(acl); 436 return PTR_ERR(acl);
444 clone = posix_acl_clone(acl, GFP_NOFS); 437 clone = posix_acl_clone(acl, GFP_NOFS);
445 posix_acl_release(acl); 438 posix_acl_release(acl);
446 if (!clone) 439 if (!clone)
447 return -ENOMEM; 440 return -ENOMEM;
448 error = posix_acl_chmod_masq(clone, inode->i_mode); 441 error = posix_acl_chmod_masq(clone, inode->i_mode);
449 if (!error) { 442 if (!error) {
450 int lock = !has_xattr_dir (inode); 443 int lock = !has_xattr_dir(inode);
451 reiserfs_write_lock_xattr_i (inode); 444 reiserfs_write_lock_xattr_i(inode);
452 if (lock) 445 if (lock)
453 reiserfs_write_lock_xattrs (inode->i_sb); 446 reiserfs_write_lock_xattrs(inode->i_sb);
454 else 447 else
455 reiserfs_read_lock_xattrs (inode->i_sb); 448 reiserfs_read_lock_xattrs(inode->i_sb);
456 error = reiserfs_set_acl(inode, ACL_TYPE_ACCESS, clone); 449 error = reiserfs_set_acl(inode, ACL_TYPE_ACCESS, clone);
457 if (lock) 450 if (lock)
458 reiserfs_write_unlock_xattrs (inode->i_sb); 451 reiserfs_write_unlock_xattrs(inode->i_sb);
459 else 452 else
460 reiserfs_read_unlock_xattrs (inode->i_sb); 453 reiserfs_read_unlock_xattrs(inode->i_sb);
461 reiserfs_write_unlock_xattr_i (inode); 454 reiserfs_write_unlock_xattr_i(inode);
462 } 455 }
463 posix_acl_release(clone); 456 posix_acl_release(clone);
464 return error; 457 return error;
465} 458}
466 459
467static int 460static int
468posix_acl_access_get(struct inode *inode, const char *name, 461posix_acl_access_get(struct inode *inode, const char *name,
469 void *buffer, size_t size) 462 void *buffer, size_t size)
470{ 463{
471 if (strlen(name) != sizeof(POSIX_ACL_XATTR_ACCESS)-1) 464 if (strlen(name) != sizeof(POSIX_ACL_XATTR_ACCESS) - 1)
472 return -EINVAL; 465 return -EINVAL;
473 return xattr_get_acl(inode, ACL_TYPE_ACCESS, buffer, size); 466 return xattr_get_acl(inode, ACL_TYPE_ACCESS, buffer, size);
474} 467}
475 468
476static int 469static int
477posix_acl_access_set(struct inode *inode, const char *name, 470posix_acl_access_set(struct inode *inode, const char *name,
478 const void *value, size_t size, int flags) 471 const void *value, size_t size, int flags)
479{ 472{
480 if (strlen(name) != sizeof(POSIX_ACL_XATTR_ACCESS)-1) 473 if (strlen(name) != sizeof(POSIX_ACL_XATTR_ACCESS) - 1)
481 return -EINVAL; 474 return -EINVAL;
482 return xattr_set_acl(inode, ACL_TYPE_ACCESS, value, size); 475 return xattr_set_acl(inode, ACL_TYPE_ACCESS, value, size);
483} 476}
484 477
485static int 478static int posix_acl_access_del(struct inode *inode, const char *name)
486posix_acl_access_del (struct inode *inode, const char *name)
487{ 479{
488 struct reiserfs_inode_info *reiserfs_i = REISERFS_I(inode); 480 struct reiserfs_inode_info *reiserfs_i = REISERFS_I(inode);
489 struct posix_acl **acl = &reiserfs_i->i_acl_access; 481 struct posix_acl **acl = &reiserfs_i->i_acl_access;
490 if (strlen(name) != sizeof(POSIX_ACL_XATTR_ACCESS)-1) 482 if (strlen(name) != sizeof(POSIX_ACL_XATTR_ACCESS) - 1)
491 return -EINVAL; 483 return -EINVAL;
492 if (!IS_ERR (*acl) && *acl) { 484 if (!IS_ERR(*acl) && *acl) {
493 posix_acl_release (*acl); 485 posix_acl_release(*acl);
494 *acl = ERR_PTR (-ENODATA); 486 *acl = ERR_PTR(-ENODATA);
495 } 487 }
496 488
497 return 0; 489 return 0;
498} 490}
499 491
500static int 492static int
501posix_acl_access_list (struct inode *inode, const char *name, int namelen, char *out) 493posix_acl_access_list(struct inode *inode, const char *name, int namelen,
494 char *out)
502{ 495{
503 int len = namelen; 496 int len = namelen;
504 if (!reiserfs_posixacl (inode->i_sb)) 497 if (!reiserfs_posixacl(inode->i_sb))
505 return 0; 498 return 0;
506 if (out) 499 if (out)
507 memcpy (out, name, len); 500 memcpy(out, name, len);
508 501
509 return len; 502 return len;
510} 503}
511 504
512struct reiserfs_xattr_handler posix_acl_access_handler = { 505struct reiserfs_xattr_handler posix_acl_access_handler = {
@@ -518,48 +511,48 @@ struct reiserfs_xattr_handler posix_acl_access_handler = {
518}; 511};
519 512
520static int 513static int
521posix_acl_default_get (struct inode *inode, const char *name, 514posix_acl_default_get(struct inode *inode, const char *name,
522 void *buffer, size_t size) 515 void *buffer, size_t size)
523{ 516{
524 if (strlen(name) != sizeof(POSIX_ACL_XATTR_DEFAULT)-1) 517 if (strlen(name) != sizeof(POSIX_ACL_XATTR_DEFAULT) - 1)
525 return -EINVAL; 518 return -EINVAL;
526 return xattr_get_acl(inode, ACL_TYPE_DEFAULT, buffer, size); 519 return xattr_get_acl(inode, ACL_TYPE_DEFAULT, buffer, size);
527} 520}
528 521
529static int 522static int
530posix_acl_default_set(struct inode *inode, const char *name, 523posix_acl_default_set(struct inode *inode, const char *name,
531 const void *value, size_t size, int flags) 524 const void *value, size_t size, int flags)
532{ 525{
533 if (strlen(name) != sizeof(POSIX_ACL_XATTR_DEFAULT)-1) 526 if (strlen(name) != sizeof(POSIX_ACL_XATTR_DEFAULT) - 1)
534 return -EINVAL; 527 return -EINVAL;
535 return xattr_set_acl(inode, ACL_TYPE_DEFAULT, value, size); 528 return xattr_set_acl(inode, ACL_TYPE_DEFAULT, value, size);
536} 529}
537 530
538static int 531static int posix_acl_default_del(struct inode *inode, const char *name)
539posix_acl_default_del (struct inode *inode, const char *name)
540{ 532{
541 struct reiserfs_inode_info *reiserfs_i = REISERFS_I(inode); 533 struct reiserfs_inode_info *reiserfs_i = REISERFS_I(inode);
542 struct posix_acl **acl = &reiserfs_i->i_acl_default; 534 struct posix_acl **acl = &reiserfs_i->i_acl_default;
543 if (strlen(name) != sizeof(POSIX_ACL_XATTR_DEFAULT)-1) 535 if (strlen(name) != sizeof(POSIX_ACL_XATTR_DEFAULT) - 1)
544 return -EINVAL; 536 return -EINVAL;
545 if (!IS_ERR (*acl) && *acl) { 537 if (!IS_ERR(*acl) && *acl) {
546 posix_acl_release (*acl); 538 posix_acl_release(*acl);
547 *acl = ERR_PTR (-ENODATA); 539 *acl = ERR_PTR(-ENODATA);
548 } 540 }
549 541
550 return 0; 542 return 0;
551} 543}
552 544
553static int 545static int
554posix_acl_default_list (struct inode *inode, const char *name, int namelen, char *out) 546posix_acl_default_list(struct inode *inode, const char *name, int namelen,
547 char *out)
555{ 548{
556 int len = namelen; 549 int len = namelen;
557 if (!reiserfs_posixacl (inode->i_sb)) 550 if (!reiserfs_posixacl(inode->i_sb))
558 return 0; 551 return 0;
559 if (out) 552 if (out)
560 memcpy (out, name, len); 553 memcpy(out, name, len);
561 554
562 return len; 555 return len;
563} 556}
564 557
565struct reiserfs_xattr_handler posix_acl_default_handler = { 558struct reiserfs_xattr_handler posix_acl_default_handler = {
diff --git a/fs/reiserfs/xattr_security.c b/fs/reiserfs/xattr_security.c
index e044d5117117..5e90a95ad60b 100644
--- a/fs/reiserfs/xattr_security.c
+++ b/fs/reiserfs/xattr_security.c
@@ -9,57 +9,55 @@
9#define XATTR_SECURITY_PREFIX "security." 9#define XATTR_SECURITY_PREFIX "security."
10 10
11static int 11static int
12security_get (struct inode *inode, const char *name, void *buffer, size_t size) 12security_get(struct inode *inode, const char *name, void *buffer, size_t size)
13{ 13{
14 if (strlen(name) < sizeof(XATTR_SECURITY_PREFIX)) 14 if (strlen(name) < sizeof(XATTR_SECURITY_PREFIX))
15 return -EINVAL; 15 return -EINVAL;
16 16
17 if (is_reiserfs_priv_object(inode)) 17 if (is_reiserfs_priv_object(inode))
18 return -EPERM; 18 return -EPERM;
19 19
20 return reiserfs_xattr_get (inode, name, buffer, size); 20 return reiserfs_xattr_get(inode, name, buffer, size);
21} 21}
22 22
23static int 23static int
24security_set (struct inode *inode, const char *name, const void *buffer, 24security_set(struct inode *inode, const char *name, const void *buffer,
25 size_t size, int flags) 25 size_t size, int flags)
26{ 26{
27 if (strlen(name) < sizeof(XATTR_SECURITY_PREFIX)) 27 if (strlen(name) < sizeof(XATTR_SECURITY_PREFIX))
28 return -EINVAL; 28 return -EINVAL;
29 29
30 if (is_reiserfs_priv_object(inode)) 30 if (is_reiserfs_priv_object(inode))
31 return -EPERM; 31 return -EPERM;
32 32
33 return reiserfs_xattr_set (inode, name, buffer, size, flags); 33 return reiserfs_xattr_set(inode, name, buffer, size, flags);
34} 34}
35 35
36static int 36static int security_del(struct inode *inode, const char *name)
37security_del (struct inode *inode, const char *name)
38{ 37{
39 if (strlen(name) < sizeof(XATTR_SECURITY_PREFIX)) 38 if (strlen(name) < sizeof(XATTR_SECURITY_PREFIX))
40 return -EINVAL; 39 return -EINVAL;
41 40
42 if (is_reiserfs_priv_object(inode)) 41 if (is_reiserfs_priv_object(inode))
43 return -EPERM; 42 return -EPERM;
44 43
45 return 0; 44 return 0;
46} 45}
47 46
48static int 47static int
49security_list (struct inode *inode, const char *name, int namelen, char *out) 48security_list(struct inode *inode, const char *name, int namelen, char *out)
50{ 49{
51 int len = namelen; 50 int len = namelen;
52 51
53 if (is_reiserfs_priv_object(inode)) 52 if (is_reiserfs_priv_object(inode))
54 return 0; 53 return 0;
55 54
56 if (out) 55 if (out)
57 memcpy (out, name, len); 56 memcpy(out, name, len);
58 57
59 return len; 58 return len;
60} 59}
61 60
62
63struct reiserfs_xattr_handler security_handler = { 61struct reiserfs_xattr_handler security_handler = {
64 .prefix = XATTR_SECURITY_PREFIX, 62 .prefix = XATTR_SECURITY_PREFIX,
65 .get = security_get, 63 .get = security_get,
diff --git a/fs/reiserfs/xattr_trusted.c b/fs/reiserfs/xattr_trusted.c
index 43762197fb0a..2501f7e66ab9 100644
--- a/fs/reiserfs/xattr_trusted.c
+++ b/fs/reiserfs/xattr_trusted.c
@@ -9,69 +9,67 @@
9#define XATTR_TRUSTED_PREFIX "trusted." 9#define XATTR_TRUSTED_PREFIX "trusted."
10 10
11static int 11static int
12trusted_get (struct inode *inode, const char *name, void *buffer, size_t size) 12trusted_get(struct inode *inode, const char *name, void *buffer, size_t size)
13{ 13{
14 if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX)) 14 if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
15 return -EINVAL; 15 return -EINVAL;
16 16
17 if (!reiserfs_xattrs (inode->i_sb)) 17 if (!reiserfs_xattrs(inode->i_sb))
18 return -EOPNOTSUPP; 18 return -EOPNOTSUPP;
19 19
20 if (!(capable(CAP_SYS_ADMIN) || is_reiserfs_priv_object(inode))) 20 if (!(capable(CAP_SYS_ADMIN) || is_reiserfs_priv_object(inode)))
21 return -EPERM; 21 return -EPERM;
22 22
23 return reiserfs_xattr_get (inode, name, buffer, size); 23 return reiserfs_xattr_get(inode, name, buffer, size);
24} 24}
25 25
26static int 26static int
27trusted_set (struct inode *inode, const char *name, const void *buffer, 27trusted_set(struct inode *inode, const char *name, const void *buffer,
28 size_t size, int flags) 28 size_t size, int flags)
29{ 29{
30 if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX)) 30 if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
31 return -EINVAL; 31 return -EINVAL;
32 32
33 if (!reiserfs_xattrs (inode->i_sb)) 33 if (!reiserfs_xattrs(inode->i_sb))
34 return -EOPNOTSUPP; 34 return -EOPNOTSUPP;
35 35
36 if (!(capable(CAP_SYS_ADMIN) || is_reiserfs_priv_object(inode))) 36 if (!(capable(CAP_SYS_ADMIN) || is_reiserfs_priv_object(inode)))
37 return -EPERM; 37 return -EPERM;
38 38
39 return reiserfs_xattr_set (inode, name, buffer, size, flags); 39 return reiserfs_xattr_set(inode, name, buffer, size, flags);
40} 40}
41 41
42static int 42static int trusted_del(struct inode *inode, const char *name)
43trusted_del (struct inode *inode, const char *name)
44{ 43{
45 if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX)) 44 if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
46 return -EINVAL; 45 return -EINVAL;
47 46
48 if (!reiserfs_xattrs (inode->i_sb)) 47 if (!reiserfs_xattrs(inode->i_sb))
49 return -EOPNOTSUPP; 48 return -EOPNOTSUPP;
50 49
51 if (!(capable(CAP_SYS_ADMIN) || is_reiserfs_priv_object(inode))) 50 if (!(capable(CAP_SYS_ADMIN) || is_reiserfs_priv_object(inode)))
52 return -EPERM; 51 return -EPERM;
53 52
54 return 0; 53 return 0;
55} 54}
56 55
57static int 56static int
58trusted_list (struct inode *inode, const char *name, int namelen, char *out) 57trusted_list(struct inode *inode, const char *name, int namelen, char *out)
59{ 58{
60 int len = namelen; 59 int len = namelen;
61 60
62 if (!reiserfs_xattrs (inode->i_sb)) 61 if (!reiserfs_xattrs(inode->i_sb))
63 return 0; 62 return 0;
64 63
65 if (!(capable(CAP_SYS_ADMIN) || is_reiserfs_priv_object(inode))) 64 if (!(capable(CAP_SYS_ADMIN) || is_reiserfs_priv_object(inode)))
66 return 0; 65 return 0;
67 66
68 if (out) 67 if (out)
69 memcpy (out, name, len); 68 memcpy(out, name, len);
70 69
71 return len; 70 return len;
72} 71}
73 72
74
75struct reiserfs_xattr_handler trusted_handler = { 73struct reiserfs_xattr_handler trusted_handler = {
76 .prefix = XATTR_TRUSTED_PREFIX, 74 .prefix = XATTR_TRUSTED_PREFIX,
77 .get = trusted_get, 75 .get = trusted_get,
diff --git a/fs/reiserfs/xattr_user.c b/fs/reiserfs/xattr_user.c
index 0772806466a8..51458048ca66 100644
--- a/fs/reiserfs/xattr_user.c
+++ b/fs/reiserfs/xattr_user.c
@@ -13,81 +13,80 @@
13#define XATTR_USER_PREFIX "user." 13#define XATTR_USER_PREFIX "user."
14 14
15static int 15static int
16user_get (struct inode *inode, const char *name, void *buffer, size_t size) 16user_get(struct inode *inode, const char *name, void *buffer, size_t size)
17{ 17{
18 18
19 int error; 19 int error;
20 20
21 if (strlen(name) < sizeof(XATTR_USER_PREFIX)) 21 if (strlen(name) < sizeof(XATTR_USER_PREFIX))
22 return -EINVAL; 22 return -EINVAL;
23 23
24 if (!reiserfs_xattrs_user (inode->i_sb)) 24 if (!reiserfs_xattrs_user(inode->i_sb))
25 return -EOPNOTSUPP; 25 return -EOPNOTSUPP;
26 26
27 error = reiserfs_permission_locked (inode, MAY_READ, NULL); 27 error = reiserfs_permission_locked(inode, MAY_READ, NULL);
28 if (error) 28 if (error)
29 return error; 29 return error;
30 30
31 return reiserfs_xattr_get (inode, name, buffer, size); 31 return reiserfs_xattr_get(inode, name, buffer, size);
32} 32}
33 33
34static int 34static int
35user_set (struct inode *inode, const char *name, const void *buffer, 35user_set(struct inode *inode, const char *name, const void *buffer,
36 size_t size, int flags) 36 size_t size, int flags)
37{ 37{
38 38
39 int error; 39 int error;
40 40
41 if (strlen(name) < sizeof(XATTR_USER_PREFIX)) 41 if (strlen(name) < sizeof(XATTR_USER_PREFIX))
42 return -EINVAL; 42 return -EINVAL;
43 43
44 if (!reiserfs_xattrs_user (inode->i_sb)) 44 if (!reiserfs_xattrs_user(inode->i_sb))
45 return -EOPNOTSUPP; 45 return -EOPNOTSUPP;
46 46
47 if (!S_ISREG (inode->i_mode) && 47 if (!S_ISREG(inode->i_mode) &&
48 (!S_ISDIR (inode->i_mode) || inode->i_mode & S_ISVTX)) 48 (!S_ISDIR(inode->i_mode) || inode->i_mode & S_ISVTX))
49 return -EPERM; 49 return -EPERM;
50 50
51 error = reiserfs_permission_locked (inode, MAY_WRITE, NULL); 51 error = reiserfs_permission_locked(inode, MAY_WRITE, NULL);
52 if (error) 52 if (error)
53 return error; 53 return error;
54 54
55 return reiserfs_xattr_set (inode, name, buffer, size, flags); 55 return reiserfs_xattr_set(inode, name, buffer, size, flags);
56} 56}
57 57
58static int 58static int user_del(struct inode *inode, const char *name)
59user_del (struct inode *inode, const char *name)
60{ 59{
61 int error; 60 int error;
62 61
63 if (strlen(name) < sizeof(XATTR_USER_PREFIX)) 62 if (strlen(name) < sizeof(XATTR_USER_PREFIX))
64 return -EINVAL; 63 return -EINVAL;
65 64
66 if (!reiserfs_xattrs_user (inode->i_sb)) 65 if (!reiserfs_xattrs_user(inode->i_sb))
67 return -EOPNOTSUPP; 66 return -EOPNOTSUPP;
68 67
69 if (!S_ISREG (inode->i_mode) && 68 if (!S_ISREG(inode->i_mode) &&
70 (!S_ISDIR (inode->i_mode) || inode->i_mode & S_ISVTX)) 69 (!S_ISDIR(inode->i_mode) || inode->i_mode & S_ISVTX))
71 return -EPERM; 70 return -EPERM;
72 71
73 error = reiserfs_permission_locked (inode, MAY_WRITE, NULL); 72 error = reiserfs_permission_locked(inode, MAY_WRITE, NULL);
74 if (error) 73 if (error)
75 return error; 74 return error;
76 75
77 return 0; 76 return 0;
78} 77}
79 78
80static int 79static int
81user_list (struct inode *inode, const char *name, int namelen, char *out) 80user_list(struct inode *inode, const char *name, int namelen, char *out)
82{ 81{
83 int len = namelen; 82 int len = namelen;
84 if (!reiserfs_xattrs_user (inode->i_sb)) 83 if (!reiserfs_xattrs_user(inode->i_sb))
85 return 0; 84 return 0;
86 85
87 if (out) 86 if (out)
88 memcpy (out, name, len); 87 memcpy(out, name, len);
89 88
90 return len; 89 return len;
91} 90}
92 91
93struct reiserfs_xattr_handler user_handler = { 92struct reiserfs_xattr_handler user_handler = {
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index d72c1ce48559..335288b9be0f 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -3,7 +3,7 @@
3 */ 3 */
4 4
5#include <linux/module.h> 5#include <linux/module.h>
6#include <linux/dnotify.h> 6#include <linux/fsnotify.h>
7#include <linux/kobject.h> 7#include <linux/kobject.h>
8#include <linux/namei.h> 8#include <linux/namei.h>
9#include <asm/uaccess.h> 9#include <asm/uaccess.h>
@@ -391,9 +391,6 @@ int sysfs_create_file(struct kobject * kobj, const struct attribute * attr)
391 * sysfs_update_file - update the modified timestamp on an object attribute. 391 * sysfs_update_file - update the modified timestamp on an object attribute.
392 * @kobj: object we're acting for. 392 * @kobj: object we're acting for.
393 * @attr: attribute descriptor. 393 * @attr: attribute descriptor.
394 *
395 * Also call dnotify for the dentry, which lots of userspace programs
396 * use.
397 */ 394 */
398int sysfs_update_file(struct kobject * kobj, const struct attribute * attr) 395int sysfs_update_file(struct kobject * kobj, const struct attribute * attr)
399{ 396{
@@ -408,7 +405,7 @@ int sysfs_update_file(struct kobject * kobj, const struct attribute * attr)
408 if (victim->d_inode && 405 if (victim->d_inode &&
409 (victim->d_parent->d_inode == dir->d_inode)) { 406 (victim->d_parent->d_inode == dir->d_inode)) {
410 victim->d_inode->i_mtime = CURRENT_TIME; 407 victim->d_inode->i_mtime = CURRENT_TIME;
411 dnotify_parent(victim, DN_MODIFY); 408 fsnotify_modify(victim);
412 409
413 /** 410 /**
414 * Drop reference from initial sysfs_get_dentry(). 411 * Drop reference from initial sysfs_get_dentry().
diff --git a/fs/xattr.c b/fs/xattr.c
index 93dee70a1dbe..6acd5c63da91 100644
--- a/fs/xattr.c
+++ b/fs/xattr.c
@@ -16,6 +16,7 @@
16#include <linux/security.h> 16#include <linux/security.h>
17#include <linux/syscalls.h> 17#include <linux/syscalls.h>
18#include <linux/module.h> 18#include <linux/module.h>
19#include <linux/fsnotify.h>
19#include <asm/uaccess.h> 20#include <asm/uaccess.h>
20 21
21/* 22/*
@@ -57,8 +58,10 @@ setxattr(struct dentry *d, char __user *name, void __user *value,
57 if (error) 58 if (error)
58 goto out; 59 goto out;
59 error = d->d_inode->i_op->setxattr(d, kname, kvalue, size, flags); 60 error = d->d_inode->i_op->setxattr(d, kname, kvalue, size, flags);
60 if (!error) 61 if (!error) {
62 fsnotify_xattr(d);
61 security_inode_post_setxattr(d, kname, kvalue, size, flags); 63 security_inode_post_setxattr(d, kname, kvalue, size, flags);
64 }
62out: 65out:
63 up(&d->d_inode->i_sem); 66 up(&d->d_inode->i_sem);
64 } 67 }
diff --git a/include/acpi/acconfig.h b/include/acpi/acconfig.h
index 2b41e47b7d80..2f6ab189fc6f 100644
--- a/include/acpi/acconfig.h
+++ b/include/acpi/acconfig.h
@@ -64,7 +64,7 @@
64 64
65/* Version string */ 65/* Version string */
66 66
67#define ACPI_CA_VERSION 0x20050309 67#define ACPI_CA_VERSION 0x20050408
68 68
69/* 69/*
70 * OS name, used for the _OS object. The _OS object is essentially obsolete, 70 * OS name, used for the _OS object. The _OS object is essentially obsolete,
@@ -130,9 +130,8 @@
130#define ACPI_MAX_GPE_BLOCKS 2 130#define ACPI_MAX_GPE_BLOCKS 2
131#define ACPI_GPE_REGISTER_WIDTH 8 131#define ACPI_GPE_REGISTER_WIDTH 8
132 132
133/* 133/* Method info (in WALK_STATE), containing local variables and argumetns */
134 * Method info (in WALK_STATE), containing local variables and argumetns 134
135 */
136#define ACPI_METHOD_NUM_LOCALS 8 135#define ACPI_METHOD_NUM_LOCALS 8
137#define ACPI_METHOD_MAX_LOCAL 7 136#define ACPI_METHOD_MAX_LOCAL 7
138 137
diff --git a/include/acpi/acdebug.h b/include/acpi/acdebug.h
index 223b2a506e49..8ba372b0f245 100644
--- a/include/acpi/acdebug.h
+++ b/include/acpi/acdebug.h
@@ -61,9 +61,7 @@ struct argument_info
61 61
62 62
63#define PARAM_LIST(pl) pl 63#define PARAM_LIST(pl) pl
64
65#define DBTEST_OUTPUT_LEVEL(lvl) if (acpi_gbl_db_opt_verbose) 64#define DBTEST_OUTPUT_LEVEL(lvl) if (acpi_gbl_db_opt_verbose)
66
67#define VERBOSE_PRINT(fp) DBTEST_OUTPUT_LEVEL(lvl) {\ 65#define VERBOSE_PRINT(fp) DBTEST_OUTPUT_LEVEL(lvl) {\
68 acpi_os_printf PARAM_LIST(fp);} 66 acpi_os_printf PARAM_LIST(fp);}
69 67
@@ -71,13 +69,9 @@ struct argument_info
71#define EX_SINGLE_STEP 2 69#define EX_SINGLE_STEP 2
72 70
73 71
74/* Prototypes */
75
76
77/* 72/*
78 * dbxface - external debugger interfaces 73 * dbxface - external debugger interfaces
79 */ 74 */
80
81acpi_status 75acpi_status
82acpi_db_initialize ( 76acpi_db_initialize (
83 void); 77 void);
@@ -92,20 +86,10 @@ acpi_db_single_step (
92 union acpi_parse_object *op, 86 union acpi_parse_object *op,
93 u32 op_type); 87 u32 op_type);
94 88
95acpi_status
96acpi_db_start_command (
97 struct acpi_walk_state *walk_state,
98 union acpi_parse_object *op);
99
100void
101acpi_db_method_end (
102 struct acpi_walk_state *walk_state);
103
104 89
105/* 90/*
106 * dbcmds - debug commands and output routines 91 * dbcmds - debug commands and output routines
107 */ 92 */
108
109acpi_status 93acpi_status
110acpi_db_disassemble_method ( 94acpi_db_disassemble_method (
111 char *name); 95 char *name);
@@ -177,57 +161,30 @@ acpi_db_find_references (
177 char *object_arg); 161 char *object_arg);
178 162
179void 163void
180acpi_db_display_locks (void); 164acpi_db_display_locks (
181 165 void);
182 166
183void 167void
184acpi_db_display_resources ( 168acpi_db_display_resources (
185 char *object_arg); 169 char *object_arg);
186 170
187void 171void
188acpi_db_display_gpes (void); 172acpi_db_display_gpes (
173 void);
189 174
190void 175void
191acpi_db_check_integrity ( 176acpi_db_check_integrity (
192 void); 177 void);
193 178
194acpi_status
195acpi_db_integrity_walk (
196 acpi_handle obj_handle,
197 u32 nesting_level,
198 void *context,
199 void **return_value);
200
201acpi_status
202acpi_db_walk_and_match_name (
203 acpi_handle obj_handle,
204 u32 nesting_level,
205 void *context,
206 void **return_value);
207
208acpi_status
209acpi_db_walk_for_references (
210 acpi_handle obj_handle,
211 u32 nesting_level,
212 void *context,
213 void **return_value);
214
215acpi_status
216acpi_db_walk_for_specific_objects (
217 acpi_handle obj_handle,
218 u32 nesting_level,
219 void *context,
220 void **return_value);
221
222void 179void
223acpi_db_generate_gpe ( 180acpi_db_generate_gpe (
224 char *gpe_arg, 181 char *gpe_arg,
225 char *block_arg); 182 char *block_arg);
226 183
184
227/* 185/*
228 * dbdisply - debug display commands 186 * dbdisply - debug display commands
229 */ 187 */
230
231void 188void
232acpi_db_display_method_info ( 189acpi_db_display_method_info (
233 union acpi_parse_object *op); 190 union acpi_parse_object *op);
@@ -271,19 +228,10 @@ acpi_db_display_argument_object (
271 union acpi_operand_object *obj_desc, 228 union acpi_operand_object *obj_desc,
272 struct acpi_walk_state *walk_state); 229 struct acpi_walk_state *walk_state);
273 230
274void
275acpi_db_dump_parser_descriptor (
276 union acpi_parse_object *op);
277
278void *
279acpi_db_get_pointer (
280 void *target);
281
282 231
283/* 232/*
284 * dbexec - debugger control method execution 233 * dbexec - debugger control method execution
285 */ 234 */
286
287void 235void
288acpi_db_execute ( 236acpi_db_execute (
289 char *name, 237 char *name,
@@ -296,44 +244,15 @@ acpi_db_create_execution_threads (
296 char *num_loops_arg, 244 char *num_loops_arg,
297 char *method_name_arg); 245 char *method_name_arg);
298 246
299acpi_status
300acpi_db_execute_method (
301 struct acpi_db_method_info *info,
302 struct acpi_buffer *return_obj);
303
304void
305acpi_db_execute_setup (
306 struct acpi_db_method_info *info);
307
308u32
309acpi_db_get_outstanding_allocations (
310 void);
311
312void ACPI_SYSTEM_XFACE
313acpi_db_method_thread (
314 void *context);
315
316acpi_status
317acpi_db_execution_walk (
318 acpi_handle obj_handle,
319 u32 nesting_level,
320 void *context,
321 void **return_value);
322
323 247
324/* 248/*
325 * dbfileio - Debugger file I/O commands 249 * dbfileio - Debugger file I/O commands
326 */ 250 */
327
328acpi_object_type 251acpi_object_type
329acpi_db_match_argument ( 252acpi_db_match_argument (
330 char *user_argument, 253 char *user_argument,
331 struct argument_info *arguments); 254 struct argument_info *arguments);
332 255
333acpi_status
334ae_local_load_table (
335 struct acpi_table_header *table_ptr);
336
337void 256void
338acpi_db_close_debug_file ( 257acpi_db_close_debug_file (
339 void); 258 void);
@@ -356,16 +275,17 @@ acpi_db_read_table_from_file (
356 char *filename, 275 char *filename,
357 struct acpi_table_header **table); 276 struct acpi_table_header **table);
358 277
278
359/* 279/*
360 * dbhistry - debugger HISTORY command 280 * dbhistry - debugger HISTORY command
361 */ 281 */
362
363void 282void
364acpi_db_add_to_history ( 283acpi_db_add_to_history (
365 char *command_line); 284 char *command_line);
366 285
367void 286void
368acpi_db_display_history (void); 287acpi_db_display_history (
288 void);
369 289
370char * 290char *
371acpi_db_get_from_history ( 291acpi_db_get_from_history (
@@ -375,7 +295,6 @@ acpi_db_get_from_history (
375/* 295/*
376 * dbinput - user front-end to the AML debugger 296 * dbinput - user front-end to the AML debugger
377 */ 297 */
378
379acpi_status 298acpi_status
380acpi_db_command_dispatch ( 299acpi_db_command_dispatch (
381 char *input_buffer, 300 char *input_buffer,
@@ -386,71 +305,28 @@ void ACPI_SYSTEM_XFACE
386acpi_db_execute_thread ( 305acpi_db_execute_thread (
387 void *context); 306 void *context);
388 307
389void
390acpi_db_display_help (
391 char *help_type);
392
393char *
394acpi_db_get_next_token (
395 char *string,
396 char **next);
397
398u32
399acpi_db_get_line (
400 char *input_buffer);
401
402u32
403acpi_db_match_command (
404 char *user_command);
405
406void
407acpi_db_single_thread (
408 void);
409
410 308
411/* 309/*
412 * dbstats - Generation and display of ACPI table statistics 310 * dbstats - Generation and display of ACPI table statistics
413 */ 311 */
414
415void 312void
416acpi_db_generate_statistics ( 313acpi_db_generate_statistics (
417 union acpi_parse_object *root, 314 union acpi_parse_object *root,
418 u8 is_method); 315 u8 is_method);
419 316
420
421acpi_status 317acpi_status
422acpi_db_display_statistics ( 318acpi_db_display_statistics (
423 char *type_arg); 319 char *type_arg);
424 320
425acpi_status
426acpi_db_classify_one_object (
427 acpi_handle obj_handle,
428 u32 nesting_level,
429 void *context,
430 void **return_value);
431
432void
433acpi_db_count_namespace_objects (
434 void);
435
436void
437acpi_db_enumerate_object (
438 union acpi_operand_object *obj_desc);
439
440 321
441/* 322/*
442 * dbutils - AML debugger utilities 323 * dbutils - AML debugger utilities
443 */ 324 */
444
445void 325void
446acpi_db_set_output_destination ( 326acpi_db_set_output_destination (
447 u32 where); 327 u32 where);
448 328
449void 329void
450acpi_db_dump_buffer (
451 u32 address);
452
453void
454acpi_db_dump_object ( 330acpi_db_dump_object (
455 union acpi_object *obj_desc, 331 union acpi_object *obj_desc,
456 u32 level); 332 u32 level);
@@ -459,14 +335,8 @@ void
459acpi_db_prep_namestring ( 335acpi_db_prep_namestring (
460 char *name); 336 char *name);
461 337
462
463acpi_status
464acpi_db_second_pass_parse (
465 union acpi_parse_object *root);
466
467struct acpi_namespace_node * 338struct acpi_namespace_node *
468acpi_db_local_ns_lookup ( 339acpi_db_local_ns_lookup (
469 char *name); 340 char *name);
470 341
471
472#endif /* __ACDEBUG_H__ */ 342#endif /* __ACDEBUG_H__ */
diff --git a/include/acpi/acdisasm.h b/include/acpi/acdisasm.h
index 26d907eae6fe..dbfa877121ba 100644
--- a/include/acpi/acdisasm.h
+++ b/include/acpi/acdisasm.h
@@ -102,58 +102,16 @@ acpi_status (*asl_walk_callback) (
102/* 102/*
103 * dmwalk 103 * dmwalk
104 */ 104 */
105
106void
107acpi_dm_walk_parse_tree (
108 union acpi_parse_object *op,
109 asl_walk_callback descending_callback,
110 asl_walk_callback ascending_callback,
111 void *context);
112
113acpi_status
114acpi_dm_descending_op (
115 union acpi_parse_object *op,
116 u32 level,
117 void *context);
118
119acpi_status
120acpi_dm_ascending_op (
121 union acpi_parse_object *op,
122 u32 level,
123 void *context);
124
125
126/*
127 * dmopcode
128 */
129
130void
131acpi_dm_validate_name (
132 char *name,
133 union acpi_parse_object *op);
134
135u32
136acpi_dm_dump_name (
137 char *name);
138
139void
140acpi_dm_unicode (
141 union acpi_parse_object *op);
142
143void 105void
144acpi_dm_disassemble ( 106acpi_dm_disassemble (
145 struct acpi_walk_state *walk_state, 107 struct acpi_walk_state *walk_state,
146 union acpi_parse_object *origin, 108 union acpi_parse_object *origin,
147 u32 num_opcodes); 109 u32 num_opcodes);
148 110
149void
150acpi_dm_namestring (
151 char *name);
152
153void
154acpi_dm_display_path (
155 union acpi_parse_object *op);
156 111
112/*
113 * dmopcode
114 */
157void 115void
158acpi_dm_disassemble_one_op ( 116acpi_dm_disassemble_one_op (
159 struct acpi_walk_state *walk_state, 117 struct acpi_walk_state *walk_state,
@@ -165,18 +123,9 @@ acpi_dm_decode_internal_object (
165 union acpi_operand_object *obj_desc); 123 union acpi_operand_object *obj_desc);
166 124
167u32 125u32
168acpi_dm_block_type (
169 union acpi_parse_object *op);
170
171u32
172acpi_dm_list_type ( 126acpi_dm_list_type (
173 union acpi_parse_object *op); 127 union acpi_parse_object *op);
174 128
175acpi_status
176acpi_ps_display_object_pathname (
177 struct acpi_walk_state *walk_state,
178 union acpi_parse_object *op);
179
180void 129void
181acpi_dm_method_flags ( 130acpi_dm_method_flags (
182 union acpi_parse_object *op); 131 union acpi_parse_object *op);
@@ -197,10 +146,6 @@ void
197acpi_dm_match_op ( 146acpi_dm_match_op (
198 union acpi_parse_object *op); 147 union acpi_parse_object *op);
199 148
200void
201acpi_dm_match_keyword (
202 union acpi_parse_object *op);
203
204u8 149u8
205acpi_dm_comma_if_list_member ( 150acpi_dm_comma_if_list_member (
206 union acpi_parse_object *op); 151 union acpi_parse_object *op);
@@ -211,13 +156,25 @@ acpi_dm_comma_if_field_member (
211 156
212 157
213/* 158/*
214 * dmobject 159 * dmnames
215 */ 160 */
161u32
162acpi_dm_dump_name (
163 char *name);
164
165acpi_status
166acpi_ps_display_object_pathname (
167 struct acpi_walk_state *walk_state,
168 union acpi_parse_object *op);
216 169
217void 170void
218acpi_dm_decode_node ( 171acpi_dm_namestring (
219 struct acpi_namespace_node *node); 172 char *name);
173
220 174
175/*
176 * dmobject
177 */
221void 178void
222acpi_dm_display_internal_object ( 179acpi_dm_display_internal_object (
223 union acpi_operand_object *obj_desc, 180 union acpi_operand_object *obj_desc,
@@ -241,6 +198,16 @@ acpi_dm_dump_method_info (
241/* 198/*
242 * dmbuffer 199 * dmbuffer
243 */ 200 */
201void
202acpi_dm_disasm_byte_list (
203 u32 level,
204 u8 *byte_data,
205 u32 byte_count);
206
207void
208acpi_dm_byte_list (
209 struct acpi_op_walk_info *info,
210 union acpi_parse_object *op);
244 211
245void 212void
246acpi_is_eisa_id ( 213acpi_is_eisa_id (
@@ -262,18 +229,6 @@ acpi_dm_is_string_buffer (
262/* 229/*
263 * dmresrc 230 * dmresrc
264 */ 231 */
265
266void
267acpi_dm_disasm_byte_list (
268 u32 level,
269 u8 *byte_data,
270 u32 byte_count);
271
272void
273acpi_dm_byte_list (
274 struct acpi_op_walk_info *info,
275 union acpi_parse_object *op);
276
277void 232void
278acpi_dm_resource_descriptor ( 233acpi_dm_resource_descriptor (
279 struct acpi_op_walk_info *info, 234 struct acpi_op_walk_info *info,
@@ -296,19 +251,10 @@ void
296acpi_dm_decode_attribute ( 251acpi_dm_decode_attribute (
297 u8 attribute); 252 u8 attribute);
298 253
254
299/* 255/*
300 * dmresrcl 256 * dmresrcl
301 */ 257 */
302
303void
304acpi_dm_io_flags (
305 u8 flags);
306
307void
308acpi_dm_memory_flags (
309 u8 flags,
310 u8 specific_flags);
311
312void 258void
313acpi_dm_word_descriptor ( 259acpi_dm_word_descriptor (
314 struct asl_word_address_desc *resource, 260 struct asl_word_address_desc *resource,
@@ -373,7 +319,6 @@ acpi_dm_vendor_large_descriptor (
373/* 319/*
374 * dmresrcs 320 * dmresrcs
375 */ 321 */
376
377void 322void
378acpi_dm_irq_descriptor ( 323acpi_dm_irq_descriptor (
379 struct asl_irq_format_desc *resource, 324 struct asl_irq_format_desc *resource,
@@ -420,7 +365,6 @@ acpi_dm_vendor_small_descriptor (
420/* 365/*
421 * dmutils 366 * dmutils
422 */ 367 */
423
424void 368void
425acpi_dm_add_to_external_list ( 369acpi_dm_add_to_external_list (
426 char *path); 370 char *path);
diff --git a/include/acpi/acdispat.h b/include/acpi/acdispat.h
index 237d63433581..8f5f2f71b1de 100644
--- a/include/acpi/acdispat.h
+++ b/include/acpi/acdispat.h
@@ -50,40 +50,9 @@
50#define NAMEOF_ARG_NTE "__A0" 50#define NAMEOF_ARG_NTE "__A0"
51 51
52 52
53/* Common interfaces */ 53/*
54 54 * dsopcode - support for late evaluation
55acpi_status 55 */
56acpi_ds_obj_stack_push (
57 void *object,
58 struct acpi_walk_state *walk_state);
59
60acpi_status
61acpi_ds_obj_stack_pop (
62 u32 pop_count,
63 struct acpi_walk_state *walk_state);
64
65#ifdef ACPI_FUTURE_USAGE
66void *
67acpi_ds_obj_stack_get_value (
68 u32 index,
69 struct acpi_walk_state *walk_state);
70#endif
71
72acpi_status
73acpi_ds_obj_stack_pop_object (
74 union acpi_operand_object **object,
75 struct acpi_walk_state *walk_state);
76
77
78/* dsopcode - support for late evaluation */
79
80acpi_status
81acpi_ds_execute_arguments (
82 struct acpi_namespace_node *node,
83 struct acpi_namespace_node *scope_node,
84 u32 aml_length,
85 u8 *aml_start);
86
87acpi_status 56acpi_status
88acpi_ds_get_buffer_field_arguments ( 57acpi_ds_get_buffer_field_arguments (
89 union acpi_operand_object *obj_desc); 58 union acpi_operand_object *obj_desc);
@@ -101,15 +70,6 @@ acpi_ds_get_package_arguments (
101 union acpi_operand_object *obj_desc); 70 union acpi_operand_object *obj_desc);
102 71
103acpi_status 72acpi_status
104acpi_ds_init_buffer_field (
105 u16 aml_opcode,
106 union acpi_operand_object *obj_desc,
107 union acpi_operand_object *buffer_desc,
108 union acpi_operand_object *offset_desc,
109 union acpi_operand_object *length_desc,
110 union acpi_operand_object *result_desc);
111
112acpi_status
113acpi_ds_eval_buffer_field_operands ( 73acpi_ds_eval_buffer_field_operands (
114 struct acpi_walk_state *walk_state, 74 struct acpi_walk_state *walk_state,
115 union acpi_parse_object *op); 75 union acpi_parse_object *op);
@@ -130,9 +90,9 @@ acpi_ds_initialize_region (
130 acpi_handle obj_handle); 90 acpi_handle obj_handle);
131 91
132 92
133/* dsctrl - Parser/Interpreter interface, control stack routines */ 93/*
134 94 * dsctrl - Parser/Interpreter interface, control stack routines
135 95 */
136acpi_status 96acpi_status
137acpi_ds_exec_begin_control_op ( 97acpi_ds_exec_begin_control_op (
138 struct acpi_walk_state *walk_state, 98 struct acpi_walk_state *walk_state,
@@ -144,9 +104,9 @@ acpi_ds_exec_end_control_op (
144 union acpi_parse_object *op); 104 union acpi_parse_object *op);
145 105
146 106
147/* dsexec - Parser/Interpreter interface, method execution callbacks */ 107/*
148 108 * dsexec - Parser/Interpreter interface, method execution callbacks
149 109 */
150acpi_status 110acpi_status
151acpi_ds_get_predicate_value ( 111acpi_ds_get_predicate_value (
152 struct acpi_walk_state *walk_state, 112 struct acpi_walk_state *walk_state,
@@ -162,14 +122,9 @@ acpi_ds_exec_end_op (
162 struct acpi_walk_state *state); 122 struct acpi_walk_state *state);
163 123
164 124
165/* dsfield - Parser/Interpreter interface for AML fields */ 125/*
166 126 * dsfield - Parser/Interpreter interface for AML fields
167acpi_status 127 */
168acpi_ds_get_field_names (
169 struct acpi_create_field_info *info,
170 struct acpi_walk_state *walk_state,
171 union acpi_parse_object *arg);
172
173acpi_status 128acpi_status
174acpi_ds_create_field ( 129acpi_ds_create_field (
175 union acpi_parse_object *op, 130 union acpi_parse_object *op,
@@ -199,8 +154,9 @@ acpi_ds_init_field_objects (
199 struct acpi_walk_state *walk_state); 154 struct acpi_walk_state *walk_state);
200 155
201 156
202/* dsload - Parser/Interpreter interface, namespace load callbacks */ 157/*
203 158 * dsload - Parser/Interpreter interface, namespace load callbacks
159 */
204acpi_status 160acpi_status
205acpi_ds_load1_begin_op ( 161acpi_ds_load1_begin_op (
206 struct acpi_walk_state *walk_state, 162 struct acpi_walk_state *walk_state,
@@ -225,9 +181,9 @@ acpi_ds_init_callbacks (
225 u32 pass_number); 181 u32 pass_number);
226 182
227 183
228/* dsmthdat - method data (locals/args) */ 184/*
229 185 * dsmthdat - method data (locals/args)
230 186 */
231acpi_status 187acpi_status
232acpi_ds_store_object_to_local ( 188acpi_ds_store_object_to_local (
233 u16 opcode, 189 u16 opcode,
@@ -250,14 +206,6 @@ u8
250acpi_ds_is_method_value ( 206acpi_ds_is_method_value (
251 union acpi_operand_object *obj_desc); 207 union acpi_operand_object *obj_desc);
252 208
253#ifdef ACPI_FUTURE_USAGE
254acpi_object_type
255acpi_ds_method_data_get_type (
256 u16 opcode,
257 u32 index,
258 struct acpi_walk_state *walk_state);
259#endif
260
261acpi_status 209acpi_status
262acpi_ds_method_data_get_value ( 210acpi_ds_method_data_get_value (
263 u16 opcode, 211 u16 opcode,
@@ -265,12 +213,6 @@ acpi_ds_method_data_get_value (
265 struct acpi_walk_state *walk_state, 213 struct acpi_walk_state *walk_state,
266 union acpi_operand_object **dest_desc); 214 union acpi_operand_object **dest_desc);
267 215
268void
269acpi_ds_method_data_delete_value (
270 u16 opcode,
271 u32 index,
272 struct acpi_walk_state *walk_state);
273
274acpi_status 216acpi_status
275acpi_ds_method_data_init_args ( 217acpi_ds_method_data_init_args (
276 union acpi_operand_object **params, 218 union acpi_operand_object **params,
@@ -288,16 +230,10 @@ void
288acpi_ds_method_data_init ( 230acpi_ds_method_data_init (
289 struct acpi_walk_state *walk_state); 231 struct acpi_walk_state *walk_state);
290 232
291acpi_status
292acpi_ds_method_data_set_value (
293 u16 opcode,
294 u32 index,
295 union acpi_operand_object *object,
296 struct acpi_walk_state *walk_state);
297
298
299/* dsmethod - Parser/Interpreter interface - control method parsing */
300 233
234/*
235 * dsmethod - Parser/Interpreter interface - control method parsing
236 */
301acpi_status 237acpi_status
302acpi_ds_parse_method ( 238acpi_ds_parse_method (
303 acpi_handle obj_handle); 239 acpi_handle obj_handle);
@@ -324,20 +260,18 @@ acpi_ds_begin_method_execution (
324 struct acpi_namespace_node *calling_method_node); 260 struct acpi_namespace_node *calling_method_node);
325 261
326 262
327/* dsobj - Parser/Interpreter interface - object initialization and conversion */ 263/*
328 264 * dsinit
329acpi_status 265 */
330acpi_ds_init_one_object (
331 acpi_handle obj_handle,
332 u32 level,
333 void *context,
334 void **return_value);
335
336acpi_status 266acpi_status
337acpi_ds_initialize_objects ( 267acpi_ds_initialize_objects (
338 struct acpi_table_desc *table_desc, 268 struct acpi_table_desc *table_desc,
339 struct acpi_namespace_node *start_node); 269 struct acpi_namespace_node *start_node);
340 270
271
272/*
273 * dsobject - Parser/Interpreter interface - object initialization and conversion
274 */
341acpi_status 275acpi_status
342acpi_ds_build_internal_buffer_obj ( 276acpi_ds_build_internal_buffer_obj (
343 struct acpi_walk_state *walk_state, 277 struct acpi_walk_state *walk_state,
@@ -353,12 +287,6 @@ acpi_ds_build_internal_package_obj (
353 union acpi_operand_object **obj_desc); 287 union acpi_operand_object **obj_desc);
354 288
355acpi_status 289acpi_status
356acpi_ds_build_internal_object (
357 struct acpi_walk_state *walk_state,
358 union acpi_parse_object *op,
359 union acpi_operand_object **obj_desc_ptr);
360
361acpi_status
362acpi_ds_init_object_from_op ( 290acpi_ds_init_object_from_op (
363 struct acpi_walk_state *walk_state, 291 struct acpi_walk_state *walk_state,
364 union acpi_parse_object *op, 292 union acpi_parse_object *op,
@@ -372,8 +300,9 @@ acpi_ds_create_node (
372 union acpi_parse_object *op); 300 union acpi_parse_object *op);
373 301
374 302
375/* dsutils - Parser/Interpreter interface utility routines */ 303/*
376 304 * dsutils - Parser/Interpreter interface utility routines
305 */
377void 306void
378acpi_ds_clear_implicit_return ( 307acpi_ds_clear_implicit_return (
379 struct acpi_walk_state *walk_state); 308 struct acpi_walk_state *walk_state);
@@ -418,7 +347,6 @@ acpi_ds_clear_operands (
418/* 347/*
419 * dswscope - Scope Stack manipulation 348 * dswscope - Scope Stack manipulation
420 */ 349 */
421
422acpi_status 350acpi_status
423acpi_ds_scope_stack_push ( 351acpi_ds_scope_stack_push (
424 struct acpi_namespace_node *node, 352 struct acpi_namespace_node *node,
@@ -435,7 +363,18 @@ acpi_ds_scope_stack_clear (
435 struct acpi_walk_state *walk_state); 363 struct acpi_walk_state *walk_state);
436 364
437 365
438/* dswstate - parser WALK_STATE management routines */ 366/*
367 * dswstate - parser WALK_STATE management routines
368 */
369acpi_status
370acpi_ds_obj_stack_push (
371 void *object,
372 struct acpi_walk_state *walk_state);
373
374acpi_status
375acpi_ds_obj_stack_pop (
376 u32 pop_count,
377 struct acpi_walk_state *walk_state);
439 378
440struct acpi_walk_state * 379struct acpi_walk_state *
441acpi_ds_create_walk_state ( 380acpi_ds_create_walk_state (
@@ -454,12 +393,6 @@ acpi_ds_init_aml_walk (
454 struct acpi_parameter_info *info, 393 struct acpi_parameter_info *info,
455 u32 pass_number); 394 u32 pass_number);
456 395
457#ifdef ACPI_FUTURE_USAGE
458acpi_status
459acpi_ds_obj_stack_delete_all (
460 struct acpi_walk_state *walk_state);
461#endif
462
463acpi_status 396acpi_status
464acpi_ds_obj_stack_pop_and_delete ( 397acpi_ds_obj_stack_pop_and_delete (
465 u32 pop_count, 398 u32 pop_count,
@@ -494,20 +427,8 @@ struct acpi_walk_state *
494acpi_ds_get_current_walk_state ( 427acpi_ds_get_current_walk_state (
495 struct acpi_thread_state *thread); 428 struct acpi_thread_state *thread);
496 429
497#ifdef ACPI_ENABLE_OBJECT_CACHE
498void
499acpi_ds_delete_walk_state_cache (
500 void);
501#endif
502
503#ifdef ACPI_FUTURE_USAGE 430#ifdef ACPI_FUTURE_USAGE
504acpi_status 431acpi_status
505acpi_ds_result_insert (
506 void *object,
507 u32 index,
508 struct acpi_walk_state *walk_state);
509
510acpi_status
511acpi_ds_result_remove ( 432acpi_ds_result_remove (
512 union acpi_operand_object **object, 433 union acpi_operand_object **object,
513 u32 index, 434 u32 index,
@@ -529,4 +450,10 @@ acpi_ds_result_pop_from_bottom (
529 union acpi_operand_object **object, 450 union acpi_operand_object **object,
530 struct acpi_walk_state *walk_state); 451 struct acpi_walk_state *walk_state);
531 452
453#ifdef ACPI_ENABLE_OBJECT_CACHE
454void
455acpi_ds_delete_walk_state_cache (
456 void);
457#endif
458
532#endif /* _ACDISPAT_H_ */ 459#endif /* _ACDISPAT_H_ */
diff --git a/include/acpi/acevents.h b/include/acpi/acevents.h
index 2dec083ba1cd..61a27c8c5079 100644
--- a/include/acpi/acevents.h
+++ b/include/acpi/acevents.h
@@ -45,6 +45,9 @@
45#define __ACEVENTS_H__ 45#define __ACEVENTS_H__
46 46
47 47
48/*
49 * evevent
50 */
48acpi_status 51acpi_status
49acpi_ev_initialize_events ( 52acpi_ev_initialize_events (
50 void); 53 void);
@@ -53,28 +56,14 @@ acpi_status
53acpi_ev_install_xrupt_handlers ( 56acpi_ev_install_xrupt_handlers (
54 void); 57 void);
55 58
56
57/*
58 * Evfixed - Fixed event handling
59 */
60
61acpi_status
62acpi_ev_fixed_event_initialize (
63 void);
64
65u32 59u32
66acpi_ev_fixed_event_detect ( 60acpi_ev_fixed_event_detect (
67 void); 61 void);
68 62
69u32
70acpi_ev_fixed_event_dispatch (
71 u32 event);
72
73 63
74/* 64/*
75 * Evmisc 65 * evmisc
76 */ 66 */
77
78u8 67u8
79acpi_ev_is_notify_object ( 68acpi_ev_is_notify_object (
80 struct acpi_namespace_node *node); 69 struct acpi_namespace_node *node);
@@ -100,24 +89,10 @@ acpi_ev_queue_notify_request (
100 struct acpi_namespace_node *node, 89 struct acpi_namespace_node *node,
101 u32 notify_value); 90 u32 notify_value);
102 91
103void ACPI_SYSTEM_XFACE
104acpi_ev_notify_dispatch (
105 void *context);
106
107 92
108/* 93/*
109 * Evgpe - GPE handling and dispatch 94 * evgpe - GPE handling and dispatch
110 */ 95 */
111
112acpi_status
113acpi_ev_walk_gpe_list (
114 ACPI_GPE_CALLBACK gpe_walk_callback,
115 u32 flags);
116
117u8
118acpi_ev_valid_gpe_event (
119 struct acpi_gpe_event_info *gpe_event_info);
120
121acpi_status 96acpi_status
122acpi_ev_update_gpe_enable_masks ( 97acpi_ev_update_gpe_enable_masks (
123 struct acpi_gpe_event_info *gpe_event_info, 98 struct acpi_gpe_event_info *gpe_event_info,
@@ -137,9 +112,23 @@ acpi_ev_get_gpe_event_info (
137 acpi_handle gpe_device, 112 acpi_handle gpe_device,
138 u32 gpe_number); 113 u32 gpe_number);
139 114
115
116/*
117 * evgpeblk
118 */
119u8
120acpi_ev_valid_gpe_event (
121 struct acpi_gpe_event_info *gpe_event_info);
122
140acpi_status 123acpi_status
141acpi_ev_gpe_initialize ( 124acpi_ev_walk_gpe_list (
142 void); 125 ACPI_GPE_CALLBACK gpe_walk_callback,
126 u32 flags);
127
128acpi_status
129acpi_ev_delete_gpe_handlers (
130 struct acpi_gpe_xrupt_info *gpe_xrupt_info,
131 struct acpi_gpe_block_info *gpe_block);
143 132
144acpi_status 133acpi_status
145acpi_ev_create_gpe_block ( 134acpi_ev_create_gpe_block (
@@ -154,11 +143,6 @@ acpi_status
154acpi_ev_delete_gpe_block ( 143acpi_ev_delete_gpe_block (
155 struct acpi_gpe_block_info *gpe_block); 144 struct acpi_gpe_block_info *gpe_block);
156 145
157acpi_status
158acpi_ev_delete_gpe_handlers (
159 struct acpi_gpe_xrupt_info *gpe_xrupt_info,
160 struct acpi_gpe_block_info *gpe_block);
161
162u32 146u32
163acpi_ev_gpe_dispatch ( 147acpi_ev_gpe_dispatch (
164 struct acpi_gpe_event_info *gpe_event_info, 148 struct acpi_gpe_event_info *gpe_event_info,
@@ -177,10 +161,14 @@ acpi_status
177acpi_ev_check_for_wake_only_gpe ( 161acpi_ev_check_for_wake_only_gpe (
178 struct acpi_gpe_event_info *gpe_event_info); 162 struct acpi_gpe_event_info *gpe_event_info);
179 163
164acpi_status
165acpi_ev_gpe_initialize (
166 void);
167
168
180/* 169/*
181 * Evregion - Address Space handling 170 * evregion - Address Space handling
182 */ 171 */
183
184acpi_status 172acpi_status
185acpi_ev_install_region_handlers ( 173acpi_ev_install_region_handlers (
186 void); 174 void);
@@ -198,13 +186,6 @@ acpi_ev_address_space_dispatch (
198 void *value); 186 void *value);
199 187
200acpi_status 188acpi_status
201acpi_ev_install_handler (
202 acpi_handle obj_handle,
203 u32 level,
204 void *context,
205 void **return_value);
206
207acpi_status
208acpi_ev_attach_region ( 189acpi_ev_attach_region (
209 union acpi_operand_object *handler_obj, 190 union acpi_operand_object *handler_obj,
210 union acpi_operand_object *region_obj, 191 union acpi_operand_object *region_obj,
@@ -233,17 +214,10 @@ acpi_ev_execute_reg_method (
233 union acpi_operand_object *region_obj, 214 union acpi_operand_object *region_obj,
234 u32 function); 215 u32 function);
235 216
236acpi_status
237acpi_ev_reg_run (
238 acpi_handle obj_handle,
239 u32 level,
240 void *context,
241 void **return_value);
242 217
243/* 218/*
244 * Evregini - Region initialization and setup 219 * evregini - Region initialization and setup
245 */ 220 */
246
247acpi_status 221acpi_status
248acpi_ev_system_memory_region_setup ( 222acpi_ev_system_memory_region_setup (
249 acpi_handle handle, 223 acpi_handle handle,
@@ -293,9 +267,8 @@ acpi_ev_initialize_region (
293 267
294 268
295/* 269/*
296 * Evsci - SCI (System Control Interrupt) handling/dispatch 270 * evsci - SCI (System Control Interrupt) handling/dispatch
297 */ 271 */
298
299u32 ACPI_SYSTEM_XFACE 272u32 ACPI_SYSTEM_XFACE
300acpi_ev_gpe_xrupt_handler ( 273acpi_ev_gpe_xrupt_handler (
301 void *context); 274 void *context);
diff --git a/include/acpi/acexcep.h b/include/acpi/acexcep.h
index 53f8b50fac1a..60d737b2d70f 100644
--- a/include/acpi/acexcep.h
+++ b/include/acpi/acexcep.h
@@ -48,7 +48,6 @@
48/* 48/*
49 * Exceptions returned by external ACPI interfaces 49 * Exceptions returned by external ACPI interfaces
50 */ 50 */
51
52#define AE_CODE_ENVIRONMENTAL 0x0000 51#define AE_CODE_ENVIRONMENTAL 0x0000
53#define AE_CODE_PROGRAMMER 0x1000 52#define AE_CODE_PROGRAMMER 0x1000
54#define AE_CODE_ACPI_TABLES 0x2000 53#define AE_CODE_ACPI_TABLES 0x2000
@@ -99,6 +98,7 @@
99 98
100#define AE_CODE_ENV_MAX 0x001E 99#define AE_CODE_ENV_MAX 0x001E
101 100
101
102/* 102/*
103 * Programmer exceptions 103 * Programmer exceptions
104 */ 104 */
@@ -168,6 +168,7 @@
168 168
169#define AE_CODE_AML_MAX 0x0021 169#define AE_CODE_AML_MAX 0x0021
170 170
171
171/* 172/*
172 * Internal exceptions used for control 173 * Internal exceptions used for control
173 */ 174 */
@@ -188,6 +189,7 @@
188 189
189#ifdef DEFINE_ACPI_GLOBALS 190#ifdef DEFINE_ACPI_GLOBALS
190 191
192
191/* 193/*
192 * String versions of the exception codes above 194 * String versions of the exception codes above
193 * These strings must match the corresponding defines exactly 195 * These strings must match the corresponding defines exactly
@@ -304,5 +306,4 @@ char const *acpi_gbl_exception_names_ctrl[] =
304 306
305#endif /* ACPI GLOBALS */ 307#endif /* ACPI GLOBALS */
306 308
307
308#endif /* __ACEXCEP_H__ */ 309#endif /* __ACEXCEP_H__ */
diff --git a/include/acpi/acglobal.h b/include/acpi/acglobal.h
index c7f387a972cb..4946696088c3 100644
--- a/include/acpi/acglobal.h
+++ b/include/acpi/acglobal.h
@@ -146,15 +146,15 @@ ACPI_EXTERN struct acpi_table_header *acpi_gbl_DSDT;
146ACPI_EXTERN FACS_DESCRIPTOR *acpi_gbl_FACS; 146ACPI_EXTERN FACS_DESCRIPTOR *acpi_gbl_FACS;
147ACPI_EXTERN struct acpi_common_facs acpi_gbl_common_fACS; 147ACPI_EXTERN struct acpi_common_facs acpi_gbl_common_fACS;
148/* 148/*
149 * Since there may be multiple SSDTs and PSDTS, a single pointer is not 149 * Since there may be multiple SSDTs and PSDTs, a single pointer is not
150 * sufficient; Therefore, there isn't one! 150 * sufficient; Therefore, there isn't one!
151 */ 151 */
152 152
153 153
154/* 154/*
155 * Handle both ACPI 1.0 and ACPI 2.0 Integer widths 155 * Handle both ACPI 1.0 and ACPI 2.0 Integer widths:
156 * If we are running a method that exists in a 32-bit ACPI table. 156 * If we are executing a method that exists in a 32-bit ACPI table,
157 * Use only 32 bits of the Integer for conversion. 157 * use only the lower 32 bits of the (internal) 64-bit Integer.
158 */ 158 */
159ACPI_EXTERN u8 acpi_gbl_integer_bit_width; 159ACPI_EXTERN u8 acpi_gbl_integer_bit_width;
160ACPI_EXTERN u8 acpi_gbl_integer_byte_width; 160ACPI_EXTERN u8 acpi_gbl_integer_byte_width;
@@ -246,6 +246,7 @@ ACPI_EXTERN acpi_size acpi_gbl_lowest_stack_pointer;
246ACPI_EXTERN u32 acpi_gbl_deepest_nesting; 246ACPI_EXTERN u32 acpi_gbl_deepest_nesting;
247#endif 247#endif
248 248
249
249/***************************************************************************** 250/*****************************************************************************
250 * 251 *
251 * Interpreter globals 252 * Interpreter globals
@@ -268,6 +269,7 @@ ACPI_EXTERN u8 acpi_gbl_cm_single_step;
268 269
269ACPI_EXTERN union acpi_parse_object *acpi_gbl_parsed_namespace_root; 270ACPI_EXTERN union acpi_parse_object *acpi_gbl_parsed_namespace_root;
270 271
272
271/***************************************************************************** 273/*****************************************************************************
272 * 274 *
273 * Hardware globals 275 * Hardware globals
@@ -298,7 +300,6 @@ ACPI_EXTERN acpi_handle acpi_gbl_gpe_lock;
298 * 300 *
299 ****************************************************************************/ 301 ****************************************************************************/
300 302
301
302ACPI_EXTERN u8 acpi_gbl_db_output_flags; 303ACPI_EXTERN u8 acpi_gbl_db_output_flags;
303 304
304#ifdef ACPI_DISASSEMBLER 305#ifdef ACPI_DISASSEMBLER
@@ -353,5 +354,4 @@ ACPI_EXTERN u32 acpi_gbl_size_of_acpi_objects;
353 354
354#endif /* ACPI_DEBUGGER */ 355#endif /* ACPI_DEBUGGER */
355 356
356
357#endif /* __ACGLOBAL_H__ */ 357#endif /* __ACGLOBAL_H__ */
diff --git a/include/acpi/achware.h b/include/acpi/achware.h
index 28ad1398c159..9d63641b8e7d 100644
--- a/include/acpi/achware.h
+++ b/include/acpi/achware.h
@@ -46,22 +46,26 @@
46 46
47 47
48/* PM Timer ticks per second (HZ) */ 48/* PM Timer ticks per second (HZ) */
49
49#define PM_TIMER_FREQUENCY 3579545 50#define PM_TIMER_FREQUENCY 3579545
50 51
52/* Values for the _SST reserved method */
51 53
52/* Prototypes */ 54#define ACPI_SST_INDICATOR_OFF 0
55#define ACPI_SST_WORKING 1
56#define ACPI_SST_WAKING 2
57#define ACPI_SST_SLEEPING 3
58#define ACPI_SST_SLEEP_CONTEXT 4
53 59
54 60
55acpi_status 61/* Prototypes */
56acpi_hw_initialize (
57 void);
58 62
59acpi_status
60acpi_hw_shutdown (
61 void);
62 63
64/*
65 * hwacpi - high level functions
66 */
63acpi_status 67acpi_status
64acpi_hw_initialize_system_info ( 68acpi_hw_initialize (
65 void); 69 void);
66 70
67acpi_status 71acpi_status
@@ -72,12 +76,10 @@ u32
72acpi_hw_get_mode ( 76acpi_hw_get_mode (
73 void); 77 void);
74 78
75u32
76acpi_hw_get_mode_capabilities (
77 void);
78
79/* Register I/O Prototypes */
80 79
80/*
81 * hwregs - ACPI Register I/O
82 */
81struct acpi_bit_register_info * 83struct acpi_bit_register_info *
82acpi_hw_get_bit_register_info ( 84acpi_hw_get_bit_register_info (
83 u32 register_id); 85 u32 register_id);
@@ -111,8 +113,9 @@ acpi_hw_clear_acpi_status (
111 u32 flags); 113 u32 flags);
112 114
113 115
114/* GPE support */ 116/*
115 117 * hwgpe - GPE support
118 */
116acpi_status 119acpi_status
117acpi_hw_write_gpe_enable_reg ( 120acpi_hw_write_gpe_enable_reg (
118 struct acpi_gpe_event_info *gpe_event_info); 121 struct acpi_gpe_event_info *gpe_event_info);
@@ -131,12 +134,12 @@ acpi_hw_clear_gpe_block (
131 struct acpi_gpe_xrupt_info *gpe_xrupt_info, 134 struct acpi_gpe_xrupt_info *gpe_xrupt_info,
132 struct acpi_gpe_block_info *gpe_block); 135 struct acpi_gpe_block_info *gpe_block);
133 136
134#ifdef ACPI_FUTURE_USAGE 137#ifdef ACPI_FUTURE_USAGE
135acpi_status 138acpi_status
136acpi_hw_get_gpe_status ( 139acpi_hw_get_gpe_status (
137 struct acpi_gpe_event_info *gpe_event_info, 140 struct acpi_gpe_event_info *gpe_event_info,
138 acpi_event_status *event_status); 141 acpi_event_status *event_status);
139#endif 142#endif /* ACPI_FUTURE_USAGE */
140 143
141acpi_status 144acpi_status
142acpi_hw_disable_all_gpes ( 145acpi_hw_disable_all_gpes (
@@ -155,15 +158,11 @@ acpi_hw_enable_runtime_gpe_block (
155 struct acpi_gpe_xrupt_info *gpe_xrupt_info, 158 struct acpi_gpe_xrupt_info *gpe_xrupt_info,
156 struct acpi_gpe_block_info *gpe_block); 159 struct acpi_gpe_block_info *gpe_block);
157 160
158acpi_status
159acpi_hw_enable_wakeup_gpe_block (
160 struct acpi_gpe_xrupt_info *gpe_xrupt_info,
161 struct acpi_gpe_block_info *gpe_block);
162
163
164/* ACPI Timer prototypes */
165 161
166#ifdef ACPI_FUTURE_USAGE 162#ifdef ACPI_FUTURE_USAGE
163/*
164 * hwtimer - ACPI Timer prototypes
165 */
167acpi_status 166acpi_status
168acpi_get_timer_resolution ( 167acpi_get_timer_resolution (
169 u32 *resolution); 168 u32 *resolution);
@@ -177,6 +176,7 @@ acpi_get_timer_duration (
177 u32 start_ticks, 176 u32 start_ticks,
178 u32 end_ticks, 177 u32 end_ticks,
179 u32 *time_elapsed); 178 u32 *time_elapsed);
180#endif /* ACPI_FUTURE_USAGE */ 179#endif /* ACPI_FUTURE_USAGE */
180
181 181
182#endif /* __ACHWARE_H__ */ 182#endif /* __ACHWARE_H__ */
diff --git a/include/acpi/acinterp.h b/include/acpi/acinterp.h
index c5301f5ffaf4..5c7172477a0f 100644
--- a/include/acpi/acinterp.h
+++ b/include/acpi/acinterp.h
@@ -48,37 +48,9 @@
48#define ACPI_WALK_OPERANDS (&(walk_state->operands [walk_state->num_operands -1])) 48#define ACPI_WALK_OPERANDS (&(walk_state->operands [walk_state->num_operands -1]))
49 49
50 50
51acpi_status
52acpi_ex_resolve_operands (
53 u16 opcode,
54 union acpi_operand_object **stack_ptr,
55 struct acpi_walk_state *walk_state);
56
57acpi_status
58acpi_ex_check_object_type (
59 acpi_object_type type_needed,
60 acpi_object_type this_type,
61 void *object);
62
63/*
64 * exxface - External interpreter interfaces
65 */
66
67acpi_status
68acpi_ex_load_table (
69 acpi_table_type table_id);
70
71acpi_status
72acpi_ex_execute_method (
73 struct acpi_namespace_node *method_node,
74 union acpi_operand_object **params,
75 union acpi_operand_object **return_obj_desc);
76
77
78/* 51/*
79 * exconvrt - object conversion 52 * exconvrt - object conversion
80 */ 53 */
81
82acpi_status 54acpi_status
83acpi_ex_convert_to_integer ( 55acpi_ex_convert_to_integer (
84 union acpi_operand_object *obj_desc, 56 union acpi_operand_object *obj_desc,
@@ -110,17 +82,10 @@ acpi_ex_convert_to_target_type (
110 union acpi_operand_object **result_desc, 82 union acpi_operand_object **result_desc,
111 struct acpi_walk_state *walk_state); 83 struct acpi_walk_state *walk_state);
112 84
113u32
114acpi_ex_convert_to_ascii (
115 acpi_integer integer,
116 u16 base,
117 u8 *string,
118 u8 max_length);
119 85
120/* 86/*
121 * exfield - ACPI AML (p-code) execution - field manipulation 87 * exfield - ACPI AML (p-code) execution - field manipulation
122 */ 88 */
123
124acpi_status 89acpi_status
125acpi_ex_common_buffer_setup ( 90acpi_ex_common_buffer_setup (
126 union acpi_operand_object *obj_desc, 91 union acpi_operand_object *obj_desc,
@@ -128,42 +93,6 @@ acpi_ex_common_buffer_setup (
128 u32 *datum_count); 93 u32 *datum_count);
129 94
130acpi_status 95acpi_status
131acpi_ex_extract_from_field (
132 union acpi_operand_object *obj_desc,
133 void *buffer,
134 u32 buffer_length);
135
136acpi_status
137acpi_ex_insert_into_field (
138 union acpi_operand_object *obj_desc,
139 void *buffer,
140 u32 buffer_length);
141
142acpi_status
143acpi_ex_setup_region (
144 union acpi_operand_object *obj_desc,
145 u32 field_datum_byte_offset);
146
147acpi_status
148acpi_ex_access_region (
149 union acpi_operand_object *obj_desc,
150 u32 field_datum_byte_offset,
151 acpi_integer *value,
152 u32 read_write);
153
154u8
155acpi_ex_register_overflow (
156 union acpi_operand_object *obj_desc,
157 acpi_integer value);
158
159acpi_status
160acpi_ex_field_datum_io (
161 union acpi_operand_object *obj_desc,
162 u32 field_datum_byte_offset,
163 acpi_integer *value,
164 u32 read_write);
165
166acpi_status
167acpi_ex_write_with_update_rule ( 96acpi_ex_write_with_update_rule (
168 union acpi_operand_object *obj_desc, 97 union acpi_operand_object *obj_desc,
169 acpi_integer mask, 98 acpi_integer mask,
@@ -198,28 +127,33 @@ acpi_ex_write_data_to_field (
198 union acpi_operand_object *obj_desc, 127 union acpi_operand_object *obj_desc,
199 union acpi_operand_object **result_desc); 128 union acpi_operand_object **result_desc);
200 129
130
201/* 131/*
202 * exmisc - ACPI AML (p-code) execution - specific opcodes 132 * exfldio - low level field I/O
203 */ 133 */
204
205acpi_status 134acpi_status
206acpi_ex_opcode_3A_0T_0R ( 135acpi_ex_extract_from_field (
207 struct acpi_walk_state *walk_state); 136 union acpi_operand_object *obj_desc,
137 void *buffer,
138 u32 buffer_length);
208 139
209acpi_status 140acpi_status
210acpi_ex_opcode_3A_1T_1R ( 141acpi_ex_insert_into_field (
211 struct acpi_walk_state *walk_state); 142 union acpi_operand_object *obj_desc,
143 void *buffer,
144 u32 buffer_length);
212 145
213acpi_status 146acpi_status
214acpi_ex_opcode_6A_0T_1R ( 147acpi_ex_access_region (
215 struct acpi_walk_state *walk_state); 148 union acpi_operand_object *obj_desc,
149 u32 field_datum_byte_offset,
150 acpi_integer *value,
151 u32 read_write);
216 152
217u8
218acpi_ex_do_match (
219 u32 match_op,
220 union acpi_operand_object *package_obj,
221 union acpi_operand_object *match_obj);
222 153
154/*
155 * exmisc - misc support routines
156 */
223acpi_status 157acpi_status
224acpi_ex_get_object_reference ( 158acpi_ex_get_object_reference (
225 union acpi_operand_object *obj_desc, 159 union acpi_operand_object *obj_desc,
@@ -227,13 +161,6 @@ acpi_ex_get_object_reference (
227 struct acpi_walk_state *walk_state); 161 struct acpi_walk_state *walk_state);
228 162
229acpi_status 163acpi_status
230acpi_ex_resolve_multiple (
231 struct acpi_walk_state *walk_state,
232 union acpi_operand_object *operand,
233 acpi_object_type *return_type,
234 union acpi_operand_object **return_desc);
235
236acpi_status
237acpi_ex_concat_template ( 164acpi_ex_concat_template (
238 union acpi_operand_object *obj_desc, 165 union acpi_operand_object *obj_desc,
239 union acpi_operand_object *obj_desc2, 166 union acpi_operand_object *obj_desc2,
@@ -308,13 +235,6 @@ acpi_ex_create_method (
308/* 235/*
309 * exconfig - dynamic table load/unload 236 * exconfig - dynamic table load/unload
310 */ 237 */
311
312acpi_status
313acpi_ex_add_table (
314 struct acpi_table_header *table,
315 struct acpi_namespace_node *parent_node,
316 union acpi_operand_object **ddb_handle);
317
318acpi_status 238acpi_status
319acpi_ex_load_op ( 239acpi_ex_load_op (
320 union acpi_operand_object *obj_desc, 240 union acpi_operand_object *obj_desc,
@@ -334,7 +254,6 @@ acpi_ex_unload_table (
334/* 254/*
335 * exmutex - mutex support 255 * exmutex - mutex support
336 */ 256 */
337
338acpi_status 257acpi_status
339acpi_ex_acquire_mutex ( 258acpi_ex_acquire_mutex (
340 union acpi_operand_object *time_desc, 259 union acpi_operand_object *time_desc,
@@ -354,15 +273,10 @@ void
354acpi_ex_unlink_mutex ( 273acpi_ex_unlink_mutex (
355 union acpi_operand_object *obj_desc); 274 union acpi_operand_object *obj_desc);
356 275
357void
358acpi_ex_link_mutex (
359 union acpi_operand_object *obj_desc,
360 struct acpi_thread_state *thread);
361 276
362/* 277/*
363 * exprep - ACPI AML (p-code) execution - prep utilities 278 * exprep - ACPI AML execution - prep utilities
364 */ 279 */
365
366acpi_status 280acpi_status
367acpi_ex_prep_common_field_object ( 281acpi_ex_prep_common_field_object (
368 union acpi_operand_object *obj_desc, 282 union acpi_operand_object *obj_desc,
@@ -375,10 +289,10 @@ acpi_status
375acpi_ex_prep_field_value ( 289acpi_ex_prep_field_value (
376 struct acpi_create_field_info *info); 290 struct acpi_create_field_info *info);
377 291
292
378/* 293/*
379 * exsystem - Interface to OS services 294 * exsystem - Interface to OS services
380 */ 295 */
381
382acpi_status 296acpi_status
383acpi_ex_system_do_notify_op ( 297acpi_ex_system_do_notify_op (
384 union acpi_operand_object *value, 298 union acpi_operand_object *value,
@@ -421,9 +335,8 @@ acpi_ex_system_wait_semaphore (
421 335
422 336
423/* 337/*
424 * exmonadic - ACPI AML (p-code) execution, monadic operators 338 * exoparg1 - ACPI AML execution, 1 operand
425 */ 339 */
426
427acpi_status 340acpi_status
428acpi_ex_opcode_0A_0T_1R ( 341acpi_ex_opcode_0A_0T_1R (
429 struct acpi_walk_state *walk_state); 342 struct acpi_walk_state *walk_state);
@@ -445,9 +358,8 @@ acpi_ex_opcode_1A_1T_0R (
445 struct acpi_walk_state *walk_state); 358 struct acpi_walk_state *walk_state);
446 359
447/* 360/*
448 * exdyadic - ACPI AML (p-code) execution, dyadic operators 361 * exoparg2 - ACPI AML execution, 2 operands
449 */ 362 */
450
451acpi_status 363acpi_status
452acpi_ex_opcode_2A_0T_0R ( 364acpi_ex_opcode_2A_0T_0R (
453 struct acpi_walk_state *walk_state); 365 struct acpi_walk_state *walk_state);
@@ -466,21 +378,56 @@ acpi_ex_opcode_2A_2T_1R (
466 378
467 379
468/* 380/*
469 * exresolv - Object resolution and get value functions 381 * exoparg3 - ACPI AML execution, 3 operands
382 */
383acpi_status
384acpi_ex_opcode_3A_0T_0R (
385 struct acpi_walk_state *walk_state);
386
387acpi_status
388acpi_ex_opcode_3A_1T_1R (
389 struct acpi_walk_state *walk_state);
390
391
392/*
393 * exoparg6 - ACPI AML execution, 6 operands
470 */ 394 */
395acpi_status
396acpi_ex_opcode_6A_0T_1R (
397 struct acpi_walk_state *walk_state);
398
471 399
400/*
401 * exresolv - Object resolution and get value functions
402 */
472acpi_status 403acpi_status
473acpi_ex_resolve_to_value ( 404acpi_ex_resolve_to_value (
474 union acpi_operand_object **stack_ptr, 405 union acpi_operand_object **stack_ptr,
475 struct acpi_walk_state *walk_state); 406 struct acpi_walk_state *walk_state);
476 407
477acpi_status 408acpi_status
409acpi_ex_resolve_multiple (
410 struct acpi_walk_state *walk_state,
411 union acpi_operand_object *operand,
412 acpi_object_type *return_type,
413 union acpi_operand_object **return_desc);
414
415
416/*
417 * exresnte - resolve namespace node
418 */
419acpi_status
478acpi_ex_resolve_node_to_value ( 420acpi_ex_resolve_node_to_value (
479 struct acpi_namespace_node **stack_ptr, 421 struct acpi_namespace_node **stack_ptr,
480 struct acpi_walk_state *walk_state); 422 struct acpi_walk_state *walk_state);
481 423
424
425/*
426 * exresop - resolve operand to value
427 */
482acpi_status 428acpi_status
483acpi_ex_resolve_object_to_value ( 429acpi_ex_resolve_operands (
430 u16 opcode,
484 union acpi_operand_object **stack_ptr, 431 union acpi_operand_object **stack_ptr,
485 struct acpi_walk_state *walk_state); 432 struct acpi_walk_state *walk_state);
486 433
@@ -488,7 +435,6 @@ acpi_ex_resolve_object_to_value (
488/* 435/*
489 * exdump - Interpreter debug output routines 436 * exdump - Interpreter debug output routines
490 */ 437 */
491
492void 438void
493acpi_ex_dump_operand ( 439acpi_ex_dump_operand (
494 union acpi_operand_object *obj_desc, 440 union acpi_operand_object *obj_desc,
@@ -504,7 +450,7 @@ acpi_ex_dump_operands (
504 char *module_name, 450 char *module_name,
505 u32 line_number); 451 u32 line_number);
506 452
507#ifdef ACPI_FUTURE_USAGE 453#ifdef ACPI_FUTURE_USAGE
508void 454void
509acpi_ex_dump_object_descriptor ( 455acpi_ex_dump_object_descriptor (
510 union acpi_operand_object *object, 456 union acpi_operand_object *object,
@@ -514,46 +460,12 @@ void
514acpi_ex_dump_node ( 460acpi_ex_dump_node (
515 struct acpi_namespace_node *node, 461 struct acpi_namespace_node *node,
516 u32 flags); 462 u32 flags);
463#endif /* ACPI_FUTURE_USAGE */
517 464
518void
519acpi_ex_out_string (
520 char *title,
521 char *value);
522
523void
524acpi_ex_out_pointer (
525 char *title,
526 void *value);
527
528void
529acpi_ex_out_integer (
530 char *title,
531 u32 value);
532
533void
534acpi_ex_out_address (
535 char *title,
536 acpi_physical_address value);
537#endif /* ACPI_FUTURE_USAGE */
538 465
539/* 466/*
540 * exnames - interpreter/scanner name load/execute 467 * exnames - AML namestring support
541 */ 468 */
542
543char *
544acpi_ex_allocate_name_string (
545 u32 prefix_count,
546 u32 num_name_segs);
547
548u32
549acpi_ex_good_char (
550 u32 character);
551
552acpi_status
553acpi_ex_name_segment (
554 u8 **in_aml_address,
555 char *name_string);
556
557acpi_status 469acpi_status
558acpi_ex_get_name_string ( 470acpi_ex_get_name_string (
559 acpi_object_type data_type, 471 acpi_object_type data_type,
@@ -561,16 +473,10 @@ acpi_ex_get_name_string (
561 char **out_name_string, 473 char **out_name_string,
562 u32 *out_name_length); 474 u32 *out_name_length);
563 475
564acpi_status
565acpi_ex_do_name (
566 acpi_object_type data_type,
567 acpi_interpreter_mode load_exec_mode);
568
569 476
570/* 477/*
571 * exstore - Object store support 478 * exstore - Object store support
572 */ 479 */
573
574acpi_status 480acpi_status
575acpi_ex_store ( 481acpi_ex_store (
576 union acpi_operand_object *val_desc, 482 union acpi_operand_object *val_desc,
@@ -578,12 +484,6 @@ acpi_ex_store (
578 struct acpi_walk_state *walk_state); 484 struct acpi_walk_state *walk_state);
579 485
580acpi_status 486acpi_status
581acpi_ex_store_object_to_index (
582 union acpi_operand_object *val_desc,
583 union acpi_operand_object *dest_desc,
584 struct acpi_walk_state *walk_state);
585
586acpi_status
587acpi_ex_store_object_to_node ( 487acpi_ex_store_object_to_node (
588 union acpi_operand_object *source_desc, 488 union acpi_operand_object *source_desc,
589 struct acpi_namespace_node *node, 489 struct acpi_namespace_node *node,
@@ -593,10 +493,10 @@ acpi_ex_store_object_to_node (
593#define ACPI_IMPLICIT_CONVERSION TRUE 493#define ACPI_IMPLICIT_CONVERSION TRUE
594#define ACPI_NO_IMPLICIT_CONVERSION FALSE 494#define ACPI_NO_IMPLICIT_CONVERSION FALSE
595 495
496
596/* 497/*
597 * exstoren 498 * exstoren - resolve/store object
598 */ 499 */
599
600acpi_status 500acpi_status
601acpi_ex_resolve_object ( 501acpi_ex_resolve_object (
602 union acpi_operand_object **source_desc_ptr, 502 union acpi_operand_object **source_desc_ptr,
@@ -612,9 +512,8 @@ acpi_ex_store_object_to_object (
612 512
613 513
614/* 514/*
615 * excopy - object copy 515 * exstorob - store object - buffer/string
616 */ 516 */
617
618acpi_status 517acpi_status
619acpi_ex_store_buffer_to_buffer ( 518acpi_ex_store_buffer_to_buffer (
620 union acpi_operand_object *source_desc, 519 union acpi_operand_object *source_desc,
@@ -625,6 +524,10 @@ acpi_ex_store_string_to_string (
625 union acpi_operand_object *source_desc, 524 union acpi_operand_object *source_desc,
626 union acpi_operand_object *target_desc); 525 union acpi_operand_object *target_desc);
627 526
527
528/*
529 * excopy - object copy
530 */
628acpi_status 531acpi_status
629acpi_ex_copy_integer_to_index_field ( 532acpi_ex_copy_integer_to_index_field (
630 union acpi_operand_object *source_desc, 533 union acpi_operand_object *source_desc,
@@ -645,10 +548,10 @@ acpi_ex_copy_integer_to_buffer_field (
645 union acpi_operand_object *source_desc, 548 union acpi_operand_object *source_desc,
646 union acpi_operand_object *target_desc); 549 union acpi_operand_object *target_desc);
647 550
551
648/* 552/*
649 * exutils - interpreter/scanner utilities 553 * exutils - interpreter/scanner utilities
650 */ 554 */
651
652acpi_status 555acpi_status
653acpi_ex_enter_interpreter ( 556acpi_ex_enter_interpreter (
654 void); 557 void);
@@ -669,11 +572,6 @@ void
669acpi_ex_release_global_lock ( 572acpi_ex_release_global_lock (
670 u8 locked); 573 u8 locked);
671 574
672u32
673acpi_ex_digits_needed (
674 acpi_integer value,
675 u32 base);
676
677void 575void
678acpi_ex_eisa_id_to_string ( 576acpi_ex_eisa_id_to_string (
679 u32 numeric_id, 577 u32 numeric_id,
@@ -688,7 +586,6 @@ acpi_ex_unsigned_integer_to_string (
688/* 586/*
689 * exregion - default op_region handlers 587 * exregion - default op_region handlers
690 */ 588 */
691
692acpi_status 589acpi_status
693acpi_ex_system_memory_space_handler ( 590acpi_ex_system_memory_space_handler (
694 u32 function, 591 u32 function,
diff --git a/include/acpi/aclocal.h b/include/acpi/aclocal.h
index 01d3b4bc0c85..030e641115cb 100644
--- a/include/acpi/aclocal.h
+++ b/include/acpi/aclocal.h
@@ -72,7 +72,6 @@ typedef u32 acpi_mutex_handle;
72 * 72 *
73 * NOTE: any changes here must be reflected in the acpi_gbl_mutex_names table also! 73 * NOTE: any changes here must be reflected in the acpi_gbl_mutex_names table also!
74 */ 74 */
75
76#define ACPI_MTX_EXECUTE 0 75#define ACPI_MTX_EXECUTE 0
77#define ACPI_MTX_INTERPRETER 1 76#define ACPI_MTX_INTERPRETER 1
78#define ACPI_MTX_PARSER 2 77#define ACPI_MTX_PARSER 2
@@ -151,13 +150,13 @@ typedef u16 acpi_owner_id;
151#define ACPI_FIELD_DWORD_GRANULARITY 4 150#define ACPI_FIELD_DWORD_GRANULARITY 4
152#define ACPI_FIELD_QWORD_GRANULARITY 8 151#define ACPI_FIELD_QWORD_GRANULARITY 8
153 152
153
154/***************************************************************************** 154/*****************************************************************************
155 * 155 *
156 * Namespace typedefs and structs 156 * Namespace typedefs and structs
157 * 157 *
158 ****************************************************************************/ 158 ****************************************************************************/
159 159
160
161/* Operational modes of the AML interpreter/scanner */ 160/* Operational modes of the AML interpreter/scanner */
162 161
163typedef enum 162typedef enum
@@ -176,7 +175,6 @@ typedef enum
176 * data_type is used to differentiate between internal descriptors, and MUST 175 * data_type is used to differentiate between internal descriptors, and MUST
177 * be the first byte in this structure. 176 * be the first byte in this structure.
178 */ 177 */
179
180union acpi_name_union 178union acpi_name_union
181{ 179{
182 u32 integer; 180 u32 integer;
@@ -415,7 +413,6 @@ struct acpi_field_info
415 * 413 *
416 ****************************************************************************/ 414 ****************************************************************************/
417 415
418
419#define ACPI_CONTROL_NORMAL 0xC0 416#define ACPI_CONTROL_NORMAL 0xC0
420#define ACPI_CONTROL_CONDITIONAL_EXECUTING 0xC1 417#define ACPI_CONTROL_CONDITIONAL_EXECUTING 0xC1
421#define ACPI_CONTROL_PREDICATE_EXECUTING 0xC2 418#define ACPI_CONTROL_PREDICATE_EXECUTING 0xC2
@@ -424,6 +421,7 @@ struct acpi_field_info
424 421
425 422
426/* Forward declarations */ 423/* Forward declarations */
424
427struct acpi_walk_state ; 425struct acpi_walk_state ;
428struct acpi_obj_mutex; 426struct acpi_obj_mutex;
429union acpi_parse_object ; 427union acpi_parse_object ;
@@ -601,7 +599,6 @@ struct acpi_opcode_info
601 u8 type; /* Opcode type */ 599 u8 type; /* Opcode type */
602}; 600};
603 601
604
605union acpi_parse_value 602union acpi_parse_value
606{ 603{
607 acpi_integer integer; /* Integer constant (Up to 64 bits) */ 604 acpi_integer integer; /* Integer constant (Up to 64 bits) */
@@ -613,7 +610,6 @@ union acpi_parse_value
613 union acpi_parse_object *arg; /* arguments and contained ops */ 610 union acpi_parse_object *arg; /* arguments and contained ops */
614}; 611};
615 612
616
617#define ACPI_PARSE_COMMON \ 613#define ACPI_PARSE_COMMON \
618 u8 data_type; /* To differentiate various internal objs */\ 614 u8 data_type; /* To differentiate various internal objs */\
619 u8 flags; /* Type of Op */\ 615 u8 flags; /* Type of Op */\
@@ -691,7 +687,6 @@ struct acpi_parse_obj_asl
691 char parse_op_name[12]; 687 char parse_op_name[12];
692}; 688};
693 689
694
695union acpi_parse_object 690union acpi_parse_object
696{ 691{
697 struct acpi_parse_obj_common common; 692 struct acpi_parse_obj_common common;
@@ -834,7 +829,6 @@ struct acpi_bit_register_info
834 * 829 *
835 ****************************************************************************/ 830 ****************************************************************************/
836 831
837
838/* resource_type values */ 832/* resource_type values */
839 833
840#define ACPI_RESOURCE_TYPE_MEMORY_RANGE 0 834#define ACPI_RESOURCE_TYPE_MEMORY_RANGE 0
diff --git a/include/acpi/acmacros.h b/include/acpi/acmacros.h
index fcaced16b16f..09be937d2c39 100644
--- a/include/acpi/acmacros.h
+++ b/include/acpi/acmacros.h
@@ -539,11 +539,6 @@
539 539
540 540
541#define ACPI_DUMP_ENTRY(a,b) acpi_ns_dump_entry (a,b) 541#define ACPI_DUMP_ENTRY(a,b) acpi_ns_dump_entry (a,b)
542
543#ifdef ACPI_FUTURE_USAGE
544#define ACPI_DUMP_TABLES(a,b) acpi_ns_dump_tables(a,b)
545#endif
546
547#define ACPI_DUMP_PATHNAME(a,b,c,d) acpi_ns_dump_pathname(a,b,c,d) 542#define ACPI_DUMP_PATHNAME(a,b,c,d) acpi_ns_dump_pathname(a,b,c,d)
548#define ACPI_DUMP_RESOURCE_LIST(a) acpi_rs_dump_resource_list(a) 543#define ACPI_DUMP_RESOURCE_LIST(a) acpi_rs_dump_resource_list(a)
549#define ACPI_DUMP_BUFFER(a,b) acpi_ut_dump_buffer((u8 *)a,b,DB_BYTE_DISPLAY,_COMPONENT) 544#define ACPI_DUMP_BUFFER(a,b) acpi_ut_dump_buffer((u8 *)a,b,DB_BYTE_DISPLAY,_COMPONENT)
@@ -596,11 +591,6 @@
596#define ACPI_DUMP_STACK_ENTRY(a) 591#define ACPI_DUMP_STACK_ENTRY(a)
597#define ACPI_DUMP_OPERANDS(a,b,c,d,e) 592#define ACPI_DUMP_OPERANDS(a,b,c,d,e)
598#define ACPI_DUMP_ENTRY(a,b) 593#define ACPI_DUMP_ENTRY(a,b)
599
600#ifdef ACPI_FUTURE_USAGE
601#define ACPI_DUMP_TABLES(a,b)
602#endif
603
604#define ACPI_DUMP_PATHNAME(a,b,c,d) 594#define ACPI_DUMP_PATHNAME(a,b,c,d)
605#define ACPI_DUMP_RESOURCE_LIST(a) 595#define ACPI_DUMP_RESOURCE_LIST(a)
606#define ACPI_DUMP_BUFFER(a,b) 596#define ACPI_DUMP_BUFFER(a,b)
diff --git a/include/acpi/acnames.h b/include/acpi/acnames.h
new file mode 100644
index 000000000000..deb7cb06f5f0
--- /dev/null
+++ b/include/acpi/acnames.h
@@ -0,0 +1,84 @@
1/******************************************************************************
2 *
3 * Name: acnames.h - Global names and strings
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2005, R. Byron Moore
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44#ifndef __ACNAMES_H__
45#define __ACNAMES_H__
46
47/* Method names - these methods can appear anywhere in the namespace */
48
49#define METHOD_NAME__HID "_HID"
50#define METHOD_NAME__CID "_CID"
51#define METHOD_NAME__UID "_UID"
52#define METHOD_NAME__ADR "_ADR"
53#define METHOD_NAME__INI "_INI"
54#define METHOD_NAME__STA "_STA"
55#define METHOD_NAME__REG "_REG"
56#define METHOD_NAME__SEG "_SEG"
57#define METHOD_NAME__BBN "_BBN"
58#define METHOD_NAME__PRT "_PRT"
59#define METHOD_NAME__CRS "_CRS"
60#define METHOD_NAME__PRS "_PRS"
61#define METHOD_NAME__PRW "_PRW"
62#define METHOD_NAME__SRS "_SRS"
63
64/* Method names - these methods must appear at the namespace root */
65
66#define METHOD_NAME__BFS "\\_BFS"
67#define METHOD_NAME__GTS "\\_GTS"
68#define METHOD_NAME__PTS "\\_PTS"
69#define METHOD_NAME__SST "\\_SI._SST"
70#define METHOD_NAME__WAK "\\_WAK"
71
72/* Definitions of the predefined namespace names */
73
74#define ACPI_UNKNOWN_NAME (u32) 0x3F3F3F3F /* Unknown name is "????" */
75#define ACPI_ROOT_NAME (u32) 0x5F5F5F5C /* Root name is "\___" */
76#define ACPI_SYS_BUS_NAME (u32) 0x5F53425F /* Sys bus name is "_SB_" */
77
78#define ACPI_NS_ROOT_PATH "\\"
79#define ACPI_NS_SYSTEM_BUS "_SB_"
80
81
82#endif /* __ACNAMES_H__ */
83
84
diff --git a/include/acpi/acnamesp.h b/include/acpi/acnamesp.h
index 8b3cdc3566b1..d1b3ce80056f 100644
--- a/include/acpi/acnamesp.h
+++ b/include/acpi/acnamesp.h
@@ -57,17 +57,6 @@
57#define ACPI_NS_NEWSCOPE 1 /* a definition of this type opens a name scope */ 57#define ACPI_NS_NEWSCOPE 1 /* a definition of this type opens a name scope */
58#define ACPI_NS_LOCAL 2 /* suppress search of enclosing scopes */ 58#define ACPI_NS_LOCAL 2 /* suppress search of enclosing scopes */
59 59
60
61/* Definitions of the predefined namespace names */
62
63#define ACPI_UNKNOWN_NAME (u32) 0x3F3F3F3F /* Unknown name is "????" */
64#define ACPI_ROOT_NAME (u32) 0x5F5F5F5C /* Root name is "\___" */
65#define ACPI_SYS_BUS_NAME (u32) 0x5F53425F /* Sys bus name is "_SB_" */
66
67#define ACPI_NS_ROOT_PATH "\\"
68#define ACPI_NS_SYSTEM_BUS "_SB_"
69
70
71/* Flags for acpi_ns_lookup, acpi_ns_search_and_enter */ 60/* Flags for acpi_ns_lookup, acpi_ns_search_and_enter */
72 61
73#define ACPI_NS_NO_UPSEARCH 0 62#define ACPI_NS_NO_UPSEARCH 0
@@ -80,10 +69,9 @@
80#define ACPI_NS_WALK_NO_UNLOCK FALSE 69#define ACPI_NS_WALK_NO_UNLOCK FALSE
81 70
82 71
83acpi_status 72/*
84acpi_ns_load_namespace ( 73 * nsinit - Namespace initialization
85 void); 74 */
86
87acpi_status 75acpi_status
88acpi_ns_initialize_objects ( 76acpi_ns_initialize_objects (
89 void); 77 void);
@@ -93,23 +81,22 @@ acpi_ns_initialize_devices (
93 void); 81 void);
94 82
95 83
96/* Namespace init - nsxfinit */ 84/*
97 85 * nsload - Namespace loading
86 */
98acpi_status 87acpi_status
99acpi_ns_init_one_device ( 88acpi_ns_load_namespace (
100 acpi_handle obj_handle, 89 void);
101 u32 nesting_level,
102 void *context,
103 void **return_value);
104 90
105acpi_status 91acpi_status
106acpi_ns_init_one_object ( 92acpi_ns_load_table (
107 acpi_handle obj_handle, 93 struct acpi_table_desc *table_desc,
108 u32 level, 94 struct acpi_namespace_node *node);
109 void *context,
110 void **return_value);
111 95
112 96
97/*
98 * nswalk - walk the namespace
99 */
113acpi_status 100acpi_status
114acpi_ns_walk_namespace ( 101acpi_ns_walk_namespace (
115 acpi_object_type type, 102 acpi_object_type type,
@@ -126,37 +113,24 @@ acpi_ns_get_next_node (
126 struct acpi_namespace_node *parent, 113 struct acpi_namespace_node *parent,
127 struct acpi_namespace_node *child); 114 struct acpi_namespace_node *child);
128 115
129void
130acpi_ns_delete_namespace_by_owner (
131 u16 table_id);
132
133
134/* Namespace loading - nsload */
135
136acpi_status
137acpi_ns_one_complete_parse (
138 u32 pass_number,
139 struct acpi_table_desc *table_desc);
140 116
117/*
118 * nsparse - table parsing
119 */
141acpi_status 120acpi_status
142acpi_ns_parse_table ( 121acpi_ns_parse_table (
143 struct acpi_table_desc *table_desc, 122 struct acpi_table_desc *table_desc,
144 struct acpi_namespace_node *scope); 123 struct acpi_namespace_node *scope);
145 124
146acpi_status 125acpi_status
147acpi_ns_load_table ( 126acpi_ns_one_complete_parse (
148 struct acpi_table_desc *table_desc, 127 u32 pass_number,
149 struct acpi_namespace_node *node); 128 struct acpi_table_desc *table_desc);
150
151acpi_status
152acpi_ns_load_table_by_type (
153 acpi_table_type table_type);
154 129
155 130
156/* 131/*
157 * Top-level namespace access - nsaccess 132 * nsaccess - Top-level namespace access
158 */ 133 */
159
160acpi_status 134acpi_status
161acpi_ns_root_initialize ( 135acpi_ns_root_initialize (
162 void); 136 void);
@@ -173,9 +147,8 @@ acpi_ns_lookup (
173 147
174 148
175/* 149/*
176 * Named object allocation/deallocation - nsalloc 150 * nsalloc - Named object allocation/deallocation
177 */ 151 */
178
179struct acpi_namespace_node * 152struct acpi_namespace_node *
180acpi_ns_create_node ( 153acpi_ns_create_node (
181 u32 name); 154 u32 name);
@@ -189,6 +162,10 @@ acpi_ns_delete_namespace_subtree (
189 struct acpi_namespace_node *parent_handle); 162 struct acpi_namespace_node *parent_handle);
190 163
191void 164void
165acpi_ns_delete_namespace_by_owner (
166 u16 table_id);
167
168void
192acpi_ns_detach_object ( 169acpi_ns_detach_object (
193 struct acpi_namespace_node *node); 170 struct acpi_namespace_node *node);
194 171
@@ -201,36 +178,16 @@ acpi_ns_compare_names (
201 char *name1, 178 char *name1,
202 char *name2); 179 char *name2);
203 180
204void
205acpi_ns_remove_reference (
206 struct acpi_namespace_node *node);
207
208 181
209/* 182/*
210 * Namespace modification - nsmodify 183 * nsdump - Namespace dump/print utilities
211 */ 184 */
212 185#ifdef ACPI_FUTURE_USAGE
213#ifdef ACPI_FUTURE_USAGE
214acpi_status
215acpi_ns_unload_namespace (
216 acpi_handle handle);
217
218acpi_status
219acpi_ns_delete_subtree (
220 acpi_handle start_handle);
221#endif
222
223
224/*
225 * Namespace dump/print utilities - nsdump
226 */
227
228#ifdef ACPI_FUTURE_USAGE
229void 186void
230acpi_ns_dump_tables ( 187acpi_ns_dump_tables (
231 acpi_handle search_base, 188 acpi_handle search_base,
232 u32 max_depth); 189 u32 max_depth);
233#endif 190#endif /* ACPI_FUTURE_USAGE */
234 191
235void 192void
236acpi_ns_dump_entry ( 193acpi_ns_dump_entry (
@@ -249,19 +206,6 @@ acpi_ns_print_pathname (
249 u32 num_segments, 206 u32 num_segments,
250 char *pathname); 207 char *pathname);
251 208
252#ifdef ACPI_FUTURE_USAGE
253acpi_status
254acpi_ns_dump_one_device (
255 acpi_handle obj_handle,
256 u32 level,
257 void *context,
258 void **return_value);
259
260void
261acpi_ns_dump_root_devices (
262 void);
263#endif /* ACPI_FUTURE_USAGE */
264
265acpi_status 209acpi_status
266acpi_ns_dump_one_object ( 210acpi_ns_dump_one_object (
267 acpi_handle obj_handle, 211 acpi_handle obj_handle,
@@ -269,7 +213,7 @@ acpi_ns_dump_one_object (
269 void *context, 213 void *context,
270 void **return_value); 214 void **return_value);
271 215
272#ifdef ACPI_FUTURE_USAGE 216#ifdef ACPI_FUTURE_USAGE
273void 217void
274acpi_ns_dump_objects ( 218acpi_ns_dump_objects (
275 acpi_object_type type, 219 acpi_object_type type,
@@ -277,13 +221,12 @@ acpi_ns_dump_objects (
277 u32 max_depth, 221 u32 max_depth,
278 u32 ownder_id, 222 u32 ownder_id,
279 acpi_handle start_handle); 223 acpi_handle start_handle);
280#endif 224#endif /* ACPI_FUTURE_USAGE */
281 225
282 226
283/* 227/*
284 * Namespace evaluation functions - nseval 228 * nseval - Namespace evaluation functions
285 */ 229 */
286
287acpi_status 230acpi_status
288acpi_ns_evaluate_by_handle ( 231acpi_ns_evaluate_by_handle (
289 struct acpi_parameter_info *info); 232 struct acpi_parameter_info *info);
@@ -298,40 +241,14 @@ acpi_ns_evaluate_relative (
298 char *pathname, 241 char *pathname,
299 struct acpi_parameter_info *info); 242 struct acpi_parameter_info *info);
300 243
301acpi_status
302acpi_ns_execute_control_method (
303 struct acpi_parameter_info *info);
304
305acpi_status
306acpi_ns_get_object_value (
307 struct acpi_parameter_info *info);
308
309
310/*
311 * Parent/Child/Peer utility functions
312 */
313
314#ifdef ACPI_FUTURE_USAGE
315acpi_name
316acpi_ns_find_parent_name (
317 struct acpi_namespace_node *node_to_search);
318#endif
319
320 244
321/* 245/*
322 * Name and Scope manipulation - nsnames 246 * nsnames - Name and Scope manipulation
323 */ 247 */
324
325u32 248u32
326acpi_ns_opens_scope ( 249acpi_ns_opens_scope (
327 acpi_object_type type); 250 acpi_object_type type);
328 251
329void
330acpi_ns_build_external_path (
331 struct acpi_namespace_node *node,
332 acpi_size size,
333 char *name_buffer);
334
335char * 252char *
336acpi_ns_get_external_pathname ( 253acpi_ns_get_external_pathname (
337 struct acpi_namespace_node *node); 254 struct acpi_namespace_node *node);
@@ -363,9 +280,8 @@ acpi_ns_get_pathname_length (
363 280
364 281
365/* 282/*
366 * Object management for namespace nodes - nsobject 283 * nsobject - Object management for namespace nodes
367 */ 284 */
368
369acpi_status 285acpi_status
370acpi_ns_attach_object ( 286acpi_ns_attach_object (
371 struct acpi_namespace_node *node, 287 struct acpi_namespace_node *node,
@@ -399,9 +315,8 @@ acpi_ns_get_attached_data (
399 315
400 316
401/* 317/*
402 * Namespace searching and entry - nssearch 318 * nssearch - Namespace searching and entry
403 */ 319 */
404
405acpi_status 320acpi_status
406acpi_ns_search_and_enter ( 321acpi_ns_search_and_enter (
407 u32 entry_name, 322 u32 entry_name,
@@ -428,17 +343,12 @@ acpi_ns_install_node (
428 343
429 344
430/* 345/*
431 * Utility functions - nsutils 346 * nsutils - Utility functions
432 */ 347 */
433
434u8 348u8
435acpi_ns_valid_root_prefix ( 349acpi_ns_valid_root_prefix (
436 char prefix); 350 char prefix);
437 351
438u8
439acpi_ns_valid_path_separator (
440 char sep);
441
442acpi_object_type 352acpi_object_type
443acpi_ns_get_type ( 353acpi_ns_get_type (
444 struct acpi_namespace_node *node); 354 struct acpi_namespace_node *node);
@@ -511,5 +421,4 @@ struct acpi_namespace_node *
511acpi_ns_get_next_valid_node ( 421acpi_ns_get_next_valid_node (
512 struct acpi_namespace_node *node); 422 struct acpi_namespace_node *node);
513 423
514
515#endif /* __ACNAMESP_H__ */ 424#endif /* __ACNAMESP_H__ */
diff --git a/include/acpi/acobject.h b/include/acpi/acobject.h
index 036023a940b2..e079b94e4fce 100644
--- a/include/acpi/acobject.h
+++ b/include/acpi/acobject.h
@@ -133,6 +133,7 @@ struct acpi_object_integer
133 acpi_integer value; 133 acpi_integer value;
134}; 134};
135 135
136
136/* 137/*
137 * Note: The String and Buffer object must be identical through the Pointer 138 * Note: The String and Buffer object must be identical through the Pointer
138 * element. There is code that depends on this. 139 * element. There is code that depends on this.
@@ -468,7 +469,6 @@ union acpi_operand_object
468 * 469 *
469 *****************************************************************************/ 470 *****************************************************************************/
470 471
471
472/* Object descriptor types */ 472/* Object descriptor types */
473 473
474#define ACPI_DESC_TYPE_CACHED 0x01 /* Used only when object is cached */ 474#define ACPI_DESC_TYPE_CACHED 0x01 /* Used only when object is cached */
diff --git a/include/acpi/acopcode.h b/include/acpi/acopcode.h
new file mode 100644
index 000000000000..118ecba4cf05
--- /dev/null
+++ b/include/acpi/acopcode.h
@@ -0,0 +1,325 @@
1/******************************************************************************
2 *
3 * Name: acopcode.h - AML opcode information for the AML parser and interpreter
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2005, R. Byron Moore
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44#ifndef __ACOPCODE_H__
45#define __ACOPCODE_H__
46
47#define MAX_EXTENDED_OPCODE 0x88
48#define NUM_EXTENDED_OPCODE (MAX_EXTENDED_OPCODE + 1)
49#define MAX_INTERNAL_OPCODE
50#define NUM_INTERNAL_OPCODE (MAX_INTERNAL_OPCODE + 1)
51
52/* Used for non-assigned opcodes */
53
54#define _UNK 0x6B
55
56/*
57 * Reserved ASCII characters. Do not use any of these for
58 * internal opcodes, since they are used to differentiate
59 * name strings from AML opcodes
60 */
61#define _ASC 0x6C
62#define _NAM 0x6C
63#define _PFX 0x6D
64
65
66/*
67 * All AML opcodes and the parse-time arguments for each. Used by the AML
68 * parser Each list is compressed into a 32-bit number and stored in the
69 * master opcode table (in psopcode.c).
70 */
71#define ARGP_ACCESSFIELD_OP ARGP_LIST1 (ARGP_NAMESTRING)
72#define ARGP_ACQUIRE_OP ARGP_LIST2 (ARGP_SUPERNAME, ARGP_WORDDATA)
73#define ARGP_ADD_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
74#define ARGP_ALIAS_OP ARGP_LIST2 (ARGP_NAMESTRING, ARGP_NAME)
75#define ARGP_ARG0 ARG_NONE
76#define ARGP_ARG1 ARG_NONE
77#define ARGP_ARG2 ARG_NONE
78#define ARGP_ARG3 ARG_NONE
79#define ARGP_ARG4 ARG_NONE
80#define ARGP_ARG5 ARG_NONE
81#define ARGP_ARG6 ARG_NONE
82#define ARGP_BANK_FIELD_OP ARGP_LIST6 (ARGP_PKGLENGTH, ARGP_NAMESTRING, ARGP_NAMESTRING,ARGP_TERMARG, ARGP_BYTEDATA, ARGP_FIELDLIST)
83#define ARGP_BIT_AND_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
84#define ARGP_BIT_NAND_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
85#define ARGP_BIT_NOR_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
86#define ARGP_BIT_NOT_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TARGET)
87#define ARGP_BIT_OR_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
88#define ARGP_BIT_XOR_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
89#define ARGP_BREAK_OP ARG_NONE
90#define ARGP_BREAK_POINT_OP ARG_NONE
91#define ARGP_BUFFER_OP ARGP_LIST3 (ARGP_PKGLENGTH, ARGP_TERMARG, ARGP_BYTELIST)
92#define ARGP_BYTE_OP ARGP_LIST1 (ARGP_BYTEDATA)
93#define ARGP_BYTELIST_OP ARGP_LIST1 (ARGP_NAMESTRING)
94#define ARGP_CONCAT_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
95#define ARGP_CONCAT_RES_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
96#define ARGP_COND_REF_OF_OP ARGP_LIST2 (ARGP_SUPERNAME, ARGP_SUPERNAME)
97#define ARGP_CONTINUE_OP ARG_NONE
98#define ARGP_COPY_OP ARGP_LIST2 (ARGP_SUPERNAME, ARGP_SIMPLENAME)
99#define ARGP_CREATE_BIT_FIELD_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_NAME)
100#define ARGP_CREATE_BYTE_FIELD_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_NAME)
101#define ARGP_CREATE_DWORD_FIELD_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_NAME)
102#define ARGP_CREATE_FIELD_OP ARGP_LIST4 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TERMARG, ARGP_NAME)
103#define ARGP_CREATE_QWORD_FIELD_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_NAME)
104#define ARGP_CREATE_WORD_FIELD_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_NAME)
105#define ARGP_DATA_REGION_OP ARGP_LIST4 (ARGP_NAME, ARGP_TERMARG, ARGP_TERMARG, ARGP_TERMARG)
106#define ARGP_DEBUG_OP ARG_NONE
107#define ARGP_DECREMENT_OP ARGP_LIST1 (ARGP_SUPERNAME)
108#define ARGP_DEREF_OF_OP ARGP_LIST1 (ARGP_TERMARG)
109#define ARGP_DEVICE_OP ARGP_LIST3 (ARGP_PKGLENGTH, ARGP_NAME, ARGP_OBJLIST)
110#define ARGP_DIVIDE_OP ARGP_LIST4 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET, ARGP_TARGET)
111#define ARGP_DWORD_OP ARGP_LIST1 (ARGP_DWORDDATA)
112#define ARGP_ELSE_OP ARGP_LIST2 (ARGP_PKGLENGTH, ARGP_TERMLIST)
113#define ARGP_EVENT_OP ARGP_LIST1 (ARGP_NAME)
114#define ARGP_FATAL_OP ARGP_LIST3 (ARGP_BYTEDATA, ARGP_DWORDDATA, ARGP_TERMARG)
115#define ARGP_FIELD_OP ARGP_LIST4 (ARGP_PKGLENGTH, ARGP_NAMESTRING, ARGP_BYTEDATA, ARGP_FIELDLIST)
116#define ARGP_FIND_SET_LEFT_BIT_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TARGET)
117#define ARGP_FIND_SET_RIGHT_BIT_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TARGET)
118#define ARGP_FROM_BCD_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TARGET)
119#define ARGP_IF_OP ARGP_LIST3 (ARGP_PKGLENGTH, ARGP_TERMARG, ARGP_TERMLIST)
120#define ARGP_INCREMENT_OP ARGP_LIST1 (ARGP_SUPERNAME)
121#define ARGP_INDEX_FIELD_OP ARGP_LIST5 (ARGP_PKGLENGTH, ARGP_NAMESTRING, ARGP_NAMESTRING,ARGP_BYTEDATA, ARGP_FIELDLIST)
122#define ARGP_INDEX_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
123#define ARGP_LAND_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TERMARG)
124#define ARGP_LEQUAL_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TERMARG)
125#define ARGP_LGREATER_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TERMARG)
126#define ARGP_LGREATEREQUAL_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TERMARG)
127#define ARGP_LLESS_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TERMARG)
128#define ARGP_LLESSEQUAL_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TERMARG)
129#define ARGP_LNOT_OP ARGP_LIST1 (ARGP_TERMARG)
130#define ARGP_LNOTEQUAL_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TERMARG)
131#define ARGP_LOAD_OP ARGP_LIST2 (ARGP_NAMESTRING, ARGP_SUPERNAME)
132#define ARGP_LOAD_TABLE_OP ARGP_LIST6 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TERMARG, ARGP_TERMARG, ARGP_TERMARG, ARGP_TERMARG)
133#define ARGP_LOCAL0 ARG_NONE
134#define ARGP_LOCAL1 ARG_NONE
135#define ARGP_LOCAL2 ARG_NONE
136#define ARGP_LOCAL3 ARG_NONE
137#define ARGP_LOCAL4 ARG_NONE
138#define ARGP_LOCAL5 ARG_NONE
139#define ARGP_LOCAL6 ARG_NONE
140#define ARGP_LOCAL7 ARG_NONE
141#define ARGP_LOR_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TERMARG)
142#define ARGP_MATCH_OP ARGP_LIST6 (ARGP_TERMARG, ARGP_BYTEDATA, ARGP_TERMARG, ARGP_BYTEDATA, ARGP_TERMARG, ARGP_TERMARG)
143#define ARGP_METHOD_OP ARGP_LIST4 (ARGP_PKGLENGTH, ARGP_NAME, ARGP_BYTEDATA, ARGP_TERMLIST)
144#define ARGP_METHODCALL_OP ARGP_LIST1 (ARGP_NAMESTRING)
145#define ARGP_MID_OP ARGP_LIST4 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
146#define ARGP_MOD_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
147#define ARGP_MULTIPLY_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
148#define ARGP_MUTEX_OP ARGP_LIST2 (ARGP_NAME, ARGP_BYTEDATA)
149#define ARGP_NAME_OP ARGP_LIST2 (ARGP_NAME, ARGP_DATAOBJ)
150#define ARGP_NAMEDFIELD_OP ARGP_LIST1 (ARGP_NAMESTRING)
151#define ARGP_NAMEPATH_OP ARGP_LIST1 (ARGP_NAMESTRING)
152#define ARGP_NOOP_OP ARG_NONE
153#define ARGP_NOTIFY_OP ARGP_LIST2 (ARGP_SUPERNAME, ARGP_TERMARG)
154#define ARGP_ONE_OP ARG_NONE
155#define ARGP_ONES_OP ARG_NONE
156#define ARGP_PACKAGE_OP ARGP_LIST3 (ARGP_PKGLENGTH, ARGP_BYTEDATA, ARGP_DATAOBJLIST)
157#define ARGP_POWER_RES_OP ARGP_LIST5 (ARGP_PKGLENGTH, ARGP_NAME, ARGP_BYTEDATA, ARGP_WORDDATA, ARGP_OBJLIST)
158#define ARGP_PROCESSOR_OP ARGP_LIST6 (ARGP_PKGLENGTH, ARGP_NAME, ARGP_BYTEDATA, ARGP_DWORDDATA, ARGP_BYTEDATA, ARGP_OBJLIST)
159#define ARGP_QWORD_OP ARGP_LIST1 (ARGP_QWORDDATA)
160#define ARGP_REF_OF_OP ARGP_LIST1 (ARGP_SUPERNAME)
161#define ARGP_REGION_OP ARGP_LIST4 (ARGP_NAME, ARGP_BYTEDATA, ARGP_TERMARG, ARGP_TERMARG)
162#define ARGP_RELEASE_OP ARGP_LIST1 (ARGP_SUPERNAME)
163#define ARGP_RESERVEDFIELD_OP ARGP_LIST1 (ARGP_NAMESTRING)
164#define ARGP_RESET_OP ARGP_LIST1 (ARGP_SUPERNAME)
165#define ARGP_RETURN_OP ARGP_LIST1 (ARGP_TERMARG)
166#define ARGP_REVISION_OP ARG_NONE
167#define ARGP_SCOPE_OP ARGP_LIST3 (ARGP_PKGLENGTH, ARGP_NAME, ARGP_TERMLIST)
168#define ARGP_SHIFT_LEFT_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
169#define ARGP_SHIFT_RIGHT_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
170#define ARGP_SIGNAL_OP ARGP_LIST1 (ARGP_SUPERNAME)
171#define ARGP_SIZE_OF_OP ARGP_LIST1 (ARGP_SUPERNAME)
172#define ARGP_SLEEP_OP ARGP_LIST1 (ARGP_TERMARG)
173#define ARGP_STALL_OP ARGP_LIST1 (ARGP_TERMARG)
174#define ARGP_STATICSTRING_OP ARGP_LIST1 (ARGP_NAMESTRING)
175#define ARGP_STORE_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_SUPERNAME)
176#define ARGP_STRING_OP ARGP_LIST1 (ARGP_CHARLIST)
177#define ARGP_SUBTRACT_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
178#define ARGP_THERMAL_ZONE_OP ARGP_LIST3 (ARGP_PKGLENGTH, ARGP_NAME, ARGP_OBJLIST)
179#define ARGP_TIMER_OP ARG_NONE
180#define ARGP_TO_BCD_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TARGET)
181#define ARGP_TO_BUFFER_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TARGET)
182#define ARGP_TO_DEC_STR_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TARGET)
183#define ARGP_TO_HEX_STR_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TARGET)
184#define ARGP_TO_INTEGER_OP ARGP_LIST2 (ARGP_TERMARG, ARGP_TARGET)
185#define ARGP_TO_STRING_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
186#define ARGP_TYPE_OP ARGP_LIST1 (ARGP_SUPERNAME)
187#define ARGP_UNLOAD_OP ARGP_LIST1 (ARGP_SUPERNAME)
188#define ARGP_VAR_PACKAGE_OP ARGP_LIST3 (ARGP_PKGLENGTH, ARGP_TERMARG, ARGP_DATAOBJLIST)
189#define ARGP_WAIT_OP ARGP_LIST2 (ARGP_SUPERNAME, ARGP_TERMARG)
190#define ARGP_WHILE_OP ARGP_LIST3 (ARGP_PKGLENGTH, ARGP_TERMARG, ARGP_TERMLIST)
191#define ARGP_WORD_OP ARGP_LIST1 (ARGP_WORDDATA)
192#define ARGP_ZERO_OP ARG_NONE
193
194
195/*
196 * All AML opcodes and the runtime arguments for each. Used by the AML
197 * interpreter Each list is compressed into a 32-bit number and stored
198 * in the master opcode table (in psopcode.c).
199 *
200 * (Used by prep_operands procedure and the ASL Compiler)
201 */
202#define ARGI_ACCESSFIELD_OP ARGI_INVALID_OPCODE
203#define ARGI_ACQUIRE_OP ARGI_LIST2 (ARGI_MUTEX, ARGI_INTEGER)
204#define ARGI_ADD_OP ARGI_LIST3 (ARGI_INTEGER, ARGI_INTEGER, ARGI_TARGETREF)
205#define ARGI_ALIAS_OP ARGI_INVALID_OPCODE
206#define ARGI_ARG0 ARG_NONE
207#define ARGI_ARG1 ARG_NONE
208#define ARGI_ARG2 ARG_NONE
209#define ARGI_ARG3 ARG_NONE
210#define ARGI_ARG4 ARG_NONE
211#define ARGI_ARG5 ARG_NONE
212#define ARGI_ARG6 ARG_NONE
213#define ARGI_BANK_FIELD_OP ARGI_INVALID_OPCODE
214#define ARGI_BIT_AND_OP ARGI_LIST3 (ARGI_INTEGER, ARGI_INTEGER, ARGI_TARGETREF)
215#define ARGI_BIT_NAND_OP ARGI_LIST3 (ARGI_INTEGER, ARGI_INTEGER, ARGI_TARGETREF)
216#define ARGI_BIT_NOR_OP ARGI_LIST3 (ARGI_INTEGER, ARGI_INTEGER, ARGI_TARGETREF)
217#define ARGI_BIT_NOT_OP ARGI_LIST2 (ARGI_INTEGER, ARGI_TARGETREF)
218#define ARGI_BIT_OR_OP ARGI_LIST3 (ARGI_INTEGER, ARGI_INTEGER, ARGI_TARGETREF)
219#define ARGI_BIT_XOR_OP ARGI_LIST3 (ARGI_INTEGER, ARGI_INTEGER, ARGI_TARGETREF)
220#define ARGI_BREAK_OP ARG_NONE
221#define ARGI_BREAK_POINT_OP ARG_NONE
222#define ARGI_BUFFER_OP ARGI_LIST1 (ARGI_INTEGER)
223#define ARGI_BYTE_OP ARGI_INVALID_OPCODE
224#define ARGI_BYTELIST_OP ARGI_INVALID_OPCODE
225#define ARGI_CONCAT_OP ARGI_LIST3 (ARGI_COMPUTEDATA,ARGI_COMPUTEDATA, ARGI_TARGETREF)
226#define ARGI_CONCAT_RES_OP ARGI_LIST3 (ARGI_BUFFER, ARGI_BUFFER, ARGI_TARGETREF)
227#define ARGI_COND_REF_OF_OP ARGI_LIST2 (ARGI_OBJECT_REF, ARGI_TARGETREF)
228#define ARGI_CONTINUE_OP ARGI_INVALID_OPCODE
229#define ARGI_COPY_OP ARGI_LIST2 (ARGI_ANYTYPE, ARGI_SIMPLE_TARGET)
230#define ARGI_CREATE_BIT_FIELD_OP ARGI_LIST3 (ARGI_BUFFER, ARGI_INTEGER, ARGI_REFERENCE)
231#define ARGI_CREATE_BYTE_FIELD_OP ARGI_LIST3 (ARGI_BUFFER, ARGI_INTEGER, ARGI_REFERENCE)
232#define ARGI_CREATE_DWORD_FIELD_OP ARGI_LIST3 (ARGI_BUFFER, ARGI_INTEGER, ARGI_REFERENCE)
233#define ARGI_CREATE_FIELD_OP ARGI_LIST4 (ARGI_BUFFER, ARGI_INTEGER, ARGI_INTEGER, ARGI_REFERENCE)
234#define ARGI_CREATE_QWORD_FIELD_OP ARGI_LIST3 (ARGI_BUFFER, ARGI_INTEGER, ARGI_REFERENCE)
235#define ARGI_CREATE_WORD_FIELD_OP ARGI_LIST3 (ARGI_BUFFER, ARGI_INTEGER, ARGI_REFERENCE)
236#define ARGI_DATA_REGION_OP ARGI_LIST3 (ARGI_STRING, ARGI_STRING, ARGI_STRING)
237#define ARGI_DEBUG_OP ARG_NONE
238#define ARGI_DECREMENT_OP ARGI_LIST1 (ARGI_INTEGER_REF)
239#define ARGI_DEREF_OF_OP ARGI_LIST1 (ARGI_REF_OR_STRING)
240#define ARGI_DEVICE_OP ARGI_INVALID_OPCODE
241#define ARGI_DIVIDE_OP ARGI_LIST4 (ARGI_INTEGER, ARGI_INTEGER, ARGI_TARGETREF, ARGI_TARGETREF)
242#define ARGI_DWORD_OP ARGI_INVALID_OPCODE
243#define ARGI_ELSE_OP ARGI_INVALID_OPCODE
244#define ARGI_EVENT_OP ARGI_INVALID_OPCODE
245#define ARGI_FATAL_OP ARGI_LIST3 (ARGI_INTEGER, ARGI_INTEGER, ARGI_INTEGER)
246#define ARGI_FIELD_OP ARGI_INVALID_OPCODE
247#define ARGI_FIND_SET_LEFT_BIT_OP ARGI_LIST2 (ARGI_INTEGER, ARGI_TARGETREF)
248#define ARGI_FIND_SET_RIGHT_BIT_OP ARGI_LIST2 (ARGI_INTEGER, ARGI_TARGETREF)
249#define ARGI_FROM_BCD_OP ARGI_LIST2 (ARGI_INTEGER, ARGI_TARGETREF)
250#define ARGI_IF_OP ARGI_INVALID_OPCODE
251#define ARGI_INCREMENT_OP ARGI_LIST1 (ARGI_INTEGER_REF)
252#define ARGI_INDEX_FIELD_OP ARGI_INVALID_OPCODE
253#define ARGI_INDEX_OP ARGI_LIST3 (ARGI_COMPLEXOBJ, ARGI_INTEGER, ARGI_TARGETREF)
254#define ARGI_LAND_OP ARGI_LIST2 (ARGI_INTEGER, ARGI_INTEGER)
255#define ARGI_LEQUAL_OP ARGI_LIST2 (ARGI_COMPUTEDATA,ARGI_COMPUTEDATA)
256#define ARGI_LGREATER_OP ARGI_LIST2 (ARGI_COMPUTEDATA,ARGI_COMPUTEDATA)
257#define ARGI_LGREATEREQUAL_OP ARGI_INVALID_OPCODE
258#define ARGI_LLESS_OP ARGI_LIST2 (ARGI_COMPUTEDATA,ARGI_COMPUTEDATA)
259#define ARGI_LLESSEQUAL_OP ARGI_INVALID_OPCODE
260#define ARGI_LNOT_OP ARGI_LIST1 (ARGI_INTEGER)
261#define ARGI_LNOTEQUAL_OP ARGI_INVALID_OPCODE
262#define ARGI_LOAD_OP ARGI_LIST2 (ARGI_REGION_OR_FIELD,ARGI_TARGETREF)
263#define ARGI_LOAD_TABLE_OP ARGI_LIST6 (ARGI_STRING, ARGI_STRING, ARGI_STRING, ARGI_STRING, ARGI_STRING, ARGI_ANYTYPE)
264#define ARGI_LOCAL0 ARG_NONE
265#define ARGI_LOCAL1 ARG_NONE
266#define ARGI_LOCAL2 ARG_NONE
267#define ARGI_LOCAL3 ARG_NONE
268#define ARGI_LOCAL4 ARG_NONE
269#define ARGI_LOCAL5 ARG_NONE
270#define ARGI_LOCAL6 ARG_NONE
271#define ARGI_LOCAL7 ARG_NONE
272#define ARGI_LOR_OP ARGI_LIST2 (ARGI_INTEGER, ARGI_INTEGER)
273#define ARGI_MATCH_OP ARGI_LIST6 (ARGI_PACKAGE, ARGI_INTEGER, ARGI_COMPUTEDATA, ARGI_INTEGER,ARGI_COMPUTEDATA,ARGI_INTEGER)
274#define ARGI_METHOD_OP ARGI_INVALID_OPCODE
275#define ARGI_METHODCALL_OP ARGI_INVALID_OPCODE
276#define ARGI_MID_OP ARGI_LIST4 (ARGI_BUFFER_OR_STRING,ARGI_INTEGER, ARGI_INTEGER, ARGI_TARGETREF)
277#define ARGI_MOD_OP ARGI_LIST3 (ARGI_INTEGER, ARGI_INTEGER, ARGI_TARGETREF)
278#define ARGI_MULTIPLY_OP ARGI_LIST3 (ARGI_INTEGER, ARGI_INTEGER, ARGI_TARGETREF)
279#define ARGI_MUTEX_OP ARGI_INVALID_OPCODE
280#define ARGI_NAME_OP ARGI_INVALID_OPCODE
281#define ARGI_NAMEDFIELD_OP ARGI_INVALID_OPCODE
282#define ARGI_NAMEPATH_OP ARGI_INVALID_OPCODE
283#define ARGI_NOOP_OP ARG_NONE
284#define ARGI_NOTIFY_OP ARGI_LIST2 (ARGI_DEVICE_REF, ARGI_INTEGER)
285#define ARGI_ONE_OP ARG_NONE
286#define ARGI_ONES_OP ARG_NONE
287#define ARGI_PACKAGE_OP ARGI_LIST1 (ARGI_INTEGER)
288#define ARGI_POWER_RES_OP ARGI_INVALID_OPCODE
289#define ARGI_PROCESSOR_OP ARGI_INVALID_OPCODE
290#define ARGI_QWORD_OP ARGI_INVALID_OPCODE
291#define ARGI_REF_OF_OP ARGI_LIST1 (ARGI_OBJECT_REF)
292#define ARGI_REGION_OP ARGI_LIST2 (ARGI_INTEGER, ARGI_INTEGER)
293#define ARGI_RELEASE_OP ARGI_LIST1 (ARGI_MUTEX)
294#define ARGI_RESERVEDFIELD_OP ARGI_INVALID_OPCODE
295#define ARGI_RESET_OP ARGI_LIST1 (ARGI_EVENT)
296#define ARGI_RETURN_OP ARGI_INVALID_OPCODE
297#define ARGI_REVISION_OP ARG_NONE
298#define ARGI_SCOPE_OP ARGI_INVALID_OPCODE
299#define ARGI_SHIFT_LEFT_OP ARGI_LIST3 (ARGI_INTEGER, ARGI_INTEGER, ARGI_TARGETREF)
300#define ARGI_SHIFT_RIGHT_OP ARGI_LIST3 (ARGI_INTEGER, ARGI_INTEGER, ARGI_TARGETREF)
301#define ARGI_SIGNAL_OP ARGI_LIST1 (ARGI_EVENT)
302#define ARGI_SIZE_OF_OP ARGI_LIST1 (ARGI_DATAOBJECT)
303#define ARGI_SLEEP_OP ARGI_LIST1 (ARGI_INTEGER)
304#define ARGI_STALL_OP ARGI_LIST1 (ARGI_INTEGER)
305#define ARGI_STATICSTRING_OP ARGI_INVALID_OPCODE
306#define ARGI_STORE_OP ARGI_LIST2 (ARGI_DATAREFOBJ, ARGI_TARGETREF)
307#define ARGI_STRING_OP ARGI_INVALID_OPCODE
308#define ARGI_SUBTRACT_OP ARGI_LIST3 (ARGI_INTEGER, ARGI_INTEGER, ARGI_TARGETREF)
309#define ARGI_THERMAL_ZONE_OP ARGI_INVALID_OPCODE
310#define ARGI_TIMER_OP ARG_NONE
311#define ARGI_TO_BCD_OP ARGI_LIST2 (ARGI_INTEGER, ARGI_FIXED_TARGET)
312#define ARGI_TO_BUFFER_OP ARGI_LIST2 (ARGI_COMPUTEDATA,ARGI_FIXED_TARGET)
313#define ARGI_TO_DEC_STR_OP ARGI_LIST2 (ARGI_COMPUTEDATA,ARGI_FIXED_TARGET)
314#define ARGI_TO_HEX_STR_OP ARGI_LIST2 (ARGI_COMPUTEDATA,ARGI_FIXED_TARGET)
315#define ARGI_TO_INTEGER_OP ARGI_LIST2 (ARGI_COMPUTEDATA,ARGI_FIXED_TARGET)
316#define ARGI_TO_STRING_OP ARGI_LIST3 (ARGI_BUFFER, ARGI_INTEGER, ARGI_FIXED_TARGET)
317#define ARGI_TYPE_OP ARGI_LIST1 (ARGI_ANYTYPE)
318#define ARGI_UNLOAD_OP ARGI_LIST1 (ARGI_DDBHANDLE)
319#define ARGI_VAR_PACKAGE_OP ARGI_LIST1 (ARGI_INTEGER)
320#define ARGI_WAIT_OP ARGI_LIST2 (ARGI_EVENT, ARGI_INTEGER)
321#define ARGI_WHILE_OP ARGI_INVALID_OPCODE
322#define ARGI_WORD_OP ARGI_INVALID_OPCODE
323#define ARGI_ZERO_OP ARG_NONE
324
325#endif /* __ACOPCODE_H__ */
diff --git a/include/acpi/acparser.h b/include/acpi/acparser.h
index c0395ef2b0d0..698276571818 100644
--- a/include/acpi/acparser.h
+++ b/include/acpi/acparser.h
@@ -64,8 +64,17 @@
64 64
65#define ACPI_PARSE_DEFERRED_OP 0x0100 65#define ACPI_PARSE_DEFERRED_OP 0x0100
66 66
67/* Parser external interfaces */
68 67
68/******************************************************************************
69 *
70 * Parser interfaces
71 *
72 *****************************************************************************/
73
74
75/*
76 * psxface - Parser external interfaces
77 */
69acpi_status 78acpi_status
70acpi_psx_load_table ( 79acpi_psx_load_table (
71 u8 *pcode_addr, 80 u8 *pcode_addr,
@@ -76,23 +85,13 @@ acpi_psx_execute (
76 struct acpi_parameter_info *info); 85 struct acpi_parameter_info *info);
77 86
78 87
79/****************************************************************************** 88/*
80 * 89 * psargs - Parse AML opcode arguments
81 * Parser interfaces 90 */
82 *
83 *****************************************************************************/
84
85
86/* psargs - Parse AML opcode arguments */
87
88u8 * 91u8 *
89acpi_ps_get_next_package_end ( 92acpi_ps_get_next_package_end (
90 struct acpi_parse_state *parser_state); 93 struct acpi_parse_state *parser_state);
91 94
92u32
93acpi_ps_get_next_package_length (
94 struct acpi_parse_state *parser_state);
95
96char * 95char *
97acpi_ps_get_next_namestring ( 96acpi_ps_get_next_namestring (
98 struct acpi_parse_state *parser_state); 97 struct acpi_parse_state *parser_state);
@@ -110,10 +109,6 @@ acpi_ps_get_next_namepath (
110 union acpi_parse_object *arg, 109 union acpi_parse_object *arg,
111 u8 method_call); 110 u8 method_call);
112 111
113union acpi_parse_object *
114acpi_ps_get_next_field (
115 struct acpi_parse_state *parser_state);
116
117acpi_status 112acpi_status
118acpi_ps_get_next_arg ( 113acpi_ps_get_next_arg (
119 struct acpi_walk_state *walk_state, 114 struct acpi_walk_state *walk_state,
@@ -122,8 +117,9 @@ acpi_ps_get_next_arg (
122 union acpi_parse_object **return_arg); 117 union acpi_parse_object **return_arg);
123 118
124 119
125/* psfind */ 120/*
126 121 * psfind
122 */
127union acpi_parse_object * 123union acpi_parse_object *
128acpi_ps_find_name ( 124acpi_ps_find_name (
129 union acpi_parse_object *scope, 125 union acpi_parse_object *scope,
@@ -135,8 +131,9 @@ acpi_ps_get_parent (
135 union acpi_parse_object *op); 131 union acpi_parse_object *op);
136 132
137 133
138/* psopcode - AML Opcode information */ 134/*
139 135 * psopcode - AML Opcode information
136 */
140const struct acpi_opcode_info * 137const struct acpi_opcode_info *
141acpi_ps_get_opcode_info ( 138acpi_ps_get_opcode_info (
142 u16 opcode); 139 u16 opcode);
@@ -146,56 +143,25 @@ acpi_ps_get_opcode_name (
146 u16 opcode); 143 u16 opcode);
147 144
148 145
149/* psparse - top level parsing routines */ 146/*
150 147 * psparse - top level parsing routines
151u32 148 */
152acpi_ps_get_opcode_size (
153 u32 opcode);
154
155void
156acpi_ps_complete_this_op (
157 struct acpi_walk_state *walk_state,
158 union acpi_parse_object *op);
159
160acpi_status
161acpi_ps_next_parse_state (
162 struct acpi_walk_state *walk_state,
163 union acpi_parse_object *op,
164 acpi_status callback_status);
165
166acpi_status
167acpi_ps_find_object (
168 struct acpi_walk_state *walk_state,
169 union acpi_parse_object **out_op);
170
171void
172acpi_ps_delete_parse_tree (
173 union acpi_parse_object *root);
174
175acpi_status
176acpi_ps_parse_loop (
177 struct acpi_walk_state *walk_state);
178
179acpi_status 149acpi_status
180acpi_ps_parse_aml ( 150acpi_ps_parse_aml (
181 struct acpi_walk_state *walk_state); 151 struct acpi_walk_state *walk_state);
182 152
183acpi_status 153u32
184acpi_ps_parse_table ( 154acpi_ps_get_opcode_size (
185 u8 *aml, 155 u32 opcode);
186 u32 aml_size,
187 acpi_parse_downwards descending_callback,
188 acpi_parse_upwards ascending_callback,
189 union acpi_parse_object **root_object);
190 156
191u16 157u16
192acpi_ps_peek_opcode ( 158acpi_ps_peek_opcode (
193 struct acpi_parse_state *state); 159 struct acpi_parse_state *state);
194 160
195 161
196/* psscope - Scope stack management routines */ 162/*
197 163 * psscope - Scope stack management routines
198 164 */
199acpi_status 165acpi_status
200acpi_ps_init_scope ( 166acpi_ps_init_scope (
201 struct acpi_parse_state *parser_state, 167 struct acpi_parse_state *parser_state,
@@ -228,8 +194,9 @@ acpi_ps_cleanup_scope (
228 struct acpi_parse_state *state); 194 struct acpi_parse_state *state);
229 195
230 196
231/* pstree - parse tree manipulation routines */ 197/*
232 198 * pstree - parse tree manipulation routines
199 */
233void 200void
234acpi_ps_append_arg( 201acpi_ps_append_arg(
235 union acpi_parse_object *op, 202 union acpi_parse_object *op,
@@ -247,20 +214,17 @@ acpi_ps_get_arg(
247 union acpi_parse_object *op, 214 union acpi_parse_object *op,
248 u32 argn); 215 u32 argn);
249 216
250#ifdef ACPI_FUTURE_USAGE 217#ifdef ACPI_FUTURE_USAGE
251union acpi_parse_object *
252acpi_ps_get_child (
253 union acpi_parse_object *op);
254
255union acpi_parse_object * 218union acpi_parse_object *
256acpi_ps_get_depth_next ( 219acpi_ps_get_depth_next (
257 union acpi_parse_object *origin, 220 union acpi_parse_object *origin,
258 union acpi_parse_object *op); 221 union acpi_parse_object *op);
259#endif /* ACPI_FUTURE_USAGE */ 222#endif /* ACPI_FUTURE_USAGE */
260
261 223
262/* pswalk - parse tree walk routines */
263 224
225/*
226 * pswalk - parse tree walk routines
227 */
264acpi_status 228acpi_status
265acpi_ps_walk_parsed_aml ( 229acpi_ps_walk_parsed_aml (
266 union acpi_parse_object *start_op, 230 union acpi_parse_object *start_op,
@@ -283,9 +247,14 @@ acpi_status
283acpi_ps_delete_completed_op ( 247acpi_ps_delete_completed_op (
284 struct acpi_walk_state *walk_state); 248 struct acpi_walk_state *walk_state);
285 249
250void
251acpi_ps_delete_parse_tree (
252 union acpi_parse_object *root);
286 253
287/* psutils - parser utilities */
288 254
255/*
256 * psutils - parser utilities
257 */
289union acpi_parse_object * 258union acpi_parse_object *
290acpi_ps_create_scope_op ( 259acpi_ps_create_scope_op (
291 void); 260 void);
@@ -303,12 +272,6 @@ void
303acpi_ps_free_op ( 272acpi_ps_free_op (
304 union acpi_parse_object *op); 273 union acpi_parse_object *op);
305 274
306#ifdef ACPI_ENABLE_OBJECT_CACHE
307void
308acpi_ps_delete_parse_cache (
309 void);
310#endif
311
312u8 275u8
313acpi_ps_is_leading_char ( 276acpi_ps_is_leading_char (
314 u32 c); 277 u32 c);
@@ -317,20 +280,27 @@ u8
317acpi_ps_is_prefix_char ( 280acpi_ps_is_prefix_char (
318 u32 c); 281 u32 c);
319 282
320#ifdef ACPI_FUTURE_USAGE 283#ifdef ACPI_FUTURE_USAGE
321u32 284u32
322acpi_ps_get_name( 285acpi_ps_get_name(
323 union acpi_parse_object *op); 286 union acpi_parse_object *op);
324#endif 287#endif /* ACPI_FUTURE_USAGE */
325 288
326void 289void
327acpi_ps_set_name( 290acpi_ps_set_name(
328 union acpi_parse_object *op, 291 union acpi_parse_object *op,
329 u32 name); 292 u32 name);
330 293
294#ifdef ACPI_ENABLE_OBJECT_CACHE
295void
296acpi_ps_delete_parse_cache (
297 void);
298#endif
331 299
332/* psdump - display parser tree */
333 300
301/*
302 * psdump - display parser tree
303 */
334u32 304u32
335acpi_ps_sprint_path ( 305acpi_ps_sprint_path (
336 char *buffer_start, 306 char *buffer_start,
diff --git a/include/acpi/acpi.h b/include/acpi/acpi.h
index ad53252dd42d..a69d78942040 100644
--- a/include/acpi/acpi.h
+++ b/include/acpi/acpi.h
@@ -49,6 +49,7 @@
49 * We put them here because we don't want to duplicate them 49 * We put them here because we don't want to duplicate them
50 * in the rest of the source code again and again. 50 * in the rest of the source code again and again.
51 */ 51 */
52#include "acnames.h" /* Global ACPI names and strings */
52#include "acconfig.h" /* Configuration constants */ 53#include "acconfig.h" /* Configuration constants */
53#include "platform/acenv.h" /* Target environment specific items */ 54#include "platform/acenv.h" /* Target environment specific items */
54#include "actypes.h" /* Fundamental common data types */ 55#include "actypes.h" /* Fundamental common data types */
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index 9ad142476f33..8d0e1290bc76 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -351,6 +351,27 @@ int acpi_match_ids (struct acpi_device *device, char *ids);
351int acpi_create_dir(struct acpi_device *); 351int acpi_create_dir(struct acpi_device *);
352void acpi_remove_dir(struct acpi_device *); 352void acpi_remove_dir(struct acpi_device *);
353 353
354
355/*
356 * Bind physical devices with ACPI devices
357 */
358#include <linux/device.h>
359struct acpi_bus_type {
360 struct list_head list;
361 struct bus_type *bus;
362 /* For general devices under the bus*/
363 int (*find_device)(struct device *, acpi_handle*);
364 /* For bridges, such as PCI root bridge, IDE controller */
365 int (*find_bridge)(struct device *, acpi_handle *);
366};
367int register_acpi_bus_type(struct acpi_bus_type *);
368int unregister_acpi_bus_type(struct acpi_bus_type *);
369struct device *acpi_get_physical_device(acpi_handle);
370/* helper */
371acpi_handle acpi_get_child(acpi_handle, acpi_integer);
372acpi_handle acpi_get_pci_rootbridge_handle(unsigned int, unsigned int);
373#define DEVICE_ACPI_HANDLE(dev) ((acpi_handle)((dev)->firmware_data))
374
354#endif /*CONFIG_ACPI_BUS*/ 375#endif /*CONFIG_ACPI_BUS*/
355 376
356#endif /*__ACPI_BUS_H__*/ 377#endif /*__ACPI_BUS_H__*/
diff --git a/include/acpi/acpi_drivers.h b/include/acpi/acpi_drivers.h
index 4ec722d73381..caeaa71a5663 100644
--- a/include/acpi/acpi_drivers.h
+++ b/include/acpi/acpi_drivers.h
@@ -109,5 +109,10 @@ int acpi_ec_ecdt_probe (void);
109 109
110int acpi_processor_set_thermal_limit(acpi_handle handle, int type); 110int acpi_processor_set_thermal_limit(acpi_handle handle, int type);
111 111
112/* --------------------------------------------------------------------------
113 Hot Keys
114 -------------------------------------------------------------------------- */
115
116extern int acpi_specific_hotkey_enabled;
112 117
113#endif /*__ACPI_DRIVERS_H__*/ 118#endif /*__ACPI_DRIVERS_H__*/
diff --git a/include/acpi/acpiosxf.h b/include/acpi/acpiosxf.h
index 857c8072eb1e..ea489f235216 100644
--- a/include/acpi/acpiosxf.h
+++ b/include/acpi/acpiosxf.h
@@ -79,7 +79,6 @@ struct acpi_signal_fatal_info
79/* 79/*
80 * OSL Initialization and shutdown primitives 80 * OSL Initialization and shutdown primitives
81 */ 81 */
82
83acpi_status 82acpi_status
84acpi_os_initialize ( 83acpi_os_initialize (
85 void); 84 void);
@@ -92,7 +91,6 @@ acpi_os_terminate (
92/* 91/*
93 * ACPI Table interfaces 92 * ACPI Table interfaces
94 */ 93 */
95
96acpi_status 94acpi_status
97acpi_os_get_root_pointer ( 95acpi_os_get_root_pointer (
98 u32 flags, 96 u32 flags,
@@ -112,7 +110,6 @@ acpi_os_table_override (
112/* 110/*
113 * Synchronization primitives 111 * Synchronization primitives
114 */ 112 */
115
116acpi_status 113acpi_status
117acpi_os_create_semaphore ( 114acpi_os_create_semaphore (
118 u32 max_units, 115 u32 max_units,
@@ -156,7 +153,6 @@ acpi_os_release_lock (
156/* 153/*
157 * Memory allocation and mapping 154 * Memory allocation and mapping
158 */ 155 */
159
160void * 156void *
161acpi_os_allocate ( 157acpi_os_allocate (
162 acpi_size size); 158 acpi_size size);
@@ -187,7 +183,6 @@ acpi_os_get_physical_address (
187/* 183/*
188 * Interrupt handlers 184 * Interrupt handlers
189 */ 185 */
190
191acpi_status 186acpi_status
192acpi_os_install_interrupt_handler ( 187acpi_os_install_interrupt_handler (
193 u32 gsi, 188 u32 gsi,
@@ -203,7 +198,6 @@ acpi_os_remove_interrupt_handler (
203/* 198/*
204 * Threads and Scheduling 199 * Threads and Scheduling
205 */ 200 */
206
207u32 201u32
208acpi_os_get_thread_id ( 202acpi_os_get_thread_id (
209 void); 203 void);
@@ -234,7 +228,6 @@ acpi_os_stall (
234/* 228/*
235 * Platform and hardware-independent I/O interfaces 229 * Platform and hardware-independent I/O interfaces
236 */ 230 */
237
238acpi_status 231acpi_status
239acpi_os_read_port ( 232acpi_os_read_port (
240 acpi_io_address address, 233 acpi_io_address address,
@@ -251,7 +244,6 @@ acpi_os_write_port (
251/* 244/*
252 * Platform and hardware-independent physical memory interfaces 245 * Platform and hardware-independent physical memory interfaces
253 */ 246 */
254
255acpi_status 247acpi_status
256acpi_os_read_memory ( 248acpi_os_read_memory (
257 acpi_physical_address address, 249 acpi_physical_address address,
@@ -270,7 +262,6 @@ acpi_os_write_memory (
270 * Note: Can't use "Register" as a parameter, changed to "Reg" -- 262 * Note: Can't use "Register" as a parameter, changed to "Reg" --
271 * certain compilers complain. 263 * certain compilers complain.
272 */ 264 */
273
274acpi_status 265acpi_status
275acpi_os_read_pci_configuration ( 266acpi_os_read_pci_configuration (
276 struct acpi_pci_id *pci_id, 267 struct acpi_pci_id *pci_id,
@@ -288,7 +279,6 @@ acpi_os_write_pci_configuration (
288/* 279/*
289 * Interim function needed for PCI IRQ routing 280 * Interim function needed for PCI IRQ routing
290 */ 281 */
291
292void 282void
293acpi_os_derive_pci_id( 283acpi_os_derive_pci_id(
294 acpi_handle rhandle, 284 acpi_handle rhandle,
@@ -298,7 +288,6 @@ acpi_os_derive_pci_id(
298/* 288/*
299 * Miscellaneous 289 * Miscellaneous
300 */ 290 */
301
302u8 291u8
303acpi_os_readable ( 292acpi_os_readable (
304 void *pointer, 293 void *pointer,
@@ -323,7 +312,6 @@ acpi_os_signal (
323/* 312/*
324 * Debug print routines 313 * Debug print routines
325 */ 314 */
326
327void ACPI_INTERNAL_VAR_XFACE 315void ACPI_INTERNAL_VAR_XFACE
328acpi_os_printf ( 316acpi_os_printf (
329 const char *format, 317 const char *format,
@@ -339,11 +327,10 @@ acpi_os_redirect_output (
339 void *destination); 327 void *destination);
340 328
341 329
330#ifdef ACPI_FUTURE_USAGE
342/* 331/*
343 * Debug input 332 * Debug input
344 */ 333 */
345
346#ifdef ACPI_FUTURE_USAGE
347u32 334u32
348acpi_os_get_line ( 335acpi_os_get_line (
349 char *buffer); 336 char *buffer);
@@ -353,7 +340,6 @@ acpi_os_get_line (
353/* 340/*
354 * Directory manipulation 341 * Directory manipulation
355 */ 342 */
356
357void * 343void *
358acpi_os_open_directory ( 344acpi_os_open_directory (
359 char *pathname, 345 char *pathname,
@@ -377,7 +363,6 @@ acpi_os_close_directory (
377/* 363/*
378 * Debug 364 * Debug
379 */ 365 */
380
381void 366void
382acpi_os_dbg_assert( 367acpi_os_dbg_assert(
383 void *failed_assertion, 368 void *failed_assertion,
@@ -385,5 +370,4 @@ acpi_os_dbg_assert(
385 u32 line_number, 370 u32 line_number,
386 char *message); 371 char *message);
387 372
388
389#endif /* __ACPIOSXF_H__ */ 373#endif /* __ACPIOSXF_H__ */
diff --git a/include/acpi/acpixf.h b/include/acpi/acpixf.h
index 00d78b79652e..f8f619f8e4f8 100644
--- a/include/acpi/acpixf.h
+++ b/include/acpi/acpixf.h
@@ -50,10 +50,9 @@
50#include "actbl.h" 50#include "actbl.h"
51 51
52 52
53 /* 53/*
54 * Global interfaces 54 * Global interfaces
55 */ 55 */
56
57acpi_status 56acpi_status
58acpi_initialize_subsystem ( 57acpi_initialize_subsystem (
59 void); 58 void);
@@ -106,9 +105,8 @@ acpi_install_initialization_handler (
106#endif 105#endif
107 106
108/* 107/*
109 * ACPI Memory manager 108 * ACPI Memory managment
110 */ 109 */
111
112void * 110void *
113acpi_allocate ( 111acpi_allocate (
114 u32 size); 112 u32 size);
@@ -125,7 +123,6 @@ acpi_free (
125/* 123/*
126 * ACPI table manipulation interfaces 124 * ACPI table manipulation interfaces
127 */ 125 */
128
129acpi_status 126acpi_status
130acpi_find_root_pointer ( 127acpi_find_root_pointer (
131 u32 flags, 128 u32 flags,
@@ -168,7 +165,6 @@ acpi_get_firmware_table (
168/* 165/*
169 * Namespace and name interfaces 166 * Namespace and name interfaces
170 */ 167 */
171
172acpi_status 168acpi_status
173acpi_walk_namespace ( 169acpi_walk_namespace (
174 acpi_object_type type, 170 acpi_object_type type,
@@ -218,7 +214,6 @@ acpi_get_data (
218/* 214/*
219 * Object manipulation and enumeration 215 * Object manipulation and enumeration
220 */ 216 */
221
222acpi_status 217acpi_status
223acpi_evaluate_object ( 218acpi_evaluate_object (
224 acpi_handle object, 219 acpi_handle object,
@@ -262,7 +257,6 @@ acpi_get_parent (
262/* 257/*
263 * Event handler interfaces 258 * Event handler interfaces
264 */ 259 */
265
266acpi_status 260acpi_status
267acpi_install_fixed_event_handler ( 261acpi_install_fixed_event_handler (
268 u32 acpi_event, 262 u32 acpi_event,
@@ -319,7 +313,6 @@ acpi_install_exception_handler (
319/* 313/*
320 * Event interfaces 314 * Event interfaces
321 */ 315 */
322
323acpi_status 316acpi_status
324acpi_acquire_global_lock ( 317acpi_acquire_global_lock (
325 u16 timeout, 318 u16 timeout,
@@ -404,7 +397,6 @@ acpi_remove_gpe_block (
404/* 397/*
405 * Resource interfaces 398 * Resource interfaces
406 */ 399 */
407
408typedef 400typedef
409acpi_status (*ACPI_WALK_RESOURCE_CALLBACK) ( 401acpi_status (*ACPI_WALK_RESOURCE_CALLBACK) (
410 struct acpi_resource *resource, 402 struct acpi_resource *resource,
@@ -448,7 +440,6 @@ acpi_resource_to_address64 (
448/* 440/*
449 * Hardware (ACPI device) interfaces 441 * Hardware (ACPI device) interfaces
450 */ 442 */
451
452acpi_status 443acpi_status
453acpi_get_register ( 444acpi_get_register (
454 u32 register_id, 445 u32 register_id,
diff --git a/include/acpi/acresrc.h b/include/acpi/acresrc.h
index 93c55ff5c237..ed679264c12c 100644
--- a/include/acpi/acresrc.h
+++ b/include/acpi/acresrc.h
@@ -48,7 +48,6 @@
48/* 48/*
49 * Function prototypes called from Acpi* APIs 49 * Function prototypes called from Acpi* APIs
50 */ 50 */
51
52acpi_status 51acpi_status
53acpi_rs_get_prt_method_data ( 52acpi_rs_get_prt_method_data (
54 acpi_handle handle, 53 acpi_handle handle,
@@ -60,12 +59,12 @@ acpi_rs_get_crs_method_data (
60 acpi_handle handle, 59 acpi_handle handle,
61 struct acpi_buffer *ret_buffer); 60 struct acpi_buffer *ret_buffer);
62 61
63#ifdef ACPI_FUTURE_USAGE 62#ifdef ACPI_FUTURE_USAGE
64acpi_status 63acpi_status
65acpi_rs_get_prs_method_data ( 64acpi_rs_get_prs_method_data (
66 acpi_handle handle, 65 acpi_handle handle,
67 struct acpi_buffer *ret_buffer); 66 struct acpi_buffer *ret_buffer);
68#endif 67#endif /* ACPI_FUTURE_USAGE */
69 68
70acpi_status 69acpi_status
71acpi_rs_get_method_data ( 70acpi_rs_get_method_data (
@@ -95,61 +94,9 @@ acpi_rs_create_pci_routing_table (
95 94
96 95
97/* 96/*
98 * Function prototypes called from acpi_rs_create* 97 * rsdump
99 */ 98 */
100#ifdef ACPI_FUTURE_USAGE 99#ifdef ACPI_FUTURE_USAGE
101void
102acpi_rs_dump_irq (
103 union acpi_resource_data *data);
104
105void
106acpi_rs_dump_address16 (
107 union acpi_resource_data *data);
108
109void
110acpi_rs_dump_address32 (
111 union acpi_resource_data *data);
112
113void
114acpi_rs_dump_address64 (
115 union acpi_resource_data *data);
116
117void
118acpi_rs_dump_dma (
119 union acpi_resource_data *data);
120
121void
122acpi_rs_dump_io (
123 union acpi_resource_data *data);
124
125void
126acpi_rs_dump_extended_irq (
127 union acpi_resource_data *data);
128
129void
130acpi_rs_dump_fixed_io (
131 union acpi_resource_data *data);
132
133void
134acpi_rs_dump_fixed_memory32 (
135 union acpi_resource_data *data);
136
137void
138acpi_rs_dump_memory24 (
139 union acpi_resource_data *data);
140
141void
142acpi_rs_dump_memory32 (
143 union acpi_resource_data *data);
144
145void
146acpi_rs_dump_start_depend_fns (
147 union acpi_resource_data *data);
148
149void
150acpi_rs_dump_vendor_specific (
151 union acpi_resource_data *data);
152
153void 100void
154acpi_rs_dump_resource_list ( 101acpi_rs_dump_resource_list (
155 struct acpi_resource *resource); 102 struct acpi_resource *resource);
@@ -157,8 +104,12 @@ acpi_rs_dump_resource_list (
157void 104void
158acpi_rs_dump_irq_list ( 105acpi_rs_dump_irq_list (
159 u8 *route_table); 106 u8 *route_table);
160#endif /* ACPI_FUTURE_USAGE */ 107#endif /* ACPI_FUTURE_USAGE */
161 108
109
110/*
111 * rscalc
112 */
162acpi_status 113acpi_status
163acpi_rs_get_byte_stream_start ( 114acpi_rs_get_byte_stream_start (
164 u8 *byte_stream_buffer, 115 u8 *byte_stream_buffer,
diff --git a/include/acpi/acstruct.h b/include/acpi/acstruct.h
index c97843f6bcbc..e6b9e36a2eda 100644
--- a/include/acpi/acstruct.h
+++ b/include/acpi/acstruct.h
@@ -56,7 +56,6 @@
56 * Walk state - current state of a parse tree walk. Used for both a leisurely stroll through 56 * Walk state - current state of a parse tree walk. Used for both a leisurely stroll through
57 * the tree (for whatever reason), and for control method execution. 57 * the tree (for whatever reason), and for control method execution.
58 */ 58 */
59
60#define ACPI_NEXT_OP_DOWNWARD 1 59#define ACPI_NEXT_OP_DOWNWARD 1
61#define ACPI_NEXT_OP_UPWARD 2 60#define ACPI_NEXT_OP_UPWARD 2
62 61
diff --git a/include/acpi/actables.h b/include/acpi/actables.h
index e8f5d4ffd452..39df92e21a0d 100644
--- a/include/acpi/actables.h
+++ b/include/acpi/actables.h
@@ -50,17 +50,9 @@
50#define SIZE_IN_HEADER 0 50#define SIZE_IN_HEADER 0
51 51
52 52
53#ifdef ACPI_FUTURE_USAGE
54acpi_status
55acpi_tb_handle_to_object (
56 u16 table_id,
57 struct acpi_table_desc **table_desc);
58#endif
59
60/* 53/*
61 * tbconvrt - Table conversion routines 54 * tbconvrt - Table conversion routines
62 */ 55 */
63
64acpi_status 56acpi_status
65acpi_tb_convert_to_xsdt ( 57acpi_tb_convert_to_xsdt (
66 struct acpi_table_desc *table_info); 58 struct acpi_table_desc *table_info);
@@ -78,10 +70,10 @@ acpi_tb_get_table_count (
78 struct rsdp_descriptor *RSDP, 70 struct rsdp_descriptor *RSDP,
79 struct acpi_table_header *RSDT); 71 struct acpi_table_header *RSDT);
80 72
73
81/* 74/*
82 * tbget - Table "get" routines 75 * tbget - Table "get" routines
83 */ 76 */
84
85acpi_status 77acpi_status
86acpi_tb_get_table ( 78acpi_tb_get_table (
87 struct acpi_pointer *address, 79 struct acpi_pointer *address,
@@ -99,17 +91,6 @@ acpi_tb_get_table_body (
99 struct acpi_table_desc *table_info); 91 struct acpi_table_desc *table_info);
100 92
101acpi_status 93acpi_status
102acpi_tb_get_this_table (
103 struct acpi_pointer *address,
104 struct acpi_table_header *header,
105 struct acpi_table_desc *table_info);
106
107acpi_status
108acpi_tb_table_override (
109 struct acpi_table_header *header,
110 struct acpi_table_desc *table_info);
111
112acpi_status
113acpi_tb_get_table_ptr ( 94acpi_tb_get_table_ptr (
114 acpi_table_type table_type, 95 acpi_table_type table_type,
115 u32 instance, 96 u32 instance,
@@ -127,36 +108,23 @@ acpi_status
127acpi_tb_validate_rsdt ( 108acpi_tb_validate_rsdt (
128 struct acpi_table_header *table_ptr); 109 struct acpi_table_header *table_ptr);
129 110
111
112/*
113 * tbgetall - get multiple required tables
114 */
130acpi_status 115acpi_status
131acpi_tb_get_required_tables ( 116acpi_tb_get_required_tables (
132 void); 117 void);
133 118
134acpi_status
135acpi_tb_get_primary_table (
136 struct acpi_pointer *address,
137 struct acpi_table_desc *table_info);
138
139acpi_status
140acpi_tb_get_secondary_table (
141 struct acpi_pointer *address,
142 acpi_string signature,
143 struct acpi_table_desc *table_info);
144 119
145/* 120/*
146 * tbinstall - Table installation 121 * tbinstall - Table installation
147 */ 122 */
148
149acpi_status 123acpi_status
150acpi_tb_install_table ( 124acpi_tb_install_table (
151 struct acpi_table_desc *table_info); 125 struct acpi_table_desc *table_info);
152 126
153acpi_status 127acpi_status
154acpi_tb_match_signature (
155 char *signature,
156 struct acpi_table_desc *table_info,
157 u8 search_type);
158
159acpi_status
160acpi_tb_recognize_table ( 128acpi_tb_recognize_table (
161 struct acpi_table_desc *table_info, 129 struct acpi_table_desc *table_info,
162 u8 search_type); 130 u8 search_type);
@@ -170,7 +138,6 @@ acpi_tb_init_table_descriptor (
170/* 138/*
171 * tbremove - Table removal and deletion 139 * tbremove - Table removal and deletion
172 */ 140 */
173
174void 141void
175acpi_tb_delete_all_tables ( 142acpi_tb_delete_all_tables (
176 void); 143 void);
@@ -189,35 +156,23 @@ acpi_tb_uninstall_table (
189 156
190 157
191/* 158/*
192 * tbrsd - RSDP, RSDT utilities 159 * tbxfroot - RSDP, RSDT utilities
193 */ 160 */
161acpi_status
162acpi_tb_find_table (
163 char *signature,
164 char *oem_id,
165 char *oem_table_id,
166 struct acpi_table_header **table_ptr);
194 167
195acpi_status 168acpi_status
196acpi_tb_get_table_rsdt ( 169acpi_tb_get_table_rsdt (
197 void); 170 void);
198 171
199u8 *
200acpi_tb_scan_memory_for_rsdp (
201 u8 *start_address,
202 u32 length);
203
204acpi_status
205acpi_tb_find_rsdp (
206 struct acpi_table_desc *table_info,
207 u32 flags);
208
209 172
210/* 173/*
211 * tbutils - common table utilities 174 * tbutils - common table utilities
212 */ 175 */
213
214acpi_status
215acpi_tb_find_table (
216 char *signature,
217 char *oem_id,
218 char *oem_table_id,
219 struct acpi_table_header **table_ptr);
220
221acpi_status 176acpi_status
222acpi_tb_verify_table_checksum ( 177acpi_tb_verify_table_checksum (
223 struct acpi_table_header *table_header); 178 struct acpi_table_header *table_header);
@@ -231,5 +186,4 @@ acpi_status
231acpi_tb_validate_table_header ( 186acpi_tb_validate_table_header (
232 struct acpi_table_header *table_header); 187 struct acpi_table_header *table_header);
233 188
234
235#endif /* __ACTABLES_H__ */ 189#endif /* __ACTABLES_H__ */
diff --git a/include/acpi/actbl.h b/include/acpi/actbl.h
index 7eee731112b1..b5cdcca444c8 100644
--- a/include/acpi/actbl.h
+++ b/include/acpi/actbl.h
@@ -133,7 +133,6 @@ struct acpi_table_header /* ACPI common table header */
133#define DUAL_PIC 0 133#define DUAL_PIC 0
134#define MULTIPLE_APIC 1 134#define MULTIPLE_APIC 1
135 135
136
137/* Master MADT */ 136/* Master MADT */
138 137
139struct multiple_apic_table 138struct multiple_apic_table
@@ -144,7 +143,6 @@ struct multiple_apic_table
144 u32 reserved1 : 31; 143 u32 reserved1 : 31;
145}; 144};
146 145
147
148/* Values for Type in APIC_HEADER_DEF */ 146/* Values for Type in APIC_HEADER_DEF */
149 147
150#define APIC_PROCESSOR 0 148#define APIC_PROCESSOR 0
diff --git a/include/acpi/actypes.h b/include/acpi/actypes.h
index 7acb550af3eb..3a451dc48ac8 100644
--- a/include/acpi/actypes.h
+++ b/include/acpi/actypes.h
@@ -478,7 +478,6 @@ typedef u32 acpi_object_type;
478#define ACPI_TYPE_INVALID 0x1E 478#define ACPI_TYPE_INVALID 0x1E
479#define ACPI_TYPE_NOT_FOUND 0xFF 479#define ACPI_TYPE_NOT_FOUND 0xFF
480 480
481
482/* 481/*
483 * Bitmapped ACPI types. Used internally only 482 * Bitmapped ACPI types. Used internally only
484 */ 483 */
@@ -803,7 +802,6 @@ struct acpi_system_info
803/* 802/*
804 * Types specific to the OS service interfaces 803 * Types specific to the OS service interfaces
805 */ 804 */
806
807typedef u32 805typedef u32
808(ACPI_SYSTEM_XFACE *acpi_osd_handler) ( 806(ACPI_SYSTEM_XFACE *acpi_osd_handler) (
809 void *context); 807 void *context);
diff --git a/include/acpi/acutils.h b/include/acpi/acutils.h
index 0de26b8f1028..192d0bea3884 100644
--- a/include/acpi/acutils.h
+++ b/include/acpi/acutils.h
@@ -52,13 +52,6 @@ acpi_status (*acpi_pkg_callback) (
52 union acpi_generic_state *state, 52 union acpi_generic_state *state,
53 void *context); 53 void *context);
54 54
55acpi_status
56acpi_ut_walk_package_tree (
57 union acpi_operand_object *source_object,
58 void *target_object,
59 acpi_pkg_callback walk_callback,
60 void *context);
61
62struct acpi_pkg_info 55struct acpi_pkg_info
63{ 56{
64 u8 *free_space; 57 u8 *free_space;
@@ -79,37 +72,13 @@ struct acpi_pkg_info
79#define DB_QWORD_DISPLAY 8 72#define DB_QWORD_DISPLAY 8
80 73
81 74
82/* Global initialization interfaces */
83
84void
85acpi_ut_init_globals (
86 void);
87
88void
89acpi_ut_terminate (
90 void);
91
92
93/* 75/*
94 * ut_init - miscellaneous initialization and shutdown 76 * utglobal - Global data structures and procedures
95 */ 77 */
96
97acpi_status
98acpi_ut_hardware_initialize (
99 void);
100
101void 78void
102acpi_ut_subsystem_shutdown ( 79acpi_ut_init_globals (
103 void);
104
105acpi_status
106acpi_ut_validate_fadt (
107 void); 80 void);
108 81
109/*
110 * ut_global - Global data structures and procedures
111 */
112
113#if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER) 82#if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
114 83
115char * 84char *
@@ -157,9 +126,24 @@ acpi_ut_allocate_owner_id (
157 126
158 127
159/* 128/*
160 * ut_clib - Local implementations of C library functions 129 * utinit - miscellaneous initialization and shutdown
161 */ 130 */
131acpi_status
132acpi_ut_hardware_initialize (
133 void);
162 134
135void
136acpi_ut_subsystem_shutdown (
137 void);
138
139acpi_status
140acpi_ut_validate_fadt (
141 void);
142
143
144/*
145 * utclib - Local implementations of C library functions
146 */
163#ifndef ACPI_USE_SYSTEM_CLIBRARY 147#ifndef ACPI_USE_SYSTEM_CLIBRARY
164 148
165acpi_size 149acpi_size
@@ -260,10 +244,10 @@ extern const u8 _acpi_ctype[];
260 244
261#endif /* ACPI_USE_SYSTEM_CLIBRARY */ 245#endif /* ACPI_USE_SYSTEM_CLIBRARY */
262 246
247
263/* 248/*
264 * ut_copy - Object construction and conversion interfaces 249 * utcopy - Object construction and conversion interfaces
265 */ 250 */
266
267acpi_status 251acpi_status
268acpi_ut_build_simple_object( 252acpi_ut_build_simple_object(
269 union acpi_operand_object *obj, 253 union acpi_operand_object *obj,
@@ -278,30 +262,11 @@ acpi_ut_build_package_object (
278 u32 *space_used); 262 u32 *space_used);
279 263
280acpi_status 264acpi_status
281acpi_ut_copy_ielement_to_eelement (
282 u8 object_type,
283 union acpi_operand_object *source_object,
284 union acpi_generic_state *state,
285 void *context);
286
287acpi_status
288acpi_ut_copy_ielement_to_ielement (
289 u8 object_type,
290 union acpi_operand_object *source_object,
291 union acpi_generic_state *state,
292 void *context);
293
294acpi_status
295acpi_ut_copy_iobject_to_eobject ( 265acpi_ut_copy_iobject_to_eobject (
296 union acpi_operand_object *obj, 266 union acpi_operand_object *obj,
297 struct acpi_buffer *ret_buffer); 267 struct acpi_buffer *ret_buffer);
298 268
299acpi_status 269acpi_status
300acpi_ut_copy_esimple_to_isimple(
301 union acpi_object *user_obj,
302 union acpi_operand_object **return_obj);
303
304acpi_status
305acpi_ut_copy_eobject_to_iobject ( 270acpi_ut_copy_eobject_to_iobject (
306 union acpi_object *obj, 271 union acpi_object *obj,
307 union acpi_operand_object **internal_obj); 272 union acpi_operand_object **internal_obj);
@@ -312,17 +277,6 @@ acpi_ut_copy_isimple_to_isimple (
312 union acpi_operand_object *dest_obj); 277 union acpi_operand_object *dest_obj);
313 278
314acpi_status 279acpi_status
315acpi_ut_copy_ipackage_to_ipackage (
316 union acpi_operand_object *source_obj,
317 union acpi_operand_object *dest_obj,
318 struct acpi_walk_state *walk_state);
319
320acpi_status
321acpi_ut_copy_simple_object (
322 union acpi_operand_object *source_desc,
323 union acpi_operand_object *dest_desc);
324
325acpi_status
326acpi_ut_copy_iobject_to_iobject ( 280acpi_ut_copy_iobject_to_iobject (
327 union acpi_operand_object *source_desc, 281 union acpi_operand_object *source_desc,
328 union acpi_operand_object **dest_desc, 282 union acpi_operand_object **dest_desc,
@@ -330,9 +284,8 @@ acpi_ut_copy_iobject_to_iobject (
330 284
331 285
332/* 286/*
333 * ut_create - Object creation 287 * utcreate - Object creation
334 */ 288 */
335
336acpi_status 289acpi_status
337acpi_ut_update_object_reference ( 290acpi_ut_update_object_reference (
338 union acpi_operand_object *object, 291 union acpi_operand_object *object,
@@ -340,9 +293,8 @@ acpi_ut_update_object_reference (
340 293
341 294
342/* 295/*
343 * ut_debug - Debug interfaces 296 * utdebug - Debug interfaces
344 */ 297 */
345
346void 298void
347acpi_ut_init_stack_ptr_trace ( 299acpi_ut_init_stack_ptr_trace (
348 void); 300 void);
@@ -440,11 +392,14 @@ acpi_ut_debug_print_raw (
440 392
441 393
442/* 394/*
443 * ut_delete - Object deletion 395 * utdelete - Object deletion and reference counts
444 */ 396 */
397void
398acpi_ut_add_reference (
399 union acpi_operand_object *object);
445 400
446void 401void
447acpi_ut_delete_internal_obj ( 402acpi_ut_remove_reference (
448 union acpi_operand_object *object); 403 union acpi_operand_object *object);
449 404
450void 405void
@@ -461,25 +416,8 @@ acpi_ut_delete_internal_object_list (
461 416
462 417
463/* 418/*
464 * ut_eval - object evaluation 419 * uteval - object evaluation
465 */ 420 */
466
467/* Method name strings */
468
469#define METHOD_NAME__HID "_HID"
470#define METHOD_NAME__CID "_CID"
471#define METHOD_NAME__UID "_UID"
472#define METHOD_NAME__ADR "_ADR"
473#define METHOD_NAME__STA "_STA"
474#define METHOD_NAME__REG "_REG"
475#define METHOD_NAME__SEG "_SEG"
476#define METHOD_NAME__BBN "_BBN"
477#define METHOD_NAME__PRT "_PRT"
478#define METHOD_NAME__CRS "_CRS"
479#define METHOD_NAME__PRS "_PRS"
480#define METHOD_NAME__PRW "_PRW"
481
482
483acpi_status 421acpi_status
484acpi_ut_osi_implementation ( 422acpi_ut_osi_implementation (
485 struct acpi_walk_state *walk_state); 423 struct acpi_walk_state *walk_state);
@@ -522,39 +460,10 @@ acpi_ut_execute_sxds (
522 struct acpi_namespace_node *device_node, 460 struct acpi_namespace_node *device_node,
523 u8 *highest); 461 u8 *highest);
524 462
525/*
526 * ut_mutex - mutual exclusion interfaces
527 */
528
529acpi_status
530acpi_ut_mutex_initialize (
531 void);
532
533void
534acpi_ut_mutex_terminate (
535 void);
536
537acpi_status
538acpi_ut_create_mutex (
539 acpi_mutex_handle mutex_id);
540
541acpi_status
542acpi_ut_delete_mutex (
543 acpi_mutex_handle mutex_id);
544
545acpi_status
546acpi_ut_acquire_mutex (
547 acpi_mutex_handle mutex_id);
548
549acpi_status
550acpi_ut_release_mutex (
551 acpi_mutex_handle mutex_id);
552
553 463
554/* 464/*
555 * ut_object - internal object create/delete/cache routines 465 * utobject - internal object create/delete/cache routines
556 */ 466 */
557
558union acpi_operand_object * 467union acpi_operand_object *
559acpi_ut_create_internal_object_dbg ( 468acpi_ut_create_internal_object_dbg (
560 char *module_name, 469 char *module_name,
@@ -587,50 +496,15 @@ union acpi_operand_object *
587acpi_ut_create_string_object ( 496acpi_ut_create_string_object (
588 acpi_size string_size); 497 acpi_size string_size);
589 498
590
591/*
592 * ut_ref_cnt - Object reference count management
593 */
594
595void
596acpi_ut_add_reference (
597 union acpi_operand_object *object);
598
599void
600acpi_ut_remove_reference (
601 union acpi_operand_object *object);
602
603/*
604 * ut_size - Object size routines
605 */
606
607acpi_status
608acpi_ut_get_simple_object_size (
609 union acpi_operand_object *obj,
610 acpi_size *obj_length);
611
612acpi_status
613acpi_ut_get_package_object_size (
614 union acpi_operand_object *obj,
615 acpi_size *obj_length);
616
617acpi_status 499acpi_status
618acpi_ut_get_object_size( 500acpi_ut_get_object_size(
619 union acpi_operand_object *obj, 501 union acpi_operand_object *obj,
620 acpi_size *obj_length); 502 acpi_size *obj_length);
621 503
622acpi_status
623acpi_ut_get_element_length (
624 u8 object_type,
625 union acpi_operand_object *source_object,
626 union acpi_generic_state *state,
627 void *context);
628
629 504
630/* 505/*
631 * ut_state - Generic state creation/cache routines 506 * utstate - Generic state creation/cache routines
632 */ 507 */
633
634void 508void
635acpi_ut_push_generic_state ( 509acpi_ut_push_generic_state (
636 union acpi_generic_state **list_head, 510 union acpi_generic_state **list_head,
@@ -666,14 +540,14 @@ acpi_ut_create_update_state_and_push (
666 u16 action, 540 u16 action,
667 union acpi_generic_state **state_list); 541 union acpi_generic_state **state_list);
668 542
669#ifdef ACPI_FUTURE_USAGE 543#ifdef ACPI_FUTURE_USAGE
670acpi_status 544acpi_status
671acpi_ut_create_pkg_state_and_push ( 545acpi_ut_create_pkg_state_and_push (
672 void *internal_object, 546 void *internal_object,
673 void *external_object, 547 void *external_object,
674 u16 index, 548 u16 index,
675 union acpi_generic_state **state_list); 549 union acpi_generic_state **state_list);
676#endif 550#endif /* ACPI_FUTURE_USAGE */
677 551
678union acpi_generic_state * 552union acpi_generic_state *
679acpi_ut_create_control_state ( 553acpi_ut_create_control_state (
@@ -693,15 +567,10 @@ acpi_ut_delete_object_cache (
693 void); 567 void);
694#endif 568#endif
695 569
570
696/* 571/*
697 * utmisc 572 * utmath
698 */ 573 */
699
700void
701acpi_ut_print_string (
702 char *string,
703 u8 max_length);
704
705acpi_status 574acpi_status
706acpi_ut_divide ( 575acpi_ut_divide (
707 acpi_integer in_dividend, 576 acpi_integer in_dividend,
@@ -716,6 +585,25 @@ acpi_ut_short_divide (
716 acpi_integer *out_quotient, 585 acpi_integer *out_quotient,
717 u32 *out_remainder); 586 u32 *out_remainder);
718 587
588/*
589 * utmisc
590 */
591acpi_status
592acpi_ut_walk_package_tree (
593 union acpi_operand_object *source_object,
594 void *target_object,
595 acpi_pkg_callback walk_callback,
596 void *context);
597
598char *
599acpi_ut_strupr (
600 char *src_string);
601
602void
603acpi_ut_print_string (
604 char *string,
605 u8 max_length);
606
719u8 607u8
720acpi_ut_valid_acpi_name ( 608acpi_ut_valid_acpi_name (
721 u32 name); 609 u32 name);
@@ -734,11 +622,21 @@ acpi_ut_strtoul64 (
734 622
735#define ACPI_ANY_BASE 0 623#define ACPI_ANY_BASE 0
736 624
737#ifdef ACPI_FUTURE_USAGE 625acpi_status
738char * 626acpi_ut_mutex_initialize (
739acpi_ut_strupr ( 627 void);
740 char *src_string); 628
741#endif 629void
630acpi_ut_mutex_terminate (
631 void);
632
633acpi_status
634acpi_ut_acquire_mutex (
635 acpi_mutex_handle mutex_id);
636
637acpi_status
638acpi_ut_release_mutex (
639 acpi_mutex_handle mutex_id);
742 640
743u8 * 641u8 *
744acpi_ut_get_resource_end_tag ( 642acpi_ut_get_resource_end_tag (
@@ -768,9 +666,8 @@ acpi_ut_display_init_pathname (
768 666
769 667
770/* 668/*
771 * Utalloc - memory allocation and object caching 669 * utalloc - memory allocation and object caching
772 */ 670 */
773
774void * 671void *
775acpi_ut_acquire_from_cache ( 672acpi_ut_acquire_from_cache (
776 u32 list_id); 673 u32 list_id);
@@ -795,9 +692,6 @@ acpi_ut_initialize_buffer (
795 struct acpi_buffer *buffer, 692 struct acpi_buffer *buffer,
796 acpi_size required_length); 693 acpi_size required_length);
797 694
798
799/* Memory allocation functions */
800
801void * 695void *
802acpi_ut_allocate ( 696acpi_ut_allocate (
803 acpi_size size, 697 acpi_size size,
@@ -812,9 +706,7 @@ acpi_ut_callocate (
812 char *module, 706 char *module,
813 u32 line); 707 u32 line);
814 708
815
816#ifdef ACPI_DBG_TRACK_ALLOCATIONS 709#ifdef ACPI_DBG_TRACK_ALLOCATIONS
817
818void * 710void *
819acpi_ut_allocate_and_track ( 711acpi_ut_allocate_and_track (
820 acpi_size size, 712 acpi_size size,
@@ -836,34 +728,11 @@ acpi_ut_free_and_track (
836 char *module, 728 char *module,
837 u32 line); 729 u32 line);
838 730
839struct acpi_debug_mem_block * 731#ifdef ACPI_FUTURE_USAGE
840acpi_ut_find_allocation (
841 u32 list_id,
842 void *allocation);
843
844acpi_status
845acpi_ut_track_allocation (
846 u32 list_id,
847 struct acpi_debug_mem_block *address,
848 acpi_size size,
849 u8 alloc_type,
850 u32 component,
851 char *module,
852 u32 line);
853
854acpi_status
855acpi_ut_remove_allocation (
856 u32 list_id,
857 struct acpi_debug_mem_block *address,
858 u32 component,
859 char *module,
860 u32 line);
861
862#ifdef ACPI_FUTURE_USAGE
863void 732void
864acpi_ut_dump_allocation_info ( 733acpi_ut_dump_allocation_info (
865 void); 734 void);
866#endif 735#endif /* ACPI_FUTURE_USAGE */
867 736
868void 737void
869acpi_ut_dump_allocations ( 738acpi_ut_dump_allocations (
@@ -871,5 +740,4 @@ acpi_ut_dump_allocations (
871 char *module); 740 char *module);
872#endif 741#endif
873 742
874
875#endif /* _ACUTILS_H */ 743#endif /* _ACUTILS_H */
diff --git a/include/acpi/amlcode.h b/include/acpi/amlcode.h
index 2ec538eac58e..55e97ed29190 100644
--- a/include/acpi/amlcode.h
+++ b/include/acpi/amlcode.h
@@ -146,8 +146,7 @@
146 146
147/* prefixed opcodes */ 147/* prefixed opcodes */
148 148
149#define AML_EXTOP (u16) 0x005b 149#define AML_EXTOP (u16) 0x005b /* prefix for 2-byte opcodes */
150
151 150
152#define AML_MUTEX_OP (u16) 0x5b01 151#define AML_MUTEX_OP (u16) 0x5b01
153#define AML_EVENT_OP (u16) 0x5b02 152#define AML_EVENT_OP (u16) 0x5b02
@@ -194,7 +193,6 @@
194 * Use only "Unknown" AML opcodes, don't attempt to use 193 * Use only "Unknown" AML opcodes, don't attempt to use
195 * any valid ACPI ASCII values (A-Z, 0-9, '-') 194 * any valid ACPI ASCII values (A-Z, 0-9, '-')
196 */ 195 */
197
198#define AML_INT_NAMEPATH_OP (u16) 0x002d 196#define AML_INT_NAMEPATH_OP (u16) 0x002d
199#define AML_INT_NAMEDFIELD_OP (u16) 0x0030 197#define AML_INT_NAMEDFIELD_OP (u16) 0x0030
200#define AML_INT_RESERVEDFIELD_OP (u16) 0x0031 198#define AML_INT_RESERVEDFIELD_OP (u16) 0x0031
@@ -214,7 +212,6 @@
214 * There can be up to 31 unique argument types 212 * There can be up to 31 unique argument types
215 * Zero is reserved as end-of-list indicator 213 * Zero is reserved as end-of-list indicator
216 */ 214 */
217
218#define ARGP_BYTEDATA 0x01 215#define ARGP_BYTEDATA 0x01
219#define ARGP_BYTELIST 0x02 216#define ARGP_BYTELIST 0x02
220#define ARGP_CHARLIST 0x03 217#define ARGP_CHARLIST 0x03
@@ -295,7 +292,6 @@
295/* 292/*
296 * opcode groups and types 293 * opcode groups and types
297 */ 294 */
298
299#define OPGRP_NAMED 0x01 295#define OPGRP_NAMED 0x01
300#define OPGRP_FIELD 0x02 296#define OPGRP_FIELD 0x02
301#define OPGRP_BYTELIST 0x04 297#define OPGRP_BYTELIST 0x04
@@ -381,6 +377,12 @@
381#define AML_TYPE_UNDEFINED 0x19 377#define AML_TYPE_UNDEFINED 0x19
382#define AML_TYPE_BOGUS 0x1A 378#define AML_TYPE_BOGUS 0x1A
383 379
380/* AML Package Length encodings */
381
382#define ACPI_AML_PACKAGE_TYPE1 0x40
383#define ACPI_AML_PACKAGE_TYPE2 0x4000
384#define ACPI_AML_PACKAGE_TYPE3 0x400000
385#define ACPI_AML_PACKAGE_TYPE4 0x40000000
384 386
385/* 387/*
386 * Opcode classes 388 * Opcode classes
diff --git a/include/acpi/pdc_intel.h b/include/acpi/pdc_intel.h
new file mode 100644
index 000000000000..fd6730e4e567
--- /dev/null
+++ b/include/acpi/pdc_intel.h
@@ -0,0 +1,29 @@
1
2/* _PDC bit definition for Intel processors */
3
4#ifndef __PDC_INTEL_H__
5#define __PDC_INTEL_H__
6
7#define ACPI_PDC_P_FFH (0x0001)
8#define ACPI_PDC_C_C1_HALT (0x0002)
9#define ACPI_PDC_T_FFH (0x0004)
10#define ACPI_PDC_SMP_C1PT (0x0008)
11#define ACPI_PDC_SMP_C2C3 (0x0010)
12#define ACPI_PDC_SMP_P_SWCOORD (0x0020)
13#define ACPI_PDC_SMP_C_SWCOORD (0x0040)
14#define ACPI_PDC_SMP_T_SWCOORD (0x0080)
15#define ACPI_PDC_C_C1_FFH (0x0100)
16
17
18#define ACPI_PDC_EST_CAPABILITY_SMP (ACPI_PDC_SMP_C1PT | \
19 ACPI_PDC_C_C1_HALT)
20
21#define ACPI_PDC_EST_CAPABILITY_SMP_MSR (ACPI_PDC_EST_CAPABILITY_SMP | \
22 ACPI_PDC_P_FFH)
23
24#define ACPI_PDC_C_CAPABILITY_SMP (ACPI_PDC_SMP_C2C3 | \
25 ACPI_PDC_SMP_C1PT | \
26 ACPI_PDC_C_C1_HALT)
27
28#endif /* __PDC_INTEL_H__ */
29
diff --git a/include/acpi/platform/acenv.h b/include/acpi/platform/acenv.h
index 57bf9362335d..adf969efa510 100644
--- a/include/acpi/platform/acenv.h
+++ b/include/acpi/platform/acenv.h
@@ -198,6 +198,7 @@
198#endif 198#endif
199#endif /* !DEBUGGER_THREADING */ 199#endif /* !DEBUGGER_THREADING */
200 200
201
201/****************************************************************************** 202/******************************************************************************
202 * 203 *
203 * C library configuration 204 * C library configuration
@@ -209,7 +210,6 @@
209 * Use the standard C library headers. 210 * Use the standard C library headers.
210 * We want to keep these to a minimum. 211 * We want to keep these to a minimum.
211 */ 212 */
212
213#ifdef ACPI_USE_STANDARD_HEADERS 213#ifdef ACPI_USE_STANDARD_HEADERS
214/* 214/*
215 * Use the standard headers from the standard locations 215 * Use the standard headers from the standard locations
@@ -224,14 +224,8 @@
224/* 224/*
225 * We will be linking to the standard Clib functions 225 * We will be linking to the standard Clib functions
226 */ 226 */
227
228#define ACPI_STRSTR(s1,s2) strstr((s1), (s2)) 227#define ACPI_STRSTR(s1,s2) strstr((s1), (s2))
229#define ACPI_STRCHR(s1,c) strchr((s1), (c)) 228#define ACPI_STRCHR(s1,c) strchr((s1), (c))
230
231#ifdef ACPI_FUTURE_USAGE
232#define ACPI_STRUPR(s) (void) acpi_ut_strupr ((s))
233#endif
234
235#define ACPI_STRLEN(s) (acpi_size) strlen((s)) 229#define ACPI_STRLEN(s) (acpi_size) strlen((s))
236#define ACPI_STRCPY(d,s) (void) strcpy((d), (s)) 230#define ACPI_STRCPY(d,s) (void) strcpy((d), (s))
237#define ACPI_STRNCPY(d,s,n) (void) strncpy((d), (s), (acpi_size)(n)) 231#define ACPI_STRNCPY(d,s,n) (void) strncpy((d), (s), (acpi_size)(n))
@@ -254,14 +248,15 @@
254#define ACPI_IS_ALPHA isalpha 248#define ACPI_IS_ALPHA isalpha
255#define ACPI_IS_ASCII isascii 249#define ACPI_IS_ASCII isascii
256 250
251#else
252
257/****************************************************************************** 253/******************************************************************************
258 * 254 *
259 * Not using native C library, use local implementations 255 * Not using native C library, use local implementations
260 * 256 *
261 *****************************************************************************/ 257 *****************************************************************************/
262#else
263 258
264/* 259 /*
265 * Use local definitions of C library macros and functions 260 * Use local definitions of C library macros and functions
266 * NOTE: The function implementations may not be as efficient 261 * NOTE: The function implementations may not be as efficient
267 * as an inline or assembly code implementation provided by a 262 * as an inline or assembly code implementation provided by a
@@ -278,14 +273,12 @@ typedef char *va_list;
278/* 273/*
279 * Storage alignment properties 274 * Storage alignment properties
280 */ 275 */
281
282#define _AUPBND (sizeof (acpi_native_int) - 1) 276#define _AUPBND (sizeof (acpi_native_int) - 1)
283#define _ADNBND (sizeof (acpi_native_int) - 1) 277#define _ADNBND (sizeof (acpi_native_int) - 1)
284 278
285/* 279/*
286 * Variable argument list macro definitions 280 * Variable argument list macro definitions
287 */ 281 */
288
289#define _bnd(X, bnd) (((sizeof (X)) + (bnd)) & (~(bnd))) 282#define _bnd(X, bnd) (((sizeof (X)) + (bnd)) & (~(bnd)))
290#define va_arg(ap, T) (*(T *)(((ap) += (_bnd (T, _AUPBND))) - (_bnd (T,_ADNBND)))) 283#define va_arg(ap, T) (*(T *)(((ap) += (_bnd (T, _AUPBND))) - (_bnd (T,_ADNBND))))
291#define va_end(ap) (void) 0 284#define va_end(ap) (void) 0
@@ -296,11 +289,6 @@ typedef char *va_list;
296 289
297#define ACPI_STRSTR(s1,s2) acpi_ut_strstr ((s1), (s2)) 290#define ACPI_STRSTR(s1,s2) acpi_ut_strstr ((s1), (s2))
298#define ACPI_STRCHR(s1,c) acpi_ut_strchr ((s1), (c)) 291#define ACPI_STRCHR(s1,c) acpi_ut_strchr ((s1), (c))
299
300#ifdef ACPI_FUTURE_USAGE
301#define ACPI_STRUPR(s) (void) acpi_ut_strupr ((s))
302#endif
303
304#define ACPI_STRLEN(s) (acpi_size) acpi_ut_strlen ((s)) 292#define ACPI_STRLEN(s) (acpi_size) acpi_ut_strlen ((s))
305#define ACPI_STRCPY(d,s) (void) acpi_ut_strcpy ((d), (s)) 293#define ACPI_STRCPY(d,s) (void) acpi_ut_strcpy ((d), (s))
306#define ACPI_STRNCPY(d,s,n) (void) acpi_ut_strncpy ((d), (s), (acpi_size)(n)) 294#define ACPI_STRNCPY(d,s,n) (void) acpi_ut_strncpy ((d), (s), (acpi_size)(n))
diff --git a/include/acpi/processor.h b/include/acpi/processor.h
index 2f50a5bb0c78..50cfea4ff6ca 100644
--- a/include/acpi/processor.h
+++ b/include/acpi/processor.h
@@ -4,6 +4,8 @@
4#include <linux/kernel.h> 4#include <linux/kernel.h>
5#include <linux/config.h> 5#include <linux/config.h>
6 6
7#include <asm/acpi.h>
8
7#define ACPI_PROCESSOR_BUSY_METRIC 10 9#define ACPI_PROCESSOR_BUSY_METRIC 10
8 10
9#define ACPI_PROCESSOR_MAX_POWER 8 11#define ACPI_PROCESSOR_MAX_POWER 8
@@ -14,6 +16,8 @@
14#define ACPI_PROCESSOR_MAX_THROTTLE 250 /* 25% */ 16#define ACPI_PROCESSOR_MAX_THROTTLE 250 /* 25% */
15#define ACPI_PROCESSOR_MAX_DUTY_WIDTH 4 17#define ACPI_PROCESSOR_MAX_DUTY_WIDTH 4
16 18
19#define ACPI_PDC_REVISION_ID 0x1
20
17/* Power Management */ 21/* Power Management */
18 22
19struct acpi_processor_cx; 23struct acpi_processor_cx;
@@ -59,6 +63,9 @@ struct acpi_processor_power {
59 u32 bm_activity; 63 u32 bm_activity;
60 int count; 64 int count;
61 struct acpi_processor_cx states[ACPI_PROCESSOR_MAX_POWER]; 65 struct acpi_processor_cx states[ACPI_PROCESSOR_MAX_POWER];
66
67 /* the _PDC objects passed by the driver, if any */
68 struct acpi_object_list *pdc;
62}; 69};
63 70
64/* Performance Management */ 71/* Performance Management */
@@ -82,8 +89,6 @@ struct acpi_processor_px {
82 acpi_integer status; /* success indicator */ 89 acpi_integer status; /* success indicator */
83}; 90};
84 91
85#define ACPI_PDC_REVISION_ID 0x1
86
87struct acpi_processor_performance { 92struct acpi_processor_performance {
88 unsigned int state; 93 unsigned int state;
89 unsigned int platform_limit; 94 unsigned int platform_limit;
@@ -179,7 +184,32 @@ int acpi_processor_notify_smm(struct module *calling_module);
179extern struct acpi_processor *processors[NR_CPUS]; 184extern struct acpi_processor *processors[NR_CPUS];
180extern struct acpi_processor_errata errata; 185extern struct acpi_processor_errata errata;
181 186
187int acpi_processor_set_pdc(struct acpi_processor *pr,
188 struct acpi_object_list *pdc_in);
189
190#ifdef ARCH_HAS_POWER_PDC_INIT
191void acpi_processor_power_init_pdc(struct acpi_processor_power *pow,
192 unsigned int cpu);
193void acpi_processor_power_init_bm_check(struct acpi_processor_flags *flags,
194 unsigned int cpu);
195#else
196static inline void acpi_processor_power_init_pdc(
197 struct acpi_processor_power *pow, unsigned int cpu)
198{
199 pow->pdc = NULL;
200 return;
201}
202
203static inline void acpi_processor_power_init_bm_check(
204 struct acpi_processor_flags *flags, unsigned int cpu)
205{
206 flags->bm_check = 1;
207 return;
208}
209#endif
210
182/* in processor_perflib.c */ 211/* in processor_perflib.c */
212
183#ifdef CONFIG_CPU_FREQ 213#ifdef CONFIG_CPU_FREQ
184void acpi_processor_ppc_init(void); 214void acpi_processor_ppc_init(void);
185void acpi_processor_ppc_exit(void); 215void acpi_processor_ppc_exit(void);
diff --git a/include/asm-alpha/pci.h b/include/asm-alpha/pci.h
index b7806aa3785c..28957697e59c 100644
--- a/include/asm-alpha/pci.h
+++ b/include/asm-alpha/pci.h
@@ -58,7 +58,7 @@ struct pci_controller {
58 58
59extern void pcibios_set_master(struct pci_dev *dev); 59extern void pcibios_set_master(struct pci_dev *dev);
60 60
61extern inline void pcibios_penalize_isa_irq(int irq) 61extern inline void pcibios_penalize_isa_irq(int irq, int active)
62{ 62{
63 /* We don't do dynamic PCI IRQ allocation */ 63 /* We don't do dynamic PCI IRQ allocation */
64} 64}
diff --git a/include/asm-alpha/pgtable.h b/include/asm-alpha/pgtable.h
index e139463d9a0e..22b53e369f59 100644
--- a/include/asm-alpha/pgtable.h
+++ b/include/asm-alpha/pgtable.h
@@ -132,6 +132,10 @@
132#define __S110 _PAGE_S(0) 132#define __S110 _PAGE_S(0)
133#define __S111 _PAGE_S(0) 133#define __S111 _PAGE_S(0)
134 134
135/*
136 * pgprot_noncached() is only for infiniband pci support, and a real
137 * implementation for RAM would be more complicated.
138 */
135#define pgprot_noncached(prot) (prot) 139#define pgprot_noncached(prot) (prot)
136 140
137/* 141/*
diff --git a/include/asm-arm/pci.h b/include/asm-arm/pci.h
index e300646fe650..b28f1c95dd62 100644
--- a/include/asm-arm/pci.h
+++ b/include/asm-arm/pci.h
@@ -14,7 +14,7 @@ static inline void pcibios_set_master(struct pci_dev *dev)
14 /* No special bus mastering setup handling */ 14 /* No special bus mastering setup handling */
15} 15}
16 16
17static inline void pcibios_penalize_isa_irq(int irq) 17static inline void pcibios_penalize_isa_irq(int irq, int active)
18{ 18{
19 /* We don't do dynamic PCI IRQ allocation */ 19 /* We don't do dynamic PCI IRQ allocation */
20} 20}
diff --git a/include/asm-arm/smp.h b/include/asm-arm/smp.h
index 6c6c60adbbaa..dbb4d859c586 100644
--- a/include/asm-arm/smp.h
+++ b/include/asm-arm/smp.h
@@ -23,9 +23,6 @@
23 23
24#define raw_smp_processor_id() (current_thread_info()->cpu) 24#define raw_smp_processor_id() (current_thread_info()->cpu)
25 25
26extern cpumask_t cpu_present_mask;
27#define cpu_possible_map cpu_present_mask
28
29/* 26/*
30 * at the moment, there's not a big penalty for changing CPUs 27 * at the moment, there's not a big penalty for changing CPUs
31 * (the >big< penalty is running SMP in the first place) 28 * (the >big< penalty is running SMP in the first place)
diff --git a/include/asm-h8300/pci.h b/include/asm-h8300/pci.h
index d032729b19df..5edad5b70fd5 100644
--- a/include/asm-h8300/pci.h
+++ b/include/asm-h8300/pci.h
@@ -15,7 +15,7 @@ extern inline void pcibios_set_master(struct pci_dev *dev)
15 /* No special bus mastering setup handling */ 15 /* No special bus mastering setup handling */
16} 16}
17 17
18extern inline void pcibios_penalize_isa_irq(int irq) 18extern inline void pcibios_penalize_isa_irq(int irq, int active)
19{ 19{
20 /* We don't do dynamic PCI IRQ allocation */ 20 /* We don't do dynamic PCI IRQ allocation */
21} 21}
diff --git a/include/asm-i386/acpi.h b/include/asm-i386/acpi.h
index c976c1dadece..cf828ace13f9 100644
--- a/include/asm-i386/acpi.h
+++ b/include/asm-i386/acpi.h
@@ -28,6 +28,8 @@
28 28
29#ifdef __KERNEL__ 29#ifdef __KERNEL__
30 30
31#include <acpi/pdc_intel.h>
32
31#include <asm/system.h> /* defines cmpxchg */ 33#include <asm/system.h> /* defines cmpxchg */
32 34
33#define COMPILER_DEPENDENT_INT64 long long 35#define COMPILER_DEPENDENT_INT64 long long
@@ -101,12 +103,6 @@ __acpi_release_global_lock (unsigned int *lock)
101 :"=r"(n_hi), "=r"(n_lo) \ 103 :"=r"(n_hi), "=r"(n_lo) \
102 :"0"(n_hi), "1"(n_lo)) 104 :"0"(n_hi), "1"(n_lo))
103 105
104/*
105 * Refer Intel ACPI _PDC support document for bit definitions
106 */
107#define ACPI_PDC_EST_CAPABILITY_SMP 0xa
108#define ACPI_PDC_EST_CAPABILITY_MSR 0x1
109
110#ifdef CONFIG_ACPI_BOOT 106#ifdef CONFIG_ACPI_BOOT
111extern int acpi_lapic; 107extern int acpi_lapic;
112extern int acpi_ioapic; 108extern int acpi_ioapic;
@@ -185,6 +181,8 @@ extern void acpi_reserve_bootmem(void);
185 181
186extern u8 x86_acpiid_to_apicid[]; 182extern u8 x86_acpiid_to_apicid[];
187 183
184#define ARCH_HAS_POWER_PDC_INIT 1
185
188#endif /*__KERNEL__*/ 186#endif /*__KERNEL__*/
189 187
190#endif /*_ASM_ACPI_H*/ 188#endif /*_ASM_ACPI_H*/
diff --git a/include/asm-i386/apicdef.h b/include/asm-i386/apicdef.h
index 0fed5e3c699c..a96a8f48fbfc 100644
--- a/include/asm-i386/apicdef.h
+++ b/include/asm-i386/apicdef.h
@@ -109,11 +109,7 @@
109 109
110#define APIC_BASE (fix_to_virt(FIX_APIC_BASE)) 110#define APIC_BASE (fix_to_virt(FIX_APIC_BASE))
111 111
112#ifdef CONFIG_NUMA 112#define MAX_IO_APICS 64
113 #define MAX_IO_APICS 32
114#else
115 #define MAX_IO_APICS 8
116#endif
117 113
118/* 114/*
119 * the local APIC register structure, memory mapped. Not terribly well 115 * the local APIC register structure, memory mapped. Not terribly well
diff --git a/include/asm-i386/pci.h b/include/asm-i386/pci.h
index 3561899eb826..78c85985aee3 100644
--- a/include/asm-i386/pci.h
+++ b/include/asm-i386/pci.h
@@ -27,7 +27,7 @@ void pcibios_config_init(void);
27struct pci_bus * pcibios_scan_root(int bus); 27struct pci_bus * pcibios_scan_root(int bus);
28 28
29void pcibios_set_master(struct pci_dev *dev); 29void pcibios_set_master(struct pci_dev *dev);
30void pcibios_penalize_isa_irq(int irq); 30void pcibios_penalize_isa_irq(int irq, int active);
31struct irq_routing_table *pcibios_get_irq_routing_table(void); 31struct irq_routing_table *pcibios_get_irq_routing_table(void);
32int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq); 32int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq);
33 33
diff --git a/include/asm-i386/unistd.h b/include/asm-i386/unistd.h
index e25e4c71a879..a7cb377745bf 100644
--- a/include/asm-i386/unistd.h
+++ b/include/asm-i386/unistd.h
@@ -296,8 +296,11 @@
296#define __NR_keyctl 288 296#define __NR_keyctl 288
297#define __NR_ioprio_set 289 297#define __NR_ioprio_set 289
298#define __NR_ioprio_get 290 298#define __NR_ioprio_get 290
299#define __NR_inotify_init 291
300#define __NR_inotify_add_watch 292
301#define __NR_inotify_rm_watch 293
299 302
300#define NR_syscalls 291 303#define NR_syscalls 294
301 304
302/* 305/*
303 * user-visible error numbers are in the range -1 - -128: see 306 * user-visible error numbers are in the range -1 - -128: see
diff --git a/include/asm-ia64/acpi.h b/include/asm-ia64/acpi.h
index 6a26a977f253..4c06d455139c 100644
--- a/include/asm-ia64/acpi.h
+++ b/include/asm-ia64/acpi.h
@@ -98,6 +98,15 @@ const char *acpi_get_sysname (void);
98int acpi_request_vector (u32 int_type); 98int acpi_request_vector (u32 int_type);
99int acpi_gsi_to_irq (u32 gsi, unsigned int *irq); 99int acpi_gsi_to_irq (u32 gsi, unsigned int *irq);
100 100
101/*
102 * Record the cpei override flag and current logical cpu. This is
103 * useful for CPU removal.
104 */
105extern unsigned int can_cpei_retarget(void);
106extern unsigned int is_cpu_cpei_target(unsigned int cpu);
107extern void set_cpei_target_cpu(unsigned int cpu);
108extern unsigned int get_cpei_target_cpu(void);
109
101#ifdef CONFIG_ACPI_NUMA 110#ifdef CONFIG_ACPI_NUMA
102/* Proximity bitmap length; _PXM is at most 255 (8 bit)*/ 111/* Proximity bitmap length; _PXM is at most 255 (8 bit)*/
103#define MAX_PXM_DOMAINS (256) 112#define MAX_PXM_DOMAINS (256)
diff --git a/include/asm-ia64/pci.h b/include/asm-ia64/pci.h
index 8b7237cc84c1..dba9f220be71 100644
--- a/include/asm-ia64/pci.h
+++ b/include/asm-ia64/pci.h
@@ -47,7 +47,7 @@ pcibios_set_master (struct pci_dev *dev)
47} 47}
48 48
49static inline void 49static inline void
50pcibios_penalize_isa_irq (int irq) 50pcibios_penalize_isa_irq (int irq, int active)
51{ 51{
52 /* We don't do dynamic PCI IRQ allocation */ 52 /* We don't do dynamic PCI IRQ allocation */
53} 53}
diff --git a/include/asm-m68k/pci.h b/include/asm-m68k/pci.h
index 9e7d79ab5d13..9d2c07abe44f 100644
--- a/include/asm-m68k/pci.h
+++ b/include/asm-m68k/pci.h
@@ -43,7 +43,7 @@ static inline void pcibios_set_master(struct pci_dev *dev)
43 /* No special bus mastering setup handling */ 43 /* No special bus mastering setup handling */
44} 44}
45 45
46static inline void pcibios_penalize_isa_irq(int irq) 46static inline void pcibios_penalize_isa_irq(int irq, int active)
47{ 47{
48 /* We don't do dynamic PCI IRQ allocation */ 48 /* We don't do dynamic PCI IRQ allocation */
49} 49}
diff --git a/include/asm-mips/pci.h b/include/asm-mips/pci.h
index 2d323b6e147d..d70dc355c1f3 100644
--- a/include/asm-mips/pci.h
+++ b/include/asm-mips/pci.h
@@ -69,7 +69,7 @@ extern unsigned long PCIBIOS_MIN_MEM;
69 69
70extern void pcibios_set_master(struct pci_dev *dev); 70extern void pcibios_set_master(struct pci_dev *dev);
71 71
72static inline void pcibios_penalize_isa_irq(int irq) 72static inline void pcibios_penalize_isa_irq(int irq, int active)
73{ 73{
74 /* We don't do dynamic PCI IRQ allocation */ 74 /* We don't do dynamic PCI IRQ allocation */
75} 75}
diff --git a/include/asm-ppc/kexec.h b/include/asm-ppc/kexec.h
index 73191310d8db..6d2aa0aa4642 100644
--- a/include/asm-ppc/kexec.h
+++ b/include/asm-ppc/kexec.h
@@ -27,6 +27,8 @@
27 27
28#ifndef __ASSEMBLY__ 28#ifndef __ASSEMBLY__
29 29
30extern void *crash_notes;
31
30struct kimage; 32struct kimage;
31 33
32extern void machine_kexec_simple(struct kimage *image); 34extern void machine_kexec_simple(struct kimage *image);
diff --git a/include/asm-ppc/pci.h b/include/asm-ppc/pci.h
index db0a2a0ec74d..a13d55870e62 100644
--- a/include/asm-ppc/pci.h
+++ b/include/asm-ppc/pci.h
@@ -37,7 +37,7 @@ extern inline void pcibios_set_master(struct pci_dev *dev)
37 /* No special bus mastering setup handling */ 37 /* No special bus mastering setup handling */
38} 38}
39 39
40extern inline void pcibios_penalize_isa_irq(int irq) 40extern inline void pcibios_penalize_isa_irq(int irq, int active)
41{ 41{
42 /* We don't do dynamic PCI IRQ allocation */ 42 /* We don't do dynamic PCI IRQ allocation */
43} 43}
diff --git a/include/asm-ppc64/pci.h b/include/asm-ppc64/pci.h
index d12dfce21e20..faa772223075 100644
--- a/include/asm-ppc64/pci.h
+++ b/include/asm-ppc64/pci.h
@@ -37,7 +37,7 @@ static inline void pcibios_set_master(struct pci_dev *dev)
37 /* No special bus mastering setup handling */ 37 /* No special bus mastering setup handling */
38} 38}
39 39
40static inline void pcibios_penalize_isa_irq(int irq) 40static inline void pcibios_penalize_isa_irq(int irq, int active)
41{ 41{
42 /* We don't do dynamic PCI IRQ allocation */ 42 /* We don't do dynamic PCI IRQ allocation */
43} 43}
diff --git a/include/asm-sh/pci.h b/include/asm-sh/pci.h
index 26044889c770..0a523c85b11c 100644
--- a/include/asm-sh/pci.h
+++ b/include/asm-sh/pci.h
@@ -36,7 +36,7 @@ struct pci_dev;
36 36
37extern void pcibios_set_master(struct pci_dev *dev); 37extern void pcibios_set_master(struct pci_dev *dev);
38 38
39static inline void pcibios_penalize_isa_irq(int irq) 39static inline void pcibios_penalize_isa_irq(int irq, int active)
40{ 40{
41 /* We don't do dynamic PCI IRQ allocation */ 41 /* We don't do dynamic PCI IRQ allocation */
42} 42}
diff --git a/include/asm-sh64/pci.h b/include/asm-sh64/pci.h
index c68870e02d91..aa8043089bb6 100644
--- a/include/asm-sh64/pci.h
+++ b/include/asm-sh64/pci.h
@@ -26,7 +26,7 @@ extern void pcibios_set_master(struct pci_dev *dev);
26/* 26/*
27 * Set penalize isa irq function 27 * Set penalize isa irq function
28 */ 28 */
29static inline void pcibios_penalize_isa_irq(int irq) 29static inline void pcibios_penalize_isa_irq(int irq, int active)
30{ 30{
31 /* We don't do dynamic PCI IRQ allocation */ 31 /* We don't do dynamic PCI IRQ allocation */
32} 32}
diff --git a/include/asm-sparc/pci.h b/include/asm-sparc/pci.h
index 44bb38758c96..97052baf90c1 100644
--- a/include/asm-sparc/pci.h
+++ b/include/asm-sparc/pci.h
@@ -20,7 +20,7 @@ extern inline void pcibios_set_master(struct pci_dev *dev)
20 /* No special bus mastering setup handling */ 20 /* No special bus mastering setup handling */
21} 21}
22 22
23extern inline void pcibios_penalize_isa_irq(int irq) 23extern inline void pcibios_penalize_isa_irq(int irq, int active)
24{ 24{
25 /* We don't do dynamic PCI IRQ allocation */ 25 /* We don't do dynamic PCI IRQ allocation */
26} 26}
diff --git a/include/asm-sparc64/pci.h b/include/asm-sparc64/pci.h
index 84e41c1ef3f8..a4ab0ec7143a 100644
--- a/include/asm-sparc64/pci.h
+++ b/include/asm-sparc64/pci.h
@@ -23,7 +23,7 @@ static inline void pcibios_set_master(struct pci_dev *dev)
23 /* No special bus mastering setup handling */ 23 /* No special bus mastering setup handling */
24} 24}
25 25
26static inline void pcibios_penalize_isa_irq(int irq) 26static inline void pcibios_penalize_isa_irq(int irq, int active)
27{ 27{
28 /* We don't do dynamic PCI IRQ allocation */ 28 /* We don't do dynamic PCI IRQ allocation */
29} 29}
diff --git a/include/asm-sparc64/seccomp.h b/include/asm-sparc64/seccomp.h
new file mode 100644
index 000000000000..7fcd9968192b
--- /dev/null
+++ b/include/asm-sparc64/seccomp.h
@@ -0,0 +1,21 @@
1#ifndef _ASM_SECCOMP_H
2
3#include <linux/thread_info.h> /* already defines TIF_32BIT */
4
5#ifndef TIF_32BIT
6#error "unexpected TIF_32BIT on sparc64"
7#endif
8
9#include <linux/unistd.h>
10
11#define __NR_seccomp_read __NR_read
12#define __NR_seccomp_write __NR_write
13#define __NR_seccomp_exit __NR_exit
14#define __NR_seccomp_sigreturn __NR_rt_sigreturn
15
16#define __NR_seccomp_read_32 __NR_read
17#define __NR_seccomp_write_32 __NR_write
18#define __NR_seccomp_exit_32 __NR_exit
19#define __NR_seccomp_sigreturn_32 __NR_sigreturn
20
21#endif /* _ASM_SECCOMP_H */
diff --git a/include/asm-um/mmu_context.h b/include/asm-um/mmu_context.h
index 7529c9c853dd..095bb627b96a 100644
--- a/include/asm-um/mmu_context.h
+++ b/include/asm-um/mmu_context.h
@@ -16,8 +16,12 @@
16 16
17#define deactivate_mm(tsk,mm) do { } while (0) 17#define deactivate_mm(tsk,mm) do { } while (0)
18 18
19extern void force_flush_all(void);
20
19static inline void activate_mm(struct mm_struct *old, struct mm_struct *new) 21static inline void activate_mm(struct mm_struct *old, struct mm_struct *new)
20{ 22{
23 if (old != new)
24 force_flush_all();
21} 25}
22 26
23static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next, 27static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
diff --git a/include/asm-x86_64/acpi.h b/include/asm-x86_64/acpi.h
index a6b41b892062..dc8c981af27f 100644
--- a/include/asm-x86_64/acpi.h
+++ b/include/asm-x86_64/acpi.h
@@ -28,6 +28,8 @@
28 28
29#ifdef __KERNEL__ 29#ifdef __KERNEL__
30 30
31#include <acpi/pdc_intel.h>
32
31#define COMPILER_DEPENDENT_INT64 long long 33#define COMPILER_DEPENDENT_INT64 long long
32#define COMPILER_DEPENDENT_UINT64 unsigned long long 34#define COMPILER_DEPENDENT_UINT64 unsigned long long
33 35
@@ -99,12 +101,6 @@ __acpi_release_global_lock (unsigned int *lock)
99 :"=r"(n_hi), "=r"(n_lo) \ 101 :"=r"(n_hi), "=r"(n_lo) \
100 :"0"(n_hi), "1"(n_lo)) 102 :"0"(n_hi), "1"(n_lo))
101 103
102/*
103 * Refer Intel ACPI _PDC support document for bit definitions
104 */
105#define ACPI_PDC_EST_CAPABILITY_SMP 0xa
106#define ACPI_PDC_EST_CAPABILITY_MSR 0x1
107
108#ifdef CONFIG_ACPI_BOOT 104#ifdef CONFIG_ACPI_BOOT
109extern int acpi_lapic; 105extern int acpi_lapic;
110extern int acpi_ioapic; 106extern int acpi_ioapic;
diff --git a/include/asm-x86_64/pci.h b/include/asm-x86_64/pci.h
index c1961db88fac..eeb3088a1c9e 100644
--- a/include/asm-x86_64/pci.h
+++ b/include/asm-x86_64/pci.h
@@ -33,7 +33,7 @@ extern int (*pci_config_read)(int seg, int bus, int dev, int fn, int reg, int le
33extern int (*pci_config_write)(int seg, int bus, int dev, int fn, int reg, int len, u32 value); 33extern int (*pci_config_write)(int seg, int bus, int dev, int fn, int reg, int len, u32 value);
34 34
35void pcibios_set_master(struct pci_dev *dev); 35void pcibios_set_master(struct pci_dev *dev);
36void pcibios_penalize_isa_irq(int irq); 36void pcibios_penalize_isa_irq(int irq, int active);
37struct irq_routing_table *pcibios_get_irq_routing_table(void); 37struct irq_routing_table *pcibios_get_irq_routing_table(void);
38int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq); 38int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq);
39 39
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index ef8483673aa3..f85cbe919e13 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -206,7 +206,10 @@ struct acpi_table_plat_int_src {
206 u8 eid; 206 u8 eid;
207 u8 iosapic_vector; 207 u8 iosapic_vector;
208 u32 global_irq; 208 u32 global_irq;
209 u32 reserved; 209 struct {
210 u32 cpei_override_flag:1;
211 u32 reserved:31;
212 } plint_flags;
210} __attribute__ ((packed)); 213} __attribute__ ((packed));
211 214
212enum acpi_interrupt_id { 215enum acpi_interrupt_id {
@@ -475,7 +478,7 @@ struct acpi_prt_list {
475struct pci_dev; 478struct pci_dev;
476 479
477int acpi_pci_irq_enable (struct pci_dev *dev); 480int acpi_pci_irq_enable (struct pci_dev *dev);
478void acpi_penalize_isa_irq(int irq); 481void acpi_penalize_isa_irq(int irq, int active);
479 482
480#ifdef CONFIG_ACPI_DEALLOCATE_IRQ 483#ifdef CONFIG_ACPI_DEALLOCATE_IRQ
481void acpi_pci_irq_disable (struct pci_dev *dev); 484void acpi_pci_irq_disable (struct pci_dev *dev);
diff --git a/include/linux/device.h b/include/linux/device.h
index f378c846e6d5..06e5d42f2c7b 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -284,8 +284,10 @@ struct device {
284 struct device_driver *driver; /* which driver has allocated this 284 struct device_driver *driver; /* which driver has allocated this
285 device */ 285 device */
286 void *driver_data; /* data private to the driver */ 286 void *driver_data; /* data private to the driver */
287 void *platform_data; /* Platform specific data (e.g. ACPI, 287 void *platform_data; /* Platform specific data, device
288 BIOS data relevant to device) */ 288 core doesn't touch it */
289 void *firmware_data; /* Firmware specific data (e.g. ACPI,
290 BIOS data),reserved for device core*/
289 struct dev_pm_info power; 291 struct dev_pm_info power;
290 292
291 u64 *dma_mask; /* dma mask (if dma'able device) */ 293 u64 *dma_mask; /* dma mask (if dma'able device) */
diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h
index cf3847edc50f..ce8518e658b6 100644
--- a/include/linux/etherdevice.h
+++ b/include/linux/etherdevice.h
@@ -33,7 +33,7 @@ extern int eth_header(struct sk_buff *skb, struct net_device *dev,
33 unsigned short type, void *daddr, 33 unsigned short type, void *daddr,
34 void *saddr, unsigned len); 34 void *saddr, unsigned len);
35extern int eth_rebuild_header(struct sk_buff *skb); 35extern int eth_rebuild_header(struct sk_buff *skb);
36extern unsigned short eth_type_trans(struct sk_buff *skb, struct net_device *dev); 36extern __be16 eth_type_trans(struct sk_buff *skb, struct net_device *dev);
37extern void eth_header_cache_update(struct hh_cache *hh, struct net_device *dev, 37extern void eth_header_cache_update(struct hh_cache *hh, struct net_device *dev,
38 unsigned char * haddr); 38 unsigned char * haddr);
39extern int eth_header_cache(struct neighbour *neigh, 39extern int eth_header_cache(struct neighbour *neigh,
diff --git a/include/linux/ext3_fs.h b/include/linux/ext3_fs.h
index 4b6e1ab216a5..c16662836c58 100644
--- a/include/linux/ext3_fs.h
+++ b/include/linux/ext3_fs.h
@@ -239,6 +239,20 @@ struct ext3_new_group_data {
239#define EXT3_IOC_SETRSVSZ _IOW('f', 6, long) 239#define EXT3_IOC_SETRSVSZ _IOW('f', 6, long)
240 240
241/* 241/*
242 * Mount options
243 */
244struct ext3_mount_options {
245 unsigned long s_mount_opt;
246 uid_t s_resuid;
247 gid_t s_resgid;
248 unsigned long s_commit_interval;
249#ifdef CONFIG_QUOTA
250 int s_jquota_fmt;
251 char *s_qf_names[MAXQUOTAS];
252#endif
253};
254
255/*
242 * Structure of an inode on the disk 256 * Structure of an inode on the disk
243 */ 257 */
244struct ext3_inode { 258struct ext3_inode {
diff --git a/include/linux/fddidevice.h b/include/linux/fddidevice.h
index 002f6367697d..e61e42dfd317 100644
--- a/include/linux/fddidevice.h
+++ b/include/linux/fddidevice.h
@@ -25,7 +25,7 @@
25#include <linux/if_fddi.h> 25#include <linux/if_fddi.h>
26 26
27#ifdef __KERNEL__ 27#ifdef __KERNEL__
28extern unsigned short fddi_type_trans(struct sk_buff *skb, 28extern __be16 fddi_type_trans(struct sk_buff *skb,
29 struct net_device *dev); 29 struct net_device *dev);
30extern struct net_device *alloc_fddidev(int sizeof_priv); 30extern struct net_device *alloc_fddidev(int sizeof_priv);
31#endif 31#endif
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 302ec20838ca..c9bf3746a9fb 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -474,6 +474,11 @@ struct inode {
474 struct dnotify_struct *i_dnotify; /* for directory notifications */ 474 struct dnotify_struct *i_dnotify; /* for directory notifications */
475#endif 475#endif
476 476
477#ifdef CONFIG_INOTIFY
478 struct list_head inotify_watches; /* watches on this inode */
479 struct semaphore inotify_sem; /* protects the watches list */
480#endif
481
477 unsigned long i_state; 482 unsigned long i_state;
478 unsigned long dirtied_when; /* jiffies of first dirtying */ 483 unsigned long dirtied_when; /* jiffies of first dirtying */
479 484
@@ -1393,7 +1398,6 @@ extern void emergency_remount(void);
1393extern int do_remount_sb(struct super_block *sb, int flags, 1398extern int do_remount_sb(struct super_block *sb, int flags,
1394 void *data, int force); 1399 void *data, int force);
1395extern sector_t bmap(struct inode *, sector_t); 1400extern sector_t bmap(struct inode *, sector_t);
1396extern int setattr_mask(unsigned int);
1397extern int notify_change(struct dentry *, struct iattr *); 1401extern int notify_change(struct dentry *, struct iattr *);
1398extern int permission(struct inode *, int, struct nameidata *); 1402extern int permission(struct inode *, int, struct nameidata *);
1399extern int generic_permission(struct inode *, int, 1403extern int generic_permission(struct inode *, int,
diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
new file mode 100644
index 000000000000..d07a92c94776
--- /dev/null
+++ b/include/linux/fsnotify.h
@@ -0,0 +1,248 @@
1#ifndef _LINUX_FS_NOTIFY_H
2#define _LINUX_FS_NOTIFY_H
3
4/*
5 * include/linux/fsnotify.h - generic hooks for filesystem notification, to
6 * reduce in-source duplication from both dnotify and inotify.
7 *
8 * We don't compile any of this away in some complicated menagerie of ifdefs.
9 * Instead, we rely on the code inside to optimize away as needed.
10 *
11 * (C) Copyright 2005 Robert Love
12 */
13
14#ifdef __KERNEL__
15
16#include <linux/dnotify.h>
17#include <linux/inotify.h>
18
19/*
20 * fsnotify_move - file old_name at old_dir was moved to new_name at new_dir
21 */
22static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir,
23 const char *old_name, const char *new_name,
24 int isdir)
25{
26 u32 cookie = inotify_get_cookie();
27
28 if (old_dir == new_dir)
29 inode_dir_notify(old_dir, DN_RENAME);
30 else {
31 inode_dir_notify(old_dir, DN_DELETE);
32 inode_dir_notify(new_dir, DN_CREATE);
33 }
34
35 if (isdir)
36 isdir = IN_ISDIR;
37 inotify_inode_queue_event(old_dir, IN_MOVED_FROM|isdir,cookie,old_name);
38 inotify_inode_queue_event(new_dir, IN_MOVED_TO|isdir, cookie, new_name);
39}
40
41/*
42 * fsnotify_unlink - file was unlinked
43 */
44static inline void fsnotify_unlink(struct dentry *dentry, struct inode *dir)
45{
46 struct inode *inode = dentry->d_inode;
47
48 inode_dir_notify(dir, DN_DELETE);
49 inotify_inode_queue_event(dir, IN_DELETE, 0, dentry->d_name.name);
50 inotify_inode_queue_event(inode, IN_DELETE_SELF, 0, NULL);
51
52 inotify_inode_is_dead(inode);
53}
54
55/*
56 * fsnotify_rmdir - directory was removed
57 */
58static inline void fsnotify_rmdir(struct dentry *dentry, struct inode *inode,
59 struct inode *dir)
60{
61 inode_dir_notify(dir, DN_DELETE);
62 inotify_inode_queue_event(dir,IN_DELETE|IN_ISDIR,0,dentry->d_name.name);
63 inotify_inode_queue_event(inode, IN_DELETE_SELF | IN_ISDIR, 0, NULL);
64 inotify_inode_is_dead(inode);
65}
66
67/*
68 * fsnotify_create - 'name' was linked in
69 */
70static inline void fsnotify_create(struct inode *inode, const char *name)
71{
72 inode_dir_notify(inode, DN_CREATE);
73 inotify_inode_queue_event(inode, IN_CREATE, 0, name);
74}
75
76/*
77 * fsnotify_mkdir - directory 'name' was created
78 */
79static inline void fsnotify_mkdir(struct inode *inode, const char *name)
80{
81 inode_dir_notify(inode, DN_CREATE);
82 inotify_inode_queue_event(inode, IN_CREATE | IN_ISDIR, 0, name);
83}
84
85/*
86 * fsnotify_access - file was read
87 */
88static inline void fsnotify_access(struct dentry *dentry)
89{
90 struct inode *inode = dentry->d_inode;
91 u32 mask = IN_ACCESS;
92
93 if (S_ISDIR(inode->i_mode))
94 mask |= IN_ISDIR;
95
96 dnotify_parent(dentry, DN_ACCESS);
97 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
98 inotify_inode_queue_event(inode, mask, 0, NULL);
99}
100
101/*
102 * fsnotify_modify - file was modified
103 */
104static inline void fsnotify_modify(struct dentry *dentry)
105{
106 struct inode *inode = dentry->d_inode;
107 u32 mask = IN_MODIFY;
108
109 if (S_ISDIR(inode->i_mode))
110 mask |= IN_ISDIR;
111
112 dnotify_parent(dentry, DN_MODIFY);
113 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
114 inotify_inode_queue_event(inode, mask, 0, NULL);
115}
116
117/*
118 * fsnotify_open - file was opened
119 */
120static inline void fsnotify_open(struct dentry *dentry)
121{
122 struct inode *inode = dentry->d_inode;
123 u32 mask = IN_OPEN;
124
125 if (S_ISDIR(inode->i_mode))
126 mask |= IN_ISDIR;
127
128 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
129 inotify_inode_queue_event(inode, mask, 0, NULL);
130}
131
132/*
133 * fsnotify_close - file was closed
134 */
135static inline void fsnotify_close(struct file *file)
136{
137 struct dentry *dentry = file->f_dentry;
138 struct inode *inode = dentry->d_inode;
139 const char *name = dentry->d_name.name;
140 mode_t mode = file->f_mode;
141 u32 mask = (mode & FMODE_WRITE) ? IN_CLOSE_WRITE : IN_CLOSE_NOWRITE;
142
143 if (S_ISDIR(inode->i_mode))
144 mask |= IN_ISDIR;
145
146 inotify_dentry_parent_queue_event(dentry, mask, 0, name);
147 inotify_inode_queue_event(inode, mask, 0, NULL);
148}
149
150/*
151 * fsnotify_xattr - extended attributes were changed
152 */
153static inline void fsnotify_xattr(struct dentry *dentry)
154{
155 struct inode *inode = dentry->d_inode;
156 u32 mask = IN_ATTRIB;
157
158 if (S_ISDIR(inode->i_mode))
159 mask |= IN_ISDIR;
160
161 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
162 inotify_inode_queue_event(inode, mask, 0, NULL);
163}
164
165/*
166 * fsnotify_change - notify_change event. file was modified and/or metadata
167 * was changed.
168 */
169static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
170{
171 struct inode *inode = dentry->d_inode;
172 int dn_mask = 0;
173 u32 in_mask = 0;
174
175 if (ia_valid & ATTR_UID) {
176 in_mask |= IN_ATTRIB;
177 dn_mask |= DN_ATTRIB;
178 }
179 if (ia_valid & ATTR_GID) {
180 in_mask |= IN_ATTRIB;
181 dn_mask |= DN_ATTRIB;
182 }
183 if (ia_valid & ATTR_SIZE) {
184 in_mask |= IN_MODIFY;
185 dn_mask |= DN_MODIFY;
186 }
187 /* both times implies a utime(s) call */
188 if ((ia_valid & (ATTR_ATIME | ATTR_MTIME)) == (ATTR_ATIME | ATTR_MTIME))
189 {
190 in_mask |= IN_ATTRIB;
191 dn_mask |= DN_ATTRIB;
192 } else if (ia_valid & ATTR_ATIME) {
193 in_mask |= IN_ACCESS;
194 dn_mask |= DN_ACCESS;
195 } else if (ia_valid & ATTR_MTIME) {
196 in_mask |= IN_MODIFY;
197 dn_mask |= DN_MODIFY;
198 }
199 if (ia_valid & ATTR_MODE) {
200 in_mask |= IN_ATTRIB;
201 dn_mask |= DN_ATTRIB;
202 }
203
204 if (dn_mask)
205 dnotify_parent(dentry, dn_mask);
206 if (in_mask) {
207 if (S_ISDIR(inode->i_mode))
208 in_mask |= IN_ISDIR;
209 inotify_inode_queue_event(inode, in_mask, 0, NULL);
210 inotify_dentry_parent_queue_event(dentry, in_mask, 0,
211 dentry->d_name.name);
212 }
213}
214
215#ifdef CONFIG_INOTIFY /* inotify helpers */
216
217/*
218 * fsnotify_oldname_init - save off the old filename before we change it
219 */
220static inline const char *fsnotify_oldname_init(const char *name)
221{
222 return kstrdup(name, GFP_KERNEL);
223}
224
225/*
226 * fsnotify_oldname_free - free the name we got from fsnotify_oldname_init
227 */
228static inline void fsnotify_oldname_free(const char *old_name)
229{
230 kfree(old_name);
231}
232
233#else /* CONFIG_INOTIFY */
234
235static inline const char *fsnotify_oldname_init(const char *name)
236{
237 return NULL;
238}
239
240static inline void fsnotify_oldname_free(const char *old_name)
241{
242}
243
244#endif /* ! CONFIG_INOTIFY */
245
246#endif /* __KERNEL__ */
247
248#endif /* _LINUX_FS_NOTIFY_H */
diff --git a/include/linux/hardirq.h b/include/linux/hardirq.h
index 8336dba18971..5912874ca83c 100644
--- a/include/linux/hardirq.h
+++ b/include/linux/hardirq.h
@@ -2,6 +2,7 @@
2#define LINUX_HARDIRQ_H 2#define LINUX_HARDIRQ_H
3 3
4#include <linux/config.h> 4#include <linux/config.h>
5#include <linux/preempt.h>
5#include <linux/smp_lock.h> 6#include <linux/smp_lock.h>
6#include <asm/hardirq.h> 7#include <asm/hardirq.h>
7#include <asm/system.h> 8#include <asm/system.h>
diff --git a/include/linux/hdlc.h b/include/linux/hdlc.h
index ed2927ef1ff7..df695e9ae327 100644
--- a/include/linux/hdlc.h
+++ b/include/linux/hdlc.h
@@ -242,8 +242,8 @@ static __inline__ struct net_device_stats *hdlc_stats(struct net_device *dev)
242} 242}
243 243
244 244
245static __inline__ unsigned short hdlc_type_trans(struct sk_buff *skb, 245static __inline__ __be16 hdlc_type_trans(struct sk_buff *skb,
246 struct net_device *dev) 246 struct net_device *dev)
247{ 247{
248 hdlc_device *hdlc = dev_to_hdlc(dev); 248 hdlc_device *hdlc = dev_to_hdlc(dev);
249 249
diff --git a/include/linux/inotify.h b/include/linux/inotify.h
new file mode 100644
index 000000000000..a40c2bf0408e
--- /dev/null
+++ b/include/linux/inotify.h
@@ -0,0 +1,108 @@
1/*
2 * Inode based directory notification for Linux
3 *
4 * Copyright (C) 2005 John McCutchan
5 */
6
7#ifndef _LINUX_INOTIFY_H
8#define _LINUX_INOTIFY_H
9
10#include <linux/types.h>
11
12/*
13 * struct inotify_event - structure read from the inotify device for each event
14 *
15 * When you are watching a directory, you will receive the filename for events
16 * such as IN_CREATE, IN_DELETE, IN_OPEN, IN_CLOSE, ..., relative to the wd.
17 */
18struct inotify_event {
19 __s32 wd; /* watch descriptor */
20 __u32 mask; /* watch mask */
21 __u32 cookie; /* cookie to synchronize two events */
22 __u32 len; /* length (including nulls) of name */
23 char name[0]; /* stub for possible name */
24};
25
26/* the following are legal, implemented events that user-space can watch for */
27#define IN_ACCESS 0x00000001 /* File was accessed */
28#define IN_MODIFY 0x00000002 /* File was modified */
29#define IN_ATTRIB 0x00000004 /* Metadata changed */
30#define IN_CLOSE_WRITE 0x00000008 /* Writtable file was closed */
31#define IN_CLOSE_NOWRITE 0x00000010 /* Unwrittable file closed */
32#define IN_OPEN 0x00000020 /* File was opened */
33#define IN_MOVED_FROM 0x00000040 /* File was moved from X */
34#define IN_MOVED_TO 0x00000080 /* File was moved to Y */
35#define IN_CREATE 0x00000100 /* Subfile was created */
36#define IN_DELETE 0x00000200 /* Subfile was deleted */
37#define IN_DELETE_SELF 0x00000400 /* Self was deleted */
38
39/* the following are legal events. they are sent as needed to any watch */
40#define IN_UNMOUNT 0x00002000 /* Backing fs was unmounted */
41#define IN_Q_OVERFLOW 0x00004000 /* Event queued overflowed */
42#define IN_IGNORED 0x00008000 /* File was ignored */
43
44/* helper events */
45#define IN_CLOSE (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE) /* close */
46#define IN_MOVE (IN_MOVED_FROM | IN_MOVED_TO) /* moves */
47
48/* special flags */
49#define IN_ISDIR 0x40000000 /* event occurred against dir */
50#define IN_ONESHOT 0x80000000 /* only send event once */
51
52/*
53 * All of the events - we build the list by hand so that we can add flags in
54 * the future and not break backward compatibility. Apps will get only the
55 * events that they originally wanted. Be sure to add new events here!
56 */
57#define IN_ALL_EVENTS (IN_ACCESS | IN_MODIFY | IN_ATTRIB | IN_CLOSE_WRITE | \
58 IN_CLOSE_NOWRITE | IN_OPEN | IN_MOVED_FROM | \
59 IN_MOVED_TO | IN_DELETE | IN_CREATE | IN_DELETE_SELF)
60
61#ifdef __KERNEL__
62
63#include <linux/dcache.h>
64#include <linux/fs.h>
65#include <linux/config.h>
66
67#ifdef CONFIG_INOTIFY
68
69extern void inotify_inode_queue_event(struct inode *, __u32, __u32,
70 const char *);
71extern void inotify_dentry_parent_queue_event(struct dentry *, __u32, __u32,
72 const char *);
73extern void inotify_unmount_inodes(struct list_head *);
74extern void inotify_inode_is_dead(struct inode *);
75extern u32 inotify_get_cookie(void);
76
77#else
78
79static inline void inotify_inode_queue_event(struct inode *inode,
80 __u32 mask, __u32 cookie,
81 const char *filename)
82{
83}
84
85static inline void inotify_dentry_parent_queue_event(struct dentry *dentry,
86 __u32 mask, __u32 cookie,
87 const char *filename)
88{
89}
90
91static inline void inotify_unmount_inodes(struct list_head *list)
92{
93}
94
95static inline void inotify_inode_is_dead(struct inode *inode)
96{
97}
98
99static inline u32 inotify_get_cookie(void)
100{
101 return 0;
102}
103
104#endif /* CONFIG_INOTIFY */
105
106#endif /* __KERNEL __ */
107
108#endif /* _LINUX_INOTIFY_H */
diff --git a/include/linux/mount.h b/include/linux/mount.h
index 74b4727a4e30..f8f39937e301 100644
--- a/include/linux/mount.h
+++ b/include/linux/mount.h
@@ -12,6 +12,7 @@
12#define _LINUX_MOUNT_H 12#define _LINUX_MOUNT_H
13#ifdef __KERNEL__ 13#ifdef __KERNEL__
14 14
15#include <linux/types.h>
15#include <linux/list.h> 16#include <linux/list.h>
16#include <linux/spinlock.h> 17#include <linux/spinlock.h>
17#include <asm/atomic.h> 18#include <asm/atomic.h>
@@ -76,6 +77,7 @@ extern int do_add_mount(struct vfsmount *newmnt, struct nameidata *nd,
76extern void mark_mounts_for_expiry(struct list_head *mounts); 77extern void mark_mounts_for_expiry(struct list_head *mounts);
77 78
78extern spinlock_t vfsmount_lock; 79extern spinlock_t vfsmount_lock;
80extern dev_t name_to_dev_t(char *name);
79 81
80#endif 82#endif
81#endif /* _LINUX_MOUNT_H */ 83#endif /* _LINUX_MOUNT_H */
diff --git a/include/linux/netlink.h b/include/linux/netlink.h
index 27e4d164a108..2f0c085f2c7d 100644
--- a/include/linux/netlink.h
+++ b/include/linux/netlink.h
@@ -16,6 +16,7 @@
16#define NETLINK_AUDIT 9 /* auditing */ 16#define NETLINK_AUDIT 9 /* auditing */
17#define NETLINK_FIB_LOOKUP 10 17#define NETLINK_FIB_LOOKUP 10
18#define NETLINK_ROUTE6 11 /* af_inet6 route comm channel */ 18#define NETLINK_ROUTE6 11 /* af_inet6 route comm channel */
19#define NETLINK_NETFILTER 12 /* netfilter subsystem */
19#define NETLINK_IP6_FW 13 20#define NETLINK_IP6_FW 13
20#define NETLINK_DNRTMSG 14 /* DECnet routing messages */ 21#define NETLINK_DNRTMSG 14 /* DECnet routing messages */
21#define NETLINK_KOBJECT_UEVENT 15 /* Kernel messages to userspace */ 22#define NETLINK_KOBJECT_UEVENT 15 /* Kernel messages to userspace */
diff --git a/include/linux/pm.h b/include/linux/pm.h
index 14479325e3f3..7aeb208ed713 100644
--- a/include/linux/pm.h
+++ b/include/linux/pm.h
@@ -176,7 +176,7 @@ struct pm_ops {
176}; 176};
177 177
178extern void pm_set_ops(struct pm_ops *); 178extern void pm_set_ops(struct pm_ops *);
179 179extern struct pm_ops *pm_ops;
180extern int pm_suspend(suspend_state_t state); 180extern int pm_suspend(suspend_state_t state);
181 181
182 182
diff --git a/include/linux/reiserfs_acl.h b/include/linux/reiserfs_acl.h
index 0760507a545b..0a3605099c44 100644
--- a/include/linux/reiserfs_acl.h
+++ b/include/linux/reiserfs_acl.h
@@ -4,29 +4,29 @@
4#define REISERFS_ACL_VERSION 0x0001 4#define REISERFS_ACL_VERSION 0x0001
5 5
6typedef struct { 6typedef struct {
7 __le16 e_tag; 7 __le16 e_tag;
8 __le16 e_perm; 8 __le16 e_perm;
9 __le32 e_id; 9 __le32 e_id;
10} reiserfs_acl_entry; 10} reiserfs_acl_entry;
11 11
12typedef struct { 12typedef struct {
13 __le16 e_tag; 13 __le16 e_tag;
14 __le16 e_perm; 14 __le16 e_perm;
15} reiserfs_acl_entry_short; 15} reiserfs_acl_entry_short;
16 16
17typedef struct { 17typedef struct {
18 __le32 a_version; 18 __le32 a_version;
19} reiserfs_acl_header; 19} reiserfs_acl_header;
20 20
21static inline size_t reiserfs_acl_size(int count) 21static inline size_t reiserfs_acl_size(int count)
22{ 22{
23 if (count <= 4) { 23 if (count <= 4) {
24 return sizeof(reiserfs_acl_header) + 24 return sizeof(reiserfs_acl_header) +
25 count * sizeof(reiserfs_acl_entry_short); 25 count * sizeof(reiserfs_acl_entry_short);
26 } else { 26 } else {
27 return sizeof(reiserfs_acl_header) + 27 return sizeof(reiserfs_acl_header) +
28 4 * sizeof(reiserfs_acl_entry_short) + 28 4 * sizeof(reiserfs_acl_entry_short) +
29 (count - 4) * sizeof(reiserfs_acl_entry); 29 (count - 4) * sizeof(reiserfs_acl_entry);
30 } 30 }
31} 31}
32 32
@@ -46,14 +46,14 @@ static inline int reiserfs_acl_count(size_t size)
46 } 46 }
47} 47}
48 48
49
50#ifdef CONFIG_REISERFS_FS_POSIX_ACL 49#ifdef CONFIG_REISERFS_FS_POSIX_ACL
51struct posix_acl * reiserfs_get_acl(struct inode *inode, int type); 50struct posix_acl *reiserfs_get_acl(struct inode *inode, int type);
52int reiserfs_acl_chmod (struct inode *inode); 51int reiserfs_acl_chmod(struct inode *inode);
53int reiserfs_inherit_default_acl (struct inode *dir, struct dentry *dentry, struct inode *inode); 52int reiserfs_inherit_default_acl(struct inode *dir, struct dentry *dentry,
54int reiserfs_cache_default_acl (struct inode *dir); 53 struct inode *inode);
55extern int reiserfs_xattr_posix_acl_init (void) __init; 54int reiserfs_cache_default_acl(struct inode *dir);
56extern int reiserfs_xattr_posix_acl_exit (void); 55extern int reiserfs_xattr_posix_acl_init(void) __init;
56extern int reiserfs_xattr_posix_acl_exit(void);
57extern struct reiserfs_xattr_handler posix_acl_default_handler; 57extern struct reiserfs_xattr_handler posix_acl_default_handler;
58extern struct reiserfs_xattr_handler posix_acl_access_handler; 58extern struct reiserfs_xattr_handler posix_acl_access_handler;
59#else 59#else
@@ -61,28 +61,26 @@ extern struct reiserfs_xattr_handler posix_acl_access_handler;
61#define reiserfs_get_acl NULL 61#define reiserfs_get_acl NULL
62#define reiserfs_cache_default_acl(inode) 0 62#define reiserfs_cache_default_acl(inode) 0
63 63
64static inline int 64static inline int reiserfs_xattr_posix_acl_init(void)
65reiserfs_xattr_posix_acl_init (void)
66{ 65{
67 return 0; 66 return 0;
68} 67}
69 68
70static inline int 69static inline int reiserfs_xattr_posix_acl_exit(void)
71reiserfs_xattr_posix_acl_exit (void)
72{ 70{
73 return 0; 71 return 0;
74} 72}
75 73
76static inline int 74static inline int reiserfs_acl_chmod(struct inode *inode)
77reiserfs_acl_chmod (struct inode *inode)
78{ 75{
79 return 0; 76 return 0;
80} 77}
81 78
82static inline int 79static inline int
83reiserfs_inherit_default_acl (const struct inode *dir, struct dentry *dentry, struct inode *inode) 80reiserfs_inherit_default_acl(const struct inode *dir, struct dentry *dentry,
81 struct inode *inode)
84{ 82{
85 return 0; 83 return 0;
86} 84}
87 85
88#endif 86#endif
diff --git a/include/linux/reiserfs_fs.h b/include/linux/reiserfs_fs.h
index 4c7c5689ad93..17e458e17e2b 100644
--- a/include/linux/reiserfs_fs.h
+++ b/include/linux/reiserfs_fs.h
@@ -3,11 +3,10 @@
3 */ 3 */
4 4
5 /* this file has an amazingly stupid 5 /* this file has an amazingly stupid
6 name, yura please fix it to be 6 name, yura please fix it to be
7 reiserfs.h, and merge all the rest 7 reiserfs.h, and merge all the rest
8 of our .h files that are in this 8 of our .h files that are in this
9 directory into it. */ 9 directory into it. */
10
11 10
12#ifndef _LINUX_REISER_FS_H 11#ifndef _LINUX_REISER_FS_H
13#define _LINUX_REISER_FS_H 12#define _LINUX_REISER_FS_H
@@ -74,9 +73,9 @@
74/* debug levels. Right now, CONFIG_REISERFS_CHECK means print all debug 73/* debug levels. Right now, CONFIG_REISERFS_CHECK means print all debug
75** messages. 74** messages.
76*/ 75*/
77#define REISERFS_DEBUG_CODE 5 /* extra messages to help find/debug errors */ 76#define REISERFS_DEBUG_CODE 5 /* extra messages to help find/debug errors */
78 77
79void reiserfs_warning (struct super_block *s, const char * fmt, ...); 78void reiserfs_warning(struct super_block *s, const char *fmt, ...);
80/* assertions handling */ 79/* assertions handling */
81 80
82/** always check a condition and panic if it's false. */ 81/** always check a condition and panic if it's false. */
@@ -105,82 +104,78 @@ if( !( cond ) ) \
105 * Structure of super block on disk, a version of which in RAM is often accessed as REISERFS_SB(s)->s_rs 104 * Structure of super block on disk, a version of which in RAM is often accessed as REISERFS_SB(s)->s_rs
106 * the version in RAM is part of a larger structure containing fields never written to disk. 105 * the version in RAM is part of a larger structure containing fields never written to disk.
107 */ 106 */
108#define UNSET_HASH 0 // read_super will guess about, what hash names 107#define UNSET_HASH 0 // read_super will guess about, what hash names
109 // in directories were sorted with 108 // in directories were sorted with
110#define TEA_HASH 1 109#define TEA_HASH 1
111#define YURA_HASH 2 110#define YURA_HASH 2
112#define R5_HASH 3 111#define R5_HASH 3
113#define DEFAULT_HASH R5_HASH 112#define DEFAULT_HASH R5_HASH
114 113
115
116struct journal_params { 114struct journal_params {
117 __le32 jp_journal_1st_block; /* where does journal start from on its 115 __le32 jp_journal_1st_block; /* where does journal start from on its
118 * device */ 116 * device */
119 __le32 jp_journal_dev; /* journal device st_rdev */ 117 __le32 jp_journal_dev; /* journal device st_rdev */
120 __le32 jp_journal_size; /* size of the journal */ 118 __le32 jp_journal_size; /* size of the journal */
121 __le32 jp_journal_trans_max; /* max number of blocks in a transaction. */ 119 __le32 jp_journal_trans_max; /* max number of blocks in a transaction. */
122 __le32 jp_journal_magic; /* random value made on fs creation (this 120 __le32 jp_journal_magic; /* random value made on fs creation (this
123 * was sb_journal_block_count) */ 121 * was sb_journal_block_count) */
124 __le32 jp_journal_max_batch; /* max number of blocks to batch into a 122 __le32 jp_journal_max_batch; /* max number of blocks to batch into a
125 * trans */ 123 * trans */
126 __le32 jp_journal_max_commit_age; /* in seconds, how old can an async 124 __le32 jp_journal_max_commit_age; /* in seconds, how old can an async
127 * commit be */ 125 * commit be */
128 __le32 jp_journal_max_trans_age; /* in seconds, how old can a transaction 126 __le32 jp_journal_max_trans_age; /* in seconds, how old can a transaction
129 * be */ 127 * be */
130}; 128};
131 129
132/* this is the super from 3.5.X, where X >= 10 */ 130/* this is the super from 3.5.X, where X >= 10 */
133struct reiserfs_super_block_v1 131struct reiserfs_super_block_v1 {
134{ 132 __le32 s_block_count; /* blocks count */
135 __le32 s_block_count; /* blocks count */ 133 __le32 s_free_blocks; /* free blocks count */
136 __le32 s_free_blocks; /* free blocks count */ 134 __le32 s_root_block; /* root block number */
137 __le32 s_root_block; /* root block number */ 135 struct journal_params s_journal;
138 struct journal_params s_journal; 136 __le16 s_blocksize; /* block size */
139 __le16 s_blocksize; /* block size */ 137 __le16 s_oid_maxsize; /* max size of object id array, see
140 __le16 s_oid_maxsize; /* max size of object id array, see 138 * get_objectid() commentary */
141 * get_objectid() commentary */ 139 __le16 s_oid_cursize; /* current size of object id array */
142 __le16 s_oid_cursize; /* current size of object id array */ 140 __le16 s_umount_state; /* this is set to 1 when filesystem was
143 __le16 s_umount_state; /* this is set to 1 when filesystem was 141 * umounted, to 2 - when not */
144 * umounted, to 2 - when not */ 142 char s_magic[10]; /* reiserfs magic string indicates that
145 char s_magic[10]; /* reiserfs magic string indicates that 143 * file system is reiserfs:
146 * file system is reiserfs: 144 * "ReIsErFs" or "ReIsEr2Fs" or "ReIsEr3Fs" */
147 * "ReIsErFs" or "ReIsEr2Fs" or "ReIsEr3Fs" */ 145 __le16 s_fs_state; /* it is set to used by fsck to mark which
148 __le16 s_fs_state; /* it is set to used by fsck to mark which 146 * phase of rebuilding is done */
149 * phase of rebuilding is done */ 147 __le32 s_hash_function_code; /* indicate, what hash function is being use
150 __le32 s_hash_function_code; /* indicate, what hash function is being use 148 * to sort names in a directory*/
151 * to sort names in a directory*/ 149 __le16 s_tree_height; /* height of disk tree */
152 __le16 s_tree_height; /* height of disk tree */ 150 __le16 s_bmap_nr; /* amount of bitmap blocks needed to address
153 __le16 s_bmap_nr; /* amount of bitmap blocks needed to address 151 * each block of file system */
154 * each block of file system */ 152 __le16 s_version; /* this field is only reliable on filesystem
155 __le16 s_version; /* this field is only reliable on filesystem 153 * with non-standard journal */
156 * with non-standard journal */ 154 __le16 s_reserved_for_journal; /* size in blocks of journal area on main
157 __le16 s_reserved_for_journal; /* size in blocks of journal area on main 155 * device, we need to keep after
158 * device, we need to keep after 156 * making fs with non-standard journal */
159 * making fs with non-standard journal */
160} __attribute__ ((__packed__)); 157} __attribute__ ((__packed__));
161 158
162#define SB_SIZE_V1 (sizeof(struct reiserfs_super_block_v1)) 159#define SB_SIZE_V1 (sizeof(struct reiserfs_super_block_v1))
163 160
164/* this is the on disk super block */ 161/* this is the on disk super block */
165struct reiserfs_super_block 162struct reiserfs_super_block {
166{ 163 struct reiserfs_super_block_v1 s_v1;
167 struct reiserfs_super_block_v1 s_v1; 164 __le32 s_inode_generation;
168 __le32 s_inode_generation; 165 __le32 s_flags; /* Right now used only by inode-attributes, if enabled */
169 __le32 s_flags; /* Right now used only by inode-attributes, if enabled */ 166 unsigned char s_uuid[16]; /* filesystem unique identifier */
170 unsigned char s_uuid[16]; /* filesystem unique identifier */ 167 unsigned char s_label[16]; /* filesystem volume label */
171 unsigned char s_label[16]; /* filesystem volume label */ 168 char s_unused[88]; /* zero filled by mkreiserfs and
172 char s_unused[88] ; /* zero filled by mkreiserfs and 169 * reiserfs_convert_objectid_map_v1()
173 * reiserfs_convert_objectid_map_v1() 170 * so any additions must be updated
174 * so any additions must be updated 171 * there as well. */
175 * there as well. */ 172} __attribute__ ((__packed__));
176} __attribute__ ((__packed__));
177 173
178#define SB_SIZE (sizeof(struct reiserfs_super_block)) 174#define SB_SIZE (sizeof(struct reiserfs_super_block))
179 175
180#define REISERFS_VERSION_1 0 176#define REISERFS_VERSION_1 0
181#define REISERFS_VERSION_2 2 177#define REISERFS_VERSION_2 2
182 178
183
184// on-disk super block fields converted to cpu form 179// on-disk super block fields converted to cpu form
185#define SB_DISK_SUPER_BLOCK(s) (REISERFS_SB(s)->s_rs) 180#define SB_DISK_SUPER_BLOCK(s) (REISERFS_SB(s)->s_rs)
186#define SB_V1_DISK_SUPER_BLOCK(s) (&(SB_DISK_SUPER_BLOCK(s)->s_v1)) 181#define SB_V1_DISK_SUPER_BLOCK(s) (&(SB_DISK_SUPER_BLOCK(s)->s_v1))
@@ -210,13 +205,12 @@ struct reiserfs_super_block
210#define PUT_SB_TREE_HEIGHT(s, val) \ 205#define PUT_SB_TREE_HEIGHT(s, val) \
211 do { SB_V1_DISK_SUPER_BLOCK(s)->s_tree_height = cpu_to_le16(val); } while (0) 206 do { SB_V1_DISK_SUPER_BLOCK(s)->s_tree_height = cpu_to_le16(val); } while (0)
212#define PUT_SB_REISERFS_STATE(s, val) \ 207#define PUT_SB_REISERFS_STATE(s, val) \
213 do { SB_V1_DISK_SUPER_BLOCK(s)->s_umount_state = cpu_to_le16(val); } while (0) 208 do { SB_V1_DISK_SUPER_BLOCK(s)->s_umount_state = cpu_to_le16(val); } while (0)
214#define PUT_SB_VERSION(s, val) \ 209#define PUT_SB_VERSION(s, val) \
215 do { SB_V1_DISK_SUPER_BLOCK(s)->s_version = cpu_to_le16(val); } while (0) 210 do { SB_V1_DISK_SUPER_BLOCK(s)->s_version = cpu_to_le16(val); } while (0)
216#define PUT_SB_BMAP_NR(s, val) \ 211#define PUT_SB_BMAP_NR(s, val) \
217 do { SB_V1_DISK_SUPER_BLOCK(s)->s_bmap_nr = cpu_to_le16 (val); } while (0) 212 do { SB_V1_DISK_SUPER_BLOCK(s)->s_bmap_nr = cpu_to_le16 (val); } while (0)
218 213
219
220#define SB_ONDISK_JP(s) (&SB_V1_DISK_SUPER_BLOCK(s)->s_journal) 214#define SB_ONDISK_JP(s) (&SB_V1_DISK_SUPER_BLOCK(s)->s_journal)
221#define SB_ONDISK_JOURNAL_SIZE(s) \ 215#define SB_ONDISK_JOURNAL_SIZE(s) \
222 le32_to_cpu ((SB_ONDISK_JP(s)->jp_journal_size)) 216 le32_to_cpu ((SB_ONDISK_JP(s)->jp_journal_size))
@@ -231,21 +225,19 @@ struct reiserfs_super_block
231 block >= SB_JOURNAL_1st_RESERVED_BLOCK(s) \ 225 block >= SB_JOURNAL_1st_RESERVED_BLOCK(s) \
232 && block < SB_JOURNAL_1st_RESERVED_BLOCK(s) + \ 226 && block < SB_JOURNAL_1st_RESERVED_BLOCK(s) + \
233 ((!is_reiserfs_jr(SB_DISK_SUPER_BLOCK(s)) ? \ 227 ((!is_reiserfs_jr(SB_DISK_SUPER_BLOCK(s)) ? \
234 SB_ONDISK_JOURNAL_SIZE(s) + 1 : SB_ONDISK_RESERVED_FOR_JOURNAL(s))) 228 SB_ONDISK_JOURNAL_SIZE(s) + 1 : SB_ONDISK_RESERVED_FOR_JOURNAL(s)))
235
236
237 229
238 /* used by gcc */ 230 /* used by gcc */
239#define REISERFS_SUPER_MAGIC 0x52654973 231#define REISERFS_SUPER_MAGIC 0x52654973
240 /* used by file system utilities that 232 /* used by file system utilities that
241 look at the superblock, etc. */ 233 look at the superblock, etc. */
242#define REISERFS_SUPER_MAGIC_STRING "ReIsErFs" 234#define REISERFS_SUPER_MAGIC_STRING "ReIsErFs"
243#define REISER2FS_SUPER_MAGIC_STRING "ReIsEr2Fs" 235#define REISER2FS_SUPER_MAGIC_STRING "ReIsEr2Fs"
244#define REISER2FS_JR_SUPER_MAGIC_STRING "ReIsEr3Fs" 236#define REISER2FS_JR_SUPER_MAGIC_STRING "ReIsEr3Fs"
245 237
246int is_reiserfs_3_5 (struct reiserfs_super_block * rs); 238int is_reiserfs_3_5(struct reiserfs_super_block *rs);
247int is_reiserfs_3_6 (struct reiserfs_super_block * rs); 239int is_reiserfs_3_6(struct reiserfs_super_block *rs);
248int is_reiserfs_jr (struct reiserfs_super_block * rs); 240int is_reiserfs_jr(struct reiserfs_super_block *rs);
249 241
250/* ReiserFS leaves the first 64k unused, so that partition labels have 242/* ReiserFS leaves the first 64k unused, so that partition labels have
251 enough space. If someone wants to write a fancy bootloader that 243 enough space. If someone wants to write a fancy bootloader that
@@ -272,8 +264,8 @@ typedef __u32 b_blocknr_t;
272typedef __le32 unp_t; 264typedef __le32 unp_t;
273 265
274struct unfm_nodeinfo { 266struct unfm_nodeinfo {
275 unp_t unfm_nodenum; 267 unp_t unfm_nodenum;
276 unsigned short unfm_freespace; 268 unsigned short unfm_freespace;
277}; 269};
278 270
279/* there are two formats of keys: 3.5 and 3.6 271/* there are two formats of keys: 3.5 and 3.6
@@ -285,7 +277,6 @@ struct unfm_nodeinfo {
285#define STAT_DATA_V1 0 277#define STAT_DATA_V1 0
286#define STAT_DATA_V2 1 278#define STAT_DATA_V2 1
287 279
288
289static inline struct reiserfs_inode_info *REISERFS_I(const struct inode *inode) 280static inline struct reiserfs_inode_info *REISERFS_I(const struct inode *inode)
290{ 281{
291 return container_of(inode, struct reiserfs_inode_info, vfs_inode); 282 return container_of(inode, struct reiserfs_inode_info, vfs_inode);
@@ -343,15 +334,13 @@ static inline struct reiserfs_sb_info *REISERFS_SB(const struct super_block *sb)
343 file would fit into one DIRECT item. 334 file would fit into one DIRECT item.
344 Primary intention for this one is to increase performance by decreasing 335 Primary intention for this one is to increase performance by decreasing
345 seeking. 336 seeking.
346*/ 337*/
347#define STORE_TAIL_IN_UNFM_S2(n_file_size,n_tail_size,n_block_size) \ 338#define STORE_TAIL_IN_UNFM_S2(n_file_size,n_tail_size,n_block_size) \
348(\ 339(\
349 (!(n_tail_size)) || \ 340 (!(n_tail_size)) || \
350 (((n_file_size) > MAX_DIRECT_ITEM_LEN(n_block_size)) ) \ 341 (((n_file_size) > MAX_DIRECT_ITEM_LEN(n_block_size)) ) \
351) 342)
352 343
353
354
355/* 344/*
356 * values for s_umount_state field 345 * values for s_umount_state field
357 */ 346 */
@@ -364,9 +353,9 @@ static inline struct reiserfs_sb_info *REISERFS_SB(const struct super_block *sb)
364#define TYPE_STAT_DATA 0 353#define TYPE_STAT_DATA 0
365#define TYPE_INDIRECT 1 354#define TYPE_INDIRECT 1
366#define TYPE_DIRECT 2 355#define TYPE_DIRECT 2
367#define TYPE_DIRENTRY 3 356#define TYPE_DIRENTRY 3
368#define TYPE_MAXTYPE 3 357#define TYPE_MAXTYPE 3
369#define TYPE_ANY 15 // FIXME: comment is required 358#define TYPE_ANY 15 // FIXME: comment is required
370 359
371/***************************************************************************/ 360/***************************************************************************/
372/* KEY & ITEM HEAD */ 361/* KEY & ITEM HEAD */
@@ -376,60 +365,62 @@ static inline struct reiserfs_sb_info *REISERFS_SB(const struct super_block *sb)
376// directories use this key as well as old files 365// directories use this key as well as old files
377// 366//
378struct offset_v1 { 367struct offset_v1 {
379 __le32 k_offset; 368 __le32 k_offset;
380 __le32 k_uniqueness; 369 __le32 k_uniqueness;
381} __attribute__ ((__packed__)); 370} __attribute__ ((__packed__));
382 371
383struct offset_v2 { 372struct offset_v2 {
384 __le64 v; 373 __le64 v;
385} __attribute__ ((__packed__)); 374} __attribute__ ((__packed__));
386 375
387static inline __u16 offset_v2_k_type( const struct offset_v2 *v2 ) 376static inline __u16 offset_v2_k_type(const struct offset_v2 *v2)
388{ 377{
389 __u8 type = le64_to_cpu(v2->v) >> 60; 378 __u8 type = le64_to_cpu(v2->v) >> 60;
390 return (type <= TYPE_MAXTYPE)?type:TYPE_ANY; 379 return (type <= TYPE_MAXTYPE) ? type : TYPE_ANY;
391} 380}
392 381
393static inline void set_offset_v2_k_type( struct offset_v2 *v2, int type ) 382static inline void set_offset_v2_k_type(struct offset_v2 *v2, int type)
394{ 383{
395 v2->v = (v2->v & cpu_to_le64(~0ULL>>4)) | cpu_to_le64((__u64)type<<60); 384 v2->v =
385 (v2->v & cpu_to_le64(~0ULL >> 4)) | cpu_to_le64((__u64) type << 60);
396} 386}
397 387
398static inline loff_t offset_v2_k_offset( const struct offset_v2 *v2 ) 388static inline loff_t offset_v2_k_offset(const struct offset_v2 *v2)
399{ 389{
400 return le64_to_cpu(v2->v) & (~0ULL>>4); 390 return le64_to_cpu(v2->v) & (~0ULL >> 4);
401} 391}
402 392
403static inline void set_offset_v2_k_offset( struct offset_v2 *v2, loff_t offset ){ 393static inline void set_offset_v2_k_offset(struct offset_v2 *v2, loff_t offset)
404 offset &= (~0ULL>>4); 394{
405 v2->v = (v2->v & cpu_to_le64(15ULL<<60)) | cpu_to_le64(offset); 395 offset &= (~0ULL >> 4);
396 v2->v = (v2->v & cpu_to_le64(15ULL << 60)) | cpu_to_le64(offset);
406} 397}
407 398
408/* Key of an item determines its location in the S+tree, and 399/* Key of an item determines its location in the S+tree, and
409 is composed of 4 components */ 400 is composed of 4 components */
410struct reiserfs_key { 401struct reiserfs_key {
411 __le32 k_dir_id; /* packing locality: by default parent 402 __le32 k_dir_id; /* packing locality: by default parent
412 directory object id */ 403 directory object id */
413 __le32 k_objectid; /* object identifier */ 404 __le32 k_objectid; /* object identifier */
414 union { 405 union {
415 struct offset_v1 k_offset_v1; 406 struct offset_v1 k_offset_v1;
416 struct offset_v2 k_offset_v2; 407 struct offset_v2 k_offset_v2;
417 } __attribute__ ((__packed__)) u; 408 } __attribute__ ((__packed__)) u;
418} __attribute__ ((__packed__)); 409} __attribute__ ((__packed__));
419 410
420struct in_core_key { 411struct in_core_key {
421 __u32 k_dir_id; /* packing locality: by default parent 412 __u32 k_dir_id; /* packing locality: by default parent
422 directory object id */ 413 directory object id */
423 __u32 k_objectid; /* object identifier */ 414 __u32 k_objectid; /* object identifier */
424 __u64 k_offset; 415 __u64 k_offset;
425 __u8 k_type; 416 __u8 k_type;
426}; 417};
427 418
428struct cpu_key { 419struct cpu_key {
429 struct in_core_key on_disk_key; 420 struct in_core_key on_disk_key;
430 int version; 421 int version;
431 int key_length; /* 3 in all cases but direct2indirect and 422 int key_length; /* 3 in all cases but direct2indirect and
432 indirect2direct conversion */ 423 indirect2direct conversion */
433}; 424};
434 425
435/* Our function for comparing keys can compare keys of different 426/* Our function for comparing keys can compare keys of different
@@ -475,8 +466,7 @@ struct cpu_key {
475 indirect items) and specifies the location of the item itself 466 indirect items) and specifies the location of the item itself
476 within the block. */ 467 within the block. */
477 468
478struct item_head 469struct item_head {
479{
480 /* Everything in the tree is found by searching for it based on 470 /* Everything in the tree is found by searching for it based on
481 * its key.*/ 471 * its key.*/
482 struct reiserfs_key ih_key; 472 struct reiserfs_key ih_key;
@@ -492,13 +482,13 @@ struct item_head
492 number of directory entries in the directory item. */ 482 number of directory entries in the directory item. */
493 __le16 ih_entry_count; 483 __le16 ih_entry_count;
494 } __attribute__ ((__packed__)) u; 484 } __attribute__ ((__packed__)) u;
495 __le16 ih_item_len; /* total size of the item body */ 485 __le16 ih_item_len; /* total size of the item body */
496 __le16 ih_item_location; /* an offset to the item body 486 __le16 ih_item_location; /* an offset to the item body
497 * within the block */ 487 * within the block */
498 __le16 ih_version; /* 0 for all old items, 2 for new 488 __le16 ih_version; /* 0 for all old items, 2 for new
499 ones. Highest bit is set by fsck 489 ones. Highest bit is set by fsck
500 temporary, cleaned after all 490 temporary, cleaned after all
501 done */ 491 done */
502} __attribute__ ((__packed__)); 492} __attribute__ ((__packed__));
503/* size of item header */ 493/* size of item header */
504#define IH_SIZE (sizeof(struct item_head)) 494#define IH_SIZE (sizeof(struct item_head))
@@ -515,7 +505,6 @@ struct item_head
515#define put_ih_location(ih, val) do { (ih)->ih_item_location = cpu_to_le16(val); } while (0) 505#define put_ih_location(ih, val) do { (ih)->ih_item_location = cpu_to_le16(val); } while (0)
516#define put_ih_item_len(ih, val) do { (ih)->ih_item_len = cpu_to_le16(val); } while (0) 506#define put_ih_item_len(ih, val) do { (ih)->ih_item_len = cpu_to_le16(val); } while (0)
517 507
518
519#define unreachable_item(ih) (ih_version(ih) & (1 << 15)) 508#define unreachable_item(ih) (ih_version(ih) & (1 << 15))
520 509
521#define get_ih_free_space(ih) (ih_version (ih) == KEY_FORMAT_3_6 ? 0 : ih_free_space (ih)) 510#define get_ih_free_space(ih) (ih_version (ih) == KEY_FORMAT_3_6 ? 0 : ih_free_space (ih))
@@ -537,40 +526,48 @@ struct item_head
537#define V1_INDIRECT_UNIQUENESS 0xfffffffe 526#define V1_INDIRECT_UNIQUENESS 0xfffffffe
538#define V1_DIRECT_UNIQUENESS 0xffffffff 527#define V1_DIRECT_UNIQUENESS 0xffffffff
539#define V1_DIRENTRY_UNIQUENESS 500 528#define V1_DIRENTRY_UNIQUENESS 500
540#define V1_ANY_UNIQUENESS 555 // FIXME: comment is required 529#define V1_ANY_UNIQUENESS 555 // FIXME: comment is required
541 530
542// 531//
543// here are conversion routines 532// here are conversion routines
544// 533//
545static inline int uniqueness2type (__u32 uniqueness) CONSTF; 534static inline int uniqueness2type(__u32 uniqueness) CONSTF;
546static inline int uniqueness2type (__u32 uniqueness) 535static inline int uniqueness2type(__u32 uniqueness)
547{ 536{
548 switch ((int)uniqueness) { 537 switch ((int)uniqueness) {
549 case V1_SD_UNIQUENESS: return TYPE_STAT_DATA; 538 case V1_SD_UNIQUENESS:
550 case V1_INDIRECT_UNIQUENESS: return TYPE_INDIRECT; 539 return TYPE_STAT_DATA;
551 case V1_DIRECT_UNIQUENESS: return TYPE_DIRECT; 540 case V1_INDIRECT_UNIQUENESS:
552 case V1_DIRENTRY_UNIQUENESS: return TYPE_DIRENTRY; 541 return TYPE_INDIRECT;
553 default: 542 case V1_DIRECT_UNIQUENESS:
554 reiserfs_warning (NULL, "vs-500: unknown uniqueness %d", 543 return TYPE_DIRECT;
555 uniqueness); 544 case V1_DIRENTRY_UNIQUENESS:
545 return TYPE_DIRENTRY;
546 default:
547 reiserfs_warning(NULL, "vs-500: unknown uniqueness %d",
548 uniqueness);
556 case V1_ANY_UNIQUENESS: 549 case V1_ANY_UNIQUENESS:
557 return TYPE_ANY; 550 return TYPE_ANY;
558 } 551 }
559} 552}
560 553
561static inline __u32 type2uniqueness (int type) CONSTF; 554static inline __u32 type2uniqueness(int type) CONSTF;
562static inline __u32 type2uniqueness (int type) 555static inline __u32 type2uniqueness(int type)
563{ 556{
564 switch (type) { 557 switch (type) {
565 case TYPE_STAT_DATA: return V1_SD_UNIQUENESS; 558 case TYPE_STAT_DATA:
566 case TYPE_INDIRECT: return V1_INDIRECT_UNIQUENESS; 559 return V1_SD_UNIQUENESS;
567 case TYPE_DIRECT: return V1_DIRECT_UNIQUENESS; 560 case TYPE_INDIRECT:
568 case TYPE_DIRENTRY: return V1_DIRENTRY_UNIQUENESS; 561 return V1_INDIRECT_UNIQUENESS;
569 default: 562 case TYPE_DIRECT:
570 reiserfs_warning (NULL, "vs-501: unknown type %d", type); 563 return V1_DIRECT_UNIQUENESS;
564 case TYPE_DIRENTRY:
565 return V1_DIRENTRY_UNIQUENESS;
566 default:
567 reiserfs_warning(NULL, "vs-501: unknown type %d", type);
571 case TYPE_ANY: 568 case TYPE_ANY:
572 return V1_ANY_UNIQUENESS; 569 return V1_ANY_UNIQUENESS;
573 } 570 }
574} 571}
575 572
576// 573//
@@ -578,57 +575,56 @@ static inline __u32 type2uniqueness (int type)
578// there is no way to get version of object from key, so, provide 575// there is no way to get version of object from key, so, provide
579// version to these defines 576// version to these defines
580// 577//
581static inline loff_t le_key_k_offset (int version, const struct reiserfs_key * key) 578static inline loff_t le_key_k_offset(int version,
579 const struct reiserfs_key *key)
582{ 580{
583 return (version == KEY_FORMAT_3_5) ? 581 return (version == KEY_FORMAT_3_5) ?
584 le32_to_cpu( key->u.k_offset_v1.k_offset ) : 582 le32_to_cpu(key->u.k_offset_v1.k_offset) :
585 offset_v2_k_offset( &(key->u.k_offset_v2) ); 583 offset_v2_k_offset(&(key->u.k_offset_v2));
586} 584}
587 585
588static inline loff_t le_ih_k_offset (const struct item_head * ih) 586static inline loff_t le_ih_k_offset(const struct item_head *ih)
589{ 587{
590 return le_key_k_offset (ih_version (ih), &(ih->ih_key)); 588 return le_key_k_offset(ih_version(ih), &(ih->ih_key));
591} 589}
592 590
593static inline loff_t le_key_k_type (int version, const struct reiserfs_key * key) 591static inline loff_t le_key_k_type(int version, const struct reiserfs_key *key)
594{ 592{
595 return (version == KEY_FORMAT_3_5) ? 593 return (version == KEY_FORMAT_3_5) ?
596 uniqueness2type( le32_to_cpu( key->u.k_offset_v1.k_uniqueness)) : 594 uniqueness2type(le32_to_cpu(key->u.k_offset_v1.k_uniqueness)) :
597 offset_v2_k_type( &(key->u.k_offset_v2) ); 595 offset_v2_k_type(&(key->u.k_offset_v2));
598} 596}
599 597
600static inline loff_t le_ih_k_type (const struct item_head * ih) 598static inline loff_t le_ih_k_type(const struct item_head *ih)
601{ 599{
602 return le_key_k_type (ih_version (ih), &(ih->ih_key)); 600 return le_key_k_type(ih_version(ih), &(ih->ih_key));
603} 601}
604 602
605 603static inline void set_le_key_k_offset(int version, struct reiserfs_key *key,
606static inline void set_le_key_k_offset (int version, struct reiserfs_key * key, loff_t offset) 604 loff_t offset)
607{ 605{
608 (version == KEY_FORMAT_3_5) ? 606 (version == KEY_FORMAT_3_5) ? (void)(key->u.k_offset_v1.k_offset = cpu_to_le32(offset)) : /* jdm check */
609 (void)(key->u.k_offset_v1.k_offset = cpu_to_le32 (offset)) : /* jdm check */ 607 (void)(set_offset_v2_k_offset(&(key->u.k_offset_v2), offset));
610 (void)(set_offset_v2_k_offset( &(key->u.k_offset_v2), offset ));
611} 608}
612 609
613 610static inline void set_le_ih_k_offset(struct item_head *ih, loff_t offset)
614static inline void set_le_ih_k_offset (struct item_head * ih, loff_t offset)
615{ 611{
616 set_le_key_k_offset (ih_version (ih), &(ih->ih_key), offset); 612 set_le_key_k_offset(ih_version(ih), &(ih->ih_key), offset);
617} 613}
618 614
619 615static inline void set_le_key_k_type(int version, struct reiserfs_key *key,
620static inline void set_le_key_k_type (int version, struct reiserfs_key * key, int type) 616 int type)
621{ 617{
622 (version == KEY_FORMAT_3_5) ? 618 (version == KEY_FORMAT_3_5) ?
623 (void)(key->u.k_offset_v1.k_uniqueness = cpu_to_le32(type2uniqueness(type))): 619 (void)(key->u.k_offset_v1.k_uniqueness =
624 (void)(set_offset_v2_k_type( &(key->u.k_offset_v2), type )); 620 cpu_to_le32(type2uniqueness(type)))
621 : (void)(set_offset_v2_k_type(&(key->u.k_offset_v2), type));
625} 622}
626static inline void set_le_ih_k_type (struct item_head * ih, int type) 623static inline void set_le_ih_k_type(struct item_head *ih, int type)
627{ 624{
628 set_le_key_k_type (ih_version (ih), &(ih->ih_key), type); 625 set_le_key_k_type(ih_version(ih), &(ih->ih_key), type);
629} 626}
630 627
631
632#define is_direntry_le_key(version,key) (le_key_k_type (version, key) == TYPE_DIRENTRY) 628#define is_direntry_le_key(version,key) (le_key_k_type (version, key) == TYPE_DIRENTRY)
633#define is_direct_le_key(version,key) (le_key_k_type (version, key) == TYPE_DIRECT) 629#define is_direct_le_key(version,key) (le_key_k_type (version, key) == TYPE_DIRECT)
634#define is_indirect_le_key(version,key) (le_key_k_type (version, key) == TYPE_INDIRECT) 630#define is_indirect_le_key(version,key) (le_key_k_type (version, key) == TYPE_INDIRECT)
@@ -642,34 +638,32 @@ static inline void set_le_ih_k_type (struct item_head * ih, int type)
642#define is_indirect_le_ih(ih) is_indirect_le_key (ih_version(ih), &((ih)->ih_key)) 638#define is_indirect_le_ih(ih) is_indirect_le_key (ih_version(ih), &((ih)->ih_key))
643#define is_statdata_le_ih(ih) is_statdata_le_key (ih_version (ih), &((ih)->ih_key)) 639#define is_statdata_le_ih(ih) is_statdata_le_key (ih_version (ih), &((ih)->ih_key))
644 640
645
646
647// 641//
648// key is pointer to cpu key, result is cpu 642// key is pointer to cpu key, result is cpu
649// 643//
650static inline loff_t cpu_key_k_offset (const struct cpu_key * key) 644static inline loff_t cpu_key_k_offset(const struct cpu_key *key)
651{ 645{
652 return key->on_disk_key.k_offset; 646 return key->on_disk_key.k_offset;
653} 647}
654 648
655static inline loff_t cpu_key_k_type (const struct cpu_key * key) 649static inline loff_t cpu_key_k_type(const struct cpu_key *key)
656{ 650{
657 return key->on_disk_key.k_type; 651 return key->on_disk_key.k_type;
658} 652}
659 653
660static inline void set_cpu_key_k_offset (struct cpu_key * key, loff_t offset) 654static inline void set_cpu_key_k_offset(struct cpu_key *key, loff_t offset)
661{ 655{
662 key->on_disk_key.k_offset = offset; 656 key->on_disk_key.k_offset = offset;
663} 657}
664 658
665static inline void set_cpu_key_k_type (struct cpu_key * key, int type) 659static inline void set_cpu_key_k_type(struct cpu_key *key, int type)
666{ 660{
667 key->on_disk_key.k_type = type; 661 key->on_disk_key.k_type = type;
668} 662}
669 663
670static inline void cpu_key_k_offset_dec (struct cpu_key * key) 664static inline void cpu_key_k_offset_dec(struct cpu_key *key)
671{ 665{
672 key->on_disk_key.k_offset --; 666 key->on_disk_key.k_offset--;
673} 667}
674 668
675#define is_direntry_cpu_key(key) (cpu_key_k_type (key) == TYPE_DIRENTRY) 669#define is_direntry_cpu_key(key) (cpu_key_k_type (key) == TYPE_DIRENTRY)
@@ -677,34 +671,25 @@ static inline void cpu_key_k_offset_dec (struct cpu_key * key)
677#define is_indirect_cpu_key(key) (cpu_key_k_type (key) == TYPE_INDIRECT) 671#define is_indirect_cpu_key(key) (cpu_key_k_type (key) == TYPE_INDIRECT)
678#define is_statdata_cpu_key(key) (cpu_key_k_type (key) == TYPE_STAT_DATA) 672#define is_statdata_cpu_key(key) (cpu_key_k_type (key) == TYPE_STAT_DATA)
679 673
680
681/* are these used ? */ 674/* are these used ? */
682#define is_direntry_cpu_ih(ih) (is_direntry_cpu_key (&((ih)->ih_key))) 675#define is_direntry_cpu_ih(ih) (is_direntry_cpu_key (&((ih)->ih_key)))
683#define is_direct_cpu_ih(ih) (is_direct_cpu_key (&((ih)->ih_key))) 676#define is_direct_cpu_ih(ih) (is_direct_cpu_key (&((ih)->ih_key)))
684#define is_indirect_cpu_ih(ih) (is_indirect_cpu_key (&((ih)->ih_key))) 677#define is_indirect_cpu_ih(ih) (is_indirect_cpu_key (&((ih)->ih_key)))
685#define is_statdata_cpu_ih(ih) (is_statdata_cpu_key (&((ih)->ih_key))) 678#define is_statdata_cpu_ih(ih) (is_statdata_cpu_key (&((ih)->ih_key)))
686 679
687
688
689
690
691#define I_K_KEY_IN_ITEM(p_s_ih, p_s_key, n_blocksize) \ 680#define I_K_KEY_IN_ITEM(p_s_ih, p_s_key, n_blocksize) \
692 ( ! COMP_SHORT_KEYS(p_s_ih, p_s_key) && \ 681 ( ! COMP_SHORT_KEYS(p_s_ih, p_s_key) && \
693 I_OFF_BYTE_IN_ITEM(p_s_ih, k_offset (p_s_key), n_blocksize) ) 682 I_OFF_BYTE_IN_ITEM(p_s_ih, k_offset (p_s_key), n_blocksize) )
694 683
695/* maximal length of item */ 684/* maximal length of item */
696#define MAX_ITEM_LEN(block_size) (block_size - BLKH_SIZE - IH_SIZE) 685#define MAX_ITEM_LEN(block_size) (block_size - BLKH_SIZE - IH_SIZE)
697#define MIN_ITEM_LEN 1 686#define MIN_ITEM_LEN 1
698 687
699
700/* object identifier for root dir */ 688/* object identifier for root dir */
701#define REISERFS_ROOT_OBJECTID 2 689#define REISERFS_ROOT_OBJECTID 2
702#define REISERFS_ROOT_PARENT_OBJECTID 1 690#define REISERFS_ROOT_PARENT_OBJECTID 1
703extern struct reiserfs_key root_key; 691extern struct reiserfs_key root_key;
704 692
705
706
707
708/* 693/*
709 * Picture represents a leaf of the S+tree 694 * Picture represents a leaf of the S+tree
710 * ______________________________________________________ 695 * ______________________________________________________
@@ -716,13 +701,13 @@ extern struct reiserfs_key root_key;
716 701
717/* Header of a disk block. More precisely, header of a formatted leaf 702/* Header of a disk block. More precisely, header of a formatted leaf
718 or internal node, and not the header of an unformatted node. */ 703 or internal node, and not the header of an unformatted node. */
719struct block_head { 704struct block_head {
720 __le16 blk_level; /* Level of a block in the tree. */ 705 __le16 blk_level; /* Level of a block in the tree. */
721 __le16 blk_nr_item; /* Number of keys/items in a block. */ 706 __le16 blk_nr_item; /* Number of keys/items in a block. */
722 __le16 blk_free_space; /* Block free space in bytes. */ 707 __le16 blk_free_space; /* Block free space in bytes. */
723 __le16 blk_reserved; 708 __le16 blk_reserved;
724 /* dump this in v4/planA */ 709 /* dump this in v4/planA */
725 struct reiserfs_key blk_right_delim_key; /* kept only for compatibility */ 710 struct reiserfs_key blk_right_delim_key; /* kept only for compatibility */
726}; 711};
727 712
728#define BLKH_SIZE (sizeof(struct block_head)) 713#define BLKH_SIZE (sizeof(struct block_head))
@@ -741,12 +726,12 @@ struct block_head {
741 * values for blk_level field of the struct block_head 726 * values for blk_level field of the struct block_head
742 */ 727 */
743 728
744#define FREE_LEVEL 0 /* when node gets removed from the tree its 729#define FREE_LEVEL 0 /* when node gets removed from the tree its
745 blk_level is set to FREE_LEVEL. It is then 730 blk_level is set to FREE_LEVEL. It is then
746 used to see whether the node is still in the 731 used to see whether the node is still in the
747 tree */ 732 tree */
748 733
749#define DISK_LEAF_NODE_LEVEL 1 /* Leaf node level.*/ 734#define DISK_LEAF_NODE_LEVEL 1 /* Leaf node level. */
750 735
751/* Given the buffer head of a formatted node, resolve to the block head of that node. */ 736/* Given the buffer head of a formatted node, resolve to the block head of that node. */
752#define B_BLK_HEAD(p_s_bh) ((struct block_head *)((p_s_bh)->b_data)) 737#define B_BLK_HEAD(p_s_bh) ((struct block_head *)((p_s_bh)->b_data))
@@ -759,7 +744,6 @@ struct block_head {
759#define PUT_B_LEVEL(p_s_bh,val) do { set_blkh_level(B_BLK_HEAD(p_s_bh),val); } while (0) 744#define PUT_B_LEVEL(p_s_bh,val) do { set_blkh_level(B_BLK_HEAD(p_s_bh),val); } while (0)
760#define PUT_B_FREE_SPACE(p_s_bh,val) do { set_blkh_free_space(B_BLK_HEAD(p_s_bh),val); } while (0) 745#define PUT_B_FREE_SPACE(p_s_bh,val) do { set_blkh_free_space(B_BLK_HEAD(p_s_bh),val); } while (0)
761 746
762
763/* Get right delimiting key. -- little endian */ 747/* Get right delimiting key. -- little endian */
764#define B_PRIGHT_DELIM_KEY(p_s_bh) (&(blk_right_delim_key(B_BLK_HEAD(p_s_bh)) 748#define B_PRIGHT_DELIM_KEY(p_s_bh) (&(blk_right_delim_key(B_BLK_HEAD(p_s_bh))
765 749
@@ -770,41 +754,36 @@ struct block_head {
770#define B_IS_KEYS_LEVEL(p_s_bh) (B_LEVEL(p_s_bh) > DISK_LEAF_NODE_LEVEL \ 754#define B_IS_KEYS_LEVEL(p_s_bh) (B_LEVEL(p_s_bh) > DISK_LEAF_NODE_LEVEL \
771 && B_LEVEL(p_s_bh) <= MAX_HEIGHT) 755 && B_LEVEL(p_s_bh) <= MAX_HEIGHT)
772 756
773
774
775
776/***************************************************************************/ 757/***************************************************************************/
777/* STAT DATA */ 758/* STAT DATA */
778/***************************************************************************/ 759/***************************************************************************/
779 760
780
781// 761//
782// old stat data is 32 bytes long. We are going to distinguish new one by 762// old stat data is 32 bytes long. We are going to distinguish new one by
783// different size 763// different size
784// 764//
785struct stat_data_v1 765struct stat_data_v1 {
786{ 766 __le16 sd_mode; /* file type, permissions */
787 __le16 sd_mode; /* file type, permissions */ 767 __le16 sd_nlink; /* number of hard links */
788 __le16 sd_nlink; /* number of hard links */ 768 __le16 sd_uid; /* owner */
789 __le16 sd_uid; /* owner */ 769 __le16 sd_gid; /* group */
790 __le16 sd_gid; /* group */ 770 __le32 sd_size; /* file size */
791 __le32 sd_size; /* file size */ 771 __le32 sd_atime; /* time of last access */
792 __le32 sd_atime; /* time of last access */ 772 __le32 sd_mtime; /* time file was last modified */
793 __le32 sd_mtime; /* time file was last modified */ 773 __le32 sd_ctime; /* time inode (stat data) was last changed (except changes to sd_atime and sd_mtime) */
794 __le32 sd_ctime; /* time inode (stat data) was last changed (except changes to sd_atime and sd_mtime) */ 774 union {
795 union { 775 __le32 sd_rdev;
796 __le32 sd_rdev; 776 __le32 sd_blocks; /* number of blocks file uses */
797 __le32 sd_blocks; /* number of blocks file uses */ 777 } __attribute__ ((__packed__)) u;
798 } __attribute__ ((__packed__)) u; 778 __le32 sd_first_direct_byte; /* first byte of file which is stored
799 __le32 sd_first_direct_byte; /* first byte of file which is stored 779 in a direct item: except that if it
800 in a direct item: except that if it 780 equals 1 it is a symlink and if it
801 equals 1 it is a symlink and if it 781 equals ~(__u32)0 there is no
802 equals ~(__u32)0 there is no 782 direct item. The existence of this
803 direct item. The existence of this 783 field really grates on me. Let's
804 field really grates on me. Let's 784 replace it with a macro based on
805 replace it with a macro based on 785 sd_size and our tail suppression
806 sd_size and our tail suppression 786 policy. Someday. -Hans */
807 policy. Someday. -Hans */
808} __attribute__ ((__packed__)); 787} __attribute__ ((__packed__));
809 788
810#define SD_V1_SIZE (sizeof(struct stat_data_v1)) 789#define SD_V1_SIZE (sizeof(struct stat_data_v1))
@@ -862,29 +841,29 @@ struct stat_data_v1
862/* Stat Data on disk (reiserfs version of UFS disk inode minus the 841/* Stat Data on disk (reiserfs version of UFS disk inode minus the
863 address blocks) */ 842 address blocks) */
864struct stat_data { 843struct stat_data {
865 __le16 sd_mode; /* file type, permissions */ 844 __le16 sd_mode; /* file type, permissions */
866 __le16 sd_attrs; /* persistent inode flags */ 845 __le16 sd_attrs; /* persistent inode flags */
867 __le32 sd_nlink; /* number of hard links */ 846 __le32 sd_nlink; /* number of hard links */
868 __le64 sd_size; /* file size */ 847 __le64 sd_size; /* file size */
869 __le32 sd_uid; /* owner */ 848 __le32 sd_uid; /* owner */
870 __le32 sd_gid; /* group */ 849 __le32 sd_gid; /* group */
871 __le32 sd_atime; /* time of last access */ 850 __le32 sd_atime; /* time of last access */
872 __le32 sd_mtime; /* time file was last modified */ 851 __le32 sd_mtime; /* time file was last modified */
873 __le32 sd_ctime; /* time inode (stat data) was last changed (except changes to sd_atime and sd_mtime) */ 852 __le32 sd_ctime; /* time inode (stat data) was last changed (except changes to sd_atime and sd_mtime) */
874 __le32 sd_blocks; 853 __le32 sd_blocks;
875 union { 854 union {
876 __le32 sd_rdev; 855 __le32 sd_rdev;
877 __le32 sd_generation; 856 __le32 sd_generation;
878 //__le32 sd_first_direct_byte; 857 //__le32 sd_first_direct_byte;
879 /* first byte of file which is stored in a 858 /* first byte of file which is stored in a
880 direct item: except that if it equals 1 859 direct item: except that if it equals 1
881 it is a symlink and if it equals 860 it is a symlink and if it equals
882 ~(__u32)0 there is no direct item. The 861 ~(__u32)0 there is no direct item. The
883 existence of this field really grates 862 existence of this field really grates
884 on me. Let's replace it with a macro 863 on me. Let's replace it with a macro
885 based on sd_size and our tail 864 based on sd_size and our tail
886 suppression policy? */ 865 suppression policy? */
887 } __attribute__ ((__packed__)) u; 866 } __attribute__ ((__packed__)) u;
888} __attribute__ ((__packed__)); 867} __attribute__ ((__packed__));
889// 868//
890// this is 44 bytes long 869// this is 44 bytes long
@@ -919,7 +898,6 @@ struct stat_data {
919#define sd_v2_attrs(sdp) (le16_to_cpu((sdp)->sd_attrs)) 898#define sd_v2_attrs(sdp) (le16_to_cpu((sdp)->sd_attrs))
920#define set_sd_v2_attrs(sdp,v) ((sdp)->sd_attrs = cpu_to_le16(v)) 899#define set_sd_v2_attrs(sdp,v) ((sdp)->sd_attrs = cpu_to_le16(v))
921 900
922
923/***************************************************************************/ 901/***************************************************************************/
924/* DIRECTORY STRUCTURE */ 902/* DIRECTORY STRUCTURE */
925/***************************************************************************/ 903/***************************************************************************/
@@ -954,17 +932,14 @@ struct stat_data {
954/* NOT IMPLEMENTED: 932/* NOT IMPLEMENTED:
955 Directory will someday contain stat data of object */ 933 Directory will someday contain stat data of object */
956 934
957 935struct reiserfs_de_head {
958 936 __le32 deh_offset; /* third component of the directory entry key */
959struct reiserfs_de_head 937 __le32 deh_dir_id; /* objectid of the parent directory of the object, that is referenced
960{ 938 by directory entry */
961 __le32 deh_offset; /* third component of the directory entry key */ 939 __le32 deh_objectid; /* objectid of the object, that is referenced by directory entry */
962 __le32 deh_dir_id; /* objectid of the parent directory of the object, that is referenced 940 __le16 deh_location; /* offset of name in the whole item */
963 by directory entry */ 941 __le16 deh_state; /* whether 1) entry contains stat data (for future), and 2) whether
964 __le32 deh_objectid; /* objectid of the object, that is referenced by directory entry */ 942 entry is hidden (unlinked) */
965 __le16 deh_location; /* offset of name in the whole item */
966 __le16 deh_state; /* whether 1) entry contains stat data (for future), and 2) whether
967 entry is hidden (unlinked) */
968} __attribute__ ((__packed__)); 943} __attribute__ ((__packed__));
969#define DEH_SIZE sizeof(struct reiserfs_de_head) 944#define DEH_SIZE sizeof(struct reiserfs_de_head)
970#define deh_offset(p_deh) (le32_to_cpu((p_deh)->deh_offset)) 945#define deh_offset(p_deh) (le32_to_cpu((p_deh)->deh_offset))
@@ -986,7 +961,7 @@ struct reiserfs_de_head
986/* old format directories have this size when empty */ 961/* old format directories have this size when empty */
987#define EMPTY_DIR_SIZE_V1 (DEH_SIZE * 2 + 3) 962#define EMPTY_DIR_SIZE_V1 (DEH_SIZE * 2 + 3)
988 963
989#define DEH_Statdata 0 /* not used now */ 964#define DEH_Statdata 0 /* not used now */
990#define DEH_Visible 2 965#define DEH_Visible 2
991 966
992/* 64 bit systems (and the S/390) need to be aligned explicitly -jdm */ 967/* 64 bit systems (and the S/390) need to be aligned explicitly -jdm */
@@ -1023,10 +998,10 @@ struct reiserfs_de_head
1023#define de_visible(deh) test_bit_unaligned (DEH_Visible, &((deh)->deh_state)) 998#define de_visible(deh) test_bit_unaligned (DEH_Visible, &((deh)->deh_state))
1024#define de_hidden(deh) !test_bit_unaligned (DEH_Visible, &((deh)->deh_state)) 999#define de_hidden(deh) !test_bit_unaligned (DEH_Visible, &((deh)->deh_state))
1025 1000
1026extern void make_empty_dir_item_v1 (char * body, __le32 dirid, __le32 objid, 1001extern void make_empty_dir_item_v1(char *body, __le32 dirid, __le32 objid,
1027 __le32 par_dirid, __le32 par_objid); 1002 __le32 par_dirid, __le32 par_objid);
1028extern void make_empty_dir_item (char * body, __le32 dirid, __le32 objid, 1003extern void make_empty_dir_item(char *body, __le32 dirid, __le32 objid,
1029 __le32 par_dirid, __le32 par_objid); 1004 __le32 par_dirid, __le32 par_objid);
1030 1005
1031/* array of the entry headers */ 1006/* array of the entry headers */
1032 /* get item body */ 1007 /* get item body */
@@ -1043,53 +1018,48 @@ extern void make_empty_dir_item (char * body, __le32 dirid, __le32 objid,
1043#define I_DEH_N_ENTRY_LENGTH(ih,deh,i) \ 1018#define I_DEH_N_ENTRY_LENGTH(ih,deh,i) \
1044((i) ? (deh_location((deh)-1) - deh_location((deh))) : (ih_item_len((ih)) - deh_location((deh)))) 1019((i) ? (deh_location((deh)-1) - deh_location((deh))) : (ih_item_len((ih)) - deh_location((deh))))
1045*/ 1020*/
1046static inline int entry_length (const struct buffer_head * bh, 1021static inline int entry_length(const struct buffer_head *bh,
1047 const struct item_head * ih, int pos_in_item) 1022 const struct item_head *ih, int pos_in_item)
1048{ 1023{
1049 struct reiserfs_de_head * deh; 1024 struct reiserfs_de_head *deh;
1050 1025
1051 deh = B_I_DEH (bh, ih) + pos_in_item; 1026 deh = B_I_DEH(bh, ih) + pos_in_item;
1052 if (pos_in_item) 1027 if (pos_in_item)
1053 return deh_location(deh-1) - deh_location(deh); 1028 return deh_location(deh - 1) - deh_location(deh);
1054 1029
1055 return ih_item_len(ih) - deh_location(deh); 1030 return ih_item_len(ih) - deh_location(deh);
1056} 1031}
1057 1032
1058
1059
1060/* number of entries in the directory item, depends on ENTRY_COUNT being at the start of directory dynamic data. */ 1033/* number of entries in the directory item, depends on ENTRY_COUNT being at the start of directory dynamic data. */
1061#define I_ENTRY_COUNT(ih) (ih_entry_count((ih))) 1034#define I_ENTRY_COUNT(ih) (ih_entry_count((ih)))
1062 1035
1063
1064/* name by bh, ih and entry_num */ 1036/* name by bh, ih and entry_num */
1065#define B_I_E_NAME(bh,ih,entry_num) ((char *)(bh->b_data + ih_location(ih) + deh_location(B_I_DEH(bh,ih)+(entry_num)))) 1037#define B_I_E_NAME(bh,ih,entry_num) ((char *)(bh->b_data + ih_location(ih) + deh_location(B_I_DEH(bh,ih)+(entry_num))))
1066 1038
1067// two entries per block (at least) 1039// two entries per block (at least)
1068#define REISERFS_MAX_NAME(block_size) 255 1040#define REISERFS_MAX_NAME(block_size) 255
1069 1041
1070
1071/* this structure is used for operations on directory entries. It is 1042/* this structure is used for operations on directory entries. It is
1072 not a disk structure. */ 1043 not a disk structure. */
1073/* When reiserfs_find_entry or search_by_entry_key find directory 1044/* When reiserfs_find_entry or search_by_entry_key find directory
1074 entry, they return filled reiserfs_dir_entry structure */ 1045 entry, they return filled reiserfs_dir_entry structure */
1075struct reiserfs_dir_entry 1046struct reiserfs_dir_entry {
1076{ 1047 struct buffer_head *de_bh;
1077 struct buffer_head * de_bh; 1048 int de_item_num;
1078 int de_item_num; 1049 struct item_head *de_ih;
1079 struct item_head * de_ih; 1050 int de_entry_num;
1080 int de_entry_num; 1051 struct reiserfs_de_head *de_deh;
1081 struct reiserfs_de_head * de_deh; 1052 int de_entrylen;
1082 int de_entrylen; 1053 int de_namelen;
1083 int de_namelen; 1054 char *de_name;
1084 char * de_name; 1055 char *de_gen_number_bit_string;
1085 char * de_gen_number_bit_string; 1056
1086 1057 __u32 de_dir_id;
1087 __u32 de_dir_id; 1058 __u32 de_objectid;
1088 __u32 de_objectid; 1059
1089 1060 struct cpu_key de_entry_key;
1090 struct cpu_key de_entry_key;
1091}; 1061};
1092 1062
1093/* these defines are useful when a particular member of a reiserfs_dir_entry is needed */ 1063/* these defines are useful when a particular member of a reiserfs_dir_entry is needed */
1094 1064
1095/* pointer to file name, stored in entry */ 1065/* pointer to file name, stored in entry */
@@ -1099,8 +1069,6 @@ struct reiserfs_dir_entry
1099#define I_DEH_N_ENTRY_FILE_NAME_LENGTH(ih,deh,entry_num) \ 1069#define I_DEH_N_ENTRY_FILE_NAME_LENGTH(ih,deh,entry_num) \
1100(I_DEH_N_ENTRY_LENGTH (ih, deh, entry_num) - (de_with_sd (deh) ? SD_SIZE : 0)) 1070(I_DEH_N_ENTRY_LENGTH (ih, deh, entry_num) - (de_with_sd (deh) ? SD_SIZE : 0))
1101 1071
1102
1103
1104/* hash value occupies bits from 7 up to 30 */ 1072/* hash value occupies bits from 7 up to 30 */
1105#define GET_HASH_VALUE(offset) ((offset) & 0x7fffff80LL) 1073#define GET_HASH_VALUE(offset) ((offset) & 0x7fffff80LL)
1106/* generation number occupies 7 bits starting from 0 up to 6 */ 1074/* generation number occupies 7 bits starting from 0 up to 6 */
@@ -1109,7 +1077,6 @@ struct reiserfs_dir_entry
1109 1077
1110#define SET_GENERATION_NUMBER(offset,gen_number) (GET_HASH_VALUE(offset)|(gen_number)) 1078#define SET_GENERATION_NUMBER(offset,gen_number) (GET_HASH_VALUE(offset)|(gen_number))
1111 1079
1112
1113/* 1080/*
1114 * Picture represents an internal node of the reiserfs tree 1081 * Picture represents an internal node of the reiserfs tree
1115 * ______________________________________________________ 1082 * ______________________________________________________
@@ -1125,9 +1092,9 @@ struct reiserfs_dir_entry
1125/* Disk child pointer: The pointer from an internal node of the tree 1092/* Disk child pointer: The pointer from an internal node of the tree
1126 to a node that is on disk. */ 1093 to a node that is on disk. */
1127struct disk_child { 1094struct disk_child {
1128 __le32 dc_block_number; /* Disk child's block number. */ 1095 __le32 dc_block_number; /* Disk child's block number. */
1129 __le16 dc_size; /* Disk child's used space. */ 1096 __le16 dc_size; /* Disk child's used space. */
1130 __le16 dc_reserved; 1097 __le16 dc_reserved;
1131}; 1098};
1132 1099
1133#define DC_SIZE (sizeof(struct disk_child)) 1100#define DC_SIZE (sizeof(struct disk_child))
@@ -1144,7 +1111,7 @@ struct disk_child {
1144#define B_N_CHILD_NUM(p_s_bh,n_pos) (dc_block_number(B_N_CHILD(p_s_bh,n_pos))) 1111#define B_N_CHILD_NUM(p_s_bh,n_pos) (dc_block_number(B_N_CHILD(p_s_bh,n_pos)))
1145#define PUT_B_N_CHILD_NUM(p_s_bh,n_pos, val) (put_dc_block_number(B_N_CHILD(p_s_bh,n_pos), val )) 1112#define PUT_B_N_CHILD_NUM(p_s_bh,n_pos, val) (put_dc_block_number(B_N_CHILD(p_s_bh,n_pos), val ))
1146 1113
1147 /* maximal value of field child_size in structure disk_child */ 1114 /* maximal value of field child_size in structure disk_child */
1148 /* child size is the combined size of all items and their headers */ 1115 /* child size is the combined size of all items and their headers */
1149#define MAX_CHILD_SIZE(bh) ((int)( (bh)->b_size - BLKH_SIZE )) 1116#define MAX_CHILD_SIZE(bh) ((int)( (bh)->b_size - BLKH_SIZE ))
1150 1117
@@ -1159,7 +1126,6 @@ struct disk_child {
1159/* PATH STRUCTURES AND DEFINES */ 1126/* PATH STRUCTURES AND DEFINES */
1160/***************************************************************************/ 1127/***************************************************************************/
1161 1128
1162
1163/* Search_by_key fills up the path from the root to the leaf as it descends the tree looking for the 1129/* Search_by_key fills up the path from the root to the leaf as it descends the tree looking for the
1164 key. It uses reiserfs_bread to try to find buffers in the cache given their block number. If it 1130 key. It uses reiserfs_bread to try to find buffers in the cache given their block number. If it
1165 does not find them in the cache it reads them from disk. For each node search_by_key finds using 1131 does not find them in the cache it reads them from disk. For each node search_by_key finds using
@@ -1168,20 +1134,18 @@ struct disk_child {
1168 is looking through a leaf node bin_search will find the position of the item which has key either 1134 is looking through a leaf node bin_search will find the position of the item which has key either
1169 equal to given key, or which is the maximal key less than the given key. */ 1135 equal to given key, or which is the maximal key less than the given key. */
1170 1136
1171struct path_element { 1137struct path_element {
1172 struct buffer_head * pe_buffer; /* Pointer to the buffer at the path in the tree. */ 1138 struct buffer_head *pe_buffer; /* Pointer to the buffer at the path in the tree. */
1173 int pe_position; /* Position in the tree node which is placed in the */ 1139 int pe_position; /* Position in the tree node which is placed in the */
1174 /* buffer above. */ 1140 /* buffer above. */
1175}; 1141};
1176 1142
1177#define MAX_HEIGHT 5 /* maximal height of a tree. don't change this without changing JOURNAL_PER_BALANCE_CNT */ 1143#define MAX_HEIGHT 5 /* maximal height of a tree. don't change this without changing JOURNAL_PER_BALANCE_CNT */
1178#define EXTENDED_MAX_HEIGHT 7 /* Must be equals MAX_HEIGHT + FIRST_PATH_ELEMENT_OFFSET */ 1144#define EXTENDED_MAX_HEIGHT 7 /* Must be equals MAX_HEIGHT + FIRST_PATH_ELEMENT_OFFSET */
1179#define FIRST_PATH_ELEMENT_OFFSET 2 /* Must be equal to at least 2. */ 1145#define FIRST_PATH_ELEMENT_OFFSET 2 /* Must be equal to at least 2. */
1180
1181#define ILLEGAL_PATH_ELEMENT_OFFSET 1 /* Must be equal to FIRST_PATH_ELEMENT_OFFSET - 1 */
1182#define MAX_FEB_SIZE 6 /* this MUST be MAX_HEIGHT + 1. See about FEB below */
1183
1184 1146
1147#define ILLEGAL_PATH_ELEMENT_OFFSET 1 /* Must be equal to FIRST_PATH_ELEMENT_OFFSET - 1 */
1148#define MAX_FEB_SIZE 6 /* this MUST be MAX_HEIGHT + 1. See about FEB below */
1185 1149
1186/* We need to keep track of who the ancestors of nodes are. When we 1150/* We need to keep track of who the ancestors of nodes are. When we
1187 perform a search we record which nodes were visited while 1151 perform a search we record which nodes were visited while
@@ -1200,14 +1164,14 @@ excessive effort to avoid disturbing the precious VFS code.:-( The
1200gods only know how we are going to SMP the code that uses them. 1164gods only know how we are going to SMP the code that uses them.
1201znodes are the way! */ 1165znodes are the way! */
1202 1166
1203#define PATH_READA 0x1 /* do read ahead */ 1167#define PATH_READA 0x1 /* do read ahead */
1204#define PATH_READA_BACK 0x2 /* read backwards */ 1168#define PATH_READA_BACK 0x2 /* read backwards */
1205 1169
1206struct path { 1170struct path {
1207 int path_length; /* Length of the array above. */ 1171 int path_length; /* Length of the array above. */
1208 int reada; 1172 int reada;
1209 struct path_element path_elements[EXTENDED_MAX_HEIGHT]; /* Array of the path elements. */ 1173 struct path_element path_elements[EXTENDED_MAX_HEIGHT]; /* Array of the path elements. */
1210 int pos_in_item; 1174 int pos_in_item;
1211}; 1175};
1212 1176
1213#define pos_in_item(path) ((path)->pos_in_item) 1177#define pos_in_item(path) ((path)->pos_in_item)
@@ -1224,25 +1188,23 @@ struct path var = {.path_length = ILLEGAL_PATH_ELEMENT_OFFSET, .reada = 0,}
1224/* Get position in the element at the path by path and path position. */ 1188/* Get position in the element at the path by path and path position. */
1225#define PATH_OFFSET_POSITION(p_s_path,n_offset) (PATH_OFFSET_PELEMENT(p_s_path,n_offset)->pe_position) 1189#define PATH_OFFSET_POSITION(p_s_path,n_offset) (PATH_OFFSET_PELEMENT(p_s_path,n_offset)->pe_position)
1226 1190
1227
1228#define PATH_PLAST_BUFFER(p_s_path) (PATH_OFFSET_PBUFFER((p_s_path), (p_s_path)->path_length)) 1191#define PATH_PLAST_BUFFER(p_s_path) (PATH_OFFSET_PBUFFER((p_s_path), (p_s_path)->path_length))
1229 /* you know, to the person who didn't 1192 /* you know, to the person who didn't
1230 write this the macro name does not 1193 write this the macro name does not
1231 at first suggest what it does. 1194 at first suggest what it does.
1232 Maybe POSITION_FROM_PATH_END? Or 1195 Maybe POSITION_FROM_PATH_END? Or
1233 maybe we should just focus on 1196 maybe we should just focus on
1234 dumping paths... -Hans */ 1197 dumping paths... -Hans */
1235#define PATH_LAST_POSITION(p_s_path) (PATH_OFFSET_POSITION((p_s_path), (p_s_path)->path_length)) 1198#define PATH_LAST_POSITION(p_s_path) (PATH_OFFSET_POSITION((p_s_path), (p_s_path)->path_length))
1236 1199
1237
1238#define PATH_PITEM_HEAD(p_s_path) B_N_PITEM_HEAD(PATH_PLAST_BUFFER(p_s_path),PATH_LAST_POSITION(p_s_path)) 1200#define PATH_PITEM_HEAD(p_s_path) B_N_PITEM_HEAD(PATH_PLAST_BUFFER(p_s_path),PATH_LAST_POSITION(p_s_path))
1239 1201
1240/* in do_balance leaf has h == 0 in contrast with path structure, 1202/* in do_balance leaf has h == 0 in contrast with path structure,
1241 where root has level == 0. That is why we need these defines */ 1203 where root has level == 0. That is why we need these defines */
1242#define PATH_H_PBUFFER(p_s_path, h) PATH_OFFSET_PBUFFER (p_s_path, p_s_path->path_length - (h)) /* tb->S[h] */ 1204#define PATH_H_PBUFFER(p_s_path, h) PATH_OFFSET_PBUFFER (p_s_path, p_s_path->path_length - (h)) /* tb->S[h] */
1243#define PATH_H_PPARENT(path, h) PATH_H_PBUFFER (path, (h) + 1) /* tb->F[h] or tb->S[0]->b_parent */ 1205#define PATH_H_PPARENT(path, h) PATH_H_PBUFFER (path, (h) + 1) /* tb->F[h] or tb->S[0]->b_parent */
1244#define PATH_H_POSITION(path, h) PATH_OFFSET_POSITION (path, path->path_length - (h)) 1206#define PATH_H_POSITION(path, h) PATH_OFFSET_POSITION (path, path->path_length - (h))
1245#define PATH_H_B_ITEM_ORDER(path, h) PATH_H_POSITION(path, h + 1) /* tb->S[h]->b_item_order */ 1207#define PATH_H_B_ITEM_ORDER(path, h) PATH_H_POSITION(path, h + 1) /* tb->S[h]->b_item_order */
1246 1208
1247#define PATH_H_PATH_OFFSET(p_s_path, n_h) ((p_s_path)->path_length - (n_h)) 1209#define PATH_H_PATH_OFFSET(p_s_path, n_h) ((p_s_path)->path_length - (n_h))
1248 1210
@@ -1253,7 +1215,6 @@ struct path var = {.path_length = ILLEGAL_PATH_ELEMENT_OFFSET, .reada = 0,}
1253#define item_moved(ih,path) comp_items(ih, path) 1215#define item_moved(ih,path) comp_items(ih, path)
1254#define path_changed(ih,path) comp_items (ih, path) 1216#define path_changed(ih,path) comp_items (ih, path)
1255 1217
1256
1257/***************************************************************************/ 1218/***************************************************************************/
1258/* MISC */ 1219/* MISC */
1259/***************************************************************************/ 1220/***************************************************************************/
@@ -1272,30 +1233,26 @@ struct path var = {.path_length = ILLEGAL_PATH_ELEMENT_OFFSET, .reada = 0,}
1272// reiserfs version 2 has max offset 60 bits. Version 1 - 32 bit offset 1233// reiserfs version 2 has max offset 60 bits. Version 1 - 32 bit offset
1273#define U32_MAX (~(__u32)0) 1234#define U32_MAX (~(__u32)0)
1274 1235
1275static inline loff_t max_reiserfs_offset (struct inode * inode) 1236static inline loff_t max_reiserfs_offset(struct inode *inode)
1276{ 1237{
1277 if (get_inode_item_key_version(inode) == KEY_FORMAT_3_5) 1238 if (get_inode_item_key_version(inode) == KEY_FORMAT_3_5)
1278 return (loff_t)U32_MAX; 1239 return (loff_t) U32_MAX;
1279 1240
1280 return (loff_t)((~(__u64)0) >> 4); 1241 return (loff_t) ((~(__u64) 0) >> 4);
1281} 1242}
1282 1243
1283
1284/*#define MAX_KEY_UNIQUENESS MAX_UL_INT*/ 1244/*#define MAX_KEY_UNIQUENESS MAX_UL_INT*/
1285#define MAX_KEY_OBJECTID MAX_UL_INT 1245#define MAX_KEY_OBJECTID MAX_UL_INT
1286 1246
1287
1288#define MAX_B_NUM MAX_UL_INT 1247#define MAX_B_NUM MAX_UL_INT
1289#define MAX_FC_NUM MAX_US_INT 1248#define MAX_FC_NUM MAX_US_INT
1290 1249
1291
1292/* the purpose is to detect overflow of an unsigned short */ 1250/* the purpose is to detect overflow of an unsigned short */
1293#define REISERFS_LINK_MAX (MAX_US_INT - 1000) 1251#define REISERFS_LINK_MAX (MAX_US_INT - 1000)
1294 1252
1295
1296/* The following defines are used in reiserfs_insert_item and reiserfs_append_item */ 1253/* The following defines are used in reiserfs_insert_item and reiserfs_append_item */
1297#define REISERFS_KERNEL_MEM 0 /* reiserfs kernel memory mode */ 1254#define REISERFS_KERNEL_MEM 0 /* reiserfs kernel memory mode */
1298#define REISERFS_USER_MEM 1 /* reiserfs user memory mode */ 1255#define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
1299 1256
1300#define fs_generation(s) (REISERFS_SB(s)->s_generation_counter) 1257#define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
1301#define get_generation(s) atomic_read (&fs_generation(s)) 1258#define get_generation(s) atomic_read (&fs_generation(s))
@@ -1303,7 +1260,6 @@ static inline loff_t max_reiserfs_offset (struct inode * inode)
1303#define __fs_changed(gen,s) (gen != get_generation (s)) 1260#define __fs_changed(gen,s) (gen != get_generation (s))
1304#define fs_changed(gen,s) ({cond_resched(); __fs_changed(gen, s);}) 1261#define fs_changed(gen,s) ({cond_resched(); __fs_changed(gen, s);})
1305 1262
1306
1307/***************************************************************************/ 1263/***************************************************************************/
1308/* FIXATE NODES */ 1264/* FIXATE NODES */
1309/***************************************************************************/ 1265/***************************************************************************/
@@ -1324,38 +1280,34 @@ static inline loff_t max_reiserfs_offset (struct inode * inode)
1324 calculating what we can shift to neighbors and how many nodes we 1280 calculating what we can shift to neighbors and how many nodes we
1325 have to have if we do not any shiftings, if we shift to left/right 1281 have to have if we do not any shiftings, if we shift to left/right
1326 neighbor or to both. */ 1282 neighbor or to both. */
1327struct virtual_item 1283struct virtual_item {
1328{ 1284 int vi_index; // index in the array of item operations
1329 int vi_index; // index in the array of item operations 1285 unsigned short vi_type; // left/right mergeability
1330 unsigned short vi_type; // left/right mergeability 1286 unsigned short vi_item_len; /* length of item that it will have after balancing */
1331 unsigned short vi_item_len; /* length of item that it will have after balancing */ 1287 struct item_head *vi_ih;
1332 struct item_head * vi_ih; 1288 const char *vi_item; // body of item (old or new)
1333 const char * vi_item; // body of item (old or new) 1289 const void *vi_new_data; // 0 always but paste mode
1334 const void * vi_new_data; // 0 always but paste mode 1290 void *vi_uarea; // item specific area
1335 void * vi_uarea; // item specific area
1336}; 1291};
1337 1292
1338 1293struct virtual_node {
1339struct virtual_node 1294 char *vn_free_ptr; /* this is a pointer to the free space in the buffer */
1340{ 1295 unsigned short vn_nr_item; /* number of items in virtual node */
1341 char * vn_free_ptr; /* this is a pointer to the free space in the buffer */ 1296 short vn_size; /* size of node , that node would have if it has unlimited size and no balancing is performed */
1342 unsigned short vn_nr_item; /* number of items in virtual node */ 1297 short vn_mode; /* mode of balancing (paste, insert, delete, cut) */
1343 short vn_size; /* size of node , that node would have if it has unlimited size and no balancing is performed */ 1298 short vn_affected_item_num;
1344 short vn_mode; /* mode of balancing (paste, insert, delete, cut) */ 1299 short vn_pos_in_item;
1345 short vn_affected_item_num; 1300 struct item_head *vn_ins_ih; /* item header of inserted item, 0 for other modes */
1346 short vn_pos_in_item; 1301 const void *vn_data;
1347 struct item_head * vn_ins_ih; /* item header of inserted item, 0 for other modes */ 1302 struct virtual_item *vn_vi; /* array of items (including a new one, excluding item to be deleted) */
1348 const void * vn_data;
1349 struct virtual_item * vn_vi; /* array of items (including a new one, excluding item to be deleted) */
1350}; 1303};
1351 1304
1352/* used by directory items when creating virtual nodes */ 1305/* used by directory items when creating virtual nodes */
1353struct direntry_uarea { 1306struct direntry_uarea {
1354 int flags; 1307 int flags;
1355 __u16 entry_count; 1308 __u16 entry_count;
1356 __u16 entry_sizes[1]; 1309 __u16 entry_sizes[1];
1357} __attribute__ ((__packed__)) ; 1310} __attribute__ ((__packed__));
1358
1359 1311
1360/***************************************************************************/ 1312/***************************************************************************/
1361/* TREE BALANCE */ 1313/* TREE BALANCE */
@@ -1378,73 +1330,72 @@ struct direntry_uarea {
1378#define MAX_AMOUNT_NEEDED 2 1330#define MAX_AMOUNT_NEEDED 2
1379 1331
1380/* someday somebody will prefix every field in this struct with tb_ */ 1332/* someday somebody will prefix every field in this struct with tb_ */
1381struct tree_balance 1333struct tree_balance {
1382{ 1334 int tb_mode;
1383 int tb_mode; 1335 int need_balance_dirty;
1384 int need_balance_dirty; 1336 struct super_block *tb_sb;
1385 struct super_block * tb_sb; 1337 struct reiserfs_transaction_handle *transaction_handle;
1386 struct reiserfs_transaction_handle *transaction_handle ; 1338 struct path *tb_path;
1387 struct path * tb_path; 1339 struct buffer_head *L[MAX_HEIGHT]; /* array of left neighbors of nodes in the path */
1388 struct buffer_head * L[MAX_HEIGHT]; /* array of left neighbors of nodes in the path */ 1340 struct buffer_head *R[MAX_HEIGHT]; /* array of right neighbors of nodes in the path */
1389 struct buffer_head * R[MAX_HEIGHT]; /* array of right neighbors of nodes in the path*/ 1341 struct buffer_head *FL[MAX_HEIGHT]; /* array of fathers of the left neighbors */
1390 struct buffer_head * FL[MAX_HEIGHT]; /* array of fathers of the left neighbors */ 1342 struct buffer_head *FR[MAX_HEIGHT]; /* array of fathers of the right neighbors */
1391 struct buffer_head * FR[MAX_HEIGHT]; /* array of fathers of the right neighbors */ 1343 struct buffer_head *CFL[MAX_HEIGHT]; /* array of common parents of center node and its left neighbor */
1392 struct buffer_head * CFL[MAX_HEIGHT]; /* array of common parents of center node and its left neighbor */ 1344 struct buffer_head *CFR[MAX_HEIGHT]; /* array of common parents of center node and its right neighbor */
1393 struct buffer_head * CFR[MAX_HEIGHT]; /* array of common parents of center node and its right neighbor */ 1345
1394 1346 struct buffer_head *FEB[MAX_FEB_SIZE]; /* array of empty buffers. Number of buffers in array equals
1395 struct buffer_head * FEB[MAX_FEB_SIZE]; /* array of empty buffers. Number of buffers in array equals 1347 cur_blknum. */
1396 cur_blknum. */ 1348 struct buffer_head *used[MAX_FEB_SIZE];
1397 struct buffer_head * used[MAX_FEB_SIZE]; 1349 struct buffer_head *thrown[MAX_FEB_SIZE];
1398 struct buffer_head * thrown[MAX_FEB_SIZE]; 1350 int lnum[MAX_HEIGHT]; /* array of number of items which must be
1399 int lnum[MAX_HEIGHT]; /* array of number of items which must be 1351 shifted to the left in order to balance the
1400 shifted to the left in order to balance the 1352 current node; for leaves includes item that
1401 current node; for leaves includes item that 1353 will be partially shifted; for internal
1402 will be partially shifted; for internal 1354 nodes, it is the number of child pointers
1403 nodes, it is the number of child pointers 1355 rather than items. It includes the new item
1404 rather than items. It includes the new item 1356 being created. The code sometimes subtracts
1405 being created. The code sometimes subtracts 1357 one to get the number of wholly shifted
1406 one to get the number of wholly shifted 1358 items for other purposes. */
1407 items for other purposes. */ 1359 int rnum[MAX_HEIGHT]; /* substitute right for left in comment above */
1408 int rnum[MAX_HEIGHT]; /* substitute right for left in comment above */ 1360 int lkey[MAX_HEIGHT]; /* array indexed by height h mapping the key delimiting L[h] and
1409 int lkey[MAX_HEIGHT]; /* array indexed by height h mapping the key delimiting L[h] and 1361 S[h] to its item number within the node CFL[h] */
1410 S[h] to its item number within the node CFL[h] */ 1362 int rkey[MAX_HEIGHT]; /* substitute r for l in comment above */
1411 int rkey[MAX_HEIGHT]; /* substitute r for l in comment above */ 1363 int insert_size[MAX_HEIGHT]; /* the number of bytes by we are trying to add or remove from
1412 int insert_size[MAX_HEIGHT]; /* the number of bytes by we are trying to add or remove from 1364 S[h]. A negative value means removing. */
1413 S[h]. A negative value means removing. */ 1365 int blknum[MAX_HEIGHT]; /* number of nodes that will replace node S[h] after
1414 int blknum[MAX_HEIGHT]; /* number of nodes that will replace node S[h] after 1366 balancing on the level h of the tree. If 0 then S is
1415 balancing on the level h of the tree. If 0 then S is 1367 being deleted, if 1 then S is remaining and no new nodes
1416 being deleted, if 1 then S is remaining and no new nodes 1368 are being created, if 2 or 3 then 1 or 2 new nodes is
1417 are being created, if 2 or 3 then 1 or 2 new nodes is 1369 being created */
1418 being created */ 1370
1419 1371 /* fields that are used only for balancing leaves of the tree */
1420 /* fields that are used only for balancing leaves of the tree */ 1372 int cur_blknum; /* number of empty blocks having been already allocated */
1421 int cur_blknum; /* number of empty blocks having been already allocated */ 1373 int s0num; /* number of items that fall into left most node when S[0] splits */
1422 int s0num; /* number of items that fall into left most node when S[0] splits */ 1374 int s1num; /* number of items that fall into first new node when S[0] splits */
1423 int s1num; /* number of items that fall into first new node when S[0] splits */ 1375 int s2num; /* number of items that fall into second new node when S[0] splits */
1424 int s2num; /* number of items that fall into second new node when S[0] splits */ 1376 int lbytes; /* number of bytes which can flow to the left neighbor from the left */
1425 int lbytes; /* number of bytes which can flow to the left neighbor from the left */ 1377 /* most liquid item that cannot be shifted from S[0] entirely */
1426 /* most liquid item that cannot be shifted from S[0] entirely */ 1378 /* if -1 then nothing will be partially shifted */
1427 /* if -1 then nothing will be partially shifted */ 1379 int rbytes; /* number of bytes which will flow to the right neighbor from the right */
1428 int rbytes; /* number of bytes which will flow to the right neighbor from the right */ 1380 /* most liquid item that cannot be shifted from S[0] entirely */
1429 /* most liquid item that cannot be shifted from S[0] entirely */ 1381 /* if -1 then nothing will be partially shifted */
1430 /* if -1 then nothing will be partially shifted */ 1382 int s1bytes; /* number of bytes which flow to the first new node when S[0] splits */
1431 int s1bytes; /* number of bytes which flow to the first new node when S[0] splits */ 1383 /* note: if S[0] splits into 3 nodes, then items do not need to be cut */
1432 /* note: if S[0] splits into 3 nodes, then items do not need to be cut */ 1384 int s2bytes;
1433 int s2bytes; 1385 struct buffer_head *buf_to_free[MAX_FREE_BLOCK]; /* buffers which are to be freed after do_balance finishes by unfix_nodes */
1434 struct buffer_head * buf_to_free[MAX_FREE_BLOCK]; /* buffers which are to be freed after do_balance finishes by unfix_nodes */ 1386 char *vn_buf; /* kmalloced memory. Used to create
1435 char * vn_buf; /* kmalloced memory. Used to create
1436 virtual node and keep map of 1387 virtual node and keep map of
1437 dirtied bitmap blocks */ 1388 dirtied bitmap blocks */
1438 int vn_buf_size; /* size of the vn_buf */ 1389 int vn_buf_size; /* size of the vn_buf */
1439 struct virtual_node * tb_vn; /* VN starts after bitmap of bitmap blocks */ 1390 struct virtual_node *tb_vn; /* VN starts after bitmap of bitmap blocks */
1440 1391
1441 int fs_gen; /* saved value of `reiserfs_generation' counter 1392 int fs_gen; /* saved value of `reiserfs_generation' counter
1442 see FILESYSTEM_CHANGED() macro in reiserfs_fs.h */ 1393 see FILESYSTEM_CHANGED() macro in reiserfs_fs.h */
1443#ifdef DISPLACE_NEW_PACKING_LOCALITIES 1394#ifdef DISPLACE_NEW_PACKING_LOCALITIES
1444 struct in_core_key key; /* key pointer, to pass to block allocator or 1395 struct in_core_key key; /* key pointer, to pass to block allocator or
1445 another low-level subsystem */ 1396 another low-level subsystem */
1446#endif 1397#endif
1447} ; 1398};
1448 1399
1449/* These are modes of balancing */ 1400/* These are modes of balancing */
1450 1401
@@ -1479,13 +1430,12 @@ struct tree_balance
1479/* used in do_balance for passing parent of node information that has 1430/* used in do_balance for passing parent of node information that has
1480 been gotten from tb struct */ 1431 been gotten from tb struct */
1481struct buffer_info { 1432struct buffer_info {
1482 struct tree_balance * tb; 1433 struct tree_balance *tb;
1483 struct buffer_head * bi_bh; 1434 struct buffer_head *bi_bh;
1484 struct buffer_head * bi_parent; 1435 struct buffer_head *bi_parent;
1485 int bi_position; 1436 int bi_position;
1486}; 1437};
1487 1438
1488
1489/* there are 4 types of items: stat data, directory item, indirect, direct. 1439/* there are 4 types of items: stat data, directory item, indirect, direct.
1490+-------------------+------------+--------------+------------+ 1440+-------------------+------------+--------------+------------+
1491| | k_offset | k_uniqueness | mergeable? | 1441| | k_offset | k_uniqueness | mergeable? |
@@ -1503,24 +1453,24 @@ struct buffer_info {
1503*/ 1453*/
1504 1454
1505struct item_operations { 1455struct item_operations {
1506 int (*bytes_number) (struct item_head * ih, int block_size); 1456 int (*bytes_number) (struct item_head * ih, int block_size);
1507 void (*decrement_key) (struct cpu_key *); 1457 void (*decrement_key) (struct cpu_key *);
1508 int (*is_left_mergeable) (struct reiserfs_key * ih, unsigned long bsize); 1458 int (*is_left_mergeable) (struct reiserfs_key * ih,
1509 void (*print_item) (struct item_head *, char * item); 1459 unsigned long bsize);
1510 void (*check_item) (struct item_head *, char * item); 1460 void (*print_item) (struct item_head *, char *item);
1511 1461 void (*check_item) (struct item_head *, char *item);
1512 int (*create_vi) (struct virtual_node * vn, struct virtual_item * vi, 1462
1513 int is_affected, int insert_size); 1463 int (*create_vi) (struct virtual_node * vn, struct virtual_item * vi,
1514 int (*check_left) (struct virtual_item * vi, int free, 1464 int is_affected, int insert_size);
1515 int start_skip, int end_skip); 1465 int (*check_left) (struct virtual_item * vi, int free,
1516 int (*check_right) (struct virtual_item * vi, int free); 1466 int start_skip, int end_skip);
1517 int (*part_size) (struct virtual_item * vi, int from, int to); 1467 int (*check_right) (struct virtual_item * vi, int free);
1518 int (*unit_num) (struct virtual_item * vi); 1468 int (*part_size) (struct virtual_item * vi, int from, int to);
1519 void (*print_vi) (struct virtual_item * vi); 1469 int (*unit_num) (struct virtual_item * vi);
1470 void (*print_vi) (struct virtual_item * vi);
1520}; 1471};
1521 1472
1522 1473extern struct item_operations *item_ops[TYPE_ANY + 1];
1523extern struct item_operations * item_ops [TYPE_ANY + 1];
1524 1474
1525#define op_bytes_number(ih,bsize) item_ops[le_ih_k_type (ih)]->bytes_number (ih, bsize) 1475#define op_bytes_number(ih,bsize) item_ops[le_ih_k_type (ih)]->bytes_number (ih, bsize)
1526#define op_is_left_mergeable(key,bsize) item_ops[le_key_k_type (le_key_version (key), key)]->is_left_mergeable (key, bsize) 1476#define op_is_left_mergeable(key,bsize) item_ops[le_key_k_type (le_key_version (key), key)]->is_left_mergeable (key, bsize)
@@ -1533,8 +1483,6 @@ extern struct item_operations * item_ops [TYPE_ANY + 1];
1533#define op_unit_num(vi) item_ops[(vi)->vi_index]->unit_num (vi) 1483#define op_unit_num(vi) item_ops[(vi)->vi_index]->unit_num (vi)
1534#define op_print_vi(vi) item_ops[(vi)->vi_index]->print_vi (vi) 1484#define op_print_vi(vi) item_ops[(vi)->vi_index]->print_vi (vi)
1535 1485
1536
1537
1538#define COMP_SHORT_KEYS comp_short_keys 1486#define COMP_SHORT_KEYS comp_short_keys
1539 1487
1540/* number of blocks pointed to by the indirect item */ 1488/* number of blocks pointed to by the indirect item */
@@ -1545,8 +1493,7 @@ extern struct item_operations * item_ops [TYPE_ANY + 1];
1545 1493
1546/* number of bytes contained by the direct item or the unformatted nodes the indirect item points to */ 1494/* number of bytes contained by the direct item or the unformatted nodes the indirect item points to */
1547 1495
1548 1496/* get the item header */
1549/* get the item header */
1550#define B_N_PITEM_HEAD(bh,item_num) ( (struct item_head * )((bh)->b_data + BLKH_SIZE) + (item_num) ) 1497#define B_N_PITEM_HEAD(bh,item_num) ( (struct item_head * )((bh)->b_data + BLKH_SIZE) + (item_num) )
1551 1498
1552/* get key */ 1499/* get key */
@@ -1577,9 +1524,9 @@ extern struct item_operations * item_ops [TYPE_ANY + 1];
1577#define PUT_B_I_POS_UNFM_POINTER(bh,ih,pos, val) do {*(((unp_t *)B_I_PITEM(bh,ih)) + (pos)) = cpu_to_le32(val); } while (0) 1524#define PUT_B_I_POS_UNFM_POINTER(bh,ih,pos, val) do {*(((unp_t *)B_I_PITEM(bh,ih)) + (pos)) = cpu_to_le32(val); } while (0)
1578 1525
1579struct reiserfs_iget_args { 1526struct reiserfs_iget_args {
1580 __u32 objectid ; 1527 __u32 objectid;
1581 __u32 dirid ; 1528 __u32 dirid;
1582} ; 1529};
1583 1530
1584/***************************************************************************/ 1531/***************************************************************************/
1585/* FUNCTION DECLARATIONS */ 1532/* FUNCTION DECLARATIONS */
@@ -1595,11 +1542,11 @@ struct reiserfs_iget_args {
1595 1542
1596/* first block written in a commit. */ 1543/* first block written in a commit. */
1597struct reiserfs_journal_desc { 1544struct reiserfs_journal_desc {
1598 __le32 j_trans_id ; /* id of commit */ 1545 __le32 j_trans_id; /* id of commit */
1599 __le32 j_len ; /* length of commit. len +1 is the commit block */ 1546 __le32 j_len; /* length of commit. len +1 is the commit block */
1600 __le32 j_mount_id ; /* mount id of this trans*/ 1547 __le32 j_mount_id; /* mount id of this trans */
1601 __le32 j_realblock[1] ; /* real locations for each block */ 1548 __le32 j_realblock[1]; /* real locations for each block */
1602} ; 1549};
1603 1550
1604#define get_desc_trans_id(d) le32_to_cpu((d)->j_trans_id) 1551#define get_desc_trans_id(d) le32_to_cpu((d)->j_trans_id)
1605#define get_desc_trans_len(d) le32_to_cpu((d)->j_len) 1552#define get_desc_trans_len(d) le32_to_cpu((d)->j_len)
@@ -1611,10 +1558,10 @@ struct reiserfs_journal_desc {
1611 1558
1612/* last block written in a commit */ 1559/* last block written in a commit */
1613struct reiserfs_journal_commit { 1560struct reiserfs_journal_commit {
1614 __le32 j_trans_id ; /* must match j_trans_id from the desc block */ 1561 __le32 j_trans_id; /* must match j_trans_id from the desc block */
1615 __le32 j_len ; /* ditto */ 1562 __le32 j_len; /* ditto */
1616 __le32 j_realblock[1] ; /* real locations for each block */ 1563 __le32 j_realblock[1]; /* real locations for each block */
1617} ; 1564};
1618 1565
1619#define get_commit_trans_id(c) le32_to_cpu((c)->j_trans_id) 1566#define get_commit_trans_id(c) le32_to_cpu((c)->j_trans_id)
1620#define get_commit_trans_len(c) le32_to_cpu((c)->j_len) 1567#define get_commit_trans_len(c) le32_to_cpu((c)->j_len)
@@ -1628,19 +1575,19 @@ struct reiserfs_journal_commit {
1628** and this transaction does not need to be replayed. 1575** and this transaction does not need to be replayed.
1629*/ 1576*/
1630struct reiserfs_journal_header { 1577struct reiserfs_journal_header {
1631 __le32 j_last_flush_trans_id ; /* id of last fully flushed transaction */ 1578 __le32 j_last_flush_trans_id; /* id of last fully flushed transaction */
1632 __le32 j_first_unflushed_offset ; /* offset in the log of where to start replay after a crash */ 1579 __le32 j_first_unflushed_offset; /* offset in the log of where to start replay after a crash */
1633 __le32 j_mount_id ; 1580 __le32 j_mount_id;
1634 /* 12 */ struct journal_params jh_journal; 1581 /* 12 */ struct journal_params jh_journal;
1635} ; 1582};
1636 1583
1637/* biggest tunable defines are right here */ 1584/* biggest tunable defines are right here */
1638#define JOURNAL_BLOCK_COUNT 8192 /* number of blocks in the journal */ 1585#define JOURNAL_BLOCK_COUNT 8192 /* number of blocks in the journal */
1639#define JOURNAL_TRANS_MAX_DEFAULT 1024 /* biggest possible single transaction, don't change for now (8/3/99) */ 1586#define JOURNAL_TRANS_MAX_DEFAULT 1024 /* biggest possible single transaction, don't change for now (8/3/99) */
1640#define JOURNAL_TRANS_MIN_DEFAULT 256 1587#define JOURNAL_TRANS_MIN_DEFAULT 256
1641#define JOURNAL_MAX_BATCH_DEFAULT 900 /* max blocks to batch into one transaction, don't make this any bigger than 900 */ 1588#define JOURNAL_MAX_BATCH_DEFAULT 900 /* max blocks to batch into one transaction, don't make this any bigger than 900 */
1642#define JOURNAL_MIN_RATIO 2 1589#define JOURNAL_MIN_RATIO 2
1643#define JOURNAL_MAX_COMMIT_AGE 30 1590#define JOURNAL_MAX_COMMIT_AGE 30
1644#define JOURNAL_MAX_TRANS_AGE 30 1591#define JOURNAL_MAX_TRANS_AGE 30
1645#define JOURNAL_PER_BALANCE_CNT (3 * (MAX_HEIGHT-2) + 9) 1592#define JOURNAL_PER_BALANCE_CNT (3 * (MAX_HEIGHT-2) + 9)
1646#ifdef CONFIG_QUOTA 1593#ifdef CONFIG_QUOTA
@@ -1664,10 +1611,10 @@ struct reiserfs_journal_header {
1664** the current number of nodes is > max, the node is freed, otherwise, 1611** the current number of nodes is > max, the node is freed, otherwise,
1665** it is put on a free list for faster use later. 1612** it is put on a free list for faster use later.
1666*/ 1613*/
1667#define REISERFS_MIN_BITMAP_NODES 10 1614#define REISERFS_MIN_BITMAP_NODES 10
1668#define REISERFS_MAX_BITMAP_NODES 100 1615#define REISERFS_MAX_BITMAP_NODES 100
1669 1616
1670#define JBH_HASH_SHIFT 13 /* these are based on journal hash size of 8192 */ 1617#define JBH_HASH_SHIFT 13 /* these are based on journal hash size of 8192 */
1671#define JBH_HASH_MASK 8191 1618#define JBH_HASH_MASK 8191
1672 1619
1673#define _jhashfn(sb,block) \ 1620#define _jhashfn(sb,block) \
@@ -1681,14 +1628,14 @@ struct reiserfs_journal_header {
1681#define journal_bread(s, block) __bread(SB_JOURNAL(s)->j_dev_bd, block, s->s_blocksize) 1628#define journal_bread(s, block) __bread(SB_JOURNAL(s)->j_dev_bd, block, s->s_blocksize)
1682 1629
1683enum reiserfs_bh_state_bits { 1630enum reiserfs_bh_state_bits {
1684 BH_JDirty = BH_PrivateStart, /* buffer is in current transaction */ 1631 BH_JDirty = BH_PrivateStart, /* buffer is in current transaction */
1685 BH_JDirty_wait, 1632 BH_JDirty_wait,
1686 BH_JNew, /* disk block was taken off free list before 1633 BH_JNew, /* disk block was taken off free list before
1687 * being in a finished transaction, or 1634 * being in a finished transaction, or
1688 * written to disk. Can be reused immed. */ 1635 * written to disk. Can be reused immed. */
1689 BH_JPrepared, 1636 BH_JPrepared,
1690 BH_JRestore_dirty, 1637 BH_JRestore_dirty,
1691 BH_JTest, // debugging only will go away 1638 BH_JTest, // debugging only will go away
1692}; 1639};
1693 1640
1694BUFFER_FNS(JDirty, journaled); 1641BUFFER_FNS(JDirty, journaled);
@@ -1708,175 +1655,192 @@ TAS_BUFFER_FNS(JTest, journal_test);
1708** transaction handle which is passed around for all journal calls 1655** transaction handle which is passed around for all journal calls
1709*/ 1656*/
1710struct reiserfs_transaction_handle { 1657struct reiserfs_transaction_handle {
1711 struct super_block *t_super ; /* super for this FS when journal_begin was 1658 struct super_block *t_super; /* super for this FS when journal_begin was
1712 called. saves calls to reiserfs_get_super 1659 called. saves calls to reiserfs_get_super
1713 also used by nested transactions to make 1660 also used by nested transactions to make
1714 sure they are nesting on the right FS 1661 sure they are nesting on the right FS
1715 _must_ be first in the handle 1662 _must_ be first in the handle
1716 */ 1663 */
1717 int t_refcount; 1664 int t_refcount;
1718 int t_blocks_logged ; /* number of blocks this writer has logged */ 1665 int t_blocks_logged; /* number of blocks this writer has logged */
1719 int t_blocks_allocated ; /* number of blocks this writer allocated */ 1666 int t_blocks_allocated; /* number of blocks this writer allocated */
1720 unsigned long t_trans_id ; /* sanity check, equals the current trans id */ 1667 unsigned long t_trans_id; /* sanity check, equals the current trans id */
1721 void *t_handle_save ; /* save existing current->journal_info */ 1668 void *t_handle_save; /* save existing current->journal_info */
1722 unsigned displace_new_blocks:1; /* if new block allocation occurres, that block 1669 unsigned displace_new_blocks:1; /* if new block allocation occurres, that block
1723 should be displaced from others */ 1670 should be displaced from others */
1724 struct list_head t_list; 1671 struct list_head t_list;
1725} ; 1672};
1726 1673
1727/* used to keep track of ordered and tail writes, attached to the buffer 1674/* used to keep track of ordered and tail writes, attached to the buffer
1728 * head through b_journal_head. 1675 * head through b_journal_head.
1729 */ 1676 */
1730struct reiserfs_jh { 1677struct reiserfs_jh {
1731 struct reiserfs_journal_list *jl; 1678 struct reiserfs_journal_list *jl;
1732 struct buffer_head *bh; 1679 struct buffer_head *bh;
1733 struct list_head list; 1680 struct list_head list;
1734}; 1681};
1735 1682
1736void reiserfs_free_jh(struct buffer_head *bh); 1683void reiserfs_free_jh(struct buffer_head *bh);
1737int reiserfs_add_tail_list(struct inode *inode, struct buffer_head *bh); 1684int reiserfs_add_tail_list(struct inode *inode, struct buffer_head *bh);
1738int reiserfs_add_ordered_list(struct inode *inode, struct buffer_head *bh); 1685int reiserfs_add_ordered_list(struct inode *inode, struct buffer_head *bh);
1739int journal_mark_dirty(struct reiserfs_transaction_handle *, struct super_block *, struct buffer_head *bh) ; 1686int journal_mark_dirty(struct reiserfs_transaction_handle *,
1740 1687 struct super_block *, struct buffer_head *bh);
1741static inline int 1688
1742reiserfs_file_data_log(struct inode *inode) { 1689static inline int reiserfs_file_data_log(struct inode *inode)
1743 if (reiserfs_data_log(inode->i_sb) || 1690{
1744 (REISERFS_I(inode)->i_flags & i_data_log)) 1691 if (reiserfs_data_log(inode->i_sb) ||
1745 return 1 ; 1692 (REISERFS_I(inode)->i_flags & i_data_log))
1746 return 0 ; 1693 return 1;
1694 return 0;
1747} 1695}
1748 1696
1749static inline int reiserfs_transaction_running(struct super_block *s) { 1697static inline int reiserfs_transaction_running(struct super_block *s)
1750 struct reiserfs_transaction_handle *th = current->journal_info ; 1698{
1751 if (th && th->t_super == s) 1699 struct reiserfs_transaction_handle *th = current->journal_info;
1752 return 1 ; 1700 if (th && th->t_super == s)
1753 if (th && th->t_super == NULL) 1701 return 1;
1754 BUG(); 1702 if (th && th->t_super == NULL)
1755 return 0 ; 1703 BUG();
1704 return 0;
1756} 1705}
1757 1706
1758int reiserfs_async_progress_wait(struct super_block *s); 1707int reiserfs_async_progress_wait(struct super_block *s);
1759 1708
1760struct reiserfs_transaction_handle * 1709struct reiserfs_transaction_handle *reiserfs_persistent_transaction(struct
1761reiserfs_persistent_transaction(struct super_block *, int count); 1710 super_block
1711 *,
1712 int count);
1762int reiserfs_end_persistent_transaction(struct reiserfs_transaction_handle *); 1713int reiserfs_end_persistent_transaction(struct reiserfs_transaction_handle *);
1763int reiserfs_commit_page(struct inode *inode, struct page *page, 1714int reiserfs_commit_page(struct inode *inode, struct page *page,
1764 unsigned from, unsigned to); 1715 unsigned from, unsigned to);
1765int reiserfs_flush_old_commits(struct super_block *); 1716int reiserfs_flush_old_commits(struct super_block *);
1766int reiserfs_commit_for_inode(struct inode *) ; 1717int reiserfs_commit_for_inode(struct inode *);
1767int reiserfs_inode_needs_commit(struct inode *) ; 1718int reiserfs_inode_needs_commit(struct inode *);
1768void reiserfs_update_inode_transaction(struct inode *) ; 1719void reiserfs_update_inode_transaction(struct inode *);
1769void reiserfs_wait_on_write_block(struct super_block *s) ; 1720void reiserfs_wait_on_write_block(struct super_block *s);
1770void reiserfs_block_writes(struct reiserfs_transaction_handle *th) ; 1721void reiserfs_block_writes(struct reiserfs_transaction_handle *th);
1771void reiserfs_allow_writes(struct super_block *s) ; 1722void reiserfs_allow_writes(struct super_block *s);
1772void reiserfs_check_lock_depth(struct super_block *s, char *caller) ; 1723void reiserfs_check_lock_depth(struct super_block *s, char *caller);
1773int reiserfs_prepare_for_journal(struct super_block *, struct buffer_head *bh, int wait) ; 1724int reiserfs_prepare_for_journal(struct super_block *, struct buffer_head *bh,
1774void reiserfs_restore_prepared_buffer(struct super_block *, struct buffer_head *bh) ; 1725 int wait);
1775int journal_init(struct super_block *, const char * j_dev_name, int old_format, unsigned int) ; 1726void reiserfs_restore_prepared_buffer(struct super_block *,
1776int journal_release(struct reiserfs_transaction_handle*, struct super_block *) ; 1727 struct buffer_head *bh);
1777int journal_release_error(struct reiserfs_transaction_handle*, struct super_block *) ; 1728int journal_init(struct super_block *, const char *j_dev_name, int old_format,
1778int journal_end(struct reiserfs_transaction_handle *, struct super_block *, unsigned long) ; 1729 unsigned int);
1779int journal_end_sync(struct reiserfs_transaction_handle *, struct super_block *, unsigned long) ; 1730int journal_release(struct reiserfs_transaction_handle *, struct super_block *);
1780int journal_mark_freed(struct reiserfs_transaction_handle *, struct super_block *, b_blocknr_t blocknr) ; 1731int journal_release_error(struct reiserfs_transaction_handle *,
1781int journal_transaction_should_end(struct reiserfs_transaction_handle *, int) ; 1732 struct super_block *);
1782int reiserfs_in_journal(struct super_block *p_s_sb, int bmap_nr, int bit_nr, int searchall, b_blocknr_t *next) ; 1733int journal_end(struct reiserfs_transaction_handle *, struct super_block *,
1783int journal_begin(struct reiserfs_transaction_handle *, struct super_block *p_s_sb, unsigned long) ; 1734 unsigned long);
1784int journal_join_abort(struct reiserfs_transaction_handle *, struct super_block *p_s_sb, unsigned long) ; 1735int journal_end_sync(struct reiserfs_transaction_handle *, struct super_block *,
1785void reiserfs_journal_abort (struct super_block *sb, int errno); 1736 unsigned long);
1786void reiserfs_abort (struct super_block *sb, int errno, const char *fmt, ...); 1737int journal_mark_freed(struct reiserfs_transaction_handle *,
1787int reiserfs_allocate_list_bitmaps(struct super_block *s, struct reiserfs_list_bitmap *, int) ; 1738 struct super_block *, b_blocknr_t blocknr);
1788 1739int journal_transaction_should_end(struct reiserfs_transaction_handle *, int);
1789void add_save_link (struct reiserfs_transaction_handle * th, 1740int reiserfs_in_journal(struct super_block *p_s_sb, int bmap_nr, int bit_nr,
1790 struct inode * inode, int truncate); 1741 int searchall, b_blocknr_t * next);
1791int remove_save_link (struct inode * inode, int truncate); 1742int journal_begin(struct reiserfs_transaction_handle *,
1743 struct super_block *p_s_sb, unsigned long);
1744int journal_join_abort(struct reiserfs_transaction_handle *,
1745 struct super_block *p_s_sb, unsigned long);
1746void reiserfs_journal_abort(struct super_block *sb, int errno);
1747void reiserfs_abort(struct super_block *sb, int errno, const char *fmt, ...);
1748int reiserfs_allocate_list_bitmaps(struct super_block *s,
1749 struct reiserfs_list_bitmap *, int);
1750
1751void add_save_link(struct reiserfs_transaction_handle *th,
1752 struct inode *inode, int truncate);
1753int remove_save_link(struct inode *inode, int truncate);
1792 1754
1793/* objectid.c */ 1755/* objectid.c */
1794__u32 reiserfs_get_unused_objectid (struct reiserfs_transaction_handle *th); 1756__u32 reiserfs_get_unused_objectid(struct reiserfs_transaction_handle *th);
1795void reiserfs_release_objectid (struct reiserfs_transaction_handle *th, __u32 objectid_to_release); 1757void reiserfs_release_objectid(struct reiserfs_transaction_handle *th,
1796int reiserfs_convert_objectid_map_v1(struct super_block *) ; 1758 __u32 objectid_to_release);
1759int reiserfs_convert_objectid_map_v1(struct super_block *);
1797 1760
1798/* stree.c */ 1761/* stree.c */
1799int B_IS_IN_TREE(const struct buffer_head *); 1762int B_IS_IN_TREE(const struct buffer_head *);
1800extern void copy_item_head(struct item_head * p_v_to, 1763extern void copy_item_head(struct item_head *p_v_to,
1801 const struct item_head * p_v_from); 1764 const struct item_head *p_v_from);
1802 1765
1803// first key is in cpu form, second - le 1766// first key is in cpu form, second - le
1804extern int comp_short_keys (const struct reiserfs_key * le_key, 1767extern int comp_short_keys(const struct reiserfs_key *le_key,
1805 const struct cpu_key * cpu_key); 1768 const struct cpu_key *cpu_key);
1806extern void le_key2cpu_key (struct cpu_key * to, const struct reiserfs_key * from); 1769extern void le_key2cpu_key(struct cpu_key *to, const struct reiserfs_key *from);
1807 1770
1808// both are in le form 1771// both are in le form
1809extern int comp_le_keys (const struct reiserfs_key *, const struct reiserfs_key *); 1772extern int comp_le_keys(const struct reiserfs_key *,
1810extern int comp_short_le_keys (const struct reiserfs_key *, const struct reiserfs_key *); 1773 const struct reiserfs_key *);
1774extern int comp_short_le_keys(const struct reiserfs_key *,
1775 const struct reiserfs_key *);
1811 1776
1812// 1777//
1813// get key version from on disk key - kludge 1778// get key version from on disk key - kludge
1814// 1779//
1815static inline int le_key_version (const struct reiserfs_key * key) 1780static inline int le_key_version(const struct reiserfs_key *key)
1816{ 1781{
1817 int type; 1782 int type;
1818
1819 type = offset_v2_k_type( &(key->u.k_offset_v2));
1820 if (type != TYPE_DIRECT && type != TYPE_INDIRECT && type != TYPE_DIRENTRY)
1821 return KEY_FORMAT_3_5;
1822
1823 return KEY_FORMAT_3_6;
1824
1825}
1826 1783
1784 type = offset_v2_k_type(&(key->u.k_offset_v2));
1785 if (type != TYPE_DIRECT && type != TYPE_INDIRECT
1786 && type != TYPE_DIRENTRY)
1787 return KEY_FORMAT_3_5;
1788
1789 return KEY_FORMAT_3_6;
1827 1790
1828static inline void copy_key (struct reiserfs_key *to, const struct reiserfs_key *from)
1829{
1830 memcpy (to, from, KEY_SIZE);
1831} 1791}
1832 1792
1793static inline void copy_key(struct reiserfs_key *to,
1794 const struct reiserfs_key *from)
1795{
1796 memcpy(to, from, KEY_SIZE);
1797}
1833 1798
1834int comp_items (const struct item_head * stored_ih, const struct path * p_s_path); 1799int comp_items(const struct item_head *stored_ih, const struct path *p_s_path);
1835const struct reiserfs_key * get_rkey (const struct path * p_s_chk_path, 1800const struct reiserfs_key *get_rkey(const struct path *p_s_chk_path,
1836 const struct super_block * p_s_sb); 1801 const struct super_block *p_s_sb);
1837int search_by_key (struct super_block *, const struct cpu_key *, 1802int search_by_key(struct super_block *, const struct cpu_key *,
1838 struct path *, int); 1803 struct path *, int);
1839#define search_item(s,key,path) search_by_key (s, key, path, DISK_LEAF_NODE_LEVEL) 1804#define search_item(s,key,path) search_by_key (s, key, path, DISK_LEAF_NODE_LEVEL)
1840int search_for_position_by_key (struct super_block * p_s_sb, 1805int search_for_position_by_key(struct super_block *p_s_sb,
1841 const struct cpu_key * p_s_cpu_key, 1806 const struct cpu_key *p_s_cpu_key,
1842 struct path * p_s_search_path); 1807 struct path *p_s_search_path);
1843extern void decrement_bcount (struct buffer_head * p_s_bh); 1808extern void decrement_bcount(struct buffer_head *p_s_bh);
1844void decrement_counters_in_path (struct path * p_s_search_path); 1809void decrement_counters_in_path(struct path *p_s_search_path);
1845void pathrelse (struct path * p_s_search_path); 1810void pathrelse(struct path *p_s_search_path);
1846int reiserfs_check_path(struct path *p) ; 1811int reiserfs_check_path(struct path *p);
1847void pathrelse_and_restore (struct super_block *s, struct path * p_s_search_path); 1812void pathrelse_and_restore(struct super_block *s, struct path *p_s_search_path);
1848 1813
1849int reiserfs_insert_item (struct reiserfs_transaction_handle *th, 1814int reiserfs_insert_item(struct reiserfs_transaction_handle *th,
1850 struct path * path, 1815 struct path *path,
1851 const struct cpu_key * key, 1816 const struct cpu_key *key,
1852 struct item_head * ih, 1817 struct item_head *ih,
1853 struct inode *inode, const char * body); 1818 struct inode *inode, const char *body);
1854 1819
1855int reiserfs_paste_into_item (struct reiserfs_transaction_handle *th, 1820int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th,
1856 struct path * path, 1821 struct path *path,
1857 const struct cpu_key * key, 1822 const struct cpu_key *key,
1858 struct inode *inode, 1823 struct inode *inode,
1859 const char * body, int paste_size); 1824 const char *body, int paste_size);
1860 1825
1861int reiserfs_cut_from_item (struct reiserfs_transaction_handle *th, 1826int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
1862 struct path * path, 1827 struct path *path,
1863 struct cpu_key * key, 1828 struct cpu_key *key,
1864 struct inode * inode, 1829 struct inode *inode,
1865 struct page *page, 1830 struct page *page, loff_t new_file_size);
1866 loff_t new_file_size); 1831
1867 1832int reiserfs_delete_item(struct reiserfs_transaction_handle *th,
1868int reiserfs_delete_item (struct reiserfs_transaction_handle *th, 1833 struct path *path,
1869 struct path * path, 1834 const struct cpu_key *key,
1870 const struct cpu_key * key, 1835 struct inode *inode, struct buffer_head *p_s_un_bh);
1871 struct inode * inode, 1836
1872 struct buffer_head * p_s_un_bh); 1837void reiserfs_delete_solid_item(struct reiserfs_transaction_handle *th,
1873 1838 struct inode *inode, struct reiserfs_key *key);
1874void reiserfs_delete_solid_item (struct reiserfs_transaction_handle *th, 1839int reiserfs_delete_object(struct reiserfs_transaction_handle *th,
1875 struct inode *inode, struct reiserfs_key * key); 1840 struct inode *p_s_inode);
1876int reiserfs_delete_object (struct reiserfs_transaction_handle *th, struct inode * p_s_inode); 1841int reiserfs_do_truncate(struct reiserfs_transaction_handle *th,
1877int reiserfs_do_truncate (struct reiserfs_transaction_handle *th, 1842 struct inode *p_s_inode, struct page *,
1878 struct inode * p_s_inode, struct page *, 1843 int update_timestamps);
1879 int update_timestamps);
1880 1844
1881#define i_block_size(inode) ((inode)->i_sb->s_blocksize) 1845#define i_block_size(inode) ((inode)->i_sb->s_blocksize)
1882#define file_size(inode) ((inode)->i_size) 1846#define file_size(inode) ((inode)->i_size)
@@ -1885,66 +1849,67 @@ int reiserfs_do_truncate (struct reiserfs_transaction_handle *th,
1885#define tail_has_to_be_packed(inode) (have_large_tails ((inode)->i_sb)?\ 1849#define tail_has_to_be_packed(inode) (have_large_tails ((inode)->i_sb)?\
1886!STORE_TAIL_IN_UNFM_S1(file_size (inode), tail_size(inode), inode->i_sb->s_blocksize):have_small_tails ((inode)->i_sb)?!STORE_TAIL_IN_UNFM_S2(file_size (inode), tail_size(inode), inode->i_sb->s_blocksize):0 ) 1850!STORE_TAIL_IN_UNFM_S1(file_size (inode), tail_size(inode), inode->i_sb->s_blocksize):have_small_tails ((inode)->i_sb)?!STORE_TAIL_IN_UNFM_S2(file_size (inode), tail_size(inode), inode->i_sb->s_blocksize):0 )
1887 1851
1888void padd_item (char * item, int total_length, int length); 1852void padd_item(char *item, int total_length, int length);
1889 1853
1890/* inode.c */ 1854/* inode.c */
1891/* args for the create parameter of reiserfs_get_block */ 1855/* args for the create parameter of reiserfs_get_block */
1892#define GET_BLOCK_NO_CREATE 0 /* don't create new blocks or convert tails */ 1856#define GET_BLOCK_NO_CREATE 0 /* don't create new blocks or convert tails */
1893#define GET_BLOCK_CREATE 1 /* add anything you need to find block */ 1857#define GET_BLOCK_CREATE 1 /* add anything you need to find block */
1894#define GET_BLOCK_NO_HOLE 2 /* return -ENOENT for file holes */ 1858#define GET_BLOCK_NO_HOLE 2 /* return -ENOENT for file holes */
1895#define GET_BLOCK_READ_DIRECT 4 /* read the tail if indirect item not found */ 1859#define GET_BLOCK_READ_DIRECT 4 /* read the tail if indirect item not found */
1896#define GET_BLOCK_NO_ISEM 8 /* i_sem is not held, don't preallocate */ 1860#define GET_BLOCK_NO_ISEM 8 /* i_sem is not held, don't preallocate */
1897#define GET_BLOCK_NO_DANGLE 16 /* don't leave any transactions running */ 1861#define GET_BLOCK_NO_DANGLE 16 /* don't leave any transactions running */
1898 1862
1899int restart_transaction(struct reiserfs_transaction_handle *th, struct inode *inode, struct path *path); 1863int restart_transaction(struct reiserfs_transaction_handle *th,
1900void reiserfs_read_locked_inode(struct inode * inode, struct reiserfs_iget_args *args) ; 1864 struct inode *inode, struct path *path);
1901int reiserfs_find_actor(struct inode * inode, void *p) ; 1865void reiserfs_read_locked_inode(struct inode *inode,
1902int reiserfs_init_locked_inode(struct inode * inode, void *p) ; 1866 struct reiserfs_iget_args *args);
1903void reiserfs_delete_inode (struct inode * inode); 1867int reiserfs_find_actor(struct inode *inode, void *p);
1904int reiserfs_write_inode (struct inode * inode, int) ; 1868int reiserfs_init_locked_inode(struct inode *inode, void *p);
1905int reiserfs_get_block (struct inode * inode, sector_t block, struct buffer_head * bh_result, int create); 1869void reiserfs_delete_inode(struct inode *inode);
1906struct dentry *reiserfs_get_dentry(struct super_block *, void *) ; 1870int reiserfs_write_inode(struct inode *inode, int);
1907struct dentry *reiserfs_decode_fh(struct super_block *sb, __u32 *data, 1871int reiserfs_get_block(struct inode *inode, sector_t block,
1908 int len, int fhtype, 1872 struct buffer_head *bh_result, int create);
1909 int (*acceptable)(void *contect, struct dentry *de), 1873struct dentry *reiserfs_get_dentry(struct super_block *, void *);
1910 void *context) ; 1874struct dentry *reiserfs_decode_fh(struct super_block *sb, __u32 * data,
1911int reiserfs_encode_fh( struct dentry *dentry, __u32 *data, int *lenp, 1875 int len, int fhtype,
1912 int connectable ); 1876 int (*acceptable) (void *contect,
1913 1877 struct dentry * de),
1914int reiserfs_truncate_file(struct inode *, int update_timestamps) ; 1878 void *context);
1915void make_cpu_key (struct cpu_key * cpu_key, struct inode * inode, loff_t offset, 1879int reiserfs_encode_fh(struct dentry *dentry, __u32 * data, int *lenp,
1916 int type, int key_length); 1880 int connectable);
1917void make_le_item_head (struct item_head * ih, const struct cpu_key * key, 1881
1918 int version, 1882int reiserfs_truncate_file(struct inode *, int update_timestamps);
1919 loff_t offset, int type, int length, int entry_count); 1883void make_cpu_key(struct cpu_key *cpu_key, struct inode *inode, loff_t offset,
1920struct inode * reiserfs_iget (struct super_block * s, 1884 int type, int key_length);
1921 const struct cpu_key * key); 1885void make_le_item_head(struct item_head *ih, const struct cpu_key *key,
1922 1886 int version,
1923 1887 loff_t offset, int type, int length, int entry_count);
1924int reiserfs_new_inode (struct reiserfs_transaction_handle *th, 1888struct inode *reiserfs_iget(struct super_block *s, const struct cpu_key *key);
1925 struct inode * dir, int mode, 1889
1926 const char * symname, loff_t i_size, 1890int reiserfs_new_inode(struct reiserfs_transaction_handle *th,
1927 struct dentry *dentry, struct inode *inode); 1891 struct inode *dir, int mode,
1928 1892 const char *symname, loff_t i_size,
1929void reiserfs_update_sd_size (struct reiserfs_transaction_handle *th, 1893 struct dentry *dentry, struct inode *inode);
1930 struct inode * inode, loff_t size); 1894
1895void reiserfs_update_sd_size(struct reiserfs_transaction_handle *th,
1896 struct inode *inode, loff_t size);
1931 1897
1932static inline void reiserfs_update_sd(struct reiserfs_transaction_handle *th, 1898static inline void reiserfs_update_sd(struct reiserfs_transaction_handle *th,
1933 struct inode *inode) 1899 struct inode *inode)
1934{ 1900{
1935 reiserfs_update_sd_size(th, inode, inode->i_size) ; 1901 reiserfs_update_sd_size(th, inode, inode->i_size);
1936} 1902}
1937 1903
1938void sd_attrs_to_i_attrs( __u16 sd_attrs, struct inode *inode ); 1904void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
1939void i_attrs_to_sd_attrs( struct inode *inode, __u16 *sd_attrs ); 1905void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
1940int reiserfs_setattr(struct dentry *dentry, struct iattr *attr); 1906int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
1941 1907
1942/* namei.c */ 1908/* namei.c */
1943void set_de_name_and_namelen (struct reiserfs_dir_entry * de); 1909void set_de_name_and_namelen(struct reiserfs_dir_entry *de);
1944int search_by_entry_key (struct super_block * sb, const struct cpu_key * key, 1910int search_by_entry_key(struct super_block *sb, const struct cpu_key *key,
1945 struct path * path, 1911 struct path *path, struct reiserfs_dir_entry *de);
1946 struct reiserfs_dir_entry * de); 1912struct dentry *reiserfs_get_parent(struct dentry *);
1947struct dentry *reiserfs_get_parent(struct dentry *) ;
1948/* procfs.c */ 1913/* procfs.c */
1949 1914
1950#if defined( CONFIG_PROC_FS ) && defined( CONFIG_REISERFS_PROC_INFO ) 1915#if defined( CONFIG_PROC_FS ) && defined( CONFIG_REISERFS_PROC_INFO )
@@ -1953,15 +1918,15 @@ struct dentry *reiserfs_get_parent(struct dentry *) ;
1953#undef REISERFS_PROC_INFO 1918#undef REISERFS_PROC_INFO
1954#endif 1919#endif
1955 1920
1956int reiserfs_proc_info_init( struct super_block *sb ); 1921int reiserfs_proc_info_init(struct super_block *sb);
1957int reiserfs_proc_info_done( struct super_block *sb ); 1922int reiserfs_proc_info_done(struct super_block *sb);
1958struct proc_dir_entry *reiserfs_proc_register_global( char *name, 1923struct proc_dir_entry *reiserfs_proc_register_global(char *name,
1959 read_proc_t *func ); 1924 read_proc_t * func);
1960void reiserfs_proc_unregister_global( const char *name ); 1925void reiserfs_proc_unregister_global(const char *name);
1961int reiserfs_proc_info_global_init( void ); 1926int reiserfs_proc_info_global_init(void);
1962int reiserfs_proc_info_global_done( void ); 1927int reiserfs_proc_info_global_done(void);
1963int reiserfs_global_version_in_proc( char *buffer, char **start, off_t offset, 1928int reiserfs_global_version_in_proc(char *buffer, char **start, off_t offset,
1964 int count, int *eof, void *data ); 1929 int count, int *eof, void *data);
1965 1930
1966#if defined( REISERFS_PROC_INFO ) 1931#if defined( REISERFS_PROC_INFO )
1967 1932
@@ -1993,123 +1958,132 @@ extern struct inode_operations reiserfs_special_inode_operations;
1993extern struct file_operations reiserfs_dir_operations; 1958extern struct file_operations reiserfs_dir_operations;
1994 1959
1995/* tail_conversion.c */ 1960/* tail_conversion.c */
1996int direct2indirect (struct reiserfs_transaction_handle *, struct inode *, struct path *, struct buffer_head *, loff_t); 1961int direct2indirect(struct reiserfs_transaction_handle *, struct inode *,
1997int indirect2direct (struct reiserfs_transaction_handle *, struct inode *, struct page *, struct path *, const struct cpu_key *, loff_t, char *); 1962 struct path *, struct buffer_head *, loff_t);
1998void reiserfs_unmap_buffer(struct buffer_head *) ; 1963int indirect2direct(struct reiserfs_transaction_handle *, struct inode *,
1999 1964 struct page *, struct path *, const struct cpu_key *,
1965 loff_t, char *);
1966void reiserfs_unmap_buffer(struct buffer_head *);
2000 1967
2001/* file.c */ 1968/* file.c */
2002extern struct inode_operations reiserfs_file_inode_operations; 1969extern struct inode_operations reiserfs_file_inode_operations;
2003extern struct file_operations reiserfs_file_operations; 1970extern struct file_operations reiserfs_file_operations;
2004extern struct address_space_operations reiserfs_address_space_operations ; 1971extern struct address_space_operations reiserfs_address_space_operations;
2005 1972
2006/* fix_nodes.c */ 1973/* fix_nodes.c */
2007#ifdef CONFIG_REISERFS_CHECK 1974#ifdef CONFIG_REISERFS_CHECK
2008void * reiserfs_kmalloc (size_t size, int flags, struct super_block * s); 1975void *reiserfs_kmalloc(size_t size, int flags, struct super_block *s);
2009void reiserfs_kfree (const void * vp, size_t size, struct super_block * s); 1976void reiserfs_kfree(const void *vp, size_t size, struct super_block *s);
2010#else 1977#else
2011static inline void *reiserfs_kmalloc(size_t size, int flags, 1978static inline void *reiserfs_kmalloc(size_t size, int flags,
2012 struct super_block *s) 1979 struct super_block *s)
2013{ 1980{
2014 return kmalloc(size, flags); 1981 return kmalloc(size, flags);
2015} 1982}
2016 1983
2017static inline void reiserfs_kfree(const void *vp, size_t size, 1984static inline void reiserfs_kfree(const void *vp, size_t size,
2018 struct super_block *s) 1985 struct super_block *s)
2019{ 1986{
2020 kfree(vp); 1987 kfree(vp);
2021} 1988}
2022#endif 1989#endif
2023 1990
2024int fix_nodes (int n_op_mode, struct tree_balance * p_s_tb, 1991int fix_nodes(int n_op_mode, struct tree_balance *p_s_tb,
2025 struct item_head * p_s_ins_ih, const void *); 1992 struct item_head *p_s_ins_ih, const void *);
2026void unfix_nodes (struct tree_balance *); 1993void unfix_nodes(struct tree_balance *);
2027
2028 1994
2029/* prints.c */ 1995/* prints.c */
2030void reiserfs_panic (struct super_block * s, const char * fmt, ...) __attribute__ ( ( noreturn ) ); 1996void reiserfs_panic(struct super_block *s, const char *fmt, ...)
2031void reiserfs_info (struct super_block *s, const char * fmt, ...); 1997 __attribute__ ((noreturn));
2032void reiserfs_debug (struct super_block *s, int level, const char * fmt, ...); 1998void reiserfs_info(struct super_block *s, const char *fmt, ...);
2033void print_indirect_item (struct buffer_head * bh, int item_num); 1999void reiserfs_debug(struct super_block *s, int level, const char *fmt, ...);
2034void store_print_tb (struct tree_balance * tb); 2000void print_indirect_item(struct buffer_head *bh, int item_num);
2035void print_cur_tb (char * mes); 2001void store_print_tb(struct tree_balance *tb);
2036void print_de (struct reiserfs_dir_entry * de); 2002void print_cur_tb(char *mes);
2037void print_bi (struct buffer_info * bi, char * mes); 2003void print_de(struct reiserfs_dir_entry *de);
2038#define PRINT_LEAF_ITEMS 1 /* print all items */ 2004void print_bi(struct buffer_info *bi, char *mes);
2039#define PRINT_DIRECTORY_ITEMS 2 /* print directory items */ 2005#define PRINT_LEAF_ITEMS 1 /* print all items */
2040#define PRINT_DIRECT_ITEMS 4 /* print contents of direct items */ 2006#define PRINT_DIRECTORY_ITEMS 2 /* print directory items */
2041void print_block (struct buffer_head * bh, ...); 2007#define PRINT_DIRECT_ITEMS 4 /* print contents of direct items */
2042void print_bmap (struct super_block * s, int silent); 2008void print_block(struct buffer_head *bh, ...);
2043void print_bmap_block (int i, char * data, int size, int silent); 2009void print_bmap(struct super_block *s, int silent);
2010void print_bmap_block(int i, char *data, int size, int silent);
2044/*void print_super_block (struct super_block * s, char * mes);*/ 2011/*void print_super_block (struct super_block * s, char * mes);*/
2045void print_objectid_map (struct super_block * s); 2012void print_objectid_map(struct super_block *s);
2046void print_block_head (struct buffer_head * bh, char * mes); 2013void print_block_head(struct buffer_head *bh, char *mes);
2047void check_leaf (struct buffer_head * bh); 2014void check_leaf(struct buffer_head *bh);
2048void check_internal (struct buffer_head * bh); 2015void check_internal(struct buffer_head *bh);
2049void print_statistics (struct super_block * s); 2016void print_statistics(struct super_block *s);
2050char * reiserfs_hashname(int code); 2017char *reiserfs_hashname(int code);
2051 2018
2052/* lbalance.c */ 2019/* lbalance.c */
2053int leaf_move_items (int shift_mode, struct tree_balance * tb, int mov_num, int mov_bytes, struct buffer_head * Snew); 2020int leaf_move_items(int shift_mode, struct tree_balance *tb, int mov_num,
2054int leaf_shift_left (struct tree_balance * tb, int shift_num, int shift_bytes); 2021 int mov_bytes, struct buffer_head *Snew);
2055int leaf_shift_right (struct tree_balance * tb, int shift_num, int shift_bytes); 2022int leaf_shift_left(struct tree_balance *tb, int shift_num, int shift_bytes);
2056void leaf_delete_items (struct buffer_info * cur_bi, int last_first, int first, int del_num, int del_bytes); 2023int leaf_shift_right(struct tree_balance *tb, int shift_num, int shift_bytes);
2057void leaf_insert_into_buf (struct buffer_info * bi, int before, 2024void leaf_delete_items(struct buffer_info *cur_bi, int last_first, int first,
2058 struct item_head * inserted_item_ih, const char * inserted_item_body, int zeros_number); 2025 int del_num, int del_bytes);
2059void leaf_paste_in_buffer (struct buffer_info * bi, int pasted_item_num, 2026void leaf_insert_into_buf(struct buffer_info *bi, int before,
2060 int pos_in_item, int paste_size, const char * body, int zeros_number); 2027 struct item_head *inserted_item_ih,
2061void leaf_cut_from_buffer (struct buffer_info * bi, int cut_item_num, int pos_in_item, 2028 const char *inserted_item_body, int zeros_number);
2062 int cut_size); 2029void leaf_paste_in_buffer(struct buffer_info *bi, int pasted_item_num,
2063void leaf_paste_entries (struct buffer_head * bh, int item_num, int before, 2030 int pos_in_item, int paste_size, const char *body,
2064 int new_entry_count, struct reiserfs_de_head * new_dehs, const char * records, int paste_size); 2031 int zeros_number);
2032void leaf_cut_from_buffer(struct buffer_info *bi, int cut_item_num,
2033 int pos_in_item, int cut_size);
2034void leaf_paste_entries(struct buffer_head *bh, int item_num, int before,
2035 int new_entry_count, struct reiserfs_de_head *new_dehs,
2036 const char *records, int paste_size);
2065/* ibalance.c */ 2037/* ibalance.c */
2066int balance_internal (struct tree_balance * , int, int, struct item_head * , 2038int balance_internal(struct tree_balance *, int, int, struct item_head *,
2067 struct buffer_head **); 2039 struct buffer_head **);
2068 2040
2069/* do_balance.c */ 2041/* do_balance.c */
2070void do_balance_mark_leaf_dirty (struct tree_balance * tb, 2042void do_balance_mark_leaf_dirty(struct tree_balance *tb,
2071 struct buffer_head * bh, int flag); 2043 struct buffer_head *bh, int flag);
2072#define do_balance_mark_internal_dirty do_balance_mark_leaf_dirty 2044#define do_balance_mark_internal_dirty do_balance_mark_leaf_dirty
2073#define do_balance_mark_sb_dirty do_balance_mark_leaf_dirty 2045#define do_balance_mark_sb_dirty do_balance_mark_leaf_dirty
2074 2046
2075void do_balance (struct tree_balance * tb, struct item_head * ih, 2047void do_balance(struct tree_balance *tb, struct item_head *ih,
2076 const char * body, int flag); 2048 const char *body, int flag);
2077void reiserfs_invalidate_buffer (struct tree_balance * tb, struct buffer_head * bh); 2049void reiserfs_invalidate_buffer(struct tree_balance *tb,
2050 struct buffer_head *bh);
2078 2051
2079int get_left_neighbor_position (struct tree_balance * tb, int h); 2052int get_left_neighbor_position(struct tree_balance *tb, int h);
2080int get_right_neighbor_position (struct tree_balance * tb, int h); 2053int get_right_neighbor_position(struct tree_balance *tb, int h);
2081void replace_key (struct tree_balance * tb, struct buffer_head *, int, struct buffer_head *, int); 2054void replace_key(struct tree_balance *tb, struct buffer_head *, int,
2082void make_empty_node (struct buffer_info *); 2055 struct buffer_head *, int);
2083struct buffer_head * get_FEB (struct tree_balance *); 2056void make_empty_node(struct buffer_info *);
2057struct buffer_head *get_FEB(struct tree_balance *);
2084 2058
2085/* bitmap.c */ 2059/* bitmap.c */
2086 2060
2087/* structure contains hints for block allocator, and it is a container for 2061/* structure contains hints for block allocator, and it is a container for
2088 * arguments, such as node, search path, transaction_handle, etc. */ 2062 * arguments, such as node, search path, transaction_handle, etc. */
2089 struct __reiserfs_blocknr_hint { 2063struct __reiserfs_blocknr_hint {
2090 struct inode * inode; /* inode passed to allocator, if we allocate unf. nodes */ 2064 struct inode *inode; /* inode passed to allocator, if we allocate unf. nodes */
2091 long block; /* file offset, in blocks */ 2065 long block; /* file offset, in blocks */
2092 struct in_core_key key; 2066 struct in_core_key key;
2093 struct path * path; /* search path, used by allocator to deternine search_start by 2067 struct path *path; /* search path, used by allocator to deternine search_start by
2094 * various ways */ 2068 * various ways */
2095 struct reiserfs_transaction_handle * th; /* transaction handle is needed to log super blocks and 2069 struct reiserfs_transaction_handle *th; /* transaction handle is needed to log super blocks and
2096 * bitmap blocks changes */ 2070 * bitmap blocks changes */
2097 b_blocknr_t beg, end; 2071 b_blocknr_t beg, end;
2098 b_blocknr_t search_start; /* a field used to transfer search start value (block number) 2072 b_blocknr_t search_start; /* a field used to transfer search start value (block number)
2099 * between different block allocator procedures 2073 * between different block allocator procedures
2100 * (determine_search_start() and others) */ 2074 * (determine_search_start() and others) */
2101 int prealloc_size; /* is set in determine_prealloc_size() function, used by underlayed 2075 int prealloc_size; /* is set in determine_prealloc_size() function, used by underlayed
2102 * function that do actual allocation */ 2076 * function that do actual allocation */
2103 2077
2104 unsigned formatted_node:1; /* the allocator uses different polices for getting disk space for 2078 unsigned formatted_node:1; /* the allocator uses different polices for getting disk space for
2105 * formatted/unformatted blocks with/without preallocation */ 2079 * formatted/unformatted blocks with/without preallocation */
2106 unsigned preallocate:1; 2080 unsigned preallocate:1;
2107}; 2081};
2108 2082
2109typedef struct __reiserfs_blocknr_hint reiserfs_blocknr_hint_t; 2083typedef struct __reiserfs_blocknr_hint reiserfs_blocknr_hint_t;
2110 2084
2111int reiserfs_parse_alloc_options (struct super_block *, char *); 2085int reiserfs_parse_alloc_options(struct super_block *, char *);
2112void reiserfs_init_alloc_options (struct super_block *s); 2086void reiserfs_init_alloc_options(struct super_block *s);
2113 2087
2114/* 2088/*
2115 * given a directory, this will tell you what packing locality 2089 * given a directory, this will tell you what packing locality
@@ -2118,68 +2092,72 @@ void reiserfs_init_alloc_options (struct super_block *s);
2118 */ 2092 */
2119__le32 reiserfs_choose_packing(struct inode *dir); 2093__le32 reiserfs_choose_packing(struct inode *dir);
2120 2094
2121int is_reusable (struct super_block * s, b_blocknr_t block, int bit_value); 2095int is_reusable(struct super_block *s, b_blocknr_t block, int bit_value);
2122void reiserfs_free_block (struct reiserfs_transaction_handle *th, struct inode *, b_blocknr_t, int for_unformatted); 2096void reiserfs_free_block(struct reiserfs_transaction_handle *th, struct inode *,
2123int reiserfs_allocate_blocknrs(reiserfs_blocknr_hint_t *, b_blocknr_t * , int, int); 2097 b_blocknr_t, int for_unformatted);
2124extern inline int reiserfs_new_form_blocknrs (struct tree_balance * tb, 2098int reiserfs_allocate_blocknrs(reiserfs_blocknr_hint_t *, b_blocknr_t *, int,
2125 b_blocknr_t *new_blocknrs, int amount_needed) 2099 int);
2100extern inline int reiserfs_new_form_blocknrs(struct tree_balance *tb,
2101 b_blocknr_t * new_blocknrs,
2102 int amount_needed)
2126{ 2103{
2127 reiserfs_blocknr_hint_t hint = { 2104 reiserfs_blocknr_hint_t hint = {
2128 .th = tb->transaction_handle, 2105 .th = tb->transaction_handle,
2129 .path = tb->tb_path, 2106 .path = tb->tb_path,
2130 .inode = NULL, 2107 .inode = NULL,
2131 .key = tb->key, 2108 .key = tb->key,
2132 .block = 0, 2109 .block = 0,
2133 .formatted_node = 1 2110 .formatted_node = 1
2134 }; 2111 };
2135 return reiserfs_allocate_blocknrs(&hint, new_blocknrs, amount_needed, 0); 2112 return reiserfs_allocate_blocknrs(&hint, new_blocknrs, amount_needed,
2113 0);
2136} 2114}
2137 2115
2138extern inline int reiserfs_new_unf_blocknrs (struct reiserfs_transaction_handle *th, 2116extern inline int reiserfs_new_unf_blocknrs(struct reiserfs_transaction_handle
2139 struct inode *inode, 2117 *th, struct inode *inode,
2140 b_blocknr_t *new_blocknrs, 2118 b_blocknr_t * new_blocknrs,
2141 struct path * path, long block) 2119 struct path *path, long block)
2142{ 2120{
2143 reiserfs_blocknr_hint_t hint = { 2121 reiserfs_blocknr_hint_t hint = {
2144 .th = th, 2122 .th = th,
2145 .path = path, 2123 .path = path,
2146 .inode = inode, 2124 .inode = inode,
2147 .block = block, 2125 .block = block,
2148 .formatted_node = 0, 2126 .formatted_node = 0,
2149 .preallocate = 0 2127 .preallocate = 0
2150 }; 2128 };
2151 return reiserfs_allocate_blocknrs(&hint, new_blocknrs, 1, 0); 2129 return reiserfs_allocate_blocknrs(&hint, new_blocknrs, 1, 0);
2152} 2130}
2153 2131
2154#ifdef REISERFS_PREALLOCATE 2132#ifdef REISERFS_PREALLOCATE
2155extern inline int reiserfs_new_unf_blocknrs2(struct reiserfs_transaction_handle *th, 2133extern inline int reiserfs_new_unf_blocknrs2(struct reiserfs_transaction_handle
2156 struct inode * inode, 2134 *th, struct inode *inode,
2157 b_blocknr_t *new_blocknrs, 2135 b_blocknr_t * new_blocknrs,
2158 struct path * path, long block) 2136 struct path *path, long block)
2159{ 2137{
2160 reiserfs_blocknr_hint_t hint = { 2138 reiserfs_blocknr_hint_t hint = {
2161 .th = th, 2139 .th = th,
2162 .path = path, 2140 .path = path,
2163 .inode = inode, 2141 .inode = inode,
2164 .block = block, 2142 .block = block,
2165 .formatted_node = 0, 2143 .formatted_node = 0,
2166 .preallocate = 1 2144 .preallocate = 1
2167 }; 2145 };
2168 return reiserfs_allocate_blocknrs(&hint, new_blocknrs, 1, 0); 2146 return reiserfs_allocate_blocknrs(&hint, new_blocknrs, 1, 0);
2169} 2147}
2170 2148
2171void reiserfs_discard_prealloc (struct reiserfs_transaction_handle *th, 2149void reiserfs_discard_prealloc(struct reiserfs_transaction_handle *th,
2172 struct inode * inode); 2150 struct inode *inode);
2173void reiserfs_discard_all_prealloc (struct reiserfs_transaction_handle *th); 2151void reiserfs_discard_all_prealloc(struct reiserfs_transaction_handle *th);
2174#endif 2152#endif
2175void reiserfs_claim_blocks_to_be_allocated( struct super_block *sb, int blocks); 2153void reiserfs_claim_blocks_to_be_allocated(struct super_block *sb, int blocks);
2176void reiserfs_release_claimed_blocks( struct super_block *sb, int blocks); 2154void reiserfs_release_claimed_blocks(struct super_block *sb, int blocks);
2177int reiserfs_can_fit_pages(struct super_block *sb); 2155int reiserfs_can_fit_pages(struct super_block *sb);
2178 2156
2179/* hashes.c */ 2157/* hashes.c */
2180__u32 keyed_hash (const signed char *msg, int len); 2158__u32 keyed_hash(const signed char *msg, int len);
2181__u32 yura_hash (const signed char *msg, int len); 2159__u32 yura_hash(const signed char *msg, int len);
2182__u32 r5_hash (const signed char *msg, int len); 2160__u32 r5_hash(const signed char *msg, int len);
2183 2161
2184/* the ext2 bit routines adjust for big or little endian as 2162/* the ext2 bit routines adjust for big or little endian as
2185** appropriate for the arch, so in our laziness we use them rather 2163** appropriate for the arch, so in our laziness we use them rather
@@ -2199,11 +2177,10 @@ __u32 r5_hash (const signed char *msg, int len);
2199 absolutely safe */ 2177 absolutely safe */
2200#define SPARE_SPACE 500 2178#define SPARE_SPACE 500
2201 2179
2202
2203/* prototypes from ioctl.c */ 2180/* prototypes from ioctl.c */
2204int reiserfs_ioctl (struct inode * inode, struct file * filp, 2181int reiserfs_ioctl(struct inode *inode, struct file *filp,
2205 unsigned int cmd, unsigned long arg); 2182 unsigned int cmd, unsigned long arg);
2206 2183
2207/* ioctl's command */ 2184/* ioctl's command */
2208#define REISERFS_IOC_UNPACK _IOW(0xCD,1,long) 2185#define REISERFS_IOC_UNPACK _IOW(0xCD,1,long)
2209/* define following flags to be the same as in ext2, so that chattr(1), 2186/* define following flags to be the same as in ext2, so that chattr(1),
@@ -2218,10 +2195,8 @@ int reiserfs_ioctl (struct inode * inode, struct file * filp,
2218 would evolve into real per-fs locks */ 2195 would evolve into real per-fs locks */
2219#define reiserfs_write_lock( sb ) lock_kernel() 2196#define reiserfs_write_lock( sb ) lock_kernel()
2220#define reiserfs_write_unlock( sb ) unlock_kernel() 2197#define reiserfs_write_unlock( sb ) unlock_kernel()
2221 2198
2222/* xattr stuff */ 2199/* xattr stuff */
2223#define REISERFS_XATTR_DIR_SEM(s) (REISERFS_SB(s)->xattr_dir_sem) 2200#define REISERFS_XATTR_DIR_SEM(s) (REISERFS_SB(s)->xattr_dir_sem)
2224 2201
2225#endif /* _LINUX_REISER_FS_H */ 2202#endif /* _LINUX_REISER_FS_H */
2226
2227
diff --git a/include/linux/reiserfs_fs_i.h b/include/linux/reiserfs_fs_i.h
index e321eb050d65..149be8d9a0c9 100644
--- a/include/linux/reiserfs_fs_i.h
+++ b/include/linux/reiserfs_fs_i.h
@@ -10,54 +10,53 @@ typedef enum {
10 /** this says what format of key do all items (but stat data) of 10 /** this says what format of key do all items (but stat data) of
11 an object have. If this is set, that format is 3.6 otherwise 11 an object have. If this is set, that format is 3.6 otherwise
12 - 3.5 */ 12 - 3.5 */
13 i_item_key_version_mask = 0x0001, 13 i_item_key_version_mask = 0x0001,
14 /** If this is unset, object has 3.5 stat data, otherwise, it has 14 /** If this is unset, object has 3.5 stat data, otherwise, it has
15 3.6 stat data with 64bit size, 32bit nlink etc. */ 15 3.6 stat data with 64bit size, 32bit nlink etc. */
16 i_stat_data_version_mask = 0x0002, 16 i_stat_data_version_mask = 0x0002,
17 /** file might need tail packing on close */ 17 /** file might need tail packing on close */
18 i_pack_on_close_mask = 0x0004, 18 i_pack_on_close_mask = 0x0004,
19 /** don't pack tail of file */ 19 /** don't pack tail of file */
20 i_nopack_mask = 0x0008, 20 i_nopack_mask = 0x0008,
21 /** If those is set, "safe link" was created for this file during 21 /** If those is set, "safe link" was created for this file during
22 truncate or unlink. Safe link is used to avoid leakage of disk 22 truncate or unlink. Safe link is used to avoid leakage of disk
23 space on crash with some files open, but unlinked. */ 23 space on crash with some files open, but unlinked. */
24 i_link_saved_unlink_mask = 0x0010, 24 i_link_saved_unlink_mask = 0x0010,
25 i_link_saved_truncate_mask = 0x0020, 25 i_link_saved_truncate_mask = 0x0020,
26 i_has_xattr_dir = 0x0040, 26 i_has_xattr_dir = 0x0040,
27 i_data_log = 0x0080, 27 i_data_log = 0x0080,
28} reiserfs_inode_flags; 28} reiserfs_inode_flags;
29 29
30
31struct reiserfs_inode_info { 30struct reiserfs_inode_info {
32 __u32 i_key [4];/* key is still 4 32 bit integers */ 31 __u32 i_key[4]; /* key is still 4 32 bit integers */
33 /** transient inode flags that are never stored on disk. Bitmasks 32 /** transient inode flags that are never stored on disk. Bitmasks
34 for this field are defined above. */ 33 for this field are defined above. */
35 __u32 i_flags; 34 __u32 i_flags;
36 35
37 __u32 i_first_direct_byte; // offset of first byte stored in direct item. 36 __u32 i_first_direct_byte; // offset of first byte stored in direct item.
38 37
39 /* copy of persistent inode flags read from sd_attrs. */ 38 /* copy of persistent inode flags read from sd_attrs. */
40 __u32 i_attrs; 39 __u32 i_attrs;
41 40
42 int i_prealloc_block; /* first unused block of a sequence of unused blocks */ 41 int i_prealloc_block; /* first unused block of a sequence of unused blocks */
43 int i_prealloc_count; /* length of that sequence */ 42 int i_prealloc_count; /* length of that sequence */
44 struct list_head i_prealloc_list; /* per-transaction list of inodes which 43 struct list_head i_prealloc_list; /* per-transaction list of inodes which
45 * have preallocated blocks */ 44 * have preallocated blocks */
46 45
47 unsigned new_packing_locality:1; /* new_packig_locality is created; new blocks 46 unsigned new_packing_locality:1; /* new_packig_locality is created; new blocks
48 * for the contents of this directory should be 47 * for the contents of this directory should be
49 * displaced */ 48 * displaced */
50 49
51 /* we use these for fsync or O_SYNC to decide which transaction 50 /* we use these for fsync or O_SYNC to decide which transaction
52 ** needs to be committed in order for this inode to be properly 51 ** needs to be committed in order for this inode to be properly
53 ** flushed */ 52 ** flushed */
54 unsigned long i_trans_id ; 53 unsigned long i_trans_id;
55 struct reiserfs_journal_list *i_jl; 54 struct reiserfs_journal_list *i_jl;
56 55
57 struct posix_acl *i_acl_access; 56 struct posix_acl *i_acl_access;
58 struct posix_acl *i_acl_default; 57 struct posix_acl *i_acl_default;
59 struct rw_semaphore xattr_sem; 58 struct rw_semaphore xattr_sem;
60 struct inode vfs_inode; 59 struct inode vfs_inode;
61}; 60};
62 61
63#endif 62#endif
diff --git a/include/linux/reiserfs_fs_sb.h b/include/linux/reiserfs_fs_sb.h
index 31c709d0fe18..3e68592e52e9 100644
--- a/include/linux/reiserfs_fs_sb.h
+++ b/include/linux/reiserfs_fs_sb.h
@@ -10,7 +10,7 @@
10#endif 10#endif
11 11
12typedef enum { 12typedef enum {
13 reiserfs_attrs_cleared = 0x00000001, 13 reiserfs_attrs_cleared = 0x00000001,
14} reiserfs_super_block_flags; 14} reiserfs_super_block_flags;
15 15
16/* struct reiserfs_super_block accessors/mutators 16/* struct reiserfs_super_block accessors/mutators
@@ -61,7 +61,7 @@ typedef enum {
61#define sb_umount_state(sbp) (le16_to_cpu((sbp)->s_v1.s_umount_state)) 61#define sb_umount_state(sbp) (le16_to_cpu((sbp)->s_v1.s_umount_state))
62#define set_sb_umount_state(sbp,v) ((sbp)->s_v1.s_umount_state = cpu_to_le16(v)) 62#define set_sb_umount_state(sbp,v) ((sbp)->s_v1.s_umount_state = cpu_to_le16(v))
63#define sb_fs_state(sbp) (le16_to_cpu((sbp)->s_v1.s_fs_state)) 63#define sb_fs_state(sbp) (le16_to_cpu((sbp)->s_v1.s_fs_state))
64#define set_sb_fs_state(sbp,v) ((sbp)->s_v1.s_fs_state = cpu_to_le16(v)) 64#define set_sb_fs_state(sbp,v) ((sbp)->s_v1.s_fs_state = cpu_to_le16(v))
65#define sb_hash_function_code(sbp) \ 65#define sb_hash_function_code(sbp) \
66 (le32_to_cpu((sbp)->s_v1.s_hash_function_code)) 66 (le32_to_cpu((sbp)->s_v1.s_hash_function_code))
67#define set_sb_hash_function_code(sbp,v) \ 67#define set_sb_hash_function_code(sbp,v) \
@@ -103,10 +103,10 @@ typedef enum {
103 103
104/* don't mess with these for a while */ 104/* don't mess with these for a while */
105 /* we have a node size define somewhere in reiserfs_fs.h. -Hans */ 105 /* we have a node size define somewhere in reiserfs_fs.h. -Hans */
106#define JOURNAL_BLOCK_SIZE 4096 /* BUG gotta get rid of this */ 106#define JOURNAL_BLOCK_SIZE 4096 /* BUG gotta get rid of this */
107#define JOURNAL_MAX_CNODE 1500 /* max cnodes to allocate. */ 107#define JOURNAL_MAX_CNODE 1500 /* max cnodes to allocate. */
108#define JOURNAL_HASH_SIZE 8192 108#define JOURNAL_HASH_SIZE 8192
109#define JOURNAL_NUM_BITMAPS 5 /* number of copies of the bitmaps to have floating. Must be >= 2 */ 109#define JOURNAL_NUM_BITMAPS 5 /* number of copies of the bitmaps to have floating. Must be >= 2 */
110 110
111/* One of these for every block in every transaction 111/* One of these for every block in every transaction
112** Each one is in two hash tables. First, a hash of the current transaction, and after journal_end, a 112** Each one is in two hash tables. First, a hash of the current transaction, and after journal_end, a
@@ -117,27 +117,27 @@ typedef enum {
117** to a given transaction. 117** to a given transaction.
118*/ 118*/
119struct reiserfs_journal_cnode { 119struct reiserfs_journal_cnode {
120 struct buffer_head *bh ; /* real buffer head */ 120 struct buffer_head *bh; /* real buffer head */
121 struct super_block *sb ; /* dev of real buffer head */ 121 struct super_block *sb; /* dev of real buffer head */
122 __u32 blocknr ; /* block number of real buffer head, == 0 when buffer on disk */ 122 __u32 blocknr; /* block number of real buffer head, == 0 when buffer on disk */
123 long state ; 123 long state;
124 struct reiserfs_journal_list *jlist ; /* journal list this cnode lives in */ 124 struct reiserfs_journal_list *jlist; /* journal list this cnode lives in */
125 struct reiserfs_journal_cnode *next ; /* next in transaction list */ 125 struct reiserfs_journal_cnode *next; /* next in transaction list */
126 struct reiserfs_journal_cnode *prev ; /* prev in transaction list */ 126 struct reiserfs_journal_cnode *prev; /* prev in transaction list */
127 struct reiserfs_journal_cnode *hprev ; /* prev in hash list */ 127 struct reiserfs_journal_cnode *hprev; /* prev in hash list */
128 struct reiserfs_journal_cnode *hnext ; /* next in hash list */ 128 struct reiserfs_journal_cnode *hnext; /* next in hash list */
129}; 129};
130 130
131struct reiserfs_bitmap_node { 131struct reiserfs_bitmap_node {
132 int id ; 132 int id;
133 char *data ; 133 char *data;
134 struct list_head list ; 134 struct list_head list;
135} ; 135};
136 136
137struct reiserfs_list_bitmap { 137struct reiserfs_list_bitmap {
138 struct reiserfs_journal_list *journal_list ; 138 struct reiserfs_journal_list *journal_list;
139 struct reiserfs_bitmap_node **bitmaps ; 139 struct reiserfs_bitmap_node **bitmaps;
140} ; 140};
141 141
142/* 142/*
143** one of these for each transaction. The most important part here is the j_realblock. 143** one of these for each transaction. The most important part here is the j_realblock.
@@ -146,273 +146,269 @@ struct reiserfs_list_bitmap {
146** and to make sure every real block in a transaction is on disk before allowing the log area 146** and to make sure every real block in a transaction is on disk before allowing the log area
147** to be overwritten */ 147** to be overwritten */
148struct reiserfs_journal_list { 148struct reiserfs_journal_list {
149 unsigned long j_start ; 149 unsigned long j_start;
150 unsigned long j_state; 150 unsigned long j_state;
151 unsigned long j_len ; 151 unsigned long j_len;
152 atomic_t j_nonzerolen ; 152 atomic_t j_nonzerolen;
153 atomic_t j_commit_left ; 153 atomic_t j_commit_left;
154 atomic_t j_older_commits_done ; /* all commits older than this on disk*/ 154 atomic_t j_older_commits_done; /* all commits older than this on disk */
155 struct semaphore j_commit_lock; 155 struct semaphore j_commit_lock;
156 unsigned long j_trans_id ; 156 unsigned long j_trans_id;
157 time_t j_timestamp ; 157 time_t j_timestamp;
158 struct reiserfs_list_bitmap *j_list_bitmap ; 158 struct reiserfs_list_bitmap *j_list_bitmap;
159 struct buffer_head *j_commit_bh ; /* commit buffer head */ 159 struct buffer_head *j_commit_bh; /* commit buffer head */
160 struct reiserfs_journal_cnode *j_realblock ; 160 struct reiserfs_journal_cnode *j_realblock;
161 struct reiserfs_journal_cnode *j_freedlist ; /* list of buffers that were freed during this trans. free each of these on flush */ 161 struct reiserfs_journal_cnode *j_freedlist; /* list of buffers that were freed during this trans. free each of these on flush */
162 /* time ordered list of all active transactions */ 162 /* time ordered list of all active transactions */
163 struct list_head j_list; 163 struct list_head j_list;
164 164
165 /* time ordered list of all transactions we haven't tried to flush yet */ 165 /* time ordered list of all transactions we haven't tried to flush yet */
166 struct list_head j_working_list; 166 struct list_head j_working_list;
167 167
168 /* list of tail conversion targets in need of flush before commit */ 168 /* list of tail conversion targets in need of flush before commit */
169 struct list_head j_tail_bh_list; 169 struct list_head j_tail_bh_list;
170 /* list of data=ordered buffers in need of flush before commit */ 170 /* list of data=ordered buffers in need of flush before commit */
171 struct list_head j_bh_list; 171 struct list_head j_bh_list;
172 int j_refcount; 172 int j_refcount;
173} ; 173};
174 174
175struct reiserfs_journal { 175struct reiserfs_journal {
176 struct buffer_head ** j_ap_blocks ; /* journal blocks on disk */ 176 struct buffer_head **j_ap_blocks; /* journal blocks on disk */
177 struct reiserfs_journal_cnode *j_last ; /* newest journal block */ 177 struct reiserfs_journal_cnode *j_last; /* newest journal block */
178 struct reiserfs_journal_cnode *j_first ; /* oldest journal block. start here for traverse */ 178 struct reiserfs_journal_cnode *j_first; /* oldest journal block. start here for traverse */
179 179
180 struct file *j_dev_file; 180 struct file *j_dev_file;
181 struct block_device *j_dev_bd; 181 struct block_device *j_dev_bd;
182 int j_1st_reserved_block; /* first block on s_dev of reserved area journal */ 182 int j_1st_reserved_block; /* first block on s_dev of reserved area journal */
183 183
184 long j_state ; 184 long j_state;
185 unsigned long j_trans_id ; 185 unsigned long j_trans_id;
186 unsigned long j_mount_id ; 186 unsigned long j_mount_id;
187 unsigned long j_start ; /* start of current waiting commit (index into j_ap_blocks) */ 187 unsigned long j_start; /* start of current waiting commit (index into j_ap_blocks) */
188 unsigned long j_len ; /* lenght of current waiting commit */ 188 unsigned long j_len; /* lenght of current waiting commit */
189 unsigned long j_len_alloc ; /* number of buffers requested by journal_begin() */ 189 unsigned long j_len_alloc; /* number of buffers requested by journal_begin() */
190 atomic_t j_wcount ; /* count of writers for current commit */ 190 atomic_t j_wcount; /* count of writers for current commit */
191 unsigned long j_bcount ; /* batch count. allows turning X transactions into 1 */ 191 unsigned long j_bcount; /* batch count. allows turning X transactions into 1 */
192 unsigned long j_first_unflushed_offset ; /* first unflushed transactions offset */ 192 unsigned long j_first_unflushed_offset; /* first unflushed transactions offset */
193 unsigned long j_last_flush_trans_id ; /* last fully flushed journal timestamp */ 193 unsigned long j_last_flush_trans_id; /* last fully flushed journal timestamp */
194 struct buffer_head *j_header_bh ; 194 struct buffer_head *j_header_bh;
195 195
196 time_t j_trans_start_time ; /* time this transaction started */ 196 time_t j_trans_start_time; /* time this transaction started */
197 struct semaphore j_lock; 197 struct semaphore j_lock;
198 struct semaphore j_flush_sem; 198 struct semaphore j_flush_sem;
199 wait_queue_head_t j_join_wait ; /* wait for current transaction to finish before starting new one */ 199 wait_queue_head_t j_join_wait; /* wait for current transaction to finish before starting new one */
200 atomic_t j_jlock ; /* lock for j_join_wait */ 200 atomic_t j_jlock; /* lock for j_join_wait */
201 int j_list_bitmap_index ; /* number of next list bitmap to use */ 201 int j_list_bitmap_index; /* number of next list bitmap to use */
202 int j_must_wait ; /* no more journal begins allowed. MUST sleep on j_join_wait */ 202 int j_must_wait; /* no more journal begins allowed. MUST sleep on j_join_wait */
203 int j_next_full_flush ; /* next journal_end will flush all journal list */ 203 int j_next_full_flush; /* next journal_end will flush all journal list */
204 int j_next_async_flush ; /* next journal_end will flush all async commits */ 204 int j_next_async_flush; /* next journal_end will flush all async commits */
205 205
206 int j_cnode_used ; /* number of cnodes on the used list */ 206 int j_cnode_used; /* number of cnodes on the used list */
207 int j_cnode_free ; /* number of cnodes on the free list */ 207 int j_cnode_free; /* number of cnodes on the free list */
208 208
209 unsigned int j_trans_max ; /* max number of blocks in a transaction. */ 209 unsigned int j_trans_max; /* max number of blocks in a transaction. */
210 unsigned int j_max_batch ; /* max number of blocks to batch into a trans */ 210 unsigned int j_max_batch; /* max number of blocks to batch into a trans */
211 unsigned int j_max_commit_age ; /* in seconds, how old can an async commit be */ 211 unsigned int j_max_commit_age; /* in seconds, how old can an async commit be */
212 unsigned int j_max_trans_age ; /* in seconds, how old can a transaction be */ 212 unsigned int j_max_trans_age; /* in seconds, how old can a transaction be */
213 unsigned int j_default_max_commit_age ; /* the default for the max commit age */ 213 unsigned int j_default_max_commit_age; /* the default for the max commit age */
214 214
215 struct reiserfs_journal_cnode *j_cnode_free_list ; 215 struct reiserfs_journal_cnode *j_cnode_free_list;
216 struct reiserfs_journal_cnode *j_cnode_free_orig ; /* orig pointer returned from vmalloc */ 216 struct reiserfs_journal_cnode *j_cnode_free_orig; /* orig pointer returned from vmalloc */
217 217
218 struct reiserfs_journal_list *j_current_jl; 218 struct reiserfs_journal_list *j_current_jl;
219 int j_free_bitmap_nodes ; 219 int j_free_bitmap_nodes;
220 int j_used_bitmap_nodes ; 220 int j_used_bitmap_nodes;
221 221
222 int j_num_lists; /* total number of active transactions */ 222 int j_num_lists; /* total number of active transactions */
223 int j_num_work_lists; /* number that need attention from kreiserfsd */ 223 int j_num_work_lists; /* number that need attention from kreiserfsd */
224 224
225 /* debugging to make sure things are flushed in order */ 225 /* debugging to make sure things are flushed in order */
226 int j_last_flush_id; 226 int j_last_flush_id;
227 227
228 /* debugging to make sure things are committed in order */ 228 /* debugging to make sure things are committed in order */
229 int j_last_commit_id; 229 int j_last_commit_id;
230 230
231 struct list_head j_bitmap_nodes ; 231 struct list_head j_bitmap_nodes;
232 struct list_head j_dirty_buffers ; 232 struct list_head j_dirty_buffers;
233 spinlock_t j_dirty_buffers_lock ; /* protects j_dirty_buffers */ 233 spinlock_t j_dirty_buffers_lock; /* protects j_dirty_buffers */
234 234
235 /* list of all active transactions */ 235 /* list of all active transactions */
236 struct list_head j_journal_list; 236 struct list_head j_journal_list;
237 /* lists that haven't been touched by writeback attempts */ 237 /* lists that haven't been touched by writeback attempts */
238 struct list_head j_working_list; 238 struct list_head j_working_list;
239 239
240 struct reiserfs_list_bitmap j_list_bitmap[JOURNAL_NUM_BITMAPS] ; /* array of bitmaps to record the deleted blocks */ 240 struct reiserfs_list_bitmap j_list_bitmap[JOURNAL_NUM_BITMAPS]; /* array of bitmaps to record the deleted blocks */
241 struct reiserfs_journal_cnode *j_hash_table[JOURNAL_HASH_SIZE] ; /* hash table for real buffer heads in current trans */ 241 struct reiserfs_journal_cnode *j_hash_table[JOURNAL_HASH_SIZE]; /* hash table for real buffer heads in current trans */
242 struct reiserfs_journal_cnode *j_list_hash_table[JOURNAL_HASH_SIZE] ; /* hash table for all the real buffer heads in all 242 struct reiserfs_journal_cnode *j_list_hash_table[JOURNAL_HASH_SIZE]; /* hash table for all the real buffer heads in all
243 the transactions */ 243 the transactions */
244 struct list_head j_prealloc_list; /* list of inodes which have preallocated blocks */ 244 struct list_head j_prealloc_list; /* list of inodes which have preallocated blocks */
245 int j_persistent_trans; 245 int j_persistent_trans;
246 unsigned long j_max_trans_size ; 246 unsigned long j_max_trans_size;
247 unsigned long j_max_batch_size ; 247 unsigned long j_max_batch_size;
248 248
249 int j_errno; 249 int j_errno;
250 250
251 /* when flushing ordered buffers, throttle new ordered writers */ 251 /* when flushing ordered buffers, throttle new ordered writers */
252 struct work_struct j_work; 252 struct work_struct j_work;
253 atomic_t j_async_throttle; 253 atomic_t j_async_throttle;
254}; 254};
255 255
256enum journal_state_bits { 256enum journal_state_bits {
257 J_WRITERS_BLOCKED = 1, /* set when new writers not allowed */ 257 J_WRITERS_BLOCKED = 1, /* set when new writers not allowed */
258 J_WRITERS_QUEUED, /* set when log is full due to too many writers */ 258 J_WRITERS_QUEUED, /* set when log is full due to too many writers */
259 J_ABORTED, /* set when log is aborted */ 259 J_ABORTED, /* set when log is aborted */
260}; 260};
261 261
262#define JOURNAL_DESC_MAGIC "ReIsErLB" /* ick. magic string to find desc blocks in the journal */
262 263
263#define JOURNAL_DESC_MAGIC "ReIsErLB" /* ick. magic string to find desc blocks in the journal */ 264typedef __u32(*hashf_t) (const signed char *, int);
264 265
265typedef __u32 (*hashf_t) (const signed char *, int); 266struct reiserfs_bitmap_info {
266 267 // FIXME: Won't work with block sizes > 8K
267struct reiserfs_bitmap_info 268 __u16 first_zero_hint;
268{ 269 __u16 free_count;
269 // FIXME: Won't work with block sizes > 8K 270 struct buffer_head *bh; /* the actual bitmap */
270 __u16 first_zero_hint;
271 __u16 free_count;
272 struct buffer_head *bh; /* the actual bitmap */
273}; 271};
274 272
275struct proc_dir_entry; 273struct proc_dir_entry;
276 274
277#if defined( CONFIG_PROC_FS ) && defined( CONFIG_REISERFS_PROC_INFO ) 275#if defined( CONFIG_PROC_FS ) && defined( CONFIG_REISERFS_PROC_INFO )
278typedef unsigned long int stat_cnt_t; 276typedef unsigned long int stat_cnt_t;
279typedef struct reiserfs_proc_info_data 277typedef struct reiserfs_proc_info_data {
280{ 278 spinlock_t lock;
281 spinlock_t lock; 279 int exiting;
282 int exiting; 280 int max_hash_collisions;
283 int max_hash_collisions; 281
284 282 stat_cnt_t breads;
285 stat_cnt_t breads; 283 stat_cnt_t bread_miss;
286 stat_cnt_t bread_miss; 284 stat_cnt_t search_by_key;
287 stat_cnt_t search_by_key; 285 stat_cnt_t search_by_key_fs_changed;
288 stat_cnt_t search_by_key_fs_changed; 286 stat_cnt_t search_by_key_restarted;
289 stat_cnt_t search_by_key_restarted; 287
290 288 stat_cnt_t insert_item_restarted;
291 stat_cnt_t insert_item_restarted; 289 stat_cnt_t paste_into_item_restarted;
292 stat_cnt_t paste_into_item_restarted; 290 stat_cnt_t cut_from_item_restarted;
293 stat_cnt_t cut_from_item_restarted; 291 stat_cnt_t delete_solid_item_restarted;
294 stat_cnt_t delete_solid_item_restarted; 292 stat_cnt_t delete_item_restarted;
295 stat_cnt_t delete_item_restarted; 293
296 294 stat_cnt_t leaked_oid;
297 stat_cnt_t leaked_oid; 295 stat_cnt_t leaves_removable;
298 stat_cnt_t leaves_removable; 296
299 297 /* balances per level. Use explicit 5 as MAX_HEIGHT is not visible yet. */
300 /* balances per level. Use explicit 5 as MAX_HEIGHT is not visible yet. */ 298 stat_cnt_t balance_at[5]; /* XXX */
301 stat_cnt_t balance_at[ 5 ]; /* XXX */ 299 /* sbk == search_by_key */
302 /* sbk == search_by_key */ 300 stat_cnt_t sbk_read_at[5]; /* XXX */
303 stat_cnt_t sbk_read_at[ 5 ]; /* XXX */ 301 stat_cnt_t sbk_fs_changed[5];
304 stat_cnt_t sbk_fs_changed[ 5 ]; 302 stat_cnt_t sbk_restarted[5];
305 stat_cnt_t sbk_restarted[ 5 ]; 303 stat_cnt_t items_at[5]; /* XXX */
306 stat_cnt_t items_at[ 5 ]; /* XXX */ 304 stat_cnt_t free_at[5]; /* XXX */
307 stat_cnt_t free_at[ 5 ]; /* XXX */ 305 stat_cnt_t can_node_be_removed[5]; /* XXX */
308 stat_cnt_t can_node_be_removed[ 5 ]; /* XXX */ 306 long int lnum[5]; /* XXX */
309 long int lnum[ 5 ]; /* XXX */ 307 long int rnum[5]; /* XXX */
310 long int rnum[ 5 ]; /* XXX */ 308 long int lbytes[5]; /* XXX */
311 long int lbytes[ 5 ]; /* XXX */ 309 long int rbytes[5]; /* XXX */
312 long int rbytes[ 5 ]; /* XXX */ 310 stat_cnt_t get_neighbors[5];
313 stat_cnt_t get_neighbors[ 5 ]; 311 stat_cnt_t get_neighbors_restart[5];
314 stat_cnt_t get_neighbors_restart[ 5 ]; 312 stat_cnt_t need_l_neighbor[5];
315 stat_cnt_t need_l_neighbor[ 5 ]; 313 stat_cnt_t need_r_neighbor[5];
316 stat_cnt_t need_r_neighbor[ 5 ]; 314
317 315 stat_cnt_t free_block;
318 stat_cnt_t free_block; 316 struct __scan_bitmap_stats {
319 struct __scan_bitmap_stats { 317 stat_cnt_t call;
320 stat_cnt_t call; 318 stat_cnt_t wait;
321 stat_cnt_t wait; 319 stat_cnt_t bmap;
322 stat_cnt_t bmap; 320 stat_cnt_t retry;
323 stat_cnt_t retry; 321 stat_cnt_t in_journal_hint;
324 stat_cnt_t in_journal_hint; 322 stat_cnt_t in_journal_nohint;
325 stat_cnt_t in_journal_nohint; 323 stat_cnt_t stolen;
326 stat_cnt_t stolen; 324 } scan_bitmap;
327 } scan_bitmap; 325 struct __journal_stats {
328 struct __journal_stats { 326 stat_cnt_t in_journal;
329 stat_cnt_t in_journal; 327 stat_cnt_t in_journal_bitmap;
330 stat_cnt_t in_journal_bitmap; 328 stat_cnt_t in_journal_reusable;
331 stat_cnt_t in_journal_reusable; 329 stat_cnt_t lock_journal;
332 stat_cnt_t lock_journal; 330 stat_cnt_t lock_journal_wait;
333 stat_cnt_t lock_journal_wait; 331 stat_cnt_t journal_being;
334 stat_cnt_t journal_being; 332 stat_cnt_t journal_relock_writers;
335 stat_cnt_t journal_relock_writers; 333 stat_cnt_t journal_relock_wcount;
336 stat_cnt_t journal_relock_wcount; 334 stat_cnt_t mark_dirty;
337 stat_cnt_t mark_dirty; 335 stat_cnt_t mark_dirty_already;
338 stat_cnt_t mark_dirty_already; 336 stat_cnt_t mark_dirty_notjournal;
339 stat_cnt_t mark_dirty_notjournal; 337 stat_cnt_t restore_prepared;
340 stat_cnt_t restore_prepared; 338 stat_cnt_t prepare;
341 stat_cnt_t prepare; 339 stat_cnt_t prepare_retry;
342 stat_cnt_t prepare_retry; 340 } journal;
343 } journal;
344} reiserfs_proc_info_data_t; 341} reiserfs_proc_info_data_t;
345#else 342#else
346typedef struct reiserfs_proc_info_data 343typedef struct reiserfs_proc_info_data {
347{} reiserfs_proc_info_data_t; 344} reiserfs_proc_info_data_t;
348#endif 345#endif
349 346
350/* reiserfs union of in-core super block data */ 347/* reiserfs union of in-core super block data */
351struct reiserfs_sb_info 348struct reiserfs_sb_info {
352{ 349 struct buffer_head *s_sbh; /* Buffer containing the super block */
353 struct buffer_head * s_sbh; /* Buffer containing the super block */ 350 /* both the comment and the choice of
354 /* both the comment and the choice of 351 name are unclear for s_rs -Hans */
355 name are unclear for s_rs -Hans */ 352 struct reiserfs_super_block *s_rs; /* Pointer to the super block in the buffer */
356 struct reiserfs_super_block * s_rs; /* Pointer to the super block in the buffer */ 353 struct reiserfs_bitmap_info *s_ap_bitmap;
357 struct reiserfs_bitmap_info * s_ap_bitmap; 354 struct reiserfs_journal *s_journal; /* pointer to journal information */
358 struct reiserfs_journal *s_journal ; /* pointer to journal information */ 355 unsigned short s_mount_state; /* reiserfs state (valid, invalid) */
359 unsigned short s_mount_state; /* reiserfs state (valid, invalid) */ 356
360 357 /* Comment? -Hans */
361 /* Comment? -Hans */ 358 void (*end_io_handler) (struct buffer_head *, int);
362 void (*end_io_handler)(struct buffer_head *, int); 359 hashf_t s_hash_function; /* pointer to function which is used
363 hashf_t s_hash_function; /* pointer to function which is used 360 to sort names in directory. Set on
364 to sort names in directory. Set on 361 mount */
365 mount */ 362 unsigned long s_mount_opt; /* reiserfs's mount options are set
366 unsigned long s_mount_opt; /* reiserfs's mount options are set 363 here (currently - NOTAIL, NOLOG,
367 here (currently - NOTAIL, NOLOG, 364 REPLAYONLY) */
368 REPLAYONLY) */ 365
369 366 struct { /* This is a structure that describes block allocator options */
370 struct { /* This is a structure that describes block allocator options */ 367 unsigned long bits; /* Bitfield for enable/disable kind of options */
371 unsigned long bits; /* Bitfield for enable/disable kind of options */ 368 unsigned long large_file_size; /* size started from which we consider file to be a large one(in blocks) */
372 unsigned long large_file_size; /* size started from which we consider file to be a large one(in blocks) */ 369 int border; /* percentage of disk, border takes */
373 int border; /* percentage of disk, border takes */ 370 int preallocmin; /* Minimal file size (in blocks) starting from which we do preallocations */
374 int preallocmin; /* Minimal file size (in blocks) starting from which we do preallocations */ 371 int preallocsize; /* Number of blocks we try to prealloc when file
375 int preallocsize; /* Number of blocks we try to prealloc when file 372 reaches preallocmin size (in blocks) or
376 reaches preallocmin size (in blocks) or 373 prealloc_list is empty. */
377 prealloc_list is empty. */ 374 } s_alloc_options;
378 } s_alloc_options; 375
379 376 /* Comment? -Hans */
380 /* Comment? -Hans */ 377 wait_queue_head_t s_wait;
381 wait_queue_head_t s_wait; 378 /* To be obsoleted soon by per buffer seals.. -Hans */
382 /* To be obsoleted soon by per buffer seals.. -Hans */ 379 atomic_t s_generation_counter; // increased by one every time the
383 atomic_t s_generation_counter; // increased by one every time the 380 // tree gets re-balanced
384 // tree gets re-balanced 381 unsigned long s_properties; /* File system properties. Currently holds
385 unsigned long s_properties; /* File system properties. Currently holds 382 on-disk FS format */
386 on-disk FS format */ 383
387 384 /* session statistics */
388 /* session statistics */ 385 int s_kmallocs;
389 int s_kmallocs; 386 int s_disk_reads;
390 int s_disk_reads; 387 int s_disk_writes;
391 int s_disk_writes; 388 int s_fix_nodes;
392 int s_fix_nodes; 389 int s_do_balance;
393 int s_do_balance; 390 int s_unneeded_left_neighbor;
394 int s_unneeded_left_neighbor; 391 int s_good_search_by_key_reada;
395 int s_good_search_by_key_reada; 392 int s_bmaps;
396 int s_bmaps; 393 int s_bmaps_without_search;
397 int s_bmaps_without_search; 394 int s_direct2indirect;
398 int s_direct2indirect; 395 int s_indirect2direct;
399 int s_indirect2direct;
400 /* set up when it's ok for reiserfs_read_inode2() to read from 396 /* set up when it's ok for reiserfs_read_inode2() to read from
401 disk inode with nlink==0. Currently this is only used during 397 disk inode with nlink==0. Currently this is only used during
402 finish_unfinished() processing at mount time */ 398 finish_unfinished() processing at mount time */
403 int s_is_unlinked_ok; 399 int s_is_unlinked_ok;
404 reiserfs_proc_info_data_t s_proc_info_data; 400 reiserfs_proc_info_data_t s_proc_info_data;
405 struct proc_dir_entry *procdir; 401 struct proc_dir_entry *procdir;
406 int reserved_blocks; /* amount of blocks reserved for further allocations */ 402 int reserved_blocks; /* amount of blocks reserved for further allocations */
407 spinlock_t bitmap_lock; /* this lock on now only used to protect reserved_blocks variable */ 403 spinlock_t bitmap_lock; /* this lock on now only used to protect reserved_blocks variable */
408 struct dentry *priv_root; /* root of /.reiserfs_priv */ 404 struct dentry *priv_root; /* root of /.reiserfs_priv */
409 struct dentry *xattr_root; /* root of /.reiserfs_priv/.xa */ 405 struct dentry *xattr_root; /* root of /.reiserfs_priv/.xa */
410 struct rw_semaphore xattr_dir_sem; 406 struct rw_semaphore xattr_dir_sem;
411 407
412 int j_errno; 408 int j_errno;
413#ifdef CONFIG_QUOTA 409#ifdef CONFIG_QUOTA
414 char *s_qf_names[MAXQUOTAS]; 410 char *s_qf_names[MAXQUOTAS];
415 int s_jquota_fmt; 411 int s_jquota_fmt;
416#endif 412#endif
417}; 413};
418 414
@@ -422,14 +418,14 @@ struct reiserfs_sb_info
422 418
423enum reiserfs_mount_options { 419enum reiserfs_mount_options {
424/* Mount options */ 420/* Mount options */
425 REISERFS_LARGETAIL, /* large tails will be created in a session */ 421 REISERFS_LARGETAIL, /* large tails will be created in a session */
426 REISERFS_SMALLTAIL, /* small (for files less than block size) tails will be created in a session */ 422 REISERFS_SMALLTAIL, /* small (for files less than block size) tails will be created in a session */
427 REPLAYONLY, /* replay journal and return 0. Use by fsck */ 423 REPLAYONLY, /* replay journal and return 0. Use by fsck */
428 REISERFS_CONVERT, /* -o conv: causes conversion of old 424 REISERFS_CONVERT, /* -o conv: causes conversion of old
429 format super block to the new 425 format super block to the new
430 format. If not specified - old 426 format. If not specified - old
431 partition will be dealt with in a 427 partition will be dealt with in a
432 manner of 3.5.x */ 428 manner of 3.5.x */
433 429
434/* -o hash={tea, rupasov, r5, detect} is meant for properly mounting 430/* -o hash={tea, rupasov, r5, detect} is meant for properly mounting
435** reiserfs disks from 3.5.19 or earlier. 99% of the time, this option 431** reiserfs disks from 3.5.19 or earlier. 99% of the time, this option
@@ -439,41 +435,41 @@ enum reiserfs_mount_options {
439** the existing hash on the FS, so if you have a tea hash disk, and mount 435** the existing hash on the FS, so if you have a tea hash disk, and mount
440** with -o hash=rupasov, the mount will fail. 436** with -o hash=rupasov, the mount will fail.
441*/ 437*/
442 FORCE_TEA_HASH, /* try to force tea hash on mount */ 438 FORCE_TEA_HASH, /* try to force tea hash on mount */
443 FORCE_RUPASOV_HASH, /* try to force rupasov hash on mount */ 439 FORCE_RUPASOV_HASH, /* try to force rupasov hash on mount */
444 FORCE_R5_HASH, /* try to force rupasov hash on mount */ 440 FORCE_R5_HASH, /* try to force rupasov hash on mount */
445 FORCE_HASH_DETECT, /* try to detect hash function on mount */ 441 FORCE_HASH_DETECT, /* try to detect hash function on mount */
446 442
447 REISERFS_DATA_LOG, 443 REISERFS_DATA_LOG,
448 REISERFS_DATA_ORDERED, 444 REISERFS_DATA_ORDERED,
449 REISERFS_DATA_WRITEBACK, 445 REISERFS_DATA_WRITEBACK,
450 446
451/* used for testing experimental features, makes benchmarking new 447/* used for testing experimental features, makes benchmarking new
452 features with and without more convenient, should never be used by 448 features with and without more convenient, should never be used by
453 users in any code shipped to users (ideally) */ 449 users in any code shipped to users (ideally) */
454 450
455 REISERFS_NO_BORDER, 451 REISERFS_NO_BORDER,
456 REISERFS_NO_UNHASHED_RELOCATION, 452 REISERFS_NO_UNHASHED_RELOCATION,
457 REISERFS_HASHED_RELOCATION, 453 REISERFS_HASHED_RELOCATION,
458 REISERFS_ATTRS, 454 REISERFS_ATTRS,
459 REISERFS_XATTRS, 455 REISERFS_XATTRS,
460 REISERFS_XATTRS_USER, 456 REISERFS_XATTRS_USER,
461 REISERFS_POSIXACL, 457 REISERFS_POSIXACL,
462 REISERFS_BARRIER_NONE, 458 REISERFS_BARRIER_NONE,
463 REISERFS_BARRIER_FLUSH, 459 REISERFS_BARRIER_FLUSH,
464 460
465 /* Actions on error */ 461 /* Actions on error */
466 REISERFS_ERROR_PANIC, 462 REISERFS_ERROR_PANIC,
467 REISERFS_ERROR_RO, 463 REISERFS_ERROR_RO,
468 REISERFS_ERROR_CONTINUE, 464 REISERFS_ERROR_CONTINUE,
469 465
470 REISERFS_QUOTA, /* Some quota option specified */ 466 REISERFS_QUOTA, /* Some quota option specified */
471 467
472 REISERFS_TEST1, 468 REISERFS_TEST1,
473 REISERFS_TEST2, 469 REISERFS_TEST2,
474 REISERFS_TEST3, 470 REISERFS_TEST3,
475 REISERFS_TEST4, 471 REISERFS_TEST4,
476 REISERFS_UNSUPPORTED_OPT, 472 REISERFS_UNSUPPORTED_OPT,
477}; 473};
478 474
479#define reiserfs_r5_hash(s) (REISERFS_SB(s)->s_mount_opt & (1 << FORCE_R5_HASH)) 475#define reiserfs_r5_hash(s) (REISERFS_SB(s)->s_mount_opt & (1 << FORCE_R5_HASH))
@@ -504,18 +500,17 @@ enum reiserfs_mount_options {
504#define reiserfs_error_panic(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_ERROR_PANIC)) 500#define reiserfs_error_panic(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_ERROR_PANIC))
505#define reiserfs_error_ro(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_ERROR_RO)) 501#define reiserfs_error_ro(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_ERROR_RO))
506 502
507void reiserfs_file_buffer (struct buffer_head * bh, int list); 503void reiserfs_file_buffer(struct buffer_head *bh, int list);
508extern struct file_system_type reiserfs_fs_type; 504extern struct file_system_type reiserfs_fs_type;
509int reiserfs_resize(struct super_block *, unsigned long) ; 505int reiserfs_resize(struct super_block *, unsigned long);
510 506
511#define CARRY_ON 0 507#define CARRY_ON 0
512#define SCHEDULE_OCCURRED 1 508#define SCHEDULE_OCCURRED 1
513 509
514
515#define SB_BUFFER_WITH_SB(s) (REISERFS_SB(s)->s_sbh) 510#define SB_BUFFER_WITH_SB(s) (REISERFS_SB(s)->s_sbh)
516#define SB_JOURNAL(s) (REISERFS_SB(s)->s_journal) 511#define SB_JOURNAL(s) (REISERFS_SB(s)->s_journal)
517#define SB_JOURNAL_1st_RESERVED_BLOCK(s) (SB_JOURNAL(s)->j_1st_reserved_block) 512#define SB_JOURNAL_1st_RESERVED_BLOCK(s) (SB_JOURNAL(s)->j_1st_reserved_block)
518#define SB_JOURNAL_LEN_FREE(s) (SB_JOURNAL(s)->j_journal_len_free) 513#define SB_JOURNAL_LEN_FREE(s) (SB_JOURNAL(s)->j_journal_len_free)
519#define SB_AP_BITMAP(s) (REISERFS_SB(s)->s_ap_bitmap) 514#define SB_AP_BITMAP(s) (REISERFS_SB(s)->s_ap_bitmap)
520 515
521#define SB_DISK_JOURNAL_HEAD(s) (SB_JOURNAL(s)->j_header_bh->) 516#define SB_DISK_JOURNAL_HEAD(s) (SB_JOURNAL(s)->j_header_bh->)
@@ -525,13 +520,14 @@ int reiserfs_resize(struct super_block *, unsigned long) ;
525 */ 520 */
526static inline char *reiserfs_bdevname(struct super_block *s) 521static inline char *reiserfs_bdevname(struct super_block *s)
527{ 522{
528 return (s == NULL) ? "Null superblock" : s -> s_id; 523 return (s == NULL) ? "Null superblock" : s->s_id;
529} 524}
530 525
531#define reiserfs_is_journal_aborted(journal) (unlikely (__reiserfs_is_journal_aborted (journal))) 526#define reiserfs_is_journal_aborted(journal) (unlikely (__reiserfs_is_journal_aborted (journal)))
532static inline int __reiserfs_is_journal_aborted (struct reiserfs_journal *journal) 527static inline int __reiserfs_is_journal_aborted(struct reiserfs_journal
528 *journal)
533{ 529{
534 return test_bit (J_ABORTED, &journal->j_state); 530 return test_bit(J_ABORTED, &journal->j_state);
535} 531}
536 532
537#endif /* _LINUX_REISER_FS_SB */ 533#endif /* _LINUX_REISER_FS_SB */
diff --git a/include/linux/reiserfs_xattr.h b/include/linux/reiserfs_xattr.h
index 9244c5748820..c84354e8374c 100644
--- a/include/linux/reiserfs_xattr.h
+++ b/include/linux/reiserfs_xattr.h
@@ -7,48 +7,48 @@
7#include <linux/xattr.h> 7#include <linux/xattr.h>
8 8
9/* Magic value in header */ 9/* Magic value in header */
10#define REISERFS_XATTR_MAGIC 0x52465841 /* "RFXA" */ 10#define REISERFS_XATTR_MAGIC 0x52465841 /* "RFXA" */
11 11
12struct reiserfs_xattr_header { 12struct reiserfs_xattr_header {
13 __le32 h_magic; /* magic number for identification */ 13 __le32 h_magic; /* magic number for identification */
14 __le32 h_hash; /* hash of the value */ 14 __le32 h_hash; /* hash of the value */
15}; 15};
16 16
17#ifdef __KERNEL__ 17#ifdef __KERNEL__
18 18
19struct reiserfs_xattr_handler { 19struct reiserfs_xattr_handler {
20 char *prefix; 20 char *prefix;
21 int (*init)(void); 21 int (*init) (void);
22 void (*exit)(void); 22 void (*exit) (void);
23 int (*get)(struct inode *inode, const char *name, void *buffer, 23 int (*get) (struct inode * inode, const char *name, void *buffer,
24 size_t size); 24 size_t size);
25 int (*set)(struct inode *inode, const char *name, const void *buffer, 25 int (*set) (struct inode * inode, const char *name, const void *buffer,
26 size_t size, int flags); 26 size_t size, int flags);
27 int (*del)(struct inode *inode, const char *name); 27 int (*del) (struct inode * inode, const char *name);
28 int (*list)(struct inode *inode, const char *name, int namelen, char *out); 28 int (*list) (struct inode * inode, const char *name, int namelen,
29 struct list_head handlers; 29 char *out);
30 struct list_head handlers;
30}; 31};
31 32
32
33#ifdef CONFIG_REISERFS_FS_XATTR 33#ifdef CONFIG_REISERFS_FS_XATTR
34#define is_reiserfs_priv_object(inode) IS_PRIVATE(inode) 34#define is_reiserfs_priv_object(inode) IS_PRIVATE(inode)
35#define has_xattr_dir(inode) (REISERFS_I(inode)->i_flags & i_has_xattr_dir) 35#define has_xattr_dir(inode) (REISERFS_I(inode)->i_flags & i_has_xattr_dir)
36ssize_t reiserfs_getxattr (struct dentry *dentry, const char *name, 36ssize_t reiserfs_getxattr(struct dentry *dentry, const char *name,
37 void *buffer, size_t size); 37 void *buffer, size_t size);
38int reiserfs_setxattr (struct dentry *dentry, const char *name, 38int reiserfs_setxattr(struct dentry *dentry, const char *name,
39 const void *value, size_t size, int flags); 39 const void *value, size_t size, int flags);
40ssize_t reiserfs_listxattr (struct dentry *dentry, char *buffer, size_t size); 40ssize_t reiserfs_listxattr(struct dentry *dentry, char *buffer, size_t size);
41int reiserfs_removexattr (struct dentry *dentry, const char *name); 41int reiserfs_removexattr(struct dentry *dentry, const char *name);
42int reiserfs_delete_xattrs (struct inode *inode); 42int reiserfs_delete_xattrs(struct inode *inode);
43int reiserfs_chown_xattrs (struct inode *inode, struct iattr *attrs); 43int reiserfs_chown_xattrs(struct inode *inode, struct iattr *attrs);
44int reiserfs_xattr_init (struct super_block *sb, int mount_flags); 44int reiserfs_xattr_init(struct super_block *sb, int mount_flags);
45int reiserfs_permission (struct inode *inode, int mask, struct nameidata *nd); 45int reiserfs_permission(struct inode *inode, int mask, struct nameidata *nd);
46int reiserfs_permission_locked (struct inode *inode, int mask, struct nameidata *nd); 46int reiserfs_permission_locked(struct inode *inode, int mask,
47 47 struct nameidata *nd);
48int reiserfs_xattr_del (struct inode *, const char *); 48
49int reiserfs_xattr_get (const struct inode *, const char *, void *, size_t); 49int reiserfs_xattr_del(struct inode *, const char *);
50int reiserfs_xattr_set (struct inode *, const char *, const void *, 50int reiserfs_xattr_get(const struct inode *, const char *, void *, size_t);
51 size_t, int); 51int reiserfs_xattr_set(struct inode *, const char *, const void *, size_t, int);
52 52
53extern struct reiserfs_xattr_handler user_handler; 53extern struct reiserfs_xattr_handler user_handler;
54extern struct reiserfs_xattr_handler trusted_handler; 54extern struct reiserfs_xattr_handler trusted_handler;
@@ -56,57 +56,48 @@ extern struct reiserfs_xattr_handler trusted_handler;
56extern struct reiserfs_xattr_handler security_handler; 56extern struct reiserfs_xattr_handler security_handler;
57#endif 57#endif
58 58
59int reiserfs_xattr_register_handlers (void) __init; 59int reiserfs_xattr_register_handlers(void) __init;
60void reiserfs_xattr_unregister_handlers (void); 60void reiserfs_xattr_unregister_handlers(void);
61 61
62static inline void 62static inline void reiserfs_write_lock_xattrs(struct super_block *sb)
63reiserfs_write_lock_xattrs(struct super_block *sb)
64{ 63{
65 down_write (&REISERFS_XATTR_DIR_SEM(sb)); 64 down_write(&REISERFS_XATTR_DIR_SEM(sb));
66} 65}
67static inline void 66static inline void reiserfs_write_unlock_xattrs(struct super_block *sb)
68reiserfs_write_unlock_xattrs(struct super_block *sb)
69{ 67{
70 up_write (&REISERFS_XATTR_DIR_SEM(sb)); 68 up_write(&REISERFS_XATTR_DIR_SEM(sb));
71} 69}
72static inline void 70static inline void reiserfs_read_lock_xattrs(struct super_block *sb)
73reiserfs_read_lock_xattrs(struct super_block *sb)
74{ 71{
75 down_read (&REISERFS_XATTR_DIR_SEM(sb)); 72 down_read(&REISERFS_XATTR_DIR_SEM(sb));
76} 73}
77 74
78static inline void 75static inline void reiserfs_read_unlock_xattrs(struct super_block *sb)
79reiserfs_read_unlock_xattrs(struct super_block *sb)
80{ 76{
81 up_read (&REISERFS_XATTR_DIR_SEM(sb)); 77 up_read(&REISERFS_XATTR_DIR_SEM(sb));
82} 78}
83 79
84static inline void 80static inline void reiserfs_write_lock_xattr_i(struct inode *inode)
85reiserfs_write_lock_xattr_i(struct inode *inode)
86{ 81{
87 down_write (&REISERFS_I(inode)->xattr_sem); 82 down_write(&REISERFS_I(inode)->xattr_sem);
88} 83}
89static inline void 84static inline void reiserfs_write_unlock_xattr_i(struct inode *inode)
90reiserfs_write_unlock_xattr_i(struct inode *inode)
91{ 85{
92 up_write (&REISERFS_I(inode)->xattr_sem); 86 up_write(&REISERFS_I(inode)->xattr_sem);
93} 87}
94static inline void 88static inline void reiserfs_read_lock_xattr_i(struct inode *inode)
95reiserfs_read_lock_xattr_i(struct inode *inode)
96{ 89{
97 down_read (&REISERFS_I(inode)->xattr_sem); 90 down_read(&REISERFS_I(inode)->xattr_sem);
98} 91}
99 92
100static inline void 93static inline void reiserfs_read_unlock_xattr_i(struct inode *inode)
101reiserfs_read_unlock_xattr_i(struct inode *inode)
102{ 94{
103 up_read (&REISERFS_I(inode)->xattr_sem); 95 up_read(&REISERFS_I(inode)->xattr_sem);
104} 96}
105 97
106static inline void 98static inline void reiserfs_mark_inode_private(struct inode *inode)
107reiserfs_mark_inode_private(struct inode *inode)
108{ 99{
109 inode->i_flags |= S_PRIVATE; 100 inode->i_flags |= S_PRIVATE;
110} 101}
111 102
112#else 103#else
@@ -127,13 +118,20 @@ reiserfs_mark_inode_private(struct inode *inode)
127#define reiserfs_xattr_register_handlers() 0 118#define reiserfs_xattr_register_handlers() 0
128#define reiserfs_xattr_unregister_handlers() 119#define reiserfs_xattr_unregister_handlers()
129 120
130static inline int reiserfs_delete_xattrs (struct inode *inode) { return 0; }; 121static inline int reiserfs_delete_xattrs(struct inode *inode)
131static inline int reiserfs_chown_xattrs (struct inode *inode, struct iattr *attrs) { return 0; }; 122{
132static inline int reiserfs_xattr_init (struct super_block *sb, int mount_flags) 123 return 0;
124};
125static inline int reiserfs_chown_xattrs(struct inode *inode,
126 struct iattr *attrs)
127{
128 return 0;
129};
130static inline int reiserfs_xattr_init(struct super_block *sb, int mount_flags)
133{ 131{
134 sb->s_flags = (sb->s_flags & ~MS_POSIXACL); /* to be sure */ 132 sb->s_flags = (sb->s_flags & ~MS_POSIXACL); /* to be sure */
135 return 0; 133 return 0;
136}; 134};
137#endif 135#endif
138 136
139#endif /* __KERNEL__ */ 137#endif /* __KERNEL__ */
diff --git a/include/linux/sched.h b/include/linux/sched.h
index ff48815bd3a2..dec5827c7742 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -410,6 +410,10 @@ struct user_struct {
410 atomic_t processes; /* How many processes does this user have? */ 410 atomic_t processes; /* How many processes does this user have? */
411 atomic_t files; /* How many open files does this user have? */ 411 atomic_t files; /* How many open files does this user have? */
412 atomic_t sigpending; /* How many pending signals does this user have? */ 412 atomic_t sigpending; /* How many pending signals does this user have? */
413#ifdef CONFIG_INOTIFY
414 atomic_t inotify_watches; /* How many inotify watches does this user have? */
415 atomic_t inotify_devs; /* How many inotify devs does this user have opened? */
416#endif
413 /* protected by mq_lock */ 417 /* protected by mq_lock */
414 unsigned long mq_bytes; /* How many bytes can be allocated to mqueue? */ 418 unsigned long mq_bytes; /* How many bytes can be allocated to mqueue? */
415 unsigned long locked_shm; /* How many pages of mlocked shm ? */ 419 unsigned long locked_shm; /* How many pages of mlocked shm ? */
diff --git a/include/linux/swap.h b/include/linux/swap.h
index c75954f2d868..239f520cc49e 100644
--- a/include/linux/swap.h
+++ b/include/linux/swap.h
@@ -7,6 +7,8 @@
7#include <linux/mmzone.h> 7#include <linux/mmzone.h>
8#include <linux/list.h> 8#include <linux/list.h>
9#include <linux/sched.h> 9#include <linux/sched.h>
10#include <linux/pagemap.h>
11
10#include <asm/atomic.h> 12#include <asm/atomic.h>
11#include <asm/page.h> 13#include <asm/page.h>
12 14
diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
index 5b5f434ac9a0..bfbbe94b297d 100644
--- a/include/linux/sysctl.h
+++ b/include/linux/sysctl.h
@@ -70,6 +70,14 @@ enum
70 CTL_BUS_ISA=1 /* ISA */ 70 CTL_BUS_ISA=1 /* ISA */
71}; 71};
72 72
73/* /proc/sys/fs/inotify/ */
74enum
75{
76 INOTIFY_MAX_USER_INSTANCES=1, /* max instances per user */
77 INOTIFY_MAX_USER_WATCHES=2, /* max watches per user */
78 INOTIFY_MAX_QUEUED_EVENTS=3 /* max queued events per instance */
79};
80
73/* CTL_KERN names: */ 81/* CTL_KERN names: */
74enum 82enum
75{ 83{
@@ -676,6 +684,7 @@ enum
676 FS_XFS=17, /* struct: control xfs parameters */ 684 FS_XFS=17, /* struct: control xfs parameters */
677 FS_AIO_NR=18, /* current system-wide number of aio requests */ 685 FS_AIO_NR=18, /* current system-wide number of aio requests */
678 FS_AIO_MAX_NR=19, /* system-wide maximum number of aio requests */ 686 FS_AIO_MAX_NR=19, /* system-wide maximum number of aio requests */
687 FS_INOTIFY=20, /* inotify submenu */
679}; 688};
680 689
681/* /proc/sys/fs/quota/ */ 690/* /proc/sys/fs/quota/ */
diff --git a/include/linux/usb.h b/include/linux/usb.h
index eb282b581546..724637792996 100644
--- a/include/linux/usb.h
+++ b/include/linux/usb.h
@@ -938,17 +938,17 @@ static inline void usb_fill_int_urb (struct urb *urb,
938} 938}
939 939
940extern void usb_init_urb(struct urb *urb); 940extern void usb_init_urb(struct urb *urb);
941extern struct urb *usb_alloc_urb(int iso_packets, int mem_flags); 941extern struct urb *usb_alloc_urb(int iso_packets, unsigned mem_flags);
942extern void usb_free_urb(struct urb *urb); 942extern void usb_free_urb(struct urb *urb);
943#define usb_put_urb usb_free_urb 943#define usb_put_urb usb_free_urb
944extern struct urb *usb_get_urb(struct urb *urb); 944extern struct urb *usb_get_urb(struct urb *urb);
945extern int usb_submit_urb(struct urb *urb, int mem_flags); 945extern int usb_submit_urb(struct urb *urb, unsigned mem_flags);
946extern int usb_unlink_urb(struct urb *urb); 946extern int usb_unlink_urb(struct urb *urb);
947extern void usb_kill_urb(struct urb *urb); 947extern void usb_kill_urb(struct urb *urb);
948 948
949#define HAVE_USB_BUFFERS 949#define HAVE_USB_BUFFERS
950void *usb_buffer_alloc (struct usb_device *dev, size_t size, 950void *usb_buffer_alloc (struct usb_device *dev, size_t size,
951 int mem_flags, dma_addr_t *dma); 951 unsigned mem_flags, dma_addr_t *dma);
952void usb_buffer_free (struct usb_device *dev, size_t size, 952void usb_buffer_free (struct usb_device *dev, size_t size,
953 void *addr, dma_addr_t dma); 953 void *addr, dma_addr_t dma);
954 954
@@ -1055,7 +1055,7 @@ int usb_sg_init (
1055 struct scatterlist *sg, 1055 struct scatterlist *sg,
1056 int nents, 1056 int nents,
1057 size_t length, 1057 size_t length,
1058 int mem_flags 1058 unsigned mem_flags
1059); 1059);
1060void usb_sg_cancel (struct usb_sg_request *io); 1060void usb_sg_cancel (struct usb_sg_request *io);
1061void usb_sg_wait (struct usb_sg_request *io); 1061void usb_sg_wait (struct usb_sg_request *io);
diff --git a/include/linux/usb_cdc.h b/include/linux/usb_cdc.h
index f22d6beecc73..ba617c372455 100644
--- a/include/linux/usb_cdc.h
+++ b/include/linux/usb_cdc.h
@@ -34,6 +34,7 @@
34#define USB_CDC_ACM_TYPE 0x02 /* acm_descriptor */ 34#define USB_CDC_ACM_TYPE 0x02 /* acm_descriptor */
35#define USB_CDC_UNION_TYPE 0x06 /* union_desc */ 35#define USB_CDC_UNION_TYPE 0x06 /* union_desc */
36#define USB_CDC_COUNTRY_TYPE 0x07 36#define USB_CDC_COUNTRY_TYPE 0x07
37#define USB_CDC_NETWORK_TERMINAL_TYPE 0x0a /* network_terminal_desc */
37#define USB_CDC_ETHERNET_TYPE 0x0f /* ether_desc */ 38#define USB_CDC_ETHERNET_TYPE 0x0f /* ether_desc */
38#define USB_CDC_WHCM_TYPE 0x11 39#define USB_CDC_WHCM_TYPE 0x11
39#define USB_CDC_MDLM_TYPE 0x12 /* mdlm_desc */ 40#define USB_CDC_MDLM_TYPE 0x12 /* mdlm_desc */
@@ -83,6 +84,18 @@ struct usb_cdc_union_desc {
83 /* ... and there could be other slave interfaces */ 84 /* ... and there could be other slave interfaces */
84} __attribute__ ((packed)); 85} __attribute__ ((packed));
85 86
87/* "Network Channel Terminal Functional Descriptor" from CDC spec 5.2.3.11 */
88struct usb_cdc_network_terminal_desc {
89 __u8 bLength;
90 __u8 bDescriptorType;
91 __u8 bDescriptorSubType;
92
93 __u8 bEntityId;
94 __u8 iName;
95 __u8 bChannelIndex;
96 __u8 bPhysicalInterface;
97} __attribute__ ((packed));
98
86/* "Ethernet Networking Functional Descriptor" from CDC spec 5.2.3.16 */ 99/* "Ethernet Networking Functional Descriptor" from CDC spec 5.2.3.16 */
87struct usb_cdc_ether_desc { 100struct usb_cdc_ether_desc {
88 __u8 bLength; 101 __u8 bLength;
diff --git a/include/linux/usb_gadget.h b/include/linux/usb_gadget.h
index b00f127cb447..71e608607324 100644
--- a/include/linux/usb_gadget.h
+++ b/include/linux/usb_gadget.h
@@ -107,18 +107,18 @@ struct usb_ep_ops {
107 int (*disable) (struct usb_ep *ep); 107 int (*disable) (struct usb_ep *ep);
108 108
109 struct usb_request *(*alloc_request) (struct usb_ep *ep, 109 struct usb_request *(*alloc_request) (struct usb_ep *ep,
110 int gfp_flags); 110 unsigned gfp_flags);
111 void (*free_request) (struct usb_ep *ep, struct usb_request *req); 111 void (*free_request) (struct usb_ep *ep, struct usb_request *req);
112 112
113 void *(*alloc_buffer) (struct usb_ep *ep, unsigned bytes, 113 void *(*alloc_buffer) (struct usb_ep *ep, unsigned bytes,
114 dma_addr_t *dma, int gfp_flags); 114 dma_addr_t *dma, unsigned gfp_flags);
115 void (*free_buffer) (struct usb_ep *ep, void *buf, dma_addr_t dma, 115 void (*free_buffer) (struct usb_ep *ep, void *buf, dma_addr_t dma,
116 unsigned bytes); 116 unsigned bytes);
117 // NOTE: on 2.6, drivers may also use dma_map() and 117 // NOTE: on 2.6, drivers may also use dma_map() and
118 // dma_sync_single_*() to directly manage dma overhead. 118 // dma_sync_single_*() to directly manage dma overhead.
119 119
120 int (*queue) (struct usb_ep *ep, struct usb_request *req, 120 int (*queue) (struct usb_ep *ep, struct usb_request *req,
121 int gfp_flags); 121 unsigned gfp_flags);
122 int (*dequeue) (struct usb_ep *ep, struct usb_request *req); 122 int (*dequeue) (struct usb_ep *ep, struct usb_request *req);
123 123
124 int (*set_halt) (struct usb_ep *ep, int value); 124 int (*set_halt) (struct usb_ep *ep, int value);
@@ -214,7 +214,7 @@ usb_ep_disable (struct usb_ep *ep)
214 * Returns the request, or null if one could not be allocated. 214 * Returns the request, or null if one could not be allocated.
215 */ 215 */
216static inline struct usb_request * 216static inline struct usb_request *
217usb_ep_alloc_request (struct usb_ep *ep, int gfp_flags) 217usb_ep_alloc_request (struct usb_ep *ep, unsigned gfp_flags)
218{ 218{
219 return ep->ops->alloc_request (ep, gfp_flags); 219 return ep->ops->alloc_request (ep, gfp_flags);
220} 220}
@@ -254,7 +254,7 @@ usb_ep_free_request (struct usb_ep *ep, struct usb_request *req)
254 */ 254 */
255static inline void * 255static inline void *
256usb_ep_alloc_buffer (struct usb_ep *ep, unsigned len, dma_addr_t *dma, 256usb_ep_alloc_buffer (struct usb_ep *ep, unsigned len, dma_addr_t *dma,
257 int gfp_flags) 257 unsigned gfp_flags)
258{ 258{
259 return ep->ops->alloc_buffer (ep, len, dma, gfp_flags); 259 return ep->ops->alloc_buffer (ep, len, dma, gfp_flags);
260} 260}
@@ -330,7 +330,7 @@ usb_ep_free_buffer (struct usb_ep *ep, void *buf, dma_addr_t dma, unsigned len)
330 * reported when the usb peripheral is disconnected. 330 * reported when the usb peripheral is disconnected.
331 */ 331 */
332static inline int 332static inline int
333usb_ep_queue (struct usb_ep *ep, struct usb_request *req, int gfp_flags) 333usb_ep_queue (struct usb_ep *ep, struct usb_request *req, unsigned gfp_flags)
334{ 334{
335 return ep->ops->queue (ep, req, gfp_flags); 335 return ep->ops->queue (ep, req, gfp_flags);
336} 336}
diff --git a/include/linux/wanrouter.h b/include/linux/wanrouter.h
index 3e89f0f15f49..1b6b76a4eb54 100644
--- a/include/linux/wanrouter.h
+++ b/include/linux/wanrouter.h
@@ -516,8 +516,7 @@ struct wan_device {
516/* Public functions available for device drivers */ 516/* Public functions available for device drivers */
517extern int register_wan_device(struct wan_device *wandev); 517extern int register_wan_device(struct wan_device *wandev);
518extern int unregister_wan_device(char *name); 518extern int unregister_wan_device(char *name);
519unsigned short wanrouter_type_trans(struct sk_buff *skb, 519__be16 wanrouter_type_trans(struct sk_buff *skb, struct net_device *dev);
520 struct net_device *dev);
521int wanrouter_encapsulate(struct sk_buff *skb, struct net_device *dev, 520int wanrouter_encapsulate(struct sk_buff *skb, struct net_device *dev,
522 unsigned short type); 521 unsigned short type);
523 522
diff --git a/include/media/audiochip.h b/include/media/audiochip.h
index f345a61c3bdb..cd831168fdc1 100644
--- a/include/media/audiochip.h
+++ b/include/media/audiochip.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: audiochip.h,v 1.3 2005/06/12 04:19:19 mchehab Exp $ 2 * $Id: audiochip.h,v 1.5 2005/06/16 22:59:16 hhackmann Exp $
3 */ 3 */
4 4
5#ifndef AUDIOCHIP_H 5#ifndef AUDIOCHIP_H
@@ -35,5 +35,4 @@
35 35
36/* misc stuff to pass around config info to i2c chips */ 36/* misc stuff to pass around config info to i2c chips */
37#define AUDC_CONFIG_PINNACLE _IOW('m',32,int) 37#define AUDC_CONFIG_PINNACLE _IOW('m',32,int)
38
39#endif /* AUDIOCHIP_H */ 38#endif /* AUDIOCHIP_H */
diff --git a/include/media/saa6752hs.h b/include/media/saa6752hs.h
index 791bad2b86e9..3b8686ead80d 100644
--- a/include/media/saa6752hs.h
+++ b/include/media/saa6752hs.h
@@ -18,55 +18,6 @@
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/ 19*/
20 20
21#if 0 /* ndef _SAA6752HS_H */
22#define _SAA6752HS_H
23
24enum mpeg_video_bitrate_mode {
25 MPEG_VIDEO_BITRATE_MODE_VBR = 0, /* Variable bitrate */
26 MPEG_VIDEO_BITRATE_MODE_CBR = 1, /* Constant bitrate */
27
28 MPEG_VIDEO_BITRATE_MODE_MAX
29};
30
31enum mpeg_audio_bitrate {
32 MPEG_AUDIO_BITRATE_256 = 0, /* 256 kBit/sec */
33 MPEG_AUDIO_BITRATE_384 = 1, /* 384 kBit/sec */
34
35 MPEG_AUDIO_BITRATE_MAX
36};
37
38enum mpeg_video_format {
39 MPEG_VIDEO_FORMAT_D1 = 0,
40 MPEG_VIDEO_FORMAT_2_3_D1 = 1,
41 MPEG_VIDEO_FORMAT_1_2_D1 = 2,
42 MPEG_VIDEO_FORMAT_SIF = 3,
43
44 MPEG_VIDEO_FORMAT_MAX
45};
46
47#define MPEG_VIDEO_TARGET_BITRATE_MAX 27000
48#define MPEG_VIDEO_MAX_BITRATE_MAX 27000
49#define MPEG_TOTAL_BITRATE_MAX 27000
50#define MPEG_PID_MAX ((1 << 14) - 1)
51
52struct mpeg_params {
53 enum mpeg_video_bitrate_mode video_bitrate_mode;
54 unsigned int video_target_bitrate;
55 unsigned int video_max_bitrate; // only used for VBR
56 enum mpeg_audio_bitrate audio_bitrate;
57 unsigned int total_bitrate;
58
59 unsigned int pmt_pid;
60 unsigned int video_pid;
61 unsigned int audio_pid;
62 unsigned int pcr_pid;
63
64 enum mpeg_video_format video_format;
65};
66
67#define MPEG_SETPARAMS _IOW('6',100,struct mpeg_params)
68
69#endif // _SAA6752HS_H
70 21
71/* 22/*
72 * Local variables: 23 * Local variables:
diff --git a/include/media/tuner.h b/include/media/tuner.h
index 4794c5632360..d8c0a5563289 100644
--- a/include/media/tuner.h
+++ b/include/media/tuner.h
@@ -1,5 +1,5 @@
1 1
2/* $Id: tuner.h,v 1.33 2005/06/21 14:58:08 mkrufky Exp $ 2/* $Id: tuner.h,v 1.42 2005/07/06 09:42:19 mchehab Exp $
3 * 3 *
4 tuner.h - definition for different tuners 4 tuner.h - definition for different tuners
5 5
@@ -26,8 +26,6 @@
26 26
27#include <linux/videodev2.h> 27#include <linux/videodev2.h>
28 28
29#include "id.h"
30
31#define ADDR_UNSET (255) 29#define ADDR_UNSET (255)
32 30
33#define TUNER_TEMIC_PAL 0 /* 4002 FH5 (3X 7756, 9483) */ 31#define TUNER_TEMIC_PAL 0 /* 4002 FH5 (3X 7756, 9483) */
@@ -111,8 +109,6 @@
111#define TUNER_TEA5767 62 /* Only FM Radio Tuner */ 109#define TUNER_TEA5767 62 /* Only FM Radio Tuner */
112#define TUNER_PHILIPS_FMD1216ME_MK3 63 110#define TUNER_PHILIPS_FMD1216ME_MK3 63
113 111
114#define TEA5767_TUNER_NAME "Philips TEA5767HN FM Radio"
115
116#define NOTUNER 0 112#define NOTUNER 0
117#define PAL 1 /* PAL_BG */ 113#define PAL 1 /* PAL_BG */
118#define PAL_I 2 114#define PAL_I 2
@@ -135,19 +131,8 @@
135#define TCL 11 131#define TCL 11
136#define THOMSON 12 132#define THOMSON 12
137 133
138enum v4l_radio_tuner { 134#define TUNER_SET_TYPE_ADDR _IOW('T',3,int)
139 TEA5767_LOW_LO_32768 = 0, 135#define TDA9887_SET_CONFIG _IOW('t',5,int)
140 TEA5767_HIGH_LO_32768 = 1,
141 TEA5767_LOW_LO_13MHz = 2,
142 TEA5767_HIGH_LO_13MHz = 3,
143};
144
145
146#define TUNER_SET_TYPE _IOW('t',1,int) /* set tuner type */
147#define TUNER_SET_TVFREQ _IOW('t',2,int) /* set tv freq */
148#define TUNER_SET_TYPE_ADDR _IOW('T',3,int) /* set tuner type and I2C addr */
149
150#define TDA9887_SET_CONFIG _IOW('t',5,int)
151 136
152/* tv card specific */ 137/* tv card specific */
153# define TDA9887_PRESENT (1<<0) 138# define TDA9887_PRESENT (1<<0)
@@ -169,25 +154,34 @@ enum v4l_radio_tuner {
169#define I2C_ADDR_TDA8290 0x4b 154#define I2C_ADDR_TDA8290 0x4b
170#define I2C_ADDR_TDA8275 0x61 155#define I2C_ADDR_TDA8275 0x61
171 156
172struct tuner_addr { 157enum tuner_mode {
173 enum v4l2_tuner_type v4l2_tuner; 158 T_UNINITIALIZED = 0,
174 unsigned int type; 159 T_RADIO = 1 << V4L2_TUNER_RADIO,
160 T_ANALOG_TV = 1 << V4L2_TUNER_ANALOG_TV,
161 T_DIGITAL_TV = 1 << V4L2_TUNER_DIGITAL_TV,
162 T_STANDBY = 1 << 31
163};
164
165struct tuner_setup {
175 unsigned short addr; 166 unsigned short addr;
167 unsigned int type;
168 unsigned int mode_mask;
176}; 169};
177 170
178struct tuner { 171struct tuner {
179 /* device */ 172 /* device */
180 struct i2c_client i2c; 173 struct i2c_client i2c;
181 174
182 /* state + config */
183 unsigned int initialized;
184 unsigned int type; /* chip type */ 175 unsigned int type; /* chip type */
176
177 unsigned int mode;
178 unsigned int mode_mask; /* Combination of allowable modes */
179
185 unsigned int freq; /* keep track of the current settings */ 180 unsigned int freq; /* keep track of the current settings */
181 unsigned int audmode;
186 v4l2_std_id std; 182 v4l2_std_id std;
187 int using_v4l2;
188 183
189 enum v4l2_tuner_type mode; 184 int using_v4l2;
190 unsigned int input;
191 185
192 /* used by MT2032 */ 186 /* used by MT2032 */
193 unsigned int xogc; 187 unsigned int xogc;
@@ -197,15 +191,11 @@ struct tuner {
197 unsigned char i2c_easy_mode[2]; 191 unsigned char i2c_easy_mode[2];
198 unsigned char i2c_set_freq[8]; 192 unsigned char i2c_set_freq[8];
199 193
200 /* used to keep track of audmode */
201 unsigned int audmode;
202
203 /* function ptrs */ 194 /* function ptrs */
204 void (*tv_freq)(struct i2c_client *c, unsigned int freq); 195 void (*tv_freq)(struct i2c_client *c, unsigned int freq);
205 void (*radio_freq)(struct i2c_client *c, unsigned int freq); 196 void (*radio_freq)(struct i2c_client *c, unsigned int freq);
206 int (*has_signal)(struct i2c_client *c); 197 int (*has_signal)(struct i2c_client *c);
207 int (*is_stereo)(struct i2c_client *c); 198 int (*is_stereo)(struct i2c_client *c);
208 int (*set_tuner)(struct i2c_client *c, struct v4l2_tuner *v);
209}; 199};
210 200
211extern unsigned int tuner_debug; 201extern unsigned int tuner_debug;
@@ -215,6 +205,7 @@ extern int microtune_init(struct i2c_client *c);
215extern int tda8290_init(struct i2c_client *c); 205extern int tda8290_init(struct i2c_client *c);
216extern int tea5767_tuner_init(struct i2c_client *c); 206extern int tea5767_tuner_init(struct i2c_client *c);
217extern int default_tuner_init(struct i2c_client *c); 207extern int default_tuner_init(struct i2c_client *c);
208extern int tea5767_autodetection(struct i2c_client *c);
218 209
219#define tuner_warn(fmt, arg...) \ 210#define tuner_warn(fmt, arg...) \
220 dev_printk(KERN_WARNING , &t->i2c.dev , fmt , ## arg) 211 dev_printk(KERN_WARNING , &t->i2c.dev , fmt , ## arg)
diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
index ef2738159ab3..4a26adfaed71 100644
--- a/include/net/sctp/sctp.h
+++ b/include/net/sctp/sctp.h
@@ -125,7 +125,8 @@
125 */ 125 */
126extern struct sock *sctp_get_ctl_sock(void); 126extern struct sock *sctp_get_ctl_sock(void);
127extern int sctp_copy_local_addr_list(struct sctp_bind_addr *, 127extern int sctp_copy_local_addr_list(struct sctp_bind_addr *,
128 sctp_scope_t, int gfp, int flags); 128 sctp_scope_t, unsigned int __nocast gfp,
129 int flags);
129extern struct sctp_pf *sctp_get_pf_specific(sa_family_t family); 130extern struct sctp_pf *sctp_get_pf_specific(sa_family_t family);
130extern int sctp_register_pf(struct sctp_pf *, sa_family_t); 131extern int sctp_register_pf(struct sctp_pf *, sa_family_t);
131 132
diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
index 88d9fe5975d5..58462164d960 100644
--- a/include/net/sctp/sm.h
+++ b/include/net/sctp/sm.h
@@ -181,17 +181,17 @@ const sctp_sm_table_entry_t *sctp_sm_lookup_event(sctp_event_t,
181int sctp_chunk_iif(const struct sctp_chunk *); 181int sctp_chunk_iif(const struct sctp_chunk *);
182struct sctp_association *sctp_make_temp_asoc(const struct sctp_endpoint *, 182struct sctp_association *sctp_make_temp_asoc(const struct sctp_endpoint *,
183 struct sctp_chunk *, 183 struct sctp_chunk *,
184 int gfp); 184 unsigned int __nocast gfp);
185__u32 sctp_generate_verification_tag(void); 185__u32 sctp_generate_verification_tag(void);
186void sctp_populate_tie_tags(__u8 *cookie, __u32 curTag, __u32 hisTag); 186void sctp_populate_tie_tags(__u8 *cookie, __u32 curTag, __u32 hisTag);
187 187
188/* Prototypes for chunk-building functions. */ 188/* Prototypes for chunk-building functions. */
189struct sctp_chunk *sctp_make_init(const struct sctp_association *, 189struct sctp_chunk *sctp_make_init(const struct sctp_association *,
190 const struct sctp_bind_addr *, 190 const struct sctp_bind_addr *,
191 int gfp, int vparam_len); 191 unsigned int __nocast gfp, int vparam_len);
192struct sctp_chunk *sctp_make_init_ack(const struct sctp_association *, 192struct sctp_chunk *sctp_make_init_ack(const struct sctp_association *,
193 const struct sctp_chunk *, 193 const struct sctp_chunk *,
194 const int gfp, 194 const unsigned int __nocast gfp,
195 const int unkparam_len); 195 const int unkparam_len);
196struct sctp_chunk *sctp_make_cookie_echo(const struct sctp_association *, 196struct sctp_chunk *sctp_make_cookie_echo(const struct sctp_association *,
197 const struct sctp_chunk *); 197 const struct sctp_chunk *);
@@ -265,7 +265,7 @@ int sctp_do_sm(sctp_event_t event_type, sctp_subtype_t subtype,
265 struct sctp_endpoint *, 265 struct sctp_endpoint *,
266 struct sctp_association *asoc, 266 struct sctp_association *asoc,
267 void *event_arg, 267 void *event_arg,
268 int gfp); 268 unsigned int __nocast gfp);
269 269
270/* 2nd level prototypes */ 270/* 2nd level prototypes */
271void sctp_generate_t3_rtx_event(unsigned long peer); 271void sctp_generate_t3_rtx_event(unsigned long peer);
@@ -275,7 +275,8 @@ void sctp_ootb_pkt_free(struct sctp_packet *);
275 275
276struct sctp_association *sctp_unpack_cookie(const struct sctp_endpoint *, 276struct sctp_association *sctp_unpack_cookie(const struct sctp_endpoint *,
277 const struct sctp_association *, 277 const struct sctp_association *,
278 struct sctp_chunk *, int gfp, int *err, 278 struct sctp_chunk *,
279 unsigned int __nocast gfp, int *err,
279 struct sctp_chunk **err_chk_p); 280 struct sctp_chunk **err_chk_p);
280int sctp_addip_addr_config(struct sctp_association *, sctp_param_t, 281int sctp_addip_addr_config(struct sctp_association *, sctp_param_t,
281 struct sockaddr_storage*, int); 282 struct sockaddr_storage*, int);
diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
index 7435528a1747..994009bbe3b4 100644
--- a/include/net/sctp/structs.h
+++ b/include/net/sctp/structs.h
@@ -445,7 +445,8 @@ struct sctp_ssnmap {
445 int malloced; 445 int malloced;
446}; 446};
447 447
448struct sctp_ssnmap *sctp_ssnmap_new(__u16 in, __u16 out, int gfp); 448struct sctp_ssnmap *sctp_ssnmap_new(__u16 in, __u16 out,
449 unsigned int __nocast gfp);
449void sctp_ssnmap_free(struct sctp_ssnmap *map); 450void sctp_ssnmap_free(struct sctp_ssnmap *map);
450void sctp_ssnmap_clear(struct sctp_ssnmap *map); 451void sctp_ssnmap_clear(struct sctp_ssnmap *map);
451 452
@@ -945,7 +946,8 @@ struct sctp_transport {
945 } cacc; 946 } cacc;
946}; 947};
947 948
948struct sctp_transport *sctp_transport_new(const union sctp_addr *, int); 949struct sctp_transport *sctp_transport_new(const union sctp_addr *,
950 unsigned int __nocast);
949void sctp_transport_set_owner(struct sctp_transport *, 951void sctp_transport_set_owner(struct sctp_transport *,
950 struct sctp_association *); 952 struct sctp_association *);
951void sctp_transport_route(struct sctp_transport *, union sctp_addr *, 953void sctp_transport_route(struct sctp_transport *, union sctp_addr *,
@@ -1093,9 +1095,10 @@ void sctp_bind_addr_init(struct sctp_bind_addr *, __u16 port);
1093void sctp_bind_addr_free(struct sctp_bind_addr *); 1095void sctp_bind_addr_free(struct sctp_bind_addr *);
1094int sctp_bind_addr_copy(struct sctp_bind_addr *dest, 1096int sctp_bind_addr_copy(struct sctp_bind_addr *dest,
1095 const struct sctp_bind_addr *src, 1097 const struct sctp_bind_addr *src,
1096 sctp_scope_t scope, int gfp,int flags); 1098 sctp_scope_t scope, unsigned int __nocast gfp,
1099 int flags);
1097int sctp_add_bind_addr(struct sctp_bind_addr *, union sctp_addr *, 1100int sctp_add_bind_addr(struct sctp_bind_addr *, union sctp_addr *,
1098 int gfp); 1101 unsigned int __nocast gfp);
1099int sctp_del_bind_addr(struct sctp_bind_addr *, union sctp_addr *); 1102int sctp_del_bind_addr(struct sctp_bind_addr *, union sctp_addr *);
1100int sctp_bind_addr_match(struct sctp_bind_addr *, const union sctp_addr *, 1103int sctp_bind_addr_match(struct sctp_bind_addr *, const union sctp_addr *,
1101 struct sctp_sock *); 1104 struct sctp_sock *);
@@ -1104,9 +1107,10 @@ union sctp_addr *sctp_find_unmatch_addr(struct sctp_bind_addr *bp,
1104 int addrcnt, 1107 int addrcnt,
1105 struct sctp_sock *opt); 1108 struct sctp_sock *opt);
1106union sctp_params sctp_bind_addrs_to_raw(const struct sctp_bind_addr *bp, 1109union sctp_params sctp_bind_addrs_to_raw(const struct sctp_bind_addr *bp,
1107 int *addrs_len, int gfp); 1110 int *addrs_len,
1111 unsigned int __nocast gfp);
1108int sctp_raw_to_bind_addrs(struct sctp_bind_addr *bp, __u8 *raw, int len, 1112int sctp_raw_to_bind_addrs(struct sctp_bind_addr *bp, __u8 *raw, int len,
1109 __u16 port, int gfp); 1113 __u16 port, unsigned int __nocast gfp);
1110 1114
1111sctp_scope_t sctp_scope(const union sctp_addr *); 1115sctp_scope_t sctp_scope(const union sctp_addr *);
1112int sctp_in_scope(const union sctp_addr *addr, const sctp_scope_t scope); 1116int sctp_in_scope(const union sctp_addr *addr, const sctp_scope_t scope);
@@ -1235,7 +1239,7 @@ static inline struct sctp_endpoint *sctp_ep(struct sctp_ep_common *base)
1235} 1239}
1236 1240
1237/* These are function signatures for manipulating endpoints. */ 1241/* These are function signatures for manipulating endpoints. */
1238struct sctp_endpoint *sctp_endpoint_new(struct sock *, int); 1242struct sctp_endpoint *sctp_endpoint_new(struct sock *, unsigned int __nocast);
1239void sctp_endpoint_free(struct sctp_endpoint *); 1243void sctp_endpoint_free(struct sctp_endpoint *);
1240void sctp_endpoint_put(struct sctp_endpoint *); 1244void sctp_endpoint_put(struct sctp_endpoint *);
1241void sctp_endpoint_hold(struct sctp_endpoint *); 1245void sctp_endpoint_hold(struct sctp_endpoint *);
@@ -1256,7 +1260,7 @@ int sctp_verify_init(const struct sctp_association *asoc, sctp_cid_t,
1256 struct sctp_chunk **err_chunk); 1260 struct sctp_chunk **err_chunk);
1257int sctp_process_init(struct sctp_association *, sctp_cid_t cid, 1261int sctp_process_init(struct sctp_association *, sctp_cid_t cid,
1258 const union sctp_addr *peer, 1262 const union sctp_addr *peer,
1259 sctp_init_chunk_t *init, int gfp); 1263 sctp_init_chunk_t *init, unsigned int __nocast gfp);
1260__u32 sctp_generate_tag(const struct sctp_endpoint *); 1264__u32 sctp_generate_tag(const struct sctp_endpoint *);
1261__u32 sctp_generate_tsn(const struct sctp_endpoint *); 1265__u32 sctp_generate_tsn(const struct sctp_endpoint *);
1262 1266
@@ -1719,7 +1723,7 @@ static inline struct sctp_association *sctp_assoc(struct sctp_ep_common *base)
1719 1723
1720struct sctp_association * 1724struct sctp_association *
1721sctp_association_new(const struct sctp_endpoint *, const struct sock *, 1725sctp_association_new(const struct sctp_endpoint *, const struct sock *,
1722 sctp_scope_t scope, int gfp); 1726 sctp_scope_t scope, unsigned int __nocast gfp);
1723void sctp_association_free(struct sctp_association *); 1727void sctp_association_free(struct sctp_association *);
1724void sctp_association_put(struct sctp_association *); 1728void sctp_association_put(struct sctp_association *);
1725void sctp_association_hold(struct sctp_association *); 1729void sctp_association_hold(struct sctp_association *);
@@ -1735,7 +1739,7 @@ int sctp_assoc_lookup_laddr(struct sctp_association *asoc,
1735 const union sctp_addr *laddr); 1739 const union sctp_addr *laddr);
1736struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *, 1740struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *,
1737 const union sctp_addr *address, 1741 const union sctp_addr *address,
1738 const int gfp, 1742 const unsigned int __nocast gfp,
1739 const int peer_state); 1743 const int peer_state);
1740void sctp_assoc_del_peer(struct sctp_association *asoc, 1744void sctp_assoc_del_peer(struct sctp_association *asoc,
1741 const union sctp_addr *addr); 1745 const union sctp_addr *addr);
@@ -1759,9 +1763,11 @@ void sctp_assoc_rwnd_increase(struct sctp_association *, unsigned);
1759void sctp_assoc_rwnd_decrease(struct sctp_association *, unsigned); 1763void sctp_assoc_rwnd_decrease(struct sctp_association *, unsigned);
1760void sctp_assoc_set_primary(struct sctp_association *, 1764void sctp_assoc_set_primary(struct sctp_association *,
1761 struct sctp_transport *); 1765 struct sctp_transport *);
1762int sctp_assoc_set_bind_addr_from_ep(struct sctp_association *, int); 1766int sctp_assoc_set_bind_addr_from_ep(struct sctp_association *,
1767 unsigned int __nocast);
1763int sctp_assoc_set_bind_addr_from_cookie(struct sctp_association *, 1768int sctp_assoc_set_bind_addr_from_cookie(struct sctp_association *,
1764 struct sctp_cookie*, int gfp); 1769 struct sctp_cookie*,
1770 unsigned int __nocast gfp);
1765 1771
1766int sctp_cmp_addr_exact(const union sctp_addr *ss1, 1772int sctp_cmp_addr_exact(const union sctp_addr *ss1,
1767 const union sctp_addr *ss2); 1773 const union sctp_addr *ss2);
diff --git a/include/net/sctp/ulpevent.h b/include/net/sctp/ulpevent.h
index 1019d83a580a..90fe4bf6754f 100644
--- a/include/net/sctp/ulpevent.h
+++ b/include/net/sctp/ulpevent.h
@@ -88,7 +88,7 @@ struct sctp_ulpevent *sctp_ulpevent_make_assoc_change(
88 __u16 error, 88 __u16 error,
89 __u16 outbound, 89 __u16 outbound,
90 __u16 inbound, 90 __u16 inbound,
91 int gfp); 91 unsigned int __nocast gfp);
92 92
93struct sctp_ulpevent *sctp_ulpevent_make_peer_addr_change( 93struct sctp_ulpevent *sctp_ulpevent_make_peer_addr_change(
94 const struct sctp_association *asoc, 94 const struct sctp_association *asoc,
@@ -96,35 +96,35 @@ struct sctp_ulpevent *sctp_ulpevent_make_peer_addr_change(
96 int flags, 96 int flags,
97 int state, 97 int state,
98 int error, 98 int error,
99 int gfp); 99 unsigned int __nocast gfp);
100 100
101struct sctp_ulpevent *sctp_ulpevent_make_remote_error( 101struct sctp_ulpevent *sctp_ulpevent_make_remote_error(
102 const struct sctp_association *asoc, 102 const struct sctp_association *asoc,
103 struct sctp_chunk *chunk, 103 struct sctp_chunk *chunk,
104 __u16 flags, 104 __u16 flags,
105 int gfp); 105 unsigned int __nocast gfp);
106struct sctp_ulpevent *sctp_ulpevent_make_send_failed( 106struct sctp_ulpevent *sctp_ulpevent_make_send_failed(
107 const struct sctp_association *asoc, 107 const struct sctp_association *asoc,
108 struct sctp_chunk *chunk, 108 struct sctp_chunk *chunk,
109 __u16 flags, 109 __u16 flags,
110 __u32 error, 110 __u32 error,
111 int gfp); 111 unsigned int __nocast gfp);
112 112
113struct sctp_ulpevent *sctp_ulpevent_make_shutdown_event( 113struct sctp_ulpevent *sctp_ulpevent_make_shutdown_event(
114 const struct sctp_association *asoc, 114 const struct sctp_association *asoc,
115 __u16 flags, 115 __u16 flags,
116 int gfp); 116 unsigned int __nocast gfp);
117 117
118struct sctp_ulpevent *sctp_ulpevent_make_pdapi( 118struct sctp_ulpevent *sctp_ulpevent_make_pdapi(
119 const struct sctp_association *asoc, 119 const struct sctp_association *asoc,
120 __u32 indication, int gfp); 120 __u32 indication, unsigned int __nocast gfp);
121 121
122struct sctp_ulpevent *sctp_ulpevent_make_adaption_indication( 122struct sctp_ulpevent *sctp_ulpevent_make_adaption_indication(
123 const struct sctp_association *asoc, int gfp); 123 const struct sctp_association *asoc, unsigned int __nocast gfp);
124 124
125struct sctp_ulpevent *sctp_ulpevent_make_rcvmsg(struct sctp_association *asoc, 125struct sctp_ulpevent *sctp_ulpevent_make_rcvmsg(struct sctp_association *asoc,
126 struct sctp_chunk *chunk, 126 struct sctp_chunk *chunk,
127 int gfp); 127 unsigned int __nocast gfp);
128 128
129void sctp_ulpevent_read_sndrcvinfo(const struct sctp_ulpevent *event, 129void sctp_ulpevent_read_sndrcvinfo(const struct sctp_ulpevent *event,
130 struct msghdr *); 130 struct msghdr *);
diff --git a/include/net/sctp/ulpqueue.h b/include/net/sctp/ulpqueue.h
index 961736d29d21..1a60c6d943c1 100644
--- a/include/net/sctp/ulpqueue.h
+++ b/include/net/sctp/ulpqueue.h
@@ -62,19 +62,22 @@ struct sctp_ulpq *sctp_ulpq_init(struct sctp_ulpq *,
62void sctp_ulpq_free(struct sctp_ulpq *); 62void sctp_ulpq_free(struct sctp_ulpq *);
63 63
64/* Add a new DATA chunk for processing. */ 64/* Add a new DATA chunk for processing. */
65int sctp_ulpq_tail_data(struct sctp_ulpq *, struct sctp_chunk *, int); 65int sctp_ulpq_tail_data(struct sctp_ulpq *, struct sctp_chunk *,
66 unsigned int __nocast);
66 67
67/* Add a new event for propagation to the ULP. */ 68/* Add a new event for propagation to the ULP. */
68int sctp_ulpq_tail_event(struct sctp_ulpq *, struct sctp_ulpevent *ev); 69int sctp_ulpq_tail_event(struct sctp_ulpq *, struct sctp_ulpevent *ev);
69 70
70/* Renege previously received chunks. */ 71/* Renege previously received chunks. */
71void sctp_ulpq_renege(struct sctp_ulpq *, struct sctp_chunk *, int); 72void sctp_ulpq_renege(struct sctp_ulpq *, struct sctp_chunk *,
73 unsigned int __nocast);
72 74
73/* Perform partial delivery. */ 75/* Perform partial delivery. */
74void sctp_ulpq_partial_delivery(struct sctp_ulpq *, struct sctp_chunk *, int); 76void sctp_ulpq_partial_delivery(struct sctp_ulpq *, struct sctp_chunk *,
77 unsigned int __nocast);
75 78
76/* Abort the partial delivery. */ 79/* Abort the partial delivery. */
77void sctp_ulpq_abort_pd(struct sctp_ulpq *, int); 80void sctp_ulpq_abort_pd(struct sctp_ulpq *, unsigned int __nocast);
78 81
79/* Clear the partial data delivery condition on this socket. */ 82/* Clear the partial data delivery condition on this socket. */
80int sctp_clear_pd(struct sock *sk); 83int sctp_clear_pd(struct sock *sk);
diff --git a/include/net/x25device.h b/include/net/x25device.h
index cf36a20ea3c5..d45ae883bd1d 100644
--- a/include/net/x25device.h
+++ b/include/net/x25device.h
@@ -5,8 +5,7 @@
5#include <linux/if_packet.h> 5#include <linux/if_packet.h>
6#include <linux/skbuff.h> 6#include <linux/skbuff.h>
7 7
8static inline unsigned short x25_type_trans(struct sk_buff *skb, 8static inline __be16 x25_type_trans(struct sk_buff *skb, struct net_device *dev)
9 struct net_device *dev)
10{ 9{
11 skb->mac.raw = skb->data; 10 skb->mac.raw = skb->data;
12 skb->input_dev = skb->dev = dev; 11 skb->input_dev = skb->dev = dev;
diff --git a/include/pcmcia/ds.h b/include/pcmcia/ds.h
index 0190e766e1a7..b707a603351b 100644
--- a/include/pcmcia/ds.h
+++ b/include/pcmcia/ds.h
@@ -16,10 +16,13 @@
16#ifndef _LINUX_DS_H 16#ifndef _LINUX_DS_H
17#define _LINUX_DS_H 17#define _LINUX_DS_H
18 18
19#ifdef __KERNEL__
20#include <linux/mod_devicetable.h>
21#endif
22
19#include <pcmcia/bulkmem.h> 23#include <pcmcia/bulkmem.h>
20#include <pcmcia/cs_types.h> 24#include <pcmcia/cs_types.h>
21#include <pcmcia/device_id.h> 25#include <pcmcia/device_id.h>
22#include <linux/mod_devicetable.h>
23 26
24typedef struct tuple_parse_t { 27typedef struct tuple_parse_t {
25 tuple_t tuple; 28 tuple_t tuple;
diff --git a/init/do_mounts.c b/init/do_mounts.c
index b7570c074d0f..1b02be734ccc 100644
--- a/init/do_mounts.c
+++ b/init/do_mounts.c
@@ -7,6 +7,7 @@
7#include <linux/root_dev.h> 7#include <linux/root_dev.h>
8#include <linux/security.h> 8#include <linux/security.h>
9#include <linux/delay.h> 9#include <linux/delay.h>
10#include <linux/mount.h>
10 11
11#include <linux/nfs_fs.h> 12#include <linux/nfs_fs.h>
12#include <linux/nfs_fs_sb.h> 13#include <linux/nfs_fs_sb.h>
diff --git a/init/do_mounts.h b/init/do_mounts.h
index de92bee4f35e..e0a7ac9649e1 100644
--- a/init/do_mounts.h
+++ b/init/do_mounts.h
@@ -9,7 +9,6 @@
9#include <linux/major.h> 9#include <linux/major.h>
10#include <linux/root_dev.h> 10#include <linux/root_dev.h>
11 11
12dev_t name_to_dev_t(char *name);
13void change_floppy(char *fmt, ...); 12void change_floppy(char *fmt, ...);
14void mount_block_root(char *name, int flags); 13void mount_block_root(char *name, int flags);
15void mount_root(void); 14void mount_root(void);
diff --git a/ipc/util.h b/ipc/util.h
index 07d689452363..44348ca5a707 100644
--- a/ipc/util.h
+++ b/ipc/util.h
@@ -67,7 +67,7 @@ int ipc_checkid(struct ipc_ids* ids, struct kern_ipc_perm* ipcp, int uid);
67void kernel_to_ipc64_perm(struct kern_ipc_perm *in, struct ipc64_perm *out); 67void kernel_to_ipc64_perm(struct kern_ipc_perm *in, struct ipc64_perm *out);
68void ipc64_perm_to_ipc_perm(struct ipc64_perm *in, struct ipc_perm *out); 68void ipc64_perm_to_ipc_perm(struct ipc64_perm *in, struct ipc_perm *out);
69 69
70#if defined(__ia64__) || defined(__x86_64__) || defined(__hppa__) 70#if defined(__ia64__) || defined(__x86_64__) || defined(__hppa__) || defined(__XTENSA__)
71 /* On IA-64, we always use the "64-bit version" of the IPC structures. */ 71 /* On IA-64, we always use the "64-bit version" of the IPC structures. */
72# define ipc_parse_version(cmd) IPC_64 72# define ipc_parse_version(cmd) IPC_64
73#else 73#else
diff --git a/kernel/fork.c b/kernel/fork.c
index cdef6cea8900..b65187f0c74e 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -208,8 +208,10 @@ static inline int dup_mmap(struct mm_struct * mm, struct mm_struct * oldmm)
208 struct file *file; 208 struct file *file;
209 209
210 if (mpnt->vm_flags & VM_DONTCOPY) { 210 if (mpnt->vm_flags & VM_DONTCOPY) {
211 long pages = vma_pages(mpnt);
212 mm->total_vm -= pages;
211 __vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file, 213 __vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
212 -vma_pages(mpnt)); 214 -pages);
213 continue; 215 continue;
214 } 216 }
215 charge = 0; 217 charge = 0;
diff --git a/kernel/power/disk.c b/kernel/power/disk.c
index c51a4d96d4eb..3ec789c6b537 100644
--- a/kernel/power/disk.c
+++ b/kernel/power/disk.c
@@ -16,6 +16,8 @@
16#include <linux/device.h> 16#include <linux/device.h>
17#include <linux/delay.h> 17#include <linux/delay.h>
18#include <linux/fs.h> 18#include <linux/fs.h>
19#include <linux/mount.h>
20
19#include "power.h" 21#include "power.h"
20 22
21 23
diff --git a/kernel/power/main.c b/kernel/power/main.c
index c94cb9e95090..71aa0fd22007 100644
--- a/kernel/power/main.c
+++ b/kernel/power/main.c
@@ -19,6 +19,9 @@
19 19
20#include "power.h" 20#include "power.h"
21 21
22/*This is just an arbitrary number */
23#define FREE_PAGE_NUMBER (100)
24
22DECLARE_MUTEX(pm_sem); 25DECLARE_MUTEX(pm_sem);
23 26
24struct pm_ops * pm_ops = NULL; 27struct pm_ops * pm_ops = NULL;
@@ -49,6 +52,7 @@ void pm_set_ops(struct pm_ops * ops)
49static int suspend_prepare(suspend_state_t state) 52static int suspend_prepare(suspend_state_t state)
50{ 53{
51 int error = 0; 54 int error = 0;
55 unsigned int free_pages;
52 56
53 if (!pm_ops || !pm_ops->enter) 57 if (!pm_ops || !pm_ops->enter)
54 return -EPERM; 58 return -EPERM;
@@ -67,6 +71,16 @@ static int suspend_prepare(suspend_state_t state)
67 goto Thaw; 71 goto Thaw;
68 } 72 }
69 73
74 if ((free_pages = nr_free_pages()) < FREE_PAGE_NUMBER) {
75 pr_debug("PM: free some memory\n");
76 shrink_all_memory(FREE_PAGE_NUMBER - free_pages);
77 if (nr_free_pages() < FREE_PAGE_NUMBER) {
78 error = -ENOMEM;
79 printk(KERN_ERR "PM: No enough memory\n");
80 goto Thaw;
81 }
82 }
83
70 if (pm_ops->prepare) { 84 if (pm_ops->prepare) {
71 if ((error = pm_ops->prepare(state))) 85 if ((error = pm_ops->prepare(state)))
72 goto Thaw; 86 goto Thaw;
@@ -194,7 +208,7 @@ int software_suspend(void)
194 208
195int pm_suspend(suspend_state_t state) 209int pm_suspend(suspend_state_t state)
196{ 210{
197 if (state > PM_SUSPEND_ON && state < PM_SUSPEND_MAX) 211 if (state > PM_SUSPEND_ON && state <= PM_SUSPEND_MAX)
198 return enter_state(state); 212 return enter_state(state);
199 return -EINVAL; 213 return -EINVAL;
200} 214}
diff --git a/kernel/power/swsusp.c b/kernel/power/swsusp.c
index 7d7801cd01f0..f2bc71b9fe8b 100644
--- a/kernel/power/swsusp.c
+++ b/kernel/power/swsusp.c
@@ -63,6 +63,7 @@
63#include <linux/console.h> 63#include <linux/console.h>
64#include <linux/highmem.h> 64#include <linux/highmem.h>
65#include <linux/bio.h> 65#include <linux/bio.h>
66#include <linux/mount.h>
66 67
67#include <asm/uaccess.h> 68#include <asm/uaccess.h>
68#include <asm/mmu_context.h> 69#include <asm/mmu_context.h>
@@ -1260,8 +1261,6 @@ static int data_read(struct pbe *pblist)
1260 return error; 1261 return error;
1261} 1262}
1262 1263
1263extern dev_t name_to_dev_t(const char *line);
1264
1265/** 1264/**
1266 * read_pagedir - Read page backup list pages from swap 1265 * read_pagedir - Read page backup list pages from swap
1267 */ 1266 */
diff --git a/kernel/sys_ni.c b/kernel/sys_ni.c
index 29196ce9b40f..42b40ae5eada 100644
--- a/kernel/sys_ni.c
+++ b/kernel/sys_ni.c
@@ -80,6 +80,9 @@ cond_syscall(sys_keyctl);
80cond_syscall(compat_sys_keyctl); 80cond_syscall(compat_sys_keyctl);
81cond_syscall(compat_sys_socketcall); 81cond_syscall(compat_sys_socketcall);
82cond_syscall(sys_set_zone_reclaim); 82cond_syscall(sys_set_zone_reclaim);
83cond_syscall(sys_inotify_init);
84cond_syscall(sys_inotify_add_watch);
85cond_syscall(sys_inotify_rm_watch);
83 86
84/* arch-specific weak syscall entries */ 87/* arch-specific weak syscall entries */
85cond_syscall(sys_pciconfig_read); 88cond_syscall(sys_pciconfig_read);
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 270ee7fadbd8..e60b9c36f1f0 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -146,6 +146,9 @@ extern ctl_table random_table[];
146#ifdef CONFIG_UNIX98_PTYS 146#ifdef CONFIG_UNIX98_PTYS
147extern ctl_table pty_table[]; 147extern ctl_table pty_table[];
148#endif 148#endif
149#ifdef CONFIG_INOTIFY
150extern ctl_table inotify_table[];
151#endif
149 152
150#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT 153#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
151int sysctl_legacy_va_layout; 154int sysctl_legacy_va_layout;
@@ -218,6 +221,7 @@ static ctl_table root_table[] = {
218 .mode = 0555, 221 .mode = 0555,
219 .child = dev_table, 222 .child = dev_table,
220 }, 223 },
224
221 { .ctl_name = 0 } 225 { .ctl_name = 0 }
222}; 226};
223 227
@@ -950,6 +954,14 @@ static ctl_table fs_table[] = {
950 .mode = 0644, 954 .mode = 0644,
951 .proc_handler = &proc_dointvec, 955 .proc_handler = &proc_dointvec,
952 }, 956 },
957#ifdef CONFIG_INOTIFY
958 {
959 .ctl_name = FS_INOTIFY,
960 .procname = "inotify",
961 .mode = 0555,
962 .child = inotify_table,
963 },
964#endif
953#endif 965#endif
954 { 966 {
955 .ctl_name = KERN_SETUID_DUMPABLE, 967 .ctl_name = KERN_SETUID_DUMPABLE,
@@ -968,7 +980,7 @@ static ctl_table debug_table[] = {
968 980
969static ctl_table dev_table[] = { 981static ctl_table dev_table[] = {
970 { .ctl_name = 0 } 982 { .ctl_name = 0 }
971}; 983};
972 984
973extern void init_irq_proc (void); 985extern void init_irq_proc (void);
974 986
diff --git a/kernel/user.c b/kernel/user.c
index 734575d55769..89e562feb1b1 100644
--- a/kernel/user.c
+++ b/kernel/user.c
@@ -120,6 +120,10 @@ struct user_struct * alloc_uid(uid_t uid)
120 atomic_set(&new->processes, 0); 120 atomic_set(&new->processes, 0);
121 atomic_set(&new->files, 0); 121 atomic_set(&new->files, 0);
122 atomic_set(&new->sigpending, 0); 122 atomic_set(&new->sigpending, 0);
123#ifdef CONFIG_INOTIFY
124 atomic_set(&new->inotify_watches, 0);
125 atomic_set(&new->inotify_devs, 0);
126#endif
123 127
124 new->mq_bytes = 0; 128 new->mq_bytes = 0;
125 new->locked_shm = 0; 129 new->locked_shm = 0;
diff --git a/mm/filemap_xip.c b/mm/filemap_xip.c
index 3b6e384b98a6..4553b2c5aab4 100644
--- a/mm/filemap_xip.c
+++ b/mm/filemap_xip.c
@@ -191,7 +191,7 @@ __xip_unmap (struct address_space * mapping,
191 address); 191 address);
192 if (!IS_ERR(pte)) { 192 if (!IS_ERR(pte)) {
193 /* Nuke the page table entry. */ 193 /* Nuke the page table entry. */
194 flush_cache_page(vma, address, pte_pfn(pte)); 194 flush_cache_page(vma, address, pte_pfn(*pte));
195 pteval = ptep_clear_flush(vma, address, pte); 195 pteval = ptep_clear_flush(vma, address, pte);
196 BUG_ON(pte_dirty(pteval)); 196 BUG_ON(pte_dirty(pteval));
197 pte_unmap(pte); 197 pte_unmap(pte);
diff --git a/net/802/fddi.c b/net/802/fddi.c
index ebcf4830d6f1..5ce24c4bb840 100644
--- a/net/802/fddi.c
+++ b/net/802/fddi.c
@@ -122,10 +122,10 @@ static int fddi_rebuild_header(struct sk_buff *skb)
122 * the proper pointer to the start of packet data (skb->data). 122 * the proper pointer to the start of packet data (skb->data).
123 */ 123 */
124 124
125unsigned short fddi_type_trans(struct sk_buff *skb, struct net_device *dev) 125__be16 fddi_type_trans(struct sk_buff *skb, struct net_device *dev)
126{ 126{
127 struct fddihdr *fddi = (struct fddihdr *)skb->data; 127 struct fddihdr *fddi = (struct fddihdr *)skb->data;
128 unsigned short type; 128 __be16 type;
129 129
130 /* 130 /*
131 * Set mac.raw field to point to FC byte, set data field to point 131 * Set mac.raw field to point to FC byte, set data field to point
diff --git a/net/8021q/Kconfig b/net/8021q/Kconfig
new file mode 100644
index 000000000000..c4a382e450e2
--- /dev/null
+++ b/net/8021q/Kconfig
@@ -0,0 +1,19 @@
1#
2# Configuration for 802.1Q VLAN support
3#
4
5config VLAN_8021Q
6 tristate "802.1Q VLAN Support"
7 ---help---
8 Select this and you will be able to create 802.1Q VLAN interfaces
9 on your ethernet interfaces. 802.1Q VLAN supports almost
10 everything a regular ethernet interface does, including
11 firewalling, bridging, and of course IP traffic. You will need
12 the 'vconfig' tool from the VLAN project in order to effectively
13 use VLANs. See the VLAN web page for more information:
14 <http://www.candelatech.com/~greear/vlan.html>
15
16 To compile this code as a module, choose M here: the module
17 will be called 8021q.
18
19 If unsure, say N.
diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
index 1f6d31670bc7..91e412b0ab00 100644
--- a/net/8021q/vlan.c
+++ b/net/8021q/vlan.c
@@ -578,6 +578,14 @@ static int vlan_device_event(struct notifier_block *unused, unsigned long event,
578 if (!vlandev) 578 if (!vlandev)
579 continue; 579 continue;
580 580
581 if (netif_carrier_ok(dev)) {
582 if (!netif_carrier_ok(vlandev))
583 netif_carrier_on(vlandev);
584 } else {
585 if (netif_carrier_ok(vlandev))
586 netif_carrier_off(vlandev);
587 }
588
581 if ((vlandev->state & VLAN_LINK_STATE_MASK) != flgs) { 589 if ((vlandev->state & VLAN_LINK_STATE_MASK) != flgs) {
582 vlandev->state = (vlandev->state &~ VLAN_LINK_STATE_MASK) 590 vlandev->state = (vlandev->state &~ VLAN_LINK_STATE_MASK)
583 | flgs; 591 | flgs;
diff --git a/net/Kconfig b/net/Kconfig
index 9251b28e8d5d..2684e809a649 100644
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -2,7 +2,7 @@
2# Network configuration 2# Network configuration
3# 3#
4 4
5menu "Networking support" 5menu "Networking"
6 6
7config NET 7config NET
8 bool "Networking support" 8 bool "Networking support"
@@ -10,7 +10,9 @@ config NET
10 Unless you really know what you are doing, you should say Y here. 10 Unless you really know what you are doing, you should say Y here.
11 The reason is that some programs need kernel networking support even 11 The reason is that some programs need kernel networking support even
12 when running on a stand-alone machine that isn't connected to any 12 when running on a stand-alone machine that isn't connected to any
13 other computer. If you are upgrading from an older kernel, you 13 other computer.
14
15 If you are upgrading from an older kernel, you
14 should consider updating your networking tools too because changes 16 should consider updating your networking tools too because changes
15 in the kernel and the tools often go hand in hand. The tools are 17 in the kernel and the tools often go hand in hand. The tools are
16 contained in the package net-tools, the location and version number 18 contained in the package net-tools, the location and version number
@@ -20,57 +22,14 @@ config NET
20 recommended to read the NET-HOWTO, available from 22 recommended to read the NET-HOWTO, available from
21 <http://www.tldp.org/docs.html#howto>. 23 <http://www.tldp.org/docs.html#howto>.
22 24
23menu "Networking options" 25# Make sure that all config symbols are dependent on NET
24 depends on NET 26if NET
25
26config PACKET
27 tristate "Packet socket"
28 ---help---
29 The Packet protocol is used by applications which communicate
30 directly with network devices without an intermediate network
31 protocol implemented in the kernel, e.g. tcpdump. If you want them
32 to work, choose Y.
33 27
34 To compile this driver as a module, choose M here: the module will 28menu "Networking options"
35 be called af_packet.
36
37 If unsure, say Y.
38
39config PACKET_MMAP
40 bool "Packet socket: mmapped IO"
41 depends on PACKET
42 help
43 If you say Y here, the Packet protocol driver will use an IO
44 mechanism that results in faster communication.
45
46 If unsure, say N.
47
48config UNIX
49 tristate "Unix domain sockets"
50 ---help---
51 If you say Y here, you will include support for Unix domain sockets;
52 sockets are the standard Unix mechanism for establishing and
53 accessing network connections. Many commonly used programs such as
54 the X Window system and syslog use these sockets even if your
55 machine is not connected to any network. Unless you are working on
56 an embedded system or something similar, you therefore definitely
57 want to say Y here.
58
59 To compile this driver as a module, choose M here: the module will be
60 called unix. Note that several important services won't work
61 correctly if you say M here and then neglect to load the module.
62
63 Say Y unless you know what you are doing.
64
65config NET_KEY
66 tristate "PF_KEY sockets"
67 select XFRM
68 ---help---
69 PF_KEYv2 socket family, compatible to KAME ones.
70 They are required if you are going to use IPsec tools ported
71 from KAME.
72 29
73 Say Y unless you know what you are doing. 30source "net/packet/Kconfig"
31source "net/unix/Kconfig"
32source "net/xfrm/Kconfig"
74 33
75config INET 34config INET
76 bool "TCP/IP networking" 35 bool "TCP/IP networking"
@@ -94,30 +53,12 @@ config INET
94 53
95 Short answer: say Y. 54 Short answer: say Y.
96 55
56if INET
97source "net/ipv4/Kconfig" 57source "net/ipv4/Kconfig"
98
99# IPv6 as module will cause a CRASH if you try to unload it
100config IPV6
101 tristate "The IPv6 protocol"
102 depends on INET
103 default m
104 select CRYPTO if IPV6_PRIVACY
105 select CRYPTO_MD5 if IPV6_PRIVACY
106 ---help---
107 This is complemental support for the IP version 6.
108 You will still be able to do traditional IPv4 networking as well.
109
110 For general information about IPv6, see
111 <http://playground.sun.com/pub/ipng/html/ipng-main.html>.
112 For Linux IPv6 development information, see <http://www.linux-ipv6.org>.
113 For specific information about IPv6 under Linux, read the HOWTO at
114 <http://www.bieringer.de/linux/IPv6/>.
115
116 To compile this protocol support as a module, choose M here: the
117 module will be called ipv6.
118
119source "net/ipv6/Kconfig" 58source "net/ipv6/Kconfig"
120 59
60endif # if INET
61
121menuconfig NETFILTER 62menuconfig NETFILTER
122 bool "Network packet filtering (replaces ipchains)" 63 bool "Network packet filtering (replaces ipchains)"
123 ---help--- 64 ---help---
@@ -206,269 +147,16 @@ source "net/bridge/netfilter/Kconfig"
206 147
207endif 148endif
208 149
209config XFRM
210 bool
211 depends on NET
212
213source "net/xfrm/Kconfig"
214
215source "net/sctp/Kconfig" 150source "net/sctp/Kconfig"
216 151source "net/atm/Kconfig"
217config ATM 152source "net/bridge/Kconfig"
218 tristate "Asynchronous Transfer Mode (ATM) (EXPERIMENTAL)" 153source "net/8021q/Kconfig"
219 depends on EXPERIMENTAL
220 ---help---
221 ATM is a high-speed networking technology for Local Area Networks
222 and Wide Area Networks. It uses a fixed packet size and is
223 connection oriented, allowing for the negotiation of minimum
224 bandwidth requirements.
225
226 In order to participate in an ATM network, your Linux box needs an
227 ATM networking card. If you have that, say Y here and to the driver
228 of your ATM card below.
229
230 Note that you need a set of user-space programs to actually make use
231 of ATM. See the file <file:Documentation/networking/atm.txt> for
232 further details.
233
234config ATM_CLIP
235 tristate "Classical IP over ATM (EXPERIMENTAL)"
236 depends on ATM && INET
237 help
238 Classical IP over ATM for PVCs and SVCs, supporting InARP and
239 ATMARP. If you want to communication with other IP hosts on your ATM
240 network, you will typically either say Y here or to "LAN Emulation
241 (LANE)" below.
242
243config ATM_CLIP_NO_ICMP
244 bool "Do NOT send ICMP if no neighbour (EXPERIMENTAL)"
245 depends on ATM_CLIP
246 help
247 Normally, an "ICMP host unreachable" message is sent if a neighbour
248 cannot be reached because there is no VC to it in the kernel's
249 ATMARP table. This may cause problems when ATMARP table entries are
250 briefly removed during revalidation. If you say Y here, packets to
251 such neighbours are silently discarded instead.
252
253config ATM_LANE
254 tristate "LAN Emulation (LANE) support (EXPERIMENTAL)"
255 depends on ATM
256 help
257 LAN Emulation emulates services of existing LANs across an ATM
258 network. Besides operating as a normal ATM end station client, Linux
259 LANE client can also act as an proxy client bridging packets between
260 ELAN and Ethernet segments. You need LANE if you want to try MPOA.
261
262config ATM_MPOA
263 tristate "Multi-Protocol Over ATM (MPOA) support (EXPERIMENTAL)"
264 depends on ATM && INET && ATM_LANE!=n
265 help
266 Multi-Protocol Over ATM allows ATM edge devices such as routers,
267 bridges and ATM attached hosts establish direct ATM VCs across
268 subnetwork boundaries. These shortcut connections bypass routers
269 enhancing overall network performance.
270
271config ATM_BR2684
272 tristate "RFC1483/2684 Bridged protocols"
273 depends on ATM && INET
274 help
275 ATM PVCs can carry ethernet PDUs according to rfc2684 (formerly 1483)
276 This device will act like an ethernet from the kernels point of view,
277 with the traffic being carried by ATM PVCs (currently 1 PVC/device).
278 This is sometimes used over DSL lines. If in doubt, say N.
279
280config ATM_BR2684_IPFILTER
281 bool "Per-VC IP filter kludge"
282 depends on ATM_BR2684
283 help
284 This is an experimental mechanism for users who need to terminating a
285 large number of IP-only vcc's. Do not enable this unless you are sure
286 you know what you are doing.
287
288config BRIDGE
289 tristate "802.1d Ethernet Bridging"
290 ---help---
291 If you say Y here, then your Linux box will be able to act as an
292 Ethernet bridge, which means that the different Ethernet segments it
293 is connected to will appear as one Ethernet to the participants.
294 Several such bridges can work together to create even larger
295 networks of Ethernets using the IEEE 802.1 spanning tree algorithm.
296 As this is a standard, Linux bridges will cooperate properly with
297 other third party bridge products.
298
299 In order to use the Ethernet bridge, you'll need the bridge
300 configuration tools; see <file:Documentation/networking/bridge.txt>
301 for location. Please read the Bridge mini-HOWTO for more
302 information.
303
304 If you enable iptables support along with the bridge support then you
305 turn your bridge into a bridging IP firewall.
306 iptables will then see the IP packets being bridged, so you need to
307 take this into account when setting up your firewall rules.
308 Enabling arptables support when bridging will let arptables see
309 bridged ARP traffic in the arptables FORWARD chain.
310
311 To compile this code as a module, choose M here: the module
312 will be called bridge.
313
314 If unsure, say N.
315
316config VLAN_8021Q
317 tristate "802.1Q VLAN Support"
318 ---help---
319 Select this and you will be able to create 802.1Q VLAN interfaces
320 on your ethernet interfaces. 802.1Q VLAN supports almost
321 everything a regular ethernet interface does, including
322 firewalling, bridging, and of course IP traffic. You will need
323 the 'vconfig' tool from the VLAN project in order to effectively
324 use VLANs. See the VLAN web page for more information:
325 <http://www.candelatech.com/~greear/vlan.html>
326
327 To compile this code as a module, choose M here: the module
328 will be called 8021q.
329
330 If unsure, say N.
331
332config DECNET
333 tristate "DECnet Support"
334 ---help---
335 The DECnet networking protocol was used in many products made by
336 Digital (now Compaq). It provides reliable stream and sequenced
337 packet communications over which run a variety of services similar
338 to those which run over TCP/IP.
339
340 To find some tools to use with the kernel layer support, please
341 look at Patrick Caulfield's web site:
342 <http://linux-decnet.sourceforge.net/>.
343
344 More detailed documentation is available in
345 <file:Documentation/networking/decnet.txt>.
346
347 Be sure to say Y to "/proc file system support" and "Sysctl support"
348 below when using DECnet, since you will need sysctl support to aid
349 in configuration at run time.
350
351 The DECnet code is also available as a module ( = code which can be
352 inserted in and removed from the running kernel whenever you want).
353 The module is called decnet.
354
355source "net/decnet/Kconfig" 154source "net/decnet/Kconfig"
356
357source "net/llc/Kconfig" 155source "net/llc/Kconfig"
358
359config IPX
360 tristate "The IPX protocol"
361 select LLC
362 ---help---
363 This is support for the Novell networking protocol, IPX, commonly
364 used for local networks of Windows machines. You need it if you
365 want to access Novell NetWare file or print servers using the Linux
366 Novell client ncpfs (available from
367 <ftp://platan.vc.cvut.cz/pub/linux/ncpfs/>) or from
368 within the Linux DOS emulator DOSEMU (read the DOSEMU-HOWTO,
369 available from <http://www.tldp.org/docs.html#howto>). In order
370 to do the former, you'll also have to say Y to "NCP file system
371 support", below.
372
373 IPX is similar in scope to IP, while SPX, which runs on top of IPX,
374 is similar to TCP. There is also experimental support for SPX in
375 Linux (see "SPX networking", below).
376
377 To turn your Linux box into a fully featured NetWare file server and
378 IPX router, say Y here and fetch either lwared from
379 <ftp://ibiblio.org/pub/Linux/system/network/daemons/> or
380 mars_nwe from <ftp://www.compu-art.de/mars_nwe/>. For more
381 information, read the IPX-HOWTO available from
382 <http://www.tldp.org/docs.html#howto>.
383
384 General information about how to connect Linux, Windows machines and
385 Macs is on the WWW at <http://www.eats.com/linux_mac_win.html>.
386
387 The IPX driver would enlarge your kernel by about 16 KB. To compile
388 this driver as a module, choose M here: the module will be called ipx.
389 Unless you want to integrate your Linux box with a local Novell
390 network, say N.
391
392source "net/ipx/Kconfig" 156source "net/ipx/Kconfig"
393
394config ATALK
395 tristate "Appletalk protocol support"
396 select LLC
397 ---help---
398 AppleTalk is the protocol that Apple computers can use to communicate
399 on a network. If your Linux box is connected to such a network and you
400 wish to connect to it, say Y. You will need to use the netatalk package
401 so that your Linux box can act as a print and file server for Macs as
402 well as access AppleTalk printers. Check out
403 <http://www.zettabyte.net/netatalk/> on the WWW for details.
404 EtherTalk is the name used for AppleTalk over Ethernet and the
405 cheaper and slower LocalTalk is AppleTalk over a proprietary Apple
406 network using serial links. EtherTalk and LocalTalk are fully
407 supported by Linux.
408
409 General information about how to connect Linux, Windows machines and
410 Macs is on the WWW at <http://www.eats.com/linux_mac_win.html>. The
411 NET-3-HOWTO, available from
412 <http://www.tldp.org/docs.html#howto>, contains valuable
413 information as well.
414
415 To compile this driver as a module, choose M here: the module will be
416 called appletalk. You almost certainly want to compile it as a
417 module so you can restart your AppleTalk stack without rebooting
418 your machine. I hear that the GNU boycott of Apple is over, so
419 even politically correct people are allowed to say Y here.
420
421source "drivers/net/appletalk/Kconfig" 157source "drivers/net/appletalk/Kconfig"
422 158source "net/x25/Kconfig"
423config X25 159source "net/lapb/Kconfig"
424 tristate "CCITT X.25 Packet Layer (EXPERIMENTAL)"
425 depends on EXPERIMENTAL
426 ---help---
427 X.25 is a set of standardized network protocols, similar in scope to
428 frame relay; the one physical line from your box to the X.25 network
429 entry point can carry several logical point-to-point connections
430 (called "virtual circuits") to other computers connected to the X.25
431 network. Governments, banks, and other organizations tend to use it
432 to connect to each other or to form Wide Area Networks (WANs). Many
433 countries have public X.25 networks. X.25 consists of two
434 protocols: the higher level Packet Layer Protocol (PLP) (say Y here
435 if you want that) and the lower level data link layer protocol LAPB
436 (say Y to "LAPB Data Link Driver" below if you want that).
437
438 You can read more about X.25 at <http://www.sangoma.com/x25.htm> and
439 <http://www.cisco.com/univercd/cc/td/doc/product/software/ios11/cbook/cx25.htm>.
440 Information about X.25 for Linux is contained in the files
441 <file:Documentation/networking/x25.txt> and
442 <file:Documentation/networking/x25-iface.txt>.
443
444 One connects to an X.25 network either with a dedicated network card
445 using the X.21 protocol (not yet supported by Linux) or one can do
446 X.25 over a standard telephone line using an ordinary modem (say Y
447 to "X.25 async driver" below) or over Ethernet using an ordinary
448 Ethernet card and the LAPB over Ethernet (say Y to "LAPB Data Link
449 Driver" and "LAPB over Ethernet driver" below).
450
451 To compile this driver as a module, choose M here: the module
452 will be called x25. If unsure, say N.
453
454config LAPB
455 tristate "LAPB Data Link Driver (EXPERIMENTAL)"
456 depends on EXPERIMENTAL
457 ---help---
458 Link Access Procedure, Balanced (LAPB) is the data link layer (i.e.
459 the lower) part of the X.25 protocol. It offers a reliable
460 connection service to exchange data frames with one other host, and
461 it is used to transport higher level protocols (mostly X.25 Packet
462 Layer, the higher part of X.25, but others are possible as well).
463 Usually, LAPB is used with specialized X.21 network cards, but Linux
464 currently supports LAPB only over Ethernet connections. If you want
465 to use LAPB connections over Ethernet, say Y here and to "LAPB over
466 Ethernet driver" below. Read
467 <file:Documentation/networking/lapb-module.txt> for technical
468 details.
469
470 To compile this driver as a module, choose M here: the
471 module will be called lapb. If unsure, say N.
472 160
473config NET_DIVERT 161config NET_DIVERT
474 bool "Frame Diverter (EXPERIMENTAL)" 162 bool "Frame Diverter (EXPERIMENTAL)"
@@ -496,107 +184,10 @@ config NET_DIVERT
496 184
497 If unsure, say N. 185 If unsure, say N.
498 186
499config ECONET 187source "net/econet/Kconfig"
500 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)" 188source "net/wanrouter/Kconfig"
501 depends on EXPERIMENTAL && INET
502 ---help---
503 Econet is a fairly old and slow networking protocol mainly used by
504 Acorn computers to access file and print servers. It uses native
505 Econet network cards. AUN is an implementation of the higher level
506 parts of Econet that runs over ordinary Ethernet connections, on
507 top of the UDP packet protocol, which in turn runs on top of the
508 Internet protocol IP.
509
510 If you say Y here, you can choose with the next two options whether
511 to send Econet/AUN traffic over a UDP Ethernet connection or over
512 a native Econet network card.
513
514 To compile this driver as a module, choose M here: the module
515 will be called econet.
516
517config ECONET_AUNUDP
518 bool "AUN over UDP"
519 depends on ECONET
520 help
521 Say Y here if you want to send Econet/AUN traffic over a UDP
522 connection (UDP is a packet based protocol that runs on top of the
523 Internet protocol IP) using an ordinary Ethernet network card.
524
525config ECONET_NATIVE
526 bool "Native Econet"
527 depends on ECONET
528 help
529 Say Y here if you have a native Econet network card installed in
530 your computer.
531
532config WAN_ROUTER
533 tristate "WAN router"
534 depends on EXPERIMENTAL
535 ---help---
536 Wide Area Networks (WANs), such as X.25, frame relay and leased
537 lines, are used to interconnect Local Area Networks (LANs) over vast
538 distances with data transfer rates significantly higher than those
539 achievable with commonly used asynchronous modem connections.
540 Usually, a quite expensive external device called a `WAN router' is
541 needed to connect to a WAN.
542
543 As an alternative, WAN routing can be built into the Linux kernel.
544 With relatively inexpensive WAN interface cards available on the
545 market, a perfectly usable router can be built for less than half
546 the price of an external router. If you have one of those cards and
547 wish to use your Linux box as a WAN router, say Y here and also to
548 the WAN driver for your card, below. You will then need the
549 wan-tools package which is available from <ftp://ftp.sangoma.com/>.
550 Read <file:Documentation/networking/wan-router.txt> for more
551 information.
552
553 To compile WAN routing support as a module, choose M here: the
554 module will be called wanrouter.
555
556 If unsure, say N.
557
558menu "QoS and/or fair queueing"
559
560config NET_SCHED
561 bool "QoS and/or fair queueing"
562 ---help---
563 When the kernel has several packets to send out over a network
564 device, it has to decide which ones to send first, which ones to
565 delay, and which ones to drop. This is the job of the packet
566 scheduler, and several different algorithms for how to do this
567 "fairly" have been proposed.
568
569 If you say N here, you will get the standard packet scheduler, which
570 is a FIFO (first come, first served). If you say Y here, you will be
571 able to choose from among several alternative algorithms which can
572 then be attached to different network devices. This is useful for
573 example if some of your network devices are real time devices that
574 need a certain minimum data flow rate, or if you need to limit the
575 maximum data flow rate for traffic which matches specified criteria.
576 This code is considered to be experimental.
577
578 To administer these schedulers, you'll need the user-level utilities
579 from the package iproute2+tc at <ftp://ftp.tux.org/pub/net/ip-routing/>.
580 That package also contains some documentation; for more, check out
581 <http://snafu.freedom.org/linux2.2/iproute-notes.html>.
582
583 This Quality of Service (QoS) support will enable you to use
584 Differentiated Services (diffserv) and Resource Reservation Protocol
585 (RSVP) on your Linux router if you also say Y to "QoS support",
586 "Packet classifier API" and to some classifiers below. Documentation
587 and software is at <http://diffserv.sourceforge.net/>.
588
589 If you say Y here and to "/proc file system" below, you will be able
590 to read status information about packet schedulers from the file
591 /proc/net/psched.
592
593 The available schedulers are listed in the following questions; you
594 can say Y to as many as you like. If unsure, say N now.
595
596source "net/sched/Kconfig" 189source "net/sched/Kconfig"
597 190
598endmenu
599
600menu "Network testing" 191menu "Network testing"
601 192
602config NET_PKTGEN 193config NET_PKTGEN
@@ -635,12 +226,9 @@ config NET_POLL_CONTROLLER
635 def_bool NETPOLL 226 def_bool NETPOLL
636 227
637source "net/ax25/Kconfig" 228source "net/ax25/Kconfig"
638
639source "net/irda/Kconfig" 229source "net/irda/Kconfig"
640
641source "net/bluetooth/Kconfig" 230source "net/bluetooth/Kconfig"
642 231
643source "drivers/net/Kconfig" 232endif # if NET
644 233endmenu # Networking
645endmenu
646 234
diff --git a/net/atm/Kconfig b/net/atm/Kconfig
new file mode 100644
index 000000000000..bea2426229b1
--- /dev/null
+++ b/net/atm/Kconfig
@@ -0,0 +1,74 @@
1#
2# Asynchronous Transfer Mode (ATM) (EXPERIMENTAL)
3#
4
5config ATM
6 tristate "Asynchronous Transfer Mode (ATM) (EXPERIMENTAL)"
7 depends on EXPERIMENTAL
8 ---help---
9 ATM is a high-speed networking technology for Local Area Networks
10 and Wide Area Networks. It uses a fixed packet size and is
11 connection oriented, allowing for the negotiation of minimum
12 bandwidth requirements.
13
14 In order to participate in an ATM network, your Linux box needs an
15 ATM networking card. If you have that, say Y here and to the driver
16 of your ATM card below.
17
18 Note that you need a set of user-space programs to actually make use
19 of ATM. See the file <file:Documentation/networking/atm.txt> for
20 further details.
21
22config ATM_CLIP
23 tristate "Classical IP over ATM (EXPERIMENTAL)"
24 depends on ATM && INET
25 help
26 Classical IP over ATM for PVCs and SVCs, supporting InARP and
27 ATMARP. If you want to communication with other IP hosts on your ATM
28 network, you will typically either say Y here or to "LAN Emulation
29 (LANE)" below.
30
31config ATM_CLIP_NO_ICMP
32 bool "Do NOT send ICMP if no neighbour (EXPERIMENTAL)"
33 depends on ATM_CLIP
34 help
35 Normally, an "ICMP host unreachable" message is sent if a neighbour
36 cannot be reached because there is no VC to it in the kernel's
37 ATMARP table. This may cause problems when ATMARP table entries are
38 briefly removed during revalidation. If you say Y here, packets to
39 such neighbours are silently discarded instead.
40
41config ATM_LANE
42 tristate "LAN Emulation (LANE) support (EXPERIMENTAL)"
43 depends on ATM
44 help
45 LAN Emulation emulates services of existing LANs across an ATM
46 network. Besides operating as a normal ATM end station client, Linux
47 LANE client can also act as an proxy client bridging packets between
48 ELAN and Ethernet segments. You need LANE if you want to try MPOA.
49
50config ATM_MPOA
51 tristate "Multi-Protocol Over ATM (MPOA) support (EXPERIMENTAL)"
52 depends on ATM && INET && ATM_LANE!=n
53 help
54 Multi-Protocol Over ATM allows ATM edge devices such as routers,
55 bridges and ATM attached hosts establish direct ATM VCs across
56 subnetwork boundaries. These shortcut connections bypass routers
57 enhancing overall network performance.
58
59config ATM_BR2684
60 tristate "RFC1483/2684 Bridged protocols"
61 depends on ATM && INET
62 help
63 ATM PVCs can carry ethernet PDUs according to rfc2684 (formerly 1483)
64 This device will act like an ethernet from the kernels point of view,
65 with the traffic being carried by ATM PVCs (currently 1 PVC/device).
66 This is sometimes used over DSL lines. If in doubt, say N.
67
68config ATM_BR2684_IPFILTER
69 bool "Per-VC IP filter kludge"
70 depends on ATM_BR2684
71 help
72 This is an experimental mechanism for users who need to terminating a
73 large number of IP-only vcc's. Do not enable this unless you are sure
74 you know what you are doing.
diff --git a/net/atm/br2684.c b/net/atm/br2684.c
index e6954cf1459d..289956c4dd3e 100644
--- a/net/atm/br2684.c
+++ b/net/atm/br2684.c
@@ -289,8 +289,7 @@ xmit will add the additional header part in that case */
289 * This is similar to eth_type_trans, which cannot be used because of 289 * This is similar to eth_type_trans, which cannot be used because of
290 * our dev->hard_header_len 290 * our dev->hard_header_len
291 */ 291 */
292static inline unsigned short br_type_trans(struct sk_buff *skb, 292static inline __be16 br_type_trans(struct sk_buff *skb, struct net_device *dev)
293 struct net_device *dev)
294{ 293{
295 struct ethhdr *eth; 294 struct ethhdr *eth;
296 unsigned char *rawp; 295 unsigned char *rawp;
diff --git a/net/bridge/Kconfig b/net/bridge/Kconfig
new file mode 100644
index 000000000000..db23d59746cf
--- /dev/null
+++ b/net/bridge/Kconfig
@@ -0,0 +1,31 @@
1#
2# 802.1d Ethernet Bridging
3#
4
5config BRIDGE
6 tristate "802.1d Ethernet Bridging"
7 ---help---
8 If you say Y here, then your Linux box will be able to act as an
9 Ethernet bridge, which means that the different Ethernet segments it
10 is connected to will appear as one Ethernet to the participants.
11 Several such bridges can work together to create even larger
12 networks of Ethernets using the IEEE 802.1 spanning tree algorithm.
13 As this is a standard, Linux bridges will cooperate properly with
14 other third party bridge products.
15
16 In order to use the Ethernet bridge, you'll need the bridge
17 configuration tools; see <file:Documentation/networking/bridge.txt>
18 for location. Please read the Bridge mini-HOWTO for more
19 information.
20
21 If you enable iptables support along with the bridge support then you
22 turn your bridge into a bridging IP firewall.
23 iptables will then see the IP packets being bridged, so you need to
24 take this into account when setting up your firewall rules.
25 Enabling arptables support when bridging will let arptables see
26 bridged ARP traffic in the arptables FORWARD chain.
27
28 To compile this code as a module, choose M here: the module
29 will be called bridge.
30
31 If unsure, say N.
diff --git a/net/decnet/Kconfig b/net/decnet/Kconfig
index 2101da542ba8..92f2ec46fd22 100644
--- a/net/decnet/Kconfig
+++ b/net/decnet/Kconfig
@@ -1,6 +1,29 @@
1# 1#
2# DECnet configuration 2# DECnet configuration
3# 3#
4config DECNET
5 tristate "DECnet Support"
6 ---help---
7 The DECnet networking protocol was used in many products made by
8 Digital (now Compaq). It provides reliable stream and sequenced
9 packet communications over which run a variety of services similar
10 to those which run over TCP/IP.
11
12 To find some tools to use with the kernel layer support, please
13 look at Patrick Caulfield's web site:
14 <http://linux-decnet.sourceforge.net/>.
15
16 More detailed documentation is available in
17 <file:Documentation/networking/decnet.txt>.
18
19 Be sure to say Y to "/proc file system support" and "Sysctl support"
20 below when using DECnet, since you will need sysctl support to aid
21 in configuration at run time.
22
23 The DECnet code is also available as a module ( = code which can be
24 inserted in and removed from the running kernel whenever you want).
25 The module is called decnet.
26
4config DECNET_ROUTER 27config DECNET_ROUTER
5 bool "DECnet: router support (EXPERIMENTAL)" 28 bool "DECnet: router support (EXPERIMENTAL)"
6 depends on DECNET && EXPERIMENTAL 29 depends on DECNET && EXPERIMENTAL
diff --git a/net/econet/Kconfig b/net/econet/Kconfig
new file mode 100644
index 000000000000..39a2d2975e0e
--- /dev/null
+++ b/net/econet/Kconfig
@@ -0,0 +1,36 @@
1#
2# Acorn Econet/AUN protocols
3#
4
5config ECONET
6 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
7 depends on EXPERIMENTAL && INET
8 ---help---
9 Econet is a fairly old and slow networking protocol mainly used by
10 Acorn computers to access file and print servers. It uses native
11 Econet network cards. AUN is an implementation of the higher level
12 parts of Econet that runs over ordinary Ethernet connections, on
13 top of the UDP packet protocol, which in turn runs on top of the
14 Internet protocol IP.
15
16 If you say Y here, you can choose with the next two options whether
17 to send Econet/AUN traffic over a UDP Ethernet connection or over
18 a native Econet network card.
19
20 To compile this driver as a module, choose M here: the module
21 will be called econet.
22
23config ECONET_AUNUDP
24 bool "AUN over UDP"
25 depends on ECONET
26 help
27 Say Y here if you want to send Econet/AUN traffic over a UDP
28 connection (UDP is a packet based protocol that runs on top of the
29 Internet protocol IP) using an ordinary Ethernet network card.
30
31config ECONET_NATIVE
32 bool "Native Econet"
33 depends on ECONET
34 help
35 Say Y here if you have a native Econet network card installed in
36 your computer.
diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c
index ab60ea63688e..f6dbfb99b14d 100644
--- a/net/ethernet/eth.c
+++ b/net/ethernet/eth.c
@@ -155,7 +155,7 @@ int eth_rebuild_header(struct sk_buff *skb)
155 * This is normal practice and works for any 'now in use' protocol. 155 * This is normal practice and works for any 'now in use' protocol.
156 */ 156 */
157 157
158unsigned short eth_type_trans(struct sk_buff *skb, struct net_device *dev) 158__be16 eth_type_trans(struct sk_buff *skb, struct net_device *dev)
159{ 159{
160 struct ethhdr *eth; 160 struct ethhdr *eth;
161 unsigned char *rawp; 161 unsigned char *rawp;
diff --git a/net/ipv4/Kconfig b/net/ipv4/Kconfig
index 3e63123f7bbd..df5386885a90 100644
--- a/net/ipv4/Kconfig
+++ b/net/ipv4/Kconfig
@@ -3,7 +3,6 @@
3# 3#
4config IP_MULTICAST 4config IP_MULTICAST
5 bool "IP: multicasting" 5 bool "IP: multicasting"
6 depends on INET
7 help 6 help
8 This is code for addressing several networked computers at once, 7 This is code for addressing several networked computers at once,
9 enlarging your kernel by about 2 KB. You need multicasting if you 8 enlarging your kernel by about 2 KB. You need multicasting if you
@@ -17,7 +16,6 @@ config IP_MULTICAST
17 16
18config IP_ADVANCED_ROUTER 17config IP_ADVANCED_ROUTER
19 bool "IP: advanced router" 18 bool "IP: advanced router"
20 depends on INET
21 ---help--- 19 ---help---
22 If you intend to run your Linux box mostly as a router, i.e. as a 20 If you intend to run your Linux box mostly as a router, i.e. as a
23 computer that forwards and redistributes network packets, say Y; you 21 computer that forwards and redistributes network packets, say Y; you
@@ -183,7 +181,6 @@ config IP_ROUTE_VERBOSE
183 181
184config IP_PNP 182config IP_PNP
185 bool "IP: kernel level autoconfiguration" 183 bool "IP: kernel level autoconfiguration"
186 depends on INET
187 help 184 help
188 This enables automatic configuration of IP addresses of devices and 185 This enables automatic configuration of IP addresses of devices and
189 of the routing table during kernel boot, based on either information 186 of the routing table during kernel boot, based on either information
@@ -242,7 +239,6 @@ config IP_PNP_RARP
242# bool ' IP: ARP support' CONFIG_IP_PNP_ARP 239# bool ' IP: ARP support' CONFIG_IP_PNP_ARP
243config NET_IPIP 240config NET_IPIP
244 tristate "IP: tunneling" 241 tristate "IP: tunneling"
245 depends on INET
246 select INET_TUNNEL 242 select INET_TUNNEL
247 ---help--- 243 ---help---
248 Tunneling means encapsulating data of one protocol type within 244 Tunneling means encapsulating data of one protocol type within
@@ -260,7 +256,6 @@ config NET_IPIP
260 256
261config NET_IPGRE 257config NET_IPGRE
262 tristate "IP: GRE tunnels over IP" 258 tristate "IP: GRE tunnels over IP"
263 depends on INET
264 select XFRM 259 select XFRM
265 help 260 help
266 Tunneling means encapsulating data of one protocol type within 261 Tunneling means encapsulating data of one protocol type within
@@ -319,7 +314,7 @@ config IP_PIMSM_V2
319 314
320config ARPD 315config ARPD
321 bool "IP: ARP daemon support (EXPERIMENTAL)" 316 bool "IP: ARP daemon support (EXPERIMENTAL)"
322 depends on INET && EXPERIMENTAL 317 depends on EXPERIMENTAL
323 ---help--- 318 ---help---
324 Normally, the kernel maintains an internal cache which maps IP 319 Normally, the kernel maintains an internal cache which maps IP
325 addresses to hardware addresses on the local network, so that 320 addresses to hardware addresses on the local network, so that
@@ -344,7 +339,6 @@ config ARPD
344 339
345config SYN_COOKIES 340config SYN_COOKIES
346 bool "IP: TCP syncookie support (disabled per default)" 341 bool "IP: TCP syncookie support (disabled per default)"
347 depends on INET
348 ---help--- 342 ---help---
349 Normal TCP/IP networking is open to an attack known as "SYN 343 Normal TCP/IP networking is open to an attack known as "SYN
350 flooding". This denial-of-service attack prevents legitimate remote 344 flooding". This denial-of-service attack prevents legitimate remote
@@ -381,7 +375,6 @@ config SYN_COOKIES
381 375
382config INET_AH 376config INET_AH
383 tristate "IP: AH transformation" 377 tristate "IP: AH transformation"
384 depends on INET
385 select XFRM 378 select XFRM
386 select CRYPTO 379 select CRYPTO
387 select CRYPTO_HMAC 380 select CRYPTO_HMAC
@@ -394,7 +387,6 @@ config INET_AH
394 387
395config INET_ESP 388config INET_ESP
396 tristate "IP: ESP transformation" 389 tristate "IP: ESP transformation"
397 depends on INET
398 select XFRM 390 select XFRM
399 select CRYPTO 391 select CRYPTO
400 select CRYPTO_HMAC 392 select CRYPTO_HMAC
@@ -408,7 +400,6 @@ config INET_ESP
408 400
409config INET_IPCOMP 401config INET_IPCOMP
410 tristate "IP: IPComp transformation" 402 tristate "IP: IPComp transformation"
411 depends on INET
412 select XFRM 403 select XFRM
413 select INET_TUNNEL 404 select INET_TUNNEL
414 select CRYPTO 405 select CRYPTO
@@ -421,7 +412,6 @@ config INET_IPCOMP
421 412
422config INET_TUNNEL 413config INET_TUNNEL
423 tristate "IP: tunnel transformation" 414 tristate "IP: tunnel transformation"
424 depends on INET
425 select XFRM 415 select XFRM
426 ---help--- 416 ---help---
427 Support for generic IP tunnel transformation, which is required by 417 Support for generic IP tunnel transformation, which is required by
@@ -431,7 +421,6 @@ config INET_TUNNEL
431 421
432config IP_TCPDIAG 422config IP_TCPDIAG
433 tristate "IP: TCP socket monitoring interface" 423 tristate "IP: TCP socket monitoring interface"
434 depends on INET
435 default y 424 default y
436 ---help--- 425 ---help---
437 Support for TCP socket monitoring interface used by native Linux 426 Support for TCP socket monitoring interface used by native Linux
@@ -447,7 +436,6 @@ config IP_TCPDIAG_IPV6
447 436
448config TCP_CONG_ADVANCED 437config TCP_CONG_ADVANCED
449 bool "TCP: advanced congestion control" 438 bool "TCP: advanced congestion control"
450 depends on INET
451 ---help--- 439 ---help---
452 Support for selection of various TCP congestion control 440 Support for selection of various TCP congestion control
453 modules. 441 modules.
@@ -463,7 +451,6 @@ menu "TCP congestion control"
463 451
464config TCP_CONG_BIC 452config TCP_CONG_BIC
465 tristate "Binary Increase Congestion (BIC) control" 453 tristate "Binary Increase Congestion (BIC) control"
466 depends on INET
467 default y 454 default y
468 ---help--- 455 ---help---
469 BIC-TCP is a sender-side only change that ensures a linear RTT 456 BIC-TCP is a sender-side only change that ensures a linear RTT
@@ -478,7 +465,6 @@ config TCP_CONG_BIC
478 465
479config TCP_CONG_WESTWOOD 466config TCP_CONG_WESTWOOD
480 tristate "TCP Westwood+" 467 tristate "TCP Westwood+"
481 depends on INET
482 default m 468 default m
483 ---help--- 469 ---help---
484 TCP Westwood+ is a sender-side only modification of the TCP Reno 470 TCP Westwood+ is a sender-side only modification of the TCP Reno
@@ -493,7 +479,6 @@ config TCP_CONG_WESTWOOD
493 479
494config TCP_CONG_HTCP 480config TCP_CONG_HTCP
495 tristate "H-TCP" 481 tristate "H-TCP"
496 depends on INET
497 default m 482 default m
498 ---help--- 483 ---help---
499 H-TCP is a send-side only modifications of the TCP Reno 484 H-TCP is a send-side only modifications of the TCP Reno
@@ -505,7 +490,7 @@ config TCP_CONG_HTCP
505 490
506config TCP_CONG_HSTCP 491config TCP_CONG_HSTCP
507 tristate "High Speed TCP" 492 tristate "High Speed TCP"
508 depends on INET && EXPERIMENTAL 493 depends on EXPERIMENTAL
509 default n 494 default n
510 ---help--- 495 ---help---
511 Sally Floyd's High Speed TCP (RFC 3649) congestion control. 496 Sally Floyd's High Speed TCP (RFC 3649) congestion control.
@@ -516,7 +501,7 @@ config TCP_CONG_HSTCP
516 501
517config TCP_CONG_HYBLA 502config TCP_CONG_HYBLA
518 tristate "TCP-Hybla congestion control algorithm" 503 tristate "TCP-Hybla congestion control algorithm"
519 depends on INET && EXPERIMENTAL 504 depends on EXPERIMENTAL
520 default n 505 default n
521 ---help--- 506 ---help---
522 TCP-Hybla is a sender-side only change that eliminates penalization of 507 TCP-Hybla is a sender-side only change that eliminates penalization of
@@ -526,7 +511,7 @@ config TCP_CONG_HYBLA
526 511
527config TCP_CONG_VEGAS 512config TCP_CONG_VEGAS
528 tristate "TCP Vegas" 513 tristate "TCP Vegas"
529 depends on INET && EXPERIMENTAL 514 depends on EXPERIMENTAL
530 default n 515 default n
531 ---help--- 516 ---help---
532 TCP Vegas is a sender-side only change to TCP that anticipates 517 TCP Vegas is a sender-side only change to TCP that anticipates
@@ -537,7 +522,7 @@ config TCP_CONG_VEGAS
537 522
538config TCP_CONG_SCALABLE 523config TCP_CONG_SCALABLE
539 tristate "Scalable TCP" 524 tristate "Scalable TCP"
540 depends on INET && EXPERIMENTAL 525 depends on EXPERIMENTAL
541 default n 526 default n
542 ---help--- 527 ---help---
543 Scalable TCP is a sender-side only change to TCP which uses a 528 Scalable TCP is a sender-side only change to TCP which uses a
diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
index 9de83e6e0f1d..80d13103b2b0 100644
--- a/net/ipv4/ip_output.c
+++ b/net/ipv4/ip_output.c
@@ -107,7 +107,6 @@ static int ip_dev_loopback_xmit(struct sk_buff *newskb)
107 newskb->pkt_type = PACKET_LOOPBACK; 107 newskb->pkt_type = PACKET_LOOPBACK;
108 newskb->ip_summed = CHECKSUM_UNNECESSARY; 108 newskb->ip_summed = CHECKSUM_UNNECESSARY;
109 BUG_TRAP(newskb->dst); 109 BUG_TRAP(newskb->dst);
110 nf_reset(newskb);
111 netif_rx(newskb); 110 netif_rx(newskb);
112 return 0; 111 return 0;
113} 112}
@@ -188,14 +187,6 @@ static inline int ip_finish_output2(struct sk_buff *skb)
188 skb = skb2; 187 skb = skb2;
189 } 188 }
190 189
191#ifdef CONFIG_BRIDGE_NETFILTER
192 /* bridge-netfilter defers calling some IP hooks to the bridge layer
193 * and still needs the conntrack reference.
194 */
195 if (skb->nf_bridge == NULL)
196#endif
197 nf_reset(skb);
198
199 if (hh) { 190 if (hh) {
200 int hh_alen; 191 int hh_alen;
201 192
diff --git a/net/ipv4/ipvs/Kconfig b/net/ipv4/ipvs/Kconfig
index 63a82b4b64bb..c9820bfc493a 100644
--- a/net/ipv4/ipvs/Kconfig
+++ b/net/ipv4/ipvs/Kconfig
@@ -2,11 +2,11 @@
2# IP Virtual Server configuration 2# IP Virtual Server configuration
3# 3#
4menu "IP: Virtual Server Configuration" 4menu "IP: Virtual Server Configuration"
5 depends on INET && NETFILTER 5 depends on NETFILTER
6 6
7config IP_VS 7config IP_VS
8 tristate "IP virtual server support (EXPERIMENTAL)" 8 tristate "IP virtual server support (EXPERIMENTAL)"
9 depends on INET && NETFILTER 9 depends on NETFILTER
10 ---help--- 10 ---help---
11 IP Virtual Server support will let you build a high-performance 11 IP Virtual Server support will let you build a high-performance
12 virtual server based on cluster of two or more real servers. This 12 virtual server based on cluster of two or more real servers. This
diff --git a/net/ipv4/ipvs/ip_vs_conn.c b/net/ipv4/ipvs/ip_vs_conn.c
index 9f16ab309106..d0145a8b1551 100644
--- a/net/ipv4/ipvs/ip_vs_conn.c
+++ b/net/ipv4/ipvs/ip_vs_conn.c
@@ -758,7 +758,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
758 return 1; 758 return 1;
759} 759}
760 760
761 761/* Called from keventd and must protect itself from softirqs */
762void ip_vs_random_dropentry(void) 762void ip_vs_random_dropentry(void)
763{ 763{
764 int idx; 764 int idx;
@@ -773,7 +773,7 @@ void ip_vs_random_dropentry(void)
773 /* 773 /*
774 * Lock is actually needed in this loop. 774 * Lock is actually needed in this loop.
775 */ 775 */
776 ct_write_lock(hash); 776 ct_write_lock_bh(hash);
777 777
778 list_for_each_entry(cp, &ip_vs_conn_tab[hash], c_list) { 778 list_for_each_entry(cp, &ip_vs_conn_tab[hash], c_list) {
779 if (!cp->cport && !(cp->flags & IP_VS_CONN_F_NO_CPORT)) 779 if (!cp->cport && !(cp->flags & IP_VS_CONN_F_NO_CPORT))
@@ -806,7 +806,7 @@ void ip_vs_random_dropentry(void)
806 ip_vs_conn_expire_now(cp->control); 806 ip_vs_conn_expire_now(cp->control);
807 } 807 }
808 } 808 }
809 ct_write_unlock(hash); 809 ct_write_unlock_bh(hash);
810 } 810 }
811} 811}
812 812
diff --git a/net/ipv4/ipvs/ip_vs_ctl.c b/net/ipv4/ipvs/ip_vs_ctl.c
index 12a82e91d22a..7d99ede2ef79 100644
--- a/net/ipv4/ipvs/ip_vs_ctl.c
+++ b/net/ipv4/ipvs/ip_vs_ctl.c
@@ -90,7 +90,8 @@ int ip_vs_get_debug_level(void)
90#endif 90#endif
91 91
92/* 92/*
93 * update_defense_level is called from keventd and from sysctl. 93 * update_defense_level is called from keventd and from sysctl,
94 * so it needs to protect itself from softirqs
94 */ 95 */
95static void update_defense_level(void) 96static void update_defense_level(void)
96{ 97{
@@ -110,6 +111,8 @@ static void update_defense_level(void)
110 111
111 nomem = (availmem < sysctl_ip_vs_amemthresh); 112 nomem = (availmem < sysctl_ip_vs_amemthresh);
112 113
114 local_bh_disable();
115
113 /* drop_entry */ 116 /* drop_entry */
114 spin_lock(&__ip_vs_dropentry_lock); 117 spin_lock(&__ip_vs_dropentry_lock);
115 switch (sysctl_ip_vs_drop_entry) { 118 switch (sysctl_ip_vs_drop_entry) {
@@ -206,6 +209,8 @@ static void update_defense_level(void)
206 if (to_change >= 0) 209 if (to_change >= 0)
207 ip_vs_protocol_timeout_change(sysctl_ip_vs_secure_tcp>1); 210 ip_vs_protocol_timeout_change(sysctl_ip_vs_secure_tcp>1);
208 write_unlock(&__ip_vs_securetcp_lock); 211 write_unlock(&__ip_vs_securetcp_lock);
212
213 local_bh_enable();
209} 214}
210 215
211 216
@@ -1360,9 +1365,7 @@ proc_do_defense_mode(ctl_table *table, int write, struct file * filp,
1360 /* Restore the correct value */ 1365 /* Restore the correct value */
1361 *valp = val; 1366 *valp = val;
1362 } else { 1367 } else {
1363 local_bh_disable();
1364 update_defense_level(); 1368 update_defense_level();
1365 local_bh_enable();
1366 } 1369 }
1367 } 1370 }
1368 return rc; 1371 return rc;
diff --git a/net/ipv4/netfilter/ip_conntrack_standalone.c b/net/ipv4/netfilter/ip_conntrack_standalone.c
index 42dc95102873..1dd824f3cf0a 100644
--- a/net/ipv4/netfilter/ip_conntrack_standalone.c
+++ b/net/ipv4/netfilter/ip_conntrack_standalone.c
@@ -432,6 +432,13 @@ static unsigned int ip_conntrack_defrag(unsigned int hooknum,
432 const struct net_device *out, 432 const struct net_device *out,
433 int (*okfn)(struct sk_buff *)) 433 int (*okfn)(struct sk_buff *))
434{ 434{
435#if !defined(CONFIG_IP_NF_NAT) && !defined(CONFIG_IP_NF_NAT_MODULE)
436 /* Previously seen (loopback)? Ignore. Do this before
437 fragment check. */
438 if ((*pskb)->nfct)
439 return NF_ACCEPT;
440#endif
441
435 /* Gather fragments. */ 442 /* Gather fragments. */
436 if ((*pskb)->nh.iph->frag_off & htons(IP_MF|IP_OFFSET)) { 443 if ((*pskb)->nh.iph->frag_off & htons(IP_MF|IP_OFFSET)) {
437 *pskb = ip_ct_gather_frags(*pskb, 444 *pskb = ip_ct_gather_frags(*pskb,
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 726ea5e8180a..d675ff80b04d 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -1685,7 +1685,7 @@ static void ip_handle_martian_source(struct net_device *dev,
1685 printk(KERN_WARNING "martian source %u.%u.%u.%u from " 1685 printk(KERN_WARNING "martian source %u.%u.%u.%u from "
1686 "%u.%u.%u.%u, on dev %s\n", 1686 "%u.%u.%u.%u, on dev %s\n",
1687 NIPQUAD(daddr), NIPQUAD(saddr), dev->name); 1687 NIPQUAD(daddr), NIPQUAD(saddr), dev->name);
1688 if (dev->hard_header_len) { 1688 if (dev->hard_header_len && skb->mac.raw) {
1689 int i; 1689 int i;
1690 unsigned char *p = skb->mac.raw; 1690 unsigned char *p = skb->mac.raw;
1691 printk(KERN_WARNING "ll header: "); 1691 printk(KERN_WARNING "ll header: ");
diff --git a/net/ipv6/Kconfig b/net/ipv6/Kconfig
index e66ca9381cfd..95163cd52ae0 100644
--- a/net/ipv6/Kconfig
+++ b/net/ipv6/Kconfig
@@ -1,6 +1,26 @@
1# 1#
2# IPv6 configuration 2# IPv6 configuration
3# 3#
4
5# IPv6 as module will cause a CRASH if you try to unload it
6config IPV6
7 tristate "The IPv6 protocol"
8 default m
9 select CRYPTO if IPV6_PRIVACY
10 select CRYPTO_MD5 if IPV6_PRIVACY
11 ---help---
12 This is complemental support for the IP version 6.
13 You will still be able to do traditional IPv4 networking as well.
14
15 For general information about IPv6, see
16 <http://playground.sun.com/pub/ipng/html/ipng-main.html>.
17 For Linux IPv6 development information, see <http://www.linux-ipv6.org>.
18 For specific information about IPv6 under Linux, read the HOWTO at
19 <http://www.bieringer.de/linux/IPv6/>.
20
21 To compile this protocol support as a module, choose M here: the
22 module will be called ipv6.
23
4config IPV6_PRIVACY 24config IPV6_PRIVACY
5 bool "IPv6: Privacy Extensions (RFC 3041) support" 25 bool "IPv6: Privacy Extensions (RFC 3041) support"
6 depends on IPV6 26 depends on IPV6
diff --git a/net/ipx/Kconfig b/net/ipx/Kconfig
index a16237c0e783..980a826f5d02 100644
--- a/net/ipx/Kconfig
+++ b/net/ipx/Kconfig
@@ -1,6 +1,39 @@
1# 1#
2# IPX configuration 2# IPX configuration
3# 3#
4config IPX
5 tristate "The IPX protocol"
6 select LLC
7 ---help---
8 This is support for the Novell networking protocol, IPX, commonly
9 used for local networks of Windows machines. You need it if you
10 want to access Novell NetWare file or print servers using the Linux
11 Novell client ncpfs (available from
12 <ftp://platan.vc.cvut.cz/pub/linux/ncpfs/>) or from
13 within the Linux DOS emulator DOSEMU (read the DOSEMU-HOWTO,
14 available from <http://www.tldp.org/docs.html#howto>). In order
15 to do the former, you'll also have to say Y to "NCP file system
16 support", below.
17
18 IPX is similar in scope to IP, while SPX, which runs on top of IPX,
19 is similar to TCP. There is also experimental support for SPX in
20 Linux (see "SPX networking", below).
21
22 To turn your Linux box into a fully featured NetWare file server and
23 IPX router, say Y here and fetch either lwared from
24 <ftp://ibiblio.org/pub/Linux/system/network/daemons/> or
25 mars_nwe from <ftp://www.compu-art.de/mars_nwe/>. For more
26 information, read the IPX-HOWTO available from
27 <http://www.tldp.org/docs.html#howto>.
28
29 General information about how to connect Linux, Windows machines and
30 Macs is on the WWW at <http://www.eats.com/linux_mac_win.html>.
31
32 The IPX driver would enlarge your kernel by about 16 KB. To compile
33 this driver as a module, choose M here: the module will be called ipx.
34 Unless you want to integrate your Linux box with a local Novell
35 network, say N.
36
4config IPX_INTERN 37config IPX_INTERN
5 bool "IPX: Full internal IPX network" 38 bool "IPX: Full internal IPX network"
6 depends on IPX 39 depends on IPX
diff --git a/net/lapb/Kconfig b/net/lapb/Kconfig
new file mode 100644
index 000000000000..f0b5efb31a00
--- /dev/null
+++ b/net/lapb/Kconfig
@@ -0,0 +1,22 @@
1#
2# LAPB Data Link Drive
3#
4
5config LAPB
6 tristate "LAPB Data Link Driver (EXPERIMENTAL)"
7 depends on EXPERIMENTAL
8 ---help---
9 Link Access Procedure, Balanced (LAPB) is the data link layer (i.e.
10 the lower) part of the X.25 protocol. It offers a reliable
11 connection service to exchange data frames with one other host, and
12 it is used to transport higher level protocols (mostly X.25 Packet
13 Layer, the higher part of X.25, but others are possible as well).
14 Usually, LAPB is used with specialized X.21 network cards, but Linux
15 currently supports LAPB only over Ethernet connections. If you want
16 to use LAPB connections over Ethernet, say Y here and to "LAPB over
17 Ethernet driver" below. Read
18 <file:Documentation/networking/lapb-module.txt> for technical
19 details.
20
21 To compile this driver as a module, choose M here: the
22 module will be called lapb. If unsure, say N.
diff --git a/net/packet/Kconfig b/net/packet/Kconfig
new file mode 100644
index 000000000000..34ff93ff894d
--- /dev/null
+++ b/net/packet/Kconfig
@@ -0,0 +1,26 @@
1#
2# Packet configuration
3#
4
5config PACKET
6 tristate "Packet socket"
7 ---help---
8 The Packet protocol is used by applications which communicate
9 directly with network devices without an intermediate network
10 protocol implemented in the kernel, e.g. tcpdump. If you want them
11 to work, choose Y.
12
13 To compile this driver as a module, choose M here: the module will
14 be called af_packet.
15
16 If unsure, say Y.
17
18config PACKET_MMAP
19 bool "Packet socket: mmapped IO"
20 depends on PACKET
21 help
22 If you say Y here, the Packet protocol driver will use an IO
23 mechanism that results in faster communication.
24
25 If unsure, say N.
26
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 0269616e75a1..c9d5980aa4de 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -274,6 +274,9 @@ static int packet_rcv_spkt(struct sk_buff *skb, struct net_device *dev, struct
274 dst_release(skb->dst); 274 dst_release(skb->dst);
275 skb->dst = NULL; 275 skb->dst = NULL;
276 276
277 /* drop conntrack reference */
278 nf_reset(skb);
279
277 spkt = (struct sockaddr_pkt*)skb->cb; 280 spkt = (struct sockaddr_pkt*)skb->cb;
278 281
279 skb_push(skb, skb->data-skb->mac.raw); 282 skb_push(skb, skb->data-skb->mac.raw);
@@ -517,6 +520,9 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev, struct packe
517 dst_release(skb->dst); 520 dst_release(skb->dst);
518 skb->dst = NULL; 521 skb->dst = NULL;
519 522
523 /* drop conntrack reference */
524 nf_reset(skb);
525
520 spin_lock(&sk->sk_receive_queue.lock); 526 spin_lock(&sk->sk_receive_queue.lock);
521 po->stats.tp_packets++; 527 po->stats.tp_packets++;
522 __skb_queue_tail(&sk->sk_receive_queue, skb); 528 __skb_queue_tail(&sk->sk_receive_queue, skb);
diff --git a/net/sched/Kconfig b/net/sched/Kconfig
index 7bac249258e3..59d3e71f8b85 100644
--- a/net/sched/Kconfig
+++ b/net/sched/Kconfig
@@ -1,6 +1,43 @@
1# 1#
2# Traffic control configuration. 2# Traffic control configuration.
3# 3#
4
5menuconfig NET_SCHED
6 bool "QoS and/or fair queueing"
7 ---help---
8 When the kernel has several packets to send out over a network
9 device, it has to decide which ones to send first, which ones to
10 delay, and which ones to drop. This is the job of the packet
11 scheduler, and several different algorithms for how to do this
12 "fairly" have been proposed.
13
14 If you say N here, you will get the standard packet scheduler, which
15 is a FIFO (first come, first served). If you say Y here, you will be
16 able to choose from among several alternative algorithms which can
17 then be attached to different network devices. This is useful for
18 example if some of your network devices are real time devices that
19 need a certain minimum data flow rate, or if you need to limit the
20 maximum data flow rate for traffic which matches specified criteria.
21 This code is considered to be experimental.
22
23 To administer these schedulers, you'll need the user-level utilities
24 from the package iproute2+tc at <ftp://ftp.tux.org/pub/net/ip-routing/>.
25 That package also contains some documentation; for more, check out
26 <http://snafu.freedom.org/linux2.2/iproute-notes.html>.
27
28 This Quality of Service (QoS) support will enable you to use
29 Differentiated Services (diffserv) and Resource Reservation Protocol
30 (RSVP) on your Linux router if you also say Y to "QoS support",
31 "Packet classifier API" and to some classifiers below. Documentation
32 and software is at <http://diffserv.sourceforge.net/>.
33
34 If you say Y here and to "/proc file system" below, you will be able
35 to read status information about packet schedulers from the file
36 /proc/net/psched.
37
38 The available schedulers are listed in the following questions; you
39 can say Y to as many as you like. If unsure, say N now.
40
4choice 41choice
5 prompt "Packet scheduler clock source" 42 prompt "Packet scheduler clock source"
6 depends on NET_SCHED 43 depends on NET_SCHED
diff --git a/net/sctp/associola.c b/net/sctp/associola.c
index 4b47dd6f2485..5b24ae0650d3 100644
--- a/net/sctp/associola.c
+++ b/net/sctp/associola.c
@@ -71,7 +71,7 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a
71 const struct sctp_endpoint *ep, 71 const struct sctp_endpoint *ep,
72 const struct sock *sk, 72 const struct sock *sk,
73 sctp_scope_t scope, 73 sctp_scope_t scope,
74 int gfp) 74 unsigned int __nocast gfp)
75{ 75{
76 struct sctp_sock *sp; 76 struct sctp_sock *sp;
77 int i; 77 int i;
@@ -272,7 +272,8 @@ fail_init:
272/* Allocate and initialize a new association */ 272/* Allocate and initialize a new association */
273struct sctp_association *sctp_association_new(const struct sctp_endpoint *ep, 273struct sctp_association *sctp_association_new(const struct sctp_endpoint *ep,
274 const struct sock *sk, 274 const struct sock *sk,
275 sctp_scope_t scope, int gfp) 275 sctp_scope_t scope,
276 unsigned int __nocast gfp)
276{ 277{
277 struct sctp_association *asoc; 278 struct sctp_association *asoc;
278 279
@@ -478,7 +479,7 @@ void sctp_assoc_rm_peer(struct sctp_association *asoc,
478/* Add a transport address to an association. */ 479/* Add a transport address to an association. */
479struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *asoc, 480struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *asoc,
480 const union sctp_addr *addr, 481 const union sctp_addr *addr,
481 const int gfp, 482 const unsigned int __nocast gfp,
482 const int peer_state) 483 const int peer_state)
483{ 484{
484 struct sctp_transport *peer; 485 struct sctp_transport *peer;
@@ -1229,7 +1230,8 @@ void sctp_assoc_rwnd_decrease(struct sctp_association *asoc, unsigned len)
1229/* Build the bind address list for the association based on info from the 1230/* Build the bind address list for the association based on info from the
1230 * local endpoint and the remote peer. 1231 * local endpoint and the remote peer.
1231 */ 1232 */
1232int sctp_assoc_set_bind_addr_from_ep(struct sctp_association *asoc, int gfp) 1233int sctp_assoc_set_bind_addr_from_ep(struct sctp_association *asoc,
1234 unsigned int __nocast gfp)
1233{ 1235{
1234 sctp_scope_t scope; 1236 sctp_scope_t scope;
1235 int flags; 1237 int flags;
@@ -1251,7 +1253,8 @@ int sctp_assoc_set_bind_addr_from_ep(struct sctp_association *asoc, int gfp)
1251 1253
1252/* Build the association's bind address list from the cookie. */ 1254/* Build the association's bind address list from the cookie. */
1253int sctp_assoc_set_bind_addr_from_cookie(struct sctp_association *asoc, 1255int sctp_assoc_set_bind_addr_from_cookie(struct sctp_association *asoc,
1254 struct sctp_cookie *cookie, int gfp) 1256 struct sctp_cookie *cookie,
1257 unsigned int __nocast gfp)
1255{ 1258{
1256 int var_size2 = ntohs(cookie->peer_init->chunk_hdr.length); 1259 int var_size2 = ntohs(cookie->peer_init->chunk_hdr.length);
1257 int var_size3 = cookie->raw_addr_list_len; 1260 int var_size3 = cookie->raw_addr_list_len;
diff --git a/net/sctp/bind_addr.c b/net/sctp/bind_addr.c
index f90eadfb60a2..f71549710f2e 100644
--- a/net/sctp/bind_addr.c
+++ b/net/sctp/bind_addr.c
@@ -53,7 +53,8 @@
53 53
54/* Forward declarations for internal helpers. */ 54/* Forward declarations for internal helpers. */
55static int sctp_copy_one_addr(struct sctp_bind_addr *, union sctp_addr *, 55static int sctp_copy_one_addr(struct sctp_bind_addr *, union sctp_addr *,
56 sctp_scope_t scope, int gfp, int flags); 56 sctp_scope_t scope, unsigned int __nocast gfp,
57 int flags);
57static void sctp_bind_addr_clean(struct sctp_bind_addr *); 58static void sctp_bind_addr_clean(struct sctp_bind_addr *);
58 59
59/* First Level Abstractions. */ 60/* First Level Abstractions. */
@@ -63,7 +64,8 @@ static void sctp_bind_addr_clean(struct sctp_bind_addr *);
63 */ 64 */
64int sctp_bind_addr_copy(struct sctp_bind_addr *dest, 65int sctp_bind_addr_copy(struct sctp_bind_addr *dest,
65 const struct sctp_bind_addr *src, 66 const struct sctp_bind_addr *src,
66 sctp_scope_t scope, int gfp, int flags) 67 sctp_scope_t scope, unsigned int __nocast gfp,
68 int flags)
67{ 69{
68 struct sctp_sockaddr_entry *addr; 70 struct sctp_sockaddr_entry *addr;
69 struct list_head *pos; 71 struct list_head *pos;
@@ -144,7 +146,7 @@ void sctp_bind_addr_free(struct sctp_bind_addr *bp)
144 146
145/* Add an address to the bind address list in the SCTP_bind_addr structure. */ 147/* Add an address to the bind address list in the SCTP_bind_addr structure. */
146int sctp_add_bind_addr(struct sctp_bind_addr *bp, union sctp_addr *new, 148int sctp_add_bind_addr(struct sctp_bind_addr *bp, union sctp_addr *new,
147 int gfp) 149 unsigned int __nocast gfp)
148{ 150{
149 struct sctp_sockaddr_entry *addr; 151 struct sctp_sockaddr_entry *addr;
150 152
@@ -197,7 +199,8 @@ int sctp_del_bind_addr(struct sctp_bind_addr *bp, union sctp_addr *del_addr)
197 * The second argument is the return value for the length. 199 * The second argument is the return value for the length.
198 */ 200 */
199union sctp_params sctp_bind_addrs_to_raw(const struct sctp_bind_addr *bp, 201union sctp_params sctp_bind_addrs_to_raw(const struct sctp_bind_addr *bp,
200 int *addrs_len, int gfp) 202 int *addrs_len,
203 unsigned int __nocast gfp)
201{ 204{
202 union sctp_params addrparms; 205 union sctp_params addrparms;
203 union sctp_params retval; 206 union sctp_params retval;
@@ -249,7 +252,7 @@ end_raw:
249 * address parameters). 252 * address parameters).
250 */ 253 */
251int sctp_raw_to_bind_addrs(struct sctp_bind_addr *bp, __u8 *raw_addr_list, 254int sctp_raw_to_bind_addrs(struct sctp_bind_addr *bp, __u8 *raw_addr_list,
252 int addrs_len, __u16 port, int gfp) 255 int addrs_len, __u16 port, unsigned int __nocast gfp)
253{ 256{
254 union sctp_addr_param *rawaddr; 257 union sctp_addr_param *rawaddr;
255 struct sctp_paramhdr *param; 258 struct sctp_paramhdr *param;
@@ -347,7 +350,8 @@ union sctp_addr *sctp_find_unmatch_addr(struct sctp_bind_addr *bp,
347/* Copy out addresses from the global local address list. */ 350/* Copy out addresses from the global local address list. */
348static int sctp_copy_one_addr(struct sctp_bind_addr *dest, 351static int sctp_copy_one_addr(struct sctp_bind_addr *dest,
349 union sctp_addr *addr, 352 union sctp_addr *addr,
350 sctp_scope_t scope, int gfp, int flags) 353 sctp_scope_t scope, unsigned int __nocast gfp,
354 int flags)
351{ 355{
352 int error = 0; 356 int error = 0;
353 357
diff --git a/net/sctp/chunk.c b/net/sctp/chunk.c
index 0c2ab7885058..61da2937e641 100644
--- a/net/sctp/chunk.c
+++ b/net/sctp/chunk.c
@@ -62,7 +62,7 @@ static void sctp_datamsg_init(struct sctp_datamsg *msg)
62} 62}
63 63
64/* Allocate and initialize datamsg. */ 64/* Allocate and initialize datamsg. */
65SCTP_STATIC struct sctp_datamsg *sctp_datamsg_new(int gfp) 65SCTP_STATIC struct sctp_datamsg *sctp_datamsg_new(unsigned int __nocast gfp)
66{ 66{
67 struct sctp_datamsg *msg; 67 struct sctp_datamsg *msg;
68 msg = kmalloc(sizeof(struct sctp_datamsg), gfp); 68 msg = kmalloc(sizeof(struct sctp_datamsg), gfp);
diff --git a/net/sctp/endpointola.c b/net/sctp/endpointola.c
index c44bf4165c6e..e47ac0d1a6d6 100644
--- a/net/sctp/endpointola.c
+++ b/net/sctp/endpointola.c
@@ -67,7 +67,8 @@ static void sctp_endpoint_bh_rcv(struct sctp_endpoint *ep);
67 * Initialize the base fields of the endpoint structure. 67 * Initialize the base fields of the endpoint structure.
68 */ 68 */
69static struct sctp_endpoint *sctp_endpoint_init(struct sctp_endpoint *ep, 69static struct sctp_endpoint *sctp_endpoint_init(struct sctp_endpoint *ep,
70 struct sock *sk, int gfp) 70 struct sock *sk,
71 unsigned int __nocast gfp)
71{ 72{
72 struct sctp_sock *sp = sctp_sk(sk); 73 struct sctp_sock *sp = sctp_sk(sk);
73 memset(ep, 0, sizeof(struct sctp_endpoint)); 74 memset(ep, 0, sizeof(struct sctp_endpoint));
@@ -137,7 +138,8 @@ static struct sctp_endpoint *sctp_endpoint_init(struct sctp_endpoint *ep,
137/* Create a sctp_endpoint with all that boring stuff initialized. 138/* Create a sctp_endpoint with all that boring stuff initialized.
138 * Returns NULL if there isn't enough memory. 139 * Returns NULL if there isn't enough memory.
139 */ 140 */
140struct sctp_endpoint *sctp_endpoint_new(struct sock *sk, int gfp) 141struct sctp_endpoint *sctp_endpoint_new(struct sock *sk,
142 unsigned int __nocast gfp)
141{ 143{
142 struct sctp_endpoint *ep; 144 struct sctp_endpoint *ep;
143 145
diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
index e7f37faba7c0..ce9245e71fca 100644
--- a/net/sctp/protocol.c
+++ b/net/sctp/protocol.c
@@ -219,7 +219,7 @@ static void sctp_free_local_addr_list(void)
219 219
220/* Copy the local addresses which are valid for 'scope' into 'bp'. */ 220/* Copy the local addresses which are valid for 'scope' into 'bp'. */
221int sctp_copy_local_addr_list(struct sctp_bind_addr *bp, sctp_scope_t scope, 221int sctp_copy_local_addr_list(struct sctp_bind_addr *bp, sctp_scope_t scope,
222 int gfp, int copy_flags) 222 unsigned int __nocast gfp, int copy_flags)
223{ 223{
224 struct sctp_sockaddr_entry *addr; 224 struct sctp_sockaddr_entry *addr;
225 int error = 0; 225 int error = 0;
diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c
index 773cd93fa3d0..00d32b7c8266 100644
--- a/net/sctp/sm_make_chunk.c
+++ b/net/sctp/sm_make_chunk.c
@@ -78,7 +78,7 @@ static sctp_cookie_param_t *sctp_pack_cookie(const struct sctp_endpoint *ep,
78static int sctp_process_param(struct sctp_association *asoc, 78static int sctp_process_param(struct sctp_association *asoc,
79 union sctp_params param, 79 union sctp_params param,
80 const union sctp_addr *peer_addr, 80 const union sctp_addr *peer_addr,
81 int gfp); 81 unsigned int __nocast gfp);
82 82
83/* What was the inbound interface for this chunk? */ 83/* What was the inbound interface for this chunk? */
84int sctp_chunk_iif(const struct sctp_chunk *chunk) 84int sctp_chunk_iif(const struct sctp_chunk *chunk)
@@ -174,7 +174,7 @@ void sctp_init_cause(struct sctp_chunk *chunk, __u16 cause_code,
174 */ 174 */
175struct sctp_chunk *sctp_make_init(const struct sctp_association *asoc, 175struct sctp_chunk *sctp_make_init(const struct sctp_association *asoc,
176 const struct sctp_bind_addr *bp, 176 const struct sctp_bind_addr *bp,
177 int gfp, int vparam_len) 177 unsigned int __nocast gfp, int vparam_len)
178{ 178{
179 sctp_inithdr_t init; 179 sctp_inithdr_t init;
180 union sctp_params addrs; 180 union sctp_params addrs;
@@ -261,7 +261,7 @@ nodata:
261 261
262struct sctp_chunk *sctp_make_init_ack(const struct sctp_association *asoc, 262struct sctp_chunk *sctp_make_init_ack(const struct sctp_association *asoc,
263 const struct sctp_chunk *chunk, 263 const struct sctp_chunk *chunk,
264 int gfp, int unkparam_len) 264 unsigned int __nocast gfp, int unkparam_len)
265{ 265{
266 sctp_inithdr_t initack; 266 sctp_inithdr_t initack;
267 struct sctp_chunk *retval; 267 struct sctp_chunk *retval;
@@ -1233,7 +1233,8 @@ void sctp_chunk_assign_tsn(struct sctp_chunk *chunk)
1233 1233
1234/* Create a CLOSED association to use with an incoming packet. */ 1234/* Create a CLOSED association to use with an incoming packet. */
1235struct sctp_association *sctp_make_temp_asoc(const struct sctp_endpoint *ep, 1235struct sctp_association *sctp_make_temp_asoc(const struct sctp_endpoint *ep,
1236 struct sctp_chunk *chunk, int gfp) 1236 struct sctp_chunk *chunk,
1237 unsigned int __nocast gfp)
1237{ 1238{
1238 struct sctp_association *asoc; 1239 struct sctp_association *asoc;
1239 struct sk_buff *skb; 1240 struct sk_buff *skb;
@@ -1348,7 +1349,7 @@ nodata:
1348struct sctp_association *sctp_unpack_cookie( 1349struct sctp_association *sctp_unpack_cookie(
1349 const struct sctp_endpoint *ep, 1350 const struct sctp_endpoint *ep,
1350 const struct sctp_association *asoc, 1351 const struct sctp_association *asoc,
1351 struct sctp_chunk *chunk, int gfp, 1352 struct sctp_chunk *chunk, unsigned int __nocast gfp,
1352 int *error, struct sctp_chunk **errp) 1353 int *error, struct sctp_chunk **errp)
1353{ 1354{
1354 struct sctp_association *retval = NULL; 1355 struct sctp_association *retval = NULL;
@@ -1812,7 +1813,7 @@ int sctp_verify_init(const struct sctp_association *asoc,
1812 */ 1813 */
1813int sctp_process_init(struct sctp_association *asoc, sctp_cid_t cid, 1814int sctp_process_init(struct sctp_association *asoc, sctp_cid_t cid,
1814 const union sctp_addr *peer_addr, 1815 const union sctp_addr *peer_addr,
1815 sctp_init_chunk_t *peer_init, int gfp) 1816 sctp_init_chunk_t *peer_init, unsigned int __nocast gfp)
1816{ 1817{
1817 union sctp_params param; 1818 union sctp_params param;
1818 struct sctp_transport *transport; 1819 struct sctp_transport *transport;
@@ -1983,7 +1984,7 @@ nomem:
1983static int sctp_process_param(struct sctp_association *asoc, 1984static int sctp_process_param(struct sctp_association *asoc,
1984 union sctp_params param, 1985 union sctp_params param,
1985 const union sctp_addr *peer_addr, 1986 const union sctp_addr *peer_addr,
1986 int gfp) 1987 unsigned int __nocast gfp)
1987{ 1988{
1988 union sctp_addr addr; 1989 union sctp_addr addr;
1989 int i; 1990 int i;
diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
index 778639db125a..39c970b5b198 100644
--- a/net/sctp/sm_sideeffect.c
+++ b/net/sctp/sm_sideeffect.c
@@ -63,7 +63,7 @@ static int sctp_cmd_interpreter(sctp_event_t event_type,
63 void *event_arg, 63 void *event_arg,
64 sctp_disposition_t status, 64 sctp_disposition_t status,
65 sctp_cmd_seq_t *commands, 65 sctp_cmd_seq_t *commands,
66 int gfp); 66 unsigned int __nocast gfp);
67static int sctp_side_effects(sctp_event_t event_type, sctp_subtype_t subtype, 67static int sctp_side_effects(sctp_event_t event_type, sctp_subtype_t subtype,
68 sctp_state_t state, 68 sctp_state_t state,
69 struct sctp_endpoint *ep, 69 struct sctp_endpoint *ep,
@@ -71,7 +71,7 @@ static int sctp_side_effects(sctp_event_t event_type, sctp_subtype_t subtype,
71 void *event_arg, 71 void *event_arg,
72 sctp_disposition_t status, 72 sctp_disposition_t status,
73 sctp_cmd_seq_t *commands, 73 sctp_cmd_seq_t *commands,
74 int gfp); 74 unsigned int __nocast gfp);
75 75
76/******************************************************************** 76/********************************************************************
77 * Helper functions 77 * Helper functions
@@ -497,7 +497,8 @@ static void sctp_cmd_assoc_failed(sctp_cmd_seq_t *commands,
497static int sctp_cmd_process_init(sctp_cmd_seq_t *commands, 497static int sctp_cmd_process_init(sctp_cmd_seq_t *commands,
498 struct sctp_association *asoc, 498 struct sctp_association *asoc,
499 struct sctp_chunk *chunk, 499 struct sctp_chunk *chunk,
500 sctp_init_chunk_t *peer_init, int gfp) 500 sctp_init_chunk_t *peer_init,
501 unsigned int __nocast gfp)
501{ 502{
502 int error; 503 int error;
503 504
@@ -852,7 +853,7 @@ int sctp_do_sm(sctp_event_t event_type, sctp_subtype_t subtype,
852 struct sctp_endpoint *ep, 853 struct sctp_endpoint *ep,
853 struct sctp_association *asoc, 854 struct sctp_association *asoc,
854 void *event_arg, 855 void *event_arg,
855 int gfp) 856 unsigned int __nocast gfp)
856{ 857{
857 sctp_cmd_seq_t commands; 858 sctp_cmd_seq_t commands;
858 const sctp_sm_table_entry_t *state_fn; 859 const sctp_sm_table_entry_t *state_fn;
@@ -897,7 +898,7 @@ static int sctp_side_effects(sctp_event_t event_type, sctp_subtype_t subtype,
897 void *event_arg, 898 void *event_arg,
898 sctp_disposition_t status, 899 sctp_disposition_t status,
899 sctp_cmd_seq_t *commands, 900 sctp_cmd_seq_t *commands,
900 int gfp) 901 unsigned int __nocast gfp)
901{ 902{
902 int error; 903 int error;
903 904
@@ -985,7 +986,7 @@ static int sctp_cmd_interpreter(sctp_event_t event_type,
985 void *event_arg, 986 void *event_arg,
986 sctp_disposition_t status, 987 sctp_disposition_t status,
987 sctp_cmd_seq_t *commands, 988 sctp_cmd_seq_t *commands,
988 int gfp) 989 unsigned int __nocast gfp)
989{ 990{
990 int error = 0; 991 int error = 0;
991 int force; 992 int force;
diff --git a/net/sctp/ssnmap.c b/net/sctp/ssnmap.c
index e627d2b451b6..25037daf3fa0 100644
--- a/net/sctp/ssnmap.c
+++ b/net/sctp/ssnmap.c
@@ -57,7 +57,8 @@ static inline size_t sctp_ssnmap_size(__u16 in, __u16 out)
57/* Create a new sctp_ssnmap. 57/* Create a new sctp_ssnmap.
58 * Allocate room to store at least 'len' contiguous TSNs. 58 * Allocate room to store at least 'len' contiguous TSNs.
59 */ 59 */
60struct sctp_ssnmap *sctp_ssnmap_new(__u16 in, __u16 out, int gfp) 60struct sctp_ssnmap *sctp_ssnmap_new(__u16 in, __u16 out,
61 unsigned int __nocast gfp)
61{ 62{
62 struct sctp_ssnmap *retval; 63 struct sctp_ssnmap *retval;
63 int size; 64 int size;
diff --git a/net/sctp/transport.c b/net/sctp/transport.c
index a63b69179607..d2f04ebe5081 100644
--- a/net/sctp/transport.c
+++ b/net/sctp/transport.c
@@ -57,7 +57,7 @@
57/* Initialize a new transport from provided memory. */ 57/* Initialize a new transport from provided memory. */
58static struct sctp_transport *sctp_transport_init(struct sctp_transport *peer, 58static struct sctp_transport *sctp_transport_init(struct sctp_transport *peer,
59 const union sctp_addr *addr, 59 const union sctp_addr *addr,
60 int gfp) 60 unsigned int __nocast gfp)
61{ 61{
62 /* Copy in the address. */ 62 /* Copy in the address. */
63 peer->ipaddr = *addr; 63 peer->ipaddr = *addr;
@@ -121,7 +121,8 @@ static struct sctp_transport *sctp_transport_init(struct sctp_transport *peer,
121} 121}
122 122
123/* Allocate and initialize a new transport. */ 123/* Allocate and initialize a new transport. */
124struct sctp_transport *sctp_transport_new(const union sctp_addr *addr, int gfp) 124struct sctp_transport *sctp_transport_new(const union sctp_addr *addr,
125 unsigned int __nocast gfp)
125{ 126{
126 struct sctp_transport *transport; 127 struct sctp_transport *transport;
127 128
diff --git a/net/sctp/ulpevent.c b/net/sctp/ulpevent.c
index 17d0ff534735..0abd5101107c 100644
--- a/net/sctp/ulpevent.c
+++ b/net/sctp/ulpevent.c
@@ -74,7 +74,7 @@ SCTP_STATIC void sctp_ulpevent_init(struct sctp_ulpevent *event, int msg_flags)
74 74
75/* Create a new sctp_ulpevent. */ 75/* Create a new sctp_ulpevent. */
76SCTP_STATIC struct sctp_ulpevent *sctp_ulpevent_new(int size, int msg_flags, 76SCTP_STATIC struct sctp_ulpevent *sctp_ulpevent_new(int size, int msg_flags,
77 int gfp) 77 unsigned int __nocast gfp)
78{ 78{
79 struct sctp_ulpevent *event; 79 struct sctp_ulpevent *event;
80 struct sk_buff *skb; 80 struct sk_buff *skb;
@@ -136,7 +136,7 @@ static inline void sctp_ulpevent_release_owner(struct sctp_ulpevent *event)
136struct sctp_ulpevent *sctp_ulpevent_make_assoc_change( 136struct sctp_ulpevent *sctp_ulpevent_make_assoc_change(
137 const struct sctp_association *asoc, 137 const struct sctp_association *asoc,
138 __u16 flags, __u16 state, __u16 error, __u16 outbound, 138 __u16 flags, __u16 state, __u16 error, __u16 outbound,
139 __u16 inbound, int gfp) 139 __u16 inbound, unsigned int __nocast gfp)
140{ 140{
141 struct sctp_ulpevent *event; 141 struct sctp_ulpevent *event;
142 struct sctp_assoc_change *sac; 142 struct sctp_assoc_change *sac;
@@ -237,7 +237,7 @@ fail:
237struct sctp_ulpevent *sctp_ulpevent_make_peer_addr_change( 237struct sctp_ulpevent *sctp_ulpevent_make_peer_addr_change(
238 const struct sctp_association *asoc, 238 const struct sctp_association *asoc,
239 const struct sockaddr_storage *aaddr, 239 const struct sockaddr_storage *aaddr,
240 int flags, int state, int error, int gfp) 240 int flags, int state, int error, unsigned int __nocast gfp)
241{ 241{
242 struct sctp_ulpevent *event; 242 struct sctp_ulpevent *event;
243 struct sctp_paddr_change *spc; 243 struct sctp_paddr_change *spc;
@@ -350,7 +350,7 @@ fail:
350 */ 350 */
351struct sctp_ulpevent *sctp_ulpevent_make_remote_error( 351struct sctp_ulpevent *sctp_ulpevent_make_remote_error(
352 const struct sctp_association *asoc, struct sctp_chunk *chunk, 352 const struct sctp_association *asoc, struct sctp_chunk *chunk,
353 __u16 flags, int gfp) 353 __u16 flags, unsigned int __nocast gfp)
354{ 354{
355 struct sctp_ulpevent *event; 355 struct sctp_ulpevent *event;
356 struct sctp_remote_error *sre; 356 struct sctp_remote_error *sre;
@@ -448,7 +448,7 @@ fail:
448 */ 448 */
449struct sctp_ulpevent *sctp_ulpevent_make_send_failed( 449struct sctp_ulpevent *sctp_ulpevent_make_send_failed(
450 const struct sctp_association *asoc, struct sctp_chunk *chunk, 450 const struct sctp_association *asoc, struct sctp_chunk *chunk,
451 __u16 flags, __u32 error, int gfp) 451 __u16 flags, __u32 error, unsigned int __nocast gfp)
452{ 452{
453 struct sctp_ulpevent *event; 453 struct sctp_ulpevent *event;
454 struct sctp_send_failed *ssf; 454 struct sctp_send_failed *ssf;
@@ -557,7 +557,7 @@ fail:
557 */ 557 */
558struct sctp_ulpevent *sctp_ulpevent_make_shutdown_event( 558struct sctp_ulpevent *sctp_ulpevent_make_shutdown_event(
559 const struct sctp_association *asoc, 559 const struct sctp_association *asoc,
560 __u16 flags, int gfp) 560 __u16 flags, unsigned int __nocast gfp)
561{ 561{
562 struct sctp_ulpevent *event; 562 struct sctp_ulpevent *event;
563 struct sctp_shutdown_event *sse; 563 struct sctp_shutdown_event *sse;
@@ -620,7 +620,7 @@ fail:
620 * 5.3.1.6 SCTP_ADAPTION_INDICATION 620 * 5.3.1.6 SCTP_ADAPTION_INDICATION
621 */ 621 */
622struct sctp_ulpevent *sctp_ulpevent_make_adaption_indication( 622struct sctp_ulpevent *sctp_ulpevent_make_adaption_indication(
623 const struct sctp_association *asoc, int gfp) 623 const struct sctp_association *asoc, unsigned int __nocast gfp)
624{ 624{
625 struct sctp_ulpevent *event; 625 struct sctp_ulpevent *event;
626 struct sctp_adaption_event *sai; 626 struct sctp_adaption_event *sai;
@@ -657,7 +657,7 @@ fail:
657 */ 657 */
658struct sctp_ulpevent *sctp_ulpevent_make_rcvmsg(struct sctp_association *asoc, 658struct sctp_ulpevent *sctp_ulpevent_make_rcvmsg(struct sctp_association *asoc,
659 struct sctp_chunk *chunk, 659 struct sctp_chunk *chunk,
660 int gfp) 660 unsigned int __nocast gfp)
661{ 661{
662 struct sctp_ulpevent *event = NULL; 662 struct sctp_ulpevent *event = NULL;
663 struct sk_buff *skb; 663 struct sk_buff *skb;
@@ -718,7 +718,8 @@ fail:
718 * various events. 718 * various events.
719 */ 719 */
720struct sctp_ulpevent *sctp_ulpevent_make_pdapi( 720struct sctp_ulpevent *sctp_ulpevent_make_pdapi(
721 const struct sctp_association *asoc, __u32 indication, int gfp) 721 const struct sctp_association *asoc, __u32 indication,
722 unsigned int __nocast gfp)
722{ 723{
723 struct sctp_ulpevent *event; 724 struct sctp_ulpevent *event;
724 struct sctp_pdapi_event *pd; 725 struct sctp_pdapi_event *pd;
diff --git a/net/sctp/ulpqueue.c b/net/sctp/ulpqueue.c
index d5dd2cf7ac4a..8bbc279d6c99 100644
--- a/net/sctp/ulpqueue.c
+++ b/net/sctp/ulpqueue.c
@@ -100,7 +100,7 @@ void sctp_ulpq_free(struct sctp_ulpq *ulpq)
100 100
101/* Process an incoming DATA chunk. */ 101/* Process an incoming DATA chunk. */
102int sctp_ulpq_tail_data(struct sctp_ulpq *ulpq, struct sctp_chunk *chunk, 102int sctp_ulpq_tail_data(struct sctp_ulpq *ulpq, struct sctp_chunk *chunk,
103 int gfp) 103 unsigned int __nocast gfp)
104{ 104{
105 struct sk_buff_head temp; 105 struct sk_buff_head temp;
106 sctp_data_chunk_t *hdr; 106 sctp_data_chunk_t *hdr;
@@ -778,7 +778,8 @@ static __u16 sctp_ulpq_renege_frags(struct sctp_ulpq *ulpq, __u16 needed)
778 778
779/* Partial deliver the first message as there is pressure on rwnd. */ 779/* Partial deliver the first message as there is pressure on rwnd. */
780void sctp_ulpq_partial_delivery(struct sctp_ulpq *ulpq, 780void sctp_ulpq_partial_delivery(struct sctp_ulpq *ulpq,
781 struct sctp_chunk *chunk, int gfp) 781 struct sctp_chunk *chunk,
782 unsigned int __nocast gfp)
782{ 783{
783 struct sctp_ulpevent *event; 784 struct sctp_ulpevent *event;
784 struct sctp_association *asoc; 785 struct sctp_association *asoc;
@@ -802,7 +803,7 @@ void sctp_ulpq_partial_delivery(struct sctp_ulpq *ulpq,
802 803
803/* Renege some packets to make room for an incoming chunk. */ 804/* Renege some packets to make room for an incoming chunk. */
804void sctp_ulpq_renege(struct sctp_ulpq *ulpq, struct sctp_chunk *chunk, 805void sctp_ulpq_renege(struct sctp_ulpq *ulpq, struct sctp_chunk *chunk,
805 int gfp) 806 unsigned int __nocast gfp)
806{ 807{
807 struct sctp_association *asoc; 808 struct sctp_association *asoc;
808 __u16 needed, freed; 809 __u16 needed, freed;
@@ -841,7 +842,7 @@ void sctp_ulpq_renege(struct sctp_ulpq *ulpq, struct sctp_chunk *chunk,
841/* Notify the application if an association is aborted and in 842/* Notify the application if an association is aborted and in
842 * partial delivery mode. Send up any pending received messages. 843 * partial delivery mode. Send up any pending received messages.
843 */ 844 */
844void sctp_ulpq_abort_pd(struct sctp_ulpq *ulpq, int gfp) 845void sctp_ulpq_abort_pd(struct sctp_ulpq *ulpq, unsigned int __nocast gfp)
845{ 846{
846 struct sctp_ulpevent *ev = NULL; 847 struct sctp_ulpevent *ev = NULL;
847 struct sock *sk; 848 struct sock *sk;
diff --git a/net/unix/Kconfig b/net/unix/Kconfig
new file mode 100644
index 000000000000..5a69733bcdad
--- /dev/null
+++ b/net/unix/Kconfig
@@ -0,0 +1,21 @@
1#
2# Unix Domain Sockets
3#
4
5config UNIX
6 tristate "Unix domain sockets"
7 ---help---
8 If you say Y here, you will include support for Unix domain sockets;
9 sockets are the standard Unix mechanism for establishing and
10 accessing network connections. Many commonly used programs such as
11 the X Window system and syslog use these sockets even if your
12 machine is not connected to any network. Unless you are working on
13 an embedded system or something similar, you therefore definitely
14 want to say Y here.
15
16 To compile this driver as a module, choose M here: the module will be
17 called unix. Note that several important services won't work
18 correctly if you say M here and then neglect to load the module.
19
20 Say Y unless you know what you are doing.
21
diff --git a/net/wanrouter/Kconfig b/net/wanrouter/Kconfig
new file mode 100644
index 000000000000..1debe1cb054e
--- /dev/null
+++ b/net/wanrouter/Kconfig
@@ -0,0 +1,29 @@
1#
2# Configuration for WAN router
3#
4
5config WAN_ROUTER
6 tristate "WAN router"
7 depends on EXPERIMENTAL
8 ---help---
9 Wide Area Networks (WANs), such as X.25, frame relay and leased
10 lines, are used to interconnect Local Area Networks (LANs) over vast
11 distances with data transfer rates significantly higher than those
12 achievable with commonly used asynchronous modem connections.
13 Usually, a quite expensive external device called a `WAN router' is
14 needed to connect to a WAN.
15
16 As an alternative, WAN routing can be built into the Linux kernel.
17 With relatively inexpensive WAN interface cards available on the
18 market, a perfectly usable router can be built for less than half
19 the price of an external router. If you have one of those cards and
20 wish to use your Linux box as a WAN router, say Y here and also to
21 the WAN driver for your card, below. You will then need the
22 wan-tools package which is available from <ftp://ftp.sangoma.com/>.
23 Read <file:Documentation/networking/wan-router.txt> for more
24 information.
25
26 To compile WAN routing support as a module, choose M here: the
27 module will be called wanrouter.
28
29 If unsure, say N.
diff --git a/net/wanrouter/wanmain.c b/net/wanrouter/wanmain.c
index d6844ac226f5..13b650ad22e2 100644
--- a/net/wanrouter/wanmain.c
+++ b/net/wanrouter/wanmain.c
@@ -358,10 +358,10 @@ int wanrouter_encapsulate(struct sk_buff *skb, struct net_device *dev,
358 */ 358 */
359 359
360 360
361unsigned short wanrouter_type_trans(struct sk_buff *skb, struct net_device *dev) 361__be16 wanrouter_type_trans(struct sk_buff *skb, struct net_device *dev)
362{ 362{
363 int cnt = skb->data[0] ? 0 : 1; /* there may be a pad present */ 363 int cnt = skb->data[0] ? 0 : 1; /* there may be a pad present */
364 unsigned short ethertype; 364 __be16 ethertype;
365 365
366 switch (skb->data[cnt]) { 366 switch (skb->data[cnt]) {
367 case NLPID_IP: /* IP datagramm */ 367 case NLPID_IP: /* IP datagramm */
@@ -379,7 +379,7 @@ unsigned short wanrouter_type_trans(struct sk_buff *skb, struct net_device *dev)
379 skb->data[cnt+3], dev->name); 379 skb->data[cnt+3], dev->name);
380 return 0; 380 return 0;
381 } 381 }
382 ethertype = *((unsigned short*)&skb->data[cnt+4]); 382 ethertype = *((__be16*)&skb->data[cnt+4]);
383 cnt += 6; 383 cnt += 6;
384 break; 384 break;
385 385
diff --git a/net/x25/Kconfig b/net/x25/Kconfig
new file mode 100644
index 000000000000..e6759c9660bb
--- /dev/null
+++ b/net/x25/Kconfig
@@ -0,0 +1,36 @@
1#
2# CCITT X.25 Packet Layer
3#
4
5config X25
6 tristate "CCITT X.25 Packet Layer (EXPERIMENTAL)"
7 depends on EXPERIMENTAL
8 ---help---
9 X.25 is a set of standardized network protocols, similar in scope to
10 frame relay; the one physical line from your box to the X.25 network
11 entry point can carry several logical point-to-point connections
12 (called "virtual circuits") to other computers connected to the X.25
13 network. Governments, banks, and other organizations tend to use it
14 to connect to each other or to form Wide Area Networks (WANs). Many
15 countries have public X.25 networks. X.25 consists of two
16 protocols: the higher level Packet Layer Protocol (PLP) (say Y here
17 if you want that) and the lower level data link layer protocol LAPB
18 (say Y to "LAPB Data Link Driver" below if you want that).
19
20 You can read more about X.25 at <http://www.sangoma.com/x25.htm> and
21 <http://www.cisco.com/univercd/cc/td/doc/product/software/ios11/cbook/cx25.htm>.
22 Information about X.25 for Linux is contained in the files
23 <file:Documentation/networking/x25.txt> and
24 <file:Documentation/networking/x25-iface.txt>.
25
26 One connects to an X.25 network either with a dedicated network card
27 using the X.21 protocol (not yet supported by Linux) or one can do
28 X.25 over a standard telephone line using an ordinary modem (say Y
29 to "X.25 async driver" below) or over Ethernet using an ordinary
30 Ethernet card and the LAPB over Ethernet (say Y to "LAPB Data Link
31 Driver" and "LAPB over Ethernet driver" below).
32
33 To compile this driver as a module, choose M here: the module
34 will be called x25. If unsure, say N.
35
36
diff --git a/net/xfrm/Kconfig b/net/xfrm/Kconfig
index 58ca6a972c48..0c1c04322baf 100644
--- a/net/xfrm/Kconfig
+++ b/net/xfrm/Kconfig
@@ -1,6 +1,10 @@
1# 1#
2# XFRM configuration 2# XFRM configuration
3# 3#
4config XFRM
5 bool
6 depends on NET
7
4config XFRM_USER 8config XFRM_USER
5 tristate "IPsec user configuration interface" 9 tristate "IPsec user configuration interface"
6 depends on INET && XFRM 10 depends on INET && XFRM
@@ -10,3 +14,14 @@ config XFRM_USER
10 14
11 If unsure, say Y. 15 If unsure, say Y.
12 16
17config NET_KEY
18 tristate "PF_KEY sockets"
19 select XFRM
20 ---help---
21 PF_KEYv2 socket family, compatible to KAME ones.
22 They are required if you are going to use IPsec tools ported
23 from KAME.
24
25 Say Y unless you know what you are doing.
26
27
diff --git a/scripts/Lindent b/scripts/Lindent
index 34ed785116b6..7d8d8896e309 100755
--- a/scripts/Lindent
+++ b/scripts/Lindent
@@ -1,2 +1,2 @@
1#!/bin/sh 1#!/bin/sh
2indent -kr -i8 -ts8 -sob -l80 -ss -ncs "$@" 2indent -npro -kr -i8 -ts8 -sob -l80 -ss -ncs "$@"