����14-5 linux/include/fcntl.h
1 #ifndef _FCNTL_H
2 #define _FCNTL_H
3
4 #include <sys/types.h> // ����ͷ�ļ��������˻�����ϵͳ�������͡�
5
6 /* open/fcntl - NOCTTY, NDELAY isn't implemented yet */
/* open/fcntl - NOCTTY��NDELAY���ڻ�û��ʵ�� */
7 #define O_ACCMODE 00003 // �ļ�����ģʽ�����롣
// ���ļ�open()���ļ����ƺ���fcntl()ʹ�õ��ļ�����ģʽ��ͬʱֻ��ʹ������֮һ��
8 #define O_RDONLY 00 // ��ֻ����ʽ���ļ���
9 #define O_WRONLY 01 // ��ֻд��ʽ���ļ���
10 #define O_RDWR 02 // �Զ�д��ʽ���ļ���
// �������ļ������Ͳ�����־������open()�������������ģʽ��'λ��'�ķ�ʽһ��ʹ�á�
11 #define O_CREAT 00100 /* not fcntl */ // ����ļ������ھʹ�����fcntl�������á�
12 #define O_EXCL 00200 /* not fcntl */ // ��ռʹ���ļ���־��
13 #define O_NOCTTY 00400 /* not fcntl */ // ����������նˡ�
14 #define O_TRUNC 01000 /* not fcntl */ // ���ļ��Ѵ�������д�������Ƚ�Ϊ0��
15 #define O_APPEND 02000 // �����ӷ�ʽ���ļ�ָ����Ϊ�ļ�β��
16 #define O_NONBLOCK 04000 /* not fcntl */ // ��������ʽ�Ͳ����ļ���
17 #define O_NDELAY O_NONBLOCK // ��������ʽ�Ͳ����ļ���
18
19 /* Defines for fcntl-commands. Note that currently
20 * locking isn't supported, and other things aren't really
21 * tested.
22 */
/* ���涨����fcntl�����ע��Ŀǰ�������û��֧�֣�������
* ����ʵ���ϻ�û�в��Թ���
*/
// ����(������)��������fcntl()�����cmd����
23 #define F_DUPFD 0 /* dup */ // �����ļ����Ϊ��С��ֵ�ľ����
24 #define F_GETFD 1 /* get f_flags */ // ȡ�����־����1����־FD_CLOEXEC��
25 #define F_SETFD 2 /* set f_flags */ // �����ļ������־��
26 #define F_GETFL 3 /* more flags (cloexec) */ // ȡ�ļ�״̬��־�ͷ���ģʽ��
27 #define F_SETFL 4 // �����ļ�״̬��־�ͷ���ģʽ��
// �������ļ��������fcntl()�ĵ���������lock��ָ��flock�ṹ��ָ�롣
28 #define F_GETLK 5 /* not implemented */ // ������ֹ������flock�ṹ��
29 #define F_SETLK 6 // ����(F_RDLCK��F_WRLCK)�����(F_UNLCK)������
30 #define F_SETLKW 7 // �ȴ����û����������
31
32 /* for F_[GET|SET]FL */
/* ���� F_GETFL��F_SETFL */
// ��ִ��exec()�غ���ʱ��Ҫ�رյ��ļ������(ִ��ʱ�ر� - Close On EXECution)
33 #define FD_CLOEXEC 1 /* actually anything with low bit set goes */
/* ʵ����ֻҪ��λΪ1���� */
34
35 /* Ok, these are locking features, and aren't implemented at any
36 * level. POSIX wants them.
37 */
/* OK���������������ͣ��κκ����ж���û��ʵ�֡�POSIX��Ҫ����Щ���͡�
*/
38 #define F_RDLCK 0 // ��������������
39 #define F_WRLCK 1 // ��ռ��д�ļ�������
40 #define F_UNLCK 2 // �������
41
42 /* Once again - not implemented, but ... */
/* ͬ�� - Ҳ��û��ʵ�֣�����... */
// �ļ������������ݽṹ����������Ӱ���ļ��ε�����(l_type)����ʼƫ��(l_whence)��
// ���ƫ��(l_start)����������(l_len)��ʵʩ�����Ľ���id��
43 struct flock {
44 short l_type; // �������ͣ�F_RDLCK��F_WRLCK��F_UNLCK����
45 short l_whence; // ��ʼƫ��(SEEK_SET��SEEK_CUR��SEEK_END)��
46 off_t l_start; // ���������Ŀ�ʼ�������ƫ�ƣ��ֽ�������
47 off_t l_len; // ���������Ĵ�С�������0��Ϊ���ļ�ĩβ��
48 pid_t l_pid; // �����Ľ���id��
49 };
50
// ������ʹ��������־������ĺ���ԭ�͡�
// �������ļ�����дһ���Ѵ����ļ���
// ����filename���������ļ����ļ�����mode�Ǵ����ļ������ԣ���include/sys/stat.h����
51 extern int creat(const char * filename,mode_t mode);
// �ļ������������Ӱ���ļ��Ĵ�
// ����fildes���ļ������cmd�Dz������������23--30�С��ú����������¼�����ʽ��
// int fcntl(int fildes, int cmd);
// int fcntl(int fildes, int cmd, long arg);
// int fcntl(int fildes, int cmd, struct flock *lock);
52 extern int fcntl(int fildes,int cmd, ...);
// ���ļ������ļ����ļ����֮�佨����ϵ��
// ����filename�������ļ����ļ�����flags������7-17���ϵı�־����ϡ�
53 extern int open(const char * filename, int flags, ...);
54
55 #endif
56