16.2 Using a DBFS SecureFiles Store File System

The DBFS Content API provides methods to access and manage a SecureFiles Store file system.

16.2.1 DBFS Content API Working Example

You can create new file and directory elements to populate a SecureFiles Store file system.

If you have executed the steps in "Setting Up a SecureFiles Store", set the DBFS Content API permissions, created at least one SecureFiles Store reference file system, and mounted it under the mount point /mnt1, then you can create a new file and directory elements as demonstrated in Example 16-1.

Example 16-1 Working with DBFS Content API

CONNECT tjones
Enter password: <password>

DECLARE
   ret INTEGER;
   b   BLOB;
   str VARCHAR2(1000)  := '' || chr(10) ||
    '#include <stdio.h>' || chr(10) ||
    '' || chr(10) ||
    'int main(int argc, char** argv)' || chr(10) ||
    '{' || chr(10) ||
    '    (void) printf("hello world\n");' || chr(10) ||
    '    RETURN 0;' || chr(10) ||
    '}' || chr(10) ||
    '';
   properties      DBMS_DBFS_CONTENT.PROPERTIES_T;

BEGIN
   properties('posix:mode') := DBMS_DBFS_CONTENT.propNumber(16777);
                                           --  drwxr-xr-x  --
   properties('posix:uid')  := DBMS_DBFS_CONTENT.propNumber(0);
   properties('posix:gid')  := DBMS_DBFS_CONTENT.propNumber(0);
   DBMS_DBFS_CONTENT.createDirectory(
            '/mnt1/FS1',
            properties); 

   properties('posix:mode') := DBMS_DBFS_CONTENT.propNumber(33188);
                                            --  -rw-r--r--  --
   DBMS_DBFS_CONTENT.createFile(
            '/mnt1/FS1/hello.c',
            properties,
            b);

    DBMS_LOB.writeappend(b, length(str), utl_raw.cast_to_raw(str));
    COMMIT;
END;
/
SHOW ERRORS;

-- verify newly created directory and file

SELECT pathname, pathtype, length(filedata),
      utl_raw.cast_to_varchar2(filedata)
      FROM dbfs_content
         WHERE pathname LIKE '/mnt1/FS1%'
         ORDER BY pathname;

The file system can be populated and accessed from PL/SQL with DBMS_DBFS_CONTENT. The file system can be accessed read-only from SQL using the dbfs_content and dbfs_content_properties views.

The file system can also be populated and accessed using regular file system APIs and UNIX utilities when mounted using FUSE, or by the standalone dbfs_client tool (in environments where FUSE is either unavailable or not set up).

16.2.2 Dropping SecureFiles Store File Systems

You can use the unmountStore method to drop SecureFiles Store file systems.

This method removes all stores referring to the file system from the metadata tables, and drops the underlying file system table. The procedure executes like a DDL, auto-committing before and after its execution.

  1. Unmount the store.
    CONNECT sfs_demo/<password>
    
    DECLARE
      BEGIN
        DBMS_DBFS_CONTENT.UNMOUNTSTORE(
          store_name    => 'FS1',
          store_mount   => 'mntl';
        );
        COMMIT;
    END;
    /
    

    where:

    • store_name is FS1, a case-sensitive unique username.

    • store_mount is the mount point.

  2. Unregister the stores.
    CONNECT sfs_demo/<password>
    EXEC DBMS_DBFS_CONTENT.UNREGISTERSTORE(store_name => 'FS1');
    COMMIT;
    

    where store_name is SecureFiles Store FS1, which uses table SFS_DEMO.T1.

  3. Drop the store.
    CONNECT sfs_demo/<password>;
    EXEC DBMS_DBFS_SFS.DROPFILESYSTEM(store_name => 'FS1');
    COMMIT;
    

    where store_name is SecureFiles Store FS1, which uses table SFS_DEMO.T1.