Carbon only?

  • Hello,

    As many of you know I am writing a class to gather file attributes.
    Everything is going smoothly but I think I've found some attributes that
    need to be accessed via Carbon. Correct me if I'm wrong:

    * Resource Fork Size
    * Data Fork Size
    * Locked
    * Visibility
    * If it resides on read only volume
    * Stationary Pad setting

    Does anyone have a wrapper for the carbon code for any of these? Or are they
    in Cocoa but I missed them?

    Also, I've heard some chatter about aliases in Cocoa and about a class that
    assists in working with them. Anyone know of the class and URL?

    Thanks again,
    --
    Matt Ronge

    President
    Monkeybread Software
    http://www.monkeybreadsoftware.com
  • > Hello,
    >
    > As many of you know I am writing a class to gather file attributes.
    > Everything is going smoothly but I think I've found some attributes that
    > need to be accessed via Carbon. Correct me if I'm wrong:
    >
    > * Resource Fork Size
    > * Data Fork Size
    > * Locked
    > * Visibility
    > * If it resides on read only volume
    > * Stationary Pad setting
    >
    > Does anyone have a wrapper for the carbon code for any of these? Or are they
    > in Cocoa but I missed them?

    I would probably go for Carbon for these, yes. You _can_ find Res/data-fork
    sizes, and maybe readonlyvolume using cocoa/bsd, but for visibility and
    stationary pad setting you will have to go for Carbon.

    > Also, I've heard some chatter about aliases in Cocoa and about a class that
    > assists in working with them. Anyone know of the class and URL?

    BDAlias - <http://bdistributed.com/Projects/BDAlias/>

    > Thanks again,

    / David
  • On Monday, February 11, 2002, at 09:42 PM, David Remahl wrote:
    >> * Resource Fork Size
    >> * Data Fork Size
    >> * Locked
    >> * Visibility
    >> * If it resides on read only volume
    >> * Stationary Pad setting
    >>
    >> Does anyone have a wrapper for the carbon code for any of these? Or
    >> are they
    >> in Cocoa but I missed them?
    >
    > I would probably go for Carbon for these, yes. You _can_ find
    > Res/data-fork
    > sizes, and maybe readonlyvolume using cocoa/bsd, but for visibility and
    > stationary pad setting you will have to go for Carbon.

    Not true... remember that Carbon sits completely (mostly) on top of the
    BSD VFS layer. This means that every Carbon function to get file
    attributes, file allocation routines, etc., etc., ultimately turn into
    calls into Darwin's VFS layer.

    In particular, a lot of the functionality of Carbon is access using
    getattrlist(), and some of the 9-style file manager functions have
    analogues by performing a fcntl() on an open file descriptor.

    I will see if I can whip up some generic code to show some of these
    properties if Matt is interested...
    Although if you are linking against Cocoa you are already getting
    CoreServices, and CarbonCore, so the API is there for you if you
    prefer...

    Shantonu
  • I've created an class for using aliases you can find it at my iTool home
    page at http://homepage.mac.com/nathan_day/ the interface is

    + (id)aliasWithURL:(NSURL *)aURL;
    + (id)aliasWithURL:(NSURL *)aURL fromURL:(NSURL *)aFromURL;
    + (id)aliasWithPath:(NSString *)aPath;
    + (id)aliasWithPath:(NSString *)aPath fromPath:(NSString *)aFromPath;

    - (id)initWithPath:(NSString *)aPath;
    - (id)initWithPath:(NSString *)aPath fromPath:(NSString *)aFromPath;
    - (id)initWithURL:(NSURL *)aURL;
    - (id)initWithURL:(NSURL *)aURL fromURL:(NSURL *)aFromURL;

    - (NSURL *)url;
    - (NSString *)path;
    - (BOOL)changed;

    - (BOOL)setURL:(NSURL *)aURL;
    - (BOOL)setURL:(NSURL *)aURL fromURL:(NSURL *)aFromURL;
    - (BOOL)setPath:(NSString *)aPath;
    - (BOOL)setPath:(NSString *)aPath fromPath:(NSString *)aFromPath;

    On Tuesday, February 12, 2002, at 01:03  PM, Matt Ronge wrote:

    > Also, I've heard some chatter about aliases in Cocoa and about a class
    > that
    > assists in working with them. Anyone know of the class and URL?
  • If anybody downloaded that you might have gat an earlier version where I
    was not autoreleasing the CFURL I was creating, that has been fixed.

    On Wednesday, February 13, 2002, at 12:20  AM, Nathan Day wrote:

    > I've created an class for using aliases you can find it at my iTool
    > home page at http://homepage.mac.com/nathan_day/ the interface is
    >
  • Matt, the following program does most of what you want. For
    readonly-ness, I would call statfs(2), and look at the f_flags field and
    compare it with MNT_RDONLY.

    There are lots of other attributes in /usr/include/sys/attr.h.
    Unfortunately, it's not very self-documenting, but there is a bug to
    write a man page for getattrlist(). The best way to get more info is to
    download the Mac OS X kernel sources (called xnu) from Darwin Open
    Source CVS. In the directory "bsd/hfs", look at "hfs_vfsutils.c". You
    will see:
                    if (a & ATTR_VOL_MINALLOCATION) size += sizeof(off_t);
                    if (a & ATTR_VOL_ALLOCATIONCLUMP) size += sizeof(off_t);
    This defines the storage space for each attribute. You can define your
    own struct (leaving an extra 4-byte word at the beginning - I use a
    u_int32_t) and make entries corresponding to the attributes you want. To
    set attributes (where appropriate), call setattrlist() with a pointer to
    the first word *after* the length word (i.e. you don't need to leave
    space for the function to write data back).

    For instance, I can use the program to get:
    shantonu% ./getHFSAttributes /System/Library/CFMSupport/CarbonLib
                Type: shlb
            Creator: MACS
          kIsOnDesk: NO
              kColor: NO
          kIsShared: NO
        kHasNoINITs: NO
      kHasBeenInited: NO
      kHasCustomIcon: NO
      kIsStationery: NO
        kNameLocked: NO
          kHasBundle: NO
        kIsInvisible: NO
            kIsAlias: NO
        Data fork length:              397860 (0x0000000000061224) bytes
    Resource fork length:                  530 (0x0000000000000212) bytes

    Good luck,
    Shantonu

    /*
      * getHFSAttributes.c
      * Shantonu Sen <ssen...>
      *
      * cc -o getHFSAttributes getHFSAttributes.c
      */

    #include <libc.h>
    #include <sys/attr.h>

    /* From Finder.h. If you (directly of indirectly) include
      * Carbon headers, you might want to rename these.
      */
    enum {
      kIsOnDesk                    = 0x0001, /* Files and folders (System
    6) */
      kColor                        = 0x000E, /* Files and folders */
      kIsShared                    = 0x0040, /* Files only (Applications
    only) */
      kHasNoINITs                  = 0x0080, /* Files only
    (Extensions/Control Panels only) */
      kHasBeenInited                = 0x0100, /* Files only */
      kHasCustomIcon                = 0x0400, /* Files and folders */
      kIsStationery                = 0x0800, /* Files only */
      kNameLocked                  = 0x1000, /* Files and folders */
      kHasBundle                    = 0x2000, /* Files only */
      kIsInvisible                  = 0x4000, /* Files and folders */
      kIsAlias                      = 0x8000 /* Files only */
    };

    #define MSTR(mask) { mask, #mask }
    #define ISSET(bit) ( bit ? "YES" : "NO" )

    const struct ffbit {
      u_int32_t mask;
      char *description;
    } ffarray[] = {
      MSTR(kIsOnDesk),
      MSTR(kColor),
      MSTR(kIsShared),
      MSTR(kHasNoINITs),
      MSTR(kHasBeenInited),
      MSTR(kHasCustomIcon),
      MSTR(kIsStationery),
      MSTR(kNameLocked),
      MSTR(kHasBundle),
      MSTR(kIsInvisible),
      MSTR(kIsAlias)
    };

    struct fileinfobuf {
      u_int32_t info_length;
      union {
        u_int32_t padding[8];
        struct {
          u_int32_t type;
          u_int32_t creator;
          u_int16_t fdFlags;
          u_int16_t location;
          u_int32_t padding[4];
        } info;
      } data;
    };

    struct filesizebuf {
      u_int32_t info_length;
      off_t dataForkSize;
      off_t rsrcForkSize;
    };

    int main(int argc, char *argv[]) {

      struct attrlist alist;
      struct fileinfobuf finfo;

      struct attrlist blist;
      struct filesizebuf fsize;

      char *path = NULL;
      int i;
      int err;

      if(argc != 2) {
        fprintf(stderr, "Please provide a single path\n");
        exit(1);
      }

      path = argv[1];

      alist.bitmapcount = 5;
      alist.reserved = 0;
      alist.commonattr = ATTR_CMN_FNDRINFO;
      alist.volattr = 0;
      alist.dirattr = 0;
      alist.fileattr = 0;
      alist.forkattr = 0;

      /* last argument is whether to resolve symlinks. 0=yes, 1=no */
      err = getattrlist(path, &alist, &finfo, sizeof(finfo),
               FSOPT_NOFOLLOW);

      if(err) {
        fprintf(stderr, "Can't get file information for %s\n", path);
        exit(1);
      }

      printf("          Type: %4.4s\n", &finfo.data.info.type);
      printf("        Creator: %4.4s\n", &finfo.data.info.creator);

      for(i=0; i < sizeof(ffarray)/sizeof(struct ffbit); i++) {
        printf("%15s: %s\n", ffarray[i].description,
         ISSET(finfo.data.info.fdFlags & ffarray[i].mask));

        /* uncomment this if you want to turn all flags on */
        // finfo.data.info.fdFlags |= ffarray[i].mask;

      }

      /* uncomment this if you want to set the type */
      // finfo.data.info.type = 'cool';

      /* uncomment this if you want to write back attributes */
      /*
      err = setattrlist(path, &alist, &finfo.data, sizeof(finfo.data), 1);
      if(err) {
        fprintf(stderr, "Error while setting file information for %s\n",
    path);
        exit(1);
      }
      */

      blist.bitmapcount = 5;
      blist.reserved = 0;
      blist.commonattr = 0;
      blist.volattr = 0;
      blist.dirattr = 0;
      blist.fileattr = ATTR_FILE_DATALENGTH | ATTR_FILE_RSRCLENGTH;
      blist.forkattr = 0;

      /* last argument is whether to resolve symlinks. 0=yes, 1=no */
      err = getattrlist(path, &blist, &fsize, sizeof(fsize),
               FSOPT_NOFOLLOW);
      if(err) {
        fprintf(stderr, "Can't get file size information for %s\n", path);
        exit(1);
      }

      printf("    Data fork length: %20qu (0x%016qX) bytes\n",
        fsize.dataForkSize, fsize.dataForkSize);
      printf("Resource fork length: %20qu (0x%016qX) bytes\n",
        fsize.rsrcForkSize, fsize.rsrcForkSize);

      exit(0);
    }
previous month february 2002 next month
MTWTFSS
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28      
Go to today