File: create.c

package info (click to toggle)
reiser4progs 1.0.6-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 5,348 kB
  • ctags: 3,714
  • sloc: ansic: 33,468; sh: 8,489; makefile: 1,012
file content (63 lines) | stat: -rw-r--r-- 1,559 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* Copyright (C) 2001-2005 by Hans Reiser, licensing governed by
   reiser4progs/COPYING.
   
   create.c -- a demo program that creates a reg file on reiser4. */

#include "busy.h"

errno_t create_cmd(busy_ctx_t *ctx) {
	reiser4_object_t *parent, *object;
	char *name;

	aal_assert("vpf-1710", ctx != NULL);

	if (!ctx->in.fs) {
		aal_error("Fs is not openned. Wrong PATH is specified: %s.",
			  ctx->in.path);
		return -EINVAL;
	}
	
	if (ctx->in.path[0] == 0) {
		aal_error("NULL path is given.");
		return -EINVAL;
	}
	
	name = ctx->in.path;
	
	parent = busy_misc_open_parent(ctx->in.fs->tree, &name);
	if (!parent || parent == INVAL_PTR)
		return -EINVAL;
	
	if (ctx->objtype == REG_OBJECT)
		object = reiser4_reg_create(parent, name);
	else if (ctx->objtype == DIR_OBJECT)
		object = reiser4_dir_create(parent, name);
	else if (ctx->objtype == SPL_OBJECT)
		object = reiser4_spl_create(parent, name, ctx->mode, ctx->rdev);
	else if (ctx->objtype == SYM_OBJECT) {
		if (ctx->out.path[0] == 0)
			goto error_free_parent;
		
		object = reiser4_sym_create(parent, name, ctx->out.path);
	} else if (ctx->objtype == (REG_OBJECT | OBJFLAG_CRYCOM)) {
		object = reiser4_ccreg_create(parent, name, NULL);
	} else {
		aal_error("Illegal object type is given (%d).", ctx->objtype);
		goto error_free_parent;
	}
	
	if (!object) {
		aal_error("Failed to create the file %s.", ctx->in.path);
		goto error_free_parent;
	}

	reiser4_object_close(object);
	reiser4_object_close(parent);
	
	return 0;
	
 error_free_parent:
	reiser4_object_close(parent);
	return -EIO;
}