[libc-commits] [libc] [libc] add statvfs/fstatvfs (PR #86169)

Nick Desaulniers via libc-commits libc-commits at lists.llvm.org
Fri Mar 22 09:44:27 PDT 2024


================
@@ -0,0 +1,85 @@
+//===-- Convert Statfs to Statvfs -------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_SYS_STATVFS_LINUX_STATFS_TO_STATVFS_H
+#define LLVM_LIBC_SRC_SYS_STATVFS_LINUX_STATFS_TO_STATVFS_H
+
+#include "llvm-libc-types/struct_statvfs.h"
+#include "src/__support/CPP/optional.h"
+#include "src/__support/OSUtil/syscall.h"
+#include "src/__support/macros/attributes.h"
+#include "src/errno/libc_errno.h"
+#include <asm/statfs.h>
+#include <sys/syscall.h>
+namespace LIBC_NAMESPACE {
+
+namespace statfs_utils {
+#ifdef SYS_statfs64
+using LinuxStatFs = statfs64;
+#else
+using LinuxStatFs = statfs;
+#endif
+
+LIBC_INLINE cpp::optional<LinuxStatFs> linux_statfs(const char *path) {
+#ifdef __clang__
+  // Disable pattern filling for result buffer: this struct is to be populated
+  // by the syscall.
+  [[clang::uninitialized]]
+#endif
----------------
nickdesaulniers wrote:

We'll need to read through linux/fs/statfs.c to verify that the kernel shouldn't return early.

I would like the ensure we don't end up returning uninitialized memory to our caller.

cc @thejh

https://github.com/llvm/llvm-project/pull/86169


More information about the libc-commits mailing list