Saturday, November 29, 2008

Building a Modified cp Binary on Solaris 10

I thought I would write a post on how I setup my Solaris 10 system to build an improved version of the stock cp(1) utility that comes with Solaris 10 in case anyone arrives here from Kevin Closson's blog. If you are looking for more background information on why I am performing this modification, have a look at this post by Kevin Closson.

GNU Core Utilities

We need to download the source code for the cp utility that we will be modifying. This source code is available as part of the GNU Core Utilities.

Down the software to an appropriate location on your system.

Modifying the Code

Untar the code first on your system.

# gunzip coreutils-5.2.1.tar.gz
# tar xvf coreutils-5.2.1.tar

Proceed to the coreutils-5.2.1/src directory. Open the copy.c file with an editor. The following are the differences between the modified copy.c file and the original copy.c file:

# diff -b copy.c.orig copy.c
287c315
< buf_size =" ST_BLKSIZE"> /* buf_size = ST_BLKSIZE (sb);*/

288a317,319
>
> buf_size = 8388608 ;
>
Building the Binary

To build the modified cp binary, navigate first to the coreutils-5.2.1 directory. Then enter the following (ensure that the gcc binary is in your PATH first; it is located at /usr/sfw/bin/):

# ./configure
# /usr/ccs/bin/make

We don't want to do make install as is the usual when building something from source like this as it would replace the stock cp(1) utility. Instead, we will copy the cp binary located in the coreutils-5.2.1/src directory like so:

# cp coreutils-5.2.1/src/cp /usr/bin/cp8m

Results of using the Modified cp

See Kevin Closson's post on copying files on Solaris for some in-depth discussion of this topic and more information on the reasoning behind making this modification to the cp(1) utility.

No comments: