jrb@wdl1.UUCP (John R Blaker) (02/17/84)
/*==========================================================================* * == D I R E C T == * *==========================================================================* * John R Blaker -- Ford Aerospace & Communications Corporation -- Oct 1982 * *==========================================================================* * This file contains routines which put the disc directory into a more * * readily usable form. It also contains routines for accessing that new * * form. This file contains the following functions: * * makedir() Gets the directory off the disc and into memory * * findentry() Ginds an entry matching its argument and returns a * * pointer to it. * * The new form is a linked list of structures the diefinition of wich is in* * 'rt11.h'. * *==========================================================================* */ /* * Include files */ #include "rt11.h" /* Global definitions */ /* * makedir() * this function builds the in-memory directory referenced elsewhere * in the program. It uses rt11_to_a() tor translate the filename from * RADIX-50 to ASCII. The in-memory directory is implemented as a singly * linked list. The routine uses calloc() to allocate space for new * nodes. * The routine assumes that there is only one segment in the directory. */ makedir() { DIR_SEGMNT seg1; /* A segment of the disc directory */ DIR_SEGMENT *seg_ptr = &seg1; /* Pointer to that segment */ char filename[15]; /* String to hold filename */ int index; /* Loop index */ int i; /* Loop index */ int j; /* Loop index */ MEM_DIR *newnode; /* Pointer to newly allocated node */ unsigned cur_addr; /* Current address */ MEM_DIR *cur_node; /* Current node */ char *calloc(); /* Memory allocator */ char fname[15]; /* Name with embedded spaces removed */ trace("Making in-memory directory"); dir_header = NULL; getsegment(6, (char *)seg_ptr); cur_addr = (seg_ptr -> ds_header).dh_addr; for (index = 0; index < 72; index++) { if (((((seg_ptr -> ds_direct)[index]).de_status) & ST_EOSG) != 0) break; if (((((seg_ptr -> ds_direct)[index]).de_status) & ST_EMPT) != 0) continue; rt11_to_a(((seg_ptr -> ds_direct)[index]).de_fln1, ((seg_ptr -> ds_direct)[index]).de_fln2, ((seg_ptr -> ds_direct)[index]).de_type, filename); for (i = 0, j = 0; j < 15;) { /* Get rid of embedded spaces */ if (filename[j] == ' ') j++; else fname[i++] = filename[j++]; } /* for */ strcpy(filename, fname); trace(filename); newnode = (MEM_DIR *)calloc(1, sizeof(MEM_DIR)); strcpy(newnode -> md_name, filename); newnode -> md_addr = cur_addr; cur_addr += (((seg_ptr -> ds_direct)[index]).de_length); newnode -> md_size = ((seg_ptr -> ds_direct)[index]).de_length * BLOCKSIZE; newnode -> md_date = ((seg_ptr -> ds_direct)[index]).de_date; newnode -> md_next = NULL; if (dir_header == NULL) { dir_header = newnode; } else { cur_node = dir_header; while (cur_node -> md_next != NULL) cur_node = cur_node -> md_next; cur_node -> md_next = newnode; } /* if...else */ } /* for */ } /* makedir */ /* * findentry() * This does a linear search of the in-memory directory * for the given filename. If found, a pointer to it is * returned. If it isn't foundan error message is printed * and NULL is returned. */ MEM_DIR *findentry(name) char name[]; /* Filename to be found */ { MEM_DIR *current_entry; /* Current location in directory */ trace("Got to findentry()"); current_entry = dir_header; while (current_entry != NULL) { if (strcmp(current_entry -> md_name, name) == 0) return(current_entry); else current_entry = current_entry -> md_next; } /* while */ error("File not found"); return(NULL); } /* findentry */