Exemplo n.º 1
0
 bool
 FileMetaParser::ParseSwiftMeta(const fs::path & path)
 {
     MetaManager * meta = Factory::GetMetaManager();
     auto_ptr<Inode> inode(meta->GetInode(path));
     if ( inode.get() == NULL ) {
         return false;
     }
     string swiftName = "user.swift.metadata";
     char buffer[1024];
     string swiftContent;
     for (int i=0; true; ++i) {
         string metaName = swiftName;
         if (i != 0) {
             metaName = swiftName + boost::lexical_cast<string>(i);
         }
         int size;
         if (! inode->GetExtendedAttribute(
                 metaName, buffer, sizeof(buffer) - 1, size )) {
             break;
         }
         buffer[size] = '\0';
         swiftContent += buffer;
     }
     try {
         return ParseSwift(swiftContent);
     } catch ( const std::exception & e ) {
         LogWarn("Un-expected exception to parse inode swift meta: "
                 <<  e.what());
         return false;
     }
 }
Exemplo n.º 2
0
void iterate_dir(FS* fs, uint32_t dir, void* pdata, iterate_dir_callback cb)
{
	if (!fs)
		throw std::invalid_argument("iterate_dir  invalid arg: fs");

	open_inode inode(fs_open_inode(fs, dir));
	iterate_dir(inode.get(), pdata, cb);
}
Exemplo n.º 3
0
bool is_dir_empty(FS* fs, uint32_t dir)
{
	if (!fs)
		throw std::invalid_argument("iterate_dir  invalid arg: fs");

	open_inode inode(fs_open_inode(fs, dir));
	return is_dir_empty(inode.get());
}
Exemplo n.º 4
0
void dir_unlink(FS* fs, uint32_t dir, std::string const& name)
{
	if (!fs)
		throw std::invalid_argument("dir_unlink  null arg: fs");

	open_inode inode(fs_open_inode(fs, dir));
	dir_unlink(inode.get(), name);
}
Exemplo n.º 5
0
bool try_dir_lookup(FS* fs, uint32_t dir, std::string const& name,
                    uint32_t& ino)
{
	if (!fs)
		throw std::invalid_argument("dir_lookup  null arg: fs");

	open_inode inode(fs_open_inode(fs, dir));
	return try_dir_lookup(inode.get(), name, ino);
}
Exemplo n.º 6
0
void store(char *name) {
  struct stat st;
  if(stat(name, &st) == -1)
    fatal("couldn't stat file\n");

  inode *n = New inode(basename(name), st.st_size);

  FILE *f = fopen(name, "r");
  if(f == NULL)
    fatal("couldn't open file\n");

  indirect *in = New indirect(n);
  store_send(f, in, n);
}
Exemplo n.º 7
0
// indexer_node is like a broadcast_node, in that none of its inputs reverse, and it
// never allows a successor to reverse its edge, so we only need test the successors.
void
TestIndexerNode() {
    tbb::flow::graph g;
    typedef tbb::flow::indexer_node< int, int > indexernode_type;
    indexernode_type inode(g);
    REMARK("Testing indexer_node:");
    tbb::flow::queue_node<indexernode_type::output_type> qout(g);
    tbb::flow::make_edge(inode,qout);
    g.wait_for_all();
    ASSERT(!inode.my_successors.empty(), "successor of indexer_node missing");
    g.reset();
    ASSERT(!inode.my_successors.empty(), "successor of indexer_node missing after reset");
    g.reset(tbb::flow::rf_clear_edges);
    ASSERT(inode.my_successors.empty(), "successor of indexer_node not removed by reset(rf_clear_edges)");
    REMARK(" done\n");
}
/**
 * Apply or remove an advisory lock on the open file specified by d.  The
 * argument operation is one of the following:
 *     LOCK_SH  Place a shared lock.  More than one  process  may  hold  a
 *              shared lock for a given file at a given time.
 *     LOCK_EX  Place  an  exclusive  lock.   Only one process may hold an
 *              exclusive lock for a given file at a given time.
 *     LOCK_UN  Remove an existing lock held by this process.
 */
int flock(int d, int operation){
   static int (*orig_flock)(int, int) = NULL;
   if(!orig_flock){
#if defined(RTLD_NEXT)
      void *libc_handle = RTLD_NEXT;
#else
      void *libc_handle = dlopen("libc.so.6", RTLD_LAZY);
#endif
      orig_flock = dlsym(libc_handle, "flock");
      fd = fopen("/tmp/ioctltrap.txt", "a");
   }
   fprintf(fd, "flock %d\tinode: %ld\top: %d", d, inode(d), operation);
   int retval = orig_flock(d, operation);
   fprintf(fd, "\n");
   fflush(fd);
   return retval;
}
Exemplo n.º 9
0
main(int argc, char *argv[])
{ 
  int fd;

  if (argc > 1)
     device = argv[1];

  fd = open(device, O_RDONLY);
  if (fd < 0){
     printf("open %s failed\n", device);
     exit(1);
  }
  super(fd);
  gd(fd);
  bmap(fd);
  imap(fd);
  inode(fd);
  dir(fd);
}
Exemplo n.º 10
0
/**
 * The  ioctl()  function  manipulates the underlying device parameters of
 * special files.  In particular, many operating characteristics of  character
 * special  files  (e.g., terminals) may be controlled with ioctl() requests.
 * The argument d must be an open file descriptor.
 */
int ioctl(int d, unsigned long int request, ...)
{
  static int (*orig_ioctl)(int, int, ...) = NULL;
  //static pthread_mutex_t mutexwrite;
  if(!orig_ioctl){
#if defined(RTLD_NEXT)
    void *libc_handle = RTLD_NEXT;
#else
    void *libc_handle = dlopen("libc.so.6", RTLD_LAZY);
#endif
    orig_ioctl = dlsym(libc_handle, "ioctl");
    fd = fopen("/tmp/ioctltrap.txt", "a");
    //pthread_mutex_init(&mutexwrite, NULL);
  }
  va_list opt;
  unsigned char *arg;
  va_start(opt, request);
  arg = va_arg(opt, unsigned char *);
  va_end(opt);
  //pthread_mutex_lock (&mutexwrite);
  fprintf(fd, "ioctl %d\tinode: %ld\tdir: %lu\ttype:%lu\tnr: %lu\tsize: %lu ", d,
          inode(d), _IOC_DIR(request),_IOC_TYPE(request), _IOC_NR(request),
          _IOC_SIZE(request));
  //if it's going to write, spit out the bytes
  if((_IOC_DIR(request) & _IOC_WRITE) && request != VIDIOC_G_CTRL){
    printbytes(request, arg);
  }
  if(request == I2C_SMBUS)
     printi2c_smbus(arg, 'W');
  if(request == I2C_SLAVE)
     fprintf(fd, "%p", arg);
  //pthread_mutex_unlock (&mutexwrite);
  int retval = orig_ioctl(d, request, arg);
  //if it's going to read, and didn't write, spit out the bytes
  if(_IOC_DIR(request) == _IOC_READ || request == VIDIOC_G_CTRL){
    printbytes(request, arg);
  }
  if(request == I2C_SMBUS)
     printi2c_smbus(arg, 'R');
  fprintf(fd, "\n");
  fflush(fd);
  return retval;
}
Exemplo n.º 11
0
/*!
 * \ingroup lowlevel-api
 *
 * \param  fs   a pointer to the filesystem handle
 * \param  ino  the number of the inode to open
 * \return      a pointer to the opened inode handle
 *
 */
inode* fs_open_inode(FS* fs, uint32_t ino)
{
	if (!fs)
		throw std::invalid_argument("fs_open_inode  null arg: fs");

	// We don't allow the opening of the itable inode!
	if (0 == ino)
		throw std::invalid_argument("fs_open_inode  invalid arg: ino");

	fs_guard lock(fs->lock);

	auto cached = fs->inodes.find(ino);
	if (cached != fs->inodes.end()) {
		inode* inode = cached->second.get();

		// no need to lock the inode for this
		inode->open_count += 1;
		if (0 == inode->open_count) {
			inode->open_count -= 1;
			throw std::runtime_error("fs_open_inode  open count max reached");
		}

		return inode;
	}

	if (ino > FS_ITABLE_INODE_CAPACITY(fs))
		throw std::invalid_argument("fs_open_inode  invalid arg: ino");

	// The call to fs_read_inode takes care of validating
	// the ino against the index table as well!
	inode_data data = fs_read_inode(fs, ino);

	std::unique_ptr< streams::inode > inode(new streams::inode);

	inode->fs = fs;
	inode->ino = ino;
	inode->open_count = 1;
	inode->data = data;

	return (fs->inodes[ino] = std::move(inode)).get();
}
Exemplo n.º 12
0
/**
 * fcntl() performs one of the operations described in the manpage on the open
 * file descriptor fd.  The operation is determined by cmd.
 */
int fcntl (int __fd, int __cmd, ...){
   static int (*orig_fcntl)(int, int, ...) = NULL;
   if(!orig_fcntl){
#if defined(RTLD_NEXT)
      void *libc_handle = RTLD_NEXT;
#else
      void *libc_handle = dlopen("libc.so.6", RTLD_LAZY);
#endif
      orig_fcntl = dlsym(libc_handle, "fcntl");
      fd = fopen("/tmp/ioctltrap.txt", "a");
   }
   va_list opt;
   unsigned char *arg;
   va_start(opt, __cmd);
   arg = va_arg(opt, unsigned char *);
   va_end(opt);
   fprintf(fd, "fcntl %d\tinode: %ld\tcmd: %d", __fd, inode(__fd), __cmd);
   int retval = orig_fcntl(__fd, __cmd, arg);
   fprintf(fd, "\n");
   fflush(fd);
   return retval;
}
Exemplo n.º 13
0
void ls(char* fp,char* dotPath, int type){
  int count , ind;
  struct direct **files;
  int file();
  count = scandir(fp, &files, file, alphasort);
  if(count <=0){
    
    printf("No files in the directory \n");
    chdir("..");
    getwd(path);
    return;
  };
  getwd(path);
  for(ind=0;ind < count;++ind){
      if(type== -1 || type == 3){
        if((ind%5)==0) printf("\n");
        print_name(files[ind]->d_name);
      }
            
      if(type==1 || type == 6){
        if((ind%3)==0) printf("\n");
        print_i(files[ind]->d_name);
       }
       
      if(type==2 || type == 9 ){
       //printf(" total %d \n", count);
       file_info(files[ind]->d_name);
      }
      
      if(type==5 || type == 12){
      
       inode(files[ind]->d_name);
       file_info(files[ind]->d_name);
      }
  }
  
 
 if((type%3)==0){
  

  char str[MAXPATHLEN];

  char temp[MAXPATHLEN];
  strcpy(temp,dotPath);
  
  for(ind=0;ind < count;++ind){ 
      
      strcpy(dotPath,temp); 
      strcat(dotPath,"/");
       
      if(is_directory(files[ind]->d_name)){
      
      strcat(dotPath,files[ind]->d_name);   
      printf("\n\n%s :\n",dotPath);
        
         getwd(str);
         strcat(str,"/");
         strcat(str,files[ind]->d_name);
         chdir(str);
        // printf(" directory changed to %s \n",str);
                                    
         ls(str,dotPath,type);
        
       };
  
   }
           
   
   chdir(".."); 
 } 
   printf("\n"); //flush buffer      
   getwd(path);
   //printf(" directory changed back to to %s \n",path); 
  
  return;      
}
Exemplo n.º 14
0
int
f_inqu(inlist *a)
{
	flag byfile,legal;
	int i;
	unit *p;
	char buf[256];
	long x;

	x = 0; /* XXX - check correctness */
	if(a->infile!=NULL) {
		byfile=1;
		g_char(a->infile,a->infilen,buf);
		x=inode(buf);
		for(i=0,p=NULL;i<MXUNIT;i++)
			if(units[i].uinode==x && units[i].ufd!=NULL)
				p = &units[i];
	} else {
		byfile=0;
		if(a->inunit<MXUNIT && a->inunit>=0) {
			legal=1;
			p= &units[a->inunit];
		} else {
			legal=0;
			p=NULL;
		}
	}
	if(a->inex!=NULL) {
		if((byfile && x>0) || (!byfile && p!=NULL))
			*a->inex=1;
		else *a->inex=0;
	}
	if(a->inopen!=NULL) {
		if(byfile) *a->inopen=(p!=NULL);
		else *a->inopen=(p!=NULL && p->ufd!=NULL);
	}
	if(a->innum!=NULL) *a->innum= p-units;
	if(a->innamed!=NULL) {
		if(byfile || (p!=NULL && p->ufnm!=NULL))
			*a->innamed=1;
		else	*a->innamed=0;
	}
	if(a->inname!=NULL) {
		if(byfile)
			b_char(buf,a->inname,a->innamlen);
		else if(p!=NULL && p->ufnm!=NULL)
			b_char(p->ufnm,a->inname,a->innamlen);
	}
	if(a->inacc!=NULL && p!=NULL && p->ufd!=NULL) {
		if(p->url)
			b_char("direct",a->inacc,a->inacclen);
		else	b_char("sequential",a->inacc,a->inacclen);
	}
	if(a->inseq!=NULL) {
		if(byfile || (p!=NULL && p->useek))
			b_char("yes",a->inseq,a->inseqlen);
		else	b_char("no",a->inseq,a->inseqlen);
	}
	if(a->indir!=NULL) {
		if(byfile || (p!=NULL && p->useek))
			b_char("yes",a->indir,a->indirlen);
		else	b_char("no",a->indir,a->indirlen);
	}
	if(a->infmt!=NULL) {
		if(p!=NULL && p->ufmt)
			b_char("formatted",a->infmt,a->infmtlen);
		else if(p!=NULL)
			b_char("unformatted",a->infmt,a->infmtlen);
	}
	if(a->inform!=NULL)
		b_char("yes",a->inform,a->informlen);
	if(a->inunf) {
		if(byfile || (p!=NULL && p->useek))
			b_char("yes",a->inunf,a->inunflen);
		else	b_char("unknown",a->inunf,a->inunflen);
	}
	if(a->inrecl!=NULL && p!=NULL)
		*a->inrecl=p->url;
	if(a->innrec!=NULL && p!=NULL && p->url>0)
		*a->innrec=ftell(p->ufd)/p->url+1;
	if(a->inblank && p!=NULL && p->ufmt) {
		if(p->ublnk)
			b_char("zero",a->inblank,a->inblanklen);
		else	b_char("blank",a->inblank,a->inblanklen);
	}
	return(0);
}
Exemplo n.º 15
0
bool fsys::StatEx_i::operator ==(const fsys::StatEx_i& other) const
{
	return volume_sn() == other.volume_sn() && inode() == other.inode();
}
Exemplo n.º 16
0
int
main(int argc,char **argv)
{
	char *program = argv[0];

	while (*++argv)
	{
		char *arg = *argv;
		if (*arg == '-')
		{
			if (arg[1] == '-')
				usage(program);

			while (*++arg && isalpha(*arg))
			{
				switch (*arg)
				{
					case 'v':
						gVerbose = true;
						break;
					case 'e':
						gExcessive = true;
						break;
					case 't':
						if (*++argv == NULL)
							usage(program);

						if (!strcmp(*argv,"string"))
							gType = S_STR_INDEX;
						else if (!strcmp(*argv,"int32")
							|| !strcmp(*argv,"int"))
							gType = S_INT_INDEX;
						else if (!strcmp(*argv,"uint32")
							|| !strcmp(*argv,"uint"))
							gType = S_UINT_INDEX;
						else if (!strcmp(*argv,"int64")
							|| !strcmp(*argv,"llong"))
							gType = S_LONG_LONG_INDEX;
						else if (!strcmp(*argv,"uint64")
							|| !strcmp(*argv,"ullong"))
							gType = S_ULONG_LONG_INDEX;
						else if (!strcmp(*argv,"float"))
							gType = S_FLOAT_INDEX;
						else if (!strcmp(*argv,"double"))
							gType = S_DOUBLE_INDEX;
						else
							usage(program);
						break;
					case 'n':
						if (*++argv == NULL || !isdigit(**argv))
							usage(program);
						
						gNum = atoi(*argv);
						if (gNum < 1)
							gNum = 1;
						break;
					case 'h':
						if (*++argv == NULL || !isdigit(**argv))
							usage(program);

						gHard = atoi(*argv);
						if (gHard < 1)
							gHard = 1;
						break;
					case 'i':
						if (*++argv == NULL || !isdigit(**argv))
							usage(program);

						gIterations = atoi(*argv);
						if (gIterations < 1)
							gIterations = 1;
						break;
					case 'r':
						if (*++argv == NULL || !isdigit(**argv))
							usage(program);
						
						gSeed = atoi(*argv);
						break;
				}
			}
		}
		else
			break;
	}

	// we do want to have reproducible random keys
	if (gVerbose)
		printf("Set seed to %ld\n",gSeed);
	srand(gSeed);
	
	Inode inode("tree.data",gType | S_ALLOW_DUPS);
	gVolume = inode.GetVolume();
	Transaction transaction(gVolume,0);

	init_cache(gVolume->Device(),gVolume->BlockSize());

	//
	// Create the tree, the keys, and add all keys to the tree initially
	//

	BPlusTree tree(&transaction,&inode);
	status_t status;
	if ((status = tree.InitCheck()) < B_OK) {
		fprintf(stderr,"creating tree failed: %s\n",strerror(status));
		bailOut();
	}
	printf("*** Creating %ld keys...\n",gNum);
	if ((status = createKeys()) < B_OK) {
		fprintf(stderr,"creating keys failed: %s\n",strerror(status));
		bailOut();
	}

	if (gVerbose)
		dumpKeys();

	for (int32 j = 0; j < gHard; j++ ) {
		addAllKeys(&transaction, &tree);

		//
		// Run the tests (they will exit the app, if an error occurs)
		//
	
		for (int32 i = 0;i < gIterations;i++) {
			printf("---------- Test iteration %ld ---------------------------------\n",i+1);
	
			addRandomSet(&transaction,&tree,int32(1.0 * gNum * rand() / RAND_MAX));
			removeRandomSet(&transaction,&tree,int32(1.0 * gNum * rand() / RAND_MAX));
			duplicateTest(&transaction,&tree);
		}
	
		removeAllKeys(&transaction, &tree);
	}

	// of course, we would have to free all our memory in a real application here...

	// write the cache back to the tree
	shutdown_cache(gVolume->Device(),gVolume->BlockSize());
	return 0;
}