NTSTATUS PvfsFileDirname( PSTR *ppszDirname, PCSTR pszPath ) { NTSTATUS ntError = STATUS_UNSUCCESSFUL; PSTR pszCursor = NULL; PSTR pszNewString = NULL; /* Case #1: No '/' so just return '.' */ if (((pszCursor = strrchr(pszPath, '/')) == NULL)) { ntError = RtlCStringDuplicate(ppszDirname, "."); goto cleanup; } /* Case #2: only one '/' (at beginning of path) */ if (pszCursor == pszPath) { ntError = RtlCStringDuplicate(ppszDirname, "/"); goto cleanup; } /* Case #3: Real dirname and file name components */ ntError = RTL_ALLOCATE(&pszNewString, CHAR, PVFS_PTR_DIFF(pszPath,pszCursor) + 1); BAIL_ON_NT_STATUS(ntError); RtlCopyMemory(pszNewString, pszPath, PVFS_PTR_DIFF(pszPath,pszCursor)); *ppszDirname = pszNewString; ntError = STATUS_SUCCESS; cleanup: return ntError; error: goto cleanup; }
static NTSTATUS PvfsNotifyReportBuffer( PPVFS_NOTIFY_FILTER_BUFFER pFilterBuffer, FILE_ACTION Action, PCSTR pszFilename ) { NTSTATUS ntError = STATUS_UNSUCCESSFUL; PVOID pBuffer = pFilterBuffer->pData + pFilterBuffer->Offset; ULONG Length = pFilterBuffer->Length - pFilterBuffer->Offset; PFILE_NOTIFY_INFORMATION pNotifyInfo = NULL; LONG FilenameBytes = 0; PWSTR pwszFilename = NULL; ULONG BytesNeeded = 0; /* Don't bother if we have already overflowed the buffer */ BAIL_ON_NT_STATUS(pFilterBuffer->Status); ntError = LwRtlWC16StringAllocateFromCString(&pwszFilename, pszFilename); BAIL_ON_NT_STATUS(ntError); FilenameBytes = (LwRtlWC16StringNumChars(pwszFilename) + 1) * sizeof(WCHAR); BytesNeeded = sizeof(*pNotifyInfo) + FilenameBytes; PVFS_ALIGN_MEMORY(BytesNeeded, 8); if (Length < BytesNeeded) { ntError = pFilterBuffer->Status = STATUS_NOTIFY_ENUM_DIR; BAIL_ON_NT_STATUS(ntError); } pNotifyInfo = (PFILE_NOTIFY_INFORMATION)pBuffer; pNotifyInfo->NextEntryOffset = 0; pNotifyInfo->Action = Action; pNotifyInfo->FileNameLength = FilenameBytes; memcpy(&pNotifyInfo->FileName, pwszFilename, FilenameBytes); if (pFilterBuffer->pNotify) { ULONG NextEntry = PVFS_PTR_DIFF(pFilterBuffer->pNotify, pNotifyInfo); pFilterBuffer->pNotify->NextEntryOffset = NextEntry; } pFilterBuffer->pNotify = pNotifyInfo; pFilterBuffer->Offset += BytesNeeded; cleanup: LwRtlWC16StringFree(&pwszFilename); return ntError; error: goto cleanup; }