3 static char getdents_buf
[GETDENTS_BUFSIZ
];
5 ssize_t
fs_read(ino_t ino_nr
, struct fsdriver_data
*data
, size_t bytes
,
6 off_t pos
, int __unused call
)
8 size_t off
, chunk
, block_size
, cum_io
;
14 /* Try to get inode according to its index. */
15 if ((i_node
= get_inode(ino_nr
)) == NULL
)
16 return EINVAL
; /* No inode found. */
18 f_size
= i_node
->i_stat
.st_size
;
22 /* Limit the request to the remainder of the file size. */
23 if ((off_t
)bytes
> f_size
- pos
)
24 bytes
= (size_t)(f_size
- pos
);
26 block_size
= v_pri
.logical_block_size_l
;
31 /* Split the transfer into chunks that don't span two blocks. */
33 off
= pos
% block_size
;
35 chunk
= block_size
- off
;
39 /* Read 'chunk' bytes. */
40 bp
= read_extent_block(&i_node
->extent
, pos
);
42 panic("bp not valid in rw_chunk; this can't happen");
44 r
= fsdriver_copyout(data
, cum_io
, b_data(bp
)+off
, chunk
);
51 /* Update counters and pointers. */
52 bytes
-= chunk
; /* Bytes yet to be read. */
53 cum_io
+= chunk
; /* Bytes read so far. */
54 pos
+= chunk
; /* Position within the file. */
57 return (r
== OK
) ? cum_io
: r
;
60 ssize_t
fs_getdents(ino_t ino_nr
, struct fsdriver_data
*data
, size_t bytes
,
63 struct fsdriver_dentry fsdentry
;
69 if ((i_node
= get_inode(ino_nr
)) == NULL
)
72 if (*pos
< 0 || *pos
> SSIZE_MAX
)
75 r
= read_directory(i_node
);
79 fsdriver_dentry_init(&fsdentry
, data
, bytes
, getdents_buf
,
80 sizeof(getdents_buf
));
84 for (cur_pos
= *pos
; cur_pos
< i_node
->dir_size
; cur_pos
++) {
85 /* Compute the length of the name */
86 cp
= memchr(i_node
->dir_contents
[cur_pos
].name
, '\0', NAME_MAX
);
90 len
= cp
- i_node
->dir_contents
[cur_pos
].name
;
92 r
= fsdriver_dentry_add(&fsdentry
,
93 i_node
->dir_contents
[cur_pos
].i_node
->i_stat
.st_ino
,
94 i_node
->dir_contents
[cur_pos
].name
, len
,
95 IFTODT(i_node
->dir_contents
[cur_pos
].i_node
->i_stat
.st_mode
));
101 if (r
>= 0 && (r
= fsdriver_dentry_finish(&fsdentry
)) >= 0)