Exemplo n.º 1
0
/** Get file attributes.
 *
 * Similar to stat().  The 'st_dev' and 'st_blksize' fields are
 * ignored.  The 'st_ino' field is ignored except if the 'use_ino'
 * mount option is given.
 */
int nphfuse_getattr(const char *path, struct stat *stbuf){
    // extract_directory_file(dir,filename,path);
    npheap_store *inode = NULL;
    
    if(strcmp(path,"/")==0){
        inode = getRootDirectory();
        if(inode==NULL)
        {
            log_msg("Root directory not found in getattr.\n");
            return -ENOENT;
        }
        else
        {
            log_msg("Assigning root stbuf in getattr\n");
            memcpy(stbuf, &inode->mystat, sizeof(struct stat));
            return 0;
        }
    }

    inode = retrieve_inode(path);

    if(inode == NULL){
        return -ENOENT;
    }

    // else return the proper value
    log_msg("Assigning normal stbuf in getattr\n");
    memcpy(stbuf, &inode->mystat, sizeof(struct stat));
    return 0;
}
Exemplo n.º 2
0
/**
 * Get attributes from an open file
 *
 * This method is called instead of the getattr() method if the
 * file information is available.
 *
 * Currently this is only called after the create() method if that
 * is implemented (see above).  Later it may be called for
 * invocations of fstat() too.
 *
 */
int nphfuse_fgetattr(const char *path, struct stat *statbuf, struct fuse_file_info *fi)
{
    log_msg("Into fgetattr.\n");
    npheap_store *inode = NULL;
    char dir[236];
    char filename[128];

    if(strcmp(path,"/")==0){
        inode = getRootDirectory();
        if(inode==NULL)
        {
            log_msg("Root directory not found in getattr.\n");
            return -ENOENT;
        }else{
            log_msg("Everything worked fine\n");
            memcpy(statbuf, &inode->mystat, sizeof(struct stat));
            return 0;
        }
    }

    inode = retrieve_inode(path);
    if(inode==NULL){
        return -ENOENT;
    }

    log_msg("Worked fine\n");
    memcpy(statbuf, &inode->mystat, sizeof(struct stat));
    return 0;
}
Exemplo n.º 3
0
/** Change the owner and group of a file */
int nphfuse_chown(const char *path, uid_t uid, gid_t gid){
    log_msg("Entry into CHOWN.\n");
    npheap_store *inode = NULL;
    struct timeval currTime;

    if(strcmp (path,"/")==0){
        log_msg("Calling getRootDirectory() in CHOWN.\n");
        
        inode = getRootDirectory();
        if(inode==NULL)
        {
            log_msg("Root directory not found. in CHOWN.\n");
            return -ENOENT;
        }
        else
        {
            log_msg("Root directory found. in CHOWN.\n");
            //Check if accessibilty can be given
            int flag = checkAccess(inode);
            //Deny the access
            if(flag == 0){
                return -EACCES;
            }
            //else set correct value
            log_msg("Owner of root  changed in CHOWN.\n", path);
            gettimeofday(&currTime, NULL);
            inode->mystat.st_uid = uid;
            inode->mystat.st_gid = gid;
            inode->mystat.st_ctime = currTime.tv_sec;
            log_msg("Exit from CHOWN.\n");
            return 0;
        }
    }
    
    inode = retrieve_inode(path);
    
    if(inode == NULL){
        log_msg("Couldn't find path - %s - in CHOWN.\n", path);
        return -ENOENT;
    }
    //Check Accessibility
    int flag1 = checkAccess(inode);
    
    //Deny the access
    if(flag1 == 0){
        return -EACCES;
    }
    
    //else set correct value
    log_msg("Owner of path - %s - changed in CHOWN.\n", path);
    gettimeofday(&currTime, NULL);
    inode->mystat.st_uid = uid;
    inode->mystat.st_gid = gid;
    inode->mystat.st_ctime = currTime.tv_sec;
    log_msg("Exit from CHOWN.\n");
    return 0;
}
Exemplo n.º 4
0
/** Change the access and/or modification times of a file */
int nphfuse_utime(const char *path, struct utimbuf *ubuf){
    log_msg("Into utime.\n");
    npheap_store *temp = NULL;

    if(strcmp(path,"/")==0){
        temp = getRootDirectory();
        if(temp==NULL)
        {
            log_msg("Root directory not found in utime.\n");
            return -ENOENT;
        }
        else
        {
            int flag = checkAccess(temp);
            if(flag==0){
                log_msg("Cannot access in root.\n");
                return - EACCES;
            }

            // Set from ubuf
            if(ubuf->actime){
                temp->mystat.st_atime = ubuf->actime;
            }
            if(ubuf->modtime){
                temp->mystat.st_mtime = ubuf->modtime;
            }
            log_msg("Ubuf ran successfully.! \n");
            return 0;
        }
    }

    temp = retrieve_inode(path);

    if(temp==0){
        log_msg("Cannot find the inode in ubuf.\n");
        return -ENOENT;
    }

    int flag1 = checkAccess(temp);
    if(flag1==0){
        log_msg("Cannot access the asked inode.\n");
        return - EACCES;
    }

    if(ubuf->actime){
        temp->mystat.st_atime = ubuf->actime;
    }
    if(ubuf->modtime){
        temp->mystat.st_mtime = ubuf->modtime;
    }
    log_msg("Ubuf ran successfully.! \n");
    return 0;

}
Exemplo n.º 5
0
int
find_ino(const char *path)
		/* Returns inode number Or -1 on error */
{
	char 		m_path[strlen(path)+1];   /* mutable string for path2tokens() */
	int 		tokenc;
	char 	    **tokens;
	char		**tokenp;				  /* for travese tokens */
	char		*token;
	inode_t  	*inodep;
	dirent_t 	dir;
	entry_t  	ent;
	// indirect_t 	indirect;
	insert_t 	insert;

	strcpy(m_path, path);

	if ((strcmp(path, "/") == 0) ||
		(strcmp(path, "///") == 0))
		return 1;

	inodep = retrieve_root();
	tokenc = path2tokens(m_path, &tokens);
	if (tokenc < 0)
		return -1;
	tokenp = tokens;

	int i;
	int type = S_IFDIR; /* starts from root dir */
	for (i=0; 
		( i<(tokenc-1) && I_ISDIR(type) ); 
		i++, tokenp++)
	{
		token = *tokenp;
		if ( ( insert=search_entry(token, inodep, &dir, &ent) ) < 0 )
			return -1;
		if (!(inodep = retrieve_inode(ent.et_ino)))
			return -1;
		type = inodep->i_type;
		if (ent.et_ino != 1)
			free(inodep);
	}
	if (i != (tokenc-1))
		return -1;
	token = *tokenp;
	if ( (insert=search_entry(token, inodep, &dir, &ent)) < 0 )
		return -1;

	for (int i=0; i<tokenc; i++){		/* free tokens */
		free(*(tokens+i));
	}
	free(tokens);
	return ent.et_ino;
}
Exemplo n.º 6
0
// both path and newpath are fs-relative
int nphfuse_rename(const char *path, const char *newpath)
{
    log_msg("RENAME called for %s path to %s newpath\n", path, newpath);
    struct timeval currTime;
    npheap_store *inode = NULL;
    char dir[236];
    char filename[128];

    //Root directory cannot be changed.
    if(strcmp(path,"/")==0){
        return -EACCES;
    }

    //Get inode into path
    inode = retrieve_inode(path);
    if(inode == NULL){
        log_msg("Inode was not found in rename.\n");
        return -ENOENT;
    }

    //Check if newpath is valid
    int extract = extract_directory_file(dir, filename, newpath);
    if(extract == 1){
        log_msg("Newpath is invalid.\n");
        return -EINVAL;
    }

    //Check if user has access
    int flag = checkAccess(inode);
    if(flag==0){
        log_msg("Cannot access the directory.\n");
        return - EACCES;
    }

    //memset the dirname and filename
    //memset(inode->dirname, 0, 236);
    //memset(inode->filename, 0, 128);

    //copy the new path
    strcpy(inode->dirname, dir);
    strcpy(inode->filename, filename);

    //Change the changetime
    gettimeofday(&currTime, NULL);
    inode->mystat.st_ctime = currTime.tv_sec;

    log_msg("Exiting from RENAME.\n");
    return 0;
}
Exemplo n.º 7
0
/** File open operation
 *
 * No creation, or truncation flags (O_CREAT, O_EXCL, O_TRUNC)
 * will be passed to open().  Open should check if the operation
 * is permitted for the given flags.  Optionally open may also
 * return an arbitrary filehandle in the fuse_file_info structure,
 * which will be passed to all file operations.
 *
 * Changed in version 2.2
 */
int nphfuse_open(const char *path, struct fuse_file_info *fi){
    struct timeval currTime;
    npheap_store *temp = NULL;

    //Check for root directory
    if(strcmp(path,"/")==0){
        temp = getRootDirectory();
        if(temp==NULL)
        {
            log_msg("Root directory not found in open.\n");
            return -ENOENT;
        }
        else
        {
            int flag = checkAccess(temp);

            //If cannot access
            if(flag == 0){
                log_msg("Root access denied.\n");
                return -EACCES;
            }
            // Worked fine
            log_msg("Access granted to root.\n");
            return 0;
        }
    }

    temp = retrieve_inode(path);
    if(temp == NULL){
        return -ENOENT;
    }

    int flag1 = checkAccess(temp);

    //if cannot access
    if(flag1 == 0){
        log_msg("Access denied.\n");
        return -EACCES;
    }
    //Everything worked fine
    fi->fh = temp->mystat.st_ino;
    gettimeofday(&currTime, NULL);
    temp->mystat.st_atime = currTime.tv_sec;
    return 0;
}
Exemplo n.º 8
0
/** Open directory
 *
 * This method should check if the open operation is permitted for
 * this directory
 *
 * Introduced in version 2.3
 */
int nphfuse_opendir(const char *path, struct fuse_file_info *fi){
    // char *filename, *dir;
    // extract_directory_file(&dir,&filename,path);
    npheap_store *inode = NULL;
    log_msg("Entry into OPENDIR.\n");
    if(strcmp (path,"/")==0){
        inode = getRootDirectory();
        if(inode==NULL)
        {
            log_msg("Root directory not found in opendir.\n");
            return -ENOENT;
        }
        else
        {
            //Check if accessibilty can be given
            int flag = checkAccess(inode);
            //Deny the access
            log_msg("Root access %d (if 1 then yes)",flag);
            if(flag == 0){
                return -EACCES;
            }
            return 0;
        }
    }

    inode = retrieve_inode(path);

    if(inode == NULL){
        log_msg("Couldn't find path - %s - in OPENDIR.\n", path);
        return -ENOENT;
    }
    //Check Accessibility
    int flag1 = checkAccess(inode);

    //Deny the access
    log_msg("Normal access %d (if 1 then yes)",flag1);
    if(flag1 == 0){
        return -EACCES;
    }
    //else return correct value
    log_msg("Exit into OPENDIR.\n");
    return 0;
}
Exemplo n.º 9
0
/** Remove a file */
int nphfuse_unlink(const char *path){
    //Individual file delete
    npheap_store *inode = NULL;
    log_msg("Into UNLINK for %s\n", path);

    //Root directory cannot be deleted.
    if(strcmp(path,"/")==0){
        return -EACCES;
    }

    inode = retrieve_inode(path);

    if(inode==NULL){
        return -ENOENT;
    }

    //Check for permission
    int flag = checkAccess(inode);
    if(flag==0){
        log_msg("Cannot access the directory\n");
        return - EACCES;
    }

    //Check for dirname and filename
    if(npheap_getsize(npheap_fd, inode->offset) != 0){
        log_msg("Data offset exist. for %d data off\n", inode->offset);
        npheap_delete(npheap_fd, inode->offset);
    }

    inode->dirname[0] = '\0';
    inode->filename[0] = '\0';
    blk_array[inode->offset] == NULL;
    memset(inode, 0, sizeof(npheap_store));
    log_msg("Exiting UNLINK.\n");
    return 0;
}
Exemplo n.º 10
0
int nphfuse_access(const char *path, int mask){

    npheap_store *inode = NULL;
    
    if(strcmp(path,"/")==0){
        inode = getRootDirectory();
        if(inode==NULL)
        {
            log_msg("Root directory not found in access.\n");
            return -ENOENT;
        }
        else
        {
            log_msg("Checking Access of root\n");
            int flag = checkAccess(inode);
            if(flag==0){
                log_msg("Cannot access the directory\n");
                return -EACCES;
            }
            return 0;
        }
    }

    inode = retrieve_inode(path);

    if(inode == NULL){
        return -ENOENT;
    }
    int flag = checkAccess(inode);
    if(flag==0){
        log_msg("Cannot access the directory\n");
        return -EACCES;
    }
    
    return 0;
}
Exemplo n.º 11
0
// I don't fully understand the documentation above -- it doesn't
// match the documentation for the read() system call which says it
// can return with anything up to the amount of data requested. nor
// with the fusexmp code which returns the amount of data also
// returned by read.
int nphfuse_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi){
    log_msg("Into READ function.\n");
    //Variables needed
    npheap_store *inode = NULL;
    struct timeval currTime;
    char *blk_data = NULL;

    //Root is not the file, so throw error
    if(strcmp(path,"/")==0){
        return -ENOENT;
    }

    inode = retrieve_inode(path);
    if(inode==NULL){
        log_msg("Couldn't find file.\n");
        return -ENOENT;
    }

    //Check for the access
    int flag = checkAccess(inode);
    if(flag==0){
        log_msg("Cannot access in root.\n");
        return - EACCES;
    }

    blk_data = (char *)blk_array[inode->offset];
    if(blk_data==NULL){
        return -ENOENT;
    }

    size_t left_to_read = size;
    size_t offset_read = offset;
    size_t rem = 0;
    size_t curr_buff = 0;
    uint64_t curr_offset = 0;
    uint64_t pos_in_offset = 0;
    size_t curr_size = 0;

    curr_size = npheap_getsize(npheap_fd, inode->offset);
    if(curr_size == 0){
        return 0;
    }

    log_msg("Reading started.\n");

    while(left_to_read != 0){
        //log_msg("Reached here\n");
        pos_in_offset = offset_read/BLOCK_SIZE;
        curr_offset = inode->offset;

        while(pos_in_offset != 0){
            curr_offset = dt_link[curr_offset-FIXED_VALUE];
            pos_in_offset--;
        }

        blk_data = blk_array[curr_offset];  
        if(blk_data==NULL){
            return -ENOENT;
        }
        log_msg("Reached with %s block data\n", blk_data);
        if(npheap_getsize(npheap_fd, curr_offset) == 0){
           return -EINVAL;
        }

        curr_size = npheap_getsize(npheap_fd, curr_offset);
        rem = offset_read % BLOCK_SIZE;

        if(curr_size <= left_to_read + rem){
            log_msg("Reading still left.\n");
            memcpy(buf + curr_buff, blk_data + rem, curr_size - rem);
            offset_read = offset_read + curr_size - rem;
            curr_buff = curr_buff + curr_size - rem;
            left_to_read = left_to_read - curr_size + rem;
        }else{
            log_msg("Last read in the data block.\n");
            memcpy(buf + curr_buff, blk_data + rem, left_to_read);
            offset_read = offset_read + left_to_read;
            curr_buff = curr_buff + left_to_read;
            left_to_read = 0;
        }
    }

    gettimeofday(&currTime, NULL);
    inode->mystat.st_atime = currTime.tv_sec;

    return curr_buff;
}