Switch from GPLv2 to GPLv2+
[fw/altos] / src / drivers / ao_fat.c
index afd645cdec579a9f40063c5d006dce8c83a13a51..fb8eecff177322cf9b46a959f87fee4bbe9fbf89 100644 (file)
@@ -3,7 +3,8 @@
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -187,7 +188,7 @@ _ao_fat_entry_replace(cluster_t  cluster, cluster_t new_value)
        sector_t                sector;
        cluster_offset_t        offset;
        uint8_t                 *buf;
-       cluster_t               ret;
+       cluster_t               ret = 0;
        cluster_t               old_value;
        uint8_t                 fat;
 
@@ -747,7 +748,7 @@ _ao_fat_current_sector(struct ao_file *file)
        DBG("current sector offset %d size %d\n",
            file->offset, file->dirent->size);
 
-       if (file->offset > file->dirent->size) {
+       if (file->offset > (offset_t) file->dirent->size) {
                printf ("file offset %d larger than size %d\n",
                        file->offset, file->dirent->size);
                return 0xffffffff;
@@ -761,7 +762,7 @@ _ao_fat_current_sector(struct ao_file *file)
                DBG("\treset to start of file %08x\n", file->cluster);
        }
 
-       if (file->cluster_offset + bytes_per_cluster <= file->offset) {
+       if ((offset_t) (file->cluster_offset + bytes_per_cluster) <= file->offset) {
                cluster_t       cluster_distance;
 
                cluster_offset = sector_offset / sectors_per_cluster;
@@ -804,7 +805,7 @@ _ao_fat_invalidate_cluster_offset(struct ao_fat_dirent *dirent)
                if (!file->busy)
                        continue;
                if (file->dirent == dirent) {
-                       if (file->cluster_offset >= dirent->size) {
+                       if (file->cluster_offset >= (offset_t) dirent->size) {
                                file->cluster_offset = 0;
                                file->cluster = dirent->cluster;
                        }
@@ -838,7 +839,7 @@ _ao_fat_set_size(struct ao_file *file, uint32_t size)
 
        DBG ("\tfirst cluster %08x have %d need %d\n", first_cluster, have_clusters, need_clusters);
        if (have_clusters != need_clusters) {
-               if (file->cluster && size > file->cluster_offset) {
+               if (file->cluster && (offset_t) size > file->cluster_offset) {
                        cluster_t       offset_clusters = (file->cluster_offset + bytes_per_cluster) / bytes_per_cluster;
                        cluster_t       extra_clusters = need_clusters - offset_clusters;
                        cluster_t       next_cluster;
@@ -888,6 +889,7 @@ _ao_fat_set_size(struct ao_file *file, uint32_t size)
 static void
 _ao_fat_root_init(uint8_t *dent, char name[11], uint8_t attr)
 {
+       (void) attr;
        memset(dent, '\0', 0x20);
        memmove(dent, name, 11);
 
@@ -1052,7 +1054,7 @@ static int8_t
 _ao_fat_open(char name[11], uint8_t mode)
 {
        uint16_t                entry = 0;
-       struct ao_fat_dirent    dirent;
+       static struct ao_fat_dirent     dirent;
        int8_t                  status;
 
        if (_ao_fat_setup() != AO_FAT_FILESYSTEM_SUCCESS)
@@ -1214,12 +1216,11 @@ ao_fat_map_current(struct ao_file *file, int len, cluster_offset_t *offsetp, clu
        offset = file->offset & SECTOR_MASK;
        sector = _ao_fat_current_sector(file);
        if (sector == 0xffffffff) {
-               printf ("invalid sector at offset %d\n", file->offset);
                return NULL;
        }
        buf = _ao_fat_sector_get(sector);
        if (!buf)
-               printf ("sector get failed. Sector %d. Partition end %d\n", sector, partition_end);
+               return NULL;
        if (offset + len < SECTOR_SIZE)
                *this_time = len;
        else
@@ -1250,7 +1251,7 @@ ao_fat_read(int8_t fd, void *dst, int len)
                goto done;
        }
 
-       if (file->offset + len > file->dirent->size)
+       if (file->offset + len > (offset_t) file->dirent->size)
                len = file->dirent->size - file->offset;
 
        if (len < 0)
@@ -1259,7 +1260,6 @@ ao_fat_read(int8_t fd, void *dst, int len)
        while (len) {
                buf = ao_fat_map_current(file, len, &offset, &this_time);
                if (!buf) {
-                       printf ("map_current failed\n");
                        ret = -AO_FAT_EIO;
                        break;
                }
@@ -1298,7 +1298,7 @@ ao_fat_write(int8_t fd, void *src, int len)
                goto done;
        }
 
-       if (file->offset + len > file->dirent->size) {
+       if (file->offset + len > (offset_t) file->dirent->size) {
                ret = _ao_fat_set_size(file, file->offset + len);
                if (ret < 0)
                        goto done;
@@ -1307,7 +1307,6 @@ ao_fat_write(int8_t fd, void *src, int len)
        while (len) {
                buf = ao_fat_map_current(file, len, &offset, &this_time);
                if (!buf) {
-                       printf ("map_current failed\n");
                        ret = -AO_FAT_EIO;
                        break;
                }
@@ -1375,7 +1374,7 @@ int8_t
 ao_fat_unlink(char name[11])
 {
        uint16_t                entry = 0;
-       struct ao_fat_dirent    dirent;
+       static struct ao_fat_dirent     dirent;
        int8_t                  ret;
 
        ao_mutex_get(&ao_fat_mutex);
@@ -1427,6 +1426,8 @@ done:
 int8_t
 ao_fat_rename(char old[11], char new[11])
 {
+       (void) old;
+       (void) new;
        return -AO_FAT_EIO;
 }
 
@@ -1492,7 +1493,7 @@ static void
 ao_fat_list_cmd(void)
 {
        uint16_t                entry = 0;
-       struct ao_fat_dirent    dirent;
+       static struct ao_fat_dirent     dirent;
        int                     i;
        int8_t                  status;
 
@@ -1502,7 +1503,7 @@ ao_fat_list_cmd(void)
                putchar('.');
                for (; i < 11; i++)
                        putchar(dirent.name[i]);
-               for (i = 0; i < NUM_FAT_ATTR; i++)
+               for (i = 0; i < (int) NUM_FAT_ATTR; i++)
                        putchar (dirent.attr & ao_fat_attr[i].bit ? ao_fat_attr[i].label : ' ');
                printf (" @%08x %d\n", dirent.cluster, dirent.size);
        }
@@ -1510,7 +1511,7 @@ ao_fat_list_cmd(void)
                printf ("readdir failed: %d\n", status);
 }
 
-static uint8_t
+static void
 ao_fat_parse_name(char name[11])
 {
        uint8_t c;
@@ -1535,10 +1536,10 @@ ao_fat_parse_name(char name[11])
 static void
 ao_fat_dump_cmd(void)
 {
-       char            name[11];
+       static char     name[11];
        int8_t          fd;
        int             cnt, i;
-       char            buf[32];
+       static char     buf[32];
 
        ao_fat_parse_name(name);
        if (name[0] == '\0') {
@@ -1561,10 +1562,8 @@ ao_fat_dump_cmd(void)
 static void
 ao_fat_write_cmd(void)
 {
-       char            name[11];
+       static char     name[11];
        int8_t          fd;
-       int             cnt, i;
-       char            buf[64];
        char            c;
        int             status;