2009-10-01 16:00:27 +02:00
|
|
|
#include "inc.h"
|
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
static char getdents_buf[GETDENTS_BUFSIZ];
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
|
2014-08-24 12:37:12 +02:00
|
|
|
ssize_t fs_read(ino_t ino_nr, struct fsdriver_data *data, size_t bytes,
|
|
|
|
off_t pos, int __unused call)
|
2014-08-03 19:24:51 +02:00
|
|
|
{
|
2014-08-24 12:37:12 +02:00
|
|
|
size_t off, chunk, block_size, cum_io;
|
|
|
|
off_t f_size;
|
2014-08-03 19:24:51 +02:00
|
|
|
struct inode *i_node;
|
2014-08-24 12:37:12 +02:00
|
|
|
struct buf *bp;
|
|
|
|
int r;
|
2009-10-01 16:00:27 +02:00
|
|
|
|
2014-08-03 19:24:51 +02:00
|
|
|
/* Try to get inode according to its index. */
|
2015-09-16 14:36:11 +02:00
|
|
|
if ((i_node = get_inode(ino_nr)) == NULL)
|
2014-08-03 19:24:51 +02:00
|
|
|
return EINVAL; /* No inode found. */
|
|
|
|
|
2014-08-24 12:37:12 +02:00
|
|
|
f_size = i_node->i_stat.st_size;
|
|
|
|
if (pos >= f_size)
|
|
|
|
return 0; /* EOF */
|
2014-08-03 19:24:51 +02:00
|
|
|
|
2014-08-24 12:37:12 +02:00
|
|
|
/* Limit the request to the remainder of the file size. */
|
|
|
|
if ((off_t)bytes > f_size - pos)
|
|
|
|
bytes = (size_t)(f_size - pos);
|
2014-08-03 19:24:51 +02:00
|
|
|
|
|
|
|
block_size = v_pri.logical_block_size_l;
|
2014-08-24 12:37:12 +02:00
|
|
|
cum_io = 0;
|
2014-08-03 19:24:51 +02:00
|
|
|
|
2014-08-24 12:37:12 +02:00
|
|
|
r = OK;
|
2014-08-03 19:24:51 +02:00
|
|
|
|
|
|
|
/* Split the transfer into chunks that don't span two blocks. */
|
2014-08-24 12:37:12 +02:00
|
|
|
while (bytes > 0) {
|
|
|
|
off = pos % block_size;
|
2014-08-03 19:24:51 +02:00
|
|
|
|
2014-08-24 12:37:12 +02:00
|
|
|
chunk = block_size - off;
|
|
|
|
if (chunk > bytes)
|
|
|
|
chunk = bytes;
|
2014-08-03 19:24:51 +02:00
|
|
|
|
|
|
|
/* Read 'chunk' bytes. */
|
2015-09-16 14:36:11 +02:00
|
|
|
bp = read_extent_block(&i_node->extent, pos);
|
2014-08-24 12:37:12 +02:00
|
|
|
if (bp == NULL)
|
|
|
|
panic("bp not valid in rw_chunk; this can't happen");
|
|
|
|
|
|
|
|
r = fsdriver_copyout(data, cum_io, b_data(bp)+off, chunk);
|
|
|
|
|
2015-03-28 01:45:28 +01:00
|
|
|
lmfs_put_block(bp);
|
2014-08-03 19:24:51 +02:00
|
|
|
|
|
|
|
if (r != OK)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Update counters and pointers. */
|
2014-08-24 12:37:12 +02:00
|
|
|
bytes -= chunk; /* Bytes yet to be read. */
|
|
|
|
cum_io += chunk; /* Bytes read so far. */
|
|
|
|
pos += chunk; /* Position within the file. */
|
2014-08-03 19:24:51 +02:00
|
|
|
}
|
|
|
|
|
2014-08-24 12:37:12 +02:00
|
|
|
return (r == OK) ? cum_io : r;
|
2014-08-03 19:24:51 +02:00
|
|
|
}
|
2009-10-01 16:00:27 +02:00
|
|
|
|
2014-08-24 12:37:12 +02:00
|
|
|
ssize_t fs_getdents(ino_t ino_nr, struct fsdriver_data *data, size_t bytes,
|
|
|
|
off_t *pos)
|
2013-09-16 22:52:36 +02:00
|
|
|
{
|
2014-08-24 12:37:12 +02:00
|
|
|
struct fsdriver_dentry fsdentry;
|
2015-09-16 14:36:11 +02:00
|
|
|
struct inode *i_node;
|
|
|
|
off_t cur_pos;
|
2014-08-24 12:37:12 +02:00
|
|
|
int r, len;
|
2014-08-03 19:24:51 +02:00
|
|
|
char *cp;
|
|
|
|
|
2015-09-16 14:36:11 +02:00
|
|
|
if ((i_node = get_inode(ino_nr)) == NULL)
|
2014-08-24 12:37:12 +02:00
|
|
|
return EINVAL;
|
2014-08-03 19:24:51 +02:00
|
|
|
|
2014-08-24 12:37:12 +02:00
|
|
|
if (*pos < 0 || *pos > SSIZE_MAX)
|
2014-08-03 19:24:51 +02:00
|
|
|
return EINVAL;
|
|
|
|
|
2015-09-16 14:36:11 +02:00
|
|
|
r = read_directory(i_node);
|
|
|
|
if (r != OK)
|
|
|
|
return r;
|
|
|
|
|
2014-08-24 12:37:12 +02:00
|
|
|
fsdriver_dentry_init(&fsdentry, data, bytes, getdents_buf,
|
|
|
|
sizeof(getdents_buf));
|
|
|
|
|
|
|
|
r = OK;
|
|
|
|
|
2015-09-16 14:36:11 +02:00
|
|
|
for (cur_pos = *pos; cur_pos < i_node->dir_size; cur_pos++) {
|
2014-08-03 19:24:51 +02:00
|
|
|
/* Compute the length of the name */
|
2015-09-16 14:36:11 +02:00
|
|
|
cp = memchr(i_node->dir_contents[cur_pos].name, '\0', NAME_MAX);
|
2014-08-03 19:24:51 +02:00
|
|
|
if (cp == NULL)
|
|
|
|
len = NAME_MAX;
|
|
|
|
else
|
2015-09-16 14:36:11 +02:00
|
|
|
len = cp - i_node->dir_contents[cur_pos].name;
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
|
2015-09-16 14:36:11 +02:00
|
|
|
r = fsdriver_dentry_add(&fsdentry,
|
|
|
|
i_node->dir_contents[cur_pos].i_node->i_stat.st_ino,
|
|
|
|
i_node->dir_contents[cur_pos].name, len,
|
|
|
|
IFTODT(i_node->dir_contents[cur_pos].i_node->i_stat.st_mode));
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
|
2014-08-24 12:37:12 +02:00
|
|
|
if (r <= 0)
|
|
|
|
break;
|
2014-08-03 19:24:51 +02:00
|
|
|
}
|
|
|
|
|
2014-08-24 12:37:12 +02:00
|
|
|
if (r >= 0 && (r = fsdriver_dentry_finish(&fsdentry)) >= 0)
|
|
|
|
*pos = cur_pos;
|
2014-08-03 19:24:51 +02:00
|
|
|
|
|
|
|
return r;
|
2009-10-01 16:00:27 +02:00
|
|
|
}
|