65X-DOS/include/kernel/file.h

80 lines
2.1 KiB
C
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// SPDX-License-Identifier: MIT
//
// kernel/file.h
// File related declarations
//
// Copyright © 2024 Kyle J Cardoza <Kyle.Cardoza@icloud.com>
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include "kernel/device.h"
enum file_type {
FILE_TYPE_NORMAL,
FILE_TYPE_DIRECTORY,
FILE_TYPE_DEVICE
};
struct file {
// The full path of the file, including its volume and basename.
char *pathname;
// The basename of the file. This usually points to
// the begining of the basename of the file in the
// pathname string.
char *basename;
// The type of the file.
enum file_type type;
bool open;
// Generic driver-specific data pointer
void *userdata;
// The major number identifies the device driver responsible for
// the file.
uint8_t major_number;
// The minor number identifies the device, among those the driver
// controls, which this file represents or is associated with.
uint8_t minor_number;
};
// Using the pathname in the provided FCB, identify the device which manages
// the file and have that device populate the FCB.
int file_init(char *pathname, struct file *file);
int file_open(struct file *file);
int file_ioctl(struct file *file,
unsigned short operation,
void *arg);
// Closes an open file, given a unique ID.
int file_close(struct file *file);
// Seeks within an open file, given a unique ID and a length.
int file_seek(struct file *file, int32_t length);
// Reads data from the specified file.
int file_read(struct file *file, void *dest, size_t length);
// Writes data to the specified file.
int file_write(struct file *file, void *src, size_t length);
// Creates the specified file given a pathname.
int file_create(struct file *file);
// Copies the specified file using the specified names.
int file_copy(struct file *src, struct file *dest);
// Moves the specified file using the specified names.
int file_move(struct file *src, struct file *dest);
// Gets the size of the file.
int file_get_file_size(struct file *file, size_t *size);