Software Development Kit (SDK) and API Discussions

How to rename a file from NM SDK API

SPERKMANDL
4,885 Views

Hello all, the file group in Manageability SDK does not allow to rename a file, only directories.

Is there anything I missed about this operation?

8 REPLIES 8

sens
4,885 Views

Yeah, apparently there is no API to rename a file.

However, you can indirectly achieve the "rename" functionality for file with existing APIs as discussed below:

# Assuming we want to rename file fileA to fileB. Both files are under /vol/myvol/mydir


Step 1: Execute file-get-file-info API for existing file:

     <file-get-file-info>

         <path>/vol/myvol/mydir/fileA</path>

     </file-get-file-info>

Get the value of "file-size" from the API response (say, the obtained value is 14)

Step 2: Read the data from the file:

  <file-read-file>

    <length>14</length>

    <offset>0</offset>

    <path>/vol/myvol/mydir/fileA</path>

  </file-read-file>

And get the value of "data" from the API response (say, the obtained value is 53756e204175672031322030303a)

Step 3: Write the data into the new non-existing file:

  <file-write-file>

    <data>53756e204175672031322030303a</data>

    <offset>0</offset>

    <path>/vol/myvol/mydir/fileB</path>

  </file-write-file>

Step 4: Finally delete the original file:

  <file-delete-file>

    <path>/vol/myvol/mydir/fileA</path>

  </file-delete-file>

SPERKMANDL
4,885 Views

Thanks, but this solution requires a full copy price to pay.

In practice. this is feasible for small files only.

IMHO it doesn't make sense to miss a renaming feature from any file-oriented interface.

Even more strange, there is a directory renaming.

sens
4,885 Views

True, this solution can be applied only for the files with size less than 1 MB.

We can file a bug report on Data ONTAP to get this addressed.

rle
NetApp Alumni
4,885 Views

Hi Renzo,

The file-* APIs were created to manipulate ONTAP system files, which are less that 1M.  At the time, there was no need to rename files.

The file-* APIs are NOT a replacement for a general file system calls.  Please use NFS or CIFS.

Regards,

   - Rick -

SPERKMANDL
4,885 Views

Hi Rick, this is a surprise. File-* API contains all is needed to manipulate a filesystem, except for file renaming and file locking.

Furthermore I have some doubts concerning performance, being forced to hex encoding (potentially) large binary contents.

I need NetApp to implement a DMS storage subsystem, and I wanted to stay away from OS dependencies (CIFS for Windows clients, NFS for Unix clients).

However it seems I have to redesign the entire stuff.

rle
NetApp Alumni
4,885 Views

Hi Renzo -

I can understand your disappointment; however, I think it is better to work on top of well-know, and well tested file systems.  As for OS dependencies, NFS works on Windows and UNIX/Linux; and CIFS works on UNIX/Linux via SAMBA.

Regards,

   - Rick -

SPERKMANDL
4,885 Views

Hi Rick, indeed I'm considering to use JCIFS as common element, being constrained to the Java world.

Thanks and regards,

Renzo

sens
4,885 Views

Hi Renzo,

file-rename-file API is available in the Vserver context of Cluster Mode ONTAP.

Regards,

Sen.

Public