2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
9 * Portions Copyright (c) 2006 Sine Nomine Associates
15 Institution: The Information Technology Center, Carnegie-Mellon University
19 #ifndef AFS_VOL_PARTITION_H
20 #define AFS_VOL_PARTITION_H
22 #include <afs/param.h>
24 #if defined(AFS_HPUX_ENV)
25 #define AFS_DSKDEV "/dev/dsk"
26 #define AFS_RDSKDEV "/dev/rdsk/"
27 #define AFS_LVOLDEV "/dev/vg0"
28 #define AFS_ACVOLDEV "/dev/ac"
29 #define AFS_RACVOLDEV "/dev/ac/r"
31 #define AFS_DSKDEV "/dev"
32 #define AFS_RDSKDEV "/dev/r"
38 /* All Vice partitions on a server will have the following name prefix */
39 #define VICE_PARTITION_PREFIX "/vicep"
40 #define VICE_PREFIX_SIZE (sizeof(VICE_PARTITION_PREFIX)-1)
42 /* If a file by this name exists in a /vicepX directory, it means that
43 * this directory should be used as an AFS partition even if it's not
44 * on a separate partition (for instance if it's part of a large /).
45 * This feature only works with the NAMEI fileserver.
48 #define VICE_ALWAYSATTACH_FILE "AlwaysAttach"
52 * abstraction for files used for file-locking.
55 FD_t fd; /**< fd holding the lock(s) */
56 char *path; /**< path to the lock file */
57 int refcount; /**< how many locks we have on the file */
59 #ifdef AFS_PTHREAD_ENV
60 pthread_mutex_t mutex; /**< lock for the VLockFile struct */
61 #endif /* AFS_PTHREAD_ENV */
64 #ifdef AFS_DEMAND_ATTACH_FS
66 * flag bits for 'flags' in struct VDiskLock.
68 #define VDISKLOCK_ACQUIRING 0x1 /**< is someone waiting for an fs lock? */
69 #define VDISKLOCK_ACQUIRED 0x2 /**< we have an fs lock */
72 * on-disk locking mechanism.
75 struct VLockFile *lockfile; /**< file holding the locks */
76 afs_uint32 offset; /**< what offset we lock in the file */
78 struct Lock rwlock; /**< rw lock for inter-thread locking */
79 pthread_mutex_t mutex; /**< lock for the DiskLock object itself */
80 pthread_cond_t cv; /**< cond var for 'acquiring' changes */
82 int lockers; /**< # of callers that have this locked; */
84 unsigned int flags; /**< see above for flag bits */
86 #endif /* AFS_DEMAND_ATTACH_FS */
89 /* For NT, the roles of "name" and "devName" are reversed. That is, "name"
90 * refers to the drive letter name and "devName" refers to the /vicep style
91 * or name. The reason for this is that a lot of places assume that "name"
92 * is the right thing to use to access the partition. Silly of them isn't it?
93 * The NT version of VInitPartition does the intial setup. There is an NT
94 * variant for VGetPartition as well. Also, the VolPartitionInfo RPC does
95 * a swap before sending the data out on the wire.
97 struct DiskPartition64 {
98 struct DiskPartition64 *next;
99 char *name; /* Mounted partition name */
100 char *devName; /* Device mounted on */
101 Device device; /* device number */
102 afs_int32 index; /* partition index (0<=x<=VOLMAXPARTS) */
103 FD_t lock_fd; /* File descriptor of this partition if locked; otherwise -1;
104 * Not used by the file server */
105 afs_int64 free; /* Total number of blocks (1K) presumed
106 * available on this partition (accounting
107 * for the minfree parameter for the
108 * partition). This is adjusted
109 * approximately by the sizes of files
110 * and directories read/written, and
111 * periodically the superblock is read and
112 * this is recomputed. This number can
113 * be negative, if the partition starts
115 afs_int64 totalUsable; /* Total number of blocks available on this
116 * partition, taking into account the minfree
117 * parameter for the partition (see the
118 * 4.2bsd command tunefs, but note that the
119 * bug mentioned there--that the superblock
120 * is not reread--does not apply here. The
121 * superblock is re-read periodically by
122 * VSetPartitionDiskUsage().) */
123 afs_int64 minFree; /* Number blocks to be kept free, as last read
124 * from the superblock */
126 afs_int64 f_files; /* total number of files in this partition */
127 #ifdef AFS_DEMAND_ATTACH_FS
129 struct rx_queue head; /* list of volumes on this partition (VByPList) */
130 afs_uint32 len; /* length of volume list */
131 int busy; /* asynch vol list op in progress */
132 pthread_cond_t cv; /* vol_list.busy change cond var */
134 struct VLockFile headerLockFile;
135 struct VDiskLock headerLock; /* lock for the collective headers on the partition */
137 struct VLockFile volLockFile; /* lock file for individual volume locks */
138 #endif /* AFS_DEMAND_ATTACH_FS */
141 struct DiskPartitionStats64 {
143 afs_int64 totalUsable;
146 #ifdef AFS_DEMAND_ATTACH_FS
147 afs_int32 vol_list_len;
151 #define PART_DONTUPDATE 1
152 #define PART_DUPLICATE 2 /* NT - used if we find more than one partition
153 * using the same drive. Will be dumped before
154 * all partitions attached.
158 #include <WINNT/vptab.h>
159 extern int VValidVPTEntry(struct vptab *vptp);
163 struct Volume; /* Potentially forward definition */
165 extern struct DiskPartition64 *DiskPartitionList;
166 extern struct DiskPartition64 *VGetPartition(char * name, int abortp);
167 extern struct DiskPartition64 *VGetPartition_r(char * name, int abortp);
168 #ifdef AFS_DEMAND_ATTACH_FS
169 extern struct DiskPartition64 *VGetPartitionById(afs_int32 index, int abortp);
170 extern struct DiskPartition64 *VGetPartitionById_r(afs_int32 index, int abortp);
171 extern int VPartHeaderLock(struct DiskPartition64 *dp, int locktype);
172 extern void VPartHeaderUnlock(struct DiskPartition64 *dp, int locktype);
174 extern int VAttachPartitions(void);
175 extern void VLockPartition(char *name);
176 extern void VLockPartition_r(char *name);
177 extern void VUnlockPartition(char *name);
178 extern void VUnlockPartition_r(char *name);
179 extern void VResetDiskUsage(void);
180 extern void VResetDiskUsage_r(void);
181 extern void VSetPartitionDiskUsage(struct DiskPartition64 *dp);
182 extern void VSetPartitionDiskUsage_r(struct DiskPartition64 *dp);
183 extern char *VPartitionPath(struct DiskPartition64 *p);
184 extern void VAdjustDiskUsage(Error * ec, struct Volume *vp,
185 afs_sfsize_t blocks, afs_sfsize_t checkBlocks);
186 extern int VDiskUsage(struct Volume *vp, afs_sfsize_t blocks);
187 extern void VPrintDiskStats(void);
188 extern int VInitPartitionPackage(void);
190 #endif /* AFS_VOL_PARTITION_H */