Filling a grid so as not to completely fill any row, column or *any* diagonal This is a problem inspired by a comment I made on this question: Problem regarding filling squares inside a $n\times n$ grid.
Suppose we are given an $n\times n$ grid and we fill it with $0$'s and $1$'s so that no row, column or any maximal$^*$ diagonal contains only $1$'s. Let $g(n)$ be the maximum number of $1$'s that can be used in such a filling. 
It is easy to see that $g(n)\geq (n-1)(n-2)$ by considering the filling consisting of placing only $0$'s in the first row and first and last columns, and then filling all remaining square with $1$'s. 
I believe we should have equality, i.e., $g(n)=(n-1)(n-2)$, but I'm having a little trouble coming up with a proof before I finish my coffee. Does equality indeed hold? And, for the $m\times n$ case  with $m\geq n$, is the natural generalization true, i.e., is $g(m,n)=(m-1)(n-2)$?
$^*$ "Maximal diagonal" here means any of the corner squares, or a diagonal that can't be extended to a larger diagonal in either direction. So for example, the pair of squares in entries $(1,2)$ and $ (2,1)$ form a maximal diagonal, as do the pair in entries $(1,n-1),(2,n)$, etc.
 A: $$\pmatrix{0&0&1&0\\
1&1&1&0\\
0&1&1&1\\
0&1&0&0}$$
has no all-$1$ rows, columns, or "maximal" diagonals, and does it with $8$ $1$'s, which is greater than $(4-1)(4-2)=6$.
Note:  This answer has been superseded by Ross Millikan's much more complete and general constructions.
Added later:  On reading Ross Millikan's and zyx's answers, here's a construction that works for $2k\times2k$ grids, best thought of as black-and-white chessboards:

Place $0$'s on all the white squares along the top and bottom rows,
  and on all the black squares along the left and rightmost columns.

This uses $4k=2n$ $0$'s and guarantees there's a $0$ in each row, column, and diagonal.  Assuming the top left square is white, then, as Ross Millikan noted, there are $n$ white "up" diagonals and $n$ black "down" diagonals, so you can't get by with fewer than $2n$ $0$'s.  So for even $n$, $g(n)=n^2-2n$.  Note, though, that the construction fails rather badly for odd $n$.
A: For maximal diagonals,
If you consider every maximal diagonal, not containing a corner, as a ray of light and continue reflecting it to follow the light path, you get a rectangle.  Placing $0$'s at two opposite corners of all such rectangles, plus the four corners of the board, is $2(n-2)+4$ excluded points and is the minimum number to exclude to cover all diagonal requirements.  If this can be done while covering all rows and columns, you get a solution with $n^2 - 2n$ points.  For $n=2k$, a square board of even size ($n \geq 4$), it is possible by excluding points $(i,1)$ and $(1,i)$ for $2 \leq i \leq k$, their opposite points, and the corners.  Probably the same construction could be modified for odd or asymmetric boards.
For maximum diagonals, 

When $\min(m,n) = d \geq 3$ the largest arrangement avoiding all length $d$ diagonals  is $mn - \max(m,n)$, and can be built by viewing the board as a torus filling all squares except a line of knight's moves where the $+1$ part of the move is in the long direction of the board. 
For $1 \times n$ there are no solutions.  For $2 \times n$ with $n \geq 2$, the answer is $\lceil n/2 \rceil$ by occupying alternate positions on one line in the long direction. 

A: For $n=8$ we can get $g(8)=48 \gt 7\cdot 6=42$.  Fill all squares except $a1,b1,e1,f1,h1,h2,h5,h6,h8,g8,d8,c8,a8,a7,a4,a3$  This is the best that can be done, as (with $h1$ white) there are eight white diagonals running down to the right and eight black diagonals running up to the right.  Each of these sixteen must be interrupted.  The same construction, going around the edge, start from a corner, leave two empty, fill the next two, repeat, works for all boards of size $4k$, giving $g(n)=n^2-2n$ for these cases.
For $n=10$, we can get $g(10)=80$ by leaving $a1,b1,e1,g1,j1$ empty and rotating that around the edges.  This also satisfies $g(n)=n^2-2n$  I believe this pattern works for all $4k+2$ boards-do the alternating twos but make a single one at the point nearest the center.
For $n$ odd, you can leave open the $\frac {n+1}2$ squares clockwise from one corner, then $\frac {n-1}2$, then repeat plus the center cell giving $g(n)=n^2-2n-1$  The center cell is needed for the middle row or column.  I have not proved that we can't do one better.
