#! /bin/ksh
# This script modifies 32-bit XCOFF variable o_maxdata (+4C).
# This script CANNOT be use on a 64-bit XCOFF executable.
# This script MUST be run on the REAL executable, you CANNOT run
# this script on a symbolic link.
# See "AIX: General Programming Concepts, Writing and Debugging Pgms."
# To find the current maxdata setting for an executable
# run the command dump -ov executable  look for the maxDATA entry
# on the last line.                                          
# This script requires exactly two parameters?              
# 1st parm is name of executable
# 2nd parm is maxdata unit
# maxdata units are:      
# 0 = 256mb              
# 1 = 256mb             
# 2 = 512mb            
# 3 = 768mb
# 4 = 1024mb-1gb
# 5 = 1280mb
# 6 = 1536mb
# 7 = 1792mb
# 8 = 2048mb-2gb-max size for 32bit software/hardware
if [[ $# -ne 2 ]]
then                       
  print 'usage: "maxdata XCOFF [0-8]"' ;
  print '\tThe second parameter (maxdata size) specifies units of 256M.'
  print '\ie:  "maxdata /bin/xldb  4" sets /bin/xldb maxdata to 1G.' ; 
  exit ;
fi
# first parm a 32-bit xcoff?  
file $1 | grep -q 'executable (RISC System/6000) or object module' ;
if [[ $? -ne 0 ]]
then
  print "$1 isn't a readable 32-bit XCOFF file." ;
  exit ;
fi
# ... and writable?
if [[ ! -w $1 ]]
then  
  print "$1 isn't a writable and executable file." ; 
  exit ;
fi
# second parm equals 0,1,2,...,8 ?
case ${2:-4} in
[0-8] ) typeset -i8  d=${2:-4}*16  ;
        typeset -i10 m=${2:-4}*256 ;; 
    * ) print 'The second parameter has to be an integer [0-8].' ;
        exit 1 ;;
esac
# Do it:
print -n "$1 o_maxdata before: " ; od -HAx -N4 -j76 $1 | head -1 ;
eval "print -n '\\0'${d#*#}'\\0\\0\\0' |
      dd of=$1 bs=4 count=1 seek=19 conv=notrunc 2>/dev/null" ;
print -n "$1 o_maxdata after:  " ; od -HAx -N4 -j76 $1 | head -1 ;
print "Maxdata in $1 now set to ${m}M." ; 


#
#
#
#
#How to check the current size of executable                                 13
#.                                                                           OF
#Before using the maxdata script, you should check the                       24
#current size of the executable.  Enter the following
#command: dump -ov executable-name
#This should produce output similar to:
#executable-name:
#                        ***Object Module Header***
## Sections      Symbol Ptr      # Symbols       Opt Hdr Len     Flags
#         4      0x00000000              0                72     0x1007
#Flags=( RELFLG EXEC LNNO DYNLOAD )                                         OID
#Timestamp = "Jun 09 20:51:49 1999"                                         RS4
#Magic = 0x1df  (32-bit XCOFF)
#                        ***Optional Header***
#Tsize        Dsize       Bsize       Tstart      Dstart                   PAGE
#0x00005cc4  0x000009a4  0x00000984  0x10000100  0x00000000                  14
#SNloader     SNentry     SNtext      SNtoc       SNdata                     OF
#0x0004      0x0002      0x0001      0x0002      0x0002                      24
#TXTalign     DATAalign   TOC         vstamp      entry
#0x0005      0x0003      0x00000898  0x0001      0x00000878
#maxSTACK     maxDATA     SNbss       magic       modtype
#0x00000000  0x00000000  0x0003      0x010b        1L
#Check the second entry in the last line (maxDATA) this field
#shows the current size of the program.  You can look at the
#maxdata script for a descript of maxDATA units.
#.                                                                          OID
#How to use the maxdata script                                              RS4
#You MUST have read and write authority to the executable to
#use the maxdata script.                                                   PAGE
#.                                                                           15
#Using the above output as an example, to increase from 0                    OF
#maxDATA units to 4 (1gb) enter the command:                                 24
#     maxdata executable-name 4
#You should see output similar to:
#     executable-name o_maxdata before: 0000000  00000000
#     executable-name o_maxdata after:  0000000  40000000
#     Maxdata in executable-name now set to 1024M.
#To set the executable back to 0 maxDATA units enter the                    OID
#command:                                                                   RS4
#     maxdata executable-name 0
#.                                                                         PAGE
#You should see output similar to:                                           16
#     executable-name o_maxdata before: 0000000  40000000                    OF
#     executable-name o_maxdata after:  0000000  00000000                    24
#     Maxdata in executable-name now set to 0M.
#You should always use dump -ov executable-name to confirm
#the change.
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#Documentation on LOCAL LOOPBACK
#After the database is created, the following additional                    OID
#steps are required to use local loopback connections for                   RS4
#DB2:
#1.Add these entries to the /etc/services:                                 PAGE
#db2service         3700/tcp                                                 17
#db2servicei        3701/tcp                                                 OF
#.                                                                           24
#2.Instruct the database manager to use the service:
#itzhack
#Normal.dot
#itzhack
#Microsoft Word 9.0
#Title
#Microsoft Word Document
#MSWordDoc
#Word.Document.8
