more patches for System-V bdf command

Wietse Venema wswietse at eutrc3.UUCP
Fri Feb 19 01:10:33 AEST 1988


The following patch avoids a division by zero error when mount points 
have long names as in

	/usr/users(/dev/dsk/0s6): xxxx blocks yyyy i-nodes

The patch also solves a problem for 16-bit systems caused by the use of 
plain integers for block and inode counts instead of long ones.

			Wietse Venema

*** bdf.c.orig	Wed Feb 17 22:46:57 1988
--- bdf.c	Wed Feb 17 23:07:38 1988
***************
*** 57,63 ****
  	void output_part1(), output_part2(), output_part3();
  	void header_part1(), header_part2(), header_part3();
  	char filesys[50], device[50];
! 	int fblocks, finodes, tblocks, tinodes;
  	FILE *df;
  
  	if (!(df = popen(df_command, "r"))) {
--- 57,63 ----
  	void output_part1(), output_part2(), output_part3();
  	void header_part1(), header_part2(), header_part3();
  	char filesys[50], device[50];
! 	long int fblocks, finodes, tblocks, tinodes;
  	FILE *df;
  
  	if (!(df = popen(df_command, "r"))) {
***************
*** 70,78 ****
  	if (iflag) header_part2();
  	header_part3();
  
! 	while (EOF != fscanf(df, "%s (%s ): %d blocks %d i-nodes",
  				filesys, device, &fblocks, &finodes)) {
! 		if (EOF == fscanf(df, " total: %d blocks %d i-nodes",
  				&tblocks, &tinodes)) {
  			perror("fscanf#2");
  			exit(2);
--- 70,78 ----
  	if (iflag) header_part2();
  	header_part3();
  
! 	while (EOF != fscanf(df, " %[^( ] (%[^) ] ): %ld blocks %ld i-nodes",
  				filesys, device, &fblocks, &finodes)) {
! 		if (EOF == fscanf(df, " total: %ld blocks %ld i-nodes",
  				&tblocks, &tinodes)) {
  			perror("fscanf#2");
  			exit(2);
***************
*** 106,128 ****
  static void
  output_part1(device, free_kb, total_kb)
  	char *device;
! 	int free_kb, total_kb;
  {
! 	int used_kb = total_kb - free_kb;
  	int capacity = (100 * used_kb) / total_kb;
  
! 	printf("%12s %7d %7d %7d   %3d%%  ",
  		device, total_kb, used_kb, free_kb, capacity);
  }
  
  static void
  output_part2(free_inodes, total_inodes)
! 	int free_inodes, total_inodes;
  {
! 	int used_inodes = total_inodes - free_inodes;
  	int percent_used = (100 * used_inodes) / total_inodes;
  
! 	printf("%6d  %6d   %3d%% ", used_inodes, free_inodes, percent_used);
  }
  
  static void
--- 106,128 ----
  static void
  output_part1(device, free_kb, total_kb)
  	char *device;
! 	long int free_kb, total_kb;
  {
! 	long int used_kb = total_kb - free_kb;
  	int capacity = (100 * used_kb) / total_kb;
  
! 	printf("%12s %7ld %7ld %7ld   %3d%%  ",
  		device, total_kb, used_kb, free_kb, capacity);
  }
  
  static void
  output_part2(free_inodes, total_inodes)
! 	long int free_inodes, total_inodes;
  {
! 	long int used_inodes = total_inodes - free_inodes;
  	int percent_used = (100 * used_inodes) / total_inodes;
  
! 	printf("%6ld  %6ld   %3d%% ", used_inodes, free_inodes, percent_used);
  }
  
  static void



-- 
uucp:	mcvax!eutrc3!wswietse	| Eindhoven University of Technology
bitnet:	wswietse at heithe5	| Dept. of Mathematics and Computer Science
surf:	tuerc5::wswietse	| Eindhoven, The Netherlands.



More information about the Comp.sources.bugs mailing list