Skip to content

Commit 41f949e

Browse files
authored
merging v3 to main for a base (#7)
* restructure * in-flight structs * queue creation and submition * handle completion init * main:v1::3 * traiing fix getdent64() * imp: custom #6 * make change * Moving Hybrid * recursive-tree init * minor typo : : awating approval #6 * tested - Adding build files * code cleanup awaiting approval awaiting build files * tested - adding build file * [STAGE] merge-step-1 * chaning * check * pushing readmes * usage update * changing * readme edit * readme edit * readme edit * Add MIT License to the project * Add LICENSE file * Add LICENSE file * Add GNUL license file * adding licence * redo * Add MIT License file * adding LGNU * adding licences * add: debian * add: debian builds
1 parent f7442c6 commit 41f949e

File tree

23 files changed

+1213
-380
lines changed

23 files changed

+1213
-380
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ testdir
33
ffind.*
44
.vscode/
55
temp.md
6+
.DS_Store

COPYING

Lines changed: 504 additions & 0 deletions
Large diffs are not rendered by default.

COPYING.GPL

Lines changed: 339 additions & 0 deletions
Large diffs are not rendered by default.

LICENCE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
MIT License
3+
4+
Copyright (c) 2025 Archit Anant
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.

Makefile

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,47 @@
1-
# Compiler and flags
2-
CC = gcc
3-
CFLAGS = -Wall -Iinclude -g # -g for debugging symbols
1+
CC := gcc
2+
INC_DIR := headers
43

5-
# Source and build directories
6-
SRC_DIR = src
7-
BUILD_DIR = build
8-
SRC = $(SRC_DIR)/main.c $(SRC_DIR)/workqueue.c $(SRC_DIR)/worker.c
9-
OBJ = $(SRC:%.c=$(BUILD_DIR)/%.o)
4+
# Use pkg-config if available for liburing
5+
PKG_CFLAGS := $(shell pkg-config --cflags liburing 2>/dev/null)
6+
PKG_LIBS := $(shell pkg-config --libs liburing 2>/dev/null)
107

11-
# Target binary
12-
TARGET = $(BUILD_DIR)/ffind
8+
CFLAGS := -Wall -Wextra -O2 -I$(INC_DIR) $(PKG_CFLAGS)
9+
LDLIBS := $(if $(PKG_LIBS),$(PKG_LIBS),-luring)
1310

14-
# Ensure build directory exists
15-
$(shell mkdir -p $(BUILD_DIR)/$(SRC_DIR))
11+
SRC_DIR := src
12+
BUILD_DIR := build
13+
14+
# Source and object files
15+
SRCS := $(wildcard $(SRC_DIR)/*.c)
16+
OBJS := $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/%.o,$(SRCS))
17+
TARGET := $(BUILD_DIR)/ffind
18+
19+
# Install prefix (Debian packaging overrides with DESTDIR + PREFIX=/usr)
20+
PREFIX ?= /usr
21+
BINDIR := $(PREFIX)/bin
1622

17-
# Default rule
1823
all: $(TARGET)
1924

20-
# Link object files to create the binary
21-
$(TARGET): $(OBJ)
22-
$(CC) $(OBJ) -o $(TARGET)
25+
$(TARGET): $(OBJS) | $(BUILD_DIR)
26+
$(CC) $(CFLAGS) -o $@ $^ $(LDLIBS)
2327

24-
# Compile source files to object files
25-
$(BUILD_DIR)/%.o: %.c
28+
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c $(INC_DIR)/submissions.h | $(BUILD_DIR)
2629
$(CC) $(CFLAGS) -c $< -o $@
2730

28-
# Clean build artifacts
31+
$(BUILD_DIR):
32+
mkdir -p $(BUILD_DIR)
33+
34+
install: $(TARGET)
35+
mkdir -p $(DESTDIR)$(BINDIR)
36+
cp $(TARGET) $(DESTDIR)$(BINDIR)/ffind
37+
38+
uninstall:
39+
rm -f $(DESTDIR)$(BINDIR)/ffind
40+
2941
clean:
3042
rm -rf $(BUILD_DIR)
3143

32-
.PHONY: all clean
44+
run: $(TARGET)
45+
./$(TARGET) testdir
3346

47+
.PHONY: all clean run install uninstall

README

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
2+
3+
ffind
4+
-----
5+
6+
An Asynchronous File Finder for Linux
7+
8+
ffind is a high-performance, command-line utility for recursively finding files on a Linux filesystem. It is built from the ground up using io_uring, the modern asynchronous I/O interface in the Linux kernel, to achieve maximum throughput and efficiency.
9+
10+
ffind is designed to do one thing exceptionally well: find files that contain a specific substring in their name, as fast as possible.
11+
12+
13+
14+
Usage
15+
_____
16+
17+
CHECK :: USAGE.md
18+
19+
20+
21+
Working
22+
_______
23+
24+
The Asynchronous io_uring Engine :
25+
26+
ffind achieves its performance by fundamentally changing the conversation with the Linux kernel. Instead of the traditional "ask and wait" (blocking) model, ffind uses an event-driven, asynchronous architecture.
27+
28+
29+
The Core Components :
30+
31+
io_uring : The foundation of the application. ffind initializes an io_uring instance, creating two ring buffers in memory that are shared directly with the kernel: the Submission Queue (SQ) and the Completion Queue (CQ). This shared memory allows for extremely low-overhead communication.
32+
33+
34+
The Event Loop :
35+
36+
The application is built around a single-threaded event loop in main(). This loop's only job is to manage the flow of I/O operations:
37+
- Submit pending requests from the SQ to the kernel.
38+
- Wait for completion events (CQEs) to appear on the CQ.
39+
- Dispatch completed events to a handler function.
40+
- Repeat.
41+
42+
The State Machine (handle_completion) :
43+
44+
The heart of the logic resides in the handle_completion function. Since operations are asynchronous and can complete in any order, a state machine is used to track the progress of each directory scan.
45+
46+
A single Request struct holds the state for scanning one directory, transitioning through different phases:
47+
48+
- Open Phase:
49+
An openat operation is submitted. When it completes, the function receives a file descriptor (fd).
50+
51+
- Read Phase:
52+
The function stores the fd in the Request struct and submits a getdents64 operation (using the IORING_OP_READ opcode on the directory fd) to read the directory's contents.
53+
54+
- Process and Recurse:
55+
When the read completes, the buffer of directory entries is processed. For each subdirectory found, a new openat request is submitted, creating a new task. For each file, the name is checked against the search term.
56+
57+
- Terminal State:
58+
When a directory read returns 0 bytes, the directory scan is complete. The file descriptor is closed, and all associated memory is freed.
59+
60+
61+
Targeting Efficiency :
62+
63+
- Reduced System Call Overhead : The most expensive part of traditional I/O is the context switch between user space and kernel space for each system call. With io_uring, ffind can submit a large batch of I/O requests with a single syscall, and reap many completions with another. This drastically reduces the number of context switches.
64+
65+
- True Asynchronicity : ffind can have hundreds or thousands of filesystem operations "in-flight" simultaneously. While the kernel is working on opening one directory or reading another, the application's CPU is free to process the results of already-completed operations. This keeps the CPU and the storage device constantly busy, maximizing parallelism.
66+
67+
- Kernel-Side Polling (Optional) : For ultimate low-latency, io_uring can be configured to use kernel-side polling (IORING_SETUP_SQPOLL), which can eliminate system calls from the submission path almost entirely under heavy load.
68+
69+
70+
License
71+
-------
72+
73+
All software contained within this repo is dual licensed LGPL and MIT.
74+
75+
76+
Archit Anant 2025-09-23
77+

README.md

Lines changed: 0 additions & 32 deletions
This file was deleted.

USAGE.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
## Usage
2+
**Prerequisites**
3+
ffind requires a modern Linux kernel (5.10+ recommended) and the liburing development library.
4+
5+
### On Debian/Ubuntu
6+
```shell
7+
sudo apt-get install build-essential liburing-dev
8+
# you can search for equivalent packages for Arch/Fedora.
9+
```
10+
### Compile the application
11+
```shell
12+
make
13+
```
14+
15+
### Clean up build files
16+
```bash
17+
make clean
18+
```
19+
### Examples
20+
```shell
21+
./ffind <path> <search_term>
22+
23+
# Search for all files containing "config" in your home directory
24+
./ffind ~ config
25+
26+
# Search for all header files containing "net" in /usr/include
27+
./ffind /usr/include net
28+
29+
# Find all Markdown files in the current directory
30+
./ffind . .md
31+
```

debian/changelog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ffind (1.0-1) unstable; urgency=medium
2+
3+
* Initial release (Closes: #000000)
4+
5+
-- Archit Anant <[email protected]> Sat, 23 Aug 2025 20:00:00 +0530

debian/control

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Source: ffind
2+
Section: utils
3+
Priority: optional
4+
Maintainer: Archit Anant <[email protected]>
5+
Build-Depends: debhelper-compat (= 13), pkg-config, liburing-dev
6+
Standards-Version: 4.6.2
7+
Rules-Requires-Root: no
8+
9+
Package: ffind
10+
Architecture: any
11+
Depends: ${shlibs:Depends}, ${misc:Depends}, liburing2
12+
Description: Fast file finder using io_uring
13+
ffind is a fast alternative to find files, implemented using Linux io_uring.
14+

0 commit comments

Comments
 (0)