void sfs_read(int sfs_handle, char *fn) { int i, block_i, already_read, rem_to_read, to_read; sfs_file_entry_t fe; if ((i = sfs_lookup(sfs_handle, fn, &fe)) == -1) { printf("File %s doesn't exist\n", fn); return; } if (!(fe.perms & 04)) { printf("File %s doesn't have read permissions\n", fn); return; } already_read = 0; rem_to_read = fe.size; for (block_i = 0; block_i < SIMULA_FS_DATA_BLOCK_CNT; block_i++) { if (!fe.blocks[block_i]) break; to_read = (rem_to_read >= sb.block_size) ? sb.block_size : rem_to_read; lseek(sfs_handle, fe.blocks[block_i] * sb.block_size, SEEK_SET); read(sfs_handle, block, to_read); write(1, block, to_read); already_read += to_read; rem_to_read -= to_read; if (!rem_to_read) break; } }
int sfs_remove(sfs_info_t *info, char *fn) { int vfs_ino, block_i; sfs_file_entry_t fe; if ((vfs_ino = sfs_lookup(info, fn, &fe)) == -1) { printk(KERN_ERR "File %s doesn't exist\n", fn); return -1; } /* Free up all allocated blocks, if any */ for (block_i = 0; block_i < SIMULA_FS_DATA_BLOCK_CNT; block_i++) { if (!fe.blocks[block_i]) { break; } sfs_put_data_block(info, fe.blocks[block_i]); } memset(&fe, 0, sizeof(sfs_file_entry_t)); if (write_to_real_sfs(info, info->sb.entry_table_block_start, V2S_INODE_NUM(vfs_ino) * sizeof(sfs_file_entry_t), &fe, sizeof(sfs_file_entry_t)) == -1) return -1; return vfs_ino; }
void sfs_write(int sfs_handle, char *fn) { int i, cur_read_i, to_read, cur_read, total_size, block_i, free_i; sfs_file_entry_t fe; if ((i = sfs_lookup(sfs_handle, fn, &fe)) == -1) { printf("File %s doesn't exist\n", fn); return; } cur_read_i = 0; to_read = sb.block_size; total_size = 0; block_i = 0; while ((cur_read = read(0, block + cur_read_i, to_read)) > 0) { if (cur_read == to_read) { /* Write this block */ if (block_i == SIMULA_FS_DATA_BLOCK_CNT) break; /* File size limit */ if ((free_i = get_data_block(sfs_handle)) == -1) break; /* File system full */ lseek(sfs_handle, free_i * sb.block_size, SEEK_SET); write(sfs_handle, block, sb.block_size); fe.blocks[block_i] = free_i; block_i++; total_size += sb.block_size; /* Reset various variables */ cur_read_i = 0; to_read = sb.block_size; } else { cur_read_i += cur_read; to_read -= cur_read; } } if ((cur_read <= 0) && (cur_read_i)) { /* Write this partial block */ if ((block_i != SIMULA_FS_DATA_BLOCK_CNT) && ((fe.blocks[block_i] = get_data_block(sfs_handle)) != -1)) { lseek(sfs_handle, fe.blocks[block_i] * sb.block_size, SEEK_SET); write(sfs_handle, block, cur_read_i); total_size += cur_read_i; } } fe.size = total_size; fe.timestamp = time(NULL); lseek(sfs_handle, sb.entry_table_block_start * sb.block_size + i * sb.entry_size, SEEK_SET); write(sfs_handle, &fe, sizeof(sfs_file_entry_t)); }
void sfs_remove(int sfs_handle, char *fn) { int i; sfs_file_entry_t fe; if ((i = sfs_lookup(sfs_handle, fn, &fe)) == -1) { printf("File %s doesn't exist\n", fn); return; } memset(&fe, 0, sizeof(sfs_file_entry_t)); lseek(sfs_handle, sb.entry_table_block_start * sb.block_size + i * sb.entry_size, SEEK_SET); write(sfs_handle, &fe, sizeof(sfs_file_entry_t)); }
void sfs_update(int sfs_handle, char *fn, int *size, int update_ts, int *perms) { int i; sfs_file_entry_t fe; if ((i = sfs_lookup(sfs_handle, fn, &fe)) == -1) { printf("File %s doesn't exist\n", fn); return; } if (size) fe.size = *size; if (update_ts) fe.timestamp = time(NULL); if (perms && (*perms <= 07)) fe.perms = *perms; lseek(sfs_handle, sb.entry_table_block_start * sb.block_size + i * sb.entry_size, SEEK_SET); write(sfs_handle, &fe, sizeof(sfs_file_entry_t)); }
void sfs_remove(int sfs_handle, char *fn) { int i, block_i; sfs_file_entry_t fe; if ((i = sfs_lookup(sfs_handle, fn, &fe)) == -1) { printf("File %s doesn't exist\n", fn); return; } /* Free up all allocated blocks, if any */ for (block_i = 0; block_i < SIMULA_FS_DATA_BLOCK_CNT; block_i++) { if (!fe.blocks[block_i]) { break; } put_data_block(sfs_handle, fe.blocks[block_i]); } memset(&fe, 0, sizeof(sfs_file_entry_t)); lseek(sfs_handle, sb.entry_table_block_start * sb.block_size + i * sb.entry_size, SEEK_SET); write(sfs_handle, &fe, sizeof(sfs_file_entry_t)); }