libk  file.h at [12a51d9c50]

File mod/kfile/file.h artifact a786627a56 part of check-in 12a51d9c50


#ifndef KIfile
#define KIfile
#include <k/type.h>
#include <k/io.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef enum kfcond {
	kfcond_ok = 0,
	kfcond_fail = 1,
		// an unspecified error occurred
	kfcond_bad_domain,
		// the values passed to the function are not within
		// that function's domain and are invalid
	kfcond_overstep,
		// kfstep() was only able to move part of the
		// distance requested
	kfcond_bad_index,
		// the requested index is past the end of the file
	kfcond_notfound,
		// the specified object could not be found
	kfcond_unauth,
		// you do not have permission to open this object
	kfcond_mem,
		// there is not enough memory to complete the
		// requested operation
} kfcond;

typedef enum kfile_kind {
	kfile_closed,
		// the file object does not refer to an open file
	kfile_open,
		// the file object refers to an open file
} kfile_kind;

enum kfopen {
	/* file open modes */
	kf_read   = 1 << 9,  kf_write = 1 << 10,
	kf_ascii  = 1 << 11, kf_new   = 1 << 12,
	kf_create = 1 << 13, kf_load  = 1 << 14,
	kf_top    = 1 << 15, kf_end   = 1 << 16,
	kf_wipe   = 1 << 17, kf_map   = 1 << 18,

	/* file permission flags */
	kf_ur = 4 << 6, kf_uw = 2 << 6, kf_ux = 1 << 6,
	kf_gr = 4 << 3, kf_gw = 2 << 3, kf_gx = 1 << 3, 
	kf_or = 4 << 0, kf_ow = 2 << 0, kf_ox = 1 << 0,
}

typedef struct kfile {
	enum kfile_kind kind;
	enum kfopen mode;
	kiochan chan;
	u8* content;
} kfile;

enum kfset_mode {
	kfset_none, // do not move
	kfset_top, // move to x bytes from the start of the file
	kfset_end, // move to x bytes from the end of the file
}

enum kfplace { 
	kfplace_none,
	kfplace_conf,
	kfplace_home,
	kfplace_desk,
	kfplace_dl,
	kfplace_img,
	kfplace_vid,
	kfplace_msc,
	kfplace_doc,
	kfplace_dat,
	kfplace_share,
	kfplace_share_global,
	kfplace_cache,
}

kfile kfplace(enum kfplace location, const char* file, enum kfopen mode);
kfile kfopen (const char* file, enum kfopen mode);
kfile kfopens(const ksraw file, enum kfopen mode);

kfcond kfset (struct kfile file, enum kfset_mode mode, sz position);
kfcond kfstep(struct kfile file, offset position);

kfcond kfshred(struct kfile file, sz count);

#ifdef __cplusplus
}
#endif

#endif