A distributed file system implementation using C programming and socket communication, designed for educational purposes and demonstrating basic distributed computing concepts.
The system consists of 4 servers and 1 client that work together to provide a distributed file storage solution:
- S1 (Main Server): Primary server that handles client connections and coordinates file distribution
- S2 (PDF Server): Dedicated server for storing PDF files
- S3 (Text Server): Dedicated server for storing text files
- S4 (ZIP Server): Dedicated server for storing ZIP files
- s25client: Client application for user interaction
Files are automatically distributed based on their extensions:
File Type | Extension | Storage Location |
---|---|---|
C Source Files | .c |
S1 (Main Server) |
PDF Documents | .pdf |
S2 (PDF Server) |
Text Files | .txt |
S3 (Text Server) |
ZIP Archives | .zip |
S4 (ZIP Server) |
- Multi-client Support: S1 uses
fork()
to handle multiple concurrent client connections - Automatic File Distribution: Files are automatically routed to appropriate servers
- Transparent Access: Clients interact only with S1, unaware of the distributed nature
- File Operations: Upload, download, delete, and list files across the distributed system
- Tar Archive Creation: Create compressed archives of specific file types
- Directory Management: Automatic creation of directory structures
- Operating System: Linux/Unix environment
- Compiler: GCC with C99 support
- Network: All servers and client must be able to communicate via sockets
- Permissions: Write access to home directory for creating server directories
-
Clone the repository:
git clone <repository-url> cd DistributedFileSystem
-
Compile the project:
make all
-
Create required directories:
make install
Start each server in separate terminals:
# Terminal 1 - Main Server (S1)
./S1
# Terminal 2 - PDF Server (S2)
./S2
# Terminal 3 - Text Server (S3)
./S3
# Terminal 4 - ZIP Server (S4)
./S4
# Terminal 5 - Client
./s25client
Upload up to 3 files to the distributed system:
uploadf file1.c file2.pdf file3.txt ~S1/destination/path
Download up to 2 files from the system:
downlf ~S1/path/file1.c ~S1/path/file2.pdf
Delete up to 2 files from the system:
removef ~S1/path/file1.c ~S1/path/file2.pdf
Create and download a tar archive of specific file type:
downltar .c # Downloads cfiles.tar
downltar .pdf # Downloads pdf.tar
downltar .txt # Downloads text.tar
List all files in a directory:
dispfnames ~S1/directory/path
- S1 (Main Server): Port 8080
- S2 (PDF Server): Port 8081
- S3 (Text Server): Port 8082
- S4 (ZIP Server): Port 8083
~/S1/ # Main server files (.c files)
~/S2/ # PDF server files
~/S3/ # Text server files
~/S4/ # ZIP server files
- Start all servers in separate terminals
- Run the client and test each command
- Verify file distribution by checking the appropriate server directories
- Test concurrent connections by running multiple clients
# Upload files
uploadf sample.c document.pdf readme.txt ~S1/test/
# List files
dispfnames ~S1/test/
# Download files
downlf ~S1/test/sample.c ~S1/test/document.pdf
# Create tar archive
downltar .c
# Remove files
removef ~S1/test/sample.c
DistributedFileSystem/
├── S1.c # Main server implementation
├── S2.c # PDF server implementation
├── S3.c # Text server implementation
├── S4.c # ZIP server implementation
├── s25client.c # Client application
├── Makefile # Build configuration
└── README.md # This file
- Protocol: TCP sockets
- Address: 127.0.0.1 (localhost)
- Communication: Bidirectional client-server communication
- Forking: S1 forks child processes for each client connection
- Process Isolation: Each client connection runs in its own process
- Signal Handling: Proper cleanup of child processes
- Binary Transfer: Files are transferred in binary mode
- Chunked Transfer: Large files are transferred in chunks
- Error Handling: Basic error checking and validation
-
Port Already in Use:
# Check if ports are in use netstat -tulpn | grep :808 # Kill processes using the ports sudo kill -9 <PID>
-
Permission Denied:
# Make sure directories are writable chmod 755 ~/S1 ~/S2 ~/S3 ~/S4
-
Connection Refused:
- Ensure all servers are running
- Check firewall settings
- Verify port availability
Compile with debug flags for detailed output:
make debug
This project demonstrates:
- Socket Programming: Network communication between processes
- Process Management: Forking and child process handling
- File System Operations: File I/O and directory management
- Distributed Systems: Basic concepts of distributed file storage
- C Programming: System programming and network protocols
- Inspired by distributed systems concepts
- Built for educational purposes
- Uses standard C libraries and system calls
Note: This is an educational project designed to demonstrate basic distributed computing concepts. For production use, additional security, error handling, and performance optimizations would be required.