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