"The Linux Gazette...making Linux just a little more fun!"


(?) The Answer Guy (!)


By James T. Dennis, [email protected]
LinuxCare, http://www.linuxcare.com/


(?) Getting to the Source(s) of fsck

From hasan jamal on Tue, 28 Mar 2000

I need the source code of "fsck", the file system checker under the /sbin directory.

I have searched most of the ftp archives related to linux and did not find anywhere.

I got RedHat & SuSe distribution, in none of them I found. I would be grateful if anybody can give me the source code or the ftp site.

(!) I presume that you want the version of fsck for the ext2 filesystem. Of course Linux supports many other filesystems, and has filesystem check utilities for a few of them. the fsck command itself just calls on the filesystem specific filesystem checker, just as e2fsck (a.k.a. fsck.ext2).
You want to look for the e2fsprogs sources. Here's one area where I really like the Debian system. When I need the sources to some package I just use the command: 'apt-get source <package-name>' and it's done. Of course, the hard part can be to find out the package name. On an RPM system you can find the package to which almost any file belongs using the command: 'rpm -qf <filename>' (using the FULL PATH to the filename). Under Debian you can use the command: 'dpkg -S <filename>' (where you can use the full path or just a simple substring --- though the latter may list many matches other than the one you care about).
On an RPM system (such as Red Hat or S.u.S.E.) you should look for the e2fsprogs-*.src.rpm file on your "sources" CD or on their web/ftp sites. When you use the 'rpm' command to install a .src.rpm file you'll actually find the sources installed under the /usr/src/redhat/SOURCES directory. (Actually it will be under the /usr/src/<distributionname>/SOURCES directory). Those are called the "pristine" sources. There will be at least one file (usually a tar.gz or "tar ball"). Usually there will also be a set of "patches" (files created with the 'diff' commmand) which modify the pristine sources in whatever ways the packager felt was necessary.
To build new, installable, RPM files from the installed src.rpm you use a command like:
rpm -bb /usr/src/redhat/SPECS/<package-name>.spec
... an RPM .spec file is sort of like a 'make' file. It lists the names of the source files and patches, has the package name, description, author, packager, and other meta data, and contains scripts which are used to build the package, as well as the pre and post-install and removal scripts which prepare a system for the installation of a package, complete the configuration of a package, prepare a system for the removal of a package and/or clean up after the removal of a package.
You can ignore the 'rpm -bb' command if you simply want to play with the sources, build your own private copy of the binary and experiment with it. You can always bypass the packaging system for "local" binaries. Alternatively you can take any sources from the 'net, or that you write yourself, and create a .spec file for them. That allows you to build your own packages and manage your local programs using the RPM system.
The Debian packaging system is similar. However it uses "rules" scripts (which usually start with '#!/usr/bin/make -f' or something like that). It's a bit more difficult to build Debian packages --- but there are over 400 Debian maintainers, so it can be too difficult. There are also a number of packages that Debian maintainers use to make the job somewhat easier. The hardest part is that you must come up with a make target that installs the resulting binaries into a "prefix/root" directory. In other words the analogue to "make install" must install all of it's files into a set of directories that are relative to your own, rather than under root. Any well written Makefile and/or ./configure script already allows one to specify a --prefix or define (-D) a prefix.
Anyway, that's the short form. If all else fails, look at the old North Carolina "sunsite" archives (now known as ftp://metalab.unc.edu/pub/Linux). That still has a vast array of Linux source archives, mostly in good old tarball form. Of course there are also Freshmeat (http://www.freshmeat.net) and Appwatch (http://www.appwatch.com).


Copyright © 2000, James T. Dennis
Published in The Linux Gazette Issue 52 April 2000
HTML transformation by Heather Stern of Tuxtops, Inc., http://www.tuxtops.com/


[ Answer Guy Current Index ] [ Index of Past Answers ] greetings 1 2 3 4
5 6 7 8 9
10 11 12 13 14 15 16 17
18 19 20 21 22 23 24


[ Table Of Contents ] [ Front Page ] [ Previous Section ] [ Linux Gazette FAQ ] [ Next Section ]