Solved

Volume locking

Posted on 1997-03-04
1
1,103 Views
Last Modified: 2013-12-26
How is it possible to lock/unlock a volume (Harddisk)? It is not possible with the RedEdit "Get File/Folder Info". Is there a command in C to lock/unlock a volume, or to safe files on a locked volume?
0
Comment
Question by:MacJon
1 Comment
 
LVL 4

Accepted Solution

by:
Alex Curylo earned 50 total points
ID: 1291385
You use PBSetVInfo(). Of course, that only works if it's a software lock, there's obviously nothing code can do about a hardware lock (like the tab on a floppy).

Here's code which is untested but I imagine should work:

OSErr      VolLock(ConstStr255Param pathname, short vRefNum, bool lockIt)
{
      HParamBlockRec pb;
      OSErr error;

      error = GetVolumeInfoNoName(pathname,vRefNum, &pb);
      if ( error == noErr )
      {
            if ( (pb.volumeParam.ioVAtrb & 0x0080) != 0 )
            {
                  error = wPrErr;            /* volume locked by hardware */
            }
            else
  {
     bool swLocked = ( (pb.volumeParam.ioVAtrb & 0x8000) != 0 );
     if (swLocked != lockIt)
     {
        pb.volumeParam.ioVAtrb ^= 0x8000;
        error = PBSetVInfoSync(&pb);
     }
   }
 }
      
      return ( error );
}

GetVolumeInfoNoName() is part of the fine, fine MoreFiles source, available from

<ftp://members.aol.com/JumpLong/MoreFiles_1.4.6.sea.hqx


0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Macro to save highlighted rows as a separate file 5 46
deburging in oracle form 12 109
maven archtype selection in eclipse 1 58
has77  challenge 9 96
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question