PostgreSQL Source Code: src/backend/libpq/be-fsstubs.c Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

40

41#include <fcntl.h>

42#include <sys/stat.h>

44

57

58

59

60

61#define BUFSIZE 8192

62

63

64

65

66

67

68

69

70

73

76

80

81

82

83

84

85

88{

92 int fd;

93

94#ifdef FSDB

96#endif

97

100

101

102

103

104

106

109

110

111

112

113

114

118

121

123}

124

127{

129

132 (errcode(ERRCODE_UNDEFINED_OBJECT),

133 errmsg("invalid large-object descriptor: %d", fd)));

134

135#ifdef FSDB

137#endif

138

140

142}

143

144

145

146

147

148

149

150

151

152

153int

155{

156 int status;

158

161 (errcode(ERRCODE_UNDEFINED_OBJECT),

162 errmsg("invalid large-object descriptor: %d", fd)));

164

165

166

167

168

169

172 (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),

173 errmsg("large object descriptor %d was not opened for reading",

174 fd)));

175

177

178 return status;

179}

180

181int

183{

184 int status;

186

189 (errcode(ERRCODE_UNDEFINED_OBJECT),

190 errmsg("invalid large-object descriptor: %d", fd)));

192

193

196 (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),

197 errmsg("large object descriptor %d was not opened for writing",

198 fd)));

199

201

202 return status;

203}

204

207{

212

215 (errcode(ERRCODE_UNDEFINED_OBJECT),

216 errmsg("invalid large-object descriptor: %d", fd)));

217

219

220

221 if (status != (int32) status)

223 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),

224 errmsg("lo_lseek result out of range for large-object descriptor %d",

225 fd)));

226

228}

229

232{

237

240 (errcode(ERRCODE_UNDEFINED_OBJECT),

241 errmsg("invalid large-object descriptor: %d", fd)));

242

244

246}

247

250{

251 Oid lobjId;

252

254

257

259}

260

263{

265

267

270

272}

273

276{

279

282 (errcode(ERRCODE_UNDEFINED_OBJECT),

283 errmsg("invalid large-object descriptor: %d", fd)));

284

286

287

288 if (offset != (int32) offset)

290 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),

291 errmsg("lo_tell result out of range for large-object descriptor %d",

292 fd)));

293

295}

296

299{

302

305 (errcode(ERRCODE_UNDEFINED_OBJECT),

306 errmsg("invalid large-object descriptor: %d", fd)));

307

309

311}

312

315{

317

319

322 (errcode(ERRCODE_UNDEFINED_OBJECT),

323 errmsg("large object %u does not exist", lobjId)));

324

325

326

327

328

329

333 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),

334 errmsg("must be owner of large object %u", lobjId)));

335

336

337

338

339 if (fscxt != NULL)

340 {

341 int i;

342

344 {

347 }

348 }

349

350

351

352

353

355}

356

357

358

359

360

363{

367 int totalread;

368

369 if (len < 0)

371

375

377}

378

381{

384 int bytestowrite;

385 int totalwritten;

386

388

392}

393

394

395

396

397

398

399

400

401

404{

406

408}

409

410

411

412

413

416{

419

421}

422

423static Oid

425{

426 int fd;

427 int nbytes,

433

435

436

437

438

441 if (fd < 0)

444 errmsg("could not open server file \"%s\": %m",

445 fnamebuf)));

446

447

448

449

452

453

454

455

457

459 {

461 Assert(tmp == nbytes);

462 }

463

464 if (nbytes < 0)

467 errmsg("could not read server file \"%s\": %m",

468 fnamebuf)));

469

471

475 errmsg("could not close file \"%s\": %m",

476 fnamebuf)));

477

478 return oid;

479}

480

481

482

483

484

487{

490 int fd;

491 int nbytes,

492 tmp;

496 mode_t oumask;

497

498

499

500

503

504

505

506

507

508

509

510

514 {

517 }

519 {

520 umask(oumask);

521 }

523 if (fd < 0)

526 errmsg("could not create server file \"%s\": %m",

527 fnamebuf)));

528

529

530

531

533 {

535 if (tmp != nbytes)

538 errmsg("could not write server file \"%s\": %m",

539 fnamebuf)));

540 }

541

545 errmsg("could not close file \"%s\": %m",

546 fnamebuf)));

547

549

551}

552

553

554

555

556

557static void

559{

561

564 (errcode(ERRCODE_UNDEFINED_OBJECT),

565 errmsg("invalid large-object descriptor: %d", fd)));

567

568

571 (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),

572 errmsg("large object descriptor %d was not opened for writing",

573 fd)));

574

576}

577

580{

583

585

588}

589

592{

595

597

600}

601

602

603

604

605

606void

608{

609 int i;

610

612 return;

613

614

615

616

617

618

619

620

621 if (isCommit)

622 {

624 {

627 }

628 }

629

630

633

634

638

639

641

643}

644

645

646

647

648

649

650

651

652void

655{

656 int i;

657

658 if (fscxt == NULL)

659 return;

660

662 {

664

665 if (lo != NULL && lo->subid == mySubid)

666 {

667 if (isCommit)

668 lo->subid = parentSubid;

669 else

671 }

672 }

673}

674

675

676

677

678

679static int

681{

682 int i,

683 newsize;

684

686 if (fscxt == NULL)

688 "Filesystem",

690

691

693 {

695 return i;

696 }

697

698

700 {

701

702 i = 0;

703 newsize = 64;

706 }

707 else

708 {

709

714 }

716

717 return i;

718}

719

720static void

722{

724

725

726

727

728

731

736}

737

738

739

740

741

742

743

744

747{

750 int64 result_length;

752 bytea *result = NULL;

753

756

757

758

759

760

761 loSize = inv_seek(loDesc, 0, SEEK_END);

762 if (loSize > offset)

763 {

764 if (nbytes >= 0 && nbytes <= loSize - offset)

765 result_length = nbytes;

766 else

767 result_length = loSize - offset;

768 }

769 else

770 result_length = 0;

771

772

773

774

775

778 (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),

779 errmsg("large object read request is too large")));

780

782

783 inv_seek(loDesc, offset, SEEK_SET);

784 total_read = inv_read(loDesc, VARDATA(result), result_length);

785 Assert(total_read == result_length);

787

789

790 return result;

791}

792

793

794

795

798{

801

803

805}

806

807

808

809

812{

817

818 if (nbytes < 0)

820 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),

821 errmsg("requested length cannot be negative")));

822

824

826}

827

828

829

830

833{

838

840

847

849}

850

851

852

853

856{

862

864

867 inv_seek(loDesc, offset, SEEK_SET);

871

873}

bool object_ownercheck(Oid classid, Oid objectid, Oid roleid)

static bytea * lo_get_fragment_internal(Oid loOid, int64 offset, int32 nbytes)

Datum be_lo_lseek(PG_FUNCTION_ARGS)

Datum be_loread(PG_FUNCTION_ARGS)

static MemoryContext fscxt

Datum be_lo_get(PG_FUNCTION_ARGS)

static void closeLOfd(int fd)

Datum be_lo_export(PG_FUNCTION_ARGS)

void AtEOXact_LargeObject(bool isCommit)

Datum be_lo_unlink(PG_FUNCTION_ARGS)

Datum be_lo_import_with_oid(PG_FUNCTION_ARGS)

Datum be_lo_truncate64(PG_FUNCTION_ARGS)

Datum be_lo_lseek64(PG_FUNCTION_ARGS)

Datum be_lo_tell64(PG_FUNCTION_ARGS)

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

Datum be_lo_from_bytea(PG_FUNCTION_ARGS)

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

static Oid lo_import_internal(text *filename, Oid lobjOid)

Datum be_lowrite(PG_FUNCTION_ARGS)

Datum be_lo_creat(PG_FUNCTION_ARGS)

Datum be_lo_put(PG_FUNCTION_ARGS)

Datum be_lo_truncate(PG_FUNCTION_ARGS)

Datum be_lo_create(PG_FUNCTION_ARGS)

static bool lo_cleanup_needed

Datum be_lo_tell(PG_FUNCTION_ARGS)

Datum be_lo_import(PG_FUNCTION_ARGS)

Datum be_lo_get_fragment(PG_FUNCTION_ARGS)

static LargeObjectDesc ** cookies

Datum be_lo_close(PG_FUNCTION_ARGS)

static void lo_truncate_internal(int32 fd, int64 len)

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

Datum be_lo_open(PG_FUNCTION_ARGS)

#define PG_USED_FOR_ASSERTS_ONLY

int errcode_for_file_access(void)

int errcode(int sqlerrcode)

int errmsg(const char *fmt,...)

#define ereport(elevel,...)

int CloseTransientFile(int fd)

int OpenTransientFile(const char *fileName, int fileFlags)

int OpenTransientFilePerm(const char *fileName, int fileFlags, mode_t fileMode)

#define PG_GETARG_BYTEA_PP(n)

#define PG_GETARG_TEXT_PP(n)

#define PG_RETURN_BYTEA_P(x)

#define PG_RETURN_INT64(x)

#define PG_GETARG_INT64(n)

#define PG_RETURN_INT32(x)

#define PG_GETARG_INT32(n)

Assert(PointerIsAligned(start, uint64))

LargeObjectDesc * inv_open(Oid lobjId, int flags, MemoryContext mcxt)

void inv_truncate(LargeObjectDesc *obj_desc, int64 len)

int inv_read(LargeObjectDesc *obj_desc, char *buf, int nbytes)

Oid inv_create(Oid lobjId)

int64 inv_seek(LargeObjectDesc *obj_desc, int64 offset, int whence)

void close_lo_relation(bool isCommit)

int inv_write(LargeObjectDesc *obj_desc, const char *buf, int nbytes)

int64 inv_tell(LargeObjectDesc *obj_desc)

bool lo_compat_privileges

void inv_close(LargeObjectDesc *obj_desc)

void * MemoryContextAllocZero(MemoryContext context, Size size)

MemoryContext TopMemoryContext

MemoryContext CurrentMemoryContext

void MemoryContextDelete(MemoryContext context)

#define AllocSetContextCreate

#define ALLOCSET_DEFAULT_SIZES

#define repalloc0_array(pointer, type, oldcount, count)

static PgChecksumMode mode

bool LargeObjectExists(Oid loid)

static int fd(const char *x, int i)

ResourceOwner TopTransactionResourceOwner

void UnregisterSnapshotFromOwner(Snapshot snapshot, ResourceOwner owner)

Snapshot RegisterSnapshotOnOwner(Snapshot snapshot, ResourceOwner owner)

void PreventCommandIfReadOnly(const char *cmdname)

#define SET_VARSIZE(PTR, len)

#define VARSIZE_ANY_EXHDR(PTR)

void text_to_cstring_buffer(const text *src, char *dst, size_t dst_len)

SubTransactionId GetCurrentSubTransactionId(void)