corrected calculation for swap on openbsd
The swapctl(2) function fills the swapent struct with 512KB blocks. As we want to display in GB, i just modified the calculation for this to get the expected output.
This commit is contained in:
		
				
					committed by
					
						
						Aaron Marcher
					
				
			
			
				
	
			
			
			
						parent
						
							82eb6e3832
						
					
				
				
					commit
					c1f79d741a
				
			@@ -131,8 +131,6 @@
 | 
				
			|||||||
	#include <sys/types.h>
 | 
						#include <sys/types.h>
 | 
				
			||||||
	#include <unistd.h>
 | 
						#include <unistd.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	#define	dbtoqb(b) dbtob((int64_t)(b))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	static void
 | 
						static void
 | 
				
			||||||
	getstats(int *total, int *used)
 | 
						getstats(int *total, int *used)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
@@ -162,8 +160,8 @@
 | 
				
			|||||||
		*used = 0;
 | 
							*used = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		for (i = 0; i < rnswap; i++) {
 | 
							for (i = 0; i < rnswap; i++) {
 | 
				
			||||||
			*total += dbtoqb(sep->se_nblks);
 | 
								*total += sep->se_nblks >> 1;
 | 
				
			||||||
			*used += dbtoqb(sep->se_inuse);
 | 
								*used += sep->se_inuse >> 1;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		free(fsep);
 | 
							free(fsep);
 | 
				
			||||||
@@ -176,7 +174,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		getstats(&total, &used);
 | 
							getstats(&total, &used);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		return bprintf("%f", (float)(total - used) / 1024 / 1024 / 1024);
 | 
							return bprintf("%f", (float)(total - used) / 1024 / 1024);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const char *
 | 
						const char *
 | 
				
			||||||
@@ -196,7 +194,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		getstats(&total, &used);
 | 
							getstats(&total, &used);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		return bprintf("%f", (float)total / 1024 / 1024 / 1024);
 | 
							return bprintf("%f", (float)total / 1024 / 1024);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const char *
 | 
						const char *
 | 
				
			||||||
@@ -206,6 +204,6 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		getstats(&total, &used);
 | 
							getstats(&total, &used);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		return bprintf("%f", (float)used / 1024 / 1024 / 1024);
 | 
							return bprintf("%f", (float)used / 1024 / 1024);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user