Solved

Volume locking

Posted on 1997-03-04
1
1,104 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Hibernate methods 2 88
sum28 challenge 31 117
post4 challenge 28 122
mapAB Challlenge 35 186
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…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

738 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