diskdev_cmds-332.25/0000755000000000000000000000000010640030222013053 5ustar rootwheeldiskdev_cmds-332.25/clri.tproj/0000755000000000000000000000000010640030222015141 5ustar rootwheeldiskdev_cmds-332.25/clri.tproj/clri.80000644000000000000000000000553306712726561016220 0ustar rootwheel.\" Copyright (c) 1980, 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: .\" This product includes software developed by the University of .\" California, Berkeley and its contributors. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)clri.8 8.2 (Berkeley) 4/19/94 .\" .Dd April 19, 1994 .Dt CLRI 8 .Os BSD 4 .Sh NAME .Nm clri .Nd clear an inode .Sh SYNOPSIS .Nm clri .Ar special_device inode_number ... .Sh DESCRIPTION .Bf -symbolic .Nm Clri is obsoleted for normal file system repair work by .Xr fsck 8 . .Ef .Pp .Nm Clri zeros out the inodes with the specified inode number(s) on the filesystem residing on the given .Ar special_device . The .Xr fsck 8 utility is usually run after .Nm clri to reclaim the zero'ed inode(s) and the blocks previously claimed by those inode(s). Both read and write permission are required on the specified .Ar special_device . .Pp The primary purpose of this routine is to remove a file which for some reason is not being properly handled by .Xr fsck 8 . Once removed, it is anticipated that .Xr fsck 8 will be able to clean up the resulting mess. .Sh "SEE ALSO" .Xr fsck 8 , .Xr fsdb 8 , .Xr icheck 8 , .Xr ncheck 8 .Sh BUGS If the file is open, the work of .Nm clri will be lost when the inode is written back to disk from the inode cache. diskdev_cmds-332.25/clri.tproj/clri.c0000644000000000000000000001376706712726561016303 0ustar rootwheel/* * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights * Reserved. This file contains Original Code and/or Modifications of * Original Code as defined in and that are subject to the Apple Public * Source License Version 1.0 (the 'License'). You may not use this file * except in compliance with the License. Please obtain a copy of the * License at http://www.apple.com/publicsource and read it before using * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License." * * @APPLE_LICENSE_HEADER_END@ */ /* * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Rich $alz of BBN Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #include #include #include #include #include #include #include #include #include #include #if REV_ENDIAN_FS #import "ufs_byte_order.h" #include #endif /* REV_ENDIAN_FS */ #if REV_ENDIAN_FS int rev_endian=0; #endif /* REV_ENDIAN_FS */ int main(argc, argv) int argc; char *argv[]; { register struct fs *sbp; register struct dinode *ip; register int fd; struct dinode ibuf[MAXBSIZE / sizeof (struct dinode)]; long generation, bsize; off_t offset; int inonum; #ifdef __APPLE__ long dev_bsize; #endif /* __APPLE__ */ char *fs, sblock[SBSIZE]; if (argc < 3) { (void)fprintf(stderr, "usage: clri filesystem inode ...\n"); exit(1); } fs = *++argv; /* get the superblock. */ if ((fd = open(fs, O_RDWR, 0)) < 0) err(1, "%s", fs); #ifdef __APPLE__ if (lseek(fd, (off_t)SBOFF, SEEK_SET) < 0) #else if (lseek(fd, (off_t)(SBLOCK * DEV_BSIZE), SEEK_SET) < 0) #endif /* __APPLE__ */ err(1, "%s", fs); if (read(fd, sblock, sizeof(sblock)) != sizeof(sblock)) errx(1, "%s: can't read superblock", fs); sbp = (struct fs *)sblock; if (sbp->fs_magic != FS_MAGIC) #if REV_ENDIAN_FS { byte_swap_sbin(sbp); if (sbp->fs_magic != FS_MAGIC) { #endif /* REV_ENDIAN_FS */ errx(1, "%s: superblock magic number 0x%x, not 0x%x", fs, sbp->fs_magic, FS_MAGIC); #if REV_ENDIAN_FS } else { (void)printf("Reverse Byte order Filesystem Detected\n"); rev_endian=1; } } else rev_endian = 0; #endif /* REV_ENDIAN_FS */ bsize = sbp->fs_bsize; #ifdef __APPLE__ dev_bsize = sbp->fs_fsize / fsbtodb(sbp, 1); #endif /* __APPLE__ */ /* remaining arguments are inode numbers. */ while (*++argv) { /* get the inode number. */ if ((inonum = atoi(*argv)) <= 0) errx(1, "%s is not a valid inode number", *argv); (void)printf("clearing %d\n", inonum); /* read in the appropriate block. */ offset = ino_to_fsba(sbp, inonum); /* inode to fs blk */ offset = fsbtodb(sbp, offset); /* fs blk disk blk */ #ifdef __APPLE__ offset *= dev_bsize; /* disk blk to bytes */ #else offset *= DEV_BSIZE; /* disk blk to bytes */ #endif /* __APPLE__ */ /* seek and read the block */ if (lseek(fd, offset, SEEK_SET) < 0) err(1, "%s", fs); if (read(fd, ibuf, bsize) != bsize) err(1, "%s", fs); /* get the inode within the block. */ ip = &ibuf[ino_to_fsbo(sbp, inonum)]; /* clear the inode, and bump the generation count. */ #if REV_ENDIAN_FS if (rev_endian) ip->di_gen = NXSwapLong(ip->di_gen); #endif /* REV_ENDIAN_FS */ generation = ip->di_gen + 1; memset(ip, 0, sizeof(*ip)); #if REV_ENDIAN_FS if (rev_endian) generation = NXSwapLong(generation); #endif /* REV_ENDIAN_FS */ ip->di_gen = generation; /* backup and write the block */ if (lseek(fd, (off_t)-bsize, SEEK_CUR) < 0) err(1, "%s", fs); if (write(fd, ibuf, bsize) != bsize) err(1, "%s", fs); (void)fsync(fd); } (void)close(fd); exit(0); } diskdev_cmds-332.25/clri.tproj/Makefile0000644000000000000000000000212110216156236016612 0ustar rootwheel# # Generated by the NeXT Project Builder. # # NOTE: Do NOT change this file -- Project Builder maintains it. # # Put all of your customizations in files called Makefile.preamble # and Makefile.postamble (both optional), and Makefile will include them. # NAME = clri PROJECTVERSION = 2.8 PROJECT_TYPE = Tool HFILES = ufs_byte_order.h CFILES = clri.c ufs_byte_order.c OTHERSRCS = Makefile.preamble Makefile.postamble Makefile Makefile.dist clri.8 MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles CODE_GEN_STYLE = DYNAMIC MAKEFILE = tool.make NEXTSTEP_INSTALLDIR = /sbin WINDOWS_INSTALLDIR = /sbin PDO_UNIX_INSTALLDIR = /sbin LIBS = DEBUG_LIBS = $(LIBS) PROF_LIBS = $(LIBS) NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc NEXTSTEP_JAVA_COMPILER = /usr/bin/javac WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac include $(MAKEFILEDIR)/platform.make -include Makefile.preamble include $(MAKEFILEDIR)/$(MAKEFILE) -include Makefile.postamble -include Makefile.dependencies diskdev_cmds-332.25/clri.tproj/Makefile.dist0000644000000000000000000000012606712726561017571 0ustar rootwheel# @(#)Makefile 8.1 (Berkeley) 6/5/93 PROG= clri MAN8= clri.0 .include diskdev_cmds-332.25/clri.tproj/Makefile.postamble0000644000000000000000000000023210216156236020600 0ustar rootwheelafter_install: install -m 755 -o root -g wheel -d $(DSTROOT)/usr/share/man/man8 install -m 644 -o root -g wheel -c clri.8 $(DSTROOT)/usr/share/man/man8 diskdev_cmds-332.25/clri.tproj/Makefile.preamble0000644000000000000000000000014506712726561020416 0ustar rootwheelOTHER_GENERATED_OFILES = $(VERS_OFILE) -include ../Makefile.include OTHER_CFLAGS = -DREV_ENDIAN_FS=1 diskdev_cmds-332.25/clri.tproj/PB.project0000644000000000000000000000175610216156236017060 0ustar rootwheel{ APPCLASS = NSApplication; FILESTABLE = { CLASSES = (); FRAMEWORKS = (); H_FILES = (ufs_byte_order.h); M_FILES = (); OTHER_LIBS = (); OTHER_LINKED = (clri.c, ufs_byte_order.c); OTHER_SOURCES = (Makefile.preamble, Makefile.postamble, Makefile, Makefile.dist, clri.8); SUBPROJECTS = (); }; LANGUAGE = English; LOCALIZABLE_FILES = {}; NEXTSTEP_INSTALLDIR = /sbin; NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; NEXTSTEP_MAINNIB = clri; NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; PDO_UNIX_INSTALLDIR = /sbin; PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; PDO_UNIX_MAINNIB = clri; PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; PROJECTNAME = clri; PROJECTTYPE = Tool; PROJECTVERSION = 2.8; WINDOWS_INSTALLDIR = /sbin; WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; WINDOWS_MAINNIB = clri; WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; } diskdev_cmds-332.25/clri.tproj/ufs_byte_order.c0000644000000000000000000002374210267354542020353 0ustar rootwheel/* * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights * Reserved. This file contains Original Code and/or Modifications of * Original Code as defined in and that are subject to the Apple Public * Source License Version 1.0 (the 'License'). You may not use this file * except in compliance with the License. Please obtain a copy of the * License at http://www.apple.com/publicsource and read it before using * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License." * * @APPLE_LICENSE_HEADER_END@ */ /* Copyright 1998 Apple Computer, Inc. * * UFS byte swapping routines to make a big endian file system useful on a * little endian machine. * * HISTORY * * 16 Feb 1998 A. Ramesh at Apple * Rhapsody version created. */ #include #include #include #include #include #include "ufs_byte_order.h" #include #if 0 #define byte_swap_longlong(thing) ((thing) = NXSwapBigLongLongToHost(thing)) #define byte_swap_int(thing) ((thing) = NXSwapBigLongToHost(thing)) #define byte_swap_short(thing) ((thing) = NXSwapBigShortToHost(thing)) #else #define byte_swap_longlong(thing) ((thing) = NXSwapLongLong(thing)) #define byte_swap_int(thing) ((thing) = NXSwapLong(thing)) #define byte_swap_short(thing) ((thing) = NXSwapShort(thing)) #endif void byte_swap_longlongs(unsigned long long *array, int count) { register unsigned long long i; for (i = 0; i < count; i++) byte_swap_longlong(array[i]); } void byte_swap_ints(int *array, int count) { register int i; for (i = 0; i < count; i++) byte_swap_int(array[i]); } void byte_swap_shorts(short *array, int count) { register int i; for (i = 0; i < count; i++) byte_swap_short(array[i]); } void byte_swap_sbin(struct fs *sb) { u_int16_t *usptr; unsigned long size; byte_swap_ints(((int32_t *)&sb->fs_firstfield), 52); byte_swap_int(sb->fs_cgrotor); byte_swap_int(sb->fs_cpc); byte_swap_shorts((int16_t *)sb->fs_opostbl, sizeof(sb->fs_opostbl) / sizeof(int16_t)); byte_swap_int(sb->fs_avgfilesize); byte_swap_int(sb->fs_avgfpdir); byte_swap_ints((int32_t *)sb->fs_sparecon, sizeof(sb->fs_sparecon) / sizeof(int32_t)); byte_swap_ints((int32_t *)&sb->fs_contigsumsize, 3); byte_swap_longlongs((u_int64_t *)&sb->fs_maxfilesize,3); byte_swap_ints((int32_t *)&sb->fs_state, 6); /* Got these magic numbers from mkfs.c in newfs */ if (sb->fs_nrpos != 8 || sb->fs_cpc > 16) { usptr = (u_int16_t *)((u_int8_t *)(sb) + (sb)->fs_postbloff); size = sb->fs_cpc * sb->fs_nrpos; byte_swap_shorts(usptr,size); /* fs_postbloff */ } } void byte_swap_sbout(struct fs *sb) { u_int16_t *usptr; unsigned long size; /* Got these magic numbers from mkfs.c in newfs */ if (sb->fs_nrpos != 8 || sb->fs_cpc > 16) { usptr = (u_int16_t *)((u_int8_t *)(sb) + (sb)->fs_postbloff); size = sb->fs_cpc * sb->fs_nrpos; byte_swap_shorts(usptr,size); /* fs_postbloff */ } byte_swap_ints(((int32_t *)&sb->fs_firstfield), 52); byte_swap_int(sb->fs_cgrotor); byte_swap_int(sb->fs_cpc); byte_swap_shorts((int16_t *)sb->fs_opostbl, sizeof(sb->fs_opostbl) / sizeof(int16_t)); byte_swap_int(sb->fs_avgfilesize); byte_swap_int(sb->fs_avgfpdir); byte_swap_ints((int32_t *)sb->fs_sparecon, sizeof(sb->fs_sparecon) / sizeof(int32_t)); byte_swap_ints((int32_t *)&sb->fs_contigsumsize, 3); byte_swap_longlongs((u_int64_t *)&sb->fs_maxfilesize,3); byte_swap_ints((int32_t *)&sb->fs_state, 6); } void byte_swap_csum(struct csum *cs) { byte_swap_ints((int *) cs, sizeof(struct csum) / sizeof(int32_t)); } /* This is for the new 4.4 cylinder group block */ void byte_swap_cgin(struct cg *cg, struct fs * fs) { int32_t * ulptr; int16_t * usptr; int size; byte_swap_int(cg->cg_firstfield); byte_swap_int(cg->cg_magic); byte_swap_int(cg->cg_time); byte_swap_int(cg->cg_cgx); byte_swap_short(cg->cg_ncyl); byte_swap_short(cg->cg_niblk); byte_swap_int(cg->cg_ndblk); byte_swap_csum(&cg->cg_cs); byte_swap_int(cg->cg_rotor); byte_swap_int(cg->cg_frotor); byte_swap_int(cg->cg_irotor); byte_swap_ints(cg->cg_frsum, MAXFRAG); byte_swap_int(cg->cg_iusedoff); byte_swap_int(cg->cg_freeoff); byte_swap_int(cg->cg_nextfreeoff); byte_swap_int(cg->cg_clusteroff); byte_swap_int(cg->cg_nclusterblks); byte_swap_ints(cg->cg_sparecon, 13); byte_swap_int(cg->cg_btotoff); ulptr = ((int32_t *)((u_int8_t *)(cg) + (cg)->cg_btotoff)); size = fs->fs_cpg; byte_swap_ints(ulptr, size); /*cg_btotoff*/ byte_swap_int(cg->cg_boff); usptr = ((int16_t *)((u_int8_t *)(cg) + (cg)->cg_boff)); size = fs->fs_cpg * fs->fs_nrpos; byte_swap_shorts(usptr,size); /*cg_boff*/ byte_swap_int(cg->cg_clustersumoff); if ((unsigned int)fs->fs_contigsumsize > 0) { ulptr = ((int32_t *)((u_int8_t *)(cg) + (cg)->cg_clustersumoff)); size = (fs->fs_contigsumsize + 1); byte_swap_ints(ulptr, size); /*cg_clustersumoff*/ } } // This is for the new 4.4 cylinder group block void byte_swap_cgout(struct cg *cg, struct fs * fs) { int32_t * ulptr; int16_t * usptr; int size; byte_swap_int(cg->cg_firstfield); byte_swap_int(cg->cg_magic); byte_swap_int(cg->cg_time); byte_swap_int(cg->cg_cgx); byte_swap_short(cg->cg_ncyl); byte_swap_short(cg->cg_niblk); byte_swap_int(cg->cg_ndblk); byte_swap_csum(&cg->cg_cs); byte_swap_int(cg->cg_rotor); byte_swap_int(cg->cg_frotor); byte_swap_int(cg->cg_irotor); byte_swap_ints(cg->cg_frsum, MAXFRAG); byte_swap_int(cg->cg_freeoff); byte_swap_int(cg->cg_nextfreeoff); byte_swap_int(cg->cg_nclusterblks); byte_swap_ints(cg->cg_sparecon, 13); byte_swap_int(cg->cg_iusedoff); byte_swap_int(cg->cg_clusteroff); ulptr = ((int32_t *)((u_int8_t *)(cg) + (cg)->cg_btotoff)); size = fs->fs_cpg; byte_swap_ints(ulptr, size); /*cg_btotoff*/ byte_swap_int(cg->cg_btotoff); usptr = ((int16_t *)((u_int8_t *)(cg) + (cg)->cg_boff)); size = fs->fs_cpg * fs->fs_nrpos; byte_swap_shorts(usptr,size); /*cg_boff*/ byte_swap_int(cg->cg_boff); if ((unsigned int)fs->fs_contigsumsize > 0) { ulptr = ((int32_t *)((u_int8_t *)(cg) + (cg)->cg_clustersumoff)); size = (fs->fs_contigsumsize + 1); byte_swap_ints(ulptr, size); /*cg_clustersumoff*/ } byte_swap_int(cg->cg_clustersumoff); } /* This value should correspond to the value set in the ffs_mounts */ #define RESYMLNKLEN 60 void byte_swap_dinodecount(struct dinode *ep, int count, int writeout) { int i,numinodes; struct dinode *dp; dp = ep; numinodes = count/sizeof(struct dinode); for(i=0;idi_mode = NXSwapShort(di->di_mode); di->di_nlink = NXSwapShort(di->di_nlink); #ifdef LFS di->di_u.inumber = NXSwapLong(di->di_u.inumber); #else di->di_u.oldids[0] = NXSwapShort(di->di_u.oldids[0]); di->di_u.oldids[1] = NXSwapShort(di->di_u.oldids[1]); #endif di->di_size = NXSwapLongLong(di->di_size); di->di_atime = NXSwapLong(di->di_atime); di->di_atimensec = NXSwapLong(di->di_atimensec); di->di_mtime = NXSwapLong(di->di_mtime); di->di_mtimensec = NXSwapLong(di->di_mtimensec); di->di_ctime = NXSwapLong(di->di_ctime); di->di_ctimensec = NXSwapLong(di->di_ctimensec); if (((di->di_mode & IFMT) != IFLNK ) || (di->di_size > RESYMLNKLEN)) { for (i=0; i < NDADDR; i++) /* direct blocks */ di->di_db[i] = NXSwapLong(di->di_db[i]); for (i=0; i < NIADDR; i++) /* indirect blocks */ di->di_ib[i] = NXSwapLong(di->di_ib[i]); } di->di_flags = NXSwapLong(di->di_flags); di->di_blocks = NXSwapLong(di->di_blocks); di->di_gen = NXSwapLong(di->di_gen); di->di_uid = NXSwapLong(di->di_uid); di->di_gid = NXSwapLong(di->di_gid); di->di_spare[0] = NXSwapLong(di->di_spare[0]); di->di_spare[1] = NXSwapLong(di->di_spare[1]); } void byte_swap_dinode_out(struct dinode *di) { int i; int mode, inosize; mode = (di->di_mode & IFMT); inosize = di->di_size; di->di_mode = NXSwapShort(di->di_mode); di->di_nlink = NXSwapShort(di->di_nlink); #ifdef LFS di->di_u.inumber = NXSwapLong(di->di_u.inumber); #else di->di_u.oldids[0] = NXSwapShort(di->di_u.oldids[0]); di->di_u.oldids[1] = NXSwapShort(di->di_u.oldids[1]); #endif di->di_size = NXSwapLongLong(di->di_size); di->di_atime = NXSwapLong(di->di_atime); di->di_atimensec = NXSwapLong(di->di_atimensec); di->di_mtime = NXSwapLong(di->di_mtime); di->di_mtimensec = NXSwapLong(di->di_mtimensec); di->di_ctime = NXSwapLong(di->di_ctime); di->di_ctimensec = NXSwapLong(di->di_ctimensec); if ((mode != IFLNK) || (inosize > RESYMLNKLEN)) { for (i=0; i < NDADDR; i++) /* direct blocks */ di->di_db[i] = NXSwapLong(di->di_db[i]); for (i=0; i < NIADDR; i++) /* indirect blocks */ di->di_ib[i] = NXSwapLong(di->di_ib[i]); } di->di_flags = NXSwapLong(di->di_flags); di->di_blocks = NXSwapLong(di->di_blocks); di->di_gen = NXSwapLong(di->di_gen); di->di_uid = NXSwapLong(di->di_uid); di->di_gid = NXSwapLong(di->di_gid); di->di_spare[0] = NXSwapLong(di->di_spare[0]); di->di_spare[1] = NXSwapLong(di->di_spare[1]); } #if notdef /* [ */ void byte_swap_direct(struct direct *dirp) { byte_swap_int(dirp->d_ino); byte_swap_short(dirp->d_reclen); } void byte_swap_dirtemplate_in(struct dirtemplate *dirt) { byte_swap_int(dirt->dot_ino); byte_swap_short(dirt->dot_reclen); byte_swap_int(dirt->dotdot_ino); byte_swap_short(dirt->dotdot_reclen); } void byte_swap_minidir_in(struct direct *dirp) { byte_swap_int(dirp->d_ino); byte_swap_short(dirp->d_reclen); } #endif /* notdef ] */ diskdev_cmds-332.25/clri.tproj/ufs_byte_order.h0000755000000000000000000000450106712726561020357 0ustar rootwheel/* * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights * Reserved. This file contains Original Code and/or Modifications of * Original Code as defined in and that are subject to the Apple Public * Source License Version 1.0 (the 'License'). You may not use this file * except in compliance with the License. Please obtain a copy of the * License at http://www.apple.com/publicsource and read it before using * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License." * * @APPLE_LICENSE_HEADER_END@ */ /* Copyright 1998 Apple Computer, Inc. * * UFS byte swapping routines to make a big endian file system useful on a * little endian machine. * * HISTORY * * 16 Feb 1998 A. Ramesh at Apple * Rhapsody version created. */ #ifndef _CLRI_BYTE_ORDER_H_ #define _CLRI_BYTE_ORDER_H_ extern int rev_endian; void byte_swap_longlongs __P((unsigned long long *, int)); void byte_swap_ints __P((int *, int)); void byte_swap_shorts __P((short *, int)); /* void byte_swap_superblock __P((struct fs *)); */ void byte_swap_sbin __P((struct fs *)); void byte_swap_sbout __P((struct fs *)); void byte_swap_csum __P((struct csum *)); void byte_swap_cgin __P((struct cg *, struct fs *)); void byte_swap_cgout __P((struct cg *, struct fs *)); /* void byte_swap_dinodes __P((struct bufarea *, int)); */ void byte_swap_dinodecount __P((struct dinode *, int, int)); void byte_swap_dinode_in __P((struct dinode *)); void byte_swap_dinode_out __P((struct dinode *)); /* void byte_swap_dir_block_in __P((struct bufarea *)); */ /* void byte_swap_dir_block_out __P((struct bufarea *)); */ /* void swapblock __P((struct bufarea *, int)); */ #if 0 void byte_swap_direct __P((struct direct *)); void byte_swap_dirtemplate_in __P((struct dirtemplate *)); void byte_swap_minidir_in __P((struct direct *)); #endif #endif /* _CLRI_BYTE_ORDER_H_ */ diskdev_cmds-332.25/dev_mkdb.tproj/0000755000000000000000000000000010640030222015763 5ustar rootwheeldiskdev_cmds-332.25/dev_mkdb.tproj/dev_mkdb.80000644000000000000000000000532206712726561017660 0ustar rootwheel.\" Copyright (c) 1990, 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: .\" This product includes software developed by the University of .\" California, Berkeley and its contributors. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)dev_mkdb.8 8.1 (Berkeley) 6/6/93 .\" .Dd June 6, 1993 .Os .Dt DEV_MKDB 8 .Sh NAME .Nm dev_mkdb .Nd create .Pa /dev database .Sh SYNOPSIS .Nm dev_mkdb .Sh DESCRIPTION The .Nm dev_mkdb command creates a .Xr db 3 hash access method database in .Dq Pa /var/run/dev.db which contains the names of all of the character and block special files in the .Dq Pa /dev directory, using the file type and the .Fa st_rdev field as the key. .Pp Keys are a structure containing a mode_t followed by a dev_t, with any padding zero'd out. The former is the type of the file (st_mode & S_IFMT), the latter is the st_rdev field. .Sh FILES .Bl -tag -width /var/run/dev.db -compact .It Pa /dev Device directory. .It Pa /var/run/dev.db Database file. .El .Sh SEE ALSO .Xr ps 1 , .Xr stat 2 , .Xr db 3 , .Xr devname 3 , .Xr kvm_nlist 3 , .Xr ttyname 3 , .Xr kvm_mkdb 8 .Sh HISTORY The .Nm dev_mkdb command appeared in .Bx 4.4 . diskdev_cmds-332.25/dev_mkdb.tproj/dev_mkdb.c0000644000000000000000000001331706712726561017736 0ustar rootwheel/* * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights * Reserved. This file contains Original Code and/or Modifications of * Original Code as defined in and that are subject to the Apple Public * Source License Version 1.0 (the 'License'). You may not use this file * except in compliance with the License. Please obtain a copy of the * License at http://www.apple.com/publicsource and read it before using * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License." * * @APPLE_LICENSE_HEADER_END@ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef lint static char copyright[] = "@(#) Copyright (c) 1990, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint static char sccsid[] = "@(#)dev_mkdb.c 8.1 (Berkeley) 6/6/93"; #endif /* not lint */ #include #include #include #undef DIRBLKSIZ #include #include #include #include #include #include #include #include #include #include void err __P((const char *, ...)); void usage __P((void)); int main(argc, argv) int argc; char *argv[]; { register DIR *dirp; register struct dirent *dp; struct stat sb; struct { mode_t type; dev_t dev; } bkey; DB *db; DBT data, key; int ch; u_char buf[MAXNAMLEN + 1]; char dbtmp[MAXPATHLEN + 1], dbname[MAXPATHLEN + 1]; while ((ch = getopt(argc, argv, "")) != EOF) switch((char)ch) { case '?': default: usage(); } argc -= optind; argv += optind; if (argc > 0) usage(); if (chdir(_PATH_DEV)) err("%s: %s", _PATH_DEV, strerror(errno)); dirp = opendir("."); (void)snprintf(dbtmp, sizeof(dbtmp), "%sdev.tmp", _PATH_VARRUN); (void)snprintf(dbname, sizeof(dbtmp), "%sdev.db", _PATH_VARRUN); db = dbopen(dbtmp, O_CREAT|O_EXLOCK|O_RDWR|O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH, DB_HASH, NULL); if (db == NULL) err("%s: %s", dbtmp, strerror(errno)); /* * Keys are a mode_t followed by a dev_t. The former is the type of * the file (mode & S_IFMT), the latter is the st_rdev field. Note * that the structure may contain padding, so we have to clear it * out here. */ bzero(&bkey, sizeof(bkey)); key.data = &bkey; key.size = sizeof(bkey); data.data = buf; while (dp = readdir(dirp)) { if (lstat(dp->d_name, &sb)) { (void)fprintf(stderr, "dev_mkdb: %s: %s\n", dp->d_name, strerror(errno)); continue; } /* Create the key. */ if (S_ISCHR(sb.st_mode)) bkey.type = S_IFCHR; else if (S_ISBLK(sb.st_mode)) bkey.type = S_IFBLK; else continue; bkey.dev = sb.st_rdev; /* * Create the data; nul terminate the name so caller doesn't * have to. */ bcopy(dp->d_name, buf, dp->d_namlen); buf[dp->d_namlen] = '\0'; data.size = dp->d_namlen + 1; if ((db->put)(db, &key, &data, 0)) err("dbput %s: %s\n", dbtmp, strerror(errno)); } (void)(db->close)(db); if (rename(dbtmp, dbname)) err("rename %s to %s: %s", dbtmp, dbname, strerror(errno)); exit(0); } void usage() { (void)fprintf(stderr, "usage: dev_mkdb\n"); exit(1); } #if __STDC__ #include #else #include #endif void #if __STDC__ err(const char *fmt, ...) #else err(fmt, va_alist) char *fmt; va_dcl #endif { va_list ap; #if __STDC__ va_start(ap, fmt); #else va_start(ap); #endif (void)fprintf(stderr, "dev_mkdb: "); (void)vfprintf(stderr, fmt, ap); va_end(ap); (void)fprintf(stderr, "\n"); exit(1); /* NOTREACHED */ } diskdev_cmds-332.25/dev_mkdb.tproj/Makefile0000644000000000000000000000205706712726561017456 0ustar rootwheel# # Generated by the NeXT Project Builder. # # NOTE: Do NOT change this file -- Project Builder maintains it. # # Put all of your customizations in files called Makefile.preamble # and Makefile.postamble (both optional), and Makefile will include them. # NAME = dev_mkdb PROJECTVERSION = 2.8 PROJECT_TYPE = Tool CFILES = dev_mkdb.c OTHERSRCS = Makefile.preamble Makefile Makefile.postamble dev_mkdb.8 MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles CODE_GEN_STYLE = DYNAMIC MAKEFILE = tool.make NEXTSTEP_INSTALLDIR = /usr/sbin WINDOWS_INSTALLDIR = /usr/sbin PDO_UNIX_INSTALLDIR = /usr/sbin LIBS = DEBUG_LIBS = $(LIBS) PROF_LIBS = $(LIBS) NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc NEXTSTEP_JAVA_COMPILER = /usr/bin/javac WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac include $(MAKEFILEDIR)/platform.make -include Makefile.preamble include $(MAKEFILEDIR)/$(MAKEFILE) -include Makefile.postamble -include Makefile.dependencies diskdev_cmds-332.25/dev_mkdb.tproj/Makefile.postamble0000644000000000000000000001176410216156236021436 0ustar rootwheel############################################################################### # NeXT Makefile.postamble Template # Copyright 1993, NeXT Computer, Inc. # # This Makefile is used for configuring the standard app makefiles associated # with ProjectBuilder. # # Use this template to set attributes for a project, sub-project, bundle, or # palette. Each node in the project's tree of sub-projects and bundles # should have it's own Makefile.preamble and Makefile.postamble. Additional # rules (e.g., after_install) that are defined by the developer should be # defined in this file. # ############################################################################### # # Here are the variables exported by the common "app" makefiles that can be # used in any customizations you make to the template below: # # PRODUCT_ROOT - Name of top-level app-wrapper (e.g., Webster.app) # OFILE_DIR - Directory into which .o object files are generated. # (Note that this name is calculated based on the target # architectures specified in Project Builder). # DERIVED_SRC_DIR - Directory used for all other derived files # ALL_CFLAGS - All the flags passed to the cc(1) driver for compilations # # NAME - name of application, bundle, subproject, palette, etc. # LANGUAGE - langage in which the project is written (default "English") # ENGLISH - boolean flag set iff $(LANGUAGE) = "English" # JAPANESE - boolean flag set iff $(LANGUAGE) = "Japanese" # LOCAL_RESOURCES - localized resources (e.g. nib's, images) of project # GLOBAL_RESOURCES - non-localized resources of project # PROJECTVERSION - version of ProjectBuilder that output Makefile # APPICON - application icon file # DOCICONS - dock icon files # ICONSECTIONS - Specifies icon sections when linking executable # # CLASSES - Class implementation files in project. # HFILES - Header files in project. # MFILES - Other Objective-C source files in project. # CFILES - Other C source files in project. # PSWFILES - .psw files in the project # PSWMFILES - .pswm files in the project # SUBPROJECTS - Subprojects of this project # BUNDLES - Bundle subprojects of this project # OTHERSRCS - Other miscellaneous sources of this project # OTHERLINKED - Source files not matching a standard source extention # # LIBS - Libraries to link with when making app target # DEBUG_LIBS - Libraries to link with when making debug target # PROF_LIBS - Libraries to link with when making profile target # OTHERLINKEDOFILES - Other relocatable files to (always) link in. # # APP_MAKEFILE_DIR - Directory in which to find generic set of Makefiles # MAKEFILEDIR - Directory in which to find $(MAKEFILE) # MAKEFILE - Top level mechanism Makefile (e.g., app.make, bundle.make) # INSTALLDIR - Directory app will be installed into by 'install' target # Change defaults assumed by the standard app makefiles here. Edit the # following default values as appropriate. (Note that if no Makefile.postamble # exists, these values will have defaults set in common.make). # Add Makefile.preamble, Makefile.postamble, and Makefile.dependencies here if # you would like changes to them to invalidate previous builds. The project # depends on $(MAKEFILES) so that changes to Makefiles will trigger a re-build. #MAKEFILES = Makefile # Optimization flag passed to compiler: #OPTIMIZATION_CFLAG = -O # Flags always passed to compiler: #COMMON_CFLAGS = $(PROJECT_SPECIFIC_CFLAGS) -g -Wall # Flags passed to compiler in normal 'app' compiles: #NORMAL_CFLAGS = $(COMMON_CFLAGS) $(OPTIMIZATION_CFLAG) # Flags passed to compiler in 'debug' compiles: #DEBUG_CFLAGS = $(COMMON_CFLAGS) -DDEBUG # Flags passed to compiler in 'profile' compiles #PROFILE_CFLAGS = $(COMMON_CFLAGS) -pg $(OPTIMIZATION_CFLAG) -DPROFILE # Flags passed to yacc #YFLAGS = -d # Ownership and permissions of files installed by 'install' target #INSTALL_AS_USER = root # User to chown app to #INSTALL_AS_GROUP = wheel # Group to chgrp app to #INSTALL_PERMISSIONS = # If set, 'install' chmod's executable to this # Options to strip for bundles, apps with bundles, and apps without bundles, # respectively. #RELOCATABLE_STRIP_OPTS = -x -u #DYLD_APP_STRIP_OPTS = -A -n #APP_STRIP_OPTS = #TOOL_STRIP_OPTS = #LIBRARY_STRIP_OPTS = -x -S # Note: -S strips debugging symbols # (Note: APP_STRIP_OPTS and TOOL_STRIP_OPTS default to empty, but # developers doing their own dynamic loading should set this to # $(DYLD_APP_STRIP_OPTS)). ######################################################################### # Put rules to extend the behavior of the standard Makefiles here. Typical # user-defined rules are before_install and after_install (please don't # redefine things like install or app, as they are owned by the top-level # Makefile API), which are rules that get invoked before and after the install # target runs. Such rules should be specified with the '::' syntax rather than # a single colon. after_install: install -m 755 -o root -g wheel -d $(DSTROOT)/usr/share/man/man8 install -m 644 -o root -g wheel -c dev_mkdb.8 $(DSTROOT)/usr/share/man/man8 diskdev_cmds-332.25/dev_mkdb.tproj/Makefile.preamble0000644000000000000000000001104106712726561021235 0ustar rootwheel############################################################################### # NeXT Makefile.preamble Template # Copyright 1993, NeXT Computer, Inc. # # This Makefile is used for configuring the standard app makefiles associated # with ProjectBuilder. # # Use this template to set attributes for a project, sub-project, bundle, or # palette. Each node in the project's tree of sub-projects and bundles # should have it's own Makefile.preamble and Makefile.postamble. # ############################################################################### ## Configure the flags passed to $(CC) here. These flags will also be ## inherited by all nested sub-projects and bundles. Put your -I, -D, -U, and ## -L flags here. To change the default flags that get passed to ${CC} ## (e.g. change -O to -O2), see Makefile.postamble. # Flags passed to compiler (in addition to -g, -O, etc) OTHER_CFLAGS = # Flags passed to ld (in addition to -ObjC, etc.) OTHER_LDFLAGS = BUNDLELDFLAGS = # use iff project is a bundle PALETTELDFLAGS = # use iff project is a palette ## Specify which headers in this project should be published to the outside ## world in a flat header directory given in PUBLIC_HEADER_DIR (which will be ## prepended by DSTROOT, below. Any subset of these public headers can be ## precompiled automatically after installation, with extra user-defined flags. PUBLIC_HEADER_DIR = PUBLIC_HEADERS = PUBLIC_PRECOMPILED_HEADERS = PUBLIC_PRECOMPILED_HEADERS_CFLAGS = ## Configure what is linked in at each level here. Libraries are only used in ## the final 'app' linking step. Final 'app' linking is only done via the ## 'app', 'debug', and 'profile' targets when they are invoked for ## the top-level app. # Additional relocatables to be linked in at this level OTHER_OFILES = # Additional libs to link apps against ('app' target) #OTHER_LIBS = # Additional libs to link apps against ('debug' target) OTHER_DEBUG_LIBS = # Additional libs to link apps against ('profile' target) OTHER_PROF_LIBS = # More 'app' libraries when $(JAPANESE) = "YES" OTHER_JAPANESE_LIBS = # More 'debug' libraries when $(JAPANESE) = "YES" OTHER_JAPANESE_DEBUG_LIBS = # More 'profile' libs when $(JAPANESE) = "YES" OTHER_JAPANESE_PROF_LIBS = # If this is a bundle, and you *know* the enclosing application will not # be linking with a library which you require in your bundle code, then # mention it here so that it gets linked into the bundle. Note that this # is wasteful but sometimes necessary. BUNDLE_LIBS = ## Configure how things get built here. Additional dependencies, sourcefiles, ## derived files, and build order should be specified here. # Other dependencies of this project OTHER_PRODUCT_DEPENDS = # Built *before* building subprojects/bundles OTHER_INITIAL_TARGETS = # Other source files maintained by .pre/postamble OTHER_SOURCEFILES = # Additional files to be removed by `make clean' OTHER_GARBAGE = # Precompiled headers to be built before any compilation occurs (e.g., draw.p) PRECOMPS = # Targets to be built before installation OTHER_INSTALL_DEPENDS = # A virtual root directory (other than /) to be prepended to the $(INSTALLDIR) # passed from ProjectBuilder. DSTROOT = # Set the following to "YES" if you want the old behavior of recursively # cleaning all nested subprojects during 'make clean'. CLEAN_ALL_SUBPROJECTS = ## Add more obscure source files here to cause them to be automatically ## processed by the appropriate tool. Note that these files should also be ## added to "Supporting Files" in ProjectBuilder. The desired .o files that ## result from these files should also be added to OTHER_OFILES above so they ## will be linked in. # .msg files that should have msgwrap run on them MSGFILES = # .defs files that should have mig run on them DEFSFILES = # .mig files (no .defs files) that should have mig run on them MIGFILES = ## Add additional Help directories here (add them to the project as "Other ## Resources" in Project Builder) so that they will be compressed into .store ## files and copied into the app wrapper. If the help directories themselves ## need to also be in the app wrapper, then a cp command will need to be added ## in an after_install target. OTHER_HELP_DIRS = # Don't add more rules here unless you want the first one to be the default # target for make! Put all your targets in Makefile.postamble. # To include a version string, project source must exist in a directory named # $(NAME).%d[.%d][.%d] and the following line must be uncommented. OTHER_GENERATED_OFILES = $(VERS_OFILE) -include ../Makefile.include diskdev_cmds-332.25/dev_mkdb.tproj/PB.project0000644000000000000000000000255006712726561017705 0ustar rootwheel{ DOCICONFILES = (); FILESTABLE = { CLASSES = (); C_FILES = (); H_FILES = (); OTHER_LIBS = (); OTHER_LINKED = (dev_mkdb.c); OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble, dev_mkdb.8); PRECOMPILED_HEADERS = (); PROJECT_HEADERS = (); PUBLIC_HEADERS = (); SUBPROJECTS = (); }; GENERATEMAIN = YES; LANGUAGE = English; LOCALIZABLE_FILES = {}; NEXTSTEP_BUILDDIR = ""; NEXTSTEP_BUILDTOOL = /bin/make; NEXTSTEP_COMPILEROPTIONS = ""; NEXTSTEP_INSTALLDIR = /usr/sbin; NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; NEXTSTEP_LINKEROPTIONS = ""; NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; PDO_UNIX_BUILDDIR = ""; PDO_UNIX_BUILDTOOL = /bin/make; PDO_UNIX_COMPILEROPTIONS = ""; PDO_UNIX_INSTALLDIR = /usr/sbin; PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; PDO_UNIX_LINKEROPTIONS = ""; PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; PROJECTNAME = dev_mkdb; PROJECTTYPE = Tool; PROJECTVERSION = 2.8; WINDOWS_BUILDDIR = ""; WINDOWS_BUILDTOOL = /bin/make; WINDOWS_COMPILEROPTIONS = ""; WINDOWS_INSTALLDIR = /usr/sbin; WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; WINDOWS_LINKEROPTIONS = ""; WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; } diskdev_cmds-332.25/disklib/0000755000000000000000000000000010640030222014474 5ustar rootwheeldiskdev_cmds-332.25/disklib/dkcksum.c0000644000000000000000000000625407157754202016334 0ustar rootwheel/* * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights * Reserved. This file contains Original Code and/or Modifications of * Original Code as defined in and that are subject to the Apple Public * Source License Version 1.0 (the 'License'). You may not use this file * except in compliance with the License. Please obtain a copy of the * License at http://www.apple.com/publicsource and read it before using * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License." * * @APPLE_LICENSE_HEADER_END@ */ /*- * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #if defined (linux) && defined (__powerpc__) #define __ppc__ #endif #include u_short dkcksum(lp) register struct disklabel *lp; { register u_short *start, *end; register u_short sum = 0; start = (u_short *)lp; end = (u_short *)&lp->d_partitions[lp->d_npartitions]; while (start < end) sum ^= *start++; return (sum); } diskdev_cmds-332.25/disklib/dkdisklabel.c0000644000000000000000000001772207611133116017134 0ustar rootwheel/* Copyright 1999 Apple Computer, Inc. * * Generate a bsd disk label routine. * Input: open file descriptor to the device node, and * pointer to a disk label structure to fill in * Return: errno status * * HISTORY * * 24 Feb 1999 D. Markarian at Apple * Created. */ #include /* memset */ #include /* sys/disklabel.h */ #include /* NBPG */ #include /* ufs/ffs/fs.h */ #include /* BBSIZE, SBSIZE */ #include /* DKIOCGETBLOCKSIZE ioctl */ #include /* struct disklabel */ u_short dkcksum __P((register struct disklabel *lp)); int dkdisklabelregenerate __P((int fd, struct disklabel * lp, int newblksize)); /* * The following two constants set the default block and fragment sizes. * Both constants must be a power of 2 and meet the following constraints: * MINBSIZE <= GENBLKSIZE <= MAXBSIZE * sectorsize <= GENFRAGSIZE <= GENBLKSIZE * GENBLKSIZE / GENFRAGSIZE <= 8 */ #define GENFRAGSIZE 1024 #define GENBLKSIZE NBPG /* 4096 */ /* * Cylinder groups may have up to many cylinders. The actual * number used depends upon how much information can be stored * on a single cylinder. The default is to use 16 cylinders * per group. */ #define GENCPG 16 /* * Interleave is physical sector interleave, set up by the * formatter or controller when formatting. When interleaving is * in use, logically adjacent sectors are not physically * contiguous, but instead are separated by some number of * sectors. It is specified as the ratio of physical sectors * traversed per logical sector. Thus an interleave of 1:1 * implies contiguous layout, while 2:1 implies that logical * sector 0 is separated by one sector from logical sector 1. */ #define GENINTERLEAVE 1 /* * Rotational speed; # of data sectors per track. */ #define GENRPM 3600 #define GENNSECTORS 32 int dkdisklabel(int fd, struct disklabel * lp) { return dkdisklabelregenerate(fd, lp, 0); } int dkdisklabelregenerate(int fd, struct disklabel * lp, int newblksize) { /* * Generate a bsd-style disk label for the specified device node. */ int blksize; int error; int index; long long numblks; /* obtain the size of the media (in blocks) */ if ( (error = ioctl(fd, DKIOCGETBLOCKCOUNT, &numblks)) < 0 ) return(error); /* obtain the block size of the media */ if ( (error = ioctl(fd, DKIOCGETBLOCKSIZE, &blksize)) < 0 ) return(error); /* adjust the size of the media with newblksize should it be specified */ if (newblksize) { numblks = (int)((((long long) numblks) * blksize) / newblksize); blksize = newblksize; } /* * clear the disk label structure and then fill in the appropriate fields; * we comment out lines that are initializations to zero with //, since it * is redundant work */ memset(lp, 0, sizeof(struct disklabel)); lp->d_magic = DISKMAGIC; /* the magic number */ // lp->d_type = 0; /* drive type */ // lp->d_subtype = 0; /* controller/d_type specific */ // lp->d_typename[0] = 0; /* type name, e.g. "eagle" */ /* * d_packname contains the pack identifier and is returned when * the disklabel is read off the disk or in-core copy. * d_boot0 and d_boot1 are the (optional) names of the * primary (block 0) and secondary (block 1-15) bootstraps * as found in /usr/mdec. These are returned when using * getdiskbyname(3) to retrieve the values from /etc/disktab. */ // lp->d_packname[0] = 0; /* pack identifier */ /* disk geometry: */ lp->d_secsize = blksize; /* # of bytes per sector */ lp->d_nsectors = GENNSECTORS; /* # of data sectors per track */ /* # of tracks per cylinder */ if (numblks < 8*32*1024) /* <=528.4 MB */ lp->d_ntracks = 16; else if (numblks < 16*32*1024) /* <=1.057 GB */ lp->d_ntracks = 32; else if (numblks < 32*32*1024) /* <=2.114 GB */ lp->d_ntracks = 54; else if (numblks < 64*32*1024) /* <=4.228 GB */ lp->d_ntracks = 128; else /* > 4.228 GB */ lp->d_ntracks = 255; /* # of data cylinders per unit */ lp->d_ncylinders = numblks / lp->d_ntracks / lp->d_nsectors; /* # of data sectors per cylinder */ lp->d_secpercyl = lp->d_nsectors * lp->d_ntracks; lp->d_secperunit = numblks; /* # of data sectors per unit */ /* * Spares (bad sector replacements) below are not counted in * d_nsectors or d_secpercyl. Spare sectors are assumed to * be physical sectors which occupy space at the end of each * track and/or cylinder. */ // lp->d_sparespertrack = 0; /* # of spare sectors per track */ // lp->d_sparespercyl = 0; /* # of data sectors per unit */ /* * Alternate cylinders include maintenance, replacement, configuration * description areas, etc. */ // lp->d_acylinders = 0; /* # of alt. cylinders per unit */ /* hardware characteristics: */ /* * d_interleave, d_trackskew and d_cylskew describe perturbations * in the media format used to compensate for a slow controller. * Interleave is physical sector interleave, set up by the * formatter or controller when formatting. When interleaving is * in use, logically adjacent sectors are not physically * contiguous, but instead are separated by some number of * sectors. It is specified as the ratio of physical sectors * traversed per logical sector. Thus an interleave of 1:1 * implies contiguous layout, while 2:1 implies that logical * sector 0 is separated by one sector from logical sector 1. * d_trackskew is the offset of sector 0 on track N relative to * sector 0 on track N-1 on the same cylinder. Finally, d_cylskew * is the offset of sector 0 on cylinder N relative to sector 0 * on cylinder N-1. */ lp->d_rpm = GENRPM; /* rotational speed */ lp->d_interleave = GENINTERLEAVE; /* hardware sector interleave */ // lp->d_trackskew = 0; /* sector 0 skew, per track */ // lp->d_cylskew = 0; /* sector 0 skew, per cylinder */ // lp->d_headswitch = 0; /* head switch time, usec */ // lp->d_trkseek = 0; /* track-to-track seek, usec */ // lp->d_flags = 0; /* generic flags */ // lp->d_drivedata[0-4] = 0; /* drive-type specific information */ // lp->d_spare[0-4] = 0; /* reserved for future use */ lp->d_magic2 = DISKMAGIC; /* the magic number (again) */ // lp->d_checksum = 0; /* xor of data incl. partitions */ /* filesystem and partition information: */ lp->d_npartitions = MAXPARTITIONS; /* number of partitions */ lp->d_bbsize = BBSIZE; /* size of boot area at sn0, bytes */ lp->d_sbsize = SBSIZE; /* max size of fs superblock, bytes */ for (index = 0; index < MAXPARTITIONS; index++) { struct partition * pp = &(lp->d_partitions[index]); pp->p_size = numblks; /* number of sectors */ // pp->p_offset = 0; /* starting sector */ pp->p_fsize = MAX(GENFRAGSIZE, blksize); /* fs fragment size */ pp->p_fstype = FS_BSDFFS; /* fs type */ pp->p_frag = MIN(8, GENBLKSIZE / pp->p_fsize);/* fs fragments/block */ pp->p_cpg = GENCPG; /* fs cylinders/group */ } /* compute a checksum on the resulting structure */ lp->d_checksum = dkcksum(lp); return 0; /* success */ } diskdev_cmds-332.25/disklib/dkopen.c0000644000000000000000000000320607157754202016145 0ustar rootwheel/* * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights * Reserved. This file contains Original Code and/or Modifications of * Original Code as defined in and that are subject to the Apple Public * Source License Version 1.0 (the 'License'). You may not use this file * except in compliance with the License. Please obtain a copy of the * License at http://www.apple.com/publicsource and read it before using * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License." * * @APPLE_LICENSE_HEADER_END@ */ #include "dkopen.h" #include #include #include #include int dkopen (const char *path, int flags, int mode) { #if defined (linux) return (open64 (path, flags, mode)); #elif defined (__APPLE__) return (open (path, flags, mode)); #endif } int dkclose (int filedes) { #if defined (linux) return (close (filedes)); #elif defined (__APPLE__) return (close (filedes)); #endif } off64_t dklseek (int filedes, off64_t offset, int whence) { #if defined (linux) return (lseek64 (filedes, offset, whence)); #elif defined (__APPLE__) return (lseek (filedes, offset, whence)); #endif } diskdev_cmds-332.25/disklib/dkopen.h0000644000000000000000000000342507157754202016155 0ustar rootwheel/* * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights * Reserved. This file contains Original Code and/or Modifications of * Original Code as defined in and that are subject to the Apple Public * Source License Version 1.0 (the 'License'). You may not use this file * except in compliance with the License. Please obtain a copy of the * License at http://www.apple.com/publicsource and read it before using * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License." * * @APPLE_LICENSE_HEADER_END@ */ /* * File I/O stubs * * Linux and other OSs may use open64, lseek64 instead of defaulting off_t to * 64-bits like OSX does. This file provides cover functions to always perform * 64-bit file I/O. */ #ifndef _DKOPEN_H_ #define _DKOPEN_H_ /* Must predefine the large file flags before including sys/types.h */ #if defined (linux) #define _LARGEFILE_SOURCE #define _LARGEFILE64_SOURCE #elif defined (__APPLE__) #else #error Platform not recognized #endif #include /* Typedef off64_t for platforms that don't have it declared */ #if defined (__APPLE__) && !defined (linux) typedef u_int64_t off64_t; #endif int dkopen (const char *path, int flags, int mode); int dkclose (int filedes); off64_t dklseek (int fileds, off64_t offset, int whence); #endif diskdev_cmds-332.25/disklib/dksecsize.c0000644000000000000000000000440710267354542016654 0ustar rootwheel/* * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights * Reserved. This file contains Original Code and/or Modifications of * Original Code as defined in and that are subject to the Apple Public * Source License Version 1.0 (the 'License'). You may not use this file * except in compliance with the License. Please obtain a copy of the * License at http://www.apple.com/publicsource and read it before using * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License." * * @APPLE_LICENSE_HEADER_END@ */ /* Copyright 1998 Apple Computer, Inc. * * Get disk label's sector size routine. * Input: pointer to a block device string ie: "/dev/disk1s1" * Return: sector size from the disk label * * HISTORY * * 27 May 1998 K. Crippes at Apple * Rhapsody version created. * 18 Feb 1999 D. Markarian at Apple * DKIOCGLABEL deprecated; using DKIOCBLKSIZE instead, which now returns * the appropriate size for ufs partitions created with wierd block sizes. */ #include #include #include #include #include #include #include char *blockcheck __P((char *)); long dksecsize (dev) char *dev; { int fd; /* file descriptor for reading device label */ char *cdev; int devblklen; extern int errno; /* Convert block device into a character device string */ if (cdev = blockcheck(dev)) { if ((fd = open(cdev, O_RDONLY)) < 0) { fprintf(stderr, "Can't open %s, %s\n", cdev, strerror(errno)); return (0); } } else return (0); if (ioctl(fd, DKIOCGETBLOCKSIZE, &devblklen) < 0) { (void)close(fd); return (0); } else { (void)close(fd); return (devblklen); } } diskdev_cmds-332.25/disklib/dump.h0000644000000000000000000002054610216156236015636 0ustar rootwheel/* * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights * Reserved. This file contains Original Code and/or Modifications of * Original Code as defined in and that are subject to the Apple Public * Source License Version 1.0 (the 'License'). You may not use this file * except in compliance with the License. Please obtain a copy of the * License at http://www.apple.com/publicsource and read it before using * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License." * * @APPLE_LICENSE_HEADER_END@ */ /*- * Copyright (c) 1980, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)dump.h 8.2 (Berkeley) 4/28/95 */ #define MAXINOPB (MAXBSIZE / sizeof(struct dinode)) #define MAXNINDIR (MAXBSIZE / sizeof(daddr_t)) /* * Dump maps used to describe what is to be dumped. */ extern int mapsize; /* size of the state maps */ extern char *usedinomap; /* map of allocated inodes */ extern char *dumpdirmap; /* map of directories to be dumped */ extern char *dumpinomap; /* map of files to be dumped */ extern union u_spcl u_spcl; #define spcl u_spcl.s_spcl /* * Map manipulation macros. */ #define SETINO(ino, map) \ map[(u_int)((ino) - 1) / NBBY] |= 1 << ((u_int)((ino) - 1) % NBBY) #define CLRINO(ino, map) \ map[(u_int)((ino) - 1) / NBBY] &= ~(1 << ((u_int)((ino) - 1) % NBBY)) #define TSTINO(ino, map) \ (map[(u_int)((ino) - 1) / NBBY] & (1 << ((u_int)((ino) - 1) % NBBY))) /* * All calculations done in 0.1" units! */ extern char *disk; /* name of the disk file */ extern char *tape; /* name of the tape file */ extern char *dumpdates; /* name of the file containing dump date information*/ extern char *temp; /* name of the file for doing rewrite of dumpdates */ extern char lastlevel; /* dump level of previous dump */ extern char level; /* dump level of this dump */ extern int uflag; /* update flag */ extern int diskfd; /* disk file descriptor */ extern int tapefd; /* tape file descriptor */ extern int pipeout; /* true => output to standard output */ extern ino_t curino; /* current inumber; used globally */ extern int newtape; /* new tape flag */ extern int density; /* density in 0.1" units */ extern long tapesize; /* estimated tape size, blocks */ extern long tsize; /* tape size in 0.1" units */ extern long asize; /* number of 0.1" units written on current tape */ extern int etapes; /* estimated number of tapes */ extern int nonodump; /* if set, do not honor UF_NODUMP user flags */ extern int notify; /* notify operator flag */ extern int blockswritten; /* number of blocks written on current tape */ extern int tapeno; /* current tape number */ extern time_t tstart_writing; /* when started writing the first tape block */ extern struct fs *sblock; /* the file system super block */ extern char sblock_buf[MAXBSIZE]; extern long dev_bsize; /* block size of underlying disk device */ extern int dev_bshift; /* log2(dev_bsize) */ extern int tp_bshift; /* log2(TP_BSIZE) */ #ifndef __P #include #endif /* operator interface functions */ void broadcast __P((char *message)); void lastdump __P((int arg)); /* int should be char */ void msg __P((const char *fmt, ...)); void msgtail __P((const char *fmt, ...)); int query __P((char *question)); void quit __P((const char *fmt, ...)); void set_operators __P((void)); void timeest __P((void)); time_t unctime __P((char *str)); /* mapping rouintes */ struct dinode; long blockest __P((struct dinode *dp)); int mapfiles __P((ino_t maxino, long *tapesize)); int mapdirs __P((ino_t maxino, long *tapesize)); /* file dumping routines */ void blksout __P((daddr_t *blkp, int frags, ino_t ino)); void bread __P((daddr_t blkno, char *buf, int size)); void dumpino __P((struct dinode *dp, ino_t ino)); void dumpmap __P((char *map, int type, ino_t ino)); void writeheader __P((ino_t ino)); /* tape writing routines */ int alloctape __P((void)); void close_rewind __P((void)); void dumpblock __P((daddr_t blkno, int size)); void startnewtape __P((int top)); void trewind __P((void)); void writerec __P((char *dp, int isspcl)); __dead void Exit __P((int status)); void dumpabort __P((int signo)); void getfstab __P((void)); char *rawname __P((char *cp)); struct dinode *getino __P((ino_t inum)); /* rdump routines */ #ifdef RDUMP void rmtclose __P((void)); int rmthost __P((char *host)); int rmtopen __P((char *tape, int mode)); int rmtwrite __P((char *buf, int count)); #endif /* RDUMP */ void interrupt __P((int signo)); /* in case operator bangs on console */ /* * Exit status codes */ #define X_FINOK 0 /* normal exit */ #define X_REWRITE 2 /* restart writing from the check point */ #define X_ABORT 3 /* abort dump; don't attempt checkpointing */ #define OPGRENT "operator" /* group entry to notify */ #define DIALUP "ttyd" /* prefix for dialups */ struct fstab *fstabsearch __P((char *key)); /* search fs_file and fs_spec */ #ifndef NAME_MAX #define NAME_MAX 255 #endif /* * The contents of the file _PATH_DUMPDATES is maintained both on * a linked list, and then (eventually) arrayified. */ struct dumpdates { char dd_name[NAME_MAX+3]; char dd_level; time_t dd_ddate; }; struct dumptime { struct dumpdates dt_value; struct dumptime *dt_next; }; extern struct dumptime *dthead; /* head of the list version */ extern int nddates; /* number of records (might be zero) */ extern int ddates_in; /* we have read the increment file */ extern struct dumpdates **ddatev; /* the arrayfied version */ void initdumptimes __P((void)); void getdumptime __P((void)); void putdumptime __P((void)); #define ITITERATE(i, ddp) \ for (ddp = ddatev[i = 0]; i < nddates; ddp = ddatev[++i]) void sig __P((int signo)); /* * Compatibility with old systems. */ #ifdef COMPAT #include #define strchr(a,b) index(a,b) #define strrchr(a,b) rindex(a,b) extern char *strdup(), *ctime(); extern int read(), write(); extern int errno; #endif #ifndef _PATH_UTMP #define _PATH_UTMP "/etc/utmp" #endif #ifndef _PATH_FSTAB #define _PATH_FSTAB "/etc/fstab" #endif #ifdef sunos extern char *calloc(); extern char *malloc(); extern long atol(); extern char *strcpy(); extern char *strncpy(); extern char *strcat(); extern time_t time(); extern void endgrent(); extern __dead void exit(); extern off_t lseek(); extern const char *strerror(); #endif diskdev_cmds-332.25/disklib/dumprmt.c0000644000000000000000000002051410267354542016355 0ustar rootwheel/* * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights * Reserved. This file contains Original Code and/or Modifications of * Original Code as defined in and that are subject to the Apple Public * Source License Version 1.0 (the 'License'). You may not use this file * except in compliance with the License. Please obtain a copy of the * License at http://www.apple.com/publicsource and read it before using * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License." * * @APPLE_LICENSE_HEADER_END@ */ /*- * Copyright (c) 1980, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #include #include #include #include #ifdef sunos #include #include #else #include #endif #include #include #include #include #include #include #include #include #include #include #ifdef __STDC__ #include #include #include #endif #include "pathnames.h" #include "dump.h" #define TS_CLOSED 0 #define TS_OPEN 1 static int rmtstate = TS_CLOSED; static int rmtape; static char *rmtpeer; static int okname __P((char *)); static int rmtcall __P((char *, char *)); static void rmtconnaborted __P((/* int, int */)); static int rmtgetb __P((void)); static void rmtgetconn __P((void)); static void rmtgets __P((char *, int)); static int rmtreply __P((char *)); extern int ntrec; /* blocking factor on tape */ union u_spcl u_spcl; int rmthost(host) char *host; { rmtpeer = malloc(strlen(host) + 1); if (rmtpeer) strcpy(rmtpeer, host); else rmtpeer = host; signal(SIGPIPE, rmtconnaborted); rmtgetconn(); if (rmtape < 0) return (0); return (1); } static void rmtconnaborted() { errx(1, "Lost connection to remote host."); } void rmtgetconn() { register char *cp; static struct servent *sp = NULL; static struct passwd *pwd = NULL; #ifdef notdef static int on = 1; #endif char *tuser; int size; int maxseg; if (sp == NULL) { sp = getservbyname("shell", "tcp"); if (sp == NULL) errx(1, "shell/tcp: unknown service"); pwd = getpwuid(getuid()); if (pwd == NULL) errx(1, "who are you?"); } if ((cp = strchr(rmtpeer, '@')) != NULL) { tuser = rmtpeer; *cp = '\0'; if (!okname(tuser)) exit(1); rmtpeer = ++cp; } else tuser = pwd->pw_name; rmtape = rcmd(&rmtpeer, (u_short)sp->s_port, pwd->pw_name, tuser, _PATH_RMT, (int *)0); size = ntrec * TP_BSIZE; if (size > 60 * 1024) /* XXX */ size = 60 * 1024; /* Leave some space for rmt request/response protocol */ size += 2 * 1024; while (size > TP_BSIZE && setsockopt(rmtape, SOL_SOCKET, SO_SNDBUF, &size, sizeof (size)) < 0) size -= TP_BSIZE; (void)setsockopt(rmtape, SOL_SOCKET, SO_RCVBUF, &size, sizeof (size)); maxseg = 1024; if (setsockopt(rmtape, IPPROTO_TCP, TCP_MAXSEG, &maxseg, sizeof (maxseg)) < 0) perror("TCP_MAXSEG setsockopt"); #ifdef notdef if (setsockopt(rmtape, IPPROTO_TCP, TCP_NODELAY, &on, sizeof (on)) < 0) perror("TCP_NODELAY setsockopt"); #endif } static int okname(cp0) char *cp0; { register char *cp; register int c; for (cp = cp0; *cp; cp++) { c = *cp; if (!isascii(c) || !(isalnum(c) || c == '_' || c == '-')) { warnx("invalid user name: %s", cp0); return (0); } } return (1); } int rmtopen(tape, mode) char *tape; int mode; { char buf[256]; (void)sprintf(buf, "O%s\n%d\n", tape, mode); rmtstate = TS_OPEN; return (rmtcall(tape, buf)); } void rmtclose() { if (rmtstate != TS_OPEN) return; rmtcall("close", "C\n"); rmtstate = TS_CLOSED; } int rmtread(buf, count) char *buf; int count; { char line[30]; int n, i, cc; (void)sprintf(line, "R%d\n", count); n = rmtcall("read", line); if (n < 0) { errno = n; return (-1); } for (i = 0; i < n; i += cc) { cc = read(rmtape, buf+i, n - i); if (cc <= 0) { rmtconnaborted(); } } return (n); } int rmtwrite(buf, count) char *buf; int count; { char line[30]; (void)sprintf(line, "W%d\n", count); write(rmtape, line, strlen(line)); write(rmtape, buf, count); return (rmtreply("write")); } void rmtwrite0(count) int count; { char line[30]; (void)sprintf(line, "W%d\n", count); write(rmtape, line, strlen(line)); } void rmtwrite1(buf, count) char *buf; int count; { write(rmtape, buf, count); } int rmtwrite2() { return (rmtreply("write")); } int rmtseek(offset, pos) int offset, pos; { char line[80]; (void)sprintf(line, "L%d\n%d\n", offset, pos); return (rmtcall("seek", line)); } struct mtget mts; struct mtget * rmtstatus() { register int i; register char *cp; if (rmtstate != TS_OPEN) return (NULL); rmtcall("status", "S\n"); for (i = 0, cp = (char *)&mts; i < sizeof(mts); i++) *cp++ = rmtgetb(); return (&mts); } int rmtioctl(cmd, count) int cmd, count; { char buf[256]; if (count < 0) return (-1); (void)sprintf(buf, "I%d\n%d\n", cmd, count); return (rmtcall("ioctl", buf)); } static int rmtcall(cmd, buf) char *cmd, *buf; { if (write(rmtape, buf, strlen(buf)) != strlen(buf)) rmtconnaborted(); return (rmtreply(cmd)); } static int rmtreply(cmd) char *cmd; { register char *cp; char code[30], emsg[BUFSIZ]; rmtgets(code, sizeof (code)); if (*code == 'E' || *code == 'F') { rmtgets(emsg, sizeof (emsg)); msg("%s: %s", cmd, emsg); if (*code == 'F') { rmtstate = TS_CLOSED; return (-1); } return (-1); } if (*code != 'A') { /* Kill trailing newline */ cp = code + strlen(code); if (cp > code && *--cp == '\n') *cp = '\0'; msg("Protocol to remote tape server botched (code \"%s\").\n", code); rmtconnaborted(); } return (atoi(code + 1)); } int rmtgetb() { char c; if (read(rmtape, &c, 1) != 1) rmtconnaborted(); return (c); } /* Get a line (guaranteed to have a trailing newline). */ void rmtgets(line, len) char *line; int len; { register char *cp = line; while (len > 1) { *cp = rmtgetb(); if (*cp == '\n') { cp[1] = '\0'; return; } cp++; len--; } *cp = '\0'; msg("Protocol to remote tape server botched.\n"); msg("(rmtgets got \"%s\").\n", line); rmtconnaborted(); } diskdev_cmds-332.25/disklib/fsck.h0000644000000000000000000003013210216156236015607 0ustar rootwheel/* * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights * Reserved. This file contains Original Code and/or Modifications of * Original Code as defined in and that are subject to the Apple Public * Source License Version 1.0 (the 'License'). You may not use this file * except in compliance with the License. Please obtain a copy of the * License at http://www.apple.com/publicsource and read it before using * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License." * * @APPLE_LICENSE_HEADER_END@ */ /* * Copyright (c) 1980, 1986, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)fsck.h 8.4 (Berkeley) 5/9/95 */ #include #include #include #define MAXDUP 10 /* limit on dup blks (per inode) */ #define MAXBAD 10 /* limit on bad blks (per inode) */ #define MAXBUFSPACE 40*1024 /* maximum space to allocate to buffers */ #define INOBUFSIZE 56*1024 /* size of buffer to read inodes in pass1 */ #ifndef BUFSIZ #define BUFSIZ 1024 #endif #define USTATE 01 /* inode not allocated */ #define FSTATE 02 /* inode is file */ #define DSTATE 03 /* inode is directory */ #define DFOUND 04 /* directory found during descent */ #define DCLEAR 05 /* directory is to be cleared */ #define FCLEAR 06 /* file is to be cleared */ /* * buffer cache structure. */ struct bufarea { struct bufarea *b_next; /* free list queue */ struct bufarea *b_prev; /* free list queue */ ufs_daddr_t b_bno; int b_size; int b_errs; int b_flags; union { char *b_buf; /* buffer space */ ufs_daddr_t *b_indir; /* indirect block */ struct fs *b_fs; /* super block */ struct cg *b_cg; /* cylinder group */ struct dinode *b_dinode; /* inode block */ } b_un; char b_dirty; }; #define B_INUSE 1 #define MINBUFS 5 /* minimum number of buffers required */ extern struct bufarea bufhead; /* head of list of other blks in filesys */ extern struct bufarea sblk; /* file system superblock */ extern struct bufarea cgblk; /* cylinder group blocks */ extern struct bufarea *pdirbp; /* current directory contents */ extern struct bufarea *pbp; /* current inode block */ #define dirty(bp) (bp)->b_dirty = 1 #define initbarea(bp) \ (bp)->b_dirty = 0; \ (bp)->b_bno = (ufs_daddr_t)-1; \ (bp)->b_flags = 0; #define sbdirty() sblk.b_dirty = 1 #define cgdirty() cgblk.b_dirty = 1 #define sblock (*sblk.b_un.b_fs) #define cgrp (*cgblk.b_un.b_cg) enum fixstate {DONTKNOW, NOFIX, FIX, IGNORE}; struct inodesc { enum fixstate id_fix; /* policy on fixing errors */ int (*id_func)(); /* function to be applied to blocks of inode */ ino_t id_number; /* inode number described */ ino_t id_parent; /* for DATA nodes, their parent */ ufs_daddr_t id_blkno; /* current block number being examined */ int id_numfrags; /* number of frags contained in block */ quad_t id_filesize; /* for DATA nodes, the size of the directory */ int id_loc; /* for DATA nodes, current location in dir */ int id_entryno; /* for DATA nodes, current entry number */ struct direct *id_dirp; /* for DATA nodes, ptr to current entry */ char *id_name; /* for DATA nodes, name to find or enter */ char id_type; /* type of descriptor, DATA or ADDR */ }; /* file types */ #define DATA 1 #define ADDR 2 /* * Linked list of duplicate blocks. * * The list is composed of two parts. The first part of the * list (from duplist through the node pointed to by muldup) * contains a single copy of each duplicate block that has been * found. The second part of the list (from muldup to the end) * contains duplicate blocks that have been found more than once. * To check if a block has been found as a duplicate it is only * necessary to search from duplist through muldup. To find the * total number of times that a block has been found as a duplicate * the entire list must be searched for occurences of the block * in question. The following diagram shows a sample list where * w (found twice), x (found once), y (found three times), and z * (found once) are duplicate block numbers: * * w -> y -> x -> z -> y -> w -> y * ^ ^ * | | * duplist muldup */ struct dups { struct dups *next; ufs_daddr_t dup; }; extern struct dups *duplist; /* head of dup list */ extern struct dups *muldup; /* end of unique duplicate dup block numbers */ /* * Linked list of inodes with zero link counts. */ struct zlncnt { struct zlncnt *next; ino_t zlncnt; }; extern struct zlncnt *zlnhead; /* head of zero link count list */ /* * Inode cache data structures. */ struct inoinfo { struct inoinfo *i_nexthash; /* next entry in hash chain */ ino_t i_number; /* inode number of this entry */ ino_t i_parent; /* inode number of parent */ ino_t i_dotdot; /* inode number of `..' */ size_t i_isize; /* size of inode */ u_int i_numblks; /* size of block array in bytes */ ufs_daddr_t i_blks[1]; /* actually longer */ } ; extern struct inoinfo **inphead, **inpsort; extern long numdirs, listmax, inplast; extern char *cdevname; /* name of device being checked */ extern long dev_bsize; /* computed value of DEV_BSIZE */ extern long secsize; /* actual disk sector size */ extern char nflag; /* assume a no response */ extern char yflag; /* assume a yes response */ extern int bflag; /* location of alternate super block */ #ifdef __APPLE__ extern int qflag; /* quick check return zero if clean, nonzero if dirty */ #endif /* __APPLE__ */ extern int debug; /* output debugging info */ extern int cvtlevel; /* convert to newer file system format */ extern int doinglevel1; /* converting to new cylinder group format */ extern int doinglevel2; /* converting to new inode format */ extern int newinofmt; /* filesystem has new inode format */ extern char preen; /* just fix normal inconsistencies */ extern char hotroot; /* checking root device */ extern char havesb; /* superblock has been read */ extern int fsmodified; /* 1 => write done to file system */ extern int fsreadfd; /* file descriptor for reading file system */ extern int fswritefd; /* file descriptor for writing file system */ extern ufs_daddr_t maxfsblock; /* number of blocks in the file system */ extern char *blockmap; /* ptr to primary blk allocation map */ extern ino_t maxino; /* number of inodes in file system */ extern ino_t lastino; /* last inode in use */ extern char *statemap; /* ptr to inode state table */ extern u_char *typemap; /* ptr to inode type table */ extern short *lncntp; /* ptr to link count table */ extern ino_t lfdir; /* lost & found directory inode number */ extern char *lfname; /* lost & found directory name */ extern int lfmode; /* lost & found directory creation mode */ extern ufs_daddr_t n_blks; /* number of blocks in use */ extern ufs_daddr_t n_files; /* number of files in use */ #define clearinode(dp) (*(dp) = zino) extern struct dinode zino; #define setbmap(blkno) setbit(blockmap, blkno) #define testbmap(blkno) isset(blockmap, blkno) #define clrbmap(blkno) clrbit(blockmap, blkno) #define STOP 0x01 #define SKIP 0x02 #define KEEPON 0x04 #define ALTERED 0x08 #define FOUND 0x10 #define EEXIT 8 /* Standard error exit. */ #ifdef __APPLE__ /* define qflag exit codes */ #define CLEANEXIT 0 /* Filesystem Clean, no checks */ #define DIRTYEXIT 3 /* Filesystem Dirty, no checks */ #endif /* __APPLE__ */ struct fstab; void adjust __P((struct inodesc *, int lcnt)); ufs_daddr_t allocblk __P((long frags)); ino_t allocdir __P((ino_t parent, ino_t request, int mode)); ino_t allocino __P((ino_t request, int type)); void blkerror __P((ino_t ino, char *type, ufs_daddr_t blk)); char *blockcheck __P((char *name)); int bread __P((int fd, char *buf, ufs_daddr_t blk, long size)); void bufinit __P((void)); void bwrite __P((int fd, char *buf, ufs_daddr_t blk, long size)); void cacheino __P((struct dinode *dp, ino_t inumber)); void catch __P((int)); void catchquit __P((int)); int changeino __P((ino_t dir, char *name, ino_t newnum)); int checkfstab __P((int preen, int maxrun, int (*docheck)(struct fstab *), int (*chkit)(char *, char *, long, int))); int chkrange __P((ufs_daddr_t blk, int cnt)); void ckfini __P((int markclean)); int ckinode __P((struct dinode *dp, struct inodesc *)); void clri __P((struct inodesc *, char *type, int flag)); void direrror __P((ino_t ino, char *errmesg)); int dirscan __P((struct inodesc *)); int dofix __P((struct inodesc *, char *msg)); extern void ffs_clrblock __P((struct fs *, u_char *, ufs_daddr_t)); extern void ffs_fragacct __P((struct fs *, int, int32_t [], int)); extern int ffs_isblock __P((struct fs *, u_char *, ufs_daddr_t)); extern void ffs_setblock __P((struct fs *, u_char *, ufs_daddr_t)); extern void fileerror __P((ino_t cwd, ino_t ino, char *errmesg)); extern int findino __P((struct inodesc *)); int findname __P((struct inodesc *)); void flush __P((int fd, struct bufarea *bp)); void freeblk __P((ufs_daddr_t blkno, long frags)); void freeino __P((ino_t ino)); void freeinodebuf __P((void)); int ftypeok __P((struct dinode *dp)); void getblk __P((struct bufarea *bp, ufs_daddr_t blk, long size)); struct bufarea *getdatablk __P((ufs_daddr_t blkno, long size)); struct inoinfo *getinoinfo __P((ino_t inumber)); struct dinode *getnextinode __P((ino_t inumber)); void getpathname __P((char *namebuf, ino_t curdir, ino_t ino)); struct dinode *ginode __P((ino_t inumber)); void inocleanup __P((void)); void inodirty __P((void)); int linkup __P((ino_t orphan, ino_t parentdir)); int makeentry __P((ino_t parent, ino_t ino, char *name)); void panic __P((const char *fmt, ...)); void pass1 __P((void)); void pass1b __P((void)); int pass1check __P((struct inodesc *)); void pass2 __P((void)); void pass3 __P((void)); void pass4 __P((void)); int pass4check __P((struct inodesc *)); void pass5 __P((void)); void pfatal __P((const char *fmt, ...)); void pinode __P((ino_t ino)); void propagate __P((void)); void pwarn __P((const char *fmt, ...)); int reply __P((char *question)); void resetinodebuf __P((void)); int setup __P((char *dev)); void voidquit __P((int)); diskdev_cmds-332.25/disklib/getmntopts.c0000644000000000000000000001165207310022560017057 0ustar rootwheel/* * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights * Reserved. This file contains Original Code and/or Modifications of * Original Code as defined in and that are subject to the Apple Public * Source License Version 1.0 (the 'License'). You may not use this file * except in compliance with the License. Please obtain a copy of the * License at http://www.apple.com/publicsource and read it before using * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License." * * @APPLE_LICENSE_HEADER_END@ */ /*- * Copyright (c) 1994 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #include #include #include #include #include #include #include "mntopts.h" int getmnt_silent = 1; void getmntopts(options, m0, flagp, altflagp) const char *options; const struct mntopt *m0; int *flagp; int *altflagp; { const struct mntopt *m; int negative, len; char *opt, *optbuf, *p; int *thisflagp; /* Copy option string, since it is about to be torn asunder... */ if ((optbuf = strdup(options)) == NULL) err(1, NULL); for (opt = optbuf; (opt = strtok(opt, ",")) != NULL; opt = NULL) { /* Check for "no" prefix. */ if (opt[0] == 'n' && opt[1] == 'o') { negative = 1; opt += 2; } else negative = 0; /* * for options with assignments in them (ie. quotas) * ignore the assignment as it's handled elsewhere */ p = strchr(opt, '='); if (p) *++p = '\0'; /* Scan option table. */ for (m = m0; m->m_option != NULL; ++m) { len = strlen(m->m_option); if (strncasecmp(opt, m->m_option, len) == 0) if ( opt[len] == '\0' || opt[len] == '=' ) break; } /* Save flag, or fail if option is not recognized. */ if (m->m_option) { thisflagp = m->m_altloc ? altflagp : flagp; if (negative == m->m_inverse) *thisflagp |= m->m_flag; else *thisflagp &= ~m->m_flag; } else if (!getmnt_silent) { errx(1, "-o %s: option not supported", opt); } } free(optbuf); } void rmslashes(rrpin, rrpout) char *rrpin; char *rrpout; { char *rrpoutstart; *rrpout = *rrpin; for (rrpoutstart = rrpout; *rrpin != '\0'; *rrpout++ = *rrpin++) { /* skip all double slashes */ while (*rrpin == '/' && *(rrpin + 1) == '/') rrpin++; } /* remove trailing slash if necessary */ if (rrpout - rrpoutstart > 1 && *(rrpout - 1) == '/') *(rrpout - 1) = '\0'; else *rrpout = '\0'; } void checkpath(path, resolved) const char *path; char *resolved; { struct stat sb; if (realpath(path, resolved) != NULL && stat(resolved, &sb) == 0) { if (!S_ISDIR(sb.st_mode)) errx(EX_USAGE, "%s: not a directory", resolved); } else errx(EX_USAGE, "%s: %s", resolved, strerror(errno)); } diskdev_cmds-332.25/disklib/Makefile0000644000000000000000000000314410133057751016153 0ustar rootwheel# # Generated by the NeXT Project Builder. # # NOTE: Do NOT change this file -- Project Builder maintains it. # # Put all of your customizations in files called Makefile.preamble # and Makefile.postamble (both optional), and Makefile will include them. # NAME = disk PROJECTVERSION = 2.8 PROJECT_TYPE = Library HFILES = dump.h fsck.h mntopts.h pathnames.h ufslabel.h dkopen.h CFILES = dkcksum.c dksecsize.c dumprmt.c getmntopts.c preen.c\ vfslist.c dkdisklabel.c ufslabel.c dkopen.c OTHERSRCS = Makefile.preamble Makefile Makefile.postamble MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles CURRENTLY_ACTIVE_VERSION = YES DEPLOY_WITH_VERSION_NAME = A CODE_GEN_STYLE = DYNAMIC MAKEFILE = library.make NEXTSTEP_INSTALLDIR = /usr/local/lib WINDOWS_INSTALLDIR = LOCAL_DEVELOPER_DIR/Libraries PDO_UNIX_INSTALLDIR = /usr/local/lib LIBS = DEBUG_LIBS = $(LIBS) PROF_LIBS = $(LIBS) HEADER_PATHS = -I$(NEXT_ROOT)$(SYSTEM_LIBRARY_DIR)/Frameworks/System.framework/PrivateHeaders PROJECT_HEADERS = mntopts.h fsck.h pathnames.h dump.h NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/BUILD WINDOWS_PUBLIC_HEADERS_DIR = LOCAL_DEVELOPER_DIR/Headers/$(NAME) PDO_UNIX_PUBLIC_HEADERS_DIR = LOCAL_DEVELOPER_DIR/Headers/$(NAME) NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc NEXTSTEP_JAVA_COMPILER = /usr/bin/javac WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac include $(MAKEFILEDIR)/platform.make -include Makefile.preamble include $(MAKEFILEDIR)/$(MAKEFILE) -include Makefile.postamble -include Makefile.dependencies diskdev_cmds-332.25/disklib/Makefile.postamble0000644000000000000000000001236010216156236020140 0ustar rootwheel############################################################################### # NeXT Makefile.postamble # Copyright 1996, NeXT Software, Inc. # # This Makefile is used for configuring the standard app makefiles associated # with ProjectBuilder. # # Use this template to set attributes for a project, sub-project, bundle, or # palette. Each node in the project's tree of sub-projects and bundles # should have it's own Makefile.preamble and Makefile.postamble. Additional # rules (e.g., after_install) that are defined by the developer should be # defined in this file. # ############################################################################### # # Here are the variables exported by the common "app" makefiles that can be # used in any customizations you make to the template below: # # PRODUCT_ROOT - Name of the directory to which resources are copied. # OFILE_DIR - Directory into which .o object files are generated. # (Note that this name is calculated based on the target # architectures specified in Project Builder). # DERIVED_SRC_DIR - Directory used for all other derived files # ALL_CFLAGS - All the flags passed to the cc(1) driver for compilations # # NAME - name of application, bundle, subproject, palette, etc. # LANGUAGE - langage in which the project is written (default "English") # LOCAL_RESOURCES - localized resources (e.g. nib's, images) of project # GLOBAL_RESOURCES - non-localized resources of project # PROJECTVERSION - version of ProjectBuilder project (NS3.X = 1.1, NS4.0 = 2.0) # ICONSECTIONS - Specifies icon sections when linking executable # # CLASSES - Class implementation files in project. # HFILES - Header files in project. # MFILES - Other Objective-C source files in project. # CFILES - Other C source files in project. # PSWFILES - .psw files in the project # PSWMFILES - .pswm files in the project # SUBPROJECTS - Subprojects of this project # BUNDLES - Bundle subprojects of this project # OTHERSRCS - Other miscellaneous sources of this project # OTHERLINKED - Source files not matching a standard source extention # # LIBS - Libraries to link with when making app target # DEBUG_LIBS - Libraries to link with when making debug target # PROF_LIBS - Libraries to link with when making profile target # OTHERLINKEDOFILES - Other relocatable files to (always) link in. # # APP_MAKEFILE_DIR - Directory in which to find generic set of Makefiles # MAKEFILEDIR - Directory in which to find $(MAKEFILE) # MAKEFILE - Top level mechanism Makefile (e.g., app.make, bundle.make) # INSTALLDIR - Directory app will be installed into by 'install' target # ############################################################################### # Change defaults assumed by the standard makefiles here. Edit the # following default values as appropriate. (Note that if no Makefile.postamble # exists, these values will have defaults set in common.make). # Versioning of frameworks, libraries, bundles, and palettes: #CURRENTLY_ACTIVE_VERSION = YES # Set to "NO" to produce a compatibility binary #DEPLOY_WITH_VERSION_NAME = A # This should be incremented as your API changes. #COMPATIBILITY_PROJECT_VERSION = 1 # This should be incremented as your API grows. #CURRENT_PROJECT_VERSION = 1 # Defaults to using the "vers_string" hack. # Some compiler flags can be easily overridden here, but onlytake effect at # the top-level: #OPTIMIZATION_CFLAG = -O #DEBUG_SYMBOLS_CFLAG = -g #WARNING_CFLAGS = -Wmost #DEBUG_BUILD_CFLAGS = -DDEBUG #PROFILE_BUILD_CFLAGS = -pg -DPROFILE # This definition will suppress stripping of debug symbols when an executable # is installed. By default it is YES. # STRIP_ON_INSTALL = NO # Flags passed to yacc #YFLAGS = -d # Library and Framework projects only: # 1. If you want something other than the default .dylib name, override it here #DYLIB_INSTALL_NAME = lib$(NAME).dylib # 2. If you want to change the -install_name flag from the absolute path to the development area, change it here. One good choice is the installation directory. Another one might be none at all. #DYLIB_INSTALL_DIR = $(INSTALLDIR) # Ownership and permissions of files installed by 'install' target #INSTALL_AS_USER = root # User/group ownership #INSTALL_AS_GROUP = wheel # (probably want to set both of these) #INSTALL_PERMISSIONS = # If set, 'install' chmod's executable to this # Options to strip for various project types. Note: -S strips debugging symbols # (executables can be stripped down further with -x or, if they load no bundles, with no # options at all). #APP_STRIP_OPTS = -S #TOOL_STRIP_OPTS = -S #LIBRARY_STRIP_OPTS = -S # for .a archives #DYNAMIC_STRIP_OPTS = -S # for bundles and shared libraries ######################################################################### # Put rules to extend the behavior of the standard Makefiles here. "Official" # user-defined rules are: # * before_install # * after_install # * after_installhdrs # You should avoid redefining things like "install" or "app", as they are # owned by the top-level Makefile API and no context has been set up for where # derived files should go. # # Note: on MS Windows, executables, have an extension, so rules and dependencies # for generated tools should use $(EXECUTABLE_EXT) on the end. diskdev_cmds-332.25/disklib/Makefile.preamble0000644000000000000000000001205410216156236017741 0ustar rootwheel############################################################################### # NeXT Makefile.preamble # Copyright 1996, NeXT Software, Inc. # # This Makefile is used for configuring the standard app makefiles associated # with ProjectBuilder. # # Use this template to set attributes for a project. Each node in a project # tree of sub-projects, tools, etc. should have its own Makefile.preamble and # Makefile.postamble. # ############################################################################### ## Configure the flags passed to $(CC) here. These flags will also be ## inherited by all nested sub-projects and bundles. Put your -I, -D, -U, and ## -L flags in ProjectBuilder's Build Options inspector if at all possible. ## To change the default flags that get passed to ${CC} ## (e.g. change -O to -O2), see Makefile.postamble. # Flags passed to compiler (in addition to -g, -O, etc) OTHER_CFLAGS = # Flags passed to ld (in addition to -ObjC, etc.) OTHER_LDFLAGS = # Flags passed to libtool when building libraries OTHER_LIBTOOL_FLAGS = # For ordering named sections on NEXTSTEP (see ld(1)) SECTORDER_FLAGS = # If you do not want any headers exported before compilations begin, # uncomment the following line. This can be a big time saver. #SKIP_EXPORTING_HEADERS = YES # Stuff related to exporting headers from this project that isn't already # handled by PB. OTHER_PUBLIC_HEADERS = OTHER_PROJECT_HEADERS = OTHER_PRIVATE_HEADERS = # Set these two macros if you want a precomp to be built as part of # installation. The cc -precomp will be run in the public header directory # on the specified public header files with the specified additional flags. PUBLIC_PRECOMPILED_HEADERS = PUBLIC_PRECOMPILED_HEADERS_CFLAGS = # Set this for library projects if you want to publish header files. If your # app or tool project exports headers Don't # include $(DSTROOT); this is added for you automatically. PUBLIC_HEADER_DIR = PRIVATE_HEADER_DIR = # If, in a subproject, you want to append to the parent's PUBLIC_HEADER_DIR# # (say, to add a subdirectory like "/sys"), you can use: PUBLIC_HEADER_DIR_SUFFIX = PRIVATE_HEADER_DIR_SUFFIX = # Set this for dynamic library projects on platforms where code which references # a dynamic library must link against an import library (i.e., Windows NT) # Don't include $(DSTROOT); this is added for you automatically. IMPORT_LIBRARY_DIR = # Additional (non-localized) resources for this project, which can be generated OTHER_RESOURCES = # Uncomment this to produce a static archive-style (.a) library LIBRARY_STYLE = STATIC # Set this to YES if you don't want a final libtool call for a library/framework. BUILD_OFILES_LIST_ONLY = # Additional relocatables to be linked into this project OTHER_OFILES = # Additional libraries to link against OTHER_LIBS = # To include a version string, project source must exist in a directory named # $(NAME).%d[.%d][.%d] and the following line must be uncommented. # OTHER_GENERATED_OFILES = $(VERS_OFILE) ## Configure how things get built here. Additional dependencies, source files, ## derived files, and build order should be specified here. # Other dependencies of this project OTHER_PRODUCT_DEPENDS = # Built *before* building subprojects/bundles OTHER_INITIAL_TARGETS = # Other source files maintained by .pre/postamble OTHER_SOURCEFILES = # Additional files to be removed by `make clean' OTHER_GARBAGE = # Targets to build before installation OTHER_INSTALL_DEPENDS = # More obscure flags you might want to set for pswrap, yacc, lex, etc. PSWFLAGS = YFLAGS = LFLAGS = ## Delete this line if you want fast and loose cleans that will not remove ## things like precomps and user-defined OTHER_GARBAGE in subprojects. CLEAN_ALL_SUBPROJECTS = YES ## Add more obscure source files here to cause them to be automatically ## processed by the appropriate tool. Note that these files should also be ## added to "Supporting Files" in ProjectBuilder. The desired .o files that ## result from these files should also be added to OTHER_OFILES above so they ## will be linked in. # .msg files that should have msgwrap run on them MSGFILES = # .defs files that should have mig run on them DEFSFILES = # .mig files (no .defs files) that should have mig run on them MIGFILES = # .x files that should have rpcgen run on them RPCFILES = ## Add additional Help directories here (add them to the project as "Other ## Resources" in Project Builder) so that they will be compressed into .store ## files and copied into the app wrapper. If the help directories themselves ## need to also be in the app wrapper, then a cp command will need to be added ## in an after_install target. OTHER_HELP_DIRS = # After you have saved your project using the 4.0 PB, you will automatically # start using the makefiles in $(SYSTEM_DEVELOPER_DIR)/Makefiles/project. If you should # need to revert back to the old 3.3 Makefile behavior, override MAKEFILEDIR to # be $(SYSTEM_DEVELOPER_DIR)/Makefiles/app. # Don't add more rules here unless you want the first one to be the default # target for make! Put all your targets in Makefile.postamble. diskdev_cmds-332.25/disklib/mntopts.h0000644000000000000000000001270210113217067016364 0ustar rootwheel/* * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights * Reserved. This file contains Original Code and/or Modifications of * Original Code as defined in and that are subject to the Apple Public * Source License Version 1.0 (the 'License'). You may not use this file * except in compliance with the License. Please obtain a copy of the * License at http://www.apple.com/publicsource and read it before using * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License." * * @APPLE_LICENSE_HEADER_END@ */ /*- * Copyright (c) 1994 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)mntopts.h 8.7 (Berkeley) 3/29/95 */ #ifdef linux #define MNT_RDONLY 0x00000001 /* read only filesystem */ #define MNT_SYNCHRONOUS 0x00000002 /* file system written synchronously */ #define MNT_NOEXEC 0x00000004 /* can't exec from filesystem */ #define MNT_NOSUID 0x00000008 /* don't honor setuid bits on fs */ #define MNT_NODEV 0x00000010 /* don't interpret special files */ #define MNT_UNION 0x00000020 /* union with underlying filesystem */ #define MNT_ASYNC 0x00000040 /* file system written asynchronously */ #define FS_OPTTIME 0 /* minimize allocation time */ #define MINFREE 5 #define DEFAULTOPT FS_OPTTIME #define BBSIZE 8192 #define SBSIZE 8192 #define MINBSIZE 4096 #define FS_OPTSPACE 1 /* minimize disk fragmentation */ #endif struct mntopt { const char *m_option; /* option name */ int m_inverse; /* if a negative option, eg "dev" */ int m_flag; /* bit to set, eg. MNT_RDONLY */ int m_altloc; /* 1 => set bit in altflags */ }; /* User-visible MNT_ flags. */ #define MOPT_ASYNC { "async", 0, MNT_ASYNC, 0 } #define MOPT_NODEV { "dev", 1, MNT_NODEV, 0 } #define MOPT_NOEXEC { "exec", 1, MNT_NOEXEC, 0 } #define MOPT_NOSUID { "suid", 1, MNT_NOSUID, 0 } #define MOPT_RDONLY { "rdonly", 0, MNT_RDONLY, 0 } #define MOPT_SYNC { "sync", 0, MNT_SYNCHRONOUS, 0 } #define MOPT_UNION { "union", 0, MNT_UNION, 0 } #define MOPT_USERQUOTA { "userquota", 0, 0, 0 } #define MOPT_GROUPQUOTA { "groupquota", 0, 0, 0 } #define MOPT_BROWSE { "browse", 1, MNT_DONTBROWSE, 0 } #define MOPT_AUTOMOUNTED { "automounted",0, MNT_AUTOMOUNTED, 0 } #define MOPT_DEFWRITE { "defwrite", 0, MNT_DEFWRITE, 0} /* Control flags. */ #define MOPT_FORCE { "force", 0, MNT_FORCE, 0 } #define MOPT_UPDATE { "update", 0, MNT_UPDATE, 0 } #define MOPT_RO { "ro", 0, MNT_RDONLY, 0 } #define MOPT_RW { "rw", 1, MNT_RDONLY, 0 } /* This is parsed by mount(8), but is ignored by specific mount_*(8)s. */ #define MOPT_AUTO { "auto", 0, 0, 0 } #define MOPT_FSTAB_COMPAT \ MOPT_RO, \ MOPT_RW, \ MOPT_AUTO /* Standard options which all mounts can understand. */ #define MOPT_STDOPTS \ MOPT_USERQUOTA, \ MOPT_GROUPQUOTA, \ MOPT_FSTAB_COMPAT, \ MOPT_NODEV, \ MOPT_NOEXEC, \ MOPT_NOSUID, \ MOPT_RDONLY, \ MOPT_UNION, \ MOPT_BROWSE, \ MOPT_AUTOMOUNTED, \ MOPT_DEFWRITE void getmntopts __P((const char *, const struct mntopt *, int *, int *)); void checkpath __P((const char *, char resolved_path[])); void rmslashes __P((char *, char *)); extern int getmnt_silent; diskdev_cmds-332.25/disklib/pathnames.h0000644000000000000000000000604110216156236016643 0ustar rootwheel/* * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights * Reserved. This file contains Original Code and/or Modifications of * Original Code as defined in and that are subject to the Apple Public * Source License Version 1.0 (the 'License'). You may not use this file * except in compliance with the License. Please obtain a copy of the * License at http://www.apple.com/publicsource and read it before using * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License." * * @APPLE_LICENSE_HEADER_END@ */ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)pathnames.h 8.1 (Berkeley) 6/5/93 */ #include #define _PATH_DEFTAPE "/dev/rmt8" #define _PATH_DTMP "/etc/dtmp" #define _PATH_DUMPDATES "/etc/dumpdates" #define _PATH_LOCK "/tmp/dumplockXXXXXX" #define _PATH_RMT "rmt" diskdev_cmds-332.25/disklib/PB.project0000644000000000000000000000343507200110032016366 0ustar rootwheel{ CURRENTLY_ACTIVE_VERSION = YES; DEPLOY_WITH_VERSION_NAME = A; DYNAMIC_CODE_GEN = YES; FILESTABLE = { CLASSES = (); FRAMEWORKS = (); H_FILES = ( dump.h, fsck.h, mntopts.h, pathnames.h, ufslabel.h, dkopen.h ); OTHER_LINKED = ( dkcksum.c, dksecsize.c, dumprmt.c, getmntopts.c, preen.c, vfslist.c, dkdisklabel.c, ufslabel.c, dkopen.c ); OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble); PRECOMPILED_HEADERS = (); PROJECT_HEADERS = (mntopts.h, fsck.h, pathnames.h, dump.h); PUBLIC_HEADERS = (); SUBPROJECTS = (); }; LANGUAGE = English; LOCALIZABLE_FILES = {}; MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; NEXTSTEP_BUILDDIR = /tmp/BUILD; NEXTSTEP_BUILDTOOL = /bin/gnumake; NEXTSTEP_INSTALLDIR = /usr/local/lib; NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; PDO_UNIX_INSTALLDIR = /usr/local/lib; PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; PDO_UNIX_PUBLICHEADERSDIR = "LOCAL_DEVELOPER_DIR/Headers/$(NAME)"; PROJECTNAME = disk; PROJECTTYPE = Library; PROJECTVERSION = 2.8; WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; WINDOWS_INSTALLDIR = LOCAL_DEVELOPER_DIR/Libraries; WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; WINDOWS_PUBLICHEADERSDIR = "LOCAL_DEVELOPER_DIR/Headers/$(NAME)"; } diskdev_cmds-332.25/disklib/preen.c0000644000000000000000000002415610216156236015776 0ustar rootwheel/* * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights * Reserved. This file contains Original Code and/or Modifications of * Original Code as defined in and that are subject to the Apple Public * Source License Version 1.0 (the 'License'). You may not use this file * except in compliance with the License. Please obtain a copy of the * License at http://www.apple.com/publicsource and read it before using * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License." * * @APPLE_LICENSE_HEADER_END@ */ /* * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #include #include #include #include #include #include #include "fsck.h" struct part { struct part *next; /* forward link of partitions on disk */ char *name; /* device name */ char *fsname; /* mounted filesystem name */ long auxdata; /* auxillary data for application */ } *badlist, **badnext = &badlist; struct disk { char *name; /* disk base name */ struct disk *next; /* forward link for list of disks */ struct part *part; /* head of list of partitions on disk */ int pid; /* If != 0, pid of proc working on */ } *disks; int nrun, ndisks; char hotroot; static void addpart __P((char *name, char *fsname, long auxdata)); static struct disk *finddisk __P((char *name)); static char *rawname __P((char *name)); static int startdisk __P((struct disk *dk, int (*checkit)(char *, char *, long, int))); static char *unrawname __P((char *name)); int checkfstab(preen, maxrun, docheck, chkit) int preen; int maxrun; int (*docheck)(struct fstab *); int (*chkit)(char *, char *, long, int); { register struct fstab *fsp; register struct disk *dk, *nextdisk; register struct part *pt; int ret, pid, retcode, passno, sumstatus, status; long auxdata; char *name; sumstatus = 0; for (passno = 1; passno <= 2; passno++) { if (setfsent() == 0) { fprintf(stderr, "Can't open checklist file: %s\n", _PATH_FSTAB); return (8); } while ((fsp = getfsent()) != 0) { if ((auxdata = (*docheck)(fsp)) == 0) continue; if (preen == 0 || (passno == 1 && fsp->fs_passno == 1)) { if ((name = blockcheck(fsp->fs_spec)) != 0) { if ((sumstatus = (*chkit)(name, fsp->fs_file, auxdata, 0)) != 0) return (sumstatus); } else if (preen) return (8); } else if (passno == 2 && fsp->fs_passno > 1) { if ((name = blockcheck(fsp->fs_spec)) == NULL) { fprintf(stderr, "BAD DISK NAME %s\n", fsp->fs_spec); sumstatus |= 8; continue; } addpart(name, fsp->fs_file, auxdata); } } if (preen == 0) return (0); } if (preen) { if (maxrun == 0) maxrun = ndisks; if (maxrun > ndisks) maxrun = ndisks; nextdisk = disks; for (passno = 0; passno < maxrun; ++passno) { while ((ret = startdisk(nextdisk, chkit)) && nrun > 0) sleep(10); if (ret) return (ret); nextdisk = nextdisk->next; } while ((pid = wait(&status)) != -1) { for (dk = disks; dk; dk = dk->next) if (dk->pid == pid) break; if (dk == 0) { printf("Unknown pid %d\n", pid); continue; } if (WIFEXITED(status)) retcode = WEXITSTATUS(status); else retcode = 0; if (WIFSIGNALED(status)) { printf("%s (%s): EXITED WITH SIGNAL %d\n", dk->part->name, dk->part->fsname, WTERMSIG(status)); retcode = 8; } if (retcode != 0) { sumstatus |= retcode; *badnext = dk->part; badnext = &dk->part->next; dk->part = dk->part->next; *badnext = NULL; } else dk->part = dk->part->next; dk->pid = 0; nrun--; if (dk->part == NULL) ndisks--; if (nextdisk == NULL) { if (dk->part) { while ((ret = startdisk(dk, chkit)) && nrun > 0) sleep(10); if (ret) return (ret); } } else if (nrun < maxrun && nrun < ndisks) { for ( ;; ) { if ((nextdisk = nextdisk->next) == NULL) nextdisk = disks; if (nextdisk->part != NULL && nextdisk->pid == 0) break; } while ((ret = startdisk(nextdisk, chkit)) && nrun > 0) sleep(10); if (ret) return (ret); } } } if (sumstatus) { if (badlist == 0) return (sumstatus); fprintf(stderr, "THE FOLLOWING FILE SYSTEM%s HAD AN %s\n\t", badlist->next ? "S" : "", "UNEXPECTED INCONSISTENCY:"); for (pt = badlist; pt; pt = pt->next) fprintf(stderr, "%s (%s)%s", pt->name, pt->fsname, pt->next ? ", " : "\n"); return (sumstatus); } (void)endfsent(); return (0); } static struct disk * finddisk(name) char *name; { register struct disk *dk, **dkp; register char *p; size_t len; for (len = strlen(name), p = name + len - 1; p >= name; --p) if (isdigit(*p)) { len = p - name + 1; break; } for (dk = disks, dkp = &disks; dk; dkp = &dk->next, dk = dk->next) { if (strncmp(dk->name, name, len) == 0 && dk->name[len] == 0) return (dk); } if ((*dkp = (struct disk *)malloc(sizeof(struct disk))) == NULL) { fprintf(stderr, "out of memory"); exit (8); } dk = *dkp; if ((dk->name = malloc(len + 1)) == NULL) { fprintf(stderr, "out of memory"); exit (8); } (void)strncpy(dk->name, name, len); dk->name[len] = '\0'; dk->part = NULL; dk->next = NULL; dk->pid = 0; ndisks++; return (dk); } static void addpart(name, fsname, auxdata) char *name, *fsname; long auxdata; { struct disk *dk = finddisk(name); register struct part *pt, **ppt = &dk->part; for (pt = dk->part; pt; ppt = &pt->next, pt = pt->next) if (strcmp(pt->name, name) == 0) { printf("%s in fstab more than once!\n", name); return; } if ((*ppt = (struct part *)malloc(sizeof(struct part))) == NULL) { fprintf(stderr, "out of memory"); exit (8); } pt = *ppt; if ((pt->name = malloc(strlen(name) + 1)) == NULL) { fprintf(stderr, "out of memory"); exit (8); } (void)strcpy(pt->name, name); if ((pt->fsname = malloc(strlen(fsname) + 1)) == NULL) { fprintf(stderr, "out of memory"); exit (8); } (void)strcpy(pt->fsname, fsname); pt->next = NULL; pt->auxdata = auxdata; } static int startdisk(dk, checkit) register struct disk *dk; int (*checkit)(char *, char *, long, int); { register struct part *pt = dk->part; dk->pid = fork(); if (dk->pid < 0) { perror("fork"); return (8); } if (dk->pid == 0) exit((*checkit)(pt->name, pt->fsname, pt->auxdata, 1)); nrun++; return (0); } char * blockcheck(origname) char *origname; { struct stat stslash, stblock, stchar; char *newname, *raw; int retried = 0; hotroot = 0; if (stat("/", &stslash) < 0) { perror("/"); printf("Can't stat root\n"); return (origname); } newname = origname; retry: if (stat(newname, &stblock) < 0) { perror(newname); printf("Can't stat %s\n", newname); return (origname); } if ((stblock.st_mode & S_IFMT) == S_IFBLK) { if (stslash.st_dev == stblock.st_rdev) hotroot++; raw = rawname(newname); if (stat(raw, &stchar) < 0) { perror(raw); printf("Can't stat %s\n", raw); return (origname); } if ((stchar.st_mode & S_IFMT) == S_IFCHR) { return (raw); } else { printf("%s is not a character device\n", raw); return (origname); } } else if ((stblock.st_mode & S_IFMT) == S_IFCHR && !retried) { newname = unrawname(newname); retried++; goto retry; } /* * Not a block or character device, just return name and * let the user decide whether to use it. */ return (origname); } static char * unrawname(name) char *name; { char *dp; struct stat stb; if ((dp = strrchr(name, '/')) == 0) return (name); if (stat(name, &stb) < 0) return (name); if ((stb.st_mode & S_IFMT) != S_IFCHR) return (name); if (dp[1] != 'r') return (name); (void)strcpy(&dp[1], &dp[2]); return (name); } static char * rawname(name) char *name; { static char rawbuf[32]; char *dp; if ((dp = strrchr(name, '/')) == 0) return (0); *dp = 0; (void)strcpy(rawbuf, name); *dp = '/'; (void)strcat(rawbuf, "/r"); (void)strcat(rawbuf, &dp[1]); return (rawbuf); } diskdev_cmds-332.25/disklib/ufslabel.c0000644000000000000000000004400610267354542016464 0ustar rootwheel /* * Copyright 1999 Apple Computer, Inc. * * ufslabel.c * - library routines to read/write the UFS disk label */ /* * Modification History: * * Dieter Siegmund (dieter@apple.com) Fri Nov 5 12:48:55 PST 1999 * - created */ #include "dkopen.h" #include #include #ifndef linux #include #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "ufslabel.h" char ufs_label_magic[4] = UFS_LABEL_MAGIC; typedef union { char c[2]; u_short s; } short_union_t; typedef union { u_short s[2]; long l; } long_union_t; typedef struct { unsigned long state[5]; unsigned long count[2]; unsigned char buffer[64]; } SHA1_CTX; #define VOLUMEUUIDVALUESIZE 2 typedef union VolumeUUID { unsigned long value[VOLUMEUUIDVALUESIZE]; struct { unsigned long high; unsigned long low; } v; } VolumeUUID; #define VOLUMEUUIDLENGTH 16 typedef char VolumeUUIDString[VOLUMEUUIDLENGTH+1]; /* * Local Functions: */ static __inline__ void reduce(int * sum) { long_union_t l_util; l_util.l = *sum; *sum = l_util.s[0] + l_util.s[1]; if (*sum > 65535) *sum -= 65535; return; } static unsigned short in_cksum(void * data, int len) { u_short * w; int sum = 0; w = (u_short *)data; while ((len -= 32) >= 0) { sum += w[0]; sum += w[1]; sum += w[2]; sum += w[3]; sum += w[4]; sum += w[5]; sum += w[6]; sum += w[7]; sum += w[8]; sum += w[9]; sum += w[10]; sum += w[11]; sum += w[12]; sum += w[13]; sum += w[14]; sum += w[15]; w += 16; } len += 32; while ((len -= 8) >= 0) { sum += w[0]; sum += w[1]; sum += w[2]; sum += w[3]; w += 4; } len += 8; if (len) { reduce(&sum); while ((len -= 2) >= 0) { sum += *w++; } } if (len == -1) { /* odd-length data */ short_union_t s_util; s_util.s = 0; s_util.c[0] = *((char *)w); s_util.c[1] = 0; sum += s_util.s; } reduce(&sum); return (~sum & 0xffff); } static boolean_t ufslabel_check(struct ufslabel * ul_p) { if (bcmp(&ul_p->ul_magic, ufs_label_magic, sizeof(ul_p->ul_magic))) { #ifdef DEBUG fprintf(stderr, "check_label: label has bad magic number\n"); #endif DEBUG return (FALSE); } if (ntohl(ul_p->ul_version) != UFS_LABEL_VERSION) { #ifdef DEBUG fprintf(stderr, "check_label: label has incorect version %d (should be %d)\n", ntohl(ul_p->ul_version), UFS_LABEL_VERSION); #endif DEBUG return (FALSE); } if (ntohs(ul_p->ul_namelen) > UFS_MAX_LABEL_NAME) { #ifdef DEBUG fprintf(stderr, "check_label: name length %d is too big (> %d)\n", ntohs(ul_p->ul_namelen), UFS_MAX_LABEL_NAME); #endif DEBUG return (FALSE); } { u_int16_t calc; u_int16_t checksum = ul_p->ul_checksum; ul_p->ul_checksum = 0; calc = in_cksum(ul_p, sizeof(*ul_p)); if (calc != checksum) { #ifdef DEBUG fprintf(stderr, "check_label: label checksum %x (should be %x)\n", checksum, calc); #endif DEBUG return (FALSE); } } return (TRUE); } static void * ufslabel_read_blocks(int fd, off_t * offset_p, ssize_t * size_p, struct ufslabel * * label_p) { int blocksize; off_t offset; ssize_t size; void * ptr = NULL; struct ufslabel * ul_p; *label_p = NULL; #ifndef linux if (ioctl(fd, DKIOCGETBLOCKSIZE, &blocksize) < 0) { fprintf(stderr, "DKIOCGETBLOCKSIZE failed, %s\n", strerror(errno)); return (NULL); } #else blocksize = DEV_BSIZE; #endif offset = UFS_LABEL_OFFSET / blocksize * blocksize; size = (UFS_LABEL_SIZE + blocksize - 1) / blocksize * blocksize; if (dklseek(fd, offset, SEEK_SET) != offset) { fprintf(stderr, "ufslabel_read_blocks: lseek failed, %s\n", strerror(errno)); return (NULL); } ptr = malloc(size); if (ptr == NULL) { fprintf(stderr, "ufslabel_read_blocks: malloc() failed\n"); return (NULL); } ul_p = (struct ufslabel *)(ptr + (UFS_LABEL_OFFSET - offset)); if (read(fd, ptr, size) != size) { fprintf(stderr, "ufslabel_read_blocks: read failed, %s\n", strerror(errno)); goto fail; } if (label_p) *label_p = ul_p; if (offset_p) *offset_p = offset; if (size_p) *size_p = size; return (ptr); fail: if (ptr) free(ptr); return (NULL); } static boolean_t ufslabel_read(int fd, struct ufslabel * label_p) { struct ufslabel * ul_p; void * ptr; boolean_t ret = TRUE; ptr = ufslabel_read_blocks(fd, NULL, NULL, &ul_p); if (ptr == NULL) return (FALSE); if (ufslabel_check(ul_p) == FALSE) { ret = FALSE; goto fail; } *label_p = *ul_p; fail: free(ptr); return (ret); } static boolean_t ufslabel_write(int fd, struct ufslabel * label_p) { off_t offset; ssize_t size; void * ptr = NULL; struct ufslabel * ul_p; /* get blocks that will contain the new label */ ptr = ufslabel_read_blocks(fd, &offset, &size, &ul_p); if (ptr == NULL) return (FALSE); /* copy the label into the raw blocks */ *ul_p = *label_p; /* make sure the checksum is updated */ ul_p->ul_checksum = 0; ul_p->ul_checksum = in_cksum(ul_p, sizeof(*ul_p)); /* write the new label */ if (dklseek(fd, offset, SEEK_SET) != offset) { fprintf(stderr, "ufslabel_write: lseek failed, %s\n", strerror(errno)); goto fail; } if (write(fd, ptr, size) != (ssize_t)size) { fprintf(stderr, "ufslabel_write: write failed, %s\n", strerror(errno)); goto fail; } if (ptr) free(ptr); return (TRUE); fail: if (ptr) free(ptr); return (FALSE); } /****************************************************************************** * * S H A - 1 I M P L E M E N T A T I O N R O U T I N E S * *****************************************************************************/ /* Derived from SHA-1 in C By Steve Reid 100% Public Domain Test Vectors (from FIPS PUB 180-1) "abc" A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1 A million repetitions of "a" 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F */ /* #define LITTLE_ENDIAN * This should be #define'd if true. */ /* #define SHA1HANDSOFF * Copies data before messing with it. */ #define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits)))) /* blk0() and blk() perform the initial expand. */ /* I got the idea of expanding during the round function from SSLeay */ #ifdef LITTLE_ENDIAN #define blk0(i) (block->l[i] = (rol(block->l[i],24)&0xFF00FF00) \ |(rol(block->l[i],8)&0x00FF00FF)) #else #define blk0(i) block->l[i] #endif #define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \ ^block->l[(i+2)&15]^block->l[i&15],1)) /* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */ #if TRACE_HASH #define R0(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30);printf("t = %2d: %08lX %08lX %08lX %08lX %08lX\n", i, a, b, c, d, e); #define R1(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30);printf("t = %2d: %08lX %08lX %08lX %08lX %08lX\n", i, a, b, c, d, e); #define R2(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30);printf("t = %2d: %08lX %08lX %08lX %08lX %08lX\n", i, a, b, c, d, e); #define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30);printf("t = %2d: %08lX %08lX %08lX %08lX %08lX\n", i, a, b, c, d, e); #define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30);printf("t = %2d: %08lX %08lX %08lX %08lX %08lX\n", i, a, b, c, d, e); #else #define R0(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30); #define R1(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30); #define R2(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30); #define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30); #define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30); #endif /* Hash a single 512-bit block. This is the core of the algorithm. */ static void SHA1Transform(unsigned long state[5], unsigned char buffer[64]) { unsigned long a, b, c, d, e; typedef union { unsigned char c[64]; unsigned long l[16]; } CHAR64LONG16; CHAR64LONG16* block; #ifdef SHA1HANDSOFF static unsigned char workspace[64]; block = (CHAR64LONG16*)workspace; memcpy(block, buffer, 64); #else block = (CHAR64LONG16*)buffer; #endif /* Copy context->state[] to working vars */ a = state[0]; b = state[1]; c = state[2]; d = state[3]; e = state[4]; #if TRACE_HASH printf(" A B C D E\n"); printf(" -------- -------- -------- -------- --------\n"); printf(" %08lX %08lX %08lX %08lX %08lX\n", a, b, c, d, e); #endif /* 4 rounds of 20 operations each. Loop unrolled. */ R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3); R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7); R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11); R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15); R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19); R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23); R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27); R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31); R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35); R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39); R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43); R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47); R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51); R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55); R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59); R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63); R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67); R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71); R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75); R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79); /* Add the working vars back into context.state[] */ state[0] += a; state[1] += b; state[2] += c; state[3] += d; state[4] += e; /* Wipe variables */ a = b = c = d = e = 0; } /* SHA1Init - Initialize new context */ static void SHA1Init(SHA1_CTX* context) { /* SHA1 initialization constants */ context->state[0] = 0x67452301; context->state[1] = 0xEFCDAB89; context->state[2] = 0x98BADCFE; context->state[3] = 0x10325476; context->state[4] = 0xC3D2E1F0; context->count[0] = context->count[1] = 0; } /* Run your data through this. */ static void SHA1Update(SHA1_CTX* context, void* data, size_t len) { unsigned char *dataptr = data; unsigned int i, j; j = (context->count[0] >> 3) & 63; if ((context->count[0] += len << 3) < (len << 3)) context->count[1]++; context->count[1] += (len >> 29); if ((j + len) > 63) { memcpy(&context->buffer[j], dataptr, (i = 64-j)); SHA1Transform(context->state, context->buffer); for ( ; i + 63 < len; i += 64) { SHA1Transform(context->state, &dataptr[i]); } j = 0; } else i = 0; memcpy(&context->buffer[j], &dataptr[i], len - i); } /* Add padding and return the message digest. */ static void SHA1Final(unsigned char digest[20], SHA1_CTX* context) { unsigned long i, j; unsigned char finalcount[8]; for (i = 0; i < 8; i++) { finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)] >> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */ } SHA1Update(context, (unsigned char *)"\200", 1); while ((context->count[0] & 504) != 448) { SHA1Update(context, (unsigned char *)"\0", 1); } SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() */ for (i = 0; i < 20; i++) { digest[i] = (unsigned char) ((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255); } /* Wipe variables */ i = j = 0; memset(context->buffer, 0, 64); memset(context->state, 0, 20); memset(context->count, 0, 8); memset(&finalcount, 0, 8); #ifdef SHA1HANDSOFF /* make SHA1Transform overwrite it's own static vars */ SHA1Transform(context->state, context->buffer); #endif } static void FormatULong(unsigned long u, char *s) { unsigned long d; int i; char *digitptr = s; for (i = 0; i < 8; ++i) { d = ((u & 0xF0000000) >> 28) & 0x0000000F; if (d < 10) { *digitptr++ = (char)(d + '0'); } else { *digitptr++ = (char)(d - 10 + 'A'); }; u = u << 4; }; } void GenerateVolumeUUID(VolumeUUID *newVolumeID) { SHA1_CTX context; char randomInputBuffer[26]; unsigned char digest[20]; time_t now; clock_t uptime; int mib[2]; int sysdata; char sysctlstring[128]; size_t datalen; double sysloadavg[3]; struct vmtotal sysvmtotal; do { /* Initialize the SHA-1 context for processing: */ SHA1Init(&context); /* Now process successive bits of "random" input to seed the process: */ /* The current system's uptime: */ uptime = clock(); SHA1Update(&context, &uptime, sizeof(uptime)); /* The kernel's boot time: */ mib[0] = CTL_KERN; mib[1] = KERN_BOOTTIME; datalen = sizeof(sysdata); sysctl(mib, 2, &sysdata, &datalen, NULL, 0); SHA1Update(&context, &sysdata, datalen); /* The system's host id: */ mib[0] = CTL_KERN; mib[1] = KERN_HOSTID; datalen = sizeof(sysdata); sysctl(mib, 2, &sysdata, &datalen, NULL, 0); SHA1Update(&context, &sysdata, datalen); /* The system's host name: */ mib[0] = CTL_KERN; mib[1] = KERN_HOSTNAME; datalen = sizeof(sysctlstring); sysctl(mib, 2, sysctlstring, &datalen, NULL, 0); SHA1Update(&context, sysctlstring, datalen); /* The running kernel's OS release string: */ mib[0] = CTL_KERN; mib[1] = KERN_OSRELEASE; datalen = sizeof(sysctlstring); sysctl(mib, 2, sysctlstring, &datalen, NULL, 0); SHA1Update(&context, sysctlstring, datalen); /* The running kernel's version string: */ mib[0] = CTL_KERN; mib[1] = KERN_VERSION; datalen = sizeof(sysctlstring); sysctl(mib, 2, sysctlstring, &datalen, NULL, 0); SHA1Update(&context, sysctlstring, datalen); /* The system's load average: */ datalen = sizeof(sysloadavg); getloadavg(sysloadavg, 3); SHA1Update(&context, &sysloadavg, datalen); /* The system's VM statistics: */ mib[0] = CTL_VM; mib[1] = VM_METER; datalen = sizeof(sysvmtotal); sysctl(mib, 2, &sysvmtotal, &datalen, NULL, 0); SHA1Update(&context, &sysvmtotal, datalen); /* The current GMT (26 ASCII characters): */ time(&now); strncpy(randomInputBuffer, asctime(gmtime(&now)), 26); /* "Mon Mar 27 13:46:26 2000" */ SHA1Update(&context, randomInputBuffer, 26); /* Pad the accumulated input and extract the final digest hash: */ SHA1Final(digest, &context); memcpy(newVolumeID, digest, sizeof(*newVolumeID)); } while ((newVolumeID->v.high == 0) || (newVolumeID->v.low == 0)); } static void FormatUUID(VolumeUUID *volumeID, char *UUIDField) { FormatULong(volumeID->v.high, UUIDField); FormatULong(volumeID->v.low, UUIDField+8); }; void ConvertVolumeUUIDStringToUUID(const char *UUIDString, VolumeUUID *volumeID) { int i; char c; unsigned long nextdigit; unsigned long high = 0; unsigned long low = 0; unsigned long carry; for (i = 0; (i < VOLUMEUUIDLENGTH) && ((c = UUIDString[i]) != (char)0) ; ++i) { if ((c >= '0') && (c <= '9')) { nextdigit = c - '0'; } else if ((c >= 'A') && (c <= 'F')) { nextdigit = c - 'A' + 10; } else if ((c >= 'a') && (c <= 'f')) { nextdigit = c - 'a' + 10; } else { nextdigit = 0; }; carry = ((low & 0xF0000000) >> 28) & 0x0000000F; high = (high << 4) | carry; low = (low << 4) | nextdigit; }; volumeID->v.high = high; volumeID->v.low = low; } void ConvertVolumeUUIDToString(VolumeUUID *volumeID, char *UUIDString) { FormatUUID(volumeID, UUIDString); *(UUIDString+16) = (char)0; /* Append a terminating null character */ } /* * Exported Functions: */ void ufslabel_get_name(struct ufslabel * ul_p, char * name, int * len) { if (ntohs(ul_p->ul_namelen) < *len) *len = ntohs(ul_p->ul_namelen); bcopy(ul_p->ul_name, name, *len); } void ufslabel_get_uuid(struct ufslabel * ul_p, char * uuid) { u_int32_t *volumeUUID; VolumeUUID swappedUUID; volumeUUID = (u_int32_t *) &ul_p->ul_uuid; swappedUUID.v.high = ntohl(volumeUUID[0]); swappedUUID.v.low = ntohl(volumeUUID[1]); ConvertVolumeUUIDToString(&swappedUUID, uuid); } boolean_t ufslabel_set_name(struct ufslabel * ul_p, char * name, int len) { if (len > UFS_MAX_LABEL_NAME) { fprintf(stderr, "ufslabel_set_name: name length %d too long (>%d)\n", len, UFS_MAX_LABEL_NAME); return (FALSE); } ul_p->ul_namelen = htons(len); bcopy(name, ul_p->ul_name, len); return (TRUE); } void ufslabel_set_uuid(struct ufslabel * ul_p) { u_int32_t *volumeUUID; VolumeUUID newUUID; GenerateVolumeUUID(&newUUID); volumeUUID = (u_int32_t *) &ul_p->ul_uuid; volumeUUID[0] = htonl(newUUID.v.high); volumeUUID[1] = htonl(newUUID.v.low); } void ufslabel_init(struct ufslabel * ul_p) { struct timeval tv; bzero(ul_p, sizeof(*ul_p)); ul_p->ul_version = htonl(UFS_LABEL_VERSION); bcopy(ufs_label_magic, &ul_p->ul_magic, sizeof(ul_p->ul_magic)); gettimeofday(&tv, 0); ul_p->ul_time = htonl(tv.tv_sec); } boolean_t ufslabel_get(int fd, struct ufslabel * label) { if (ufslabel_read(fd, label) == FALSE) return (FALSE); return (TRUE); } boolean_t ufslabel_set(int fd, struct ufslabel * label) { if (ufslabel_write(fd, label) == FALSE) return (FALSE); return (TRUE); } diskdev_cmds-332.25/disklib/ufslabel.h0000644000000000000000000000152107425604251016461 0ustar rootwheel /* * Copyright 1999 Apple Computer, Inc. * * ufslabel.h * - library routines to read/write the UFS disk label */ /* * Modification History: * * Dieter Siegmund (dieter@apple.com) Fri Nov 5 12:48:55 PST 1999 * - created */ #ifndef _UFSLABEL #define _UFSLABEL #ifdef linux typedef int boolean_t; #ifndef TRUE #define TRUE 1 #endif #ifndef FALSE #define FALSE 0 #endif #endif #define UFS_MAX_LABEL_UUID 16 boolean_t ufslabel_get(int fd, struct ufslabel * label); boolean_t ufslabel_set(int fd, struct ufslabel * label); boolean_t ufslabel_set_name(struct ufslabel * ul_p, char * name, int len); void ufslabel_set_uuid(struct ufslabel * ul_p); void ufslabel_get_name(struct ufslabel * ul_p, char * name, int * len); void ufslabel_get_uuid(struct ufslabel * ul_p, char * uuid); void ufslabel_init(struct ufslabel * ul_p); #endif diskdev_cmds-332.25/disklib/vfslist.c0000644000000000000000000000743110267354542016362 0ustar rootwheel/* * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights * Reserved. This file contains Original Code and/or Modifications of * Original Code as defined in and that are subject to the Apple Public * Source License Version 1.0 (the 'License'). You may not use this file * except in compliance with the License. Please obtain a copy of the * License at http://www.apple.com/publicsource and read it before using * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License." * * @APPLE_LICENSE_HEADER_END@ */ /*- * Copyright (c) 1995 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #include #include #include int checkvfsname __P((const char *, const char **)); const char **makevfslist __P((char *)); static int skipvfs; int checkvfsname(vfsname, vfslist) const char *vfsname; const char **vfslist; { if (vfslist == NULL) return (0); while (*vfslist != NULL) { if (strcmp(vfsname, *vfslist) == 0) return (skipvfs); ++vfslist; } return (!skipvfs); } const char ** makevfslist(fslist) char *fslist; { const char **av; int i; char *nextcp; if (fslist == NULL) return (NULL); if (fslist[0] == 'n' && fslist[1] == 'o') { fslist += 2; skipvfs = 1; } for (i = 0, nextcp = fslist; *nextcp; nextcp++) if (*nextcp == ',') i++; if ((av = malloc((size_t)(i + 2) * sizeof(char *))) == NULL) { warn(NULL); return (NULL); } nextcp = fslist; i = 0; av[i++] = nextcp; while ((nextcp = strchr(nextcp, ',')) != NULL) { *nextcp++ = '\0'; av[i++] = nextcp; } av[i++] = NULL; return (av); } diskdev_cmds-332.25/dump.tproj/0000755000000000000000000000000010640030222015155 5ustar rootwheeldiskdev_cmds-332.25/dump.tproj/dump.80000644000000000000000000002324507036476013016242 0ustar rootwheel.\" Copyright (c) 1980, 1991, 1993 .\" Regents of the University of California. .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: .\" This product includes software developed by the University of .\" California, Berkeley and its contributors. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)dump.8 8.3 (Berkeley) 5/1/95 .\" .Dd May 1, 1995 .Dt DUMP 8 .Os BSD 4 .Sh NAME .Nm dump .Nd filesystem backup .Sh SYNOPSIS .Nm dump .Op Fl 0123456789cnu .Op Fl B Ar records .Op Fl b Ar blocksize .Op Fl d Ar density .Op Fl f Ar file .Op Fl h Ar level .Op Fl s Ar feet .Op Fl T Ar date .Ar filesystem .Nm dump .Op Fl W Li \&| Fl w .Pp .in -\\n(iSu (The .Bx 4.3 option syntax is implemented for backward compatibility, but is not documented here.) .Sh DESCRIPTION .Nm Dump examines files on a filesystem and determines which files need to be backed up. These files are copied to the given disk, tape or other storage medium for safe keeping (see the .Fl f option below for doing remote backups). A dump that is larger than the output medium is broken into multiple volumes. On most media the size is determined by writing until an end-of-media indication is returned. On media that cannot reliably return an end-of-media indication (such as some cartridge tape drives) each volume is of a fixed size; the actual size is determined by the tape size and density and/or block count options below. By default, the same output file name is used for each volume after prompting the operator to change media. .Pp The following options are supported by .Nm dump : .Bl -tag -width Ds .It Fl 0\-9 Dump levels. A level 0, full backup, guarantees the entire file system is copied (but see also the .Fl h option below). A level number above 0, incremental backup, tells dump to copy all files new or modified since the last dump of the same or lower level. The default level is 9. .It Fl B Ar records The number of dump records per volume. This option overrides the calculation of tape size based on length and density. .It Fl b Ar blocksize The number of kilobytes per dump record. .It Fl c Modify the calculation of the default density and tape size to be more appropriate for cartridge tapes. .It Fl d Ar density Set tape density to .Ar density . The default is 1600BPI. .It Fl f Ar file Write the backup to .Ar file ; .Ar file may be a special device file like .Pa /dev/rmt12 (a tape drive), .Pa /dev/rdisk1s3 (a disk drive), an ordinary file, or .Ql Fl (the standard output). Multiple file names may be given as a single argument separated by commas. Each file will be used for one dump volume in the order listed; if the dump requires more volumes than the number of names given, the last file name will used for all remaining volumes after prompting for media changes. If the name of the file is of the form .Dq host:file , or .Dq user@host:file , .Nm dump writes to the named file on the remote host using .Xr rmt 8 . .It Fl h Ar level Honor the user .Dq nodump flag .Dp Dv UF_NODUMP only for dumps at or above the given .Ar level . The default honor level is 1, so that incremental backups omit such files but full backups retain them. .It Fl n Whenever .Nm dump requires operator attention, notify all operators in the group .Dq operator by means similar to a .Xr wall 1 . .It Fl s Ar feet Attempt to calculate the amount of tape needed at a particular density. If this amount is exceeded, .Nm dump prompts for a new tape. It is recommended to be a bit conservative on this option. The default tape length is 2300 feet. .ne 1i .It Fl T Ar date Use the specified date as the starting time for the dump instead of the time determined from looking in .Pa /etc/dumpdates . The format of date is the same as that of .Xr ctime 3 . This option is useful for automated dump scripts that wish to dump over a specific period of time. The .Fl T option is mutually exclusive from the .Fl u option. .It Fl u Update the file .Pa /etc/dumpdates after a successful dump. The format of .Pa /etc/dumpdates is readable by people, consisting of one free format record per line: filesystem name, increment level and .Xr ctime 3 format dump date. There may be only one entry per filesystem at each level. The file .Pa /etc/dumpdates may be edited to change any of the fields, if necessary. .It Fl W .Nm Dump tells the operator what file systems need to be dumped. This information is gleaned from the files .Pa /etc/dumpdates and .Pa /etc/fstab . The .Fl W option causes .Nm dump to print out, for each file system in .Pa /etc/dumpdates the most recent dump date and level, and highlights those file systems that should be dumped. If the .Fl W option is set, all other options are ignored, and .Nm dump exits immediately. .It Fl w Is like W, but prints only those filesystems which need to be dumped. .El .Pp .Nm Dump requires operator intervention on these conditions: end of tape, end of dump, tape write error, tape open error or disk read error (if there are more than a threshold of 32). In addition to alerting all operators implied by the .Fl n key, .Nm dump interacts with the operator on .Em dump's control terminal at times when .Nm dump can no longer proceed, or if something is grossly wrong. All questions .Nm dump poses .Em must be answered by typing .Dq yes or .Dq no , appropriately. .Pp Since making a dump involves a lot of time and effort for full dumps, .Nm dump checkpoints itself at the start of each tape volume. If writing that volume fails for some reason, .Nm dump will, with operator permission, restart itself from the checkpoint after the old tape has been rewound and removed, and a new tape has been mounted. .Pp .Nm Dump tells the operator what is going on at periodic intervals, including usually low estimates of the number of blocks to write, the number of tapes it will take, the time to completion, and the time to the tape change. The output is verbose, so that others know that the terminal controlling .Nm dump is busy, and will be for some time. .Pp In the event of a catastrophic disk event, the time required to restore all the necessary backup tapes or files to disk can be kept to a minimum by staggering the incremental dumps. An efficient method of staggering incremental dumps to minimize the number of tapes follows: .Bl -bullet -offset indent .It Always start with a level 0 backup, for example: .Bd -literal -offset indent /sbin/dump -0u -f /dev/nrst1 /usr/src .Ed .Pp This should be done at set intervals, say once a month or once every two months, and on a set of fresh tapes that is saved forever. .It After a level 0, dumps of active file systems are taken on a daily basis, using a modified Tower of Hanoi algorithm, with this sequence of dump levels: .Bd -literal -offset indent 3 2 5 4 7 6 9 8 9 9 ... .Ed .Pp For the daily dumps, it should be possible to use a fixed number of tapes for each day, used on a weekly basis. Each week, a level 1 dump is taken, and the daily Hanoi sequence repeats beginning with 3. For weekly dumps, another fixed set of tapes per dumped file system is used, also on a cyclical basis. .El .Pp After several months or so, the daily and weekly tapes should get rotated out of the dump cycle and fresh tapes brought in. .Sh FILES .Bl -tag -width /etc/dumpdates -compact .It Pa /dev/rmt8 default tape unit to dump to .It Pa /etc/dumpdates dump date records .It Pa /etc/fstab dump table: file systems and frequency .It Pa /etc/group to find group .Em operator .El .Sh SEE ALSO .Xr restore 8 , .Xr rmt 8 , .Xr dump 5 , .Xr fstab 5 .Sh DIAGNOSTICS Many, and verbose. .Pp Dump exits with zero status on success. Startup errors are indicated with an exit code of 1; abnormal termination is indicated with an exit code of 3. .Sh BUGS Fewer than 32 read errors on the filesystem are ignored. .Pp Each reel requires a new process, so parent processes for reels already written just hang around until the entire tape is written. .Pp .Nm Dump with the .Fl W or .Fl w options does not report filesystems that have never been recorded in .Pa /etc/dumpdates , even if listed in .Pa /etc/fstab . .Pp It would be nice if .Nm dump knew about the dump sequence, kept track of the tapes scribbled on, told the operator which tape to mount when, and provided more assistance for the operator running .Xr restore . .Sh HISTORY A .Nm dump command appeared in Version 6 AT&T UNIX. diskdev_cmds-332.25/dump.tproj/itime.c0000644000000000000000000001723706712726561016471 0ustar rootwheel/* * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights * Reserved. This file contains Original Code and/or Modifications of * Original Code as defined in and that are subject to the Apple Public * Source License Version 1.0 (the 'License'). You may not use this file * except in compliance with the License. Please obtain a copy of the * License at http://www.apple.com/publicsource and read it before using * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License." * * @APPLE_LICENSE_HEADER_END@ */ /*- * Copyright (c) 1980, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #include #ifdef sunos #include #include #include #include #else #include #endif #include #include #include #include #ifdef __STDC__ #include #include #include #endif #include "dump.h" struct dumpdates **ddatev = 0; int nddates = 0; int ddates_in = 0; struct dumptime *dthead = 0; static void dumprecout __P((FILE *, struct dumpdates *)); static int getrecord __P((FILE *, struct dumpdates *)); static int makedumpdate __P((struct dumpdates *, char *)); static void readdumptimes __P((FILE *)); void initdumptimes() { FILE *df; if ((df = fopen(dumpdates, "r")) == NULL) { if (errno != ENOENT) { quit("cannot read %s: %s\n", dumpdates, strerror(errno)); /* NOTREACHED */ } /* * Dumpdates does not exist, make an empty one. */ msg("WARNING: no file `%s', making an empty one\n", dumpdates); if ((df = fopen(dumpdates, "w")) == NULL) { quit("cannot create %s: %s\n", dumpdates, strerror(errno)); /* NOTREACHED */ } (void) fclose(df); if ((df = fopen(dumpdates, "r")) == NULL) { quit("cannot read %s even after creating it: %s\n", dumpdates, strerror(errno)); /* NOTREACHED */ } } (void) flock(fileno(df), LOCK_SH); readdumptimes(df); (void) fclose(df); } static void readdumptimes(df) FILE *df; { register int i; register struct dumptime *dtwalk; for (;;) { dtwalk = (struct dumptime *)calloc(1, sizeof (struct dumptime)); if (getrecord(df, &(dtwalk->dt_value)) < 0) break; nddates++; dtwalk->dt_next = dthead; dthead = dtwalk; } ddates_in = 1; /* * arrayify the list, leaving enough room for the additional * record that we may have to add to the ddate structure */ ddatev = (struct dumpdates **) calloc((unsigned) (nddates + 1), sizeof (struct dumpdates *)); dtwalk = dthead; for (i = nddates - 1; i >= 0; i--, dtwalk = dtwalk->dt_next) ddatev[i] = &dtwalk->dt_value; } void getdumptime() { register struct dumpdates *ddp; register int i; char *fname; fname = disk; #ifdef FDEBUG msg("Looking for name %s in dumpdates = %s for level = %c\n", fname, dumpdates, level); #endif spcl.c_ddate = 0; lastlevel = '0'; initdumptimes(); /* * Go find the entry with the same name for a lower increment * and older date */ ITITERATE(i, ddp) { if (strncmp(fname, ddp->dd_name, sizeof (ddp->dd_name)) != 0) continue; if (ddp->dd_level >= level) continue; if (ddp->dd_ddate <= spcl.c_ddate) continue; spcl.c_ddate = ddp->dd_ddate; lastlevel = ddp->dd_level; } } void putdumptime() { FILE *df; register struct dumpdates *dtwalk; register int i; int fd; char *fname; if(uflag == 0) return; if ((df = fopen(dumpdates, "r+")) == NULL) quit("cannot rewrite %s: %s\n", dumpdates, strerror(errno)); fd = fileno(df); (void) flock(fd, LOCK_EX); fname = disk; free((char *)ddatev); ddatev = 0; nddates = 0; dthead = 0; ddates_in = 0; readdumptimes(df); if (fseek(df, 0L, 0) < 0) quit("fseek: %s\n", strerror(errno)); spcl.c_ddate = 0; ITITERATE(i, dtwalk) { if (strncmp(fname, dtwalk->dd_name, sizeof (dtwalk->dd_name)) != 0) continue; if (dtwalk->dd_level != level) continue; goto found; } /* * construct the new upper bound; * Enough room has been allocated. */ dtwalk = ddatev[nddates] = (struct dumpdates *)calloc(1, sizeof (struct dumpdates)); nddates += 1; found: (void) strncpy(dtwalk->dd_name, fname, sizeof (dtwalk->dd_name)); dtwalk->dd_level = level; dtwalk->dd_ddate = spcl.c_date; ITITERATE(i, dtwalk) { dumprecout(df, dtwalk); } if (fflush(df)) quit("%s: %s\n", dumpdates, strerror(errno)); if (ftruncate(fd, ftell(df))) quit("ftruncate (%s): %s\n", dumpdates, strerror(errno)); (void) fclose(df); msg("level %c dump on %s", level, spcl.c_date == 0 ? "the epoch\n" : ctime(&spcl.c_date)); } static void dumprecout(file, what) FILE *file; struct dumpdates *what; { if (fprintf(file, DUMPOUTFMT, what->dd_name, what->dd_level, ctime(&what->dd_ddate)) < 0) quit("%s: %s\n", dumpdates, strerror(errno)); } int recno; static int getrecord(df, ddatep) FILE *df; struct dumpdates *ddatep; { char tbuf[BUFSIZ]; recno = 0; if ( (fgets(tbuf, sizeof (tbuf), df)) != tbuf) return(-1); recno++; if (makedumpdate(ddatep, tbuf) < 0) msg("Unknown intermediate format in %s, line %d\n", dumpdates, recno); #ifdef FDEBUG msg("getrecord: %s %c %s", ddatep->dd_name, ddatep->dd_level, ddatep->dd_ddate == 0 ? "the epoch\n" : ctime(&ddatep->dd_ddate)); #endif return(0); } static int makedumpdate(ddp, tbuf) struct dumpdates *ddp; char *tbuf; { char un_buf[128]; (void) sscanf(tbuf, DUMPINFMT, ddp->dd_name, &ddp->dd_level, un_buf); ddp->dd_ddate = unctime(un_buf); if (ddp->dd_ddate < 0) return(-1); return(0); } diskdev_cmds-332.25/dump.tproj/main.c0000644000000000000000000004240406712726561016300 0ustar rootwheel/* * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights * Reserved. This file contains Original Code and/or Modifications of * Original Code as defined in and that are subject to the Apple Public * Source License Version 1.0 (the 'License'). You may not use this file * except in compliance with the License. Please obtain a copy of the * License at http://www.apple.com/publicsource and read it before using * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License." * * @APPLE_LICENSE_HEADER_END@ */ /*- * Copyright (c) 1980, 1991, 1993, 1994 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #include #ifdef sunos #include #include #include #else #include #include #endif #include #include #include #include #include #include #include #include #include #include #include #include "dump.h" #include "pathnames.h" #ifndef SBOFF #define SBOFF (SBLOCK * DEV_BSIZE) #endif /******************************************************/ int mapsize; /* size of the state maps */ char *usedinomap; /* map of allocated inodes */ char *dumpdirmap; /* map of directories to be dumped */ char *dumpinomap; /* map of files to be dumped */ /* * All calculations done in 0.1" units! */ char *disk; /* name of the disk file */ char *tape; /* name of the tape file */ char *dumpdates; /* name of the file containing dump date information*/ char *temp; /* name of the file for doing rewrite of dumpdates */ char lastlevel; /* dump level of previous dump */ char level; /* dump level of this dump */ int uflag; /* update flag */ int diskfd; /* disk file descriptor */ int tapefd; /* tape file descriptor */ int pipeout; /* true => output to standard output */ ino_t curino; /* current inumber; used globally */ int newtape; /* new tape flag */ int density; /* density in 0.1" units */ long tapesize; /* estimated tape size, blocks */ long tsize; /* tape size in 0.1" units */ long asize; /* number of 0.1" units written on current tape */ int etapes; /* estimated number of tapes */ int nonodump; /* if set, do not honor UF_NODUMP user flags */ int notify; /* notify operator flag */ int blockswritten; /* number of blocks written on current tape */ int tapeno; /* current tape number */ time_t tstart_writing; /* when started writing the first tape block */ struct fs *sblock; /* the file system super block */ char sblock_buf[MAXBSIZE]; long dev_bsize; /* block size of underlying disk device */ int dev_bshift; /* log2(dev_bsize) */ int tp_bshift; /* log2(TP_BSIZE) */ /******************************************************/ int notify = 0; /* notify operator flag */ int blockswritten = 0; /* number of blocks written on current tape */ int tapeno = 0; /* current tape number */ int density = 0; /* density in bytes/0.1" */ int ntrec = NTREC; /* # tape blocks in each tape record */ int cartridge = 0; /* Assume non-cartridge tape */ long dev_bsize = 1; /* recalculated below */ long blocksperfile; /* output blocks per file */ char *host = NULL; /* remote host (if any) */ static long numarg __P((char *, long, long)); static void obsolete __P((int *, char **[])); static void usage __P((void)); int main(argc, argv) int argc; char *argv[]; { register ino_t ino; register int dirty; register struct dinode *dp; register struct fstab *dt; register char *map; register int ch; int i, anydirskipped, bflag = 0, Tflag = 0, honorlevel = 1; ino_t maxino; spcl.c_date = 0; (void)time((time_t *)&spcl.c_date); tsize = 0; /* Default later, based on 'c' option for cart tapes */ tape = _PATH_DEFTAPE; dumpdates = _PATH_DUMPDATES; temp = _PATH_DTMP; if (TP_BSIZE / DEV_BSIZE == 0 || TP_BSIZE % DEV_BSIZE != 0) quit("TP_BSIZE must be a multiple of DEV_BSIZE\n"); level = '0'; if (argc < 2) usage(); obsolete(&argc, &argv); while ((ch = getopt(argc, argv, "0123456789B:b:cd:f:h:ns:T:uWw")) != -1) switch (ch) { /* dump level */ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': level = ch; break; case 'B': /* blocks per output file */ blocksperfile = numarg("blocks per file", 1L, 0L); break; case 'b': /* blocks per tape write */ ntrec = numarg("blocks per write", 1L, 1000L); break; case 'c': /* Tape is cart. not 9-track */ cartridge = 1; break; case 'd': /* density, in bits per inch */ density = numarg("density", 10L, 327670L) / 10; if (density >= 625 && !bflag) ntrec = HIGHDENSITYTREC; break; case 'f': /* output file */ tape = optarg; break; case 'h': honorlevel = numarg("honor level", 0L, 10L); break; case 'n': /* notify operators */ notify = 1; break; case 's': /* tape size, feet */ tsize = numarg("tape size", 1L, 0L) * 12 * 10; break; case 'T': /* time of last dump */ spcl.c_ddate = unctime(optarg); if (spcl.c_ddate < 0) { (void)fprintf(stderr, "bad time \"%s\"\n", optarg); exit(X_ABORT); } Tflag = 1; lastlevel = '?'; break; case 'u': /* update /etc/dumpdates */ uflag = 1; break; case 'W': /* what to do */ case 'w': lastdump(ch); exit(0); /* do nothing else */ default: usage(); } argc -= optind; argv += optind; if (argc < 1) { (void)fprintf(stderr, "Must specify disk or filesystem\n"); exit(X_ABORT); } disk = *argv++; argc--; if (argc >= 1) { (void)fprintf(stderr, "Unknown arguments to dump:"); while (argc--) (void)fprintf(stderr, " %s", *argv++); (void)fprintf(stderr, "\n"); exit(X_ABORT); } if (Tflag && uflag) { (void)fprintf(stderr, "You cannot use the T and u flags together.\n"); exit(X_ABORT); } if (strcmp(tape, "-") == 0) { pipeout++; tape = "standard output"; } if (blocksperfile) blocksperfile = blocksperfile / ntrec * ntrec; /* round down */ else { /* * Determine how to default tape size and density * * density tape size * 9-track 1600 bpi (160 bytes/.1") 2300 ft. * 9-track 6250 bpi (625 bytes/.1") 2300 ft. * cartridge 8000 bpi (100 bytes/.1") 1700 ft. * (450*4 - slop) */ if (density == 0) density = cartridge ? 100 : 160; if (tsize == 0) tsize = cartridge ? 1700L*120L : 2300L*120L; } if (strchr(tape, ':')) { host = tape; tape = strchr(host, ':'); *tape++ = '\0'; #ifdef RDUMP if (rmthost(host) == 0) exit(X_ABORT); #else (void)fprintf(stderr, "remote dump not enabled\n"); exit(X_ABORT); #endif } (void)setuid(getuid()); /* rmthost() is the only reason to be setuid */ if (signal(SIGHUP, SIG_IGN) != SIG_IGN) signal(SIGHUP, sig); if (signal(SIGTRAP, SIG_IGN) != SIG_IGN) signal(SIGTRAP, sig); if (signal(SIGFPE, SIG_IGN) != SIG_IGN) signal(SIGFPE, sig); if (signal(SIGBUS, SIG_IGN) != SIG_IGN) signal(SIGBUS, sig); if (signal(SIGSEGV, SIG_IGN) != SIG_IGN) signal(SIGSEGV, sig); if (signal(SIGTERM, SIG_IGN) != SIG_IGN) signal(SIGTERM, sig); if (signal(SIGINT, interrupt) == SIG_IGN) signal(SIGINT, SIG_IGN); set_operators(); /* /etc/group snarfed */ getfstab(); /* /etc/fstab snarfed */ /* * disk can be either the full special file name, * the suffix of the special file name, * the special name missing the leading '/', * the file system name with or without the leading '/'. */ dt = fstabsearch(disk); if (dt != NULL) { disk = rawname(dt->fs_spec); (void)strncpy(spcl.c_dev, dt->fs_spec, NAMELEN); (void)strncpy(spcl.c_filesys, dt->fs_file, NAMELEN); } else { (void)strncpy(spcl.c_dev, disk, NAMELEN); (void)strncpy(spcl.c_filesys, "an unlisted file system", NAMELEN); } (void)strcpy(spcl.c_label, "none"); (void)gethostname(spcl.c_host, NAMELEN); spcl.c_level = level - '0'; spcl.c_type = TS_TAPE; if (!Tflag) getdumptime(); /* /etc/dumpdates snarfed */ msg("Date of this level %c dump: %s", level, spcl.c_date == 0 ? "the epoch\n" : ctime(&spcl.c_date)); msg("Date of last level %c dump: %s", lastlevel, spcl.c_ddate == 0 ? "the epoch\n" : ctime(&spcl.c_ddate)); msg("Dumping %s ", disk); if (dt != NULL) msgtail("(%s) ", dt->fs_file); if (host) msgtail("to %s on host %s\n", tape, host); else msgtail("to %s\n", tape); if ((diskfd = open(disk, O_RDONLY)) < 0) { msg("Cannot open %s\n", disk); exit(X_ABORT); } sync(); sblock = (struct fs *)sblock_buf; bread(SBOFF, (char *) sblock, SBSIZE); if (sblock->fs_magic != FS_MAGIC) quit("bad sblock magic number\n"); dev_bsize = sblock->fs_fsize / fsbtodb(sblock, 1); dev_bshift = ffs(dev_bsize) - 1; if (dev_bsize != (1 << dev_bshift)) quit("dev_bsize (%d) is not a power of 2", dev_bsize); tp_bshift = ffs(TP_BSIZE) - 1; if (TP_BSIZE != (1 << tp_bshift)) quit("TP_BSIZE (%d) is not a power of 2", TP_BSIZE); #ifdef FS_44INODEFMT if (sblock->fs_inodefmt >= FS_44INODEFMT) spcl.c_flags |= DR_NEWINODEFMT; #endif maxino = sblock->fs_ipg * sblock->fs_ncg; mapsize = roundup(howmany(maxino, NBBY), TP_BSIZE); usedinomap = (char *)calloc((unsigned) mapsize, sizeof(char)); dumpdirmap = (char *)calloc((unsigned) mapsize, sizeof(char)); dumpinomap = (char *)calloc((unsigned) mapsize, sizeof(char)); tapesize = 3 * (howmany(mapsize * sizeof(char), TP_BSIZE) + 1); nonodump = spcl.c_level < honorlevel; msg("mapping (Pass I) [regular files]\n"); anydirskipped = mapfiles(maxino, &tapesize); msg("mapping (Pass II) [directories]\n"); while (anydirskipped) { anydirskipped = mapdirs(maxino, &tapesize); } if (pipeout) { tapesize += 10; /* 10 trailer blocks */ msg("estimated %ld tape blocks.\n", tapesize); } else { double fetapes; if (blocksperfile) fetapes = (double) tapesize / blocksperfile; else if (cartridge) { /* Estimate number of tapes, assuming streaming stops at the end of each block written, and not in mid-block. Assume no erroneous blocks; this can be compensated for with an artificially low tape size. */ fetapes = ( tapesize /* blocks */ * TP_BSIZE /* bytes/block */ * (1.0/density) /* 0.1" / byte */ + tapesize /* blocks */ * (1.0/ntrec) /* streaming-stops per block */ * 15.48 /* 0.1" / streaming-stop */ ) * (1.0 / tsize ); /* tape / 0.1" */ } else { /* Estimate number of tapes, for old fashioned 9-track tape */ int tenthsperirg = (density == 625) ? 3 : 7; fetapes = ( tapesize /* blocks */ * TP_BSIZE /* bytes / block */ * (1.0/density) /* 0.1" / byte */ + tapesize /* blocks */ * (1.0/ntrec) /* IRG's / block */ * tenthsperirg /* 0.1" / IRG */ ) * (1.0 / tsize ); /* tape / 0.1" */ } etapes = fetapes; /* truncating assignment */ etapes++; /* count the dumped inodes map on each additional tape */ tapesize += (etapes - 1) * (howmany(mapsize * sizeof(char), TP_BSIZE) + 1); tapesize += etapes + 10; /* headers + 10 trailer blks */ msg("estimated %ld tape blocks on %3.2f tape(s).\n", tapesize, fetapes); } /* * Allocate tape buffer. */ if (!alloctape()) quit("can't allocate tape buffers - try a smaller blocking factor.\n"); startnewtape(1); (void)time((time_t *)&(tstart_writing)); dumpmap(usedinomap, TS_CLRI, maxino - 1); msg("dumping (Pass III) [directories]\n"); dirty = 0; /* XXX just to get gcc to shut up */ for (map = dumpdirmap, ino = 1; ino < maxino; ino++) { if (((ino - 1) % NBBY) == 0) /* map is offset by 1 */ dirty = *map++; else dirty >>= 1; if ((dirty & 1) == 0) continue; /* * Skip directory inodes deleted and maybe reallocated */ dp = getino(ino); if ((dp->di_mode & IFMT) != IFDIR) continue; (void)dumpino(dp, ino); } msg("dumping (Pass IV) [regular files]\n"); for (map = dumpinomap, ino = 1; ino < maxino; ino++) { int mode; if (((ino - 1) % NBBY) == 0) /* map is offset by 1 */ dirty = *map++; else dirty >>= 1; if ((dirty & 1) == 0) continue; /* * Skip inodes deleted and reallocated as directories. */ dp = getino(ino); mode = dp->di_mode & IFMT; if (mode == IFDIR) continue; (void)dumpino(dp, ino); } spcl.c_type = TS_END; for (i = 0; i < ntrec; i++) writeheader(maxino - 1); if (pipeout) msg("DUMP: %ld tape blocks\n",spcl.c_tapea); else msg("DUMP: %ld tape blocks on %d volumes(s)\n", spcl.c_tapea, spcl.c_volume); putdumptime(); trewind(); broadcast("DUMP IS DONE!\7\7\n"); msg("DUMP IS DONE\n"); Exit(X_FINOK); /* NOTREACHED */ } static void usage() { (void)fprintf(stderr, "usage: dump [-0123456789cnu] [-B records] [-b blocksize] [-d density] [-f file]\n [-h level] [-s feet] [-T date] filesystem\n"); (void)fprintf(stderr, " dump [-W | -w]\n"); exit(1); } /* * Pick up a numeric argument. It must be nonnegative and in the given * range (except that a vmax of 0 means unlimited). */ static long numarg(meaning, vmin, vmax) char *meaning; long vmin, vmax; { char *p; long val; val = strtol(optarg, &p, 10); if (*p) errx(1, "illegal %s -- %s", meaning, optarg); if (val < vmin || (vmax && val > vmax)) errx(1, "%s must be between %ld and %ld", meaning, vmin, vmax); return (val); } void sig(signo) int signo; { switch(signo) { case SIGALRM: case SIGBUS: case SIGFPE: case SIGHUP: case SIGTERM: case SIGTRAP: if (pipeout) quit("Signal on pipe: cannot recover\n"); msg("Rewriting attempted as response to unknown signal.\n"); (void)fflush(stderr); (void)fflush(stdout); close_rewind(); exit(X_REWRITE); /* NOTREACHED */ case SIGSEGV: msg("SIGSEGV: ABORTING!\n"); (void)signal(SIGSEGV, SIG_DFL); (void)kill(0, SIGSEGV); /* NOTREACHED */ } } char * rawname(cp) char *cp; { static char rawbuf[MAXPATHLEN]; char *dp = strrchr(cp, '/'); if (dp == NULL) return (NULL); *dp = '\0'; (void)strcpy(rawbuf, cp); *dp = '/'; (void)strcat(rawbuf, "/r"); (void)strcat(rawbuf, dp + 1); return (rawbuf); } /* * obsolete -- * Change set of key letters and ordered arguments into something * getopt(3) will like. */ static void obsolete(argcp, argvp) int *argcp; char **argvp[]; { int argc, flags; char *ap, **argv, *flagsp, **nargv, *p; /* Setup. */ argv = *argvp; argc = *argcp; /* Return if no arguments or first argument has leading dash. */ ap = argv[1]; if (argc == 1 || *ap == '-') return; /* Allocate space for new arguments. */ if ((*argvp = nargv = malloc((argc + 1) * sizeof(char *))) == NULL || (p = flagsp = malloc(strlen(ap) + 2)) == NULL) err(1, NULL); *nargv++ = *argv; argv += 2; for (flags = 0; *ap; ++ap) { switch (*ap) { case 'B': case 'b': case 'd': case 'f': case 'h': case 's': case 'T': if (*argv == NULL) { warnx("option requires an argument -- %c", *ap); usage(); } if ((nargv[0] = malloc(strlen(*argv) + 2 + 1)) == NULL) err(1, NULL); nargv[0][0] = '-'; nargv[0][1] = *ap; (void)strcpy(&nargv[0][2], *argv); ++argv; ++nargv; break; default: if (!flags) { *p++ = '-'; flags = 1; } *p++ = *ap; break; } } /* Terminate flags. */ if (flags) { *p = '\0'; *nargv++ = flagsp; } /* Copy remaining arguments. */ while (*nargv++ = *argv++); /* Update argument count. */ *argcp = nargv - *argvp - 1; } diskdev_cmds-332.25/dump.tproj/Makefile0000644000000000000000000000227106712726561016646 0ustar rootwheel# # Generated by the NeXT Project Builder. # # NOTE: Do NOT change this file -- Project Builder maintains it. # # Put all of your customizations in files called Makefile.preamble # and Makefile.postamble (both optional), and Makefile will include them. # NAME = dump PROJECTVERSION = 2.8 PROJECT_TYPE = Tool CFILES = itime.c main.c optr.c tape.c traverse.c unctime.c OTHERSRCS = Makefile.preamble Makefile Makefile.postamble Makefile.dist\ dump.8 MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles CODE_GEN_STYLE = DYNAMIC MAKEFILE = tool.make NEXTSTEP_INSTALLDIR = /sbin WINDOWS_INSTALLDIR = /sbin PDO_UNIX_INSTALLDIR = /sbin LIBS = -ldisk DEBUG_LIBS = $(LIBS) PROF_LIBS = $(LIBS) NEXTSTEP_PB_CFLAGS = -DRDUMP WINDOWS_PB_CFLAGS = -DRDUMP PDO_UNIX_PB_CFLAGS = -DRDUMP NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc NEXTSTEP_JAVA_COMPILER = /usr/bin/javac WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac include $(MAKEFILEDIR)/platform.make -include Makefile.preamble include $(MAKEFILEDIR)/$(MAKEFILE) -include Makefile.postamble -include Makefile.dependencies diskdev_cmds-332.25/dump.tproj/Makefile.dist0000644000000000000000000000117210216156236017575 0ustar rootwheel# @(#)Makefile 8.1 (Berkeley) 6/5/93 # dump.h header file # itime.c reads /etc/dumpdates # main.c driver # optr.c operator interface # dumprmt.c handles remote tape via rmt(8) # tape.c handles the mag tape and opening/closing # traverse.c traverses the file system # unctime.c undo ctime # # DEBUG use local directory to find ddate and dumpdates # TDEBUG trace out the process forking PROG= dump LINKS= ${BINDIR}/dump ${BINDIR}/rdump CFLAGS+=-DRDUMP SRCS= itime.c main.c optr.c dumprmt.c tape.c traverse.c unctime.c BINOWN= root BINGRP= wheel BINMODE=555 MAN8= dump.0 MLINKS+=dump.8 rdump.8 .include diskdev_cmds-332.25/dump.tproj/Makefile.postamble0000644000000000000000000000055210216156236020621 0ustar rootwheelINSTALL_AS_GROUP = wheel # (probably want to set both of these) INSTALL_PERMISSIONS = 555 # If set, 'install' chmod's executable to this after_install:: $(LN) -f $(INSTALLED_PRODUCTS) $(DSTROOT)$(INSTALLDIR)/rdump install -m 755 -o root -g wheel -d $(DSTROOT)/usr/share/man/man8 install -m 644 -o root -g wheel -c dump.8 $(DSTROOT)/usr/share/man/man8 diskdev_cmds-332.25/dump.tproj/Makefile.preamble0000644000000000000000000000010406712726561020425 0ustar rootwheelOTHER_GENERATED_OFILES = $(VERS_OFILE) -include ../Makefile.include diskdev_cmds-332.25/dump.tproj/optr.c0000644000000000000000000003157106712726561016343 0ustar rootwheel/* * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights * Reserved. This file contains Original Code and/or Modifications of * Original Code as defined in and that are subject to the Apple Public * Source License Version 1.0 (the 'License'). You may not use this file * except in compliance with the License. Please obtain a copy of the * License at http://www.apple.com/publicsource and read it before using * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License." * * @APPLE_LICENSE_HEADER_END@ */ /*- * Copyright (c) 1980, 1988, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #include #include #include #include #include #include #include #ifdef __STDC__ #include #include #include #endif #include #ifdef __STDC__ #include #endif #include #ifndef __STDC__ #include #endif #include "dump.h" #include "pathnames.h" void alarmcatch __P((/* int, int */)); int datesort __P((const void *, const void *)); static void sendmes __P((char *, char *)); /* * Query the operator; This previously-fascist piece of code * no longer requires an exact response. * It is intended to protect dump aborting by inquisitive * people banging on the console terminal to see what is * happening which might cause dump to croak, destroying * a large number of hours of work. * * Every 2 minutes we reprint the message, alerting others * that dump needs attention. */ static int timeout; static char *attnmessage; /* attention message */ int query(question) char *question; { char replybuffer[64]; int back, errcount; FILE *mytty; if ((mytty = fopen(_PATH_TTY, "r")) == NULL) quit("fopen on %s fails: %s\n", _PATH_TTY, strerror(errno)); attnmessage = question; timeout = 0; alarmcatch(); back = -1; errcount = 0; do { if (fgets(replybuffer, 63, mytty) == NULL) { clearerr(mytty); if (++errcount > 30) /* XXX ugly */ quit("excessive operator query failures\n"); } else if (replybuffer[0] == 'y' || replybuffer[0] == 'Y') { back = 1; } else if (replybuffer[0] == 'n' || replybuffer[0] == 'N') { back = 0; } else { (void) fprintf(stderr, " DUMP: \"Yes\" or \"No\"?\n"); (void) fprintf(stderr, " DUMP: %s: (\"yes\" or \"no\") ", question); } } while (back < 0); /* * Turn off the alarm, and reset the signal to trap out.. */ (void) alarm(0); if (signal(SIGALRM, sig) == SIG_IGN) signal(SIGALRM, SIG_IGN); (void) fclose(mytty); return(back); } char lastmsg[100]; /* * Alert the console operator, and enable the alarm clock to * sleep for 2 minutes in case nobody comes to satisfy dump */ void alarmcatch() { if (notify == 0) { if (timeout == 0) (void) fprintf(stderr, " DUMP: %s: (\"yes\" or \"no\") ", attnmessage); else msgtail("\7\7"); } else { if (timeout) { msgtail("\n"); broadcast(""); /* just print last msg */ } (void) fprintf(stderr," DUMP: %s: (\"yes\" or \"no\") ", attnmessage); } signal(SIGALRM, alarmcatch); (void) alarm(120); timeout = 1; } /* * Here if an inquisitive operator interrupts the dump program */ void interrupt(signo) int signo; { msg("Interrupt received.\n"); if (query("Do you want to abort dump?")) dumpabort(0); } /* * The following variables and routines manage alerting * operators to the status of dump. * This works much like wall(1) does. */ struct group *gp; /* * Get the names from the group entry "operator" to notify. */ void set_operators() { if (!notify) /*not going to notify*/ return; gp = getgrnam(OPGRENT); (void) endgrent(); if (gp == NULL) { msg("No group entry for %s.\n", OPGRENT); notify = 0; return; } } struct tm *localclock; /* * We fork a child to do the actual broadcasting, so * that the process control groups are not messed up */ void broadcast(message) char *message; { time_t clock; FILE *f_utmp; struct utmp utmp; char **np; int pid, s; if (!notify || gp == NULL) return; switch (pid = fork()) { case -1: return; case 0: break; default: while (wait(&s) != pid) continue; return; } clock = time((time_t *)0); localclock = localtime(&clock); if ((f_utmp = fopen(_PATH_UTMP, "r")) == NULL) { msg("Cannot open %s: %s\n", _PATH_UTMP, strerror(errno)); return; } while (!feof(f_utmp)) { if (fread((char *) &utmp, sizeof (struct utmp), 1, f_utmp) != 1) break; if (utmp.ut_name[0] == 0) continue; for (np = gp->gr_mem; *np; np++) { if (strncmp(*np, utmp.ut_name, sizeof(utmp.ut_name)) != 0) continue; /* * Do not send messages to operators on dialups */ if (strncmp(utmp.ut_line, DIALUP, strlen(DIALUP)) == 0) continue; #ifdef DEBUG msg("Message to %s at %s\n", *np, utmp.ut_line); #endif sendmes(utmp.ut_line, message); } } (void) fclose(f_utmp); Exit(0); /* the wait in this same routine will catch this */ /* NOTREACHED */ } static void sendmes(tty, message) char *tty, *message; { char t[50], buf[BUFSIZ]; register char *cp; int lmsg = 1; FILE *f_tty; (void) strcpy(t, _PATH_DEV); (void) strcat(t, tty); if ((f_tty = fopen(t, "w")) != NULL) { setbuf(f_tty, buf); (void) fprintf(f_tty, "\n\ \7\7\7Message from the dump program to all operators at %d:%02d ...\r\n\n\ DUMP: NEEDS ATTENTION: ", localclock->tm_hour, localclock->tm_min); for (cp = lastmsg; ; cp++) { if (*cp == '\0') { if (lmsg) { cp = message; if (*cp == '\0') break; lmsg = 0; } else break; } if (*cp == '\n') (void) putc('\r', f_tty); (void) putc(*cp, f_tty); } (void) fclose(f_tty); } } /* * print out an estimate of the amount of time left to do the dump */ time_t tschedule = 0; void timeest() { time_t tnow, deltat; (void) time((time_t *) &tnow); if (tnow >= tschedule) { tschedule = tnow + 300; if (blockswritten < 500) return; deltat = tstart_writing - tnow + (1.0 * (tnow - tstart_writing)) / blockswritten * tapesize; msg("%3.2f%% done, finished in %d:%02d\n", (blockswritten * 100.0) / tapesize, deltat / 3600, (deltat % 3600) / 60); } } void #if __STDC__ msg(const char *fmt, ...) #else msg(fmt, va_alist) char *fmt; va_dcl #endif { va_list ap; (void) fprintf(stderr," DUMP: "); #ifdef TDEBUG (void) fprintf(stderr, "pid=%d ", getpid()); #endif #if __STDC__ va_start(ap, fmt); #else va_start(ap); #endif (void) vfprintf(stderr, fmt, ap); (void) fflush(stdout); (void) fflush(stderr); (void) vsprintf(lastmsg, fmt, ap); va_end(ap); } void #if __STDC__ msgtail(const char *fmt, ...) #else msgtail(fmt, va_alist) char *fmt; va_dcl #endif { va_list ap; #if __STDC__ va_start(ap, fmt); #else va_start(ap); #endif (void) vfprintf(stderr, fmt, ap); va_end(ap); } void #if __STDC__ quit(const char *fmt, ...) #else quit(fmt, va_alist) char *fmt; va_dcl #endif { va_list ap; (void) fprintf(stderr," DUMP: "); #ifdef TDEBUG (void) fprintf(stderr, "pid=%d ", getpid()); #endif #if __STDC__ va_start(ap, fmt); #else va_start(ap); #endif (void) vfprintf(stderr, fmt, ap); va_end(ap); (void) fflush(stdout); (void) fflush(stderr); dumpabort(0); } /* * Tell the operator what has to be done; * we don't actually do it */ struct fstab * allocfsent(fs) register struct fstab *fs; { register struct fstab *new; new = (struct fstab *)malloc(sizeof (*fs)); if (new == NULL || (new->fs_file = strdup(fs->fs_file)) == NULL || (new->fs_type = strdup(fs->fs_type)) == NULL || (new->fs_spec = strdup(fs->fs_spec)) == NULL) quit("%s\n", strerror(errno)); new->fs_passno = fs->fs_passno; new->fs_freq = fs->fs_freq; return (new); } struct pfstab { struct pfstab *pf_next; struct fstab *pf_fstab; }; static struct pfstab *table; void getfstab() { register struct fstab *fs; register struct pfstab *pf; if (setfsent() == 0) { msg("Can't open %s for dump table information: %s\n", _PATH_FSTAB, strerror(errno)); return; } while ((fs = getfsent()) != NULL) { if (strcmp(fs->fs_type, FSTAB_RW) && strcmp(fs->fs_type, FSTAB_RO) && strcmp(fs->fs_type, FSTAB_RQ)) continue; fs = allocfsent(fs); if ((pf = (struct pfstab *)malloc(sizeof (*pf))) == NULL) quit("%s\n", strerror(errno)); pf->pf_fstab = fs; pf->pf_next = table; table = pf; } (void) endfsent(); } /* * Search in the fstab for a file name. * This file name can be either the special or the path file name. * * The entries in the fstab are the BLOCK special names, not the * character special names. * The caller of fstabsearch assures that the character device * is dumped (that is much faster) * * The file name can omit the leading '/'. */ struct fstab * fstabsearch(key) char *key; { register struct pfstab *pf; register struct fstab *fs; char *rn; for (pf = table; pf != NULL; pf = pf->pf_next) { fs = pf->pf_fstab; if (strcmp(fs->fs_file, key) == 0 || strcmp(fs->fs_spec, key) == 0) return (fs); rn = rawname(fs->fs_spec); if (rn != NULL && strcmp(rn, key) == 0) return (fs); if (key[0] != '/') { if (*fs->fs_spec == '/' && strcmp(fs->fs_spec + 1, key) == 0) return (fs); if (*fs->fs_file == '/' && strcmp(fs->fs_file + 1, key) == 0) return (fs); } } return (NULL); } /* * Tell the operator what to do */ void lastdump(arg) char arg; /* w ==> just what to do; W ==> most recent dumps */ { register int i; register struct fstab *dt; register struct dumpdates *dtwalk; char *lastname, *date; int dumpme; time_t tnow; (void) time(&tnow); getfstab(); /* /etc/fstab input */ initdumptimes(); /* /etc/dumpdates input */ qsort((char *) ddatev, nddates, sizeof(struct dumpdates *), datesort); if (arg == 'w') (void) printf("Dump these file systems:\n"); else (void) printf("Last dump(s) done (Dump '>' file systems):\n"); lastname = "??"; ITITERATE(i, dtwalk) { if (strncmp(lastname, dtwalk->dd_name, sizeof(dtwalk->dd_name)) == 0) continue; date = (char *)ctime(&dtwalk->dd_ddate); date[16] = '\0'; /* blast away seconds and year */ lastname = dtwalk->dd_name; dt = fstabsearch(dtwalk->dd_name); dumpme = (dt != NULL && dt->fs_freq != 0 && dtwalk->dd_ddate < tnow - (dt->fs_freq * SECSPERDAY)); if (arg != 'w' || dumpme) (void) printf( "%c %8s\t(%6s) Last dump: Level %c, Date %s\n", dumpme && (arg != 'w') ? '>' : ' ', dtwalk->dd_name, dt ? dt->fs_file : "", dtwalk->dd_level, date); } } int datesort(a1, a2) const void *a1, *a2; { struct dumpdates *d1 = *(struct dumpdates **)a1; struct dumpdates *d2 = *(struct dumpdates **)a2; int diff; diff = strncmp(d1->dd_name, d2->dd_name, sizeof(d1->dd_name)); if (diff == 0) return (d2->dd_ddate - d1->dd_ddate); return (diff); } diskdev_cmds-332.25/dump.tproj/PB.project0000644000000000000000000000220006712726561017067 0ustar rootwheel{ APPCLASS = NSApplication; FILESTABLE = { CLASSES = (); FRAMEWORKS = (); H_FILES = (); M_FILES = (); OTHER_LIBS = (disk); OTHER_LINKED = (itime.c, main.c, optr.c, tape.c, traverse.c, unctime.c); OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble, Makefile.dist, dump.8); SUBPROJECTS = (); }; LANGUAGE = English; LOCALIZABLE_FILES = {}; NEXTSTEP_COMPILEROPTIONS = "-DRDUMP"; NEXTSTEP_INSTALLDIR = /sbin; NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; NEXTSTEP_MAINNIB = dump; NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; PDO_UNIX_COMPILEROPTIONS = "-DRDUMP"; PDO_UNIX_INSTALLDIR = /sbin; PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; PDO_UNIX_MAINNIB = dump; PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; PROJECTNAME = dump; PROJECTTYPE = Tool; PROJECTVERSION = 2.8; WINDOWS_COMPILEROPTIONS = "-DRDUMP"; WINDOWS_INSTALLDIR = /sbin; WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; WINDOWS_MAINNIB = dump; WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; } diskdev_cmds-332.25/dump.tproj/tape.c0000644000000000000000000005362010267354542016303 0ustar rootwheel/* * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights * Reserved. This file contains Original Code and/or Modifications of * Original Code as defined in and that are subject to the Apple Public * Source License Version 1.0 (the 'License'). You may not use this file * except in compliance with the License. Please obtain a copy of the * License at http://www.apple.com/publicsource and read it before using * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License." * * @APPLE_LICENSE_HEADER_END@ */ /*- * Copyright (c) 1980, 1991, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #include #include #include #ifdef sunos #include #include #include #else #include #include #endif #include #include #include #include #include #include #ifdef __STDC__ #include #include #include #else int write(), read(); #endif #include "dump.h" #include "pathnames.h" int writesize; /* size of malloc()ed buffer for tape */ long lastspclrec = -1; /* tape block number of last written header */ int trecno = 0; /* next record to write in current block */ extern long blocksperfile; /* number of blocks per output file */ long blocksthisvol; /* number of blocks on current output file */ extern int ntrec; /* blocking factor on tape */ extern int cartridge; extern char *host; char *nexttape; static int atomic __P((ssize_t (*)(int, void *, size_t), int, char *, int)); static void doslave __P((int, int)); static void enslave __P((void)); static void flushtape __P((void)); static void killall __P((void)); static void rollforward __P((void)); /* * Concurrent dump mods (Caltech) - disk block reading and tape writing * are exported to several slave processes. While one slave writes the * tape, the others read disk blocks; they pass control of the tape in * a ring via signals. The parent process traverses the filesystem and * sends writeheader()'s and lists of daddr's to the slaves via pipes. * The following structure defines the instruction packets sent to slaves. */ struct req { daddr_t dblk; int count; }; int reqsiz; #define SLAVES 3 /* 1 slave writing, 1 reading, 1 for slack */ struct slave { int tapea; /* header number at start of this chunk */ int count; /* count to next header (used for TS_TAPE */ /* after EOT) */ int inode; /* inode that we are currently dealing with */ int fd; /* FD for this slave */ int pid; /* PID for this slave */ int sent; /* 1 == we've sent this slave requests */ int firstrec; /* record number of this block */ char (*tblock)[TP_BSIZE]; /* buffer for data blocks */ struct req *req; /* buffer for requests */ } slaves[SLAVES+1]; struct slave *slp; char (*nextblock)[TP_BSIZE]; int master; /* pid of master, for sending error signals */ int tenths; /* length of tape used per block written */ static int caught; /* have we caught the signal to proceed? */ static int ready; /* have we reached the lock point without having */ /* received the SIGUSR2 signal from the prev slave? */ static jmp_buf jmpbuf; /* where to jump to if we are ready when the */ /* SIGUSR2 arrives from the previous slave */ int alloctape() { int pgoff = getpagesize() - 1; char *buf; int i; writesize = ntrec * TP_BSIZE; reqsiz = (ntrec + 1) * sizeof(struct req); /* * CDC 92181's and 92185's make 0.8" gaps in 1600-bpi start/stop mode * (see DEC TU80 User's Guide). The shorter gaps of 6250-bpi require * repositioning after stopping, i.e, streaming mode, where the gap is * variable, 0.30" to 0.45". The gap is maximal when the tape stops. */ if (blocksperfile == 0) tenths = writesize / density + (cartridge ? 16 : density == 625 ? 5 : 8); /* * Allocate tape buffer contiguous with the array of instruction * packets, so flushtape() can write them together with one write(). * Align tape buffer on page boundary to speed up tape write(). */ for (i = 0; i <= SLAVES; i++) { buf = (char *) malloc((unsigned)(reqsiz + writesize + pgoff + TP_BSIZE)); if (buf == NULL) return(0); slaves[i].tblock = (char (*)[TP_BSIZE]) (((long)&buf[ntrec + 1] + pgoff) &~ pgoff); slaves[i].req = (struct req *)slaves[i].tblock - ntrec - 1; } slp = &slaves[0]; slp->count = 1; slp->tapea = 0; slp->firstrec = 0; nextblock = slp->tblock; return(1); } void writerec(dp, isspcl) char *dp; int isspcl; { slp->req[trecno].dblk = (daddr_t)0; slp->req[trecno].count = 1; *(union u_spcl *)(*(nextblock)++) = *(union u_spcl *)dp; if (isspcl) lastspclrec = spcl.c_tapea; trecno++; spcl.c_tapea++; if (trecno >= ntrec) flushtape(); } void dumpblock(blkno, size) daddr_t blkno; int size; { int avail, tpblks, dblkno; dblkno = fsbtodb(sblock, blkno); tpblks = size >> tp_bshift; while ((avail = MIN(tpblks, ntrec - trecno)) > 0) { slp->req[trecno].dblk = dblkno; slp->req[trecno].count = avail; trecno += avail; spcl.c_tapea += avail; if (trecno >= ntrec) flushtape(); dblkno += avail << (tp_bshift - dev_bshift); tpblks -= avail; } } int nogripe = 0; void tperror(signo) int signo; { if (pipeout) { msg("write error on %s\n", tape); quit("Cannot recover\n"); /* NOTREACHED */ } msg("write error %d blocks into volume %d\n", blocksthisvol, tapeno); broadcast("DUMP WRITE ERROR!\n"); if (!query("Do you want to restart?")) dumpabort(0); msg("Closing this volume. Prepare to restart with new media;\n"); msg("this dump volume will be rewritten.\n"); killall(); nogripe = 1; close_rewind(); Exit(X_REWRITE); } void sigpipe(signo) int signo; { quit("Broken pipe\n"); } static void flushtape() { int i, blks, got; long lastfirstrec; int siz = (char *)nextblock - (char *)slp->req; slp->req[trecno].count = 0; /* Sentinel */ if (atomic(write, slp->fd, (char *)slp->req, siz) != siz) quit("error writing command pipe: %s\n", strerror(errno)); slp->sent = 1; /* we sent a request, read the response later */ lastfirstrec = slp->firstrec; if (++slp >= &slaves[SLAVES]) slp = &slaves[0]; /* Read results back from next slave */ if (slp->sent) { if (atomic(read, slp->fd, (char *)&got, sizeof got) != sizeof got) { perror(" DUMP: error reading command pipe in master"); dumpabort(0); } slp->sent = 0; /* Check for end of tape */ if (got < writesize) { msg("End of tape detected\n"); /* * Drain the results, don't care what the values were. * If we read them here then trewind won't... */ for (i = 0; i < SLAVES; i++) { if (slaves[i].sent) { if (atomic(read, slaves[i].fd, (char *)&got, sizeof got) != sizeof got) { perror(" DUMP: error reading command pipe in master"); dumpabort(0); } slaves[i].sent = 0; } } close_rewind(); rollforward(); return; } } blks = 0; if (spcl.c_type != TS_END) { for (i = 0; i < spcl.c_count; i++) if (spcl.c_addr[i] != 0) blks++; } slp->count = lastspclrec + blks + 1 - spcl.c_tapea; slp->tapea = spcl.c_tapea; slp->firstrec = lastfirstrec + ntrec; slp->inode = curino; nextblock = slp->tblock; trecno = 0; asize += tenths; blockswritten += ntrec; blocksthisvol += ntrec; if (!pipeout && (blocksperfile ? (blocksthisvol >= blocksperfile) : (asize > tsize))) { close_rewind(); startnewtape(0); } timeest(); } void trewind() { int f; int got; for (f = 0; f < SLAVES; f++) { /* * Drain the results, but unlike EOT we DO (or should) care * what the return values were, since if we detect EOT after * we think we've written the last blocks to the tape anyway, * we have to replay those blocks with rollforward. * * fixme: punt for now. */ if (slaves[f].sent) { if (atomic(read, slaves[f].fd, (char *)&got, sizeof got) != sizeof got) { perror(" DUMP: error reading command pipe in master"); dumpabort(0); } slaves[f].sent = 0; if (got != writesize) { msg("EOT detected in last 2 tape records!\n"); msg("Use a longer tape, decrease the size estimate\n"); quit("or use no size estimate at all.\n"); } } (void) close(slaves[f].fd); } while (wait((int *)NULL) >= 0) /* wait for any signals from slaves */ /* void */; if (pipeout) return; msg("Closing %s\n", tape); #ifdef RDUMP if (host) { rmtclose(); while (rmtopen(tape, 0) < 0) sleep(10); rmtclose(); return; } #endif (void) close(tapefd); while ((f = open(tape, 0)) < 0) sleep (10); (void) close(f); } void close_rewind() { trewind(); if (nexttape) return; if (!nogripe) { msg("Change Volumes: Mount volume #%d\n", tapeno+1); broadcast("CHANGE DUMP VOLUMES!\7\7\n"); } while (!query("Is the new volume mounted and ready to go?")) if (query("Do you want to abort?")) { dumpabort(0); /*NOTREACHED*/ } } void rollforward() { register struct req *p, *q, *prev; register struct slave *tslp; int i, size, savedtapea, got; union u_spcl *ntb, *otb; tslp = &slaves[SLAVES]; ntb = (union u_spcl *)tslp->tblock[1]; /* * Each of the N slaves should have requests that need to * be replayed on the next tape. Use the extra slave buffers * (slaves[SLAVES]) to construct request lists to be sent to * each slave in turn. */ for (i = 0; i < SLAVES; i++) { q = &tslp->req[1]; otb = (union u_spcl *)slp->tblock; /* * For each request in the current slave, copy it to tslp. */ prev = NULL; for (p = slp->req; p->count > 0; p += p->count) { *q = *p; if (p->dblk == 0) *ntb++ = *otb++; /* copy the datablock also */ prev = q; q += q->count; } if (prev == NULL) quit("rollforward: protocol botch"); if (prev->dblk != 0) prev->count -= 1; else ntb--; q -= 1; q->count = 0; q = &tslp->req[0]; if (i == 0) { q->dblk = 0; q->count = 1; trecno = 0; nextblock = tslp->tblock; savedtapea = spcl.c_tapea; spcl.c_tapea = slp->tapea; startnewtape(0); spcl.c_tapea = savedtapea; lastspclrec = savedtapea - 1; } size = (char *)ntb - (char *)q; if (atomic(write, slp->fd, (char *)q, size) != size) { perror(" DUMP: error writing command pipe"); dumpabort(0); } slp->sent = 1; if (++slp >= &slaves[SLAVES]) slp = &slaves[0]; q->count = 1; if (prev->dblk != 0) { /* * If the last one was a disk block, make the * first of this one be the last bit of that disk * block... */ q->dblk = prev->dblk + prev->count * (TP_BSIZE / DEV_BSIZE); ntb = (union u_spcl *)tslp->tblock; } else { /* * It wasn't a disk block. Copy the data to its * new location in the buffer. */ q->dblk = 0; *((union u_spcl *)tslp->tblock) = *ntb; ntb = (union u_spcl *)tslp->tblock[1]; } } slp->req[0] = *q; nextblock = slp->tblock; if (q->dblk == 0) nextblock++; trecno = 1; /* * Clear the first slaves' response. One hopes that it * worked ok, otherwise the tape is much too short! */ if (slp->sent) { if (atomic(read, slp->fd, (char *)&got, sizeof got) != sizeof got) { perror(" DUMP: error reading command pipe in master"); dumpabort(0); } slp->sent = 0; if (got != writesize) { quit("EOT detected at start of the tape!\n"); } } } /* * We implement taking and restoring checkpoints on the tape level. * When each tape is opened, a new process is created by forking; this * saves all of the necessary context in the parent. The child * continues the dump; the parent waits around, saving the context. * If the child returns X_REWRITE, then it had problems writing that tape; * this causes the parent to fork again, duplicating the context, and * everything continues as if nothing had happened. */ void startnewtape(top) int top; { int parentpid; int childpid; int status; int waitpid; char *p; #ifdef sunos void (*interrupt_save)(); #else sig_t interrupt_save; #endif interrupt_save = signal(SIGINT, SIG_IGN); parentpid = getpid(); restore_check_point: (void)signal(SIGINT, interrupt_save); /* * All signals are inherited... */ childpid = fork(); if (childpid < 0) { msg("Context save fork fails in parent %d\n", parentpid); Exit(X_ABORT); } if (childpid != 0) { /* * PARENT: * save the context by waiting * until the child doing all of the work returns. * don't catch the interrupt */ signal(SIGINT, SIG_IGN); #ifdef TDEBUG msg("Tape: %d; parent process: %d child process %d\n", tapeno+1, parentpid, childpid); #endif /* TDEBUG */ while ((waitpid = wait(&status)) != childpid) msg("Parent %d waiting for child %d has another child %d return\n", parentpid, childpid, waitpid); if (status & 0xFF) { msg("Child %d returns LOB status %o\n", childpid, status&0xFF); } status = (status >> 8) & 0xFF; #ifdef TDEBUG switch(status) { case X_FINOK: msg("Child %d finishes X_FINOK\n", childpid); break; case X_ABORT: msg("Child %d finishes X_ABORT\n", childpid); break; case X_REWRITE: msg("Child %d finishes X_REWRITE\n", childpid); break; default: msg("Child %d finishes unknown %d\n", childpid, status); break; } #endif /* TDEBUG */ switch(status) { case X_FINOK: Exit(X_FINOK); case X_ABORT: Exit(X_ABORT); case X_REWRITE: goto restore_check_point; default: msg("Bad return code from dump: %d\n", status); Exit(X_ABORT); } /*NOTREACHED*/ } else { /* we are the child; just continue */ #ifdef TDEBUG sleep(4); /* allow time for parent's message to get out */ msg("Child on Tape %d has parent %d, my pid = %d\n", tapeno+1, parentpid, getpid()); #endif /* TDEBUG */ /* * If we have a name like "/dev/rmt0,/dev/rmt1", * use the name before the comma first, and save * the remaining names for subsequent volumes. */ tapeno++; /* current tape sequence */ if (nexttape || strchr(tape, ',')) { if (nexttape && *nexttape) tape = nexttape; if ((p = strchr(tape, ',')) != NULL) { *p = '\0'; nexttape = p + 1; } else nexttape = NULL; msg("Dumping volume %d on %s\n", tapeno, tape); } #ifdef RDUMP while ((tapefd = (host ? rmtopen(tape, 2) : pipeout ? 1 : open(tape, O_WRONLY|O_CREAT, 0666))) < 0) #else while ((tapefd = (pipeout ? 1 : open(tape, O_WRONLY|O_CREAT, 0666))) < 0) #endif { msg("Cannot open output \"%s\".\n", tape); if (!query("Do you want to retry the open?")) dumpabort(0); } enslave(); /* Share open tape file descriptor with slaves */ asize = 0; blocksthisvol = 0; if (top) newtape++; /* new tape signal */ spcl.c_count = slp->count; /* * measure firstrec in TP_BSIZE units since restore doesn't * know the correct ntrec value... */ spcl.c_firstrec = slp->firstrec; spcl.c_volume++; spcl.c_type = TS_TAPE; spcl.c_flags |= DR_NEWHEADER; writeheader((ino_t)slp->inode); spcl.c_flags &=~ DR_NEWHEADER; if (tapeno > 1) msg("Volume %d begins with blocks from inode %d\n", tapeno, slp->inode); } } void dumpabort(signo) int signo; { if (master != 0 && master != getpid()) /* Signals master to call dumpabort */ (void) kill(master, SIGTERM); else { killall(); msg("The ENTIRE dump is aborted.\n"); } #ifdef RDUMP rmtclose(); #endif Exit(X_ABORT); } __dead void Exit(status) int status; { #ifdef TDEBUG msg("pid = %d exits with status %d\n", getpid(), status); #endif /* TDEBUG */ exit(status); } /* * proceed - handler for SIGUSR2, used to synchronize IO between the slaves. */ void proceed(signo) int signo; { if (ready) longjmp(jmpbuf, 1); caught++; } void enslave() { int cmd[2]; register int i, j; master = getpid(); signal(SIGTERM, dumpabort); /* Slave sends SIGTERM on dumpabort() */ signal(SIGPIPE, sigpipe); signal(SIGUSR1, tperror); /* Slave sends SIGUSR1 on tape errors */ signal(SIGUSR2, proceed); /* Slave sends SIGUSR2 to next slave */ for (i = 0; i < SLAVES; i++) { if (i == slp - &slaves[0]) { caught = 1; } else { caught = 0; } if (socketpair(AF_UNIX, SOCK_STREAM, 0, cmd) < 0 || (slaves[i].pid = fork()) < 0) quit("too many slaves, %d (recompile smaller): %s\n", i, strerror(errno)); slaves[i].fd = cmd[1]; slaves[i].sent = 0; if (slaves[i].pid == 0) { /* Slave starts up here */ for (j = 0; j <= i; j++) (void) close(slaves[j].fd); signal(SIGINT, SIG_IGN); /* Master handles this */ doslave(cmd[0], i); Exit(X_FINOK); } } for (i = 0; i < SLAVES; i++) (void) atomic(write, slaves[i].fd, (char *) &slaves[(i + 1) % SLAVES].pid, sizeof slaves[0].pid); master = 0; } void killall() { register int i; for (i = 0; i < SLAVES; i++) if (slaves[i].pid > 0) (void) kill(slaves[i].pid, SIGKILL); } /* * Synchronization - each process has a lockfile, and shares file * descriptors to the following process's lockfile. When our write * completes, we release our lock on the following process's lock- * file, allowing the following process to lock it and proceed. We * get the lock back for the next cycle by swapping descriptors. */ static void doslave(cmd, slave_number) register int cmd; int slave_number; { register int nread; int nextslave, size, wrote, eot_count; /* * Need our own seek pointer. */ (void) close(diskfd); if ((diskfd = open(disk, O_RDONLY)) < 0) quit("slave couldn't reopen disk: %s\n", strerror(errno)); /* * Need the pid of the next slave in the loop... */ if ((nread = atomic(read, cmd, (char *)&nextslave, sizeof nextslave)) != sizeof nextslave) { quit("master/slave protocol botched - didn't get pid of next slave.\n"); } /* * Get list of blocks to dump, read the blocks into tape buffer */ while ((nread = atomic(read, cmd, (char *)slp->req, reqsiz)) == reqsiz) { register struct req *p = slp->req; for (trecno = 0; trecno < ntrec; trecno += p->count, p += p->count) { if (p->dblk) { bread(p->dblk, slp->tblock[trecno], p->count * TP_BSIZE); } else { if (p->count != 1 || atomic(read, cmd, (char *)slp->tblock[trecno], TP_BSIZE) != TP_BSIZE) quit("master/slave protocol botched.\n"); } } if (setjmp(jmpbuf) == 0) { ready = 1; if (!caught) (void) pause(); } ready = 0; caught = 0; /* Try to write the data... */ eot_count = 0; size = 0; while (eot_count < 10 && size < writesize) { #ifdef RDUMP if (host) wrote = rmtwrite(slp->tblock[0]+size, writesize-size); else #endif wrote = write(tapefd, slp->tblock[0]+size, writesize-size); #ifdef WRITEDEBUG printf("slave %d wrote %d\n", slave_number, wrote); #endif if (wrote < 0) break; if (wrote == 0) eot_count++; size += wrote; } #ifdef WRITEDEBUG if (size != writesize) printf("slave %d only wrote %d out of %d bytes and gave up.\n", slave_number, size, writesize); #endif if (eot_count > 0) size = 0; /* * fixme: Pyramids running OSx return ENOSPC * at EOT on 1/2 inch drives. */ if (size < 0) { (void) kill(master, SIGUSR1); for (;;) (void) sigpause(0); } else { /* * pass size of write back to master * (for EOT handling) */ (void) atomic(write, cmd, (char *)&size, sizeof size); } /* * If partial write, don't want next slave to go. * Also jolts him awake. */ (void) kill(nextslave, SIGUSR2); } if (nread != 0) quit("error reading command pipe: %s\n", strerror(errno)); } /* * Since a read from a pipe may not return all we asked for, * or a write may not write all we ask if we get a signal, * loop until the count is satisfied (or error). */ static int atomic(func, fd, buf, count) ssize_t (*func)(int, void *, size_t); int fd; char *buf; int count; { int got, need = count; while ((got = (*func)(fd, buf, need)) > 0 && (need -= got) > 0) buf += got; return (got < 0 ? got : count - need); } diskdev_cmds-332.25/dump.tproj/traverse.c0000644000000000000000000004036607036476013017206 0ustar rootwheel/* * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights * Reserved. This file contains Original Code and/or Modifications of * Original Code as defined in and that are subject to the Apple Public * Source License Version 1.0 (the 'License'). You may not use this file * except in compliance with the License. Please obtain a copy of the * License at http://www.apple.com/publicsource and read it before using * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License." * * @APPLE_LICENSE_HEADER_END@ */ /*- * Copyright (c) 1980, 1988, 1991, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #include #include #ifdef sunos #include #include #include #include #else #include #include #include #endif #include #include #include #ifdef __STDC__ #include #include #endif #include "dump.h" #define HASDUMPEDFILE 0x1 #define HASSUBDIRS 0x2 #ifdef FS_44INODEFMT typedef quad_t fsizeT; #else typedef long fsizeT; #endif static int dirindir __P((ino_t ino, daddr_t blkno, int level, long *size)); static void dmpindir __P((ino_t ino, daddr_t blk, int level, fsizeT *size)); static int searchdir __P((ino_t ino, daddr_t blkno, long size, long filesize)); /* * This is an estimation of the number of TP_BSIZE blocks in the file. * It estimates the number of blocks in files with holes by assuming * that all of the blocks accounted for by di_blocks are data blocks * (when some of the blocks are usually used for indirect pointers); * hence the estimate may be high. */ long blockest(dp) register struct dinode *dp; { long blkest, sizeest; /* * dp->di_size is the size of the file in bytes. * dp->di_blocks stores the number of sectors actually in the file. * If there are more sectors than the size would indicate, this just * means that there are indirect blocks in the file or unused * sectors in the last file block; we can safely ignore these * (blkest = sizeest below). * If the file is bigger than the number of sectors would indicate, * then the file has holes in it. In this case we must use the * block count to estimate the number of data blocks used, but * we use the actual size for estimating the number of indirect * dump blocks (sizeest vs. blkest in the indirect block * calculation). */ #ifdef __APPLE__ blkest = howmany(dbtob(dp->di_blocks, dev_bsize), TP_BSIZE); #else blkest = howmany(dbtob(dp->di_blocks), TP_BSIZE); #endif /* __APPLE__ */ sizeest = howmany(dp->di_size, TP_BSIZE); if (blkest > sizeest) blkest = sizeest; if (dp->di_size > sblock->fs_bsize * NDADDR) { /* calculate the number of indirect blocks on the dump tape */ blkest += howmany(sizeest - NDADDR * sblock->fs_bsize / TP_BSIZE, TP_NINDIR); } return (blkest + 1); } /* Auxiliary macro to pick up files changed since previous dump. */ #define CHANGEDSINCE(dp, t) \ ((dp)->di_mtime >= (t) || (dp)->di_ctime >= (t)) /* The WANTTODUMP macro decides whether a file should be dumped. */ #ifdef UF_NODUMP #define WANTTODUMP(dp) \ (CHANGEDSINCE(dp, spcl.c_ddate) && \ (nonodump || ((dp)->di_flags & UF_NODUMP) != UF_NODUMP)) #else #define WANTTODUMP(dp) CHANGEDSINCE(dp, spcl.c_ddate) #endif /* * Dump pass 1. * * Walk the inode list for a filesystem to find all allocated inodes * that have been modified since the previous dump time. Also, find all * the directories in the filesystem. */ int mapfiles(maxino, tapesize) ino_t maxino; long *tapesize; { register int mode; register ino_t ino; register struct dinode *dp; int anydirskipped = 0; for (ino = ROOTINO; ino < maxino; ino++) { dp = getino(ino); if ((mode = (dp->di_mode & IFMT)) == 0) continue; SETINO(ino, usedinomap); if (mode == IFDIR) SETINO(ino, dumpdirmap); if (WANTTODUMP(dp)) { SETINO(ino, dumpinomap); if (mode != IFREG && mode != IFDIR && mode != IFLNK) *tapesize += 1; else *tapesize += blockest(dp); continue; } if (mode == IFDIR) anydirskipped = 1; } /* * Restore gets very upset if the root is not dumped, * so ensure that it always is dumped. */ SETINO(ROOTINO, dumpinomap); return (anydirskipped); } /* * Dump pass 2. * * Scan each directory on the filesystem to see if it has any modified * files in it. If it does, and has not already been added to the dump * list (because it was itself modified), then add it. If a directory * has not been modified itself, contains no modified files and has no * subdirectories, then it can be deleted from the dump list and from * the list of directories. By deleting it from the list of directories, * its parent may now qualify for the same treatment on this or a later * pass using this algorithm. */ int mapdirs(maxino, tapesize) ino_t maxino; long *tapesize; { register struct dinode *dp; register int i, isdir; register char *map; register ino_t ino; long filesize; int ret, change = 0; isdir = 0; /* XXX just to get gcc to shut up */ for (map = dumpdirmap, ino = 1; ino < maxino; ino++) { if (((ino - 1) % NBBY) == 0) /* map is offset by 1 */ isdir = *map++; else isdir >>= 1; if ((isdir & 1) == 0 || TSTINO(ino, dumpinomap)) continue; dp = getino(ino); filesize = dp->di_size; for (ret = 0, i = 0; filesize > 0 && i < NDADDR; i++) { if (dp->di_db[i] != 0) ret |= searchdir(ino, dp->di_db[i], (long)dblksize(sblock, dp, i), filesize); if (ret & HASDUMPEDFILE) filesize = 0; else filesize -= sblock->fs_bsize; } for (i = 0; filesize > 0 && i < NIADDR; i++) { if (dp->di_ib[i] == 0) continue; ret |= dirindir(ino, dp->di_ib[i], i, &filesize); } if (ret & HASDUMPEDFILE) { SETINO(ino, dumpinomap); *tapesize += blockest(dp); change = 1; continue; } if ((ret & HASSUBDIRS) == 0) { if (!TSTINO(ino, dumpinomap)) { CLRINO(ino, dumpdirmap); change = 1; } } } return (change); } /* * Read indirect blocks, and pass the data blocks to be searched * as directories. Quit as soon as any entry is found that will * require the directory to be dumped. */ static int dirindir(ino, blkno, ind_level, filesize) ino_t ino; daddr_t blkno; int ind_level; long *filesize; { int ret = 0; register int i; daddr_t idblk[MAXNINDIR]; bread(fsbtodb(sblock, blkno), (char *)idblk, (int)sblock->fs_bsize); if (ind_level <= 0) { for (i = 0; *filesize > 0 && i < NINDIR(sblock); i++) { blkno = idblk[i]; if (blkno != 0) ret |= searchdir(ino, blkno, sblock->fs_bsize, *filesize); if (ret & HASDUMPEDFILE) *filesize = 0; else *filesize -= sblock->fs_bsize; } return (ret); } ind_level--; for (i = 0; *filesize > 0 && i < NINDIR(sblock); i++) { blkno = idblk[i]; if (blkno != 0) ret |= dirindir(ino, blkno, ind_level, filesize); } return (ret); } /* * Scan a disk block containing directory information looking to see if * any of the entries are on the dump list and to see if the directory * contains any subdirectories. */ static int searchdir(ino, blkno, size, filesize) ino_t ino; daddr_t blkno; register long size; long filesize; { register struct direct *dp; register long loc, ret = 0; char dblk[MAXBSIZE]; bread(fsbtodb(sblock, blkno), dblk, (int)size); if (filesize < size) size = filesize; for (loc = 0; loc < size; ) { dp = (struct direct *)(dblk + loc); if (dp->d_reclen == 0) { msg("corrupted directory, inumber %d\n", ino); break; } loc += dp->d_reclen; if (dp->d_ino == 0) continue; if (dp->d_name[0] == '.') { if (dp->d_name[1] == '\0') continue; if (dp->d_name[1] == '.' && dp->d_name[2] == '\0') continue; } if (TSTINO(dp->d_ino, dumpinomap)) { ret |= HASDUMPEDFILE; if (ret & HASSUBDIRS) break; } if (TSTINO(dp->d_ino, dumpdirmap)) { ret |= HASSUBDIRS; if (ret & HASDUMPEDFILE) break; } } return (ret); } /* * Dump passes 3 and 4. * * Dump the contents of an inode to tape. */ void dumpino(dp, ino) register struct dinode *dp; ino_t ino; { int ind_level, cnt; fsizeT size; char buf[TP_BSIZE]; if (newtape) { newtape = 0; dumpmap(dumpinomap, TS_BITS, ino); } CLRINO(ino, dumpinomap); spcl.c_dinode = *dp; spcl.c_type = TS_INODE; spcl.c_count = 0; switch (dp->di_mode & S_IFMT) { case 0: /* * Freed inode. */ return; case S_IFLNK: /* * Check for short symbolic link. */ #ifdef FS_44INODEFMT if (dp->di_size > 0 && dp->di_size < sblock->fs_maxsymlinklen) { spcl.c_addr[0] = 1; spcl.c_count = 1; writeheader(ino); memmove(buf, dp->di_shortlink, (u_long)dp->di_size); buf[dp->di_size] = '\0'; writerec(buf, 0); return; } #endif /* fall through */ case S_IFDIR: case S_IFREG: if (dp->di_size > 0) break; /* fall through */ case S_IFIFO: case S_IFSOCK: case S_IFCHR: case S_IFBLK: writeheader(ino); return; default: msg("Warning: undefined file type 0%o\n", dp->di_mode & IFMT); return; } if (dp->di_size > NDADDR * sblock->fs_bsize) cnt = NDADDR * sblock->fs_frag; else cnt = howmany(dp->di_size, sblock->fs_fsize); blksout(&dp->di_db[0], cnt, ino); if ((size = dp->di_size - NDADDR * sblock->fs_bsize) <= 0) return; for (ind_level = 0; ind_level < NIADDR; ind_level++) { dmpindir(ino, dp->di_ib[ind_level], ind_level, &size); if (size <= 0) return; } } /* * Read indirect blocks, and pass the data blocks to be dumped. */ static void dmpindir(ino, blk, ind_level, size) ino_t ino; daddr_t blk; int ind_level; fsizeT *size; { int i, cnt; daddr_t idblk[MAXNINDIR]; if (blk != 0) bread(fsbtodb(sblock, blk), (char *)idblk, (int) sblock->fs_bsize); else memset(idblk, 0, (int)sblock->fs_bsize); if (ind_level <= 0) { if (*size < NINDIR(sblock) * sblock->fs_bsize) cnt = howmany(*size, sblock->fs_fsize); else cnt = NINDIR(sblock) * sblock->fs_frag; *size -= NINDIR(sblock) * sblock->fs_bsize; blksout(&idblk[0], cnt, ino); return; } ind_level--; for (i = 0; i < NINDIR(sblock); i++) { dmpindir(ino, idblk[i], ind_level, size); if (*size <= 0) return; } } /* * Collect up the data into tape record sized buffers and output them. */ void blksout(blkp, frags, ino) daddr_t *blkp; int frags; ino_t ino; { register daddr_t *bp; int i, j, count, blks, tbperdb; blks = howmany(frags * sblock->fs_fsize, TP_BSIZE); tbperdb = sblock->fs_bsize >> tp_bshift; for (i = 0; i < blks; i += TP_NINDIR) { if (i + TP_NINDIR > blks) count = blks; else count = i + TP_NINDIR; for (j = i; j < count; j++) if (blkp[j / tbperdb] != 0) spcl.c_addr[j - i] = 1; else spcl.c_addr[j - i] = 0; spcl.c_count = count - i; writeheader(ino); bp = &blkp[i / tbperdb]; for (j = i; j < count; j += tbperdb, bp++) if (*bp != 0) if (j + tbperdb <= count) dumpblock(*bp, (int)sblock->fs_bsize); else dumpblock(*bp, (count - j) * TP_BSIZE); spcl.c_type = TS_ADDR; } } /* * Dump a map to the tape. */ void dumpmap(map, type, ino) char *map; int type; ino_t ino; { register int i; char *cp; spcl.c_type = type; spcl.c_count = howmany(mapsize * sizeof(char), TP_BSIZE); writeheader(ino); for (i = 0, cp = map; i < spcl.c_count; i++, cp += TP_BSIZE) writerec(cp, 0); } /* * Write a header record to the dump tape. */ void writeheader(ino) ino_t ino; { register long sum, cnt, *lp; spcl.c_inumber = ino; spcl.c_magic = NFS_MAGIC; spcl.c_checksum = 0; lp = (long *)&spcl; sum = 0; cnt = sizeof(union u_spcl) / (4 * sizeof(long)); while (--cnt >= 0) { sum += *lp++; sum += *lp++; sum += *lp++; sum += *lp++; } spcl.c_checksum = CHECKSUM - sum; writerec((char *)&spcl, 1); } struct dinode * getino(inum) ino_t inum; { static daddr_t minino, maxino; static struct dinode inoblock[MAXINOPB]; curino = inum; if (inum >= minino && inum < maxino) return (&inoblock[inum - minino]); bread(fsbtodb(sblock, ino_to_fsba(sblock, inum)), (char *)inoblock, (int)sblock->fs_bsize); minino = inum - (inum % INOPB(sblock)); maxino = minino + INOPB(sblock); return (&inoblock[inum - minino]); } /* * Read a chunk of data from the disk. * Try to recover from hard errors by reading in sector sized pieces. * Error recovery is attempted at most BREADEMAX times before seeking * consent from the operator to continue. */ int breaderrors = 0; #define BREADEMAX 32 void bread(blkno, buf, size) daddr_t blkno; char *buf; int size; { int cnt, i; extern int errno; loop: if ((int)lseek(diskfd, ((off_t)blkno << dev_bshift), 0) == -1) msg("bread: lseek fails\n"); if ((cnt = read(diskfd, buf, size)) == size) return; if (blkno + (size / dev_bsize) > fsbtodb(sblock, sblock->fs_size)) { /* * Trying to read the final fragment. * * NB - dump only works in TP_BSIZE blocks, hence * rounds `dev_bsize' fragments up to TP_BSIZE pieces. * It should be smarter about not actually trying to * read more than it can get, but for the time being * we punt and scale back the read only when it gets * us into trouble. (mkm 9/25/83) */ size -= dev_bsize; goto loop; } if (cnt == -1) msg("read error from %s: %s: [block %d]: count=%d\n", disk, strerror(errno), blkno, size); else msg("short read error from %s: [block %d]: count=%d, got=%d\n", disk, blkno, size, cnt); if (++breaderrors > BREADEMAX) { msg("More than %d block read errors from %d\n", BREADEMAX, disk); broadcast("DUMP IS AILING!\n"); msg("This is an unrecoverable error.\n"); if (!query("Do you want to attempt to continue?")){ dumpabort(0); /*NOTREACHED*/ } else breaderrors = 0; } /* * Zero buffer, then try to read each sector of buffer separately. */ memset(buf, 0, size); for (i = 0; i < size; i += dev_bsize, buf += dev_bsize, blkno++) { if ((int)lseek(diskfd, ((off_t)blkno << dev_bshift), 0) == -1) msg("bread: lseek2 fails!\n"); if ((cnt = read(diskfd, buf, (int)dev_bsize)) == dev_bsize) continue; if (cnt == -1) { msg("read error from %s: %s: [sector %d]: count=%d\n", disk, strerror(errno), blkno, dev_bsize); continue; } msg("short read error from %s: [sector %d]: count=%d, got=%d\n", disk, blkno, dev_bsize, cnt); } } diskdev_cmds-332.25/dump.tproj/unctime.c0000644000000000000000000001005606712726561017016 0ustar rootwheel/* * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights * Reserved. This file contains Original Code and/or Modifications of * Original Code as defined in and that are subject to the Apple Public * Source License Version 1.0 (the 'License'). You may not use this file * except in compliance with the License. Please obtain a copy of the * License at http://www.apple.com/publicsource and read it before using * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License." * * @APPLE_LICENSE_HEADER_END@ */ /*- * Copyright (c) 1980, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #include #include #ifdef __STDC__ #include #include #endif #ifndef __P #include #endif /* * Convert a ctime(3) format string into a system format date. * Return the date thus calculated. * * Return -1 if the string is not in ctime format. */ /* * Offsets into the ctime string to various parts. */ #define E_MONTH 4 #define E_DAY 8 #define E_HOUR 11 #define E_MINUTE 14 #define E_SECOND 17 #define E_YEAR 20 static int lookup __P((char *)); time_t unctime(str) char *str; { struct tm then; char dbuf[26]; (void) strncpy(dbuf, str, sizeof(dbuf) - 1); dbuf[sizeof(dbuf) - 1] = '\0'; dbuf[E_MONTH+3] = '\0'; if ((then.tm_mon = lookup(&dbuf[E_MONTH])) < 0) return (-1); then.tm_mday = atoi(&dbuf[E_DAY]); then.tm_hour = atoi(&dbuf[E_HOUR]); then.tm_min = atoi(&dbuf[E_MINUTE]); then.tm_sec = atoi(&dbuf[E_SECOND]); then.tm_year = atoi(&dbuf[E_YEAR]) - 1900; then.tm_isdst = -1; return(mktime(&then)); } static char months[] = "JanFebMarAprMayJunJulAugSepOctNovDec"; static int lookup(str) char *str; { register char *cp, *cp2; for (cp = months, cp2 = str; *cp != '\0'; cp += 3) if (strncmp(cp, cp2, 3) == 0) return((cp-months) / 3); return(-1); } diskdev_cmds-332.25/dumpfs.tproj/0000755000000000000000000000000010640030222015506 5ustar rootwheeldiskdev_cmds-332.25/dumpfs.tproj/dumpfs.80000644000000000000000000000470207702340001017104 0ustar rootwheel.\" Copyright (c) 1983, 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: .\" This product includes software developed by the University of .\" California, Berkeley and its contributors. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)dumpfs.8 8.1 (Berkeley) 6/5/93 .\" .Dd June 5, 1993 .Dt DUMPFS 8 .Os BSD 4.2 .Sh NAME .Nm dumpfs .Nd dump file system information .Sh SYNOPSIS .Nm dumpfs .Op Ar filesys No \&| Ar device .Sh DESCRIPTION .Nm Dumpfs prints out the super block and cylinder group information for the file system or special device specified. The listing is very long and detailed. This command is useful mostly for finding out certain file system information such as the file system block size and minimum free space percentage. .Sh SEE ALSO .Xr fs 5 , .Xr fsck 8 , .Xr newfs 8 , .Xr tunefs 8 .Sh HISTORY The .Nm command appeared in .Bx 4.2 . diskdev_cmds-332.25/dumpfs.tproj/dumpfs.c0000644000000000000000000002576407464556045017220 0ustar rootwheel/* * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights * Reserved. This file contains Original Code and/or Modifications of * Original Code as defined in and that are subject to the Apple Public * Source License Version 1.0 (the 'License'). You may not use this file * except in compliance with the License. Please obtain a copy of the * License at http://www.apple.com/publicsource and read it before using * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License." * * @APPLE_LICENSE_HEADER_END@ */ /* * Copyright (c) 1983, 1992, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #include #include #include #include #include #include #include #include #include #include #include #if REV_ENDIAN_FS #import "ufs_byte_order.h" #endif /* REV_ENDIAN_FS */ union { struct fs fs; char pad[MAXBSIZE]; } fsun; #define afs fsun.fs union { struct cg cg; char pad[MAXBSIZE]; } cgun; #define acg cgun.cg long dev_bsize = 1; #if REV_ENDIAN_FS int rev_endian=0; #endif /* REV_ENDIAN_FS */ int dumpfs __P((char *)); int dumpcg __P((char *, int, int)); void pbits __P((void *, int)); void usage __P((void)); int main(argc, argv) int argc; char *argv[]; { register struct fstab *fs; int ch, eval; while ((ch = getopt(argc, argv, "")) != -1) switch(ch) { case '?': default: usage(); } argc -= optind; argv += optind; if (argc < 1) usage(); for (eval = 0; *argv; ++argv) if ((fs = getfsfile(*argv)) == NULL) eval |= dumpfs(*argv); else eval |= dumpfs(fs->fs_spec); exit(eval); } int dumpfs(name) char *name; { int fd, c, i, j, k, size; if ((fd = open(name, O_RDONLY, 0)) < 0) goto err; if (lseek(fd, (off_t)SBOFF, SEEK_SET) == (off_t)-1) goto err; if (read(fd, &afs, SBSIZE) != SBSIZE) goto err; if (afs.fs_magic != FS_MAGIC) { #if REV_ENDIAN_FS byte_swap_sbin(&afs); if (afs.fs_magic != FS_MAGIC) { #endif /* REV_ENDIAN_FS */ warnx("%s: superblock has bad magic number, skipped", name); (void)close(fd); return (1); #if REV_ENDIAN_FS } else { printf("Reverse Byte order Filesystem Detected\n"); rev_endian=1; } #endif /* REV_ENDIAN_FS */ } #if REV_ENDIAN_FS else rev_endian=0; #endif /* REV_ENDIAN_FS */ if (afs.fs_postblformat == FS_42POSTBLFMT) afs.fs_nrpos = 8; dev_bsize = afs.fs_fsize / fsbtodb(&afs, 1); printf("magic\t%x\ttime\t%s", afs.fs_magic, ctime(&afs.fs_time)); printf("cylgrp\t%s\tinodes\t%s\n", afs.fs_postblformat == FS_42POSTBLFMT ? "static" : "dynamic", afs.fs_inodefmt < FS_44INODEFMT ? "4.2/4.3BSD" : "4.4BSD"); printf("nbfree\t%d\tndir\t%d\tnifree\t%d\tnffree\t%d\n", afs.fs_cstotal.cs_nbfree, afs.fs_cstotal.cs_ndir, afs.fs_cstotal.cs_nifree, afs.fs_cstotal.cs_nffree); printf("ncg\t%d\tncyl\t%d\tsize\t%d\tblocks\t%d\n", afs.fs_ncg, afs.fs_ncyl, afs.fs_size, afs.fs_dsize); printf("bsize\t%d\tshift\t%d\tmask\t0x%08x\n", afs.fs_bsize, afs.fs_bshift, afs.fs_bmask); printf("fsize\t%d\tshift\t%d\tmask\t0x%08x\n", afs.fs_fsize, afs.fs_fshift, afs.fs_fmask); printf("frag\t%d\tshift\t%d\tfsbtodb\t%d\n", afs.fs_frag, afs.fs_fragshift, afs.fs_fsbtodb); printf("cpg\t%d\tbpg\t%d\tfpg\t%d\tipg\t%d\n", afs.fs_cpg, afs.fs_fpg / afs.fs_frag, afs.fs_fpg, afs.fs_ipg); printf("minfree\t%d%%\toptim\t%s\tmaxcontig %d\tmaxbpg\t%d\n", afs.fs_minfree, afs.fs_optim == FS_OPTSPACE ? "space" : "time", afs.fs_maxcontig, afs.fs_maxbpg); printf("rotdelay %dms\theadswitch %dus\ttrackseek %dus\trps\t%d\n", afs.fs_rotdelay, afs.fs_headswitch, afs.fs_trkseek, afs.fs_rps); printf("ntrak\t%d\tnsect\t%d\tnpsect\t%d\tspc\t%d\n", afs.fs_ntrak, afs.fs_nsect, afs.fs_npsect, afs.fs_spc); printf("symlinklen %d\ttrackskew %d\tinterleave %d\tcontigsumsize %d\n", afs.fs_maxsymlinklen, afs.fs_trackskew, afs.fs_interleave, afs.fs_contigsumsize); printf("nindir\t%d\tinopb\t%d\tnspf\t%d\n", afs.fs_nindir, afs.fs_inopb, afs.fs_nspf); printf("sblkno\t%d\tcblkno\t%d\tiblkno\t%d\tdblkno\t%d\n", afs.fs_sblkno, afs.fs_cblkno, afs.fs_iblkno, afs.fs_dblkno); printf("sbsize\t%d\tcgsize\t%d\tcgoffset %d\tcgmask\t0x%08x\n", afs.fs_sbsize, afs.fs_cgsize, afs.fs_cgoffset, afs.fs_cgmask); printf("csaddr\t%d\tcssize\t%d\tshift\t%d\tmask\t0x%08x\n", afs.fs_csaddr, afs.fs_cssize, afs.fs_csshift, afs.fs_csmask); printf("cgrotor\t%d\tfmod\t%d\tronly\t%d\tclean\t%d\n", afs.fs_cgrotor, afs.fs_fmod, afs.fs_ronly, afs.fs_clean); if (afs.fs_cpc != 0) printf("blocks available in each of %d rotational positions", afs.fs_nrpos); else printf("(no rotational position table)\n"); for (c = 0; c < afs.fs_cpc; c++) { printf("\ncylinder number %d:", c); for (i = 0; i < afs.fs_nrpos; i++) { if (fs_postbl(&afs, c)[i] == -1) continue; printf("\n position %d:\t", i); for (j = fs_postbl(&afs, c)[i], k = 1; ; j += fs_rotbl(&afs)[j], k++) { printf("%5d", j); if (k % 12 == 0) printf("\n\t\t"); if (fs_rotbl(&afs)[j] == 0) break; } } } printf("\ncs[].cs_(nbfree,ndir,nifree,nffree):\n\t"); afs.fs_csp = calloc(1, afs.fs_cssize); for (i = 0, j = 0; i < afs.fs_cssize; i += afs.fs_bsize, j++) { size = afs.fs_cssize - i < afs.fs_bsize ? afs.fs_cssize - i : afs.fs_bsize; if (lseek(fd, (off_t)(fsbtodb(&afs, (afs.fs_csaddr + j * afs.fs_frag)) * dev_bsize), SEEK_SET) == (off_t)-1) goto err; if (read(fd, (char *)afs.fs_csp + i, size) != size) goto err; } for (i = 0; i < afs.fs_ncg; i++) { struct csum *cs = &afs.fs_cs(&afs, i); #if REV_ENDIAN_FS if (rev_endian) byte_swap_csum(cs); #endif /* REV_ENDIAN_FS */ if (i && i % 4 == 0) printf("\n\t"); printf("(%d,%d,%d,%d) ", cs->cs_nbfree, cs->cs_ndir, cs->cs_nifree, cs->cs_nffree); } printf("\n"); if (afs.fs_ncyl % afs.fs_cpg) { printf("cylinders in last group %d\n", i = afs.fs_ncyl % afs.fs_cpg); printf("blocks in last group %d\n", i * afs.fs_spc / NSPB(&afs)); } printf("\n"); for (i = 0; i < afs.fs_ncg; i++) if (dumpcg(name, fd, i)) goto err; (void)close(fd); return (0); err: if (fd != -1) (void)close(fd); warn("%s", name); return (1); }; int dumpcg(name, fd, c) char *name; int fd, c; { off_t cur; int i, j; printf("\ncg %d:\n", c); if ((cur = lseek(fd, (off_t)(fsbtodb(&afs, cgtod(&afs, c)) * dev_bsize), SEEK_SET)) == (off_t)-1) return (1); if (read(fd, &acg, afs.fs_bsize) != afs.fs_bsize) { warnx("%s: error reading cg", name); return (1); } #if REV_ENDIAN_FS if (rev_endian) { byte_swap_cgin(&acg, &afs); } #endif /* REV_ENDIAN_FS */ printf("magic\t%x\ttell\t%qx\ttime\t%s", afs.fs_postblformat == FS_42POSTBLFMT ? ((struct ocg *)&acg)->cg_magic : acg.cg_magic, cur, ctime(&acg.cg_time)); printf("cgx\t%d\tncyl\t%d\tniblk\t%d\tndblk\t%d\n", acg.cg_cgx, acg.cg_ncyl, acg.cg_niblk, acg.cg_ndblk); printf("nbfree\t%d\tndir\t%d\tnifree\t%d\tnffree\t%d\n", acg.cg_cs.cs_nbfree, acg.cg_cs.cs_ndir, acg.cg_cs.cs_nifree, acg.cg_cs.cs_nffree); printf("rotor\t%d\tirotor\t%d\tfrotor\t%d\nfrsum", acg.cg_rotor, acg.cg_irotor, acg.cg_frotor); for (i = 1, j = 0; i < afs.fs_frag; i++) { printf("\t%d", acg.cg_frsum[i]); j += i * acg.cg_frsum[i]; } printf("\nsum of frsum: %d", j); if (afs.fs_contigsumsize > 0) { for (i = 1; i < afs.fs_contigsumsize; i++) { if ((i - 1) % 8 == 0) printf("\nclusters %d-%d:", i, afs.fs_contigsumsize - 1 < i + 7 ? afs.fs_contigsumsize - 1 : i + 7); printf("\t%d", cg_clustersum(&acg)[i]); } printf("\nclusters size %d and over: %d\n", afs.fs_contigsumsize, cg_clustersum(&acg)[afs.fs_contigsumsize]); printf("clusters free:\t"); pbits(cg_clustersfree(&acg), acg.cg_nclusterblks); } else printf("\n"); printf("iused:\t"); pbits(cg_inosused(&acg), afs.fs_ipg); printf("free:\t"); pbits(cg_blksfree(&acg), afs.fs_fpg); printf("b:\n"); for (i = 0; i < afs.fs_cpg; i++) { if (cg_blktot(&acg)[i] == 0) continue; printf(" c%d:\t(%d)\t", i, cg_blktot(&acg)[i]); for (j = 0; j < afs.fs_nrpos; j++) { if (afs.fs_cpc > 0 && fs_postbl(&afs, i % afs.fs_cpc)[j] == -1) continue; printf(" %d", cg_blks(&afs, &acg, i)[j]); } printf("\n"); } return (0); }; void pbits(vp, max) register void *vp; int max; { register int i; register char *p; int count, j; for (count = i = 0, p = vp; i < max; i++) if (isset(p, i)) { if (count) printf(",%s", count % 6 ? " " : "\n\t"); count++; printf("%d", i); j = i; while ((i+1) diskdev_cmds-332.25/dumpfs.tproj/Makefile.postamble0000644000000000000000000000023507200107626021146 0ustar rootwheelafter_install:: install -m 755 -o root -g wheel -d $(DSTROOT)/usr/share/man/man8 install -m 644 -o root -g wheel -c dumpfs.8 $(DSTROOT)/usr/share/man/man8 diskdev_cmds-332.25/dumpfs.tproj/Makefile.preamble0000644000000000000000000000014510216156236020751 0ustar rootwheelOTHER_GENERATED_OFILES = $(VERS_OFILE) -include ../Makefile.include OTHER_CFLAGS = -DREV_ENDIAN_FS=1 diskdev_cmds-332.25/dumpfs.tproj/PB.project0000644000000000000000000000213207200107626017410 0ustar rootwheel{ APPCLASS = NSApplication; FILESTABLE = { CLASSES = (); FRAMEWORKS = (); H_FILES = (ufs_byte_order.h); M_FILES = (); OTHER_LIBS = (); OTHER_LINKED = (dumpfs.c, ufs_byte_order.c); OTHER_SOURCES = (Makefile.preamble, Makefile.postamble, Makefile, Makefile.dist, dumpfs.8); PRECOMPILED_HEADERS = (); PROJECT_HEADERS = (); PUBLIC_HEADERS = (); SUBPROJECTS = (); }; LANGUAGE = English; LOCALIZABLE_FILES = {}; NEXTSTEP_INSTALLDIR = /sbin; NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; NEXTSTEP_MAINNIB = dumpfs; NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; PDO_UNIX_INSTALLDIR = /sbin; PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; PDO_UNIX_MAINNIB = dumpfs; PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; PROJECTNAME = dumpfs; PROJECTTYPE = Tool; PROJECTVERSION = 2.8; WINDOWS_INSTALLDIR = /sbin; WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; WINDOWS_MAINNIB = dumpfs; WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; } diskdev_cmds-332.25/dumpfs.tproj/ufs_byte_order.c0000644000000000000000000002374210267354542020720 0ustar rootwheel/* * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights * Reserved. This file contains Original Code and/or Modifications of * Original Code as defined in and that are subject to the Apple Public * Source License Version 1.0 (the 'License'). You may not use this file * except in compliance with the License. Please obtain a copy of the * License at http://www.apple.com/publicsource and read it before using * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License." * * @APPLE_LICENSE_HEADER_END@ */ /* Copyright 1998 Apple Computer, Inc. * * UFS byte swapping routines to make a big endian file system useful on a * little endian machine. * * HISTORY * * 16 Feb 1998 A. Ramesh at Apple * Rhapsody version created. */ #include #include #include #include #include #include "ufs_byte_order.h" #include #if 0 #define byte_swap_longlong(thing) ((thing) = NXSwapBigLongLongToHost(thing)) #define byte_swap_int(thing) ((thing) = NXSwapBigLongToHost(thing)) #define byte_swap_short(thing) ((thing) = NXSwapBigShortToHost(thing)) #else #define byte_swap_longlong(thing) ((thing) = NXSwapLongLong(thing)) #define byte_swap_int(thing) ((thing) = NXSwapLong(thing)) #define byte_swap_short(thing) ((thing) = NXSwapShort(thing)) #endif void byte_swap_longlongs(unsigned long long *array, int count) { register unsigned long long i; for (i = 0; i < count; i++) byte_swap_longlong(array[i]); } void byte_swap_ints(int *array, int count) { register int i; for (i = 0; i < count; i++) byte_swap_int(array[i]); } void byte_swap_shorts(short *array, int count) { register int i; for (i = 0; i < count; i++) byte_swap_short(array[i]); } void byte_swap_sbin(struct fs *sb) { u_int16_t *usptr; unsigned long size; byte_swap_ints(((int32_t *)&sb->fs_firstfield), 52); byte_swap_int(sb->fs_cgrotor); byte_swap_int(sb->fs_cpc); byte_swap_shorts((int16_t *)sb->fs_opostbl, sizeof(sb->fs_opostbl) / sizeof(int16_t)); byte_swap_int(sb->fs_avgfilesize); byte_swap_int(sb->fs_avgfpdir); byte_swap_ints((int32_t *)sb->fs_sparecon, sizeof(sb->fs_sparecon) / sizeof(int32_t)); byte_swap_ints((int32_t *)&sb->fs_contigsumsize, 3); byte_swap_longlongs((u_int64_t *)&sb->fs_maxfilesize,3); byte_swap_ints((int32_t *)&sb->fs_state, 6); /* Got these magic numbers from mkfs.c in newfs */ if (sb->fs_nrpos != 8 || sb->fs_cpc > 16) { usptr = (u_int16_t *)((u_int8_t *)(sb) + (sb)->fs_postbloff); size = sb->fs_cpc * sb->fs_nrpos; byte_swap_shorts(usptr,size); /* fs_postbloff */ } } void byte_swap_sbout(struct fs *sb) { u_int16_t *usptr; unsigned long size; /* Got these magic numbers from mkfs.c in newfs */ if (sb->fs_nrpos != 8 || sb->fs_cpc > 16) { usptr = (u_int16_t *)((u_int8_t *)(sb) + (sb)->fs_postbloff); size = sb->fs_cpc * sb->fs_nrpos; byte_swap_shorts(usptr,size); /* fs_postbloff */ } byte_swap_ints(((int32_t *)&sb->fs_firstfield), 52); byte_swap_int(sb->fs_cgrotor); byte_swap_int(sb->fs_cpc); byte_swap_shorts((int16_t *)sb->fs_opostbl, sizeof(sb->fs_opostbl) / sizeof(int16_t)); byte_swap_int(sb->fs_avgfilesize); byte_swap_int(sb->fs_avgfpdir); byte_swap_ints((int32_t *)sb->fs_sparecon, sizeof(sb->fs_sparecon) / sizeof(int32_t)); byte_swap_ints((int32_t *)&sb->fs_contigsumsize, 3); byte_swap_longlongs((u_int64_t *)&sb->fs_maxfilesize,3); byte_swap_ints((int32_t *)&sb->fs_state, 6); } void byte_swap_csum(struct csum *cs) { byte_swap_ints((int *) cs, sizeof(struct csum) / sizeof(int32_t)); } /* This is for the new 4.4 cylinder group block */ void byte_swap_cgin(struct cg *cg, struct fs * fs) { int32_t * ulptr; int16_t * usptr; int size; byte_swap_int(cg->cg_firstfield); byte_swap_int(cg->cg_magic); byte_swap_int(cg->cg_time); byte_swap_int(cg->cg_cgx); byte_swap_short(cg->cg_ncyl); byte_swap_short(cg->cg_niblk); byte_swap_int(cg->cg_ndblk); byte_swap_csum(&cg->cg_cs); byte_swap_int(cg->cg_rotor); byte_swap_int(cg->cg_frotor); byte_swap_int(cg->cg_irotor); byte_swap_ints(cg->cg_frsum, MAXFRAG); byte_swap_int(cg->cg_iusedoff); byte_swap_int(cg->cg_freeoff); byte_swap_int(cg->cg_nextfreeoff); byte_swap_int(cg->cg_clusteroff); byte_swap_int(cg->cg_nclusterblks); byte_swap_ints(cg->cg_sparecon, 13); byte_swap_int(cg->cg_btotoff); ulptr = ((int32_t *)((u_int8_t *)(cg) + (cg)->cg_btotoff)); size = fs->fs_cpg; byte_swap_ints(ulptr, size); /*cg_btotoff*/ byte_swap_int(cg->cg_boff); usptr = ((int16_t *)((u_int8_t *)(cg) + (cg)->cg_boff)); size = fs->fs_cpg * fs->fs_nrpos; byte_swap_shorts(usptr,size); /*cg_boff*/ byte_swap_int(cg->cg_clustersumoff); if ((unsigned int)fs->fs_contigsumsize > 0) { ulptr = ((int32_t *)((u_int8_t *)(cg) + (cg)->cg_clustersumoff)); size = (fs->fs_contigsumsize + 1); byte_swap_ints(ulptr, size); /*cg_clustersumoff*/ } } // This is for the new 4.4 cylinder group block void byte_swap_cgout(struct cg *cg, struct fs * fs) { int32_t * ulptr; int16_t * usptr; int size; byte_swap_int(cg->cg_firstfield); byte_swap_int(cg->cg_magic); byte_swap_int(cg->cg_time); byte_swap_int(cg->cg_cgx); byte_swap_short(cg->cg_ncyl); byte_swap_short(cg->cg_niblk); byte_swap_int(cg->cg_ndblk); byte_swap_csum(&cg->cg_cs); byte_swap_int(cg->cg_rotor); byte_swap_int(cg->cg_frotor); byte_swap_int(cg->cg_irotor); byte_swap_ints(cg->cg_frsum, MAXFRAG); byte_swap_int(cg->cg_freeoff); byte_swap_int(cg->cg_nextfreeoff); byte_swap_int(cg->cg_nclusterblks); byte_swap_ints(cg->cg_sparecon, 13); byte_swap_int(cg->cg_iusedoff); byte_swap_int(cg->cg_clusteroff); ulptr = ((int32_t *)((u_int8_t *)(cg) + (cg)->cg_btotoff)); size = fs->fs_cpg; byte_swap_ints(ulptr, size); /*cg_btotoff*/ byte_swap_int(cg->cg_btotoff); usptr = ((int16_t *)((u_int8_t *)(cg) + (cg)->cg_boff)); size = fs->fs_cpg * fs->fs_nrpos; byte_swap_shorts(usptr,size); /*cg_boff*/ byte_swap_int(cg->cg_boff); if ((unsigned int)fs->fs_contigsumsize > 0) { ulptr = ((int32_t *)((u_int8_t *)(cg) + (cg)->cg_clustersumoff)); size = (fs->fs_contigsumsize + 1); byte_swap_ints(ulptr, size); /*cg_clustersumoff*/ } byte_swap_int(cg->cg_clustersumoff); } /* This value should correspond to the value set in the ffs_mounts */ #define RESYMLNKLEN 60 void byte_swap_dinodecount(struct dinode *ep, int count, int writeout) { int i,numinodes; struct dinode *dp; dp = ep; numinodes = count/sizeof(struct dinode); for(i=0;idi_mode = NXSwapShort(di->di_mode); di->di_nlink = NXSwapShort(di->di_nlink); #ifdef LFS di->di_u.inumber = NXSwapLong(di->di_u.inumber); #else di->di_u.oldids[0] = NXSwapShort(di->di_u.oldids[0]); di->di_u.oldids[1] = NXSwapShort(di->di_u.oldids[1]); #endif di->di_size = NXSwapLongLong(di->di_size); di->di_atime = NXSwapLong(di->di_atime); di->di_atimensec = NXSwapLong(di->di_atimensec); di->di_mtime = NXSwapLong(di->di_mtime); di->di_mtimensec = NXSwapLong(di->di_mtimensec); di->di_ctime = NXSwapLong(di->di_ctime); di->di_ctimensec = NXSwapLong(di->di_ctimensec); if (((di->di_mode & IFMT) != IFLNK ) || (di->di_size > RESYMLNKLEN)) { for (i=0; i < NDADDR; i++) /* direct blocks */ di->di_db[i] = NXSwapLong(di->di_db[i]); for (i=0; i < NIADDR; i++) /* indirect blocks */ di->di_ib[i] = NXSwapLong(di->di_ib[i]); } di->di_flags = NXSwapLong(di->di_flags); di->di_blocks = NXSwapLong(di->di_blocks); di->di_gen = NXSwapLong(di->di_gen); di->di_uid = NXSwapLong(di->di_uid); di->di_gid = NXSwapLong(di->di_gid); di->di_spare[0] = NXSwapLong(di->di_spare[0]); di->di_spare[1] = NXSwapLong(di->di_spare[1]); } void byte_swap_dinode_out(struct dinode *di) { int i; int mode, inosize; mode = (di->di_mode & IFMT); inosize = di->di_size; di->di_mode = NXSwapShort(di->di_mode); di->di_nlink = NXSwapShort(di->di_nlink); #ifdef LFS di->di_u.inumber = NXSwapLong(di->di_u.inumber); #else di->di_u.oldids[0] = NXSwapShort(di->di_u.oldids[0]); di->di_u.oldids[1] = NXSwapShort(di->di_u.oldids[1]); #endif di->di_size = NXSwapLongLong(di->di_size); di->di_atime = NXSwapLong(di->di_atime); di->di_atimensec = NXSwapLong(di->di_atimensec); di->di_mtime = NXSwapLong(di->di_mtime); di->di_mtimensec = NXSwapLong(di->di_mtimensec); di->di_ctime = NXSwapLong(di->di_ctime); di->di_ctimensec = NXSwapLong(di->di_ctimensec); if ((mode != IFLNK) || (inosize > RESYMLNKLEN)) { for (i=0; i < NDADDR; i++) /* direct blocks */ di->di_db[i] = NXSwapLong(di->di_db[i]); for (i=0; i < NIADDR; i++) /* indirect blocks */ di->di_ib[i] = NXSwapLong(di->di_ib[i]); } di->di_flags = NXSwapLong(di->di_flags); di->di_blocks = NXSwapLong(di->di_blocks); di->di_gen = NXSwapLong(di->di_gen); di->di_uid = NXSwapLong(di->di_uid); di->di_gid = NXSwapLong(di->di_gid); di->di_spare[0] = NXSwapLong(di->di_spare[0]); di->di_spare[1] = NXSwapLong(di->di_spare[1]); } #if notdef /* [ */ void byte_swap_direct(struct direct *dirp) { byte_swap_int(dirp->d_ino); byte_swap_short(dirp->d_reclen); } void byte_swap_dirtemplate_in(struct dirtemplate *dirt) { byte_swap_int(dirt->dot_ino); byte_swap_short(dirt->dot_reclen); byte_swap_int(dirt->dotdot_ino); byte_swap_short(dirt->dotdot_reclen); } void byte_swap_minidir_in(struct direct *dirp) { byte_swap_int(dirp->d_ino); byte_swap_short(dirp->d_reclen); } #endif /* notdef ] */ diskdev_cmds-332.25/dumpfs.tproj/ufs_byte_order.h0000644000000000000000000000450710216156236020715 0ustar rootwheel/* * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights * Reserved. This file contains Original Code and/or Modifications of * Original Code as defined in and that are subject to the Apple Public * Source License Version 1.0 (the 'License'). You may not use this file * except in compliance with the License. Please obtain a copy of the * License at http://www.apple.com/publicsource and read it before using * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License." * * @APPLE_LICENSE_HEADER_END@ */ /* Copyright 1998 Apple Computer, Inc. * * UFS byte swapping routines to make a big endian file system useful on a * little endian machine. * * HISTORY * * 16 Feb 1998 A. Ramesh at Apple * Rhapsody version created. */ #ifndef _DUMPFS_BYTE_ORDER_H_ #define _DUMPFS_BYTE_ORDER_H_ extern int rev_endian; void byte_swap_longlongs __P((unsigned long long *, int)); void byte_swap_ints __P((int *, int)); void byte_swap_shorts __P((short *, int)); /* void byte_swap_superblock __P((struct fs *)); */ void byte_swap_sbin __P((struct fs *)); void byte_swap_sbout __P((struct fs *)); void byte_swap_csum __P((struct csum *)); void byte_swap_cgin __P((struct cg *, struct fs *)); void byte_swap_cgout __P((struct cg *, struct fs *)); /* void byte_swap_dinodes __P((struct bufarea *, int)); */ void byte_swap_dinodecount __P((struct dinode *, int, int)); void byte_swap_dinode_in __P((struct dinode *)); void byte_swap_dinode_out __P((struct dinode *)); /* void byte_swap_dir_block_in __P((struct bufarea *)); */ /* void byte_swap_dir_block_out __P((struct bufarea *)); */ /* void swapblock __P((struct bufarea *, int)); */ #if 0 void byte_swap_direct __P((struct direct *)); void byte_swap_dirtemplate_in __P((struct dirtemplate *)); void byte_swap_minidir_in __P((struct direct *)); #endif #endif /* _DUMPFS_BYTE_ORDER_H_ */ diskdev_cmds-332.25/edquota.tproj/0000755000000000000000000000000010640030223015653 5ustar rootwheeldiskdev_cmds-332.25/edquota.tproj/edquota.80000644000000000000000000001370510216156236017430 0ustar rootwheel.\" Copyright (c) 1983, 1990, 1993, 2002 .\" The Regents of the University of California. All rights reserved. .\" .\" This code is derived from software contributed to Berkeley by .\" Robert Elz at The University of Melbourne. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: .\" This product includes software developed by the University of .\" California, Berkeley and its contributors. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)edquota.8 8.2 (Berkeley) 4/27/95 .\" .Dd "March 28, 2002" .Dt EDQUOTA 8 .Os .Sh NAME .Nm edquota .Nd edit user quotas .Sh SYNOPSIS .Nm edquota .Op Fl u .Op Fl p Ar proto-username .Ar username ... .Nm edquota .Fl g .Op Fl p Ar proto-groupname .Ar groupname ... .Nm edquota .Fl t .Op Fl u .Nm edquota .Fl t .Fl g .Sh DESCRIPTION .Nm Edquota is a quota editor. By default, or if the .Fl u flag is specified, one or more users may be specified on the command line. For each user a temporary file is created with an ASCII representation of the current disk quotas for that user. The list of filesystems with user quotas is determined by scanning the mounted filesystems for a .Pa .quota.ops.user file located at its root. An editor is invoked on the ASCII file. The editor invoked is .Xr vi 1 unless the environment variable .Ev EDITOR specifies otherwise. .Pp The quotas may then be modified, new quotas added, etc. Setting a quota to zero indicates that no quota should be imposed. Setting a hard limit to one indicates that no allocations should be permitted. Setting a soft limit to one with a hard limit of zero indicates that allocations should be permitted on only a temporary basis (see .Fl t below). The current usage information in the file is for informational purposes; only the hard and soft limits can be changed. .Pp On leaving the editor, .Nm edquota reads the temporary file and modifies the binary quota files to reflect the changes made. The binary quota file, .Pa .quota.user is stored at the root of the filesystem. The default filename and root location for the user quotas cannot be overridden. .Pp If the .Fl p flag is specified, .Nm edquota will duplicate the quotas of the prototypical user specified for each user specified. This is the normal mechanism used to initialize quotas for groups of users. .Pp If the .Fl g flag is specified, .Nm edquota is invoked to edit the quotas of one or more groups specified on the command line. The list of filesystems with group quotas is determined by scanning the mounted filesystems for a .Pa .quota.ops.group file located at its root. Similarly, the binary quota file, .Pa .quota.group is stored at the root of the filesystem. The default filename and root location for group quotas cannot be overridden. The .Fl p flag can be specified in conjunction with the .Fl g flag to specify a prototypical group to be duplicated among the listed set of groups. .Pp Users are permitted to exceed their soft limits for a grace period that may be specified per filesystem. Once the grace period has expired, the soft limit is enforced as a hard limit. The default grace period for a filesystem is specified in .Pa /usr/include/sys/quota.h . The .Fl t flag can be used to change the grace period. By default, or when invoked with the .Fl u flag, the grace period is set for each filesystem with a .Pa .quota.ops.user file located at its root. When invoked with the .Fl g flag, the grace period is set for each filesystem with a .Pa .quota.ops.group file located at its root. The grace period may be specified in days, hours, minutes, or seconds. Setting a grace period to zero indicates that the default grace period should be imposed. Setting a grace period to one second indicates that no grace period should be granted. .Pp Only the super-user may edit quotas. .Sh FILES Each of the following quota files is located at the root of the mounted filesystem. The mount option files are empty files whose existence indicates that quotas are to be enabled for that filesystem. The binary data files will be created by edquota, if they don't already exist. .Pp .Bl -tag -width .quota.ops.group -compact .It Pa .quota.user data file containing user quotas .It Pa .quota.group data file containing group quotas .It Pa .quota.ops.user mount option file used to enable user quotas .It Pa .quota.ops.group mount option file used to enable group quotas .El .Sh SEE ALSO .Xr quota 1 , .Xr quotactl 2 , .Xr quotacheck 8 , .Xr quotaon 8 , .Xr repquota 8 .Sh DIAGNOSTICS Various messages about inaccessible files; self-explanatory. diskdev_cmds-332.25/edquota.tproj/edquota.c0000644000000000000000000007437610311456604017514 0ustar rootwheel/* * Copyright (c) 2002-2005 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * The contents of this file constitute Original Code as defined in and * are subject to the Apple Public Source License Version 1.1 (the * "License"). You may not use this file except in compliance with the * License. Please obtain a copy of the License at * http://www.apple.com/publicsource and read it before using this file. * * This Original Code and all software distributed under the License are * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License. * * @APPLE_LICENSE_HEADER_END@ */ /* * Copyright (c) 1980, 1990, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Robert Elz at The University of Melbourne. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef lint static char copyright[] = "@(#) Copyright (c) 1980, 1990, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint static char sccsid[] = "@(#)edquota.c 8.3 (Berkeley) 4/27/95"; #endif /* not lint */ /* * Disk quota editor. */ #include #include #include #ifdef __APPLE__ #include #endif /* __APPLE__ */ #include #include #include #include #include #include #include #include #include #include #include #include #include "pathnames.h" #ifdef __APPLE__ #include #endif /* __APPLE__ */ char *qfname = QUOTAFILENAME; char *qfextension[] = INITQFNAMES; char *quotagroup = QUOTAGROUP; char tmpfil[] = _PATH_TMP; #ifdef __APPLE__ u_int32_t quotamagic[MAXQUOTAS] = INITQMAGICS; #endif /* __APPLE__ */ struct quotause { struct quotause *next; long flags; struct dqblk dqblk; char fsname[MAXPATHLEN + 1]; char qfname[1]; /* actually longer */ } *getprivs(); #define FOUND 0x01 int alldigits __P((char *)); int cvtatos __P((time_t, char *, time_t *)); int editit __P((char *)); void freeprivs __P((struct quotause *)); int getentry __P((char *, int)); int hasquota __P((struct statfs *, int, char **)); void putprivs __P((long, int, struct quotause *)); int readprivs __P((struct quotause *, int)); int readtimes __P((struct quotause *, int)); void usage __P((void)); int writeprivs __P((struct quotause *, int, char *, int)); int writetimes __P((struct quotause *, int, int)); #ifdef __APPLE__ int qfinit(int, struct statfs *, int); int qflookup(int, u_long, int, struct dqblk *); int qfupdate(int, u_long, int, struct dqblk *); #endif /* __APPLE__ */ int main(argc, argv) register char **argv; int argc; { register struct quotause *qup, *protoprivs, *curprivs; extern char *optarg; extern int optind; register long id, protoid; register int quotatype, tmpfd; char *protoname = NULL, ch; int tflag = 0, pflag = 0; if (argc < 2) usage(); if (getuid()) { fprintf(stderr, "edquota: permission denied\n"); exit(1); } quotatype = USRQUOTA; while ((ch = getopt(argc, argv, "ugtp:")) != EOF) { switch(ch) { case 'p': protoname = optarg; pflag++; break; case 'g': quotatype = GRPQUOTA; break; case 'u': quotatype = USRQUOTA; break; case 't': tflag++; break; default: usage(); } } argc -= optind; argv += optind; if (pflag) { if ((protoid = getentry(protoname, quotatype)) == -1) exit(1); protoprivs = getprivs(protoid, quotatype); #ifdef __APPLE__ if (protoprivs == (struct quotause *) NULL) exit(0); #endif /* __APPLE__ */ for (qup = protoprivs; qup; qup = qup->next) { qup->dqblk.dqb_btime = 0; qup->dqblk.dqb_itime = 0; } while (argc-- > 0) { if ((id = getentry(*argv++, quotatype)) < 0) continue; putprivs(id, quotatype, protoprivs); } exit(0); } tmpfd = mkstemp(tmpfil); fchown(tmpfd, getuid(), getgid()); if (tflag) { protoprivs = getprivs(0, quotatype); #ifdef __APPLE__ if (protoprivs == (struct quotause *) NULL) exit(0); #endif /* __APPLE__ */ if (writetimes(protoprivs, tmpfd, quotatype) == 0) exit(1); if (editit(tmpfil)) { /* * Re-open tmpfil to be editor independent. */ close(tmpfd); tmpfd = open(tmpfil, O_RDWR, 0); if (tmpfd < 0) { freeprivs(protoprivs); unlink(tmpfil); exit(1); } if (readtimes(protoprivs, tmpfd)) putprivs(0, quotatype, protoprivs); } freeprivs(protoprivs); exit(0); } for ( ; argc > 0; argc--, argv++) { if ((id = getentry(*argv, quotatype)) == -1) continue; curprivs = getprivs(id, quotatype); #ifdef __APPLE__ if (curprivs == (struct quotause *) NULL) exit(0); #endif /* __APPLE__ */ if (writeprivs(curprivs, tmpfd, *argv, quotatype) == 0) { freeprivs(curprivs); continue; } if (editit(tmpfil)) { /* * Re-open tmpfil to be editor independent. */ close(tmpfd); tmpfd = open(tmpfil, O_RDWR, 0); if (tmpfd < 0) { freeprivs(curprivs); unlink(tmpfil); exit(1); } if (readprivs(curprivs, tmpfd)) putprivs(id, quotatype, curprivs); } freeprivs(curprivs); } close(tmpfd); unlink(tmpfil); exit(0); } void usage() { fprintf(stderr, "%s%s%s%s", "Usage: edquota [-u] [-p username] username ...\n", "\tedquota -g [-p groupname] groupname ...\n", "\tedquota [-u] -t\n", "\tedquota -g -t\n"); #ifdef __APPLE__ fprintf(stderr, "\nQuota file editing triggers only on filesystems with a\n"); fprintf(stderr, "%s.%s or %s.%s file located at its root.\n", QUOTAOPSNAME, qfextension[USRQUOTA], QUOTAOPSNAME, qfextension[GRPQUOTA]); #endif /* __APPLE__ */ exit(1); } /* * This routine converts a name for a particular quota type to * an identifier. This routine must agree with the kernel routine * getinoquota as to the interpretation of quota types. */ int getentry(name, quotatype) char *name; int quotatype; { struct passwd *pw; struct group *gr; if (alldigits(name)) return (atoi(name)); switch(quotatype) { case USRQUOTA: if (pw = getpwnam(name)) return (pw->pw_uid); fprintf(stderr, "%s: no such user\n", name); break; case GRPQUOTA: if (gr = getgrnam(name)) return (gr->gr_gid); fprintf(stderr, "%s: no such group\n", name); break; default: fprintf(stderr, "%d: unknown quota type\n", quotatype); break; } sleep(1); return (-1); } /* * Collect the requested quota information. */ #ifdef __APPLE__ struct quotause * getprivs(id, quotatype) register long id; int quotatype; { struct statfs *fst; register struct quotause *qup, *quptail; struct quotause *quphead; int qcmd, qupsize, fd; char *qfpathname; static int warned = 0; int nfst, i; extern int errno; quptail = quphead = (struct quotause *)0; qcmd = QCMD(Q_GETQUOTA, quotatype); nfst = getmntinfo(&fst, MNT_WAIT); if (nfst==0) { fprintf(stderr, "edquota: no mounted filesystems\n"); exit(1); } for (i=0; idqblk) != 0) { if (errno == EOPNOTSUPP && !warned) { warned++; fprintf(stderr, "Warning: %s\n", "Quotas are not compiled into this kernel"); sleep(3); } if ((fd = open(qfpathname, O_RDONLY)) < 0) { fd = open(qfpathname, O_RDWR|O_CREAT, 0640); if (fd < 0 && errno != ENOENT) { perror(qfpathname); free(qup); continue; } fprintf(stderr, "Creating quota file %s\n", qfpathname); sleep(3); (void) fchown(fd, getuid(), getentry(quotagroup, GRPQUOTA)); (void) fchmod(fd, 0640); if (qfinit(fd, &fst[i], quotatype)) { perror(qfpathname); close(fd); free(qup); continue; } } if (qflookup(fd, id, quotatype, &qup->dqblk) != 0) { fprintf(stderr, "edquota: lookup error in "); perror(qfpathname); close(fd); free(qup); continue; } close(fd); } strcpy(qup->qfname, qfpathname); strcpy(qup->fsname, fst[i].f_mntonname); if (quphead == NULL) quphead = qup; else quptail->next = qup; quptail = qup; qup->next = 0; } return (quphead); } #else struct quotause * getprivs(id, quotatype) register long id; int quotatype; { register struct fstab *fs; register struct quotause *qup, *quptail; struct quotause *quphead; int qcmd, qupsize, fd; char *qfpathname; static int warned = 0; extern int errno; setfsent(); quphead = (struct quotause *)0; qcmd = QCMD(Q_GETQUOTA, quotatype); while (fs = getfsent()) { if (strcmp(fs->fs_vfstype, "ufs")) continue; if (!hasquota(fs, quotatype, &qfpathname)) continue; qupsize = sizeof(*qup) + strlen(qfpathname); if ((qup = (struct quotause *)malloc(qupsize)) == NULL) { fprintf(stderr, "edquota: out of memory\n"); exit(2); } if (quotactl(fs->fs_file, qcmd, id, &qup->dqblk) != 0) { if (errno == EOPNOTSUPP && !warned) { warned++; fprintf(stderr, "Warning: %s\n", "Quotas are not compiled into this kernel"); sleep(3); } if ((fd = open(qfpathname, O_RDONLY)) < 0) { fd = open(qfpathname, O_RDWR|O_CREAT, 0640); if (fd < 0 && errno != ENOENT) { perror(qfpathname); free(qup); continue; } fprintf(stderr, "Creating quota file %s\n", qfpathname); sleep(3); (void) fchown(fd, getuid(), getentry(quotagroup, GRPQUOTA)); (void) fchmod(fd, 0640); } lseek(fd, (off_t)(id * sizeof(struct dqblk)), L_SET); switch (read(fd, &qup->dqblk, sizeof(struct dqblk))) { case 0: /* EOF */ /* * Convert implicit 0 quota (EOF) * into an explicit one (zero'ed dqblk) */ bzero((caddr_t)&qup->dqblk, sizeof(struct dqblk)); break; case sizeof(struct dqblk): /* OK */ break; default: /* ERROR */ fprintf(stderr, "edquota: read error in "); perror(qfpathname); close(fd); free(qup); continue; } close(fd); } strcpy(qup->qfname, qfpathname); strcpy(qup->fsname, fs->fs_file); if (quphead == NULL) quphead = qup; else quptail->next = qup; quptail = qup; qup->next = 0; } endfsent(); return (quphead); } #endif /* __APPLE */ #ifdef __APPLE__ #define ONEGIGABYTE (1024*1024*1024) /* * Initialize a new quota file. */ int qfinit(fd, fst, type) int fd; struct statfs *fst; int type; { struct dqfilehdr dqhdr = {0}; u_int64_t fs_size; int max = 0; /* * Calculate the size of the hash table from the size of * the file system. Note that the open addressing hashing * used by the quota file assumes that this table will not * be more than 90% full. */ fs_size = (u_int64_t)fst->f_blocks * (u_int64_t)fst->f_bsize; if (type == USRQUOTA) { max = QF_USERS_PER_GB * (fs_size / ONEGIGABYTE); if (max < QF_MIN_USERS) max = QF_MIN_USERS; else if (max > QF_MAX_USERS) max = QF_MAX_USERS; } else if (type == GRPQUOTA) { max = QF_GROUPS_PER_GB * (fs_size / ONEGIGABYTE); if (max < QF_MIN_GROUPS) max = QF_MIN_GROUPS; else if (max > QF_MAX_GROUPS) max = QF_MAX_GROUPS; } /* Round up to a power of 2 */ if (max && !powerof2(max)) { int x = max; max = 4; while (x>>1 != 1) { x = x >> 1; max = max << 1; } } (void) ftruncate(fd, (off_t)((max + 1) * sizeof(struct dqblk))); dqhdr.dqh_magic = OSSwapHostToBigInt32(quotamagic[type]); dqhdr.dqh_version = OSSwapHostToBigConstInt32(QF_VERSION); dqhdr.dqh_maxentries = OSSwapHostToBigInt32(max); dqhdr.dqh_btime = OSSwapHostToBigConstInt32(MAX_DQ_TIME); dqhdr.dqh_itime = OSSwapHostToBigConstInt32(MAX_IQ_TIME); memmove(dqhdr.dqh_string, QF_STRING_TAG, strlen(QF_STRING_TAG)); (void) lseek(fd, 0, L_SET); (void) write(fd, &dqhdr, sizeof(dqhdr)); return (0); } /* * Lookup an entry in a quota file. */ int qflookup(fd, id, type, dqbp) int fd; u_long id; int type; struct dqblk *dqbp; { struct dqfilehdr dqhdr; int i, skip, last, m; u_long mask; bzero(dqbp, sizeof(struct dqblk)); if (id == 0) return (0); lseek(fd, 0, L_SET); if (read(fd, &dqhdr, sizeof(struct dqfilehdr)) != sizeof(struct dqfilehdr)) return (-1); /* Sanity check the quota file header. */ if ((OSSwapBigToHostInt32(dqhdr.dqh_magic) != quotamagic[type]) || (OSSwapBigToHostInt32(dqhdr.dqh_version) > 1) || (!powerof2(OSSwapBigToHostInt32(dqhdr.dqh_maxentries)))) { fprintf(stderr, "quota: invalid quota file header\n"); return (-1); } m = OSSwapBigToHostInt32(dqhdr.dqh_maxentries); mask = m - 1; i = dqhash1(id, dqhashshift(m), mask); skip = dqhash2(id, mask); for (last = (i + (m-1) * skip) & mask; i != last; i = (i + skip) & mask) { lseek(fd, dqoffset(i), L_SET); if (read(fd, dqbp, sizeof(struct dqblk)) < sizeof(struct dqblk)) return (-1); /* * Stop when an empty entry is found * or we encounter a matching id. */ if (dqbp->dqb_id == 0 || OSSwapBigToHostInt32(dqbp->dqb_id) == id) break; } /* Put data in host native byte order. */ dqbp->dqb_bhardlimit = OSSwapBigToHostInt64(dqbp->dqb_bhardlimit); dqbp->dqb_bsoftlimit = OSSwapBigToHostInt64(dqbp->dqb_bsoftlimit); dqbp->dqb_curbytes = OSSwapBigToHostInt64(dqbp->dqb_curbytes); dqbp->dqb_ihardlimit = OSSwapBigToHostInt32(dqbp->dqb_ihardlimit); dqbp->dqb_isoftlimit = OSSwapBigToHostInt32(dqbp->dqb_isoftlimit); dqbp->dqb_curinodes = OSSwapBigToHostInt32(dqbp->dqb_curinodes); dqbp->dqb_btime = OSSwapBigToHostInt32(dqbp->dqb_btime); dqbp->dqb_itime = OSSwapBigToHostInt32(dqbp->dqb_itime); dqbp->dqb_id = OSSwapBigToHostInt32(dqbp->dqb_id); return (0); } #endif /* __APPLE */ /* * Store the requested quota information. */ void putprivs(id, quotatype, quplist) long id; int quotatype; struct quotause *quplist; { register struct quotause *qup; int qcmd, fd; qcmd = QCMD(Q_SETQUOTA, quotatype); for (qup = quplist; qup; qup = qup->next) { if (quotactl(qup->fsname, qcmd, id, (char *)&qup->dqblk) == 0) continue; #ifdef __APPLE__ if ((fd = open(qup->qfname, O_RDWR)) < 0) { perror(qup->qfname); } else { if (qfupdate(fd, id, quotatype, &qup->dqblk) != 0) { fprintf(stderr, "edquota: "); perror(qup->qfname); } #else if ((fd = open(qup->qfname, O_WRONLY)) < 0) { perror(qup->qfname); } else { lseek(fd, (off_t)(id * (long)sizeof (struct dqblk)), L_SET); if (write(fd, &qup->dqblk, sizeof (struct dqblk)) != sizeof (struct dqblk)) { fprintf(stderr, "edquota: "); perror(qup->qfname); } #endif /* __APPLE */ close(fd); } } } #ifdef __APPLE__ /* * Update an entry in a quota file. */ int qfupdate(fd, id, type, dqbp) int fd; u_long id; int type; struct dqblk *dqbp; { struct dqblk dqbuf; struct dqfilehdr dqhdr; int i, skip, last, m; u_long mask; if (id == 0) return (0); lseek(fd, 0, L_SET); if (read(fd, &dqhdr, sizeof(struct dqfilehdr)) != sizeof(struct dqfilehdr)) return (-1); /* Sanity check the quota file header. */ if ((OSSwapBigToHostInt32(dqhdr.dqh_magic) != quotamagic[type]) || (OSSwapBigToHostInt32(dqhdr.dqh_version) > QF_VERSION) || (!powerof2(OSSwapBigToHostInt32(dqhdr.dqh_maxentries)))) { fprintf(stderr, "quota: invalid quota file header\n"); return (EINVAL); } m = OSSwapBigToHostInt32(dqhdr.dqh_maxentries); mask = m - 1; i = dqhash1(id, dqhashshift(m), mask); skip = dqhash2(id, mask); for (last = (i + (m-1) * skip) & mask; i != last; i = (i + skip) & mask) { lseek(fd, dqoffset(i), L_SET); if (read(fd, &dqbuf, sizeof(struct dqblk)) < sizeof(struct dqblk)) return (-1); /* * Stop when an empty entry is found * or we encounter a matching id. */ if (dqbuf.dqb_id == 0 || OSSwapBigToHostInt32(dqbuf.dqb_id) == id) { /* Convert buffer to big endian before writing. */ dqbp->dqb_bhardlimit = OSSwapHostToBigInt64(dqbp->dqb_bhardlimit); dqbp->dqb_bsoftlimit = OSSwapHostToBigInt64(dqbp->dqb_bsoftlimit); dqbp->dqb_curbytes = OSSwapHostToBigInt64(dqbp->dqb_curbytes); dqbp->dqb_ihardlimit = OSSwapHostToBigInt32(dqbp->dqb_ihardlimit); dqbp->dqb_isoftlimit = OSSwapHostToBigInt32(dqbp->dqb_isoftlimit); dqbp->dqb_curinodes = OSSwapHostToBigInt32(dqbp->dqb_curinodes); dqbp->dqb_btime = OSSwapHostToBigInt32(dqbp->dqb_btime); dqbp->dqb_itime = OSSwapHostToBigInt32(dqbp->dqb_itime); dqbp->dqb_id = OSSwapHostToBigInt32(id); lseek(fd, dqoffset(i), L_SET); if (write(fd, dqbp, sizeof (struct dqblk)) != sizeof (struct dqblk)) { return (-1); } return (0); } } errno = ENOSPC; return (-1); } #endif /* __APPLE__ */ /* * Take a list of priviledges and get it edited. */ int editit(tmpfile) char *tmpfile; { long omask; int pid, stat; extern char *getenv(); omask = sigblock(sigmask(SIGINT)|sigmask(SIGQUIT)|sigmask(SIGHUP)); top: if ((pid = fork()) < 0) { extern int errno; if (errno == EPROCLIM) { fprintf(stderr, "You have too many processes\n"); return(0); } if (errno == EAGAIN) { sleep(1); goto top; } perror("fork"); return (0); } if (pid == 0) { register char *ed; sigsetmask(omask); setgid(getgid()); setuid(getuid()); if ((ed = getenv("EDITOR")) == (char *)0) ed = _PATH_VI; execlp(ed, ed, tmpfile, NULL); perror(ed); exit(1); } waitpid(pid, &stat, 0); sigsetmask(omask); if (!WIFEXITED(stat) || WEXITSTATUS(stat) != 0) return (0); return (1); } /* * Convert a quotause list to an ASCII file. */ int writeprivs(quplist, outfd, name, quotatype) struct quotause *quplist; int outfd; char *name; int quotatype; { register struct quotause *qup; FILE *fd; ftruncate(outfd, 0); lseek(outfd, 0, L_SET); if ((fd = fdopen(dup(outfd), "w")) == NULL) { fprintf(stderr, "edquota: "); perror(tmpfil); exit(1); } fprintf(fd, "Quotas for %s %s:\n", qfextension[quotatype], name); for (qup = quplist; qup; qup = qup->next) { #ifdef __APPLE__ fprintf(fd, "%s: %s %qd, limits (soft = %qd, hard = %qd)\n", qup->fsname, "1K blocks in use:", qup->dqblk.dqb_curbytes / 1024, qup->dqblk.dqb_bsoftlimit / 1024, qup->dqblk.dqb_bhardlimit / 1024); #else fprintf(fd, "%s: %s %d, limits (soft = %d, hard = %d)\n", qup->fsname, "blocks in use:", dbtob(qup->dqblk.dqb_curblocks) / 1024, dbtob(qup->dqblk.dqb_bsoftlimit) / 1024, dbtob(qup->dqblk.dqb_bhardlimit) / 1024); #endif /* __APPLE__ */ fprintf(fd, "%s %d, limits (soft = %d, hard = %d)\n", "\tinodes in use:", qup->dqblk.dqb_curinodes, qup->dqblk.dqb_isoftlimit, qup->dqblk.dqb_ihardlimit); } fclose(fd); return (1); } /* * Merge changes to an ASCII file into a quotause list. */ int readprivs(quplist, infd) struct quotause *quplist; int infd; { register struct quotause *qup; FILE *fd; int cnt; register char *cp; struct dqblk dqblk; char *fsp, line1[BUFSIZ], line2[BUFSIZ]; lseek(infd, 0, L_SET); fd = fdopen(dup(infd), "r"); if (fd == NULL) { fprintf(stderr, "Can't re-read temp file!!\n"); return (0); } /* * Discard title line, then read pairs of lines to process. */ (void) fgets(line1, sizeof (line1), fd); while (fgets(line1, sizeof (line1), fd) != NULL && fgets(line2, sizeof (line2), fd) != NULL) { if ((fsp = strtok(line1, " \t:")) == NULL) { fprintf(stderr, "%s: bad format\n", line1); return (0); } if ((cp = strtok((char *)0, "\n")) == NULL) { fprintf(stderr, "%s: %s: bad format\n", fsp, &fsp[strlen(fsp) + 1]); return (0); } #ifdef __APPLE__ /* We expect input to be in 1K blocks */ cnt = sscanf(cp, " 1K blocks in use: %qd, limits (soft = %qd, hard = %qd)", &dqblk.dqb_curbytes, &dqblk.dqb_bsoftlimit, &dqblk.dqb_bhardlimit); if (cnt != 3) { fprintf(stderr, "%s:%s: bad format\n", fsp, cp); return (0); } /* convert default 1K blocks to byte count */ dqblk.dqb_curbytes = dqblk.dqb_curbytes * 1024; dqblk.dqb_bsoftlimit = dqblk.dqb_bsoftlimit * 1024; dqblk.dqb_bhardlimit = dqblk.dqb_bhardlimit * 1024; #else cnt = sscanf(cp, " blocks in use: %d, limits (soft = %d, hard = %d)", &dqblk.dqb_curblocks, &dqblk.dqb_bsoftlimit, &dqblk.dqb_bhardlimit); if (cnt != 3) { fprintf(stderr, "%s:%s: bad format\n", fsp, cp); return (0); } dqblk.dqb_curblocks = btodb(dqblk.dqb_curblocks * 1024); dqblk.dqb_bsoftlimit = btodb(dqblk.dqb_bsoftlimit * 1024); dqblk.dqb_bhardlimit = btodb(dqblk.dqb_bhardlimit * 1024); #endif /* __APPLE__ */ if ((cp = strtok(line2, "\n")) == NULL) { fprintf(stderr, "%s: %s: bad format\n", fsp, line2); return (0); } cnt = sscanf(cp, "\tinodes in use: %d, limits (soft = %d, hard = %d)", &dqblk.dqb_curinodes, &dqblk.dqb_isoftlimit, &dqblk.dqb_ihardlimit); if (cnt != 3) { fprintf(stderr, "%s: %s: bad format\n", fsp, line2); return (0); } for (qup = quplist; qup; qup = qup->next) { if (strcmp(fsp, qup->fsname)) continue; /* * Cause time limit to be reset when the quota * is next used if previously had no soft limit * or were under it, but now have a soft limit * and are over it. */ #ifdef __APPLE__ if (dqblk.dqb_bsoftlimit && qup->dqblk.dqb_curbytes >= dqblk.dqb_bsoftlimit && (qup->dqblk.dqb_bsoftlimit == 0 || qup->dqblk.dqb_curbytes < qup->dqblk.dqb_bsoftlimit)) qup->dqblk.dqb_btime = 0; #else if (dqblk.dqb_bsoftlimit && qup->dqblk.dqb_curblocks >= dqblk.dqb_bsoftlimit && (qup->dqblk.dqb_bsoftlimit == 0 || qup->dqblk.dqb_curblocks < qup->dqblk.dqb_bsoftlimit)) qup->dqblk.dqb_btime = 0; #endif /* __APPLE__ */ if (dqblk.dqb_isoftlimit && qup->dqblk.dqb_curinodes >= dqblk.dqb_isoftlimit && (qup->dqblk.dqb_isoftlimit == 0 || qup->dqblk.dqb_curinodes < qup->dqblk.dqb_isoftlimit)) qup->dqblk.dqb_itime = 0; qup->dqblk.dqb_bsoftlimit = dqblk.dqb_bsoftlimit; qup->dqblk.dqb_bhardlimit = dqblk.dqb_bhardlimit; qup->dqblk.dqb_isoftlimit = dqblk.dqb_isoftlimit; qup->dqblk.dqb_ihardlimit = dqblk.dqb_ihardlimit; qup->flags |= FOUND; #ifdef __APPLE__ if (dqblk.dqb_curbytes == qup->dqblk.dqb_curbytes && dqblk.dqb_curinodes == qup->dqblk.dqb_curinodes) break; #else if (dqblk.dqb_curblocks == qup->dqblk.dqb_curblocks && dqblk.dqb_curinodes == qup->dqblk.dqb_curinodes) break; #endif /* __APPLE__ */ fprintf(stderr, "%s: cannot change current allocation\n", fsp); break; } } fclose(fd); /* * Disable quotas for any filesystems that have not been found. */ for (qup = quplist; qup; qup = qup->next) { if (qup->flags & FOUND) { qup->flags &= ~FOUND; continue; } qup->dqblk.dqb_bsoftlimit = 0; qup->dqblk.dqb_bhardlimit = 0; qup->dqblk.dqb_isoftlimit = 0; qup->dqblk.dqb_ihardlimit = 0; } return (1); } /* * Convert a quotause list to an ASCII file of grace times. */ int writetimes(quplist, outfd, quotatype) struct quotause *quplist; int outfd; int quotatype; { register struct quotause *qup; char *cvtstoa(); FILE *fd; ftruncate(outfd, 0); lseek(outfd, 0, L_SET); if ((fd = fdopen(dup(outfd), "w")) == NULL) { fprintf(stderr, "edquota: "); perror(tmpfil); exit(1); } fprintf(fd, "Time units may be: days, hours, minutes, or seconds\n"); fprintf(fd, "Grace period before enforcing soft limits for %ss:\n", qfextension[quotatype]); for (qup = quplist; qup; qup = qup->next) { fprintf(fd, "%s: block grace period: %s, ", qup->fsname, cvtstoa(qup->dqblk.dqb_btime)); fprintf(fd, "file grace period: %s\n", cvtstoa(qup->dqblk.dqb_itime)); } fclose(fd); return (1); } /* * Merge changes of grace times in an ASCII file into a quotause list. */ int readtimes(quplist, infd) struct quotause *quplist; int infd; { register struct quotause *qup; FILE *fd; int cnt; register char *cp; time_t itime, btime, iseconds, bseconds; char *fsp, bunits[10], iunits[10], line1[BUFSIZ]; lseek(infd, 0, L_SET); fd = fdopen(dup(infd), "r"); if (fd == NULL) { fprintf(stderr, "Can't re-read temp file!!\n"); return (0); } /* * Discard two title lines, then read lines to process. */ (void) fgets(line1, sizeof (line1), fd); (void) fgets(line1, sizeof (line1), fd); while (fgets(line1, sizeof (line1), fd) != NULL) { if ((fsp = strtok(line1, " \t:")) == NULL) { fprintf(stderr, "%s: bad format\n", line1); return (0); } if ((cp = strtok((char *)0, "\n")) == NULL) { fprintf(stderr, "%s: %s: bad format\n", fsp, &fsp[strlen(fsp) + 1]); return (0); } cnt = sscanf(cp, " block grace period: %d %s file grace period: %d %s", &btime, bunits, &itime, iunits); if (cnt != 4) { fprintf(stderr, "%s:%s: bad format\n", fsp, cp); return (0); } if (cvtatos(btime, bunits, &bseconds) == 0) return (0); if (cvtatos(itime, iunits, &iseconds) == 0) return (0); for (qup = quplist; qup; qup = qup->next) { if (strcmp(fsp, qup->fsname)) continue; qup->dqblk.dqb_btime = bseconds; qup->dqblk.dqb_itime = iseconds; qup->flags |= FOUND; break; } } fclose(fd); /* * reset default grace periods for any filesystems * that have not been found. */ for (qup = quplist; qup; qup = qup->next) { if (qup->flags & FOUND) { qup->flags &= ~FOUND; continue; } qup->dqblk.dqb_btime = 0; qup->dqblk.dqb_itime = 0; } return (1); } /* * Convert seconds to ASCII times. */ char * cvtstoa(time) time_t time; { static char buf[20]; if (time % (24 * 60 * 60) == 0) { time /= 24 * 60 * 60; sprintf(buf, "%d day%s", (int)time, time == 1 ? "" : "s"); } else if (time % (60 * 60) == 0) { time /= 60 * 60; sprintf(buf, "%d hour%s", (int)time, time == 1 ? "" : "s"); } else if (time % 60 == 0) { time /= 60; sprintf(buf, "%d minute%s", (int)time, time == 1 ? "" : "s"); } else sprintf(buf, "%d second%s", (int)time, time == 1 ? "" : "s"); return (buf); } /* * Convert ASCII input times to seconds. */ int cvtatos(time, units, seconds) time_t time; char *units; time_t *seconds; { if (bcmp(units, "second", 6) == 0) *seconds = time; else if (bcmp(units, "minute", 6) == 0) *seconds = time * 60; else if (bcmp(units, "hour", 4) == 0) *seconds = time * 60 * 60; else if (bcmp(units, "day", 3) == 0) *seconds = time * 24 * 60 * 60; else { printf("%s: bad units, specify %s\n", units, "days, hours, minutes, or seconds"); return (0); } return (1); } /* * Free a list of quotause structures. */ void freeprivs(quplist) struct quotause *quplist; { register struct quotause *qup, *nextqup; for (qup = quplist; qup; qup = nextqup) { nextqup = qup->next; free(qup); } } /* * Check whether a string is completely composed of digits. */ int alldigits(s) register char *s; { register int c; c = *s++; do { if (!isdigit(c)) return (0); } while (c = *s++); return (1); } /* * Check to see if a particular quota is to be enabled. */ #ifdef __APPLE__ int hasquota(fst, type, qfnamep) register struct statfs *fst; int type; char **qfnamep; { struct stat sb; static char initname, usrname[100], grpname[100]; static char buf[BUFSIZ]; if (!initname) { sprintf(usrname, "%s%s", qfextension[USRQUOTA], qfname); sprintf(grpname, "%s%s", qfextension[GRPQUOTA], qfname); initname = 1; } /* We only support the default path to the on disk quota files. */ (void)sprintf(buf, "%s/%s.%s", fst->f_mntonname, QUOTAOPSNAME, qfextension[type] ); if (stat(buf, &sb) != 0) { /* There appears to be no mount option file */ return(0); } (void) sprintf(buf, "%s/%s.%s", fst->f_mntonname, qfname, qfextension[type]); *qfnamep = buf; return (1); } #else hasquota(fs, type, qfnamep) register struct fstab *fs; int type; char **qfnamep; { register char *opt; char *cp, *index(), *strtok(); static char initname, usrname[100], grpname[100]; static char buf[BUFSIZ]; if (!initname) { sprintf(usrname, "%s%s", qfextension[USRQUOTA], qfname); sprintf(grpname, "%s%s", qfextension[GRPQUOTA], qfname); initname = 1; } strcpy(buf, fs->fs_mntops); for (opt = strtok(buf, ","); opt; opt = strtok(NULL, ",")) { if (cp = index(opt, '=')) *cp++ = '\0'; if (type == USRQUOTA && strcmp(opt, usrname) == 0) break; if (type == GRPQUOTA && strcmp(opt, grpname) == 0) break; } if (!opt) return (0); if (cp) { *qfnamep = cp; return (1); } (void) sprintf(buf, "%s/%s.%s", fs->fs_file, qfname, qfextension[type]); *qfnamep = buf; return (1); } #endif /* __APPLE */ diskdev_cmds-332.25/edquota.tproj/Makefile0000644000000000000000000000216006712726561017340 0ustar rootwheel# # Generated by the NeXT Project Builder. # # NOTE: Do NOT change this file -- Project Builder maintains it. # # Put all of your customizations in files called Makefile.preamble # and Makefile.postamble (both optional), and Makefile will include them. # NAME = edquota PROJECTVERSION = 2.8 PROJECT_TYPE = Tool HFILES = pathnames.h CFILES = edquota.c OTHERSRCS = Makefile.preamble Makefile Makefile.postamble edquota.8 MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles CODE_GEN_STYLE = DYNAMIC MAKEFILE = tool.make NEXTSTEP_INSTALLDIR = /usr/sbin WINDOWS_INSTALLDIR = /usr/sbin PDO_UNIX_INSTALLDIR = /usr/sbin LIBS = -ldisk DEBUG_LIBS = $(LIBS) PROF_LIBS = $(LIBS) NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/BUILD NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc NEXTSTEP_JAVA_COMPILER = /usr/bin/javac WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac include $(MAKEFILEDIR)/platform.make -include Makefile.preamble include $(MAKEFILEDIR)/$(MAKEFILE) -include Makefile.postamble -include Makefile.dependencies diskdev_cmds-332.25/edquota.tproj/Makefile.postamble0000644000000000000000000001176210216156236021323 0ustar rootwheel############################################################################### # NeXT Makefile.postamble Template # Copyright 1993, NeXT Computer, Inc. # # This Makefile is used for configuring the standard app makefiles associated # with ProjectBuilder. # # Use this template to set attributes for a project, sub-project, bundle, or # palette. Each node in the project's tree of sub-projects and bundles # should have it's own Makefile.preamble and Makefile.postamble. Additional # rules (e.g., after_install) that are defined by the developer should be # defined in this file. # ############################################################################### # # Here are the variables exported by the common "app" makefiles that can be # used in any customizations you make to the template below: # # PRODUCT_ROOT - Name of top-level app-wrapper (e.g., Webster.app) # OFILE_DIR - Directory into which .o object files are generated. # (Note that this name is calculated based on the target # architectures specified in Project Builder). # DERIVED_SRC_DIR - Directory used for all other derived files # ALL_CFLAGS - All the flags passed to the cc(1) driver for compilations # # NAME - name of application, bundle, subproject, palette, etc. # LANGUAGE - langage in which the project is written (default "English") # ENGLISH - boolean flag set iff $(LANGUAGE) = "English" # JAPANESE - boolean flag set iff $(LANGUAGE) = "Japanese" # LOCAL_RESOURCES - localized resources (e.g. nib's, images) of project # GLOBAL_RESOURCES - non-localized resources of project # PROJECTVERSION - version of ProjectBuilder that output Makefile # APPICON - application icon file # DOCICONS - dock icon files # ICONSECTIONS - Specifies icon sections when linking executable # # CLASSES - Class implementation files in project. # HFILES - Header files in project. # MFILES - Other Objective-C source files in project. # CFILES - Other C source files in project. # PSWFILES - .psw files in the project # PSWMFILES - .pswm files in the project # SUBPROJECTS - Subprojects of this project # BUNDLES - Bundle subprojects of this project # OTHERSRCS - Other miscellaneous sources of this project # OTHERLINKED - Source files not matching a standard source extention # # LIBS - Libraries to link with when making app target # DEBUG_LIBS - Libraries to link with when making debug target # PROF_LIBS - Libraries to link with when making profile target # OTHERLINKEDOFILES - Other relocatable files to (always) link in. # # APP_MAKEFILE_DIR - Directory in which to find generic set of Makefiles # MAKEFILEDIR - Directory in which to find $(MAKEFILE) # MAKEFILE - Top level mechanism Makefile (e.g., app.make, bundle.make) # INSTALLDIR - Directory app will be installed into by 'install' target # Change defaults assumed by the standard app makefiles here. Edit the # following default values as appropriate. (Note that if no Makefile.postamble # exists, these values will have defaults set in common.make). # Add Makefile.preamble, Makefile.postamble, and Makefile.dependencies here if # you would like changes to them to invalidate previous builds. The project # depends on $(MAKEFILES) so that changes to Makefiles will trigger a re-build. #MAKEFILES = Makefile # Optimization flag passed to compiler: #OPTIMIZATION_CFLAG = -O # Flags always passed to compiler: #COMMON_CFLAGS = $(PROJECT_SPECIFIC_CFLAGS) -g -Wall # Flags passed to compiler in normal 'app' compiles: #NORMAL_CFLAGS = $(COMMON_CFLAGS) $(OPTIMIZATION_CFLAG) # Flags passed to compiler in 'debug' compiles: #DEBUG_CFLAGS = $(COMMON_CFLAGS) -DDEBUG # Flags passed to compiler in 'profile' compiles #PROFILE_CFLAGS = $(COMMON_CFLAGS) -pg $(OPTIMIZATION_CFLAG) -DPROFILE # Flags passed to yacc #YFLAGS = -d # Ownership and permissions of files installed by 'install' target #INSTALL_AS_USER = root # User to chown app to #INSTALL_AS_GROUP = wheel # Group to chgrp app to #INSTALL_PERMISSIONS = # If set, 'install' chmod's executable to this # Options to strip for bundles, apps with bundles, and apps without bundles, # respectively. #RELOCATABLE_STRIP_OPTS = -x -u #DYLD_APP_STRIP_OPTS = -A -n #APP_STRIP_OPTS = #TOOL_STRIP_OPTS = #LIBRARY_STRIP_OPTS = -x -S # Note: -S strips debugging symbols # (Note: APP_STRIP_OPTS and TOOL_STRIP_OPTS default to empty, but # developers doing their own dynamic loading should set this to # $(DYLD_APP_STRIP_OPTS)). ######################################################################### # Put rules to extend the behavior of the standard Makefiles here. Typical # user-defined rules are before_install and after_install (please don't # redefine things like install or app, as they are owned by the top-level # Makefile API), which are rules that get invoked before and after the install # target runs. Such rules should be specified with the '::' syntax rather than # a single colon. after_install: install -m 755 -o root -g wheel -d $(DSTROOT)/usr/share/man/man8 install -m 644 -o root -g wheel -c edquota.8 $(DSTROOT)/usr/share/man/man8 diskdev_cmds-332.25/edquota.tproj/Makefile.preamble0000644000000000000000000001104106712726561021124 0ustar rootwheel############################################################################### # NeXT Makefile.preamble Template # Copyright 1993, NeXT Computer, Inc. # # This Makefile is used for configuring the standard app makefiles associated # with ProjectBuilder. # # Use this template to set attributes for a project, sub-project, bundle, or # palette. Each node in the project's tree of sub-projects and bundles # should have it's own Makefile.preamble and Makefile.postamble. # ############################################################################### ## Configure the flags passed to $(CC) here. These flags will also be ## inherited by all nested sub-projects and bundles. Put your -I, -D, -U, and ## -L flags here. To change the default flags that get passed to ${CC} ## (e.g. change -O to -O2), see Makefile.postamble. # Flags passed to compiler (in addition to -g, -O, etc) OTHER_CFLAGS = # Flags passed to ld (in addition to -ObjC, etc.) OTHER_LDFLAGS = BUNDLELDFLAGS = # use iff project is a bundle PALETTELDFLAGS = # use iff project is a palette ## Specify which headers in this project should be published to the outside ## world in a flat header directory given in PUBLIC_HEADER_DIR (which will be ## prepended by DSTROOT, below. Any subset of these public headers can be ## precompiled automatically after installation, with extra user-defined flags. PUBLIC_HEADER_DIR = PUBLIC_HEADERS = PUBLIC_PRECOMPILED_HEADERS = PUBLIC_PRECOMPILED_HEADERS_CFLAGS = ## Configure what is linked in at each level here. Libraries are only used in ## the final 'app' linking step. Final 'app' linking is only done via the ## 'app', 'debug', and 'profile' targets when they are invoked for ## the top-level app. # Additional relocatables to be linked in at this level OTHER_OFILES = # Additional libs to link apps against ('app' target) #OTHER_LIBS = # Additional libs to link apps against ('debug' target) OTHER_DEBUG_LIBS = # Additional libs to link apps against ('profile' target) OTHER_PROF_LIBS = # More 'app' libraries when $(JAPANESE) = "YES" OTHER_JAPANESE_LIBS = # More 'debug' libraries when $(JAPANESE) = "YES" OTHER_JAPANESE_DEBUG_LIBS = # More 'profile' libs when $(JAPANESE) = "YES" OTHER_JAPANESE_PROF_LIBS = # If this is a bundle, and you *know* the enclosing application will not # be linking with a library which you require in your bundle code, then # mention it here so that it gets linked into the bundle. Note that this # is wasteful but sometimes necessary. BUNDLE_LIBS = ## Configure how things get built here. Additional dependencies, sourcefiles, ## derived files, and build order should be specified here. # Other dependencies of this project OTHER_PRODUCT_DEPENDS = # Built *before* building subprojects/bundles OTHER_INITIAL_TARGETS = # Other source files maintained by .pre/postamble OTHER_SOURCEFILES = # Additional files to be removed by `make clean' OTHER_GARBAGE = # Precompiled headers to be built before any compilation occurs (e.g., draw.p) PRECOMPS = # Targets to be built before installation OTHER_INSTALL_DEPENDS = # A virtual root directory (other than /) to be prepended to the $(INSTALLDIR) # passed from ProjectBuilder. DSTROOT = # Set the following to "YES" if you want the old behavior of recursively # cleaning all nested subprojects during 'make clean'. CLEAN_ALL_SUBPROJECTS = ## Add more obscure source files here to cause them to be automatically ## processed by the appropriate tool. Note that these files should also be ## added to "Supporting Files" in ProjectBuilder. The desired .o files that ## result from these files should also be added to OTHER_OFILES above so they ## will be linked in. # .msg files that should have msgwrap run on them MSGFILES = # .defs files that should have mig run on them DEFSFILES = # .mig files (no .defs files) that should have mig run on them MIGFILES = ## Add additional Help directories here (add them to the project as "Other ## Resources" in Project Builder) so that they will be compressed into .store ## files and copied into the app wrapper. If the help directories themselves ## need to also be in the app wrapper, then a cp command will need to be added ## in an after_install target. OTHER_HELP_DIRS = # Don't add more rules here unless you want the first one to be the default # target for make! Put all your targets in Makefile.postamble. # To include a version string, project source must exist in a directory named # $(NAME).%d[.%d][.%d] and the following line must be uncommented. OTHER_GENERATED_OFILES = $(VERS_OFILE) -include ../Makefile.include diskdev_cmds-332.25/edquota.tproj/pathnames.h0000644000000000000000000000565306712726561020043 0ustar rootwheel/* * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights * Reserved. This file contains Original Code and/or Modifications of * Original Code as defined in and that are subject to the Apple Public * Source License Version 1.0 (the 'License'). You may not use this file * except in compliance with the License. Please obtain a copy of the * License at http://www.apple.com/publicsource and read it before using * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License." * * @APPLE_LICENSE_HEADER_END@ */ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)pathnames.h 8.1 (Berkeley) 6/6/93 */ #include #undef _PATH_TMP #define _PATH_TMP "/tmp/EdP.aXXXXX" diskdev_cmds-332.25/edquota.tproj/PB.project0000644000000000000000000000252606712726561017577 0ustar rootwheel{ DOCICONFILES = (); FILESTABLE = { CLASSES = (); C_FILES = (); H_FILES = (pathnames.h); LIBRARYSEARCH = (); OTHER_LIBS = (disk); OTHER_LINKED = (edquota.c); OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble, edquota.8); PRECOMPILED_HEADERS = (); PROJECT_HEADERS = (); PUBLIC_HEADERS = (); SUBPROJECTS = (); }; GENERATEMAIN = YES; LANGUAGE = English; LOCALIZABLE_FILES = {}; NEXTSTEP_BUILDDIR = /tmp/BUILD; NEXTSTEP_BUILDTOOL = /bin/gnumake; NEXTSTEP_INSTALLDIR = /usr/sbin; NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; PDO_UNIX_BUILDDIR = ""; PDO_UNIX_BUILDTOOL = /bin/make; PDO_UNIX_COMPILEROPTIONS = ""; PDO_UNIX_INSTALLDIR = /usr/sbin; PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; PDO_UNIX_LINKEROPTIONS = ""; PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; PROJECTNAME = edquota; PROJECTTYPE = Tool; PROJECTVERSION = 2.8; WINDOWS_BUILDDIR = ""; WINDOWS_BUILDTOOL = /bin/make; WINDOWS_COMPILEROPTIONS = ""; WINDOWS_INSTALLDIR = /usr/sbin; WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; WINDOWS_LINKEROPTIONS = ""; WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; } diskdev_cmds-332.25/fdisk.tproj/0000755000000000000000000000000010640030223015311 5ustar rootwheeldiskdev_cmds-332.25/fdisk.tproj/auto.c0000644000000000000000000001175507627531670016465 0ustar rootwheel/* * Copyright (c) 2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * "Portions Copyright (c) 2002 Apple Computer, Inc. All Rights * Reserved. This file contains Original Code and/or Modifications of * Original Code as defined in and that are subject to the Apple Public * Source License Version 1.2 (the 'License'). You may not use this file * except in compliance with the License. Please obtain a copy of the * License at http://www.apple.com/publicsource and read it before using * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License." * * @APPLE_LICENSE_HEADER_END@ */ /* * Auto partitioning code. */ #include #include #include #include #include #include #include "disk.h" #include "mbr.h" #include "auto.h" int AUTO_boothfs __P((disk_t *, mbr_t *)); int AUTO_bootufs __P((disk_t *, mbr_t *)); int AUTO_hfs __P((disk_t *, mbr_t *)); int AUTO_ufs __P((disk_t *, mbr_t *)); int AUTO_dos __P((disk_t *, mbr_t *)); int AUTO_raid __P((disk_t *, mbr_t *)); /* The default style is the first one in the list */ struct _auto_style { char *style_name; int (*style_fn)(disk_t *, mbr_t *); char *description; } style_fns[] = { {"boothfs", AUTO_boothfs, "8Mb boot plus HFS+ root partition"}, {"bootufs", AUTO_bootufs, "8Mb boot plus UFS root partition"}, {"hfs", AUTO_hfs, "Entire disk as one HFS+ partition"}, {"ufs", AUTO_ufs, "Entire disk as one UFS partition"}, {"dos", AUTO_dos, "Entire disk as one DOS partition"}, {"raid", AUTO_raid, "Entire disk as one 0xAC partition"}, {0,0} }; void AUTO_print_styles(FILE *f) { struct _auto_style *fp; int i; for (i=0, fp = &style_fns[0]; fp->style_name != NULL; i++, fp++) { fprintf(f, " %-10s %s%s\n", fp->style_name, fp->description, (i==0) ? " (default)" : ""); } } int AUTO_init(disk_t *disk, char *style, mbr_t *mbr) { struct _auto_style *fp; for (fp = &style_fns[0]; fp->style_name != NULL; fp++) { /* If style is NULL, use the first (default) style */ if (style == NULL || strcasecmp(style, fp->style_name) == 0) { return (*fp->style_fn)(disk, mbr); } } warnx("No such auto-partition style %s", style); return AUTO_ERR; } static int use_whole_disk(disk_t *disk, unsigned char id, mbr_t *mbr) { MBR_clear(mbr); mbr->part[0].id = id; mbr->part[0].bs = 63; mbr->part[0].ns = disk->real->size - 63; PRT_fix_CHS(disk, &mbr->part[0], 0); return AUTO_OK; } /* DOS style: one partition for the whole disk */ int AUTO_dos(disk_t *disk, mbr_t *mbr) { int cc; cc = use_whole_disk(disk, 0x0C, mbr); if (cc == AUTO_OK) { mbr->part[0].flag = DOSACTIVE; } return cc; } /* HFS style: one partition for the whole disk */ int AUTO_hfs(disk_t *disk, mbr_t *mbr) { int cc; cc = use_whole_disk(disk, 0xAF, mbr); if (cc == AUTO_OK) { mbr->part[0].flag = DOSACTIVE; } return cc; } /* UFS style: one partition for the whole disk */ int AUTO_ufs(disk_t *disk, mbr_t *mbr) { int cc; cc = use_whole_disk(disk, 0xA8, mbr); if (cc == AUTO_OK) { mbr->part[0].flag = DOSACTIVE; } return cc; } /* One boot partition, one HFS+ root partition */ int AUTO_boothfs (disk_t *disk, mbr_t *mbr) { /* Check disk size. */ if (disk->real->size < 16 * 2048) { errx(1, "Disk size must be greater than 16Mb"); return AUTO_ERR; } MBR_clear(mbr); /* 8MB boot partition */ mbr->part[0].id = 0xAB; mbr->part[0].bs = 63; mbr->part[0].ns = 8 * 1024 * 2; mbr->part[0].flag = DOSACTIVE; PRT_fix_CHS(disk, &mbr->part[0], 0); /* Rest of the disk for rooting */ mbr->part[1].id = 0xAF; mbr->part[1].bs = (mbr->part[0].bs + mbr->part[0].ns); mbr->part[1].ns = disk->real->size - mbr->part[0].ns - 63; PRT_fix_CHS(disk, &mbr->part[1], 1); return AUTO_OK; } /* One boot partition, one UFS root partition */ int AUTO_bootufs(disk_t *disk, mbr_t *mbr) { /* Check disk size. */ if (disk->real->size < 16 * 2048) { errx(1, "Disk size must be greater than 16Mb"); return AUTO_ERR; } MBR_clear(mbr); /* 8MB boot partition */ mbr->part[0].id = 0xAB; mbr->part[0].bs = 63; mbr->part[0].ns = 8 * 1024 * 2; mbr->part[0].flag = DOSACTIVE; PRT_fix_CHS(disk, &mbr->part[0], 0); /* Rest of the disk for rooting */ mbr->part[1].id = 0xA8; mbr->part[1].bs = (mbr->part[0].bs + mbr->part[0].ns); mbr->part[1].ns = disk->real->size - mbr->part[0].ns - 63; PRT_fix_CHS(disk, &mbr->part[1], 1); return AUTO_OK; } /* RAID style: one 0xAC partition for the whole disk */ int AUTO_raid(disk_t *disk, mbr_t *mbr) { return use_whole_disk(disk, 0xAC, mbr); } diskdev_cmds-332.25/fdisk.tproj/auto.h0000644000000000000000000000226307551557064016465 0ustar rootwheel/* * Copyright (c) 2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * "Portions Copyright (c) 2002 Apple Computer, Inc. All Rights * Reserved. This file contains Original Code and/or Modifications of * Original Code as defined in and that are subject to the Apple Public * Source License Version 1.2 (the 'License'). You may not use this file * except in compliance with the License. Please obtain a copy of the * License at http://www.apple.com/publicsource and read it before using * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License." * * @APPLE_LICENSE_HEADER_END@ */ #include "mbr.h" /* Prototypes */ void AUTO_print_styles __P((FILE *)); int AUTO_init __P((disk_t *, char *, mbr_t *)); #define AUTO_OK 0 #define AUTO_ERR -1 diskdev_cmds-332.25/fdisk.tproj/cmd.c0000644000000000000000000002664610267354171016256 0ustar rootwheel/* * Copyright (c) 2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * "Portions Copyright (c) 2002 Apple Computer, Inc. All Rights * Reserved. This file contains Original Code and/or Modifications of * Original Code as defined in and that are subject to the Apple Public * Source License Version 1.2 (the 'License'). You may not use this file * except in compliance with the License. Please obtain a copy of the * License at http://www.apple.com/publicsource and read it before using * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License." * * @APPLE_LICENSE_HEADER_END@ */ /* * Copyright (c) 1997 Tobias Weingartner * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Tobias Weingartner. * 4. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include #include #include #include #include "disk.h" #include "misc.h" #include "user.h" #include "part.h" #include "cmd.h" #include "auto.h" #define MAX(a, b) ((a) >= (b) ? (a) : (b)) int Xerase(cmd, disk, mbr, tt, offset) cmd_t *cmd; disk_t *disk; mbr_t *mbr; mbr_t *tt; int offset; { bzero(mbr->part, sizeof(mbr->part)); mbr->signature = MBR_SIGNATURE; return (CMD_DIRTY); } int Xreinit(cmd, disk, mbr, tt, offset) cmd_t *cmd; disk_t *disk; mbr_t *mbr; mbr_t *tt; int offset; { /* Copy template MBR */ MBR_make(tt); MBR_parse(disk, offset, 0, mbr); MBR_init(disk, mbr); /* Tell em we did something */ printf("In memory copy is initialized to:\n"); printf("Offset: %d\t", offset); MBR_print(mbr); printf("Use 'write' to update disk.\n"); return (CMD_DIRTY); } int Xauto(cmd, disk, mbr, tt, offset) cmd_t *cmd; disk_t *disk; mbr_t *mbr; mbr_t *tt; int offset; { if (cmd->args[0] == '\0') { printf("usage: auto