Exemplo n.º 1
0
/**
 * Create a new, regular, and empty file under directory 'parent'.
 */
void ext2_create(fs_node_t *parent, char *name, uint16_t permission) {
	
	kprintf("[kernel/ext2] Creating file.\n");
	uint16_t mode = permission | EXT2_S_IFREG;
	ext2_inodetable_t *parent_inode = ext2_disk_inode(parent->inode);
	
	// Check to make sure no same name in the parent dir
	fs_node_t *b_exist = finddir_ext2_disk(parent, name);
	if (b_exist) {
		kprintf("[kernel/ext2] %s: Already exists\n", name);
		free(b_exist);
		free(parent_inode);
		return;
	}
	free(b_exist);

	// Create the inode under 'parent'
	uint32_t inode_no;
	ext2_inodetable_t *inode = ext2_disk_alloc_inode(parent_inode, parent->inode, name, mode, &inode_no);
	free(parent_inode);

	if (inode == NULL) {
		kprintf("[kernel/ext2] Failed to create file '%s' (inode allocation failed)?\n", name);
		return;
	}

	free(inode);
}
Exemplo n.º 2
0
/**
 * Make a new directory. 'name' consists the name for the new directory
 * to be created using 'permission' under 'parent' directory.
 * Message will be displayed in the terminal for success or failure.
 */
void ext2_mkdir(fs_node_t *parent, char *name, uint16_t permission) {

	uint16_t mode = permission | EXT2_S_IFDIR;
	ext2_inodetable_t *parent_inode = ext2_disk_inode(parent->inode);

	// Check to make sure no same name in the parent dir
	fs_node_t *b_exist = finddir_ext2_disk(parent, name);
	if (b_exist) {
		kprintf("mkdir: %s: Already exists\n", name);
		free(b_exist);
		free(parent_inode);
		return;
	}
	free(b_exist);

	// Create the inode under 'parent'
	uint32_t inode_no;
	ext2_inodetable_t *inode = ext2_disk_alloc_inode(parent_inode, parent->inode, name, mode, &inode_no);
	free(parent_inode);

	if (inode == NULL) {
		kprintf("mkdir: %s: Cannot be created\n", name);
		return;
	}

	// Init this newly created dir, put '.' and '..' into it.
	// Here we pass in 0 as the inode number for '.' and '..' because the 
	// 'cd' command can handle them correctly, so it does not matter.
	insertdir_ext2_disk(inode, inode_no, 0, ".", 2);
	insertdir_ext2_disk(inode, inode_no, 0, "..", 2);

	free(inode);
}
Exemplo n.º 3
0
/**
 * Create a new, regular, and empty file under directory 'parent'.
 */
void ext2_create(fs_node_t *parent, char *name, uint16_t permission) {

	debug_print(NOTICE, "Creating file %s", name);
	uint16_t mode = permission | EXT2_S_IFREG;
	ext2_inodetable_t *parent_inode = ext2_disk_inode(parent->inode);
	
	// Check to make sure no same name in the parent dir
	fs_node_t *b_exist = finddir_ext2_disk(parent, name);
	if (b_exist) {
		debug_print(WARNING, "File already exists!");
		free(b_exist);
		free(parent_inode);
		return;
	}
	free(b_exist);

	// Create the inode under 'parent'
	uint32_t inode_no;
	ext2_inodetable_t *inode = ext2_disk_alloc_inode(parent_inode, parent->inode, name, mode, &inode_no);
	free(parent_inode);

	if (inode == NULL) {
		debug_print(ERROR, "Failed to create file (inode allocation failed)");
		return;
	}

	free(inode);
}