int main (int argc, char *argv[]) { struct or_dbrec dbrec; char renamebuf[256]; time_t now; struct tm *time_ptr; _Xltimeparams localtime_buf; aa_argv0 = argv[0]; setlocale (LC_ALL, ""); dtsearch_catd = catopen (FNAME_DTSRCAT, 0); austools_catd = catopen (FNAME_AUSCAT, 0); time (&now); time_ptr = _XLocaltime(&now, localtime_buf); strftime (renamebuf, sizeof (renamebuf), catgets (dtsearch_catd, MS_misc, 22, "%A, %b %d %Y, %I:%M %p"), time_ptr); printf (catgets (dtsearch_catd, MS_misc, 23, "%s: Version %s. Run %s.\n"), aa_argv0, DtSrVERSION, renamebuf); if (argc < 2) { printf (catgets (dtsearch_catd, MS_dbrec, 310, "USAGE: %s <dbname>\n"), aa_argv0); return 2; } sprintf (renamebuf, "%s.d00", argv[1]); db_oflag = O_RDONLY; /* db files may be read-only */ d_open (argv[1], "o"); if (db_status != S_OKAY) { printf (catgets (dtsearch_catd, MS_dbrec, 330, "Could not open '%s' database.\n%s\n"), argv[1], vista_msg(PROGNAME"293")); return 3; } d_recfrst (OR_DBREC, 0); if (db_status != S_OKAY) { printf (catgets (dtsearch_catd, MS_dbrec, 340, "No dbrec record in database '%s'.\n"), argv[1]); return 4; } d_recread (&dbrec, 0); if (db_status != S_OKAY) { printf (catgets (dtsearch_catd, MS_dbrec, 350, "Can't read dbrec record in database '%s'.\n%s\n"), argv[1], vista_msg(PROGNAME"306")); return 5; } swab_dbrec (&dbrec, NTOH); print_dbrec (argv[1], &dbrec); return 0; } /* main() */
/* * Open a device. */ void DEVICE::open_device(DCR *dcr, int omode) { POOL_MEM archive_name(PM_FNAME); get_autochanger_loaded_slot(dcr); /* * Handle opening of File Archive (not a tape) */ pm_strcpy(archive_name, dev_name); /* * If this is a virtual autochanger (i.e. changer_res != NULL) we simply use * the device name, assuming it has been appropriately setup by the "autochanger". */ if (!device->changer_res || device->changer_command[0] == 0) { if (VolCatInfo.VolCatName[0] == 0) { Mmsg(errmsg, _("Could not open file device %s. No Volume name given.\n"), print_name()); clear_opened(); return; } if (!IsPathSeparator(archive_name.c_str()[strlen(archive_name.c_str())-1])) { pm_strcat(archive_name, "/"); } pm_strcat(archive_name, getVolCatName()); } mount(dcr, 1); /* do mount if required */ open_mode = omode; set_mode(omode); /* * If creating file, give 0640 permissions */ Dmsg3(100, "open disk: mode=%s open(%s, 0x%x, 0640)\n", mode_to_str(omode), archive_name.c_str(), oflags); if ((m_fd = d_open(archive_name.c_str(), oflags, 0640)) < 0) { berrno be; dev_errno = errno; Mmsg2(errmsg, _("Could not open: %s, ERR=%s\n"), archive_name.c_str(), be.bstrerror()); Dmsg1(100, "open failed: %s", errmsg); } if (m_fd >= 0) { dev_errno = 0; file = 0; file_addr = 0; } Dmsg1(100, "open dev: disk fd=%d opened\n", m_fd); }
void fuzix_main(void) { /* setup state */ inint = false; udata.u_insys = true; #ifdef PROGTOP /* FIXME */ ramtop = (uaddr_t)PROGTOP; #endif tty_init(); if (d_open(TTYDEV, 0) != 0) panic(PANIC_NOTTY); /* Sign on messages */ kprintf( "FUZIX version %s\n" "Copyright (c) 1988-2002 by H.F.Bower, D.Braun, S.Nitschke, H.Peraza\n" "Copyright (c) 1997-2001 by Arcady Schekochikhin, Adriano C. R. da Cunha\n" "Copyright (c) 2013-2015 Will Sowerbutts <*****@*****.**>\n" "Copyright (c) 2014-2015 Alan Cox <*****@*****.**>\nDevboot\n", sysinfo.uname); #ifndef SWAPDEV #ifdef PROC_SIZE maxproc = procmem / PROC_SIZE; /* Check we don't exceed the process table size limit */ if (maxproc > PTABSIZE) { kprintf("WARNING: Increase PTABSIZE to %d to use available RAM\n", maxproc); maxproc = PTABSIZE; } #else maxproc = PTABSIZE; #endif #else maxproc = PTABSIZE; #endif /* Used as a stop marker to make compares fast on process scheduling and the like */ ptab_end = &ptab[maxproc]; /* Parameters message */ kprintf("%dkB total RAM, %dkB available to processes (%d processes max)\n", ramsize, procmem, maxproc); bufinit(); fstabinit(); pagemap_init(); create_init(); /* runtime configurable, defaults to build time setting */ ticks_per_dsecond = TICKSPERSEC / 10; kputs("Enabling interrupts ... "); __hard_ei(); /* Physical interrupts on */ kputs("ok.\n"); /* get the root device */ root_dev = get_root_dev(); /* finish building argv */ complete_init(); /* initialise hardware devices */ device_init(); /* Mount the root device */ kprintf("Mounting root fs (root_dev=%d, r%c): ", root_dev, ro ? 'o' : 'w'); if (fmount(root_dev, NULLINODE, ro)) panic(PANIC_NOFILESYS); root = i_open(root_dev, ROOTINODE); if (!root) panic(PANIC_NOROOT); kputs("OK\n"); udata.u_cwd = i_ref(root); udata.u_root = i_ref(root); rdtime32(&udata.u_time); exec_or_die(); }
/* dblk.path may be NULL */ int open_dblk (DBLK ** dblist, int numpages, int debugging) { DBLK *db, *bad_db, **lastlink; int i; size_t totlen = 0L; char *allnames; int vistano = 0; char *srcptr, *targptr; char temp_file_name[1024]; char sprintbuf[1024]; struct stat statbuf; char open_mode [8]; if (debugging) fprintf (aa_stderr, PROGNAME"76 " "Entering open_dblks(). db_oflag==%d.\n", db_oflag); if (dblist == NULL || numpages < 8) { BAD_INPUT: sprintf (sprintbuf, catgets (dtsearch_catd, MS_oeinit, 99, "%s Programming Error: Invalid input to open_dblk()."), PROGNAME "99"); DtSearchAddMessage (sprintbuf); return FALSE; } if (*dblist == NULL) /* empty list of dblks */ goto BAD_INPUT; if (debugging) { fprintf (aa_stderr, PROGNAME "96 Current list of dblks:\n"); for (db = *dblist; db != NULL; db = db->link) { targptr = sprintbuf; for (i = 0; i < db->ktcount; i++) { *targptr++ = db->keytypes[i].ktchar; } *targptr = 0; fprintf (aa_stderr, "--> DBLK at %p link=%p name='%s' maxhits=%d\n" " keytypes='%s', path='%s'\n", (void *) db, (void *) db->link, db->name, db->maxhits, sprintbuf, NULLORSTR (db->path)); } } /* By doing setpages first, we can trap previously opened databases. * Overflow and transaction locking files are not required. */ d_setpages (numpages, 0); if (db_status != S_OKAY) { DtSearchAddMessage (vista_msg (PROGNAME "389")); return FALSE; } /* ---- PASS #1 ------------------------------------------ * Open nonvista (d99) files. If error, unlink dblk from dblist. * Add up the total string length of surviving paths and database names. * This giant path/file string will be used in the single d_open() * below to find the .dbd files. * While we're at it, set vistano in each dblk. * The open mode depends on the current setting of db_oflag. */ if (db_oflag == O_RDONLY) strcpy (open_mode, "rb"); else strcpy (open_mode, "r+b"); db = *dblist; lastlink = dblist; while (db != NULL) { if (db->path == NULL) db->path = strdup (""); strcpy (temp_file_name, db->path); strcat (temp_file_name, db->name); strcat (temp_file_name, EXT_DTBS); if ((db->iifile = fopen (temp_file_name, open_mode)) == NULL) { if (debugging) fprintf (aa_stderr, PROGNAME "129 UNLINK: cant open '%s'.\n", temp_file_name); sprintf (sprintbuf, catgets (dtsearch_catd, MS_oeinit, 317, "%s Cannot open database file '%s'.\n" " Errno %d = %s\n" " %s is removing '%s' from list of available databases."), PROGNAME "317", temp_file_name, errno, strerror (errno), OE_prodname, db->name); if (errno == ENOENT) strcat (sprintbuf, catgets (dtsearch_catd, MS_oeinit, 318, "\n This can usually be corrected by specifying a valid\n" " database PATH in the site configuration file.")); DtSearchAddMessage (sprintbuf); goto DELETE_DB; } /* * Find and save the timestamp for when the d99 file was * last modified. An engine reinit is forced if it changes * while the engine is running. */ if (fstat (fileno (db->iifile), &statbuf) == -1) { if (debugging) fprintf (aa_stderr, PROGNAME "149 UNLINK: cant get status '%s'.\n", temp_file_name); sprintf (sprintbuf, catgets (dtsearch_catd, MS_oeinit, 1404, "%s Removing database '%s' from list of " "available databases because status is " "unavailable for file %s: %s"), PROGNAME "1404", db->name, temp_file_name, strerror (errno)); DtSearchAddMessage (sprintbuf); goto DELETE_DB; } db->iimtime = statbuf.st_mtime; /* * This dblk is ok so far. Increment pointers and * continue. */ if (debugging) fprintf (aa_stderr, PROGNAME "163 opened '%s'.\n", temp_file_name); db->vistano = vistano++; totlen += strlen (db->path) + strlen (db->name) + 16; lastlink = &db->link; db = db->link; continue; DELETE_DB: /* * This dblk failed in one or more ways. Unlink it and * don't increment pointers. If all dblks unlinked, *dblist * will = NULL. */ bad_db = db; /* temp save */ *lastlink = db->link; db = db->link; free (bad_db); } /* end PASS #1 */ /* quit if no dblks remain */ if (vistano <= 0) { sprintf (sprintbuf, catgets (dtsearch_catd, MS_misc, 8, "%s No valid databases remain."), PROGNAME "265"); DtSearchAddMessage (sprintbuf); return FALSE; } allnames = austext_malloc (totlen + 512, PROGNAME "66", NULL); /* ---- PASS #2 ------------------------------------------ * Build string of accumulated path and database names. */ targptr = allnames; for (db = *dblist; db != NULL; db = db->link) { srcptr = db->path; while (*srcptr != 0) *targptr++ = *srcptr++; srcptr = db->name; while (*srcptr != 0) *targptr++ = *srcptr++; *targptr++ = ';'; } *(--targptr) = 0; /* terminate string */ if (debugging) fprintf (aa_stderr, PROGNAME "150 vista opening databases '%s'\n", allnames); d_open (allnames, "o"); /* replaces OPEN() call from dmacros.h */ if (db_status != S_OKAY) { targptr = austext_malloc (totlen + 128, PROGNAME"239", NULL); sprintf (targptr, catgets (dtsearch_catd, MS_vista, 378, "%s Could not open following database name string:\n '%s'"), PROGNAME"378", allnames); DtSearchAddMessage (targptr); DtSearchAddMessage (vista_msg (PROGNAME"379")); free (allnames); free (targptr); return FALSE; } else if (debugging) fprintf (aa_stderr, " --> vista open successful!\n"); /* From here on, emergency exits MUST close the databases */ austext_exit_dbms = (void (*) (int)) d_close; free (allnames); return TRUE; } /* open_dblk() */
/* * Open a fifo device */ void win32_fifo_device::open_device(DCR *dcr, int omode) { file_size = 0; int timeout = max_open_wait; utime_t start_time = time(NULL); mount(dcr, 1); /* do mount if required */ Dmsg0(100, "Open dev: device is fifo\n"); get_autochanger_loaded_slot(dcr); open_mode = omode; set_mode(omode); if (timeout < 1) { timeout = 1; } errno = 0; if (timeout) { /* * Set open timer */ tid = start_thread_timer(dcr->jcr, pthread_self(), timeout); } Dmsg2(100, "Try open %s mode=%s\n", prt_name, mode_to_str(omode)); /* * If busy retry each second for max_open_wait seconds */ for ( ;; ) { /* * Try non-blocking open */ m_fd = d_open(dev_name, oflags | O_NONBLOCK, 0); if (m_fd < 0) { berrno be; dev_errno = errno; Dmsg5(100, "Open error on %s omode=%d oflags=%x errno=%d: ERR=%s\n", prt_name, omode, oflags, errno, be.bstrerror()); } else { d_close(m_fd); m_fd = d_open(dev_name, oflags, 0); /* open normally */ if (m_fd < 0) { berrno be; dev_errno = errno; Dmsg5(100, "Open error on %s omode=%d oflags=%x errno=%d: ERR=%s\n", prt_name, omode, oflags, errno, be.bstrerror()); break; } dev_errno = 0; lock_door(); break; /* Successfully opened and rewound */ } bmicrosleep(5, 0); /* * Exceed wait time ? */ if (time(NULL) - start_time >= max_open_wait) { break; /* yes, get out */ } } if (!is_open()) { berrno be; Mmsg2(errmsg, _("Unable to open device %s: ERR=%s\n"), prt_name, be.bstrerror(dev_errno)); Dmsg1(100, "%s", errmsg); } /* * Stop any open() timer we started */ if (tid) { stop_thread_timer(tid); tid = 0; } Dmsg1(100, "open dev: fifo %d opened\n", m_fd); }
int16_t _open(void) { int8_t uindex; int8_t oftindex; staticfast inoptr ino; inoptr itmp; int16_t perm; staticfast inoptr parent; char fname[FILENAME_LEN + 1]; int trunc; int r; int w; int j; parent = NULLINODE; trunc = flag & O_TRUNC; r = (flag + 1) & 1; w = (flag + 1) & 2; if (O_ACCMODE(flag) == 3 || (flag & O_BADBITS)) { udata.u_error = EINVAL; return (-1); } if ((uindex = uf_alloc()) == -1) return (-1); if ((oftindex = oft_alloc()) == -1) goto nooft; ino = n_open(name, &parent); if (ino) { i_deref(parent); /* O_EXCL test */ if ((flag & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)) { udata.u_error = EEXIST; goto idrop; } } else { /* New file */ if (!(flag & O_CREAT)) { udata.u_error = ENOENT; goto cantopen; } filename(name, fname); /* newfile drops parent for us */ if (parent && (ino = newfile(parent, fname))) { ino->c_node.i_mode = (F_REG | (mode & MODE_MASK & ~udata.u_mask)); setftime(ino, A_TIME | M_TIME | C_TIME); wr_inode(ino); } else { udata.u_error = ENFILE; /* FIXME, should be set in newfile not bodged to a guessed code */ goto cantopen; } } of_tab[oftindex].o_inode = ino; perm = getperm(ino); if ((r && !(perm & OTH_RD)) || (w && !(perm & OTH_WR))) { udata.u_error = EPERM; goto cantopen; } if (getmode(ino) == F_DIR && w) { udata.u_error = EISDIR; goto cantopen; } itmp = ino; /* d_open may block and thus ino may become invalid as may parent (but we don't need it again) */ if (isdevice(ino) && d_open((int) ino->c_node.i_addr[0], flag) != 0) { udata.u_error = ENXIO; goto cantopen; } /* get the static pointer back */ ino = itmp; if (trunc && getmode(ino) == F_REG) { f_trunc(ino); for (j = 0; j < OFTSIZE; ++j) /* Arguably should fix at read/write */ if (of_tab[j].o_inode == ino) of_tab[j].o_ptr = 0; } udata.u_files[uindex] = oftindex; of_tab[oftindex].o_ptr = 0; of_tab[oftindex].o_access = flag; /* Save the low bits only */ if (flag & O_CLOEXEC) udata.u_cloexec |= (1 << oftindex); /* FIXME: ATIME ? */ /* * Sleep process if no writer or reader */ if (getmode(ino) == F_PIPE && of_tab[oftindex].o_refs == 1 && !(flag & O_NDELAY)) psleep(ino); /* From the moment of the psleep ino is invalid */ return (uindex); idrop: i_deref(ino); cantopen: oft_deref(oftindex); /* This will call i_deref() */ nooft: udata.u_files[uindex] = NO_FILE; return (-1); }
void fuzix_main(void) { /* setup state */ inint = false; udata.u_insys = true; ramtop = PROGTOP; tty_init(); if (d_open(TTYDEV, 0) != 0) panic("no tty"); /* Sign on messages (stashed in a buffer so we can bin them */ kprintf((char *)bufpool[0].bf_data, uname_str); #ifndef SWAPDEV #ifdef PROC_SIZE maxproc = procmem / PROC_SIZE; /* Check we don't exceed the process table size limit */ if (maxproc > PTABSIZE) { kprintf((char *)bufpool[1].bf_data, maxproc); maxproc = PTABSIZE; } #else maxproc = PTABSIZE; #endif #else maxproc = PTABSIZE; #endif /* Parameters message */ kprintf((char *)bufpool[2].bf_data, ramsize, procmem, maxproc); /* Now blow away the strings */ bufinit(); pagemap_init(); create_init(); kprintf("%x:%x\n", udata.u_page, udata.u_page2); kprintf("%x:%x\n", udata.u_ptab->p_page, udata.u_ptab->p_page2); kputs("Enabling interrupts ... "); ei(); kputs("ok.\n"); /* initialise hardware devices */ device_init(); root_dev = DEFAULT_ROOT; if (cmdline && *cmdline) { while (*cmdline == ' ') ++cmdline; root_dev = *cmdline - '0'; } else { kputs("bootdev: "); udata.u_base = bootline; udata.u_sysio = 1; udata.u_count = 2; udata.u_euid = 0; /* Always begin as superuser */ cdread(TTYDEV, O_RDONLY); /* read root filesystem name from tty */ if (*bootline >= '0') root_dev = *bootline - '0'; } /* Mount the root device */ kprintf("Mounting root fs (root_dev=%d): ", root_dev); if (fmount(root_dev, NULLINODE, 0)) panic("no filesys"); root = i_open(root_dev, ROOTINODE); if (!root) panic("no root"); kputs("OK\n"); i_ref(udata.u_cwd = root); i_ref(udata.u_root = root); rdtime32(&udata.u_time); exec_or_die(); }
bool CDbVista::OpenDatabase(const CString &strDbPath, const CString &strDbName, CString *pstrErrorMsg) { char strTempPath[DBVISTA_NAMELEN+1]; char strTempName[DBVISTA_NAMELEN+1]; char strTempDbFile[DBVISTA_NAMELEN + DBVISTA_NAMELEN +1]; CString strErrorMsg; int iLen = strlen(strDbPath); if (iLen > (DBVISTA_NAMELEN - 1)) { strErrorMsg.Format("Path formed by %s is %d characters\nDbVista limit is 46 characters.", strDbPath, iLen); //WAS "NOT FOR NDAR". Reenabled by pjm 11/27/2007 for B2R1 if (!m_bQuietMode) MessageBox(NULL, strErrorMsg, "Database Path Error", MB_OK|MB_ICONSTOP); if (pstrErrorMsg) *pstrErrorMsg = strErrorMsg; return(false); } strncpy(strTempPath, strDbPath, DBVISTA_NAMELEN); strncpy(strTempName, strDbName, DBVISTA_NAMELEN); if (pstrErrorMsg) pstrErrorMsg->Empty(); // clear the error string if (mbDatabaseOpen) CloseDatabase(); // if db is already open, must close it //SetCurrentDrive(); // check if we have to implement this in new version SFK strcpy(strTempDbFile, strTempName); strcat(strTempDbFile, ".dbd"); if (!m_Dir.FileExists(strTempPath, strTempDbFile)) { strErrorMsg.Format("Database does not exist at %s.", strDbPath); //WAS "NOT FOR NDAR". Reenabled by pjm 11/27/2007 for B2R1 if (!m_bQuietMode) MessageBox(NULL, strErrorMsg, "Database Open Error", MB_OK|MB_ICONWARNING); if (pstrErrorMsg) *pstrErrorMsg = strErrorMsg; return(false); } // Open the database. This takes several steps. if (dt_opentask(&Currtask) != S_OKAY) { strErrorMsg.Format("Could not open the dbVista task.\nDatabase at %s could not be opened.", strDbPath); //WAS "NOT FOR NDAR". Reenabled by pjm 11/27/2007 for B2R1 if (!m_bQuietMode) MessageBox(NULL, strErrorMsg, "Database Open Error", MB_OK|MB_ICONWARNING); if (pstrErrorMsg) *pstrErrorMsg = strErrorMsg; return(false); } d_set_dberr(CustomDbVistaErrorHandler); if (d_dbtaf(strTempPath) != S_OKAY) { strErrorMsg.Format("Could not set the dbVista transaction file path variable.\nDatabase at %s could not be opened.", strDbPath); //WAS "NOT FOR NDAR". Reenabled by pjm 11/27/2007 for B2R1 if (!m_bQuietMode) MessageBox(NULL, strErrorMsg, "Database Open Error", MB_OK|MB_ICONWARNING); if (pstrErrorMsg) *pstrErrorMsg = strErrorMsg; return(false); } if (d_dbdpath(strTempPath) != S_OKAY) { strErrorMsg.Format("Could not set the dbVista path variable.\nDatabase at %s could not be opened.", strDbPath); //WAS "NOT FOR NDAR". Reenabled by pjm 11/27/2007 for B2R1 if (!m_bQuietMode) MessageBox(NULL, strErrorMsg, "Database Open Error", MB_OK|MB_ICONWARNING); if (pstrErrorMsg) *pstrErrorMsg = strErrorMsg; return(false); } if (d_dbfpath(strTempPath) != S_OKAY) { strErrorMsg.Format("Could not set the dbVista file variable.\nDatabase at %s could not be opened.", strDbPath); //WAS "NOT FOR NDAR". Reenabled by pjm 11/27/2007 for B2R1 if (!m_bQuietMode) MessageBox(NULL, strErrorMsg, "Database Open Error", MB_OK|MB_ICONWARNING); if (pstrErrorMsg) *pstrErrorMsg = strErrorMsg; return(false); } if (d_open(strTempName,"o") != S_OKAY) { strErrorMsg.Format("Error on database open. Database at %s could not be opened.", strDbPath); //WAS "NOT FOR NDAR". Reenabled by pjm 11/27/2007 for B2R1 if (!m_bQuietMode) MessageBox(NULL, strErrorMsg, "Database Open Error", MB_OK|MB_ICONWARNING); if (pstrErrorMsg) *pstrErrorMsg = strErrorMsg; return(false); } // Save the pathname of the currently open database // database was successfully opened, now remember the name and path mstrDatabaseName = strDbName; // name of the database mstrDatabasePath = strTempPath; // path on disk where database is found mbDatabaseOpen = true; return(true); }
/* * Open a tape device */ void generic_tape_device::open_device(DCR *dcr, int omode) { file_size = 0; int timeout = max_open_wait; #if !defined(HAVE_WIN32) struct mtop mt_com; utime_t start_time = time(NULL); #endif mount(dcr, 1); /* do mount if required */ Dmsg0(100, "Open dev: device is tape\n"); get_autochanger_loaded_slot(dcr); open_mode = omode; set_mode(omode); if (timeout < 1) { timeout = 1; } errno = 0; Dmsg2(100, "Try open %s mode=%s\n", prt_name, mode_to_str(omode)); #if defined(HAVE_WIN32) /* * Windows Code */ if ((m_fd = d_open(dev_name, oflags, 0)) < 0) { dev_errno = errno; } #else /* * UNIX Code * * If busy retry each second for max_open_wait seconds */ for ( ;; ) { /* * Try non-blocking open */ m_fd = d_open(dev_name, oflags | O_NONBLOCK, 0); if (m_fd < 0) { berrno be; dev_errno = errno; Dmsg5(100, "Open error on %s omode=%d oflags=%x errno=%d: ERR=%s\n", prt_name, omode, oflags, errno, be.bstrerror()); } else { /* * Tape open, now rewind it */ Dmsg0(100, "Rewind after open\n"); mt_com.mt_op = MTREW; mt_com.mt_count = 1; /* * Rewind only if dev is a tape */ if (d_ioctl(m_fd, MTIOCTOP, (char *)&mt_com) < 0) { berrno be; dev_errno = errno; /* set error status from rewind */ d_close(m_fd); clear_opened(); Dmsg2(100, "Rewind error on %s close: ERR=%s\n", prt_name, be.bstrerror(dev_errno)); /* * If we get busy, device is probably rewinding, try again */ if (dev_errno != EBUSY) { break; /* error -- no medium */ } } else { /* * Got fd and rewind worked, so we must have medium in drive */ d_close(m_fd); m_fd = d_open(dev_name, oflags, 0); /* open normally */ if (m_fd < 0) { berrno be; dev_errno = errno; Dmsg5(100, "Open error on %s omode=%d oflags=%x errno=%d: ERR=%s\n", prt_name, omode, oflags, errno, be.bstrerror()); break; } dev_errno = 0; lock_door(); set_os_device_parameters(dcr); /* do system dependent stuff */ break; /* Successfully opened and rewound */ } } bmicrosleep(5, 0); /* * Exceed wait time ? */ if (time(NULL) - start_time >= max_open_wait) { break; /* yes, get out */ } } #endif if (!is_open()) { berrno be; Mmsg2(errmsg, _("Unable to open device %s: ERR=%s\n"), prt_name, be.bstrerror(dev_errno)); Dmsg1(100, "%s", errmsg); } Dmsg1(100, "open dev: tape %d opened\n", m_fd); }
/* 1. CREATE or find database dictionary (.dbd file). * 2. CREATE empty 'dtsearch' database files. * 3. OPEN 'dtsearch' database. * 4. INITIALIZE the database. * 5. WRITE dbrec after initializing it. * 6. RENAME each database file. * 7. UNLINK (delete) d9x files. */ int main (int argc, char *argv[]) { int i; char *ptr; FILE *f; struct or_miscrec miscrec; struct or_swordrec swordrec; struct or_lwordrec lwordrec; setlocale (LC_ALL, ""); dtsearch_catd = catopen (FNAME_DTSRCAT, 0); aa_argv0 = argv[0]; max_ormisc_size = sizeof (miscrec.or_misc); maxwidth_sword = sizeof (swordrec.or_swordkey) - 1; maxwidth_lword = sizeof (lwordrec.or_lwordkey) - 1; printf (catgets (dtsearch_catd, MS_misc, 4, "%s Version %s.\n"), aa_argv0, DtSrVERSION ); /* Handle cmd line args. Init global variables. */ user_args_processor (argc, argv); /* ------- copy model .dbd to new .dbd ------- */ /* CASE 1: If user specified -d special alternative * directory for model .dbd, it should be there. */ if (modelpath[0] != 0) { if (debug_mode) printf (PROGNAME"628 Try opening '%s' (-d dir).\n", modelpath); if ((f = fopen (modelpath, "rb")) != NULL) { if (debug_mode) puts (PROGNAME"638 Found it!"); create_new_dbd (f); fclose (f); goto DBD_OKAY; } else { print_usage(); printf (catgets (dtsearch_catd, MS_initausd, 213, default_unable_to_open_msg), "\n"PROGNAME"302", modelpath, strerror(errno)); DtSearchExit (4); } } /* end CASE 1 */ /* CASE 2: If model .dbd is in current directory, use it. * If error is anything other than 'cant find file', quit now. */ if (debug_mode) printf (PROGNAME"649 Try opening '%s' (curr dir).\n", FNAME_MODEL); if ((f = fopen (FNAME_MODEL, "rb")) != NULL) { if (debug_mode) puts (PROGNAME"660 Found it!"); create_new_dbd (f); fclose (f); goto DBD_OKAY; } else if (errno != ENOENT) { print_usage(); printf (catgets (dtsearch_catd, MS_initausd, 213, default_unable_to_open_msg), "\n"PROGNAME"655", FNAME_MODEL, strerror(errno)); DtSearchExit (4); } /* end else CASE 2 */ /* CASE 3: Last chance. Look for model .dbd in target directory. * At this point have to quit on any error. */ strcpy (modelpath, newpath); strcpy (modelpath + path_offset, FNAME_MODEL); if (debug_mode) printf (PROGNAME"672 Try opening '%s' (new dir).\n", modelpath); if ((f = fopen (modelpath, "rb")) != NULL) { if (debug_mode) puts (PROGNAME"675 Found it!"); create_new_dbd (f); fclose (f); goto DBD_OKAY; } if (debug_mode) puts (PROGNAME"682 Never found it!"); print_usage(); printf (catgets (dtsearch_catd, MS_initausd, 213, default_unable_to_open_msg), "\n"PROGNAME"686", FNAME_MODEL, "Not found in either current or target directories. Use -d option\a"); DtSearchExit (4); DBD_OKAY: /* Open a new database */ *newextp = 0; /* use no extension when opening database */ if (debug_mode) printf ("040*** d_open newpath = '%s'.\n", newpath); d_open (newpath, "o"); if (db_status != S_OKAY) { printf (catgets (dtsearch_catd, MS_initausd, 230, PROGNAME "230 Could not open database '%s'.\n"), newpath); puts (vista_msg (PROGNAME "231")); DtSearchExit (3); } austext_exit_dbms = (void (*) (int)) d_close; /* emerg exit func */ /* initialize the 'dtsearch' database */ if (debug_mode) printf ("042*** d_initialize.\n"); d_initialize (0); if (db_status != S_OKAY) { printf (catgets (dtsearch_catd, MS_initausd, 239, PROGNAME "239 Could not initialize database '%s'.\n"), newpath); puts (vista_msg (PROGNAME "240")); DtSearchExit (3); } /* Create and initialize dbrec database header record in first slot. * First fill entire record with binary zeros. * Then set specific values as specified by flavor on command line. * For now most values are hard-coded. */ if (debug_mode) printf ("050*** create dbrec.\n"); memset (&dbrec, 0, sizeof (dbrec)); /* Init fields that are completely independent */ dbrec.or_language = (DtSrINT16) language; dbrec.or_maxwordsz = (DtSrINT16) maxwordsz; dbrec.or_minwordsz = (DtSrINT16) minwordsz; dbrec.or_fzkeysz = (DtSrINT16) fzkeysz; dbrec.or_abstrsz = (DtSrINT16) abstrsz; dbrec.or_dbflags = ORD_NONOTES | ORD_NOMARKDEL | ORD_XWORDS; strncpy (dbrec.or_version, SCHEMA_VERSION, sizeof(dbrec.or_version)); dbrec.or_version [sizeof(dbrec.or_version) - 1] = 0; /* Load dbrec's recslots fields based on correct number * of misc recs required to hold user's abstract. * Round abstrsz upward if there is any space left on last misc rec. */ dbrec.or_recslots = 1; /* start with obj rec itself */ for (i = dbrec.or_fzkeysz + dbrec.or_abstrsz; i > 0; i -= max_ormisc_size) dbrec.or_recslots++; if (i < 0) { /* Add in difference to INCREASE abstrsz */ dbrec.or_abstrsz -= i; printf (catgets (dtsearch_catd, MS_misc, 433, "%1$sAdjusted maximum abstract size upward to %2$hd.\n"), PROGNAME "433 ", dbrec.or_abstrsz); } /* Init fields that are dependent on language */ switch (language) { case DtSrLaENG: case DtSrLaENG2: dbrec.or_dbflags |= ORD_XSTEMS; break; default: break; } /* Init fields that are dependent on flavor */ if (flavor == AUSTEXT_FLAVOR) { dbrec.or_dbaccess = ORA_BLOB; dbrec.or_compflags = ORC_COMPBLOB; dbrec.or_hufid = -1L; /* -1 = use huffman compression, but * hufid not yet known. */ dbrec.or_dbotype = DtSrObjTEXT; } else { /* default flavor == DTSEARCH_FLAVOR */ dbrec.or_dbaccess = ORA_NOTAVAIL; } if (!quiet_mode) { /******putchar ('\n');******/ print_dbrec (newpath, &dbrec); fflush (stdout); } swab_dbrec (&dbrec, HTON); if (debug_mode) printf ("060*** fillnew dbrec.\n"); d_fillnew (OR_DBREC, &dbrec, 0); if (db_status != S_OKAY) { printf (catgets (dtsearch_catd, MS_initausd, 509, PROGNAME "509 Could not initialize database header record.\n")); puts (vista_msg (PROGNAME "510")); DtSearchExit (3); } /* Close the database */ d_close (); austext_exit_dbms = NULL; /* emerg exit no longer required */ /* Delete all nonvista (inverted index) database files (.d9x) */ remove_d9x_file (".d97"); remove_d9x_file (".d98"); remove_d9x_file (".d99"); *newextp = 0; /* no extension suffixes for next msgs */ printf (catgets (dtsearch_catd, MS_initausd, 24, PROGNAME " Successfully initialized database '%s'.\n"), newpath); return 0; } /* main() */