MAN=
BINDIR?= /sbin
+CFLAGS+= -Wall -Wextra -Werror
.include <minix.service.mk>
/* we preallocate bytes only */
ASSERT(EXT2_PREALLOC_BLOCKS == sizeof(char)*CHAR_BIT);
- bit = setbyte(bp->b_bitmap, sp->s_blocks_per_group, word);
+ bit = setbyte(bp->b_bitmap, sp->s_blocks_per_group);
if (bit != -1) {
block = bit + sp->s_first_data_block +
group * sp->s_blocks_per_group;
/* Flush all dirty blocks for one device. */
register struct buf *bp;
- static struct buf **dirty; /* static so it isn't on stack */
+ static struct buf **dirty = NULL; /* static so it isn't on stack */
static int unsigned dirtylistsize = 0;
int ndirty;
int j, r;
STATICINIT(iovec, NR_IOREQS);
+ assert(bufq != NULL);
/* (Shell) sort buffers on b_blocknr. */
gap = 1;
}
-static int find_group_dir(struct super_block *sp, struct inode
- *parent);
+static int find_group_dir(struct super_block *sp);
static int find_group_hashalloc(struct super_block *sp, struct inode
*parent);
-static int find_group_any(struct super_block *sp, struct inode
- *parent);
+static int find_group_any(struct super_block *sp);
static int find_group_orlov(struct super_block *sp, struct inode
*parent);
panic("can't alloc inode on read-only filesys.");
if (opt.mfsalloc) {
- group = find_group_any(sp, parent);
+ group = find_group_any(sp);
} else {
if (is_dir) {
if (opt.use_orlov) {
group = find_group_orlov(sp, parent);
} else {
- group = find_group_dir(sp, parent);
+ group = find_group_dir(sp);
}
} else {
group = find_group_hashalloc(sp, parent);
/* it's implemented very close to the linux' find_group_dir() */
-static int find_group_dir(struct super_block *sp, struct inode *parent)
+static int find_group_dir(struct super_block *sp)
{
int avefreei = sp->s_free_inodes_count / sp->s_groups_count;
struct group_desc *gd, *best_gd = NULL;
/* Find first group which has free inode slot.
* This is similar to what MFS does.
*/
-static int find_group_any(struct super_block *sp, struct inode *parent)
+static int find_group_any(struct super_block *sp)
{
int ngroups = sp->s_groups_count;
struct group_desc *gd;
r = EIO;
} else {
bp = get_block(rip->i_dev, b, NORMAL);
- link_text = bp->b_data;
- if (bp)
+ if (bp != NULL) {
+ link_text = bp->b_data;
r = OK;
- else
+ } else {
r = EIO;
+ }
}
} else {
/* fast symlink, stored in inode */
{ "reserved", OPT_BOOL, &opt.use_reserved_blocks, TRUE },
{ "prealloc", OPT_BOOL, &opt.use_prealloc, TRUE },
{ "noprealloc", OPT_BOOL, &opt.use_prealloc, FALSE },
- { NULL }
+ { NULL, 0, NULL, 0 }
};
/*===========================================================================*
/*===========================================================================*
* sef_cb_init_fresh *
*===========================================================================*/
-static int sef_cb_init_fresh(int type, sef_init_info_t *info)
+static int sef_cb_init_fresh(int UNUSED(type), sef_init_info_t *UNUSED(info))
{
/* Initialize the Minix file server. */
int i;
/* Special case of the string at cp is empty */
if (len == 0)
- strcpy(string, "."); /* Return "." */
+ strlcpy(string, ".", NAME_MAX + 1); /* Return "." */
else {
memcpy(string, cp, len);
string[len]= '\0';
int ansi_strcmp(register const char* ansi_s, register const char *s2,
register size_t ansi_s_length);
bit_t setbit(bitchunk_t *bitmap, bit_t max_bits, unsigned int word);
-bit_t setbyte(bitchunk_t *bitmap, bit_t max_bits, unsigned int word);
+bit_t setbyte(bitchunk_t *bitmap, bit_t max_bits);
int unsetbit(bitchunk_t *bitmap, bit_t bit);
/* write.c */
size_t chunk, unsigned left, int rw_flag, cp_grant_id_t gid, unsigned
buf_off, unsigned int block_size, int *completed);
-static char getdents_buf[GETDENTS_BUFSIZ];
-
static off_t rdahedpos; /* position to read ahead */
static struct inode *rdahed_inode; /* pointer to inode to read ahead */
dev_t dev;
struct buf *bp = NULL;
static unsigned int readqsize = 0;
- static struct buf **read_q;
+ static struct buf **read_q = NULL;
if(readqsize != nr_bufs) {
if(readqsize > 0) {
assert(read_q != NULL);
free(read_q);
- }
+ read_q = NULL;
+ readqsize = 0;
+ }
+
+ assert(readqsize == 0);
+ assert(read_q == NULL);
+
if(!(read_q = malloc(sizeof(read_q[0])*nr_bufs)))
panic("couldn't allocate read_q");
readqsize = nr_bufs;
*===========================================================================*/
int fs_getdents(void)
{
- register struct inode *rip;
+#define GETDENTS_BUFSIZE (sizeof(struct dirent) + EXT2_NAME_MAX + 1)
+#define GETDENTS_ENTRIES 8
+ static char getdents_buf[GETDENTS_BUFSIZE * GETDENTS_ENTRIES];
+ struct inode *rip;
int o, r, done;
unsigned int block_size, len, reclen;
ino_t ino;
block_pos = pos - off;
done = FALSE; /* Stop processing directory blocks when done is set */
- memset(getdents_buf, '\0', GETDENTS_BUFSIZ); /* Avoid leaking any data */
+ memset(getdents_buf, '\0', sizeof(getdents_buf)); /* Avoid leaking any data */
tmpbuf_off = 0; /* Offset in getdents_buf */
userbuf_off = 0; /* Offset in the user's buffer */
b = read_map(rip, block_pos); /* get block number */
/* Since directories don't have holes, 'b' cannot be NO_BLOCK. */
bp = get_block(rip->i_dev, b, NORMAL); /* get a dir block */
-
- if (bp == NO_BLOCK)
- panic("get_block returned NO_BLOCK");
assert(bp != NULL);
/* Search a directory block. */
/* Need the position of this entry in the directory */
ent_pos = block_pos + ((char *)d_desc - bp->b_data);
- if (tmpbuf_off + reclen > GETDENTS_BUFSIZ) {
- r = sys_safecopyto(VFS_PROC_NR, gid,
- (vir_bytes) userbuf_off,
- (vir_bytes) getdents_buf,
- (size_t) tmpbuf_off);
- if (r != OK) {
- put_inode(rip);
- return(r);
- }
- userbuf_off += tmpbuf_off;
- tmpbuf_off = 0;
- }
-
- if (userbuf_off + tmpbuf_off + reclen > size) {
+ if (userbuf_off + tmpbuf_off + reclen >= size) {
/* The user has no space for one more record */
done = TRUE;
break;
}
+ if (tmpbuf_off + reclen >= GETDENTS_BUFSIZE*GETDENTS_ENTRIES) {
+ r = sys_safecopyto(VFS_PROC_NR, gid,
+ (vir_bytes) userbuf_off,
+ (vir_bytes) getdents_buf,
+ (size_t) tmpbuf_off);
+ if (r != OK) {
+ put_inode(rip);
+ return(r);
+ }
+ userbuf_off += tmpbuf_off;
+ tmpbuf_off = 0;
+ }
+
dep = (struct dirent *) &getdents_buf[tmpbuf_off];
dep->d_ino = conv4(le_CPU, d_desc->d_ino);
dep->d_off = ent_pos;
STATICINIT(ondisk_superblock, 1);
- if (!sp || !ondisk_superblock)
+ if (!ondisk_superblock)
panic("can't allocate memory for super_block buffers");
assert(_MIN_BLOCK_SIZE <= sizeof(*ondisk_superblock));
/*===========================================================================*
* setbyte *
*===========================================================================*/
-bit_t setbyte(bitchunk_t *bitmap, bit_t max_bits, unsigned int word)
+bit_t setbyte(bitchunk_t *bitmap, bit_t max_bits)
{
/* Find free byte in bitmap and set it. Return number of the starting bit,
* if failed return -1.
long excess, block_pos;
char new_ind = 0, new_dbl = 0, new_triple = 0;
int single = 0, triple = 0;
- register block_t old_block, b1, b2, b3;
+ block_t old_block = NO_BLOCK, b1 = NO_BLOCK, b2 = NO_BLOCK, b3 = NO_BLOCK;
struct buf *bp = NULL,
*bp_dindir = NULL,
*bp_tindir = NULL;