Changeset 768

Show
Ignore:
Timestamp:
07/09/08 18:45:59 (2 months ago)
Author:
mwhitworth
Message:

Memory map instead of reading in file. Doesn't cause bugs on loading, and is better practice anyway.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • Whitix/branches/fs/user/system/moduleadd.c

    r551 r768  
    1717        FILE* file=fopen(name, "r"); 
    1818        unsigned int size; 
    19         char* buf; 
    2019        int ret; 
     20        DWORD address; 
    2121 
    2222        if (!file) 
     23        { 
     24                printf("moduleadd: Could not open %s\n", name); 
    2325                return 1; 
     26        } 
    2427 
    2528        fseek(file, 0, SEEK_END); 
    26  
    2729        size=ftell(file); 
    28  
    2930        fseek(file, 0, SEEK_SET); 
    3031 
    31         buf=(char*)malloc(size); 
    32         if (!buf) 
     32        address=SysMemoryMap(0, size, 5, file->fd, 0, _SYS_MMAP_PRIVATE); 
     33 
     34        if (!address) 
    3335        { 
    34                 printf("Could not allocate memory. Exiting.\n"); 
    35                 return 2; 
     36                printf("Could not read %s\n", name); 
     37                return 1; 
    3638        } 
    3739 
    38         fread(buf, size, 1, file); 
     40        ret=SysModuleAdd(address, size); 
    3941 
    40         ret=SysModuleAdd(buf, size); 
    41  
    42         free(buf); 
     42        SysMemoryUnmap(address, size); 
    4343 
    4444        /* Check ret. */ 
    4545        if (ret) 
    4646                printf("moduleadd: Error adding module %s to kernel: %s\n", name, strerror(ret)); 
     47 
     48        fclose(file); 
    4749 
    4850        return ret;