#endif
*/
+#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifndef S_IREAD
unsigned int tnum = 0;
char *tstrtab;
unsigned int tssiz = 0;
-char *malloc(), *realloc(), *strcpy(), *strncpy();
long time();
unsigned int tabsz, strtabsz;
#else
#define MEMBER struct ar_hdr
-#define NIL_PTR ((char *) 0)
-#define NIL_MEM ((MEMBER *) 0)
-#define NIL_LONG ((long *) 0)
-
#define IO_SIZE (10 * 1024)
#define equal(str1, str2) (!strncmp((str1), (str2), 14))
char *path;
{
register char *ptr = path;
- register char *last = NIL_PTR;
+ register char *last = NULL;
while (*ptr != '\0') {
if (*ptr == '/')
last = ptr;
ptr++;
}
- if (last == NIL_PTR)
+ if (last == NULL)
return path;
if (*(last + 1) == '\0') {
*last = '\0';
again:
if (rd_arhdr(ar_fd, &member) == 0)
- return NIL_MEM;
+ return NULL;
if (member.ar_size < 0) {
error(TRUE, "archive has member with negative size\n");
}
#endif
)
temp_fd = open_archive(temp_arch, CREATE);
- while ((member = get_member()) != NIL_MEM) {
+ while ((member = get_member()) != NULL) {
if (argc > 3) {
for (i = 3; i < argc; i++) {
if (equal(basename(argv[i]), member->ar_name))
#define DIR 0x2E
#define DIR_SIZE (sizeof (struct dir_entry))
#define SUB_DIR 0x10
-#define NIL_DIR ((DIRECTORY *) 0)
#define LAST_CLUSTER12 0xFFF
#define LAST_CLUSTER 0xFFFF
#define TRUE 1
#define FALSE 0
-#define NIL_PTR ((char *) 0)
#define DOS_TIME 315532800L /* 1970 - 1980 */
#define LABEL 4
#define ENTRY 5
#define find_entry(d, e, p) directory(d, e, FIND, p)
-#define list_dir(d, e, f) (void) directory(d, e, f, NIL_PTR)
-#define label() directory(root, root_entries, LABEL, NIL_PTR)
-#define new_entry(d, e) directory(d, e, ENTRY, NIL_PTR)
+#define list_dir(d, e, f) (void) directory(d, e, f, NULL)
+#define label() directory(root, root_entries, LABEL, NULL)
+#define new_entry(d, e) directory(d, e, ENTRY, NULL)
#define is_dir(d) ((d)->d_attribute & SUB_DIR)
if (dos_dir && Lflag) {
entry = label();
printf ("Volume in drive %c ", dev_nr);
- if (entry == NIL_DIR)
+ if (entry == NULL)
printf("has no label.\n\n");
else
printf ("is %.11s\n\n", entry->d_name);
}
- if (argv[idx] == NIL_PTR) {
+ if (argv[idx] == NULL) {
if (!dos_dir) usage(argv[0]);
if (Lflag) printf ("Root directory:\n");
list_dir(root, root_entries, FALSE);
} else if (dos_read)
extract(entry);
else {
- if (entry != NIL_DIR) {
+ if (entry != NULL) {
fflush (stdout);
if (is_dir(entry))
fprintf (stderr, "%s: %s is a directory.\n", cmnd, path);
fprintf (stderr, "%s: %s already exists.\n", cmnd, argv[idx]);
exit(1);
}
- add_path(NIL_PTR, TRUE);
+ add_path(NULL, TRUE);
if (*path) make_file(find_entry(root, root_entries, path),
sub_entries, slash(argv[idx]));
register char *pathname;
{
register DIRECTORY *dir_ptr = dir;
- DIRECTORY *mem = NIL_DIR;
+ DIRECTORY *mem = NULL;
unsigned short cl_no = dir->d_cluster;
unsigned short type, last = 0;
char file_name[14];
printf ( "Directory %s%s:\n", path, name);
add_path(name, FALSE);
list_dir(dir_ptr, sub_entries, FALSE);
- add_path(NIL_PTR, FALSE);
+ add_path(NULL, FALSE);
}
}
}
switch (function) {
case FIND:
- if (dos_write && *pathname == '\0') return NIL_DIR;
+ if (dos_write && *pathname == '\0') return NULL;
fflush (stdout);
fprintf (stderr, "%s: Cannot find `%s'.\n", cmnd, file_name);
exit(1);
case LABEL:
- return NIL_DIR;
+ return NULL;
case ENTRY:
if (!mem) {
fflush (stdout);
while (*ptr) ptr++;
- if (file == NIL_PTR) {
+ if (file == NULL) {
if (ptr != path) ptr--;
if (ptr != path) do {
ptr--;
typedef struct regex REGEX;
/* NULL definitions */
-#define NIL_PTR ((char *) 0)
-#define NIL_LINE ((LINE *) 0)
-#define NIL_REG ((REGEX *) 0)
-#define NIL_INT ((int *) 0)
/*
* Forward declarations
/*
* Move to coordinates and set textp. (Don't use address)
*/
-#define move_to(nx, ny) move((nx), NIL_PTR, (ny))
+#define move_to(nx, ny) move((nx), NULL, (ny))
/*
* Move to coordinates on screen as indicated by textp.
* Functions handling status_line. ON means in reverse video.
*/
#define status_line(str1, str2) (void) bottom_line(ON, (str1), \
- (str2), NIL_PTR, FALSE)
+ (str2), NULL, FALSE)
#define error(str1, str2) (void) bottom_line(ON, (str1), \
- (str2), NIL_PTR, FALSE)
-#define get_string(str1,str2, fl) bottom_line(ON, (str1), NIL_PTR, (str2), fl)
-#define clear_status() (void) bottom_line(OFF, NIL_PTR, NIL_PTR, \
- NIL_PTR, FALSE)
+ (str2), NULL, FALSE)
+#define get_string(str1,str2, fl) bottom_line(ON, (str1), NULL, (str2), fl)
+#define clear_status() (void) bottom_line(OFF, NULL, NULL, \
+ NULL, FALSE)
/*
* Print info about current file and buffer.
*
* A special structure is allocated and its address is assigned to the
* variable header as well as the variable tail. The text field of this
- * structure is set to NIL_PTR. The tail->prev of this structure points
+ * structure is set to NULL. The tail->prev of this structure points
* to the last LINE of the file and the header->next to the first LINE.
* Other LINE *variables are top_line and bot_line which point to the
* first line resp. the last line on the screen.
* startposition on the current line, and a flag indicating FORWARD or
* REVERSE search. Match () checks out the whole file until a match is
* found. If match is found it returns a pointer to the line in which the
- * match was found else it returns a NIL_LINE. Line_check () takes the
+ * match was found else it returns a NULL. Line_check () takes the
* same arguments, but return either MATCH or NO_MATCH.
* During checking, the start_ptr and end_ptr fields of the REGEX
* structure are assigned to the start and end of the match.
* backwards search (SR)) call search () with an apropiate message and a
* flag indicating FORWARD or REVERSE search. Search () will get an
* expression from the user by calling get_expression(). Get_expression()
- * returns a pointer to a REGEX structure or NIL_REG upon errors and
+ * returns a pointer to a REGEX structure or NULL upon errors and
* prompts for the expression. If no expression if given, the previous is
* used instead. After that search will call match (), and if a match is
* found, we can move to that place in the file by the functions find_x()
#else
string_print (enter_string);
#endif /* UNIX */
- load_file(new_file[0] == '\0' ? NIL_PTR : new_file);
+ load_file(new_file[0] == '\0' ? NULL : new_file);
}
/*
int fd; /* Filedescriptor of file */
if (modified == FALSE) {
- error ("Write not necessary.", NIL_PTR);
+ error ("Write not necessary.", NULL);
return FINE;
}
int pid, status;
char *shell;
- if ((shell = getenv("SHELL")) == NIL_PTR) shell = "/bin/sh";
+ if ((shell = getenv("SHELL")) == NULL) shell = "/bin/sh";
switch (pid = fork()) {
case -1: /* Error */
- error("Cannot fork.", NIL_PTR);
+ error("Cannot fork.", NULL);
return;
case 0: /* This is the child */
set_cursor(0, ymax);
if ((status >> 8) == 127) /* Child died with 127 */
error("Cannot exec ", shell);
else if ((status >> 8) == 126)
- error("Cannot open /dev/tty as fd #0", NIL_PTR);
+ error("Cannot open /dev/tty as fd #0", NULL);
}
/*
register char *p = buf;
*p++ = ' ';
- if (s1 != NIL_PTR)
+ if (s1 != NULL)
while (*p = *s1++)
p++;
- if (s2 != NIL_PTR)
+ if (s2 != NULL)
while (*p = *s2++)
p++;
*p++ = ' ';
string_print(buf);
- if (inbuf != NIL_PTR)
+ if (inbuf != NULL)
ret = input(inbuf, statfl);
/* Print normal video */
string_print(normal_video);
string_print(blank_line); /* Clear the rest of the line */
#endif /* UNIX */
- if (inbuf != NIL_PTR)
+ if (inbuf != NULL)
set_cursor(0, ymax);
else
set_cursor(x, y); /* Set cursor back to old position */
}
/* Set or unset relative x-coordinate */
- if (new_address == NIL_PTR) {
+ if (new_address == NULL) {
new_address = find_address(line, (new_x == x) ? rel_x : new_x , &tx);
if (new_x != x)
rel_x = tx;
{
register int count = 0;
- if (string != NIL_PTR) {
+ if (string != NULL) {
while (*string++ != '\0')
count++;
}
build_string(text_buffer, "Command aborted: %s (File incomplete)",
(errno == ENOSPC || errno == -ENOSPC) ?
"No space on device" : "Write error");
- error(text_buffer, NIL_PTR);
+ error(text_buffer, NULL);
}
/*
quit = FALSE;
/* Ask for confirmation */
- status_line("Really abort? ", NIL_PTR);
+ status_line("Really abort? ", NULL);
if (getchar() != 'y') {
clear_status();
return;
char *p;
p = malloc((unsigned) bytes);
- if (p == NIL_PTR) {
+ if (p == NULL) {
if (loading == TRUE)
panic("File too big.");
panic("Out of memory.");
char *path;
{
register char *ptr = path;
- register char *last = NIL_PTR;
+ register char *last = NULL;
while (*ptr != '\0') {
if (*ptr == '/')
last = ptr;
ptr++;
}
- if (last == NIL_PTR)
+ if (last == NULL)
return path;
if (*(last + 1) == '\0') { /* E.g. /usr/tmp/pipo/ */
*last = '\0';
}
/*
- * Load_file loads the file `file' into core. If file is a NIL_PTR or the file
+ * Load_file loads the file `file' into core. If file is a NULL or the file
* couldn't be opened, just some initializations are done, and a line consisting
* of a `\n' is installed.
*/
/* Open file */
writable = TRUE; /* Benefit of the doubt */
- if (file == NIL_PTR) {
+ if (file == NULL) {
if (rpipe == FALSE)
- status_line("No file.", NIL_PTR);
+ status_line("No file.", NULL);
else {
fd = 0;
file = "standard input";
int fd;
register char *buffer;
{
- static char *last = NIL_PTR;
- static char *current = NIL_PTR;
+ static char *last = NULL;
+ static char *current = NULL;
static int read_chars;
register char *cur_pos = current;
char *begin = buffer;
raw_mode(ON); /* Set tty to appropriate mode */
header = tail = (LINE *) alloc(sizeof(LINE)); /* Make header of list*/
- header->text = NIL_PTR;
+ header->text = NULL;
header->next = tail->prev = header;
/* Load the file (if any) */
if (argc < 2)
- load_file(NIL_PTR);
+ load_file(NULL);
else {
- (void) get_file(NIL_PTR, argv[1]); /* Truncate filename */
+ (void) get_file(NULL, argv[1]); /* Truncate filename */
load_file(argv[1]);
}
}
if (quit == TRUE) /* Abort has been given */
- error("Aborted", NIL_PTR);
+ error("Aborted", NULL);
}
/*
msg[LINE_LEN - 4] = SHIFT_MARK; /* Overflow on status line */
msg[LINE_LEN - 3] = '\0';
}
- status_line(msg, NIL_PTR); /* Print the information */
+ status_line(msg, NULL); /* Print the information */
}
/*
register int index;
register int count = 0;
- status_line(message, NIL_PTR);
+ status_line(message, NULL);
index = getchar();
if (quit == FALSE && (index < '0' || index > '9')) {
- error("Bad count", NIL_PTR);
+ error("Bad count", NULL);
return ERRORS;
}
char *ptr;
int ret;
- if (message == NIL_PTR || (ret = get_string(message, file, TRUE)) == FINE) {
+ if (message == NULL || (ret = get_string(message, file, TRUE)) == FINE) {
if (length_of((ptr = basename(file))) > NAME_MAX)
ptr[NAME_MAX] = '\0';
}
{
register char ctrl;
- status_line("Enter control character.", NIL_PTR);
+ status_line("Enter control character.", NULL);
if ((ctrl = getchar()) >= '\01' && ctrl <= '\037') {
S(ctrl); /* Insert the char */
clear_status();
}
else
- error ("Unknown control character", NIL_PTR);
+ error ("Unknown control character", NULL);
}
/*
register char *textp = line->text;
if (length_of(textp) + length_of(string) >= MAX_CHARS) {
- error("Line too long", NIL_PTR);
+ error("Line too long", NULL);
return ERRORS;
}
/* Check if line doesn't exceed MAX_CHARS */
if (count + length_of(end_textp) >= MAX_CHARS) {
- error("Line too long", NIL_PTR);
+ error("Line too long", NULL);
return;
}
/* Copy last part of end_line if end_line is not tail */
- copy_string(bufp, (end_textp != NIL_PTR) ? end_textp : "\n");
+ copy_string(bufp, (end_textp != NULL) ? end_textp : "\n");
/* Delete all lines between start and end_position (including end_line) */
line = start_line->next;
}
/* Check if last line of file should be deleted */
- if (end_textp == NIL_PTR && length_of(start_line->text) == 1 && nlines > 1) {
+ if (end_textp == NULL && length_of(start_line->text) == 1 && nlines > 1) {
start_line = start_line->prev;
(void) line_delete(start_line->next);
line_cnt++;
register int fd; /* File descriptor for buffer */
if ((fd = scratch_file(READ)) == ERRORS)
- error("Buffer is empty.", NIL_PTR);
+ error("Buffer is empty.", NULL);
else {
file_insert(fd, FALSE);/* Insert the buffer */
(void) close(fd);
/* Checkout the buffer */
if ((yank_fd = scratch_file(READ)) == ERRORS) {
- error("Buffer is empty.", NIL_PTR);
+ error("Buffer is empty.", NULL);
return;
}
{
mark_line = cur_line;
mark_text = cur_text;
- status_line("Mark set", NIL_PTR);
+ status_line("Mark set", NULL);
}
/*
{
switch (checkmark()) {
case NOT_VALID :
- error("Mark not set.", NIL_PTR);
+ error("Mark not set.", NULL);
return;
case SMALLER :
yank(mark_line, mark_text, cur_line, cur_text, remove);
case SAME : /* Ignore stupid behaviour */
yank_status = EMPTY;
chars_saved = 0L;
- status_line("0 characters saved in buffer.", NIL_PTR);
+ status_line("0 characters saved in buffer.", NULL);
break;
}
}
chars_saved = 0L;
lines_saved = 0;
- status_line("Saving text.", NIL_PTR);
+ status_line("Saving text.", NULL);
/* Keep writing chars until the end_location is reached. */
while (textp != end_textp) {
/* Check file existence */
if (access(yank_file, 0) == 0 || (fd = creat(yank_file, 0644)) < 0) {
if (trials++ >= MAXTRAILS) {
- error("Unable to creat scratchfile.", NIL_PTR);
+ error("Unable to creat scratchfile.", NULL);
return ERRORS;
}
else
/*
* Get_expression() prompts for an expression. If just a return is typed, the
* old expression is used. If the expression changed, compile() is called and
- * the returning REGEX structure is returned. It returns NIL_REG upon error.
+ * the returning REGEX structure is returned. It returns NULL upon error.
* The save flag indicates whether the expression should be appended at the
* message pointer.
*/
char exp_buf[LINE_LEN]; /* Buffer for new expr. */
if (get_string(message, exp_buf, FALSE) == ERRORS)
- return NIL_REG;
+ return NULL;
if (exp_buf[0] == '\0' && typed_expression[0] == '\0') {
- error("No previous expression.", NIL_PTR);
- return NIL_REG;
+ error("No previous expression.", NULL);
+ return NULL;
}
if (exp_buf[0] != '\0') { /* A new expr. is typed */
}
if (program.status == REG_ERROR) { /* Error during compiling */
- error(program.result.err_mess, NIL_PTR);
- return NIL_REG;
+ error(program.result.err_mess, NULL);
+ return NULL;
}
return &program;
}
/* Save message and get expression */
copy_string(mess_buf, message);
- if ((program = get_expression(mess_buf)) == NIL_REG)
+ if ((program = get_expression(mess_buf)) == NULL)
return;
/* Get substitution pattern */
do {
subs++; /* Increment subs */
if ((textp = substitute(line, program,replacement))
- == NIL_PTR)
+ == NULL)
return; /* Line too long */
} while ((program->status & BEGIN_LINE) != BEGIN_LINE &&
(program->status & END_LINE) != END_LINE &&
copy_string(mess_buf, (quit == TRUE) ? "(Aborted) " : "");
/* Fix the status line */
if (subs == 0L && quit == FALSE)
- error("Pattern not found.", NIL_PTR);
+ error("Pattern not found.", NULL);
else if (lines >= REPORT || quit == TRUE) {
build_string(mess_buf, "%s %D substitutions on %D lines.", mess_buf,
subs, lines);
- status_line(mess_buf, NIL_PTR);
+ status_line(mess_buf, NULL);
}
else if (file == NOT_VALID && subs >= REPORT)
status_line(num_out(subs), " substitutions.");
/* Check for line length not exceeding MAX_CHARS */
if (length_of(text_buffer) + length_of(program->end_ptr) >= MAX_CHARS) {
- error("Substitution result: line too big", NIL_PTR);
- return NIL_PTR;
+ error("Substitution result: line too big", NULL);
+ return NULL;
}
/* Append last part of line to the new build line */
/*
* Search() calls get_expression to fetch the expression. If this went well,
* the function match() is called which returns the line with the next match.
- * If this line is the NIL_LINE, it means that a match could not be found.
+ * If this line is the NULL, it means that a match could not be found.
* Find_x() and find_y() display the right page on the screen, and return
* the right coordinates for x and y. These coordinates are passed to move_to()
*/
register LINE *match_line;
/* Get the expression */
- if ((program = get_expression(message)) == NIL_REG)
+ if ((program = get_expression(message)) == NULL)
return;
set_cursor(0, ymax);
flush();
/* Find the match */
- if ((match_line = match(program, cur_text, method)) == NIL_LINE) {
+ if ((match_line = match(program, cur_text, method)) == NULL) {
if (quit == TRUE)
- status_line("Aborted", NIL_PTR);
+ status_line("Aborted", NULL);
else
- status_line("Pattern not found.", NIL_PTR);
+ status_line("Pattern not found.", NULL);
return;
}
* Match gets as argument the program, pointer to place in current line to
* start from and the method to search for (either FORWARD or REVERSE).
* Match() will look through the whole file until a match is found.
- * NIL_LINE is returned if no match could be found.
+ * NULL is returned if no match could be found.
*/
LINE *match(program, string, method)
REGEX *program;
/* Corrupted program */
if (program->status == REG_ERROR)
- return NIL_LINE;
+ return NULL;
/* Check part of text first */
if (!(program->status & BEGIN_LINE)) {
/* No match in last (or first) part of line. Check out rest of file */
do {
line = (method == FORWARD) ? line->next : line->prev;
- if (line->text == NIL_PTR) /* Header/tail */
+ if (line->text == NULL) /* Header/tail */
continue;
if (line_check(program, line->text, method) == MATCH)
return line;
} while (line != cur_line && quit == FALSE);
/* No match found. */
- return NIL_LINE;
+ return NULL;
}
/*
/* If the match must be anchored, just check the string. */
if (program->status & BEGIN_LINE)
- return check_string(program, string, NIL_INT);
+ return check_string(program, string, NULL);
if (method == REVERSE) {
/* First move to the end of the string */
/* Start checking string until the begin of the string is met */
while (textp >= string) {
program->start_ptr = textp;
- if (check_string(program, textp--, NIL_INT))
+ if (check_string(program, textp--, NULL))
return MATCH;
}
}
/* Move through the string until the end of is found */
while (quit == FALSE && *textp != '\0') {
program->start_ptr = textp;
- if (check_string(program, textp, NIL_INT))
+ if (check_string(program, textp, NULL))
return MATCH;
if (*textp == '\n')
break;
char *mark; /* For marking position */
int star_fl; /* A star has been born */
- if (expression == NIL_INT)
+ if (expression == NULL)
expression = program->result.expression;
/* Loop until end of string or end of expression */
/* Return status of functions */
#define OK 0
#define ERROR -1
-#define NIL_PTR ((char *) 0)
/* Compare return values */
#define LOWER -1
char *line; /* Contains line currently used */
} MERGE;
-#define NIL_MERGE ((MERGE *) 0)
MERGE merge_f[OPEN_FILES]; /* Merge structs */
int buf_size; /* Size of core available for each struct */
field->reverse = TRUE;
break;
default: /* Illegal options */
- error(TRUE, USAGE, NIL_PTR);
+ error(TRUE, USAGE, NULL);
}
}
if (ptr && *ptr == '-' && ((table[*(ptr + 1)] & DIGIT) || *(ptr + 1) == '.')) {
new_field(field, offset, FALSE);
if (field->beg_field > field->end_field)
- error(TRUE, "End field is before start field!", NIL_PTR);
+ error(TRUE, "End field is before start field!", NULL);
} else /* No end pos. */
field->end_field = ERROR;
}
break;
if (*ptr == '+') { /* Assign field. */
if (++field_cnt == FIELDS_LIMIT)
- error(TRUE, "Too many fields", NIL_PTR);
+ error(TRUE, "Too many fields", NULL);
new_field(&fields[field_cnt], &arg_count, TRUE);
} else { /* Get output options */
while (*++ptr) {
/* Only merge files. Set up */
if (only_merge) {
args_limit = args_offset = arg_count;
- while (argv[args_limit] != NIL_PTR)
+ while (argv[args_limit] != NULL)
args_limit++; /* Find nr of args */
files_merge(args_limit - arg_count);
exit(0);
}
if (arg_count == argc) { /* No args left. Use stdin */
if (check)
- check_file(0, NIL_PTR);
+ check_file(0, NULL);
else
get_file(0, (off_t) 0);
} else
register char *message, *arg;
{
write(2, message, strlen(message));
- if (arg != NIL_PTR) write(2, arg, strlen(arg));
+ if (arg != NULL) write(2, arg, strlen(arg));
perror(" ");
if (quit) exit(1);
}
*/
void open_outfile()
{
- if (output_file == NIL_PTR)
+ if (output_file == NULL)
out_fd = STD_OUT;
else if ((out_fd = creat(output_file, 0644)) < 0)
error(TRUE, "Cannot creat ", output_file);
if ((fd = creat(file_name(nr_of_files), 0644)) < 0)
error(TRUE, "Cannot creat ", file_name(nr_of_files));
}
- for (line_ptr = line_table; *line_ptr != NIL_PTR; line_ptr++) {
+ for (line_ptr = line_table; *line_ptr != NULL; line_ptr++) {
ptr = *line_ptr;
/* Skip all same lines if uniq is set */
- if (uniq && *(line_ptr + 1) != NIL_PTR) {
+ if (uniq && *(line_ptr + 1) != NULL) {
if (compare(ptr, *(line_ptr + 1)) == SAME) continue;
}
do { /* Print line in a buffered way */
register int bytes;
{
if (read(fd, address, bytes) < 0 && bytes != 0)
- error(TRUE, "Read error", NIL_PTR);
+ error(TRUE, "Read error", NULL);
}
/* Mwrite () performs a normal write (), but checks the return value. */
register int bytes;
{
if (write(fd, address, bytes) != bytes && bytes != 0)
- error(TRUE, "Write error", NIL_PTR);
+ error(TRUE, "Write error", NULL);
}
/* Sort () sorts the input in memory starting at mem_top. */
if (*ptr++ == '\n') line_table[count++] = ptr;
}
- line_table[count - 1] = NIL_PTR;
+ line_table[count - 1] = NULL;
/* Sort the line table */
sort_table(count - 1);
if (only_merge && uniq)
uniq_lines(smallest); /* Print only uniq lines */
else /* Print rest of file */
- while (print(smallest, file_cnt) != NIL_MERGE);
+ while (print(smallest, file_cnt) != NULL);
- put_line(NIL_PTR); /* Flush output buffer */
+ put_line(NULL); /* Flush output buffer */
}
/* Put_line () prints the line into the out_fd filedescriptor. If line equals
- * NIL_PTR, the out_fd is flushed and closed.
+ * NULL, the out_fd is flushed and closed.
*/
void put_line(line)
register char *line;
{
static int index = 0; /* Index in out_buffer */
- if (line == NIL_PTR) { /* Flush and close */
+ if (line == NULL) { /* Flush and close */
mwrite(out_fd, out_buffer, index);
index = 0;
(void) close(out_fd);
}
}
if (i == file_cnt) /* No more files left */
- return NIL_MERGE;
+ return NULL;
}
return merg;
}
register char *address;
if ((address = sbrk(size)) == (char *) -1)
- error(TRUE, "Not enough memory. Use chmem to allocate more", NIL_PTR);
+ error(TRUE, "Not enough memory. Use chmem to allocate more", NULL);
return address;
}
void mbrk(address)
char *address;
{
- if (brk(address) == -1) error(TRUE, "Cannot reset memory", NIL_PTR);
+ if (brk(address) == -1) error(TRUE, "Cannot reset memory", NULL);
}
void catch(dummy)
struct wini *wn;
- if (w_prepare(m_ptr->DEVICE) == NIL_DEV) return(ENXIO);
+ if (w_prepare(m_ptr->DEVICE) == NULL) return(ENXIO);
wn = w_wn;
w_dv = &w_wn->subpart[device % SUB_PER_DRIVE];
} else {
w_device = -1;
- return(NIL_DEV);
+ return(NULL);
}
return(w_dv);
}
w_testing = 1;
/* Try I/O on the actual drive (not any (sub)partition). */
- if (w_prepare(w_drive * DEV_PER_DRIVE) == NIL_DEV)
+ if (w_prepare(w_drive * DEV_PER_DRIVE) == NULL)
panic("Couldn't switch devices");
r = w_transfer(SELF, DEV_GATHER_S, cvu64(0), &iov, 1);
/* Switch back. */
- if (w_prepare(save_dev) == NIL_DEV)
+ if (w_prepare(save_dev) == NULL)
panic("Couldn't switch back devices");
/* Restore parameters. */
PRIVATE int w_do_close(struct driver *dp, message *m_ptr)
{
/* Device close: Release a device. */
- if (w_prepare(m_ptr->DEVICE) == NIL_DEV)
+ if (w_prepare(m_ptr->DEVICE) == NULL)
return(ENXIO);
w_wn->open_ct--;
#if ENABLE_ATAPI
return OK;
} else if (m->REQUEST == DIOCOPENCT) {
int count;
- if (w_prepare(m->DEVICE) == NIL_DEV) return ENXIO;
+ if (w_prepare(m->DEVICE) == NULL) return ENXIO;
count = w_wn->open_ct;
r= sys_safecopyto(m->IO_ENDPT, (cp_grant_id_t) m->IO_GRANT,
0, (vir_bytes)&count, sizeof(count), D);
w_wn = &wini[w_drive];
w_dv = &w_wn->subpart[device % SUB_PER_DRIVE];
} else {
- return(NIL_DEV);
+ return(NULL);
}
if (w_drive >= MAX_DRIVES || !w_wn->present)
- return NIL_DEV;
+ return NULL;
return(w_dv);
}
if (!init_done) { w_init(); init_done = TRUE; }
- if (w_prepare(m_ptr->DEVICE) == NIL_DEV) return(ENXIO);
+ if (w_prepare(m_ptr->DEVICE) == NULL) return(ENXIO);
if (w_wn->open_ct++ == 0) {
/* Partition the disk. */
{
/* Device close: Release a device. */
- if (w_prepare(m_ptr->DEVICE) == NIL_DEV) return(ENXIO);
+ if (w_prepare(m_ptr->DEVICE) == NULL) return(ENXIO);
w_wn->open_ct--;
return(OK);
}
if (m->REQUEST == DIOCOPENCT) {
int count;
- if (w_prepare(m->DEVICE) == NIL_DEV) return ENXIO;
+ if (w_prepare(m->DEVICE) == NULL) return ENXIO;
count = w_wn->open_ct;
r=sys_safecopyto(m->IO_ENDPT, (cp_grant_id_t)m->IO_GRANT,
0, (vir_bytes)&count, sizeof(count), D);
f_device = device;
f_drive = device & ~(DEV_TYPE_BITS | FORMAT_DEV_BIT);
- if (f_drive < 0 || f_drive >= NR_DRIVES) return(NIL_DEV);
+ if (f_drive < 0 || f_drive >= NR_DRIVES) return(NULL);
f_fp = &floppy[f_drive];
f_dv = &f_fp->fl_geom;
struct test_order *top;
/* Decode the message parameters. */
- if (f_prepare(m_ptr->DEVICE) == NIL_DEV) return(ENXIO);
+ if (f_prepare(m_ptr->DEVICE) == NULL) return(ENXIO);
dtype = f_device & DEV_TYPE_BITS; /* get density from minor dev */
if (dtype >= MINOR_fd0p0) dtype = 0;
{
/* Prepare for I/O on a device: check if the minor device number is ok. */
- if (device < 0 || device >= NR_DEVS) return(NIL_DEV);
+ if (device < 0 || device >= NR_DEVS) return(NULL);
log_device = device;
return(&log_geom[device]);
struct driver *dp;
message *m_ptr;
{
- if (log_prepare(m_ptr->DEVICE) == NIL_DEV) return(ENXIO);
+ if (log_prepare(m_ptr->DEVICE) == NULL) return(ENXIO);
return(OK);
}
int device;
{
/* Prepare for I/O on a device: check if the minor device number is ok. */
- if (device < 0 || device >= NR_DEVS) return(NIL_DEV);
+ if (device < 0 || device >= NR_DEVS) return(NULL);
m_device = device;
return(&m_geom[device]);
int r;
/* Check device number on open. */
- if (m_prepare(m_ptr->DEVICE) == NIL_DEV) return(ENXIO);
+ if (m_prepare(m_ptr->DEVICE) == NULL) return(ENXIO);
if (m_device == MEM_DEV)
{
r = sys_enable_iop(m_ptr->IO_ENDPT);
{
int r;
- if (m_prepare(m_ptr->DEVICE) == NIL_DEV) return(ENXIO);
+ if (m_prepare(m_ptr->DEVICE) == NULL) return(ENXIO);
if(m_device < 0 || m_device >= NR_DEVS) {
panic("wrong m_device: %d", m_device);
if((dev < RAM_DEV_FIRST || dev > RAM_DEV_LAST) && dev != RAM_DEV_OLD) {
printf("MEM: MIOCRAMSIZE: %d not a ramdisk\n", dev);
}
- if ((dv = m_prepare(dev)) == NIL_DEV) return(ENXIO);
+ if ((dv = m_prepare(dev)) == NULL) return(ENXIO);
/* Get request structure */
s= sys_safecopyfrom(m_ptr->IO_ENDPT, (vir_bytes)m_ptr->IO_GRANT,
{
/* Prepare for I/O on a device: check if the minor device number is ok. */
- if (device < 0 || device >= NR_DEVS) return(NIL_DEV);
+ if (device < 0 || device >= NR_DEVS) return(NULL);
m_device = device;
return(&m_geom[device]);
{
/* Check device number on open.
*/
- if (r_prepare(m_ptr->DEVICE) == NIL_DEV) return(ENXIO);
+ if (r_prepare(m_ptr->DEVICE) == NULL) return(ENXIO);
return(OK);
}
struct driver *dp; /* pointer to driver structure */
message *m_ptr; /* pointer to control message */
{
- if (r_prepare(m_ptr->DEVICE) == NIL_DEV) return(ENXIO);
+ if (r_prepare(m_ptr->DEVICE) == NULL) return(ENXIO);
switch (m_ptr->REQUEST) {
/* Message passing constants. */
#define MESS_SIZE (sizeof(message)) /* might need usizeof from FS here */
-#define NIL_MESS ((message *) 0) /* null pointer */
/* Memory related constants. */
#define SEGMENT_TYPE 0xFF00 /* bit mask to get segment type */
#define BYTE 0377 /* mask for 8 bits */
#define READING 0 /* copy data to user */
#define WRITING 1 /* copy data from user */
-#define NIL_PTR (char *) 0 /* generally useful expression */
#define HAVE_SCATTERED_IO 1 /* scattered I/O is now standard */
/* Macros. */
u64_t dv_size;
};
-#define NIL_DEV ((struct device *) 0)
#define DRIVER_STD 0 /* Use the standard reply protocol */
#define DRIVER_ASYN 1 /* Use the new asynchronous protocol */
{ "Stack exception", SIGSEGV, 286 }, /* STACK_FAULT already used */
{ "General protection", SIGSEGV, 286 },
{ "Page fault", SIGSEGV, 386 }, /* not close */
- { NIL_PTR, SIGILL, 0 }, /* probably software trap */
+ { NULL, SIGILL, 0 }, /* probably software trap */
{ "Coprocessor error", SIGFPE, 386 },
{ "Alignment check", SIGBUS, 386 },
{ "Machine check", SIGBUS, 386 },
}
/* Exception in system code. This is not supposed to happen. */
- if (ep->msg == NIL_PTR || machine.processor < ep->minprocessor)
+ if (ep->msg == NULL || machine.processor < ep->minprocessor)
printf("\nIntel-reserved exception %d\n", frame->vector);
else
printf("\n%s\n", ep->msg);
/* XT, AT or MCA bus? */
value = get_value(params_buffer, "bus");
- if (value == NIL_PTR || strcmp(value, "at") == 0) {
+ if (value == NULL || strcmp(value, "at") == 0) {
machine.pc_at = TRUE; /* PC-AT compatible hardware */
} else if (strcmp(value, "mca") == 0) {
machine.pc_at = machine.ps_mca = TRUE; /* PS/2 with micro channel */
while (*envp++ != 0)
;
}
- return(NIL_PTR);
+ return(NULL);
}
* covers F_GETFD, F_GETFL and invalid commands.
*/
m.m1_i3 = 0;
- m.m1_p1 = NIL_PTR;
+ m.m1_p1 = NULL;
/* Adjust for the stupid cases. */
switch(cmd) {
if (mp->COUNT < 0) return(EINVAL);
/* Prepare for I/O. */
- if ((*dp->dr_prepare)(mp->DEVICE) == NIL_DEV) return(ENXIO);
+ if ((*dp->dr_prepare)(mp->DEVICE) == NULL) return(ENXIO);
/* Create a one element scatter/gather vector for the buffer. */
if(mp->m_type == DEV_READ_S) opcode = DEV_GATHER_S;
}
/* Prepare for I/O. */
- if ((*dp->dr_prepare)(mp->DEVICE) == NIL_DEV) return(ENXIO);
+ if ((*dp->dr_prepare)(mp->DEVICE) == NULL) return(ENXIO);
/* Transfer bytes from/to the device. */
opcode = mp->m_type;
PUBLIC struct device *nop_prepare(int device)
{
/* Nothing to prepare for. */
- return(NIL_DEV);
+ return(NULL);
}
/*===========================================================================*
}
/* Decode the message parameters. */
- if ((dv = (*dp->dr_prepare)(mp->DEVICE)) == NIL_DEV) return(ENXIO);
+ if ((dv = (*dp->dr_prepare)(mp->DEVICE)) == NULL) return(ENXIO);
if (mp->REQUEST == DIOCSETP) {
/* Copy just this one partition table entry. */
unsigned long base, limit, part_limit;
/* Get the geometry of the device to partition */
- if ((dv = (*dp->dr_prepare)(device)) == NIL_DEV
+ if ((dv = (*dp->dr_prepare)(device)) == NULL
|| cmp64u(dv->dv_size, 0) == 0) return;
base = div64u(dv->dv_base, SECTOR_SIZE);
limit = base + div64u(dv->dv_size, SECTOR_SIZE);
}
/* Find an array of devices. */
- if ((dv = (*dp->dr_prepare)(device)) == NIL_DEV) return;
+ if ((dv = (*dp->dr_prepare)(device)) == NULL) return;
/* Set the geometry of the partitions from the partition table. */
for (par = 0; par < NR_PARTITIONS; par++, dv++) {
nextoffset = pe->lowsec;
} else
if (pe->sysind != NO_PART) {
- if ((dv = (*dp->dr_prepare)(subdev)) == NIL_DEV) return;
+ if ((dv = (*dp->dr_prepare)(subdev)) == NULL) return;
dv->dv_base = mul64u(extbase + offset + pe->lowsec,
SECTOR_SIZE);
position = mul64u(offset, SECTOR_SIZE);
iovec1.iov_addr = (vir_bytes) partbuf;
iovec1.iov_size = CD_SECTOR_SIZE;
- if ((*dp->dr_prepare)(device) != NIL_DEV) {
+ if ((*dp->dr_prepare)(device) != NULL) {
(void) (*dp->dr_transfer)(SELF, DEV_GATHER_S, position, &iovec1, 1);
}
if (iovec1.iov_size != 0) {
{
/* Given a directory inode and a component name, look up the inode associated
* with that directory entry. Return the inode (with increased reference
- * count) if found, or NIL_INODE otherwise.
+ * count) if found, or NULL otherwise.
*/
struct inode *ino;
unsigned int slot;
break;
}
- if (ino == NIL_INODE)
- return NIL_INODE;
+ if (ino == NULL)
+ return NULL;
get_inode(ino);
* Do not touch open handles. Do not add to the free list.
*/
- assert(ino->i_parent != NIL_INODE);
+ assert(ino->i_parent != NULL);
/* hash_del(ino); */
LIST_REMOVE(ino, i_hash);
/* Mark all inodes except the root inode as free. */
for (index = 1; index < NUM_INODES; index++) {
ino = &inodes[index];
- ino->i_parent = NIL_INODE;
+ ino->i_parent = NULL;
LIST_INIT(&ino->i_child);
ino->i_num = index + 1;
ino->i_gen = (unsigned short)-1; /* aesthetics */
if (index < 0) {
printf("HGFS: VFS passed invalid inode number!\n");
- return NIL_INODE;
+ return NULL;
}
assert(index < NUM_INODES);
if (INODE_GEN(ino_nr) != ino->i_gen) {
printf("HGFS: VFS passed outdated inode number!\n");
- return NIL_INODE;
+ return NULL;
}
/* The VFS/FS protocol only uses referenced inodes. */
dprintf(("HGFS: put_inode(%p) ['%s']\n", ino, ino->i_name));
- assert(ino != NIL_INODE);
+ assert(ino != NULL);
assert(ino->i_ref > 0);
ino->i_ref--;
/* Add the inode to the head or tail of the free list, depending on whether
* it is also deleted (and therefore can never be reused as is).
*/
- if (ino->i_parent == NIL_INODE)
+ if (ino->i_parent == NULL)
TAILQ_INSERT_HEAD(&free_list, ino, i_free);
else
TAILQ_INSERT_TAIL(&free_list, ino, i_free);
LIST_REMOVE(ino, i_next);
if (parent->i_ref == 0 && !HAS_CHILDREN(parent)) {
- if (parent->i_parent == NIL_INODE)
+ if (parent->i_parent == NULL)
TAILQ_INSERT_HEAD(&free_list, parent, i_free);
else
TAILQ_INSERT_TAIL(&free_list, parent, i_free);
}
- ino->i_parent = NIL_INODE;
+ ino->i_parent = NULL;
}
/*===========================================================================*
if (TAILQ_EMPTY(&free_list)) {
printf("HGFS: out of inodes!\n");
- return NIL_INODE;
+ return NULL;
}
ino = TAILQ_FIRST(&free_list);
assert(!HAS_CHILDREN(ino));
/* If this was a cached inode, free it first. */
- if (ino->i_parent != NIL_INODE)
+ if (ino->i_parent != NULL)
del_dentry(ino);
- assert(ino->i_parent == NIL_INODE);
+ assert(ino->i_parent == NULL);
/* Initialize a subset of its fields */
ino->i_gen++;
struct inode *ino;
int count;
- if ((ino = find_inode(m_in.REQ_INODE_NR)) == NIL_INODE)
+ if ((ino = find_inode(m_in.REQ_INODE_NR)) == NULL)
return EINVAL;
count = m_in.REQ_COUNT;
#define i_file i_u.u_file
#define i_dir i_u.u_dir
-#define NIL_INODE ((struct inode *)NULL)
#define I_DIR 0x01 /* this inode represents a directory */
#define I_HANDLE 0x02 /* this inode has an open handle */
if (!strcmp(name, ".") || !strcmp(name, "..")) return EEXIST;
- if ((parent = find_inode(m_in.REQ_INODE_NR)) == NIL_INODE)
+ if ((parent = find_inode(m_in.REQ_INODE_NR)) == NULL)
return EINVAL;
if ((r = verify_dentry(parent, name, path, &ino)) != OK)
/* Are we going to need a new inode upon success?
* Then make sure there is one available before trying anything.
*/
- if (ino == NIL_INODE || ino->i_ref > 1 || HAS_CHILDREN(ino)) {
+ if (ino == NULL || ino->i_ref > 1 || HAS_CHILDREN(ino)) {
if (!have_free_inode()) {
- if (ino != NIL_INODE)
+ if (ino != NULL)
put_inode(ino);
return ENFILE;
* is wrong with the directory, we'll find out later anyway.
*/
- if (ino != NIL_INODE)
+ if (ino != NULL)
put_inode(ino);
return r;
hgfs_close(handle);
- if (ino != NIL_INODE) {
+ if (ino != NULL) {
del_dentry(ino);
put_inode(ino);
/* We do assume that the HGFS open(O_CREAT|O_EXCL) did its job.
* If we previousy found an inode, get rid of it now. It's old.
*/
- if (ino != NIL_INODE) {
+ if (ino != NULL) {
del_dentry(ino);
put_inode(ino);
*/
ino = get_free_inode();
- assert(ino != NIL_INODE); /* we checked before whether we had a free one */
+ assert(ino != NULL); /* we checked before whether we had a free one */
ino->i_file = handle;
ino->i_flags = I_HANDLE;
if (!strcmp(name, ".") || !strcmp(name, "..")) return EEXIST;
- if ((parent = find_inode(m_in.REQ_INODE_NR)) == NIL_INODE)
+ if ((parent = find_inode(m_in.REQ_INODE_NR)) == NULL)
return EINVAL;
if ((r = verify_dentry(parent, name, path, &ino)) != OK)
r = hgfs_mkdir(path, m_in.REQ_MODE);
if (r != OK) {
- if (ino != NIL_INODE)
+ if (ino != NULL)
put_inode(ino);
return r;
/* If we thought the new dentry already existed, it was apparently gone
* already. Delete it.
*/
- if (ino != NIL_INODE) {
+ if (ino != NULL) {
del_dentry(ino);
put_inode(ino);
if (!strcmp(name, ".") || !strcmp(name, "..")) return EPERM;
- if ((parent = find_inode(m_in.REQ_INODE_NR)) == NIL_INODE)
+ if ((parent = find_inode(m_in.REQ_INODE_NR)) == NULL)
return EINVAL;
if ((r = verify_dentry(parent, name, path, &ino)) != OK)
r = force_remove(path, FALSE /*dir*/);
if (r != OK) {
- if (ino != NIL_INODE)
+ if (ino != NULL)
put_inode(ino);
return r;
}
/* If a dentry existed for this name, it is gone now. */
- if (ino != NIL_INODE) {
+ if (ino != NULL) {
del_dentry(ino);
put_inode(ino);
if (!strcmp(name, ".")) return EINVAL;
if (!strcmp(name, "..")) return ENOTEMPTY;
- if ((parent = find_inode(m_in.REQ_INODE_NR)) == NIL_INODE)
+ if ((parent = find_inode(m_in.REQ_INODE_NR)) == NULL)
return EINVAL;
if ((r = verify_dentry(parent, name, path, &ino)) != OK)
r = force_remove(path, TRUE /*dir*/);
if (r != OK) {
- if (ino != NIL_INODE)
+ if (ino != NULL)
put_inode(ino);
return r;
}
/* If a dentry existed for this name, it is gone now. */
- if (ino != NIL_INODE) {
+ if (ino != NULL) {
del_dentry(ino);
put_inode(ino);
if (!strcmp(old_name, ".") || !strcmp(old_name, "..") ||
!strcmp(new_name, ".") || !strcmp(new_name, "..")) return EINVAL;
- if ((old_parent = find_inode(m_in.REQ_REN_OLD_DIR)) == NIL_INODE ||
- (new_parent = find_inode(m_in.REQ_REN_NEW_DIR)) == NIL_INODE)
+ if ((old_parent = find_inode(m_in.REQ_REN_OLD_DIR)) == NULL ||
+ (new_parent = find_inode(m_in.REQ_REN_NEW_DIR)) == NULL)
return EINVAL;
if ((r = verify_dentry(old_parent, old_name, old_path, &old_ino)) != OK)
return r;
if ((r = verify_dentry(new_parent, new_name, new_path, &new_ino)) != OK) {
- if (old_ino != NIL_INODE)
+ if (old_ino != NULL)
put_inode(old_ino);
return r;
* NULL, or they both refer to the same file.
*/
if (r != OK || old_ino == new_ino) {
- if (old_ino != NIL_INODE) put_inode(old_ino);
+ if (old_ino != NULL) put_inode(old_ino);
- if (new_ino != NIL_INODE) put_inode(new_ino);
+ if (new_ino != NULL) put_inode(new_ino);
return r;
}
/* If the new dentry already existed, it has now been overwritten.
* Delete the associated inode if we had found one.
*/
- if (new_ino != NIL_INODE) {
+ if (new_ino != NULL) {
del_dentry(new_ino);
put_inode(new_ino);
}
/* If the old dentry existed, rename it accordingly. */
- if (old_ino != NIL_INODE) {
+ if (old_ino != NULL) {
del_dentry(old_ino);
add_dentry(new_parent, new_name, old_ino);
pop_path(path);
parent = ino->i_parent;
- assert(parent != NIL_INODE);
+ assert(parent != NULL);
if ((r = verify_path(path, parent, attr, NULL)) != OK)
return r;
dprintf(("HGFS: lookup_dentry('%s') returned %p\n", name, ino));
- if (ino != NIL_INODE)
+ if (ino != NULL)
r = verify_path(path, ino, attr, &stale);
else
r = hgfs_getattr(path, attr);
dprintf(("HGFS: path query returned %d\n", r));
if (r != OK) {
- if (ino != NIL_INODE) {
+ if (ino != NULL) {
put_inode(ino);
- ino = NIL_INODE;
+ ino = NULL;
}
if (!stale)
dprintf(("HGFS: name '%s'\n", name));
- if (ino == NIL_INODE) {
- if ((ino = get_free_inode()) == NIL_INODE)
+ if (ino == NULL) {
+ if ((ino = get_free_inode()) == NULL)
return ENFILE;
dprintf(("HGFS: inode %p ref %d\n", ino, ino->i_ref));
*/
ino_t dir_ino_nr, root_ino_nr;
struct inode *cur_ino, *root_ino;
- struct inode *next_ino = NIL_INODE;
+ struct inode *next_ino = NULL;
struct hgfs_attr attr;
char buf[PATH_MAX], path[PATH_MAX];
char name[NAME_MAX+1];
/* Start the actual lookup. */
dprintf(("HGFS: lookup: got query '%s'\n", buf));
- if ((cur_ino = find_inode(dir_ino_nr)) == NIL_INODE)
+ if ((cur_ino = find_inode(dir_ino_nr)) == NULL)
return EINVAL;
attr.a_mask = HGFS_ATTR_MODE | HGFS_ATTR_SIZE;
if (root_ino_nr > 0)
root_ino = find_inode(root_ino_nr);
else
- root_ino = NIL_INODE;
+ root_ino = NULL;
/* One possible optimization would be to check a path only right before the
* first ".." in a row, and at the very end (if still necessary). This would
if (r != OK)
break;
- assert(next_ino != NIL_INODE);
+ assert(next_ino != NULL);
put_inode(cur_ino);
dprintf(("HGFS: do_unmount\n"));
/* Decrease the reference count of the root inode. */
- if ((ino = find_inode(ROOT_INODE_NR)) == NIL_INODE)
+ if ((ino = find_inode(ROOT_INODE_NR)) == NULL)
return EINVAL;
put_inode(ino);
plen = strlen(prefix);
/* Construct the path right-to-left in a temporary buffer first. */
- for (total = plen; ino != NIL_INODE && !IS_ROOT(ino); ino = ino->i_parent) {
+ for (total = plen; ino != NULL && !IS_ROOT(ino); ino = ino->i_parent) {
len = strlen(ino->i_name);
total += len + 1;
/* If any of the intermediate inodes has no parent, the final inode is no
* longer addressable by name.
*/
- if (ino == NIL_INODE)
+ if (ino == NULL)
return ENOENT;
/* Put the result in the actual buffer. We need the leading slash in the
char *ptr;
int r, chunk;
- if ((ino = find_inode(m_in.REQ_INODE_NR)) == NIL_INODE)
+ if ((ino = find_inode(m_in.REQ_INODE_NR)) == NULL)
return EINVAL;
if (IS_DIR(ino)) return EISDIR;
attr.a_mask = HGFS_ATTR_MODE;
- if ((ino = find_inode(m_in.REQ_INODE_NR)) == NIL_INODE)
+ if ((ino = find_inode(m_in.REQ_INODE_NR)) == NULL)
return EINVAL;
if (m_in.REQ_SEEK_POS_HI != 0) return EINVAL;
}
else if (pos == 1) {
/* Entry for "..", but only when there is a parent. */
- if (ino->i_parent == NIL_INODE)
+ if (ino->i_parent == NULL)
continue;
child = ino->i_parent;
if (!strcmp(name, ".") || !strcmp(name, ".."))
continue;
- if ((child = lookup_dentry(ino, name)) == NIL_INODE) {
+ if ((child = lookup_dentry(ino, name)) == NULL) {
child = get_free_inode();
/* We were promised a free inode! */
- assert(child != NIL_INODE);
+ assert(child != NULL);
child->i_flags = MODE_TO_DIRFLAG(attr.a_mode);
ino_nr = m_in.REQ_INODE_NR;
/* Don't increase the inode refcount: it's already open anyway */
- if ((ino = find_inode(ino_nr)) == NIL_INODE)
+ if ((ino = find_inode(ino_nr)) == NULL)
return EINVAL;
attr.a_mask = HGFS_ATTR_MODE | HGFS_ATTR_SIZE | HGFS_ATTR_ATIME |
* It's just not worth it.
*/
stat.st_nlink = 0;
- if (ino->i_parent != NIL_INODE) stat.st_nlink++;
+ if (ino->i_parent != NULL) stat.st_nlink++;
if (IS_DIR(ino)) {
stat.st_nlink++;
if (HAS_CHILDREN(ino)) stat.st_nlink++;
if (state.read_only)
return EROFS;
- if ((ino = find_inode(m_in.REQ_INODE_NR)) == NIL_INODE)
+ if ((ino = find_inode(m_in.REQ_INODE_NR)) == NULL)
return EINVAL;
if ((r = verify_inode(ino, path, NULL)) != OK)
if (state.read_only)
return EROFS;
- if ((ino = find_inode(m_in.REQ_INODE_NR)) == NIL_INODE)
+ if ((ino = find_inode(m_in.REQ_INODE_NR)) == NULL)
return EINVAL;
if ((r = verify_inode(ino, path, NULL)) != OK)
* directory entry, check whether the path to the parent is still valid, and
* check whether there is an inode pointed to by the full path. Upon success,
* res_ino will contain either the inode for the full path, with increased
- * refcount, or NIL_INODE if no such inode exists.
+ * refcount, or NULL if no such inode exists.
*/
int r;
if (state.read_only)
return EROFS;
- if ((ino = find_inode(m_in.REQ_INODE_NR)) == NIL_INODE)
+ if ((ino = find_inode(m_in.REQ_INODE_NR)) == NULL)
return EINVAL;
if (IS_DIR(ino)) return EISDIR;
if (state.read_only)
return EROFS;
- if ((ino = find_inode(m_in.REQ_INODE_NR)) == NIL_INODE)
+ if ((ino = find_inode(m_in.REQ_INODE_NR)) == NULL)
return EINVAL;
if (IS_DIR(ino)) return EISDIR;
/* A block is free if b_dev == NO_DEV. */
-#define NIL_BUF ((struct buf *) 0) /* indicates absence of a buffer */
/* These defs make it possible to use to bp->b_data instead of bp->b.b__data */
#define b_data b.b__data
{
register struct buf *bp, *free_bp;
- free_bp = NIL_BUF;
+ free_bp = NULL;
/* Find if the block is already loaded */
for (bp = &buf[0]; bp < &buf[NR_BUFS]; bp++)
bp_to_pickup = buf;
}
- if (free_bp == NIL_BUF &&
+ if (free_bp == NULL &&
bp_to_pickup == buf &&
bp_to_pickup->b_count == 0)
free_bp = bp_to_pickup;
- if (free_bp != NIL_BUF) {
+ if (free_bp != NULL) {
/* Set fields of data structure */
free_bp->b_blocknr = block;
- if (read_block(free_bp) != OK) return NIL_BUF;
+ if (read_block(free_bp) != OK) return NULL;
free_bp->b_count = 1;
if (bp_to_pickup < &buf[NR_BUFS] - 1)
return free_bp;
} else {
- /* No free blocks. Return NIL_BUF */
- return NIL_BUF;
+ /* No free blocks. Return NULL */
+ return NULL;
}
}
PUBLIC void put_block(bp)
register struct buf *bp; /* pointer to the buffer to be released */
{
- if (bp == NIL_BUF) return; /* it is easier to check here than in caller */
+ if (bp == NULL) return; /* it is easier to check here than in caller */
bp->b_count--; /* there is one use fewer now */
}
offset = address % block_size; /* Offset starting from the block */
bp = get_block(block_nr); /* Read the block from the device */
- if (bp == NIL_BUF)
+ if (bp == NULL)
return(NULL);
dir = get_free_dir_record(); /* Get a free record */
pos = ldir_ptr->ext_attr_rec_length;
bp = get_block(ldir_ptr->loc_extent_l);
- if (bp == NIL_BUF)
+ if (bp == NULL)
return EINVAL;
while (pos < v_pri.logical_block_size_l) {
while (cur_pos<dir->d_file_size) {
bp = get_block(block); /* Get physical block */
- if (bp == NIL_BUF) {
+ if (bp == NULL) {
release_dir_record(dir);
return(EINVAL);
}
bp = get_block(b);
/* In all cases, bp now points to a valid buffer. */
- if (bp == NIL_BUF) {
+ if (bp == NULL) {
panic("bp not valid in rw_chunk; this can't happen");
}
/* A block is free if b_dev == NO_DEV. */
-#define NIL_BUF ((struct buf *) 0) /* indicates absence of a buffer */
/* These defs make it possible to use to bp->b_data instead of bp->b.b__data */
#define b_data bp->b__data
if (dev != NO_DEV) {
b = BUFHASH(block);
bp = buf_hash[b];
- while (bp != NIL_BUF) {
+ while (bp != NULL) {
if (bp->b_blocknr == block && bp->b_dev == dev) {
/* Block needed has been found. */
if (bp->b_count == 0) rm_lru(bp);
}
/* Desired block is not on available chain. Take oldest block ('front'). */
- if ((bp = front) == NIL_BUF) panic("all buffers in use: %d", nr_bufs);
+ if ((bp = front) == NULL) panic("all buffers in use: %d", nr_bufs);
if(bp->b_bytes < fs_block_size) {
ASSERT(!bp->bp);
buf_hash[b] = bp->b_hash;
} else {
/* The block just taken is not on the front of its hash chain. */
- while (prev_ptr->b_hash != NIL_BUF)
+ while (prev_ptr->b_hash != NULL)
if (prev_ptr->b_hash == bp) {
prev_ptr->b_hash = bp->b_hash; /* found it */
break;
* the integrity of the file system (e.g., inode blocks) are written to
* disk immediately if they are dirty.
*/
- if (bp == NIL_BUF) return; /* it is easier to check here than in caller */
+ if (bp == NULL) return; /* it is easier to check here than in caller */
bp->b_count--; /* there is one use fewer now */
if (bp->b_count != 0) return; /* block is still in use */
/* Block probably won't be needed quickly. Put it on front of chain.
* It will be the next block to be evicted from the cache.
*/
- bp->b_prev = NIL_BUF;
+ bp->b_prev = NULL;
bp->b_next = front;
- if (front == NIL_BUF)
+ if (front == NULL)
rear = bp; /* LRU chain was empty */
else
front->b_prev = bp;
* It will not be evicted from the cache for a long time.
*/
bp->b_prev = rear;
- bp->b_next = NIL_BUF;
- if (rear == NIL_BUF)
+ bp->b_next = NULL;
+ if (rear == NULL)
front = bp;
else
rear->b_next = bp;
bufs_in_use++;
next_ptr = bp->b_next; /* successor on LRU chain */
prev_ptr = bp->b_prev; /* predecessor on LRU chain */
- if (prev_ptr != NIL_BUF)
+ if (prev_ptr != NULL)
prev_ptr->b_next = next_ptr;
else
front = next_ptr; /* this block was at front of chain */
- if (next_ptr != NIL_BUF)
+ if (next_ptr != NULL)
next_ptr->b_prev = prev_ptr;
else
rear = prev_ptr; /* this block was at rear of chain */
bp->bp = NULL;
bp->b_bytes = 0;
}
- buf[0].b_prev = NIL_BUF;
- buf[nr_bufs - 1].b_next = NIL_BUF;
+ buf[0].b_prev = NULL;
+ buf[nr_bufs - 1].b_next = NULL;
for (bp = &buf[0]; bp < &buf[nr_bufs]; bp++) bp->b_hash = bp->b_next;
buf_hash[0] = front;
/* Inode is not on the hash, get a free one */
if (TAILQ_EMPTY(&unused_inodes)) {
err_code = ENFILE;
- return(NIL_INODE);
+ return(NULL);
}
rip = TAILQ_FIRST(&unused_inodes);
}
}
- return(NIL_INODE);
+ return(NULL);
}
* return it to the pool of available inodes.
*/
- if (rip == NIL_INODE) return; /* checking here is easier than in caller */
+ if (rip == NULL) return; /* checking here is easier than in caller */
if (rip->i_count < 1)
panic("put_inode: i_count already below 1: %d", rip->i_count);
sp = get_super(dev); /* get pointer to super_block */
if (sp->s_rd_only) { /* can't allocate an inode on a read only device. */
err_code = EROFS;
- return(NIL_INODE);
+ return(NULL);
}
/* Acquire an inode from the bit map. */
major = (int) (sp->s_dev >> MAJOR) & BYTE;
minor = (int) (sp->s_dev >> MINOR) & BYTE;
printf("Out of i-nodes on device %d/%d\n", major, minor);
- return(NIL_INODE);
+ return(NULL);
}
sp->s_isearch = b; /* next time start here */
inumb = (int) b; /* be careful not to pass unshort as param */
/* Try to acquire a slot in the inode table. */
- if ((rip = get_inode(NO_DEV, inumb)) == NIL_INODE) {
+ if ((rip = get_inode(NO_DEV, inumb)) == NULL) {
/* No inode table slots available. Free the inode just allocated. */
free_bit(sp, IMAP, b);
} else {
EXTERN unsigned int inode_cache_hit;
EXTERN unsigned int inode_cache_miss;
-#define NIL_INODE (struct inode *) 0 /* indicates absence of inode slot */
/* Field values. Note that CLEAN and DIRTY are defined in "const.h" */
#define NO_SEEK 0 /* i_seek = NO_SEEK if last op was not SEEK */
MFS_NUL(string, len, sizeof(string));
/* Temporarily open the file. */
- if( (rip = get_inode(fs_dev, fs_m_in.REQ_INODE_NR)) == NIL_INODE)
+ if( (rip = get_inode(fs_dev, fs_m_in.REQ_INODE_NR)) == NULL)
return(EINVAL);
/* Check to see if the file has maximum number of links already. */
}
/* Temporarily open the last dir */
- if( (ip = get_inode(fs_dev, fs_m_in.REQ_DIR_INO)) == NIL_INODE)
+ if( (ip = get_inode(fs_dev, fs_m_in.REQ_DIR_INO)) == NULL)
return(EINVAL);
/* If 'name2' exists in full (even if no space) set 'r' to error. */
if (r == OK) {
- if((new_ip = advance(ip, string, IGN_PERM)) == NIL_INODE) {
+ if((new_ip = advance(ip, string, IGN_PERM)) == NULL) {
r = err_code;
if(r == ENOENT)
r = OK;
MFS_NUL(string, len, sizeof(string));
/* Temporarily open the dir. */
- if( (rldirp = get_inode(fs_dev, fs_m_in.REQ_INODE_NR)) == NIL_INODE)
+ if( (rldirp = get_inode(fs_dev, fs_m_in.REQ_INODE_NR)) == NULL)
return(EINVAL);
/* The last directory exists. Does the file also exist? */
if (copylen <= 0) return(EINVAL);
/* Temporarily open the file. */
- if( (rip = get_inode(fs_dev, fs_m_in.REQ_INODE_NR)) == NIL_INODE)
+ if( (rip = get_inode(fs_dev, fs_m_in.REQ_INODE_NR)) == NULL)
return(EINVAL);
if(!S_ISLNK(rip->i_mode))
/* Unlink . and .. from the dir. The super user can link and unlink any dir,
* so don't make too many assumptions about them.
*/
- (void) unlink_file(rip, NIL_INODE, dot1);
- (void) unlink_file(rip, NIL_INODE, dot2);
+ (void) unlink_file(rip, NULL, dot1);
+ (void) unlink_file(rip, NULL, dot2);
return(OK);
}
*===========================================================================*/
PRIVATE int unlink_file(dirp, rip, file_name)
struct inode *dirp; /* parent directory of file */
-struct inode *rip; /* inode of file, may be NIL_INODE too. */
+struct inode *rip; /* inode of file, may be NULL too. */
char file_name[NAME_MAX]; /* name of file to be removed */
{
-/* Unlink 'file_name'; rip must be the inode of 'file_name' or NIL_INODE. */
+/* Unlink 'file_name'; rip must be the inode of 'file_name' or NULL. */
ino_t numb; /* inode number */
int r;
- /* If rip is not NIL_INODE, it is used to get faster access to the inode. */
- if (rip == NIL_INODE) {
+ /* If rip is not NULL, it is used to get faster access to the inode. */
+ if (rip == NULL) {
/* Search for file in directory and try to get its inode. */
err_code = search_dir(dirp, file_name, &numb, LOOK_UP, IGN_PERM);
if (err_code == OK) rip = get_inode(dirp->i_dev, (int) numb);
- if (err_code != OK || rip == NIL_INODE) return(err_code);
+ if (err_code != OK || rip == NULL) return(err_code);
} else {
dup_inode(rip); /* inode will be returned with put_inode */
}
MFS_NUL(new_name, len, sizeof(new_name));
/* Get old dir inode */
- if( (old_dirp = get_inode(fs_dev, fs_m_in.REQ_REN_OLD_DIR)) == NIL_INODE)
+ if( (old_dirp = get_inode(fs_dev, fs_m_in.REQ_REN_OLD_DIR)) == NULL)
return(err_code);
old_ip = advance(old_dirp, old_name, IGN_PERM);
}
/* Get new dir inode */
- if( (new_dirp = get_inode(fs_dev, fs_m_in.REQ_REN_NEW_DIR)) == NIL_INODE)
+ if( (new_dirp = get_inode(fs_dev, fs_m_in.REQ_REN_NEW_DIR)) == NULL)
r = err_code;
new_ip = advance(new_dirp, new_name, IGN_PERM); /* not required to exist */
r = EBUSY;
}
- if(old_ip != NIL_INODE)
+ if(old_ip != NULL)
odir = ((old_ip->i_mode & I_TYPE) == I_DIRECTORY); /* TRUE iff dir */
else
odir = FALSE; /* FIXME: is this a safe default? */
break;
}
new_superdirp = next_new_superdirp;
- if(new_superdirp == NIL_INODE) {
+ if(new_superdirp == NULL) {
/* Missing ".." entry. Assume the worst. */
r = EINVAL;
break;
if(old_dirp->i_dev != new_dirp->i_dev) r = EXDEV; */
/* Some tests apply only if the new path exists. */
- if(new_ip == NIL_INODE) {
+ if(new_ip == NULL) {
/* don't rename a file with a file system mounted on it.
if (old_ip->i_dev != old_dirp->i_dev) r = EXDEV;*/
if(odir && new_dirp->i_nlinks >=
* is completely full].
*/
if(r == OK) {
- if(new_ip != NIL_INODE) {
+ if(new_ip != NULL) {
/* There is already an entry for 'new'. Try to remove it. */
if(odir)
r = remove_dir(new_dirp, new_ip, new_name);
if(r == OK && odir && !same_pdir) {
/* Update the .. entry in the directory (still points to old_dirp).*/
numb = new_dirp->i_num;
- (void) unlink_file(old_ip, NIL_INODE, dot2);
+ (void) unlink_file(old_ip, NULL, dot2);
if(search_dir(old_ip, dot2, &numb, ENTER, IGN_PERM) == OK) {
/* New link created. */
new_dirp->i_nlinks++;
off_t start, end;
int r;
- if( (rip = find_inode(fs_dev, fs_m_in.REQ_INODE_NR)) == NIL_INODE)
+ if( (rip = find_inode(fs_dev, fs_m_in.REQ_INODE_NR)) == NULL)
return(EINVAL);
start = fs_m_in.REQ_TRC_START_LO;
if(!len) return; /* no zeroing to be done. */
if( (b = read_map(rip, pos)) == NO_BLOCK) return;
while (len > 0) {
- if( (bp = get_block(rip->i_dev, b, NORMAL)) == NIL_BUF)
+ if( (bp = get_block(rip->i_dev, b, NORMAL)) == NULL)
panic("zerozone_range: no block");
offset = pos % block_size;
bytes = block_size - offset;
fs_m_out.m_type = error;
reply(src, &fs_m_out);
- if (error == OK && rdahed_inode != NIL_INODE)
+ if (error == OK && rdahed_inode != NULL)
read_ahead(); /* do block read ahead */
}
set_blocksize(superblock.s_block_size);
/* Get the root inode of the mounted file system. */
- if( (root_ip = get_inode(fs_dev, ROOT_INODE)) == NIL_INODE) {
+ if( (root_ip = get_inode(fs_dev, ROOT_INODE)) == NULL) {
printf("MFS: couldn't get root inode\n");
superblock.s_dev = NO_DEV;
dev_close(driver_e, fs_dev);
return(EINVAL);
}
- if(root_ip != NIL_INODE && root_ip->i_mode == 0) {
+ if(root_ip != NULL && root_ip->i_mode == 0) {
printf("%s:%d zero mode for root inode?\n", __FILE__, __LINE__);
put_inode(root_ip);
superblock.s_dev = NO_DEV;
mode_t bits;
/* Temporarily open the file. */
- if( (rip = get_inode(fs_dev, fs_m_in.REQ_INODE_NR)) == NIL_INODE)
+ if( (rip = get_inode(fs_dev, fs_m_in.REQ_INODE_NR)) == NULL)
return(EINVAL);
for (rip = &inode[0]; rip < &inode[NR_INODES]; rip++)
if (rip->i_count > 0 && rip->i_dev == fs_dev) count += rip->i_count;
- if ((root_ip = find_inode(fs_dev, ROOT_INODE)) == NIL_INODE) {
+ if ((root_ip = find_inode(fs_dev, ROOT_INODE)) == NULL) {
printf("MFS: couldn't find root inode. Unmount failed.\n");
panic("MFS: couldn't find root inode: %d", EINVAL);
return(EINVAL);
MFS_NUL(lastc, len, sizeof(lastc));
/* Get last directory inode (i.e., directory that will hold the new inode) */
- if ((ldirp = get_inode(fs_dev, fs_m_in.REQ_INODE_NR)) == NIL_INODE)
+ if ((ldirp = get_inode(fs_dev, fs_m_in.REQ_INODE_NR)) == NULL)
return(ENOENT);
/* Create a new inode by calling new_node(). */
caller_gid = fs_m_in.REQ_GID;
/* Get last directory inode */
- if((ldirp = get_inode(fs_dev, fs_m_in.REQ_INODE_NR)) == NIL_INODE)
+ if((ldirp = get_inode(fs_dev, fs_m_in.REQ_INODE_NR)) == NULL)
return(ENOENT);
/* Try to create the new node */
caller_gid = fs_m_in.REQ_GID;
/* Get last directory inode */
- if((ldirp = get_inode(fs_dev, fs_m_in.REQ_INODE_NR)) == NIL_INODE)
+ if((ldirp = get_inode(fs_dev, fs_m_in.REQ_INODE_NR)) == NULL)
return(ENOENT);
/* Next make the inode. If that fails, return error code. */
rip = new_node(ldirp, lastc, fs_m_in.REQ_MODE, (zone_t) 0);
- if(rip == NIL_INODE || err_code == EEXIST) {
+ if(rip == NULL || err_code == EEXIST) {
put_inode(rip); /* can't make dir: it already exists */
put_inode(ldirp);
return(err_code);
MFS_NUL(string, len, sizeof(string));
/* Temporarily open the dir. */
- if( (ldirp = get_inode(fs_dev, fs_m_in.REQ_INODE_NR)) == NIL_INODE)
+ if( (ldirp = get_inode(fs_dev, fs_m_in.REQ_INODE_NR)) == NULL)
return(EINVAL);
/* Create the inode for the symlink. */
/* Allocate a disk block for the contents of the symlink.
* Copy contents of symlink (the name pointed to) into first disk block. */
if( (r = err_code) == OK) {
- r = (bp = new_block(sip, (off_t) 0)) == NIL_BUF ? err_code :
+ r = (bp = new_block(sip, (off_t) 0)) == NULL ? err_code :
sys_safecopyfrom(FS_PROC_NR, fs_m_in.REQ_GRANT3, 0,
(vir_bytes) bp->b_data,
(vir_bytes) fs_m_in.REQ_MEM_SIZE, D);
}
}
- put_block(bp, DIRECTORY_BLOCK); /* put_block() accepts NIL_BUF. */
+ put_block(bp, DIRECTORY_BLOCK); /* put_block() accepts NULL. */
if(r != OK) {
sip->i_nlinks = 0;
}
}
- /* put_inode() accepts NIL_INODE as a noop, so the below are safe. */
+ /* put_inode() accepts NULL as a noop, so the below are safe. */
put_inode(sip);
put_inode(ldirp);
* In all cases it allocates a new inode, makes a directory entry for it in
* the ldirp directory with string name, and initializes it.
* It returns a pointer to the inode if it can do this;
- * otherwise it returns NIL_INODE. It always sets 'err_code'
+ * otherwise it returns NULL. It always sets 'err_code'
* to an appropriate value (OK or an error code).
*
* The parsed path rest is returned in 'parsed' if parsed is nonzero. It
/* New entry is a directory, alas we can't give it a ".." */
put_inode(rip);
err_code = EMLINK;
- return(NIL_INODE);
+ return(NULL);
}
- if ( rip == NIL_INODE && err_code == ENOENT) {
+ if ( rip == NULL && err_code == ENOENT) {
/* Last path component does not exist. Make new directory entry. */
- if ( (rip = alloc_inode((ldirp)->i_dev, bits)) == NIL_INODE) {
+ if ( (rip = alloc_inode((ldirp)->i_dev, bits)) == NULL) {
/* Can't creat new inode: out of inodes. */
- return(NIL_INODE);
+ return(NULL);
}
/* Force inode to the disk before making directory entry to make
rip->i_dirt = DIRTY; /* dirty inodes are written out */
put_inode(rip); /* this call frees the inode */
err_code = r;
- return(NIL_INODE);
+ return(NULL);
}
} else if (err_code == EENTERMOUNT || err_code == ELEAVEMOUNT) {
r = EEXIST;
} else {
/* Either last component exists, or there is some problem. */
- if (rip != NIL_INODE)
+ if (rip != NULL)
r = EEXIST;
else
r = err_code;
{
struct inode *rip;
- if((rip = find_inode(fs_dev, fs_m_in.REQ_INODE_NR)) == NIL_INODE)
+ if((rip = find_inode(fs_dev, fs_m_in.REQ_INODE_NR)) == NULL)
return(EINVAL);
/* inhibit read ahead */
*symlinkp = 0;
/* Find starting inode inode according to the request message */
- if((rip = find_inode(fs_dev, dir_ino)) == NIL_INODE)
+ if((rip = find_inode(fs_dev, dir_ino)) == NULL)
return(ENOENT);
/* If dir has been removed return ENOENT. */
struct buf *bp; /* buffer containing link text */
char *sp; /* start of link text */
- bp = NIL_BUF;
+ bp = NULL;
if ((blink = read_map(rip, (off_t) 0)) == NO_BLOCK)
return(EIO);
/* If 'string' is empty, return an error. */
if (string[0] == '\0') {
err_code = ENOENT;
- return(NIL_INODE);
+ return(NULL);
}
- /* Check for NIL_INODE. */
- if (dirp == NIL_INODE) return(NIL_INODE);
+ /* Check for NULL. */
+ if (dirp == NULL) return(NULL);
/* If 'string' is not present in the directory, signal error. */
if ( (err_code = search_dir(dirp, string, &numb, LOOK_UP, chk_perm)) != OK) {
- return(NIL_INODE);
+ return(NULL);
}
/* The component has been found in the directory. Get inode. */
- if ( (rip = get_inode(dirp->i_dev, (int) numb)) == NIL_INODE) {
- return(NIL_INODE);
+ if ( (rip = get_inode(dirp->i_dev, (int) numb)) == NULL) {
+ return(NULL);
}
/* The following test is for "mountpoint/.." where mountpoint is a
* mounted file system. The super_block provides the linkage between the
* inode mounted on and the root directory of the mounted file system.
*/
- if (rip != NIL_INODE && rip->i_mountpoint) {
+ if (rip != NULL && rip->i_mountpoint) {
/* Mountpoint encountered, report it */
err_code = EENTERMOUNT;
}
if (e_hit == FALSE) { /* directory is full and no room left in last block */
new_slots++; /* increase directory size by 1 entry */
if (new_slots == 0) return(EFBIG); /* dir size limited by slot count */
- if ( (bp = new_block(ldir_ptr, ldir_ptr->i_size)) == NIL_BUF)
+ if ( (bp = new_block(ldir_ptr, ldir_ptr->i_size)) == NULL)
return(err_code);
dp = &bp->b_dir[0];
extended = 1;
register struct inode *rip;
/* Temporarily open the file. */
- if( (rip = get_inode(fs_dev, fs_m_in.REQ_INODE_NR)) == NIL_INODE)
+ if( (rip = get_inode(fs_dev, fs_m_in.REQ_INODE_NR)) == NULL)
return(EINVAL);
/* Now make the change. Clear setgid bit if file is not in caller's grp */
register int r;
/* Temporarily open the file. */
- if( (rip = get_inode(fs_dev, fs_m_in.REQ_INODE_NR)) == NIL_INODE)
+ if( (rip = get_inode(fs_dev, fs_m_in.REQ_INODE_NR)) == NULL)
return(EINVAL);
/* Not permitted to change the owner of a file on a read-only file sys. */
r = OK;
/* Find the inode referred */
- if ((rip = find_inode(fs_dev, fs_m_in.REQ_INODE_NR)) == NIL_INODE)
+ if ((rip = find_inode(fs_dev, fs_m_in.REQ_INODE_NR)) == NULL)
return(EINVAL);
mode_word = rip->i_mode & I_TYPE;
zero_block(bp);
} else {
/* Writing to a nonexistent block. Create and enter in inode.*/
- if ((bp= new_block(rip, ex64lo(position))) == NIL_BUF)
+ if ((bp= new_block(rip, ex64lo(position))) == NULL)
return(err_code);
}
} else if (rw_flag == READING) {
}
/* In all cases, bp now points to a valid buffer. */
- if (bp == NIL_BUF)
+ if (bp == NULL)
panic("bp not valid in rw_chunk; this can't happen");
if (rw_flag == WRITING && chunk != block_size && !block_spec &&
struct super_block *sp;
zone_t zone; /* V2 zones are longs (shorts in V1) */
- if(bp == NIL_BUF)
- panic("rd_indir() on NIL_BUF");
+ if(bp == NULL)
+ panic("rd_indir() on NULL");
sp = get_super(bp->b_dev); /* need super block to find file sys type */
rip = rdahed_inode; /* pointer to inode to read ahead from */
block_size = get_block_size(rip->i_dev);
- rdahed_inode = NIL_INODE; /* turn off read ahead */
+ rdahed_inode = NULL; /* turn off read ahead */
if ( (b = read_map(rip, rdahedpos)) == NO_BLOCK) return; /* at EOF */
bp = rahead(rip, b, cvul64(rdahedpos), block_size);
put_block(bp, PARTIAL_DATA_BLOCK);
if(pos % DIR_ENTRY_SIZE)
return(ENOENT);
- if( (rip = get_inode(fs_dev, ino)) == NIL_INODE)
+ if( (rip = get_inode(fs_dev, ino)) == NULL)
return(EINVAL);
block_size = rip->i_sp->s_block_size;
struct inode *rip;
int r;
- if((rip = find_inode(fs_dev, ROOT_INODE)) == NIL_INODE)
+ if((rip = find_inode(fs_dev, ROOT_INODE)) == NULL)
return(EINVAL);
st.f_bsize = rip->i_sp->s_block_size;
register int r; /* return value */
register struct inode *rip; /* target inode */
- if ((rip = get_inode(fs_dev, fs_m_in.REQ_INODE_NR)) == NIL_INODE)
+ if ((rip = get_inode(fs_dev, fs_m_in.REQ_INODE_NR)) == NULL)
return(EINVAL);
r = stat_inode(rip, fs_m_in.m_source, fs_m_in.REQ_GRANT);
char s_is_root;
} superblock;
-#define NIL_SUPER (struct super_block *) 0
#define IMAP 0 /* operating on the inode bit map */
#define ZMAP 1 /* operating on the zone bit map */
register int r;
/* Temporarily open the file. */
- if( (rip = get_inode(fs_dev, fs_m_in.REQ_INODE_NR)) == NIL_INODE)
+ if( (rip = get_inode(fs_dev, fs_m_in.REQ_INODE_NR)) == NULL)
return(EINVAL);
/* Only the owner of a file or the super_user can change its time. */
zone_t z, z1, z2 = NO_ZONE, old_zone;
register block_t b;
long excess, zone;
- struct buf *bp_dindir = NIL_BUF, *bp = NIL_BUF;
+ struct buf *bp_dindir = NULL, *bp = NULL;
rip->i_dirt = DIRTY; /* inode will be changed */
scale = rip->i_sp->s_log_zone_size; /* for zone-block conversion */
new_ind = TRUE;
/* If double ind, it is dirty. */
- if (bp_dindir != NIL_BUF) bp_dindir->b_dirt = DIRTY;
+ if (bp_dindir != NULL) bp_dindir->b_dirt = DIRTY;
if (z1 == NO_ZONE) {
/* Release dbl indirect blk. */
put_block(bp_dindir, INDIRECT_BLOCK);
struct super_block *sp;
- if(bp == NIL_BUF)
- panic("wr_indir() on NIL_BUF");
+ if(bp == NULL)
+ panic("wr_indir() on NULL");
sp = get_super(bp->b_dev); /* need super block to find file sys type */
/* searched before, start from last find */
z = rip->i_zsearch;
}
- if ( (z = alloc_zone(rip->i_dev, z)) == NO_ZONE) return(NIL_BUF);
+ if ( (z = alloc_zone(rip->i_dev, z)) == NO_ZONE) return(NULL);
rip->i_zsearch = z; /* store for next lookup */
if ( (r = write_map(rip, position, z, 0)) != OK) {
free_zone(rip->i_dev, z);
err_code = r;
- return(NIL_BUF);
+ return(NULL);
}
/* If we are not writing at EOF, clear the zone, just to be safe. */
/* A block is free if b_dev == NO_DEV. */
-#define NIL_BUF ((struct buf *) 0) /* indicates absence of a buffer */
#define BUFHASH(b) ((b) % NR_BUFS)
{
/* Initialize the buffer pool. */
- front = NIL_BUF;
- rear = NIL_BUF;
+ front = NULL;
+ rear = NULL;
}
{
struct buf *bp = front;
- while(bp != NIL_BUF) {
+ while(bp != NULL) {
if (bp->b_dev == dev && bp->b_num == inum) {
bp->b_count++;
return(bp);
bp = malloc(sizeof(struct buf));
if (bp == NULL) {
err_code = ENOSPC;
- return(NIL_BUF);
+ return(NULL);
}
bp->b_num = inum;
bp->b_dev = dev;
memset(bp->b_data, 0 , PIPE_BUF);
/* Add at the end of the buffer */
- if (front == NIL_BUF) { /* Empty list? */
+ if (front == NULL) { /* Empty list? */
front = bp;
- bp->b_prev = NIL_BUF;
+ bp->b_prev = NULL;
} else {
rear->b_next = bp;
bp->b_prev = rear;
}
- bp->b_next = NIL_BUF;
+ bp->b_next = NULL;
rear = bp;
return(bp);
struct buf *bp;
bp = get_block(dev, inum);
- if (bp == NIL_BUF) return; /* We didn't find the block. Nothing to put. */
+ if (bp == NULL) return; /* We didn't find the block. Nothing to put. */
bp->b_count--; /* Compensate for above 'get_block'. */
if (--bp->b_count > 0) return;
/* Cut bp out of the loop */
- if (bp->b_prev == NIL_BUF)
+ if (bp->b_prev == NULL)
front = bp->b_next;
else
bp->b_prev->b_next = bp->b_next;
- if (bp->b_next == NIL_BUF)
+ if (bp->b_next == NULL)
rear = bp->b_prev;
else
bp->b_next->b_prev = bp->b_prev;
/* Inode is not on the hash, get a free one */
if (TAILQ_EMPTY(&unused_inodes)) {
err_code = ENFILE;
- return(NIL_INODE);
+ return(NULL);
}
rip = TAILQ_FIRST(&unused_inodes);
}
}
- return(NIL_INODE);
+ return(NULL);
}
* return it to the pool of available inodes.
*/
- if (rip == NIL_INODE) return; /* checking here is easier than in caller */
+ if (rip == NULL) return; /* checking here is easier than in caller */
if (rip->i_count < 1)
panic("put_inode: i_count already below 1: %d", rip->i_count);
if (b == NO_BIT) {
err_code = ENOSPC;
printf("PipeFS is out of inodes\n");
- return(NIL_INODE);
+ return(NULL);
}
i_num = (ino_t) b;
/* Try to acquire a slot in the inode table. */
- if ((rip = get_inode(dev, i_num)) == NIL_INODE) {
+ if ((rip = get_inode(dev, i_num)) == NULL) {
/* No inode table slots available. Free the inode if just allocated.*/
if (dev == NO_DEV) free_bit(b);
} else {
/* inode hashtable */
EXTERN LIST_HEAD(inodelist, inode) hash_inodes[INODE_HASH_SIZE];
-#define NIL_INODE (struct inode *) 0 /* indicates absence of inode slot */
inumb = fs_m_in.REQ_INODE_NR;
- if( (rip = find_inode(inumb)) == NIL_INODE) return(EINVAL);
+ if( (rip = find_inode(inumb)) == NULL) return(EINVAL);
start = fs_m_in.REQ_TRC_START_LO;
end = fs_m_in.REQ_TRC_END_LO;
dev = fs_m_in.REQ_DEV;
/* Try to allocate the inode */
- if( (rip = alloc_inode(dev, bits) ) == NIL_INODE) return(err_code);
+ if( (rip = alloc_inode(dev, bits) ) == NULL) return(err_code);
switch (bits & S_IFMT) {
case S_IFBLK:
rip->i_rdev = dev; /* Major/minor dev numbers */
break;
case S_IFIFO:
- if ((get_block(dev, rip->i_num)) == NIL_BUF)
+ if ((get_block(dev, rip->i_num)) == NULL)
r = EIO;
break;
default:
rw_flag = (fs_m_in.m_type == REQ_READ ? READING : WRITING);
/* Find the inode referred */
- if ((rip = find_inode(inumb)) == NIL_INODE) return(EINVAL);
+ if ((rip = find_inode(inumb)) == NULL) return(EINVAL);
mode_word = rip->i_mode & I_TYPE;
if (mode_word != I_NAMED_PIPE) return(EIO);
}
/* Mark inode in use */
- if ((get_inode(rip->i_dev, rip->i_num)) == NIL_INODE) return(err_code);
- if ((bp = get_block(rip->i_dev, rip->i_num)) == NIL_BUF) return(err_code);
+ if ((get_inode(rip->i_dev, rip->i_num)) == NULL) return(err_code);
+ if ((bp = get_block(rip->i_dev, rip->i_num)) == NULL) return(err_code);
if (rw_flag == READING) {
/* Copy a chunk from the block buffer to user space. */
register int r; /* return value */
register struct inode *rip; /* target inode */
- if( (rip = find_inode(fs_m_in.REQ_INODE_NR)) == NIL_INODE) return(EINVAL);
+ if( (rip = find_inode(fs_m_in.REQ_INODE_NR)) == NULL) return(EINVAL);
get_inode(rip->i_dev, rip->i_num); /* mark inode in use */
r = stat_inode(rip, fs_m_in.m_source, fs_m_in.REQ_GRANT);
put_inode(rip); /* release the inode */
#endif
if (m_in.pid >= 0) { /* lookup process by pid */
- if ((rmp = find_proc(m_in.pid)) != NIL_MPROC) {
+ if ((rmp = find_proc(m_in.pid)) != NULL) {
mp->mp_reply.PM_ENDPT = rmp->mp_endpoint;
#if 0
printf("PM: pid result: %d\n", rmp->mp_endpoint);
if (arg_who == 0)
rmp = mp;
else
- if ((rmp = find_proc(arg_who)) == NIL_MPROC)
+ if ((rmp = find_proc(arg_who)) == NULL)
return(ESRCH);
if (mp->mp_effuid != SUPER_USER &&
#define DELAY_CALL 0x20000 /* waiting for call before sending signal */
#define PM_SCHEDULED 0x40000 /* this process is scheduled by PM */
-#define NIL_MPROC ((struct mproc *) 0)
return(OK);
case T_ATTACH: /* attach to an existing process */
- if ((child = find_proc(m_in.pid)) == NIL_MPROC) return(ESRCH);
+ if ((child = find_proc(m_in.pid)) == NULL) return(ESRCH);
if (child->mp_flags & EXITING) return(ESRCH);
/* For non-root processes, user and group ID must match. */
case T_READB_INS: /* special hack for reading text segments */
if (mp->mp_effuid != SUPER_USER) return(EPERM);
- if ((child = find_proc(m_in.pid)) == NIL_MPROC) return(ESRCH);
+ if ((child = find_proc(m_in.pid)) == NULL) return(ESRCH);
if (child->mp_flags & EXITING) return(ESRCH);
r = sys_trace(req, child->mp_endpoint, m_in.PMTRACE_ADDR, &m_in.data);
case T_WRITEB_INS: /* special hack for patching text segments */
if (mp->mp_effuid != SUPER_USER) return(EPERM);
- if ((child = find_proc(m_in.pid)) == NIL_MPROC) return(ESRCH);
+ if ((child = find_proc(m_in.pid)) == NULL) return(ESRCH);
if (child->mp_flags & EXITING) return(ESRCH);
#if 0
/* All the other calls are made by the tracing process to control execution
* of the child. For all these calls, the child must be stopped.
*/
- if ((child = find_proc(m_in.pid)) == NIL_MPROC) return(ESRCH);
+ if ((child = find_proc(m_in.pid)) == NULL) return(ESRCH);
if (child->mp_flags & EXITING) return(ESRCH);
if (child->mp_tracer != who_p) return(ESRCH);
if (!(child->mp_flags & STOPPED)) return(EBUSY);
if ((rmp->mp_flags & IN_USE) && rmp->mp_pid == lpid)
return(rmp);
- return(NIL_MPROC);
+ return(NULL);
}
/*===========================================================================*
/* Magic process table addresses. */
#define BEG_RPROC_ADDR (&rproc[0])
#define END_RPROC_ADDR (&rproc[NR_SYS_PROCS])
-#define NIL_RPROC ((struct mproc *) 0)
/* Constants for live update. */
#define RS_DEFAULT_PREPARE_MAXTIME 2*RS_DELTA_T /* default prepare max time */
register struct vnode *vp;
dev_t dev;
- if ((f = get_filp(m_in.ls_fd)) == NIL_FILP) return(err_code);
+ if ((f = get_filp(m_in.ls_fd)) == NULL) return(err_code);
vp = f->filp_vno; /* get vnode pointer */
if ((vp->v_mode & I_TYPE) != I_CHAR_SPECIAL &&
(vp->v_mode & I_TYPE) != I_BLOCK_SPECIAL) return(ENOTTY);
vp = fp->fp_filp[m_in.fd]->filp_vno;
put_vnode(vp);
- if ((vp = get_free_vnode()) == NIL_VNODE)
+ if ((vp = get_free_vnode()) == NULL)
vp = fp->fp_filp[m_in.fd]->filp_vno;
vp->v_fs_e = res.fs_e;
- vp->v_vmnt = NIL_VMNT;
+ vp->v_vmnt = NULL;
vp->v_dev = NO_DEV;
vp->v_fs_e = res.fs_e;
vp->v_inode_nr = res.inode_nr;
progname[PROC_NAME_LEN-1] = '\0';
/* Open executable */
- if ((vp = eat_path(PATH_NOFLAGS)) == NIL_VNODE) return(err_code);
+ if ((vp = eat_path(PATH_NOFLAGS)) == NULL) return(err_code);
if ((vp->v_mode & I_TYPE) != I_REGULAR)
r = ENOEXEC;
* keep state.
*/
-#define NIL_FILP (struct filp *) 0 /* indicates absence of a filp slot */
/* Search the fproc fp_filp table for a free file descriptor. */
for (i = start; i < OPEN_MAX; i++) {
- if (fp->fp_filp[i] == NIL_FILP && !FD_ISSET(i, &fp->fp_filp_inuse)) {
+ if (fp->fp_filp[i] == NULL && !FD_ISSET(i, &fp->fp_filp_inuse)) {
/* A file descriptor has been located. */
*k = i;
break;
/* See if 'fild' refers to a valid file descr. If so, return its filp ptr. */
err_code = EBADF;
- if (fild < 0 || fild >= OPEN_MAX ) return(NIL_FILP);
- if (rfp->fp_filp[fild] == NIL_FILP && FD_ISSET(fild, &rfp->fp_filp_inuse))
+ if (fild < 0 || fild >= OPEN_MAX ) return(NULL);
+ if (rfp->fp_filp[fild] == NULL && FD_ISSET(fild, &rfp->fp_filp_inuse))
err_code = EIO; /* The filedes is not there, but is not closed either.
*/
- return(rfp->fp_filp[fild]); /* may also be NIL_FILP */
+ return(rfp->fp_filp[fild]); /* may also be NULL */
}
}
/* If control passes here, the filp wasn't there. Report that back. */
- return(NIL_FILP);
+ return(NULL);
}
/*===========================================================================*
if(fproc[f].fp_pid == PID_FREE) continue;
for(fd = 0; fd < OPEN_MAX; fd++) {
if(fproc[f].fp_filp[fd] && fproc[f].fp_filp[fd] == fp) {
- fproc[f].fp_filp[fd] = NIL_FILP;
+ fproc[f].fp_filp[fd] = NULL;
n++;
}
}
/* See if 'name1' (file to be linked to) exists. */
if(fetch_name(m_in.name1, m_in.name1_length, M1) != OK) return(err_code);
- if ((vp = eat_path(PATH_NOFLAGS)) == NIL_VNODE) return(err_code);
+ if ((vp = eat_path(PATH_NOFLAGS)) == NULL) return(err_code);
/* Does the final directory of 'name2' exist? */
if (fetch_name(m_in.name2, m_in.name2_length, M1) != OK)
r = err_code;
- else if ((vp_d = last_dir()) == NIL_VNODE)
+ else if ((vp_d = last_dir()) == NULL)
r = err_code;
if (r != OK) {
put_vnode(vp);
/* Get the last directory in the path. */
if(fetch_name(m_in.name, m_in.name_length, M3) != OK) return(err_code);
- if ((vldirp = last_dir()) == NIL_VNODE) return(err_code);
+ if ((vldirp = last_dir()) == NULL) return(err_code);
/* Make sure that the object is a directory */
if((vldirp->v_mode & I_TYPE) != I_DIRECTORY) {
if ((vldirp->v_mode & S_ISVTX) == S_ISVTX) {
/* Look up inode of file to unlink to retrieve owner */
vp = advance(vldirp, PATH_RET_SYMLINK);
- if (vp != NIL_VNODE) {
+ if (vp != NULL) {
if(vp->v_uid != fp->fp_effuid && fp->fp_effuid != SU_UID)
r = EPERM;
put_vnode(vp);
/* See if 'name1' (existing file) exists. Get dir and file inodes. */
if(fetch_name(m_in.name1, m_in.name1_length, M1) != OK) return(err_code);
- if ((old_dirp = last_dir()) == NIL_VNODE) return(err_code);
+ if ((old_dirp = last_dir()) == NULL) return(err_code);
/* If the sticky bit is set, only the owner of the file or a privileged
user is allowed to rename */
if((old_dirp->v_mode & S_ISVTX) == S_ISVTX) {
/* Look up inode of file to unlink to retrieve owner */
vp = advance(old_dirp, PATH_RET_SYMLINK);
- if (vp != NIL_VNODE) {
+ if (vp != NULL) {
if(vp->v_uid != fp->fp_effuid && fp->fp_effuid != SU_UID)
r = EPERM;
put_vnode(vp);
/* See if 'name2' (new name) exists. Get dir inode */
if(fetch_name(m_in.name2, m_in.name2_length, M1) != OK)
r = err_code;
- else if ((new_dirp = last_dir()) == NIL_VNODE)
+ else if ((new_dirp = last_dir()) == NULL)
r = err_code;
if (r != OK) {
put_vnode(old_dirp);
/* Temporarily open file */
if (fetch_name(m_in.m2_p1, m_in.m2_i1, M1) != OK) return(err_code);
- if ((vp = eat_path(PATH_NOFLAGS)) == NIL_VNODE) return(err_code);
+ if ((vp = eat_path(PATH_NOFLAGS)) == NULL) return(err_code);
/* Ask FS to truncate the file */
if ((r = forbidden(vp, W_BIT)) == OK)
if ((off_t) m_in.flength < 0) return(EINVAL);
/* File is already opened; get a vnode pointer from filp */
- if ((rfilp = get_filp(m_in.m2_i1)) == NIL_FILP) return(err_code);
+ if ((rfilp = get_filp(m_in.m2_i1)) == NULL) return(err_code);
if (!(rfilp->filp_mode & W_BIT)) return(EBADF);
return truncate_vnode(rfilp->filp_vno, m_in.flength);
}
/* Get dir inode of 'name2' */
if(fetch_name(m_in.name2, m_in.name2_length, M1) != OK) return(err_code);
- if ((vp = last_dir()) == NIL_VNODE) return(err_code);
+ if ((vp = last_dir()) == NULL) return(err_code);
if ((r = forbidden(vp, W_BIT|X_BIT)) == OK) {
r = req_slink(vp->v_fs_e, vp->v_inode_nr, user_fullpath, who_e,
/* Temporarily open the file containing the symbolic link */
if(fetch_name(m_in.name1, m_in.name1_length, M1) != OK) return(err_code);
- if ((vp = eat_path(PATH_RET_SYMLINK)) == NIL_VNODE) return(err_code);
+ if ((vp = eat_path(PATH_RET_SYMLINK)) == NULL) return(err_code);
/* Make sure this is a symbolic link */
if((vp->v_mode & I_TYPE) != I_SYMBOLIC_LINK)
if (last < first) return(EINVAL);
/* Check if this region conflicts with any existing lock. */
- empty = NIL_LOCK;
+ empty = NULL;
for (flp = &file_lock[0]; flp < &file_lock[NR_LOCKS]; flp++) {
if (flp->lock_type == 0) {
- if (empty == NIL_LOCK) empty = flp;
+ if (empty == NULL) empty = flp;
continue; /* 0 means unused slot */
}
if (flp->lock_vnode != f->filp_vno) continue; /* different file */
if (ltype == F_UNLCK) return(OK); /* unlocked a region with no locks */
/* There is no conflict. If space exists, store new lock in the table. */
- if (empty == NIL_LOCK) return(ENOLCK); /* table full */
+ if (empty == NULL) return(ENOLCK); /* table full */
empty->lock_type = ltype;
empty->lock_pid = fp->fp_pid;
empty->lock_vnode = f->filp_vno;
off_t lock_last; /* offset of last byte locked */
} file_lock[NR_LOCKS];
-#define NIL_LOCK (struct file_lock *) 0
vmp = &vmnt[0];
/* We'll need a vnode for the root inode, check whether there is one */
- if ((root_node = get_free_vnode()) == NIL_VNODE)
+ if ((root_node = get_free_vnode()) == NULL)
panic("Cannot get free vnode: %d", r);
/* Is the file descriptor valid? */
rfd = m_in.fd & ~DUP_MASK; /* kill off dup2 bit, if on */
- if ((f = get_filp(rfd)) == NIL_FILP) return(err_code);
+ if ((f = get_filp(rfd)) == NULL) return(err_code);
/* Distinguish between dup and dup2. */
if (m_in.fd == rfd) { /* bit not on */
struct filp *dummy;
/* Is the file descriptor valid? */
- if ((f = get_filp(m_in.fd)) == NIL_FILP) return(err_code);
+ if ((f = get_filp(m_in.fd)) == NULL) return(err_code);
switch (m_in.request) {
case F_DUPFD:
fp = &fproc[parentno];
for (i = 0; i < OPEN_MAX; i++)
- if (cp->fp_filp[i] != NIL_FILP) cp->fp_filp[i]->filp_count++;
+ if (cp->fp_filp[i] != NULL) cp->fp_filp[i]->filp_count++;
/* Fill in new process and endpoint id. */
cp->fp_pid = cpid;
unsuspend_by_endpt(fp->fp_endpoint);
/* Release root and working directories. */
- if(fp->fp_rd) { put_vnode(fp->fp_rd); fp->fp_rd = NIL_VNODE; }
- if(fp->fp_wd) { put_vnode(fp->fp_wd); fp->fp_wd = NIL_VNODE; }
+ if(fp->fp_rd) { put_vnode(fp->fp_rd); fp->fp_rd = NULL; }
+ if(fp->fp_wd) { put_vnode(fp->fp_wd); fp->fp_wd = NULL; }
/* The rest of these actions is only done when processes actually
* exit.
if (rfp->fp_tty == dev) rfp->fp_tty = 0;
for (i = 0; i < OPEN_MAX; i++) {
- if ((rfilp = rfp->fp_filp[i]) == NIL_FILP) continue;
+ if ((rfilp = rfp->fp_filp[i]) == NULL) continue;
if (rfilp->filp_mode == FILP_CLOSED) continue;
vp = rfilp->filp_vno;
if ((vp->v_mode & I_TYPE) != I_CHAR_SPECIAL) continue;
/* Scan vmnt table to see if dev already mounted. If not, find a free slot.*/
found = FALSE;
- vmp = NIL_VMNT;
+ vmp = NULL;
for (i = 0; i < NR_MNTS; ++i) {
if (vmnt[i].m_dev == dev) {
vmp = &vmnt[i];
/* Now get the inode of the file to be mounted on. */
if (fetch_name(m_in.name2, m_in.name2_length, M1)!=OK) return(err_code);
- if ((vp = eat_path(PATH_NOFLAGS)) == NIL_VNODE) return(err_code);
+ if ((vp = eat_path(PATH_NOFLAGS)) == NULL) return(err_code);
if (vp->v_ref_count != 1) {
put_vnode(vp);
return(EBUSY);
if(!replace_root) {
/* Get vnode of mountpoint */
- if ((vp = eat_path(PATH_NOFLAGS)) == NIL_VNODE) return(err_code);
+ if ((vp = eat_path(PATH_NOFLAGS)) == NULL) return(err_code);
/* Tell FS on which vnode it is mounted (glue into mount tree) */
if ((r = req_mountpoint(vp->v_fs_e, vp->v_inode_nr)) != OK) {
}
/* We'll need a vnode for the root inode, check whether there is one */
- if ((root_node = get_free_vnode()) == NIL_VNODE) {
- if (vp != NIL_VNODE) put_vnode(vp);
+ if ((root_node = get_free_vnode()) == NULL) {
+ if (vp != NULL) put_vnode(vp);
return(ENFILE);
}
dp = &dmap[(dev >> MAJOR) & BYTE];
if (dp->dmap_driver == NONE) {
printf("VFS: no driver for dev %x\n", dev);
- if (vp != NIL_VNODE) put_vnode(vp);
+ if (vp != NULL) put_vnode(vp);
return(EINVAL);
}
/* Tell FS which device to mount */
if ((r = req_readsuper(fs_e, label, dev, rdonly, isroot, &res)) != OK) {
- if (vp != NIL_VNODE) put_vnode(vp);
+ if (vp != NULL) put_vnode(vp);
return(r);
}
if (vmp->m_mounted_on) {
put_vnode(vmp->m_mounted_on);
- vmp->m_mounted_on = NIL_VNODE;
+ vmp->m_mounted_on = NULL;
}
/* Tell FS to unmount */
vmp->m_root_node->v_ref_count = 0;
vmp->m_root_node->v_fs_count = 0;
vmp->m_root_node->v_sdev = NO_DEV;
- vmp->m_root_node = NIL_VNODE;
+ vmp->m_root_node = NULL;
vmp->m_dev = NO_DEV;
vmp->m_fs_e = NONE;
struct vnode *vp;
/* Request lookup */
- if ((vp = eat_path(PATH_NOFLAGS)) == NIL_VNODE) {
+ if ((vp = eat_path(PATH_NOFLAGS)) == NULL) {
return(NO_DEV);
}
flag is set this is an error */
} else {
/* Scan path name */
- if ((vp = eat_path(PATH_NOFLAGS)) == NIL_VNODE) return(err_code);
+ if ((vp = eat_path(PATH_NOFLAGS)) == NULL) return(err_code);
}
/* Claim the file descriptor and filp slot and fill them in. */
*/
b = (bits & R_BIT ? R_BIT : W_BIT);
fil_ptr->filp_count = 0; /* don't find self */
- if ((filp2 = find_filp(vp, b)) != NIL_FILP) {
+ if ((filp2 = find_filp(vp, b)) != NULL) {
/* Co-reader or writer found. Use it.*/
fp->fp_filp[m_in.fd] = filp2;
filp2->filp_count++;
/* If error, release inode. */
if (r != OK) {
if (r == SUSPEND) return(r); /* Oops, just suspended */
- fp->fp_filp[m_in.fd] = NIL_FILP;
+ fp->fp_filp[m_in.fd] = NULL;
FD_CLR(m_in.fd, &fp->fp_filp_inuse);
fil_ptr->filp_count= 0;
put_vnode(vp);
- fil_ptr->filp_vno = NIL_VNODE;
+ fil_ptr->filp_vno = NULL;
return(r);
}
{
/* Try to create a new inode and return a pointer to it. If the inode already
exists, return a pointer to it as well, but set err_code accordingly.
- NIL_VNODE is returned if the path cannot be resolved up to the last
+ NULL is returned if the path cannot be resolved up to the last
directory, or when the inode cannot be created due to permissions or
otherwise. */
struct vnode *dirp, *vp;
if (oflags & O_EXCL) flags |= PATH_RET_SYMLINK;
/* See if the path can be opened down to the last directory. */
- if ((dirp = last_dir()) == NIL_VNODE) return(NIL_VNODE);
+ if ((dirp = last_dir()) == NULL) return(NULL);
/* The final directory is accessible. Get final component of the path. */
vp = advance(dirp, flags);
* symlink results in a new path that needs to be re-resolved entirely. */
if (user_fullpath[0] == '/') return new_node(oflags, bits);
- if (vp == NIL_VNODE && err_code == ENOENT) {
+ if (vp == NULL && err_code == ENOENT) {
/* Last path component does not exist. Make a new directory entry. */
- if ((vp = get_free_vnode()) == NIL_VNODE) {
+ if ((vp = get_free_vnode()) == NULL) {
/* Can't create new vnode: out of vnodes. */
put_vnode(dirp);
- return(NIL_VNODE);
+ return(NULL);
}
if ((r = forbidden(dirp, W_BIT|X_BIT)) != OK ||
(r = req_create(dirp->v_fs_e, dirp->v_inode_nr,bits, fp->fp_effuid,
/* Resolve path up to symlink */
slp = advance(dirp, PATH_RET_SYMLINK);
- if (slp != NIL_VNODE) {
+ if (slp != NULL) {
if (S_ISLNK(slp->v_mode)) {
/* Get contents of link */
put_vnode(slp);
put_vnode(dirp);
err_code = r;
- return(NIL_VNODE);
+ return(NULL);
}
user_fullpath[r] = '\0';/* Term. path*/
}
vp = new_node(oflags, bits);
fp->fp_wd = old_wd; /* Restore */
- if (vp != NIL_VNODE) {
+ if (vp != NULL) {
put_vnode(dirp);
return(vp);
}
err_code = r;
put_vnode(dirp);
- return(NIL_VNODE);
+ return(NULL);
}
/* Store results and mark vnode in use */
vp->v_ref_count = 1;
} else {
/* Either last component exists, or there is some other problem. */
- if (vp != NIL_VNODE)
+ if (vp != NULL)
r = EEXIST; /* File exists or a symlink names a file while
* O_EXCL is set. */
else
if((bits & (R_BIT|W_BIT)) == (R_BIT|W_BIT)) return(ENXIO);
- if (find_filp(vp, bits & W_BIT ? R_BIT : W_BIT) == NIL_FILP) {
+ if (find_filp(vp, bits & W_BIT ? R_BIT : W_BIT) == NULL) {
if (oflags & O_NONBLOCK) {
if (bits & W_BIT) return(ENXIO);
} else {
/* Open directory that's going to hold the new node. */
if(fetch_name(m_in.name1, m_in.name1_length, M1) != OK) return(err_code);
- if((vp = last_dir()) == NIL_VNODE) return(err_code);
+ if((vp = last_dir()) == NULL) return(err_code);
/* Make sure that the object is a directory */
if((vp->v_mode & I_TYPE) != I_DIRECTORY) {
bits = I_DIRECTORY | (m_in.mode & RWX_MODES & fp->fp_umask);
/* Request lookup */
- if((vp = last_dir()) == NIL_VNODE) return(err_code);
+ if((vp = last_dir()) == NULL) return(err_code);
/* Make sure that the object is a directory */
if ((vp->v_mode & I_TYPE) != I_DIRECTORY) {
u64_t pos, newpos;
/* Check to see if the file descriptor is valid. */
- if ( (rfilp = get_filp(m_in.ls_fd)) == NIL_FILP) return(err_code);
+ if ( (rfilp = get_filp(m_in.ls_fd)) == NULL) return(err_code);
/* No lseek on pipes. */
if (rfilp->filp_vno->v_pipe == I_PIPE) return(ESPIPE);
int r;
/* Check to see if the file descriptor is valid. */
- if ( (rfilp = get_filp(m_in.ls_fd)) == NIL_FILP) return(err_code);
+ if ( (rfilp = get_filp(m_in.ls_fd)) == NULL) return(err_code);
/* No lseek on pipes. */
if (rfilp->filp_vno->v_pipe == I_PIPE) return(ESPIPE);
int lock_count;
/* First locate the vnode that belongs to the file descriptor. */
- if ( (rfilp = get_filp2(rfp, fd_nr)) == NIL_FILP) return(err_code);
+ if ( (rfilp = get_filp2(rfp, fd_nr)) == NULL) return(err_code);
vp = rfilp->filp_vno;
close_filp(rfilp);
FD_CLR(fd_nr, &rfp->fp_cloexec_set);
- rfp->fp_filp[fd_nr] = NIL_FILP;
+ rfp->fp_filp[fd_nr] = NULL;
FD_CLR(fd_nr, &rfp->fp_filp_inuse);
/* Check to see if the file is locked. If so, release all locks. */
assert(dirp);
/* Get a free vnode */
- if((new_vp = get_free_vnode()) == NIL_VNODE) return(NIL_VNODE);
+ if((new_vp = get_free_vnode()) == NULL) return(NULL);
/* Lookup vnode belonging to the file. */
if ((r = lookup(dirp, flags, &res)) != OK) {
err_code = r;
- return(NIL_VNODE);
+ return(NULL);
}
/* Check whether vnode is already in use or not */
- if ((vp = find_vnode(res.fs_e, res.inode_nr)) != NIL_VNODE) {
+ if ((vp = find_vnode(res.fs_e, res.inode_nr)) != NULL) {
dup_vnode(vp);
vp->v_fs_count++; /* We got a reference from the FS */
return(vp);
new_vp->v_gid = res.gid;
new_vp->v_sdev = res.dev;
- if( (vmp = find_vmnt(new_vp->v_fs_e)) == NIL_VMNT)
+ if( (vmp = find_vmnt(new_vp->v_fs_e)) == NULL)
panic("VFS advance: vmnt not found");
new_vp->v_vmnt = vmp;
/* Parse a path, 'user_fullpath', as far as the last directory, fetch the vnode
* for the last directory into the vnode table, and return a pointer to the
* vnode. In addition, return the final component of the path in 'string'. If
- * the last directory can't be opened, return NIL_VNODE and the reason for
+ * the last directory can't be opened, return NULL and the reason for
* failure in 'err_code'. We can't parse component by component as that would
* be too expensive. Alternatively, we cut off the last component of the path,
* and parse the path up to the penultimate component.
/* If path is empty, return ENOENT. */
if (len == 0) {
err_code = ENOENT;
- return(NIL_VNODE);
+ return(NULL);
}
#if !DO_POSIX_PATHNAME_RES
}
res = advance(vp, PATH_NOFLAGS);
- if (res == NIL_VNODE) return(NIL_VNODE);
+ if (res == NULL) return(NULL);
/* Copy the directory entry back to user_fullpath */
strcpy(user_fullpath, dir_entry);
/* Climbing up mount */
/* Find the vmnt that represents the partition on
* which we "climb up". */
- if ((vmp = find_vmnt(res.fs_e)) == NIL_VMNT) {
+ if ((vmp = find_vmnt(res.fs_e)) == NULL) {
panic("VFS lookup: can't find parent vmnt");
}
struct node_details res;
/* See if a free vnode is available */
- if ( (vp = get_free_vnode()) == NIL_VNODE) return(err_code);
+ if ( (vp = get_free_vnode()) == NULL) return(err_code);
/* Acquire two file descriptors. */
rfp = fp;
FD_SET(fil_des[0], &rfp->fp_filp_inuse);
fil_ptr0->filp_count = 1;
if ((r = get_fd(0, W_BIT, &fil_des[1], &fil_ptr1)) != OK) {
- rfp->fp_filp[fil_des[0]] = NIL_FILP;
+ rfp->fp_filp[fil_des[0]] = NULL;
FD_CLR(fil_des[0], &rfp->fp_filp_inuse);
fil_ptr0->filp_count = 0;
return(r);
NO_DEV, &res);
if (r != OK) {
- rfp->fp_filp[fil_des[0]] = NIL_FILP;
+ rfp->fp_filp[fil_des[0]] = NULL;
FD_CLR(fil_des[0], &rfp->fp_filp_inuse);
fil_ptr0->filp_count = 0;
- rfp->fp_filp[fil_des[1]] = NIL_FILP;
+ rfp->fp_filp[fil_des[1]] = NULL;
FD_CLR(fil_des[1], &rfp->fp_filp_inuse);
fil_ptr1->filp_count = 0;
return(r);
vp->v_mapfs_count = 1;
vp->v_ref_count = 1;
vp->v_size = 0;
- vp->v_vmnt = NIL_VMNT;
+ vp->v_vmnt = NULL;
vp->v_dev = NO_DEV;
/* Fill in filp objects */
if (rw_flag == READING) {
if (pos >= vp->v_size) {
/* Process is reading from an empty pipe. */
- if (find_filp(vp, W_BIT) != NIL_FILP) {
+ if (find_filp(vp, W_BIT) != NULL) {
/* Writer exists */
if (oflags & O_NONBLOCK)
r = EAGAIN;
}
/* Process is writing to a pipe. */
- if (find_filp(vp, R_BIT) == NIL_FILP) {
+ if (find_filp(vp, R_BIT) == NULL) {
/* Process is writing, but there is no reader. Tell kernel to generate
* a SIGPIPE signal. */
if (!notouch) sys_kill(fp->fp_endpoint, SIGPIPE);
fd_nr = rfp->fp_fd>>8;
if (returned < 0) {
fil_ptr = rfp->fp_filp[fd_nr];
- rfp->fp_filp[fd_nr] = NIL_FILP;
+ rfp->fp_filp[fd_nr] = NULL;
FD_CLR(fd_nr, &rfp->fp_filp_inuse);
if (fil_ptr->filp_count != 1) {
panic("revive: bad count in filp: %d",
}
fil_ptr->filp_count = 0;
put_vnode(fil_ptr->filp_vno);
- fil_ptr->filp_vno = NIL_VNODE;
+ fil_ptr->filp_vno = NULL;
reply(proc_nr_e, returned);
} else
reply(proc_nr_e, fd_nr);
if (call_nr == CHMOD) {
/* Temporarily open the file */
if(fetch_name(m_in.name, m_in.name_length, M3) != OK) return(err_code);
- if ((vp = eat_path(PATH_NOFLAGS)) == NIL_VNODE) return(err_code);
+ if ((vp = eat_path(PATH_NOFLAGS)) == NULL) return(err_code);
} else { /* call_nr == FCHMOD */
/* File is already opened; get a pointer to vnode from filp. */
if (!(flp = get_filp(m_in.fd))) return(err_code);
if (call_nr == CHOWN) {
/* Temporarily open the file. */
if(fetch_name(m_in.name1, m_in.name1_length, M1) != OK) return(err_code);
- if ((vp = eat_path(PATH_NOFLAGS)) == NIL_VNODE) return(err_code);
+ if ((vp = eat_path(PATH_NOFLAGS)) == NULL) return(err_code);
} else { /* call_nr == FCHOWN */
/* File is already opened; get a pointer to the vnode from filp. */
if (!(flp = get_filp(m_in.fd))) return(err_code);
/* Temporarily open the file. */
if (fetch_name(m_in.name, m_in.name_length, M3) != OK) return(err_code);
- if ((vp = eat_path(PATH_NOFLAGS)) == NIL_VNODE) return(err_code);
+ if ((vp = eat_path(PATH_NOFLAGS)) == NULL) return(err_code);
r = forbidden(vp, m_in.mode);
put_vnode(vp);
/* If the file descriptor is valid, get the vnode, size and mode. */
if (m_in.nbytes < 0) return(EINVAL);
- if ((f = get_filp(m_in.fd)) == NIL_FILP) return(err_code);
+ if ((f = get_filp(m_in.fd)) == NULL) return(err_code);
if (((f->filp_mode) & (rw_flag == READING ? R_BIT : W_BIT)) == 0) {
return(f->filp_mode == FILP_CLOSED ? EIO : EBADF);
}
register struct filp *rfilp;
/* Is the file descriptor valid? */
- if ( (rfilp = get_filp(m_in.fd)) == NIL_FILP) {
+ if ( (rfilp = get_filp(m_in.fd)) == NULL) {
return(err_code);
}
/* Get filp belonging to this fd */
filp = se->filps[fd] = get_filp(fd);
- if (filp == NIL_FILP) {
+ if (filp == NULL) {
if (err_code == EBADF) {
select_cancel_all(se);
return(EBADF);
if (selecttab[s].requestor == NULL) continue;
for(fd = 0; fd < selecttab[s].nfds; fd++) {
- if (selecttab[s].filps[fd] == NIL_FILP ||
- selecttab[s].filps[fd]->filp_vno == NIL_VNODE) {
+ if (selecttab[s].filps[fd] == NULL ||
+ selecttab[s].filps[fd]->filp_vno == NULL) {
continue;
}
struct filp *rfilp;
/* Is the file descriptor valid? */
- if ((rfilp = get_filp(m_in.fd)) == NIL_FILP) return(err_code);
+ if ((rfilp = get_filp(m_in.fd)) == NULL) return(err_code);
dup_vnode(rfilp->filp_vno); /* Change into expects a reference. */
return change_into(&fp->fp_wd, rfilp->filp_vno);
}
/* Try to open the directory */
if (fetch_name(name_ptr, len, M3) != OK) return(err_code);
- if ((vp = eat_path(PATH_NOFLAGS)) == NIL_VNODE) return(err_code);
+ if ((vp = eat_path(PATH_NOFLAGS)) == NULL) return(err_code);
return change_into(iip, vp);
}
struct vnode *vp;
if (fetch_name(m_in.name1, m_in.name1_length, M1) != OK) return(err_code);
- if ((vp = eat_path(PATH_NOFLAGS)) == NIL_VNODE) return(err_code);
+ if ((vp = eat_path(PATH_NOFLAGS)) == NULL) return(err_code);
r = req_stat(vp->v_fs_e, vp->v_inode_nr, who_e, m_in.name2, 0);
put_vnode(vp);
int pipe_pos = 0;
/* Is the file descriptor valid? */
- if ((rfilp = get_filp(m_in.fd)) == NIL_FILP) return(err_code);
+ if ((rfilp = get_filp(m_in.fd)) == NULL) return(err_code);
/* If we read from a pipe, send position too */
if (rfilp->filp_vno->v_pipe == I_PIPE) {
struct filp *rfilp;
/* Is the file descriptor valid? */
- if( (rfilp = get_filp(m_in.fd)) == NIL_FILP) return(err_code);
+ if( (rfilp = get_filp(m_in.fd)) == NULL) return(err_code);
return req_fstatfs(rfilp->filp_vno->v_fs_e, who_e, m_in.buffer);
}
int r;
if (fetch_name(m_in.name1, m_in.name1_length, M1) != OK) return(err_code);
- if ((vp = eat_path(PATH_RET_SYMLINK)) == NIL_VNODE) return(err_code);
+ if ((vp = eat_path(PATH_RET_SYMLINK)) == NULL) return(err_code);
r = req_stat(vp->v_fs_e, vp->v_inode_nr, who_e, m_in.name2, 0);
put_vnode(vp);
/* Temporarily open the file */
if (fetch_name(m_in.utime_file, len, M1) != OK) return(err_code);
- if ((vp = eat_path(PATH_NOFLAGS)) == NIL_VNODE) return(err_code);
+ if ((vp = eat_path(PATH_NOFLAGS)) == NULL) return(err_code);
/* Only the owner of a file or the super user can change its name. */
r = OK;
for (vp = &vmnt[0]; vp < &vmnt[NR_MNTS]; ++vp, ++(*index))
if (vp->m_dev == NO_DEV) return(vp);
- return(NIL_VMNT);
+ return(NULL);
}
for (vp = &vmnt[0]; vp < &vmnt[NR_MNTS]; ++vp)
if (vp->m_fs_e == fs_e) return(vp);
- return(NIL_VMNT);
+ return(NULL);
}
char m_label[LABEL_MAX]; /* label of the file system process */
} vmnt[NR_MNTS];
-#define NIL_VMNT (struct vmnt *) 0
}
err_code = ENFILE;
- return(NIL_VNODE);
+ return(NULL);
}
if (vp->v_ref_count > 0 && vp->v_inode_nr == numb && vp->v_fs_e == fs_e)
return(vp);
- return(NIL_VNODE);
+ return(NULL);
}
{
/* Tell the underlying FS to drop all reference but one. */
- if (vp == NIL_VNODE) return;
+ if (vp == NULL) return;
if (vp->v_fs_count <= 1) return; /* Nothing to do */
/* Drop all references except one */
struct vmnt *v_vmnt; /* vmnt object of the partition */
} vnode[NR_VNODES];
-#define NIL_VNODE (struct vnode *) 0 /* indicates absence of vnode slot */
/* Field values. */
#define NO_PIPE 0 /* i_pipe is NO_PIPE if inode is not a pipe */
static int startpages;
-#define NIL_HOLE (struct hole *) 0
#define _NR_HOLES (_NR_PROCS*2) /* No. of memory holes maintained by VM */
}
} else {
CHECKHOLES;
- prev_ptr = NIL_HOLE;
+ prev_ptr = NULL;
hp = hole_head;
- while (hp != NIL_HOLE) {
+ while (hp != NULL) {
if (hp->h_len >= clicks) {
/* We found a hole that is big enough. Use it. */
old_base = hp->h_base; /* remember where it started */
return;
}
- if ( (new_ptr = free_slots) == NIL_HOLE)
+ if ( (new_ptr = free_slots) == NULL)
panic("hole table full");
new_ptr->h_base = base;
new_ptr->h_len = clicks;
* available, or if no holes are currently available, put this hole on the
* front of the hole list.
*/
- if (hp == NIL_HOLE || base <= hp->h_base) {
+ if (hp == NULL || base <= hp->h_base) {
/* Block to be freed goes on front of the hole list. */
new_ptr->h_next = hp;
hole_head = new_ptr;
}
/* Block to be returned does not go on front of hole list. */
- prev_ptr = NIL_HOLE;
- while (hp != NIL_HOLE && base > hp->h_base) {
+ prev_ptr = NULL;
+ while (hp != NULL && base > hp->h_base) {
prev_ptr = hp;
hp = hp->h_next;
}
/* If 'hp' points to the last hole, no merging is possible. If it does not,
* try to absorb its successor into it and free the successor's table entry.
*/
- if ( (next_ptr = hp->h_next) == NIL_HOLE) return;
+ if ( (next_ptr = hp->h_next) == NULL) return;
if (hp->h_base + hp->h_len == next_ptr->h_base) {
hp->h_len += next_ptr->h_len; /* first one gets second one's mem */
del_slot(hp, next_ptr);
/* If 'hp' now points to the last hole, return; otherwise, try to absorb its
* successor into it.
*/
- if ( (next_ptr = hp->h_next) == NIL_HOLE) return;
+ if ( (next_ptr = hp->h_next) == NULL) return;
if (hp->h_base + hp->h_len == next_ptr->h_base) {
hp->h_len += next_ptr->h_len;
del_slot(hp, next_ptr);
hp->h_next = hp + 1;
hp->h_base = hp->h_len = 0;
}
- hole[_NR_HOLES-1].h_next = NIL_HOLE;
- hole_head = NIL_HOLE;
+ hole[_NR_HOLES-1].h_next = NULL;
+ hole_head = NULL;
free_slots = &hole[0];
addr_init(&addravl);