+ return 0;
+}
+
+/* ltt_get_facility_description
+ *
+ * Opens the trace corresponding to the requested facility (identified by fac_id
+ * and checksum).
+ *
+ * The name searched is : %trace root%/eventdefs/facname_checksum.xml
+ *
+ * Returns 0 on success, or 1 on failure.
+ */
+
+static int ltt_get_facility_description(LttFacility *f,
+ LttTrace *t,
+ LttTracefile *fac_tf)
+{
+ char desc_file_name[PATH_MAX];
+ const gchar *text;
+ guint textlen;
+ gint err;
+
+ text = g_quark_to_string(t->pathname);
+ textlen = strlen(text);
+
+ if(textlen >= PATH_MAX) goto name_error;
+ strcpy(desc_file_name, text);
+
+ text = "/eventdefs/";
+ textlen+=strlen(text);
+ if(textlen >= PATH_MAX) goto name_error;
+ strcat(desc_file_name, text);
+
+ text = g_quark_to_string(f->name);
+ textlen+=strlen(text);
+ if(textlen >= PATH_MAX) goto name_error;
+ strcat(desc_file_name, text);
+
+ text = "_";
+ textlen+=strlen(text);
+ if(textlen >= PATH_MAX) goto name_error;
+ strcat(desc_file_name, text);
+
+ err = snprintf(desc_file_name+textlen, PATH_MAX-textlen-1,
+ "%u", f->checksum);
+ if(err < 0) goto name_error;
+
+ textlen=strlen(desc_file_name);
+
+ text = ".xml";
+ textlen+=strlen(text);
+ if(textlen >= PATH_MAX) goto name_error;
+ strcat(desc_file_name, text);
+
+ err = ltt_facility_open(f, t, desc_file_name);
+ if(err) goto facility_error;
+
+ return 0;
+
+facility_error:
+name_error:
+ return 1;
+}
+
+static void ltt_fac_ids_destroy(gpointer data)
+{
+ GArray *fac_ids = (GArray *)data;
+
+ g_array_free(fac_ids, TRUE);
+}
+
+
+/* Presumes the tracefile is already seeked at the beginning. It makes sense,
+ * because it must be done just after the opening */
+static int ltt_process_facility_tracefile(LttTracefile *tf)
+{
+ int err;
+ LttFacility *fac;
+ GArray *fac_ids;
+ guint i;
+ LttEventType *et;
+
+ while(1) {
+ err = ltt_tracefile_read_seek(tf);
+ if(err == EPERM) goto seek_error;
+ else if(err == ERANGE) break; /* End of tracefile */
+
+ err = ltt_tracefile_read_update_event(tf);
+ if(err) goto update_error;
+
+ /* We are on a facility load/or facility unload/ or heartbeat event */
+ /* The rules are :
+ * * facility 0 is hardcoded : this is the core facility. It will be shown
+ * in the facility array though, and is shown as "loaded builtin" in the
+ * trace.
+ * It contains event :
+ * 0 : facility load
+ * 1 : facility unload
+ * 2 : state dump facility load
+ * 3 : heartbeat
+ */
+ if(tf->event.facility_id != LTT_FACILITY_CORE) {
+ /* Should only contain core facility */
+ g_warning("Error in processing facility file %s, "
+ "should not contain facility id %u.", g_quark_to_string(tf->name),
+ tf->event.facility_id);
+ err = EPERM;
+ goto fac_id_error;
+ } else {
+
+ struct LttFacilityLoad *fac_load_data;
+ struct LttStateDumpFacilityLoad *fac_state_dump_load_data;
+ char *fac_name;
+
+ // FIXME align
+ switch((enum ltt_core_events)tf->event.event_id) {
+ case LTT_EVENT_FACILITY_LOAD:
+ fac_name = (char*)(tf->event.data);
+ g_debug("Doing LTT_EVENT_FACILITY_LOAD of facility %s",
+ fac_name);
+ fac_load_data =
+ (struct LttFacilityLoad *)
+ (tf->event.data + strlen(fac_name) + 1);
+ fac = &g_array_index (tf->trace->facilities_by_num, LttFacility,
+ ltt_get_uint32(LTT_GET_BO(tf), &fac_load_data->id));
+ g_assert(fac->exists == 0);
+ fac->name = g_quark_from_string(fac_name);
+ fac->checksum = ltt_get_uint32(LTT_GET_BO(tf),
+ &fac_load_data->checksum);
+ fac->id = ltt_get_uint32(LTT_GET_BO(tf), &fac_load_data->id);
+ fac->pointer_size = ltt_get_uint32(LTT_GET_BO(tf),
+ &fac_load_data->pointer_size);
+ fac->long_size = ltt_get_uint32(LTT_GET_BO(tf),
+ &fac_load_data->long_size);
+ fac->size_t_size = ltt_get_uint32(LTT_GET_BO(tf),
+ &fac_load_data->size_t_size);
+ fac->alignment = ltt_get_uint32(LTT_GET_BO(tf),
+ &fac_load_data->alignment);
+
+ if(ltt_get_facility_description(fac, tf->trace, tf))
+ continue; /* error opening description */
+
+ fac->trace = tf->trace;
+
+ /* Preset the field offsets */
+ for(i=0; i<fac->events->len; i++){
+ et = &g_array_index(fac->events, LttEventType, i);
+ set_fields_offsets(tf, et);
+ }
+
+ fac->exists = 1;