Overview

The Object Manager provides handle-based object management for the FreeWorld OS. It manages file handles, directory handles, pipes, events, mutexes, and other kernel objects, similar to Windows' object manager.

Features

  • Handle Management: Unique handle generation and tracking
  • File Operations: Complete file read/write with filesystem integration
  • File Pointer Management: Seek operations and file size queries
  • Directory Objects: Directory handle management
  • Pipe Objects: Named pipes with read/write operations
  • Event Objects: Event synchronization (set/reset/wait)
  • Mutex Objects: Mutual exclusion locks
  • Access Control: Access mode and share mode checking
  • Conflict Detection: Share mode conflict detection

Object Types

1. File Objects

File objects represent open files with read/write capabilities:

  • Access Modes: GENERIC_READ, GENERIC_WRITE, GENERIC_EXECUTE, GENERIC_ALL
  • Share Modes: FILE_SHARE_READ, FILE_SHARE_WRITE, FILE_SHARE_DELETE, FILE_SHARE_NONE
  • Creation Dispositions: CREATE_NEW, CREATE_ALWAYS, OPEN_EXISTING, OPEN_ALWAYS, TRUNCATE_EXISTING
  • File Pointer: Tracks current read/write position

Key Functions

  • createFile(path, accessMode, shareMode, creationDisposition) - Create/open file handle
  • readFile(handle, buffer, bytesToRead) - Read data from file
  • writeFile(handle, buffer, bytesToWrite) - Write data to file
  • setFilePointer(handle, distance, moveMethod) - Move file pointer
  • getFileSize(handle) - Get file size

2. Directory Objects

Directory objects represent open directories:

  • createDirectory(path) - Create directory handle

3. Pipe Objects

Named pipes for inter-process communication:

  • createPipe(name, mode) - Create named pipe
  • readPipe(handle, buffer, bytesToRead) - Read from pipe
  • writePipe(handle, buffer, bytesToWrite) - Write to pipe

4. Event Objects

Event objects for synchronization:

  • createEvent(name, initialState, manualReset) - Create event
  • setEvent(handle) - Set event to signaled state
  • resetEvent(handle) - Reset event to non-signaled state

5. Mutex Objects

Mutex objects for mutual exclusion:

  • createMutex(name, initialOwner) - Create mutex
  • releaseMutex(handle) - Release mutex ownership

Handle Management

The Object Manager generates unique handles for all objects:

  • createHandle(object) - Create handle for object
  • getObject(handle) - Get object from handle
  • closeHandle(handle) - Close handle and cleanup object
  • findHandlesForFile(filePath) - Find all handles for a file
  • getObjectTypeName(handle) - Get object type name
  • getAllHandles() - Get all active handles
  • getHandleCount() - Get total handle count

Access Control

The Object Manager enforces access control:

  • checkAccess(handle, requiredAccess) - Check if handle has required access
  • checkShareConflict(file1, file2) - Check for share mode conflicts

Integration

The Object Manager integrates with:

  • Filesystem: Uses Node.js fs module for file operations
  • Error Manager: Returns error codes for failed operations
  • Process Management: Tracks handles per process

Usage Example

const ObjectManager = require('./system/object-manager');

const objMgr = new ObjectManager();

// Open file for reading
const handle = objMgr.createFile(
    '/path/to/file.txt',
    ObjectManager.ACCESS_MODE.GENERIC_READ,
    ObjectManager.SHARE_MODE.FILE_SHARE_READ,
    ObjectManager.CREATION_DISPOSITION.OPEN_EXISTING
);

// Read file
const buffer = Buffer.alloc(1024);
const result = objMgr.readFile(handle, buffer, 1024);
if (result.success) {
    console.log(`Read ${result.bytesRead} bytes`);
}

// Close handle
objMgr.closeHandle(handle);

Related Documentation