Skip to Main Content
IBM Power Ideas Portal


This portal is to open public enhancement requests against IBM Power Systems products, including IBM i. To view all of your ideas submitted to IBM, create and manage groups of Ideas, or create an idea explicitly set to be either visible by all (public) or visible only to you and IBM (private), use the IBM Unified Ideas Portal (https://ideas.ibm.com).


Shape the future of IBM!

We invite you to shape the future of IBM, including product roadmaps, by submitting ideas that matter to you the most. Here's how it works:

Search existing ideas

Start by searching and reviewing ideas and requests to enhance a product or service. Take a look at ideas others have posted, and add a comment, vote, or subscribe to updates on them if they matter to you. If you can't find what you are looking for,

Post your ideas
  1. Post an idea.

  2. Get feedback from the IBM team and other customers to refine your idea.

  3. Follow the idea through the IBM Ideas process.


Specific links you will want to bookmark for future use

Welcome to the IBM Ideas Portal (https://www.ibm.com/ideas) - Use this site to find out additional information and details about the IBM Ideas process and statuses.

IBM Unified Ideas Portal (https://ideas.ibm.com) - Use this site to view all of your ideas, create new ideas for any IBM product, or search for ideas across all of IBM.

ideasibm@us.ibm.com - Use this email to suggest enhancements to the Ideas process or request help from IBM for submitting your Ideas.

Status Delivered
Workspace IBM i
Categories Db2 for i
Created by Guest
Created on May 15, 2024

SQL Scalar function to check access to an IFS file or folder

IFS_ACCESS - SQL Scalar function to check access to an IFS file or folder


It returns:

0=If the file or folder Exists and you have access

-1=No access or file does not exists


use case:


-- returns 0 for the home folder - it exists

values IFS_ACCESS (

ifs_path => '/home'

);



-- returns -1 for files that does not exists

values IFS_ACCESS (

ifs_path => '/home/does_not_exists'

);


-- returns 0 for the "cat" file exists

values IFS_ACCESS (

ifs_path => '/bin/cat'

);


-- Can i execute /bin/cat

values IFS_ACCESS (

ifs_path => '/bin/cat',

access_type => ifs_access_execute

);


-- Can i write to home folder

values IFS_ACCESS (

ifs_path => '/home',

access_type => ifs_access_write

);



It returns:

0=If the file or folder Exists and you have access

-1=No access or file does not exists



This is a wrapper for the access() unix API:

https://pubs.opengroup.org/onlinepubs/009695299/functions/access.html


Note second parameter is the access mode, that defaults to F_OK

Constants for access() are also declare as SQL global variables


The implementation can be found here:


https://gist.github.com/NielsLiisberg/dd45d94da1cd21a2f4eaa178023ab4f0


or paste from here:

_____________

ifs_access.sql

-- SQL Scalar function to check access to an IFS file or folder


-- It returns:

-- 0=If the file or folder Exists and you have access

-- -1=No access or file does not exists

--

-- This is a wrapper for the access() unix API:

-- https://pubs.opengroup.org/onlinepubs/009695299/functions/access.html


-- Note second parameter is the acces mode, that defaults to F_OK

-- Constants for access() are also declare as SQL global variables


-- Simply paste this gist into ACS SQL and run it to create the feature.


-- Note: I am using library QUSRSYS. I suggest you put it into your own tool library


-- It is a cool example how far you can go with SQL: Have fun -

-- (C) Niels Liisberg 2023


-- This gist is distributed on an "as is" basis, without warranties

-- or conditions of any kind, either express or implied.

----------------------------------------------------------------------------------------------

call qcmdexc ('addlible qsysinc');

--call qcmdexc ('dltf FILE(QTEMP/C) ');

call qcmdexc ('crtsrcpf FILE(QTEMP/C) MBR(C) rcdlen(256)');

truncate qtemp.c;

insert into qtemp.c (srcdta) values

('#include <unistd.h>'),

('IFS_ACCESS.IFS_PATH.DAT[IFS_ACCESS.IFS_PATH.LEN] = 0;'),

('MAIN.RC = access ( IFS_ACCESS.IFS_PATH.DAT , IFS_ACCESS.ACCESS_TYPE);')

;

create or replace function qusrsys.ifs_access (

ifs_path varchar(256) ,

access_type int default 0 -- Posix: 0 = F_OK = Test for existence of a file

)

returns int

specific IFS_ACCESS

no external action

set option output=*print, commit=*none, dbgview = *source

main:

begin

declare rc int default 0;

include qtemp/c(c);

return rc;

end;


-- Constants for access()

create or replace variable qusrsys.ifs_access_read int default 4; -- R_OK 4

create or replace variable qusrsys.ifs_access_write int default 2; -- W_OK 2

create or replace variable qusrsys.ifs_access_execute int default 1; -- X_OK 1


stop;


-- use case:

------------


-- returns 0 for the home folder - it exists

values qusrsys.IFS_ACCESS (

ifs_path => '/home'

);



-- returns -1 for files that does not exists

values qusrsys.IFS_ACCESS (

ifs_path => '/home/does_not_exists'

);


-- returns 0 for the "cat" file exists

values qusrsys.IFS_ACCESS (

ifs_path => '/bin/cat'

);


-- Can i execute /bin/cat

values qusrsys.IFS_ACCESS (

ifs_path => '/bin/cat',

access_type => qusrsys.ifs_access_execute

);


-- Can i write to home folder

values qusrsys.IFS_ACCESS (

ifs_path => '/home',

access_type => qusrsys.ifs_access_write

);



Idea priority High
  • Guest
    Reply
    |
    Dec 13, 2024
    This enhancement was delivered in December 2024 with IBM i 7.5 Database PTF Group level 8 and IBM i 7.4 Database PTF Group level 29.

    A new scalar function, SYSTOOLS.IFS_ACCESS, has been provided.

    See this IBM Documentation page for the details: https://www.ibm.com/docs/en/i/7.5?topic=services-ifs-access-scalar-function

    Db2 for i development team
    IBM Power Systems Development
  • Admin
    Carmelita Ruvalcaba Cevallos
    Reply
    |
    Jul 30, 2024

    The CAAC has reviewed this IBM Idea and recommends that IBM not implement this request.

    This function already exists as en easy call to access API.

    Background: The COMMON Americas Advisory Council (CAAC) members have a broad range of experience in working with small and medium-sized IBM i customers. CAAC has a key role in working with IBM i development to help assess the value and impact of individual IBM Ideas on the broader IBM i community and has therefore reviewed your Idea.

    For more information about CAAC, see www.common.org/caac

    Carmelita Ruvalcaba - CAAC Program Manager

  • Guest
    Reply
    |
    Jun 10, 2024
    IBM will use this Idea as input to planning, but no commitment is made or implied. This Idea will be updated in the future if IBM implements it.

    Db2 for i development team
    IBM Power Systems Development