PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
be-fsstubs.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int lo_read (int fd, char *buf, int len)
 
int lo_write (int fd, const char *buf, int len)
 
void AtEOXact_LargeObject (bool isCommit)
 
void AtEOSubXact_LargeObject (bool isCommit, SubTransactionId mySubid, SubTransactionId parentSubid)
 

Function Documentation

◆ AtEOSubXact_LargeObject()

void AtEOSubXact_LargeObject ( bool  isCommit,
SubTransactionId  mySubid,
SubTransactionId  parentSubid 
)

Definition at line 648 of file be-fsstubs.c.

650{
651 int i;
652
653 if (fscxt == NULL) /* no LO operations in this xact */
654 return;
655
656 for (i = 0; i < cookies_size; i++)
657 {
659
660 if (lo != NULL && lo->subid == mySubid)
661 {
662 if (isCommit)
663 lo->subid = parentSubid;
664 else
665 closeLOfd(i);
666 }
667 }
668}
static MemoryContext fscxt
Definition: be-fsstubs.c:75
static void closeLOfd(int fd)
Definition: be-fsstubs.c:716
static LargeObjectDesc ** cookies
Definition: be-fsstubs.c:71
static int cookies_size
Definition: be-fsstubs.c:72
int i
Definition: isn.c:72
SubTransactionId subid
Definition: large_object.h:43

References closeLOfd(), cookies, cookies_size, fscxt, i, and LargeObjectDesc::subid.

Referenced by AbortSubTransaction(), and CommitSubTransaction().

◆ AtEOXact_LargeObject()

void AtEOXact_LargeObject ( bool  isCommit)

Definition at line 602 of file be-fsstubs.c.

603{
604 int i;
605
607 return; /* no LO operations in this xact */
608
609 /*
610 * Close LO fds and clear cookies array so that LO fds are no longer good.
611 * The memory context and resource owner holding them are going away at
612 * the end-of-transaction anyway, but on commit, we need to close them to
613 * avoid warnings about leaked resources at commit. On abort we can skip
614 * this step.
615 */
616 if (isCommit)
617 {
618 for (i = 0; i < cookies_size; i++)
619 {
620 if (cookies[i] != NULL)
621 closeLOfd(i);
622 }
623 }
624
625 /* Needn't actually pfree since we're about to zap context */
626 cookies = NULL;
627 cookies_size = 0;
628
629 /* Release the LO memory context to prevent permanent memory leaks. */
630 if (fscxt)
632 fscxt = NULL;
633
634 /* Give inv_api.c a chance to clean up, too */
635 close_lo_relation(isCommit);
636
637 lo_cleanup_needed = false;
638}
static bool lo_cleanup_needed
Definition: be-fsstubs.c:74
void close_lo_relation(bool isCommit)
Definition: inv_api.c:97
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:454

References close_lo_relation(), closeLOfd(), cookies, cookies_size, fscxt, i, lo_cleanup_needed, and MemoryContextDelete().

Referenced by AbortTransaction(), CommitTransaction(), and PrepareTransaction().

◆ lo_read()

int lo_read ( int  fd,
char *  buf,
int  len 
)

Definition at line 154 of file be-fsstubs.c.

155{
156 int status;
157 LargeObjectDesc *lobj;
158
159 if (fd < 0 || fd >= cookies_size || cookies[fd] == NULL)
161 (errcode(ERRCODE_UNDEFINED_OBJECT),
162 errmsg("invalid large-object descriptor: %d", fd)));
163 lobj = cookies[fd];
164
165 /*
166 * Check state. inv_read() would throw an error anyway, but we want the
167 * error to be about the FD's state not the underlying privilege; it might
168 * be that the privilege exists but user forgot to ask for read mode.
169 */
170 if ((lobj->flags & IFS_RDLOCK) == 0)
172 (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
173 errmsg("large object descriptor %d was not opened for reading",
174 fd)));
175
176 status = inv_read(lobj, buf, len);
177
178 return status;
179}
int errcode(int sqlerrcode)
Definition: elog.c:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
int inv_read(LargeObjectDesc *obj_desc, char *buf, int nbytes)
Definition: inv_api.c:450
#define IFS_RDLOCK
Definition: large_object.h:48
const void size_t len
static char * buf
Definition: pg_test_fsync.c:72
static int fd(const char *x, int i)
Definition: preproc-init.c:105

References buf, cookies, cookies_size, ereport, errcode(), errmsg(), ERROR, fd(), LargeObjectDesc::flags, IFS_RDLOCK, inv_read(), and len.

Referenced by be_loread(), dumpLOs(), exportFile(), and pickout().

◆ lo_write()

int lo_write ( int  fd,
const char *  buf,
int  len 
)

Definition at line 182 of file be-fsstubs.c.

183{
184 int status;
185 LargeObjectDesc *lobj;
186
187 if (fd < 0 || fd >= cookies_size || cookies[fd] == NULL)
189 (errcode(ERRCODE_UNDEFINED_OBJECT),
190 errmsg("invalid large-object descriptor: %d", fd)));
191 lobj = cookies[fd];
192
193 /* see comment in lo_read() */
194 if ((lobj->flags & IFS_WRLOCK) == 0)
196 (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
197 errmsg("large object descriptor %d was not opened for writing",
198 fd)));
199
200 status = inv_write(lobj, buf, len);
201
202 return status;
203}
int inv_write(LargeObjectDesc *obj_desc, const char *buf, int nbytes)
Definition: inv_api.c:543
#define IFS_WRLOCK
Definition: large_object.h:49

References buf, cookies, cookies_size, ereport, errcode(), errmsg(), ERROR, fd(), LargeObjectDesc::flags, IFS_WRLOCK, inv_write(), and len.

Referenced by be_lowrite(), dump_lo_buf(), importFile(), and overwrite().