Forum > Linux

Disk status snip for Raspios linux.

(1/1)

pascalbythree:
Hello FPC people,

Does anybody have a native snip for:

1 = a function to read the max disk capacity
2 = a function to read the used space
3 = a function to read data rate processed

For example for /dev/sda1

On Raspios linux for the RPI ZERO or RPI-3

Greets, Wouter van Wegen, PascalByThree...

PS: Photo from my new NAS project included. Now working on the PRI MOD

PS2: A name of a component pack will also do fine.

Edit: the  sysutils unit got Diskfree DiskSize in it. Only Waiting for the datarate solution.

pascalbythree:
Yay! it got to work already!


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program WVW_NAS_CONSOLE_TEST_V4; {$mode objfpc}{$H+} uses  {$IFDEF UNIX}  cthreads,  {$ENDIF}  Classes,  uThreadTimer,  SysUtils, CustApp,  crt, sockets, baseunix; const  IPPROTO_IP     = 0;  IF_NAMESIZE    = 16;  SIOCGIFCONF    = $8912;  type {$packrecords c}  tifr_ifrn = record    case integer of      0 : (ifrn_name: array [0..IF_NAMESIZE-1] of char);  end;  PIFrec = ^TIFrec;  TIFrec = record    ifr_ifrn : tifr_ifrn;    case integer of      0 : (ifru_addr      : TSockAddr);  end;  TIFConf = record    ifc_len : longint;    case integer of      0 : (ifcu_buf : pointer);      1 : (ifcu_req : ^tifrec);  end; var olddiskused: Int64;   function GetLocalIPs:string;var  i,n,Sd : Integer;  buf : Array[0..1023] of byte;  ifc : TIfConf;  ifp : PIFRec;  names:string;begin    sd:=fpSocket(AF_INET,SOCK_DGRAM,IPPROTO_IP);    result:='';    if (sd<0) then      exit;    Try      ifc.ifc_len:=Sizeof(Buf);      ifc.ifcu_buf:=@buf;      if fpioctl(sd, SIOCGIFCONF, @ifc)<0 then        Exit;      n:= ifc.ifc_len;      i:=0;      names:='';      While (i<n) do        begin        ifp:=PIFRec(PByte(ifc.ifcu_buf)+i);        names:=names+ ifp^.ifr_ifrn.ifrn_name+ ' ';        //if i>0 then result:=result+',';        result:=NetAddrToStr(ifp^.ifru_addr.sin_addr);        i:=i+sizeof(TIFrec);        end;    Finally      fileClose(sd);    end;end;  procedure DoOnTimer(Sender: TObject);var varDISKused:Int64;    varDISKFree:Int64;        varDISKSize:Int64;        varMBadded :Int64;begin  ClrScr;   Writeln('********************************'+#10+#13);  writeln('IP: '+GetLocalIPs+#10+#13);  Writeln ('Now : ',FormatDateTime('hh:nn:ss',now)+#10+#13);    varDISKfree := DISKfree(0);  varDISKfree := round(varDISKfree / 1024); // KB  varDISKfree := round(varDISKfree / 1024); // MB    writeln('Diskfree: '+IntToStr(varDiskfree)+' MB'+#10+#13);    varDISKSize := DISKSize(0);  varDISKSize := round(varDISKSize / 1024); // KB  varDISKSize := round(varDISKSize / 1024); // MB    writeln('Disksize: '+IntToStr(varDISKSize)+' MB'+#10+#13);    olddiskused := varDISKused;    varDISKused := Disksize(0) - Diskfree(0);  varDISKused := round(varDISKused / 1024); // KB  varDISKused := round(varDISKused / 1024); // MB  writeln('Diskused: '+IntToStr(varDISKused)+' MB'+#10+#13);    varMBadded := varDISKused - olddiskused;  writeln('Added: '+IntToStr(varMBadded)+' MB/s'+#10+#13);    Writeln('********************************'+#10+#13);end;  var  ThreadTimer: TThreadTimer;  M: TMethod;begin   olddiskused := varDISKused;  ThreadTimer := TThreadTimer.Create(True);  ThreadTimer.Interval := 1000;  M.Data := nil;  M.Code := @DoOnTimer;  ThreadTimer.OnTimer := TNotifyEvent(M);  ThreadTimer.StartTimer;   Writeln('Press a key to terminate');  Readln;   ThreadTimer.StopTimer;  ThreadTimer.Terminate;  ThreadTimer.WaitFor;end.
Now i am going to fuck I2C on it later on. In a few weeks!

Navigation

[0] Message Index

Go to full version