⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 列表7.7.txt

📁 klinux书籍的配套光盘。可以学习学习。
💻 TXT
字号:
【列表7.7】摘录自mountform.pas的程序代码。
procedure TForml.FillForm;
var
 f: PIOFile;
 mntEnt: PMountEntry;
 mntIdx: Integer;
begin
 mntIdx := 0;

 if ( getuid <> 0 ) then
  ShowMessage( 'You are not running as root. You will only be able ' +
                       'to examine the mount information, not change it.' );
// first, get the mount points of all mounted drives
f := setmntent( '/proc/mounts', 'r' );
if not Assigned( f ) then
  begin
   ShowMessage( 'Fatal: Unable to open /proc/mounts' );
   exit;
  end;

mntEnt := getmntent( f );
while ( mntEnt <> nil ) do
  begin
   mounts.Add( mntEnt.mnt_dir );
   mntEnt := getmntent( f );
  end;
endmntent( f );

 // now, populate the list of known filesystems in the list box
 // and keep track of 'em for later use.
 f := setmntent( _PATH_FSTAB, 'r' );
 if ( not Assigned( f ) ) then
  begin
    ShowMessage( 'Fatal: Unable to open ' + _PATH_FSTAB );
    exit;
  end;
 mntEnt := getmntent( f );
 while ( mntEnt <> nil ) do
  begin
    lbFilesystems. Items.Add( mntEnt.mnt_fsname
          + ' (' + mntEnt.mnt_dir + ')' );
    persistMntEntry( mntIdx, mntEnt );

    mntEnt := getmntent( f );

    Inc( mntIdx );
  end;

 endmntent( f );
end;

procedure TForml.persistMntEntry( idx: Integer; mntEnt: PMountEntry );
begin
 mntEntList[idx].fsName := mntEnt.mnt_fsname;
 mntEntList[idx].mountPoint := mntEnt.mnt_dir;
 mntEntList[idx].fsType := mntEnt.mnt_type;
 mntEntList[idx].fsOpts := mntEnt.mnt_opts;
 if (mounts. IndexOf( mntEnt.mnt_dir ) <> -1 ) then
   mntEntList[idx].mounted := true
 else
   mntEntList[idx].mounted := false;
 end;

procedure TForml.btnMountClick(Sender: TObject);
var
  idx: Integer;
  rv: Integer;
  str: String;
begin
  idx := lbFilesystems. ItemIndex;
  if ( mntEntList[idx].fstype = 'auto' )
   then begin
            TTypeSelect. ShowModal;
            str := TTypeSelect.selectedType;
        end
   else
     str := mntEntList[idx].fstype;
  // mount read only for safety in this example
  rv := mount( PChar( mntEntList[idx].fsName ),
                     PChar( mntEntList[idx].mountPoint ).
                     PChar( str ),
                     MS_MGC_VAL Or MS_RDONLY,
                     nil );
  if ( rv <> 0 )
   then ShowMessage( strerror( errno ) )
   else begin
            mntEntList[idx].mounted := true;
            RefreshForm;
            btnMount. Enabled := false;
            btnUnmount. Enabled := true;
          end;
end;
procedure TForml.btnUnmountClick(Sender: TObject);
var
 idx: Integer;
 rv:  Integer;
begin
 idx := lbFilesystems. ItemIndex;
 rv := umount( PChar( mntEntList[idx].fsName ) );
 if ( rv <> 0 )
  then ShowMessage( strerror( errno ) )
  else begin
           mntEntList[idx].mounted := false;
           RefreshForm;
           btnMount. Enabled := true;
           btnUnmount. Enabled := false;
        end;
end;
procedure TForml. RefreshForm;
var
 idx: Integer;
begin
 idx := lbFilesystems. ItemIndex;
 lblFsName.Caption := mntEntList[idx].fsName;
 lblMountPoint. Caption := mntEntList[idx].mountPoint;
 lblFsType.Caption := mntEntList[idx].fsType;
 lblMntOptions.Caption := mntEntList[idx].fsOpts;
 if ( mntEntList[idx].mounted )
   then begin
            lblMounted.Caption := 'Yes';
            btnMount. Enabled := false;
            btnUnmount. Enabled := true;
        end
   else begin
            lblMounted.Caption := 'No';
            btnMount. Enabled := true;
            btnUnmount. Enabled := false;
          end;
end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -