routine dir_readdir (
    dir: file_t;
    RPT
    out data: data_t, dealloc[];
    entry: int;
    nentries: int;
    bufsiz: vm_size_t;
    out amount: int);

Read entries from the directory. Each entry is identified by an index number starting at 0 and running through the file. This call fetches nentries (or any convenient number if nentries is -1) entries starting at entry, returning a series of struct dirent in data. Note that due to the variable-size d_name field, d_reclen has to be used to jump from one struct dirent to the other. The number of entries successfully read is returned in amount. If entry is bigger than the index of the last entry, then 0 is returned in amount. If bufsize is nonzero, never return more than bufsize bytes of data regardless.