Exemple #1
0
/*
 * Copy
 */
void copy1( struct ext2_filesystem *fs, char *pathS,
           char *nameS, char *pathD, char *nameD ) {

    struct ext2_dir_entry_2 *direntS = ext2_get_dirent_from_path( fs, pathS, nameS );
    if (!direntS) {
        printf("copy: %s%s: file not found\n", pathS, nameS);
        return;
    }
    struct ext2_dir_entry_2 *parentDirentD = ext2_get_dirent_from_path( fs, pathD, "." );
    if (!parentDirentD) {
        printf("copy: %s: directory not found\n", pathD);
        return;
    }
    struct ext2_inode *parentInode = ext2_get_inode( fs, parentDirentD->inode );
    if (!parentInode) {
        printf("copy: %d: inode not found\n", parentDirentD->inode);
        return;
    }
    struct ext2_inode *inodeS = ext2_get_inode( fs, direntS->inode );
    if (!inodeS) {
        printf("copy: %d: inode not found\n", direntS->inode);
        return;
    }

    uint32 newInodeNum = ext2_inode_alloc( fs );
    if (!newInodeNum) {
        printf("copy: no new inode available\n");
        return;
    }
    struct ext2_inode *newInode = ext2_get_inode( fs, newInodeNum );
    if (!newInode)
        return;

    newInode->i_mode = inodeS->i_mode;
    newInode->i_size = 0;

    struct ext2_dir_entry_2 *newDirent = ext2_dirent_alloc( fs, parentInode );
    if (!newDirent) {
        printf("copy: no new dirents available\n");
        return;
    }
    newDirent->inode = newInodeNum;
    newDirent->next_dirent = 0;
    newDirent->name_len = strnlen( nameD, EXT2_NAME_LEN );
    newDirent->filetype = direntS->filetype;
    memcpy( newDirent->name, nameD, strnlen( nameD, EXT2_NAME_LEN ) );

    char buff[inodeS->i_size];
    int bytesRead  = ext2_read_dirent( fs, direntS, buff, 0, inodeS->i_size );
    int bytesWritten = ext2_write_file_by_inode( fs, newDirent, buff, 0, bytesRead );

}
Exemple #2
0
ext2_write_status
ext2_raw_write
	(struct ext2_filesystem_context *context,
	const char *path,
	const void *buffer,
	Uint32 *bytes_written,
	Uint32 start,
	Uint32 nbytes)
{
	if( !bytes_written )
	{
		Uint32 throwaway = 0;
		bytes_written = &throwaway;
	}
	*bytes_written = 0;

	if( path[0] != DIRECTORY_SEPARATOR )
	{
		return EXT2_WRITE_NO_LEADING_SLASH;
	}

	// Split up the path into the filename and dirname components
	Uint path_length = _kstrlen( path );
	const char *filename = _kstrrchr( path, DIRECTORY_SEPARATOR ) + 1;

	// Set up the directory name, keep the trailing slash, ignore filename.
	char dirname[path_length+1];
	_kmemcpy( dirname, path, path_length+1 );
	serial_printf( __FILE__ ":" CPP_STRINGIFY_RESULT(__LINE__)
			", dirname before excluding filename: %s\n\r",
			dirname );
	((char *)_kstrrchr( dirname, DIRECTORY_SEPARATOR ))[1] = '\0';
	serial_printf( __FILE__ ":" CPP_STRINGIFY_RESULT(__LINE__)
			", dirname after excluding filename: %s\n\r",
			dirname );
	((char *)_kstrrchr( dirname, DIRECTORY_SEPARATOR ))[1] = '\0';

	struct ext2_directory_entry* file =
		get_file_from_dir_path( context, dirname, filename );

	if( file )
	{
		*bytes_written = ext2_write_file_by_inode(context, file, buffer, start, nbytes);
		return EXT2_WRITE_SUCCESS;
	}
	else
	{
		return EXT2_WRITE_FILE_NOT_FOUND;
	}
}
Exemple #3
0
devcall lflPutc(device *dev, char c){
  struct lflcblk *lfptr;

  lfptr = &lfltab[dev->minor];

  if( lfptr->lfstate != LF_USED ){
    return SYSERR;
  }

  printf("Pos %d\n", lfptr->lfpos);
  ext2_write_file_by_inode( Lf_data.xinufs, lfptr->dir, &c, lfptr->lfpos, 1);
  lfptr->lfpos++;
  return 0;

}