summaryrefslogtreecommitdiffstats
path: root/arch/sparc64/solaris/fs.c
blob: 7d035f0d3ae1fcbf0084f11b2451077616115a34 (plain)
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
/* $Id: fs.c,v 1.27 2002/02/08 03:57:14 davem Exp $
 * fs.c: fs related syscall emulation for Solaris
 *
 * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
 *
 * 1999-08-19 Implemented solaris F_FREESP (truncate)
 *            fcntl, by Jason Rappleye (rappleye@ccr.buffalo.edu)
 */

#include <linux/types.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/capability.h>
#include <linux/fs.h>
#include <linux/namei.h>
#include <linux/mm.h>
#include <linux/file.h>
#include <linux/stat.h>
#include <linux/smp_lock.h>
#include <linux/limits.h>
#include <linux/resource.h>
#include <linux/quotaops.h>
#include <linux/mount.h>
#include <linux/vfs.h>

#include <asm/uaccess.h>
#include <asm/string.h>
#include <asm/ptrace.h>

#include "conv.h"

#define R3_VERSION	1
#define R4_VERSION	2

typedef struct {
	s32	tv_sec;
	s32	tv_nsec;
} timestruct_t;

struct sol_stat {
	u32		st_dev;
	s32		st_pad1[3];     /* network id */
	u32		st_ino;
	u32		st_mode;
	u32		st_nlink;
	u32		st_uid;
	u32		st_gid;
	u32		st_rdev;
	s32		st_pad2[2];
	s32		st_size;
	s32		st_pad3;	/* st_size, off_t expansion */
	timestruct_t	st_atime;
	timestruct_t	st_mtime;
	timestruct_t	st_ctime;
	s32		st_blksize;
	s32		st_blocks;
	char		st_fstype[16];
	s32		st_pad4[8];     /* expansion area */
};

struct sol_stat64 {
	u32		st_dev;
	s32		st_pad1[3];     /* network id */
	u64		st_ino;
	u32		st_mode;
	u32		st_nlink;
	u32		st_uid;
	u32		st_gid;
	u32		st_rdev;
	s32		st_pad2[2];
	s64		st_size;
	timestruct_t	st_atime;
	timestruct_t	st_mtime;
	timestruct_t	st_ctime;
	s64		st_blksize;
	s32		st_blocks;
	char		st_fstype[16];
	s32		st_pad4[4];     /* expansion area */
};

#define UFSMAGIC (((unsigned)'u'<<24)||((unsigned)'f'<<16)||((unsigned)'s'<<8))

static inline int putstat(struct sol_stat __user *ubuf, struct kstat *kbuf)
{
	u32 ino;

	if (kbuf->size > MAX_NON_LFS ||
	    !sysv_valid_dev(kbuf->dev) ||
	    !sysv_valid_dev(kbuf->rdev))
		return -EOVERFLOW;
	ino = kbuf->ino;
	if (sizeof(ino) < sizeof(kbuf->ino) && ino != kbuf->ino)
		return -EOVERFLOW;
	if (put_user (sysv_encode_dev(kbuf->dev), &ubuf->st_dev)	||
	    __put_user (ino, &ubuf->st_ino)				||
	    __put_user (kbuf->mode, &ubuf->st_mode)		||
	    __put_user (kbuf->nlink, &ubuf->st_nlink)	||
	    __put_user (kbuf->uid, &ubuf->st_uid)		||
	    __put_user (kbuf->gid, &ubuf->st_gid)		||
	    __put_user (sysv_encode_dev(kbuf->rdev), &ubuf->st_rdev)	||
	    __put_user (kbuf->size, &ubuf->st_size)		||
	    __put_user (kbuf->atime.tv_sec, &ubuf->st_atime.tv_sec)	||
	    __put_user (kbuf->atime.tv_nsec, &ubuf->st_atime.tv_nsec)	||
	    __put_user (kbuf->mtime.tv_sec, &ubuf->st_mtime.tv_sec)	||
	    __put_user (kbuf->mtime.tv_nsec, &ubuf->st_mtime.tv_nsec)	||
	    __put_user (kbuf->ctime.tv_sec, &ubuf->st_ctime.tv_sec)	||
	    __put_user (kbuf->ctime.tv_nsec, &ubuf->st_ctime.tv_nsec)	||
	    __put_user (kbuf->blksize, &ubuf->st_blksize)	||
	    __put_user (kbuf->blocks, &ubuf->st_blocks)	||
	    __put_user (UFSMAGIC, (unsigned __user *)ubuf->st_fstype))
		return -EFAULT;
	return 0;
}

static inline int putstat64(struct sol_stat64 __user *ubuf, struct kstat *kbuf)
{
	if (!sysv_valid_dev(kbuf->dev) || !sysv_valid_dev(kbuf->rdev))
		return -EOVERFLOW;
	if (put_user (sysv_encode_dev(kbuf->dev), &ubuf->st_dev)	||
	    __put_user (kbuf->ino, &ubuf->st_ino)		||
	    __put_user (kbuf->mode, &ubuf->st_mode)		||
	    __put_user (kbuf->nlink, &ubuf->st_nlink)	||
	    __put_user (kbuf->uid, &ubuf->st_uid)		||
	    __put_user (kbuf->gid, &ubuf->st_gid)		||
	    __put_user (sysv_encode_dev(kbuf->rdev), &ubuf->st_rdev)	||
	    __put_user (kbuf->size, &ubuf->st_size)		||
	    __put_user (kbuf->atime.tv_sec, &ubuf->st_atime.tv_sec)	||
	    __put_user (kbuf->atime.tv_nsec, &ubuf->st_atime.tv_nsec)	||
	    __put_user (kbuf->mtime.tv_sec, &ubuf->st_mtime.tv_sec)	||
	    __put_user (kbuf->mtime.tv_nsec, &ubuf->st_mtime.tv_nsec)	||
	    __put_user (kbuf->ctime.tv_sec, &ubuf->st_ctime.tv_sec)	||
	    __put_user (kbuf->ctime.tv_nsec, &ubuf->st_ctime.tv_nsec)	||
	    __put_user (kbuf->blksize, &ubuf->st_blksize)	||
	    __put_user (kbuf->blocks, &ubuf->st_blocks)	||
	    __put_user (UFSMAGIC, (unsigned __user *)ubuf->st_fstype))
		return -EFAULT;
	return 0;
}

asmlinkage int solaris_stat(u32 filename, u32 statbuf)
{
	struct kstat s;
	int ret = vfs_stat(A(filename), &s);
	if (!ret)
		return putstat(A(statbuf), &s);
	return ret;
}

asmlinkage int solaris_xstat(int vers, u32 filename, u32 statbuf)
{
	/* Solaris doesn't bother with looking at vers, so we do neither */
	return solaris_stat(filename, statbuf);
}

asmlinkage int solaris_stat64(u32 filename, u32 statbuf)
{
	struct kstat s;
	int ret = vfs_stat(A(filename), &s);
	if (!ret)
		return putstat64(A(statbuf), &s);
	return ret;
}

asmlinkage int solaris_lstat(u32 filename, u32 statbuf)
{
	struct kstat s;
	int ret = vfs_lstat(A(filename), &s);
	if (!ret)
		return putstat(A(statbuf), &s);
	return ret;
}

asmlinkage int solaris_lxstat(int vers, u32 filename, u32 statbuf)
{
	return solaris_lstat(filename, statbuf);
}

asmlinkage int solaris_lstat64(u32 filename, u32 statbuf)
{
	struct kstat s;
	int ret = vfs_lstat(A(filename), &s);
	if (!ret)
		return putstat64(A(statbuf), &s);
	return ret;
}

asmlinkage int solaris_fstat(unsigned int fd, u32 statbuf)
{
	struct kstat s;
	int ret = vfs_fstat(fd, &s);
	if (!ret)
		return putstat(A(statbuf), &s);
	return ret;
}

asmlinkage int solaris_fxstat(int vers, u32 fd, u32 statbuf)
{
	return solaris_fstat(fd, statbuf);
}

asmlinkage int solaris_fstat64(unsigned int fd, u32 statbuf)
{
	struct kstat s;
	int ret = vfs_fstat(fd, &s);
	if (!ret)
		return putstat64(A(statbuf), &s);
	return ret;
}

asmlinkage int solaris_mknod(u32 path, u32 mode, s32 dev)
{
	int (*sys_mknod)(const char __user *,int,unsigned) = 
		(int (*)(const char __user *,int,unsigned))SYS(mknod);
	int major = sysv_major(dev);
	int minor = sysv_minor(dev);

	/* minor is guaranteed to be OK for MKDEV, major might be not */
	if (major > 0xfff)
		return -EINVAL;
	return sys_mknod(A(path), mode, new_encode_dev(MKDEV(major,minor)));
}

asmlinkage int solaris_xmknod(int vers, u32 path, u32 mode, s32 dev)
{
	return solaris_mknod(path, mode, dev);
}

asmlinkage int solaris_getdents64(unsigned int fd, void __user *dirent, unsigned int count)
{
	int (*sys_getdents)(unsigned int, void __user *, unsigned int) =
		(int (*)(unsigned int, void __user *, unsigned int))SYS(getdents);
		
	return sys_getdents(fd, dirent, count);
}

/* This statfs thingie probably will go in the near future, but... */

struct sol_statfs {
	short	f_type;
	s32	f_bsize;
	s32	f_frsize;
	s32	f_blocks;
	s32	f_bfree;
	u32	f_files;
	u32	f_ffree;
	char	f_fname[6];
	char	f_fpack[6];
};

asmlinkage int solaris_statfs(u32 path, u32 buf, int len, int fstype)
{
	int ret;
	struct statfs s;
	mm_segment_t old_fs = get_fs();
	int (*sys_statfs)(const char __user *,struct statfs __user *) = 
		(int (*)(const char __user *,struct statfs __user *))SYS(statfs);
	struct sol_statfs __user *ss = A(buf);
	
	if (len != sizeof(struct sol_statfs)) return -EINVAL;
	if (!fstype) {
		/* FIXME: mixing userland and kernel pointers */
		set_fs (KERNEL_DS);
		ret = sys_statfs(A(path), &s);
		set_fs (old_fs);
		if (!ret) {
			if (put_user (s.f_type, &ss->f_type)		||
			    __put_user (s.f_bsize, &ss->f_bsize)	||
			    __put_user (0, &ss->f_frsize)		||
			    __put_user (s.f_blocks, &ss->f_blocks)	||
			    __put_user (s.f_bfree, &ss->f_bfree)	||
			    __put_user (s.f_files, &ss->f_files)	||
			    __put_user (s.f_ffree, &ss->f_ffree)	||
			    __clear_user (&ss->f_fname, 12))
				return -EFAULT;
		}
		return ret;
	}
/* Linux can't stat unmounted filesystems so we
 * simply lie and claim 100MB of 1GB is free. Sorry.
 */
	if (put_user (fstype, &ss->f_type)		||
	    __put_user (1024, &ss->f_bsize)		||
	    __put_user (0, &ss->f_frsize)		||
	    __put_user (1024*1024, &ss->f_blocks)	||
	    __put_user (100*1024, &ss->f_bfree)		||
	    __put_user (60000, &ss->f_files)		||
	    __put_user (50000, &ss->f_ffree)		||
	    __clear_user (&ss->f_fname, 12))
		return -EFAULT;
	return 0;
}

asmlinkage int solaris_fstatfs(u32 fd, u32 buf, int len, int fstype)
{
	int ret;
	struct statfs s;
	mm_segment_t old_fs = get_fs();
	int (*sys_fstatfs)(unsigned,struct statfs __user *) = 
		(int (*)(unsigned,struct statfs __user *))SYS(fstatfs);
	struct sol_statfs __user *ss = A(buf);
	
	if (len != sizeof(struct sol_statfs)) return -EINVAL;
	if (!fstype) {
		set_fs (KERNEL_DS);
		ret = sys_fstatfs(fd, &s);
		set_fs (old_fs);
		if (!ret) {
			if (put_user (s.f_type, &ss->f_type)		||
			    __put_user (s.f_bsize, &ss->f_bsize)	||
			    __put_user (0, &ss->f_frsize)		||
			    __put_user (s.f_blocks, &ss->f_blocks)	||
			    __put_user (s.f_bfree, &ss->f_bfree)	||
			    __put_user (s.f_files, &ss->f_files)	||
			    __put_user (s.f_ffree, &ss->f_ffree)	||
			    __clear_user (&ss->f_fname, 12))
				return -EFAULT;
		}
		return ret;
	}
	/* Otherwise fstatfs is the same as statfs */
	return solaris_statfs(0, buf, len, fstype);
}

struct sol_statvfs {
	u32	f_bsize;
	u32	f_frsize;
	u32	f_blocks;
	u32	f_bfree;
	u32	f_bavail;
	u32	f_files;
	u32	f_ffree;
	u32	f_favail;
	u32	f_fsid;
	char	f_basetype[16];
	u32	f_flag;
	u32	f_namemax;
	char	f_fstr[32];
	u32	f_filler[16];
};

struct sol_statvfs64 {
	u32	f_bsize;
	u32	f_frsize;
	u64	f_blocks;
	u64	f_bfree;
	u64	f_bavail;
	u64	f_files;
	u64	f_ffree;
	u64	f_favail;
	u32	f_fsid;
	char	f_basetype[16];
	u32	f_flag;
	u32	f_namemax;
	char	f_fstr[32];
	u32	f_filler[16];
};

static int report_statvfs(struct vfsmount *mnt, struct inode *inode, u32 buf)
{
	struct kstatfs s;
	int error;
	struct sol_statvfs __user *ss = A(buf);

	error = vfs_statfs(mnt->mnt_root, &s);
	if (!error) {
		const char *p = mnt->mnt_sb->s_type->name;
		int i = 0;
		int j = strlen (p);
		
		if (j > 15) j = 15;
		if (IS_RDONLY(inode)) i = 1;
		if (mnt->mnt_flags & MNT_NOSUID) i |= 2;
		if (!sysv_valid_dev(inode->i_sb->s_dev))
			return -EOVERFLOW;
		if (put_user (s.f_bsize, &ss->f_bsize)		||
		    __put_user (0, &ss->f_frsize)		||
		    __put_user (s.f_blocks, &ss->f_blocks)	||
		    __put_user (s.f_bfree, &ss->f_bfree)	||
		    __put_user (s.f_bavail, &ss->f_bavail)	||
		    __put_user (s.f_files, &ss->f_files)	||
		    __put_user (s.f_ffree, &ss->f_ffree)	||
		    __put_user (s.f_ffree, &ss->f_favail)	||
		    __put_user (sysv_encode_dev(inode->i_sb->s_dev), &ss->f_fsid) ||
		    __copy_to_user (ss->f_basetype,p,j)		||
		    __put_user (0, (char __user *)&ss->f_basetype[j])	||
		    __put_user (s.f_namelen, &ss->f_namemax)	||
		    __put_user (i, &ss->f_flag)			||		    
		    __clear_user (&ss->f_fstr, 32))
			return -EFAULT;
	}
	return error;
}

static int report_statvfs64(struct vfsmount *mnt, struct inode *inode, u32 buf)
{
	struct kstatfs s;
	int error;
	struct sol_statvfs64 __user *ss = A(buf);
			
	error = vfs_statfs(mnt->mnt_root, &s);
	if (!error) {
		const char *p = mnt->mnt_sb->s_type->name;
		int i = 0;
		int j = strlen (p);
		
		if (j > 15) j = 15;
		if (IS_RDONLY(inode)) i = 1;
		if (mnt->mnt_flags & MNT_NOSUID) i |= 2;
		if (!sysv_valid_dev(inode->i_sb->s_dev))
			return -EOVERFLOW;
		if (put_user (s.f_bsize, &ss->f_bsize)		||
		    __put_user (0, &ss->f_frsize)		||
		    __put_user (s.f_blocks, &ss->f_blocks)	||
		    __put_user (s.f_bfree, &ss->f_bfree)	||
		    __put_user (s.f_bavail, &ss->f_bavail)	||
		    __put_user (s.f_files, &ss->f_files)	||
		    __put_user (s.f_ffree, &ss->f_ffree)	||
		    __put_user (s.f_ffree, &ss->f_favail)	||
		    __put_user (sysv_encode_dev(inode->i_sb->s_dev), &ss->f_fsid) ||
		    __copy_to_user (ss->f_basetype,p,j)		||
		    __put_user (0, (char __user *)&ss->f_basetype[j])	||
		    __put_user (s.f_namelen, &ss->f_namemax)	||
		    __put_user (i, &ss->f_flag)			||		    
		    __clear_user (&ss->f_fstr, 32))
			return -EFAULT;
	}
	return error;
}

asmlinkage int solaris_statvfs(u32 path, u32 buf)
{
	struct nameidata nd;
	int error;

	error = user_path_walk(A(path),&nd);
	if (!error) {
		struct inode *inode = nd.path.dentry->d_inode;
		error = report_statvfs(nd.path.mnt, inode, buf);
		path_put(&nd.path);
	}
	return error;
}

asmlinkage int solaris_fstatvfs(unsigned int fd, u32 buf)
{
	struct file * file;
	int error;

	error = -EBADF;
	file = fget(fd);
	if (file) {
		error = report_statvfs(file->f_path.mnt, file->f_path.dentry->d_inode, buf);
		fput(file);
	}

	return error;
}

asmlinkage int solaris_statvfs64(u32 path, u32 buf)
{
	struct nameidata nd;
	int error;

	lock_kernel();
	error = user_path_walk(A(path), &nd);
	if (!error) {
		struct inode *inode = nd.path.dentry->d_inode;
		error = report_statvfs64(nd.path.mnt, inode, buf);
		path_put(&nd.path);
	}
	unlock_kernel();
	return error;
}

asmlinkage int solaris_fstatvfs64(unsigned int fd, u32 buf)
{
	struct file * file;
	int error;

	error = -EBADF;
	file = fget(fd);
	if (file) {
		lock_kernel();
		error = report_statvfs64(file->f_path.mnt, file->f_path.dentry->d_inode, buf);
		unlock_kernel();
		fput(file);
	}
	return error;
}

extern asmlinkage long sparc32_open(const char * filename, int flags, int mode);

asmlinkage int solaris_open(u32 fname, int flags, u32 mode)
{
	const char *filename = (const char *)(long)fname;
	int fl = flags & 0xf;

	/* Translate flags first. */
	if (flags & 0x2000) fl |= O_LARGEFILE;
	if (flags & 0x8050) fl |= O_SYNC;
	if (flags & 0x80) fl |= O_NONBLOCK;
	if (flags & 0x100) fl |= O_CREAT;
	if (flags & 0x200) fl |= O_TRUNC;
	if (flags & 0x400) fl |= O_EXCL;
	if (flags & 0x800) fl |= O_NOCTTY;
	flags = fl;

	return sparc32_open(filename, flags, mode);
}

#define SOL_F_SETLK	6
#define SOL_F_SETLKW	7
#define SOL_F_FREESP    11
#define SOL_F_ISSTREAM  13
#define SOL_F_GETLK     14
#define SOL_F_PRIV      15
#define SOL_F_NPRIV     16
#define SOL_F_QUOTACTL  17
#define SOL_F_BLOCKS    18
#define SOL_F_BLKSIZE   19
#define SOL_F_GETOWN    23
#define SOL_F_SETOWN    24

struct sol_flock {
	short	l_type;
	short	l_whence;
	u32	l_start;
	u32	l_len;
	s32	l_sysid;
	s32	l_pid;
	s32	l_pad[4];
};

asmlinkage int solaris_fcntl(unsigned fd, unsigned cmd, u32 arg)
{
	int (*sys_fcntl)(unsigned,unsigned,unsigned long) = 
		(int (*)(unsigned,unsigned,unsigned long))SYS(fcntl);
	int ret, flags;

	switch (cmd) {
	case F_DUPFD:
	case F_GETFD:
	case F_SETFD: return sys_fcntl(fd, cmd, (unsigned long)arg);
	case F_GETFL:
		flags = sys_fcntl(fd, cmd, 0);
		ret = flags & 0xf;
		if (flags & O_SYNC) ret |= 0x8050;
		if (flags & O_NONBLOCK) ret |= 0x80;
		return ret;
	case F_SETFL:
		flags = arg & 0xf;
		if (arg & 0x8050) flags |= O_SYNC;
		if (arg & 0x80) flags |= O_NONBLOCK;
		return sys_fcntl(fd, cmd, (long)flags);
	case SOL_F_GETLK:
	case SOL_F_SETLK:
	case SOL_F_SETLKW:
		{
			struct flock f;
			struct sol_flock __user *p = A(arg);
			mm_segment_t old_fs = get_fs();

			switch (cmd) {
			case SOL_F_GETLK: cmd = F_GETLK; break;
			case SOL_F_SETLK: cmd = F_SETLK; break;
			case SOL_F_SETLKW: cmd = F_SETLKW; break;
			}

			if (get_user (f.l_type, &p->l_type) ||
			    __get_user (f.l_whence, &p->l_whence) ||
			    __get_user (f.l_start, &p->l_start) ||
			    __get_user (f.l_len, &p->l_len) ||
			    __get_user (f.l_pid, &p->l_sysid))
				return -EFAULT;

			set_fs(KERNEL_DS);
			ret = sys_fcntl(fd, cmd, (unsigned long)&f);
			set_fs(old_fs);

			if (__put_user (f.l_type, &p->l_type) ||
			    __put_user (f.l_whence, &p->l_whence) ||
			    __put_user (f.l_start, &p->l_start) ||
			    __put_user (f.l_len, &p->l_len) ||
			    __put_user (f.l_pid, &p->l_pid) ||
			    __put_user (0, &p->l_sysid))
				return -EFAULT;

			return ret;
		}
	case SOL_F_FREESP:
	        { 
		    int length;
		    int (*sys_newftruncate)(unsigned int, unsigned long)=
			    (int (*)(unsigned int, unsigned long))SYS(ftruncate);

		    if (get_user(length, &((struct sol_flock __user *)A(arg))->l_start))
			    return -EFAULT;

		    return sys_newftruncate(fd, length);
		}
	};
	return -EINVAL;
}

asmlinkage int solaris_ulimit(int cmd, int val)
{
	switch (cmd) {
	case 1: /* UL_GETFSIZE - in 512B chunks */
		return current->signal->rlim[RLIMIT_FSIZE].rlim_cur >> 9;
	case 2: /* UL_SETFSIZE */
		if ((unsigned long)val > (LONG_MAX>>9)) return -ERANGE;
		val <<= 9;
		task_lock(current->group_leader);
		if (val > current->signal->rlim[RLIMIT_FSIZE].rlim_max) {
			if (!capable(CAP_SYS_RESOURCE)) {
				task_unlock(current->group_leader);
				return -EPERM;
			}
			current->signal->rlim[RLIMIT_FSIZE].rlim_max = val;
		}
		current->signal->rlim[RLIMIT_FSIZE].rlim_cur = val;
		task_unlock(current->group_leader);
		return 0;
	case 3: /* UL_GMEMLIM */
		return current->signal->rlim[RLIMIT_DATA].rlim_cur;
	case 4: /* UL_GDESLIM */
		return sysctl_nr_open;
	}
	return -EINVAL;
}

/* At least at the time I'm writing this, Linux doesn't have ACLs, so we
   just fake this */
asmlinkage int solaris_acl(u32 filename, int cmd, int nentries, u32 aclbufp)
{
	return -ENOSYS;
}

asmlinkage int solaris_facl(unsigned int fd, int cmd, int nentries, u32 aclbufp)
{
	return -ENOSYS;
}

asmlinkage int solaris_pread(unsigned int fd, char __user *buf, u32 count, u32 pos)
{
	ssize_t (*sys_pread64)(unsigned int, char __user *, size_t, loff_t) =
		(ssize_t (*)(unsigned int, char __user *, size_t, loff_t))SYS(pread64);

	return sys_pread64(fd, buf, count, (loff_t)pos);
}

asmlinkage int solaris_pwrite(unsigned int fd, char __user *buf, u32 count, u32 pos)
{
	ssize_t (*sys_pwrite64)(unsigned int, char __user *, size_t, loff_t) =
		(ssize_t (*)(unsigned int, char __user *, size_t, loff_t))SYS(pwrite64);

	return sys_pwrite64(fd, buf, count, (loff_t)pos);
}

/* POSIX.1 names */
#define _PC_LINK_MAX    1
#define _PC_MAX_CANON   2
#define _PC_MAX_INPUT   3
#define _PC_NAME_MAX    4
#define _PC_PATH_MAX    5
#define _PC_PIPE_BUF    6
#define _PC_NO_TRUNC    7
#define _PC_VDISABLE    8
#define _PC_CHOWN_RESTRICTED    9
/* POSIX.4 names */
#define _PC_ASYNC_IO    10
#define _PC_PRIO_IO     11
#define _PC_SYNC_IO     12
#define _PC_LAST        12

/* This is not a real and complete implementation yet, just to keep
 * the easy Solaris binaries happy.
 */
asmlinkage int solaris_fpathconf(int fd, int name)
{
	int ret;

	switch(name) {
	case _PC_LINK_MAX:
		ret = LINK_MAX;
		break;
	case _PC_MAX_CANON:
		ret = MAX_CANON;
		break;
	case _PC_MAX_INPUT:
		ret = MAX_INPUT;
		break;
	case _PC_NAME_MAX:
		ret = NAME_MAX;
		break;
	case _PC_PATH_MAX:
		ret = PATH_MAX;
		break;
	case _PC_PIPE_BUF:
		ret = PIPE_BUF;
		break;
	case _PC_CHOWN_RESTRICTED:
		ret = 1;
		break;
	case _PC_NO_TRUNC:
	case _PC_VDISABLE:
		ret = 0;
		break;
	default:
		ret = -EINVAL;
		break;
	}
	return ret;
}

asmlinkage int solaris_pathconf(u32 path, int name)
{
	return solaris_fpathconf(0, name);
}

/* solaris_llseek returns long long - quite difficult */
asmlinkage long solaris_llseek(struct pt_regs *regs, u32 off_hi, u32 off_lo, int whence)
{
	int (*sys_llseek)(unsigned int, unsigned long, unsigned long, loff_t __user *, unsigned int) =
		(int (*)(unsigned int, unsigned long, unsigned long, loff_t __user *, unsigned int))SYS(_llseek);
	int ret;
	mm_segment_t old_fs = get_fs();
	loff_t retval;
	
	set_fs(KERNEL_DS);
	ret = sys_llseek((unsigned int)regs->u_regs[UREG_I0], off_hi, off_lo, &retval, whence);
	set_fs(old_fs);
	if (ret < 0) return ret;
	regs->u_regs[UREG_I1] = (u32)retval;
	return (retval >> 32);
}

/* Have to mask out all but lower 3 bits */
asmlinkage int solaris_access(u32 filename, long mode)
{
	int (*sys_access)(const char __user *, int) = 
		(int (*)(const char __user *, int))SYS(access);
		
	return sys_access(A(filename), mode & 7);
}