static int get_cb(afs_uint32 idx) { char * p; if (get_fe(fe_cursor.idx)) return 1; if (idx >= fe_cursor.hdr.nCBs) return 1; if (idx == cb_cursor.idx && cb_cursor.cb_valid) return 0; cb_cursor.cb_valid = 0; p = (char *)fe_cursor.fcb; p += idx * sizeof(struct CBDiskEntry); cb_cursor.cursor = (void *)p; cb_cursor.idx = idx; if (get_cb_entry()) return 1; return 0; }
static int find_fe_by_fid(afs_uint32 volid, afs_uint32 vnode, afs_uint32 unique) { int i; if (get_cb_hdr()) { return 1; } for (i = 0; i < hdrs.cb_hdr.nFEs; i++) { if (get_fe(i)) { fprintf(stderr, "error getting fe %d\n", i); return 1; } if ((fe_cursor.fe.fe.unique == unique) && (fe_cursor.fe.fe.volid == volid) && (fe_cursor.fe.fe.vnode == vnode)) break; } if (i < hdrs.cb_hdr.nFEs) { dump_this_fe(); return 0; } return 1; }
static int dvb_dvr_open(struct inode *inode, struct file *file) { struct dvb_device *dvbdev = file->private_data; struct dmxdev *dmxdev = dvbdev->priv; struct dmx_frontend *front; dprintk("function : %s\n", __func__); if (mutex_lock_interruptible(&dmxdev->mutex)) return -ERESTARTSYS; if (dmxdev->exit) { mutex_unlock(&dmxdev->mutex); return -ENODEV; } if ((file->f_flags & O_ACCMODE) == O_RDWR) { if (!(dmxdev->capabilities & DMXDEV_CAP_DUPLEX)) { mutex_unlock(&dmxdev->mutex); return -EOPNOTSUPP; } } if ((file->f_flags & O_ACCMODE) == O_RDONLY) { void *mem; if (!dvbdev->readers) { mutex_unlock(&dmxdev->mutex); return -EBUSY; } mem = vmalloc(DVR_BUFFER_SIZE); if (!mem) { mutex_unlock(&dmxdev->mutex); return -ENOMEM; } dvb_ringbuffer_init(&dmxdev->dvr_buffer, mem, DVR_BUFFER_SIZE); dvbdev->readers--; } if ((file->f_flags & O_ACCMODE) == O_WRONLY) { dmxdev->dvr_orig_fe = dmxdev->demux->frontend; if (!dmxdev->demux->write) { mutex_unlock(&dmxdev->mutex); return -EOPNOTSUPP; } front = get_fe(dmxdev->demux, DMX_MEMORY_FE); if (!front) { mutex_unlock(&dmxdev->mutex); return -EINVAL; } dmxdev->demux->disconnect_frontend(dmxdev->demux); dmxdev->demux->connect_frontend(dmxdev->demux, front); } dvbdev->users++; mutex_unlock(&dmxdev->mutex); return 0; }
static int get_fe(afs_uint32 idx) { int i; char * p; cb_cursor.cb_valid = 0; if (get_cb_hdr()) return 1; if (idx >= hdrs.cb_hdr.nFEs) return 1; if (fe_cursor.idx == idx && fe_cursor.hdr_valid && fe_cursor.fe_valid) return 0; fe_cursor.hdr_valid = fe_cursor.fe_valid = 0; if (fe_cache.cursor == NULL) { fe_cache.cursor = (void **) calloc(hdrs.cb_hdr.nFEs, sizeof(void *)); assert(fe_cache.cursor != NULL); } if (idx && fe_cache.cursor[idx-1] == NULL) { for (i = 0; i < idx; i++) { if (fe_cache.cursor[i] == NULL) { get_fe(i); } } } if (!idx) { fe_cursor.cursor = fe_cursor.ffe; } else if (fe_cursor.cursor == fe_cache.cursor[idx-1]) { p = (char *)fe_cursor.cursor; p += fe_cursor.hdr.len; fe_cursor.cursor = (void *)p; } else { fe_cursor.cursor = fe_cache.cursor[idx-1]; if (get_fe_hdr()) return 1; p = (char *)fe_cursor.cursor; p += fe_cursor.hdr.len; fe_cursor.cursor = (void *)p; } fe_cursor.idx = idx; fe_cache.cursor[idx] = fe_cursor.cursor; if (get_fe_hdr()) return 1; if (get_fe_entry()) return 1; return 0; }
static void dump_fe(afs_uint32 idx) { if (get_fe(idx)) { fprintf(stderr, "error getting fe %d\n", idx); return; } DPFOFF(fe_cursor.cursor); dump_fe_hdr(); dump_fe_entry(); }
static int get_fe_hdr(void) { if (!fe_cursor.cursor) { if(get_fe(fe_cursor.idx)) { return 1; } } memcpy(&fe_cursor.hdr, fe_cursor.cursor, sizeof(struct callback_state_entry_header)); fe_cursor.hdr_valid = 1; return 0; }
static int dvb_dvr_open(struct inode *inode, struct file *file) { struct dvb_device *dvbdev=(struct dvb_device *) file->private_data; struct dmxdev *dmxdev=(struct dmxdev *) dvbdev->priv; struct dmx_frontend *front; dprintk ("function : %s\n", __FUNCTION__); if (down_interruptible (&dmxdev->mutex)) return -ERESTARTSYS; if ((file->f_flags&O_ACCMODE)==O_RDWR) { if (!(dmxdev->capabilities&DMXDEV_CAP_DUPLEX)) { up(&dmxdev->mutex); return -EOPNOTSUPP; } } if ((file->f_flags&O_ACCMODE)==O_RDONLY) { dvb_dmxdev_buffer_init(&dmxdev->dvr_buffer); dmxdev->dvr_buffer.size=DVR_BUFFER_SIZE; dmxdev->dvr_buffer.data=vmalloc(DVR_BUFFER_SIZE); if (!dmxdev->dvr_buffer.data) { up(&dmxdev->mutex); return -ENOMEM; } } if ((file->f_flags&O_ACCMODE)==O_WRONLY) { dmxdev->dvr_orig_fe=dmxdev->demux->frontend; if (!dmxdev->demux->write) { up(&dmxdev->mutex); return -EOPNOTSUPP; } front=get_fe(dmxdev->demux, DMX_MEMORY_FE); if (!front) { up(&dmxdev->mutex); return -EINVAL; } dmxdev->demux->disconnect_frontend(dmxdev->demux); dmxdev->demux->connect_frontend(dmxdev->demux, front); } up(&dmxdev->mutex); return 0; }
int DmxDevDVROpen(dmxdev_t *dmxdev, struct file *file) { dmx_frontend_t *front; if (down_interruptible(&dmxdev->mutex)) return -ERESTARTSYS; if ((file->f_flags&O_ACCMODE)==O_RDWR) { if (!(dmxdev->capabilities&DMXDEV_CAP_DUPLEX)) { up(&dmxdev->mutex); return -EOPNOTSUPP; } } if ((file->f_flags&O_ACCMODE)==O_RDONLY) { DmxDevBufferInit(&dmxdev->dvr_buffer); dmxdev->dvr_buffer.size=DVR_BUFFER_SIZE; dmxdev->dvr_buffer.data=vmalloc(DVR_BUFFER_SIZE); if (!dmxdev->dvr_buffer.data) { up(&dmxdev->mutex); return -ENOMEM; } } if ((file->f_flags&O_ACCMODE)==O_WRONLY) { dmxdev->dvr_orig_fe=dmxdev->demux->frontend; if (!dmxdev->demux->write) { up(&dmxdev->mutex); return -EOPNOTSUPP; } front=get_fe(dmxdev->demux, DMX_MEMORY_FE); if (!front) { up(&dmxdev->mutex); return -EINVAL; } dmxdev->demux->disconnect_frontend(dmxdev->demux); dmxdev->demux->connect_frontend(dmxdev->demux, front); } up(&dmxdev->mutex); return 0; }
static int find_fe_by_index(afs_uint32 idx) { int i; if (get_cb_hdr()) { return 1; } for (i = 0; i < hdrs.cb_hdr.nFEs; i++) { if (get_fe(i)) { fprintf(stderr, "error getting fe %d\n", i); return 1; } if (fe_cursor.fe.index == idx) break; } if (i < hdrs.cb_hdr.nFEs) { dump_this_fe(); return 0; } return 1; }