Пример #1
0
status_t site_status(site_t *site, file_t *file)
{
	static char buffer[1024];

	// Status of this file on this site
	if (!site || site->failed)
		return STATUS_FAIL;

	// Do we have the file?
	if (file_find(site->files, site->num_files, file->name)) {

        // is it nuked?
		if (site->nuketest) {
			snprintf(buffer, sizeof(buffer), site->nuketest,
					 file->name);
			if (file_find(site->files, site->num_files, buffer))
				return STATUS_NUKED;
        }

		// Is it incomplete?
		if (site->inctest) {
			snprintf(buffer, sizeof(buffer), site->inctest,
					 file->name);
			if (file_find(site->files, site->num_files, buffer))
				return STATUS_INC;
		}// intest

		// Its complete
		return STATUS_COMPLETE;
	}


	// Is it ignored by patterns?
	if (site_listsok(site, file))
		return STATUS_SKIP;


    // is it nuked?
    if (site->nuketest) {
        snprintf(buffer, sizeof(buffer), site->nuketest,
                 file->name);
        if (file_find(site->files, site->num_files, buffer))
            return STATUS_NUKED;
    }


	// It is missing.
	return STATUS_MISS;

}
Пример #2
0
FD_TYPE file_type(FDSC **curr,char *fixed)
{
    FDSC **this;

    if ((this = file_find(curr,fixed))) return (*this)->type;
    return fdt_none;
}
Пример #3
0
/* Remove a command from the file hash table. */
void
file_command_remove (struct command* command, int status)
{
  DBG("FILE REMOVE COMMAND: CMD %p  status %d\n", command, status);
  FILE_LOCK;
  struct redir *redirs = ct_extract_redirs (command->cmdtree);

  /* For each file. */
  while (redirs)
    {
      DBG("FILE REMOVE COMMAND: file: %s\n", redirs->file);

      /* Find the file being accessed. */
      struct file *file = *file_find (file_hash (redirs->file), redirs->file);
      if (!file)
        DBG("FILE REMOVE COMMAND: error: file not hashed\n");

      /* Remove command as an accessor to the file. */
      file_file_remove_accessor (file, command);

      redirs = redirs->next;
    }
  command->status = status;
  ct_free (command);

  FILE_UNLOCK;
}
Пример #4
0
/* Add a command's file accesses to the hash table. */
static void
file_command_add (struct command *new_command)
{
  FILE_LOCK;
  /* Check dependencies. */
  struct redir *redirs = ct_extract_redirs (new_command->cmdtree);

  /* For each file. */
  while (redirs)
    {
      DBG("FILE ADD COMMAND: file: %s\n", redirs->file);

      /* Find the file being accessed. If not yet hashed, hash it. */
      struct file *file = *file_find (file_hash (redirs->file), redirs->file);
      if (!file)
        file = *file_file_add (redirs->file);

      /* Add command as an accessor. */
      if (file_file_add_accessor (redirs, new_command, file))
        new_command->dependencies++;

      /* Also add file to command's file-accessed list. */
      file_command_list_add (file, &new_command->files);

      redirs = redirs->next;
    }

  DBG("FILE ADD COMMAND: dependencies: %d\n", new_command->dependencies);

  /* Add to frontier if no dependencies. */
  if (new_command->dependencies == 0)
    frontier_add (new_command);
  FILE_UNLOCK;
}
Пример #5
0
CELL *
bi_printf(CELL *sp)
{
    register int k;
    register CELL *p;
    FILE *fp;

    TRACE_FUNC("bi_printf", sp);

    k = sp->type;
    if (k < 0) {
    /* k has redirection */
    if ((--sp)->type < C_STRING)
        cast1_to_s(sp);
    fp = (FILE *) file_find(string(sp), k);
    free_STRING(string(sp));
    k = (--sp)->type;
    /* k is now number of args including format */
    } else
    fp = stdout;

    sp -= k;            /* sp points at the format string */
    k--;

    if (sp->type < C_STRING)
    cast1_to_s(sp);
    do_printf(fp, string(sp)->str, (unsigned) k, sp + 1);
    free_STRING(string(sp));

    /* cleanup arguments on eval stack */
    for (p = sp + 1; k; k--, p++)
    cell_destroy(p);
    return --sp;
}
Пример #6
0
static unsigned syscall_tell(int fd)
{
		struct file *f = file_find(fd);
		if( f== NULL)
				return -1;
		else
				return (unsigned) file_tell(f);
}
Пример #7
0
static int syscall_filesize(int fd)
{
		struct file *f = file_find(fd);
		if(f == NULL) 
				return -1;
		else
				return (int)file_length(f);
}
Пример #8
0
static void syscall_seek(int fd, unsigned position)
{
		struct file *f = file_find(fd);
		if (f == NULL) 
				return;
		file_seek(f, (off_t)position);

}
Пример #9
0
int
filesys_inumber (int fd)
{
    struct file *file = file_find (fd);
    if (file == NULL)
        return false;
    struct inode *inode = file_get_inode (file);
    return inode_get_inumber (inode);
}
Пример #10
0
Widget* Msg_Layer::addWidget(const char *fileName, int tag)
{
    if(file_find(fileName))
    {
        Widget* widget = GUIReader::getInstance()->widgetFromJsonFile(fileName);
        widget->setTag(tag);
        _widgetVector.push_back(widget);
        _widgetLayer->addChild(widget);
        return widget;
    }
    return NULL;
}
Пример #11
0
static int syscall_read(int fd, char* content, unsigned content_size){
	if(fd == STDIN_FILENO){//standard input stream
		unsigned i=0;
		for(;i<content_size;i++){
			content[i] = input_getc(); // Read command line by using input_getc();
		}
		return (int)i;
	}else{
		struct file* f = file_find(fd);
		if(f != NULL) return file_read(f, content, content_size);
		else return -1;
	}
}
Пример #12
0
int file_find_and_read(const char *filename, uint8_t **buf, size_t *size)
{
    int status;
    char *full_path = file_find(filename);
    *buf = NULL;
    *size = 0;

    if (full_path != NULL) {
        status = file_read_buffer(full_path, buf, size);
        free(full_path);
        return status;
    } else {
        return BLADERF_ERR_NO_FILE;
    }
}
Пример #13
0
bool filesys_readdir (int fd, char *name)
{
    struct file *file = file_find (fd);
    if (file == NULL)
        return false;
    struct inode *inode = file_get_inode (file);
    if (!inode_is_dir (inode))
        return false;
    struct dir *dir = dir_open (inode);
    dir_set_pos (dir, file_tell (file));
    bool success = dir_readdir (dir, name);
    file_seek (file, dir_get_pos (dir));
    dir_close (dir);
    return success;
}
Пример #14
0
CELL *
bi_print(
        CELL *sp)        /* stack ptr passed in */
{
    register CELL *p;
    register int k;
    FILE *fp;

    k = sp->type;
    if (k < 0) {
    /* k holds redirection */
    if ((--sp)->type < C_STRING)
        cast1_to_s(sp);
    fp = (FILE *) file_find(string(sp), k);
    free_STRING(string(sp));
    k = (--sp)->type;
    /* k now has number of arguments */
    } else
    fp = stdout;

    if (k) {
    p = sp - k;        /* clear k variables off the stack */
    sp = p - 1;
    k--;

    while (k > 0) {
        print_cell(p, fp);
        print_cell(OFS, fp);
        cell_destroy(p);
        p++;
        k--;
    }

    print_cell(p, fp);
    cell_destroy(p);
    } else {            /* print $0 */
    sp--;
    print_cell(&field[0], fp);
    }

    print_cell(ORS, fp);
    if (ferror(fp))
    write_error();
    return sp;
}
Пример #15
0
int main()
{

char cmdline[1024];
char *args[64];
char * pathArgs[64];
char fullcmd [100];
int i;

printf("%s","This is a Simple Shell \n");

	while(1)
	{
		i = 0;
		print_prompt();
//		printf("%s", "test 1");
		read_command(cmdline);
//		printf("%s", "test 2");
//		printf("After read_command %s \n", buf);
		

		parse_command(cmdline, args);
//		printf("%s", "test 3");
//		printf("After parse_command %s \n", buf);
//		printf("After parse_comamnd %s \n", args);
//		printf("More curiosity \n");
		file_find(pathArgs, cmdline, fullcmd);
		 // while (pathArgs[i] != NULL){
		 // 	strcat(pathArgs[i], "/");
		 //  	//printf("args [i] is: %s/ls\n", pathArgs[i]);
		 //  	i++;
		 // }
//		printf("After file_find %s \n", args);		
//		printf("%s", "test 4");		
//		printf("%s", *args);
		fork_and_exec(args, fullcmd);
		//printf("After fork %s", buf);	
		//printf("%s", "test 5 \n");	

	return 0;
}
}
Пример #16
0
void file_modify(FDSC **curr,char *fixed)
{
    FDSC **this,*next;

    if (!(this = file_find(curr,fixed)))
	die("Internal error: file_find failed");
    switch ((*this)->type) {
	case fdt_drop:
	    printf("Dropping %s\n",file_name(fixed));
	    *(unsigned char *) fixed = DELETED_FLAG;
	    break;
	case fdt_undelete:
	    *fixed = *(*this)->name;
	    printf("Undeleting %s\n",file_name(fixed));
	    break;
	default:
	    die("Internal error: file_modify");
    }
    next = (*this)->next;
    free(*this);
    *this = next;
}
Пример #17
0
/*
**++
**  ROUTINE:	lbr_get_rdt
**
**  FUNCTIONAL DESCRIPTION:
**
**  	Gets the RDT of a library module.
**
**  RETURNS:	cond_value, longword (unsigned), write only, by value
**
**  PROTOTYPE:
**
**  	lbr_get_rdt(char *libfile, char *module, TIME *rdt);
**
**  libfile:	ASCIZ_string, read only, by reference
**  module: 	ASCIZ_string, read only, by reference
**  rdt:    	date_time, quadword (signed), write only, by reference
**
**  IMPLICIT INPUTS:	None.
**
**  IMPLICIT OUTPUTS:	None.
**
**  COMPLETION CODES:	Any from the LBR$ routines.
**
**  SIDE EFFECTS:   	lbrque modified.
**
**--
*/
unsigned int lbr_get_rdt (char *lib, char *mod, TIME *rdt) {

    unsigned int lbrfunc=LBR$C_READ, lbr$c_knf = 0x08680F2, libidx = 1;
    char real_name[256];
    unsigned char fid[28];
    struct dsc$descriptor libdsc, moddsc;
    struct LBR *lbr;
    unsigned int status, len;
    unsigned short rfa[3];
    struct mhddef mhd;

/*
** First look up the library file
*/
    status = file_find(lib, 0, real_name, fid);
    if (!OK(status)) return status;

/*
** Already open?
*/
    for (lbr = (struct LBR *)lbrque.head; lbr != (struct LBR *)&lbrque;
    	    	    lbr = lbr->flink) {
    	if (memcmp(fid, &lbr->nam.nam$t_dvi, 28) == 0) break;
    }

/*
** If not open yet, construct a context block and open it.
*/
    if (lbr == (struct LBR *) &lbrque) {
/*
**  Already have max number of libraries open?  If so, close one.
*/
    	if (lbrcount >= LBR$C_MAXCTL) {
    	    queue_remove(lbrque.head, &lbr);
    	    lbr$close(&lbr->lbrctx);
    	    lbrcount -= 1;
    	} else {
    	    lbr = malloc(sizeof(struct LBR));
    	}
    	queue_insert(lbr, lbrque.tail);
    	lbr->lbrctx = 0;
    	lbr->nam = cc$rms_nam;
    	lbr->nam.nam$b_rss = sizeof(lbr->rspec)-1;
    	lbr->nam.nam$b_ess = sizeof(lbr->espec)-1;
    	lbr->nam.nam$l_esa = lbr->espec;
    	lbr->nam.nam$l_rsa = lbr->rspec;
    	status = lbr$ini_control(&lbr->lbrctx, &lbrfunc, 0, &lbr->nam);
    	if (!OK(status)) lib$signal(status);
    	INIT_SDESC(libdsc, strlen(real_name), real_name);
    	status = lbr$open(&lbr->lbrctx, &libdsc);
    	if (!OK(status)) return status;
    	lbrcount += 1;
    }

/*
** Look up the module in question...
*/
    INIT_SDESC(moddsc, strlen(mod), mod);
/*    status = lbr$lookup_key(&lbr->lbrctx, &moddsc, rfa); */
    mod2search4 = &moddsc;
    return_rfa_here = rfa;
    status = lbr$get_index(&lbr->lbrctx, &libidx, &caseblindsearch);
    if (status != 2) return lbr$c_knf;		/* caseblindsearch returns 2 on success, 1 on failure */

/*
**  ... and get the RDT from the module header
*/
    INIT_SDESC(moddsc, sizeof(mhd), &mhd);
    status = lbr$set_module(&lbr->lbrctx, rfa, &moddsc, &len);
    if (!OK(status) && (status != LBR$_HDRTRUNC)) lib$signal(status);
    memcpy(rdt, &mhd.mhd$l_datim, 8);
    return SS$_NORMAL;

}
Пример #18
0
/* Insert a command into file hash table. For each file the command accesses,
   the command will be inserted after the currently runnable commands, but
   before every other command.
   Note that if the currently runnable commands have read access, and the
   inserted command also has read access, the inserted command will become
   runnable. */
static void
file_command_insert (struct command *command)
{
  FILE_LOCK;
  struct redir *redirs = ct_extract_redirs (command->cmdtree);
  bool blocked = false;

  /* For each file. */
  while (redirs)
    {
      DBG("FILE INSERT COMMAND: file: %s\n", redirs->file);

      /* Find the file to be accessed. */
      struct file *file = *file_find (file_hash (redirs->file), redirs->file);
      if (!file)
        DBG("FILE INSERT COMMAND: error: file not hashed\n");

      /* Command is blocked if file's current running command is a write, or
         the command we're inserting is a write (the converse is they're all
         reads, meaning they can run simultaneously. */
      if (file->accessors &&
          (file->accessors->access == WRITE_ACCESS ||
           redirs->type == FILE_OUT || redirs->type == FILE_CLOBBER ||
           redirs->type == FILE_APPEND))
        blocked = true;

      if (!file->accessors ||
          (redirs->type == FILE_IN && file->accessors->access == READ_ACCESS))
        frontier_add (command);

      /* Skip through runnable commands.
         1. Read access: iterate until end.
         2. Write access: insert after first accessor.
         3. No accessor: just set as accessor. */
      struct file_acc *acc = file->accessors;
      struct file_acc **accp = &file->accessors;
      while (acc)
        {
          /* Iterate through accessors until write access is found. */
          accp = &acc->next;
          if (acc->access != READ_ACCESS)
            {
              /* If writer is first accessor, skip over it. Otherwise,
                 insert before it. */
              if (acc == file->accessors)
                acc = acc->next;
              break;
            }
          acc = acc->next;
        }

      /* Create accessor for command and insert into accessor list. */
      struct file_acc *new_acc = malloc (sizeof *new_acc);
      if (redirs->type == FILE_IN)
        new_acc->access = READ_ACCESS;
      else if (redirs->type == FILE_OUT && redirs->type == FILE_CLOBBER
               && redirs->type == FILE_APPEND)
        new_acc->access = WRITE_ACCESS;
      new_acc->cmd = command;
      new_acc->next = acc;
      *accp = new_acc;

      redirs = redirs->next;
    }

  /* If the command is not blocked, put into frontier. */
  if (!blocked)
    frontier_add (command);

  FILE_UNLOCK;
}
Пример #19
0
int main( int argc, char** argv ) 
{
  int mark_period;
  FILE* output;
  char* info_path = "/tmp/info";
  FILE* aux;
  int chunk_size = 4096; //2048;//1024;
  const char* path;
  error_t err;

  if( argc < 4 ) {
    printf("Usage: %s <mark_period> <file_to_index> <output_file> <document_info_output> <chunk_size> <document_map_output>\n", argv[0]);
    printf(" <mark_period> -- set the marking period. This program will marks every character with offset %% mark_period = 0. Marked characters store full offset information; locating is faster for smaller mark_periods, but the index will be larger. If <mark_period> is 0, no characters are marked. 20 is a reasonable value here.\n");
    printf(" <file_to_index> -- a file or directory containing the document(s) to be indexed; if it is a directory, every file in that directory will be indexed.\n");
    printf(" <output_file> -- where to store the Burrows-Wheeler Transform of the prepared text\n");
    printf(" <document_info_output> -- where to store a file containing document information (e.g. the URL of each document)\n");
    printf(" <chunk_size> -- the number of rows in the Burrows-Wheeler transform to group together and save a list of matching documents. Larger chunks mean that queries for very common terms will report faster and the index will be smaller. Smaller chunks allow the chunks to be used for less common terms. 4096 is a reasonable value here.\n");
    printf(" <document_map_output> -- where to store the list of matching documents for each <chunk_size> group of rows\n");
    exit(-1);
  }

  {
    int i = 1;
    char* name;
    sscanf(argv[i++], "%i", &mark_period);
    path = argv[i++];
    printf("Will save bwt for %s marking %i\n", path, mark_period);
    name = argv[i++];
    printf("Saving bwt to %s\n", name);
    output = fopen(name, "w+");
    if( ! output ) {
      printf("Could not open output file %s\n", name);
      die_if_err(ERR_IO_UNK);
    }
    name = argv[i++];
    printf("Saving document infos to %s\n", name);
    info_path = name;
    if( argc >= 6 ) {
      if( argc < 7 ) {
        printf("Missing <chunk_size> <doc_output_file>\n");
        exit(-1);
      }
      sscanf(argv[i++], "%i", &chunk_size);
      name = argv[i++];
      printf("Saving document map to %s chunking %i\n", name, chunk_size);
      aux = fopen(name, "w+");
      if( ! aux ) {
        printf("Could not open aux. output file %s\n", name);
        die_if_err(ERR_IO_UNK);
      }
    } else aux = NULL;
  }

  start_clock();
  // step 1: prepare the text.
  // initialize the structure
  printf("Reading and preparing text\n"); 
  start_clock();
  err = init_prepared_text(&bwt_globals.p, info_path);
  die_if_err(err);
  
  // read in any documents
  err = init_file_find(&bwt_globals.ffs, 1, &path);
  die_if_err(err);
  err = file_find(&bwt_globals.ffs, size_file, &bwt_globals);
  die_if_err(err);
  free_file_find(&bwt_globals.ffs);

  // For each file... 
  err = init_file_find(&bwt_globals.ffs, 1, &path);
  die_if_err(err);
  err = file_find(&bwt_globals.ffs, read_file, &bwt_globals);
  die_if_err(err);
  free_file_find(&bwt_globals.ffs);


  stop_clock();

  {
    int64_t num_chars, num_docs; 
    err = prepared_num_docs( &bwt_globals.p, &num_docs);
    die_if_err(err);
    err = prepared_num_chars( &bwt_globals.p, &num_chars);
    die_if_err(err);


    printf("Read %"PRIi64 " chars %" PRIi64 " documents \n",
           num_chars, num_docs);

    print_timings("preparing bytes", num_chars );
  }


  printf("Creating output\n");
  err = save_prepared_bwt(&bwt_globals.p, mark_period,
                          output, chunk_size, aux, 1);
  die_if_err(err);
  
  free_prepared_text(&bwt_globals.p);

  return 0;
}
Пример #20
0
/*ARGSUSED*/
static void
pkg_door_srv(void *cookie, char *argp, size_t asz, door_desc_t *dp,
    uint_t ndesc)
{
	char *p = NULL;
	pkgcmd_t *pcmd = (pkgcmd_t *)argp;
	ucred_t *uc = NULL;
	uid_t caller;
	pid_t pcaller;
	door_desc_t ddp;
	int dnum = 0;
	int one = 1;
	int len = -1;

	if (asz < sizeof (pkgcmd_t)) {
		(void) door_return(NULL, 0, NULL, 0);
		return;
	}

	if (door_ucred(&uc) != 0) {
		(void) door_return(NULL, 0, NULL, 0);
		return;
	}

	caller = ucred_geteuid(uc);
	pcaller = ucred_getpid(uc);
	ucred_free(uc);

	if (caller != myuid) {
		(void) door_return(NULL, 0, NULL, 0);
		return;
	}

	(void) mutex_lock(&mtx);
	ncalls++;

	if (pcaller != client_pid && pcaller != -1 &&
	    (client_pid == 1 || kill(client_pid, 0) != 0)) {
		client_pid = pcaller;
	}

	if (PKG_WRITE_COMMAND(pcmd->cmd))
		while (write_locked > 0)
			(void) cond_wait(&cv, &mtx);

	switch (pcmd->cmd) {
	case PKG_FINDFILE:
		p = file_find((pkgfilter_t *)argp, &len);
		break;
	case PKG_DUMP:
		if (read_only)
			goto err;
		if (logcount > 0)
			pkgdump();
		break;
	case PKG_EXIT:
		if (logcount > 0)
			pkgdump();
		exit(0);
		/*NOTREACHED*/
	case PKG_PKGSYNC:
		if (read_only || logflush() != 0)
			goto err;
		break;
	case PKG_FILTER:
		if (pkgfilter((pkgfilter_t *)argp, &ddp) == 0)
			dnum = 1;
		break;
	case PKG_ADDLINES:
		if (read_only)
			goto err;
		changes++;

		if (pkgaddlines((pkgfilter_t *)argp) != 0)
			goto err;
		/* If we've updated the database, tell the dump thread */
		lastchange = gethrtime();
		(void) cond_broadcast(&cv);
		break;
	case PKG_NOP:
		/* Do nothing but register the current client's pid. */
		break;
	default:
		goto err;
	}

	lastcall = gethrtime();
	(void) mutex_unlock(&mtx);
	(void) door_return(p, len != -1 ? len : p == NULL ? 0 : strlen(p) + 1,
	    dnum == 0 ? NULL : &ddp, dnum);
	return;

err:
	(void) mutex_unlock(&mtx);
	(void) door_return((void *)&one, 4, NULL, NULL);
}
Пример #21
0
void sites_compare(void)
{
	int i,j;
	site_t *site;
	file_t *file, **tmp;

	// Sort it
	for (i = 0; i < num_sites; i++) {

		site = sites[i];

		printf("Sorting '%s'...\n", site->name);

		qsort(site->files, site->num_files, sizeof(file_t *), sort_by_date);

	}


	// Build new list.
	for (i = 0; i < num_sites; i++) {

		site = sites[i];

		for (j = 0; j < site->num_files; j++) {

			// Is it newer than last time we checked? OR
			// Is it part of incpattern?
			if ((conf_incpattern &&
				 file_listmatch(conf_incpattern, site->files[j]->name)) ||
				(site->files[j]->date > site->last_check)) {

				if (site->use_lists && site_listsok(site, site->files[j]))
					continue;

				// If file already in the new list?
				if (file_find(new_files, num_new, site->files[j]->name))
					continue;

				file = file_dupe(site->files[j]);
				if (!file) continue;

				tmp = realloc(new_files,
							  sizeof(file_t *)*(num_new + 1));
				if (!tmp) {
					file_free(file);
					return;
				}

				new_files = tmp;

				new_files[ num_new ] = file;
				num_new++;

				continue;

			}

			// Older, since its sorted, stop. Unless
			// we are searching for something
			if (!conf_incpattern)
				break;

		} // all files

	} // all sites.

	printf("Sorting new list...%u\n", num_new);

	qsort(new_files, num_new, sizeof(file_t *), sort_by_date);



	printf("\n\n-----======> DISPLAY MATRIX <======-----\n\n");


	printf("T |");
	for(i = 0; i < num_sites; i++)
		printf("%-5.5s|", sites[i] ? sites[i]->name : "fail1");
	printf(" New Items");
	printf("\n");
	printf("--+");
	for(i = 0; i < num_sites; i++)
		printf("-----+");
	printf("-----------");
	printf("\n");

	for (j = 0; j < num_new; j++) {

        printf("%c |", new_files[j]->type ? 'd' : 'f');

        for(i = 0; i < num_sites; i++)
            printf("%-5.5s|",
                   status2str( site_status(sites[i], new_files[j]) ));

        printf(" %s", new_files[j]->name);

        printf("\n");

	}

	printf("\n\n");

}