Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools: sync uapi/linux/fs.h header into tools subdir

We need this UAPI header in tools/include subdirectory for using it from
BPF selftests.

Link: https://lkml.kernel.org/r/20240627170900.1672542-6-andrii@kernel.org
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Mike Rapoport (IBM) <rppt@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Andrii Nakryiko and committed by
Andrew Morton
77179b6f c10cb914

+170 -10
+170 -10
tools/include/uapi/linux/fs.h
··· 1 1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 - #ifndef _LINUX_FS_H 3 - #define _LINUX_FS_H 2 + #ifndef _UAPI_LINUX_FS_H 3 + #define _UAPI_LINUX_FS_H 4 4 5 5 /* 6 6 * This file has definitions for some important file table structures ··· 13 13 #include <linux/limits.h> 14 14 #include <linux/ioctl.h> 15 15 #include <linux/types.h> 16 + #ifndef __KERNEL__ 16 17 #include <linux/fscrypt.h> 18 + #endif 17 19 18 20 /* Use of MS_* flags within the kernel is restricted to core mount(2) code. */ 21 + #if !defined(__KERNEL__) 19 22 #include <linux/mount.h> 23 + #endif 20 24 21 25 /* 22 26 * It's silly to have NR_OPEN bigger than NR_FILE, but you can change ··· 312 308 typedef int __bitwise __kernel_rwf_t; 313 309 314 310 /* high priority request, poll if possible */ 315 - #define RWF_HIPRI ((__kernel_rwf_t)0x00000001) 311 + #define RWF_HIPRI ((__force __kernel_rwf_t)0x00000001) 316 312 317 313 /* per-IO O_DSYNC */ 318 - #define RWF_DSYNC ((__kernel_rwf_t)0x00000002) 314 + #define RWF_DSYNC ((__force __kernel_rwf_t)0x00000002) 319 315 320 316 /* per-IO O_SYNC */ 321 - #define RWF_SYNC ((__kernel_rwf_t)0x00000004) 317 + #define RWF_SYNC ((__force __kernel_rwf_t)0x00000004) 322 318 323 319 /* per-IO, return -EAGAIN if operation would block */ 324 - #define RWF_NOWAIT ((__kernel_rwf_t)0x00000008) 320 + #define RWF_NOWAIT ((__force __kernel_rwf_t)0x00000008) 325 321 326 322 /* per-IO O_APPEND */ 327 - #define RWF_APPEND ((__kernel_rwf_t)0x00000010) 323 + #define RWF_APPEND ((__force __kernel_rwf_t)0x00000010) 328 324 329 325 /* per-IO negation of O_APPEND */ 330 - #define RWF_NOAPPEND ((__kernel_rwf_t)0x00000020) 326 + #define RWF_NOAPPEND ((__force __kernel_rwf_t)0x00000020) 331 327 332 328 /* mask of flags supported by the kernel */ 333 329 #define RWF_SUPPORTED (RWF_HIPRI | RWF_DSYNC | RWF_SYNC | RWF_NOWAIT |\ 334 330 RWF_APPEND | RWF_NOAPPEND) 335 331 332 + #define PROCFS_IOCTL_MAGIC 'f' 333 + 336 334 /* Pagemap ioctl */ 337 - #define PAGEMAP_SCAN _IOWR('f', 16, struct pm_scan_arg) 335 + #define PAGEMAP_SCAN _IOWR(PROCFS_IOCTL_MAGIC, 16, struct pm_scan_arg) 338 336 339 337 /* Bitmasks provided in pm_scan_args masks and reported in page_region.categories. */ 340 338 #define PAGE_IS_WPALLOWED (1 << 0) ··· 395 389 __u64 return_mask; 396 390 }; 397 391 398 - #endif /* _LINUX_FS_H */ 392 + /* /proc/<pid>/maps ioctl */ 393 + #define PROCMAP_QUERY _IOWR(PROCFS_IOCTL_MAGIC, 17, struct procmap_query) 394 + 395 + enum procmap_query_flags { 396 + /* 397 + * VMA permission flags. 398 + * 399 + * Can be used as part of procmap_query.query_flags field to look up 400 + * only VMAs satisfying specified subset of permissions. E.g., specifying 401 + * PROCMAP_QUERY_VMA_READABLE only will return both readable and read/write VMAs, 402 + * while having PROCMAP_QUERY_VMA_READABLE | PROCMAP_QUERY_VMA_WRITABLE will only 403 + * return read/write VMAs, though both executable/non-executable and 404 + * private/shared will be ignored. 405 + * 406 + * PROCMAP_QUERY_VMA_* flags are also returned in procmap_query.vma_flags 407 + * field to specify actual VMA permissions. 408 + */ 409 + PROCMAP_QUERY_VMA_READABLE = 0x01, 410 + PROCMAP_QUERY_VMA_WRITABLE = 0x02, 411 + PROCMAP_QUERY_VMA_EXECUTABLE = 0x04, 412 + PROCMAP_QUERY_VMA_SHARED = 0x08, 413 + /* 414 + * Query modifier flags. 415 + * 416 + * By default VMA that covers provided address is returned, or -ENOENT 417 + * is returned. With PROCMAP_QUERY_COVERING_OR_NEXT_VMA flag set, closest 418 + * VMA with vma_start > addr will be returned if no covering VMA is 419 + * found. 420 + * 421 + * PROCMAP_QUERY_FILE_BACKED_VMA instructs query to consider only VMAs that 422 + * have file backing. Can be combined with PROCMAP_QUERY_COVERING_OR_NEXT_VMA 423 + * to iterate all VMAs with file backing. 424 + */ 425 + PROCMAP_QUERY_COVERING_OR_NEXT_VMA = 0x10, 426 + PROCMAP_QUERY_FILE_BACKED_VMA = 0x20, 427 + }; 428 + 429 + /* 430 + * Input/output argument structured passed into ioctl() call. It can be used 431 + * to query a set of VMAs (Virtual Memory Areas) of a process. 432 + * 433 + * Each field can be one of three kinds, marked in a short comment to the 434 + * right of the field: 435 + * - "in", input argument, user has to provide this value, kernel doesn't modify it; 436 + * - "out", output argument, kernel sets this field with VMA data; 437 + * - "in/out", input and output argument; user provides initial value (used 438 + * to specify maximum allowable buffer size), and kernel sets it to actual 439 + * amount of data written (or zero, if there is no data). 440 + * 441 + * If matching VMA is found (according to criterias specified by 442 + * query_addr/query_flags, all the out fields are filled out, and ioctl() 443 + * returns 0. If there is no matching VMA, -ENOENT will be returned. 444 + * In case of any other error, negative error code other than -ENOENT is 445 + * returned. 446 + * 447 + * Most of the data is similar to the one returned as text in /proc/<pid>/maps 448 + * file, but procmap_query provides more querying flexibility. There are no 449 + * consistency guarantees between subsequent ioctl() calls, but data returned 450 + * for matched VMA is self-consistent. 451 + */ 452 + struct procmap_query { 453 + /* Query struct size, for backwards/forward compatibility */ 454 + __u64 size; 455 + /* 456 + * Query flags, a combination of enum procmap_query_flags values. 457 + * Defines query filtering and behavior, see enum procmap_query_flags. 458 + * 459 + * Input argument, provided by user. Kernel doesn't modify it. 460 + */ 461 + __u64 query_flags; /* in */ 462 + /* 463 + * Query address. By default, VMA that covers this address will 464 + * be looked up. PROCMAP_QUERY_* flags above modify this default 465 + * behavior further. 466 + * 467 + * Input argument, provided by user. Kernel doesn't modify it. 468 + */ 469 + __u64 query_addr; /* in */ 470 + /* VMA starting (inclusive) and ending (exclusive) address, if VMA is found. */ 471 + __u64 vma_start; /* out */ 472 + __u64 vma_end; /* out */ 473 + /* VMA permissions flags. A combination of PROCMAP_QUERY_VMA_* flags. */ 474 + __u64 vma_flags; /* out */ 475 + /* VMA backing page size granularity. */ 476 + __u64 vma_page_size; /* out */ 477 + /* 478 + * VMA file offset. If VMA has file backing, this specifies offset 479 + * within the file that VMA's start address corresponds to. 480 + * Is set to zero if VMA has no backing file. 481 + */ 482 + __u64 vma_offset; /* out */ 483 + /* Backing file's inode number, or zero, if VMA has no backing file. */ 484 + __u64 inode; /* out */ 485 + /* Backing file's device major/minor number, or zero, if VMA has no backing file. */ 486 + __u32 dev_major; /* out */ 487 + __u32 dev_minor; /* out */ 488 + /* 489 + * If set to non-zero value, signals the request to return VMA name 490 + * (i.e., VMA's backing file's absolute path, with " (deleted)" suffix 491 + * appended, if file was unlinked from FS) for matched VMA. VMA name 492 + * can also be some special name (e.g., "[heap]", "[stack]") or could 493 + * be even user-supplied with prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME). 494 + * 495 + * Kernel will set this field to zero, if VMA has no associated name. 496 + * Otherwise kernel will return actual amount of bytes filled in 497 + * user-supplied buffer (see vma_name_addr field below), including the 498 + * terminating zero. 499 + * 500 + * If VMA name is longer that user-supplied maximum buffer size, 501 + * -E2BIG error is returned. 502 + * 503 + * If this field is set to non-zero value, vma_name_addr should point 504 + * to valid user space memory buffer of at least vma_name_size bytes. 505 + * If set to zero, vma_name_addr should be set to zero as well 506 + */ 507 + __u32 vma_name_size; /* in/out */ 508 + /* 509 + * If set to non-zero value, signals the request to extract and return 510 + * VMA's backing file's build ID, if the backing file is an ELF file 511 + * and it contains embedded build ID. 512 + * 513 + * Kernel will set this field to zero, if VMA has no backing file, 514 + * backing file is not an ELF file, or ELF file has no build ID 515 + * embedded. 516 + * 517 + * Build ID is a binary value (not a string). Kernel will set 518 + * build_id_size field to exact number of bytes used for build ID. 519 + * If build ID is requested and present, but needs more bytes than 520 + * user-supplied maximum buffer size (see build_id_addr field below), 521 + * -E2BIG error will be returned. 522 + * 523 + * If this field is set to non-zero value, build_id_addr should point 524 + * to valid user space memory buffer of at least build_id_size bytes. 525 + * If set to zero, build_id_addr should be set to zero as well 526 + */ 527 + __u32 build_id_size; /* in/out */ 528 + /* 529 + * User-supplied address of a buffer of at least vma_name_size bytes 530 + * for kernel to fill with matched VMA's name (see vma_name_size field 531 + * description above for details). 532 + * 533 + * Should be set to zero if VMA name should not be returned. 534 + */ 535 + __u64 vma_name_addr; /* in */ 536 + /* 537 + * User-supplied address of a buffer of at least build_id_size bytes 538 + * for kernel to fill with matched VMA's ELF build ID, if available 539 + * (see build_id_size field description above for details). 540 + * 541 + * Should be set to zero if build ID should not be returned. 542 + */ 543 + __u64 build_id_addr; /* in */ 544 + }; 545 + 546 + #endif /* _UAPI_LINUX_FS_H */