Subject: lib/6623: fix to add '-f disktab' to disklabel(8) as well as clean up and
To: None <gnats-bugs@gnats.netbsd.org>
From: None <woods@mail.weird.com>
List: netbsd-bugs
Date: 12/20/1998 22:50:53
>Number:         6623
>Category:       lib
>Synopsis:       fix to add '-f disktab' to disklabel(8) as well as clean up <sys/disklabel.h> and <disktab.h>
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    lib-bug-people (Library Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sun Dec 20 20:05:00 1998
>Last-Modified:
>Originator:     Greg A. Woods
>Organization:
Planix, Inc.; Toronto, Ontario; Canada
>Release:        Sun Dec 20 08:26:45 EST 1998
>Environment:

>Description:

	There's no way to specify an alternate file for /etc/disktab to
	disklabel(8).

	This leads to adding setdisktab(3), and cleaning up and slight
	re-organization of <sys/disklabel.h> and <disktab.h>.

	(I put this in the "lib" category because it seems to affect the
	most stuff there, but it also belongs in bin, and perhaps kern.)

>How-To-Repeat:

	Observe the hoops sysinst goes to to install disk labels, and
	experience the frustration of having to temporarily edit
	/etc/disktab just to test a new disk.

	Observe how confusing and jumbled the definitions for
	/etc/disktab and "struct partition" are between
	<sys/disklabel.h> and <disktab.h>.

	Note that nothing in the source tree used the partial structures
	"struct disktab" and "struct partition" defined in <disktab.h>
	any longer.

>Fix:

	I'm not sure if the man page synopsis is entirely correct, but
	it's better than before....

Index: sys/sys/disklabel.h
===================================================================
RCS file: /cvs/NetBSD/src/sys/sys/disklabel.h,v
retrieving revision 1.1.1.3
diff -c -r1.1.1.3 sys/sys/disklabel.h
*** sys/sys/disklabel.h	1998/11/16 21:35:16	1.1.1.3
--- sys/sys/disklabel.h	1998/12/21 03:08:42
***************
*** 39,50 ****
  #define _SYS_DISKLABEL_H_
  
  /*
-  * Disk description table, see disktab(5)
-  */
- #define	_PATH_DISKTAB	"/etc/disktab"
- #define	DISKTAB		"/etc/disktab"		/* deprecated */
- 
- /*
   * Each disk has a label which includes information about the hardware
   * disk geometry, filesystem partitions, and drive specific information.
   * The location of the label, as well as the number of partitions the
--- 39,44 ----
***************
*** 365,374 ****
  #if !defined(_KERNEL) && !defined(_LOCORE)
  
  #include <sys/cdefs.h>
- 
- __BEGIN_DECLS
- struct disklabel *getdiskbyname __P((const char *));
- __END_DECLS
  
  #endif
  
--- 359,364 ----
Index: include/disktab.h
===================================================================
RCS file: /cvs/NetBSD/src/include/disktab.h,v
retrieving revision 1.1.1.2
diff -c -r1.1.1.2 include/disktab.h
*** include/disktab.h	1998/11/16 20:30:19	1.1.1.2
--- include/disktab.h	1998/12/21 03:33:07
***************
*** 43,67 ****
  /*
   * Disk description table, see disktab(5)
   */
! #define	DISKTAB		"/etc/disktab"
  
! struct	partition {
! 	int	p_size;		/* #sectors in partition */
! 	short	p_bsize;	/* block size in bytes */
! 	short	p_fsize;	/* frag size in bytes */
! };
! 
! struct	disktab {
! 	__aconst char *d_name;		/* drive name */
! 	__aconst char *d_type;		/* drive type */
! 	int	d_secsize;		/* sector size in bytes */
! 	int	d_ntracks;		/* # tracks/cylinder */
! 	int	d_nsectors;		/* # sectors/track */
! 	int	d_ncylinders;	/* # cylinders */
! 	int	d_rpm;		/* revolutions/minute */
! 	int	d_badsectforw;	/* supports DEC bad144 std */
! 	int	d_sectoffset;	/* use sect rather than cyl offsets */
! 	struct	partition d_partitions[8];
! };
  
  #endif /* !_DISKTAB_H_ */
--- 43,53 ----
  /*
   * Disk description table, see disktab(5)
   */
! #define	_PATH_DISKTAB	"/etc/disktab"
  
! __BEGIN_DECLS
! int setdisktab __P((char *));
! struct disklabel *getdiskbyname __P((const char *));
! __END_DECLS
  
  #endif /* !_DISKTAB_H_ */
Index: lib/libc/gen/disklabel.c
===================================================================
RCS file: /cvs/NetBSD/src/lib/libc/gen/disklabel.c,v
retrieving revision 1.1.1.3
diff -c -r1.1.1.3 lib/libc/gen/disklabel.c
*** lib/libc/gen/disklabel.c	1998/11/16 20:34:19	1.1.1.3
--- lib/libc/gen/disklabel.c	1998/12/21 03:17:12
***************
*** 58,63 ****
--- 58,65 ----
  #include <string.h>
  #include <unistd.h>
  
+ #include <disktab.h>
+ 
  #ifdef __weak_alias
  __weak_alias(getdiskbyname,_getdiskbyname);
  #endif
***************
*** 67,72 ****
--- 69,88 ----
  #endif
  static int	gettype __P((char *, const char *const *));
  
+ static char  	*db_array[2] = { _PATH_DISKTAB, 0 };
+ 
+ int
+ setdisktab(name)
+ 	char *name;
+ {
+ 	if (!name || !*name)
+ 		return -1;
+ 
+ 	db_array[1] = name;
+ 	return 0;
+ }
+ 
+ 
  struct disklabel *
  getdiskbyname(name)
  	const char *name;
***************
*** 75,81 ****
  	struct	disklabel *dp = &disk;
  	struct partition *pp;
  	char	*buf;
- 	char  	*db_array[2] = { _PATH_DISKTAB, 0 };
  	char	*cp, *cq;	/* can't be */
  	char	p, max, psize[3], pbsize[3],
  		pfsize[3], poffset[3], ptype[3];
--- 91,96 ----
Index: lib/libc/gen/getdiskbyname.3
===================================================================
RCS file: /cvs/NetBSD/src/lib/libc/gen/getdiskbyname.3,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 lib/libc/gen/getdiskbyname.3
*** lib/libc/gen/getdiskbyname.3	1998/02/20 00:31:34	1.1.1.1
--- lib/libc/gen/getdiskbyname.3	1998/12/21 00:41:19
***************
*** 37,48 ****
  .Dt GETDISKBYNAME 3
  .Os BSD 4.2
  .Sh NAME
! .Nm getdiskbyname
  .Nd get generic disk description by its name
  .Sh LIBRARY
  .Lb libc
  .Sh SYNOPSIS
  .Fd #include <sys/disklabel.h>
  .Ft struct disklabel *
  .Fn getdiskbyname "const char *name"
  .Sh DESCRIPTION
--- 37,53 ----
  .Dt GETDISKBYNAME 3
  .Os BSD 4.2
  .Sh NAME
! .Nm getdiskbyname ,
! .Nm setdisktab
  .Nd get generic disk description by its name
  .Sh LIBRARY
  .Lb libc
  .Sh SYNOPSIS
+ .Fd #include <sys/types.h>
  .Fd #include <sys/disklabel.h>
+ .Fd #include <disktab.h>
+ .Ft int
+ .Fn setdisktab "char *name"
  .Ft struct disklabel *
  .Fn getdiskbyname "const char *name"
  .Sh DESCRIPTION
***************
*** 57,62 ****
--- 62,77 ----
  the 
  .Xr disktab 5
  file.
+ .Pp
+ The
+ .Fn setdisktab
+ function changes the default
+ .Pn disktab
+ file name from
+ .Pa /etc/disktab
+ .Pq Dv _PATH_DISKTAB
+ to
+ .Fa name .
  .Sh SEE ALSO
  .Xr disklabel 5 ,
  .Xr disktab 5 ,
***************
*** 66,68 ****
--- 81,88 ----
  .Fn getdiskbyname
  function appeared in 
  .Bx 4.3 .
+ .Pp
+ The
+ .Fn setdisktab
+ function appeared in
+ .Nx 1.4 .
Index: lib/libc/gen/Makefile.inc
===================================================================
RCS file: /cvs/NetBSD/src/lib/libc/gen/Makefile.inc,v
retrieving revision 1.1.1.5
diff -c -r1.1.1.5 lib/libc/gen/Makefile.inc
*** lib/libc/gen/Makefile.inc	1998/11/16 20:34:07	1.1.1.5
--- lib/libc/gen/Makefile.inc	1998/12/21 03:45:39
***************
*** 68,73 ****
--- 68,74 ----
  	getcap.3 cgetnum.3 getcap.3 cgetset.3 getcap.3 cgetstr.3 \
  	getcap.3 cgetustr.3
  MLINKS+=getcwd.3 getwd.3
+ MLINKS+=getdiskbyname.3 setdisktab.3
  MLINKS+=getdomainname.3 setdomainname.3
  MLINKS+=getfsent.3 endfsent.3 getfsent.3 getfsfile.3 getfsent.3 getfsspec.3 \
  	getfsent.3 getfstype.3 getfsent.3 setfsent.3
Index: src/sbin/disklabel/disklabel.c
===================================================================
RCS file: /cvs/NetBSD/src/sbin/disklabel/disklabel.c,v
retrieving revision 1.1.1.5
diff -c -r1.1.1.5 src/sbin/disklabel/disklabel.c
*** src/sbin/disklabel/disklabel.c	1998/11/16 20:44:45	1.1.1.5
--- src/sbin/disklabel/disklabel.c	1998/12/21 03:07:18
***************
*** 74,79 ****
--- 74,81 ----
  #include <unistd.h>
  #include <util.h>
  
+ #include <disktab.h>
+ 
  #include "pathnames.h"
  #include "extern.h"
  #include "dkcksum.h"
***************
*** 130,138 ****
  
  #ifdef DEBUG
  static int	debug;
! #define OPTIONS	"BCNRWb:deirs:tw"
  #else
! #define OPTIONS	"BCNRWb:eirs:tw"
  #endif
  
  #ifdef __i386__
--- 132,140 ----
  
  #ifdef DEBUG
  static int	debug;
! #define OPTIONS	"BCNRWb:def:irs:tw"
  #else
! #define OPTIONS	"BCNRWb:ef:irs:tw"
  #endif
  
  #ifdef __i386__
***************
*** 217,222 ****
--- 219,228 ----
  				usage();
  			op = EDIT;
  			break;
+ 		case 'f':
+ 			if (setdisktab(optarg) == -1)
+ 				usage();
+ 			break;
  		case 'i':
  			if (op != UNSPEC)
  				usage();
>Audit-Trail:
>Unformatted: