D.Asare
D.Asare

Reputation: 103

How to check if a volume is currently unlocked OSX

I would like to check the state of a volume drive to see whether its locked or unlocked via terminal. how would i go around doing this?

Upvotes: 0

Views: 161

Answers (1)

Michael Dautermann
Michael Dautermann

Reputation: 89549

There's a couple commands that I know of.

GetFileInfo shows a locked attribute... for example:

GetFileInfo -al /Volumes/Macintosh\ HD will print out 0 (the l after the -a attribute parameter means locked and the return of 0 means false). It doesn't seem foolproof though, because I'll still see a 0 (false) return even for locked DMG files.

In a shell script, this might be something like:

output=$(GetFileInfo -al /Volumes/Untitled )
if [ $output -eq 1 ]
  then
    echo "locked"
  else
    echo "unlocked"
fi

Also, there's diskutil. If you do diskutil info /Volumes/Macintosh\ HD you'll see a result of:

Read-Only Media: No Read-Only Volume: No

or, on a read-only DMG, you might see:

Read-Only Media: Yes Read-Only Volume: Yes

I'm not sure if these answers are the ones you are looking for, but hopefully that gets you in the right direction.

Upvotes: 1

Related Questions