예제 #1
0
// Find the inode number for a file by its full path.
// This is the functionality that ext2cat ultimately needs.
__u32 get_inode_by_path(void * fs, char * path) {
    int num_slashes = get_number_of_slashes(path);
    char ** pathComponents = split_path(path);
    struct ext2_inode * dir = get_root_dir(fs);
    __u32 inode = 0;
    // loop through each part of path to file
    for (int i = 0; i < num_slashes; i++) {
        // look up inode of ith part of path
        inode = get_inode_from_dir(fs, dir, pathComponents[i]);
        // check if invalid
        if (inode == 0) {
            return 0;
        }
        // unless last iteration update inode entry to next file/directory
        if (i < num_slashes - 1) {
            dir = get_inode(fs,inode);
            // can't find right constant for this (value for dir is 16832)
            // so going to leave out error checking for now
            //if (dir->i_mode != LINUX_S_IFDIR) {
                 // error path is too long
            //     printf("Error path is too long\n");
            //     return 0;
            //}
        }
    }

    return inode;
}
예제 #2
0
// Find the inode number for a file by its full path.
// This is the functionality that ext2cat ultimately needs.
__u32 get_inode_by_path(void *fs, char *path) {
    char **parts = split_path(path);
    __u32 idx = 0;
    struct ext2_inode *dir = get_root_dir(fs);
    __u32 node;
    for (char *slash = path; slash != NULL; slash = strchr(slash + 1, '/')) {
        node = get_inode_from_dir(fs, dir, parts[idx]);
        dir = get_inode(fs, node);
        free(parts[idx]);
        idx++;
    }
    free(parts);
    return node;
}
예제 #3
0
// Find the inode number for a file by its full path.
// This is the functionality that ext2cat ultimately needs.
__u32 get_inode_by_path(void * fs, char * path) {

		// chuck the full path into pieces
		char** dirs = split_path(path);
		// get the inode ptr to the root dir
		struct ext2_inode* tmpInodePtr = get_root_dir(fs);
		struct ext2_dir_entry_2* dir = (struct ext2_dir_entry_2*)get_block(fs, tmpInodePtr->i_block[0]);
		__u32 inodeNum = 0;
		unsigned i = 0;
		// go to next level directory
		while(dir->file_type == EXT2_FT_DIR)
		{
			inodeNum = get_inode_from_dir(fs, tmpInodePtr, dirs[i]);
			tmpInodePtr = get_inode(fs, inodeNum);	
			dir = (struct ext2_dir_entry_2*)get_block(fs, tmpInodePtr->i_block[0]);
			++i; 
		}
		// until it is not a dir, return the inode number
		return inodeNum;
}
예제 #4
0
// Find the inode number for a file by its full path.
// This is the functionality that ext2cat ultimately needs.
__u32 get_inode_by_path(void * fs, char * path) {
    // get number of parts - length of the parts array returned from split_parts
    int num_parts=0;
    int curr=0;
    while (path[curr]!='\0') {
       if (path[curr] == '/') num_parts++;
       curr++;
    }
    //printf("Number of parts: %d \n", num_parts);
    struct ext2_inode* root = get_root_dir(fs);
    struct ext2_inode* curr_inode = root;
    char** parts = split_path(path);
    __u32 inode_num;
    for (int i = 0; i < num_parts; i++)
    {
      char* dir = parts[i]; 
      inode_num = get_inode_from_dir(fs, curr_inode, dir);
      curr_inode = get_inode(fs, inode_num);          
    }
    return inode_num;  
}
예제 #5
0
// Find the inode number for a file by its full path.
// This is the functionality that ext2cat ultimately needs.
__u32 get_inode_by_path(void * fs, char * path) {
    struct ext2_inode *p = get_root_dir(fs);

    int num_slashes = 0;
    for (char * slash = path; slash != NULL; slash = strchr(slash + 1, '/')) {
        num_slashes++;
    }

    char **parts = split_path(path);                

    __u32 num;

    for (int i = 0; i < num_slashes; i++) {
        num = get_inode_from_dir(fs, p, parts[i]);
        free(parts[i]);
        if (num == 0) {
            break;
        }
        p = get_inode(fs, num);
    }
    
    free(parts);
    return num;
}