📄 device.c
字号:
}/* This function just updates the in_file field. */static gbooleandefault_device_finish_file(Device * self) { self->in_file = FALSE; return TRUE;}/* This function just updates the file number. */static dumpfile_t *default_device_seek_file(Device * self, guint file) { self->in_file = TRUE; self->file = file; return NULL;}/* This function just updates the block number. */static gbooleandefault_device_seek_block(Device * self, guint64 block) { self->block = block; return TRUE;}/* This default implementation serves up static responses, and implements a default response to the "canonical name" property. */static gbooleandefault_device_property_get(Device * self, DevicePropertyId ID, GValue * value) { const PropertyResponse * resp; resp = (PropertyResponse*)g_hash_table_lookup(selfp->property_response, GINT_TO_POINTER(ID)); if (resp == NULL) { if (ID == PROPERTY_CANONICAL_NAME) { g_value_unset_init(value, G_TYPE_STRING); g_value_set_string(value, self->device_name); return TRUE; } else { return FALSE; } } g_value_unset_copy(&resp->response, value); return TRUE;}static gbooleandefault_device_read_to_fd(Device *self, int fd) { return do_consumer_producer_queue(device_read_producer, self, fd_write_consumer, GINT_TO_POINTER(fd));}static gbooleandefault_device_write_from_fd(Device *self, int fd) { return do_consumer_producer_queue(fd_read_producer, GINT_TO_POINTER(fd), device_write_consumer, self);}/* XXX WARNING XXX * All the functions below this comment are stub functions that do nothing * but implement the virtual function table. Call these functions and they * will do what you expect vis-a-vis virtual functions. But don't put code * in them beyond error checking and VFT lookup. */gboolean device_open_device (Device * self, char * device_name){ DeviceClass *klass; g_return_val_if_fail (self != NULL, FALSE); g_return_val_if_fail (IS_DEVICE (self), FALSE); g_return_val_if_fail (device_name != NULL, FALSE); klass = DEVICE_GET_CLASS(self); if(klass->open_device) return (*klass->open_device)(self,device_name); else return FALSE;}ReadLabelStatusFlags device_read_label(Device * self) { DeviceClass * klass; g_return_val_if_fail(self != NULL, FALSE); g_return_val_if_fail(IS_DEVICE(self), FALSE); g_return_val_if_fail(self->access_mode == ACCESS_NULL, FALSE); klass = DEVICE_GET_CLASS(self); if (klass->read_label) { return (klass->read_label)(self); } else { return ~ READ_LABEL_STATUS_SUCCESS; }}gbooleandevice_finish (Device * self) { DeviceClass *klass; g_return_val_if_fail (self != NULL, FALSE); g_return_val_if_fail (IS_DEVICE (self), FALSE); if (self->access_mode == ACCESS_NULL) return TRUE; klass = DEVICE_GET_CLASS(self); if (klass->finish) { return (*klass->finish)(self); } else { return FALSE; }}/* For a good combination of synchronization and public simplicity, this stub function does not take a timestamp, but the actual implementation function does. We generate the timestamp here with time(). */gboolean device_start (Device * self, DeviceAccessMode mode, char * label, char * timestamp){ DeviceClass *klass; g_return_val_if_fail (self != NULL, FALSE); g_return_val_if_fail (IS_DEVICE (self), FALSE); g_return_val_if_fail (mode != ACCESS_NULL, FALSE); g_return_val_if_fail (mode != ACCESS_WRITE || label != NULL, FALSE); klass = DEVICE_GET_CLASS(self); if(klass->start) { char * local_timestamp = NULL; gboolean rv; /* fill in a timestamp if none was given */ if (mode == ACCESS_WRITE && get_timestamp_state(timestamp) == TIME_STATE_REPLACE) { local_timestamp = timestamp = get_proper_stamp_from_time(time(NULL)); } rv = (*klass->start)(self, mode, label, timestamp); amfree(local_timestamp); return rv; } else { return FALSE; }}gbooleandevice_write_block (Device * self, guint size, gpointer block, gboolean short_block){ DeviceClass *klass; g_return_val_if_fail (self != NULL, FALSE); g_return_val_if_fail (IS_DEVICE (self), FALSE); g_return_val_if_fail (size > 0, FALSE); g_return_val_if_fail (short_block || size >= device_write_min_size(self), FALSE); g_return_val_if_fail (size <= device_write_max_size(self), FALSE); g_return_val_if_fail (block != NULL, FALSE); g_return_val_if_fail (IS_WRITABLE_ACCESS_MODE(self->access_mode), FALSE); klass = DEVICE_GET_CLASS(self); if(klass->write_block) return (*klass->write_block)(self,size, block, short_block); else return FALSE;}gboolean device_write_from_fd (Device * self, int fd){ DeviceClass *klass; g_return_val_if_fail (self != NULL, FALSE); g_return_val_if_fail (IS_DEVICE (self), FALSE); g_return_val_if_fail (fd >= 0, FALSE); g_return_val_if_fail (IS_WRITABLE_ACCESS_MODE(self->access_mode), FALSE); klass = DEVICE_GET_CLASS(self); if(klass->write_from_fd) return (*klass->write_from_fd)(self,fd); else return FALSE;}gbooleandevice_start_file (Device * self, const dumpfile_t * jobInfo) { DeviceClass * klass; g_return_val_if_fail (self != NULL, FALSE); g_return_val_if_fail (IS_DEVICE (self), FALSE); g_return_val_if_fail (!(self->in_file), FALSE); g_return_val_if_fail (jobInfo != NULL, FALSE); klass = DEVICE_GET_CLASS(self); if(klass->start_file) return (*klass->start_file)(self, jobInfo ); else return FALSE;}gboolean device_finish_file (Device * self){ DeviceClass *klass; g_return_val_if_fail (self != NULL, FALSE); g_return_val_if_fail (IS_DEVICE (self), FALSE); g_return_val_if_fail (IS_WRITABLE_ACCESS_MODE(self->access_mode), FALSE); g_return_val_if_fail (self->in_file, FALSE); klass = DEVICE_GET_CLASS(self); if(klass->finish_file) return (*klass->finish_file)(self); else return FALSE;}dumpfile_t*device_seek_file (Device * self, guint file){ DeviceClass *klass; g_return_val_if_fail (self != NULL, NULL); g_return_val_if_fail (IS_DEVICE (self), NULL); g_return_val_if_fail (self->access_mode == ACCESS_READ, NULL); klass = DEVICE_GET_CLASS(self); if(klass->seek_file) return (*klass->seek_file)(self,file); else return FALSE;}gboolean device_seek_block (Device * self, guint64 block){ DeviceClass *klass; g_return_val_if_fail (self != NULL, FALSE); g_return_val_if_fail (IS_DEVICE (self), FALSE); g_return_val_if_fail (self->access_mode == ACCESS_READ, FALSE); g_return_val_if_fail (self->in_file, FALSE); klass = DEVICE_GET_CLASS(self); if(klass->seek_block) return (*klass->seek_block)(self,block); else return FALSE;}intdevice_read_block (Device * self, gpointer buffer, int * size){ DeviceClass *klass; g_return_val_if_fail (self != NULL, -1); g_return_val_if_fail (IS_DEVICE (self), -1); g_return_val_if_fail (size != NULL, -1); g_return_val_if_fail (self->access_mode == ACCESS_READ, -1); if (*size != 0) { g_return_val_if_fail (buffer != NULL, -1); } /* Do a quick check here, so fixed-block subclasses don't have to. */ if (*size == 0 && device_write_min_size(self) == device_write_max_size(self)) { *size = device_write_min_size(self); return 0; } klass = DEVICE_GET_CLASS(self); if(klass->read_block) return (*klass->read_block)(self,buffer,size); else return -1;}gboolean device_read_to_fd (Device * self, int fd){ DeviceClass *klass; g_return_val_if_fail (self != NULL, FALSE); g_return_val_if_fail (IS_DEVICE (self), FALSE); g_return_val_if_fail (fd >= 0, FALSE); g_return_val_if_fail (self->access_mode == ACCESS_READ, FALSE); klass = DEVICE_GET_CLASS(self); if(klass->read_to_fd) return (*klass->read_to_fd)(self,fd); else return FALSE;}gboolean device_property_get (Device * self, DevicePropertyId id, GValue * val){ DeviceClass *klass; g_return_val_if_fail (self != NULL, FALSE); g_return_val_if_fail (IS_DEVICE (self), FALSE); g_return_val_if_fail (device_property_get_by_id(id) != NULL, FALSE); klass = DEVICE_GET_CLASS(self); /* FIXME: Check access flags? */ if(klass->property_get) return (*klass->property_get)(self,id,val); else return FALSE;}gboolean device_property_set (Device * self, DevicePropertyId id, GValue * val){ DeviceClass *klass; g_return_val_if_fail (self != NULL, FALSE); g_return_val_if_fail (IS_DEVICE (self), FALSE); klass = DEVICE_GET_CLASS(self); /* FIXME: Check access flags? */ if(klass->property_set) return (*klass->property_set)(self,id,val); else return FALSE;}gboolean device_recycle_file (Device * self, guint filenum){ DeviceClass *klass; g_return_val_if_fail (self != NULL, FALSE); g_return_val_if_fail (IS_DEVICE (self), FALSE); g_return_val_if_fail (self->access_mode == ACCESS_APPEND, FALSE); klass = DEVICE_GET_CLASS(self); if(klass->recycle_file) return (*klass->recycle_file)(self,filenum); else return FALSE;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -