Chris is the coolest. He offers up some C code for the System i to get a disk status. I am learning at the masters feet. Now I need a scratch System i to test it on?
This is good stuff Chris. Nice Job! I am just going to streal it now and post it here too if you don’t mind.
I had the need to determine just how much disk was available on the system as part of my Virtual Save process to ensure I would not be exceeding the Low Limit DASD utilization System Value. Before each image creation I will check that adding the image size 660MB will not exceed the QSTGLOWLMT number, if it does I will suspend the save action and request operator intervention.
This is a sample C program which will output the relevant data to StdOut using printf() functions. You could use this code in many places to either return the data to a calling program or take action within the program itself with some modification.
#include
#include
#include
#include
int main(int argc, char *argv[])
{
float pct_avail;
float dasd_avail;
Qwc_SSTS0200_t List_Info;
char Reset[10] = “*NO “;
char Fmt_Name[8] = “SSTS0200″;
int List_Info_Len = sizeof(List_Info);
Qus_EC_t Error_Code = {0};QWCRSSTS(&List_Info,
List_Info_Len,
Fmt_Name,
Reset,
&Error_Code);
pct_avail = (float)100 - (List_Info.Pct_System_ASP_used / 10000);
dasd_avail = List_Info.Total_Aux_Storage * pct_avail/100000;
printf(”Percentage Available disk %.1f%%\n”,pct_avail);
printf(”Total %.3fGB\n”,(float)List_Info.Total_Aux_Storage/1000);
printf(”Dasd available = %.3fGB”,dasd_avail);
Here is a breakdown of the program to show the various API and functions calls etc..
These are the headers we need for the API’s and function calls we make.
#include /* Standard I/O */
#include /* Standard Lib */
#include /* retrieve disk status */
#include /* Error Code Structures */
These are the various variables we use within the program. Error_Code has been set to 0 because we want errors to show up to the user and we will not handle them within the program. List Info is a pre-defined structure which has the right layout for the returned information, the #include entry ensures the structure definition is available in the program. If you want to see the structure to identify the elements available you can see it in QSYSINC/H member QWCRSSTS. The format we use is “SSTS0200? which is defined in the same definition file.
float pct_avail;
float dasd_avail;
Qwc_SSTS0200_t List_Info;
char Reset[10] = “*NO “;
char Fmt_Name[8] = “SSTS0200?;
int List_Info_Len = sizeof(List_Info);
Qus_EC_t Error_Code = {0};
This is where we call the API and collect the data we need from the system, it is the same as using the WRKSYSSTS command but provides the data directly to the program.
QWCRSSTS(&List_Info,
List_Info_Len,
Fmt_Name,
Reset,
&Error_Code);
Here we simply change the values from their retuned value to ones we need to output and then using printf send them to the screen. We have moved the numbers to represent GigaBytes using a rounded number, to get the true number you need to set the division parameter to the right value!
pct_avail = (float)100 - (List_Info.Pct_System_ASP_used / 10000);
dasd_avail = List_Info.Total_Aux_Storage * pct_avail/100000;
printf(”Percentage Available disk %.1f%%\n”,pct_avail);
printf(”Total %.3fGB\n”,(float)List_Info.Total_Aux_Storage/1000);
printf(”Dasd available = %.3fGB”,dasd_avail);
The program is very simple yet has the ability to provide very valuable information to programs where the DASD utilization has to be considered before an action is carried out.
Chris….
August 7th, 2007 at 7:01 pm
I hope to provide lots more programs like this which are small but provide good information that isn’t always easy to get to without using API’s. I hope others will see just how easy some of this stuff is. If you need a small program for something let me know and I will see if I can knock one up quickly and post it for your and everyones else’s benefit. Dont ask for application level programs though, I am not that willing!!!
Chris…