-
-static dir_entry *get_dentfromdir(fsdata *mydata, int startsect,
- char *filename, dir_entry *retdent,
- int dols)
-{
- __u16 prevcksum = 0xffff;
- __u32 curclust = START(retdent);
- int files = 0, dirs = 0;
-
- debug("get_dentfromdir: %s\n", filename);
-
- while (1) {
- dir_entry *dentptr;
-
- int i;
-
- if (get_cluster(mydata, curclust, get_dentfromdir_block,
- mydata->clust_size * mydata->sect_size) != 0) {
- debug("Error: reading directory block\n");
- return NULL;
- }
-
- dentptr = (dir_entry *)get_dentfromdir_block;
-
- for (i = 0; i < DIRENTSPERCLUST; i++) {
- char s_name[14], l_name[VFAT_MAXLEN_BYTES];
-
- l_name[0] = '\0';
- if (dentptr->name[0] == DELETED_FLAG) {
- dentptr++;
- continue;
- }
- if ((dentptr->attr & ATTR_VOLUME)) {
- if (vfat_enabled &&
- (dentptr->attr & ATTR_VFAT) == ATTR_VFAT &&
- (dentptr->name[0] & LAST_LONG_ENTRY_MASK)) {
- prevcksum = ((dir_slot *)dentptr)->alias_checksum;
- get_vfatname(mydata, curclust,
- get_dentfromdir_block,
- dentptr, l_name);
- if (dols) {
- int isdir;
- char dirc;
- int doit = 0;
-
- isdir = (dentptr->attr & ATTR_DIR);
-
- if (isdir) {
- dirs++;
- dirc = '/';
- doit = 1;
- } else {
- dirc = ' ';
- if (l_name[0] != 0) {
- files++;
- doit = 1;
- }
- }
- if (doit) {
- if (dirc == ' ') {
- printf(" %8u %s%c\n",
- FAT2CPU32(dentptr->size),
- l_name,
- dirc);
- } else {
- printf(" %s%c\n",
- l_name,
- dirc);
- }
- }
- dentptr++;
- continue;
- }
- debug("vfatname: |%s|\n", l_name);
- } else {
- /* Volume label or VFAT entry */
- dentptr++;
- continue;
- }
- }
- if (dentptr->name[0] == 0) {
- if (dols) {
- printf("\n%d file(s), %d dir(s)\n\n",
- files, dirs);
- }
- debug("Dentname == NULL - %d\n", i);
- return NULL;
- }
- if (vfat_enabled) {
- __u8 csum = mkcksum(dentptr->name, dentptr->ext);
- if (dols && csum == prevcksum) {
- prevcksum = 0xffff;
- dentptr++;
- continue;
- }
- }
-
- get_name(dentptr, s_name);
- if (dols) {
- int isdir = (dentptr->attr & ATTR_DIR);
- char dirc;
- int doit = 0;
-
- if (isdir) {
- dirs++;
- dirc = '/';
- doit = 1;
- } else {
- dirc = ' ';
- if (s_name[0] != 0) {
- files++;
- doit = 1;
- }
- }
-
- if (doit) {
- if (dirc == ' ') {
- printf(" %8u %s%c\n",
- FAT2CPU32(dentptr->size),
- s_name, dirc);
- } else {
- printf(" %s%c\n",
- s_name, dirc);
- }
- }
-
- dentptr++;
- continue;
- }
-
- if (strcmp(filename, s_name)
- && strcmp(filename, l_name)) {
- debug("Mismatch: |%s|%s|\n", s_name, l_name);
- dentptr++;
- continue;
- }
-
- memcpy(retdent, dentptr, sizeof(dir_entry));
-
- debug("DentName: %s", s_name);
- debug(", start: 0x%x", START(dentptr));
- debug(", size: 0x%x %s\n",
- FAT2CPU32(dentptr->size),
- (dentptr->attr & ATTR_DIR) ? "(DIR)" : "");
-
- return retdent;
- }
-
- curclust = get_fatent(mydata, curclust);
- if (CHECK_CLUST(curclust, mydata->fatsize)) {
- debug("curclust: 0x%x\n", curclust);
- printf("Invalid FAT entry\n");
- return NULL;
- }
- }
-
- return NULL;
-}