/* * smb_trans2_find_entries * * Find and encode up to args->fa_maxcount directory entries. * For compatibilty with Windows, if args->fa_maxcount is zero treat it as 1. * * Returns: * count - count of entries encoded * *eos = B_TRUE if no more directory entries * -1 - error */ static int smb_trans2_find_entries(smb_request_t *sr, smb_xa_t *xa, smb_odir_t *od, smb_find_args_t *args, boolean_t *eos) { int rc; uint16_t count, maxcount; uint32_t cookie; smb_fileinfo_t fileinfo; if ((maxcount = args->fa_maxcount) == 0) maxcount = 1; if ((smb_trans2_find_max != 0) && (maxcount > smb_trans2_find_max)) maxcount = smb_trans2_find_max; count = 0; while (count < maxcount) { if (smb_odir_read_fileinfo(sr, od, &fileinfo, eos) != 0) return (-1); if (*eos == B_TRUE) break; rc = smb_trans2_find_mbc_encode(sr, xa, &fileinfo, args); if (rc == -1) return (-1); if (rc == 1) break; cookie = fileinfo.fi_cookie; ++count; } /* save the last cookie returned to client */ if (count != 0) smb_odir_save_cookie(od, 0, cookie); /* * If all retrieved entries have been successfully encoded * and eos has not already been detected, check if there are * any more entries. eos will be set if there are no more. */ if ((rc == 0) && (!*eos)) (void) smb_odir_read_fileinfo(sr, od, &fileinfo, eos); return (count); }
/* * smb_trans2_find_entries * * Find and encode up to args->fa_maxcount directory entries. * For compatibilty with Windows, if args->fa_maxcount is zero treat it as 1. * * Returns: * count - count of entries encoded * *eos = B_TRUE if no more directory entries * -1 - error */ static int smb_trans2_find_entries(smb_request_t *sr, smb_xa_t *xa, smb_odir_t *od, smb_find_args_t *args) { int rc; uint16_t count, maxcount; smb_fileinfo_t fileinfo; smb_odir_resume_t odir_resume; if ((maxcount = args->fa_maxcount) == 0) maxcount = 1; if ((smb_trans2_find_max != 0) && (maxcount > smb_trans2_find_max)) maxcount = smb_trans2_find_max; count = 0; while (count < maxcount) { if (smb_odir_read_fileinfo(sr, od, &fileinfo, &args->fa_eos) != 0) return (-1); if (args->fa_eos != 0) break; rc = smb_trans2_find_mbc_encode(sr, xa, &fileinfo, args); if (rc == -1) return (-1); if (rc == 1) break; /* * Save the info about the last file returned. */ args->fa_lastkey = fileinfo.fi_cookie; bcopy(fileinfo.fi_name, args->fa_lastname, MAXNAMELEN); ++count; } /* save the last cookie returned to client */ if (count != 0) smb_odir_save_fname(od, args->fa_lastkey, args->fa_lastname); /* * If all retrieved entries have been successfully encoded * and eos has not already been detected, check if there are * any more entries. eos will be set if there are no more. */ if ((rc == 0) && (args->fa_eos == 0)) (void) smb_odir_read_fileinfo(sr, od, &fileinfo, &args->fa_eos); /* * When the last entry we read from the directory did not * fit in the return buffer, we will have read one entry * that will not be returned in this call. That, and the * check for EOS just above both can leave the directory * position incorrect for the next call. Fix that now. */ bzero(&odir_resume, sizeof (odir_resume)); odir_resume.or_type = SMB_ODIR_RESUME_COOKIE; odir_resume.or_cookie = args->fa_lastkey; smb_odir_resume_at(od, &odir_resume); return (count); }