2
0

large_object.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*-------------------------------------------------------------------------
  2. *
  3. * large_object.h
  4. * Declarations for PostgreSQL large objects. POSTGRES 4.2 supported
  5. * zillions of large objects (internal, external, jaquith, inversion).
  6. * Now we only support inversion.
  7. *
  8. * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
  9. * Portions Copyright (c) 1994, Regents of the University of California
  10. *
  11. * src/include/storage/large_object.h
  12. *
  13. *-------------------------------------------------------------------------
  14. */
  15. #ifndef LARGE_OBJECT_H
  16. #define LARGE_OBJECT_H
  17. #include "utils/snapshot.h"
  18. /*----------
  19. * Data about a currently-open large object.
  20. *
  21. * id is the logical OID of the large object
  22. * snapshot is the snapshot to use for read/write operations
  23. * subid is the subtransaction that opened the desc (or currently owns it)
  24. * offset is the current seek offset within the LO
  25. * flags contains some flag bits
  26. *
  27. * NOTE: as of v11, permission checks are made when the large object is
  28. * opened; therefore IFS_RDLOCK/IFS_WRLOCK indicate that read or write mode
  29. * has been requested *and* the corresponding permission has been checked.
  30. *
  31. * NOTE: before 7.1, we also had to store references to the separate table
  32. * and index of a specific large object. Now they all live in pg_largeobject
  33. * and are accessed via a common relation descriptor.
  34. *----------
  35. */
  36. typedef struct LargeObjectDesc
  37. {
  38. Oid id; /* LO's identifier */
  39. Snapshot snapshot; /* snapshot to use */
  40. SubTransactionId subid; /* owning subtransaction ID */
  41. uint64 offset; /* current seek pointer */
  42. int flags; /* see flag bits below */
  43. /* bits in flags: */
  44. #define IFS_RDLOCK (1 << 0) /* LO was opened for reading */
  45. #define IFS_WRLOCK (1 << 1) /* LO was opened for writing */
  46. } LargeObjectDesc;
  47. /*
  48. * Each "page" (tuple) of a large object can hold this much data
  49. *
  50. * We could set this as high as BLCKSZ less some overhead, but it seems
  51. * better to make it a smaller value, so that not as much space is used
  52. * up when a page-tuple is updated. Note that the value is deliberately
  53. * chosen large enough to trigger the tuple toaster, so that we will
  54. * attempt to compress page tuples in-line. (But they won't be moved off
  55. * unless the user creates a toast-table for pg_largeobject...)
  56. *
  57. * Also, it seems to be a smart move to make the page size be a power of 2,
  58. * since clients will often be written to send data in power-of-2 blocks.
  59. * This avoids unnecessary tuple updates caused by partial-page writes.
  60. *
  61. * NB: Changing LOBLKSIZE requires an initdb.
  62. */
  63. #define LOBLKSIZE (BLCKSZ / 4)
  64. /*
  65. * Maximum length in bytes for a large object. To make this larger, we'd
  66. * have to widen pg_largeobject.pageno as well as various internal variables.
  67. */
  68. #define MAX_LARGE_OBJECT_SIZE ((int64) INT_MAX * LOBLKSIZE)
  69. /*
  70. * GUC: backwards-compatibility flag to suppress LO permission checks
  71. */
  72. extern PGDLLIMPORT bool lo_compat_privileges;
  73. /*
  74. * Function definitions...
  75. */
  76. /* inversion stuff in inv_api.c */
  77. extern void close_lo_relation(bool isCommit);
  78. extern Oid inv_create(Oid lobjId);
  79. extern LargeObjectDesc *inv_open(Oid lobjId, int flags, MemoryContext mcxt);
  80. extern void inv_close(LargeObjectDesc *obj_desc);
  81. extern int inv_drop(Oid lobjId);
  82. extern int64 inv_seek(LargeObjectDesc *obj_desc, int64 offset, int whence);
  83. extern int64 inv_tell(LargeObjectDesc *obj_desc);
  84. extern int inv_read(LargeObjectDesc *obj_desc, char *buf, int nbytes);
  85. extern int inv_write(LargeObjectDesc *obj_desc, const char *buf, int nbytes);
  86. extern void inv_truncate(LargeObjectDesc *obj_desc, int64 len);
  87. #endif /* LARGE_OBJECT_H */