-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preallocate files during creation/extraction when sensible #26
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1627,6 +1627,14 @@ int extract_file( int in_xiso, dir_node *in_file, modes in_mode , char* path) { | |
|
||
if ( ! err && lseek( in_xiso, (xoff_t) in_file->start_sector * XISO_SECTOR_SIZE + s_xbox_disc_lseek, SEEK_SET ) == -1 ) seek_err(); | ||
|
||
// preallocate this file if it's not tiny | ||
if(in_file->file_size >= (READWRITE_BUFFER_SIZE * 2)) | ||
{ | ||
if ( lseek( out, (xoff_t) in_file->file_size-1, SEEK_SET ) == -1 ) seek_err(); | ||
if ( write( out, "\0", 1 ) != (int) 1 ) write_err(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: (Personal preference) |
||
if ( lseek( out, (xoff_t) 0, SEEK_SET ) == -1 ) seek_err(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of this scope will depend on |
||
|
||
if ( ! err ) { | ||
if ( in_file->file_size == 0 ) | ||
exiso_log( "%s%s%s (0 bytes) [100%%]%s\r", in_mode == k_extract ? "extracting " : "", path, in_file->filename, "" ); | ||
|
@@ -1727,6 +1735,12 @@ int write_file( dir_node_avl *in_avl, write_tree_context *in_context, int in_dep | |
int err = 0, fd = -1, i; | ||
|
||
if ( ! in_avl->subdirectory ) { | ||
// preallocate the space for this file if it's not tiny | ||
if(in_avl->file_size >= (READWRITE_BUFFER_SIZE * 2)) | ||
{ | ||
if ( lseek( in_context->xiso, (xoff_t) (in_avl->start_sector * XISO_SECTOR_SIZE) + in_avl->file_size - 1, SEEK_SET ) == -1 ) seek_err(); | ||
if ( write( in_context->xiso, "\0", 1 ) != (int) 1 ) write_err(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be moved into a function like Edit: This will unfortunately include the dangerous case where it's used to overwrite existing data with a zero-byte; maybe https://linux.die.net/man/3/posix_fallocate ? |
||
if ( lseek( in_context->xiso, (xoff_t) in_avl->start_sector * XISO_SECTOR_SIZE, SEEK_SET ) == -1 ) seek_err(); | ||
|
||
if ( ! err && ( buf = (char *) malloc( ( size = max( XISO_SECTOR_SIZE, READWRITE_BUFFER_SIZE ) ) + 1 ) ) == nil ) mem_err(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should happen before the seek in the XISO, so we can possibly group it into a
open_preallocated(in_file->filename, WRITEFLAGS, 0644, in_file->file_size)
Edit: I see this won't be possible due to the use in
write_file
- should still be moved upwards in my opinion.