Ejemplo n.º 1
0
Archivo: bin.c Proyecto: bitursa/maos
/*
  Process the input file name and return file names that can be open to
  read/write. If the file name does not end with .bin or .bin.gz it will add to
  the end .bin or .bin.gz depending on the value of defaultgzip. For read only
  access, it will also look into the path for files.
*/
static char* procfn(const char *fn, const char *mod, const int defaultgzip) {
    char *fn2;
    if(fn[0]=='~') {
        fn2=malloc(strlen(HOME)+strlen(fn)+16);
        strcpy(fn2,HOME);
        strcat(fn2,fn+1);
    } else {
        fn2=malloc(strlen(fn)+16);
        strcpy(fn2,fn);
    }
    /*If there is no recognized suffix, add .bin in the end. */
    if(!check_suffix(fn2,".bin")  && !check_suffix(fn2, ".bin.gz")
            && !check_suffix(fn2,".fits") && !check_suffix(fn2, ".fits.gz")) {
        strncat(fn2, ".bin", 4);
    }
    if(mod[0]=='r') {
        char *fnr=NULL;
        if(!(fnr=search_file(fn2))) { /*If does not exist. */
            if(!check_suffix(fn2, ".gz")) {
                /*does not end with .gz, add gz*/
                strncat(fn2, ".gz", 3);
            } else if (check_suffix(fn, ".gz")) {
                /*ended with gz, remove .gz*/
                fn2[strlen(fn2)-3]='\0';
            }
            fnr=search_file(fn2);
        }
        free(fn2);
        fn2=fnr;
        if(!fnr) {

        }
    } else if (mod[0]=='w' || mod[0]=='a') {
        if(disable_save) { //When saving is disabled, allow writing to cache folder.
            char fncache[PATH_MAX];
            snprintf(fncache, PATH_MAX, "%s/.aos/cache", HOME);
            if(mystrcmp(fn2, fncache)) {
                warning("Saving is disabled for %s.\n", fn2);
                free(fn2);
                fn2=0;
            }
        }
        if(fn2 && islink(fn2)) { /*remove old file to avoid write over a symbolic link. */
            if(remove(fn2)) {
                error("Failed to remove %s\n", fn2);
            }
        }
    } else {
        error("Invalid mode\n");
    }
    return fn2;
}
Ejemplo n.º 2
0
int cell_read(char *file, char *buf){
	int cellid = search_file(file);
	if(cellid == -1) return 0;	
	char *src = cellmbr + (cellid*CELL_SECTORS + 1) * 512;
	memcpy(buf, src, 1024);
	return 0;
}
Ejemplo n.º 3
0
static int simple_mknod(const char *path, mode_t mode, dev_t device)
{
  struct directory_entry *p;

  if (search_file(path)) {
    return -EEXIST;
  }
  p = malloc(sizeof(struct directory_entry));
  if (p == NULL) {
    return -ENOSPC;
  }
  p->file = calloc(sizeof(struct file_metadata), 1);
  if (p->file == NULL) {
    return -ENOSPC;
  }
  p->file->mode = mode;
  p->file->nlink = 1;
  p->file->length = 0;
  p->file->capacity = INITIAL_SIZE;
  p->file->data = calloc(INITIAL_SIZE, 1);

  p->name = strdup(path + 1);
  if (p->name == NULL) {
    return -ENOSPC;
  }

  p->next = root;
  root = p;

  return 0;
}
Ejemplo n.º 4
0
API struct ly_module *
ly_ctx_get_module(struct ly_ctx *ctx, const char *name, const char *revision, int read)
{
    int i;
    struct ly_module *result = NULL;

    if (!ctx || !name) {
        ly_errno = LY_EINVAL;
        return NULL;
    }

    for (i = 0; i < ctx->models.used; i++) {
        result = ctx->models.list[i];
        if (!result || strcmp(name, result->name)) {
            continue;
        }

        if (!revision || (result->rev_size && !strcmp(revision, result->rev[0].date))) {
            return result;
        }
    }

    if (!read) {
        return NULL;
    }

    /* not found in context, try to get it from the search directory */
    result = search_file(ctx, NULL, name, revision);
    if (!result) {
        LOGERR(LY_EVALID, "Data model \"%s\" not found (search path is \"%s\")", name, ctx->models.search_path);
    }

    return result;
}
Ejemplo n.º 5
0
int resolve_file(types_t **head)
{
    types_t *next_type;

    if (!head) {
        g_warning("Empty list detected");
        return RESOLV_LIST_EMPTY;
    }

    for (next_type = *head; next_type; next_type = next_type->next)
    {
        /* Only resolve typedef */
        if (next_type->type == TYPE_FILE)
            continue;

        /* No reference to a file */
        if (next_type->file == NULL) {
            continue;
        }

        g_debug("Trying to resolve file %s\n", next_type->file);

        if (search_file(*head, &next_type->file_ref, atoi(&next_type->file[1])) != RESOLV_OK) {
            /* We have to remove this reference */
        }
//         next_type->type_hr_display(next_type, 0);
    }

    return 0;
}
Ejemplo n.º 6
0
static BOOL do_create(MESSAGE *message){
    const char *path;
    char dirname[MAX_FILENAME_LENGTH]={0};
    char filename[MAX_FILENAME_LENGTH]={0};
    int flags,inode_index;

    path=message->arg_pointer;
    flags=message->flags;

    //分离父目录路径和文件名
    if(!strip_path(path,dirname,filename)){
        return FALSE;
    }

    inode_index=search_file(dirname,filename,GET_FILE_TYPE(flags));
    if(inode_index<0){
        inode_index=create_file(dirname,filename,GET_FILE_TYPE(flags));
        if(inode_index<0){
            return FALSE;
        }
    }
    else{
        set_error_index(FILE_EXIST);
        return FALSE;
    }
    return TRUE;
}
Ejemplo n.º 7
0
int main(int argc, char *argv[])
{
      DOSFileData       ffblk;                        /* File control block */
      int                     done;                   /* Done flag */

      /*--------------------------------*/

      fprintf(stderr, "\n%Fs v. %Fs : %s\n", PROGNAME, PROGVER,
              stModulInfo.pszCopyright);
      fprintf(stdout, "Argument: %s\n", argv[1]);

      if ('?' == argv[1][1])
      {
            fprintf(stderr, HELPFORMAT, argv[0]);
            exit();
      }
      strcpy(szInputFile, argv[1]);

      done = FIND_FIRST(szInputFile, 0, &ffblk);

      /* Find first file */

      while (!done)
      {
            search_file(ff_name(&ffblk));  /* Search file for tokens */
            done = FIND_NEXT(&ffblk);      /* Find next matching file */
      }

      return(0);
}
Ejemplo n.º 8
0
int search_file(char* path,char* filename)
{
	DIR *dir;
	struct dirent *ent;
	int err=0;

	if((dir = opendir (path)) == NULL)
	{
	    liblist_perror();
		return 0;
	}

	while ((ent = readdir (dir)) != NULL)
	{
		if (0 == strcmp(".",ent->d_name) || 0 == strcmp("..",ent->d_name))
			continue;

		if (0 != strstr(ent->d_name,filename))
		{
			printf("Where : %s/%s\n",path,ent->d_name);
			err++;
		}

		if (MODE_DIRT == ent->d_type)
		{
            char* new_path = list_dump_append(path, ent->d_name);
            err+=search_file(new_path,filename);
            free(new_path);
		}
	}
	closedir(dir);
	return err;
}
Ejemplo n.º 9
0
/* Open the source file for reading, closing any previously open file.
   If dir_list is not NULL, calls search_file() to search the file in dir_list */
Bool SrcFile_open( SrcFile *self, char *filename, UT_array *dir_list )
{
    char *filename_path;
	
	/* close last file */
	if (self->file != NULL)
	{
		myfclose(self->file);
		self->file = NULL;
	}

	/* search path, add to strpool */
	filename_path = search_file(filename, dir_list);

	/* check for recursive includes, return if found */
	if (!check_recursive_include(self, filename_path))
		return FALSE;
	
	self->filename = filename_path;

    /* open new file in binary mode, for cross-platform newline processing */
    self->file = myfopen( self->filename, "rb" );

	/* init current line */
    str_clear( self->line );
    self->line_nr = 0;

	if (self->file)
		return TRUE;
	else
		return FALSE;		/* error opening file */
}
Ejemplo n.º 10
0
/**
 * Entfernt eine Datei
 * \param *filename	Dateiname
 * \param *buffer	Puffer fuer mindestens BOTFS_BLOCK_SIZE Byte
 * \return			0, falls kein Fehler
 */
int8_t botfs_unlink(const char * filename, void * buffer) {
	botfs_acquire_lock_low(&botfs_mutex);
	/* Datei suchen */
	botfs_file_t * ptr = search_file(filename, buffer);
	if (ptr == NULL) {
		botfs_release_lock_low(&botfs_mutex);
		PRINT_MSG("botfs_unlink(): Datei nicht vorhanden");
		return -1;
	}

	/* Root-Dir Eintrag loeschen */
	ptr->name[0] = 0;
	ptr->name[1] = 0;
	botfs_seek(&botfs_vol_data.rootdir, -1, SEEK_CUR); // Dateizeiger stand auf naechstem Dir-Block => -1
	if (botfs_write(&botfs_vol_data.rootdir, buffer) != 0) {
		botfs_release_lock_low(&botfs_mutex);
		PRINT_MSG("botfs_unlink(): Fehler beim Schreiben des Root-Blocks");
		return -2;
	}
	const uint16_t start = ptr->descr.start;
	const uint16_t end = ptr->descr.end;

	/* Freelist aktualisieren */
	int8_t res = add_to_freelist(start, end, buffer);

	botfs_release_lock_low(&botfs_mutex);

	PRINT_MSG("botfs_unlink(): Datei \"%s\" wurde geloescht", filename);
	return res;
}
Ejemplo n.º 11
0
/**
 * Oeffnet eine Datei
 * \param filename	Dateiname
 * \param *file		Zeiger auf Datei-Deskriptor
 * \param mode		Modus, in dem die Datei geoeffnet wird
 * \param *buffer	Puffer fuer mindestens BOTFS_BLOCK_SIZE Byte
 * \return			0, falls kein Fehler
 */
int8_t botfs_open(const char * filename, botfs_file_descr_t * file, uint8_t mode, void * buffer) {
	botfs_acquire_lock_low(&botfs_mutex);
	/* Datei suchen */
	botfs_file_t * ptr = search_file(filename, buffer);
	if (ptr == NULL) {
		botfs_release_lock_low(&botfs_mutex);
		PRINT_MSG("botfs_open(): file not found");
		return -1;
	}

	/* Datei-Deskriptor laden und updaten */
	*file = ptr->descr;
	file->mode = mode;
	file->pos = file->start + BOTFS_HEADER_SIZE;

	/* Datei-Header laden */
	if (botfs_read_low(file->start, buffer) != 0) {
		botfs_release_lock_low(&botfs_mutex);
		PRINT_MSG("botfs_open(): read_low()-error");
		return -2;
	}

	/* benutzte Bloecke lt. Header in den Datei-Deskriptor uebernehmen */
	botfs_file_header_t * ptr_head = buffer;
	file->used = ptr_head->used_blocks;
//	PRINT_MSG("botfs_open(): start=0x%x end=0x%x", file->used.start, file->used.end);

	int8_t tmp = 0;
	if (mode == BOTFS_MODE_W) {
		PRINT_MSG("botfs_open(): Datei wird geleert...");
		tmp = clear_file(file, buffer);
	}
	botfs_release_lock_low(&botfs_mutex);
	return tmp;
}
Ejemplo n.º 12
0
void *search_file_worker() {
    work_queue_t *queue_item;

    while (TRUE) {
        pthread_mutex_lock(&work_queue_mtx);
        while (work_queue == NULL) {
            if (done_adding_files) {
                pthread_mutex_unlock(&work_queue_mtx);
                log_debug("Worker finished.");
                pthread_exit(NULL);
            }
            pthread_cond_wait(&files_ready, &work_queue_mtx);
        }
        queue_item = work_queue;
        work_queue = work_queue->next;
        if (work_queue == NULL) {
            work_queue_tail = NULL;
        }
        pthread_mutex_unlock(&work_queue_mtx);

        search_file(queue_item->path);
        free(queue_item->path);
        free(queue_item);
    }
}
Ejemplo n.º 13
0
int main(int argc, char **argv)
{
   int fd;
   char fname[1024];

   my_init_lib();

   for (int i = 0; i < NUM_FILES; i++) {
      snprintf(fname,sizeof(fname),"/f-%d",i);

      // create an empty file
      fd = my_open(fname,O_CREATE);
      if (fd < 0) {
         printf("[test] unable to open file.\n");
         return -1;
      }

      // close the file
      if (my_close(fd) < 0) {
         printf("[test] error closing file.\n");
         return -1;
      }

      // check that the file was added to the directory
      if(search_file(&fname[1]) <= 0) { // remove the '/'
         printf("[test] file was not added to the directory.\n");
         exit(-1);
      }
   }

   printf("[test] passed.\n");
   return 0;
}
Ejemplo n.º 14
0
int main(int argc, char* argv[]){
	int i=0;
	uint8_t* rd;
    uint8_t buf[30]="adfasdfasgfaaaaaaaaaaa";
    
	char name[14];
	char search_name[14];
	rd=ramdisk_init();
	int root_block_id=search_file(rd, "/");
    int search_file_inodeNO;
    int remove_flag;
    int a;
	printf("root block id is %d\n", root_block_id);
	
	struct inode* root_inode;
	if(!(root_inode=(struct inode*)malloc(sizeof(struct inode)))){
		printf("No mem space!\n");
		exit(-1);
	}
    //create_dir(rd,0,"ts_dir");
	//create a file under root named Jiayi.txt
    create_file(rd, 0, "ts_file.txt");
    for (i = 0; i<1024 ; i++)
    {
        a = write_ramdisk(rd,1,i*20,buf,20);
	    printf("a = %d; i = %d\n", a, i);
//        sprintf(name, "ts_%d.txt", i);
//        create_file(rd, 1, name);
    }

 /*   for (i = 1; i<=FILE_NUM ; i++)
    {
        sprintf(search_name, "/ts_%d.txt", i);
	    search_file_inodeNO = search_file(rd,search_name);
        printf("File InodeNO is:%d\n", search_file_inodeNO);
    }*/
    //remove_flag=remove_file(rd,0,2,"ts_2.txt");
    //(remove_flag==(-1))?(printf("Remove fail!\n")):(printf("Remove success!\n"));
    //search_file_inodeNO=search_file(rd,"/ts_2.txt");
    //printf("File InodeNO is:%d\n", search_file_inodeNO);
    remove_flag=remove_file(rd,0,1,"ts_file.txt");
    (remove_flag==(-1))?(printf("Remove fail!\n")):(printf("Remove success!\n"));
    search_file_inodeNO=search_file(rd,"/ts_file.txt");
    printf("File InodeNO is:%d\n", search_file_inodeNO);
    
	return 0;
}
Ejemplo n.º 15
0
static UINT search_ini( MSIPACKAGE *package, WCHAR **appValue, MSISIGNATURE *sig )
{
    static const WCHAR query[] =  {
        's','e','l','e','c','t',' ','*',' ',
        'f','r','o','m',' ',
        'I','n','i','L','o','c','a','t','o','r',' ',
        'w','h','e','r','e',' ',
        'S','i','g','n','a','t','u','r','e','_',' ','=',' ','\'','%','s','\'',0};
    MSIRECORD *row;
    LPWSTR fileName, section, key;
    int field, type;
    WCHAR buf[MAX_PATH];

    TRACE("%s\n", debugstr_w(sig->Name));

    *appValue = NULL;

    row = MSI_QueryGetRecord( package->db, query, sig->Name );
    if (!row)
    {
        TRACE("failed to query IniLocator for %s\n", debugstr_w(sig->Name));
        return ERROR_SUCCESS;
    }

    fileName = msi_dup_record_field(row, 2);
    section = msi_dup_record_field(row, 3);
    key = msi_dup_record_field(row, 4);
    field = MSI_RecordGetInteger(row, 5);
    type = MSI_RecordGetInteger(row, 6);
    if (field == MSI_NULL_INTEGER)
        field = 0;
    if (type == MSI_NULL_INTEGER)
        type = 0;

    GetPrivateProfileStringW(section, key, NULL, buf, MAX_PATH, fileName);
    if (buf[0])
    {
        switch (type & 0x0f)
        {
        case msidbLocatorTypeDirectory:
            search_directory( package, sig, buf, 0, appValue );
            break;
        case msidbLocatorTypeFileName:
            *appValue = search_file( package, buf, sig );
            break;
        case msidbLocatorTypeRawValue:
            *appValue = get_ini_field(buf, field);
            break;
        }
    }

    msi_free(fileName);
    msi_free(section);
    msi_free(key);

    msiobj_release(&row->hdr);

    return ERROR_SUCCESS;
}
Ejemplo n.º 16
0
static int simple_truncate(const char *path, off_t offset) {
  struct directory_entry *p;

  if ( (p = search_file(path)) == 0 ) { return -ENOENT; }
  if ( offset < 0 ) { return -ENOENT; }
  if ( adjust_size(p->file, offset) < 0 ) { return -ENOENT; }

  return 0;
}
Ejemplo n.º 17
0
static int simple_rename(const char *path, const char *new_name)
{
  struct directory_entry *p;

  if ( (p = search_file(path)) == 0 ) { return -ENOENT; }

  p->name = strdup(new_name + 1);

  return 0;
}
Ejemplo n.º 18
0
static int simple_open(const char *path, struct fuse_file_info *fi)
{
  struct directory_entry *p;

  if ((p = search_file(path)) == 0) {
    return -ENOENT;
  }

  fi->fh = (long)p->file;

  return 0;
}
Ejemplo n.º 19
0
char *out(char *cmd){
  char *s;
  char *file;
  s = strstr(cmd, ">");
  if(s == NULL){
    return '\0';
  }
  else{
    file=search_file(s);
    return file;
  }
}
Ejemplo n.º 20
0
int search_path(char *path, char *filetype, int sl, char *input_str) {
  char *fullpath;             //Path specified by command-line
  char *newpath;              //New path created for each item (directory, file or symbolic link)
  int len = PATH_MAX + 1;     //Max path length for linux machine +1
  DIR *dp;                    //Directory pointer
  struct dirent *current_item;//Struct with info for each item
  unsigned char dtype;        //Used to get info from struct
  char *dname;                //Used to get info from struct 
  
  
  fullpath        = (char *)malloc(len); 
  newpath         = (char *)malloc(len); 
  strcpy(fullpath, path);                 //create controlled buffer: path --> fullpath
  fullpath[len-1] = 0;                    //Null-terminated
  fullpath        = strcat(fullpath, "/");
  strcpy(newpath, fullpath);              //initialize controlled buffer: fullpath --> newpath
  
  //Opens directory if this is possible
  if ((dp = opendir(fullpath)) == NULL) {
    fprintf (stderr, "finds: '%s': No such file or directory", path);
    return -1; 
  }

  while ((current_item = readdir(dp)) != NULL) { 
    if (strcmp(current_item->d_name, ".") == 0 || strcmp(current_item->d_name, "..") == 0)
      continue; 
    // If item is directory call method again on that directory
    if ((dtype = current_item ->d_type) == DT_DIR) {
      dname = current_item -> d_name;
      strcat(newpath, dname);        
      search_path(newpath, filetype, sl, input_str);
      strcpy(newpath, fullpath);                    //reset newpath variable
    } else if (dtype == DT_REG) {
      dname = current_item -> d_name;
      strcat(newpath, dname);    
      search_file(newpath, filetype, dname, input_str); 
      strcpy(newpath, fullpath);                   //reset newpath variable
    } else if (sl == ENABLED && dtype == DT_LNK) {
      dname = current_item -> d_name;
      strcat(newpath, dname);       
      search_path(newpath, filetype, sl, input_str);
      strcpy(newpath, fullpath);                   //reset newpath variable
    } else {
      continue; 
    }
  }
  free(fullpath); 
  free(newpath); 
  return 0; 
}
Ejemplo n.º 21
0
/**
 * Benennt eine Datei um
 * \param *filename	Dateiname
 * \param *new_name	Neuer Dateiname
 * \param *buffer	Puffer fuer mindestens BOTFS_BLOCK_SIZE Byte
 * \return			0, falls kein Fehler
 *
 * Datei new_name wird geloescht, falls sie bereits existiert.
 */
int8_t botfs_rename(const char * filename, const char * new_name, void * buffer) {
	botfs_acquire_lock_low(&botfs_mutex);
	/* Datei suchen */
	botfs_file_t * ptr = search_file(filename, buffer);
	botfs_release_lock_low(&botfs_mutex);
	if (ptr == NULL) {
		PRINT_MSG("botfs_rename(): Datei nicht vorhanden");
		return -1;
	}

	/* Ziel loeschen, falls vorhanden */
	if (botfs_unlink(new_name, buffer) < -1) {
		PRINT_MSG("botfs_rename(): Fehler beim Loeschen der vorhandenen Zieldatei");
		return -2;
	}

	/* Root-Dir Eintrag updaten */
	botfs_acquire_lock_low(&botfs_mutex);
	ptr = search_file(filename, buffer);
	char * pName = ptr->name;
	if (new_name[0] != '/') {
		/* fehlenden fuehrenden / ergaenzen */
		*pName = '/';
		pName++;

	}
	strncpy(pName, new_name, BOTFS_MAX_FILENAME - 1);
	botfs_seek(&botfs_vol_data.rootdir, -1, SEEK_CUR); // Dateizeiger stand auf naechstem Dir-Block => -1
	if (botfs_write(&botfs_vol_data.rootdir, buffer) != 0) {
		botfs_release_lock_low(&botfs_mutex);
		PRINT_MSG("botfs_rename(): Fehler beim Schreiben des Root-Blocks");
		return -3;
	}
	botfs_release_lock_low(&botfs_mutex);
	return 0;
}
Ejemplo n.º 22
0
int main(int argc, char *argv[]) {
	int file_index;
	FILE *fp;

	if (argc < 2) {
		fprintf(stderr, "Usage: %s pattern [file1] [file2] ...\n", argv[0]);
		return 0;
	}
	
	if (argc == 2) {
		search_file(argv[1], "<STDIN>", stdin);
	}
	else {
		for (file_index = 2; file_index < argc; file_index++) {
			if ((fp = fopen(argv[file_index], "r")) == NULL) {
				fprintf(stderr, "%s: Could not open file %s\n", argv[0], argv[file_index]);
				continue;
			}
			search_file(argv[1], argv[file_index], fp);
			fclose(fp);
		}
	}
	return 0;
}
Ejemplo n.º 23
0
static gboolean
backend_search_file_thread (PkBackend *backend)
{
	const gchar *search;
	PkBitfield filters;

	search = pk_backend_get_string (backend, "search");
	filters = (PkBitfield) pk_backend_get_uint (backend, "filters");

	pk_backend_set_allow_cancel (backend, true);

	// as we can only search for installed files lets avoid the opposite
	if (!pk_bitfield_contain (filters, PK_FILTER_ENUM_NOT_INSTALLED)) {
		aptcc *m_apt = new aptcc(backend, _cancel);
		pk_backend_set_pointer(backend, "aptcc_obj", m_apt);
		if (m_apt->init()) {
			egg_debug ("Failed to create apt cache");
			delete m_apt;
			pk_backend_finished (backend);
			return false;
		}

		pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
		vector<string> packages = search_file (backend, search, _cancel);
		vector<pair<pkgCache::PkgIterator, pkgCache::VerIterator> > output;
		for(vector<string>::iterator i = packages.begin();
		    i != packages.end(); ++i)
		{
			if (_cancel) {
			    break;
			}
			pkgCache::PkgIterator pkg = m_apt->packageCache->FindPkg(i->c_str());
			pkgCache::VerIterator ver = m_apt->find_ver(pkg);
			if (ver.end() == true)
			{
				continue;
			}
			output.push_back(pair<pkgCache::PkgIterator, pkgCache::VerIterator>(pkg, ver));
		}
		// It's faster to emmit the packages here rather than in the matching part
		m_apt->emit_packages(output, filters);

		delete m_apt;
	}

	pk_backend_finished (backend);
	return true;
}
Ejemplo n.º 24
0
/*****************************************************************************
 *                                do_stat
 *************************************************************************//**
 * Perform the stat() syscall.
 * 
 * @return  On success, zero is returned. On error, -1 is returned.
 *****************************************************************************/
PUBLIC int do_stat()
{
	char pathname[MAX_PATH]; /* parameter from the caller */
	char filename[MAX_PATH]; /* directory has been stipped */

	/* get parameters from the message */
	int name_len = fs_msg.NAME_LEN;	/* length of filename */
	int src = fs_msg.source;	/* caller proc nr. */
	assert(name_len < MAX_PATH);
	phys_copy((void*)va2la(TASK_FS, pathname),    /* to   */
		  (void*)va2la(src, fs_msg.PATHNAME), /* from */
		  name_len);
	pathname[name_len] = 0;	/* terminate the string */

	int inode_nr = search_file(pathname);
	if (inode_nr == INVALID_INODE) {	/* file not found */
		printl("{FS} FS::do_stat():: search_file() returns "
		       "invalid inode: %s\n", pathname);
		return -1;
	}

	struct inode * pin = 0;

	struct inode * dir_inode;
	if (strip_path(filename, pathname, &dir_inode) != 0) {
		/* theoretically never fail here
		 * (it would have failed earlier when
		 *  search_file() was called)
		 */
		assert(0);
	}
	pin = get_inode(dir_inode->i_dev, inode_nr);

	struct stat s;		/* the thing requested */
	s.st_dev = pin->i_dev;
	s.st_ino = pin->i_num;
	s.st_mode= pin->i_mode;
	s.st_rdev= is_special(pin->i_mode) ? pin->i_start_sect : NO_DEV;
	s.st_size= pin->i_size;

	put_inode(pin);

	phys_copy((void*)va2la(src, fs_msg.BUF), /* to   */
		  (void*)va2la(TASK_FS, &s),	 /* from */
		  sizeof(struct stat));

	return 0;
}
Ejemplo n.º 25
0
int main(int argc, char **argv) {

  sgrep_data sgd;
  int status = 0;

  /* Parser: get user information - store sgd*/
  /* sgrep -i hejsan fil.txt */
  /*   argc: 4
       argv: ----> [0] [1] [2] [3]
                   |  |  |  |
                   |  |  |  + "fil.txt"
                   |  |  + "hejsan"
                   |  + "-i"
                   + "sgrep"
  */
  /*   argc-1: 3
       argv: ----> [1] [2] [3]
                   |  |  |
                   |  |  + "fil.txt"
                   |  + "hejsan"
                   + "-i"
  */
	status = parse(argc-1, ++argv, &sgd);
	if (status != 0) {
		if (status == 1) {
			printf("Bad input\n");
		} else {
			printf("File not found\n");
		}
		return 2;
	}

	/*printf ("Case sensitive: %d\n",
			sgd.case_sensitive);
	*/
	/* Searcher: Call search_file */
	status = search_file(&sgd);
	if (status == 0) {
		if (sgd.mode == 1) {
			printf("%d\n", sgd.matches);
		}
	}

	/*
	* make sure to return according to specification
	*/
	return status;
}
Ejemplo n.º 26
0
static int simple_unlink(const char *path) {
  struct directory_entry *p, *q;

  p = search_file(path);
  if ( p == 0 ) { return -ENOENT; }
  if ( p->file->nlink == 1 ) {
    q = p;
    if ( p == root ) { root = p->next; }
    p = p->next;
    free(q->file);
    free(q);
    return 0;
  } else {
    return -ENOENT;
  }
}
Ejemplo n.º 27
0
Archivo: q2.c Proyecto: eokeeffe/C-code
void search_file_ini()//search the file
{
	fp=fopen("employee.dat","r");
	
	int ST=0;	//ST stands for search type
	c=0;
	count=0;
	
	if(check_file(fp)==TRUE)
	{
		fclose(fp);
		printf("Please input a search code\r\n");
		printf("1.by first name\r\n");
		printf("2.by last name\r\n");
		printf("3.By ID number\r\n");
		printf("4.By working hours\r\n");
		printf("5.By tax rate\r\n");
		printf("6.By Income(net)\r\n");
		printf("7.By payment\r\n");
		printf("8.by line\r\n");
		printf("9.back to main menu\r\n");
		scanf("%d",&ST);
		
		switch(ST)
		{
			case 1:{search_file(1);break;}
			case 2:{search_file(2);break;}
			case 3:{search_file(3);break;}
			case 4:{search_file(4);break;}
			case 5:{search_file(5);break;}
			case 6:{search_file(6);break;}
			case 7:{search_file(7);break;}
			case 8:{search_file(8);break;}
			case 9:{options();break;}
			default:{search_file_ini();break;}
		}
	}
	if(check_file(fp)==FALSE)
	{
		NF
		wait_for_user();
		main();
	}
	
}
Ejemplo n.º 28
0
/* sharing some chunks but with different hash/minhash */
void collect_distinct_files(){
    init_iterator("CHUNK");

    struct chunk_rec r;
    memset(&r, 0, sizeof(r));

    int count = 0;
    while(iterate_chunk(&r, 1) == 0){

        if(r.rcount > 1 && r.fcount > 1){
            struct file_rec files[r.fcount];
            memset(files, 0, sizeof(files));
            int i = 0;
            for(; i < r.fcount; i++){
                files[i].fid = r.list[r.rcount + i];
                search_file(&files[i]);
            }
            for(i=1; i<r.fcount; i++){
                if(memcmp(files[i].minhash, files[i-1].minhash, sizeof(files[i].minhash)) != 0){
                    char suffix[8];
                    printf("CHUK %d ", r.fcount);
                    print_hash(r.hash, 10);
                    int j = 0;
                    for(; j<r.fcount; j++){
                        parse_file_suffix(files[j].fname, suffix, sizeof(suffix));
                        if(strncmp(suffix, "edu,", 4) == 0){
                            strcpy(suffix, "edu,?");
                        }else if(strlen(suffix) == 0){
                            strcpy(suffix, ".None");
                        }
                        printf("FILE %d %" PRId64 " %s %s ", files[j].fid, files[j].fsize,
                                files[j].fname, suffix);
                        print_hash(files[j].minhash, 10);
                    }

                    count++;
                    break;
                }
            }
        }
    }
    fprintf(stderr, "%d chunks are shared between distinct files\n", count);

    close_iterator();

}
Ejemplo n.º 29
0
static int simple_getattr(const char *path, struct stat *stbuf)
{
  int res = 0;
  struct directory_entry *p;

  memset(stbuf, 0, sizeof(struct stat));
  if (strcmp(path, "/") == 0) {
    stbuf->st_mode = S_IFDIR | 0755;
    stbuf->st_nlink = 2;
  } else if (p = search_file(path)) {
    stbuf->st_mode = p->file->mode;
    stbuf->st_nlink = p->file->nlink;
    stbuf->st_size = p->file->length;
  } else
    res = -ENOENT;

  return res;
}
Ejemplo n.º 30
0
Archivo: do_stat.c Proyecto: Zach41/OS
PUBLIC int do_stat() {
    char pathname[MAX_PATH];
    char filename[MAX_PATH];

    int name_len = fs_msg.NAME_LEN;
    int src      = fs_msg.source;
    
    memcpy((void*)va2la(TASK_FS, pathname),
	   (void*)va2la(src, fs_msg.PATHNAME),
	   name_len);
    pathname[name_len] = 0;

    int inode_nr = search_file(pathname);

    if (inode_nr == INVALID_INODE) {
	printl("FS::do_stat() failed, search file %s return INVALID INODE.\n", pathname);
	return -1;
    }

    struct inode* pin = 0;
    struct inode* dir_inode = 0;
    if(strip_path(filename, pathname, &dir_inode) != 0) {
	assert(0);
    }

    pin = get_inode(dir_inode -> i_dev, inode_nr);

    struct stat s;

    s.st_dev  = pin -> i_dev;
    s.st_ino  = pin -> i_num;
    s.st_mode = pin -> i_mode;
    s.st_rdev = pin -> i_mode == I_CHAR_SPECIAL ? pin -> i_start_sect : NO_DEV;
    s.st_size = pin -> i_size;

    put_inode(pin);

    memcpy((void*)va2la(src, fs_msg.BUF),
	   (void*)va2la(TASK_FS, &s),
	   sizeof(struct stat));

    return 0;
}