Ejemplo n.º 1
0
static int
ospfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
{
	ospfs_inode_t *dir_oi = ospfs_inode(dir->i_ino);
	uint32_t entry_ino = 0;

	ospfs_symlink_inode_t *symlink_inode;

	if (find_direntry(dir_oi, dentry->d_name.name, dentry->d_name.len))
		return -EEXIST;

	if (strlen(symname) > OSPFS_MAXSYMLINKLEN || dentry->d_name.len > OSPFS_MAXNAMELEN)
		return -ENAMETOOLONG;

	// create a blank direntry, and return error if bad things happen
	ospfs_direntry_t* od = create_blank_direntry(dir_oi);
	if (IS_ERR(od)) {
		return PTR_ERR(od);
	}

	// find empty inode by linear searching the inodes
	for (entry_ino = 0; entry_ino < ospfs_super->os_ninodes; entry_ino++) {
		if (!ospfs_inode(entry_ino)->oi_nlink)
			break;
	}

	// entry_ino is now either a ptr to an empty inode we can use or ninodes (no space)

	if (entry_ino == ospfs_super->os_ninodes)
		return -ENOSPC;

	// write directory entry (inode number and the name)
	od->od_ino = entry_ino;
	memcpy(od->od_name, dentry->d_name.name, dentry->d_name.len);
	od->od_name[dentry->d_name.len] = '\0';

	symlink_inode = ospfs_inode(entry_ino);

	// set values in inode
	symlink_inode->oi_nlink = 1;
	symlink_inode->oi_size = strlen(symname);
	symlink_inode->oi_ftype = OSPFS_FTYPE_SYMLINK;
	memcpy(symlink_inode->oi_symlink, symname, strlen(symname));
	symlink_inode->oi_symlink[strlen(symname)] = '\0';
	

	/* Execute this code after your function has successfully created the
	   file.  Set entry_ino to the created file's inode number before
	   getting here. */
	{
		struct inode *i = ospfs_mk_linux_inode(dir->i_sb, entry_ino);
		if (!i)
			return -ENOMEM;
		d_instantiate(dentry, i);
		return 0;
	}
}
Ejemplo n.º 2
0
static int
ospfs_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *nd)
{
	ospfs_inode_t *dir_oi = ospfs_inode(dir->i_ino);
	uint32_t entry_ino = 0;

	// if the entry is found, it already exists
	if (find_direntry(dir, dentry->d_name.name, dentry->d_name.len))
		return -EEXIST;

	// if entry name is too long
	if (dentry->d_name.len > OSPFS_MAXNAMELEN)
		return -ENAMETOOLONG;
	
	// create a blank direntry, and return error if bad things happen
	ospfs_direntry_t* od = create_blank_direntry(dir_oi);
	if (IS_ERR(od)) {
		return PTR_ERR(od);
	}

	// find empty inode by linear searching the inodes
	for (entry_ino = 0; entry_ino < ospfs_super->os_ninodes; entry_ino++) {
		if (!ospfs_inode(entry_ino)->oi_nlink)
			break;
	}

	// entry_ino is now either a ptr to an empty inode we can use or ninodes (no space)

	if (entry_ino == ospfs_super->os_ninodes)
		return -ENOSPC;

	od->od_ino = entry_ino;
	memcpy(od->od_name, dentry->d_name.name, dentry->d_name.len);
	od->od_name[dentry->d_name.len] = '\0';

	ospfs_inode_t* inode = ospfs_inode(entry_ino);

	// set values in inode
	inode->oi_mode = mode;
	inode->oi_nlink = 1;
	inode->oi_size = 0;
	inode->oi_ftype = OSPFS_FTYPE_REG;
	memset(inode->oi_direct, 0, sizeof(inode->oi_direct[0]) * OSPFS_NDIRECT);
	inode->oi_indirect = 0;
	inode->oi_indirect2 = 0;

	/* Execute this code after your function has successfully created the
	   file.  Set entry_ino to the created file's inode number before
	   getting here. */
	{
		struct inode *i = ospfs_mk_linux_inode(dir->i_sb, entry_ino);
		if (!i)
			return -ENOMEM;
		d_instantiate(dentry, i);
		return 0;
	}
}
Ejemplo n.º 3
0
static int
ospfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
{
	//eprintk("simlink");
	ospfs_inode_t *dir_oi = ospfs_inode(dir->i_ino);
	uint32_t entry_ino = 0;
	//EXERCISE: Your code here. 
	if (dentry->d_name.len > OSPFS_MAXNAMELEN)
		return -ENAMETOOLONG;
	if (find_direntry(dir_oi, dentry->d_name.name, dentry->d_name.len))
		return -EEXIST;
	//create a new symlink inode
	ospfs_inode_t *free_inode = ospfs_block(ospfs_super->os_firstinob);
	uint32_t count = 1;
	while(count<ospfs_super->os_ninodes)
	{
		if (free_inode[count].oi_nlink == 0)
			break;
		count++;
	}
	//no free inode
	if (count == ospfs_super->os_ninodes)
	{
		count = 0;
		return -ENOSPC;
	}
	else 
		entry_ino = count;
	//create new inode and entry;
	ospfs_symlink_inode_t* symlink_oi = ospfs_inode(entry_ino);
	ospfs_direntry_t * sym_dentry = create_blank_direntry(dir_oi);
	if (IS_ERR(sym_dentry))
		return PTR_ERR(sym_dentry);
	//init symlink inode:
	if (strlen(symname)>OSPFS_MAXSYMLINKLEN)
		return -ENAMETOOLONG;
	symlink_oi->oi_size = strlen(symname);
	symlink_oi->oi_ftype = OSPFS_FTYPE_SYMLINK;
	symlink_oi->oi_nlink = 1;
	memcpy (symlink_oi->oi_symlink, symname, strlen(symname)); 
	symlink_oi->oi_symlink[strlen(symname)] = '\0';
	memcpy (sym_dentry->od_name, dentry->d_name.name, dentry->d_name.len);
	sym_dentry->od_name[dentry->d_name.len] = '\0';
	sym_dentry->od_ino = entry_ino;

	 //Execute this code after your function has successfully created the
	   //file.  Set entry_ino to the created file's inode number before
	   //getting here. 
	{
		struct inode *i = ospfs_mk_linux_inode(dir->i_sb, entry_ino);
		if (!i)
			return -ENOMEM;
		d_instantiate(dentry, i);
		return 0;
	}
}
Ejemplo n.º 4
0
static int
ospfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
{
	ospfs_inode_t *dir_oi = ospfs_inode(dir->i_ino);
	uint32_t entry_ino = 0;
	ospfs_direntry_t *entry = NULL;
	ospfs_symlink_inode_t *symlink = NULL;
	/* EXERCISE: Your code here. */
	
	if(dentry->d_name.len > OSPFS_MAXNAMELEN || strlen(symname) > OSPFS_MAXNAMELEN) {
		return -ENAMETOOLONG;
	}
	if(find_direntry(dir_oi,dentry->d_name.name,dentry->d_name.len)) {
		return -EEXIST; 
	}
	
	entry = create_blank_direntry(dir_oi);
	if (IS_ERR(entry)) {
		return PTR_ERR(entry);
	}
	
	while(entry_ino < ospfs_super->os_ninodes) {
		symlink = ospfs_inode(entry_ino);
		if(symlink != NULL && symlink->oi_nlink == 0) {
			break;
		}
		entry_ino++;
	}
	
	if (entry_ino == ospfs_super->os_ninodes) {
		return -ENOSPC;
	}
	
	symlink->oi_size = strlen(symname);
	symlink->oi_ftype = OSPFS_FTYPE_SYMLINK;
	symlink->oi_nlink = 1;
	strncpy(symlink->oi_symlink,symname,symlink->oi_size);
	symlink->oi_symlink[symlink->oi_size] = 0;
	dir_oi->oi_nlink++;
	
	entry->od_ino = entry_ino;
	strncpy(entry->od_name,dentry->d_name.name, dentry->d_name.len);
	entry->od_name[dentry->d_name.len] = 0; 
	
	
	/* Execute this code after your function has successfully created the
	   file.  Set entry_ino to the created file's inode number before
	   getting here. */
	{
		struct inode *i = ospfs_mk_linux_inode(dir->i_sb, entry_ino);
		if (!i)
			return -ENOMEM;
		d_instantiate(dentry, i);
		return 0;
	}
}
Ejemplo n.º 5
0
static int
ospfs_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *nd)
{
	ospfs_inode_t *dir_oi = ospfs_inode(dir->i_ino);
	uint32_t entry_ino = 0;
	ospfs_direntry_t *entry = NULL;
	ospfs_inode_t *temp = NULL;
	/* EXERCISE: Your code here. */
	
	if (dentry->d_name.len > OSPFS_MAXNAMELEN) {
		return -ENAMETOOLONG;
	}
	
	if (find_direntry(ospfs_inode(dir->i_ino), dentry->d_name.name, dentry->d_name.len) != NULL) {
		return -EEXIST;
	}
	
	entry = create_blank_direntry(dir_oi);
	if (IS_ERR(entry)) {
		return PTR_ERR(entry);
	}
	
	while(entry_ino < ospfs_super->os_ninodes) {
		temp = ospfs_inode(entry_ino);
		if(temp != NULL && temp->oi_nlink == 0) {
			break;
		}
		entry_ino++;
	}
	
	if (entry_ino == ospfs_super->os_ninodes) {
		return -ENOSPC;
	}
	
	temp->oi_size = 0;
	temp->oi_ftype = OSPFS_FTYPE_REG;
	temp->oi_nlink = 1;
	temp->oi_mode = mode;
	temp->oi_direct[0] = 0;
	dir_oi->oi_nlink++;
	
	entry->od_ino = entry_ino;
	memcpy(entry->od_name, dentry->d_name.name, dentry->d_name.len);
	entry->od_name[dentry->d_name.len] = 0;

	/* Execute this code after your function has successfully created the
	   file.  Set entry_ino to the created file's inode number before
	   getting here. */
	{
		struct inode *i = ospfs_mk_linux_inode(dir->i_sb, entry_ino);
		if (!i)
			return -ENOMEM;
		d_instantiate(dentry, i);
		return 0;
	}
}
Ejemplo n.º 6
0
static int
ospfs_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *nd)
{
	ospfs_inode_t *dir_oi = ospfs_inode(dir->i_ino);
	ospfs_direntry_t *dir_entry;
	ospfs_inode_t *inode;
	uint32_t entry_ino = 0;

	// check if name too long
	if (dentry->d_name.len > OSPFS_MAXNAMELEN)
        return -ENAMETOOLONG;
	// check if directory entry already exists
	if (find_direntry(dir_oi, dentry->d_name.name, dentry->d_name.len))
		return -EEXIST;

	// create new directory entry
	dir_entry = create_blank_direntry(dir_oi);
	if (IS_ERR(dir_entry))
		return PTR_ERR(dir_entry);

	// find empty inode
	for (entry_ino = 0; entry_ino < ospfs_super->os_ninodes; entry_ino++) {
		inode = ospfs_inode(entry_ino);
		if (inode->oi_nlink == 0)
			break; // empty inode
	}
	if (entry_ino == ospfs_super->os_ninodes)
		return -ENOSPC;

	// initialize directory entry
	dir_entry->od_ino = entry_ino;
	memcpy(dir_entry->od_name, dentry->d_name.name, dentry->d_name.len);
	dir_entry->od_name[dentry->d_name.len] = '\0';
	// initialize file
	inode->oi_size = 0;
	inode->oi_ftype = OSPFS_FTYPE_REG;
	inode->oi_mode = mode;
	inode->oi_nlink = 1;

	/* Execute this code after your function has successfully created the
	   file.  Set entry_ino to the created file's inode number before
	   getting here. */
	{
		struct inode *i = ospfs_mk_linux_inode(dir->i_sb, entry_ino);
		if (!i)
			return -ENOMEM;
		d_instantiate(dentry, i);
		return 0;
	}
}
Ejemplo n.º 7
0
static int
ospfs_fill_super(struct super_block *sb, void *data, int flags)
{
	struct inode *root_inode;

	sb->s_blocksize = OSPFS_BLKSIZE;
	sb->s_blocksize_bits = OSPFS_BLKSIZE_BITS;
	sb->s_magic = OSPFS_MAGIC;
	sb->s_op = &ospfs_superblock_ops;

	if (!(root_inode = ospfs_mk_linux_inode(sb, OSPFS_ROOT_INO))
	    || !(sb->s_root = d_alloc_root(root_inode))) {
		iput(root_inode);
		sb->s_dev = 0;
		return -ENOMEM;
	}

	return 0;
}
Ejemplo n.º 8
0
static int
ospfs_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *nd)
{
	ospfs_inode_t *dir_oi = ospfs_inode(dir->i_ino);
	uint32_t entry_ino = 0;
	/* EXERCISE: Your code here. */
	return -EINVAL; // Replace this line

	/* Execute this code after your function has successfully created the
	   file.  Set entry_ino to the created file's inode number before
	   getting here. */
	{
		struct inode *i = ospfs_mk_linux_inode(dir->i_sb, entry_ino);
		if (!i)
			return -ENOMEM;
		d_instantiate(dentry, i);
		return 0;
	}
}
Ejemplo n.º 9
0
static struct dentry *
ospfs_dir_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *ignore)
{
	// Find the OSPFS inode corresponding to 'dir'
	ospfs_inode_t *dir_oi = ospfs_inode(dir->i_ino);
	struct inode *entry_inode = NULL;
	int entry_off;

	// Make sure filename is not too long
	if (dentry->d_name.len > OSPFS_MAXNAMELEN)
		return (struct dentry *) ERR_PTR(-ENAMETOOLONG);

	// Mark with our operations
	dentry->d_op = &ospfs_dentry_ops;

	// Search through the directory block
	for (entry_off = 0; entry_off < dir_oi->oi_size;
	     entry_off += OSPFS_DIRENTRY_SIZE) {
		// Find the OSPFS inode for the entry
		ospfs_direntry_t *od = ospfs_inode_data(dir_oi, entry_off);

		// Set 'entry_inode' if we find the file we are looking for
		if (od->od_ino > 0
		    && strlen(od->od_name) == dentry->d_name.len
		    && memcmp(od->od_name, dentry->d_name.name, dentry->d_name.len) == 0) {
			entry_inode = ospfs_mk_linux_inode(dir->i_sb, od->od_ino);
			if (!entry_inode)
				return (struct dentry *) ERR_PTR(-EINVAL);
			break;
		}
	}

	// We return a dentry whether or not the file existed.
	// The file exists if and only if 'entry_inode != NULL'.
	// If the file doesn't exist, the dentry is called a "negative dentry".

	// d_splice_alias() attaches the inode to the dentry.
	// If it returns a new dentry, we need to set its operations.
	if ((dentry = d_splice_alias(entry_inode, dentry)))
		dentry->d_op = &ospfs_dentry_ops;
	return dentry;
}
Ejemplo n.º 10
0
static int
ospfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
{
	ospfs_inode_t *dir_oi = ospfs_inode(dir->i_ino);
	uint32_t entry_ino = 0;
	ospfs_symlink_inode_t* link;

	// check if name too long
	if (dentry->d_name.len > OSPFS_MAXNAMELEN ||
		strlen(symname) > OSPFS_MAXSYMLINKLEN)
        return -ENAMETOOLONG;
	// check if directory entry already exists
	if (find_direntry(ospfs_inode(dir->i_ino),
		dentry->d_name.name, dentry->d_name.len))
		return -EEXIST;

	// create new symlinked file
	entry_ino = ospfs_create(dir, dentry, dir_oi->oi_mode, NULL);
	if (entry_ino < 0)
		return entry_ino;
	entry_ino = find_direntry(ospfs_inode(dir->i_ino),
		dentry->d_name.name, dentry->d_name.len)->od_ino;
	link = (ospfs_symlink_inode_t*) ospfs_inode(entry_ino);

	// copy file information
	link->oi_size = strlen(symname);
	link->oi_ftype = OSPFS_FTYPE_SYMLINK;
	link->oi_nlink = 1;
	memcpy(link->oi_symlink, symname, strlen(symname));

	/* Execute this code after your function has successfully created the
	   file.  Set entry_ino to the created file's inode number before
	   getting here. */
	{
		struct inode *i = ospfs_mk_linux_inode(dir->i_sb, entry_ino);
		if (!i)
			return -ENOMEM;
		d_instantiate(dentry, i);
		return 0;
	}
}
Ejemplo n.º 11
0
static int
ospfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
{
	ospfs_inode_t *dir_oi = ospfs_inode(dir->i_ino);
	uint32_t entry_ino = 0;

	/* EXERCISE: Your code here. */
	ospfs_direntry_t *od;
	ospfs_symlink_inode_t *oi = NULL;
	if (dentry->d_name.len > OSPFS_MAXNAMELEN || strlen(symname) > OSPFS_MAXSYMLINKLEN)
		return -ENAMETOOLONG;
	if (find_direntry(dir_oi, dentry->d_name.name, dentry->d_name.len))
		return -EEXIST;
	od = create_blank_direntry(dir_oi);
	if (IS_ERR(od))
		return -ENOSPC;
	for (entry_ino = 2; entry_ino < ospfs_super->os_ninodes; entry_ino++) {
		oi = (ospfs_symlink_inode_t *) ospfs_inode(entry_ino);
		if (oi->oi_nlink == 0)
			break;
	}
	if (entry_ino == ospfs_super->os_ninodes)
		return -EIO;
	od->od_ino = entry_ino;
	strcpy(od->od_name, dentry->d_name.name);
	oi->oi_size = strlen(symname);
	oi->oi_ftype = OSPFS_FTYPE_SYMLINK;
	oi->oi_nlink = 1;
	strcpy(oi->oi_symlink, symname);

	/* Execute this code after your function has successfully created the
	   file.  Set entry_ino to the created file's inode number before
	   getting here. */
	{
		struct inode *i = ospfs_mk_linux_inode(dir->i_sb, entry_ino);
		if (!i)
			return -ENOMEM;
		d_instantiate(dentry, i);
		return 0;
	}
}
Ejemplo n.º 12
0
static int
ospfs_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *nd)
{
	ospfs_inode_t *dir_oi = ospfs_inode(dir->i_ino);
	uint32_t entry_ino = 0;
	/* EXERCISE: Your code here. */
	//return -EINVAL; // Replace this line
	if (dir_oi == NULL)
		return -EIO;
	if (dentry->d_name.len > OSPFS_MAXNAMELEN)
	{
		return -ENAMETOOLONG;
	}
	// find_direntry(dir_oi, name, namelen)
	if (find_direntry(dir_oi, dentry->d_name.name, dentry->d_name.len))
		return -EEXIST;
	//find a free inode
	// ospfs_block(blockno)
//	Use this function to load a block's contents from "disk".
	ospfs_inode_t* free_inode = ospfs_block(ospfs_super->os_firstinob);
	uint32_t count = 1;
	while(count<ospfs_super->os_ninodes)
	{
		if (free_inode[count].oi_nlink == 0)
			break;
		count++;
	}
	//no free inode
	if (count == ospfs_super->os_ninodes)
	{
		count = 0;
		return -ENOSPC;
	}
	else 
		entry_ino = count;
	
	//initialize inode:
	ospfs_inode_t* new_ino = NULL;
	new_ino = ospfs_inode (entry_ino);
	new_ino -> oi_size = 0;
	new_ino -> oi_ftype = OSPFS_FTYPE_REG;
	new_ino -> oi_nlink = 1;
	new_ino -> oi_mode = mode;
	//initialize entry:
	ospfs_direntry_t* new_dentry = create_blank_direntry(dir_oi);
	if (IS_ERR(new_dentry))
		return PTR_ERR (new_dentry);
	new_dentry->od_ino = entry_ino;
	
	memcpy (new_dentry->od_name, dentry->d_name.name, dentry->d_name.len);
	new_dentry->od_name[dentry->d_name.len]='\0';





	/* Execute this code after your function has successfully created the
	   file.  Set entry_ino to the created file's inode number before
	   getting here. */
	{
		struct inode *i = ospfs_mk_linux_inode(dir->i_sb, entry_ino);
		if (!i)
			return -ENOMEM;
		d_instantiate(dentry, i);
		return 0;
	}
}
Ejemplo n.º 13
0
static int
ospfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
{
	ospfs_inode_t *dir_oi = ospfs_inode(dir->i_ino);
	uint32_t entry_ino = 0;

	/* EXERCISE: Your code here. */
	//Error checking..
	if(!dir_oi)
		return -EIO;
	if(dentry->d_name.len > OSPFS_MAXNAMELEN || strlen(symname) > OSPFS_MAXSYMLINKLEN)
		return -ENAMETOOLONG; 
	if(find_direntry(dir_oi, dentry->d_name.name, dentry->d_name.len))
		return -EEXIST;

	//Find free inode in inode block
	int i;
	for(i = ospfs_super->os_firstinob; i < ospfs_super->os_ninodes; i++){
		//Break if inode is free
		ospfs_inode_t *oi = ospfs_inode(i);
		if(oi->oi_nlink == 0)
			break;		
	}
	
	//Could not find any free inodes.
	if(i >= ospfs_super->os_ninodes)
		return -ENOSPC;

	//set up new empty node and names	
	ospfs_symlink_inode_t *symlink = (ospfs_symlink_inode_t*)ospfs_inode(i);
	symlink->oi_size = strlen(symname);
	symlink->oi_ftype = OSPFS_FTYPE_SYMLINK;
	memcpy(symlink->oi_symlink, symname, strlen(symname));

	//Find an empty direntry to store new file
	ospfs_direntry_t *od = create_blank_direntry(dir_oi);
	if(IS_ERR(od))
		return PTR_ERR(od);
	od->od_ino = i;
	memcpy(od->od_name, dentry->d_name.name, dentry->d_name.len);
	//add null character
	od->od_name[dentry->d_name.len] = 0;
	//ospfs_symlink_inode_t *symlink = ospfs_inode(entry_ino); //create sym link

	//for conditional symbolic links
	char* q_ptr = strpbrk(symname, "?");
	char* c_ptr = strpbrk(symname, ":");
	if(q_ptr && c_ptr)
	{
		memcpy(symlink->oi_symlink + strlen(symname) + 1, q_ptr, c_ptr-q_ptr - 1);

	}
	/* Execute this code after your function has successfully created the
	   file.  Set entry_ino to the created file's inode number before
	   getting here. */
	{
		struct inode *i = ospfs_mk_linux_inode(dir->i_sb, entry_ino);
		if (!i)
			return -ENOMEM;
		d_instantiate(dentry, i);
		return 0;
	}
}
Ejemplo n.º 14
0
static int
ospfs_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *nd)
{
	ospfs_inode_t *dir_oi = ospfs_inode(dir->i_ino);
	uint32_t entry_ino = 0;

	/* EXERCISE: Your code here. */
	//Check if file name is too long
	if(dentry->d_name.len > OSPFS_MAXNAMELEN)
		return -ENAMETOOLONG;

	//Check if file already exists in directory
	if(find_direntry(dir_oi, dentry->d_name.name, dentry->d_name.len))
		return -EEXIST;
	
	//Find an empty direntry to store new file
	ospfs_direntry_t *od = create_blank_direntry(dir_oi);
	if(IS_ERR(od))
		return PTR_ERR(od);
	
	//Find free inode in inode block
	int i;
	for(i = ospfs_super->os_firstinob; i < ospfs_super->os_ninodes; i++){
		//Break if inode is free
		ospfs_inode_t *oi = ospfs_inode(i);
		if(oi->oi_nlink == 0)
			break;		
	}
	
	//Could not find any free inodes.
	if(i >= ospfs_super->os_ninodes)
		return -ENOSPC;

	//Store new file in empty direntry
	od->od_ino = i;
	
	int j;
	for(j = 0; j < dentry->d_name.len; j++){
		od->od_name[j] = dentry->d_name.name[j];
	}
	od->od_name[j] = '\0';

	//Set inode
	ospfs_inode_t *oi = ospfs_inode(i);
	oi->oi_size = 0;
	oi->oi_ftype = OSPFS_FTYPE_REG;
	oi->oi_nlink = 1;
	oi->oi_mode = mode;
	oi->oi_indirect = 0;
	oi->oi_indirect2 = 0;
	int k;
	for(k = 0; k < OSPFS_NDIRECT; k++){
		oi->oi_direct[k] = 0;	
	}

	//eprintk("create:%d,  %s\n", i, dentry->d_name.name);

	entry_ino = od->od_ino;
	/* Execute this code after your function has successfully created the
	   file.  Set entry_ino to the created file's inode number before
	   getting here. */
	{
		struct inode *i = ospfs_mk_linux_inode(dir->i_sb, entry_ino);
		if (!i)
			return -ENOMEM;
		d_instantiate(dentry, i);
		return 0;
	}
}
Ejemplo n.º 15
0
static int
ospfs_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *nd)
{
	ospfs_inode_t *dir_oi = ospfs_inode(dir->i_ino);
	uint32_t entry_ino = 0;
	/* EXERCISE: Your code here. */ 
	//return -EINVAL; // Replace this line

	//edge cases:
	//ENAMETOOLONG: return if dentry length exceeds max length
	//EEXIST: return if file name already exists
	//ENOSPC: if disk is full
	//EIO: if I/O error

	if (dentry->d_name.len > OSPFS_MAXNAMELEN)
    	return -ENAMETOOLONG;
	if (find_direntry(dir_oi, dentry->d_name.name, dentry->d_name.len))
    	return -EEXIST;

	int upperlimit = ospfs_super->os_ninodes;
	int found_iNode = 0;
	uint32_t inode_counter = 2;
	ospfs_direntry_t *od = create_blank_direntry(dir_oi);
	//find an empty inode to stick our file into
	while (inode_counter < upperlimit)
	{
    	if (ospfs_inode(inode_counter)->oi_nlink == 0) {
        	//if we are in  here, we found an empty inode
        	found_iNode = 1;
        	entry_ino = inode_counter;
    	}
        	inode_counter++;
	}
   	 
	//if we are here and found_iNode is 0, then we didn't find a free inode
	if (found_iNode == 0)
    	return -ENOSPC;
    
	//if we are here, then all is good and we can make our direntry
	od->od_ino = entry_ino;
	strncpy(od->od_name, dentry->d_name.name, dentry->d_name.len);
    
	ospfs_inode_t *file_oi = ospfs_inode(entry_ino);
	file_oi->oi_size = 0;
	file_oi->oi_ftype = OSPFS_FTYPE_REG;
	file_oi->oi_nlink = 1;
	file_oi->oi_mode = mode;
	file_oi->oi_direct[0] = 0;
    
	dir_oi->oi_nlink++;
    
	/* Execute this code after your function has successfully created the
   	file.  Set entry_ino to the created file's inode number before
   	getting here. */
	{
    	struct inode *i = ospfs_mk_linux_inode(dir->i_sb, entry_ino);
    	if (!i)
        	return -ENOMEM;
    	d_instantiate(dentry, i);
    	return 0;
	}
}