Esempio n. 1
0
unsigned int explore_inode(const char *absolute_path){

    // bitmap and inode table
    // located from the group_descriptor_table [2 nd block] 
    struct ext2_group_desc *group_desc_table = (struct ext2_group_desc *)(disk + (EXT2_BLOCK_SIZE * 2));
    
    // location of the bitmaps in blocks 
    int inode_table = group_desc_table->bg_inode_table;
    
    // start from the root inode
    // find out where the inode tale start
    void *tablestart = disk + EXT2_BLOCK_SIZE*inode_table;

    // need to create a duplicate path so we don't change original
    char dup_path[strlen(absolute_path) + 1];
    strcpy(dup_path, absolute_path);
    char separator[2] = "/"; // we have to turn this into a string
    char *member = strtok(dup_path, separator);

    // check if first one is "/" we only want to look at is only root
    // special root file may have more than one block 
    if ((dup_path[0] == '/') && (strlen(dup_path) == 2)){
        return 2; // if it is root only then just return 2
    } 
    else if(dup_path[0] != '/'){ // when the path is invalid 
        return -1;
    }

    int foundnum = 2;
    while(member != NULL){ // loop through each member file name
        // creating the inode
        // foundnum - 1 is to go to beginning of inode
        struct ext2_inode *inode = (struct ext2_inode*)(tablestart)+(foundnum-1);
        int size_dblock = size_data_block(inode->i_block);
        int *data_block = (int*)malloc(size_dblock*sizeof(int));
        data_block = create_data_block(tablestart, foundnum, size_dblock);

        char *searchfile = member; // file name

        int j;
        int temp;
        for (j = 0; j < size_dblock; j++){
            temp = -1; // clear temp
            temp = found_name(searchfile, data_block[j], foundnum);
            if (temp == -1){
                fprintf(stderr, "No such file or directory\n");
                exit(ENOENT);
            }
            foundnum = temp;
        }
        free(data_block); // clear the allocated block 
        member = strtok(NULL, separator); // iterater through the loop
    }
    return foundnum;
}
Esempio n. 2
0
    void deprecated_name_check::inspect(
      const string & library_name,
      const path & full_path,      // example: c:/foo/boost/filesystem/path.hpp
      const string & contents)     // contents of file to be inspected
    {
      if (contents.find( "hpxinspect:" "nodeprecatedname" ) != string::npos)
        return;

      std::set<std::string> found_names;

      // for all given names, check whether any is used
      for (deprecated_names_regex_data const& d : regex_data)
      {
        boost::sregex_iterator cur(contents.begin(), contents.end(), d.pattern), end;
        for(/**/; cur != end; ++cur)
        {
          auto m = *cur;
          if (m[1].matched)
          {
            // avoid errors to be reported twice
            std::string found_name(m[1].first, m[1].second);
            if (found_names.find(found_name) == found_names.end())
            {
              // name was found
              found_names.insert(found_name);

              auto it = contents.begin();
              auto match_it = m[1].first;
              auto line_start = it;

              string::size_type line_number = 1;
              for (/**/; it != match_it; ++it)
              {
                if (string::traits_type::eq(*it, '\n'))
                {
                  ++line_number;
                  line_start = it + 1; // could be end()
                }
              }

              ++m_errors;
              error(library_name, full_path, string(name())
                  + " deprecated name ("
                  + found_name
                  + ") on line "
                  + linelink(full_path, boost::lexical_cast<string>(line_number))
                  + ", use " + m.format(d.data->use_instead)
                  + " instead");
            }
          }
        }
      }
    }
Esempio n. 3
0
int S2CMacroExpansion::derivation_distance(
			const LString &required,
			const MacroObjectPtr found) {
    LString required_name(required);
    LString found_name(found->object_type_name());
    MetaClass *found_meta = _env->get_object_factory()->lookupMetaClass(found_name);
    int count = 0;
    while (found_meta && (found_meta->get_instance_name() != required_name)) {
	count ++;
	found_meta = found_meta->get_link_meta_class();
	}
    if (!found_meta)
        return -1;
    return count;
    }
Esempio n. 4
0
    void include_check::inspect(
      const string & library_name,
      const path & full_path,      // example: c:/foo/boost/filesystem/path.hpp
      const string & contents)     // contents of file to be inspected
    {
      if (contents.find( "hpxinspect:" "noinclude" ) != string::npos) return;

      // first, collect all #includes in this file
      std::set<std::string> includes;

      boost::sregex_iterator cur(contents.begin(), contents.end(), include_regex), end;

      for( ; cur != end; ++cur /*, ++m_errors*/ )
      {
        auto m = *cur;
        if (m[1].matched)
          includes.insert(std::string(m[1].first, m[1].second));
        else if (m[2].matched)
          includes.insert(std::string(m[2].first, m[2].second));
      }

      // for all given names, check whether corresponding include was found
      std::set<std::string> checked_includes;
      std::set<std::string> found_names;
      for (names_regex_data const& d : regex_data)
      {
        boost::sregex_iterator cur(contents.begin(), contents.end(), d.pattern), end;
        for(/**/; cur != end; ++cur)
        {
          auto m = *cur;
          if (m[1].matched)
          {
            // avoid checking the same include twice
            auto checked_includes_it =
                checked_includes.find(m.format(d.data->include));
            if (checked_includes_it != checked_includes.end())
               continue;

            // avoid errors to be reported twice
            std::string found_name(m[1].first, m[1].second);
            if (found_names.find(found_name) != found_names.end())
                continue;
            found_names.insert(found_name);

            auto include_it = includes.find(m.format(d.data->include));
            if (include_it == includes.end())
            {
              // include is missing
              auto it = contents.begin();
              auto match_it = m[1].first;
              auto line_start = it;

              string::size_type line_number = 1;
              for (/**/; it != match_it; ++it)
              {
                if (string::traits_type::eq(*it, '\n'))
                {
                  ++line_number;
                  line_start = it + 1; // could be end()
                }
              }

              ++m_errors;
              error(library_name, full_path, string(name())
                  + " missing #include ("
                  + m.format(d.data->include)
                  + ") for symbol "
                  + m.format(d.data->name) + " on line "
                  + linelink(full_path, boost::lexical_cast<string>(line_number)));
            }
            checked_includes.insert(m.format(d.data->include));
          }
        }
      }
    }