2 * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 * Copyright (c) 1991-1999 University of Maryland at College Park
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of U.M. not be used in advertising or
11 * publicity pertaining to distribution of the software without specific,
12 * written prior permission. U.M. makes no representations about the
13 * suitability of this software for any purpose. It is provided "as is"
14 * without express or implied warranty.
16 * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
18 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 * Authors: the Amanda Development Team. Its members are listed in a
24 * file named AUTHORS, in the root directory of this distribution.
26 /* $Id: chunker.c,v 1.36 2006/08/24 11:23:32 martinea Exp $
28 * requests remote amandad processes to dump filesystems
40 #include "fileheader.h"
41 #include "amfeatures.h"
42 #include "server_util.h"
45 #include "timestamp.h"
55 #define CONNECT_TIMEOUT 5*60
57 #define STARTUP_TIMEOUT 60
60 int fd; /* file to flush to */
61 char *filename; /* name of what fd points to */
62 int filename_seq; /* for chunking */
63 off_t split_size; /* when to chunk */
64 off_t chunk_size; /* size of each chunk */
65 off_t use; /* size to use on this disk */
66 char buf[DISK_BLOCK_BYTES];
67 char *datain; /* data buffer markers */
72 static char *handle = NULL;
74 static char *errstr = NULL;
75 static int abort_pending;
76 static off_t dumpsize;
77 static unsigned long headersize;
78 static off_t dumpbytes;
79 static off_t filesize;
81 static char *hostname = NULL;
82 static char *diskname = NULL;
83 static char *qdiskname = NULL;
84 static char *options = NULL;
85 static char *progname = NULL;
87 static char *dumpdate = NULL;
88 static struct cmdargs *command_in_transit = NULL;
89 static char *chunker_timestamp = NULL;
91 static dumpfile_t file;
94 int main(int, char **);
95 static ssize_t write_tapeheader(int, dumpfile_t *);
96 static void databuf_init(struct databuf *, int, char *, off_t, off_t);
97 static int databuf_flush(struct databuf *);
99 static int startup_chunker(char *, off_t, off_t, struct databuf *, int *);
100 static int do_chunk(int, struct databuf *, int);
102 /* we use a function pointer for full_write, so that we can "shim" in
103 * full_write_with_fake_enospc for testing */
104 static size_t (*db_full_write)(int fd, const void *buf, size_t count);
105 static size_t full_write_with_fake_enospc(int fd, const void *buf, size_t count);
106 static off_t fake_enospc_at_byte = -1;
113 static struct databuf db;
114 struct cmdargs *cmdargs;
117 char *filename = NULL;
118 off_t chunksize, use;
120 am_feature_t *their_features = NULL;
122 config_overrides_t *cfg_ovr = NULL;
123 char *cfg_opt = NULL;
128 * Configure program for internationalization:
129 * 1) Only set the message locale for now.
130 * 2) Set textdomain for all amanda related programs to "amanda"
131 * We don't want to be forced to support dozens of message catalogs.
133 setlocale(LC_MESSAGES, "C");
134 textdomain("amanda");
138 set_pname("chunker");
140 dbopen(DBG_SUBDIR_SERVER);
142 /* Don't die when child closes pipe */
143 signal(SIGPIPE, SIG_IGN);
145 add_amanda_log_handler(amanda_log_stderr);
146 add_amanda_log_handler(amanda_log_trace_log);
148 cfg_ovr = extract_commandline_config_overrides(&argc, &argv);
153 set_config_overrides(cfg_ovr);
154 config_init(CONFIG_INIT_EXPLICIT_NAME | CONFIG_INIT_USE_CWD, cfg_opt);
156 if (config_errors(NULL) >= CFGERR_WARNINGS) {
157 config_print_errors();
158 if (config_errors(NULL) >= CFGERR_ERRORS) {
159 g_critical(_("errors processing config file"));
163 safe_cd(); /* do this *after* config_init() */
165 check_running_as(RUNNING_AS_DUMPUSER);
167 dbrename(get_config_name(), DBG_SUBDIR_SERVER);
169 log_add(L_INFO, "%s pid %ld", get_pname(), (long)getpid());
171 _("%s: pid %ld executable %s version %s\n"),
172 get_pname(), (long) getpid(),
176 /* now, make sure we are a valid user */
178 signal(SIGPIPE, SIG_IGN);
179 signal(SIGCHLD, SIG_IGN);
182 if(cmdargs->cmd == START) {
183 if(cmdargs->argc <= 1)
184 error(_("error [dumper START: not enough args: timestamp]"));
185 chunker_timestamp = newstralloc(chunker_timestamp, cmdargs->argv[1]);
188 log_add(L_INFO, "%s pid %ld", get_pname(), (long)getpid());
189 error(_("Didn't get START command"));
191 free_cmdargs(cmdargs);
193 /* set up a fake ENOSPC for testing purposes. Note that this counts
194 * headers as well as data written to disk. */
195 if (getenv("CHUNKER_FAKE_ENOSPC_AT")) {
196 char *env = getenv("CHUNKER_FAKE_ENOSPC_AT");
197 fake_enospc_at_byte = (off_t)atoi(env); /* these values are never > MAXINT */
198 db_full_write = full_write_with_fake_enospc;
199 g_debug("will trigger fake ENOSPC at byte %d", (int)fake_enospc_at_byte);
201 db_full_write = full_write;
207 switch(cmdargs->cmd) {
228 if(a >= cmdargs->argc) {
229 error(_("error [chunker PORT-WRITE: not enough args: handle]"));
232 handle = newstralloc(handle, cmdargs->argv[a++]);
234 if(a >= cmdargs->argc) {
235 error(_("error [chunker PORT-WRITE: not enough args: filename]"));
238 filename = newstralloc(filename, cmdargs->argv[a++]);
240 if(a >= cmdargs->argc) {
241 error(_("error [chunker PORT-WRITE: not enough args: hostname]"));
244 hostname = newstralloc(hostname, cmdargs->argv[a++]);
246 if(a >= cmdargs->argc) {
247 error(_("error [chunker PORT-WRITE: not enough args: features]"));
250 am_release_feature_set(their_features);
251 their_features = am_string_to_feature(cmdargs->argv[a++]);
252 if (!their_features) {
253 error(_("error [chunker PORT-WRITE: invalid feature string]"));
257 if(a >= cmdargs->argc) {
258 error(_("error [chunker PORT-WRITE: not enough args: diskname]"));
261 diskname = newstralloc(diskname, cmdargs->argv[a++]);
264 qdiskname = quote_string(diskname); /* qdiskname is a global */
266 if(a >= cmdargs->argc) {
267 error(_("error [chunker PORT-WRITE: not enough args: level]"));
270 level = atoi(cmdargs->argv[a++]);
272 if(a >= cmdargs->argc) {
273 error(_("error [chunker PORT-WRITE: not enough args: dumpdate]"));
276 dumpdate = newstralloc(dumpdate, cmdargs->argv[a++]);
278 if(a >= cmdargs->argc) {
279 error(_("error [chunker PORT-WRITE: not enough args: chunksize]"));
282 chunksize = OFF_T_ATOI(cmdargs->argv[a++]);
283 chunksize = am_floor(chunksize, (off_t)DISK_BLOCK_KB);
285 if(a >= cmdargs->argc) {
286 error(_("error [chunker PORT-WRITE: not enough args: progname]"));
289 progname = newstralloc(progname, cmdargs->argv[a++]);
291 if(a >= cmdargs->argc) {
292 error(_("error [chunker PORT-WRITE: not enough args: use]"));
295 use = am_floor(OFF_T_ATOI(cmdargs->argv[a++]), DISK_BLOCK_KB);
297 if(a >= cmdargs->argc) {
298 error(_("error [chunker PORT-WRITE: not enough args: options]"));
301 options = newstralloc(options, cmdargs->argv[a++]);
303 if(a != cmdargs->argc) {
304 error(_("error [chunker PORT-WRITE: too many args: %d != %d]"),
309 if ((header_fd = startup_chunker(filename, use, chunksize, &db,
310 &data_socket)) < 0) {
311 q = quote_string(vstrallocf(_("[chunker startup failed: %s]"), errstr));
312 putresult(TRYAGAIN, "%s %s\n", handle, q);
313 error("startup_chunker failed: %s", errstr);
315 command_in_transit = NULL;
316 if (header_fd >= 0 && do_chunk(header_fd, &db, data_socket)) {
317 char kb_str[NUM_STR_SIZE];
318 char kps_str[NUM_STR_SIZE];
321 runtime = stopclock();
322 rt = g_timeval_to_double(runtime);
323 g_snprintf(kb_str, SIZEOF(kb_str), "%lld",
324 (long long)(dumpsize - (off_t)headersize));
325 g_snprintf(kps_str, SIZEOF(kps_str), "%3.1lf",
326 isnormal(rt) ? (double)dumpsize / rt : 0.0);
327 errstr = newvstrallocf(errstr, "sec %s kb %s kps %s",
328 walltime_str(runtime), kb_str, kps_str);
329 m = vstrallocf("[%s]", errstr);
332 free_cmdargs(cmdargs);
333 if(command_in_transit != NULL) {
334 cmdargs = command_in_transit;
335 command_in_transit = NULL;
339 switch(cmdargs->cmd) {
341 putresult(DONE, "%s %lld %s\n", handle,
342 (long long)(dumpsize - (off_t)headersize), q);
343 log_add(L_SUCCESS, "%s %s %s %d [%s]",
344 hostname, qdiskname, chunker_timestamp, level, errstr);
350 if(dumpsize > (off_t)DISK_BLOCK_KB) {
351 putresult(PARTIAL, "%s %lld %s\n", handle,
352 (long long)(dumpsize - (off_t)headersize),
354 log_add(L_PARTIAL, "%s %s %s %d [%s]",
355 hostname, qdiskname, chunker_timestamp, level, errstr);
358 errstr = newvstrallocf(errstr,
359 _("dumper returned %s"), cmdstr[cmdargs->cmd]);
361 m = vstrallocf("[%s]",errstr);
364 putresult(FAILED, "%s %s\n", handle, q);
365 log_add(L_FAIL, "%s %s %s %d [%s]",
366 hostname, qdiskname, chunker_timestamp, level, errstr);
371 } else if (header_fd != -2) {
373 m = vstrallocf("[%s]", errstr);
378 putresult(FAILED, "%s %s\n", handle, q);
380 log_add(L_FAIL, "%s %s %s %d [%s]",
381 hostname, qdiskname, chunker_timestamp, level, errstr);
389 if(cmdargs->argc >= 1) {
390 q = quote_string(cmdargs->argv[0]);
392 q = stralloc(_("(no input?)"));
394 putresult(BAD_COMMAND, "%s\n", q);
399 /* } while(cmdargs->cmd != QUIT); */
401 log_add(L_INFO, "pid-done %ld", (long)getpid());
404 amfree(chunker_timestamp);
412 free_cmdargs(cmdargs);
413 if (command_in_transit)
414 free_cmdargs(command_in_transit);
415 am_release_feature_set(their_features);
416 their_features = NULL;
420 return (0); /* exit */
424 * Returns a file descriptor to the incoming port
425 * on success, or -1 on error.
435 int header_fd, outfd;
436 char *tmp_filename, *pc;
437 in_port_t header_port, data_port;
438 int header_socket, data_socket;
440 struct addrinfo *res;
444 if ((result = resolve_hostname("localhost", 0, &res, NULL) != 0)) {
445 errstr = newvstrallocf(errstr, _("could not resolve localhost: %s"),
446 gai_strerror(result));
449 header_socket = stream_server(res->ai_family, &header_port, 0,
451 data_socket = stream_server(res->ai_family, &data_port, 0,
453 if (res) freeaddrinfo(res);
455 if (header_socket < 0) {
456 errstr = vstrallocf(_("error creating header stream server: %s"), strerror(errno));
461 if (data_socket < 0) {
462 errstr = vstrallocf(_("error creating data stream server: %s"), strerror(errno));
463 aclose(header_socket);
467 putresult(PORT, "%d 127.0.0.1:%d\n", header_port, data_port);
469 header_fd = stream_accept(header_socket, CONNECT_TIMEOUT, 0,
471 if (header_fd == -1) {
472 errstr = vstrallocf(_("error accepting header stream: %s"),
474 aclose(header_socket);
478 aclose(header_socket);
480 tmp_filename = vstralloc(filename, ".tmp", NULL);
481 pc = strrchr(tmp_filename, '/');
482 g_assert(pc != NULL);
484 mkholdingdir(tmp_filename);
486 if ((outfd = open(tmp_filename, O_RDWR|O_CREAT|O_TRUNC, 0600)) < 0) {
487 int save_errno = errno;
488 char *m = vstrallocf(_("holding file \"%s\": %s"),
492 errstr = quote_string(m);
494 amfree(tmp_filename);
497 if(save_errno == ENOSPC) {
498 putresult(NO_ROOM, "%s %lld\n",
499 handle, (long long)use);
505 amfree(tmp_filename);
506 databuf_init(db, outfd, filename, use, chunksize);
508 *datasocket = data_socket;
520 char header_buf[DISK_BLOCK_BYTES];
524 dumpsize = dumpbytes = filesize = (off_t)0;
526 memset(header_buf, 0, sizeof(header_buf));
529 * The first thing we should receive is the file header, which we
530 * need to save into "file", as well as write out. Later, the
531 * chunk code will rewrite it.
533 nread = full_read(header_fd, header_buf, SIZEOF(header_buf));
534 if (nread != sizeof(header_buf)) {
536 errstr = vstrallocf(_("cannot read header: %s"), strerror(errno));
538 errstr = vstrallocf(_("cannot read header: got %zd bytes instead of %zd"),
539 nread, sizeof(header_buf));
544 parse_file_header(header_buf, &file, (size_t)nread);
545 if(write_tapeheader(db->fd, &file)) {
546 int save_errno = errno;
547 char *m = vstrallocf(_("write_tapeheader file %s: %s"),
548 db->filename, strerror(errno));
549 errstr = quote_string(m);
551 if(save_errno == ENOSPC) {
552 putresult(NO_ROOM, "%s %lld\n", handle,
553 (long long)(db->use+db->split_size-dumpsize));
558 dumpsize += (off_t)DISK_BLOCK_KB;
559 filesize = (off_t)DISK_BLOCK_KB;
560 headersize += DISK_BLOCK_KB;
562 /* open the data socket */
563 data_fd = stream_accept(data_socket, CONNECT_TIMEOUT, 0, STREAM_BUFSIZE);
566 errstr = vstrallocf(_("error accepting data stream: %s"),
574 * We've written the file header. Now, just write data until the
577 while ((nread = full_read(data_fd, db->buf,
578 (size_t)(db->datalimit - db->datain))) > 0) {
580 while(db->dataout < db->datain) {
581 if(!databuf_flush(db)) {
586 while(db->dataout < db->datain) {
587 if(!databuf_flush(db)) {
591 if(dumpbytes > (off_t)0) {
592 dumpsize += (off_t)1; /* count partial final KByte */
593 filesize += (off_t)1;
599 * Initialize a databuf. Takes a writeable file descriptor.
610 db->filename = stralloc(filename);
611 db->filename_seq = (off_t)0;
612 db->chunk_size = chunk_size;
613 db->split_size = (db->chunk_size > use) ? use : db->chunk_size;
614 db->use = (use > db->split_size) ? use - db->split_size : (off_t)0;
615 db->datain = db->dataout = db->buf;
616 db->datalimit = db->buf + SIZEOF(db->buf);
621 * Write out the buffer to the backing file
627 struct cmdargs *cmdargs = NULL;
629 size_t size_to_write;
632 char *arg_filename = NULL;
633 char *new_filename = NULL;
634 char *tmp_filename = NULL;
635 char sequence[NUM_STR_SIZE];
637 filetype_t save_type;
643 * If there's no data, do nothing.
645 if (db->dataout >= db->datain) {
650 * See if we need to split this file.
652 while (db->split_size > (off_t)0 && dumpsize >= db->split_size) {
653 if( db->use == (off_t)0 ) {
655 * Probably no more space on this disk. Request some more.
657 putresult(RQ_MORE_DISK, "%s\n", handle);
659 if(command_in_transit == NULL &&
660 (cmdargs->cmd == DONE || cmdargs->cmd == TRYAGAIN || cmdargs->cmd == FAILED)) {
661 command_in_transit = cmdargs;
664 if(cmdargs->cmd == CONTINUE) {
672 a = 2; /* skip CONTINUE and serial */
674 if(a >= cmdargs->argc) {
675 error(_("error [chunker CONTINUE: not enough args: filename]"));
678 arg_filename = newstralloc(arg_filename, cmdargs->argv[a++]);
680 if(a >= cmdargs->argc) {
681 error(_("error [chunker CONTINUE: not enough args: chunksize]"));
684 db->chunk_size = OFF_T_ATOI(cmdargs->argv[a++]);
685 db->chunk_size = am_floor(db->chunk_size, (off_t)DISK_BLOCK_KB);
687 if(a >= cmdargs->argc) {
688 error(_("error [chunker CONTINUE: not enough args: use]"));
691 db->use = OFF_T_ATOI(cmdargs->argv[a++]);
693 if(a != cmdargs->argc) {
694 error(_("error [chunker CONTINUE: too many args: %d != %d]"),
699 if(strcmp(db->filename, arg_filename) == 0) {
701 * Same disk, so use what room is left up to the
702 * next chunk boundary or the amount we were given,
705 left_in_chunk = db->chunk_size - filesize;
706 if(left_in_chunk > db->use) {
707 db->split_size += db->use;
710 db->split_size += left_in_chunk;
711 db->use -= left_in_chunk;
713 if(left_in_chunk > (off_t)0) {
715 * We still have space in this chunk.
721 * Different disk, so use new file.
723 db->filename = newstralloc(db->filename, arg_filename);
725 } else if(cmdargs->cmd == ABORT) {
727 errstr = newstralloc(errstr, cmdargs->argv[1]);
728 putresult(ABORT_FINISHED, "%s\n", handle);
732 if(cmdargs->argc >= 1) {
733 q = quote_string(cmdargs->argv[0]);
735 q = stralloc(_("(no input?)"));
737 error(_("error [bad command after RQ-MORE-DISK: \"%s\"]"), q);
743 * Time to use another file.
747 * First, open the new chunk file, and give it a new header
748 * that has no cont_filename pointer.
750 g_snprintf(sequence, SIZEOF(sequence), "%d", db->filename_seq);
751 new_filename = newvstralloc(new_filename,
756 tmp_filename = newvstralloc(tmp_filename,
760 pc = strrchr(tmp_filename, '/');
761 g_assert(pc != NULL); /* Only a problem if db->filename has no /. */
763 mkholdingdir(tmp_filename);
765 newfd = open(tmp_filename, O_RDWR|O_CREAT|O_TRUNC, 0600);
767 int save_errno = errno;
770 if(save_errno == ENOSPC) {
771 putresult(NO_ROOM, "%s %lld\n", handle,
772 (long long)(db->use+db->split_size-dumpsize));
773 db->use = (off_t)0; /* force RQ_MORE_DISK */
774 db->split_size = dumpsize;
777 m = vstrallocf(_("creating chunk holding file \"%s\": %s"),
780 errstr = quote_string(m);
786 save_type = file.type;
787 file.type = F_CONT_DUMPFILE;
788 file.cont_filename[0] = '\0';
789 if(write_tapeheader(newfd, &file)) {
790 int save_errno = errno;
794 if(save_errno == ENOSPC) {
795 if (unlink(tmp_filename) < 0) {
796 g_debug("could not delete '%s'; ignoring", tmp_filename);
798 putresult(NO_ROOM, "%s %lld\n", handle,
799 (long long)(db->use+db->split_size-dumpsize));
800 db->use = (off_t)0; /* force RQ_MORE DISK */
801 db->split_size = dumpsize;
802 file.type = save_type;
805 m = vstrallocf(_("write_tapeheader file %s: %s"),
808 errstr = quote_string(m);
815 * Now, update the header of the current file to point
816 * to the next chunk, and then close it.
818 if (lseek(db->fd, (off_t)0, SEEK_SET) < (off_t)0) {
819 char *m = vstrallocf(_("lseek holding file %s: %s"),
822 errstr = quote_string(m);
829 file.type = save_type;
830 strncpy(file.cont_filename, new_filename, SIZEOF(file.cont_filename));
831 file.cont_filename[SIZEOF(file.cont_filename)-1] = '\0';
832 if(write_tapeheader(db->fd, &file)) {
833 char * m = vstrallocf(_("write_tapeheader file \"%s\": %s"),
836 errstr = quote_string(m);
839 unlink(tmp_filename);
843 file.type = F_CONT_DUMPFILE;
846 * Now shift the file descriptor.
853 * Update when we need to chunk again
855 if(db->use <= (off_t)DISK_BLOCK_KB) {
857 * Cheat and use one more block than allowed so we can make
860 db->split_size += (off_t)(2 * DISK_BLOCK_KB);
862 } else if(db->chunk_size > db->use) {
863 db->split_size += db->use;
866 db->split_size += db->chunk_size;
867 db->use -= db->chunk_size;
871 amfree(tmp_filename);
872 amfree(new_filename);
873 dumpsize += (off_t)DISK_BLOCK_KB;
874 filesize = (off_t)DISK_BLOCK_KB;
875 headersize += DISK_BLOCK_KB;
880 * Write out the buffer
882 size_to_write = (size_t)(db->datain - db->dataout);
883 written = db_full_write(db->fd, db->dataout, size_to_write);
885 db->dataout += written;
886 dumpbytes += (off_t)written;
888 dumpsize += (dumpbytes / (off_t)1024);
889 filesize += (dumpbytes / (off_t)1024);
891 if (written < size_to_write) {
892 if (errno != ENOSPC) {
893 char *m = vstrallocf(_("data write: %s"), strerror(errno));
894 errstr = quote_string(m);
901 * NO-ROOM is informational only. Later, RQ_MORE_DISK will be
902 * issued to use another holding disk.
904 putresult(NO_ROOM, "%s %lld\n", handle,
905 (long long)(db->use+db->split_size-dumpsize));
906 db->use = (off_t)0; /* force RQ_MORE_DISK */
907 db->split_size = dumpsize;
910 if (db->datain == db->dataout) {
912 * We flushed the whole buffer so reset to use it all.
914 db->datain = db->dataout = db->buf;
920 free_cmdargs(cmdargs);
921 amfree(new_filename);
922 /*@i@*/ amfree(tmp_filename);
923 amfree(arg_filename);
929 * Send an Amanda dump header to the output file and set file->blocksize
939 file->blocksize = DISK_BLOCK_BYTES;
940 if (debug_chunker > 1)
941 dump_dumpfile_t(file);
942 buffer = build_header(file, NULL, DISK_BLOCK_BYTES);
943 if (!buffer) /* this shouldn't happen */
944 error(_("header does not fit in %zd bytes"), (size_t)DISK_BLOCK_BYTES);
946 written = db_full_write(outfd, buffer, DISK_BLOCK_BYTES);
948 if(written == DISK_BLOCK_BYTES) return 0;
950 /* fake ENOSPC when we get a short write without errno set */
958 full_write_with_fake_enospc(
965 //g_debug("HERE %zd %zd", count, (size_t)fake_enospc_at_byte);
967 if (count <= (size_t)fake_enospc_at_byte) {
968 fake_enospc_at_byte -= count;
969 return full_write(fd, buf, count);
972 /* if we get here, the caller has requested a size that is less
973 * than fake_enospc_at_byte. */
974 count = fake_enospc_at_byte;
975 g_debug("returning fake ENOSPC");
977 if (fake_enospc_at_byte) {
978 rc = full_write(fd, buf, fake_enospc_at_byte);
979 if (rc == (size_t)fake_enospc_at_byte) {
980 /* full_write succeeded, so fake a failure */
984 /* no bytes to write; just fake an error */
989 /* switch back to calling full_write directly */
990 fake_enospc_at_byte = -1;
991 db_full_write = full_write;