コード例 #1
0
  bool processChangeNotify(const pollfd& pfd)
  {
    assert(pfd.fd != -1);
    assert(pfd.revents & POLLIN);

    bool importantChange = false;
    int n = read(pfd.fd, &mNotifyBuffer[0], static_cast<int>(mNotifyBuffer.size()));
    if (n == -1)
    {
      rtLogWarn("failed to read change notify buffer: %d", n);
      return false;
    }
    else
    {
      inotify_event* e = reinterpret_cast<inotify_event *>(&mNotifyBuffer[0]);
      if (e->len)
      {
        size_t n = strlen(e->name);
        if ((n > 4) && (strncmp(e->name, "event", 5) == 0))
        {
          importantChange = true;
          if (deviceExists(e->name))
          {
            rtLogInfo("%s added", e->name);
            waitForDevice(kDevInputByPath);
          }
          else
          {
            rtLogInfo("device removed: %s", e->name);
          }
        }
      }
    }
    return importantChange;
  }
コード例 #2
0
ファイル: UMTSStick.cpp プロジェクト: TheGuv/Firmware
UMTSStickErr UMTSStick::getSerial(UsbSerial** ppUsbSerial)
{
  m_host.init();
  
  UMTSStickErr rc;
  
  rc = waitForDevice();
  if(rc)
    return rc;
   
  //Device is now enumerated, read table
  
  uint16_t vid = m_pDev->getVid();
  uint16_t pid = m_pDev->getPid();
  
  DBG("Configuration set: vid:%04x pid:%04x\n", vid, pid);
    
  bool handled = false;
  bool cdfs = false;
  const UMTSSwitchingInfo* pInfo;
  for(int i = 0; i < UMTS_SWITCHING_COUNT; i++)
  {
    pInfo = &UMTSwitchingTable[i];
    if( !checkDeviceState(pInfo, &cdfs) )
    {
      handled = true;
      break;
    }
    
  } //for(int i = 0; i < UMTS_SWITCHING_COUNT; i++)
  
  if(!handled)
  {
    DBG("Don't know this device!\n");
    return UMTSERR_NOTIMPLEMENTED;
  }
  
  //Check if the device is in CDFS mode, in this case switch
  if(cdfs)
  {
    DBG("Switching the device by sending a magic packet\n");
  
    rc = switchMode(pInfo);
    if(rc)
      return rc;
      
    DBG("Now wait for device to reconnect\n");
    
    m_host.releaseDevice(m_pDev);
      
    //Wait for device to reconnect
    wait(3);
    rc = waitForDevice();
    if(rc)
      return rc;
  }
  
  rc = findSerial(ppUsbSerial);
  if(rc)
    return rc;
  
  return UMTSERR_OK;
}
コード例 #3
0
ファイル: xenstore.c プロジェクト: B-Rich/afterburner
void xenstore_parse_domain_config(int domid)
{
    char **e = NULL;
    char *buf = NULL, *path;
    char *fpath = NULL, *bpath = NULL,
        *dev = NULL, *params = NULL, *type = NULL, *drv = NULL;
    int i, is_scsi, is_hdN = 0;
    unsigned int len, num, hd_index;
    BlockDriverState *bs;

    for(i = 0; i < MAX_DISKS + MAX_SCSI_DISKS; i++)
        media_filename[i] = NULL;

    xsh = xs_daemon_open();
    if (xsh == NULL) {
        fprintf(logfile, "Could not contact xenstore for domain config\n");
        return;
    }

    path = xs_get_domain_path(xsh, domid);
    if (path == NULL) {
        fprintf(logfile, "xs_get_domain_path() error\n");
        goto out;
    }

    if (pasprintf(&buf, "%s/device/vbd", path) == -1)
        goto out;

    e = xs_directory(xsh, XBT_NULL, buf, &num);
    if (e == NULL)
        goto out;

    for (i = 0; i < num; i++) {
        /* read the backend path */
        if (pasprintf(&buf, "%s/device/vbd/%s/backend", path, e[i]) == -1)
            continue;
        free(bpath);
        bpath = xs_read(xsh, XBT_NULL, buf, &len);
        if (bpath == NULL)
            continue;
        /* read the name of the device */
        if (pasprintf(&buf, "%s/dev", bpath) == -1)
            continue;
        free(dev);
        dev = xs_read(xsh, XBT_NULL, buf, &len);
        if (dev == NULL)
            continue;
        if (!strncmp(dev, "hd", 2)) {
            is_hdN = 1;
            break;
        }
    }
        
    for (i = 0; i < num; i++) {
        /* read the backend path */
        if (pasprintf(&buf, "%s/device/vbd/%s/backend", path, e[i]) == -1)
            continue;
        free(bpath);
        bpath = xs_read(xsh, XBT_NULL, buf, &len);
        if (bpath == NULL)
            continue;
        /* read the name of the device */
        if (pasprintf(&buf, "%s/dev", bpath) == -1)
            continue;
        free(dev);
        dev = xs_read(xsh, XBT_NULL, buf, &len);
        if (dev == NULL)
            continue;
        /* Change xvdN to look like hdN */
        if (!is_hdN && !strncmp(dev, "xvd", 3)) {
            fprintf(logfile, "Change xvd%c to look like hd%c\n",
                    dev[3], dev[3]);
            memmove(dev, dev+1, strlen(dev));
            dev[0] = 'h';
            dev[1] = 'd';
        }
        is_scsi = !strncmp(dev, "sd", 2);
        if ((strncmp(dev, "hd", 2) && !is_scsi) || strlen(dev) != 3 )
            continue;
        hd_index = dev[2] - 'a';
        if (hd_index >= (is_scsi ? MAX_SCSI_DISKS : MAX_DISKS))
            continue;
        /* read the type of the device */
        if (pasprintf(&buf, "%s/device/vbd/%s/device-type", path, e[i]) == -1)
            continue;
        free(type);
        type = xs_read(xsh, XBT_NULL, buf, &len);
        if (pasprintf(&buf, "%s/params", bpath) == -1)
            continue;
        free(params);
        params = xs_read(xsh, XBT_NULL, buf, &len);
        if (params == NULL)
            continue;
        /* read the name of the device */
        if (pasprintf(&buf, "%s/type", bpath) == -1)
            continue;
        free(drv);
        drv = xs_read(xsh, XBT_NULL, buf, &len);
        if (drv == NULL)
            continue;
        /* Strip off blktap sub-type prefix aio: - QEMU can autodetect this */
        if (!strcmp(drv, "tap") && params[0]) {
            char *offset = strchr(params, ':'); 
            if (!offset)
                continue ;
            memmove(params, offset+1, strlen(offset+1)+1 );
            fprintf(logfile, "Strip off blktap sub-type prefix to %s\n", params); 
        }
        /* Prefix with /dev/ if needed */
        if (!strcmp(drv, "phy") && params[0] != '/') {
            char *newparams = malloc(5 + strlen(params) + 1);
            sprintf(newparams, "/dev/%s", params);
            free(params);
            params = newparams;
        }

        /* 
         * check if device has a phantom vbd; the phantom is hooked
         * to the frontend device (for ease of cleanup), so lookup 
         * the frontend device, and see if there is a phantom_vbd
         * if there is, we will use resolution as the filename
         */
        if (pasprintf(&buf, "%s/device/vbd/%s/phantom_vbd", path, e[i]) == -1)
            continue;
        free(fpath);
        fpath = xs_read(xsh, XBT_NULL, buf, &len);
        if (fpath) {
            if (pasprintf(&buf, "%s/dev", fpath) == -1)
                continue;
            free(params);
            params = xs_read(xsh, XBT_NULL, buf , &len);
            if (params) {
                /* 
                 * wait for device, on timeout silently fail because we will 
                 * fail to open below
                 */
                waitForDevice(params);
            }
        }

        bs = bs_table[hd_index + (is_scsi ? MAX_DISKS : 0)] = bdrv_new(dev);
        /* check if it is a cdrom */
        if (type && !strcmp(type, "cdrom")) {
            bdrv_set_type_hint(bs, BDRV_TYPE_CDROM);
            if (pasprintf(&buf, "%s/params", bpath) != -1)
                xs_watch(xsh, buf, dev);
        }

        /* open device now if media present */
        if (params[0]) {
            if (bdrv_open(bs, params, 0 /* snapshot */) < 0)
                fprintf(stderr, "qemu: could not open hard disk image '%s'\n",
                        params);
        }
    }

    /* Set a watch for log-dirty requests from the migration tools */
    if (pasprintf(&buf, "/local/domain/0/device-model/%u/logdirty/next-active",
                  domid) != -1) {
        xs_watch(xsh, buf, "logdirty");
        fprintf(logfile, "Watching %s\n", buf);
    }

    /* Set a watch for suspend requests from the migration tools */
    if (pasprintf(&buf, 
                  "/local/domain/0/device-model/%u/command", domid) != -1) {
        xs_watch(xsh, buf, "dm-command");
        fprintf(logfile, "Watching %s\n", buf);
    }

 out:
    free(type);
    free(params);
    free(dev);
    free(bpath);
    free(buf);
    free(path);
    free(e);
    free(drv);
    return;
}