/* * dir.h — directory iteration via ESTEX F_FIRST / F_NEXT ($19 / $1A). * * ffirst(pattern, &buf, attrib) * Initialises the search. The pattern is a DOS wildcard like * `*.TXT` or `DATA\\*`. attrib is the search mask (use FA_NORMAL * to match plain files, OR in FA_DIREC to include subdirectories). * Returns 0 on success (buf is populated), -1 on failure (errno set). * * fnext(&buf) * Steps to the next matching entry, reusing the same buf. Returns * 0 on success, -1 when no more files match (errno = ENOENT) or on * other errors. * * The buffer fields below mirror ESTEX's layout exactly so we can hand * it straight to the kernel. Use `buf.found_name` (NUL-terminated DOS * "name.ext" form) to display results. */ #ifndef DIR_H #define DIR_H #include /* File attribute bits (ESTEX / DOS standard). */ #define FA_NORMAL 0x00 #define FA_RDONLY 0x01 #define FA_HIDDEN 0x02 #define FA_SYSTEM 0x04 #define FA_LABEL 0x08 #define FA_DIREC 0x10 #define FA_ARCH 0x20 /* 256-byte work buffer for ESTEX F_FIRST / F_NEXT (B=1 mode). */ typedef struct { char name[8]; /* +0 pattern: 8-byte filename */ char ext[3]; /* +8 pattern: 3-byte extension */ uint8_t attrib; /* +11 search attribute */ char reserved[10]; /* +12 DSS internal state */ uint16_t time; /* +22 time of last write */ uint16_t date; /* +24 date of last write */ uint16_t first_cluster; /* +26 first cluster */ uint32_t size; /* +28 file size in bytes */ uint8_t found_attr; /* +32 attribute of the matched file */ char found_name[223]; /* +33 NUL-terminated "name.ext" */ } ffblk_t; int ffirst(const char *pattern, ffblk_t *buf, uint8_t attrib); int fnext (ffblk_t *buf); #endif