Solved

Volume locking

Posted on 1997-03-04
1
1,084 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
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now