Beispiel #1
0
int openfs(struct filesys *fs, dev_t dev)
{
	int res;
	struct block_device *bdev;

	assert(BLKSZ % sizeof(struct inode) == 0);

	if(!(bdev = blk_open(dev))) {
		return -ENOENT;
	}
	fs->bdev = bdev;

	/* read the superblock */
	if(!(fs->sb = malloc(BLKSZ))) {
		blk_close(bdev);
		return -ENOMEM;
	}
	if((res = read_superblock(fs)) != 0) {
		blk_close(bdev);
		return res;
	}

	/* allocate the zero-block buffer written to zero-out blocks */
	if(!(fs->zeroblock = malloc(fs->sb->blksize))) {
		blk_close(bdev);
		free(fs->sb->ibm);
		free(fs->sb->bm);
		free(fs->sb->root);
		return -ENOMEM;
	}
	memset(fs->zeroblock, 0xff, fs->sb->blksize);

	return 0;
}
Beispiel #2
0
static void* kvfs_init(struct fuse_conn_info *conn) {

    const char* superblock_file = "/.superblock";
    char fname[strlen(mountparent) + strlen(superblock_file)];
    strcpy(fname, mountparent);
    strcat(fname,superblock_file);
    int fd;
    kvfs = calloc(1, sizeof(kvfs_t));
    kvfs->size = 0;
    if (access(fname, F_OK) == -1) {
        int size = 0;
        fd = open(fname, O_CREAT | O_WRONLY, 0644);
        write(fd, &size, sizeof(size));
        lseek(fd, SUPERBLOCK_SIZE - 1, SEEK_SET);
        write(fd, "\0", 1);
        close(fd);
    }
    else{
	int success = read_superblock();
	if(success < 0){
		printf("kv_fs_init(): read_superblock() %d\n", success);
		exit(1);	
	}
	//close(fd);
   }
    return NULL;
}
Beispiel #3
0
static int kvfs_readdir(const char *path,void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi) {
    read_superblock();
    int i;
    for(i = 0; i < kvfs->size ; i++) {
        filler(buf,kvfs->data[i].name,NULL,0);
    }
    filler(buf,".",NULL,0);
    filler(buf,"..",NULL,0);
    return 0;
}
// Usage:  "./display_dir file_name directory_path"
int main(int argc, char **argv) 
{
	const char delim[2] = "/";
  	// open the ext2 file 
	  if ((argc > 2) && (argc < 5)) 
	  {
		    // Do nothing
	  }
	  else
	  {
	  		printf("usage:  ./display_dir diskfile_name path_to_directory command_option\n");
		    return -1;
	  }

  	int fd = open(argv[1], O_RDONLY);

	  if (fd == -1) 
	  {
		    printf("couldn't open file \"%s\"\n", argv[1]);
		    return -1;
		}

	path_to_directory = argv[2];
	if (argc == 4)
	{
		if(strcmp(argv[3], "-a") == 0)
			command_option = 2;
		else
			command_option = 0;
	}
	
	
	//printf("command_option : %d\n", command_option );

	// printf(" path to Directory : %s\n", path_to_directory);
	

	// Finding tokens in the path to directory argument
	char *token = strtok(argv[2], delim);
    int noOfTokens=0;
    /* Getting all other tokens */
    while( token != NULL ) 
    {
    	strcpy(dir_parts[noOfTokens++],token);
        token = strtok(NULL, delim);
        //printf("value %s \n",token);
    }
    parts_length = noOfTokens;	

	// Sending file descriptor as parameter to read Blocks
	 read_superblock(fd);
	 read_groupdesc(fd,start_addrs_group_desc);
	 read_inodetable(fd, root_inode_block);
	 read_directory_entries(fd, directory_block_size);
}
Beispiel #5
0
void init_ext2(t_ext2 *ext2,t_device_desc* device_desc)
{	
	t_group_block* group_block;
	ext2->device_desc=device_desc;
	ext2->superblock=kmalloc(sizeof(t_superblock));
        ext2->partition_start_sector=lookup_partition(ext2,1);        
        read_superblock(ext2);
	//ext2->root_dir_inode=kmalloc(sizeof(t_inode));
	//read_root_dir_inode(ext2);
	ext2->device_desc=device_desc;
}
Beispiel #6
0
static int write_superblock(const char *name,const char *data) {
    read_superblock();
    kvfs = (kvfs_t*)realloc(kvfs, sizeof(kvfs_t) + (kvfs->size + 1)*sizeof(fnode_t) );
    strcpy(kvfs->data[kvfs->size].name,name);
    kvfs->data[kvfs->size].magic = FNODE_MAGIC;
    int fd = open_superblock();
    kvfs->size += 1;
    write(fd,&kvfs->size,sizeof(uint32_t));
    lseek(fd,4+(kvfs->size-1)*sizeof(fnode_t),SEEK_SET);
    write(fd,&kvfs->data[kvfs->size-1],sizeof(fnode_t));
    close(fd);
    return 0;
}
Beispiel #7
0
static int kvfs_utimens(const char *path, const struct timespec tv[2]) {
    read_superblock();
    int i;
    for(i = 0; i < kvfs->size ; i++) {
        if(kvfs->data[i].name == (path+1) ) {
            break;
        }
    }
    if(i == kvfs->size) {
        write_superblock(path+1,NULL);
    }
    return 0;
}
Beispiel #8
0
int
g_journal_ufs_using_last_sector(const char *prov)
{
	struct fs *fs;
	off_t psize, fssize;

	fs = read_superblock(prov);
	if (fs == NULL)
		return (0);
	/* Provider size in 512 bytes blocks. */
	psize = g_get_mediasize(prov) / DEV_BSIZE;
	/* File system size in 512 bytes blocks. */
	fssize = fsbtodb(fs, fs->fs_size);
	return (psize <= fssize);
}
Beispiel #9
0
int main(int argc, char **argv)
{
	struct minix_superblock sb;
	unsigned long size = 0;

	size = get_file_size();
	file_system = map2memory(size);
	assert(file_system != NULL);

	read_superblock(&sb);

	print_superblock(&sb);

	printf("first data zone is 0x%x\n", get_first_data_zone(sb));

	directory_walk(&sb, get_first_data_zone(sb));

	find_file_test(&sb);
	read_file_test(&sb);

	munmap(file_system, size);

	return 0;
}
Beispiel #10
0
static IDCOffer_clp Mount_m(MountLocal_cl     *self, 
			    IDCOffer_clp       drive,
			    uint32_t           partition,
			    MountLocal_Options options, 
			    Context_clp        settings)
{
    IDCOffer_clp  res;
    ext2fs_st	 *st;
    Type_Any      any;
    Heap_clp      heap;
    struct inode *root            = NULL;
    uint32_t      blockcache_size = 1024*128; /* Size of blockcache in bytes */
    CSClientStubMod_cl *stubmod_clp; 


    TRC(printf("ext2fs: mount %d from %p\n", partition, drive));
    /* It's probably a good idea to have a separate heap for the filesystem.
       For now let's just use Pvs(heap), but eventually create a stretch
       of our own. */

    heap = Pvs(heap);

    if(!(st = Heap$Malloc(heap, sizeof(*st)))) {
	fprintf(stderr, "ext2fs: cannot allocate state.\n");
	RAISE_MountLocal$Failure();
    }

    /* Where is this declared? */
    bzero(st, sizeof(*st));

    /* Fill in the fields that we can initialise without accessing the
       filesystem */
    st->heap = heap;

    st->entrymod     = NAME_FIND("modules>EntryMod", EntryMod_clp);
    st->shmtransport = NAME_FIND("modules>ShmTransport", IDCTransport_clp);
    st->csidc        = NAME_FIND("modules>CSIDCTransport", CSIDCTransport_clp);


    st->client.entry = Pvs(entry);
    /* It's not clearn how many entries we are going to require yet
       We probably want separate ones for the USDCallback and the
       FSClient offers. We need to arrange that the entry threads die
       properly when the FS is unmounted. */


    /* Interpret mount flags */
    st->fs.readonly = SET_IN(options,MountLocal_Option_ReadOnly);
    st->fs.debug    = SET_IN(options,MountLocal_Option_Debug);


    /* Place the drive in the state. */
    st->disk.partition     = partition;
    st->disk.drive_offer   = drive;
    st->disk.drive_binding = IDCOffer$Bind(drive, Pvs(gkpr), &any);
    st->disk.usddrive      = NARROW(&any, USDDrive_clp);

 
    TRC(printf("ext2fs: state at [%p, %p]\n",st, (void *)st + sizeof(*st)));
    DBO(printf("ext2fs: debugging output is switched on\n"));

    /* Connect to the disk */
    init_usd(st);

    /* We need a stretch shared between us and the USD to allow us to read
       and write metadata. We'll use this stretch as a cache of blocks read
       from the disk. Because we won't know the blocksize until we have
       managed to read the superblock, we'd better make this buffer a
       multiple of 8k long (8k is currently the maximum blocksize). */

    st->cache.str = Gatekeeper$GetStretch(Pvs(gkpr), IDCOffer$PDID(drive), 
					  blockcache_size, 
					  SET_ELEM(Stretch_Right_Read) |
					  SET_ELEM(Stretch_Right_Write), 
					  PAGE_WIDTH, PAGE_WIDTH);
    st->cache.buf = STR_RANGE(st->cache.str, &st->cache.size);

    TRC(printf("ext2fs: buf is %d bytes at %p\n", st->cache.size,
	       st->cache.buf));
    if (st->cache.size < blockcache_size) {
	printf("ext2fs: warning: couldn't allocate a large blockcache\n");
    }

    /* Now we can get at the disk. Read the superblock, and calculate
       constants from it. */
    if (!read_superblock(st)) {
	printf("ext2fs: couldn't read superblock\n");
	shutdown_usd(st);
	RAISE_MountLocal$BadFS(MountLocal_Problem_BadSuperblock);
    }

    /* XXX should sanity check filesystem size with partition size */
    TRC(printf("ext2fs: filesystem size %d blocks (%d phys)\n"
	   "	    partition size %d blocks (%d phys)\n",
	   st->superblock->s_blocks_count,
	   PHYS_BLKS(st, st->superblock->s_blocks_count),
	   LOGICAL_BLKS(st, st->disk.partition_size),
	   st->disk.partition_size));
    if (st->disk.partition_size < 
	PHYS_BLKS(st, st->superblock->s_blocks_count)) {
	printf("WARNING - filesystem is larger than partition **********\n");
	/* XXX should probably give up now */
    }

    /* Now that we know the logical block size we can initialise the block
       cache */
    init_block_cache(st);

    /* From this point on, all access to the filesystem should be done
       through the block cache. DON'T call logical_read, call bread
       instead. Remember to free blocks once you're finished with them. */

    init_groups(st);

    if(!init_inodes(st)) {
	fprintf(stderr, "ext2fs: failed to initialise inode cache.\n");
	shutdown_usd(st);
	RAISE_MountLocal$Failure();
    }

    /* Checking this probably isn't a bad idea, but let's wait until later */

    /* Ok, now we are capable of reading the root inode (I hope!) */
    TRC(printf("ext2fs: checking root inode.\n"));
    root = get_inode(st, EXT2_ROOT_INO);
    if(!root) {
	fprintf(stderr, "ext2fs: failed to read root inode.\n");
	shutdown_usd(st);
	RAISE_MountLocal$BadFS(MountLocal_Problem_BadRoot);
    }
    
    if(!S_ISDIR(root->i_mode)) {
	fprintf(stderr, "ext2fs: urk!\n"
		"	 inode %d does not refer to a directory\n", 
		EXT2_ROOT_INO);
	shutdown_usd(st);
	RAISE_MountLocal$BadFS(MountLocal_Problem_BadRoot);
    }

    release_inode(st, root);

    /* *thinks* should probably do something about deallocating state
       if we fail, too. */

    /* Initialise the list of clients */
    LINK_INIT(&st->client.clients);
    /* We create a server for the local domain; it lives in the head
       of the list of clients. The call to CSIDCTransport$Offer() will
       set up client-side stubs for this domain and put them in the
       object table. */
    create_client(st, &st->client.clients, NULL);

    /* Now we do all the export stuff */
    CL_INIT(st->client.callback, &client_callback_ms, st);
    ANY_INIT(&any, Ext2_clp, &st->client.clients.cl);
    stubmod_clp = Heap$Malloc(st->heap, sizeof(*stubmod_clp)); 
    CLP_INIT(stubmod_clp, &stubmod_ms, NULL);
    res = CSIDCTransport$Offer (
	st->csidc, &any, FSClient_clp__code, stubmod_clp,
	&st->client.callback, /* XXX produces a warning */
	st->heap, Pvs(gkpr), st->client.entry, &st->client.service);

    TRC(printf("ext2fs: offer at %p\n",res));

    return res;
}
int main(int argc, char *argv[]) {
	char * bytes_count_str = NULL;
	char * devname;
	struct stat statbuf;
	int c;

	int dev;
	struct reiserfs_super_block *sb, *sb_old;
	
	while ((c = getopt(argc, argv, "fvcqs:")) != EOF) {
		switch (c) {
		case 's' :
			  if (!optarg) 
				  die("%s: Missing argument to -s option", argv[0]);		
			  bytes_count_str = optarg;
			  break;
		case 'f':
		    opt_force = 1;
		    break;		 
		case 'v':
			opt_verbose++; 
			break;
		case 'n':
			/* no nowrite option at this moment */
			/* opt_nowrite = 1; */
			break;
		case 'c':
			opt_safe = 1;
			break;
		case 'q':
			opt_verbose = 0;
			break;
		default:
			print_usage_and_exit ();
		}
	}

	if (optind == argc || (!bytes_count_str))
		print_usage_and_exit();
	devname = argv[optind];

	/* open_device will die if it could not open device */
	dev = open (devname, O_RDWR);
	if (dev == -1)
		die ("%s: can not open '%s': %s", argv[0], devname, strerror (errno));

	if (fstat (dev, &statbuf) < 0)
		die ("%s: unable to stat %s", argv[0], devname);
  
	if (!S_ISBLK (statbuf.st_mode) && opt_force )
		die ("%s: '%s (%o)' is not a block device", 
			 argv[0], devname, statbuf.st_mode);

	read_superblock(dev);
	
	sb = (struct reiserfs_super_block *) g_sb_bh->b_data;
	g_block_count_new = calc_new_fs_size(sb->s_block_count,
					     sb->s_blocksize, bytes_count_str);
	if (is_mounted (devname)) {
		close(dev);
		if (!opt_force) 
	    	die ("%s: '%s' contains a mounted file system,\n"
			     "\tspecify -f option to resize the fs online\n", 
				 argv[0], devname);
		resize_fs_online(devname, g_block_count_new);
		return 0;
	}	

	if (sb->s_state != REISERFS_VALID_FS) 
		die ("%s: the file system isn't in valid state\n", argv[0]);
		
	if(!valid_offset(dev, (loff_t) g_block_count_new * sb->s_blocksize - 1))
		die ("%s: %s too small", argv[0], devname);

	sb_old = 0;		/* Needed to keep idiot compiler from issuing false warning */
	/* save SB for reporting */
	if(opt_verbose) {
		sb_old = getmem(sizeof(struct reiserfs_super_block));
		memcpy(sb_old, sb, sizeof(struct reiserfs_super_block));
    }

	if (g_block_count_new == sb->s_block_count) 
		die ("%s: Calculated fs size is the same as the previous one.",
			 argv[0]);
	if (g_block_count_new > sb->s_block_count) 
		expand_fs();
	else
		shrink_fs(g_block_count_new);

	if(opt_verbose) {
		sb_report(sb, sb_old);
		freemem(sb_old);
	}

	check_and_free_mem ();		
	
	if (opt_verbose) {
		printf("\nSyncing..");
		fflush(stdout);
	}
	fsync (dev);
	if (opt_verbose)
		printf("done\n");
	

	close(dev);
	
	return 0;
}
Beispiel #12
0
int
g_journal_ufs_exists(const char *prov)
{

	return (read_superblock(prov) != NULL);
}
Beispiel #13
0
struct file_struct *zfs_request_file(const char *filename,char *op){
	struct file_struct *ret = malloc(1024);
	int found = 0;
	if(strcmp(op,"r") == 0){
		ret->posx = 0;
		ret->posy = 0;
		ret->pos = 0;
		ret->filename = (char*)filename;
		ret->opperation = OP_READ;
		struct zfs_superblock *sblk = malloc(1024);
		read_superblock(sblk);
		int i = 0;
		int j = sblk->fds;
		int n = sblk->dataresv;
		//int found;
		while(i < n){
			char *buf = malloc(1024);
			ata_read_master(buf,j,0);
			struct data *data = malloc(1024);
			int k = 0;
			int a = 0;
			int b = 30;
			while(k < b){
				data->alloc = buf[a * k];
				data->islongname = buf[a * k + 1];
				if(data->alloc == 0){
					a++;k++;
					continue;
				}
				else if(data->islongname && strlen(filename) > 10){
					data->namelen = buf[a * k + 2];
					b-=(data->namelen / 10);
					data->name = malloc(1024);
					int c;
					for( c = 0; c < data->namelen;c++){
						data->name[c] = buf[a * k + 3 + c];
					}
					if(strcmp(data->name,filename) == 0){
						found = 1;
						ret->offset = a * k + 3 + c;
						ret->startingblock = buf[a * k  + data->namelen + 4] << 16 | buf[a * k + data->namelen + 5] << 8 | buf[a * k + data->namelen +6];
						ret->endingblock = buf[a * k + data->namelen + 7] << 16 | buf[a * k + data->namelen + 8] << 8 | buf[a * k + data->namelen + 9];
						ret->endingpos = buf[a * k + data->namelen + 11] << 8 | buf[a * k + data->namelen + 12];
						ret->blockpos = ret->startingblock;
						break;
					}


				}
				else if(strlen(filename) < 10 && data->islongname){
					a++;k++;
					continue;
				}
				else if(strlen(filename) < 10 && !(data->islongname)){
					data->name = malloc(1024);
					int c;
					for(c = 0; c < 10;c++){
						data->name[c] = buf[a * k + 3 + c];
					}
					if(strcmp(data->name,filename) == 0){
						found = 1;
						ret->offset = a * k + 13;
						ret->startingblock = buf[a * k + 14] << 16 | buf[a * k + 15] << 8 | buf[a * k + 16];
						ret->endingblock = buf[a * k + 17] << 16 | buf[a * k + 18] << 8 | buf[a * k + 19];
						ret->endingpos = buf[a * k + 20] << 8 | buf[a * k + 21];
						ret->blockpos = ret->startingblock;
						break;
					}
				}
				a++;
				k++;
			}
			i++;j++;
		}
	}
	if(found != 1){
		kprintf("Aborted:Couldn't find file\n");
		return (struct file_struct *)-1;
	}
	/*char *fbuf = malloc(512 * (ret->endingblock - ret->startingblock));
	char *blk = malloc(1024);
	int d;
	int f = 0;
	for(d = ret->startingblock; d < ret->endingblock;d++){
		ata_read_master(blk,d,0);
		for(int e = 0; e < 512;e++,f++){
			fbuf[f] = blk[e];
		}
		blk = malloc(1024);
	}*/
	return ret;
}