/* Find the location for a binary image and return size. */ int data_find_binary(const char *path, const char *filename, OSSpec *spec) { OSRef ref; OSSize size; OSError err; if (!filename) return 0; #if 0 if (OS_GetFileNamePtr(filename) != filename && (err = OS_MakeFileSpec(filename, spec)) == OS_NOERR && OS_Status(spec) == OS_NOERR) { // found it } else if ((err = OS_FindFileInPath(filename, path, spec)) != OS_NOERR && (err = OS_FindFileInPath(filename, syspath, spec)) != OS_NOERR) { return 0; } #endif if (!data_find_file(path, filename, spec)) return 0; if ((err = OS_Open(spec, OSReadOnly, &ref)) != OS_NOERR) { OSerror(err, "\n"); return 0; } OS_GetSize(ref, &size); OS_Close(ref); return size; }
static void PIOCloseFile() { if (pio.handle) { OS_Close(pio.handle); pio.handle = 0; } }
/* Load a binary image, return # bytes read. */ int data_load_binary(const char *type, const char *path, const char *filename, u8 * loadat, int swap, int fileoffs, int imagesize, int maxsize) { OSRef ref; OSSize size; OSError err; OSSpec spec; size = data_find_binary(path, filename, &spec); if (!size) { if (*filename) { command_logger(_L |LOG_USER|LOG_ERROR, _("Cannot find '%s' in path:\n'%s'\n"), filename, path); } return 0; } logger(_L|L_0, _("Loading %s image %s... "), type, OS_SpecToString1(&spec)); if (imagesize) size = imagesize; else if (size - fileoffs > maxsize) { command_logger(_L | LOG_WARN | LOG_USER, _("%s too long, only %d bytes of %d read... "), OS_SpecToString1(&spec), maxsize, size); size = maxsize - fileoffs; } if ((err = OS_Open(&spec, OSReadOnly, &ref)) != OS_NOERR) { OSerror(err, "\n"); return 0; } if ((err = OS_Seek(ref, OSSeekAbs, fileoffs)) != OS_NOERR || (err = OS_Read(ref, loadat, &size)) != OS_NOERR) { OSerror(err, _("could not read\n")); return 0; } if (swap) { logger(_L, _("swapping bytes... ")); swab((const void *) loadat, (void *) loadat, size); } logger(_L| L_0, _("done\n")); OS_Close(ref); return size; }
/* *---------------------------------------------------------------------- * * OS_IpcClose * * OS IPC routine to close an IPC connection. * * Results: * * * Side effects: * IPC connection is closed. * *---------------------------------------------------------------------- */ int OS_IpcClose(int ipcFd, int shutdown) { if (ipcFd == -1) return 0; /* * Catch it if fd is a bogus value */ ASSERT((ipcFd >= 0) && (ipcFd < WIN32_OPEN_MAX)); ASSERT(fdTable[ipcFd].type != FD_UNUSED); switch (listenType) { case FD_PIPE_SYNC: /* * Make sure that the client (ie. a Web Server in this case) has * read all data from the pipe before we disconnect. */ if (! FlushFileBuffers(fdTable[ipcFd].fid.fileHandle)) return -1; if (! DisconnectNamedPipe(fdTable[ipcFd].fid.fileHandle)) return -1; /* fall through */ case FD_SOCKET_SYNC: OS_Close(ipcFd, shutdown); break; case FD_UNUSED: default: exit(106); break; } return 0; }
static void FCGI_Start(char *bindPath, char *appPath, int nServers) { int listenFd, i; /* @@@ Should be able to pick up the backlog as an arg */ if((listenFd = OS_CreateLocalIpcFd(bindPath, 5)) == -1) { exit(OS_Errno); } if(access(appPath, X_OK) == -1) { fprintf(stderr, "%s is not executable\n", appPath); exit(1); } /* * Create the server processes */ for(i = 0; i < nServers; i++) { if(OS_SpawnChild(appPath, listenFd) == -1) { exit(OS_Errno); } } OS_Close(listenFd); }
/* * Search paths for a file matching 'filename'. * If found, and it is a valid GRAM-Kracker file, * set 'spec' to point to it, and return its header info in 'header' * */ int data_find_gram_kracker(const char *path, const char *filename, OSSpec *spec, gram_kracker_header *header) { int size; fiad_logger_func old; int old_unknownfileistext; fiad_tifile tf; OSError err; OSRef ref; bool is_v9t9_file; memset(header, 0, sizeof(gram_kracker_header)); /* Can we find the file? */ size = data_find_binary(path, filename, spec); if (!size) return 0; /* See if it's a V9t9/TIFILES file or perhaps a plain binary */ old = fiad_set_logger(0L); old_unknownfileistext = unknownfileistext; unknownfileistext = 0; if (fiad_tifile_setup_spec_with_spec(&tf, spec) != OS_NOERR) { goto error_exit; } /* Is it a V9t9 file? */ if (fiad_tifile_get_info(&tf)) { if (!(tf.fdr.flags & ff_program)) { command_logger(_L|LOG_ERROR|LOG_USER, _("GRAM Kracker segment '%s' is not a PROGRAM file (it's %s)\n"), OS_SpecToString1(spec), fiad_catalog_get_file_type_string(&tf.fdr)); goto error_exit; } // allow enough space for the data, header, and extra sector if (FDR_FILESIZE(&tf.fdr) > 8198+256) { command_logger(_L|LOG_ERROR|LOG_USER, _("GRAM Kracker segment '%s' is too long\n" "to be a segment (%d bytes > 8192+6 bytes)\n"), OS_SpecToString1(spec), FDR_FILESIZE(&tf.fdr)); goto error_exit; } is_v9t9_file = true; } else { is_v9t9_file = false; } /* Read header from first sector */ if (is_v9t9_file) { u16 headersize = 6; if (fiad_tifile_open_file(&tf, newfileformat, false /*create*/, false /*always*/, true /*readonly*/) != OS_NOERR || fiad_tifile_read_binary_image(&tf, (u8 *)header, headersize, &headersize) != 0 || headersize < 6) { command_logger(_L|LOG_ERROR|LOG_USER, _("Could not read signature for GRAM Kracker segment in V9t9 file '%s' (%s)\n"), OS_SpecToString1(spec), OS_GetErrText(tf.error)); goto error_exit; } header->absolute_image_file_offset = sizeof(v9t9_fdr) + 6; } else { OSSize headersize = 6; if ((err = OS_Open(spec, OSReadOnly, &ref)) != OS_NOERR || (err = OS_Read(ref, (void *)header, &headersize)) != OS_NOERR || (err = OS_Close(ref)) != OS_NOERR) { command_logger(_L|LOG_ERROR|LOG_USER, _("Could not read signature for GRAM Kracker segment in binary file '%s' (%s)\n"), OS_SpecToString1(spec), OS_GetErrText(err)); goto error_exit; } header->absolute_image_file_offset = 6; } /* Make header suitable for v9t9 */ header->address = TI2HOST(header->address); header->length = TI2HOST(header->length); if (header->more_to_load == 0x80) { command_logger(_L|LOG_ERROR|LOG_USER, _("GRAM Kracker segment '%s' is a 'UTIL' segment (not supported)\n"), OS_SpecToString1(spec)); goto error_exit; } if (header->gk_type == 0x00 || header->gk_type == 0xff || header->gk_type > GK_TYPE_ROM_2) { command_logger(_L|LOG_ERROR|LOG_USER, _("GRAM Kracker segment '%s' is not a ROM file (got >%02X)\n"), OS_SpecToString1(spec), header->gk_type); goto error_exit; } fiad_set_logger(old); return size; error_exit: fiad_set_logger(old); unknownfileistext = old_unknownfileistext; return 0; }
/* * Save data to an image found somewhere in 'path' * (if not existing, placed in first writeable entry of 'path'). * Existing file is not overwritten. * * path: search * type: string emitted in error, i.e., "RAM image" * filename: name of image * fileoffs: offset into file to write * saveat: start of memory to write * swap: if true, byteswap word data to TI format * memsize: size of memory to write */ int data_save_binary(const char *type, const char *path, const char *filename, int fileoffs, u8 * saveat, int swap, int memsize) { OSRef ref; OSSize size; OSError err; OSSpec spec; #if 0 if ((size = data_find_binary(path, syspath, filename, &spec)) == 0) { if ((err = OS_CreateFileInPath(filename, *path ? path : syspath, &spec, &osBinaryType)) != OS_NOERR) { OSerror(err, _("Couldn't create %s image %s anywhere in path: %s\n"), type, filename, path); return 0; } } #endif if ((size = data_find_binary(path, filename, &spec)) == 0) { if (!data_create_file(path, filename, &spec, &osBinaryType)) { logger(_L|LOG_USER|LOG_ERROR, _("Couldn't create %s image '%s' anywhere in path:\n'%s'\n"), type, filename, path); return 0; } size = memsize; } logger(_L |L_0, _("Writing %s image %s... "), type, OS_SpecToString1(&spec)); if ((err = OS_Open(&spec, OSReadWrite, &ref)) != OS_NOERR) { OSerror(err, "\n"); return 0; } //saveat += offset; if (swap) { logger(_L, _("swapping bytes to save... ")); swab((const void *) saveat, (void *) saveat, size); } err = OS_Seek(ref, OSSeekAbs, fileoffs); size = memsize; err = OS_Write(ref, saveat, &size); if (swap) { logger(_L, _("swapping bytes back... ")); swab((const void *) saveat, (void *) saveat, size); } if (err != OS_NOERR) { OSerror(err, _("could not write\n")); return 0; } logger(_L|L_0, _("done\n")); OS_Close(ref); return size; }
/* *---------------------------------------------------------------------- * * OS_IpcClose * * OS IPC routine to close an IPC connection. * * Results: * * * Side effects: * IPC connection is closed. * *---------------------------------------------------------------------- */ int OS_IpcClose(int ipcFd) { return OS_Close(ipcFd); }
/* *---------------------------------------------------------------------- * * OS_IpcClose * * OS IPC routine to close an IPC connection. * * Results: * * * Side effects: * IPC connection is closed. * *---------------------------------------------------------------------- */ int OS_IpcClose(int ipcFd, int shutdown) { return OS_Close(ipcFd, shutdown); }