-#if CONFIG_NIOS /* NIOS CPU cannot access big automatic arrays */
- static
-#endif
- char fnamecopy[2048];
- boot_sector bs;
- volume_info volinfo;
- fsdata datablock;
- fsdata *mydata = &datablock;
- dir_entry *dentptr;
- __u16 prevcksum = 0xffff;
- char *subname = "";
- int rootdir_size, cursect;
- int idx, isdir = 0;
- int files = 0, dirs = 0;
- long ret = 0;
- int firsttime;
-
- if (read_bootsectandvi (&bs, &volinfo, &mydata->fatsize)) {
- FAT_DPRINT ("Error: reading boot sector\n");
- return -1;
- }
- if (mydata->fatsize == 32) {
- mydata->fatlength = bs.fat32_length;
- } else {
- mydata->fatlength = bs.fat_length;
- }
- mydata->fat_sect = bs.reserved;
- cursect = mydata->rootdir_sect
- = mydata->fat_sect + mydata->fatlength * bs.fats;
- mydata->clust_size = bs.cluster_size;
- if (mydata->fatsize == 32) {
- rootdir_size = mydata->clust_size;
- mydata->data_begin = mydata->rootdir_sect /* + rootdir_size */
- - (mydata->clust_size * 2);
- } else {
- rootdir_size = ((bs.dir_entries[1] * (int) 256 + bs.dir_entries[0])
- * sizeof (dir_entry)) / SECTOR_SIZE;
- mydata->data_begin = mydata->rootdir_sect + rootdir_size
- - (mydata->clust_size * 2);
- }
- mydata->fatbufnum = -1;
-
- FAT_DPRINT ("FAT%d, fatlength: %d\n", mydata->fatsize,
- mydata->fatlength);
- FAT_DPRINT ("Rootdir begins at sector: %d, offset: %x, size: %d\n"
- "Data begins at: %d\n",
- mydata->rootdir_sect, mydata->rootdir_sect * SECTOR_SIZE,
- rootdir_size, mydata->data_begin);
- FAT_DPRINT ("Cluster size: %d\n", mydata->clust_size);
-
- /* "cwd" is always the root... */
- while (ISDIRDELIM (*filename))
- filename++;
- /* Make a copy of the filename and convert it to lowercase */
- strcpy (fnamecopy, filename);
- downcase (fnamecopy);
- if (*fnamecopy == '\0') {
- if (!dols)
- return -1;
- dols = LS_ROOT;
- } else if ((idx = dirdelim (fnamecopy)) >= 0) {
- isdir = 1;
- fnamecopy[idx] = '\0';
- subname = fnamecopy + idx + 1;
- /* Handle multiple delimiters */
- while (ISDIRDELIM (*subname))
- subname++;
- } else if (dols) {
- isdir = 1;
- }
-
- while (1) {
- int i;
+ char fnamecopy[2048];
+ boot_sector bs;
+ volume_info volinfo;
+ fsdata datablock;
+ fsdata *mydata = &datablock;
+ dir_entry *dentptr = NULL;
+ __u16 prevcksum = 0xffff;
+ char *subname = "";
+ __u32 cursect;
+ int idx, isdir = 0;
+ int files = 0, dirs = 0;
+ long ret = -1;
+ int firsttime;
+ __u32 root_cluster = 0;
+ int rootdir_size = 0;
+ int j;
+
+ if (read_bootsectandvi(&bs, &volinfo, &mydata->fatsize)) {
+ debug("Error: reading boot sector\n");
+ return -1;
+ }
+
+ if (mydata->fatsize == 32) {
+ root_cluster = bs.root_cluster;
+ mydata->fatlength = bs.fat32_length;
+ } else {
+ mydata->fatlength = bs.fat_length;
+ }