Exemplo n.º 1
0
static int sfs_fill_super(struct super_block *sb, void *data, int silent)
{
	sfs_info_t *info;

	printk(KERN_INFO "sfs: sfs_fill_super\n");
	if (!(info = (sfs_info_t *)(kzalloc(sizeof(sfs_info_t), GFP_KERNEL))))
		return -ENOMEM;
	info->vfs_sb = sb;
	if (init_browsing(info) < 0)
	{
		kfree(info);
		return -EIO;
	}
	/* Updating the VFS super_block */
	sb->s_magic = info->sb.type;
	sb->s_blocksize = info->sb.block_size;
	sb->s_blocksize_bits = get_bit_pos(info->sb.block_size);
	sb->s_type = &sfs; // file_system_type
	sb->s_op = &sfs_sops; // super block operations

	sfs_root_inode = iget_locked(sb, ROOT_INODE_NUM); // obtain an inode from VFS
	if (!sfs_root_inode)
	{
		shut_browsing(info);
		kfree(info);
		return -EACCES;
	}
	if (sfs_root_inode->i_state & I_NEW) // allocated fresh now
	{
		printk(KERN_INFO "sfs: Got new root inode, let's fill in\n");
		sfs_root_inode->i_op = &sfs_iops; // inode operations
		sfs_root_inode->i_mode = S_IFDIR | S_IRWXU | S_IRWXG | S_IRWXO;
		sfs_root_inode->i_fop = &sfs_fops; // file operations
		sfs_root_inode->i_mapping->a_ops = &sfs_aops; // address operations
		unlock_new_inode(sfs_root_inode);
	}
	else
	{
		printk(KERN_INFO "sfs: Got root inode from inode cache\n");
	}

#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
	sb->s_root = d_alloc_root(sfs_root_inode);
#else
	sb->s_root = d_make_root(sfs_root_inode);
#endif
	if (!sb->s_root)
	{
		iget_failed(sfs_root_inode);
		shut_browsing(info);
		kfree(info);
		return -ENOMEM;
	}

	return 0;
}
Exemplo n.º 2
0
static void sfs_kill_sb(struct super_block *sb)
{
	sfs_info_t *info = (sfs_info_t *)(sb->s_fs_info);
	if (info)
	{
		shut_browsing(info);
		kfree(info);
	}
	kill_block_super(sb);
}
void browse_sfs(int sfs_handle)
{
	int done;
	char cmd[256], *fn;
	int ret, perm;

	done = 0;

	printf("Welcome to SFS Browsing Shell v3.0\n\n");
	printf("Block size     : %d bytes\n", sb.block_size);
	printf("Partition size : %d blocks\n", sb.partition_size);
	printf("File entry size: %d bytes\n", sb.entry_size);
	printf("Entry tbl size : %d blocks\n", sb.entry_table_size);
	printf("Entry count    : %d\n", sb.entry_count);
	printf("\n");
	init_browsing(sfs_handle);
	while (!done)
	{
		printf(" $> ");
		ret = scanf("%[^\n]", cmd);
		if (ret < 0)
		{
			done = 1;
			printf("\n");
			continue;
		}
		else
		{
			getchar();
			if (ret == 0) continue;
		}
		if (strcmp(cmd, "?") == 0)
		{
			usage();
			continue;
		}
		else if (strcmp(cmd, "quit") == 0)
		{
			done = 1;
			continue;
		}
		else if (strcmp(cmd, "list") == 0)
		{
			sfs_list(sfs_handle);
			continue;
		}
		else if (strncmp(cmd, "create", 6) == 0)
		{
			if (cmd[6] == ' ')
			{
				fn = cmd + 7;
				while (*fn == ' ') fn++;
				if (*fn != '\0')
				{
					sfs_create(sfs_handle, fn);
					continue;
				}
			}
		}
		else if (strncmp(cmd, "remove", 6) == 0)
		{
			if (cmd[6] == ' ')
			{
				fn = cmd + 7;
				while (*fn == ' ') fn++;
				if (*fn != '\0')
				{
					sfs_remove(sfs_handle, fn);
					continue;
				}
			}
		}
		else if (strncmp(cmd, "chperm", 6) == 0)
		{
			if (cmd[6] == ' ')
			{
				perm = cmd[7] - '0';
				if ((0 <= perm) && (perm <= 7) &&  (cmd[8] == ' '))
				{
					fn = cmd + 9;
					while (*fn == ' ') fn++;
					if (*fn != '\0')
					{
						sfs_chperm(sfs_handle, fn, perm);
						continue;
					}
				}
			}
		}
		else if (strncmp(cmd, "read", 4) == 0)
		{
			if (cmd[4] == ' ')
			{
				fn = cmd + 5;
				while (*fn == ' ') fn++;
				if (*fn != '\0')
				{
					sfs_read(sfs_handle, fn);
					continue;
				}
			}
		}
		else if (strncmp(cmd, "write", 5) == 0)
		{
			if (cmd[5] == ' ')
			{
				fn = cmd + 6;
				while (*fn == ' ') fn++;
				if (*fn != '\0')
				{
					sfs_write(sfs_handle, fn);
					continue;
				}
			}
		}
		printf("Unknown/Incorrect command: %s\n", cmd);
		usage();
	}
	shut_browsing(sfs_handle);
}