Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Volume locking

Posted on 1997-03-04
1
Medium Priority
?
1,114 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 100 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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

722 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