BRL-CAD
Loading...
Searching...
No Matches
db_io.h
Go to the documentation of this file.
1/* D B _ I O . H
2 * BRL-CAD
3 *
4 * Copyright (c) 1993-2026 United States Government as represented by
5 * the U.S. Army Research Laboratory.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * version 2.1 as published by the Free Software Foundation.
10 *
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this file; see the file named COPYING for more
18 * information.
19 */
20/** @file rt/db_io.h
21 *
22 */
23
24#ifndef RT_DB_IO_H
25#define RT_DB_IO_H
26
27#include "common.h"
28
29/* system headers */
30#include <stdio.h> /* for FILE */
31
32/* interface headers */
33#include "vmath.h"
34#include "bu/avs.h"
35#include "rt/db5.h"
36#include "rt/defines.h"
37#include "rt/resource.h"
38
40
41
42struct rt_db_internal; /* forward declaration */
43struct db_i; /* forward declaration */
44struct directory; /* forward declaration */
45struct rt_wdb; /* forward declaration */
46
47
48/* db_open.c */
49/**
50 * Ensure that the on-disk database has been completely written out of
51 * the operating system's cache.
52 */
53RT_EXPORT extern void db_sync(struct db_i *dbip);
54
55
56
57/* close a model database */
58/**
59 * De-register a client of this database instance, if provided, and
60 * close out the instance.
61 */
62RT_EXPORT extern void db_close_client(struct db_i *dbip,
63 long *client);
64
65/**
66 * Check if a specified path is a .g database file, based on identification (or
67 * not) of a valid .g file header. Returns the dbi_version if the file has a
68 * valid header, and -1 otherwise.
69 *
70 * Note that this routine does NOT do the endian-flipping tests to spot
71 * big-endian v4 .g files in the case where a valid header is not found - files
72 * are assumed to be either v5 or little endian v4 formatted. Codes willing to
73 * take the performance vs robustness tradeoff of the endian flipping check
74 * (which will do more file reading than this basic check) should use db_open.
75 */
76RT_EXPORT extern int db_filetype(const char *file_path);
77
78/* dump a full copy of a database */
79/**
80 * Dump a full copy of one database into another. This is a good way
81 * of committing a ".inmem" database to a ".g" file. The input is a
82 * database instance, the output is a LIBWDB object, which could be a
83 * disk file or another database instance.
84 *
85 * Returns -
86 * -1 error
87 * 0 success
88 */
89RT_EXPORT extern int db_dump(struct rt_wdb *wdbp,
90 struct db_i *dbip);
91
92/**
93 * Obtain an additional instance of this same database. A new client
94 * is registered at the same time if one is specified.
95 */
96RT_EXPORT extern struct db_i *db_clone_dbi(struct db_i *dbip,
97 long *client);
98
99
100/**
101 * Create a v5 database "free" object of the specified size, and place
102 * it at the indicated location in the database.
103 *
104 * There are two interesting cases:
105 * - The free object is "small". Just write it all at once.
106 * - The free object is "large". Write header and trailer
107 * separately
108 *
109 * @return 0 OK
110 * @return -1 Fail. This is a horrible error.
111 */
112RT_EXPORT extern int db5_write_free(struct db_i *dbip,
113 struct directory *dp,
114 size_t length);
115
116
117/**
118 * Change the size of a v5 database object.
119 *
120 * If the object is getting smaller, break it into two pieces, and
121 * write out free objects for both. The caller is expected to
122 * re-write new data on the first one.
123 *
124 * If the object is getting larger, seek a suitable "hole" large
125 * enough to hold it, throwing back any surplus, properly marked.
126 *
127 * If the object is getting larger and there is no suitable "hole" in
128 * the database, extend the file, write a free object in the new
129 * space, and write a free object in the old space.
130 *
131 * There is no point to trying to extend in place, that would require
132 * two searches through the memory map, and doesn't save any disk I/O.
133 *
134 * Returns -
135 * 0 OK
136 * -1 Failure
137 */
138RT_EXPORT extern int db5_realloc(struct db_i *dbip,
139 struct directory *dp,
140 struct bu_external *ep);
141
142
143/**
144 * A routine for merging together the three optional parts of an
145 * object into the final on-disk format. Results in extra data
146 * copies, but serves as a starting point for testing. Any of name,
147 * attrib, and body may be null.
148 */
150 int dli,
151 const char *name,
152 const unsigned char hidden,
153 const struct bu_external *attrib,
154 const struct bu_external *body,
155 int major,
156 int minor,
157 int a_zzz,
158 int b_zzz);
159
160
161/**
162 * The attributes are taken from ip->idb_avs
163 *
164 * If present, convert attributes to on-disk format. This must happen
165 * after exporting the body, in case the ft_export5() method happened
166 * to extend the attribute set. Combinations are one "solid" which
167 * does this.
168 *
169 * The internal representation is NOT freed, that's the caller's job.
170 *
171 * The 'ext' pointer is accepted in uninitialized form, and an
172 * initialized structure is always returned, so that the caller may
173 * free it even when an error return is given.
174 *
175 * Returns -
176 * 0 OK
177 * -1 FAIL
178 */
180 const char *name,
181 const struct rt_db_internal *ip,
182 double conv2mm,
183 struct db_i *dbip,
184 const int major);
185
187 const char *name,
188 const struct rt_db_internal *ip,
189 double conv2mm,
190 struct db_i *dbip,
191 struct resource *resp,
192 const int major);
193
194
195/*
196 * Modify name of external object, if necessary.
197 */
199 const char *name);
200
201
202/**
203 * Given an external representation of a database object, convert
204 * it into its internal representation.
205 *
206 * Returns -
207 * <0 On error
208 * id On success.
209 */
210RT_EXPORT extern int
212 struct rt_db_internal *ip,
213 const struct bu_external *ep,
214 const char *name,
215 const struct db_i *dbip,
216 const mat_t mat);
217
218/**
219 * Get an object from the database, and convert it into its internal
220 * representation.
221 *
222 * Applications and middleware shouldn't call this directly, they
223 * should use the generic interface "rt_db_get_internal()".
224 *
225 * Returns -
226 * <0 On error
227 * id On success.
228 */
230 const struct directory *dp,
231 const struct db_i *dbip,
232 const mat_t mat);
233
234
235/**
236 * Convert the internal representation of a solid to the external one,
237 * and write it into the database.
238 *
239 * Applications and middleware shouldn't call this directly, they
240 * should use the version-generic interface "rt_db_put_internal()".
241 *
242 * The internal representation is always freed. (Not the pointer,
243 * just the contents).
244 *
245 * Returns -
246 * <0 error
247 * 0 success
248 *
249 * NOTE - since resp isn't the last parameter, we're leaving this but
250 * putting deprecated on it - use rt_db_put_internal_v5 until the
251 * deprecation is complete. At that point we'll rename back to
252 * rt_db_put_internal5 as a minimally impacting change.
253 */
255 struct db_i *dbip,
256 struct rt_db_internal *ip,
257 struct resource *resp,
258 const int major);
259
260
262 struct db_i *dbip,
263 struct rt_db_internal *ip,
264 const int major);
265
266
267/**
268 * Make only the front (header) portion of a free object. This is
269 * used when operating on very large contiguous free objects in the
270 * database (e.g. 50 MBytes).
271 */
273 size_t length);
274
275
276/**
277 * Make a complete, zero-filled, free object. Note that free objects
278 * can sometimes get quite large.
279 */
281 size_t length);
282
283
284/**
285 * Given a variable-width length field character pointer (cp) in
286 * network order (XDR), store it in *lenp.
287 *
288 * Format is typically expected to be one of:
289 * DB5HDR_WIDTHCODE_8BIT
290 * DB5HDR_WIDTHCODE_16BIT
291 * DB5HDR_WIDTHCODE_32BIT
292 * DB5HDR_WIDTHCODE_64BIT
293 *
294 * Returns -
295 * The number of bytes of input that were decoded.
296 */
297RT_EXPORT extern size_t db5_decode_signed(size_t *lenp,
298 const unsigned char *cp,
299 int format);
300
301/**
302 * Given a variable-width length field in network order (XDR), store
303 * it in *lenp.
304 *
305 * This routine processes unsigned values.
306 *
307 * Returns -
308 * The number of bytes of input that were decoded.
309 */
310RT_EXPORT extern size_t db5_decode_length(size_t *lenp,
311 const unsigned char *cp,
312 int format);
313#if defined(USE_BINARY_ATTRIBUTES)
314/**
315 * Given a pointer to a binary attribute, determine its length.
316 */
317RT_EXPORT extern void decode_binary_attribute(const size_t len,
318 const unsigned char *cp);
319#endif
320
321/**
322 * Given a number to encode, decide which is the smallest encoding
323 * format which will contain it.
324 */
326
327
328RT_EXPORT extern void db5_import_color_table(struct db_i *dbip, char *cp);
329
330/**
331 * Given a value and a variable-width format spec, store it in network
332 * order.
333 *
334 * Returns -
335 * pointer to next available byte.
336 */
337RT_EXPORT extern unsigned char *db5_encode_length(unsigned char *cp,
338 size_t val,
339 int format);
340
341/**
342 * Given a pointer to the memory for a serialized database object, get
343 * a raw internal representation.
344 *
345 * Returns -
346 * on success, pointer to next unused byte in 'ip' after object got;
347 * NULL, on error.
348 */
349RT_EXPORT extern const unsigned char *db5_get_raw_internal_ptr(struct db5_raw_internal *rip,
350 const unsigned char *ip);
351
352
353/**
354 * Given a file pointer to an open geometry database positioned on a
355 * serialized object, get a raw internal representation.
356 *
357 * Returns -
358 * 0 on success
359 * -1 on EOF
360 * -2 on error
361 */
363 FILE *fp);
364
365
366/**
367 * Verify that this is a valid header for a BRL-CAD v5 database.
368 *
369 * Returns -
370 * 0 Not valid v5 header
371 * 1 Valid v5 header
372 */
373RT_EXPORT extern int db5_header_is_valid(const unsigned char *hp);
374
375
376/**
377 * write an ident header (title and units) to the provided file
378 * pointer.
379 *
380 * Returns -
381 * 0 Success
382 * -1 Error
383 */
384RT_EXPORT extern int db5_fwrite_ident(FILE *,
385 const char *,
386 double);
387
388
389/**
390 *
391 * Given that caller already has an external representation of the
392 * database object, update it to have a new name (taken from
393 * dp->d_namep) in that external representation, and write the new
394 * object into the database, obtaining different storage if the size
395 * has changed.
396 *
397 * Changing the name on a v5 object is a relatively expensive
398 * operation.
399 *
400 * Caller is responsible for freeing memory of external
401 * representation, using bu_free_external().
402 *
403 * This routine is used to efficiently support MGED's "cp" and "keep"
404 * commands, which don't need to import and decompress objects just to
405 * rename and copy them.
406 *
407 * Returns -
408 * -1 error
409 * 0 success
410 */
412 struct directory *dp,
413 struct db_i *dbip);
414
415/**
416 * As the v4 database does not really have the notion of "wrapping",
417 * this function writes the object name into the proper place (a
418 * standard location in all granules).
419 */
421 const char *name);
422
423
424/* db_io.c */
425RT_EXPORT extern int db_write(struct db_i *dbip,
426 const void * addr,
427 size_t count,
428 b_off_t offset);
429
430/**
431 * Reads 'count' bytes at file offset 'offset' into buffer at 'addr'.
432 * A wrapper for the UNIX read() sys-call that takes into account
433 * syscall semaphores, stdio-only machines, and in-memory buffering.
434 *
435 * Returns -
436 * 0 OK
437 * -1 FAILURE
438 */
439RT_EXPORT extern int
440db_read(const struct db_i *dbip,
441 void *addr,
442 size_t count,
443 b_off_t offset);
444
445/**
446 * Add name from dp->d_namep to external representation of solid, and
447 * write it into a file.
448 *
449 * Caller is responsible for freeing memory of external
450 * representation, using bu_free_external().
451 *
452 * The 'name' field of the external representation is modified to
453 * contain the desired name. The 'ep' parameter cannot be const.
454 *
455 * THIS ROUTINE ONLY SUPPORTS WRITING V4 GEOMETRY.
456 *
457 * Returns -
458 * <0 error
459 * 0 OK
460 *
461 * NOTE: Callers of this should be using wdb_export_external()
462 * instead.
463 */
464RT_EXPORT extern int db_fwrite_external(FILE *fp,
465 const char *name,
466 struct bu_external *ep);
467
468/* malloc & read records */
469
470/**
471 * Retrieve all records in the database pertaining to an object, and
472 * place them in malloc()'ed storage, which the caller is responsible
473 * for free()'ing.
474 *
475 * This loads the combination into a local record buffer. This is in
476 * external v4 format.
477 *
478 * Returns -
479 * union record * - OK
480 * (union record *)0 - FAILURE
481 */
482RT_EXPORT extern union record *db_getmrec(const struct db_i *,
483 const struct directory *dp);
484/* get several records from db */
485
486/**
487 * Retrieve 'len' records from the database, "offset" granules into
488 * this entry.
489 *
490 * Returns -
491 * 0 OK
492 * -1 FAILURE
493 */
494RT_EXPORT extern int db_get(const struct db_i *,
495 const struct directory *dp,
496 union record *where,
497 b_off_t offset,
498 size_t len);
499/* put several records into db */
500
501/**
502 * Store 'len' records to the database, "offset" granules into this
503 * entry.
504 *
505 * Returns:
506 * 0 OK
507 * non-0 FAILURE
508 */
509RT_EXPORT extern int db_put(struct db_i *,
510 const struct directory *dp,
511 union record *where,
512 b_off_t offset, size_t len);
513
514/**
515 * Obtains a object from the database, leaving it in external
516 * (on-disk) format.
517 *
518 * The bu_external structure represented by 'ep' is initialized here,
519 * the caller need not pre-initialize it. On error, 'ep' is left
520 * un-initialized and need not be freed, to simplify error recovery.
521 * On success, the caller is responsible for calling
522 * bu_free_external(ep);
523 *
524 * Returns -
525 * -1 error
526 * 0 success
527 */
529 const struct directory *dp,
530 const struct db_i *dbip);
531
532/**
533 * Given that caller already has an external representation of the
534 * database object, update it to have a new name (taken from
535 * dp->d_namep) in that external representation, and write the new
536 * object into the database, obtaining different storage if the size
537 * has changed.
538 *
539 * Caller is responsible for freeing memory of external
540 * representation, using bu_free_external().
541 *
542 * This routine is used to efficiently support MGED's "cp" and "keep"
543 * commands, which don't need to import objects just to rename and
544 * copy them.
545 *
546 * Returns -
547 * <0 error
548 * 0 success
549 */
551 struct directory *dp,
552 struct db_i *dbip);
553
554/* db_scan.c */
555/* read db (to build directory) */
556RT_EXPORT extern int db_scan(struct db_i *,
557 int (*handler)(struct db_i *,
558 const char *name,
560 size_t nrec,
561 int flags,
562 void *client_data),
563 int do_old_matter,
564 void *client_data);
565/* update db unit conversions */
566#define db_ident(a, b, c) +++error+++
567
568/**
569 * Update the _GLOBAL object, which in v5 serves the place of the
570 * "ident" header record in v4 as the place to stash global
571 * information. Since every database will have one of these things,
572 * it's no problem to update it.
573 *
574 * Returns -
575 * 0 Success
576 * -1 Fatal Error
577 */
578RT_EXPORT extern int db_update_ident(struct db_i *dbip,
579 const char *title,
580 double local2mm);
581
582/**
583 * Create a header for a v5 database.
584 *
585 * This routine has the same calling sequence as db_fwrite_ident()
586 * which makes a v4 database header.
587 *
588 * In the v5 database, two database objects must be created to match
589 * the semantics of what was in the v4 header:
590 *
591 * First, a database header object.
592 *
593 * Second, create a specially named attribute-only object which
594 * contains the attributes "title=" and "units=" with the values of
595 * title and local2mm respectively.
596 *
597 * Note that the current working units are specified as a conversion
598 * factor to millimeters because database dimensional values are
599 * always stored as millimeters (mm). The units conversion factor
600 * only affects the display and conversion of input values. This
601 * helps prevent error accumulation and improves numerical stability
602 * when calculations are made.
603 *
604 * This routine should only be used by db_create(). Everyone else
605 * should use db5_update_ident().
606 *
607 * Returns -
608 * 0 Success
609 * -1 Fatal Error
610 */
611RT_EXPORT extern int db_fwrite_ident(FILE *fp,
612 const char *title,
613 double local2mm);
614
615/**
616 * Initialize conversion factors given the v4 database unit
617 */
618RT_EXPORT extern void db_conversions(struct db_i *,
619 int units);
620
621/**
622 * Given a string, return the V4 database code representing the user's
623 * preferred editing units. The v4 database format does not have many
624 * choices.
625 *
626 * Returns -
627 * -1 Not a legal V4 database code
628 * # The V4 database code number
629 */
630RT_EXPORT extern int db_v4_get_units_code(const char *str);
631
632/* db5_scan.c */
633
634/**
635 * A generic routine to determine the type of the database, (v4 or v5)
636 * and to invoke the appropriate db_scan()-like routine to build the
637 * in-memory directory.
638 *
639 * It is the caller's responsibility to close the database in case of
640 * error.
641 *
642 * Called from rt_dirbuild() and other places directly where a
643 * raytrace instance is not required.
644 *
645 * Returns -
646 * 0 OK
647 * -1 failure
648 */
649RT_EXPORT extern int db_dirbuild(struct db_i *dbip);
650RT_EXPORT extern int db_dirbuild_inmem(struct db_i *dbip, const void *data, b_off_t data_size);
651RT_EXPORT extern struct directory *db5_diradd(struct db_i *dbip,
652 const struct db5_raw_internal *rip,
654 void *client_data);
655
656/**
657 * Scan a v5 database, sending each object off to a handler.
658 *
659 * Returns -
660 * 0 Success
661 * -1 Fatal Error
662 */
663RT_EXPORT extern int db5_scan(struct db_i *dbip,
664 void (*handler)(struct db_i *,
665 const struct db5_raw_internal *,
667 void *client_data),
668 void *client_data);
669RT_EXPORT extern int db5_scan_inmem(struct db_i *dbip,
670 void (*handler)(struct db_i *,
671 const struct db5_raw_internal *,
673 void *client_data),
674 void *client_data,
675 const void *data,
677
678/**
679 * Obtain the database version for a given database instance.
680 *
681 * Returns 4 or 5 accordingly for v4 or v5 geometry database files.
682 * Returns -1 if dbip is invalid.
683 */
684RT_EXPORT extern int db_version(const struct db_i *dbip);
685RT_EXPORT extern int db_version_inmem(const struct db_i *dbip, const void *data, b_off_t data_size);
686
687
688/* db_corrupt.c */
689
690/**
691 * Detect whether a given geometry database file seems to be corrupt
692 * or invalid due to flipped endianness. Only relevant for v4
693 * geometry files that are binary-incompatible with the runtime
694 * platform.
695 *
696 * Returns true if flipping the endian type fixes all combination
697 * member matrices.
698 */
699RT_EXPORT extern int rt_db_flip_endian(struct db_i *dbip);
700
701
702/**
703 * Transmogrify an existing directory entry to be an in-memory-only
704 * one, stealing the external representation from 'ext'.
705 */
706RT_EXPORT extern void db_inmem(struct directory *dp,
707 struct bu_external *ext,
708 int flags,
709 struct db_i *dbip);
710
711/* db_lookup.c */
712
713/**
714 * Return the number of "struct directory" nodes in the given
715 * database.
716 */
717RT_EXPORT extern size_t db_directory_size(const struct db_i *dbip);
718
719/**
720 * For debugging, ensure that all the linked-lists for the directory
721 * structure are intact.
722 */
723RT_EXPORT extern void db_ck_directory(const struct db_i *dbip);
724
725/**
726 * Returns -
727 * 0 if the in-memory directory is empty
728 * 1 if the in-memory directory has entries,
729 * which implies that a db_scan() has already been performed.
730 */
731RT_EXPORT extern int db_is_directory_non_empty(const struct db_i *dbip);
732
733/**
734 * Returns a hash index for a given string that corresponds with the
735 * head of that string's hash chain.
736 */
737RT_EXPORT extern int db_dirhash(const char *str);
738
739/**
740 * This routine ensures that ret_name is not already in the
741 * directory. If it is, it tries a fixed number of times to modify
742 * ret_name before giving up. Note - most of the time, the hash for
743 * ret_name is computed once.
744 *
745 * Inputs -
746 * dbip database instance pointer
747 * ret_name the original name
748 * noisy to blather or not
749 *
750 * Outputs -
751 * ret_name the name to use
752 * headp pointer to the first (struct directory *) in the bucket
753 *
754 * Returns -
755 * 0 success
756 * <0 fail
757 */
758RT_EXPORT extern int db_dircheck(struct db_i *dbip,
759 struct bu_vls *ret_name,
760 int noisy,
761 struct directory ***headp);
762/* convert name to directory ptr */
763
764/**
765 * This routine takes a path or a name and returns the current directory
766 * pointer (if any) associated with the object.
767 *
768 * If given an object name, it will look up the object name in the directory
769 * table. If the name is present, a pointer to the directory struct element is
770 * returned, otherwise NULL is returned.
771 *
772 * If given a path, it will validate that the path is a valid path in the
773 * current database. If it is, a pointer to the current directory in the path
774 * (i.e. the leaf object on the path) is returned, otherwise NULL is returned.
775 *
776 * If noisy is non-zero, a print occurs, else only the return code indicates
777 * failure.
778 *
779 * Returns -
780 * struct directory if name is found
781 * RT_DIR_NULL on failure
782 */
783RT_EXPORT extern struct directory *db_lookup(const struct db_i *,
784 const char *name,
785 int noisy);
786
787/* add entry to directory */
788
789/**
790 * Add an entry to the directory. Try to make the regular path
791 * through the code as fast as possible, to speed up building the
792 * table of contents.
793 *
794 * dbip is a pointer to a valid/opened database instance
795 *
796 * name is the string name of the object being added
797 *
798 * laddr is the offset into the file to the object
799 *
800 * len is the length of the object, number of db granules used
801 *
802 * flags are defined in raytrace.h (RT_DIR_SOLID, RT_DIR_COMB, RT_DIR_REGION,
803 * RT_DIR_INMEM, etc.) for db version 5, ptr is the minor_type
804 * (non-null pointer to valid unsigned char code)
805 *
806 * an laddr of RT_DIR_PHONY_ADDR means that database storage has not
807 * been allocated yet.
808 */
809RT_EXPORT extern struct directory *db_diradd(struct db_i *,
810 const char *name,
812 size_t len,
813 int flags,
814 void *ptr);
815RT_EXPORT extern struct directory *db_diradd5(struct db_i *dbip,
816 const char *name,
818 unsigned char major_type,
819 unsigned char minor_type,
820 unsigned char name_hidden,
821 size_t object_length,
823
824/* delete entry from directory */
825
826/**
827 * Given a pointer to a directory entry, remove it from the linked
828 * list, and free the associated memory.
829 *
830 * It is the responsibility of the caller to have released whatever
831 * structures have been hung on the d_use_hd bu_list, first.
832 *
833 * Returns -
834 * 0 on success
835 * non-0 on failure
836 */
837RT_EXPORT extern int db_dirdelete(struct db_i *,
838 struct directory *dp);
839RT_EXPORT extern int db_fwrite_ident(FILE *,
840 const char *,
841 double);
842
843/**
844 * For debugging, print the entire contents of the database directory.
845 */
846RT_EXPORT extern void db_pr_dir(const struct db_i *dbip);
847
848/**
849 * Change the name string of a directory entry. Because of the
850 * hashing function, this takes some extra work.
851 *
852 * Returns -
853 * 0 on success
854 * non-0 on failure
855 */
856RT_EXPORT extern int db_rename(struct db_i *,
857 struct directory *,
858 const char *newname);
859
860
861/**
862 * Updates the d_nref fields (which count the number of times a given
863 * entry is referenced by a COMBination in the database).
864 *
865 */
866RT_EXPORT extern void db_update_nref(struct db_i *dbip);
867
868
869/* db_flags.c */
870/**
871 * Given the internal form of a database object, return the
872 * appropriate 'flags' word for stashing in the in-memory directory of
873 * objects.
874 */
876
877
878/* XXX - should use in db5_diradd() */
879/**
880 * Given a database object in "raw" internal form, return the
881 * appropriate 'flags' word for stashing in the in-memory directory of
882 * objects.
883 */
885
886/* db_alloc.c */
887
888/* allocate "count" granules */
889RT_EXPORT extern int db_alloc(struct db_i *,
890 struct directory *dp,
891 size_t count);
892/* delete "recnum" from entry */
893RT_EXPORT extern int db_delrec(struct db_i *,
894 struct directory *dp,
895 int recnum);
896/* delete all granules assigned dp */
897RT_EXPORT extern int db_delete(struct db_i *,
898 struct directory *dp);
899/* write FREE records from 'start' */
900RT_EXPORT extern int db_zapper(struct db_i *,
901 struct directory *dp,
902 size_t start);
903
904
905/**
906 * This routine is called by the RT_GET_DIRECTORY macro when the
907 * freelist is exhausted. Rather than simply getting one additional
908 * structure, we get a whole batch, saving overhead.
909 *
910 * DEPRECATED in favor of db_alloc_dir_block, which operates on the db_i
911 */
913
914
915/**
916 * This routine is called by the RT_GET_DIR macro when the
917 * freelist is exhausted. Rather than simply getting one additional
918 * structure, we get a whole batch, saving overhead.
919 */
920RT_EXPORT extern void db_alloc_dir_block(struct db_i *dbip);
921
922/**
923 * This routine is called by the GET_SEG macro when the freelist is
924 * exhausted. Rather than simply getting one additional structure, we
925 * get a whole batch, saving overhead. When this routine is called,
926 * the seg resource must already be locked. malloc() locking is done
927 * in bu_malloc.
928 */
930
931/**
932 * Read named MGED db, build toc.
933 */
934RT_EXPORT extern struct rt_i *rt_dirbuild(const char *filename, char *buf, int len);
935RT_EXPORT extern struct rt_i *rt_dirbuild_inmem(const void *data, b_off_t data_size, char *buf, int len);
936
937
938/* db5_types.c */
939RT_EXPORT extern int db5_type_tag_from_major(const char **tag,
940 const int major);
941
943 const int major);
944
945RT_EXPORT extern int db5_type_tag_from_codes(const char **tag,
946 const int major,
947 const int minor);
948
950 const int major,
951 const int minor);
952
954 int *minor,
955 const char *tag);
956
958 int *minor,
959 const char *descrip);
960
961RT_EXPORT extern size_t db5_type_sizeof_h_binu(const int minor);
962
963RT_EXPORT extern size_t db5_type_sizeof_n_binu(const int minor);
964
966
967#endif /* RT_DB_IO_H */
968
969/*
970 * Local Variables:
971 * tab-width: 8
972 * mode: C
973 * indent-tabs-mode: t
974 * c-file-style: "stroustrup"
975 * End:
976 * ex: shiftwidth=4 tabstop=8
977 */
Definition dvec.h:74
Header file for the BRL-CAD common definitions.
Definition of the BRL-CAD "v5" database format used for new ".g" files.
void db5_make_free_object_hdr(struct bu_external *ep, size_t length)
int db_put_external(struct bu_external *ep, struct directory *dp, struct db_i *dbip)
int db_get_external(struct bu_external *ep, const struct directory *dp, const struct db_i *dbip)
void db5_make_free_object(struct bu_external *ep, size_t length)
int db_wrap_v5_external(struct bu_external *ep, const char *name)
int db5_write_free(struct db_i *dbip, struct directory *dp, size_t length)
void db_close_client(struct db_i *dbip, long *client)
void db_update_nref(struct db_i *dbip)
struct directory * db5_diradd(struct db_i *dbip, const struct db5_raw_internal *rip, b_off_t laddr, void *client_data)
int db_update_ident(struct db_i *dbip, const char *title, double local2mm)
struct rt_i * rt_dirbuild_inmem(const void *data, b_off_t data_size, char *buf, int len)
int db_scan(struct db_i *, int(*handler)(struct db_i *, const char *name, b_off_t addr, size_t nrec, int flags, void *client_data), int do_old_matter, void *client_data)
int db_rename(struct db_i *, struct directory *, const char *newname)
void db_alloc_dir_block(struct db_i *dbip)
size_t db5_decode_length(size_t *lenp, const unsigned char *cp, int format)
int db_dirbuild(struct db_i *dbip)
int rt_db_cvt_to_ext5(struct bu_external *ext, const char *name, const struct rt_db_internal *ip, double conv2mm, struct db_i *dbip, const int major)
size_t db5_type_sizeof_h_binu(const int minor)
int db_filetype(const char *file_path)
int db_flags_raw_internal(const struct db5_raw_internal *intern)
struct directory * db_lookup(const struct db_i *, const char *name, int noisy)
int db_delete(struct db_i *, struct directory *dp)
int db_dirhash(const char *str)
struct rt_i * rt_dirbuild(const char *filename, char *buf, int len)
int db_write(struct db_i *dbip, const void *addr, size_t count, b_off_t offset)
struct directory * db_diradd5(struct db_i *dbip, const char *name, b_off_t laddr, unsigned char major_type, unsigned char minor_type, unsigned char name_hidden, size_t object_length, struct bu_attribute_value_set *avs)
void rt_alloc_seg_block(struct resource *res)
int db_dirbuild_inmem(struct db_i *dbip, const void *data, b_off_t data_size)
int db_read(const struct db_i *dbip, void *addr, size_t count, b_off_t offset)
int db_version(const struct db_i *dbip)
int db_v4_get_units_code(const char *str)
int db_alloc(struct db_i *, struct directory *dp, size_t count)
int rt_db_get_internal5(struct rt_db_internal *ip, const struct directory *dp, const struct db_i *dbip, const mat_t mat)
union record * db_getmrec(const struct db_i *, const struct directory *dp)
int db_dirdelete(struct db_i *, struct directory *dp)
int db_put(struct db_i *, const struct directory *dp, union record *where, b_off_t offset, size_t len)
int db5_scan_inmem(struct db_i *dbip, void(*handler)(struct db_i *, const struct db5_raw_internal *, b_off_t addr, void *client_data), void *client_data, const void *data, b_off_t data_size)
int db5_realloc(struct db_i *dbip, struct directory *dp, struct bu_external *ep)
int db5_fwrite_ident(FILE *, const char *, double)
const unsigned char * db5_get_raw_internal_ptr(struct db5_raw_internal *rip, const unsigned char *ip)
struct directory * db_diradd(struct db_i *, const char *name, b_off_t laddr, size_t len, int flags, void *ptr)
int db_put_external5(struct bu_external *ep, struct directory *dp, struct db_i *dbip)
int db5_type_tag_from_major(const char **tag, const int major)
int db_fwrite_external(FILE *fp, const char *name, struct bu_external *ep)
int db5_select_length_encoding(size_t len)
int rt_db_put_internal_v5(struct directory *dp, struct db_i *dbip, struct rt_db_internal *ip, const int major)
void db5_import_color_table(struct db_i *dbip, char *cp)
int rt_db_flip_endian(struct db_i *dbip)
void db_sync(struct db_i *dbip)
int db_zapper(struct db_i *, struct directory *dp, size_t start)
DEPRECATED int rt_db_cvt_to_external5(struct bu_external *ext, const char *name, const struct rt_db_internal *ip, double conv2mm, struct db_i *dbip, struct resource *resp, const int major)
int db5_type_descrip_from_codes(const char **descrip, const int major, const int minor)
int db_get(const struct db_i *, const struct directory *dp, union record *where, b_off_t offset, size_t len)
int db_dump(struct rt_wdb *wdbp, struct db_i *dbip)
int db_flags_internal(const struct rt_db_internal *intern)
void db_ck_directory(const struct db_i *dbip)
size_t db5_decode_signed(size_t *lenp, const unsigned char *cp, int format)
int db5_type_codes_from_tag(int *major, int *minor, const char *tag)
int db5_type_codes_from_descrip(int *major, int *minor, const char *descrip)
void db_pr_dir(const struct db_i *dbip)
int db5_get_raw_internal_fp(struct db5_raw_internal *rip, FILE *fp)
int db_delrec(struct db_i *, struct directory *dp, int recnum)
void db_conversions(struct db_i *, int units)
void db_inmem(struct directory *dp, struct bu_external *ext, int flags, struct db_i *dbip)
int db5_type_tag_from_codes(const char **tag, const int major, const int minor)
int db_is_directory_non_empty(const struct db_i *dbip)
struct db_i * db_clone_dbi(struct db_i *dbip, long *client)
DEPRECATED int rt_db_put_internal5(struct directory *dp, struct db_i *dbip, struct rt_db_internal *ip, struct resource *resp, const int major)
int db5_header_is_valid(const unsigned char *hp)
int rt_db_external5_to_internal5(struct rt_db_internal *ip, const struct bu_external *ep, const char *name, const struct db_i *dbip, const mat_t mat)
unsigned char * db5_encode_length(unsigned char *cp, size_t val, int format)
DEPRECATED void db_alloc_directory_block(struct resource *res)
int db_dircheck(struct db_i *dbip, struct bu_vls *ret_name, int noisy, struct directory ***headp)
void db5_export_object3(struct bu_external *out, int dli, const char *name, const unsigned char hidden, const struct bu_external *attrib, const struct bu_external *body, int major, int minor, int a_zzz, int b_zzz)
int db_version_inmem(const struct db_i *dbip, const void *data, b_off_t data_size)
int db5_type_descrip_from_major(const char **descrip, const int major)
int db5_scan(struct db_i *dbip, void(*handler)(struct db_i *, const struct db5_raw_internal *, b_off_t addr, void *client_data), void *client_data)
size_t db5_type_sizeof_n_binu(const int minor)
size_t db_directory_size(const struct db_i *dbip)
int db_fwrite_ident(FILE *fp, const char *title, double local2mm)
void db_wrap_v4_external(struct bu_external *op, const char *name)
#define DEPRECATED
Definition common.h:433
#define b_off_t
Definition common.h:255
fastf_t mat_t[ELEMENTS_PER_MAT]
4x4 matrix
Definition vmath.h:369
Definition vls.h:53
void * ptr
ptr to in-memory-only obj
Definition directory.h:67
Definition wdb.h:60
struct db_i * dbip
.g database type (RT_WDB_TYPE - disk or inmem, append-only)
Definition wdb.h:63
Definition db4.h:416
fundamental vector, matrix, quaternion math macros