• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: question about CFURLCreateFileURL
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: question about CFURLCreateFileURL


  • Subject: Re: question about CFURLCreateFileURL
  • From: Jim Luther <email@hidden>
  • Date: Thu, 19 Jan 2012 10:39:06 -0800

Patrick,

The "VolFS" style paths in the form "/.vol/<volumeID>/<dirID>/<name>" or "/.vol/<volumeID>/<CNID>" are built by the Carbon File Manager and are described in this technical Q&A <https://developer.apple.com/legacy/mac/library/#qa/qa2001/qa1113.html#//apple_ref/doc/uid/DTS10001661>.

Those "VolFS" paths are NOT the same as the paths in file reference CFURLs, so you CANNOT create a CFURL with a VolFS path, and then use CFURLCreateFilePathURL() to convert it to a regular POSIX-style path.

The only good way I can think of to convert a "VolFS" style path to a regular POSIX path is to use getattrlist(2) and ask for the ATTR_CMN_FULLPATH attribute. I know you don't work in C, so you'll have to get someone to build a command line tool from this code for you. You can call the tool something like "fullpath". The tool takes the input path, gets the full POSIX path from getattrlist, and then prints that full path to stdout and returns EXIT_SUCCESS (0). If the input path cannot be converted, it prints an error message to stderr and exits with EXIT_FAILURE (1). That way, you can use it from a script.

Hope this works for you.

- Jim

#include <sys/attr.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#pragma pack(push, 4)
struct FullPathAttributeBuffer
{
    u_int32_t length;
    attrreference_t fullPathAttr;
    char fullPathBuf[PATH_MAX];
};
#pragma pack(pop)

int main(int argc, const char * argv[])
{
    int result = EXIT_SUCCESS;
    // make sure there's an input path
    if ( argc == 2 ) {
        const char *inPath = argv[1];
        struct attrlist attrList = {
            ATTR_BIT_MAP_COUNT,
            0,
            ATTR_CMN_FULLPATH,
            0,
            0,
            0,
            0,
        };
        struct FullPathAttributeBuffer  attrBuf;
        // use getattrlist to get the full path from the input path
        if ( getattrlist(inPath, &attrList, &attrBuf, sizeof(attrBuf), FSOPT_NOFOLLOW) == 0 ) {
            if ( attrBuf.fullPathAttr.attr_length > 0 ) {
                // print the full path to stdout
                fprintf(stdout, "%s\n", (const char *)&attrBuf.fullPathAttr + attrBuf.fullPathAttr.attr_dataoffset);
            }
            else {
                // send error message to stderr
                result = EXIT_FAILURE;
                fprintf(stderr, "getattrlist could not obtain a path for %s\n", inPath);
            }
        }
        else {
            // send error message to stderr
            result = EXIT_FAILURE;
            fprintf(stderr, "getattrlist failed to find %s\n", inPath);
        }
    }
    else {
        // send error message to stderr
        result = EXIT_FAILURE;
        fprintf(stderr, "missing input argument\n");
    }
    return ( result );
}

On Jan 19, 2012, at 8:38 AM, Patrick Proniewski wrote:

> Hello,
>
> First, I must admit I'm not a developer. I know almost nothing about compiled languages and I can't write a single line of C code (but I'm proficient with bash).
> I want to track down file access using Dtrace tools like /usr/bin/filebyproc.d or /usr/bin/pathopens.d for example. It appears that some processes access files using their ID instead of their human readable Path. ie. they open /.vol/VOLUME_ID/INODE instead of /path/to/the/file.
> I need to convert this ID URL into a Path URL.
> Mac OS X 10.6 documentation refers to the function CFURLCreateFileURL that is supposed to convert a file-ID URL to a path-based URL. But I can't find any sample code that uses this function, nor any already-made command line utility that provides this conversion.
>
> <http://developer.apple.com/library/mac/#releasenotes/MacOSX/WhatsNewInOSX/Articles/MacOSX10_6.html#//apple_ref/doc/uid/TP40008898-SW1>
>
> First question: am-I right about the possibility to convert /.vol/VOLUME_ID/INODE into /path/to/the/file?
> Second question: if so, is there any sample code I could use, or even better a command line application, or DTrace function that would do the translation?
>
> My purpose is to design a script/utility that would run in the background to collect a log of file accesses over few days/week. The final log would be parsed later for analysis. Later translation of /.vol/VOLUME_ID/INODE into /path/to/the/file (using find for example) is not an option.
> The final analysis would show what files/directories/volumes are accessed, sorted by frequency (or other metric available thru DTrace like seektime, byte…)
>
> Any help appreciated.
>
> Patrick _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Filesystem-dev mailing list      (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Filesystem-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >question about CFURLCreateFileURL (From: Patrick Proniewski <email@hidden>)

  • Prev by Date: question about CFURLCreateFileURL
  • Next by Date: Re: dtrace and full path (was Re: question about CFURLCreateFileURL)
  • Previous by thread: question about CFURLCreateFileURL
  • Next by thread: Re: dtrace and full path (was Re: question about CFURLCreateFileURL)
  • Index(es):
    • Date
    • Thread