orca-software
uhfs.h
1 #define UHFS_DEBUG 1
2 
3 #define UHFS_FIXDBLK 0xfffffffc /* fixed / not allocatable */
4 #define UHFS_DEADBLK 0xfffffffd /* invalid (dead block) */
5 #define UHFS_EOCHBLK 0xfffffffe /* last block in the chain (end of file or end of chain of cluster map blocks) */
6 #define UHFS_FREEBLK 0xffffffff /* unused (free) block */
7 
8 #define UHFS_ATTRDIR 0x01 /* directory */
9 #define UHFS_ATTRHIDDEN 0x02 /* hidden */
10 #define UHFS_ATTRARCHIVE 0x04 /* file needs archiving */
11 #define UHFS_ATTRSYSTEM 0x08 /* system */
12 #define UHFS_ATTREXEC 0x10 /* execute */
13 #define UHFS_ATTRWRITE 0x20 /* write */
14 #define UHFS_ATTRREAD 0x40 /* read */
15 #define UHFS_ATTRFREE 0x80 /* deleted / free directory entry */
16 
17 #define UHFS_RDONLY 0x0001
18 #define UHFS_WRONLY 0x0002
19 #define UHFS_RDWR 0x0003
20 #define UHFS_CREAT 0x0004
21 #define UHFS_APPEND 0x0008
22 #define UHFS_SYNC 0x0010
23 #define UHFS_NONBLOCK 0x0020
24 #define UHFS_EOF 0x4000
25 #define UHFS_OPENFILE 0x8000
26 
27 enum {
28  UHFS_EOK = 0,
29  UHFS_EERROR = -1000,
30  UHFS_ENOTMOUNTED = -1001,
31  UHFS_EALREADYMOUNTED = -1002,
32  UHFS_EINVSECTORSIZE = -1003,
33  UHFS_EINVBLOCKSIZE = -1004,
34  UHFS_ESTORAGEFULL = -1005,
35  UHFS_EPATHNOTFOUND = -1006,
36  UHFS_ENOTADIR = -1007,
37  UHFS_ENOTAFILE = -1008,
38  UHFS_EFILEEXISTS = -1009,
39  UHFS_EFILENOTOPEN = -1010,
40  UHFS_EDIRNOTEMPTY = -1011
41 };
42 
43 struct fs_date {
44  uint32_t day : 5; /* range 1 - 31 */
45  uint32_t month : 4; /* range 1 - 12 */
46  uint32_t year : 15; /* range 0 - 32767 */
47  uint32_t reserved : 8;
48 };
49 
50 struct fs_time {
51  uint32_t millisecond : 7; /* precision is 0.0078125 seconds */
52  uint32_t second : 6; /* range 0 - 59 */
53  uint32_t minute : 6; /* range 0 - 59 */
54  uint32_t hour : 5; /* range 0 - 23 */
55  uint32_t reserved : 8;
56 };
57 
58 struct fs_superblock {
59  uint32_t signature;
60  int8_t oem_id[16];
61  uint32_t block_size;
62  uint32_t n_blocks;
63  int8_t volume_label[16];
64  struct fs_date vdate;
65  struct fs_time vtime;
66  uint32_t first_cmb;
67  uint32_t root_dir_block;
68  uint32_t metadata_block;
69 };
70 
71 struct fs_direntry {
72  int8_t filename[39]; /* all bytes except / and NULL */
73  uint8_t attributes;
74  struct fs_date date;
75  struct fs_time time;
76  uint32_t metadata_block; /* block containing metadata for this file (future use) */
77  uint32_t first_block; /* the number of the first data block */
78  uint64_t size;
79 };
80 
81 union fs_datablock {
82  uint32_t *cmb_data;
83  int8_t *data;
84  struct fs_direntry *dir_data;
85 };
86 
87 struct fs_blkdevice {
88  /* these structures remain fixed after the filesystem is initialized */
89  struct blk_info fsblk_info;
90  uint64_t vsize;
91  struct fs_superblock fssblock;
92  /* these structures change during filesystem usage */
93  struct fs_direntry fsdirentry;
94  union fs_datablock datablock;
95 };
96 
97 struct file {
98  struct device *dev;
99  uint32_t first_block;
100  int8_t mode;
101  int32_t flags;
102  uint32_t block;
103  int64_t offset;
104 };
105 
106 /* volume management */
107 int32_t hf_mkfs(struct device *dev, uint32_t blk_size);
108 int32_t hf_mount(struct device *dev);
109 int32_t hf_umount(struct device *dev);
110 int32_t hf_getfree(struct device *dev);
111 int32_t hf_getlabel(struct device *dev, int8_t *label);
112 int32_t hf_setlabel(struct device *dev, int8_t *label);
113 
114 /* directory management / operations */
115 int32_t hf_mkdir(struct device *dev, int8_t *path);
116 struct file * hf_opendir(struct device *dev, int8_t *path);
117 int32_t hf_closedir(struct file *desc);
118 int32_t hf_readdir(struct file *desc, struct fs_direntry *entry);
119 int32_t hf_rmdir(struct device *dev, int8_t *path);
120 
121 /* file management */
122 int32_t hf_create(struct device *dev, int8_t *path);
123 int32_t hf_unlink(struct device *dev, int8_t *path);
124 int64_t hf_size(struct device *dev, int8_t *path);
125 int32_t hf_rename(struct device *dev, int8_t *path, int8_t *newname);
126 int32_t hf_chmod(struct device *dev, int8_t *path, int8_t mode);
127 int32_t hf_touch(struct device *dev, int8_t *path, struct fs_date *ndate, struct fs_time *ntime);
128 
129 /* file operations */
130 struct file * hf_fopen(struct device *dev, int8_t *path, int8_t *mode);
131 int32_t hf_fclose(struct file *desc);
132 int64_t hf_fread(void *buf, int32_t isize, int32_t items, struct file *desc);
133 int64_t hf_fwrite(void *buf, int32_t isize, int32_t items, struct file *desc);
134 int32_t hf_fseek(struct file *desc, int64_t offset, int32_t whence);
135 int64_t hf_ftell(struct file *desc);
136 int32_t hf_feof(struct file *desc);
Definition: uhfs.h:50
Definition: uhfs.h:71
Definition: device.h:5
Definition: block.h:10
Definition: uhfs.h:58
Definition: uhfs.h:43
Definition: uhfs.h:81
Definition: uhfs.h:87
Definition: uhfs.h:97