Пример #1
0
static int
walk_dirs (struct ocfs2_dir_entry *dirent,
           uint64_t                blocknr,
           int                     offset,
	   int                     blocksize,
	   char                   *buf,
	   void                   *priv_data)
{
  PyObject *de;
  WalkData *data = priv_data;

  de = dir_entry_new (data->fs, dirent);

  if (de == NULL)
    return OCFS2_DIRENT_ERROR;

  /* XXX: handle errors */
  if (data->data)
    PyObject_CallFunction (data->func, "OiiO", de, offset, blocksize,
			   data->data);
  else
    PyObject_CallFunction (data->func, "Oii", de, offset, blocksize);

  Py_DECREF (de);

  return 0;
}
Пример #2
0
static PyObject *
dir_scan_iter_next (DirScanIter *self)
{
  errcode_t              ret;
  struct ocfs2_dir_entry dirent;

  if (self->scan == NULL)
    {
      PyErr_SetNone (PyExc_StopIteration);
      return NULL;
    }

  CHECK_ERROR (ocfs2_get_next_dir_entry (self->scan, &dirent));

  if (dirent.rec_len == 0)
    {
      ocfs2_close_dir_scan (self->scan);
      self->scan = NULL;

      Py_DECREF (self->fs_obj);
      self->fs_obj = NULL;

      PyErr_SetNone (PyExc_StopIteration);
      return NULL;
    }

  return dir_entry_new (self->fs_obj, &dirent);
}
Пример #3
0
static struct dir_info *dir_new(struct dir_info *parent, const char *name)
{
	struct dir_info *dir;
	size_t sz;
	char *path;

	path = dir_path(parent, name);
	if (mkdir(path, 0777) == -1) {
		CHECK(errno == ENOSPC);
		full = 1;
		free(path);
		return NULL;
	}
	free(path);

	sz = sizeof(struct dir_info);
	dir = (struct dir_info *) malloc(sz);
	CHECK(dir != NULL);
	memset(dir, 0, sz);
	dir->name = copy_string(name);
	dir->parent = parent;
	if (parent) {
		struct dir_entry_info *entry;

		entry = dir_entry_new();
		entry->type = 'd';
		entry->entry.dir = dir;
		entry->next = parent->first;
		parent->first = entry;
		parent->number_of_entries += 1;
	}
	return dir;
}
Пример #4
0
Файл: dir.c Проект: CCorreia/git
struct dir_entry *dir_add_ignored(struct dir_struct *dir, const char *pathname, int len)
{
	if (!cache_name_is_other(pathname, len))
		return NULL;

	ALLOC_GROW(dir->ignored, dir->ignored_nr+1, dir->ignored_alloc);
	return dir->ignored[dir->ignored_nr++] = dir_entry_new(pathname, len);
}
Пример #5
0
Файл: dir.c Проект: CCorreia/git
static struct dir_entry *dir_add_name(struct dir_struct *dir, const char *pathname, int len)
{
	if (cache_name_exists(pathname, len, ignore_case))
		return NULL;

	ALLOC_GROW(dir->entries, dir->nr+1, dir->alloc);
	return dir->entries[dir->nr++] = dir_entry_new(pathname, len);
}
Пример #6
0
static struct dir_entry *
dir_add_name(struct dir_struct *dir, const char *pathname, 
             int len, struct index_state *index)
{
    if (index_name_exists(index, pathname, len, 0))
        return NULL;

    ALLOC_GROW(dir->entries, dir->nr+1, dir->alloc);
    return dir->entries[dir->nr++] = dir_entry_new(pathname, len);
}
Пример #7
0
static struct file_info *file_new(struct dir_info *parent, const char *name)
{
	struct file_info *file = NULL;
	char *path;
	mode_t mode;
	int fd;
	size_t sz;
	struct dir_entry_info *entry;

	CHECK(parent != NULL);

	path = dir_path(parent, name);
	mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
	fd = open(path, O_CREAT | O_EXCL | O_RDWR, mode);
	if (fd == -1) {
		CHECK(errno == ENOSPC);
		free(path);
		full = 1;
		return NULL;
	}
	free(path);

	sz = sizeof(struct file_info);
	file = (struct file_info *) malloc(sz);
	CHECK(file != NULL);
	memset(file, 0, sz);
	file->name = copy_string(name);
	file->parent = parent;

	fd_new(file, fd);

	entry = dir_entry_new();
	entry->type = 'f';
	entry->entry.file = file;
	entry->next = parent->first;
	parent->first = entry;
	parent->number_of_entries += 1;

	return file;
}
Пример #8
0
/**
 * Insert a dir_entry with given filename and type in list.
 *
 * @param at the position before which the entry will be inserted
 * @param filename file name
 * @param type file type
 * @return pointer to the inserted dir_entry
 */
static dir_entry* dir_entry_insert(dir_entry **at, char* filename, unsigned type)
{
	dir_entry* e = dir_entry_new(*at, filename, type);
	if (e) *at = e;
	return e;
}