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