UbixOS V2  2.0
file.c
Go to the documentation of this file.
1 /*-
2  * Copyright (c) 2002-2018 The UbixOS Project.
3  * All rights reserved.
4  *
5  * This was developed by Christopher W. Olsen for the UbixOS Project.
6  *
7  * Redistribution and use in source and binary forms, with or without modification, are permitted
8  * provided that the following conditions are met:
9  *
10  * 1) Redistributions of source code must retain the above copyright notice, this list of
11  * conditions, the following disclaimer and the list of authors.
12  * 2) Redistributions in binary form must reproduce the above copyright notice, this list of
13  * conditions, the following disclaimer and the list of authors in the documentation and/or
14  * other materials provided with the distribution.
15  * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to
16  * endorse or promote products derived from this software without specific prior written
17  * permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
20  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
22  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include <ubixos/sched.h>
30 #include <vfs/vfs.h>
31 #include <ubixos/vitals.h>
32 #include <ubixos/kpanic.h>
33 #include <ubixos/spinlock.h>
34 #include <lib/kmalloc.h>
35 #include <string.h>
36 #include <vmm/paging.h>
37 #include <lib/kprintf.h>
38 #include <assert.h>
39 #include <sys/descrip.h>
40 
41 static struct spinLock fdTable_lock = SPIN_LOCK_INITIALIZER;
42 
44 
46 
47 int sys_fwrite(struct thread *td, struct sys_fwrite_args *uap) {
48  char *t = uap->buf;
49 
50  if (uap->fd == 0x0)
51  tty_print((char*) uap->buf, _current->term);
52  else {
53 #ifdef DEBUG_VFS
54  kprintf("uap->size: %i, FD: [0x%X], BUF: [0x%X][%c]\n", uap->nbytes, uap->fd, uap->buf, t[0]);
55 #endif
56  fwrite(uap->buf, uap->nbytes, 1, uap->fd->fd);
57  }
58 
59  td->td_retval[0] = 0x0;
60 
61  return (0);
62 }
63 
64 /* USER */
65 
66 void sysFwrite(char *ptr, int size, userFileDescriptor *userFd) {
67  if (userFd == 0x0) {
68  tty_print(ptr, _current->term);
69  }
70  else {
71  fwrite(ptr, size, 1, userFd->fd);
72  }
73  return;
74 }
75 
76 int sys_fgetc(struct thread *td, struct sys_fgetc_args *args) {
77  char c;
78 
79  if (args->FILE->fd == 0x0) {
80 
81  while (1) {
82 
83  if (_current->term == tty_foreground) {
84  c = getchar();
85 
86  if (c != 0x0) {
87  td->td_retval[0] = c;
88  return (0);
89  }
90 
91  sched_yield();
92 
93  }
94  else {
95  sched_yield();
96  }
97  /*
98  else {
99  kprintf("Waking Task: %i\n",tty_foreground->owner);
100  sched_setStatus(tty_foreground->owner,READY);
101  kprintf("Sleeping Task: %i\n",_current->id);
102  sched_setStatus(_current->id,WAIT);
103  sched_yield();
104  }
105  */
106  }
107  }
108  else {
109  c = fgetc(args->FILE->fd);
110  td->td_retval[0] = c;
111  return (0);
112  }
113 }
114 
115 void sysRmDir() {
116  return;
117 }
118 
119 int sys_fseek(struct thread *td, struct sys_fseek_args *args) {
120  kprintf("offset: %ld, whence: 0x%X", args->offset, args->whence);
121 
122  // TODO : coredump?
123  if (args->FILE == NULL) {
124  td->td_retval[0] = -1;
125  return (-1);
126  }
127 
128  if (args->FILE->fd == NULL) {
129  td->td_retval[0] = -1;
130  return (-1);
131  }
132 
133  switch (args->whence) {
134  case 0:
135  args->FILE->fd->offset = args->offset + args->whence;
136  break;
137  case 1:
138  args->FILE->fd->offset += args->offset;
139  break;
140  default:
141  kprintf("seek-whence: %i", args->whence);
142  break;
143  }
144 
145  td->td_retval[0] = args->FILE->fd->offset & 0xFFFFFFFF;
146  return (0);
147 }
148 
149 int sys_lseek(struct thread *td, struct sys_lseek_args *args) {
150  int error = 0;
151  struct file *fdd = 0x0;
152  fileDescriptor_t *fd = 0x0;
153 
154  getfd(td, &fdd, args->fd);
155 
156  fd = fdd->fd;
157 
158  if (fdd == 0 || fdd->fd == 0x0) {
159  error = -1;
160  kprintf("ERROR!");
161  }
162 
163  kprintf("loffset(%i): %i:%i, whence: 0x%X", sizeof(off_t), args->offset >> 32, args->offset & 0xFFFFFF, args->whence);
164 
165  switch (args->whence) {
166  case SEEK_SET:
167  fd->offset = args->offset;
168  td->td_retval[0] = fd->offset & 0xFFFFFFFF;
169  td->td_retval[1] = fd->offset >> 32;
170  break;
171  case SEEK_CUR:
172  fd->offset += args->offset;
173  td->td_retval[0] = fd->offset & 0xFFFFFFFF;
174  td->td_retval[1] = fd->offset >> 32;
175  break;
176  default:
177  kprintf("seek-whence: %i", args->whence);
178  break;
179  }
180 
181  kprintf("loff: %ld", fd->offset);
182 
183  return (error);
184 }
185 
186 int sys_chdir(struct thread *td, struct sys_chdir_args *args) {
187  if (strstr(args->path, ":") == 0x0) {
188  sprintf(_current->oInfo.cwd, "%s%s", _current->oInfo.cwd, args->path);
189  }
190  else {
191  sprintf(_current->oInfo.cwd, args->path);
192  }
193  td->td_retval[0] = 0;
194  return (0);
195 }
196 
197 int sys_fchdir(struct thread *td, struct sys_fchdir_args *args) {
198  int error = 0;
199  struct file *fdd = 0x0;
200  fileDescriptor_t *fd = 0x0;
201 
202  getfd(td, &fdd, args->fd);
203 
204  fd = fdd->fd;
205 
206  if (fdd == 0 || fdd->fd == 0x0) {
207  error = -1;
208  }
209  else {
210  if (strstr(fd->fileName, ":") == 0x0) {
212  }
213  else {
215  }
216  }
217  return (error);
218 }
219 
220 int sys_rename(struct thread *td, struct sys_rename_args *args) {
221  td->td_retval[0] = 0;
222  return (0);
223 }
224 
225 int sysUnlink(const char *path, int *retVal) {
226  *retVal = 0;
227  return (*retVal);
228 }
229 
230 /************************************************************************
231 
232  Function: void sysFopen();
233  Description: Opens A File Descriptor For A User Task
234  Notes:
235 
236  ************************************************************************/
237 //void sysFopen(const char *file,char *flags,userFileDescriptor *userFd) {
238 int sys_fopen(struct thread *td, struct sys_fopen_args *args) {
239  kprintf("sys_fopen");
240  if (args->FILE == NULL) {
241  kprintf("Error: userFd == NULL, File: %s, Line: %i\n", __FILE__, __LINE__);
242  return (-1);
243  }
244 
245  args->FILE->fd = fopen(args->path, args->mode);
246  if (args->FILE->fd != 0x0) {
247  args->FILE->fdSize = args->FILE->fd->size;
248  }
249  /* Return */
250  return (0);
251 }
252 
253 /************************************************************************
254 
255  Function: void sysFread();
256  Description: Reads SIZE Bytes From The userFd Into DATA
257  Notes:
258 
259  ************************************************************************/
260 int sys_fread(struct thread *td, struct sys_fread_args *args) {
261 
262  /* TODO : coredump? */
263  if (args->FILE == NULL)
264  return (-1);
265 
266  if (args->FILE->fd == NULL)
267  return (-1);
268 
269  td->td_retval[0] = fread(args->ptr, args->size, args->nmemb, args->FILE->fd);
270  return (0);
271 }
272 
273 /************************************************************************
274 
275  Function: void sysFclse();
276  Description: Closes A File Descriptor For A User Task
277  Notes:
278 
279  ************************************************************************/
280 int sys_fclose(struct thread *td, struct sys_fclose_args *args) {
281  if (args->FILE == NULL) {
282  return (-1);
283  }
284  if (args->FILE == NULL) {
285  return (-1);
286  }
287 
288  /* Return */
289  return (fclose(args->FILE->fd));
290 }
291 
292 /* KERNEL */
293 
294 size_t fread(void *ptr, size_t size, size_t nmemb, fileDescriptor_t *fd) {
295  size_t i = 0x0;
296 
297  if (fd == 0x0)
298  return (0x0);
299 
300  if (nmemb == 0x0)
301  nmemb = 1; //Temp Fix
302 
303  assert(fd);
304  assert(fd->mp);
305  assert(fd->mp->fs);
306 
307  i = fd->mp->fs->vfsRead(fd, ptr, fd->offset, size * nmemb);
308 
309  //fd->offset += size * nmemb;
310 
311  return (i);
312 }
313 
314 size_t fwrite(void *ptr, int size, int nmemb, fileDescriptor_t *fd) {
315  int res = 0x0;
316  /*
317  kprintf("fd[0x%X]\m", fd);
318  kprintf("fd->mp[0x%X]\m", fd->mp);
319  kprintf("fd->mp->fs[0x%X]\m", fd->mp->fs);
320  */
321 
322  if (fd != 0x0) {
323  res = fd->mp->fs->vfsWrite(fd, ptr, fd->offset, size * nmemb);
324  fd->offset += size * nmemb;
325  }
326  return (res);
327 }
328 
329 int fseek(fileDescriptor_t *tmpFd, long offset, int whence) {
330  tmpFd->offset = offset + whence;
331  return (tmpFd->offset);
332 }
333 
334 /************************************************************************
335 
336  Function: int feof(fileDescriptor_t *fd)
337  Description: Check A File Descriptor For EOF And Return Result
338  Notes:
339 
340  ************************************************************************/
341 int feof(fileDescriptor_t *fd) {
342  if (fd->status == fdEof) {
343  return (-1);
344  }
345  return (0);
346 }
347 
348 /************************************************************************
349 
350  Function: int fputc(int ch,fileDescriptor_t *fd)
351  Description: This Will Write Character To FD
352  Notes:
353 
354  ************************************************************************/
355 int fputc(int ch, fileDescriptor_t *fd) {
356  if (fd != 0x0) {
357  ch = fd->mp->fs->vfsWrite(fd, (char*) ch, fd->offset, 1);
358  fd->offset++;
359  return (ch);
360  }
361  /* Return NULL If FD Is Not Found */
362  return (0x0);
363 }
364 
365 /************************************************************************
366 
367  Function: int fgetc(fileDescriptor_T *fd)
368  Description: This Will Return The Next Character In A FD Stream
369  Notes:
370 
371  ************************************************************************/
372 int fgetc(fileDescriptor_t *fd) {
373  int ch = 0x0;
374  /* If Found Return Next Char */
375  if (fd != 0x0) {
376  fd->mp->fs->vfsRead(fd, (char*) &ch, fd->offset, 1);
377  fd->offset++;
378  return (ch);
379  }
380 
381  /* Return NULL If FD Is Not Found */
382  return (0x0);
383 }
384 
385 /************************************************************************
386 
387  Function: fileDescriptor_t *fopen(const char *file,cont char *flags)
388  Description: This Will Open A File And Return A File Descriptor
389  Notes:
390 
391  08/05/02 - Just Started A Rewrite Of This Function Should Work Out Well
392 
393  ************************************************************************/
394 
395 fileDescriptor_t* fopen(const char *file, const char *flags) {
396 
397  int i = 0x0;
398  char *path = 0x0;
399  char *mountPoint = 0x0;
400  char fileName[1024];
401  fileDescriptor_t *tmpFd = 0x0;
402 
403  /* Allocate Memory For File Descriptor */
404  if ((tmpFd = (fileDescriptor_t*) kmalloc(sizeof(fileDescriptor_t))) == 0x0) {
405  kprintf("Error: tmpFd == NULL, File: %s, Line: %i\n", __FILE__, __LINE__);
406  return (NULL);
407  }
408 
409  memset(tmpFd, 0x0, sizeof(fileDescriptor_t));
410 
411  path = file;
412 
413  /* Determine if path is relative or absolute */
414  if (path[0] == "." && path[1] == '\0')
415  strcpy(fileName, _current->oInfo.cwd);
416  else
417  strcpy(fileName, file);
418 
419  path = 0x0;
420 
421  if (strstr(fileName, ":")) {
422  mountPoint = (char*) strtok((char*) &fileName, ":");
423  path = strtok(NULL, "\n");
424  }
425  else {
426  path = fileName;
427  }
428 
429  if (path[0] == '/')
430  strcpy(tmpFd->fileName, path);
431  else
432  sprintf(tmpFd->fileName, "/%s", path);
433 
434  /* Find our mount point or set default to sys */
435  if (mountPoint == 0x0) {
436  tmpFd->mp = vfs_findMount("sys");
437  }
438  else {
439  tmpFd->mp = vfs_findMount(mountPoint);
440  }
441 
442  if (tmpFd->mp == 0x0) {
443  kprintf("Mount Point Bad\n");
444  return (0x0);
445  }
446 
447  /* This Will Set Up The Descriptor Modes */
448  tmpFd->mode = 0;
449  for (i = 0; '\0' != flags[i]; i++) {
450  switch (flags[i]) {
451  case 'w':
452  case 'W':
453  tmpFd->mode |= fileWrite;
454  break;
455  case 'r':
456  case 'R':
457  tmpFd->mode |= fileRead;
458  break;
459  case 'b':
460  case 'B':
461  tmpFd->mode |= fileBinary;
462  break;
463  case 'a':
464  case 'A':
465  tmpFd->mode |= fileAppend;
466  break;
467  default:
468  kprintf("Invalid mode '%c' for fopen\n", flags[i]);
469  break;
470  }
471  }
472 
473  /* Search For The File */
474  if (tmpFd->mp->fs->vfsOpenFile(tmpFd->fileName, tmpFd) == 0x1) {
475  /* If The File Is Found Then Set Up The Descriptor */
476 
477  /* in order to save resources we will allocate the buffer later when it is needed */
478 
479  tmpFd->buffer = (char*) kmalloc(4096);
480 
481  if (tmpFd->buffer == 0x0) {
482  kfree(tmpFd);
483  kprintf("Error: tmpFd->buffer == NULL, File: %s, Line: %i\n", __FILE__, __LINE__);
484  spinUnlock(&fdTable_lock);
485  return (0x0);
486  }
487 
488  /* Set Its Status To Open */
489  tmpFd->status = fdOpen;
490 
491  /* Initial File Offset Is Zero */
492  tmpFd->offset = 0;
493  tmpFd->prev = 0x0;
494 
495  /* we do not want to be in a spinlock longer than we need to, so
496  it has been moved to here. */
497  spinLock(&fdTable_lock);
498 
499  /* Increment Number Of Open Files */
501 
502  tmpFd->next = fdTable;
503 
504  if (fdTable != 0x0)
505  fdTable->prev = tmpFd;
506 
507  fdTable = tmpFd;
508 
509  spinUnlock(&fdTable_lock);
510 
511  /* Return The FD */
512  return (tmpFd);
513  }
514  else {
515  //kprintf("Freeing");
516  kfree(tmpFd->buffer);
517  kfree(tmpFd);
518  spinUnlock(&fdTable_lock);
519  //MrOlsen (2016-01-13) NOTE: We don't need this right now kprintf("File Not Found? %s\n",file);
520  return (0x0);
521  }
522 
523  /* Return NULL */
524  return (0x0);
525 }
526 
527 /************************************************************************
528 
529  Function: int fclose(fileDescriptor_t *fd);
530  Description: This Will Close And Free A File Descriptor
531  Notes:
532 
533  ************************************************************************/
534 int fclose(fileDescriptor_t *fd) {
535  fileDescriptor_t *tmpFd = 0x0;
536 
537  if (fd == 0)
538  return (0x0);
539 
540  spinLock(&fdTable_lock);
541 
542  kprintf("[%s:%i]", __FILE__, __LINE__);
543 
544  for (tmpFd = fdTable; tmpFd != 0x0; tmpFd = tmpFd->next) {
545  if (tmpFd == fd) {
546  kprintf("DUP: [%i:0x%X]", fd->dup, fd);
547  if (fd->dup > 0)
548  fd->dup--;
549  else {
550  fd->dup = -2;
551  if (fd->res != 0x0)
552  fl_fclose(fd->res);
553 
554  if (tmpFd->prev)
555  tmpFd->prev->next = tmpFd->next;
556  if (tmpFd->next)
557  tmpFd->next->prev = tmpFd->prev;
558 
559  if (tmpFd == fdTable)
560  fdTable = tmpFd->next;
561 
563  spinUnlock(&fdTable_lock);
564  if (tmpFd->buffer != NULL)
565  kfree(tmpFd->buffer);
566  kfree(tmpFd);
567  return (0x0);
568  }
569  }
570  }
571 
572  spinUnlock(&fdTable_lock);
573  return (0x1);
574 }
575 
576 /* UBU */
577 
578 /************************************************************************
579 
580  Function: void sysMkDir(const char *path)
581  Description: This Will Create A New Directory
582  Notes:
583 
584  ************************************************************************/
585 void sysMkDir(const char *path) {
586  fileDescriptor_t *tmpFD = 0x0;
587  char tmpDir[1024];
588  char rootPath[256];
589  char *dir = 0x0; //UBU*mountPoint = 0x0;
590  char *tmp = 0x0;
591  rootPath[0] = '\0';
592  dir = (char*) path;
593 
594  if (strstr(path, ":") == 0x0) {
595  sprintf(tmpDir, "%s%s", _current->oInfo.cwd, path);
596  dir = (char*) &tmpDir;
597  }
598  while (strstr(dir, "/")) {
599  if (rootPath[0] == 0x0)
600  sprintf(rootPath, "%s/", strtok(dir, "/"));
601  else
602  sprintf(rootPath, "%s%s/", rootPath, strtok(dir, "/"));
603  tmp = strtok(NULL, "\n");
604  dir = tmp;
605  }
606 
607  //kprintf("rootPath: [%s]\n",rootPath);
608  tmpFD = fopen(rootPath, "rb");
609 
610  if (tmpFD->mp == 0x0) {
611  kprintf("Invalid Mount Point\n");
612  }
613  tmpFD->mp->fs->vfsMakeDir(dir, tmpFD);
614 
615  fclose(tmpFD);
616 
617  return;
618 }
619 
620 /************************************************************************
621 
622  Function: int unlink(const char *node)
623  Description: This will unlink a file
624  Notes:
625 
626  ************************************************************************/
627 
628 int unlink(const char *node) {
629  char *path = 0x0, *mountPoint = 0x0;
630  struct vfs_mountPoint *mp = 0x0;
631 
632  path = (char*) strtok((char*) node, "@");
633  mountPoint = strtok(NULL, "\n");
634  if (mountPoint == 0x0) {
635  mp = vfs_findMount("sys"); /* _current->oInfo.container; */
636  }
637  else {
639  }
640  if (mp == 0x0) {
641  //kpanic("Mount Point Bad");
642  return (0x0);
643  }
644  mp->fs->vfsUnlink(path, mp);
645  return (0x0);
646 }
strtok
char * strtok(char *str, const char *sep)
Definition: strtok.c:76
fileDescriptor::buffer
char * buffer
Definition: file.h:74
fileDescriptor::dup
int dup
Definition: file.h:83
sys_fclose
int sys_fclose(struct thread *td, struct sys_fclose_args *args)
Definition: file.c:277
file
fileDescriptor * file
Definition: tcpdump.c:45
sys_fseek_args::offset
off_t offset
Definition: sysproto_posix.h:210
spinlock.h
fl_fclose
void fl_fclose(void *f)
Definition: fat_filelib.c:856
fputc
int fputc(int ch, fileDescriptor_t *fd)
Definition: file.c:350
vfs_findMount
struct vfs_mountPoint * vfs_findMount(char *mountPoint)
Definition: mount.c:128
strcpy
char * strcpy(char *, const char *)
sys_fseek_args::FILE
userFileDescriptor * FILE
Definition: sysproto_posix.h:207
unlink
int unlink(const char *node)
Definition: file.c:618
userFileDescriptorStruct::fdSize
uint32_t fdSize
Definition: file.h:88
fopen
fileDescriptor_t * fopen(const char *file, const char *flags)
Definition: file.c:388
vfs.h
fileDescriptor::res
void * res
Definition: file.h:82
userFileDescriptorStruct
Definition: file.h:86
string.h
fileDescriptor::offset
off_t offset
Definition: file.h:69
fileDescriptor::mode
uint16_t mode
Definition: file.h:68
sysUnlink
int sysUnlink(const char *path, int *retVal)
Definition: file.c:225
fileBinary
#define fileBinary
Definition: vfs.h:51
sys_fgetc
int sys_fgetc(struct thread *td, struct sys_fgetc_args *args)
Definition: file.c:76
fileDescriptor
Definition: file.h:62
userFileDescriptorStruct::fd
struct fileDescriptor * fd
Definition: file.h:87
fread
size_t fread(void *ptr, size_t size, size_t nmemb, fileDescriptor_t *fd)
Definition: file.c:291
file
Definition: descrip.h:67
kfree
void kfree(void *baseAddr)
Definition: kmalloc.c:342
sys_fopen
int sys_fopen(struct thread *td, struct sys_fopen_args *args)
Definition: file.c:237
thread
Definition: thread.h:40
assert
#define assert(e)
Definition: assert.h:64
assert.h
tty_print
int tty_print(char *, tty_term *)
Definition: tty.c:115
spinUnlock
void spinUnlock(spinLock_t *lock)
Definition: spinlock.c:36
feof
int feof(fileDescriptor_t *fd)
Definition: file.c:337
fwrite
size_t fwrite(void *ptr, int size, int nmemb, fileDescriptor_t *fd)
Definition: file.c:311
vitalsStruct::openFiles
uint32_t openFiles
Definition: vitals.h:41
sys_fseek_args::whence
int whence
Definition: sysproto_posix.h:213
sys_fclose_args::FILE
userFileDescriptor * FILE
Definition: sysproto_posix.h:195
fileSystem::vfsWrite
int(* vfsWrite)(void *, char *, long, long)
Definition: vfs.h:64
sys_rename_args
Definition: sysproto_posix.h:719
SPIN_LOCK_INITIALIZER
#define SPIN_LOCK_INITIALIZER
Definition: spinlock.h:36
sys_fopen_args::FILE
userFileDescriptor * FILE
Definition: sysproto_posix.h:174
sys_fwrite_args
Definition: file.h:97
sys_chdir_args
Definition: sysproto_posix.h:126
sched.h
sys_lseek_args::offset
off_t offset
Definition: sysproto_posix.h:222
fileAppend
#define fileAppend
Definition: vfs.h:52
sysMkDir
void sysMkDir(const char *path)
Definition: file.c:576
sys_fwrite_args::buf
void * buf
Definition: file.h:98
fdTable
fileDescriptor_t * fdTable
Definition: file.c:43
sys_lseek_args::fd
int fd
Definition: sysproto_posix.h:219
fileDescriptor::mp
struct vfs_mountPoint * mp
Definition: file.h:65
sprintf
int sprintf(char *buf, const char *fmt,...)
Definition: kprintf.c:278
spinLock
void spinLock(spinLock_t *lock)
Definition: spinlock.c:55
vfs_mountPoint
Definition: mount.h:66
kpanic.h
sys_chdir_args::path
char * path
Definition: sysproto_posix.h:128
file::fd
fileDescriptor_t * fd
Definition: descrip.h:71
sys_fread_args::size
long size
Definition: sysproto_posix.h:183
fileSystem::vfsMakeDir
int(* vfsMakeDir)(char *, void *)
Definition: vfs.h:67
sys_fwrite_args::nbytes
size_t nbytes
Definition: file.h:99
sys_fwrite
int sys_fwrite(struct thread *td, struct sys_fwrite_args *uap)
Definition: file.c:47
thread::td_retval
int td_retval[2]
Definition: thread.h:41
systemVitals
vitalsNode * systemVitals
Definition: vitals.c:35
sys_fclose_args
Definition: sysproto_posix.h:193
fclose
int fclose(fileDescriptor_t *fd)
Definition: file.c:526
kprintf.h
taskStruct::term
tty_term * term
Definition: sched.h:77
sys_fchdir
int sys_fchdir(struct thread *td, struct sys_fchdir_args *args)
Definition: file.c:197
sysFwrite
void sysFwrite(char *ptr, int size, userFileDescriptor *userFd)
Definition: file.c:66
vitals.h
fileSystem::vfsRead
int(* vfsRead)(void *, char *, long, long)
Definition: vfs.h:63
sys_fchdir_args::fd
int fd
Definition: sysproto_posix.h:622
fdOpen
#define fdOpen
Definition: vfs.h:45
sys_fwrite_args::fd
userFileDescriptor * fd
Definition: file.h:101
vfs_mountPoint::mountPoint
char mountPoint[1024]
Definition: mount.h:74
getfd
int getfd(struct thread *td, struct file **fp, int fd)
get pointer to file fd in specified thread
Definition: descrip.c:214
vfs_mountPoint::fs
struct fileSystem * fs
Definition: mount.h:69
sys_fread_args::nmemb
long nmemb
Definition: sysproto_posix.h:186
paging.h
sys_lseek_args
Definition: sysproto_posix.h:217
sys_fseek
int sys_fseek(struct thread *td, struct sys_fseek_args *args)
Definition: file.c:119
fileWrite
#define fileWrite
Definition: vfs.h:50
sys_fread
int sys_fread(struct thread *td, struct sys_fread_args *args)
Definition: file.c:258
sys_fseek_args
Definition: sysproto_posix.h:205
_current
kTask_t * _current
Definition: sched.c:50
fileDescriptor::fileName
char fileName[512]
Definition: file.h:73
sys_chdir
int sys_chdir(struct thread *td, struct sys_chdir_args *args)
Definition: file.c:186
sys_fread_args::FILE
userFileDescriptor * FILE
Definition: sysproto_posix.h:189
tty_foreground
tty_term * tty_foreground
Definition: tty.c:38
sys_fgetc_args::FILE
userFileDescriptor * FILE
Definition: sysproto_posix.h:201
SEEK_CUR
#define SEEK_CUR
Definition: fat_filelib.h:12
kmalloc
void * kmalloc(uInt32 len)
Definition: kmalloc.c:241
spinLock
Definition: spinlock.h:41
descrip.h
sys_fopen_args::path
char * path
Definition: sysproto_posix.h:168
memset
void * memset(void *dst, int c, size_t length)
sys_fopen_args
Definition: sysproto_posix.h:166
sys_fread_args::ptr
void * ptr
Definition: sysproto_posix.h:180
sys_fopen_args::mode
char * mode
Definition: sysproto_posix.h:171
fileRead
#define fileRead
Definition: vfs.h:49
off_t
__int64_t off_t
Definition: types.h:119
fgetc
int fgetc(fileDescriptor_t *fd)
Definition: file.c:366
sys_fread_args
Definition: sysproto_posix.h:178
sys_lseek_args::whence
int whence
Definition: sysproto_posix.h:225
sys_rename
int sys_rename(struct thread *td, struct sys_rename_args *args)
Definition: file.c:220
fdEof
#define fdEof
Definition: vfs.h:47
fileDescriptor::status
uint16_t status
Definition: file.h:67
kprintf
int kprintf(const char *,...)
Definition: kprintf.c:259
sys_lseek
int sys_lseek(struct thread *td, struct sys_lseek_args *args)
Definition: file.c:149
getchar
int getchar()
Definition: atkbd.c:346
sys_fgetc_args
Definition: sysproto_posix.h:199
sysRmDir
void sysRmDir()
Definition: file.c:115
fileDescriptor::size
uint32_t size
Definition: file.h:70
vfs_fileTable
fileDescriptor_t * vfs_fileTable
Definition: file.c:45
SEEK_SET
#define SEEK_SET
Definition: fat_filelib.h:20
strstr
char * strstr(const char *s, char *find)
sys_fchdir_args
Definition: sysproto_posix.h:620
fileSystem::vfsUnlink
int(* vfsUnlink)(char *, void *)
Definition: vfs.h:66
kmalloc.h
taskStruct::oInfo
struct osInfo oInfo
Definition: sched.h:69
osInfo::cwd
char cwd[1024]
Definition: sched.h:58
fileDescriptor::prev
struct fileDescriptor * prev
Definition: file.h:63
fileSystem::vfsOpenFile
int(* vfsOpenFile)(void *, void *)
Definition: vfs.h:65
fileDescriptor::next
struct fileDescriptor * next
Definition: file.h:64
sched_yield
void sched_yield()
Definition: sched.c:244
fseek
int fseek(fileDescriptor_t *tmpFd, long offset, int whence)
Definition: file.c:326
NULL
#define NULL
Definition: fat_string.h:17