int decFreeInodes(int fd) { char buf[BLOCK_SIZE]; // dec free inodes count in Super and GroupDesc _get_block(fd, 1, buf); Super * super = (Super *) buf; super->s_free_inodes_count--; put_block(fd, 1, buf); _get_block(fd, 2, buf); GroupDesc * gp = (GroupDesc *) buf; gp->bg_free_inodes_count--; put_block(fd, 2, buf); return 0; }
void ts_free (void * ptr ) { t_block b; if (_valid_addr(ptr)) { //we get the block address b = _get_block(ptr); fuse_and_release(b); }// else { //printf("Invalid pointer on free %p\n", ptr); // } }
/* read and broadcast the file */ static void _bcast_file(void) { int buf_size; ssize_t size_read = 0; file_bcast_msg_t bcast_msg; char *buffer; if (params.block_size) buf_size = MIN(params.block_size, f_stat.st_size); else buf_size = MIN((512 * 1024), f_stat.st_size); bcast_msg.fname = params.dst_fname; bcast_msg.block_no = 1; bcast_msg.last_block = 0; bcast_msg.force = params.force; bcast_msg.modes = f_stat.st_mode; bcast_msg.uid = f_stat.st_uid; bcast_msg.user_name = uid_to_string(f_stat.st_uid); bcast_msg.gid = f_stat.st_gid; buffer = xmalloc(buf_size); bcast_msg.block = buffer; bcast_msg.block_len = 0; bcast_msg.cred = sbcast_cred->sbcast_cred; if (params.preserve) { bcast_msg.atime = f_stat.st_atime; bcast_msg.mtime = f_stat.st_mtime; } else { bcast_msg.atime = 0; bcast_msg.mtime = 0; } while (1) { bcast_msg.block_len = _get_block(buffer, buf_size); debug("block %d, size %u", bcast_msg.block_no, bcast_msg.block_len); size_read += bcast_msg.block_len; if (size_read >= f_stat.st_size) bcast_msg.last_block = 1; send_rpc(&bcast_msg, sbcast_cred); if (bcast_msg.last_block) break; /* end of file */ bcast_msg.block_no++; } xfree(bcast_msg.user_name); xfree(buffer); }
int ialloc(int fd) { fputs("ialloc: ##################################################", stdout); char buf[BLOCK_SIZE]; _get_block(fd, 1, buf); Super * super = (Super *) buf; int ninodes = (int) super->s_inodes_count; printf("ninodes = %d\n", ninodes); _get_block(fd, 2, buf); GroupDesc * gp = (GroupDesc *) buf; int imap = (int) gp->bg_inode_bitmap; printf("imap = %d\n", imap); // read inode_bitmap block _get_block(fd, imap, buf); for (int i = 0; i < ninodes; i++) { if (tst_bit(buf, i) == 0) { set_bit(buf, i); decFreeInodes(fd); put_block(fd, imap, buf); return i + 1; } } printf("ialloc(): no more free inodes\n"); return 0; }