00001 /*------------------------------------------------------------------------- 00002 * 00003 * large_object.h 00004 * Declarations for PostgreSQL large objects. POSTGRES 4.2 supported 00005 * zillions of large objects (internal, external, jaquith, inversion). 00006 * Now we only support inversion. 00007 * 00008 * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group 00009 * Portions Copyright (c) 1994, Regents of the University of California 00010 * 00011 * src/include/storage/large_object.h 00012 * 00013 *------------------------------------------------------------------------- 00014 */ 00015 #ifndef LARGE_OBJECT_H 00016 #define LARGE_OBJECT_H 00017 00018 #include "utils/snapshot.h" 00019 00020 00021 /*---------- 00022 * Data about a currently-open large object. 00023 * 00024 * id is the logical OID of the large object 00025 * snapshot is the snapshot to use for read/write operations 00026 * subid is the subtransaction that opened the desc (or currently owns it) 00027 * offset is the current seek offset within the LO 00028 * flags contains some flag bits 00029 * 00030 * NOTE: in current usage, flag bit IFS_RDLOCK is *always* set, and we don't 00031 * bother to test for it. Permission checks are made at first read or write 00032 * attempt, not during inv_open(), so we have other bits to remember that. 00033 * 00034 * NOTE: before 7.1, we also had to store references to the separate table 00035 * and index of a specific large object. Now they all live in pg_largeobject 00036 * and are accessed via a common relation descriptor. 00037 *---------- 00038 */ 00039 typedef struct LargeObjectDesc 00040 { 00041 Oid id; /* LO's identifier */ 00042 Snapshot snapshot; /* snapshot to use */ 00043 SubTransactionId subid; /* owning subtransaction ID */ 00044 uint64 offset; /* current seek pointer */ 00045 int flags; /* see flag bits below */ 00046 00047 /* bits in flags: */ 00048 #define IFS_RDLOCK (1 << 0) /* LO was opened for reading */ 00049 #define IFS_WRLOCK (1 << 1) /* LO was opened for writing */ 00050 #define IFS_RD_PERM_OK (1 << 2) /* read permission has been verified */ 00051 #define IFS_WR_PERM_OK (1 << 3) /* write permission has been verified */ 00052 00053 } LargeObjectDesc; 00054 00055 00056 /* 00057 * Each "page" (tuple) of a large object can hold this much data 00058 * 00059 * We could set this as high as BLCKSZ less some overhead, but it seems 00060 * better to make it a smaller value, so that not as much space is used 00061 * up when a page-tuple is updated. Note that the value is deliberately 00062 * chosen large enough to trigger the tuple toaster, so that we will 00063 * attempt to compress page tuples in-line. (But they won't be moved off 00064 * unless the user creates a toast-table for pg_largeobject...) 00065 * 00066 * Also, it seems to be a smart move to make the page size be a power of 2, 00067 * since clients will often be written to send data in power-of-2 blocks. 00068 * This avoids unnecessary tuple updates caused by partial-page writes. 00069 */ 00070 #define LOBLKSIZE (BLCKSZ / 4) 00071 00072 /* 00073 * Maximum length in bytes for a large object. To make this larger, we'd 00074 * have to widen pg_largeobject.pageno as well as various internal variables. 00075 */ 00076 #define MAX_LARGE_OBJECT_SIZE ((int64) INT_MAX * LOBLKSIZE) 00077 00078 00079 /* 00080 * Function definitions... 00081 */ 00082 00083 /* inversion stuff in inv_api.c */ 00084 extern void close_lo_relation(bool isCommit); 00085 extern Oid inv_create(Oid lobjId); 00086 extern LargeObjectDesc *inv_open(Oid lobjId, int flags, MemoryContext mcxt); 00087 extern void inv_close(LargeObjectDesc *obj_desc); 00088 extern int inv_drop(Oid lobjId); 00089 extern int64 inv_seek(LargeObjectDesc *obj_desc, int64 offset, int whence); 00090 extern int64 inv_tell(LargeObjectDesc *obj_desc); 00091 extern int inv_read(LargeObjectDesc *obj_desc, char *buf, int nbytes); 00092 extern int inv_write(LargeObjectDesc *obj_desc, const char *buf, int nbytes); 00093 extern void inv_truncate(LargeObjectDesc *obj_desc, int64 len); 00094 00095 #endif /* LARGE_OBJECT_H */