1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
|
/*
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Rick Macklem at The University of Guelph.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)nfs_vnops.c 8.5 (Berkeley) 2/13/94
* $Id: nfs_vnops.c,v 1.14 1995/03/23 09:43:40 davidg Exp $
*/
/*
* vnode op calls for sun nfs version 2
*/
#include <sys/param.h>
#include <sys/proc.h>
#include <sys/kernel.h>
#include <sys/systm.h>
#include <sys/mount.h>
#include <sys/buf.h>
#include <sys/malloc.h>
#include <sys/mbuf.h>
#include <sys/conf.h>
#include <sys/namei.h>
#include <sys/vnode.h>
#include <sys/dirent.h>
#include <sys/lockf.h>
#include <vm/vm.h>
#include <miscfs/specfs/specdev.h>
#include <miscfs/fifofs/fifo.h>
#include <nfs/rpcv2.h>
#include <nfs/nfsv2.h>
#include <nfs/nfs.h>
#include <nfs/nfsnode.h>
#include <nfs/nfsmount.h>
#include <nfs/xdr_subs.h>
#include <nfs/nfsm_subs.h>
#include <nfs/nqnfs.h>
/* Defs */
#define TRUE 1
#define FALSE 0
/*
* Global vfs data structures for nfs
*/
int (**nfsv2_vnodeop_p)();
struct vnodeopv_entry_desc nfsv2_vnodeop_entries[] = {
{ &vop_default_desc, vn_default_error },
{ &vop_lookup_desc, nfs_lookup }, /* lookup */
{ &vop_create_desc, nfs_create }, /* create */
{ &vop_mknod_desc, nfs_mknod }, /* mknod */
{ &vop_open_desc, nfs_open }, /* open */
{ &vop_close_desc, nfs_close }, /* close */
{ &vop_access_desc, nfs_access }, /* access */
{ &vop_getattr_desc, nfs_getattr }, /* getattr */
{ &vop_setattr_desc, nfs_setattr }, /* setattr */
{ &vop_read_desc, nfs_read }, /* read */
{ &vop_write_desc, nfs_write }, /* write */
{ &vop_ioctl_desc, nfs_ioctl }, /* ioctl */
{ &vop_select_desc, nfs_select }, /* select */
{ &vop_mmap_desc, nfs_mmap }, /* mmap */
{ &vop_fsync_desc, nfs_fsync }, /* fsync */
{ &vop_seek_desc, nfs_seek }, /* seek */
{ &vop_remove_desc, nfs_remove }, /* remove */
{ &vop_link_desc, nfs_link }, /* link */
{ &vop_rename_desc, nfs_rename }, /* rename */
{ &vop_mkdir_desc, nfs_mkdir }, /* mkdir */
{ &vop_rmdir_desc, nfs_rmdir }, /* rmdir */
{ &vop_symlink_desc, nfs_symlink }, /* symlink */
{ &vop_readdir_desc, nfs_readdir }, /* readdir */
{ &vop_readlink_desc, nfs_readlink }, /* readlink */
{ &vop_abortop_desc, nfs_abortop }, /* abortop */
{ &vop_inactive_desc, nfs_inactive }, /* inactive */
{ &vop_reclaim_desc, nfs_reclaim }, /* reclaim */
{ &vop_lock_desc, nfs_lock }, /* lock */
{ &vop_unlock_desc, nfs_unlock }, /* unlock */
{ &vop_bmap_desc, nfs_bmap }, /* bmap */
{ &vop_strategy_desc, nfs_strategy }, /* strategy */
{ &vop_print_desc, nfs_print }, /* print */
{ &vop_islocked_desc, nfs_islocked }, /* islocked */
{ &vop_pathconf_desc, nfs_pathconf }, /* pathconf */
{ &vop_advlock_desc, nfs_advlock }, /* advlock */
{ &vop_blkatoff_desc, nfs_blkatoff }, /* blkatoff */
{ &vop_valloc_desc, nfs_valloc }, /* valloc */
{ &vop_reallocblks_desc, nfs_reallocblks }, /* reallocblks */
{ &vop_vfree_desc, nfs_vfree }, /* vfree */
{ &vop_truncate_desc, nfs_truncate }, /* truncate */
{ &vop_update_desc, nfs_update }, /* update */
{ &vop_bwrite_desc, vn_bwrite },
{ (struct vnodeop_desc*)NULL, (int(*)())NULL }
};
struct vnodeopv_desc nfsv2_vnodeop_opv_desc =
{ &nfsv2_vnodeop_p, nfsv2_vnodeop_entries };
VNODEOP_SET(nfsv2_vnodeop_opv_desc);
/*
* Special device vnode ops
*/
int (**spec_nfsv2nodeop_p)();
struct vnodeopv_entry_desc spec_nfsv2nodeop_entries[] = {
{ &vop_default_desc, vn_default_error },
{ &vop_lookup_desc, spec_lookup }, /* lookup */
{ &vop_create_desc, spec_create }, /* create */
{ &vop_mknod_desc, spec_mknod }, /* mknod */
{ &vop_open_desc, spec_open }, /* open */
{ &vop_close_desc, nfsspec_close }, /* close */
{ &vop_access_desc, nfsspec_access }, /* access */
{ &vop_getattr_desc, nfs_getattr }, /* getattr */
{ &vop_setattr_desc, nfs_setattr }, /* setattr */
{ &vop_read_desc, nfsspec_read }, /* read */
{ &vop_write_desc, nfsspec_write }, /* write */
{ &vop_ioctl_desc, spec_ioctl }, /* ioctl */
{ &vop_select_desc, spec_select }, /* select */
{ &vop_mmap_desc, spec_mmap }, /* mmap */
{ &vop_fsync_desc, nfs_fsync }, /* fsync */
{ &vop_seek_desc, spec_seek }, /* seek */
{ &vop_remove_desc, spec_remove }, /* remove */
{ &vop_link_desc, spec_link }, /* link */
{ &vop_rename_desc, spec_rename }, /* rename */
{ &vop_mkdir_desc, spec_mkdir }, /* mkdir */
{ &vop_rmdir_desc, spec_rmdir }, /* rmdir */
{ &vop_symlink_desc, spec_symlink }, /* symlink */
{ &vop_readdir_desc, spec_readdir }, /* readdir */
{ &vop_readlink_desc, spec_readlink }, /* readlink */
{ &vop_abortop_desc, spec_abortop }, /* abortop */
{ &vop_inactive_desc, nfs_inactive }, /* inactive */
{ &vop_reclaim_desc, nfs_reclaim }, /* reclaim */
{ &vop_lock_desc, nfs_lock }, /* lock */
{ &vop_unlock_desc, nfs_unlock }, /* unlock */
{ &vop_bmap_desc, spec_bmap }, /* bmap */
{ &vop_strategy_desc, spec_strategy }, /* strategy */
{ &vop_print_desc, nfs_print }, /* print */
{ &vop_islocked_desc, nfs_islocked }, /* islocked */
{ &vop_pathconf_desc, spec_pathconf }, /* pathconf */
{ &vop_advlock_desc, spec_advlock }, /* advlock */
{ &vop_blkatoff_desc, spec_blkatoff }, /* blkatoff */
{ &vop_valloc_desc, spec_valloc }, /* valloc */
{ &vop_reallocblks_desc, spec_reallocblks }, /* reallocblks */
{ &vop_vfree_desc, spec_vfree }, /* vfree */
{ &vop_truncate_desc, spec_truncate }, /* truncate */
{ &vop_update_desc, nfs_update }, /* update */
{ &vop_bwrite_desc, vn_bwrite },
{ (struct vnodeop_desc*)NULL, (int(*)())NULL }
};
struct vnodeopv_desc spec_nfsv2nodeop_opv_desc =
{ &spec_nfsv2nodeop_p, spec_nfsv2nodeop_entries };
VNODEOP_SET(spec_nfsv2nodeop_opv_desc);
int (**fifo_nfsv2nodeop_p)();
struct vnodeopv_entry_desc fifo_nfsv2nodeop_entries[] = {
{ &vop_default_desc, vn_default_error },
{ &vop_lookup_desc, fifo_lookup }, /* lookup */
{ &vop_create_desc, fifo_create }, /* create */
{ &vop_mknod_desc, fifo_mknod }, /* mknod */
{ &vop_open_desc, fifo_open }, /* open */
{ &vop_close_desc, nfsfifo_close }, /* close */
{ &vop_access_desc, nfsspec_access }, /* access */
{ &vop_getattr_desc, nfs_getattr }, /* getattr */
{ &vop_setattr_desc, nfs_setattr }, /* setattr */
{ &vop_read_desc, nfsfifo_read }, /* read */
{ &vop_write_desc, nfsfifo_write }, /* write */
{ &vop_ioctl_desc, fifo_ioctl }, /* ioctl */
{ &vop_select_desc, fifo_select }, /* select */
{ &vop_mmap_desc, fifo_mmap }, /* mmap */
{ &vop_fsync_desc, nfs_fsync }, /* fsync */
{ &vop_seek_desc, fifo_seek }, /* seek */
{ &vop_remove_desc, fifo_remove }, /* remove */
{ &vop_link_desc, fifo_link }, /* link */
{ &vop_rename_desc, fifo_rename }, /* rename */
{ &vop_mkdir_desc, fifo_mkdir }, /* mkdir */
{ &vop_rmdir_desc, fifo_rmdir }, /* rmdir */
{ &vop_symlink_desc, fifo_symlink }, /* symlink */
{ &vop_readdir_desc, fifo_readdir }, /* readdir */
{ &vop_readlink_desc, fifo_readlink }, /* readlink */
{ &vop_abortop_desc, fifo_abortop }, /* abortop */
{ &vop_inactive_desc, nfs_inactive }, /* inactive */
{ &vop_reclaim_desc, nfs_reclaim }, /* reclaim */
{ &vop_lock_desc, nfs_lock }, /* lock */
{ &vop_unlock_desc, nfs_unlock }, /* unlock */
{ &vop_bmap_desc, fifo_bmap }, /* bmap */
{ &vop_strategy_desc, fifo_badop }, /* strategy */
{ &vop_print_desc, nfs_print }, /* print */
{ &vop_islocked_desc, nfs_islocked }, /* islocked */
{ &vop_pathconf_desc, fifo_pathconf }, /* pathconf */
{ &vop_advlock_desc, fifo_advlock }, /* advlock */
{ &vop_blkatoff_desc, fifo_blkatoff }, /* blkatoff */
{ &vop_valloc_desc, fifo_valloc }, /* valloc */
{ &vop_reallocblks_desc, fifo_reallocblks }, /* reallocblks */
{ &vop_vfree_desc, fifo_vfree }, /* vfree */
{ &vop_truncate_desc, fifo_truncate }, /* truncate */
{ &vop_update_desc, nfs_update }, /* update */
{ &vop_bwrite_desc, vn_bwrite },
{ (struct vnodeop_desc*)NULL, (int(*)())NULL }
};
struct vnodeopv_desc fifo_nfsv2nodeop_opv_desc =
{ &fifo_nfsv2nodeop_p, fifo_nfsv2nodeop_entries };
VNODEOP_SET(fifo_nfsv2nodeop_opv_desc);
void nqnfs_clientlease();
/*
* Global variables
*/
extern u_long nfs_procids[NFS_NPROCS];
extern u_long nfs_prog, nfs_vers, nfs_true, nfs_false;
struct proc *nfs_iodwant[NFS_MAXASYNCDAEMON];
int nfs_numasync = 0;
#define DIRHDSIZ (sizeof (struct dirent) - (MAXNAMLEN + 1))
/*
* nfs null call from vfs.
*/
int
nfs_null(vp, cred, procp)
struct vnode *vp;
struct ucred *cred;
struct proc *procp;
{
caddr_t bpos, dpos;
int error = 0;
struct mbuf *mreq, *mrep, *md, *mb;
nfsm_reqhead(vp, NFSPROC_NULL, 0);
nfsm_request(vp, NFSPROC_NULL, procp, cred);
nfsm_reqdone;
return (error);
}
/*
* nfs access vnode op.
* For nfs, just return ok. File accesses may fail later.
* For nqnfs, use the access rpc to check accessibility. If file modes are
* changed on the server, accesses might still fail later.
*/
int
nfs_access(ap)
struct vop_access_args /* {
struct vnode *a_vp;
int a_mode;
struct ucred *a_cred;
struct proc *a_p;
} */ *ap;
{
register struct vnode *vp = ap->a_vp;
register u_long *tl;
register caddr_t cp;
caddr_t bpos, dpos;
int error = 0;
struct mbuf *mreq, *mrep, *md, *mb, *mb2;
/*
* For nqnfs, do an access rpc, otherwise you are stuck emulating
* ufs_access() locally using the vattr. This may not be correct,
* since the server may apply other access criteria such as
* client uid-->server uid mapping that we do not know about, but
* this is better than just returning anything that is lying about
* in the cache.
*/
if (VFSTONFS(vp->v_mount)->nm_flag & NFSMNT_NQNFS) {
nfsstats.rpccnt[NQNFSPROC_ACCESS]++;
nfsm_reqhead(vp, NQNFSPROC_ACCESS, NFSX_FH + 3 * NFSX_UNSIGNED);
nfsm_fhtom(vp);
nfsm_build(tl, u_long *, 3 * NFSX_UNSIGNED);
if (ap->a_mode & VREAD)
*tl++ = nfs_true;
else
*tl++ = nfs_false;
if (ap->a_mode & VWRITE)
*tl++ = nfs_true;
else
*tl++ = nfs_false;
if (ap->a_mode & VEXEC)
*tl = nfs_true;
else
*tl = nfs_false;
nfsm_request(vp, NQNFSPROC_ACCESS, ap->a_p, ap->a_cred);
nfsm_reqdone;
return (error);
} else
return (nfsspec_access(ap));
}
/*
* nfs open vnode op
* Check to see if the type is ok
* and that deletion is not in progress.
* For paged in text files, you will need to flush the page cache
* if consistency is lost.
*/
/* ARGSUSED */
int
nfs_open(ap)
struct vop_open_args /* {
struct vnode *a_vp;
int a_mode;
struct ucred *a_cred;
struct proc *a_p;
} */ *ap;
{
register struct vnode *vp = ap->a_vp;
struct nfsnode *np = VTONFS(vp);
struct nfsmount *nmp = VFSTONFS(vp->v_mount);
struct vattr vattr;
int error;
if (vp->v_type != VREG && vp->v_type != VDIR && vp->v_type != VLNK)
return (EACCES);
/*
* Get a valid lease. If cached data is stale, flush it.
*/
if (nmp->nm_flag & NFSMNT_NQNFS) {
if (NQNFS_CKINVALID(vp, np, NQL_READ)) {
do {
error = nqnfs_getlease(vp, NQL_READ, ap->a_cred, ap->a_p);
} while (error == NQNFS_EXPIRED);
if (error)
return (error);
if (np->n_lrev != np->n_brev ||
(np->n_flag & NQNFSNONCACHE)) {
if ((error = nfs_vinvalbuf(vp, V_SAVE, ap->a_cred,
ap->a_p, 1)) == EINTR)
return (error);
np->n_brev = np->n_lrev;
}
}
} else {
if (np->n_flag & NMODIFIED) {
if ((error = nfs_vinvalbuf(vp, V_SAVE, ap->a_cred,
ap->a_p, 1)) == EINTR)
return (error);
np->n_attrstamp = 0;
np->n_direofoffset = 0;
error = VOP_GETATTR(vp, &vattr, ap->a_cred, ap->a_p);
if (error)
return (error);
np->n_mtime = vattr.va_mtime.ts_sec;
} else {
error = VOP_GETATTR(vp, &vattr, ap->a_cred, ap->a_p);
if (error)
return (error);
if (np->n_mtime != vattr.va_mtime.ts_sec) {
np->n_direofoffset = 0;
if ((error = nfs_vinvalbuf(vp, V_SAVE,
ap->a_cred, ap->a_p, 1)) == EINTR)
return (error);
np->n_mtime = vattr.va_mtime.ts_sec;
}
}
}
if ((nmp->nm_flag & NFSMNT_NQNFS) == 0)
np->n_attrstamp = 0; /* For Open/Close consistency */
return (0);
}
/*
* nfs close vnode op
* For reg files, invalidate any buffer cache entries.
*/
/* ARGSUSED */
int
nfs_close(ap)
struct vop_close_args /* {
struct vnodeop_desc *a_desc;
struct vnode *a_vp;
int a_fflag;
struct ucred *a_cred;
struct proc *a_p;
} */ *ap;
{
register struct vnode *vp = ap->a_vp;
register struct nfsnode *np = VTONFS(vp);
int error = 0;
if (vp->v_type == VREG) {
if ((VFSTONFS(vp->v_mount)->nm_flag & NFSMNT_NQNFS) == 0 &&
(np->n_flag & NMODIFIED)) {
error = nfs_vinvalbuf(vp, V_SAVE, ap->a_cred, ap->a_p, 1);
np->n_attrstamp = 0;
}
if (np->n_flag & NWRITEERR) {
np->n_flag &= ~NWRITEERR;
error = np->n_error;
}
}
return (error);
}
/*
* nfs getattr call from vfs.
*/
int
nfs_getattr(ap)
struct vop_getattr_args /* {
struct vnode *a_vp;
struct vattr *a_vap;
struct ucred *a_cred;
struct proc *a_p;
} */ *ap;
{
register struct vnode *vp = ap->a_vp;
register struct nfsnode *np = VTONFS(vp);
register caddr_t cp;
caddr_t bpos, dpos;
int error = 0;
struct mbuf *mreq, *mrep, *md, *mb, *mb2;
/*
* Update local times for special files.
*/
if (np->n_flag & (NACC | NUPD))
np->n_flag |= NCHG;
/*
* First look in the cache.
*/
if (nfs_getattrcache(vp, ap->a_vap) == 0)
return (0);
nfsstats.rpccnt[NFSPROC_GETATTR]++;
nfsm_reqhead(vp, NFSPROC_GETATTR, NFSX_FH);
nfsm_fhtom(vp);
nfsm_request(vp, NFSPROC_GETATTR, ap->a_p, ap->a_cred);
nfsm_loadattr(vp, ap->a_vap);
nfsm_reqdone;
return (error);
}
/*
* nfs setattr call.
*/
int
nfs_setattr(ap)
struct vop_setattr_args /* {
struct vnodeop_desc *a_desc;
struct vnode *a_vp;
struct vattr *a_vap;
struct ucred *a_cred;
struct proc *a_p;
} */ *ap;
{
register struct nfsv2_sattr *sp;
register caddr_t cp;
register long t1;
caddr_t bpos, dpos, cp2;
u_long *tl;
int error = 0, isnq;
struct mbuf *mreq, *mrep, *md, *mb, *mb2;
register struct vnode *vp = ap->a_vp;
register struct nfsnode *np = VTONFS(vp);
register struct vattr *vap = ap->a_vap;
u_quad_t frev, tsize = 0;
if (vap->va_size != VNOVAL) {
switch (vp->v_type) {
case VDIR:
return (EISDIR);
case VCHR:
case VBLK:
if (vap->va_mtime.ts_sec == VNOVAL &&
vap->va_atime.ts_sec == VNOVAL &&
vap->va_mode == (u_short)VNOVAL &&
vap->va_uid == VNOVAL &&
vap->va_gid == VNOVAL)
return (0);
vap->va_size = VNOVAL;
break;
default:
if (np->n_flag & NMODIFIED) {
error = nfs_vinvalbuf(vp,
vap->va_size ? V_SAVE : 0,
ap->a_cred, ap->a_p, 1);
if (error)
return (error);
}
tsize = np->n_size;
np->n_size = np->n_vattr.va_size = vap->va_size;
vnode_pager_setsize(vp, (u_long)np->n_size);
}
} else if ((vap->va_mtime.ts_sec != VNOVAL ||
vap->va_atime.ts_sec != VNOVAL) && (np->n_flag & NMODIFIED)) {
error = nfs_vinvalbuf(vp, V_SAVE, ap->a_cred, ap->a_p, 1);
if (error == EINTR)
return (error);
}
nfsstats.rpccnt[NFSPROC_SETATTR]++;
isnq = (VFSTONFS(vp->v_mount)->nm_flag & NFSMNT_NQNFS);
nfsm_reqhead(vp, NFSPROC_SETATTR, NFSX_FH+NFSX_SATTR(isnq));
nfsm_fhtom(vp);
nfsm_build(sp, struct nfsv2_sattr *, NFSX_SATTR(isnq));
if (vap->va_mode == (u_short)-1)
sp->sa_mode = VNOVAL;
else
sp->sa_mode = vtonfs_mode(vp->v_type, vap->va_mode);
if (vap->va_uid == (uid_t)-1)
sp->sa_uid = VNOVAL;
else
sp->sa_uid = txdr_unsigned(vap->va_uid);
if (vap->va_gid == (gid_t)-1)
sp->sa_gid = VNOVAL;
else
sp->sa_gid = txdr_unsigned(vap->va_gid);
if (isnq) {
txdr_hyper(&vap->va_size, &sp->sa_nqsize);
txdr_nqtime(&vap->va_atime, &sp->sa_nqatime);
txdr_nqtime(&vap->va_mtime, &sp->sa_nqmtime);
sp->sa_nqflags = txdr_unsigned(vap->va_flags);
sp->sa_nqrdev = VNOVAL;
} else {
sp->sa_nfssize = txdr_unsigned(vap->va_size);
txdr_nfstime(&vap->va_atime, &sp->sa_nfsatime);
txdr_nfstime(&vap->va_mtime, &sp->sa_nfsmtime);
}
nfsm_request(vp, NFSPROC_SETATTR, ap->a_p, ap->a_cred);
nfsm_loadattr(vp, (struct vattr *)0);
if ((VFSTONFS(vp->v_mount)->nm_flag & NFSMNT_NQNFS) &&
NQNFS_CKCACHABLE(vp, NQL_WRITE)) {
nfsm_dissect(tl, u_long *, 2*NFSX_UNSIGNED);
fxdr_hyper(tl, &frev);
if (frev > np->n_brev)
np->n_brev = frev;
}
nfsm_reqdone;
if (error) {
np->n_size = np->n_vattr.va_size = tsize;
vnode_pager_setsize(vp, (u_long)np->n_size);
}
return (error);
}
/*
* nfs lookup call, one step at a time...
* First look in cache
* If not found, unlock the directory nfsnode and do the rpc
*/
int
nfs_lookup(ap)
struct vop_lookup_args /* {
struct vnodeop_desc *a_desc;
struct vnode *a_dvp;
struct vnode **a_vpp;
struct componentname *a_cnp;
} */ *ap;
{
register struct componentname *cnp = ap->a_cnp;
register struct vnode *dvp = ap->a_dvp;
register struct vnode **vpp = ap->a_vpp;
register int flags = cnp->cn_flags;
register struct vnode *vdp;
register u_long *tl;
register caddr_t cp;
register long t1, t2;
struct nfsmount *nmp;
caddr_t bpos, dpos, cp2;
time_t reqtime = 0;
struct mbuf *mreq, *mrep, *md, *mb, *mb2;
struct vnode *newvp;
long len;
nfsv2fh_t *fhp;
struct nfsnode *np;
int lockparent, wantparent, error = 0;
int nqlflag = 0, cachable = 0;
u_quad_t frev;
*vpp = NULL;
if (dvp->v_type != VDIR)
return (ENOTDIR);
lockparent = flags & LOCKPARENT;
wantparent = flags & (LOCKPARENT|WANTPARENT);
nmp = VFSTONFS(dvp->v_mount);
np = VTONFS(dvp);
if ((error = cache_lookup(dvp, vpp, cnp)) && error != ENOENT) {
struct vattr vattr;
int vpid;
vdp = *vpp;
vpid = vdp->v_id;
/*
* See the comment starting `Step through' in ufs/ufs_lookup.c
* for an explanation of the locking protocol
*/
if (dvp == vdp) {
VREF(vdp);
error = 0;
} else
error = vget(vdp, 1);
if (!error) {
if (vpid == vdp->v_id) {
if (nmp->nm_flag & NFSMNT_NQNFS) {
if ((nmp->nm_flag & NFSMNT_NQLOOKLEASE) == 0) {
nfsstats.lookupcache_hits++;
if (cnp->cn_nameiop != LOOKUP &&
(flags & ISLASTCN))
cnp->cn_flags |= SAVENAME;
return (0);
} else if (NQNFS_CKCACHABLE(dvp, NQL_READ)) {
if (np->n_lrev != np->n_brev ||
(np->n_flag & NMODIFIED)) {
np->n_direofoffset = 0;
cache_purge(dvp);
error = nfs_vinvalbuf(dvp, 0,
cnp->cn_cred, cnp->cn_proc,
1);
if (error == EINTR)
return (error);
np->n_brev = np->n_lrev;
} else {
nfsstats.lookupcache_hits++;
if (cnp->cn_nameiop != LOOKUP &&
(flags & ISLASTCN))
cnp->cn_flags |= SAVENAME;
return (0);
}
}
} else if (!VOP_GETATTR(vdp, &vattr, cnp->cn_cred, cnp->cn_proc) &&
vattr.va_ctime.ts_sec == VTONFS(vdp)->n_ctime) {
nfsstats.lookupcache_hits++;
if (cnp->cn_nameiop != LOOKUP &&
(flags & ISLASTCN))
cnp->cn_flags |= SAVENAME;
return (0);
}
cache_purge(vdp);
}
vrele(vdp);
}
*vpp = NULLVP;
}
error = 0;
nfsstats.lookupcache_misses++;
nfsstats.rpccnt[NFSPROC_LOOKUP]++;
len = cnp->cn_namelen;
nfsm_reqhead(dvp, NFSPROC_LOOKUP, NFSX_FH+NFSX_UNSIGNED+nfsm_rndup(len));
/*
* For nqnfs optionally piggyback a getlease request for the name
* being looked up.
*/
if (nmp->nm_flag & NFSMNT_NQNFS) {
nfsm_build(tl, u_long *, NFSX_UNSIGNED);
if ((nmp->nm_flag & NFSMNT_NQLOOKLEASE) &&
((cnp->cn_flags & MAKEENTRY) &&
(cnp->cn_nameiop != DELETE || !(flags & ISLASTCN))))
*tl = txdr_unsigned(nmp->nm_leaseterm);
else
*tl = 0;
}
nfsm_fhtom(dvp);
nfsm_strtom(cnp->cn_nameptr, len, NFS_MAXNAMLEN);
reqtime = time.tv_sec;
nfsm_request(dvp, NFSPROC_LOOKUP, cnp->cn_proc, cnp->cn_cred);
nfsmout:
if (error) {
if ((cnp->cn_nameiop == CREATE || cnp->cn_nameiop == RENAME) &&
(flags & ISLASTCN) && error == ENOENT)
error = EJUSTRETURN;
if (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN))
cnp->cn_flags |= SAVENAME;
return (error);
}
if (nmp->nm_flag & NFSMNT_NQNFS) {
nfsm_dissect(tl, u_long *, NFSX_UNSIGNED);
if (*tl) {
nqlflag = fxdr_unsigned(int, *tl);
nfsm_dissect(tl, u_long *, 4*NFSX_UNSIGNED);
cachable = fxdr_unsigned(int, *tl++);
reqtime += fxdr_unsigned(int, *tl++);
fxdr_hyper(tl, &frev);
} else
nqlflag = 0;
}
nfsm_dissect(fhp, nfsv2fh_t *, NFSX_FH);
/*
* Handle RENAME case...
*/
if (cnp->cn_nameiop == RENAME && wantparent && (flags & ISLASTCN)) {
if (!bcmp(np->n_fh.fh_bytes, (caddr_t)fhp, NFSX_FH)) {
m_freem(mrep);
return (EISDIR);
}
error = nfs_nget(dvp->v_mount, fhp, &np);
if (error) {
m_freem(mrep);
return (error);
}
newvp = NFSTOV(np);
error = nfs_loadattrcache(&newvp, &md, &dpos, (struct vattr*)0);
if (error) {
vrele(newvp);
m_freem(mrep);
return (error);
}
*vpp = newvp;
m_freem(mrep);
cnp->cn_flags |= SAVENAME;
return (0);
}
if (!bcmp(np->n_fh.fh_bytes, (caddr_t)fhp, NFSX_FH)) {
VREF(dvp);
newvp = dvp;
} else {
error = nfs_nget(dvp->v_mount, fhp, &np);
if (error) {
m_freem(mrep);
return (error);
}
newvp = NFSTOV(np);
}
error = nfs_loadattrcache(&newvp, &md, &dpos, (struct vattr *)0);
if (error) {
vrele(newvp);
m_freem(mrep);
return (error);
}
m_freem(mrep);
*vpp = newvp;
if (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN))
cnp->cn_flags |= SAVENAME;
if ((cnp->cn_flags & MAKEENTRY) &&
(cnp->cn_nameiop != DELETE || !(flags & ISLASTCN))) {
if ((nmp->nm_flag & NFSMNT_NQNFS) == 0)
np->n_ctime = np->n_vattr.va_ctime.ts_sec;
else if (nqlflag && reqtime > time.tv_sec)
nqnfs_clientlease(nmp, np, nqlflag, cachable, reqtime,
frev);
cache_enter(dvp, *vpp, cnp);
}
return (0);
}
/*
* nfs read call.
* Just call nfs_bioread() to do the work.
*/
int
nfs_read(ap)
struct vop_read_args /* {
struct vnode *a_vp;
struct uio *a_uio;
int a_ioflag;
struct ucred *a_cred;
} */ *ap;
{
register struct vnode *vp = ap->a_vp;
if (vp->v_type != VREG)
return (EPERM);
return (nfs_bioread(vp, ap->a_uio, ap->a_ioflag, ap->a_cred));
}
/*
* nfs readlink call
*/
int
nfs_readlink(ap)
struct vop_readlink_args /* {
struct vnode *a_vp;
struct uio *a_uio;
struct ucred *a_cred;
} */ *ap;
{
register struct vnode *vp = ap->a_vp;
if (vp->v_type != VLNK)
return (EPERM);
return (nfs_bioread(vp, ap->a_uio, 0, ap->a_cred));
}
/*
* Do a readlink rpc.
* Called by nfs_doio() from below the buffer cache.
*/
int
nfs_readlinkrpc(vp, uiop, cred)
register struct vnode *vp;
struct uio *uiop;
struct ucred *cred;
{
register u_long *tl;
register caddr_t cp;
register long t1;
caddr_t bpos, dpos, cp2;
int error = 0;
struct mbuf *mreq, *mrep, *md, *mb, *mb2;
long len;
nfsstats.rpccnt[NFSPROC_READLINK]++;
nfsm_reqhead(vp, NFSPROC_READLINK, NFSX_FH);
nfsm_fhtom(vp);
nfsm_request(vp, NFSPROC_READLINK, uiop->uio_procp, cred);
nfsm_strsiz(len, NFS_MAXPATHLEN);
nfsm_mtouio(uiop, len);
nfsm_reqdone;
return (error);
}
/*
* nfs read rpc call
* Ditto above
*/
int
nfs_readrpc(vp, uiop, cred)
register struct vnode *vp;
struct uio *uiop;
struct ucred *cred;
{
register u_long *tl;
register caddr_t cp;
register long t1;
caddr_t bpos, dpos, cp2;
int error = 0;
struct mbuf *mreq, *mrep, *md, *mb, *mb2;
struct nfsmount *nmp;
long len, retlen, tsiz;
nmp = VFSTONFS(vp->v_mount);
tsiz = uiop->uio_resid;
if (uiop->uio_offset + tsiz > 0xffffffff &&
(nmp->nm_flag & NFSMNT_NQNFS) == 0)
return (EFBIG);
while (tsiz > 0) {
nfsstats.rpccnt[NFSPROC_READ]++;
len = (tsiz > nmp->nm_rsize) ? nmp->nm_rsize : tsiz;
nfsm_reqhead(vp, NFSPROC_READ, NFSX_FH+NFSX_UNSIGNED*3);
nfsm_fhtom(vp);
nfsm_build(tl, u_long *, NFSX_UNSIGNED*3);
if (nmp->nm_flag & NFSMNT_NQNFS) {
txdr_hyper(&uiop->uio_offset, tl);
*(tl + 2) = txdr_unsigned(len);
} else {
*tl++ = txdr_unsigned(uiop->uio_offset);
*tl++ = txdr_unsigned(len);
*tl = 0;
}
nfsm_request(vp, NFSPROC_READ, uiop->uio_procp, cred);
nfsm_loadattr(vp, (struct vattr *)0);
nfsm_strsiz(retlen, nmp->nm_rsize);
nfsm_mtouio(uiop, retlen);
m_freem(mrep);
if (retlen < len)
tsiz = 0;
else
tsiz -= len;
}
nfsmout:
return (error);
}
/*
* nfs write call
*/
int
nfs_writerpc(vp, uiop, cred, ioflags)
register struct vnode *vp;
struct uio *uiop;
struct ucred *cred;
int ioflags;
{
register u_long *tl;
register caddr_t cp;
register long t1;
caddr_t bpos, dpos, cp2;
int error = 0;
struct mbuf *mreq, *mrep, *md, *mb, *mb2;
struct nfsmount *nmp;
struct nfsnode *np = VTONFS(vp);
u_quad_t frev;
long len, tsiz;
nmp = VFSTONFS(vp->v_mount);
tsiz = uiop->uio_resid;
if (uiop->uio_offset + tsiz > 0xffffffff &&
(nmp->nm_flag & NFSMNT_NQNFS) == 0)
return (EFBIG);
while (tsiz > 0) {
nfsstats.rpccnt[NFSPROC_WRITE]++;
len = (tsiz > nmp->nm_wsize) ? nmp->nm_wsize : tsiz;
nfsm_reqhead(vp, NFSPROC_WRITE,
NFSX_FH+NFSX_UNSIGNED*4+nfsm_rndup(len));
nfsm_fhtom(vp);
nfsm_build(tl, u_long *, NFSX_UNSIGNED * 4);
if (nmp->nm_flag & NFSMNT_NQNFS) {
txdr_hyper(&uiop->uio_offset, tl);
tl += 2;
#ifdef notyet
if (ioflags & IO_APPEND)
*tl++ = txdr_unsigned(1);
else
#endif
*tl++ = 0;
} else {
*++tl = txdr_unsigned(uiop->uio_offset);
tl += 2;
}
*tl = txdr_unsigned(len);
nfsm_uiotom(uiop, len);
nfsm_request(vp, NFSPROC_WRITE, uiop->uio_procp, cred);
nfsm_loadattr(vp, (struct vattr *)0);
if (nmp->nm_flag & NFSMNT_MYWRITE)
VTONFS(vp)->n_mtime = VTONFS(vp)->n_vattr.va_mtime.ts_sec;
else if ((nmp->nm_flag & NFSMNT_NQNFS) &&
NQNFS_CKCACHABLE(vp, NQL_WRITE)) {
nfsm_dissect(tl, u_long *, 2*NFSX_UNSIGNED);
fxdr_hyper(tl, &frev);
if (frev > np->n_brev)
np->n_brev = frev;
}
m_freem(mrep);
tsiz -= len;
}
nfsmout:
if (error)
uiop->uio_resid = tsiz;
return (error);
}
/*
* nfs mknod call
* This is a kludge. Use a create rpc but with the IFMT bits of the mode
* set to specify the file type and the size field for rdev.
*/
/* ARGSUSED */
int
nfs_mknod(ap)
struct vop_mknod_args /* {
struct vnode *a_dvp;
struct vnode **a_vpp;
struct componentname *a_cnp;
struct vattr *a_vap;
} */ *ap;
{
register struct vnode *dvp = ap->a_dvp;
register struct vattr *vap = ap->a_vap;
register struct componentname *cnp = ap->a_cnp;
register struct nfsv2_sattr *sp;
register u_long *tl;
register caddr_t cp;
register long t1, t2;
struct vnode *newvp = 0;
struct vattr vattr;
char *cp2;
caddr_t bpos, dpos;
int error = 0, isnq;
struct mbuf *mreq, *mrep, *md, *mb, *mb2;
u_long rdev;
isnq = (VFSTONFS(dvp->v_mount)->nm_flag & NFSMNT_NQNFS);
if (vap->va_type == VCHR || vap->va_type == VBLK)
rdev = txdr_unsigned(vap->va_rdev);
else if (vap->va_type == VFIFO)
rdev = 0xffffffff;
else {
VOP_ABORTOP(dvp, cnp);
vput(dvp);
return (EOPNOTSUPP);
}
error = VOP_GETATTR(dvp, &vattr, cnp->cn_cred, cnp->cn_proc);
if (error) {
VOP_ABORTOP(dvp, cnp);
vput(dvp);
return (error);
}
newvp = NULLVP;
nfsstats.rpccnt[NFSPROC_CREATE]++;
nfsm_reqhead(dvp, NFSPROC_CREATE,
NFSX_FH+NFSX_UNSIGNED+nfsm_rndup(cnp->cn_namelen)+NFSX_SATTR(isnq));
nfsm_fhtom(dvp);
nfsm_strtom(cnp->cn_nameptr, cnp->cn_namelen, NFS_MAXNAMLEN);
nfsm_build(sp, struct nfsv2_sattr *, NFSX_SATTR(isnq));
sp->sa_mode = vtonfs_mode(vap->va_type, vap->va_mode);
sp->sa_uid = txdr_unsigned(cnp->cn_cred->cr_uid);
sp->sa_gid = txdr_unsigned(vattr.va_gid);
if (isnq) {
sp->sa_nqrdev = rdev;
sp->sa_nqflags = 0;
txdr_nqtime(&vap->va_atime, &sp->sa_nqatime);
txdr_nqtime(&vap->va_mtime, &sp->sa_nqmtime);
} else {
sp->sa_nfssize = rdev;
txdr_nfstime(&vap->va_atime, &sp->sa_nfsatime);
txdr_nfstime(&vap->va_mtime, &sp->sa_nfsmtime);
}
nfsm_request(dvp, NFSPROC_CREATE, cnp->cn_proc, cnp->cn_cred);
nfsm_mtofh(dvp, newvp);
nfsm_reqdone;
if (!error && (cnp->cn_flags & MAKEENTRY))
cache_enter(dvp, newvp, cnp);
FREE(cnp->cn_pnbuf, M_NAMEI);
VTONFS(dvp)->n_flag |= NMODIFIED;
VTONFS(dvp)->n_attrstamp = 0;
vrele(dvp);
if (newvp != NULLVP)
vrele(newvp);
return (error);
}
/*
* nfs file create call
*/
int
nfs_create(ap)
struct vop_create_args /* {
struct vnode *a_dvp;
struct vnode **a_vpp;
struct componentname *a_cnp;
struct vattr *a_vap;
} */ *ap;
{
register struct vnode *dvp = ap->a_dvp;
register struct vattr *vap = ap->a_vap;
register struct componentname *cnp = ap->a_cnp;
register struct nfsv2_sattr *sp;
register u_long *tl;
register caddr_t cp;
register long t1, t2;
caddr_t bpos, dpos, cp2;
int error = 0, isnq;
struct mbuf *mreq, *mrep, *md, *mb, *mb2;
struct vattr vattr;
error = VOP_GETATTR(dvp, &vattr, cnp->cn_cred, cnp->cn_proc);
if (error) {
VOP_ABORTOP(dvp, cnp);
vput(dvp);
return (error);
}
nfsstats.rpccnt[NFSPROC_CREATE]++;
isnq = (VFSTONFS(dvp->v_mount)->nm_flag & NFSMNT_NQNFS);
nfsm_reqhead(dvp, NFSPROC_CREATE,
NFSX_FH+NFSX_UNSIGNED+nfsm_rndup(cnp->cn_namelen)+NFSX_SATTR(isnq));
nfsm_fhtom(dvp);
nfsm_strtom(cnp->cn_nameptr, cnp->cn_namelen, NFS_MAXNAMLEN);
nfsm_build(sp, struct nfsv2_sattr *, NFSX_SATTR(isnq));
sp->sa_mode = vtonfs_mode(vap->va_type, vap->va_mode);
sp->sa_uid = txdr_unsigned(cnp->cn_cred->cr_uid);
sp->sa_gid = txdr_unsigned(vattr.va_gid);
if (isnq) {
u_quad_t qval = 0;
txdr_hyper(&qval, &sp->sa_nqsize);
sp->sa_nqflags = 0;
sp->sa_nqrdev = -1;
txdr_nqtime(&vap->va_atime, &sp->sa_nqatime);
txdr_nqtime(&vap->va_mtime, &sp->sa_nqmtime);
} else {
sp->sa_nfssize = 0;
txdr_nfstime(&vap->va_atime, &sp->sa_nfsatime);
txdr_nfstime(&vap->va_mtime, &sp->sa_nfsmtime);
}
nfsm_request(dvp, NFSPROC_CREATE, cnp->cn_proc, cnp->cn_cred);
nfsm_mtofh(dvp, *ap->a_vpp);
nfsm_reqdone;
if (!error && (cnp->cn_flags & MAKEENTRY))
cache_enter(dvp, *ap->a_vpp, cnp);
FREE(cnp->cn_pnbuf, M_NAMEI);
VTONFS(dvp)->n_flag |= NMODIFIED;
VTONFS(dvp)->n_attrstamp = 0;
vrele(dvp);
return (error);
}
/*
* nfs file remove call
* To try and make nfs semantics closer to ufs semantics, a file that has
* other processes using the vnode is renamed instead of removed and then
* removed later on the last close.
* - If v_usecount > 1
* If a rename is not already in the works
* call nfs_sillyrename() to set it up
* else
* do the remove rpc
*/
int
nfs_remove(ap)
struct vop_remove_args /* {
struct vnodeop_desc *a_desc;
struct vnode * a_dvp;
struct vnode * a_vp;
struct componentname * a_cnp;
} */ *ap;
{
register struct vnode *vp = ap->a_vp;
register struct vnode *dvp = ap->a_dvp;
register struct componentname *cnp = ap->a_cnp;
register struct nfsnode *np = VTONFS(vp);
register u_long *tl;
register caddr_t cp;
register long t2;
caddr_t bpos, dpos;
int error = 0;
struct mbuf *mreq, *mrep, *md, *mb, *mb2;
struct vattr vattr;
if (vp->v_usecount > 1) {
if (!np->n_sillyrename)
error = nfs_sillyrename(dvp, vp, cnp);
else if (VOP_GETATTR(vp, &vattr, cnp->cn_cred, cnp->cn_proc)
== 0 && vattr.va_nlink > 1)
/*
* If we already have a silly name but there are more
* than one links, just proceed with the NFS remove
* request, as the bits will remain available (modulo
* network races). This avoids silently ignoring the
* attempted removal of a non-silly entry.
*/
goto doit;
} else {
doit:
/*
* Purge the name cache so that the chance of a lookup for
* the name succeeding while the remove is in progress is
* minimized. Without node locking it can still happen, such
* that an I/O op returns ESTALE, but since you get this if
* another host removes the file..
*/
cache_purge(vp);
/*
* Throw away biocache buffers. Mainly to avoid
* unnecessary delayed writes.
*/
error = nfs_vinvalbuf(vp, 0, cnp->cn_cred, cnp->cn_proc, 1);
if (error == EINTR)
return (error);
/* Do the rpc */
nfsstats.rpccnt[NFSPROC_REMOVE]++;
nfsm_reqhead(dvp, NFSPROC_REMOVE,
NFSX_FH+NFSX_UNSIGNED+nfsm_rndup(cnp->cn_namelen));
nfsm_fhtom(dvp);
nfsm_strtom(cnp->cn_nameptr, cnp->cn_namelen, NFS_MAXNAMLEN);
nfsm_request(dvp, NFSPROC_REMOVE, cnp->cn_proc, cnp->cn_cred);
nfsm_reqdone;
FREE(cnp->cn_pnbuf, M_NAMEI);
VTONFS(dvp)->n_flag |= NMODIFIED;
VTONFS(dvp)->n_attrstamp = 0;
/*
* Kludge City: If the first reply to the remove rpc is lost..
* the reply to the retransmitted request will be ENOENT
* since the file was in fact removed
* Therefore, we cheat and return success.
*/
if (error == ENOENT)
error = 0;
}
np->n_attrstamp = 0;
vrele(dvp);
vrele(vp);
return (error);
}
/*
* nfs file remove rpc called from nfs_inactive
*/
int
nfs_removeit(sp)
register struct sillyrename *sp;
{
register u_long *tl;
register caddr_t cp;
register long t2;
caddr_t bpos, dpos;
int error = 0;
struct mbuf *mreq, *mrep, *md, *mb, *mb2;
nfsstats.rpccnt[NFSPROC_REMOVE]++;
nfsm_reqhead(sp->s_dvp, NFSPROC_REMOVE,
NFSX_FH+NFSX_UNSIGNED+nfsm_rndup(sp->s_namlen));
nfsm_fhtom(sp->s_dvp);
nfsm_strtom(sp->s_name, sp->s_namlen, NFS_MAXNAMLEN);
nfsm_request(sp->s_dvp, NFSPROC_REMOVE, NULL, sp->s_cred);
nfsm_reqdone;
VTONFS(sp->s_dvp)->n_flag |= NMODIFIED;
VTONFS(sp->s_dvp)->n_attrstamp = 0;
return (error);
}
/*
* nfs file rename call
*/
int
nfs_rename(ap)
struct vop_rename_args /* {
struct vnode *a_fdvp;
struct vnode *a_fvp;
struct componentname *a_fcnp;
struct vnode *a_tdvp;
struct vnode *a_tvp;
struct componentname *a_tcnp;
} */ *ap;
{
register struct vnode *fvp = ap->a_fvp;
register struct vnode *tvp = ap->a_tvp;
register struct vnode *fdvp = ap->a_fdvp;
register struct vnode *tdvp = ap->a_tdvp;
register struct componentname *tcnp = ap->a_tcnp;
register struct componentname *fcnp = ap->a_fcnp;
register u_long *tl;
register caddr_t cp;
register long t2;
caddr_t bpos, dpos;
int error = 0;
struct mbuf *mreq, *mrep, *md, *mb, *mb2;
/* Check for cross-device rename */
if ((fvp->v_mount != tdvp->v_mount) ||
(tvp && (fvp->v_mount != tvp->v_mount))) {
error = EXDEV;
goto out;
}
nfsstats.rpccnt[NFSPROC_RENAME]++;
nfsm_reqhead(fdvp, NFSPROC_RENAME,
(NFSX_FH+NFSX_UNSIGNED)*2+nfsm_rndup(fcnp->cn_namelen)+
nfsm_rndup(fcnp->cn_namelen)); /* or fcnp->cn_cred?*/
nfsm_fhtom(fdvp);
nfsm_strtom(fcnp->cn_nameptr, fcnp->cn_namelen, NFS_MAXNAMLEN);
nfsm_fhtom(tdvp);
nfsm_strtom(tcnp->cn_nameptr, tcnp->cn_namelen, NFS_MAXNAMLEN);
nfsm_request(fdvp, NFSPROC_RENAME, tcnp->cn_proc, tcnp->cn_cred);
nfsm_reqdone;
VTONFS(fdvp)->n_flag |= NMODIFIED;
VTONFS(fdvp)->n_attrstamp = 0;
VTONFS(tdvp)->n_flag |= NMODIFIED;
VTONFS(tdvp)->n_attrstamp = 0;
if (fvp->v_type == VDIR) {
if (tvp != NULL && tvp->v_type == VDIR)
cache_purge(tdvp);
cache_purge(fdvp);
}
out:
if (tdvp == tvp)
vrele(tdvp);
else
vput(tdvp);
if (tvp)
vput(tvp);
vrele(fdvp);
vrele(fvp);
/*
* Kludge: Map ENOENT => 0 assuming that it is a reply to a retry.
*/
if (error == ENOENT)
error = 0;
return (error);
}
/*
* nfs file rename rpc called from nfs_remove() above
*/
int
nfs_renameit(sdvp, scnp, sp)
struct vnode *sdvp;
struct componentname *scnp;
register struct sillyrename *sp;
{
register u_long *tl;
register caddr_t cp;
register long t2;
caddr_t bpos, dpos;
int error = 0;
struct mbuf *mreq, *mrep, *md, *mb, *mb2;
nfsstats.rpccnt[NFSPROC_RENAME]++;
nfsm_reqhead(sdvp, NFSPROC_RENAME,
(NFSX_FH+NFSX_UNSIGNED)*2+nfsm_rndup(scnp->cn_namelen)+
nfsm_rndup(sp->s_namlen));
nfsm_fhtom(sdvp);
nfsm_strtom(scnp->cn_nameptr, scnp->cn_namelen, NFS_MAXNAMLEN);
nfsm_fhtom(sdvp);
nfsm_strtom(sp->s_name, sp->s_namlen, NFS_MAXNAMLEN);
nfsm_request(sdvp, NFSPROC_RENAME, scnp->cn_proc, scnp->cn_cred);
nfsm_reqdone;
FREE(scnp->cn_pnbuf, M_NAMEI);
VTONFS(sdvp)->n_flag |= NMODIFIED;
VTONFS(sdvp)->n_attrstamp = 0;
return (error);
}
/*
* nfs hard link create call
*/
int
nfs_link(ap)
struct vop_link_args /* {
struct vnode *a_vp;
struct vnode *a_tdvp;
struct componentname *a_cnp;
} */ *ap;
{
register struct vnode *vp = ap->a_vp;
register struct vnode *tdvp = ap->a_tdvp;
register struct componentname *cnp = ap->a_cnp;
register u_long *tl;
register caddr_t cp;
register long t2;
caddr_t bpos, dpos;
int error = 0;
struct mbuf *mreq, *mrep, *md, *mb, *mb2;
if (vp->v_mount != tdvp->v_mount) {
/*VOP_ABORTOP(vp, cnp);*/
if (tdvp == vp)
vrele(vp);
else
vput(vp);
return (EXDEV);
}
/*
* Push all writes to the server, so that the attribute cache
* doesn't get "out of sync" with the server.
* XXX There should be a better way!
*/
VOP_FSYNC(tdvp, cnp->cn_cred, MNT_WAIT, cnp->cn_proc);
nfsstats.rpccnt[NFSPROC_LINK]++;
nfsm_reqhead(tdvp, NFSPROC_LINK,
NFSX_FH*2+NFSX_UNSIGNED+nfsm_rndup(cnp->cn_namelen));
nfsm_fhtom(tdvp);
nfsm_fhtom(vp);
nfsm_strtom(cnp->cn_nameptr, cnp->cn_namelen, NFS_MAXNAMLEN);
nfsm_request(tdvp, NFSPROC_LINK, cnp->cn_proc, cnp->cn_cred);
nfsm_reqdone;
FREE(cnp->cn_pnbuf, M_NAMEI);
VTONFS(tdvp)->n_attrstamp = 0;
VTONFS(vp)->n_flag |= NMODIFIED;
VTONFS(vp)->n_attrstamp = 0;
vrele(vp);
/*
* Kludge: Map EEXIST => 0 assuming that it is a reply to a retry.
*/
if (error == EEXIST)
error = 0;
return (error);
}
/*
* nfs symbolic link create call
*/
/* start here */
int
nfs_symlink(ap)
struct vop_symlink_args /* {
struct vnode *a_dvp;
struct vnode **a_vpp;
struct componentname *a_cnp;
struct vattr *a_vap;
char *a_target;
} */ *ap;
{
register struct vnode *dvp = ap->a_dvp;
register struct vattr *vap = ap->a_vap;
register struct componentname *cnp = ap->a_cnp;
register struct nfsv2_sattr *sp;
register u_long *tl;
register caddr_t cp;
register long t2;
caddr_t bpos, dpos;
int slen, error = 0, isnq;
struct mbuf *mreq, *mrep, *md, *mb, *mb2;
nfsstats.rpccnt[NFSPROC_SYMLINK]++;
slen = strlen(ap->a_target);
isnq = (VFSTONFS(dvp->v_mount)->nm_flag & NFSMNT_NQNFS);
nfsm_reqhead(dvp, NFSPROC_SYMLINK, NFSX_FH+2*NFSX_UNSIGNED+
nfsm_rndup(cnp->cn_namelen)+nfsm_rndup(slen)+NFSX_SATTR(isnq));
nfsm_fhtom(dvp);
nfsm_strtom(cnp->cn_nameptr, cnp->cn_namelen, NFS_MAXNAMLEN);
nfsm_strtom(ap->a_target, slen, NFS_MAXPATHLEN);
nfsm_build(sp, struct nfsv2_sattr *, NFSX_SATTR(isnq));
sp->sa_mode = vtonfs_mode(VLNK, vap->va_mode);
sp->sa_uid = txdr_unsigned(cnp->cn_cred->cr_uid);
sp->sa_gid = txdr_unsigned(cnp->cn_cred->cr_gid);
if (isnq) {
quad_t qval = -1;
txdr_hyper(&qval, &sp->sa_nqsize);
sp->sa_nqflags = 0;
txdr_nqtime(&vap->va_atime, &sp->sa_nqatime);
txdr_nqtime(&vap->va_mtime, &sp->sa_nqmtime);
} else {
sp->sa_nfssize = -1;
txdr_nfstime(&vap->va_atime, &sp->sa_nfsatime);
txdr_nfstime(&vap->va_mtime, &sp->sa_nfsmtime);
}
nfsm_request(dvp, NFSPROC_SYMLINK, cnp->cn_proc, cnp->cn_cred);
nfsm_reqdone;
FREE(cnp->cn_pnbuf, M_NAMEI);
VTONFS(dvp)->n_flag |= NMODIFIED;
VTONFS(dvp)->n_attrstamp = 0;
vrele(dvp);
/*
* Kludge: Map EEXIST => 0 assuming that it is a reply to a retry.
*/
if (error == EEXIST)
error = 0;
return (error);
}
/*
* nfs make dir call
*/
int
nfs_mkdir(ap)
struct vop_mkdir_args /* {
struct vnode *a_dvp;
struct vnode **a_vpp;
struct componentname *a_cnp;
struct vattr *a_vap;
} */ *ap;
{
register struct vnode *dvp = ap->a_dvp;
register struct vattr *vap = ap->a_vap;
register struct componentname *cnp = ap->a_cnp;
register struct vnode **vpp = ap->a_vpp;
register struct nfsv2_sattr *sp;
register u_long *tl;
register caddr_t cp;
register long t1, t2;
register int len;
caddr_t bpos, dpos, cp2;
int error = 0, firsttry = 1, isnq;
struct mbuf *mreq, *mrep, *md, *mb, *mb2;
struct vattr vattr;
error = VOP_GETATTR(dvp, &vattr, cnp->cn_cred, cnp->cn_proc);
if (error) {
VOP_ABORTOP(dvp, cnp);
vput(dvp);
return (error);
}
len = cnp->cn_namelen;
isnq = (VFSTONFS(dvp->v_mount)->nm_flag & NFSMNT_NQNFS);
nfsstats.rpccnt[NFSPROC_MKDIR]++;
nfsm_reqhead(dvp, NFSPROC_MKDIR,
NFSX_FH+NFSX_UNSIGNED+nfsm_rndup(len)+NFSX_SATTR(isnq));
nfsm_fhtom(dvp);
nfsm_strtom(cnp->cn_nameptr, len, NFS_MAXNAMLEN);
nfsm_build(sp, struct nfsv2_sattr *, NFSX_SATTR(isnq));
sp->sa_mode = vtonfs_mode(VDIR, vap->va_mode);
sp->sa_uid = txdr_unsigned(cnp->cn_cred->cr_uid);
sp->sa_gid = txdr_unsigned(vattr.va_gid);
if (isnq) {
quad_t qval = -1;
txdr_hyper(&qval, &sp->sa_nqsize);
sp->sa_nqflags = 0;
txdr_nqtime(&vap->va_atime, &sp->sa_nqatime);
txdr_nqtime(&vap->va_mtime, &sp->sa_nqmtime);
} else {
sp->sa_nfssize = -1;
txdr_nfstime(&vap->va_atime, &sp->sa_nfsatime);
txdr_nfstime(&vap->va_mtime, &sp->sa_nfsmtime);
}
nfsm_request(dvp, NFSPROC_MKDIR, cnp->cn_proc, cnp->cn_cred);
nfsm_mtofh(dvp, *vpp);
nfsm_reqdone;
VTONFS(dvp)->n_flag |= NMODIFIED;
VTONFS(dvp)->n_attrstamp = 0;
/*
* Kludge: Map EEXIST => 0 assuming that you have a reply to a retry
* if we can succeed in looking up the directory.
* "firsttry" is necessary since the macros may "goto nfsmout" which
* is above the if on errors. (Ugh)
*/
if (error == EEXIST && firsttry) {
firsttry = 0;
error = 0;
nfsstats.rpccnt[NFSPROC_LOOKUP]++;
*vpp = NULL;
nfsm_reqhead(dvp, NFSPROC_LOOKUP,
NFSX_FH+NFSX_UNSIGNED+nfsm_rndup(len));
nfsm_fhtom(dvp);
nfsm_strtom(cnp->cn_nameptr, len, NFS_MAXNAMLEN);
nfsm_request(dvp, NFSPROC_LOOKUP, cnp->cn_proc, cnp->cn_cred);
nfsm_mtofh(dvp, *vpp);
if ((*vpp)->v_type != VDIR) {
vput(*vpp);
error = EEXIST;
}
m_freem(mrep);
}
FREE(cnp->cn_pnbuf, M_NAMEI);
vrele(dvp);
return (error);
}
/*
* nfs remove directory call
*/
int
nfs_rmdir(ap)
struct vop_rmdir_args /* {
struct vnode *a_dvp;
struct vnode *a_vp;
struct componentname *a_cnp;
} */ *ap;
{
register struct vnode *vp = ap->a_vp;
register struct vnode *dvp = ap->a_dvp;
register struct componentname *cnp = ap->a_cnp;
register u_long *tl;
register caddr_t cp;
register long t2;
caddr_t bpos, dpos;
int error = 0;
struct mbuf *mreq, *mrep, *md, *mb, *mb2;
if (dvp == vp) {
vrele(dvp);
vrele(dvp);
FREE(cnp->cn_pnbuf, M_NAMEI);
return (EINVAL);
}
nfsstats.rpccnt[NFSPROC_RMDIR]++;
nfsm_reqhead(dvp, NFSPROC_RMDIR,
NFSX_FH+NFSX_UNSIGNED+nfsm_rndup(cnp->cn_namelen));
nfsm_fhtom(dvp);
nfsm_strtom(cnp->cn_nameptr, cnp->cn_namelen, NFS_MAXNAMLEN);
nfsm_request(dvp, NFSPROC_RMDIR, cnp->cn_proc, cnp->cn_cred);
nfsm_reqdone;
FREE(cnp->cn_pnbuf, M_NAMEI);
VTONFS(dvp)->n_flag |= NMODIFIED;
VTONFS(dvp)->n_attrstamp = 0;
cache_purge(dvp);
cache_purge(vp);
vrele(vp);
vrele(dvp);
/*
* Kludge: Map ENOENT => 0 assuming that you have a reply to a retry.
*/
if (error == ENOENT)
error = 0;
return (error);
}
/*
* nfs readdir call
* Although cookie is defined as opaque, I translate it to/from net byte
* order so that it looks more sensible. This appears consistent with the
* Ultrix implementation of NFS.
*/
int
nfs_readdir(ap)
struct vop_readdir_args /* {
struct vnode *a_vp;
struct uio *a_uio;
struct ucred *a_cred;
} */ *ap;
{
register struct vnode *vp = ap->a_vp;
register struct nfsnode *np = VTONFS(vp);
register struct uio *uio = ap->a_uio;
int tresid, error;
struct vattr vattr;
if (vp->v_type != VDIR)
return (EPERM);
/*
* First, check for hit on the EOF offset cache
*/
if (uio->uio_offset != 0 && uio->uio_offset == np->n_direofoffset &&
(np->n_flag & NMODIFIED) == 0) {
if (VFSTONFS(vp->v_mount)->nm_flag & NFSMNT_NQNFS) {
if (NQNFS_CKCACHABLE(vp, NQL_READ)) {
nfsstats.direofcache_hits++;
return (0);
}
} else if (VOP_GETATTR(vp, &vattr, ap->a_cred, uio->uio_procp) == 0 &&
np->n_mtime == vattr.va_mtime.ts_sec) {
nfsstats.direofcache_hits++;
return (0);
}
}
/*
* Call nfs_bioread() to do the real work.
*/
tresid = uio->uio_resid;
error = nfs_bioread(vp, uio, 0, ap->a_cred);
if (!error && uio->uio_resid == tresid)
nfsstats.direofcache_misses++;
return (error);
}
/*
* Readdir rpc call.
* Called from below the buffer cache by nfs_doio().
*/
int
nfs_readdirrpc(vp, uiop, cred)
register struct vnode *vp;
struct uio *uiop;
struct ucred *cred;
{
register long len;
register struct dirent *dp = 0;
register u_long *tl;
register caddr_t cp;
register long t1;
long tlen, lastlen = 0;
caddr_t bpos, dpos, cp2;
int error = 0;
struct mbuf *mreq, *mrep, *md, *mb, *mb2;
struct mbuf *md2;
caddr_t dpos2;
int siz;
int more_dirs = 1;
u_long off, savoff = 0;
struct dirent *savdp = 0;
struct nfsmount *nmp;
struct nfsnode *np = VTONFS(vp);
long tresid;
nmp = VFSTONFS(vp->v_mount);
tresid = uiop->uio_resid;
/*
* Loop around doing readdir rpc's of size uio_resid or nm_rsize,
* whichever is smaller, truncated to a multiple of NFS_DIRBLKSIZ.
* The stopping criteria is EOF or buffer full.
*/
while (more_dirs && uiop->uio_resid >= NFS_DIRBLKSIZ) {
nfsstats.rpccnt[NFSPROC_READDIR]++;
nfsm_reqhead(vp, NFSPROC_READDIR,
NFSX_FH + 2 * NFSX_UNSIGNED);
nfsm_fhtom(vp);
nfsm_build(tl, u_long *, 2 * NFSX_UNSIGNED);
off = (u_long)uiop->uio_offset;
*tl++ = txdr_unsigned(off);
*tl = txdr_unsigned(((uiop->uio_resid > nmp->nm_rsize) ?
nmp->nm_rsize : uiop->uio_resid) & ~(NFS_DIRBLKSIZ-1));
nfsm_request(vp, NFSPROC_READDIR, uiop->uio_procp, cred);
siz = 0;
nfsm_dissect(tl, u_long *, NFSX_UNSIGNED);
more_dirs = fxdr_unsigned(int, *tl);
/* Save the position so that we can do nfsm_mtouio() later */
dpos2 = dpos;
md2 = md;
/* loop thru the dir entries, doctoring them to 4bsd form */
#ifdef lint
dp = (struct dirent *)0;
#endif /* lint */
while (more_dirs && siz < uiop->uio_resid) {
savoff = off; /* Hold onto offset and dp */
savdp = dp;
nfsm_dissect(tl, u_long *, 2 * NFSX_UNSIGNED);
dp = (struct dirent *)tl;
dp->d_fileno = fxdr_unsigned(u_long, *tl++);
len = fxdr_unsigned(int, *tl);
if (len <= 0 || len > NFS_MAXNAMLEN) {
error = EBADRPC;
m_freem(mrep);
goto nfsmout;
}
dp->d_namlen = (u_char)len;
dp->d_type = DT_UNKNOWN;
nfsm_adv(len); /* Point past name */
tlen = nfsm_rndup(len);
/*
* This should not be necessary, but some servers have
* broken XDR such that these bytes are not null filled.
*/
if (tlen != len) {
*dpos = '\0'; /* Null-terminate */
nfsm_adv(tlen - len);
len = tlen;
}
nfsm_dissect(tl, u_long *, 2 * NFSX_UNSIGNED);
off = fxdr_unsigned(u_long, *tl);
*tl++ = 0; /* Ensures null termination of name */
more_dirs = fxdr_unsigned(int, *tl);
dp->d_reclen = len + 4 * NFSX_UNSIGNED;
siz += dp->d_reclen;
}
/*
* If at end of rpc data, get the eof boolean
*/
if (!more_dirs) {
nfsm_dissect(tl, u_long *, NFSX_UNSIGNED);
more_dirs = (fxdr_unsigned(int, *tl) == 0);
/*
* If at EOF, cache directory offset
*/
if (!more_dirs)
np->n_direofoffset = off;
}
/*
* If there is too much to fit in the data buffer, use savoff and
* savdp to trim off the last record.
* --> we are not at eof
*/
if (siz > uiop->uio_resid) {
off = savoff;
siz -= dp->d_reclen;
dp = savdp;
more_dirs = 0; /* Paranoia */
}
if (siz > 0) {
lastlen = dp->d_reclen;
md = md2;
dpos = dpos2;
nfsm_mtouio(uiop, siz);
uiop->uio_offset = (off_t)off;
} else
more_dirs = 0; /* Ugh, never happens, but in case.. */
m_freem(mrep);
}
/*
* Fill last record, iff any, out to a multiple of NFS_DIRBLKSIZ
* by increasing d_reclen for the last record.
*/
if (uiop->uio_resid < tresid) {
len = uiop->uio_resid & (NFS_DIRBLKSIZ - 1);
if (len > 0) {
dp = (struct dirent *)
(uiop->uio_iov->iov_base - lastlen);
dp->d_reclen += len;
uiop->uio_iov->iov_base += len;
uiop->uio_iov->iov_len -= len;
uiop->uio_resid -= len;
}
}
nfsmout:
return (error);
}
/*
* Nqnfs readdir_and_lookup RPC. Used in place of nfs_readdirrpc().
*/
int
nfs_readdirlookrpc(vp, uiop, cred)
struct vnode *vp;
register struct uio *uiop;
struct ucred *cred;
{
register int len;
register struct dirent *dp = 0;
register u_long *tl;
register caddr_t cp;
register long t1;
caddr_t bpos, dpos, cp2;
struct mbuf *mreq, *mrep, *md, *mb, *mb2;
struct nameidata nami, *ndp = &nami;
struct componentname *cnp = &ndp->ni_cnd;
u_long off, endoff = 0, fileno;
time_t reqtime, ltime = 0;
struct nfsmount *nmp;
struct nfsnode *np;
struct vnode *newvp;
nfsv2fh_t *fhp;
u_quad_t frev;
int error = 0, tlen, more_dirs = 1, tresid, doit, bigenough, i;
int cachable = 0;
if (uiop->uio_iovcnt != 1)
panic("nfs rdirlook");
nmp = VFSTONFS(vp->v_mount);
tresid = uiop->uio_resid;
ndp->ni_dvp = vp;
newvp = NULLVP;
/*
* Loop around doing readdir rpc's of size uio_resid or nm_rsize,
* whichever is smaller, truncated to a multiple of NFS_DIRBLKSIZ.
* The stopping criteria is EOF or buffer full.
*/
while (more_dirs && uiop->uio_resid >= NFS_DIRBLKSIZ) {
nfsstats.rpccnt[NQNFSPROC_READDIRLOOK]++;
nfsm_reqhead(vp, NQNFSPROC_READDIRLOOK,
NFSX_FH + 3 * NFSX_UNSIGNED);
nfsm_fhtom(vp);
nfsm_build(tl, u_long *, 3 * NFSX_UNSIGNED);
off = (u_long)uiop->uio_offset;
*tl++ = txdr_unsigned(off);
*tl++ = txdr_unsigned(((uiop->uio_resid > nmp->nm_rsize) ?
nmp->nm_rsize : uiop->uio_resid) & ~(NFS_DIRBLKSIZ-1));
if (nmp->nm_flag & NFSMNT_NQLOOKLEASE)
*tl = txdr_unsigned(nmp->nm_leaseterm);
else
*tl = 0;
reqtime = time.tv_sec;
nfsm_request(vp, NQNFSPROC_READDIRLOOK, uiop->uio_procp, cred);
nfsm_dissect(tl, u_long *, NFSX_UNSIGNED);
more_dirs = fxdr_unsigned(int, *tl);
/* loop thru the dir entries, doctoring them to 4bsd form */
bigenough = 1;
while (more_dirs && bigenough) {
doit = 1;
nfsm_dissect(tl, u_long *, 4 * NFSX_UNSIGNED);
if (nmp->nm_flag & NFSMNT_NQLOOKLEASE) {
cachable = fxdr_unsigned(int, *tl++);
ltime = reqtime + fxdr_unsigned(int, *tl++);
fxdr_hyper(tl, &frev);
}
nfsm_dissect(fhp, nfsv2fh_t *, NFSX_FH);
if (!bcmp(VTONFS(vp)->n_fh.fh_bytes, (caddr_t)fhp, NFSX_FH)) {
VREF(vp);
newvp = vp;
np = VTONFS(vp);
} else {
error = nfs_nget(vp->v_mount, fhp, &np);
if (error)
doit = 0;
newvp = NFSTOV(np);
}
error = nfs_loadattrcache(&newvp, &md, &dpos,
(struct vattr *)0);
if (error)
doit = 0;
nfsm_dissect(tl, u_long *, 2 * NFSX_UNSIGNED);
fileno = fxdr_unsigned(u_long, *tl++);
len = fxdr_unsigned(int, *tl);
if (len <= 0 || len > NFS_MAXNAMLEN) {
error = EBADRPC;
m_freem(mrep);
goto nfsmout;
}
tlen = (len + 4) & ~0x3;
if ((tlen + DIRHDSIZ) > uiop->uio_resid)
bigenough = 0;
if (bigenough && doit) {
dp = (struct dirent *)uiop->uio_iov->iov_base;
dp->d_fileno = fileno;
dp->d_namlen = len;
dp->d_reclen = tlen + DIRHDSIZ;
dp->d_type =
IFTODT(VTTOIF(np->n_vattr.va_type));
uiop->uio_resid -= DIRHDSIZ;
uiop->uio_iov->iov_base += DIRHDSIZ;
uiop->uio_iov->iov_len -= DIRHDSIZ;
cnp->cn_nameptr = uiop->uio_iov->iov_base;
cnp->cn_namelen = len;
ndp->ni_vp = newvp;
nfsm_mtouio(uiop, len);
cp = uiop->uio_iov->iov_base;
tlen -= len;
for (i = 0; i < tlen; i++)
*cp++ = '\0';
uiop->uio_iov->iov_base += tlen;
uiop->uio_iov->iov_len -= tlen;
uiop->uio_resid -= tlen;
cnp->cn_hash = 0;
for (cp = cnp->cn_nameptr, i = 1; i <= len; i++, cp++)
cnp->cn_hash += (unsigned char)*cp * i;
if ((nmp->nm_flag & NFSMNT_NQLOOKLEASE) &&
ltime > time.tv_sec)
nqnfs_clientlease(nmp, np, NQL_READ,
cachable, ltime, frev);
if (cnp->cn_namelen <= NCHNAMLEN)
cache_enter(ndp->ni_dvp, ndp->ni_vp, cnp);
} else {
nfsm_adv(nfsm_rndup(len));
}
if (newvp != NULLVP) {
vrele(newvp);
newvp = NULLVP;
}
nfsm_dissect(tl, u_long *, 2 * NFSX_UNSIGNED);
if (bigenough)
endoff = off = fxdr_unsigned(u_long, *tl++);
else
endoff = fxdr_unsigned(u_long, *tl++);
more_dirs = fxdr_unsigned(int, *tl);
}
/*
* If at end of rpc data, get the eof boolean
*/
if (!more_dirs) {
nfsm_dissect(tl, u_long *, NFSX_UNSIGNED);
more_dirs = (fxdr_unsigned(int, *tl) == 0);
/*
* If at EOF, cache directory offset
*/
if (!more_dirs)
VTONFS(vp)->n_direofoffset = endoff;
}
if (uiop->uio_resid < tresid)
uiop->uio_offset = (off_t)off;
else
more_dirs = 0;
m_freem(mrep);
}
/*
* Fill last record, iff any, out to a multiple of NFS_DIRBLKSIZ
* by increasing d_reclen for the last record.
*/
if (uiop->uio_resid < tresid) {
len = uiop->uio_resid & (NFS_DIRBLKSIZ - 1);
if (len > 0) {
dp->d_reclen += len;
uiop->uio_iov->iov_base += len;
uiop->uio_iov->iov_len -= len;
uiop->uio_resid -= len;
}
}
nfsmout:
if (newvp != NULLVP)
vrele(newvp);
return (error);
}
static char hextoasc[] = "0123456789abcdef";
/*
* Silly rename. To make the NFS filesystem that is stateless look a little
* more like the "ufs" a remove of an active vnode is translated to a rename
* to a funny looking filename that is removed by nfs_inactive on the
* nfsnode. There is the potential for another process on a different client
* to create the same funny name between the nfs_lookitup() fails and the
* nfs_rename() completes, but...
*/
int
nfs_sillyrename(dvp, vp, cnp)
struct vnode *dvp, *vp;
struct componentname *cnp;
{
register struct nfsnode *np;
register struct sillyrename *sp;
int error;
short pid;
cache_purge(dvp);
np = VTONFS(vp);
#ifdef SILLYSEPARATE
MALLOC(sp, struct sillyrename *, sizeof (struct sillyrename),
M_NFSREQ, M_WAITOK);
#else
sp = &np->n_silly;
#endif
sp->s_cred = crdup(cnp->cn_cred);
sp->s_dvp = dvp;
VREF(dvp);
/* Fudge together a funny name */
pid = cnp->cn_proc->p_pid;
bcopy(".nfsAxxxx4.4", sp->s_name, 13);
sp->s_namlen = 12;
sp->s_name[8] = hextoasc[pid & 0xf];
sp->s_name[7] = hextoasc[(pid >> 4) & 0xf];
sp->s_name[6] = hextoasc[(pid >> 8) & 0xf];
sp->s_name[5] = hextoasc[(pid >> 12) & 0xf];
/* Try lookitups until we get one that isn't there */
while (nfs_lookitup(sp, (nfsv2fh_t *)0, cnp->cn_proc) == 0) {
sp->s_name[4]++;
if (sp->s_name[4] > 'z') {
error = EINVAL;
goto bad;
}
}
error = nfs_renameit(dvp, cnp, sp);
if (error)
goto bad;
nfs_lookitup(sp, &np->n_fh, cnp->cn_proc);
np->n_sillyrename = sp;
return (0);
bad:
vrele(sp->s_dvp);
crfree(sp->s_cred);
#ifdef SILLYSEPARATE
free((caddr_t)sp, M_NFSREQ);
#endif
return (error);
}
/*
* Look up a file name for silly rename stuff.
* Just like nfs_lookup() except that it doesn't load returned values
* into the nfsnode table.
* If fhp != NULL it copies the returned file handle out
*/
int
nfs_lookitup(sp, fhp, procp)
register struct sillyrename *sp;
nfsv2fh_t *fhp;
struct proc *procp;
{
register struct vnode *vp = sp->s_dvp;
register u_long *tl;
register caddr_t cp;
register long t1, t2;
caddr_t bpos, dpos, cp2;
int error = 0, isnq;
struct mbuf *mreq, *mrep, *md, *mb, *mb2;
long len;
isnq = (VFSTONFS(vp->v_mount)->nm_flag & NFSMNT_NQNFS);
nfsstats.rpccnt[NFSPROC_LOOKUP]++;
len = sp->s_namlen;
nfsm_reqhead(vp, NFSPROC_LOOKUP, NFSX_FH+NFSX_UNSIGNED+nfsm_rndup(len));
if (isnq) {
nfsm_build(tl, u_long *, NFSX_UNSIGNED);
*tl = 0;
}
nfsm_fhtom(vp);
nfsm_strtom(sp->s_name, len, NFS_MAXNAMLEN);
nfsm_request(vp, NFSPROC_LOOKUP, procp, sp->s_cred);
if (fhp != NULL) {
if (isnq)
nfsm_dissect(tl, u_long *, NFSX_UNSIGNED);
nfsm_dissect(cp, caddr_t, NFSX_FH);
bcopy(cp, (caddr_t)fhp, NFSX_FH);
}
nfsm_reqdone;
return (error);
}
/*
* Kludge City..
* - make nfs_bmap() essentially a no-op that does no translation
* - do nfs_strategy() by faking physical I/O with nfs_readrpc/nfs_writerpc
* after mapping the physical addresses into Kernel Virtual space in the
* nfsiobuf area.
* (Maybe I could use the process's page mapping, but I was concerned that
* Kernel Write might not be enabled and also figured copyout() would do
* a lot more work than bcopy() and also it currently happens in the
* context of the swapper process (2).
*/
int
nfs_bmap(ap)
struct vop_bmap_args /* {
struct vnode *a_vp;
daddr_t a_bn;
struct vnode **a_vpp;
daddr_t *a_bnp;
int *a_runp;
} */ *ap;
{
register struct vnode *vp = ap->a_vp;
if (ap->a_vpp != NULL)
*ap->a_vpp = vp;
if (ap->a_bnp != NULL)
*ap->a_bnp = ap->a_bn * btodb(vp->v_mount->mnt_stat.f_iosize);
if (ap->a_runp != NULL)
*ap->a_runp = 0;
return (0);
}
/*
* Strategy routine.
* For async requests when nfsiod(s) are running, queue the request by
* calling nfs_asyncio(), otherwise just all nfs_doio() to do the
* request.
*/
int
nfs_strategy(ap)
struct vop_strategy_args *ap;
{
register struct buf *bp = ap->a_bp;
struct ucred *cr;
struct proc *p;
int error = 0;
if ((bp->b_flags & (B_PHYS|B_ASYNC)) == (B_PHYS|B_ASYNC))
panic("nfs physio/async");
if (bp->b_flags & B_ASYNC)
p = (struct proc *)0;
else
p = curproc; /* XXX */
if (bp->b_flags & B_READ)
cr = bp->b_rcred;
else
cr = bp->b_wcred;
/*
* If the op is asynchronous and an i/o daemon is waiting
* queue the request, wake it up and wait for completion
* otherwise just do it ourselves.
*/
if ((bp->b_flags & B_ASYNC) == 0 ||
nfs_asyncio(bp, NOCRED))
error = nfs_doio(bp, cr, p);
return (error);
}
/*
* Mmap a file
*
* NB Currently unsupported.
*/
/* ARGSUSED */
int
nfs_mmap(ap)
struct vop_mmap_args /* {
struct vnode *a_vp;
int a_fflags;
struct ucred *a_cred;
struct proc *a_p;
} */ *ap;
{
return (EINVAL);
}
/*
* Flush all the blocks associated with a vnode.
* Walk through the buffer pool and push any dirty pages
* associated with the vnode.
*/
/* ARGSUSED */
int
nfs_fsync(ap)
struct vop_fsync_args /* {
struct vnodeop_desc *a_desc;
struct vnode * a_vp;
struct ucred * a_cred;
int a_waitfor;
struct proc * a_p;
} */ *ap;
{
register struct vnode *vp = ap->a_vp;
register struct nfsnode *np = VTONFS(vp);
register struct buf *bp;
struct buf *nbp;
struct nfsmount *nmp;
int s, error = 0, slptimeo = 0, slpflag = 0;
nmp = VFSTONFS(vp->v_mount);
if (nmp->nm_flag & NFSMNT_INT)
slpflag = PCATCH;
loop:
s = splbio();
for (bp = vp->v_dirtyblkhd.lh_first; bp; bp = nbp) {
nbp = bp->b_vnbufs.le_next;
if (bp->b_flags & B_BUSY) {
if (ap->a_waitfor != MNT_WAIT)
continue;
bp->b_flags |= B_WANTED;
error = tsleep((caddr_t)bp, slpflag | (PRIBIO + 1),
"nfsfsync", slptimeo);
splx(s);
if (error) {
if (nfs_sigintr(nmp, (struct nfsreq *)0, ap->a_p))
return (EINTR);
if (slpflag == PCATCH) {
slpflag = 0;
slptimeo = 2 * hz;
}
}
goto loop;
}
if ((bp->b_flags & B_DELWRI) == 0)
panic("nfs_fsync: not dirty");
bremfree(bp);
bp->b_flags |= B_BUSY;
splx(s);
bp->b_flags |= B_ASYNC;
VOP_BWRITE(bp);
goto loop;
}
splx(s);
if (ap->a_waitfor == MNT_WAIT) {
while (vp->v_numoutput) {
vp->v_flag |= VBWAIT;
error = tsleep((caddr_t)&vp->v_numoutput,
slpflag | (PRIBIO + 1), "nfsfsync", slptimeo);
if (error) {
if (nfs_sigintr(nmp, (struct nfsreq *)0, ap->a_p))
return (EINTR);
if (slpflag == PCATCH) {
slpflag = 0;
slptimeo = 2 * hz;
}
}
}
if (vp->v_dirtyblkhd.lh_first) {
goto loop;
}
}
if (np->n_flag & NWRITEERR) {
error = np->n_error;
np->n_flag &= ~NWRITEERR;
}
return (error);
}
/*
* Return POSIX pathconf information applicable to nfs.
*
* Currently the NFS protocol does not support getting such
* information from the remote server.
*/
/* ARGSUSED */
int
nfs_pathconf(ap)
struct vop_pathconf_args /* {
struct vnode *a_vp;
int a_name;
int *a_retval;
} */ *ap;
{
return (EINVAL);
}
/*
* NFS advisory byte-level locks.
* Currently unsupported.
*/
int
nfs_advlock(ap)
struct vop_advlock_args /* {
struct vnode *a_vp;
caddr_t a_id;
int a_op;
struct flock *a_fl;
int a_flags;
} */ *ap;
{
register struct nfsnode *np = VTONFS(ap->a_vp);
/*
* The following kludge is to allow diskless support to work
* until a real NFS lockd is implemented. Basically, just pretend
* that this is a local lock.
*/
return (lf_advlock(ap, &(np->n_lockf), np->n_size));
}
/*
* Print out the contents of an nfsnode.
*/
int
nfs_print(ap)
struct vop_print_args /* {
struct vnode *a_vp;
} */ *ap;
{
register struct vnode *vp = ap->a_vp;
register struct nfsnode *np = VTONFS(vp);
printf("tag VT_NFS, fileid %ld fsid 0x%lx",
np->n_vattr.va_fileid, np->n_vattr.va_fsid);
if (vp->v_type == VFIFO)
fifo_printinfo(vp);
printf("\n");
return (0);
}
/*
* NFS directory offset lookup.
* Currently unsupported.
*/
int
nfs_blkatoff(ap)
struct vop_blkatoff_args /* {
struct vnode *a_vp;
off_t a_offset;
char **a_res;
struct buf **a_bpp;
} */ *ap;
{
return (EOPNOTSUPP);
}
/*
* NFS flat namespace allocation.
* Currently unsupported.
*/
int
nfs_valloc(ap)
struct vop_valloc_args /* {
struct vnode *a_pvp;
int a_mode;
struct ucred *a_cred;
struct vnode **a_vpp;
} */ *ap;
{
return (EOPNOTSUPP);
}
/*
* NFS flat namespace free.
* Currently unsupported.
*/
int
nfs_vfree(ap)
struct vop_vfree_args /* {
struct vnode *a_pvp;
ino_t a_ino;
int a_mode;
} */ *ap;
{
return (EOPNOTSUPP);
}
/*
* NFS file truncation.
*/
int
nfs_truncate(ap)
struct vop_truncate_args /* {
struct vnode *a_vp;
off_t a_length;
int a_flags;
struct ucred *a_cred;
struct proc *a_p;
} */ *ap;
{
/* Use nfs_setattr */
printf("nfs_truncate: need to implement!!");
return (EOPNOTSUPP);
}
/*
* NFS update.
*/
int
nfs_update(ap)
struct vop_update_args /* {
struct vnode *a_vp;
struct timeval *a_ta;
struct timeval *a_tm;
int a_waitfor;
} */ *ap;
{
#if 0
/* Use nfs_setattr */
printf("nfs_update: need to implement!!");
#endif
return (EOPNOTSUPP);
}
/*
* nfs special file access vnode op.
* Essentially just get vattr and then imitate iaccess() since the device is
* local to the client.
*/
int
nfsspec_access(ap)
struct vop_access_args /* {
struct vnode *a_vp;
int a_mode;
struct ucred *a_cred;
struct proc *a_p;
} */ *ap;
{
register struct vattr *vap;
register gid_t *gp;
register struct ucred *cred = ap->a_cred;
mode_t mode = ap->a_mode;
struct vattr vattr;
register int i;
int error;
/*
* If you're the super-user,
* you always get access.
*/
if (cred->cr_uid == 0)
return (0);
vap = &vattr;
error = VOP_GETATTR(ap->a_vp, vap, cred, ap->a_p);
if (error)
return (error);
/*
* Access check is based on only one of owner, group, public.
* If not owner, then check group. If not a member of the
* group, then check public access.
*/
if (cred->cr_uid != vap->va_uid) {
mode >>= 3;
gp = cred->cr_groups;
for (i = 0; i < cred->cr_ngroups; i++, gp++)
if (vap->va_gid == *gp)
goto found;
mode >>= 3;
found:
;
}
return ((vap->va_mode & mode) == mode ? 0 : EACCES);
}
/*
* Read wrapper for special devices.
*/
int
nfsspec_read(ap)
struct vop_read_args /* {
struct vnode *a_vp;
struct uio *a_uio;
int a_ioflag;
struct ucred *a_cred;
} */ *ap;
{
register struct nfsnode *np = VTONFS(ap->a_vp);
/*
* Set access flag.
*/
np->n_flag |= NACC;
np->n_atim = time;
return (VOCALL(spec_vnodeop_p, VOFFSET(vop_read), ap));
}
/*
* Write wrapper for special devices.
*/
int
nfsspec_write(ap)
struct vop_write_args /* {
struct vnode *a_vp;
struct uio *a_uio;
int a_ioflag;
struct ucred *a_cred;
} */ *ap;
{
register struct nfsnode *np = VTONFS(ap->a_vp);
/*
* Set update flag.
*/
np->n_flag |= NUPD;
np->n_mtim = time;
return (VOCALL(spec_vnodeop_p, VOFFSET(vop_write), ap));
}
/*
* Close wrapper for special devices.
*
* Update the times on the nfsnode then do device close.
*/
int
nfsspec_close(ap)
struct vop_close_args /* {
struct vnode *a_vp;
int a_fflag;
struct ucred *a_cred;
struct proc *a_p;
} */ *ap;
{
register struct vnode *vp = ap->a_vp;
register struct nfsnode *np = VTONFS(vp);
struct vattr vattr;
if (np->n_flag & (NACC | NUPD)) {
np->n_flag |= NCHG;
if (vp->v_usecount == 1 &&
(vp->v_mount->mnt_flag & MNT_RDONLY) == 0) {
VATTR_NULL(&vattr);
if (np->n_flag & NACC) {
vattr.va_atime.ts_sec = np->n_atim.tv_sec;
vattr.va_atime.ts_nsec =
np->n_atim.tv_usec * 1000;
}
if (np->n_flag & NUPD) {
vattr.va_mtime.ts_sec = np->n_mtim.tv_sec;
vattr.va_mtime.ts_nsec =
np->n_mtim.tv_usec * 1000;
}
(void)VOP_SETATTR(vp, &vattr, ap->a_cred, ap->a_p);
}
}
return (VOCALL(spec_vnodeop_p, VOFFSET(vop_close), ap));
}
/*
* Read wrapper for fifos.
*/
int
nfsfifo_read(ap)
struct vop_read_args /* {
struct vnode *a_vp;
struct uio *a_uio;
int a_ioflag;
struct ucred *a_cred;
} */ *ap;
{
register struct nfsnode *np = VTONFS(ap->a_vp);
/*
* Set access flag.
*/
np->n_flag |= NACC;
np->n_atim = time;
return (VOCALL(fifo_vnodeop_p, VOFFSET(vop_read), ap));
}
/*
* Write wrapper for fifos.
*/
int
nfsfifo_write(ap)
struct vop_write_args /* {
struct vnode *a_vp;
struct uio *a_uio;
int a_ioflag;
struct ucred *a_cred;
} */ *ap;
{
register struct nfsnode *np = VTONFS(ap->a_vp);
/*
* Set update flag.
*/
np->n_flag |= NUPD;
np->n_mtim = time;
return (VOCALL(fifo_vnodeop_p, VOFFSET(vop_write), ap));
}
/*
* Close wrapper for fifos.
*
* Update the times on the nfsnode then do fifo close.
*/
int
nfsfifo_close(ap)
struct vop_close_args /* {
struct vnode *a_vp;
int a_fflag;
struct ucred *a_cred;
struct proc *a_p;
} */ *ap;
{
register struct vnode *vp = ap->a_vp;
register struct nfsnode *np = VTONFS(vp);
struct vattr vattr;
if (np->n_flag & (NACC | NUPD)) {
if (np->n_flag & NACC)
np->n_atim = time;
if (np->n_flag & NUPD)
np->n_mtim = time;
np->n_flag |= NCHG;
if (vp->v_usecount == 1 &&
(vp->v_mount->mnt_flag & MNT_RDONLY) == 0) {
VATTR_NULL(&vattr);
if (np->n_flag & NACC) {
vattr.va_atime.ts_sec = np->n_atim.tv_sec;
vattr.va_atime.ts_nsec =
np->n_atim.tv_usec * 1000;
}
if (np->n_flag & NUPD) {
vattr.va_mtime.ts_sec = np->n_mtim.tv_sec;
vattr.va_mtime.ts_nsec =
np->n_mtim.tv_usec * 1000;
}
(void)VOP_SETATTR(vp, &vattr, ap->a_cred, ap->a_p);
}
}
return (VOCALL(fifo_vnodeop_p, VOFFSET(vop_close), ap));
}
|