fsMediaWriteProtected (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

All

Firmware version:

1.00 / 1.00.00


This queries if a media is write protected. If the media is write protected, it is not possible to write any information to it (read-only mode), and it is not possible to create, modify, or delete any files or directories.

 

The write protection on an SD-CARD is determined by the small "tab" on the edge of the card.

This "tab" is only present on the full-size SD-CARD - therefore devices with a micro-SD-CARD reader will never report the media as write protected.

 

USB medias can be write protected for multiple reasons, including by setting physical write protection switches or, especially in the case of flash medias, in the case of errors on the file system.

 

Input:

media : INT (0..3)

The media to query.

 

Returns: BOOL

TRUE:

Media is write protected (files and directories are read only).

FALSE:

Media is not write protected.

 

Declaration:

FUNCTION fsMediaWriteProtected : BOOL;
VAR_INPUT
  media : INT;
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
 
PROGRAM FileExample;
VAR
  mediaPresent : BOOL;
  rc           : INT;
END_VAR;
 
fsMediaOpen(media := 0);
 
BEGIN
  // Update media status
  IF mediaPresent <> fsMediaPresent(media := 0) THEN
    IF fsMediaPresent(media := 0) THEN
        IF fsMediaWriteProtected(media := 0) THEN
          DebugMsg(message := "Media present, media write protected!");
        END_IF;
        // Open files
        ...
    ELSE
        DebugMsg(message := "Media has been removed!");
    END_IF;
    // Save current status
     mediaPresent := fsMediaPresent(media := 0);
  END_IF;
  ...
END;
 
END_PROGRAM;