33 if ((
size_t) offset >= m_inode.
size)
37 char *block =
kmalloc(bs, &M_BUFFER, 0);
46 size_t off = (offset + done) % bs;
47 size_t len =
MIN(bs - off,
size - done);
52 if ((r =
iobuf_out(io, block + off, len)) < 0)
63 return done ? (
ssize_t) done : r;
82 if ((
size_t) offset + size >
vnode->
size) {
92 if ((
size_t) offset >= m_inode.
size) {
99 char *block =
kmalloc(bs, &M_BUFFER, 0);
107 while (done <
size) {
108 size_t off = (offset + done) % bs;
109 size_t len =
MIN(bs - off,
size - done);
112 if ((off || len < bs) &&
116 if ((r =
iobuf_in(io, block + off, len)) <= 0)
129 if ((
size_t) r < len)
136 if (done <
size && (
size_t) offset +
size > old_size)
139 return done ? (
ssize_t) done : r;
155 struct minix *desc = dir->
p;
156 size_t bs = desc->
bs;
159 if (!S_ISDIR(dir->
mode))
167 if (!S_ISDIR(m_inode.
mode))
170 size_t nr_blocks = (m_inode.
size + bs - 1) / bs;
176 for (
size_t i = 0; i < nr_blocks; ++i) {
181 while ((
char *) dentry < (
char *) block + bs) {
184 dirent->d_ino = dentry->
ino;
187 dirent->d_name[desc->
name_len] =
'\0';
223 struct minix *desc = dir->
p;
229 if (!S_ISDIR(dir_inode.
mode))
264 memset(buf, 0,
sizeof(buf));
328 struct minix *desc = dir->
p;
337 if (!S_ISDIR(m_inode.
mode))
365 struct minix *desc = super->
p;
397 size_t bs = desc->
bs;
404 char *buf =
kmalloc(bs, &M_BUFFER, 0);
411 memset(buf + len % bs, 0, bs - len % bs);
#define DEV(major, minor)
ssize_t iobuf_out(struct iobuf *io, const void *src, size_t n)
Copies bytes from the kernel into the iobuf's buffer, and moves past them.
ssize_t iobuf_in(struct iobuf *io, void *dst, size_t n)
Copies bytes from the iobuf's buffer into the kernel, and moves past them.
void * kmalloc(size_t size, struct malloc_type *type, int flags)
Allocates memory for one of the kernel's structures.
void kfree(void *)
Frees an object that kmalloc() gave.
void * memset(void *dst, int c, size_t n)
Sets n bytes to c.
void * memcpy(void *dst, const void *src, size_t n)
Copies n bytes; dst and src must not overlap.
uint32_t minix_dentry_find(struct minix *desc, struct minix_inode *m_inode, const char *name)
Finds the inode number of a name in a directory.
int minix_dentry_create(struct vnode *dir, const char *name, ino_t ino, mode_t mode)
Adds an entry to a directory, in its first free slot.
ssize_t minix_inode_block_write(struct minix *desc, struct minix_inode *inode, ino_t ino, size_t idx, void *buf)
Writes a zone of a file, allocating it and the indirect zones above it if they don't exist yet.
ssize_t minix_inode_block_read(struct minix *desc, struct minix_inode *m_inode, size_t idx, void *buf)
Reads a zone of a file.
int minix_inode_read(struct minix *desc, ino_t ino, struct minix_inode *ref)
Reads an inode from the disk.
int minix_inode_write(struct minix *desc, ino_t ino, struct minix_inode *ref)
Writes an inode to the disk.
void minix_zones_free(struct minix *desc, struct minix_inode *inode, size_t from)
Frees a file's zones, from a zone on, when the file is truncated or removed.
void minix_inode_free(struct minix *desc, ino_t ino)
Frees an inode: its bit is cleared in the inode bitmap, which is written back at once.
ino_t minix_inode_alloc(struct minix *desc)
Allocates a free inode: its bit is set in the inode bitmap, which is written back to the disk at once...
int minix_inode_build(struct minix *desc, ino_t ino, struct vnode **ref)
Gets the vnode of an inode: the cached one if it's in use, or a new one made from the inode on the di...
int minix_inode_sync(struct vnode *inode)
Writes a vnode's attributes back to its inode on the disk.
ssize_t minix_read(struct vnode *inode, off_t offset, struct iobuf *io)
Reads from a file.
int minix_vget(struct vnode *super, ino_t ino, struct vnode **ref)
Gets the vnode of an inode, by its number.
int minix_finddir(struct vnode *dir, const char *fn, struct dirent *dirent)
Finds the entry of a directory that has a name.
int minix_trunc(struct vnode *inode, off_t len)
Changes a file's length.
ssize_t minix_readdir(struct vnode *dir, off_t offset, struct dirent *dirent)
Reads a directory's entry at an offset; unused entries don't count.
int minix_vmknod(struct vnode *dir, const char *fn, mode_t mode, dev_t dev, struct uio *uio, struct vnode **ref)
Makes a node in a directory: a new inode, and an entry for it.
ssize_t minix_write(struct vnode *inode, off_t offset, struct iobuf *io)
Writes to a file, which grows if the write goes past its end.
A device driver: its operations, any of which may be NULL.
A directory entry, as it is on the disk: 0 as the inode number is an unused entry.
A minix v1 inode, as it is on the disk.
A mounted minix filesystem.
Who does a filesystem operation: where its paths start, and its credentials and umask.
A file in memory (a vnode): what its inode says, and the kernel's own state.
void * p
the filesystem's own data