Changeset 259


Ignore:
Timestamp:
Dec 5, 2013, 12:45:34 PM (11 years ago)
Author:
devigne
Message:

giet_fat32/fat32.c :
Added _fat_write function. At the moment it does not support the creation of a
new file (the writing must exist in the disk image) and does not support the
allocation of additional cluster from the original file.

create_dmg :
Bug fix for support Linux (The tree files were not consistent with the
pathnames in boot.c).

giet_libs/stdlib.c and stdlib.h :
Added stdlib file. At the moment they only contain the atoi function.

giet_libs/stdio.h :
Bug fix in SYSCALL DEFINE. SYSCALL_FAT_READ, WRITE, CLOSE, LSEEK had the same
value.

Makefile :
Added compilation line for stdlib.o

Location:
soft/giet_vm
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/Makefile

    r258 r259  
    290290        $(CC) $(CFLAGS) $(USER_INCLUDE) -c -o $@ $<
    291291
     292build/libs/stdlib.o: giet_libs/stdlib.c \
     293                     giet_libs/stdlib.h \
     294                     giet_config.h
     295        $(CC) $(CFLAGS) $(USER_INCLUDE) -c -o $@ $<
     296
    292297build/libs/string.o: giet_libs/string.c \
    293298                     giet_libs/string.h \
  • soft/giet_vm/create_dmg

    r258 r259  
    88reserved_sectors=32
    99
     10# FAT32 SPEC: The first two clusters are not present in the data region but
     11# they are used in the computation of the FAT sectors
     12data_region_clusters=$clusters-2
    1013
    11 let "data_sectors = (clusters - 2) * sectors_per_cluster"
    12 let "fat_sectors = (clusters * 4) / 512"
    13 let "sectors=data_sectors + fat_sectors + reserved_sectors"
     14let "data_sectors = data_region_clusters * sectors_per_cluster"
     15let "fat_sectors  = (clusters * 4) / 512"
     16
     17# The disk image contains:
     18#   - MBR sector : this sector is removed by this script as it will be copied
     19#                  after)
     20#   - Reserved region sectors (usually 32)
     21#   - FAT region sectors
     22#   - DATA region sectors
     23let "sectors      = data_sectors + fat_sectors + reserved_sectors + 1"
    1424
    1525platform=`uname`
     
    4353                        # RAW DISK IMAGE READ-ONLY
    4454                        # The not used space is not considered (smaller disk image)
    45                         # format="UDRO"
     55                        format="UDRO"
    4656
    4757                        # RAW DISK IMAGE READ-WRITE
    4858                        # None compression is made
    49                         format="UDRW"
     59                        # format="UDRW"
    5060
    5161                        echo "Creating partition file $3 from $2 directory"
     
    5969                                -format $format \
    6070                                $3;
    61 #                               -verbose \
     71#                               -verbose \
    6272
    6373                        echo "Removing first sector of diskimage"
     
    106116
    107117elif [[ $platform == "Linux" ]]; then
    108         echo "Creating partion file: partition.dmg"
    109         mkfs.vfat -C -F32 -S $sector_size -s $sectors_per_cluster \
    110                 partition.dmg $sectors
     118        case $1 in
     119                create )
     120                        if [[ -z $2 ]]; then
     121                                echo "Create action need second argument: <srcdir_path>"
     122                                exit 1;
     123                        fi;
    111124
    112         echo "Copying files into the partition"
    113         mcopy -s -i partition.dmg build :://
    114         mcopy -i    partition.dmg map.bin :://
     125                        if [[ -z $3 ]]; then
     126                                echo "Create action need third argument: <disk_image>"
     127                                exit 1;
     128                        fi;
    115129
    116         echo "Copying MBR on the first sector"
    117         dd if=mbr.dmg of=disk.dmg count=1 bs=$sector_size
     130                        echo "Creating partition file: $3"
    118131
    119         echo "Copying partition file on the sector 200 of the disk"
    120         dd if=partition.dmg of=disk.dmg seek=200 bs=$sector_size
     132                        let "sectors = (sectors - 1) / 2"
     133                    mkfs.vfat \
     134                                -C \
     135                                -F32 \
     136                                -f 1 \
     137                                -R $reserved_sectors \
     138                                -S $sector_size \
     139                                -s $sectors_per_cluster \
     140                                -v \
     141                                $3.dmg $sectors
     142
     143                        if [[ -e $2 ]]; then
     144                                echo "Copying files from $2 into partition"
     145                                mcopy -s -i $3.dmg $2/* :://
     146                        fi;;
     147
     148                * )
     149                        echo "Pass the command as the first parameter: "
     150                        echo "  - create: create disk image"
     151                        echo "            First parameter after create action is the path"
     152                    echo "            of the directory to copy in the created "
     153                        echo "            partition"
     154                        echo ""
     155                        echo "EXAMPLES:"
     156                        echo " ./create_diskimage.sh create /path/to/source_dir disk_image"
     157        esac;
    121158
    122159else
  • soft/giet_vm/giet_fat32/fat32.c

    r258 r259  
    11631163                unsigned int offset )    // nuber of sectors to skip in file
    11641164{
    1165     _tty_get_lock( 0 );
    1166     _puts("\n[FAT ERROR] _fat_write() function not implemented\n");
    1167     _tty_release_lock( 0 );
    1168     return -1;
     1165
     1166    unsigned int spc = fat.sectors_per_cluster;
     1167
     1168    unsigned int file_size;         // number of bytes in file
     1169    unsigned int file_sectors;      // number of sectors in file
     1170    unsigned int cluster;           // cluster index
     1171    unsigned int clusters_to_skip;  // number of clusters to skip because offset
     1172    unsigned int sectors_to_skip;   // number of sectors to skip in first iteration
     1173    unsigned int allocate;          // need allocate or not
     1174
     1175    // compute file size as a number of sectors
     1176    file_size    = fat.fd[fd_id].file_size;
     1177    if ( file_size & 0x1FF ) file_sectors = (file_size >> 9) + 1;
     1178    else                     file_sectors = (file_size >> 9);
     1179   
     1180    allocate = ( ((count + offset) / spc) > (file_sectors / spc) );
     1181
     1182#if GIET_DEBUG_FAT
     1183_tty_get_lock( 0 );
     1184_puts("\n[FAT DEBUG] Enter _fat_write() for file ");
     1185_puts( fat.fd[fd_id].name );
     1186_puts("\n - buffer base     = ");
     1187_putx( (unsigned int)buffer );
     1188_puts("\n - skipped sectors = ");
     1189_putd( offset );
     1190_puts("\n - write sectors    = ");
     1191_putd( count );
     1192_puts("\n - file size (sectors)  = ");
     1193_putd( file_sectors );
     1194_puts("\n - need allocate = ");
     1195allocate ? _puts( "True" ) : _puts( "False");
     1196_tty_release_lock( 0 );
     1197#endif
     1198
     1199    if ( allocate  )
     1200    {
     1201        _tty_get_lock( 0 );
     1202        _puts("\n[FAT ERROR] in _fat_write() : \n");
     1203        _puts("we need to allocate more cluster... But this function is not implemented\n");
     1204        _tty_release_lock( 0 );
     1205        return -1;
     1206    }
     1207    // arguments checking
     1208    if ( fd_id >= GIET_OPEN_FILES_MAX )
     1209    {
     1210        _tty_get_lock( 0 );
     1211        _puts("\n[FAT ERROR] in _fat_write() : illegal file descriptor index\n");
     1212        _tty_release_lock( 0 );
     1213        return -1;
     1214    }
     1215    if ( fat.fd[fd_id].used != 1 )
     1216    {
     1217        _tty_get_lock( 0 );
     1218        _puts("\n[FAT ERROR] in _fat_write() : file not open\n");
     1219        _tty_release_lock( 0 );
     1220        return -1;
     1221    }
     1222    if ( ((unsigned int)buffer & 0x1FF) != 0 )
     1223    {
     1224        _tty_get_lock( 0 );
     1225        _puts("\n[FAT ERROR] in _fat_write() : memory buffer not sector aligned\n");
     1226        _tty_release_lock( 0 );
     1227        return -1;
     1228    }
     1229
     1230    // compute clusters and sectors to be skipped
     1231    clusters_to_skip = offset / spc;
     1232    sectors_to_skip  = offset % spc;
     1233   
     1234    // get first cluster index
     1235    cluster = fat.fd[fd_id].first_cluster;
     1236
     1237#if GIET_DEBUG_FAT
     1238_tty_get_lock( 0 );
     1239_puts("\n - first cluster   = ");
     1240_putd( cluster );   
     1241_puts("\n - skiped clusters = ");
     1242_putd( clusters_to_skip );   
     1243_puts("\n");
     1244_tty_release_lock( 0 );
     1245#endif
     1246
     1247    // compute index of first cluster to be loaded
     1248    // as we may need to scan the FAT, we use the kernel mode
     1249    while ( clusters_to_skip )
     1250    {
     1251        cluster = get_next_cluster_id( IOC_KERNEL_MODE, cluster );
     1252        clusters_to_skip--;
     1253    }
     1254
     1255    // variables used in the loop on clusters
     1256    int             todo_sectors;   // number of sectors still to be loaded
     1257    unsigned int    lba;            // first sector index on device
     1258    unsigned int    iter_sectors;   // number of sectors to load in iteration
     1259    char*           src;            // pointer on target buffer
     1260
     1261    // initialize these variables for the first iteration
     1262    todo_sectors  = count;
     1263    src           = (char*)buffer;
     1264    lba           = cluster_to_lba(cluster) + sectors_to_skip;
     1265    if( count < (spc - sectors_to_skip) ) iter_sectors = count;
     1266    else                                  iter_sectors = spc - sectors_to_skip;
     1267
     1268    // loop on the clusters
     1269    while ( todo_sectors > 0 )
     1270    {
     1271
     1272#if GIET_DEBUG_FAT
     1273_tty_get_lock( 0 );
     1274_puts("\n[FAT DEBUG] _fat_write() IOC request : buf = ");
     1275_putx( (unsigned int)src );
     1276_puts(" / lba = ");
     1277_putd( lba );
     1278_puts(" / sectors = ");
     1279_putd( iter_sectors );
     1280_puts("\n"); 
     1281_tty_release_lock( 0 );
     1282#endif
     1283
     1284        if( _ioc_write( mode,              // mode for IOC driver
     1285                        lba,               // first sector index
     1286                        src,               // buffer address
     1287                        iter_sectors ) )   // number of sectors
     1288        {
     1289            _tty_get_lock( 0 );
     1290            _puts("\n[FAT ERROR] in _fat_write() cannot write block ");
     1291            _putd( lba );
     1292            _puts("\n");
     1293            _tty_release_lock( 0 );
     1294            return -1;
     1295        }
     1296         
     1297        // update variables for next iteration
     1298        cluster      = get_next_cluster_id( mode, cluster );
     1299        todo_sectors = todo_sectors - iter_sectors;
     1300        src          = src + (iter_sectors << 9);
     1301        lba          = cluster_to_lba(cluster);
     1302        if ( todo_sectors > spc ) iter_sectors = spc;
     1303        else                      iter_sectors = todo_sectors;
     1304    }
     1305         
     1306    // returns number of sectors actually transfered
     1307    return count;
    11691308}
    11701309
  • soft/giet_vm/giet_libs/stdio.h

    r258 r259  
    4848#define SYSCALL_FAT_OPEN          0x20
    4949#define SYSCALL_FAT_READ          0x21
    50 #define SYSCALL_FAT_WRITE         0x21
    51 #define SYSCALL_FAT_LSEEK         0x21
    52 #define SYSCALL_FAT_CLOSE         0x21
     50#define SYSCALL_FAT_WRITE         0x22
     51#define SYSCALL_FAT_LSEEK         0x23
     52#define SYSCALL_FAT_CLOSE         0x24
    5353
    5454//////////////////////////////////////////////////////////////////////////////////
Note: See TracChangeset for help on using the changeset viewer.