~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Minix Cross Reference
Minix/fs/utility.c


  1 /* This file contains a few general purpose utility routines.
  2  *
  3  * The entry points into this file are
  4  *   clock_time:  ask the clock task for the real time
  5  *   copy:        copy a block of data
  6  *   fetch_name:  go get a path name from user space
  7  *   no_sys:      reject a system call that FS does not handle
  8  *   panic:       something awful has occurred;  MINIX cannot continue
  9  *   conv2:       do byte swapping on a 16-bit int
 10  *   conv4:       do byte swapping on a 32-bit long
 11  */
 12 
 13 #include "fs.h"
 14 #include <minix/com.h>
 15 #include <minix/boot.h>
 16 #include <unistd.h>
 17 #include "buf.h"
 18 #include "file.h"
 19 #include "fproc.h"
 20 #include "inode.h"
 21 #include "param.h"
 22 
 23 PRIVATE int panicking;          /* inhibits recursive panics during sync */
 24 PRIVATE message clock_mess;
 25 
 26 /*===========================================================================*
 27  *                              clock_time                                   *
 28  *===========================================================================*/
 29 PUBLIC time_t clock_time()
 30 {
 31 /* This routine returns the time in seconds since 1.1.1970.  MINIX is an
 32  * astrophysically naive system that assumes the earth rotates at a constant
 33  * rate and that such things as leap seconds do not exist.
 34  */
 35 
 36   register int k;
 37 
 38   clock_mess.m_type = GET_TIME;
 39   if ( (k = sendrec(CLOCK, &clock_mess)) != OK) panic("clock_time err", k);
 40 
 41   return( (time_t) clock_mess.NEW_TIME);
 42 }
 43 
 44 
 45 /*===========================================================================*
 46  *                              fetch_name                                   *
 47  *===========================================================================*/
 48 PUBLIC int fetch_name(path, len, flag)
 49 char *path;                     /* pointer to the path in user space */
 50 int len;                        /* path length, including 0 byte */
 51 int flag;                       /* M3 means path may be in message */
 52 {
 53 /* Go get path and put it in 'user_path'.
 54  * If 'flag' = M3 and 'len' <= M3_STRING, the path is present in 'message'.
 55  * If it is not, go copy it from user space.
 56  */
 57 
 58   register char *rpu, *rpm;
 59   int r;
 60 
 61   /* Check name length for validity. */
 62   if (len <= 0) {
 63         err_code = EINVAL;
 64         return(EGENERIC);
 65   }
 66 
 67   if (len > PATH_MAX) {
 68         err_code = ENAMETOOLONG;
 69         return(EGENERIC);
 70   }
 71 
 72   if (flag == M3 && len <= M3_STRING) {
 73         /* Just copy the path from the message to 'user_path'. */
 74         rpu = &user_path[0];
 75         rpm = pathname;         /* contained in input message */
 76         do { *rpu++ = *rpm++; } while (--len);
 77         r = OK;
 78   } else {
 79         /* String is not contained in the message.  Get it from user space. */
 80         r = sys_copy(who, D, (phys_bytes) path,
 81                 FS_PROC_NR, D, (phys_bytes) user_path, (phys_bytes) len);
 82   }
 83   return(r);
 84 }
 85 
 86 
 87 /*===========================================================================*
 88  *                              no_sys                                       *
 89  *===========================================================================*/
 90 PUBLIC int no_sys()
 91 {
 92 /* Somebody has used an illegal system call number */
 93 
 94   return(EINVAL);
 95 }
 96 
 97 
 98 /*===========================================================================*
 99  *                              panic                                        *
100  *===========================================================================*/
101 PUBLIC void panic(format, num)
102 char *format;                   /* format string */
103 int num;                        /* number to go with format string */
104 {
105 /* Something awful has happened.  Panics are caused when an internal
106  * inconsistency is detected, e.g., a programming error or illegal value of a
107  * defined constant.
108  */
109 
110   if (panicking) return;        /* do not panic during a sync */
111   panicking = TRUE;             /* prevent another panic during the sync */
112   printf("File system panic: %s ", format);
113   if (num != NO_NUM) printf("%d",num); 
114   printf("\n");
115   (void) do_sync();             /* flush everything to the disk */
116   sys_abort(RBT_PANIC);
117 }
118 
119 
120 /*===========================================================================*
121  *                              conv2                                        *
122  *===========================================================================*/
123 PUBLIC unsigned conv2(norm, w)
124 int norm;                       /* TRUE if no swap, FALSE for byte swap */
125 int w;                          /* promotion of 16-bit word to be swapped */
126 {
127 /* Possibly swap a 16-bit word between 8086 and 68000 byte order. */
128 
129   if (norm) return( (unsigned) w & 0xFFFF);
130   return( ((w&BYTE) << 8) | ( (w>>8) & BYTE));
131 }
132 
133 
134 /*===========================================================================*
135  *                              conv4                                        *
136  *===========================================================================*/
137 PUBLIC long conv4(norm, x)
138 int norm;                       /* TRUE if no swap, FALSE for byte swap */
139 long x;                         /* 32-bit long to be byte swapped */
140 {
141 /* Possibly swap a 32-bit long between 8086 and 68000 byte order. */
142 
143   unsigned lo, hi;
144   long l;
145   
146   if (norm) return(x);                  /* byte order was already ok */
147   lo = conv2(FALSE, (int) x & 0xFFFF);  /* low-order half, byte swapped */
148   hi = conv2(FALSE, (int) (x>>16) & 0xFFFF);    /* high-order half, swapped */
149   l = ( (long) lo <<16) | hi;
150   return(l);
151 }
152 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.