Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00080
00081 #include <unistd.h>
00082
00083 #include <errno.h>
00084 #include <sys/device.h>
00085 #include <string.h>
00086
00087 #include <fs/fs.h>
00088 #include <sys/stat.h>
00089
00094
00095 static int PathOperation(CONST char *path, int opcode)
00096 {
00097 NUTDEVICE *dev;
00098 char dev_name[9];
00099 uint8_t nidx;
00100 CONST char *nptr = path;
00101
00102
00103
00104
00105 for (nidx = 0; *nptr && *nptr != ':' && nidx < 8; nidx++) {
00106 dev_name[nidx] = *nptr++;
00107 }
00108 dev_name[nidx] = 0;
00109 nptr++;
00110
00111
00112
00113
00114
00115 if ((dev = NutDeviceLookup(dev_name)) == 0) {
00116 errno = ENOENT;
00117 return -1;
00118 }
00119 return (*dev->dev_ioctl) (dev, opcode, (void *) nptr);
00120 }
00121
00136 int access(CONST char *path, int what)
00137 {
00138 struct stat s;
00139
00140 if (stat(path, &s)) {
00141 return -1;
00142 }
00143 return 0;
00144 }
00145
00155 long lseek(int fh, long pos, int whence)
00156 {
00157
00158
00159
00160
00161
00162
00163 return -1;
00164 }
00165
00175 int rmdir(CONST char *path)
00176 {
00177 return PathOperation(path, FS_DIR_REMOVE);
00178 }
00179
00185 int unlink(CONST char *path)
00186 {
00187 return PathOperation(path, FS_FILE_DELETE);
00188 }
00189
00190
00196 int stat(CONST char *path, struct stat *s)
00197 {
00198 NUTDEVICE *dev;
00199 char dev_name[9];
00200 uint8_t nidx;
00201 CONST char *nptr = path;
00202 FSCP_STATUS parms;
00203
00204
00205 for (nidx = 0; *nptr && *nptr != ':' && nidx < 8; nidx++) {
00206 dev_name[nidx] = *nptr++;
00207 }
00208 dev_name[nidx] = 0;
00209
00210
00211 if ((dev = NutDeviceLookup(dev_name)) != 0) {
00212 if (*nptr == ':') {
00213 nptr++;
00214 }
00215 parms.par_path = nptr;
00216 parms.par_stp = s;
00217 return (*dev->dev_ioctl) (dev, FS_STATUS, (void *) &parms);
00218 }
00219 return -1;
00220 }
00221
00227 int fstat(int fh, struct stat *s)
00228 {
00229 return -1;
00230 }
00231
00237 int mkdir(CONST char *path, int mode)
00238 {
00239 return PathOperation(path, FS_DIR_CREATE);
00240 }
00241
00254 int rename(CONST char *old_name, CONST char *new_name)
00255 {
00256 int rc = -1;
00257 NUTDEVICE *dev;
00258 char old_devname[9];
00259 char new_devname[9];
00260 uint8_t nidx;
00261 CONST char *nptr;
00262 FSCP_RENAME parms;
00263
00264
00265 nptr = old_name;
00266 for (nidx = 0; *nptr && *nptr != ':' && nidx < 8; nidx++, nptr++) {
00267 old_devname[nidx] = *nptr;
00268 }
00269 old_devname[nidx] = 0;
00270
00271
00272 if (*nptr++ == ':') {
00273
00274 parms.par_old = nptr;
00275
00276
00277 nptr = new_name;
00278
00279 for (nidx = 0; *nptr && *nptr != ':' && nidx < 8; nidx++, nptr++) {
00280 new_devname[nidx] = *nptr;
00281 }
00282 new_devname[nidx] = 0;
00283
00284
00285 if (*nptr++ == ':') {
00286
00287 parms.par_new = nptr;
00288
00289
00290 if (strcmp(new_devname, old_devname) == 0) {
00291
00292 if ((dev = NutDeviceLookup(old_devname)) == 0) {
00293 errno = ENOENT;
00294 } else {
00295 rc = (*dev->dev_ioctl) (dev, FS_RENAME, (void *) &parms);
00296 }
00297 }
00298 }
00299 }
00300 return rc;
00301 }
00302