From: Nathan Scott Date: Wed, 11 Jul 2001 04:01:18 +0000 (+0000) Subject: rework for libtool support. X-Git-Tag: v1.3.0 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f937adaca258caee81ccc668ce1c5a0c5e3c2152;p=thirdparty%2Fxfsprogs-dev.git rework for libtool support. --- diff --git a/Makefile b/Makefile index 6bcec76b9..3c66cc412 100644 --- a/Makefile +++ b/Makefile @@ -38,10 +38,15 @@ include $(TOPDIR)/include/builddefs endif CONFIGURE = configure include/builddefs include/platform_defs.h -LSRCFILES = configure configure.in Makepkgs install-sh README VERSION -LDIRT = config.* conftest* Logs/* built install.* install-dev.* *.gz -SUBDIRS = include libxfs libhandle \ +LT_LSRCFILES = config.guess config.sub ltmain.sh ltconfig aclocal.m4 +LSRCFILES = configure configure.in Makepkgs install-sh README VERSION \ + $(LT_LSRCFILES) + +LDIRT = config.log config.status config.cache confdefs.h conftest* \ + Logs/* built .census install.* install-dev.* *.gz libtool + +SUBDIRS = include libxfs libhandle libdisk \ bmap db freeze fsck growfs logprint mkfile mkfs repair rtcp \ man doc debian build @@ -58,10 +63,10 @@ else clean: # if configure hasn't run, nothing to clean endif -$(CONFIGURE): configure.in include/builddefs.in VERSION - rm -f config.cache +$(CONFIGURE): autoconf ./configure + touch .census install: default $(SUBDIRS_MAKERULE) diff --git a/VERSION b/VERSION index 147b299db..edf33a81f 100644 --- a/VERSION +++ b/VERSION @@ -2,6 +2,6 @@ # This file is used by configure to get version information # PKG_MAJOR=1 -PKG_MINOR=2 -PKG_REVISION=8 -PKG_BUILD=0 +PKG_MINOR=3 +PKG_REVISION=0 +PKG_BUILD=pre1 diff --git a/bmap/Makefile b/bmap/Makefile index bbb2adbbe..f5e09a572 100644 --- a/bmap/Makefile +++ b/bmap/Makefile @@ -33,14 +33,15 @@ TOPDIR = .. include $(TOPDIR)/include/builddefs -CMDTARGET = xfs_bmap +LTCOMMAND = xfs_bmap CFILES = xfs_bmap.c +LLDFLAGS += -static -default: $(CMDTARGET) +default: $(LTCOMMAND) include $(BUILDRULES) install: default $(INSTALL) -m 755 -d $(PKG_BIN_DIR) - $(INSTALL) -m 755 $(CMDTARGET) $(PKG_BIN_DIR) + $(INSTALL) -m 755 $(LTCOMMAND) $(PKG_BIN_DIR) install-dev: diff --git a/configure.in b/configure.in index cec479d09..e5a8af917 100644 --- a/configure.in +++ b/configure.in @@ -3,6 +3,12 @@ AC_INIT(include/libxfs.h) pkg_name="xfsprogs" AC_SUBST(pkg_name) +# For libtool +AC_PROG_LIBTOOL +AC_SUBST(LIBTOOL_DEPS) +AC_SUBST(enable_shared) + + # # Note: the following environment variables may be set to override the # defaults (to change paths and/or executables, build parameters, etc): @@ -35,7 +41,7 @@ pkg_release=$PKG_BUILD AC_SUBST(pkg_version) AC_SUBST(pkg_release) -pkg_distribution="SGI ProPack" +pkg_distribution="SGI XFS" test -z "$DISTRIBUTION" || pkg_distribution="$DISTRIBUTION" AC_SUBST(pkg_distribution) @@ -233,6 +239,8 @@ AC_SUBST(pkg_sbin_dir) dnl include files pkg_inc_dir=${prefix}/include/xfs AC_SUBST(pkg_inc_dir) +dk_inc_dir=${prefix}/include/disk +AC_SUBST(dk_inc_dir) dnl doc directory pkg_doc_dir=${prefix}/share/doc/${pkg_name} @@ -243,6 +251,14 @@ dnl dnl output files dnl +#For libtool, from section 5.4.2 of the libtool manual. Just in +# case we ever need them. +LTLIBOBJS=`echo "$LIBOBJS" | sed 's/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'` +AC_SUBST(LTLIBOBJS) +LTALLOCA=`echo "$ALLOCA" | sed 's/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'` +AC_SUBST(LTALLOCA) + + AC_OUTPUT( \ dnl Build definitions for use in Makefiles include/builddefs \ diff --git a/db/Makefile b/db/Makefile index 666c7918f..2fc3a9d6a 100644 --- a/db/Makefile +++ b/db/Makefile @@ -33,7 +33,7 @@ TOPDIR = .. include $(TOPDIR)/include/builddefs -CMDTARGET = xfs_db +LTCOMMAND = xfs_db HFILES = addr.h agf.h agfl.h agi.h attr.h attrshort.h bit.h block.h bmap.h \ bmapbt.h bmroot.h bnobt.h check.h cntbt.h command.h convert.h data.h \ @@ -44,15 +44,16 @@ HFILES = addr.h agf.h agfl.h agi.h attr.h attrshort.h bit.h block.h bmap.h \ CFILES = $(HFILES:.h=.c) main.c LSRCFILES = xfs_admin.sh xfs_check.sh xfs_ncheck.sh LLDLIBS = $(LIBXFS) $(LIBUUID) -LLDFLAGS = -L$(TOPDIR)/libxfs +LTDEPENDENCIES = $(LIBXFS) +LLDFLAGS += -static -default: $(CMDTARGET) +default: $(LTCOMMAND) include $(BUILDRULES) install: default $(INSTALL) -m 755 -d $(PKG_BIN_DIR) - $(INSTALL) -m 755 $(CMDTARGET) $(PKG_BIN_DIR) + $(INSTALL) -m 755 $(LTCOMMAND) $(PKG_BIN_DIR) $(INSTALL) -m 755 xfs_admin.sh $(PKG_BIN_DIR)/xfs_admin $(INSTALL) -m 755 xfs_check.sh $(PKG_BIN_DIR)/xfs_check $(INSTALL) -m 755 xfs_ncheck.sh $(PKG_BIN_DIR)/xfs_ncheck diff --git a/debian/changelog b/debian/changelog index e2b1921e2..9370fa066 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,13 @@ +xfsprogs (1.3.0) unstable; urgency=low + + * Reworked Makefiles to use libtool + * New libdisk to allow sharing of generic mount/disk code and + * Also abstracts individual driver support (LVM, MD, XVM..) + * Partition table detection so mkfs.xfs doesn't blindly overwrite + * Small xfs_repair bug fix from Steve + + -- Nathan Scott Thu, 19 Jul 2001 10:12:03 +1000 + xfsprogs (1.2.8) unstable; urgency=low * Fixed a bug in libxfs /etc/mtab read-only mount detection diff --git a/debian/control b/debian/control index 39d8d7db2..5fc550ead 100644 --- a/debian/control +++ b/debian/control @@ -2,7 +2,7 @@ Source: xfsprogs Section: admin Priority: optional Maintainer: Nathan Scott -Build-Depends: uuid-dev, autoconf, debmake +Build-Depends: uuid-dev, autoconf, debmake, libtool Standards-Version: 3.1.1 Package: xfsprogs diff --git a/debian/rules b/debian/rules index b1904a803..1c0a72cc4 100755 --- a/debian/rules +++ b/debian/rules @@ -15,18 +15,23 @@ options = DEBUG=-DNDEBUG; DISTRIBUTION=debian; export DEBUG DISTRIBUTION; checkdir = test -f debian/rules build: built -built: +built: config @echo "== dpkg-buildpackage: build" 1>&2 + $(MAKE) default + touch built + +config: .census +.census: + @echo "== dpkg-buildpackage: configure" 1>&2 $(checkdir) autoconf $(options) ./configure - $(MAKE) default - touch built + touch .census clean: @echo "== dpkg-buildpackage: clean" 1>&2 $(checkdir) - -rm -f built + -rm -f built .census $(MAKE) distclean -rm -rf $(dirtmp) $(dirdev) debian/*substvars debian/files* @@ -44,7 +49,8 @@ binary-arch: checkroot built $(pkgdev) ./install-sh -m 644 debian/copyright $(docdev) $(pkgdev) ./install-sh -m 644 debian/changelog $(docdev) @echo "== dpkg-buildpackage: debstd" 1>&2 - $(stdenv) debstd -m + # dev pkg with .so symlinks to base pkg confuses debstd... + $(stdenv) debstd -m | grep -v 'Dangling symlink' dpkg-gencontrol -isp -p$(package) -P$(dirtmp) dpkg-gencontrol -isp -p$(develop) -P$(dirdev) chown -R root.root $(dirtmp) $(dirdev) diff --git a/doc/CHANGES b/doc/CHANGES index 08429ab5b..2d54d627c 100644 --- a/doc/CHANGES +++ b/doc/CHANGES @@ -1,3 +1,10 @@ +xfsprogs-1.3.0 (19 Jul 2001) + - reworked Makefiles to use libtool + - new libdisk to allow sharing of generic mount/disk code and + - also abstracts individual driver support (LVM, MD, XVM..) + - partition table detection so mkfs.xfs doesn't blindly overwrite + - small xfs_repair bug fix from Steve + xfsprogs-1.2.8 (02 Jul 2001) - fixed a bug in libxfs /etc/mtab read-only mount detection - first try procfs, fall back to /etc/mtab, for read-only mounts diff --git a/doc/INSTALL b/doc/INSTALL index 83facca26..3c8f7a611 100644 --- a/doc/INSTALL +++ b/doc/INSTALL @@ -4,12 +4,14 @@ run them. 0. If you have the binary rpm, simply install it and skip to step 2 (below). The rpm command to do this is: - # rpm -Uvh xfsprogs + # rpm -Uvh xfsprogs-*.rpm + [and optionally, for the development libraries and headers] + # rpm -Uvh xfsprogs-devel-*.rpm The Debian command to do this is: - # dpkg -i xfsprogs - or, if you have apt configured (don't need the binary package): # apt-get install xfsprogs + [and optionally, for the development libraries and headers] + # apt-get install xfslibs-dev 1. Configure, build and install the package @@ -25,15 +27,17 @@ run them. directory. It will also leave a tar file in the build/tar directory. - # ./Makepkgs verbose + # ./Makepkgs verbose If you want to build the package and install it manually, use the following steps: - # make configure (or run autoconf; ./configure) - # make - # su root - # make install + # make configure (or run autoconf; ./configure) + # make + # su root + # make install + [and optionally, for the development libraries and headers] + # make install-dev Note that there are so many "install" variants out there that we wrote our own script (see "install-sh" in the top level directory). @@ -41,7 +45,7 @@ run them. If you wish to turn off debugging asserts in the command build and turn on the optimizer then set the shell environment variables: - OPTIMIZER=-O + OPTIMIZER=-O1 DEBUG=-DNDEBUG before running make configure or Makepkgs. diff --git a/doc/Makefile b/doc/Makefile index fa3e77525..0e09ea786 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -37,7 +37,7 @@ README = README.LVM README.quota LSRCFILES = INSTALL PORTING CHANGES COPYING CREDITS $(README) LDIRT = *.gz -default: $(CMDTARGET) CHANGES.gz +default: CHANGES.gz include $(BUILDRULES) diff --git a/freeze/Makefile b/freeze/Makefile index b9820c1a8..e583e4fc7 100644 --- a/freeze/Makefile +++ b/freeze/Makefile @@ -33,15 +33,16 @@ TOPDIR = .. include $(TOPDIR)/include/builddefs -CMDTARGET = xfs_freeze +LTCOMMAND = xfs_freeze CFILES = xfs_freeze.c +LLDFLAGS += -static -default: $(CMDTARGET) +default: $(LTCOMMAND) include $(BUILDRULES) install: default $(INSTALL) -m 755 -d $(PKG_BIN_DIR) - $(INSTALL) -m 755 $(CMDTARGET) $(PKG_BIN_DIR) + $(INSTALL) -m 755 $(LTCOMMAND) $(PKG_BIN_DIR) install-dev: diff --git a/fsck/Makefile b/fsck/Makefile index 56b4e9236..5d9cce43d 100644 --- a/fsck/Makefile +++ b/fsck/Makefile @@ -33,15 +33,16 @@ TOPDIR = .. include $(TOPDIR)/include/builddefs -CMDTARGET = fsck.xfs +LTCOMMAND = fsck.xfs CFILES = xfs_fsck.c LCFLAGS = -s -O3 +LLDFLAGS += -static -default: $(CMDTARGET) +default: $(LTCOMMAND) include $(BUILDRULES) install: default $(INSTALL) -m 755 -d $(PKG_SBIN_DIR) - $(INSTALL) -m 755 $(CMDTARGET) $(PKG_SBIN_DIR) + $(INSTALL) -m 755 $(LTCOMMAND) $(PKG_SBIN_DIR) install-dev: diff --git a/growfs/Makefile b/growfs/Makefile index 6a3ade362..27bda6711 100644 --- a/growfs/Makefile +++ b/growfs/Makefile @@ -33,19 +33,19 @@ TOPDIR = .. include $(TOPDIR)/include/builddefs -CMDTARGET = xfs_growfs +LTCOMMAND = xfs_growfs CFILES = xfs_growfs.c LLDLIBS = $(LIBXFS) $(LIBUUID) -LLDFLAGS = -L$(TOPDIR)/libxfs +LLDFLAGS = -static LSRCFILES = xfs_info.sh -default: $(CMDTARGET) +default: $(LTCOMMAND) include $(BUILDRULES) install: default $(INSTALL) -m 755 -d $(PKG_BIN_DIR) - $(INSTALL) -m 755 $(CMDTARGET) $(PKG_BIN_DIR) + $(INSTALL) -m 755 $(LTCOMMAND) $(PKG_BIN_DIR) $(INSTALL) -m 755 xfs_info.sh $(PKG_BIN_DIR)/xfs_info install-dev: diff --git a/include/Makefile b/include/Makefile index 10623efed..e54a8e3e4 100644 --- a/include/Makefile +++ b/include/Makefile @@ -44,9 +44,8 @@ HFILES = arch.h handle.h jdm.h libxfs.h xqm.h \ xfs_log.h xfs_log_priv.h xfs_log_recover.h xfs_mount.h xfs_quota.h \ xfs_rtalloc.h xfs_sb.h xfs_trans.h xfs_trans_space.h xfs_types.h -LSRCFILES = platform_defs.h.in builddefs.in buildrules \ - lvm.h lvm_config.h lvm_log.h lvm_user.h liblvm.h \ - md-int.h +DK_HFILES = mountinfo.h volume.h fstyp.h dvh.h +LSRCFILES = platform_defs.h.in builddefs.in buildrules $(DK_HFILES) default install : @@ -56,3 +55,5 @@ install-dev: default $(INSTALL) -m 755 -d $(PKG_INC_DIR) $(INSTALL) -m 644 $(HFILES) $(PKG_INC_DIR) $(INSTALL) -m 644 platform_defs.h $(PKG_INC_DIR) + $(INSTALL) -m 755 -d $(DK_INC_DIR) + $(INSTALL) -m 644 $(DK_HFILES) $(DK_INC_DIR) diff --git a/include/builddefs.in b/include/builddefs.in index 274c3a543..00bfc649d 100644 --- a/include/builddefs.in +++ b/include/builddefs.in @@ -40,15 +40,14 @@ OPTIMIZER = @opt_build@ MALLOCLIB = @malloc_lib@ LIBUUID = @libuuid@ -LIBXFS = -lxfs -LIBHANDLE = -lhandle +LIBXFS = $(TOPDIR)/libxfs/libxfs.la +LIBDISK = $(TOPDIR)/libdisk/libdisk.la +LIBHANDLE = $(TOPDIR)/libhandle/libhandle.la LIBLVM = @liblvm@ USELVM = -DHAVE_LIBLVM=@have_liblvm@ +DK_INC_DIR = @dk_inc_dir@ -BUILDRULES = $(TOPDIR)/include/buildrules - -# General package information PKG_NAME = @pkg_name@ PKG_RELEASE = @pkg_release@ PKG_VERSION = @pkg_version@ @@ -62,6 +61,31 @@ PKG_INC_DIR = @pkg_inc_dir@ PKG_MAN_DIR = @pkg_man_dir@ PKG_DOC_DIR = @pkg_doc_dir@ +CC = @cc@ +LD = @ld@ +AWK = @awk@ +SED = @sed@ +MAKE = @make@ +ECHO = @echo@ +LN_S = @LN_S@ +ZIP = @zip@ +TAR = @tar@ +RPM = @rpm@ + +RPM_VERSION = @rpm_version@ +HAVE_ZIPPED_MANPAGES = @have_zipped_manpages@ +MAKEDEPEND = @makedepend@ + +LIBTOOL = @LIBTOOL@ +LIBTOOL_DEPS = @LIBTOOL_DEPS@ +ENABLE_SHARED = @enable_shared@ + +# +# end configure'd section + + +BUILDRULES = $(TOPDIR)/include/buildrules + # LCFLAGS, LLDFLAGS, LLDLIBS, LSRCFILES and LDIRT may be specified in # user Makefiles. Note: LSRCFILES is anything other than Makefile, $(CFILES) # $(CXXFILES), or $(HFILES) and is used to construct the manifest list @@ -76,54 +100,61 @@ LDLIBS = $(LLDLIBS) $(MALLOCLIB) MAKEOPTS = --no-print-directory SRCFILES = Makefile $(HFILES) $(CFILES) $(LSRCFILES) $(LFILES) $(YFILES) -DIRT = $(LDIRT) dep dep.bak $(OBJECTS) $(CMDTARGET) $(LIBTARGET) \ - $(STATICLIBTARGET) *.[1-9].gz +DIRT = $(LDIRT) dep dep.bak $(OBJECTS) $(LTCOMMAND) $(LTLIBRARY) *.[1-9].gz OBJECTS = $(ASFILES:.s=.o) \ $(CFILES:.c=.o) \ $(LFILES:.l=.o) \ $(YFILES:%.y=%.tab.o) -MAKE = @make@ -CC = @cc@ -LD = @ld@ -AWK = @awk@ -SED = @sed@ INSTALL = $(TOPDIR)/install-sh -o root -g root -ECHO = @echo@ -LN_S = @LN_S@ + +SHELL = /bin/sh +IMAGES_DIR = $(TOPDIR)/all-images +DIST_DIR = $(TOPDIR)/dist CCF = $(CC) $(CFLAGS) MAKEF = $(MAKE) $(MAKEOPTS) CXXF = $(CXX) $(CXXFLAGS) LDF = $(LD) $(LDFLAGS) -MAKEDEPEND = @makedepend@ - -ZIP = @zip@ -TAR = @tar@ -RPM = @rpm@ -RPM_VERSION = @rpm_version@ -HAVE_ZIPPED_MANPAGES = @have_zipped_manpages@ +# For libtool. Pieces from Automake, slightly modified. +top_builddir = $(TOPDIR) +DIRT += $(LTOBJECTS) $(LTLIBRARY) +LTLINK = $(LIBTOOL) --mode=link $(CC) +LTEXEC = $(LIBTOOL) --mode=execute +LTCOMPILE = $(LIBTOOL) --mode=compile $(CCF) -D_REENTRANT +LTVERSION = $(LT_CURRENT).$(LT_REVISION).$(LT_AGE) +LTOBJECTS = $(OBJECTS:.o=.lo) +ifeq ($(ENABLE_SHARED),yes) +LTLDFLAGS += -rpath $(PKG_LIB_DIR) +LTLDFLAGS += -version-info $(subst .,:,$(LTVERSION)) +endif +LIBNAME = $(basename $(LTLIBRARY)) + +ifeq ($(ENABLE_SHARED),yes) +INSTALL_LTLIB = \ + cd $(TOPDIR)/$(LIBNAME)/.libs; \ + ../$(INSTALL) -m 755 -d $(PKG_LIB_DIR); \ + ../$(INSTALL) -m 644 $(LIBNAME).so.$(LTVERSION) $(PKG_LIB_DIR); \ + test "$(PKG_DISTRIBUTION)" = debian || \ + ../$(INSTALL) -S $(LIBNAME).so.$(LTVERSION) $(PKG_LIB_DIR)/$(LIBNAME).so.$(LT_CURRENT) +endif -SHELL = /bin/sh -IMAGES_DIR = $(TOPDIR)/all-images -DIST_DIR = $(TOPDIR)/dist +ifeq ($(ENABLE_SHARED),yes) +INSTALL_LTLIB_DEV = \ + cd $(TOPDIR)/$(LIBNAME)/.libs; \ + ../$(INSTALL) -m 755 -d $(PKG_LIB_DIR); \ + ../$(INSTALL) -m 644 $(LIBNAME).a $(PKG_LIB_DIR); \ + ../$(INSTALL) -S $(LIBNAME).so.$(LT_CURRENT) $(PKG_LIB_DIR)/$(LIBNAME).so +else +INSTALL_LTLIB_DEV = $(INSTALL_LTLIB_STATIC) +endif -SUBDIRS_MAKERULE = \ - @for d in $(SUBDIRS) ""; do \ - if test -d "$$d" -a ! -z "$$d"; then \ - $(ECHO) === $$d ===; \ - $(MAKEF) -C $$d $@ || exit $$?; \ - fi; \ - done - -MAN_MAKERULE = \ - @for f in *.[12345678] ""; do \ - if test ! -z "$$f"; then \ - $(ZIP) --best -c < $$f > $$f.gz; \ - fi; \ - done +INSTALL_LTLIB_STATIC = \ + cd $(TOPDIR)/$(LIBNAME)/.libs; \ + ../$(INSTALL) -m 755 -d $(PKG_LIB_DIR); \ + ../$(INSTALL) -m 644 $(LIBNAME).a $(PKG_LIB_DIR) INSTALL_MAN = \ @for d in $(MAN_PAGES); do \ @@ -148,6 +179,21 @@ INSTALL_MAN = \ done; \ done +SUBDIRS_MAKERULE = \ + @for d in $(SUBDIRS) ""; do \ + if test -d "$$d" -a ! -z "$$d"; then \ + $(ECHO) === $$d ===; \ + $(MAKEF) -C $$d $@ || exit $$?; \ + fi; \ + done + +MAN_MAKERULE = \ + @for f in *.[12345678] ""; do \ + if test ! -z "$$f"; then \ + $(ZIP) --best -c < $$f > $$f.gz; \ + fi; \ + done + DIST_MAKERULE = \ $(MAKEF) -C build dist diff --git a/include/buildrules b/include/buildrules index dab3faeda..11b192271 100644 --- a/include/buildrules +++ b/include/buildrules @@ -26,28 +26,9 @@ _BUILDRULES_INCLUDED_ = 1 include $(TOPDIR)/include/builddefs -# -# Standard targets -# -ifdef CMDTARGET -$(CMDTARGET) : $(SUBDIRS) $(OBJECTS) - $(CCF) -o $(CMDTARGET) $(LDFLAGS) $(OBJECTS) $(LDLIBS) -$(CMDTARGET).static : $(SUBDIRS) $(OBJECTS) - $(CCF) -static -o $(CMDTARGET).static $(LDFLAGS) $(OBJECTS) $(LDLIBS) -endif - -ifdef LIBTARGET -$(LIBTARGET) : $(SUBDIRS) $(OBJECTS) - $(CC) $(LDFLAGS) -fPIC -shared -Wl,-soname,$(LIBTARGET) -o $(LIBTARGET) $(OBJECTS) $(LDLIBS) -endif - -ifdef STATICLIBTARGET -$(STATICLIBTARGET) : $(SUBDIRS) $(OBJECTS) - $(AR) crf $(STATICLIBTARGET) $? -endif - clean clobber : $(SUBDIRS) rm -f $(DIRT) + @rm -fr .libs $(SUBDIRS_MAKERULE) # Never blow away subdirs @@ -57,10 +38,27 @@ $(SUBDIRS): $(SUBDIRS_MAKERULE) endif +# +# Standard targets +# + +ifdef LTCOMMAND +$(LTCOMMAND) : $(SUBDIRS) $(OBJECTS) $(LTDEPENDENCIES) + $(LTLINK) -o $@ $(LDFLAGS) $(OBJECTS) $(LDLIBS) +endif + +ifdef LTLIBRARY +$(LTLIBRARY) : $(SUBDIRS) $(LTOBJECTS) + $(LTLINK) $(LDFLAGS) $(LTLDFLAGS) -o $(LTLIBRARY) $(LTOBJECTS) $(LDLIBS) + +%.lo: %.c + $(LTCOMPILE) -c $< +endif + source : $(SOURCE_MAKERULE) -endif +endif # _BUILDRULES_INCLUDED_ $(_FORCE): diff --git a/include/dvh.h b/include/dvh.h new file mode 100644 index 000000000..2c764b256 --- /dev/null +++ b/include/dvh.h @@ -0,0 +1,191 @@ +/* + * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it would be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write the Free Software Foundation, Inc., 59 + * Temple Place - Suite 330, Boston MA 02111-1307, USA. + * + * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, + * Mountain View, CA 94043, or: + * + * http://www.sgi.com + * + * For further information regarding this notice, see: + * + * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ + */ +#ifndef __DVH_H__ +#define __DVH_H__ + +/* + * Format for volume header information + * + * The volume header is a block located at the beginning of all disk + * media (sector 0). It contains information pertaining to physical + * device parameters and logical partition information. + * + * The volume header is manipulated by disk formatters/verifiers, + * partition builders (e.g. fx, dvhtool, and mkfs), and disk drivers. + * + * Previous versions of IRIX wrote a copy of the volume header is + * located at sector 0 of each track of cylinder 0. These copies were + * never used, and reduced the capacity of the volume header to hold large + * files, so this practice was discontinued. + * The volume header is constrained to be less than or equal to 512 + * bytes long. A particular copy is assumed valid if no drive errors + * are detected, the magic number is correct, and the 32 bit 2's complement + * of the volume header is correct. The checksum is calculated by initially + * zeroing vh_csum, summing the entire structure and then storing the + * 2's complement of the sum. Thus a checksum to verify the volume header + * should be 0. + * + * The error summary table, bad sector replacement table, and boot blocks are + * located by searching the volume directory within the volume header. + * + * Tables are sized simply by the integral number of table records that + * will fit in the space indicated by the directory entry. + * + * The amount of space allocated to the volume header, replacement blocks, + * and other tables is user defined when the device is formatted. + */ + +/* + * device parameters are in the volume header to determine mapping + * from logical block numbers to physical device addresses + * + * Linux doesn't care ... + */ +struct device_parameters { + unsigned char dp_skew; /* spiral addressing skew */ + unsigned char dp_gap1; /* words of 0 before header */ + unsigned char dp_gap2; /* words of 0 between hdr and data */ + unsigned char dp_spares_cyl; /* This is for drives (such as SCSI + that support zone oriented sparing, where the zone is larger + than one track. It gets subracteded from the cylinder size + ( dp_trks0 * dp_sec) when doing partition size calculations */ + unsigned short dp_cyls; /* number of usable cylinders (i.e., + doesn't include cylinders reserved by the drive for badblocks, + etc.). For drives with variable geometry, this number may be + decreased so that: + dp_cyls * ((dp_heads * dp_trks0) - dp_spares_cyl) <= actualcapacity + This happens on SCSI drives such as the Wren IV and Toshiba 156 + Also see dp_cylshi below */ + unsigned short dp_shd0; /* starting head vol 0 */ + unsigned short dp_trks0; /* number of tracks / cylinder vol 0*/ + unsigned char dp_ctq_depth; /* Depth of CTQ queue */ + unsigned char dp_cylshi; /* high byte of 24 bits of cylinder count */ + unsigned short dp_unused; /* not used */ + unsigned short dp_secs; /* number of sectors/track */ + unsigned short dp_secbytes; /* length of sector in bytes */ + unsigned short dp_interleave; /* sector interleave */ + int dp_flags; /* controller characteristics */ + int dp_datarate; /* bytes/sec for kernel stats */ + int dp_nretries; /* max num retries on data error */ + int dp_mspw; /* ms per word to xfer, for iostat */ + unsigned short dp_xgap1; /* Gap 1 for xylogics controllers */ + unsigned short dp_xsync; /* sync delay for xylogics controllers */ + unsigned short dp_xrdly; /* read delay for xylogics controllers */ + unsigned short dp_xgap2; /* gap 2 for xylogics controllers */ + unsigned short dp_xrgate; /* read gate for xylogics controllers */ + unsigned short dp_xwcont; /* write continuation for xylogics */ +}; + +/* + * Device characterization flags + * (dp_flags) + */ +#define DP_SECTSLIP 0x00000001 /* sector slip to spare sector */ +#define DP_SECTFWD 0x00000002 /* forward to replacement sector */ +#define DP_TRKFWD 0x00000004 /* forward to replacement track */ +#define DP_MULTIVOL 0x00000008 /* multiple volumes per spindle */ +#define DP_IGNOREERRORS 0x00000010 /* transfer data regardless of errors */ +#define DP_RESEEK 0x00000020 /* recalibrate as last resort */ +#define DP_CTQ_EN 0x00000040 /* enable command tag queueing */ + +/* + * Boot blocks, bad sector tables, and the error summary table, are located + * via the volume_directory. + */ +#define VDNAMESIZE 8 + +struct volume_directory { + char vd_name[VDNAMESIZE]; /* name */ + int vd_lbn; /* logical block number */ + int vd_nbytes; /* file length in bytes */ +}; + +/* + * partition table describes logical device partitions + * (device drivers examine this to determine mapping from logical units + * to cylinder groups, device formatters/verifiers examine this to determine + * location of replacement tracks/sectors, etc) + * + * NOTE: pt_firstlbn SHOULD BE CYLINDER ALIGNED + */ +struct partition_table { /* one per logical partition */ + int pt_nblks; /* # of logical blks in partition */ + int pt_firstlbn; /* first lbn of partition */ + int pt_type; /* use of partition */ +}; + +#define PTYPE_VOLHDR 0 /* partition is volume header */ +#define PTYPE_TRKREPL 1 /* partition is used for repl trks */ +#define PTYPE_SECREPL 2 /* partition is used for repl secs */ +#define PTYPE_RAW 3 /* partition is used for data */ +#define PTYPE_BSD42 4 /* partition is 4.2BSD file system */ +#define PTYPE_BSD 4 /* partition is 4.2BSD file system */ +#define PTYPE_SYSV 5 /* partition is SysV file system */ +#define PTYPE_VOLUME 6 /* partition is entire volume */ +#define PTYPE_EFS 7 /* partition is sgi EFS */ +#define PTYPE_LVOL 8 /* partition is part of a logical vol */ +#define PTYPE_RLVOL 9 /* part of a "raw" logical vol */ +#define PTYPE_XFS 10 /* partition is sgi XFS */ +#define PTYPE_XFSLOG 11 /* partition is sgi XFS log */ +#define PTYPE_XLV 12 /* partition is part of an XLV vol */ +#define PTYPE_XVM 13 /* partition is sgi XVM */ +#define NPTYPES 16 + +#define VHMAGIC 0xbe5a941 /* randomly chosen value */ +#define NPARTAB 16 /* 16 unix partitions */ +#define NVDIR 15 /* max of 15 directory entries */ +#define BFNAMESIZE 16 /* max 16 chars in boot file name */ + +/* Partition types for ARCS */ +#define NOT_USED 0 /* Not used */ +#define FAT_SHORT 1 /* FAT filesystem, 12-bit FAT entries */ +#define FAT_LONG 4 /* FAT filesystem, 16-bit FAT entries */ +#define EXTENDED 5 /* extended partition */ +#define HUGE 6 /* huge partition- MS/DOS 4.0 and later */ + +/* Active flags for ARCS */ +#define BOOTABLE 0x00; +#define NOT_BOOTABLE 0x80; + +struct volume_header { + int vh_magic; /* identifies volume header */ + short vh_rootpt; /* root partition number */ + short vh_swappt; /* swap partition number */ + char vh_bootfile[BFNAMESIZE]; /* name of file to boot */ + struct device_parameters vh_dp; /* device parameters */ + struct volume_directory vh_vd[NVDIR]; /* other vol hdr contents */ + struct partition_table vh_pt[NPARTAB]; /* device partition layout */ + int vh_csum; /* volume header checksum */ + int vh_fill; /* fill out to 512 bytes */ +}; + +#endif /* __DVH_H__ */ diff --git a/include/fstyp.h b/include/fstyp.h new file mode 100644 index 000000000..b9aab89b1 --- /dev/null +++ b/include/fstyp.h @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it would be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write the Free Software Foundation, Inc., 59 + * Temple Place - Suite 330, Boston MA 02111-1307, USA. + * + * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, + * Mountain View, CA 94043, or: + * + * http://www.sgi.com + * + * For further information regarding this notice, see: + * + * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ + */ +#ifndef __FSTYP_H__ +#define __FSTYP_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Compatibility macros for IRIX fstyp.h, in case anyone needs them. + */ +#define FSTYPSZ 16 /* max size of fs identifier */ +/* Opcodes for the sysfs() system call. */ +#define GETFSIND 1 /* translate fs identifier to fstype index */ +#define GETFSTYP 2 /* translate fstype index to fs identifier */ +#define GETNFSTYP 3 /* return the number of fstypes */ +extern int sysfs (int, ...); + +/* + * fstype allows the user to determine the filesystem identifier of + * mounted or unmounted filesystems, using heuristics. + * The filesystem type is required by mount(2) and sometimes by mount(8) + * to mount filesystems of different types. + */ +extern char *fstype (const char * __device); + +/* + * ptabtype allows one to determine the type of partition table in + * use on a given volume, using heuristics. + */ +extern char *pttype (const char *__device); + +#ifdef __cplusplus +} +#endif + +#endif /* __FSTYP_H__ */ diff --git a/include/mountinfo.h b/include/mountinfo.h new file mode 100644 index 000000000..771f6b9b8 --- /dev/null +++ b/include/mountinfo.h @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it would be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write the Free Software Foundation, Inc., 59 + * Temple Place - Suite 330, Boston MA 02111-1307, USA. + * + * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, + * Mountain View, CA 94043, or: + * + * http://www.sgi.com + * + * For further information regarding this notice, see: + * + * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ + */ +#ifndef __MOUNTINFO_H__ +#define __MOUNTINFO_H__ + +/* + * mountinfo.h + * Header for disk volume/partition check routines + */ + +#define MNT_CAUSE_NONE 0x00 +#define MNT_CAUSE_MOUNTED 0x01 /* partition already mounted */ +#define MNT_CAUSE_OVERLAP 0x02 /* partitions overlap */ +#define MNT_CAUSE_NODEV 0x04 /* no /dev/rdsk /dev/dsk entry */ +#define MNT_CAUSE_UNUSED 0x08 /* unallocated partition */ +#define MNT_CAUSE_MULTIMOUNT 0x10 /* multiple owners */ +#define MNT_CAUSE_LVOL_OWNED 0x20 /* owned by logical vol */ +#define MNT_CAUSE_XVM_MNT 0x40 /* mounted xvm subvolume */ +#define MNT_CAUSE_XVM_PART 0x80 /* xvm-owned partition */ +#define MNT_CAUSE__END 0x100 /* last entry */ + +typedef struct mnt_check_state_s { + /* currently unused, remains from IRIX */ +} mnt_check_state_t; + +/* prototypes */ +extern int mnt_check_init (mnt_check_state_t **); +extern int mnt_find_mount_conflicts (mnt_check_state_t *, char *); +extern int mnt_find_mounted_partitions (mnt_check_state_t *, char *); +extern int mnt_causes_test (mnt_check_state_t *, int); +extern void mnt_causes_show (mnt_check_state_t *, FILE *, char *); +extern void mnt_plist_show (mnt_check_state_t *, FILE *, char *); +extern int mnt_check_end (mnt_check_state_t *); + +#endif /* __MOUNTINFO_H__ */ diff --git a/include/volume.h b/include/volume.h new file mode 100644 index 000000000..eef504147 --- /dev/null +++ b/include/volume.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it would be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write the Free Software Foundation, Inc., 59 + * Temple Place - Suite 330, Boston MA 02111-1307, USA. + * + * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, + * Mountain View, CA 94043, or: + * + * http://www.sgi.com + * + * For further information regarding this notice, see: + * + * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ + */ +#ifndef __VOLUME_H__ +#define __VOLUME_H__ + +/* + * Subvolume Types for all volume managers. + * + * There is a maximum of 255 subvolumes. 0 is reserved. + * Note: SVTYPE_LOG, SVTYPE_DATA, SVTYPE_RT values matches XLV. + * Do not change - Colin Ngam + */ +typedef enum sv_type_e { + SVTYPE_ALL =0, /* special: denotes all sv's */ + SVTYPE_LOG =1, /* XVM Log subvol type */ + SVTYPE_DATA, /* XVM Data subvol type */ + SVTYPE_RT, /* XVM Real Time subvol type */ + SVTYPE_SWAP, /* swap area */ + SVTYPE_RSVD5, /* reserved 5 */ + SVTYPE_RSVD6, /* reserved 6 */ + SVTYPE_RSVD7, /* reserved 7 */ + SVTYPE_RSVD8, /* reserved 8 */ + SVTYPE_RSVD9, /* reserved 9 */ + SVTYPE_RSVD10, /* reserved 10 */ + SVTYPE_RSVD11, /* reserved 11 */ + SVTYPE_RSVD12, /* reserved 12 */ + SVTYPE_RSVD13, /* reserved 13 */ + SVTYPE_RSVD14, /* reserved 14 */ + SVTYPE_RSVD15, /* reserved 15 */ + SVTYPE_USER1, /* First User Defined Subvol Type */ + SVTYPE_LAST =255 +} sv_type_t; + +extern void get_subvol_stripe_wrapper (char *, sv_type_t, int *, int *); + +#endif /* __VOLUME_H__ */ diff --git a/install-sh b/install-sh index 395497ad6..08c6c2f69 100755 --- a/install-sh +++ b/install-sh @@ -187,9 +187,9 @@ then # if [ $# -ne 1 ] then - _usage + _usage else - target=$DIST_ROOT/$1 + target=$DIST_ROOT/$1 fi $LN -s -f $symlink $target status=$? @@ -211,7 +211,7 @@ else $CP $f $dir status=$? if [ $status -eq 0 ] - then + then if [ -f $dir/$f ] then $CHMOD $FILEMODE $dir/$f @@ -222,7 +222,8 @@ else status=$? fi $MANIFEST f $FILEMODE $OWNER $GROUP $HERE/$f ${dir#$DIST_ROOT}/$f - else + elif [ -f $dir ] + then $CHMOD $FILEMODE $dir status=$? if [ $status -eq 0 ] diff --git a/libdisk/Makefile b/libdisk/Makefile new file mode 100644 index 000000000..0a4ee8c2b --- /dev/null +++ b/libdisk/Makefile @@ -0,0 +1,52 @@ +# +# Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of version 2 of the GNU General Public License as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it would be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# +# Further, this software is distributed without any warranty that it is +# free of the rightful claim of any third person regarding infringement +# or the like. Any license provided herein, whether implied or +# otherwise, applies only to this software file. Patent licenses, if +# any, provided herein do not apply to combinations of this program with +# other software, or any other product whatsoever. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write the Free Software Foundation, Inc., 59 +# Temple Place - Suite 330, Boston MA 02111-1307, USA. +# +# Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, +# Mountain View, CA 94043, or: +# +# http://www.sgi.com +# +# For further information regarding this notice, see: +# +# http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ +# + +TOPDIR = .. +include $(TOPDIR)/include/builddefs + +LTLIBRARY = libdisk.la +LT_CURRENT = 0 +LT_REVISION = 0 +LT_AGE = 0 + +LCFLAGS = $(USELVM) +CFILES = fstype.c pttype.c md.c xvm.c lvm.c drivers.c mountinfo.c +HFILES = fstype.h pttype.h md.h xvm.h lvm.h lvm_user.h liblvm.h + +default: $(LTLIBRARY) + +include $(BUILDRULES) + +install: default + +install-dev: default + $(INSTALL_LTLIB_STATIC) diff --git a/libdisk/drivers.c b/libdisk/drivers.c new file mode 100644 index 000000000..791809e92 --- /dev/null +++ b/libdisk/drivers.c @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it would be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write the Free Software Foundation, Inc., 59 + * Temple Place - Suite 330, Boston MA 02111-1307, USA. + * + * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, + * Mountain View, CA 94043, or: + * + * http://www.sgi.com + * + * For further information regarding this notice, see: + * + * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ + */ + +#include +#include +#include +#include +#include + +extern int md_get_subvol_stripe(char*, sv_type_t, int*, int*, struct stat64*); +extern int lvm_get_subvol_stripe(char*, sv_type_t, int*, int*, struct stat64*); +extern int xvm_get_subvol_stripe(char*, sv_type_t, int*, int*, struct stat64*); + +void +get_subvol_stripe_wrapper(char *dev, sv_type_t type, int *sunit, int *swidth) +{ + struct stat64 sb; + + if (dev == NULL) + return; + + if (stat64(dev, &sb)) { + fprintf(stderr, "Cannot stat %s: %s\n", dev, strerror(errno)); + exit(1); + } + + if ( md_get_subvol_stripe(dev, type, sunit, swidth, &sb)); + return; + if (lvm_get_subvol_stripe(dev, type, sunit, swidth, &sb)); + return; + if (xvm_get_subvol_stripe(dev, type, sunit, swidth, &sb)); + return; + /* ... add new device drivers here */ +} diff --git a/libdisk/fstype.c b/libdisk/fstype.c new file mode 100644 index 000000000..c936f85f4 --- /dev/null +++ b/libdisk/fstype.c @@ -0,0 +1,329 @@ +/* + * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it would be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write the Free Software Foundation, Inc., 59 + * Temple Place - Suite 330, Boston MA 02111-1307, USA. + * + * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, + * Mountain View, CA 94043, or: + * + * http://www.sgi.com + * + * For further information regarding this notice, see: + * + * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ + */ + +#include +#include +#include +#include +#include +#include +#include "fstype.h" + +/* + * From mount(8) source by Andries Brouwer. Hacked for XFS by mkp. + * Recent sync's to mount source: + * - util-linux-2.10o ... 06 Sep 00 + * - util-linux-2.10r ... 06 Dec 00 + * - util-linux-2.11g ... 02 Jul 01 + */ + +#define SIZE(a) (sizeof(a)/sizeof(a[0])) + +static inline unsigned short +swapped(unsigned short a) { + return (a>>8) | (a<<8); +} + +static inline int +assemble4le(unsigned char *p) { + return (p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24)); +} + +/* + Probes the device and attempts to determine the type of filesystem + contained within. + + Original routine by ; made into a function + for mount(8) by Mike Grupenhoff . + Read the superblock only once - aeb + Added iso9660, romfs, qnx4, udf, swap - aeb + Added a test for high sierra (iso9660) - quinlan@bucknell.edu + Corrected the test for xiafs - aeb + Added ufs from a patch by jj. But maybe there are several types of ufs? + Added ntfs from a patch by Richard Russon. + Added a very weak heuristic for vfat - aeb + Added xfs - 2000-03-21 Martin K. Petersen + Added cramfs, hfs, hpfs, adfs - Sepp Wijnands + Added ext3 - Andrew Morton +*/ + +/* udf magic - I find that trying to mount garbage as an udf fs + causes a very large kernel delay, almost killing the machine. + So, we do not try udf unless there is positive evidence that it + might work. Try iso9660 first, it is much more likely. + Strings below taken from ECMA 167. */ +static char +*udf_magic[] = { "BEA01", "BOOT2", "CD001", "CDW02", "NSR02", + "NSR03", "TEA01" }; + +static int +may_be_udf(const char *id) { + char **m; + + for (m = udf_magic; m - udf_magic < SIZE(udf_magic); m++) + if (!strncmp(*m, id, 5)) + return 1; + return 0; +} + +static int +may_be_swap(const char *s) { + return (strncmp(s-10, "SWAP-SPACE", 10) == 0 || + strncmp(s-10, "SWAPSPACE2", 10) == 0); +} + +/* rather weak necessary condition */ +static int +may_be_adfs(const u_char *s) { + u_char *p; + int sum; + + p = (u_char *) s + 511; + sum = 0; + while(--p != s) + sum = (sum >> 8) + (sum & 0xff) + *p; + + return (sum == p[511]); +} + +static int is_reiserfs_magic_string (struct reiserfs_super_block * rs) +{ + return (!strncmp (rs->s_magic, REISERFS_SUPER_MAGIC_STRING, + strlen ( REISERFS_SUPER_MAGIC_STRING)) || + !strncmp (rs->s_magic, REISER2FS_SUPER_MAGIC_STRING, + strlen ( REISER2FS_SUPER_MAGIC_STRING))); +} + +char * +fstype(const char *device) { + int fd; + char *type = NULL; + union { + struct minix_super_block ms; + struct ext_super_block es; + struct ext2_super_block e2s; + struct reiserfs_super_block rs; + } sb; + union { + struct xiafs_super_block xiasb; + char romfs_magic[8]; + char qnx4fs_magic[10]; /* ignore first 4 bytes */ + long bfs_magic; + struct ntfs_super_block ntfssb; + struct fat_super_block fatsb; + struct xfs_super_block xfsb; + struct cramfs_super_block cramfssb; + } xsb; + struct ufs_super_block ufssb; + union { + struct iso_volume_descriptor iso; + struct hs_volume_descriptor hs; + } isosb; + struct hfs_super_block hfssb; + struct hpfs_super_block hpfssb; + struct adfs_super_block adfssb; + struct stat statbuf; + + /* opening and reading an arbitrary unknown path can have + undesired side effects - first check that `device' refers + to a block device */ + if (stat (device, &statbuf) || !S_ISBLK(statbuf.st_mode)) + return 0; + + fd = open(device, O_RDONLY); + if (fd < 0) + return 0; + + if (lseek(fd, 1024, SEEK_SET) != 1024 + || read(fd, (char *) &sb, sizeof(sb)) != sizeof(sb)) + goto io_error; + + /* ext2 has magic in little-endian on disk, so "swapped" is + superfluous; however, there have existed strange byteswapped + PPC ext2 systems */ + if (ext2magic(sb.e2s) == EXT2_SUPER_MAGIC + || ext2magic(sb.e2s) == EXT2_PRE_02B_MAGIC + || ext2magic(sb.e2s) == swapped(EXT2_SUPER_MAGIC)) { + type = "ext2"; + + /* maybe even ext3? */ + if ((assemble4le(sb.e2s.s_feature_compat) + & EXT3_FEATURE_COMPAT_HAS_JOURNAL) && + assemble4le(sb.e2s.s_journal_inum) != 0) + type = "ext3,ext2"; + } + + else if (minixmagic(sb.ms) == MINIX_SUPER_MAGIC + || minixmagic(sb.ms) == MINIX_SUPER_MAGIC2 + || minixmagic(sb.ms) == swapped(MINIX_SUPER_MAGIC2)) + type = "minix"; + + else if (extmagic(sb.es) == EXT_SUPER_MAGIC) + type = "ext"; + + if (!type) { + if (lseek(fd, REISERFS_DISK_OFFSET_IN_BYTES, SEEK_SET) != + REISERFS_DISK_OFFSET_IN_BYTES + || read(fd, (char *) &sb, sizeof(sb)) != sizeof(sb)) + goto io_error; + if (is_reiserfs_magic_string(&sb.rs)) + type = "reiserfs"; + } + + if (!type) { + if (lseek(fd, REISERFS_OLD_DISK_OFFSET_IN_BYTES, SEEK_SET) != + REISERFS_OLD_DISK_OFFSET_IN_BYTES + || read(fd, (char *) &sb, sizeof(sb)) != sizeof(sb)) + goto io_error; + if (is_reiserfs_magic_string(&sb.rs)) + type = "reiserfs"; + } + + if (!type) { + if (lseek(fd, 0, SEEK_SET) != 0 + || read(fd, (char *) &xsb, sizeof(xsb)) != sizeof(xsb)) + goto io_error; + + if (xiafsmagic(xsb.xiasb) == _XIAFS_SUPER_MAGIC) + type = "xiafs"; + else if(!strncmp(xsb.romfs_magic, "-rom1fs-", 8)) + type = "romfs"; + else if(!strncmp(xsb.xfsb.s_magic, XFS_SUPER_MAGIC, 4)) + type = "xfs"; + else if(!strncmp(xsb.qnx4fs_magic+4, "QNX4FS", 6)) + type = "qnx4fs"; + else if(xsb.bfs_magic == 0x1badface) + type = "bfs"; + else if(!strncmp(xsb.ntfssb.s_magic, NTFS_SUPER_MAGIC, + sizeof(xsb.ntfssb.s_magic))) + type = "ntfs"; + else if(cramfsmagic(xsb.cramfssb) == CRAMFS_SUPER_MAGIC) + type = "cramfs"; + else if ((!strncmp(xsb.fatsb.s_os, "MSDOS", 5) || + !strncmp(xsb.fatsb.s_os, "MSWIN", 5) || + !strncmp(xsb.fatsb.s_os, "MTOOL", 5) || + !strncmp(xsb.fatsb.s_os, "mkdosfs", 7) || + !strncmp(xsb.fatsb.s_os, "kmkdosfs", 8) || + /* Michal Svec: created by fdformat, old msdos utility for + formatting large (1.7) floppy disks. */ + !strncmp(xsb.fatsb.s_os, "CH-FOR18", 8)) + && (!strncmp(xsb.fatsb.s_fs, "FAT12 ", 8) || + !strncmp(xsb.fatsb.s_fs, "FAT16 ", 8) || + !strncmp(xsb.fatsb.s_fs2, "FAT32 ", 8))) + type = "vfat"; /* only guessing - might as well be fat or umsdos */ + } + + if (!type) { + if (lseek(fd, 8192, SEEK_SET) != 8192 + || read(fd, (char *) &ufssb, sizeof(ufssb)) != sizeof(ufssb)) + goto io_error; + + if (ufsmagic(ufssb) == UFS_SUPER_MAGIC) /* also test swapped version? */ + type = "ufs"; + } + + if (!type) { + if (lseek(fd, 0x8000, SEEK_SET) != 0x8000 + || read(fd, (char *) &isosb, sizeof(isosb)) != sizeof(isosb)) + goto io_error; + + if(strncmp(isosb.iso.id, ISO_STANDARD_ID, sizeof(isosb.iso.id)) == 0 + || strncmp(isosb.hs.id, HS_STANDARD_ID, sizeof(isosb.hs.id)) == 0) + type = "iso9660"; + else if (may_be_udf(isosb.iso.id)) + type = "udf"; + } + + if (!type) { + if (lseek(fd, 0x400, SEEK_SET) != 0x400 + || read(fd, (char *) &hfssb, sizeof(hfssb)) != sizeof(hfssb)) + goto io_error; + + /* also check if block size is equal to 512 bytes, + since the hfs driver currently only has support + for block sizes of 512 bytes long, and to be + more accurate (sb magic is only a short int) */ + if ((hfsmagic(hfssb) == HFS_SUPER_MAGIC && + hfsblksize(hfssb) == 0x20000) || + (swapped(hfsmagic(hfssb)) == HFS_SUPER_MAGIC && + hfsblksize(hfssb) == 0x200)) + type = "hfs"; + } + + if (!type) { + if (lseek(fd, 0x2000, SEEK_SET) != 0x2000 + || read(fd, (char *) &hpfssb, sizeof(hpfssb)) != sizeof(hpfssb)) + goto io_error; + + if (hpfsmagic(hpfssb) == HPFS_SUPER_MAGIC) + type = "hpfs"; + } + + if (!type) { + if (lseek(fd, 0xc00, SEEK_SET) != 0xc00 + || read(fd, (char *) &adfssb, sizeof(adfssb)) != sizeof(adfssb)) + goto io_error; + + /* only a weak test */ + if (may_be_adfs((u_char *) &adfssb) + && (adfsblksize(adfssb) >= 8 && + adfsblksize(adfssb) <= 10)) + type = "adfs"; + } + + if (!type) { + /* perhaps the user tries to mount the swap space + on a new disk; warn her before she does mkfs on it */ + int pagesize = getpagesize(); + int rd; + char buf[32768]; + + rd = pagesize; + if (rd < 8192) + rd = 8192; + if (rd > sizeof(buf)) + rd = sizeof(buf); + if (lseek(fd, 0, SEEK_SET) != 0 + || read(fd, buf, rd) != rd) + goto io_error; + if (may_be_swap(buf+pagesize) || + may_be_swap(buf+4096) || may_be_swap(buf+8192)) + type = "swap"; + } + + close (fd); + return(type); + +io_error: + close(fd); + return 0; +} diff --git a/libdisk/fstype.h b/libdisk/fstype.h new file mode 100644 index 000000000..a66f052bd --- /dev/null +++ b/libdisk/fstype.h @@ -0,0 +1,213 @@ +/* + * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it would be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write the Free Software Foundation, Inc., 59 + * Temple Place - Suite 330, Boston MA 02111-1307, USA. + * + * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, + * Mountain View, CA 94043, or: + * + * http://www.sgi.com + * + * For further information regarding this notice, see: + * + * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ + */ + +#undef XFS_SUPER_MAGIC + +/* + * From mount(8) source by Andries Brouwer. Hacked for XFS by mkp. + * Recent sync's to mount source: + * - util-linux-2.10o ... 06 Sep 00 + * - util-linux-2.10r ... 06 Dec 00 + * - util-linux-2.11g ... 02 Jul 01 + */ + +/* Including became more and more painful. + Below a very abbreviated version of some declarations, + only designed to be able to check a magic number + in case no filesystem type was given. */ + +#define MINIX_SUPER_MAGIC 0x137F /* original minix fs */ +#define MINIX_SUPER_MAGIC2 0x138F /* minix fs, 30 char names */ +struct minix_super_block { + u_char s_dummy[16]; + u_char s_magic[2]; +}; +#define minixmagic(s) ((uint) s.s_magic[0] + (((uint) s.s_magic[1]) << 8)) + +#define ISODCL(from, to) (to - from + 1) +#define ISO_STANDARD_ID "CD001" +struct iso_volume_descriptor { + char type[ISODCL(1,1)]; /* 711 */ + char id[ISODCL(2,6)]; + char version[ISODCL(7,7)]; + char data[ISODCL(8,2048)]; +}; + +#define HS_STANDARD_ID "CDROM" +struct hs_volume_descriptor { + char foo[ISODCL ( 1, 8)]; /* 733 */ + char type[ISODCL ( 9, 9)]; /* 711 */ + char id[ISODCL ( 10, 14)]; + char version[ISODCL ( 15, 15)]; /* 711 */ + char data[ISODCL(16,2048)]; +}; + +#define EXT_SUPER_MAGIC 0x137D +struct ext_super_block { + u_char s_dummy[56]; + u_char s_magic[2]; +}; +#define extmagic(s) ((uint) s.s_magic[0] + (((uint) s.s_magic[1]) << 8)) + +#define EXT2_PRE_02B_MAGIC 0xEF51 +#define EXT2_SUPER_MAGIC 0xEF53 +#define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x0004 +struct ext2_super_block { + u_char s_dummy1[56]; + u_char s_magic[2]; + u_char s_dummy2[34]; + u_char s_feature_compat[4]; + u_char s_feature_incompat[4]; + u_char s_feature_ro_compat[4]; + u_char s_uuid[16]; + u_char s_volume_name[16]; + u_char s_dummy3[88]; + u_char s_journal_inum[4]; /* ext3 only */ +}; +#define ext2magic(s) ((uint) s.s_magic[0] + (((uint) s.s_magic[1]) << 8)) + +struct reiserfs_super_block +{ + u_char s_block_count[4]; + u_char s_free_blocks[4]; + u_char s_root_block[4]; + u_char s_journal_block[4]; + u_char s_journal_dev[4]; + u_char s_orig_journal_size[4]; + u_char s_journal_trans_max[4]; + u_char s_journal_block_count[4]; + u_char s_journal_max_batch[4]; + u_char s_journal_max_commit_age[4]; + u_char s_journal_max_trans_age[4]; + u_char s_blocksize[2]; + u_char s_oid_maxsize[2]; + u_char s_oid_cursize[2]; + u_char s_state[2]; + u_char s_magic[12]; +}; +#define REISERFS_SUPER_MAGIC_STRING "ReIsErFs" +#define REISER2FS_SUPER_MAGIC_STRING "ReIsEr2Fs" +#define REISERFS_DISK_OFFSET_IN_BYTES (64 * 1024) +/* the spot for the super in versions 3.5 - 3.5.10 (inclusive) */ +#define REISERFS_OLD_DISK_OFFSET_IN_BYTES (8 * 1024) + +#define _XIAFS_SUPER_MAGIC 0x012FD16D +struct xiafs_super_block { + u_char s_boot_segment[512]; /* 1st sector reserved for boot */ + u_char s_dummy[60]; + u_char s_magic[4]; +}; +#define xiafsmagic(s) ((uint) s.s_magic[0] + (((uint) s.s_magic[1]) << 8) + \ + (((uint) s.s_magic[2]) << 16) + \ + (((uint) s.s_magic[3]) << 24)) + +/* From jj@sunsite.ms.mff.cuni.cz Mon Mar 23 15:19:05 1998 */ +#define UFS_SUPER_MAGIC 0x00011954 +struct ufs_super_block { + u_char s_dummy[0x55c]; + u_char s_magic[4]; +}; +#define ufsmagic(s) ((uint) s.s_magic[0] + (((uint) s.s_magic[1]) << 8) + \ + (((uint) s.s_magic[2]) << 16) + \ + (((uint) s.s_magic[3]) << 24)) + +/* From Richard.Russon@ait.co.uk Wed Feb 24 08:05:27 1999 */ +#define NTFS_SUPER_MAGIC "NTFS" +struct ntfs_super_block { + u_char s_dummy[3]; + u_char s_magic[4]; +}; + +/* From inspection of a few FAT filesystems - aeb */ +/* Unfortunately I find almost the same thing on an extended partition; + it looks like a primary has some directory entries where the extended + has a partition table: IO.SYS, MSDOS.SYS, WINBOOT.SYS */ +struct fat_super_block { + u_char s_dummy[3]; + u_char s_os[8]; /* "MSDOS5.0" or "MSWIN4.0" or "MSWIN4.1" */ + /* mtools-3.9.4 writes "MTOOL394" */ + u_char s_dummy2[32]; + u_char s_label[11]; /* for DOS? */ + u_char s_fs[8]; /* "FAT12 " or "FAT16 " or all zero */ + /* OS/2 BM has "FAT " here. */ + u_char s_dummy3[9]; + u_char s_label2[11]; /* for Windows? */ + u_char s_fs2[8]; /* garbage or "FAT32 " */ +}; + +#define XFS_SUPER_MAGIC "XFSB" +struct xfs_super_block { + u_char s_magic[4]; + u_char s_dummy[28]; + u_char s_uuid[16]; + u_char s_dummy2[60]; + u_char s_fname[12]; +}; + +#define CRAMFS_SUPER_MAGIC 0x28cd3d45 +struct cramfs_super_block { + u_char s_magic[4]; + u_char s_dummy[12]; + u_char s_id[16]; +}; +#define cramfsmagic(s) ((uint) s.s_magic[0] + (((uint) s.s_magic[1]) << 8) + \ + (((uint) s.s_magic[2]) << 16) + \ + (((uint) s.s_magic[3]) << 24)) + +#define HFS_SUPER_MAGIC 0x4244 +struct hfs_super_block { + u_char s_magic[2]; + u_char s_dummy[18]; + u_char s_blksize[4]; +}; +#define hfsmagic(s) ((uint) s.s_magic[0] + (((uint) s.s_magic[1]) << 8)) +#define hfsblksize(s) ((uint) s.s_blksize[0] + \ + (((uint) s.s_blksize[1]) << 8) + \ + (((uint) s.s_blksize[2]) << 16) + \ + (((uint) s.s_blksize[3]) << 24)) + +#define HPFS_SUPER_MAGIC 0xf995e849 +struct hpfs_super_block { + u_char s_magic[4]; + u_char s_magic2[4]; +}; +#define hpfsmagic(s) ((uint) s.s_magic[0] + (((uint) s.s_magic[1]) << 8) + \ + (((uint) s.s_magic[2]) << 16) + \ + (((uint) s.s_magic[3]) << 24)) + +struct adfs_super_block { + u_char s_dummy[448]; + u_char s_blksize[1]; + u_char s_dummy2[62]; + u_char s_checksum[1]; +}; +#define adfsblksize(s) ((uint) s.s_blksize[0]) diff --git a/libdisk/lvm.c b/libdisk/lvm.c new file mode 100644 index 000000000..12b10d869 --- /dev/null +++ b/libdisk/lvm.c @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it would be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write the Free Software Foundation, Inc., 59 + * Temple Place - Suite 330, Boston MA 02111-1307, USA. + * + * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, + * Mountain View, CA 94043, or: + * + * http://www.sgi.com + * + * For further information regarding this notice, see: + * + * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ + */ + +#include +#include +#include +#include + +#if HAVE_LIBLVM + #include "lvm_user.h" + + char *cmd; /* Not used. liblvm is broken */ + int opt_d; /* Same thing */ +#endif + + +int +lvm_get_subvol_stripe( + char *dfile, + sv_type_t type, + int *sunit, + int *swidth, + struct stat64 *sb) +{ +#if HAVE_LIBLVM + if (sb->st_rdev >> 8 == LVM_BLK_MAJOR) { + lv_t *lv; + char *vgname; + + /* Find volume group */ + if (! (vgname = vg_name_of_lv(dfile))) { + fprintf(stderr, "Can't find volume group for %s\n", + dfile); + exit(1); + } + + /* Logical volume */ + if (! lvm_tab_lv_check_exist(dfile)) { + fprintf(stderr, "Logical volume %s doesn't exist!\n", + dfile); + exit(1); + } + + /* Get status */ + if (lv_status_byname(vgname, dfile, &lv) < 0 || lv == NULL) { + fprintf(stderr, "Could not get status info from %s\n", + dfile); + exit(1); + } + + /* Check that data is consistent */ + if (lv_check_consistency(lv) < 0) { + fprintf(stderr, "Logical volume %s is inconsistent\n", + dfile); + exit(1); + } + + /* Update sizes */ + *sunit = lv->lv_stripesize; + *swidth = lv->lv_stripes * lv->lv_stripesize; + + return 1; + } +#endif /* HAVE_LIBLVM */ + return 0; +} diff --git a/libdisk/md.c b/libdisk/md.c new file mode 100644 index 000000000..7e7a2981f --- /dev/null +++ b/libdisk/md.c @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it would be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write the Free Software Foundation, Inc., 59 + * Temple Place - Suite 330, Boston MA 02111-1307, USA. + * + * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, + * Mountain View, CA 94043, or: + * + * http://www.sgi.com + * + * For further information regarding this notice, see: + * + * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ + */ + +#include +#include +#include +#include +#include "md.h" + +int +md_get_subvol_stripe( + char *dfile, + sv_type_t type, + int *sunit, + int *swidth, + struct stat64 *sb) +{ + if (sb->st_rdev >> 8 == MD_MAJOR) { + struct md_array_info_s md; + int fd; + + /* Open device */ + fd = open(dfile, O_RDONLY); + if (fd == -1) + return 0; + + /* Is this thing on... */ + if (ioctl(fd, GET_ARRAY_INFO, &md)) { + fprintf(stderr, "Error getting MD array info from %s\n", + dfile); + exit(1); + } + + /* Check state */ + if (md.state) { + fprintf(stderr, "MD array %s not in clean state\n", + dfile); + exit(1); + } + + /* Deduct a disk from stripe width on RAID4/5 */ + if (md.level == 4 || md.level == 5) + md.nr_disks--; + + /* Update sizes */ + *sunit = md.chunk_size >> 9; + *swidth = *sunit * md.nr_disks; + + return 1; + } + return 0; +} diff --git a/libdisk/md.h b/libdisk/md.h new file mode 100644 index 000000000..5e8ad5fba --- /dev/null +++ b/libdisk/md.h @@ -0,0 +1,286 @@ +/* + md.h : Multiple Devices driver for Linux + Copyright (C) 1997-1999 Ingo Molnar + + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + You should have received a copy of the GNU General Public License + (for example /usr/src/linux/COPYING); if not, write to the Free + Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +/* don't include the kernel RAID header! */ +#define _MD_H + +typedef unsigned int md_u32; +typedef unsigned short md_u16; +typedef unsigned char md_u8; + +#include +#include + +/* + * Different major versions are not compatible. + * Different minor versions are only downward compatible. + * Different patchlevel versions are downward and upward compatible. + */ + +struct md_version { + int major; + int minor; + int patchlevel; +}; + +/* + * default readahead + */ +#define MD_READAHEAD (256 * 1024) + +/* These are the ioctls for md versions < 0.50 */ +#define REGISTER_MD_DEV _IO (MD_MAJOR, 1) +#define START_MD _IO (MD_MAJOR, 2) +#define STOP_MD _IO (MD_MAJOR, 3) + +/* status */ +#define RAID_VERSION _IOR (MD_MAJOR, 0x10, struct md_version) +#define GET_ARRAY_INFO _IOR (MD_MAJOR, 0x11, md_array_info_t) +#define GET_DISK_INFO _IOR (MD_MAJOR, 0x12, md_disk_info_t) +#define PRINT_RAID_DEBUG _IO (MD_MAJOR, 0x13) + +/* configuration */ +#define CLEAR_ARRAY _IO (MD_MAJOR, 0x20) +#define ADD_NEW_DISK _IOW (MD_MAJOR, 0x21, md_disk_info_t) +#define HOT_REMOVE_DISK _IO (MD_MAJOR, 0x22) +#define SET_ARRAY_INFO _IOW (MD_MAJOR, 0x23, md_array_info_t) +#define SET_DISK_INFO _IO (MD_MAJOR, 0x24) +#define WRITE_RAID_INFO _IO (MD_MAJOR, 0x25) +#define UNPROTECT_ARRAY _IO (MD_MAJOR, 0x26) +#define PROTECT_ARRAY _IO (MD_MAJOR, 0x27) +#define HOT_ADD_DISK _IO (MD_MAJOR, 0x28) +#define SET_DISK_FAULTY _IO (MD_MAJOR, 0x29) + +/* usage */ +#define RUN_ARRAY _IOW (MD_MAJOR, 0x30, struct md_param) +#define START_ARRAY _IO (MD_MAJOR, 0x31) +#define STOP_ARRAY _IO (MD_MAJOR, 0x32) +#define STOP_ARRAY_RO _IO (MD_MAJOR, 0x33) +#define RESTART_ARRAY_RW _IO (MD_MAJOR, 0x34) + + +/* for raid < 0.50 only */ +#define MD_PERSONALITY_SHIFT 16 + +#define MD_RESERVED 0UL +#define LINEAR 1UL +#define STRIPED 2UL +#define RAID0 STRIPED +#define RAID1 3UL +#define RAID5 4UL +#define TRANSLUCENT 5UL +#define LVM 6UL +#define MAX_PERSONALITY 7UL + +/* + * MD superblock. + * + * The MD superblock maintains some statistics on each MD configuration. + * Each real device in the MD set contains it near the end of the device. + * Some of the ideas are copied from the ext2fs implementation. + * + * We currently use 4096 bytes as follows: + * + * word offset function + * + * 0 - 31 Constant generic MD device information. + * 32 - 63 Generic state information. + * 64 - 127 Personality specific information. + * 128 - 511 12 32-words descriptors of the disks in the raid set. + * 512 - 911 Reserved. + * 912 - 1023 Disk specific descriptor. + */ + +/* + * If x is the real device size in bytes, we return an apparent size of: + * + * y = (x & ~(MD_RESERVED_BYTES - 1)) - MD_RESERVED_BYTES + * + * and place the 4kB superblock at offset y. + */ +#define MD_RESERVED_BYTES (64 * 1024) +#define MD_RESERVED_SECTORS (MD_RESERVED_BYTES / 512) +#define MD_RESERVED_BLOCKS (MD_RESERVED_BYTES / BLOCK_SIZE) + +#define MD_NEW_SIZE_SECTORS(x) ((x & ~(MD_RESERVED_SECTORS - 1)) - MD_RESERVED_SECTORS) +#define MD_NEW_SIZE_BLOCKS(x) ((x & ~(MD_RESERVED_BLOCKS - 1)) - MD_RESERVED_BLOCKS) + +#define MD_SB_BYTES 4096 +#define MD_SB_WORDS (MD_SB_BYTES / 4) +#define MD_SB_BLOCKS (MD_SB_BYTES / BLOCK_SIZE) +#define MD_SB_SECTORS (MD_SB_BYTES / 512) + +/* + * The following are counted in 32-bit words + */ +#define MD_SB_GENERIC_OFFSET 0 +#define MD_SB_PERSONALITY_OFFSET 64 +#define MD_SB_DISKS_OFFSET 128 +#define MD_SB_DESCRIPTOR_OFFSET 992 + +#define MD_SB_GENERIC_CONSTANT_WORDS 32 +#define MD_SB_GENERIC_STATE_WORDS 32 +#define MD_SB_GENERIC_WORDS (MD_SB_GENERIC_CONSTANT_WORDS + MD_SB_GENERIC_STATE_WORDS) +#define MD_SB_PERSONALITY_WORDS 64 +#define MD_SB_DESCRIPTOR_WORDS 32 +#define MD_SB_DISKS 27 +#define MD_SB_DISKS_WORDS (MD_SB_DISKS*MD_SB_DESCRIPTOR_WORDS) +#define MD_SB_RESERVED_WORDS (1024 - MD_SB_GENERIC_WORDS - MD_SB_PERSONALITY_WORDS - MD_SB_DISKS_WORDS - MD_SB_DESCRIPTOR_WORDS) +#define MD_SB_EQUAL_WORDS (MD_SB_GENERIC_WORDS + MD_SB_PERSONALITY_WORDS + MD_SB_DISKS_WORDS) + +/* + * Device "operational" state bits + */ +#define MD_DISK_FAULTY 0 /* disk is faulty / operational */ +#define MD_DISK_ACTIVE 1 /* disk is running or spare disk */ +#define MD_DISK_SYNC 2 /* disk is in sync with the raid set */ + +typedef struct md_device_descriptor_s { + md_u32 number; /* 0 Device number in the entire set */ + md_u32 major; /* 1 Device major number */ + md_u32 minor; /* 2 Device minor number */ + md_u32 raid_disk; /* 3 The role of the device in the raid set */ + md_u32 state; /* 4 Operational state */ + md_u32 reserved[MD_SB_DESCRIPTOR_WORDS - 5]; +} md_descriptor_t; + +#define MD_SB_MAGIC 0xa92b4efc + +/* + * Superblock state bits + */ +#define MD_SB_CLEAN 0 +#define MD_SB_ERRORS 1 + +typedef struct md_superblock_s { + /* + * Constant generic information + */ + md_u32 md_magic; /* 0 MD identifier */ + md_u32 major_version; /* 1 major version to which the set conforms */ + md_u32 minor_version; /* 2 minor version ... */ + md_u32 patch_version; /* 3 patchlevel version ... */ + md_u32 gvalid_words; /* 4 Number of used words in this section */ + md_u32 set_magic; /* 5 Raid set identifier */ + md_u32 ctime; /* 6 Creation time */ + md_u32 level; /* 7 Raid personality */ + md_u32 size; /* 8 Apparent size of each individual disk */ + md_u32 nr_disks; /* 9 total disks in the raid set */ + md_u32 raid_disks; /* 10 disks in a fully functional raid set */ + md_u32 md_minor; /* 11 preferred MD minor device number */ + md_u32 gstate_creserved[MD_SB_GENERIC_CONSTANT_WORDS - 12]; + + /* + * Generic state information + */ + md_u32 utime; /* 0 Superblock update time */ + md_u32 state; /* 1 State bits (clean, ...) */ + md_u32 active_disks; /* 2 Number of currently active disks */ + md_u32 working_disks; /* 3 Number of working disks */ + md_u32 failed_disks; /* 4 Number of failed disks */ + md_u32 spare_disks; /* 5 Number of spare disks */ + md_u32 gstate_sreserved[MD_SB_GENERIC_STATE_WORDS - 6]; + + /* + * Personality information + */ + md_u32 layout; /* 0 the array's physical layout */ + md_u32 chunk_size; /* 1 chunk size in bytes */ + md_u32 pstate_reserved[MD_SB_PERSONALITY_WORDS - 2]; + + /* + * Disks information + */ + md_descriptor_t disks[MD_SB_DISKS]; + + /* + * Reserved + */ + md_u32 reserved[MD_SB_RESERVED_WORDS]; + + /* + * Active descriptor + */ + md_descriptor_t descriptor; + +} md_superblock_t; + +/* + * options passed in raidstart: + */ + +#define MAX_CHUNK_SIZE (4096*1024) + +struct md_param +{ + int personality; /* 1,2,3,4 */ + int chunk_size; /* in bytes */ + int max_fault; /* unused for now */ +}; + +typedef struct md_array_info_s { + /* + * Generic constant information + */ + md_u32 major_version; + md_u32 minor_version; + md_u32 patch_version; + md_u32 ctime; + md_u32 level; + md_u32 size; + md_u32 nr_disks; + md_u32 raid_disks; + md_u32 md_minor; + md_u32 not_persistent; + + /* + * Generic state information + */ + md_u32 utime; /* 0 Superblock update time */ + md_u32 state; /* 1 State bits (clean, ...) */ + md_u32 active_disks; /* 2 Number of currently active disks */ + md_u32 working_disks; /* 3 Number of working disks */ + md_u32 failed_disks; /* 4 Number of failed disks */ + md_u32 spare_disks; /* 5 Number of spare disks */ + + /* + * Personality information + */ + md_u32 layout; /* 0 the array's physical layout */ + md_u32 chunk_size; /* 1 chunk size in bytes */ + +} md_array_info_t; + +typedef struct md_disk_info_s { + /* + * configuration/status of one particular disk + */ + md_u32 number; + md_u32 major; + md_u32 minor; + md_u32 raid_disk; + md_u32 state; + +} md_disk_info_t; + + +/* + * Supported RAID5 algorithms + */ +#define RAID5_ALGORITHM_LEFT_ASYMMETRIC 0 +#define RAID5_ALGORITHM_RIGHT_ASYMMETRIC 1 +#define RAID5_ALGORITHM_LEFT_SYMMETRIC 2 +#define RAID5_ALGORITHM_RIGHT_SYMMETRIC 3 + diff --git a/libdisk/mountinfo.c b/libdisk/mountinfo.c new file mode 100644 index 000000000..b8abf9672 --- /dev/null +++ b/libdisk/mountinfo.c @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it would be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write the Free Software Foundation, Inc., 59 + * Temple Place - Suite 330, Boston MA 02111-1307, USA. + * + * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, + * Mountain View, CA 94043, or: + * + * http://www.sgi.com + * + * For further information regarding this notice, see: + * + * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "mountinfo.h" + +int +mnt_check_init(mnt_check_state_t **check_state) +{ + return(0); +} + +int +mnt_find_mount_conflicts(mnt_check_state_t *check_state, char *devname) +{ +#define PROC_MOUNTED "/proc/mounts" + int sts = 0; + FILE *f; + struct mntent *mnt; + struct stat64 ns, ms; + char mounts[MAXPATHLEN]; + + if (stat64(devname, &ns) < 0) + return sts; + + strcpy(mounts, access(PROC_MOUNTED, R_OK)? PROC_MOUNTED : MOUNTED); + if ((f = setmntent(mounts, "r")) == NULL) + return sts; + while ((mnt = getmntent(f)) != NULL) { + if (stat64(mnt->mnt_fsname, &ms) < 0) + continue; + if (S_ISBLK(ms.st_mode) && ns.st_rdev == ms.st_rdev) + break; + if (!S_ISBLK(ms.st_mode) && !strcmp(devname, mnt->mnt_fsname)) + break; + } + endmntent(f); + if (mnt) + sts = 1; + return sts; +} + +int +mnt_find_mounted_partitions(mnt_check_state_t *check_state, char *devname) +{ + return 0; +} + +int +mnt_causes_test(mnt_check_state_t *check_state, int cause) +{ + switch(cause) { + case MNT_CAUSE_MOUNTED: + return(1); + + default: + fprintf(stderr, "mnt_causes_test: unknown cause %d\n", cause); + exit(99); + } +} + +void +mnt_causes_show(mnt_check_state_t *check_state, FILE *fp, char *prefix) +{ + fprintf(fp, "mnt_causes_show: not implemented. Called with %s\n", + prefix); + exit(98); +} + +void +mnt_plist_show(mnt_check_state_t *check_state, FILE *fp, char *prefix) +{ + /* + * Need to do some work for volume mgmt. + */ +} + +int +mnt_check_end(mnt_check_state_t *check_state) +{ + return(0); +} diff --git a/libdisk/pttype.c b/libdisk/pttype.c new file mode 100644 index 000000000..4d61b76a4 --- /dev/null +++ b/libdisk/pttype.c @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it would be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write the Free Software Foundation, Inc., 59 + * Temple Place - Suite 330, Boston MA 02111-1307, USA. + * + * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, + * Mountain View, CA 94043, or: + * + * http://www.sgi.com + * + * For further information regarding this notice, see: + * + * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ + */ + +#include +#include +#include +#include +#include +#include +#include "pttype.h" + +#define blksize 512 + +static __uint32_t +twos_complement_32bit_sum(__uint32_t *base, int size) +{ + int i; + __uint32_t sum = 0; + + size = size / sizeof(__uint32_t); + for (i = 0; i < size; i++) + sum = sum - ntohl(base[i]); + return sum; +} + +static int +sgi_parttable(char *base) +{ + __uint32_t csum; + struct volume_header *vh = (struct volume_header *)base; + + if (ntohl(vh->vh_magic) != VHMAGIC) + return 0; + csum = twos_complement_32bit_sum((__uint32_t *)vh, + sizeof(struct volume_header)); + return !csum; +} + +static int +dos_parttable(char *base) +{ + return (base[510] == 0x55 && base[511] == 0xaa); +} + +static int +aix_parttable(char *base) +{ + return (aixlabel(base)->magic == AIX_LABEL_MAGIC || + aixlabel(base)->magic == AIX_LABEL_MAGIC_SWAPPED); +} + +static int +sun_parttable(char *base) +{ + unsigned short *ush; + int csum = 0; + + if (sunlabel(base)->magic != SUN_LABEL_MAGIC && + sunlabel(base)->magic != SUN_LABEL_MAGIC_SWAPPED) + return csum; + ush = ((unsigned short *) (sunlabel(base) + 1)) - 1; + while (ush >= (unsigned short *)sunlabel(base)) + csum ^= *ush--; + return !csum; +} + + +char * +pttype(char *device) +{ + int fd; + char *type = NULL; + char buf[blksize]; + + if ((fd = open(device, O_RDONLY)) < 0) + ; + else if (read(fd, buf, blksize) != blksize) + ; + else { + if (sgi_parttable(buf)) + type = "SGI"; + else if (sun_parttable(buf)) + type = "Sun"; + else if (aix_parttable(buf)) + type = "AIX"; + else if (dos_parttable(buf)) + type = "DOS"; + } + + if (fd >= 0) + close(fd); + return type; +} diff --git a/libdisk/pttype.h b/libdisk/pttype.h new file mode 100644 index 000000000..3d0b71fff --- /dev/null +++ b/libdisk/pttype.h @@ -0,0 +1,41 @@ + +typedef struct { + unsigned char info[128]; /* Informative text string */ + unsigned char spare0[14]; + struct sun_info { + unsigned char spare1; + unsigned char id; + unsigned char spare2; + unsigned char flags; + } infos[8]; + unsigned char spare1[246]; /* Boot information etc. */ + unsigned short rspeed; /* Disk rotational speed */ + unsigned short pcylcount; /* Physical cylinder count */ + unsigned short sparecyl; /* extra sects per cylinder */ + unsigned char spare2[4]; /* More magic... */ + unsigned short ilfact; /* Interleave factor */ + unsigned short ncyl; /* Data cylinder count */ + unsigned short nacyl; /* Alt. cylinder count */ + unsigned short ntrks; /* Tracks per cylinder */ + unsigned short nsect; /* Sectors per track */ + unsigned char spare3[4]; /* Even more magic... */ + struct sun_partition { + __uint32_t start_cylinder; + __uint32_t num_sectors; + } partitions[8]; + unsigned short magic; /* Magic number */ + unsigned short csum; /* Label xor'd checksum */ +} sun_partition; + +#define SUN_LABEL_MAGIC 0xDABE +#define SUN_LABEL_MAGIC_SWAPPED 0xBEDA +#define sunlabel(x) ((sun_partition *)x) + +typedef struct { + unsigned int magic; /* expect AIX_LABEL_MAGIC */ + /* ... */ +} aix_partition; + +#define AIX_LABEL_MAGIC 0xc9c2d4c1 +#define AIX_LABEL_MAGIC_SWAPPED 0xc1d4c2c9 +#define aixlabel(x) ((aix_partition *)x) diff --git a/libdisk/xvm.c b/libdisk/xvm.c new file mode 100644 index 000000000..f1edc3395 --- /dev/null +++ b/libdisk/xvm.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it would be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write the Free Software Foundation, Inc., 59 + * Temple Place - Suite 330, Boston MA 02111-1307, USA. + * + * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, + * Mountain View, CA 94043, or: + * + * http://www.sgi.com + * + * For further information regarding this notice, see: + * + * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ + */ + +#include +#include +#include +#include +#include +#include +#include "xvm.h" + +static int +mnt_is_xvm_subvol(dev_t dev) +{ + /* TODO - DeanJ? - for now, always return false */ + return 0; +} + +/* + * If the logical device is a xvm striped volume, then it returns the + * stripe unit and stripe width information. + * Input parameters: the logical volume + * the subvolume type - (SVTYPE_RT or + * SVTYPE_DATA) + * Output parameters: the stripe unit and width in 512 byte blocks + * true/false - was this device an XVM volume? + */ +int +xvm_get_subvol_stripe( + char *dev, + sv_type_t type, + int *sunit, + int *swidth, + struct stat64 *sb) +{ + /* TODO - DeanJ? - for now, always return false */ + return 1; +} diff --git a/libdisk/xvm.h b/libdisk/xvm.h new file mode 100644 index 000000000..e0f0281f2 --- /dev/null +++ b/libdisk/xvm.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it would be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write the Free Software Foundation, Inc., 59 + * Temple Place - Suite 330, Boston MA 02111-1307, USA. + * + * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, + * Mountain View, CA 94043, or: + * + * http://www.sgi.com + * + * For further information regarding this notice, see: + * + * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ + */ + +/* + * Header for XVM support in libdisk + */ + + /* TODO - DeanJ? - empty for now */ + diff --git a/libhandle/Makefile b/libhandle/Makefile index 1566af629..3d9fb667b 100644 --- a/libhandle/Makefile +++ b/libhandle/Makefile @@ -33,29 +33,19 @@ TOPDIR = .. include $(TOPDIR)/include/builddefs -LIB = libhandle -STATICLIBTARGET = $(LIB).a -#MAJOR = 1 -#MINOR = 0 -#LIBTARGET = $(LIB).so.$(MAJOR) +LTLIBRARY = libhandle.la +LT_CURRENT = 0 +LT_REVISION = 0 +LT_AGE = 0 CFILES = handle.c jdm.c -LCFLAGS = -D_REENTRANT -default: $(STATICLIBTARGET) +default: $(LTLIBRARY) include $(BUILDRULES) install: default - -#MODE = $(shell test -f /etc/debian_version && echo 644 || echo 755) -#install: default -# $(INSTALL) -m 755 -d $(PKG_SLIB_DIR) -# $(INSTALL) -m $(MODE) $(LIBTARGET) $(PKG_SLIB_DIR)/$(LIBTARGET).$(MINOR) -# $(INSTALL) -S $(LIBTARGET).$(MINOR) $(PKG_SLIB_DIR)/$(LIBTARGET) -#install-dev: default -# $(INSTALL) -S $(PKG_SLIB_DIR)/$(LIBTARGET) $(PKG_LIB_DIR)/$(LIB).so + $(INSTALL_LTLIB) install-dev: default - $(INSTALL) -m 755 -d $(PKG_LIB_DIR) - $(INSTALL) -m 644 $(STATICLIBTARGET) $(PKG_LIB_DIR) + $(INSTALL_LTLIB_DEV) diff --git a/libxfs/Makefile b/libxfs/Makefile index e6a0eb4fe..e1cbf3bec 100644 --- a/libxfs/Makefile +++ b/libxfs/Makefile @@ -33,8 +33,10 @@ TOPDIR = .. include $(TOPDIR)/include/builddefs -LIB = libxfs -STATICLIBTARGET = $(LIB).a +LTLIBRARY = libxfs.la +LT_CURRENT = 0 +LT_REVISION = 0 +LT_AGE = 0 HFILES = xfs.h CFILES = init.c logitem.c rdwr.c trans.c util.c \ @@ -57,26 +59,11 @@ LCFLAGS += -I. # don't try linking xfs_repair with a debug libxfs. DEBUG = -DNDEBUG -default: $(STATICLIBTARGET) +default: $(LTLIBRARY) include $(BUILDRULES) install: default install-dev: default - $(INSTALL) -m 755 -d $(PKG_LIB_DIR) - $(INSTALL) -m 644 $(STATICLIBTARGET) $(PKG_LIB_DIR) - -#MODE = $(shell test -f /etc/debian_version && echo 644 || echo 755) -#MAJOR = 1 -#MINOR = 0 -#LIBTARGET = $(LIB).so.$(MAJOR) -#LDIRT = $(LIB).so -#default: -# [ -L $(LIB).so ] || $(LN_S) $(LIBTARGET) $(LIB).so -#install: default -# $(INSTALL) -m 755 -d $(PKG_SLIB_DIR) -# $(INSTALL) -m $(MODE) $(LIBTARGET) $(PKG_SLIB_DIR)/$(LIBTARGET).$(MINOR) -# #$(INSTALL) -S $(LIBTARGET).$(MINOR) $(PKG_SLIB_DIR)/$(LIBTARGET) -#install-dev: default -# $(INSTALL) -S $(PKG_SLIB_DIR)/$(LIBTARGET) $(PKG_LIB_DIR)/$(LIB).so + $(INSTALL_LTLIB_STATIC) diff --git a/logprint/Makefile b/logprint/Makefile index ff7bc5e92..86d06941a 100644 --- a/logprint/Makefile +++ b/logprint/Makefile @@ -33,19 +33,19 @@ TOPDIR = .. include $(TOPDIR)/include/builddefs -CMDTARGET = xfs_logprint +LTCOMMAND = xfs_logprint CFILES = log_print_trans.c log_print_all.c log_misc.c logprint.c \ xfs_log_recover.c HFILES = logprint.h LLDLIBS = $(LIBXFS) $(LIBUUID) -LLDFLAGS = -L$(TOPDIR)/libxfs +LLDFLAGS = -static -default: $(CMDTARGET) +default: $(LTCOMMAND) include $(BUILDRULES) install: default $(INSTALL) -m 755 -d $(PKG_BIN_DIR) - $(INSTALL) -m 755 $(CMDTARGET) $(PKG_BIN_DIR) + $(INSTALL) -m 755 $(LTCOMMAND) $(PKG_BIN_DIR) install-dev: diff --git a/mkfile/Makefile b/mkfile/Makefile index c28d71b69..a1d9dd329 100644 --- a/mkfile/Makefile +++ b/mkfile/Makefile @@ -33,14 +33,15 @@ TOPDIR = .. include $(TOPDIR)/include/builddefs -CMDTARGET = xfs_mkfile +LTCOMMAND = xfs_mkfile CFILES = xfs_mkfile.c +LLDFLAGS += -static -default: $(CMDTARGET) +default: $(LTCOMMAND) include $(BUILDRULES) install: default $(INSTALL) -m 755 -d $(PKG_BIN_DIR) - $(INSTALL) -m 755 $(CMDTARGET) $(PKG_BIN_DIR) + $(INSTALL) -m 755 $(LTCOMMAND) $(PKG_BIN_DIR) install-dev: diff --git a/mkfs/Makefile b/mkfs/Makefile index 690a1be61..5f7761a70 100644 --- a/mkfs/Makefile +++ b/mkfs/Makefile @@ -33,35 +33,34 @@ TOPDIR = .. include $(TOPDIR)/include/builddefs -CMDTARGET = mkfs.xfs +LTCOMMAND = mkfs.xfs MAXTRRES = maxtrres FSTYP = fstyp -CFILES = xfs_mkfs.c mountinfo.c proto.c -HFILES = xfs_mkfs.h mountinfo.h proto.h volume.h -LCFLAGS = $(USELVM) -LLDLIBS = $(LIBXFS) $(LIBUUID) $(LIBLVM) -LLDFLAGS = -L$(TOPDIR)/libxfs +HFILES = xfs_mkfs.h proto.h +CFILES = $(HFILES:.h=.c) +LLDLIBS = $(LIBXFS) $(LIBDISK) $(LIBUUID) $(LIBLVM) +LTDEPENDENCIES = $(LIBXFS) $(LIBDISK) +LLDFLAGS = -static MAXTRLIBS = $(LIBXFS) $(LIBUUID) LSRCFILES = $(MAXTRRES).c $(FSTYP).c LDIRT = $(MAXTRRES) $(MAXTRRES).h $(FSTYP) -default: $(MAXTRRES).h $(CMDTARGET) +default: $(MAXTRRES).h $(FSTYP) $(LTCOMMAND) include $(BUILDRULES) $(MAXTRRES): - $(CCF) $@.c -o $@ $(LDFLAGS) $(MAXTRLIBS) + $(LTLINK) $@.c -o $@ $(CFLAGS) $(LDFLAGS) $(MAXTRLIBS) $(MAXTRRES).h: $(MAXTRRES) - LD_LIBRARY_PATH=../libxfs; export LD_LIBRARY_PATH; \ - ./$(MAXTRRES) > $@ || ( rm -f $@ && exit 1 ) + $(LTEXEC) ./$(MAXTRRES) > $@ || ( rm -f $@ && exit 1 ) -$(FSTYP): $(CMDTARGET) - $(CCF) $@.c -o $@ $(LDFLAGS) mountinfo.o +$(FSTYP): + $(LTLINK) $@.c -o $@ $(CFLAGS) $(LDFLAGS) $(LIBDISK) install: default $(INSTALL) -m 755 -d $(PKG_SBIN_DIR) - $(INSTALL) -m 755 $(CMDTARGET) $(PKG_SBIN_DIR) + $(INSTALL) -m 755 $(LTCOMMAND) $(PKG_SBIN_DIR) install-dev: diff --git a/mkfs/fstyp.c b/mkfs/fstyp.c index 5fa010b32..3a46b93eb 100644 --- a/mkfs/fstyp.c +++ b/mkfs/fstyp.c @@ -34,8 +34,7 @@ #include #include #include - -#include "mountinfo.h" +#include /* * fstyp allows the user to determine the filesystem identifier of @@ -68,7 +67,7 @@ main(int argc, char *argv[]) exit(1); } - if ((type = mnt_known_fs_type(argv[1])) == NULL) { + if ((type = fstype(argv[1])) == NULL) { printf("Unknown\n"); exit(1); } diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index c20178858..991a3581b 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -30,22 +30,15 @@ * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ */ +#include +#include +#include +#include #include #include "xfs_mkfs.h" -#include "proto.h" -#include "volume.h" #include "maxtrres.h" -#include "mountinfo.h" - -#if HAVE_LIBLVM - #include "lvm_user.h" - - char *cmd; /* Not used. liblvm is broken */ - int opt_d; /* Same thing */ -#endif - -#include "md-int.h" +#include "proto.h" /* * Prototypes for internal functions. @@ -264,100 +257,6 @@ static const int max_trres_v2[DFL_B][DFL_I][DFL_D] = { ((uint)(MKFS_BLOCKRES_INODE + XFS_DA_NODE_MAXDEPTH + \ (XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) - 1) + (rb))) -static void -get_subvol_stripe_wrapper(char *dfile, int type, int *sunit, int *swidth) -{ - struct stat64 sb; - struct md_array_info_s md; -#if HAVE_LIBLVM - lv_t *lv; - char *vgname; -#endif - - if (!dfile) - return; - - if (stat64 (dfile, &sb)) { - fprintf (stderr, "Could not stat %s\n", dfile); - usage(); - } - - /* MD volume */ - if (sb.st_rdev >> 8 == MD_MAJOR) { - int fd; - - /* Open device */ - fd = open (dfile, O_RDONLY); - if (fd == -1) - return; - - /* Is this thing on... */ - if (ioctl (fd, GET_ARRAY_INFO, &md)) { - fprintf (stderr, "Error getting array info from %s\n", - dfile); - usage(); - } - - /* Check state */ - if (md.state) { - fprintf (stderr, "MD array %s not in clean state\n", - dfile); - usage(); - } - - /* Deduct a disk from stripe width on RAID4/5 */ - if (md.level == 4 || md.level == 5) - md.nr_disks--; - - /* Update sizes */ - *sunit = md.chunk_size >> 9; - *swidth = *sunit * md.nr_disks; - - return; - } - -#if HAVE_LIBLVM - /* LVM volume */ - if (sb.st_rdev >> 8 == LVM_BLK_MAJOR) { - - /* Find volume group */ - if (! (vgname = vg_name_of_lv (dfile))) { - fprintf (stderr, "Can't find volume group for %s\n", - dfile); - usage(); - } - - /* Logical volume */ - if (! lvm_tab_lv_check_exist (dfile)) { - fprintf (stderr, "Logical volume %s doesn't exist!\n", - dfile); - usage(); - } - - /* Get status */ - if (lv_status_byname (vgname, dfile, &lv) < 0 || lv == NULL) { - fprintf (stderr, "Could not get status info from %s\n", - dfile); - usage(); - } - - /* Check that data is consistent */ - if (lv_check_consistency (lv) < 0) { - fprintf (stderr, "Logical volume %s is inconsistent\n", - dfile); - usage(); - } - - /* Update sizes */ - *sunit = lv->lv_stripesize; - *swidth = lv->lv_stripes * lv->lv_stripesize; - - return; - } -#endif /* HAVE_LIBLVM */ -} - - static void calc_stripe_factors(int dsu, int dsw, int *dsunit, int *dswidth) { @@ -419,6 +318,28 @@ get_default_blocksize(void) return (1 << XFS_DFL_BLOCKSIZE_LOG); } +static int +check_overwrite(char *device) +{ + char *type; + + if (device && *device) { + if ((type = fstype(device)) != NULL) { + fprintf(stderr, + "%s: %s appears to contain an existing filesystem (%s).\n", + progname, device, type); + return 1; + } + if ((type = pttype(device)) != NULL) { + fprintf(stderr, + "%s: %s appears to contain a partition table (%s).\n", + progname, device, type); + return 1; + } + } + return 0; +} + int main(int argc, char **argv) @@ -451,7 +372,7 @@ main(int argc, char **argv) int dsunit; int dswidth; int extent_flagging; - int force_fs_overwrite; + int force_overwrite; int i; int iaflag; int ilflag; @@ -530,7 +451,7 @@ main(int argc, char **argv) dsu = dsw = dsunit = dswidth = nodsflag = lalign = 0; do_overlap_checks = 1; extent_flagging = 0; - force_fs_overwrite = 0; + force_overwrite = 0; worst_freelist = 0; while ((c = getopt(argc, argv, "b:d:i:l:L:n:p:qr:CfV")) != EOF) { @@ -539,7 +460,7 @@ main(int argc, char **argv) do_overlap_checks = 0; break; case 'f': - force_fs_overwrite = 1; + force_overwrite = 1; break; case 'b': p = optarg; @@ -1198,48 +1119,12 @@ main(int argc, char **argv) usage(); } - /* - * Check whether this partition contains a known filesystem. - */ - - if (force_fs_overwrite == 0) { - char *fstyp; - int fsfound = 0; - - fstyp = (char *) mnt_known_fs_type (dfile); - - if (fstyp != NULL) { - fprintf(stderr, "%s: " - "%s appears to contain an existing filesystem (%s).\n", - progname, dfile, fstyp); - fsfound = 1; - } - - if (logfile && *logfile) { - fstyp = (char *) mnt_known_fs_type (logfile); - - if (fstyp != NULL) { - fprintf(stderr, "%s: " - "%s appears to contain an existing filesystem (%s).\n", - progname, logfile, fstyp); - fsfound = 1; - } - } - - if (xi.rtname && *xi.rtname) { - fstyp = (char *) mnt_known_fs_type (xi.rtname); - - if (fstyp != NULL) { - fprintf(stderr, "%s: " - "%s appears to contain an existing filesystem (%s).\n", - progname, xi.rtname, fstyp); - fsfound = 1; - } - } - - if (fsfound) { + if (!force_overwrite) { + if (check_overwrite(dfile) || + check_overwrite(logfile) || + check_overwrite(xi.rtname)) { fprintf(stderr, "%s: " - "Use the -f option to force overwrite\n", + "Use the -f option to force overwrite.\n", progname); exit(1); } diff --git a/repair/Makefile b/repair/Makefile index 876f796c2..a19c419e8 100644 --- a/repair/Makefile +++ b/repair/Makefile @@ -33,7 +33,7 @@ TOPDIR = .. include $(TOPDIR)/include/builddefs -CMDTARGET = xfs_repair +LTCOMMAND = xfs_repair HFILES = agheader.h attr_repair.h avl.h avl64.h bmap.h dinode.h dir.h \ dir2.h dir_stack.h err_protos.h globals.h incore.h protos.h rt.h \ @@ -46,9 +46,10 @@ CFILES = agheader.c attr_repair.c avl.c avl64.c bmap.c dino_chunks.c \ scan.c versions.c xfs_repair.c LLDLIBS = $(LIBXFS) $(LIBUUID) -LLDFLAGS = -L$(TOPDIR)/libxfs +LTDEPENDENCIES = $(LIBXFS) +LLDFLAGS = -static -default: $(CMDTARGET) +default: $(LTCOMMAND) include $(BUILDRULES) @@ -69,5 +70,5 @@ CFLAGS += -DAVL_USER_MODE -DAVL_FUTURE_ENHANCEMENTS install: default $(INSTALL) -m 755 -d $(PKG_SBIN_DIR) - $(INSTALL) -m 755 $(CMDTARGET) $(PKG_SBIN_DIR) + $(INSTALL) -m 755 $(LTCOMMAND) $(PKG_SBIN_DIR) install-dev: diff --git a/rtcp/Makefile b/rtcp/Makefile index b7d08bfb4..b4544ad94 100644 --- a/rtcp/Makefile +++ b/rtcp/Makefile @@ -33,14 +33,15 @@ TOPDIR = .. include $(TOPDIR)/include/builddefs -CMDTARGET = xfs_rtcp +LTCOMMAND = xfs_rtcp CFILES = xfs_rtcp.c +LLDFLAGS = -static -default: $(CMDTARGET) +default: $(LTCOMMAND) include $(BUILDRULES) install: default $(INSTALL) -m 755 -d $(PKG_BIN_DIR) - $(INSTALL) -m 755 $(CMDTARGET) $(PKG_BIN_DIR) + $(INSTALL) -m 755 $(LTCOMMAND) $(PKG_BIN_DIR) install-dev: