Whamcloud - gitweb
This commit was generated by cvs2svn to compensate for changes in r46154,
[fs/lustre-release.git] / libsysio / tests / sysio_tests.c
1 #define _BSD_SOURCE
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <getopt.h>
7 #include <errno.h>
8 #include <ctype.h>
9 #include <sys/types.h>
10 #include <sys/stat.h>
11 #include <sys/statvfs.h>
12 #include <fcntl.h>
13 #include <sys/queue.h>
14 #include <unistd.h>
15 #include <dirent.h>
16 #include <sys/mount.h>
17
18 #include "xtio.h"
19 #include "mount.h"
20 #include "test.h"
21 #include "test_driver.h"
22
23 /*
24  * ###################################################
25  * # Test functions                                  #
26  * #  These functions are used to test libsysio.     #
27  * #  Eventually, there should be one of these for   #
28  * #  every function document in sysio.h             #
29  * ###################################################
30  */
31 int initilize_sysio()
32 {
33   char *wd;
34  
35   /* 
36    * Attempt to set the cwd by getting it out of the
37    * user's environment.  If that does not work, set
38    * it to /
39    */
40   wd = getenv("PWD");
41   if (wd == NULL) {
42     wd = malloc(5);
43     strcpy(wd, "/");
44   }
45   if (chdir(wd) != 0) {
46     DBG(5, sprintf(output, "%schdir: errno %d\n", output, errno));
47     my_perror(wd);
48     my_errno = errno;
49     last_ret_val = errno;
50     return SUCCESS;
51   }
52
53   DBG(3, sprintf(output, "Your current working directory is %s\n", wd));
54   last_ret_val = 0;
55   return SUCCESS;
56 }
57
58
59 int sysio_list(char *path)
60 {
61   int   fd;
62   size_t        n;
63   struct dirent *buf, *dp;
64   __off_t       base;
65   ssize_t       cc;
66   int numfiles = 0;
67
68   fd = open(path, O_RDONLY);
69   if (fd < 0) {
70     my_errno = errno;
71     last_ret_val = fd;
72     my_perror(path);
73     return SUCCESS;
74   }
75   
76   n = 16 * 1024;
77   buf = malloc(n);
78   if (!buf) {
79     my_perror(path);
80     cc = -1;
81     goto out;
82   }
83   base = 0;
84   DBG(5, sprintf(output, "About to call getdirentries\n"));
85   while ((cc = getdirentries(fd, (char *)buf, n, &base)) > 0) {
86     dp = buf;
87     while (cc > 0) {
88       DBG(4, fprintf(outfp, "\t%s: ino %#08x off %#08x type %#08x\n",
89                      dp->d_name,
90                      (unsigned int)dp->d_ino,
91                      (unsigned int)dp->d_off,
92                      (int )dp->d_type));
93       
94       sprintf(output, "%s\n", dp->d_name);
95       cc -= dp->d_reclen;
96       dp = (struct dirent *)((char *)dp + dp->d_reclen);
97       numfiles++;
98     }
99     printf("Out of inner loop\n");
100     if (!base)
101       break;
102   }
103
104  out:
105   if (cc < 0) {
106     DBG(2, sprintf(output, "cc barfed\n"));
107     my_perror(path);
108   }
109   
110   free(buf);
111   {
112     int oerrno = errno;
113     
114     if (close(fd) != 0) {
115       DBG(2,sprintf(output, "close barfed\n"));
116       my_perror(path);
117       if (cc < 0)
118         errno = oerrno;
119       else
120         cc = -1;
121     }
122   }
123
124   last_ret_val = numfiles;
125   my_errno = errno;
126
127   return SUCCESS;
128 }
129
130 int sysio_mount(char *from, char *to)
131 {
132   int   err;
133   char  *s;
134   char  *buf;
135   char  *cp;
136   char  *fstype, *source, *opts, *target;
137
138   err = 0;
139
140   /*
141    * Copy everything to a buffer we can modify.
142    */
143   s = buf = malloc(strlen(from) + 1);
144   if (!buf) {
145     my_perror(from);
146     last_ret_val = -1;
147     my_errno = errno;
148     return SUCCESS;
149   }
150   (void )strcpy(s, from);
151   
152   /*
153    * Eat leading white.
154    */
155    while (*s && *s == ' ' && *s == '\t')
156      s++;
157   /*
158    * Get fstype.
159    */
160    fstype = cp = s;
161    while (*cp && *cp != ':' && *cp != ' ' && *cp != '\t')
162      cp++;
163    if (fstype == cp || *cp != ':') {
164      DBG(1, sprintf(output, "%s: Missing FS type\n", from));
165      err = -1;
166      goto out;
167    }
168   *cp++ = '\0';
169
170   s = cp;
171   /*
172    * Eat leading white.
173    */
174    while (*s && *s == ' ' && *s == '\t')
175      s++;
176   /*
177    * Get source.
178    */
179    source = cp = s;
180    while (*cp && *cp != ' ' && *cp != '\t')
181      cp++;
182    if (source == cp) {
183      DBG(1, sprintf(output, "%s: Missing source\n", from));
184      err = -1;
185      goto out;
186    }
187    if (*cp)
188      *cp++ = '\0';
189
190    s = to;
191    /*
192     * Eat leading white.
193     */
194     while (*s && *s == ' ' && *s == '\t')
195       s++;
196    /*
197     * Get opts.
198     */
199     opts = cp = s;
200     while (*cp && *cp != ' ' && *cp != '\t')
201       cp++;
202     if (opts == cp) {
203       DBG(1,sprintf(output, "%s: Missing target\n", to));
204       err = -1;
205       goto out;
206     }
207     if (*cp)
208       *cp++ = '\0';
209
210     s = cp;
211     /*
212      * Eat leading white.
213      */
214      while (*s && *s == ' ' && *s == '\t')
215        s++;
216     /*
217      * Get target
218      */
219      target = cp = s;
220      while (*cp && *cp != ' ' && *cp != '\t')
221        cp++;
222      if (target == cp) {
223        target = opts;
224        opts = NULL;
225      }
226      if (*cp)
227        *cp++ = '\0';
228
229      err = mount(source, target, fstype, 0, opts);
230      if (err)
231        my_perror(from);
232
233 out:
234      free(buf);
235      last_ret_val = err;
236      my_errno = errno;
237      return SUCCESS;
238 }
239
240 int sysio_chdir(char *newdir) 
241 {
242
243   if (chdir(newdir) != 0) {
244     my_perror(newdir);
245     return -1;
246   }
247   /*  
248   buf = getcwd(NULL, 0);
249   if (!buf) {
250     my_perror(newdir);
251     last_ret_val = -1;
252     my_errno = errno;
253     return SUCCESS;
254   }
255   DBG(4, sprintf(output, "New dir is %s\n", buf));
256
257   free(buf);
258   */
259   return SUCCESS;
260 }
261
262 static mode_t get_mode(char *arg, int type, int start_mode);
263
264 #define SYMBOLIC 0
265 #define DEFINED  1
266 #define NUMERIC  2 
267 /*
268  * Change the permissions on a given file
269  *
270  * sysio_chmod <filename> <permissions>
271  *
272  */
273 int sysio_chmod(char *mode_arg, const char *path) 
274 {
275   int   err;
276   mode_t mode;
277   struct stat st;
278
279   /* Get the current mode */
280   err = stat(path, &st);
281
282   /* Is the new mode symbolic? */
283   if (isalpha(mode_arg[0])) {
284     /* Could be specifying defines */
285     if (mode_arg[0] == 'S')
286       mode = get_mode(mode_arg, DEFINED, st.st_mode);
287     else
288       mode = get_mode(mode_arg, SYMBOLIC, st.st_mode);
289   } else 
290     mode = get_mode(mode_arg, NUMERIC, st.st_mode);
291   DBG(3,sprintf(output, "Using a mode of %o and a file of %s\n", mode, path));
292
293   if (mode == 0) {
294     DBG(2,sprintf(output, "Invalid mode\n"));
295     return INVALID_ARGS;
296   }
297
298   last_ret_val = chmod(path, mode);
299   my_errno = errno;
300   return SUCCESS;
301   
302 }
303
304
305 #define USER_STATE 0 /* Specifies that the users are still being listed */
306 #define MODE_STATE_ADD 1 
307 #define MODE_STATE_REMOVE 2 
308         
309 #define READ    00444
310 #define WRITE   00222
311 #define EXECUTE 00111
312
313 #define OWNER  00700
314 #define GROUP  00070
315 #define OTHER  00007
316
317   
318 mode_t
319 get_mode(char *arg, int type, int start_mode) 
320 {
321   int i, j,digit, total;
322   char c;
323   int state = USER_STATE;
324   int len = strlen(arg);
325   unsigned int users = 0;
326   unsigned int modes = 0;
327
328
329   if (type == DEFINED) {
330     char curr_word[10];
331
332     total = digit = 0;
333     j = 0;
334     DBG(4, sprintf(output, "len is %d\n", len));
335     for (i=0; i < len; i++) {
336       if (arg[i] == '|') {
337         curr_word[j] = '\0';
338         DBG(3, sprintf(output, "Got mode word %s\n", curr_word));
339         digit = get_obj(curr_word);
340         if (digit < 0 ) {
341           DBG(2, sprintf(output, "Unable to understand mode arg %s\n",
342                          curr_word));
343           return -1;
344         } 
345         total |= digit;
346         j = 0;
347       } else 
348         curr_word[j++] = arg[i];
349     }
350     curr_word[j] = '\0';
351     DBG(3, sprintf(output, "Got mode word %s\n", curr_word));
352     digit = get_obj(curr_word);
353     if (digit < 0 ) {
354       DBG(3, sprintf(output, "Unable to understand mode arg %s\n",
355              curr_word));
356       return -1;
357     } 
358     total |= digit;
359     return total;
360   }
361       
362   if (type == SYMBOLIC) {
363     for (i=0; i < len; i++) {
364       c = arg[i];
365       if (state == USER_STATE) {
366         switch(c){
367         case 'u':
368           users |= OWNER;
369           break;
370         case 'g':
371           users |= GROUP;
372           break;
373         case 'o':
374           users |= OTHER;
375           break;
376         case 'a':
377           users |= (OWNER|GROUP|OTHER);
378           break;
379         case '+':
380           state = MODE_STATE_ADD;
381           break;
382         case '-':
383           state = MODE_STATE_REMOVE;
384           break;
385         default:
386           return 0;
387         }
388       } else {
389
390         switch(c){
391         case 'r':
392           modes |= READ;
393           break;
394         case 'w':
395           modes |= WRITE;
396           break;
397         case 'x':
398           modes |= EXECUTE;
399           break;
400         default:
401           return 0;
402         }
403       }
404     }
405
406     if (state == MODE_STATE_ADD) {
407       return (start_mode | (users & modes));
408     } else {
409       return (start_mode & ~(users & modes));
410     }
411
412   } else {
413     /* Digits should be octal digits, so should convert */
414     total = 0;
415     for (i=0; i < len; i++) {
416       c = arg[i];
417       digit = atoi(&c);
418       if (digit > 7)
419         return 0;
420       for (j=len-i-1; j >0; j--)
421         digit *= 8;
422       total += digit;
423     }
424     return total;
425   }
426  
427 }
428
429 /*
430  * Changes the ownership of the file.  The new_id
431  * is of the format owner:group.  Either the owner
432  * or the group may be omitted, but, in order to 
433  * change the group, the : must preced the group.
434  */
435 int sysio_chown(char *new_id, char *file)
436 {
437   char *owner = NULL;
438   char *group = NULL;
439   uid_t o_id=-1, g_id=-1;
440   int len, j, i=0;
441   int state = 0; /* Correspond to getting owner name */
442   
443   len = strlen(new_id);
444   for (i=0; i < len; i++) {
445
446     if (new_id[i] == ':') {
447       /* Group name */
448       if (!group) 
449                                 group = malloc(strlen(new_id) -i +2);
450       state = 1; /* Now getting group name */
451       j = 0;
452       if (owner)
453                                 owner[i] = '\0';
454     }
455                 
456     if (!state) {
457       /* Getting owner name */
458       if (!owner)
459                                 owner = malloc(strlen(new_id) +1 ); 
460       owner[i] = new_id[i];
461     } else {
462       /* Group name */
463       group[j] = new_id[i];
464       j++;
465     }
466   }
467   if (group)
468     group[i] = '\0';
469   else
470     owner[i] = '\0';
471
472   /* Are the owner and/or group symbolic or numeric? */
473   if (owner) {
474     if (isdigit(owner[0])) {
475       /* Numeric -- just convert */
476       o_id = (uid_t) atoi(owner);
477
478                 } else {
479       /* No longer support non-numeric ids */
480                         
481                         DBG(2, sprintf(output, "Error: non-numeric ids unsupported\n"));
482                         return INVALID_ARGS;
483     }
484   }
485
486
487
488   if (group) {
489     if (isdigit(group[0])) {
490       /* Numeric -- just convert */
491       g_id = (uid_t) atoi(group);
492                 } else {
493       /* Don't support group names either */
494                         DBG(2, sprintf(output, "Error: non-numeric ids unsupported\n"));
495                         return INVALID_ARGS;
496     }
497   }
498
499   /* Now issue the syscall */
500   DBG(4, sprintf(output, "Changing owner of file %s to %d (group %d)\n",
501                  file, o_id, g_id));
502  
503   last_ret_val = chown(file, o_id, g_id);
504   my_errno = errno;
505   return SUCCESS;
506 }
507
508 int sysio_open(char *path, int flags)
509 {
510   last_ret_val = open(path, flags);
511   my_errno = errno;
512   DBG(3, sprintf(output, "Returning with errno set to %s (ret val is %d)\n", 
513                  strerror(my_errno), (int)last_ret_val));
514   return SUCCESS;
515 }
516
517 int sysio_open3(char *path, int flags, char *mode_arg)
518 {
519   mode_t mode;
520
521   /* Is the new mode symbolic? */
522   if (isalpha(mode_arg[0])) {
523     /* Could be specifying defines */
524     if (mode_arg[0] == 'S')
525       mode = get_mode(mode_arg, DEFINED, 0);
526     else
527       mode = get_mode(mode_arg, SYMBOLIC, 0);
528   } else 
529     mode = get_mode(mode_arg, NUMERIC, 0);
530   
531   last_ret_val = open(path, flags, mode);
532   my_errno = errno;
533   
534   return SUCCESS;
535 }
536
537 int sysio_close(int fd)
538 {
539
540   last_ret_val = close(fd);
541   my_errno = errno;
542   return SUCCESS;
543 }
544
545 int sysio_fcntl(int fd, struct cmd_map* cmdptr, char *arg)
546 {
547   int fd_new, index, cmd, flag;
548   char *cmdname;
549   void *buf;
550
551   cmd = cmdptr->cmd;
552   cmdname = cmdptr->cmd_name;
553
554   switch(cmd) {
555   case F_DUPFD:
556     fd_new = get_obj(arg);
557     last_ret_val = fcntl(fd, F_DUPFD, fd_new);
558     my_errno = errno;
559     return SUCCESS;
560     break;
561
562   case F_GETFD:
563   case F_GETFL:
564   case F_GETOWN:
565     /* case F_GETSIG:
566        case F_GETLEASE: */
567
568     last_ret_val= fcntl(fd, cmd);
569     my_errno = errno;
570     return SUCCESS;
571     break;
572
573   case F_SETFD:    
574   case F_SETFL:
575   case F_SETOWN:
576     /*case F_SETSIG:
577     case F_SETLEASE:
578     case F_NOTIFY: */
579     flag = atoi(arg);
580     last_ret_val =  fcntl(fd, cmd, flag);
581     my_errno = errno;
582     return SUCCESS;
583     break;
584
585   case F_SETLK:
586   case F_SETLKW:
587   case F_GETLK:
588   
589      /* Get the buffer to hold the lock structure */
590      index = get_obj(arg);
591      if (index < 0) {
592        sprintf(output, "Unable to find buffer %s\n", arg+1);
593        return INVALID_VAR;
594      }
595
596      buf = buflist[index];
597      if (!buf) {
598        sprintf(output, "Buffer at index %d (mapped by %s) is null\n",
599               index, arg);
600        return INVALID_VAR;
601      }
602
603      last_ret_val = fcntl(fd, cmd, (struct flock *)buf);
604      my_errno = errno;
605     return SUCCESS;
606   default:
607     /* THis should be impossible */
608     return INVALID_ARGS;
609   }
610
611   return INVALID_ARGS;
612 }
613
614 void print_stat(struct stat *st)
615 {
616   DBG(3, sprintf(output, "%sstruct stat: \n", output));
617   DBG(3, sprintf(output, "%s  st_dev: %#16x\n", output, (unsigned int)st->st_dev));
618   DBG(3, sprintf(output, "%s  st_ino: %#16x\n", output, (unsigned int) st->st_ino));
619   DBG(3, sprintf(output, "%s  st_mode: %#16x\n", output, st->st_mode));
620   DBG(3, sprintf(output, "%s  st_nlink: %#16x\n", output, (int)st->st_nlink));
621   DBG(3, sprintf(output, "%s  st_uid: %#16x\n", output, st->st_uid));
622   DBG(3, sprintf(output, "%s  st_gid: %#16x\n", output, st->st_gid));
623   DBG(3, sprintf(output, "%s  st_rdev: %#16x\n", output, (int)st->st_rdev));
624   DBG(3, sprintf(output, "%s  st_size: %#16x\n", output, (int) st->st_size));
625   DBG(3, sprintf(output, "%s  st_blksize: %#16x\n", output, (int) st->st_blksize));
626   DBG(3, sprintf(output, "%s  st_blocks: %#16x\n", output, (int) st->st_blocks));
627   DBG(3, sprintf(output, "%s  st_atime: %#16x\n", output, (unsigned int) st->st_atime));
628   DBG(3, sprintf(output, "%s  st_mtime: %#16x\n", output, (unsigned int) st->st_mtime));
629   DBG(3, sprintf(output, "%s  st_ctime: %#16x", output, (unsigned int) st->st_ctime));
630 }
631
632 int sysio_fstat(int fd, void *buf)
633 {
634   int err;
635   struct stat *st = (struct stat *)buf;
636   err = fstat(fd, st); 
637   if (err < 0) {
638     my_perror("fstat");
639   }
640   my_errno = errno;
641   last_ret_val = err;
642   print_stat(st);
643
644   return SUCCESS;
645 }
646
647 int sysio_lstat(char *filename, void *buf)
648 {
649   int err;
650   struct stat *st = (struct stat *)buf;
651   err = lstat(filename, st); 
652   if (err < 0) {
653     my_perror("lstat");
654   }
655
656   my_errno = errno;
657   last_ret_val = err;
658   print_stat(st);
659   return SUCCESS;
660 }
661
662
663 int sysio_stat(char *filename, void *buf)
664 {
665   int err;
666   struct stat *st = (struct stat *)buf;
667
668   err = stat(filename, st); 
669   if (err < 0) {
670     my_perror("stat");
671   }
672
673   my_errno = errno;
674   last_ret_val = err;
675   print_stat(st);
676   return SUCCESS;
677 }
678
679
680 int sysio_getdirentries(int fd, char *buf, size_t nbytes, off_t *basep)
681 {
682   int err;
683   struct dirent *dp;
684
685   err = getdirentries(fd, buf, nbytes, basep); 
686   last_ret_val = err;
687  
688   DBG(4, sprintf(output, "%sRead %d bytes\n", output, err));
689
690   dp = (struct dirent *)buf;
691   while (err > 0) {
692       DBG(3, sprintf(output, "%s\t%s: ino %llu off %llu len %x type %c\n",
693                      output,
694                      dp->d_name,
695                      (unsigned long long )dp->d_ino,
696                      (unsigned long long )dp->d_off,
697                      dp->d_reclen,
698                     (char )dp->d_type));
699       err -= dp->d_reclen;
700       dp = (struct dirent *)((char *)dp + dp->d_reclen);
701   }
702
703   my_errno = errno;
704   return last_ret_val;
705 }
706
707
708 int sysio_mkdir(char *path, char *mode_arg) 
709 {
710   int   err;
711   mode_t mode;
712   struct stat st;
713
714   /* Is the new mode symbolic? */
715   if (isalpha(mode_arg[0])) {
716     /* Could be specifying defines */
717     if (mode_arg[0] == 'S')
718       mode = get_mode(mode_arg, DEFINED, st.st_mode);
719     else
720       mode = get_mode(mode_arg, SYMBOLIC, st.st_mode);
721   } else 
722     mode = get_mode(mode_arg, NUMERIC, st.st_mode);
723
724   DBG(3, sprintf(output, "Using a mode of %o and a file of %s\n", mode, path));
725
726   if (mode == 0) {
727     DBG(2, sprintf(output, "Invalid mode\n"));
728     return INVALID_ARGS;
729   }
730
731   err = mkdir(path, mode);
732   my_errno = errno;
733   last_ret_val = err;
734   return SUCCESS;
735   
736 }
737
738 int sysio_creat(char *path, char *mode_arg) 
739 {
740   mode_t mode;
741   int err;
742
743   /* Is the new mode symbolic? */
744   if (isalpha(mode_arg[0])) {
745     /* Could be specifying defines */
746     if (mode_arg[0] == 'S')
747       mode = get_mode(mode_arg, DEFINED, 0);
748     else
749       mode = get_mode(mode_arg, SYMBOLIC, 0);
750   } else 
751     mode = get_mode(mode_arg, NUMERIC, 0);
752
753   DBG(3, sprintf(output, "Using a mode of %o and a file of %s\n", mode, path));
754
755   if (mode == 0) {
756     DBG(2, sprintf(output, "Invalid mode\n"));
757     return INVALID_ARGS;
758   }
759
760   err = creat(path, mode);
761   my_errno = errno;
762   last_ret_val = err;
763   return SUCCESS;
764 }
765
766 void print_statvfs(struct statvfs *st)
767 {
768   DBG(3, sprintf(output, "%sstruct statvfs: \n", output));
769   DBG(3, sprintf(output, "%s  f_bsize: %x\n", output, (unsigned int) st->f_bsize));
770   DBG(3, sprintf(output, "%s  f_frsize: %x\n", output, (unsigned int) st->f_frsize));
771   DBG(3, sprintf(output, "%s  f_blocks: %x\n", output, (unsigned int) st->f_blocks));
772   DBG(3, sprintf(output, "%s  f_bfree: %x\n", output, (unsigned int) st->f_bfree));
773   DBG(3, sprintf(output, "%s  f_bavail: %x\n", output, (unsigned int) st->f_bavail));
774   DBG(3, sprintf(output, "%s  f_files: %x\n", output, (unsigned int) st->f_files));
775   DBG(3, sprintf(output, "%s  f_ffree: %x\n", output, (unsigned int) st->f_ffree));
776   DBG(3, sprintf(output, "%s  f_favail: %x\n", output, (unsigned int) st->f_favail));
777   DBG(3, sprintf(output, "%s  f_files: %x\n", output, (unsigned int) st->f_files));
778 #if (__GLIBC__  == 2 && __GLIBC_MINOR__ == 1)
779   DBG(3, sprintf(output, "%s  f_fsid: %x\n", output, (unsigned int) st->f_fsid.__val[1]));
780 #else
781  DBG(3, sprintf(output, "%s  f_fsid: %x\n", output, (unsigned int) st->f_fsid));
782 #endif
783   DBG(3, sprintf(output, "%s  f_flag: %x\n", output, (unsigned int) st->f_flag));
784   DBG(3, sprintf(output, "%s  f_fnamemax: %x\n", output, (unsigned int) st->f_namemax));
785 }
786
787
788 int sysio_statvfs(char *filename, void *buf)
789 {
790   int err;
791   struct statvfs *st = (struct statvfs *)buf;
792   
793   err = statvfs(filename, st); 
794   if ( err == -1) { 
795     my_perror("statvfs");
796   }
797
798   my_errno = errno;
799   last_ret_val = err;
800
801   print_statvfs(st);
802   return SUCCESS;
803 }
804
805 int sysio_fstatvfs(int fd, void *buf)
806 {
807   int err;
808   struct statvfs *st = (struct statvfs *)buf;
809
810   err = fstatvfs(fd, st);
811   if (err == -1) { 
812     my_perror("fstatvfs");
813   }
814
815   my_errno = errno;
816   last_ret_val = err;
817
818   print_statvfs(st);
819   return SUCCESS;
820 }
821
822 int sysio_umask(char *mode_arg)
823 {
824   mode_t mode;
825
826    /* Is the new mode symbolic? */
827   if (isalpha(mode_arg[0])) {
828     /* Could be specifying defines */
829     if (mode_arg[0] == 'S')
830       mode = get_mode(mode_arg, DEFINED, 0);
831     else
832       mode = get_mode(mode_arg, SYMBOLIC, 0);
833   } else 
834     mode = get_mode(mode_arg, NUMERIC, 0);
835
836   last_ret_val = umask(mode);
837   my_errno = errno;
838   return SUCCESS;
839 }
840
841 int sysio_mknod(char *path, char *mode_arg, dev_t dev)
842 {
843   int err;
844   int mode;
845
846   mode = get_obj(mode_arg);
847   
848   if (mode < 0) {
849     DBG(2,sprintf(output, "Cant get mode from %s\n", mode_arg));
850     fprintf(stderr, "Cant get mode from %s\n", mode_arg);
851     return INVALID_VAR;
852   }
853
854   err = mknod(path, (mode_t) mode, dev);
855   if (err < 0)
856     my_perror("mknod");
857
858   last_ret_val = err;
859   my_errno = errno;
860   return SUCCESS;
861 }