DiskArbitration & Finder

  • Hi,

    I'm playing with DiskArbitration and I am trying to block the
    insertion of CD, DVD (and other types of volumes, but it's not
    relevant to my question)

    I'm sucessful at intercepting the insertion of a CD/DVD and ejecting
    it as soon as it is inserted, but, if I leave the CD/DVD prefpane
    settings to, let's say, open iTunes when a music CD is inserted,
    itunes is launched even if my app ejects the CD. Same thing happens
    if I insert a blank CD: the finder asks me what I want to do with it,
    while my app is ejecting the CD in the background.

    How is it possible to intercept these insertion events, without
    changing the CD/DVD prefpane?

    my code is as follow:

    /* Init */
    mySession = DASessionCreate(kCFAllocatorDefault);
    DASessionScheduleWithRunLoop(mySession, CFRunLoopGetCurrent(),
    kCFRunLoopDefaultMode);
    DARegisterDiskAppearedCallback(mySession,
    kDADiskDescriptionMatchMediaWhole, diskAppearedCallback, NULL);
    DARegisterDiskDisappearedCallback(mySession,
    kDADiskDescriptionMatchMediaWhole, diskDisappearedCallback, NULL);

    And the diskAppearedCallback is:

    static void diskAppearedCallback(DADiskRef disk, void * userInfo)
    {
    NSLog(@"diskAppearedCallback");
    DADiskEject(disk, kDADiskEjectOptionDefault, ejectCallback, userInfo);
    }

    Thanks for any help,
    Stephan Burlot
  • AFAIK you shouldn't be waiting for the disk to appear. Wouldn't you
    want to register an approval session, register an approval callback
    and return a dissenter from your callback?

    -- Finlay

    On 02/12/06, Stephan Burlot <apple_list...> wrote:
    > Hi,
    >
    > I'm playing with DiskArbitration and I am trying to block the
    > insertion of CD, DVD (and other types of volumes, but it's not
    > relevant to my question)
    >
    > I'm sucessful at intercepting the insertion of a CD/DVD and ejecting
    > it as soon as it is inserted, but, if I leave the CD/DVD prefpane
    > settings to, let's say, open iTunes when a music CD is inserted,
    > itunes is launched even if my app ejects the CD. Same thing happens
    > if I insert a blank CD: the finder asks me what I want to do with it,
    > while my app is ejecting the CD in the background.
    >
    > How is it possible to intercept these insertion events, without
    > changing the CD/DVD prefpane?
    >
    > my code is as follow:
    >
    > /* Init */
    > mySession = DASessionCreate(kCFAllocatorDefault);
    > DASessionScheduleWithRunLoop(mySession, CFRunLoopGetCurrent(),
    > kCFRunLoopDefaultMode);
    > DARegisterDiskAppearedCallback(mySession,
    > kDADiskDescriptionMatchMediaWhole, diskAppearedCallback, NULL);
    > DARegisterDiskDisappearedCallback(mySession,
    > kDADiskDescriptionMatchMediaWhole, diskDisappearedCallback, NULL);
    >
    > And the diskAppearedCallback is:
    >
    > static void diskAppearedCallback(DADiskRef disk, void * userInfo)
    > {
    > NSLog(@"diskAppearedCallback");
    > DADiskEject(disk, kDADiskEjectOptionDefault, ejectCallback, userInfo);
    > }
    >
    > Thanks for any help,
    > Stephan Burlot
    >
  • Nice! it works!

    Now, how can I intercept unformatted CD/DVD ?

    I've tried to register a callback with
    DARegisterDiskMountApprovalCallback(approvalSession,
    kDADiskDescriptionMatchMediaWhole, mountApprovalCallback, NULL);
    or
    DARegisterDiskMountApprovalCallback(approvalSession, NULL,
    mountApprovalCallback, NULL);

    but the callback is not called when the disk is not formatted (but is
    called when the disk contains something).

    I've looked at the DiskArbitration code from oopendarwin, but I cant
    see any callback called when the disk is not formatted (or
    unrecognized, I suppose it's the same)

    Any hints?

    Regards,
    Stephan

    Le 3 déc. 06 à 03:40, Finlay Dobbie a écrit :

    > AFAIK you shouldn't be waiting for the disk to appear. Wouldn't you
    > want to register an approval session, register an approval callback
    > and return a dissenter from your callback?
    >
    > -- Finlay
    >
    > On 02/12/06, Stephan Burlot <apple_list...> wrote:
    >> Hi,
    >>
    >> I'm playing with DiskArbitration and I am trying to block the
    >> insertion of CD, DVD (and other types of volumes, but it's not
    >> relevant to my question)
    >>
    >> I'm sucessful at intercepting the insertion of a CD/DVD and ejecting
    >> it as soon as it is inserted, but, if I leave the CD/DVD prefpane
    >> settings to, let's say, open iTunes when a music CD is inserted,
    >> itunes is launched even if my app ejects the CD. Same thing happens
    >> if I insert a blank CD: the finder asks me what I want to do with it,
    >> while my app is ejecting the CD in the background.
    >>
    >> How is it possible to intercept these insertion events, without
    >> changing the CD/DVD prefpane?
    >>
    >> my code is as follow:
    >>
    >> /* Init */
    >> mySession = DASessionCreate(kCFAllocatorDefault);
    >> DASessionScheduleWithRunLoop(mySession, CFRunLoopGetCurrent
    >> (),
    >> kCFRunLoopDefaultMode);
    >> DARegisterDiskAppearedCallback(mySession,
    >> kDADiskDescriptionMatchMediaWhole, diskAppearedCallback, NULL);
    >> DARegisterDiskDisappearedCallback(mySession,
    >> kDADiskDescriptionMatchMediaWhole, diskDisappearedCallback, NULL);
    >>
    >> And the diskAppearedCallback is:
    >>
    >> static void diskAppearedCallback(DADiskRef disk, void * userInfo)
    >> {
    >> NSLog(@"diskAppearedCallback");
    >> DADiskEject(disk, kDADiskEjectOptionDefault,
    >> ejectCallback, userInfo);
    >> }
    >>
    >> Thanks for any help,
    >> Stephan Burlot
    >>
  • On 3 Dec 2006, at 13:09, Stephan Burlot wrote:

    > Nice! it works!
    >
    > Now, how can I intercept unformatted CD/DVD ?

    Have you considered using the acquireMediaReservation method on
    DRDevice?

    -- Dave

    >
    > I've tried to register a callback with
    > DARegisterDiskMountApprovalCallback(approvalSession,
    > kDADiskDescriptionMatchMediaWhole, mountApprovalCallback, NULL);
    > or
    > DARegisterDiskMountApprovalCallback(approvalSession, NULL,
    > mountApprovalCallback, NULL);
    >
    > but the callback is not called when the disk is not formatted (but
    > is called when the disk contains something).
    >
    > I've looked at the DiskArbitration code from oopendarwin, but I
    > cant see any callback called when the disk is not formatted (or
    > unrecognized, I suppose it's the same)
    >
    > Any hints?
    >
    > Regards,
    > Stephan
    >
    >
    >
    > Le 3 déc. 06 à 03:40, Finlay Dobbie a écrit :
    >
    >> AFAIK you shouldn't be waiting for the disk to appear. Wouldn't you
    >> want to register an approval session, register an approval callback
    >> and return a dissenter from your callback?
    >>
    >> -- Finlay
    >>
    >> On 02/12/06, Stephan Burlot <apple_list...> wrote:
    >>> Hi,
    >>>
    >>> I'm playing with DiskArbitration and I am trying to block the
    >>> insertion of CD, DVD (and other types of volumes, but it's not
    >>> relevant to my question)
    >>>
    >>> I'm sucessful at intercepting the insertion of a CD/DVD and ejecting
    >>> it as soon as it is inserted, but, if I leave the CD/DVD prefpane
    >>> settings to, let's say, open iTunes when a music CD is inserted,
    >>> itunes is launched even if my app ejects the CD. Same thing happens
    >>> if I insert a blank CD: the finder asks me what I want to do with
    >>> it,
    >>> while my app is ejecting the CD in the background.
    >>>
    >>> How is it possible to intercept these insertion events, without
    >>> changing the CD/DVD prefpane?
    >>>
    >>> my code is as follow:
    >>>
    >>> /* Init */
    >>> mySession = DASessionCreate(kCFAllocatorDefault);
    >>> DASessionScheduleWithRunLoop(mySession,
    >>> CFRunLoopGetCurrent(),
    >>> kCFRunLoopDefaultMode);
    >>> DARegisterDiskAppearedCallback(mySession,
    >>> kDADiskDescriptionMatchMediaWhole, diskAppearedCallback, NULL);
    >>> DARegisterDiskDisappearedCallback(mySession,
    >>> kDADiskDescriptionMatchMediaWhole, diskDisappearedCallback, NULL);
    >>>
    >>> And the diskAppearedCallback is:
    >>>
    >>> static void diskAppearedCallback(DADiskRef disk, void * userInfo)
    >>> {
    >>> NSLog(@"diskAppearedCallback");
    >>> DADiskEject(disk, kDADiskEjectOptionDefault,
    >>> ejectCallback, userInfo);
    >>> }
    >>>
    >>> Thanks for any help,
    >>> Stephan Burlot
    >>>

    >

    ------
    David Kennedy (http://www.zenopolis.com)
  • That's it! I havent tried yet, but this should solve my problem.

    Thanks a lot!

    Stephan

    Le 3 déc. 06 à 14:31, Citizen a écrit :

    >
    > On 3 Dec 2006, at 13:09, Stephan Burlot wrote:
    >
    >> Nice! it works!
    >>
    >> Now, how can I intercept unformatted CD/DVD ?
    >
    > Have you considered using the acquireMediaReservation method on
    > DRDevice?
    >
    > -- Dave
    >
    >>
    >> I've tried to register a callback with
    >> DARegisterDiskMountApprovalCallback(approvalSession,
    >> kDADiskDescriptionMatchMediaWhole, mountApprovalCallback, NULL);
    >> or
    >> DARegisterDiskMountApprovalCallback(approvalSession, NULL,
    >> mountApprovalCallback, NULL);
    >>
    >> but the callback is not called when the disk is not formatted (but
    >> is called when the disk contains something).
    >>
    >> I've looked at the DiskArbitration code from oopendarwin, but I
    >> cant see any callback called when the disk is not formatted (or
    >> unrecognized, I suppose it's the same)
    >>
    >> Any hints?
    >>
    >> Regards,
    >> Stephan
    >>
    >>
    >>
    >> Le 3 déc. 06 à 03:40, Finlay Dobbie a écrit :
    >>
    >>> AFAIK you shouldn't be waiting for the disk to appear. Wouldn't you
    >>> want to register an approval session, register an approval callback
    >>> and return a dissenter from your callback?
    >>>
    >>> -- Finlay
    >>>
    >>> On 02/12/06, Stephan Burlot <apple_list...> wrote:
    >>>> Hi,
    >>>>
    >>>> I'm playing with DiskArbitration and I am trying to block the
    >>>> insertion of CD, DVD (and other types of volumes, but it's not
    >>>> relevant to my question)
    >>>>
    >>>> I'm sucessful at intercepting the insertion of a CD/DVD and
    >>>> ejecting
    >>>> it as soon as it is inserted, but, if I leave the CD/DVD prefpane
    >>>> settings to, let's say, open iTunes when a music CD is inserted,
    >>>> itunes is launched even if my app ejects the CD. Same thing happens
    >>>> if I insert a blank CD: the finder asks me what I want to do
    >>>> with it,
    >>>> while my app is ejecting the CD in the background.
    >>>>
    >>>> How is it possible to intercept these insertion events, without
    >>>> changing the CD/DVD prefpane?
    >>>>
    >>>> my code is as follow:
    >>>>
    >>>> /* Init */
    >>>> mySession = DASessionCreate(kCFAllocatorDefault);
    >>>> DASessionScheduleWithRunLoop(mySession,
    >>>> CFRunLoopGetCurrent(),
    >>>> kCFRunLoopDefaultMode);
    >>>> DARegisterDiskAppearedCallback(mySession,
    >>>> kDADiskDescriptionMatchMediaWhole, diskAppearedCallback, NULL);
    >>>> DARegisterDiskDisappearedCallback(mySession,
    >>>> kDADiskDescriptionMatchMediaWhole, diskDisappearedCallback, NULL);
    >>>>
    >>>> And the diskAppearedCallback is:
    >>>>
    >>>> static void diskAppearedCallback(DADiskRef disk, void * userInfo)
    >>>> {
    >>>> NSLog(@"diskAppearedCallback");
    >>>> DADiskEject(disk, kDADiskEjectOptionDefault,
    >>>> ejectCallback, userInfo);
    >>>> }
    >>>>
    >>>> Thanks for any help,
    >>>> Stephan Burlot
    >>>>

    >>
    >
    > ------
    > David Kennedy (http://www.zenopolis.com)
    >
previous month december 2006 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 29 30 31
Go to today