Finish haggis_load_node
function; Add *node related function
prototypes to haggis.h;
This commit is contained in:
parent
5b520b54e2
commit
e97feb1e3d
2 changed files with 34 additions and 5 deletions
|
@ -118,4 +118,9 @@ struct haggis_node {
|
||||||
struct haggis_filetype *filetype;
|
struct haggis_filetype *filetype;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct haggis_node* haggis_create_node(char *file);
|
||||||
|
int haggis_extract_node(FILE *stram, struct haggis_node *node);
|
||||||
|
int haggis_load_node(FILE *stream, struct haggis_node *node);
|
||||||
|
int haggis_store_node(FILE *stream, struct haggis_node *node);
|
||||||
|
|
||||||
#endif // !HAGGIS_H
|
#endif // !HAGGIS_H
|
||||||
|
|
34
src/haggis.c
34
src/haggis.c
|
@ -30,6 +30,7 @@
|
||||||
* other than his own.
|
* other than his own.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
#if defined(__FreeBSD__) || defined(__DragonFly__)
|
#if defined(__FreeBSD__) || defined(__DragonFly__)
|
||||||
#include <sha.h>
|
#include <sha.h>
|
||||||
#include <sha256.h>
|
#include <sha256.h>
|
||||||
|
@ -357,7 +358,7 @@ int haggis_load_filetype(
|
||||||
file->tag = 2;
|
file->tag = 2;
|
||||||
case directory:
|
case directory:
|
||||||
file->tag = 3;
|
file->tag = 3;
|
||||||
break;
|
break;
|
||||||
case character:
|
case character:
|
||||||
file->tag = 4;
|
file->tag = 4;
|
||||||
return haggis_load_device(stream, file->f_type);
|
return haggis_load_device(stream, file->f_type);
|
||||||
|
@ -366,7 +367,7 @@ int haggis_load_filetype(
|
||||||
return haggis_load_device(stream, file->f_type);
|
return haggis_load_device(stream, file->f_type);
|
||||||
case fifo:
|
case fifo:
|
||||||
file->tag = 6;
|
file->tag = 6;
|
||||||
break;
|
break;
|
||||||
case eof:
|
case eof:
|
||||||
file->tag = 7;
|
file->tag = 7;
|
||||||
break;
|
break;
|
||||||
|
@ -374,7 +375,19 @@ int haggis_load_filetype(
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int haggis_store_node(FILE *stream, struct haggis_node *node) {
|
enum haggis_typeflag haggis_filetype_from_mode(union u16 mode) {
|
||||||
|
u8 mask = 07 << 5;
|
||||||
|
int filetype = (int)((mode.bytes[0] & mask) >> 5);
|
||||||
|
return filetype;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct haggis_node* haggis_create_node(char *file) {
|
||||||
|
struct haggis_node *node = malloc(sizeof(struct haggis_node));
|
||||||
|
// todo
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
int haggis_extract_node(FILE *stram, struct haggis_node *node) {
|
||||||
// todo
|
// todo
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -382,8 +395,9 @@ int haggis_store_node(FILE *stream, struct haggis_node *node) {
|
||||||
int haggis_load_node(FILE *stream, struct haggis_node *node) {
|
int haggis_load_node(FILE *stream, struct haggis_node *node) {
|
||||||
int res;
|
int res;
|
||||||
union u16 mode;
|
union u16 mode;
|
||||||
enum haggis_typeflag flag;
|
enum haggis_typeflag tag;
|
||||||
|
|
||||||
|
mode.val = 0;
|
||||||
res = haggis_load_filename(stream, node->name);
|
res = haggis_load_filename(stream, node->name);
|
||||||
if (res)
|
if (res)
|
||||||
return res;
|
return res;
|
||||||
|
@ -399,6 +413,16 @@ int haggis_load_node(FILE *stream, struct haggis_node *node) {
|
||||||
res = load_u16(stream, mode);
|
res = load_u16(stream, mode);
|
||||||
if (res != 2)
|
if (res != 2)
|
||||||
return 2;
|
return 2;
|
||||||
//todo
|
tag = haggis_filetype_from_mode(mode);
|
||||||
|
node->mode.bytes[0] = mode.bytes[0] & 037;
|
||||||
|
node->mode.bytes[1] = mode.bytes[1];
|
||||||
|
res = haggis_load_filetype(stream, tag, node->filetype);
|
||||||
|
if (res)
|
||||||
|
return res;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int haggis_store_node(FILE *stream, struct haggis_node *node) {
|
||||||
|
// todo
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue