From: jim@lime.rsmas.miami.edu (Jim Brown)
Subject: sizedrive - get SCSI disk geometry (SHAR) (OSF, ULTRIX)
Date: 22 Mar 1994 23:56:21 -0500 [thread overview]
Message-ID: <2moi5l$imk@lime.rsmas.miami.edu> (raw)
The enclosed utility can be used to query compliant SCSI disks to
determine their device geometry. This is particularly useful on OSF
as disklabel lacks this functionality.
I have built and run this utility on both Ultrix v4.2a and OSF v2.0.
Enjoy,
Jim Brown
#!/bin/sh
# This is a shell archive (produced by shar 3.49)
# To extract the files from this archive, save it to a file, remove
# everything above the "!/bin/sh" line above, and type "sh file_name".
#
# made 03/23/1994 04:49 UTC by jim@guanabana.rsmas.miami.edu
# Source directory /a/gate-guanabana/d1/jim/src/sizedrive
#
# existing files will NOT be overwritten unless -c is specified
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 298 -rw-rw-r-- Makefile
# 1499 -rw-rw-r-- sizedrive.8
# 2478 -rw-rw-r-- sizedrive.c
#
# ============= Makefile ==============
if test -f 'Makefile' -a X"$1" != X"-c"; then
echo 'x - skipping Makefile (File already exists)'
else
echo 'x - extracting Makefile (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'Makefile' &&
EXE=sizedrive
BIN=/usr/local/etc
LVL=8
MAN=/usr/local/man/man
X
##why bother
#CFLAGS=
X
sizedrive: sizedrive.o
X $(CC) -o $@ $?
X
install: sizedrive
X rm -f $(BIN)/$(EXE);\
X cp $(EXE) $(BIN)
X rm -f $(MAN)$(LVL)/$(EXE).$(LVL);\
X cp $(EXE).8 $(MAN)$(LVL)/$(EXE).$(LVL)
X
clean:
X rm -f core $(EXE) $(EXE).o
SHAR_EOF
chmod 0664 Makefile ||
echo 'restore of Makefile failed'
Wc_c="`wc -c < 'Makefile'`"
test 298 -eq "$Wc_c" ||
echo 'Makefile: original size 298, current size' "$Wc_c"
fi
# ============= sizedrive.8 ==============
if test -f 'sizedrive.8' -a X"$1" != X"-c"; then
echo 'x - skipping sizedrive.8 (File already exists)'
else
echo 'x - extracting sizedrive.8 (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'sizedrive.8' &&
.\"
.\" Copyright (c) 1994 Jim Brown
.\" 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.
.\"
.\" $Id:$
.\"
.TH SIZEDRIVE 8 "22 March 1994"
.SH NAME
sizedrive \- query SCSI disk for geometry information
.SH SYNOPSIS
.B sizedrive
.I drive
.SH DESCRIPTION
.B Sizedrive
is a program which queries a SCSI disk drive to determine what its geometry
parameters might be.
.I Drive
can be any of rzNN, rzNN[letter], rrzNN, rrzNN[letter], or a full special
device name.
For most modern disk drives the total number of
sectors will not be equal to sectors * tracks * cylinders because of
variable drive geometry from inner cylinder to outer cylinder.
However, the number of tracks and sectors make a reasonable starting place
from which one can produce a disktab entry.
.SH CAVEATS
You have to be super-user to run
.B sizedrive.
.SH AUTHOR
Jim Brown <jim@lime.rsmas.miami.edu>, Department of Meteorology and Physical
Oceanography, Rosenstiel School of Marine and Atmospheric Science,
University of Miami, Miami, FL.
SHAR_EOF
chmod 0664 sizedrive.8 ||
echo 'restore of sizedrive.8 failed'
Wc_c="`wc -c < 'sizedrive.8'`"
test 1499 -eq "$Wc_c" ||
echo 'sizedrive.8: original size 1499, current size' "$Wc_c"
fi
# ============= sizedrive.c ==============
if test -f 'sizedrive.c' -a X"$1" != X"-c"; then
echo 'x - skipping sizedrive.c (File already exists)'
else
echo 'x - extracting sizedrive.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'sizedrive.c' &&
#include <stdio.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/devio.h>
X
char *choose_name(char *try);
X
main(int argc, char *argv[])
{
X /*
X Ask SCSI disk for its device geometry information.
X */
X DEVGEOMST buf;
X int f, s;
X char *t;
X char temp[128];
X unsigned long got;
X
#define P buf.geom_info
X
X if (argc != 2)
X usage();
X
X if (strlen(argv[1]) > 40) {
X fprintf(stderr,"Unlikely device name: %s\n", argv[1]);
X exit(1);
X }
X
X t = choose_name(argv[1]);
X f = open(t, O_RDONLY, 0666);
X if (f != -1) {
X s = ioctl(f, DEVGETGEOM, &buf);
X if (s != -1) {
X printf("Device geometry information for %s\n", t);
X printf(" Total blocks: %d\n", P.dev_size); /* number of blocks in the user area (#pc)*/
X printf(" tracks: %d\n", P.ntracks); /* number of tracks per cylinder (#nt) */
X printf(" sectors: %d\n", P.nsectors); /* number of sectors per track (#ns) */
X printf(" cylinders: %d\n", P.ncylinders); /* total number of cylinders (#nc) */
X printf(" attributes:"); /* Device attributes; see defs below */
X got = 0;
#ifdef DEVGEOM_REMOVE
X if (P.attributes & DEVGEOM_REMOVE) {
X printf(" Removeable_media");
X got |= DEVGEOM_REMOVE;
X }
#endif
#ifdef DEVGEOM_DYNAMIC
X if (P.attributes & DEVGEOM_DYNAMIC) {
X printf(" Dynamic_geometry");
X got |= DEVGEOM_DYNAMIC;
X }
#endif
X if (P.attributes != got)
X printf(" unknown:0x%x", P.attributes-got);
X else if (P.attributes == 0)
X printf(" none");
X printf("\n");
X }
X else
X perror("ioctl failed");
X close(f);
X }
X else {
X sprintf(temp, "open failed for %s", t);
X perror(temp);
X }
X
X exit(0);
}
X
usage()
{
X printf("usage: sizedrive device\n");
X printf("\tQuery SCSI disk drive for geometry infomation.\n");
X exit(1);
}
X
char *
choose_name(char *try)
{
X /*
X Try to turn rzNNx into /dev/rrzNNx.
X */
X static char temp[64], *t;
X char c;
X int i;
X int unit;
X
X i = sscanf(try, "rz%d%c", &unit, &c);
X if (i == 1) {
X strcpy(temp, "/dev/r");
X strcat(temp, try);
X strcat(temp, "a");
X }
X else if (i == 2) {
X strcpy(temp, "/dev/r");
X strcat(temp, try);
X }
X else {
X i = sscanf(try, "rrz%d%c", &unit, &c);
X if (i == 1) {
X strcpy(temp, "/dev/");
X strcat(temp, try);
X strcat(temp, "a");
X }
X else if (i == 2) {
X strcpy(temp, "/dev/");
X strcat(temp, try);
X }
X else
X strcpy(temp, try); /* punt */
X }
X return temp;
}
SHAR_EOF
chmod 0664 sizedrive.c ||
echo 'restore of sizedrive.c failed'
Wc_c="`wc -c < 'sizedrive.c'`"
test 2478 -eq "$Wc_c" ||
echo 'sizedrive.c: original size 2478, current size' "$Wc_c"
fi
exit 0
--
Jim Brown, University of Miami, RSMAS/MPO
[send mail to jim@lime.rsmas.miami.edu]
reply other threads:[~1994-03-23 4:56 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox