2018-10-10 11:53:07 +02:00
|
|
|
#pragma once
|
|
|
|
|
2019-05-28 11:53:16 +02:00
|
|
|
#include <AK/Badge.h>
|
2018-10-10 11:53:07 +02:00
|
|
|
#include <AK/ByteBuffer.h>
|
2018-11-12 01:28:46 +01:00
|
|
|
#include <AK/CircularQueue.h>
|
2019-06-21 18:58:45 +02:00
|
|
|
#include <AK/RefCounted.h>
|
2019-05-28 11:53:16 +02:00
|
|
|
#include <Kernel/FileSystem/FIFO.h>
|
|
|
|
#include <Kernel/FileSystem/Inode.h>
|
|
|
|
#include <Kernel/FileSystem/InodeMetadata.h>
|
|
|
|
#include <Kernel/FileSystem/VirtualFileSystem.h>
|
2019-08-05 11:35:49 +02:00
|
|
|
#include <Kernel/KBuffer.h>
|
2019-04-06 20:29:48 +02:00
|
|
|
#include <Kernel/Net/Socket.h>
|
2019-07-09 14:54:26 +02:00
|
|
|
#include <Kernel/VM/VirtualAddress.h>
|
2018-10-10 11:53:07 +02:00
|
|
|
|
2019-04-28 15:02:55 +02:00
|
|
|
class File;
|
2018-10-30 22:03:02 +01:00
|
|
|
class TTY;
|
2019-01-15 06:30:19 +01:00
|
|
|
class MasterPTY;
|
2019-01-14 14:21:51 +01:00
|
|
|
class Process;
|
2019-02-16 09:57:42 +01:00
|
|
|
class Region;
|
|
|
|
class CharacterDevice;
|
2019-04-28 22:31:31 +02:00
|
|
|
class SharedMemory;
|
2019-02-14 15:40:04 +01:00
|
|
|
|
2019-06-21 15:29:31 +02:00
|
|
|
class FileDescription : public RefCounted<FileDescription> {
|
2018-10-10 11:53:07 +02:00
|
|
|
public:
|
2019-08-11 09:32:21 +02:00
|
|
|
static NonnullRefPtr<FileDescription> create(Custody&);
|
2019-08-11 16:38:20 +03:00
|
|
|
static NonnullRefPtr<FileDescription> create(File&);
|
2019-06-07 09:36:51 +02:00
|
|
|
~FileDescription();
|
2018-10-10 11:53:07 +02:00
|
|
|
|
2018-11-01 14:00:28 +01:00
|
|
|
int close();
|
|
|
|
|
2019-01-23 06:53:01 +01:00
|
|
|
off_t seek(off_t, int whence);
|
2019-07-03 21:17:35 +02:00
|
|
|
ssize_t read(u8*, ssize_t);
|
|
|
|
ssize_t write(const u8* data, ssize_t);
|
2019-03-02 00:11:08 +01:00
|
|
|
KResult fstat(stat&);
|
2018-10-14 21:19:27 +02:00
|
|
|
|
2019-03-01 10:39:19 +01:00
|
|
|
KResult fchmod(mode_t);
|
|
|
|
|
2019-07-19 13:19:47 +02:00
|
|
|
bool can_read() const;
|
|
|
|
bool can_write() const;
|
2018-10-25 13:07:59 +02:00
|
|
|
|
2019-07-03 21:17:35 +02:00
|
|
|
ssize_t get_dir_entries(u8* buffer, ssize_t);
|
2018-10-24 12:43:52 +02:00
|
|
|
|
2019-04-29 13:58:40 +02:00
|
|
|
ByteBuffer read_entire_file();
|
2018-10-10 11:53:07 +02:00
|
|
|
|
2019-06-01 18:56:56 +02:00
|
|
|
String absolute_path() const;
|
2018-10-24 14:28:22 +02:00
|
|
|
|
2019-11-05 19:35:12 +01:00
|
|
|
bool is_direct() const { return m_direct; }
|
|
|
|
|
2019-10-25 09:22:22 +02:00
|
|
|
bool is_directory() const { return m_is_directory; }
|
2018-10-26 14:24:11 +02:00
|
|
|
|
2019-05-30 13:39:17 +02:00
|
|
|
File& file() { return *m_file; }
|
|
|
|
const File& file() const { return *m_file; }
|
2019-02-16 09:57:42 +01:00
|
|
|
|
2019-04-28 15:02:55 +02:00
|
|
|
bool is_device() const;
|
2018-11-16 13:11:21 +01:00
|
|
|
|
2018-12-03 00:39:25 +01:00
|
|
|
bool is_tty() const;
|
2018-10-30 22:03:02 +01:00
|
|
|
const TTY* tty() const;
|
2018-11-02 13:14:25 +01:00
|
|
|
TTY* tty();
|
2019-01-15 06:30:19 +01:00
|
|
|
|
|
|
|
bool is_master_pty() const;
|
|
|
|
const MasterPTY* master_pty() const;
|
|
|
|
MasterPTY* master_pty();
|
2018-10-30 22:03:02 +01:00
|
|
|
|
2019-01-16 12:57:07 +01:00
|
|
|
InodeMetadata metadata() const;
|
|
|
|
Inode* inode() { return m_inode.ptr(); }
|
|
|
|
const Inode* inode() const { return m_inode.ptr(); }
|
2018-10-27 16:43:03 +02:00
|
|
|
|
2019-05-30 18:58:59 +02:00
|
|
|
Custody* custody() { return m_custody.ptr(); }
|
|
|
|
const Custody* custody() const { return m_custody.ptr(); }
|
|
|
|
|
2019-06-07 12:56:50 +02:00
|
|
|
KResultOr<Region*> mmap(Process&, VirtualAddress, size_t offset, size_t, int prot);
|
2018-10-26 14:24:11 +02:00
|
|
|
|
2018-12-03 00:39:25 +01:00
|
|
|
bool is_blocking() const { return m_is_blocking; }
|
|
|
|
void set_blocking(bool b) { m_is_blocking = b; }
|
2019-05-26 01:18:04 +02:00
|
|
|
bool should_append() const { return m_should_append; }
|
|
|
|
void set_should_append(bool s) { m_should_append = s; }
|
2018-11-11 15:36:40 +01:00
|
|
|
|
2019-07-03 21:17:35 +02:00
|
|
|
u32 file_flags() const { return m_file_flags; }
|
|
|
|
void set_file_flags(u32);
|
2018-11-12 01:28:46 +01:00
|
|
|
|
2019-05-03 20:42:43 +02:00
|
|
|
bool is_socket() const;
|
|
|
|
Socket* socket();
|
|
|
|
const Socket* socket() const;
|
2019-02-14 14:17:38 +01:00
|
|
|
|
2019-04-29 04:55:54 +02:00
|
|
|
bool is_fifo() const;
|
|
|
|
FIFO* fifo();
|
2018-11-12 01:28:46 +01:00
|
|
|
FIFO::Direction fifo_direction() { return m_fifo_direction; }
|
2019-04-29 04:55:54 +02:00
|
|
|
void set_fifo_direction(Badge<FIFO>, FIFO::Direction direction) { m_fifo_direction = direction; }
|
2018-10-18 10:27:07 +02:00
|
|
|
|
2019-04-28 22:31:31 +02:00
|
|
|
bool is_shared_memory() const;
|
|
|
|
SharedMemory* shared_memory();
|
|
|
|
const SharedMemory* shared_memory() const;
|
2019-04-09 01:10:00 +02:00
|
|
|
|
2019-08-05 11:35:49 +02:00
|
|
|
Optional<KBuffer>& generator_cache() { return m_generator_cache; }
|
2018-10-27 00:14:24 +02:00
|
|
|
|
2019-06-21 18:37:47 +02:00
|
|
|
void set_original_inode(Badge<VFS>, NonnullRefPtr<Inode>&& inode) { m_inode = move(inode); }
|
2019-01-31 05:05:57 +01:00
|
|
|
|
2019-04-09 01:10:00 +02:00
|
|
|
KResult truncate(off_t);
|
|
|
|
|
2019-05-30 13:39:17 +02:00
|
|
|
off_t offset() const { return m_current_offset; }
|
|
|
|
|
2019-06-01 20:31:36 +02:00
|
|
|
KResult chown(uid_t, gid_t);
|
|
|
|
|
2018-10-10 11:53:07 +02:00
|
|
|
private:
|
2018-11-15 14:43:10 +01:00
|
|
|
friend class VFS;
|
2019-08-11 16:38:20 +03:00
|
|
|
explicit FileDescription(File&);
|
2019-06-07 09:36:51 +02:00
|
|
|
FileDescription(FIFO&, FIFO::Direction);
|
2018-10-10 11:53:07 +02:00
|
|
|
|
2019-06-21 18:37:47 +02:00
|
|
|
RefPtr<Custody> m_custody;
|
|
|
|
RefPtr<Inode> m_inode;
|
2019-08-11 09:32:21 +02:00
|
|
|
NonnullRefPtr<File> m_file;
|
2018-10-14 21:19:27 +02:00
|
|
|
|
2019-01-23 06:53:01 +01:00
|
|
|
off_t m_current_offset { 0 };
|
2018-10-18 10:27:07 +02:00
|
|
|
|
2019-08-05 11:35:49 +02:00
|
|
|
Optional<KBuffer> m_generator_cache;
|
2018-10-27 00:14:24 +02:00
|
|
|
|
2019-07-03 21:17:35 +02:00
|
|
|
u32 m_file_flags { 0 };
|
2018-11-12 01:28:46 +01:00
|
|
|
|
2019-05-18 04:14:22 +02:00
|
|
|
bool m_is_blocking { true };
|
2019-10-25 09:22:22 +02:00
|
|
|
bool m_is_directory { false };
|
2019-05-26 01:18:04 +02:00
|
|
|
bool m_should_append { false };
|
2019-11-05 19:35:12 +01:00
|
|
|
bool m_direct { false };
|
2019-05-18 04:14:22 +02:00
|
|
|
FIFO::Direction m_fifo_direction { FIFO::Direction::Neither };
|
2018-10-10 11:53:07 +02:00
|
|
|
};
|