PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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)
 

Variables

bool lo_compat_privileges
 

Function Documentation

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

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

References cookies_size, deleteLOfd(), i, inv_close(), NULL, and LargeObjectDesc::subid.

Referenced by AbortSubTransaction(), and CommitSubTransaction().

676 {
677  int i;
678 
679  if (fscxt == NULL) /* no LO operations in this xact */
680  return;
681 
682  for (i = 0; i < cookies_size; i++)
683  {
684  LargeObjectDesc *lo = cookies[i];
685 
686  if (lo != NULL && lo->subid == mySubid)
687  {
688  if (isCommit)
689  lo->subid = parentSubid;
690  else
691  {
692  /*
693  * Make sure we do not call inv_close twice if it errors out
694  * for some reason. Better a leak than a crash.
695  */
696  deleteLOfd(i);
697  inv_close(lo);
698  }
699  }
700  }
701 }
static void deleteLOfd(int fd)
Definition: be-fsstubs.c:751
void inv_close(LargeObjectDesc *obj_desc)
Definition: inv_api.c:320
SubTransactionId subid
Definition: large_object.h:43
#define NULL
Definition: c.h:229
static int cookies_size
Definition: be-fsstubs.c:73
static MemoryContext fscxt
Definition: be-fsstubs.c:75
int i
static LargeObjectDesc ** cookies
Definition: be-fsstubs.c:72
void AtEOXact_LargeObject ( bool  isCommit)

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

References close_lo_relation(), cookies_size, deleteLOfd(), i, inv_close(), MemoryContextDelete(), and NULL.

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

634 {
635  int i;
636 
637  if (fscxt == NULL)
638  return; /* no LO operations in this xact */
639 
640  /*
641  * Close LO fds and clear cookies array so that LO fds are no longer good.
642  * On abort we skip the close step.
643  */
644  for (i = 0; i < cookies_size; i++)
645  {
646  if (cookies[i] != NULL)
647  {
648  if (isCommit)
649  inv_close(cookies[i]);
650  deleteLOfd(i);
651  }
652  }
653 
654  /* Needn't actually pfree since we're about to zap context */
655  cookies = NULL;
656  cookies_size = 0;
657 
658  /* Release the LO memory context to prevent permanent memory leaks. */
660  fscxt = NULL;
661 
662  /* Give inv_api.c a chance to clean up, too */
663  close_lo_relation(isCommit);
664 }
static void deleteLOfd(int fd)
Definition: be-fsstubs.c:751
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:200
void inv_close(LargeObjectDesc *obj_desc)
Definition: inv_api.c:320
void close_lo_relation(bool isCommit)
Definition: inv_api.c:102
#define NULL
Definition: c.h:229
static int cookies_size
Definition: be-fsstubs.c:73
static MemoryContext fscxt
Definition: be-fsstubs.c:75
int i
static LargeObjectDesc ** cookies
Definition: be-fsstubs.c:72
int lo_read ( int  fd,
char *  buf,
int  len 
)

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

References ACL_SELECT, ACLCHECK_OK, cookies_size, ereport, errcode(), errmsg(), ERROR, fd(), LargeObjectDesc::flags, GetUserId(), LargeObjectDesc::id, IFS_RD_PERM_OK, inv_read(), lo_compat_privileges, NULL, pg_largeobject_aclcheck_snapshot(), LargeObjectDesc::snapshot, and status().

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

156 {
157  int status;
158  LargeObjectDesc *lobj;
159 
160  if (fd < 0 || fd >= cookies_size || cookies[fd] == NULL)
161  ereport(ERROR,
162  (errcode(ERRCODE_UNDEFINED_OBJECT),
163  errmsg("invalid large-object descriptor: %d", fd)));
164  lobj = cookies[fd];
165 
166  /* We don't bother to check IFS_RDLOCK, since it's always set */
167 
168  /* Permission checks --- first time through only */
169  if ((lobj->flags & IFS_RD_PERM_OK) == 0)
170  {
171  if (!lo_compat_privileges &&
173  GetUserId(),
174  ACL_SELECT,
175  lobj->snapshot) != ACLCHECK_OK)
176  ereport(ERROR,
177  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
178  errmsg("permission denied for large object %u",
179  lobj->id)));
180  lobj->flags |= IFS_RD_PERM_OK;
181  }
182 
183  status = inv_read(lobj, buf, len);
184 
185  return status;
186 }
#define IFS_RD_PERM_OK
Definition: large_object.h:50
Oid GetUserId(void)
Definition: miscinit.c:284
int errcode(int sqlerrcode)
Definition: elog.c:575
static int fd(const char *x, int i)
Definition: preproc-init.c:105
bool lo_compat_privileges
Definition: be-fsstubs.c:57
#define ERROR
Definition: elog.h:43
Snapshot snapshot
Definition: large_object.h:42
static char * buf
Definition: pg_test_fsync.c:66
#define ereport(elevel, rest)
Definition: elog.h:122
#define ACL_SELECT
Definition: parsenodes.h:73
#define NULL
Definition: c.h:229
static int cookies_size
Definition: be-fsstubs.c:73
int errmsg(const char *fmt,...)
Definition: elog.c:797
AclResult pg_largeobject_aclcheck_snapshot(Oid lobj_oid, Oid roleid, AclMode mode, Snapshot snapshot)
Definition: aclchk.c:4470
static LargeObjectDesc ** cookies
Definition: be-fsstubs.c:72
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:224
int inv_read(LargeObjectDesc *obj_desc, char *buf, int nbytes)
Definition: inv_api.c:464
int lo_write ( int  fd,
const char *  buf,
int  len 
)

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

References ACL_UPDATE, ACLCHECK_OK, cookies_size, ereport, errcode(), errmsg(), ERROR, fd(), LargeObjectDesc::flags, GetUserId(), LargeObjectDesc::id, IFS_WR_PERM_OK, IFS_WRLOCK, inv_write(), lo_compat_privileges, NULL, pg_largeobject_aclcheck_snapshot(), LargeObjectDesc::snapshot, and status().

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

190 {
191  int status;
192  LargeObjectDesc *lobj;
193 
194  if (fd < 0 || fd >= cookies_size || cookies[fd] == NULL)
195  ereport(ERROR,
196  (errcode(ERRCODE_UNDEFINED_OBJECT),
197  errmsg("invalid large-object descriptor: %d", fd)));
198  lobj = cookies[fd];
199 
200  if ((lobj->flags & IFS_WRLOCK) == 0)
201  ereport(ERROR,
202  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
203  errmsg("large object descriptor %d was not opened for writing",
204  fd)));
205 
206  /* Permission checks --- first time through only */
207  if ((lobj->flags & IFS_WR_PERM_OK) == 0)
208  {
209  if (!lo_compat_privileges &&
211  GetUserId(),
212  ACL_UPDATE,
213  lobj->snapshot) != ACLCHECK_OK)
214  ereport(ERROR,
215  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
216  errmsg("permission denied for large object %u",
217  lobj->id)));
218  lobj->flags |= IFS_WR_PERM_OK;
219  }
220 
221  status = inv_write(lobj, buf, len);
222 
223  return status;
224 }
Oid GetUserId(void)
Definition: miscinit.c:284
int errcode(int sqlerrcode)
Definition: elog.c:575
static int fd(const char *x, int i)
Definition: preproc-init.c:105
#define IFS_WRLOCK
Definition: large_object.h:49
bool lo_compat_privileges
Definition: be-fsstubs.c:57
#define ERROR
Definition: elog.h:43
Snapshot snapshot
Definition: large_object.h:42
static char * buf
Definition: pg_test_fsync.c:66
#define ereport(elevel, rest)
Definition: elog.h:122
#define ACL_UPDATE
Definition: parsenodes.h:74
#define NULL
Definition: c.h:229
static int cookies_size
Definition: be-fsstubs.c:73
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define IFS_WR_PERM_OK
Definition: large_object.h:51
AclResult pg_largeobject_aclcheck_snapshot(Oid lobj_oid, Oid roleid, AclMode mode, Snapshot snapshot)
Definition: aclchk.c:4470
static LargeObjectDesc ** cookies
Definition: be-fsstubs.c:72
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:224
int inv_write(LargeObjectDesc *obj_desc, const char *buf, int nbytes)
Definition: inv_api.c:551

Variable Documentation

bool lo_compat_privileges