Writing works! Yay!
This commit is contained in:
parent
219bf47d55
commit
8f32c5229b
29
hd.c
29
hd.c
@ -194,7 +194,7 @@ void hd_buffer_trim() {
|
||||
}
|
||||
}
|
||||
|
||||
void hd_write_block(int hd, unsigned int blockno, char *source, unsigned int blocksize) {
|
||||
void do_hd_write_block(int hd, unsigned int blockno, char *source, unsigned int blocksize, int sync) {
|
||||
char key[16];
|
||||
struct block_buffer *bb;
|
||||
int i;
|
||||
@ -215,6 +215,9 @@ void hd_write_block(int hd, unsigned int blockno, char *source, unsigned int blo
|
||||
bb->dirty = 1;
|
||||
bb->accessed++;
|
||||
memcpy(bb->buffer, &source[i * 512], 512);
|
||||
if (sync) {
|
||||
hd_sync_iter(hd, bb);
|
||||
}
|
||||
} else {
|
||||
bb = (struct block_buffer *)malloc(sizeof(struct block_buffer));
|
||||
bb->lba = lba + i ;
|
||||
@ -223,8 +226,19 @@ void hd_write_block(int hd, unsigned int blockno, char *source, unsigned int blo
|
||||
strcpy(bb->key, hd_convert_key(lba + i, key));
|
||||
memcpy(bb->buffer, &source[i * 512], 512);
|
||||
hashmap_put(hds[hd]->block_buffers,bb->key, bb);
|
||||
if (sync) {
|
||||
hd_sync_iter(hd, bb);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void hd_write_block_sync(int hd, unsigned int blockno, char *source, unsigned int blocksize) {
|
||||
do_hd_write_block(hd, blockno, source, blocksize, 1);
|
||||
}
|
||||
|
||||
void hd_write_block(int hd, unsigned int blockno, char *source, unsigned int blocksize) {
|
||||
do_hd_write_block(hd, blockno, source, blocksize, 0);
|
||||
}
|
||||
|
||||
|
||||
@ -267,7 +281,7 @@ char *hd_read_block(int hd, unsigned int blockno, char *dest, unsigned int block
|
||||
return dest;
|
||||
}
|
||||
|
||||
void hd_write_blocks(int hd, unsigned int blockstart, unsigned int blockcount, char *source, unsigned int blocksize) {
|
||||
void do_hd_write_blocks(int hd, unsigned int blockstart, unsigned int blockcount, char *source, unsigned int blocksize, int sync) {
|
||||
int i;
|
||||
|
||||
if (hd < 0 || hd >= hd_count) {
|
||||
@ -286,12 +300,21 @@ void hd_write_blocks(int hd, unsigned int blockstart, unsigned int blockcount, c
|
||||
}
|
||||
|
||||
for (i=0;i<blocks;i++) {
|
||||
hd_write_block(hd, blockstart * (blocksize / 512) + i, &source[i * 512], 512);
|
||||
do_hd_write_block(hd, blockstart * (blocksize / 512) + i, &source[i * 512], 512, sync);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void hd_write_blocks(int hd, unsigned int blockstart, unsigned int blockcount, char *source, unsigned int blocksize) {
|
||||
do_hd_write_blocks(hd, blockstart, blockcount, source, blocksize, 0);
|
||||
}
|
||||
|
||||
void hd_write_blocks_sync(int hd, unsigned int blockstart, unsigned int blockcount, char *source, unsigned int blocksize) {
|
||||
do_hd_write_blocks(hd, blockstart, blockcount, source, blocksize, 1);
|
||||
}
|
||||
|
||||
|
||||
int hd_read_blocks(int hd, unsigned int blockstart, unsigned int blockcount, char *dest, unsigned int blocksize) {
|
||||
int i;
|
||||
|
||||
|
2
hd.h
2
hd.h
@ -38,5 +38,7 @@ extern void hd_buffer_trim();
|
||||
extern char *hd_read_block(int hd, unsigned int blockno, char *dest, unsigned int blocksize);
|
||||
extern int hd_read_blocks(int hd, unsigned int blockstart, unsigned int blockcount, char *dest, unsigned int blocksize);
|
||||
extern void hd_write_blocks(int hd, unsigned int blockstart, unsigned int blockcount, char *source, unsigned int blocksize);
|
||||
extern void hd_write_blocks_sync(int hd, unsigned int blockstart, unsigned int blockcount, char *source, unsigned int blocksize);
|
||||
extern void hd_write_block(int hd, unsigned int blockno, char *source, unsigned int blocksize);
|
||||
extern void hd_write_block_sync(int hd, unsigned int blockno, char *source, unsigned int blocksize);
|
||||
#endif
|
||||
|
163
minix.c
163
minix.c
@ -12,7 +12,8 @@ struct minix_file_info *minix_check_if_exists(struct vfs_device_t *device, char
|
||||
struct minix_inode *minix_alloc_inode(struct vfs_device_t *device, unsigned short mode, unsigned int *ino);
|
||||
unsigned int minix_read_map(struct vfs_device_t *device, struct minix_inode *inode, unsigned long long position);
|
||||
unsigned int minix_alloc_zone(struct vfs_device_t *device, unsigned int z) {
|
||||
return minix_alloc_bit(device, 1, z);
|
||||
struct minix_data *mdata = (struct minix_data *)device->fs_data;
|
||||
return minix_alloc_bit(device, 1, z) + mdata->first_data_block - 1;
|
||||
}
|
||||
|
||||
unsigned int minix_free_zone(struct vfs_device_t *device, unsigned int z) {
|
||||
@ -45,6 +46,11 @@ int minix_add_directory_entry(struct vfs_device_t *device, struct minix_inode *d
|
||||
char *buffer;
|
||||
struct minix_dir_entry *direntry;
|
||||
|
||||
if (!(dir->i_mode & S_IFDIR)) {
|
||||
kprintf("Trying to add an entry to something not a directory %d\n", dir_ino);
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int blockstoread = dir->i_size / mdata->sb.s_blocksize;
|
||||
unsigned int blockno;
|
||||
|
||||
@ -78,15 +84,16 @@ int minix_add_directory_entry(struct vfs_device_t *device, struct minix_inode *d
|
||||
|
||||
if (direntry->inode == 0) {
|
||||
direntry->inode = ino;
|
||||
for (j=0;j<60 && j < strlen(name);j++) {
|
||||
for (j=0;j<59 && j < strlen(name);j++) {
|
||||
direntry->name[j] = name[j];
|
||||
direntry->name[j+1] = '\0';
|
||||
}
|
||||
if (device->device == 1) {
|
||||
ramdisk_write_block(blockno, buffer, mdata->sb.s_blocksize);
|
||||
} else if ((device->device & 0xff00) == 0x100) {
|
||||
hd_write_block((device->device & 0xff), blockno, buffer, mdata->sb.s_blocksize);
|
||||
}
|
||||
// kprintf("Found old entry old entrys %d, this entry %d\n", old_entrys, i);
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@ -95,19 +102,20 @@ int minix_add_directory_entry(struct vfs_device_t *device, struct minix_inode *d
|
||||
if (new_entrys > 0) {
|
||||
direntry = (struct minix_dir_entry *)&buffer[i * sizeof(struct minix_dir_entry)];
|
||||
direntry->inode = ino;
|
||||
for (j=0;j<60 && j < strlen(name);j++) {
|
||||
for (j=0;j<59 && j < strlen(name);j++) {
|
||||
direntry->name[j] = name[j];
|
||||
direntry->name[j+1] = '\0';
|
||||
}
|
||||
|
||||
if (device->device == 1) {
|
||||
ramdisk_write_block(blockno, buffer, mdata->sb.s_blocksize);
|
||||
} else if ((device->device & 0xff00) == 0x100) {
|
||||
hd_write_block((device->device & 0xff), blockno, buffer, mdata->sb.s_blocksize);
|
||||
hd_write_block_sync((device->device & 0xff), blockno, buffer, mdata->sb.s_blocksize);
|
||||
}
|
||||
|
||||
dir->i_size += sizeof(struct minix_dir_entry);
|
||||
minix_write_inode(device, dir_ino, dir);
|
||||
// kprintf("Found new entry on old block\n");
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@ -127,8 +135,9 @@ int minix_add_directory_entry(struct vfs_device_t *device, struct minix_inode *d
|
||||
|
||||
direntry = (struct minix_dir_entry *)buffer;
|
||||
direntry->inode = ino;
|
||||
for (j=0;j<60 && j < strlen(name);j++) {
|
||||
for (j=0;j<59 && j < strlen(name);j++) {
|
||||
direntry->name[j] = name[j];
|
||||
direntry->name[j+1] = '\0';
|
||||
}
|
||||
|
||||
if (device->device == 1) {
|
||||
@ -137,7 +146,7 @@ int minix_add_directory_entry(struct vfs_device_t *device, struct minix_inode *d
|
||||
hd_write_block((device->device & 0xff), blockno, buffer, mdata->sb.s_blocksize);
|
||||
}
|
||||
|
||||
// kprintf("Allocated new block for entry\n");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -188,14 +197,26 @@ int minix_create_file(struct vfs_device_t *device, char *path) {
|
||||
|
||||
struct minix_file_info *minfo;
|
||||
struct minix_inode *dirp;
|
||||
struct minix_inode *new_node;
|
||||
struct minix_inode *new_node = (void *)0;
|
||||
unsigned int az = minix_alloc_zone(device, 0);
|
||||
|
||||
if (strlen(path_copy) > 0) {
|
||||
|
||||
|
||||
minfo = minix_check_if_exists(device, path_copy, 0);
|
||||
dirp = minix_get_inode(device, minfo->inode);
|
||||
new_node = minix_new_node(device, dirp, minfo->inode, basename, S_IFREG | 0644, minix_alloc_zone(device, 0));
|
||||
if (dirp->i_mode & S_IFDIR) {
|
||||
new_node = minix_new_node(device, dirp, minfo->inode, basename, S_IFREG | 0644, az);
|
||||
} else {
|
||||
kprintf("Trying to create a file in a file!\n");
|
||||
}
|
||||
} else {
|
||||
dirp = minix_get_inode(device, 1);
|
||||
new_node = minix_new_node(device, dirp, 1, basename, S_IFREG | 0644, minix_alloc_zone(device, 0));
|
||||
if (dirp->i_mode & S_IFDIR) {
|
||||
new_node = minix_new_node(device, dirp, 1, basename, S_IFREG | 0644, az);
|
||||
} else {
|
||||
kprintf("Root directory is not a directory!\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (!new_node) {
|
||||
@ -471,54 +492,82 @@ void minix_free_bit(struct vfs_device_t *device, int map, unsigned int bit) {
|
||||
|
||||
unsigned int minix_alloc_bit(struct vfs_device_t *device, int map, unsigned int bit) {
|
||||
struct minix_data *mdata = (struct minix_data *)device->fs_data;
|
||||
unsigned int mask, offset, index, i;
|
||||
unsigned int mask, offset, index, i, x, b;
|
||||
int j;
|
||||
int oldbit;
|
||||
|
||||
unsigned int startblock;
|
||||
if (map == 0) {
|
||||
oldbit = mdata->sb.s_ninodes;
|
||||
startblock = 2;
|
||||
} else {
|
||||
oldbit = mdata->sb.s_zones;
|
||||
startblock = 2 + mdata->sb.s_imap_blocks;
|
||||
oldbit = mdata->sb.s_zones;//(mdata->sb.s_zones - (mdata->first_data_block - 1));
|
||||
}
|
||||
|
||||
if (bit >= oldbit) bit = 0;
|
||||
|
||||
for (j=0;j<2;j++) {
|
||||
if (map == 0) {
|
||||
// inode map
|
||||
for (i=bit;i<oldbit;i++) {
|
||||
mask = 1;
|
||||
index = i / 8;
|
||||
offset = i % 8;
|
||||
unsigned int count = mdata->sb.s_imap_blocks * mdata->sb.s_blocksize;
|
||||
for (i = bit / 8;i < count; i++) {
|
||||
unsigned char mi = mdata->s_imap[i];
|
||||
if (mi == 0xFF) continue;
|
||||
// there's a free bit in here
|
||||
for (x = 0; (mi & (1 << x)) != 0 ; x++) {
|
||||
if (x >= 8) {
|
||||
kprintf("x >= 8!!!");
|
||||
}
|
||||
}
|
||||
|
||||
if (!(mdata->s_imap[index] & (mask << offset))) {
|
||||
mdata->s_imap[index] |= (mask << offset);
|
||||
b = i * 8 + x;
|
||||
|
||||
if (b >= oldbit) break;
|
||||
|
||||
|
||||
|
||||
mi |= 1 << x;
|
||||
|
||||
mdata->s_imap[i] = mi;
|
||||
|
||||
// write out inode table
|
||||
if (device->device == 1) {
|
||||
ramdisk_write_blocks(2, mdata->sb.s_imap_blocks, mdata->s_imap, mdata->sb.s_blocksize);
|
||||
ramdisk_write_blocks(startblock, mdata->sb.s_imap_blocks, mdata->s_imap, mdata->sb.s_blocksize);
|
||||
} else if ((device->device & 0xff00) == 0x100) {
|
||||
hd_write_blocks((device->device & 0xff), 2, mdata->sb.s_imap_blocks, mdata->s_imap, mdata->sb.s_blocksize);
|
||||
}
|
||||
return i;
|
||||
hd_write_blocks((device->device & 0xff), startblock, mdata->sb.s_imap_blocks, mdata->s_imap, mdata->sb.s_blocksize);
|
||||
}
|
||||
return b;
|
||||
|
||||
}
|
||||
} else {
|
||||
// zone map
|
||||
for (i=bit;i<oldbit;i++) {
|
||||
mask = 1;
|
||||
index = i / 8;
|
||||
offset = i % 8;
|
||||
unsigned int count = mdata->sb.s_zmap_blocks * mdata->sb.s_blocksize;
|
||||
for (i = bit / 8;i < count; i++) {
|
||||
unsigned char mi = mdata->s_zmap[i];
|
||||
if (mi == 0xFF) {
|
||||
continue;
|
||||
}
|
||||
// there's a free bit in here
|
||||
for (x = 0; (mi & (1 << x)) != 0; x++) {
|
||||
if (x >= 8) {
|
||||
kprintf("x >= 8!!!");
|
||||
}
|
||||
}
|
||||
|
||||
if (!(mdata->s_zmap[index] & (mask << offset))) {
|
||||
mdata->s_zmap[index] |= (mask << offset);
|
||||
b = i * 8 + x;
|
||||
|
||||
if (b >= oldbit) break;
|
||||
|
||||
mi |= 1 << x;
|
||||
mdata->s_zmap[i] = mi;
|
||||
// write out zone table
|
||||
if (device->device == 1) {
|
||||
ramdisk_write_blocks(2 + mdata->sb.s_imap_blocks, mdata->sb.s_zmap_blocks, mdata->s_zmap, mdata->sb.s_blocksize);
|
||||
ramdisk_write_blocks(startblock, mdata->sb.s_zmap_blocks, mdata->s_zmap, mdata->sb.s_blocksize);
|
||||
} else if ((device->device & 0xff00) == 0x100) {
|
||||
hd_write_blocks((device->device & 0xff), 2 + mdata->sb.s_imap_blocks, mdata->sb.s_zmap_blocks, mdata->s_zmap, mdata->sb.s_blocksize);
|
||||
}
|
||||
return i;
|
||||
hd_write_blocks((device->device & 0xff), startblock, mdata->sb.s_zmap_blocks, mdata->s_zmap, mdata->sb.s_blocksize);
|
||||
}
|
||||
return b;
|
||||
|
||||
}
|
||||
}
|
||||
if (bit == 0) {
|
||||
@ -528,13 +577,15 @@ unsigned int minix_alloc_bit(struct vfs_device_t *device, int map, unsigned int
|
||||
oldbit = bit + 1;
|
||||
bit = 0;
|
||||
}
|
||||
kprintf("Failed to get bit!!!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int minix_write_inode(struct vfs_device_t *device, unsigned int ino, struct minix_inode *inode) {
|
||||
struct minix_data *mdata = (struct minix_data *)device->fs_data;
|
||||
ino--;
|
||||
unsigned int block = mdata->inode_table_start_block + ino / (mdata->sb.s_blocksize / sizeof(struct minix_inode));
|
||||
unsigned int offset = mdata->inode_table_start_block;
|
||||
unsigned int block = ino / (mdata->sb.s_blocksize / sizeof(struct minix_inode)) + offset;
|
||||
char *buffer = (char *)malloc(mdata->sb.s_blocksize);
|
||||
|
||||
if (!buffer) {
|
||||
@ -547,7 +598,14 @@ int minix_write_inode(struct vfs_device_t *device, unsigned int ino, struct mini
|
||||
hd_read_block((device->device & 0xff), block, buffer, mdata->sb.s_blocksize);
|
||||
}
|
||||
|
||||
memcpy(&buffer[(ino % (mdata->sb.s_blocksize / sizeof(struct minix_inode))) * sizeof(struct minix_inode)], inode, sizeof(struct minix_inode));
|
||||
unsigned int ino_offset = (ino % (mdata->sb.s_blocksize / sizeof(struct minix_inode))) * sizeof(struct minix_inode);
|
||||
|
||||
if (ino_offset >= mdata->sb.s_blocksize) {
|
||||
kprintf("ino_offset >= block size!\n");
|
||||
} else {
|
||||
memcpy(buffer + ino_offset, inode, sizeof(struct minix_inode));
|
||||
}
|
||||
|
||||
|
||||
if (device->device == 1) {
|
||||
ramdisk_write_block(block, buffer, mdata->sb.s_blocksize);
|
||||
@ -714,7 +772,7 @@ struct minix_inode *minix_alloc_inode(struct vfs_device_t *device, unsigned shor
|
||||
new_inode->i_ctime = new_inode->i_atime;
|
||||
minix_write_inode(device, b, new_inode);
|
||||
*ino = b;
|
||||
// kprintf("INODE %d\n", b);
|
||||
|
||||
return new_inode;
|
||||
}
|
||||
|
||||
@ -1303,7 +1361,7 @@ int minix_write_data(struct vfs_device_t *device, struct minix_file_info *info,
|
||||
unsigned int last_block = 0;
|
||||
unsigned int buffer_at = 0;
|
||||
obuffer = (char *)malloc(mdata->sb.s_blocksize);
|
||||
if (!buffer) {
|
||||
if (!obuffer) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1326,7 +1384,8 @@ int minix_write_data(struct vfs_device_t *device, struct minix_file_info *info,
|
||||
for (i=block_start;i<blockcount + block_start;i++) {
|
||||
block = minix_read_map(device, inode, i * mdata->sb.s_blocksize);
|
||||
if (block == 0) {
|
||||
if (!minix_write_map(device, inode, info->inode, i * mdata->sb.s_blocksize, minix_alloc_zone(device, last_block), 0)) {
|
||||
unsigned int az = minix_alloc_zone(device, last_block);
|
||||
if (!minix_write_map(device, inode, info->inode, i * mdata->sb.s_blocksize, az, 0)) {
|
||||
if (inode->i_size < offset + buffer_at) {
|
||||
inode->i_size = offset + buffer_at;
|
||||
minix_write_inode(device, info->inode, inode);
|
||||
@ -1349,9 +1408,9 @@ int minix_write_data(struct vfs_device_t *device, struct minix_file_info *info,
|
||||
} else {
|
||||
last_block = block;
|
||||
if (device->device == 1) {
|
||||
ramdisk_read_block(block, obuffer, mdata->sb.s_blocksize);
|
||||
ramdisk_read_block(block , obuffer, mdata->sb.s_blocksize);
|
||||
} else if ((device->device & 0xff00) == 0x100) {
|
||||
hd_read_block((device->device & 0xff), block, obuffer, mdata->sb.s_blocksize);
|
||||
hd_read_block((device->device & 0xff), block , obuffer, mdata->sb.s_blocksize);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1362,12 +1421,12 @@ int minix_write_data(struct vfs_device_t *device, struct minix_file_info *info,
|
||||
if (device->device == 1) {
|
||||
ramdisk_write_block(block, obuffer, mdata->sb.s_blocksize);
|
||||
} else if ((device->device & 0xff00) == 0x100) {
|
||||
hd_write_block((device->device & 0xff), block, obuffer, mdata->sb.s_blocksize);
|
||||
hd_write_block((device->device & 0xff), block , obuffer, mdata->sb.s_blocksize);
|
||||
}
|
||||
} else {
|
||||
memcpy(&obuffer[block_offset], buffer, len);
|
||||
if (device->device == 1) {
|
||||
ramdisk_write_block(block, obuffer, mdata->sb.s_blocksize);
|
||||
ramdisk_write_block(block , obuffer, mdata->sb.s_blocksize);
|
||||
} else if ((device->device & 0xff00) == 0x100) {
|
||||
hd_write_block((device->device & 0xff), block, obuffer, mdata->sb.s_blocksize);
|
||||
}
|
||||
@ -1385,9 +1444,9 @@ int minix_write_data(struct vfs_device_t *device, struct minix_file_info *info,
|
||||
memcpy(obuffer, &buffer[buffer_at], mdata->sb.s_blocksize);
|
||||
buffer_at += mdata->sb.s_blocksize;
|
||||
if (device->device == 1) {
|
||||
ramdisk_write_block(block, obuffer, mdata->sb.s_blocksize);
|
||||
ramdisk_write_block(block , obuffer, mdata->sb.s_blocksize);
|
||||
} else if ((device->device & 0xff00) == 0x100) {
|
||||
hd_write_block((device->device & 0xff), block, obuffer, mdata->sb.s_blocksize);
|
||||
hd_write_block((device->device & 0xff),block , obuffer, mdata->sb.s_blocksize);
|
||||
}
|
||||
} else {
|
||||
memcpy(obuffer, &buffer[buffer_at], len - buffer_at);
|
||||
@ -1442,13 +1501,13 @@ int minix_load_superblock(struct vfs_device_t *device) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
mdata->s_imap = (char *)malloc(mdata->sb.s_imap_blocks * mdata->sb.s_blocksize);
|
||||
mdata->s_imap = (unsigned int *)malloc(mdata->sb.s_imap_blocks * mdata->sb.s_blocksize);
|
||||
if (!mdata->s_imap) {
|
||||
free(buffer);
|
||||
free(mdata);
|
||||
return 0;
|
||||
}
|
||||
mdata->s_zmap = (char *)malloc(mdata->sb.s_zmap_blocks * mdata->sb.s_blocksize);
|
||||
mdata->s_zmap = (unsigned int *)malloc(mdata->sb.s_zmap_blocks * mdata->sb.s_blocksize);
|
||||
if (!mdata->s_zmap) {
|
||||
free(mdata->s_imap);
|
||||
free(buffer);
|
||||
@ -1465,7 +1524,17 @@ int minix_load_superblock(struct vfs_device_t *device) {
|
||||
}
|
||||
|
||||
mdata->inode_table_start_block = 2 + mdata->sb.s_imap_blocks + mdata->sb.s_zmap_blocks;
|
||||
|
||||
if (mdata->sb.s_first_data_zone == 0) {
|
||||
|
||||
mdata->first_data_block = mdata->inode_table_start_block + ((mdata->sb.s_ninodes * sizeof(struct minix_inode)) / mdata->sb.s_blocksize);
|
||||
if ((mdata->sb.s_ninodes * sizeof(struct minix_inode)) % mdata->sb.s_blocksize != 0) {
|
||||
kprintf("More inodes than blocksize\n");
|
||||
mdata->first_data_block += 1;
|
||||
}
|
||||
} else {
|
||||
mdata->first_data_block = (unsigned int)mdata->sb.s_first_data_zone;
|
||||
}
|
||||
kprintf("MINIX FS: Recognized Filesystem (Blocksize: %d)\n", mdata->sb.s_blocksize);
|
||||
|
||||
device->fs_data = mdata;
|
||||
|
4
minix.h
4
minix.h
@ -45,8 +45,8 @@ struct minix_file_info {
|
||||
|
||||
struct minix_data {
|
||||
struct minix_super_block sb;
|
||||
char *s_imap;
|
||||
char *s_zmap;
|
||||
unsigned char *s_imap;
|
||||
unsigned char *s_zmap;
|
||||
int inode_table_start_block;
|
||||
int first_data_block;
|
||||
};
|
||||
|
2
programs/external/SDL/make.sh
vendored
2
programs/external/SDL/make.sh
vendored
@ -1,7 +1,7 @@
|
||||
#!/bin/bash
|
||||
if [ ! -e SDL ]
|
||||
then
|
||||
git clone https://github.com/apamment/SDL.git
|
||||
git clone https://gitlab.com/apamment/quinn-sdl.git SDL
|
||||
fi
|
||||
|
||||
cd SDL
|
||||
|
2
programs/external/dungeonbash/make.sh
vendored
2
programs/external/dungeonbash/make.sh
vendored
@ -10,7 +10,7 @@ patch -p0 < dungeonbash-1.7.diff
|
||||
cd dungeonbash-1.7
|
||||
make
|
||||
|
||||
mkdir $HOME/Quinn/games
|
||||
mkdir -p $HOME/Quinn/fsroot/games
|
||||
|
||||
cp dungeonbash.exe $HOME/Quinn/fsroot/games
|
||||
|
||||
|
@ -9,6 +9,8 @@
|
||||
|
||||
struct widget_t *listbox;
|
||||
struct widget_t *listbox2;
|
||||
struct widget_t *textbox;
|
||||
struct widget_t *textbox2;
|
||||
|
||||
int window_handle;
|
||||
|
||||
@ -39,7 +41,7 @@ void set_active_list() {
|
||||
}
|
||||
}
|
||||
|
||||
void fill_dir_list(struct widget_t *lb, char *wd) {
|
||||
int fill_dir_list(struct widget_t *lb, char *wd) {
|
||||
int fno = open(wd, 0, 0);
|
||||
int len;
|
||||
int bpos;
|
||||
@ -50,7 +52,6 @@ void fill_dir_list(struct widget_t *lb, char *wd) {
|
||||
struct stat s;
|
||||
|
||||
if (fno >= 0) {
|
||||
|
||||
while (1) {
|
||||
__asm__ volatile ("int $0x30" : "=a" (len) : "0" (13), "b" (fno), "c" (buffer), "d" (1024));
|
||||
if (len <= 0) {
|
||||
@ -75,8 +76,31 @@ void fill_dir_list(struct widget_t *lb, char *wd) {
|
||||
}
|
||||
}
|
||||
close(fno);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void textbox_callback() {
|
||||
char newcwd[512];
|
||||
quinn_listbox_clear(listbox);
|
||||
strcpy(newcwd, quinn_textbox_get_text(textbox));
|
||||
if (fill_dir_list(listbox, newcwd)) {
|
||||
strcpy(cwd, newcwd);
|
||||
} else {
|
||||
quinn_textbox_set_text(textbox, cwd);
|
||||
}
|
||||
}
|
||||
|
||||
void textbox2_callback() {
|
||||
char newcwd[512];
|
||||
quinn_listbox_clear(listbox2);
|
||||
strcpy(newcwd, quinn_textbox_get_text(textbox2));
|
||||
if (fill_dir_list(listbox2, newcwd)) {
|
||||
strcpy(cwd2, newcwd);
|
||||
} else {
|
||||
quinn_textbox_set_text(textbox2, cwd2);
|
||||
}
|
||||
}
|
||||
|
||||
void delete_ok_callback() {
|
||||
@ -150,31 +174,47 @@ void ramdisk_callback(void *data) {
|
||||
quinn_listbox_clear(listbox);
|
||||
strcpy(cwd, "ramdisk:/");
|
||||
fill_dir_list(listbox, cwd);
|
||||
quinn_textbox_set_text(textbox, cwd);
|
||||
}
|
||||
|
||||
void disk0_callback(void *data) {
|
||||
quinn_listbox_clear(listbox);
|
||||
strcpy(cwd, "disk0:/");
|
||||
fill_dir_list(listbox, cwd);
|
||||
quinn_textbox_set_text(textbox, cwd);
|
||||
}
|
||||
|
||||
void ramdisk_callback2(void *data) {
|
||||
quinn_listbox_clear(listbox2);
|
||||
strcpy(cwd2, "ramdisk:/");
|
||||
fill_dir_list(listbox2, cwd2);
|
||||
quinn_textbox_set_text(textbox2, cwd2);
|
||||
}
|
||||
|
||||
void disk0_callback2(void *data) {
|
||||
quinn_listbox_clear(listbox2);
|
||||
strcpy(cwd2, "disk0:/");
|
||||
fill_dir_list(listbox2, cwd2);
|
||||
quinn_textbox_set_text(textbox2, cwd2);
|
||||
}
|
||||
|
||||
void listbox_callback(char *item, int index) {
|
||||
if (item[strlen(item) - 1] == '/') {
|
||||
if (strcmp(item, "../") == 0) {
|
||||
cwd[strlen(cwd)-1] = '\0';
|
||||
if (strlen(cwd) > 2 && strrchr(cwd, '/') != NULL) {
|
||||
char *ptr = strrchr(cwd, '/');
|
||||
*ptr = '\0';
|
||||
}
|
||||
strcat(cwd, "/");
|
||||
} else if (strcmp(item, "./") == 0) {
|
||||
|
||||
} else {
|
||||
strcat(cwd, item);
|
||||
}
|
||||
quinn_listbox_clear(listbox);
|
||||
fill_dir_list(listbox, cwd);
|
||||
quinn_textbox_set_text(textbox, cwd);
|
||||
filename[0] = '\0';
|
||||
} else {
|
||||
strcpy(filename, item);
|
||||
@ -186,9 +226,21 @@ void listbox_callback(char *item, int index) {
|
||||
|
||||
void listbox2_callback(char *item, int index) {
|
||||
if (item[strlen(item) - 1] == '/') {
|
||||
if (strcmp(item, "../") == 0) {
|
||||
cwd2[strlen(cwd2)-1] = '\0';
|
||||
if (strlen(cwd2) > 2 && strrchr(cwd2, '/') != NULL) {
|
||||
char *ptr = strrchr(cwd2, '/');
|
||||
*ptr = '\0';
|
||||
}
|
||||
strcat(cwd2, "/");
|
||||
} else if (strcmp(item, "./") == 0) {
|
||||
|
||||
} else {
|
||||
strcat(cwd2, item);
|
||||
}
|
||||
quinn_listbox_clear(listbox2);
|
||||
fill_dir_list(listbox2, cwd2);
|
||||
quinn_textbox_set_text(textbox2, cwd2);
|
||||
filename[0] = '\0';
|
||||
} else {
|
||||
strcpy(filename, item);
|
||||
@ -239,9 +291,11 @@ int main(int argc, char **argv) {
|
||||
listbox = quinn_add_listbox(window_handle, 3, 31, 290, 240, listbox_callback);
|
||||
listbox2 = quinn_add_listbox(window_handle, 300, 31, 290, 240, listbox2_callback);
|
||||
|
||||
textbox = quinn_add_textbox(window_handle, 3, 284, 290, 20, NULL, textbox_callback);
|
||||
textbox2 = quinn_add_textbox(window_handle, 300, 284, 290, 20, NULL, textbox2_callback);
|
||||
|
||||
quinn_add_button(window_handle, 3, 284, 60,25, "Copy", NULL, copy_callback);
|
||||
quinn_add_button(window_handle, 63, 284, 60, 25, "Delete", NULL, delete_callback);
|
||||
quinn_add_button(window_handle, 3, 306, 60,25, "Copy", NULL, copy_callback);
|
||||
quinn_add_button(window_handle, 63, 306, 60, 25, "Delete", NULL, delete_callback);
|
||||
|
||||
while (1) {
|
||||
quinn_process();
|
||||
|
@ -1269,7 +1269,7 @@ struct widget_t *quinn_add_textbox(int wh, int x, int y, int w, int h, char *tex
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (text == NULL) {
|
||||
if (text == NULL || strlen(text) == 0) {
|
||||
txtbox->text = (char *)malloc(sizeof(char));
|
||||
if (!txtbox->text) {
|
||||
printf("Out of memory\n");
|
||||
@ -1293,6 +1293,8 @@ struct widget_t *quinn_add_textbox(int wh, int x, int y, int w, int h, char *tex
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
txtbox->callback = callback;
|
||||
|
||||
newwidget->widget = txtbox;
|
||||
newwidget->type = 5;
|
||||
newwidget->w = w;
|
||||
@ -1316,6 +1318,29 @@ struct widget_t *quinn_add_textbox(int wh, int x, int y, int w, int h, char *tex
|
||||
return newwidget;
|
||||
}
|
||||
|
||||
void quinn_textbox_set_text(struct widget_t *w, const char * text) {
|
||||
struct textbox_t *txtbox;
|
||||
if (w->type != 5) {
|
||||
return;
|
||||
}
|
||||
|
||||
txtbox = (struct textbox_t *)w->widget;
|
||||
free(txtbox->text);
|
||||
txtbox->text = strdup(text);
|
||||
txtbox->cursor_at = strlen(text);
|
||||
}
|
||||
|
||||
const char *quinn_textbox_get_text(struct widget_t *w) {
|
||||
struct textbox_t *txtbox;
|
||||
|
||||
if (w->type != 5) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
txtbox = (struct textbox_t *)w->widget;
|
||||
return txtbox->text;
|
||||
}
|
||||
|
||||
void quinn_free_textbox(struct widget_t *w) {
|
||||
struct textbox_t *txtbox;
|
||||
|
||||
|
@ -75,6 +75,8 @@ extern void quinn_remove_window(int wh);
|
||||
extern void quinn_show_message_box(int wh, char *title, char *message, unsigned char show_cancel, void (*callback)());
|
||||
extern struct widget_t *quinn_add_textbox(int wh, int x, int y, int w, int h, char *text, void (*callback)());
|
||||
extern void quinn_textbox_insert_char(struct widget_t *w, char c);
|
||||
extern const char *quinn_textbox_get_text(struct widget_t *w);
|
||||
extern void quinn_textbox_set_text(struct widget_t *w, const char * text);
|
||||
extern void quinn_free_textbox(struct widget_t *w);
|
||||
extern void quinn_render_offset(unsigned char* dest, unsigned char* src, unsigned int src_width, unsigned int src_height, unsigned int offset_x, unsigned int offset_y, int dest_x, int dest_y, unsigned int dest_width, unsigned int dest_height);
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user