1 /* 2 * Copyright 2002-2008, Axel Dörfler, axeld@pinc-software.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include <fs_index.h> 8 9 #include <stdlib.h> 10 #include <fcntl.h> 11 #include <errno.h> 12 13 #include <dirent_private.h> 14 #include <syscalls.h> 15 16 17 #define RETURN_AND_SET_ERRNO(status) \ 18 { \ 19 if (status < 0) { \ 20 errno = status; \ 21 return -1; \ 22 } \ 23 return status; \ 24 } 25 26 27 int 28 fs_create_index(dev_t device, const char *name, uint32 type, uint32 flags) 29 { 30 status_t status = _kern_create_index(device, name, type, flags); 31 32 RETURN_AND_SET_ERRNO(status); 33 } 34 35 36 int 37 fs_remove_index(dev_t device, const char *name) 38 { 39 status_t status = _kern_remove_index(device, name); 40 41 RETURN_AND_SET_ERRNO(status); 42 } 43 44 45 int 46 fs_stat_index(dev_t device, const char *name, struct index_info *indexInfo) 47 { 48 struct stat stat; 49 50 status_t status = _kern_read_index_stat(device, name, &stat); 51 if (status == B_OK) { 52 indexInfo->type = stat.st_type; 53 indexInfo->size = stat.st_size; 54 indexInfo->modification_time = stat.st_mtime; 55 indexInfo->creation_time = stat.st_crtime; 56 indexInfo->uid = stat.st_uid; 57 indexInfo->gid = stat.st_gid; 58 } 59 60 RETURN_AND_SET_ERRNO(status); 61 } 62 63 64 DIR * 65 fs_open_index_dir(dev_t device) 66 { 67 DIR *dir; 68 69 int fd = _kern_open_index_dir(device); 70 if (fd < 0) { 71 errno = fd; 72 return NULL; 73 } 74 75 /* allocate the memory for the DIR structure */ 76 if ((dir = (DIR *)malloc(DIR_BUFFER_SIZE)) == NULL) { 77 errno = B_NO_MEMORY; 78 _kern_close(fd); 79 return NULL; 80 } 81 82 dir->fd = fd; 83 dir->entries_left = 0; 84 85 return dir; 86 } 87 88 89 int 90 fs_close_index_dir(DIR *dir) 91 { 92 int status = _kern_close(dir->fd); 93 94 free(dir); 95 96 RETURN_AND_SET_ERRNO(status); 97 } 98 99 100 struct dirent * 101 fs_read_index_dir(DIR *dir) 102 { 103 return readdir(dir); 104 } 105 106 107 void 108 fs_rewind_index_dir(DIR *dir) 109 { 110 rewinddir(dir); 111 } 112 113